package com.glxp.api.controller.inout; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.annotation.Log; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.BusinessType; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.inout.IoCodeLostEntity; import com.glxp.api.entity.inout.IoCodeTempEntity; import com.glxp.api.req.inout.IoCodeLostRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.inout.IoCodeLostResponse; import com.glxp.api.service.inout.IoCodeLostService; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; import java.util.Date; import java.util.List; @RestController public class IoCodeLostController extends BaseController { @Resource IoCodeLostService codeLostService; @AuthRuleAnnotation("") @PostMapping("warehouse/inout/getCodeLost") public BaseResponse getCodeLost(@RequestBody @Valid IoCodeLostRequest ioCodeLostEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } List list = codeLostService.selectLost(ioCodeLostEntity); PageInfo pageInfo; pageInfo = new PageInfo<>(list); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(list); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("warehouse/inout/updateCodeLost") @Log(title = "单据管理", businessType = BusinessType.UPDATE) public BaseResponse updateCodeLost(@RequestBody @Valid IoCodeLostEntity ioCodeLostEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } codeLostService.update(ioCodeLostEntity); return ResultVOUtils.success("成功"); } @AuthRuleAnnotation("") @PostMapping("warehouse/inout/saveTabCode") public BaseResponse saveCode(@RequestBody IoCodeTempEntity codeTempEntity) { if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo()) && codeTempEntity.getSerialNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!序列号超出最大范围,不予缓存"); } if (StrUtil.isNotEmpty(codeTempEntity.getBatchNo()) && codeTempEntity.getBatchNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!批次号超出最大范围,不予缓存"); } if (StrUtil.isBlank(codeTempEntity.getSerialNo()) && StrUtil.isBlank(codeTempEntity.getBatchNo())) { return ResultVOUtils.error(500, "批次号不能为空!,不予缓存"); } if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo())) { return ResultVOUtils.error(500, "有序列号不予缓存"); } IoCodeLostEntity codeLostEntity = codeLostService.findByCode(codeTempEntity.getCode()); IoCodeLostEntity insertEntity = null; if (codeLostEntity == null) { insertEntity = new IoCodeLostEntity(); insertEntity.setCreateTime(new Date()); } else { insertEntity = codeLostEntity; } insertEntity.setCode(codeTempEntity.getCode()); insertEntity.setBatchNo(codeTempEntity.getBatchNo()); insertEntity.setProduceDate(codeTempEntity.getProduceDate()); insertEntity.setExpireDate(codeTempEntity.getExpireDate()); insertEntity.setSerialNo(codeTempEntity.getSerialNo()); insertEntity.setSupId(codeTempEntity.getSupId()); insertEntity.setUpdateTime(new Date()); if (codeLostEntity != null) { codeLostService.update(insertEntity); } else { codeLostService.insert(insertEntity); } return ResultVOUtils.success("修改成功!"); } //获取验收单据业务详情 @AuthRuleAnnotation("") @GetMapping("/warehouse/inout/getTabCode") public BaseResponse getTabCode(String code) { if (StrUtil.isBlank(code)) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } IoCodeLostEntity codeLostEntity = codeLostService.findByCode(code); if (codeLostEntity == null) return ResultVOUtils.error(500, "未缓存!"); return ResultVOUtils.success(codeLostEntity); } }