package com.sy.coinage.app.controller;

import com.sy.coinage.core.annotation.CurrentUser;
import com.sy.coinage.core.aop.annotation.Operation;
import com.sy.coinage.core.controller.BaseController;
import com.sy.coinage.core.interceptor.Create;
import com.sy.coinage.core.vo.CacheUserVO;
import com.sy.coinage.workshop.req.WorkshopEntryReq;
import com.sy.coinage.workshop.service.IWorkshopEntryService;
import io.netty.handler.timeout.ReadTimeoutException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * -车间入库单（仅记录入库单，及返检单）Controller
 */
@Api(tags = "App-车间入库单（仅记录入库单，及返检单）接口")
@RestController
@RequestMapping(value = "/app/workshopEntry")
public class AppWorkshopEntryController extends BaseController {

    @Autowired
    private IWorkshopEntryService workshopEntryService;

    //=========app接口

    /**
     * 新增车间入库单（仅记录入库单，及返检单）
     *
     * @param req {@link WorkshopEntryReq}
     * @return
     */
    @ApiOperation(value = "2.1 app新增车间入库单（仅记录入库单，及返检单）")
    @Operation(value = "新增车间入库单（仅记录入库单，及返检单）")
    @PostMapping("/add")
    // @Permission("workshopEntry:add")
    public Object add(@RequestBody @ApiParam(value = "新增请求bean") @Validated({Create.class}) WorkshopEntryReq req,
                      @CurrentUser CacheUserVO user) {
        //delete by hliu ,由于车间入库可以是零箱零枚，因此，这两个列表可以为空，所以注释掉该判断
//        if (req.getAutoLs().isEmpty() && req.getManualLs().isEmpty()) {
//            throw new ReadTimeoutException("扫描的rfid列表与手动录入rfid列表不能都为空");
//        }
        this.workshopEntryService.add(req, user);
        return "";
    }

}
