You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-spms-java/src/main/java/com/glxp/api/controller/inout/IoOrderReviewController.java

418 lines
19 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.api.controller.inout;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
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.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.controller.BaseController;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
import com.glxp.api.entity.basic.EntrustReceEntity;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.inout.FilterOrderDetailResultRequest;
import com.glxp.api.req.inout.ReviewFinishRequest;
import com.glxp.api.req.inout.UpdateExportStatusRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.inout.AcceptOrderResponse;
import com.glxp.api.res.inout.IoOrderDetailResultResponse;
import com.glxp.api.service.auth.AuthAdminService;
import com.glxp.api.service.basic.EntrustReceService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.inout.*;
import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.CustomUtil;
import com.glxp.api.util.GennerOrderUtils;
import com.glxp.api.util.OrderNoTypeBean;
import com.glxp.api.util.RedisUtil;
import com.glxp.api.util.udi.UdiCalCountUtil;
import lombok.extern.slf4j.Slf4j;
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 java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
//单据验收
@Slf4j
@RestController
public class IoOrderReviewController extends BaseController {
@Resource
private RedisUtil redisUtil;
@Resource
private IoOrderDetailResultService orderDetailResultService;
@Resource
IoOrderService orderService;
@Resource
IoCheckInoutService ioCheckInoutService;
//获取验收单据业务详情
@AuthRuleAnnotation("")
@GetMapping("/udiwms/stock/order/accept/getOrder")
public BaseResponse getAcceptOrder(String billNo) {
if (StrUtil.isBlank(billNo)) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
AcceptOrderResponse acceptOrderEntity = new AcceptOrderResponse();
acceptOrderEntity.setBillNo(billNo);
List<IoOrderDetailResultResponse> datas = (List<IoOrderDetailResultResponse>) redisUtil.get(ConstantStatus.REDIS_BILLNO + billNo);
if (CollUtil.isNotEmpty(datas)) {
acceptOrderEntity.setOrderDetailEntities(datas);
acceptOrderEntity.setExitAccept(true);
} else {
FilterOrderDetailResultRequest filterOrderDetailResultRequest = new FilterOrderDetailResultRequest();
filterOrderDetailResultRequest.setOrderIdFk(billNo);
List<IoOrderDetailResultResponse> orderDetailResultResponses = orderDetailResultService.filterList(filterOrderDetailResultRequest);
acceptOrderEntity.setOrderDetailEntities(orderDetailResultResponses);
acceptOrderEntity.setExitAccept(false);
}
return ResultVOUtils.success(acceptOrderEntity);
}
//获取验收单据业务详情
@AuthRuleAnnotation("")
@GetMapping("/udiwms/stock/order/accept/getStatus")
public BaseResponse getStatus(String billNo) {
if (StrUtil.isBlank(billNo)) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
AcceptOrderResponse acceptOrderEntity = new AcceptOrderResponse();
acceptOrderEntity.setBillNo(billNo);
List<IoOrderDetailResultResponse> datas = (List<IoOrderDetailResultResponse>) redisUtil.get(ConstantStatus.REDIS_BILLNO + billNo);
if (CollUtil.isNotEmpty(datas)) {
boolean isFinish = vailFinish(datas);
if (isFinish)
return ResultVOUtils.success("单据已验收完成");
else
return ResultVOUtils.error(500, "单据未验收完成");
} else {
return ResultVOUtils.error(500, "单据未验收完成");
}
}
//前端二次审核
@AuthRuleAnnotation("")
@PostMapping("/spms/inout/order/web/updateStatus")
@Log(title = "单据管理", businessType = BusinessType.UPDATE)
public BaseResponse webUpdateStatus(@RequestBody ReviewFinishRequest updateExportStatusRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
IoOrderEntity orderEntity = orderService.findByBillNo(updateExportStatusRequest.getOrderId());
if (orderEntity == null) {
return ResultVOUtils.error(500, "未找到该业务单据");
}
if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_CHECK_REW) {
return updateReview(getUser(), orderEntity);
} else if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_CHECK_SUCCESS) {
return thirdUpdateReview(getUser(), orderEntity);
} else {
return ResultVOUtils.error(500, "当前单据状态非处于审核状态!");
}
}
//前端第三次验收
@AuthRuleAnnotation("")
@PostMapping("/spms/inout/order/third/updateStatus")
@Log(title = "单据管理", businessType = BusinessType.UPDATE)
public BaseResponse thirdUpdateStatus(@RequestBody ReviewFinishRequest updateExportStatusRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
IoOrderEntity orderEntity = orderService.findByBillNo(updateExportStatusRequest.getOrderId());
if (orderEntity == null) {
return ResultVOUtils.error(500, "未找到该业务单据");
}
return thirdUpdateReview(getUser(), orderEntity);
}
@Resource
IoCodeService codeService;
@Resource
IoCodeTempService codeTempService;
@Resource
UdiCalCountUtil calCountUtil;
//前端扫码验收
@AuthRuleAnnotation("")
@PostMapping("/udiwms/stock/order/accept/addCode")
public BaseResponse acceptAddCode(@RequestBody AcceptOrderResponse acceptOrderEntity) {
IoOrderEntity stockOrderEntity = orderService.findByBillNo(acceptOrderEntity.getBillNo());
List<IoCodeEntity> codeList;
List<IoCodeEntity> codeEntityList = (List<IoCodeEntity>) redisUtil.get(ConstantStatus.REDIS_BILLNO_CODES + acceptOrderEntity.getBillNo());
if (CollUtil.isEmpty(codeEntityList)) {
codeList = codeService.findByOrderId(stockOrderEntity.getBillNo());
} else {
codeList = codeEntityList;
}
IoCodeEntity codeEntity = isExit(codeList, acceptOrderEntity.getCode());
if (codeEntity == null) {
return ResultVOUtils.error(500, "非此单UDI码");
}
int status = checkCodeExit(codeEntity.getCode(), codeList);
if (status == Constant.CHECK_REPEAT) {
return ResultVOUtils.error(500, "重复扫码!");
} else if (status == Constant.CHECK_NULL) {
return ResultVOUtils.error(500, "非此单UDI码");
}
List<IoOrderDetailResultResponse> orderDetailResultResponses = acceptOrderEntity.getOrderDetailEntities();
if (StrUtil.isNotEmpty(acceptOrderEntity.getCode()) && CollUtil.isNotEmpty(orderDetailResultResponses)) {
boolean isExit = false;
for (IoOrderDetailResultResponse orderDetailResultResponse : orderDetailResultResponses) {
if (orderDetailResultResponse.getBindRlFk().longValue() == codeEntity.getRelId().longValue() &&
StrUtil.trimToEmpty(orderDetailResultResponse.getBatchNo()).equals(StrUtil.trimToEmpty(codeEntity.getBatchNo()))) {
orderDetailResultResponse.setAcceptCount(orderDetailResultResponse.getAcceptCount() + calCountUtil.getActCount(codeEntity.getNameCode()));
if (orderDetailResultResponse.getAcceptCount() > orderDetailResultResponse.getCount()) {
return ResultVOUtils.error(500, "数量溢出!");
}
isExit = true;
break;
}
}
if (isExit) {
redisUtil.set(ConstantStatus.REDIS_BILLNO + acceptOrderEntity.getBillNo(), orderDetailResultResponses);
redisUtil.set(ConstantStatus.REDIS_BILLNO_CODES + acceptOrderEntity.getBillNo(), codeList);
acceptOrderEntity.setOrderDetailEntities(orderDetailResultResponses);
if (vailFinish(orderDetailResultResponses)) {
acceptOrderEntity.setFinishAccept(true);
return ResultVOUtils.success(acceptOrderEntity);
}
return ResultVOUtils.success(acceptOrderEntity);
}
}
return ResultVOUtils.error(500, "非此单条码!");
}
@Resource
AuthAdminService authAdminService;
@Resource
EntrustReceService entrustReceService;
//手持终端验收完成后,更新订单状态
@AuthRuleAnnotation("")
@PostMapping("/spms/inout/order/check/updateStatus")
@Log(title = "单据管理", businessType = BusinessType.UPDATE)
public BaseResponse updateStatus(@RequestBody UpdateExportStatusRequest updateExportStatusRequest,
BindingResult bindingResult) {
AuthAdmin authAdmin = null;
if (StrUtil.isNotEmpty(updateExportStatusRequest.getWmsUserId())) {
authAdmin = authAdminService.findById(Long.parseLong(updateExportStatusRequest.getWmsUserId()));
} else
authAdmin = getUser();
IoOrderEntity orderEntity = orderService.findByBillNo(updateExportStatusRequest.getOrderId());
if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_AUDITED) {
return ResultVOUtils.error(500, "单据已验收!");
}
if (updateExportStatusRequest.isEntrust() && updateExportStatusRequest.getEntrustId() != null) {
EntrustReceEntity entrustReceEntity = entrustReceService.findById(updateExportStatusRequest.getEntrustId());
if (entrustReceEntity == null) {
return ResultVOUtils.error(500, "无验收权限!");
} else {
if (orderEntity.getFromType().intValue() != ConstantStatus.FROM_CHANGE && orderEntity.getFromType().intValue() != ConstantStatus.FROM_PEACE_CHANGE) {
if (StrUtil.isNotEmpty(entrustReceEntity.getEntrustAction())) {
transferOrder(orderEntity, entrustReceEntity);
}
}
if (!entrustReceEntity.getFinishRece()) {
redisUtil.del(ConstantStatus.REDIS_BILLNO + orderEntity.getBillNo());
redisUtil.del(ConstantStatus.REDIS_BILLNO_CODES + orderEntity.getBillNo());
return ResultVOUtils.success("验收成功!");
} else
return updateReview(authAdmin, orderEntity);
}
} else
return updateReview(authAdmin, orderEntity);
}
@Resource
IBasicBussinessTypeService basicBussinessTypeService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
SystemParamConfigService systemParamConfigService;
public void transferOrder(IoOrderEntity orderEntity, EntrustReceEntity entrustReceEntity) {
List<IoCodeEntity> warehouseEntities = codeService.findByOrderId(orderEntity.getBillNo());
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(entrustReceEntity.getEntrustAction());
IoOrderEntity supplementOrder = new IoOrderEntity();
BeanUtil.copyProperties(orderEntity, supplementOrder);
//生成补单单号
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
String supplementOrderNo = orderNo;
supplementOrder.setOriginUllageSupNo(orderEntity.getBillNo());
supplementOrder.setBillNo(supplementOrderNo);
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("additional_auto_submit");
if ("1".equals(systemParamConfigEntity.getParamValue())) {
supplementOrder.setStatus(ConstantStatus.ORDER_STATUS_PROCESS); //设置状态为补录单据
} else {
supplementOrder.setStatus(ConstantStatus.ORDER_STATUS_ADDITIONAL); //设置状态为补录单据
}
supplementOrder.setStatus(ConstantStatus.ORDER_STATUS_PROCESS); //设置导出状态为未导出
supplementOrder.setCorpOrderId(CustomUtil.getId() + "x");
//修改往来单位及当前库存号
supplementOrder.setFromDeptCode(orderEntity.getDeptCode());
supplementOrder.setFromInvCode(orderEntity.getInvCode());
supplementOrder.setDeptCode(entrustReceEntity.getEntrustDept());
supplementOrder.setInvCode(entrustReceEntity.getEntrustInv());
supplementOrder.setFromType(ConstantStatus.FROM_REVIEW);
supplementOrder.setMainAction(bussinessTypeEntity.getMainAction());
supplementOrder.setAction(bussinessTypeEntity.getAction());
orderEntity.setBusType(bussinessTypeEntity.getBusType());
//复制码表
List<IoCodeTempEntity> supplementCodes = new ArrayList<>();
warehouseEntities.forEach(
code -> {
IoCodeTempEntity supplementCode = new IoCodeTempEntity();
BeanUtil.copyProperties(code, supplementCode);
supplementCode.setInvCode(supplementOrder.getInvCode());
supplementCode.setDeptCode(supplementOrder.getDeptCode());
supplementCode.setOrderId(supplementOrderNo);
//查询补单设置
supplementCode.setAction(bussinessTypeEntity.getSupplementOrderType());
supplementCode.setMainAction(bussinessTypeEntity.getMainAction());
supplementCode.setId(null);
supplementCodes.add(supplementCode);
}
);
//更新数据
orderService.insertOrder(supplementOrder);
orderEntity.setUllageSupNo(supplementOrder.getBillNo());
orderService.update(orderEntity);
codeTempService.insertBatch(supplementCodes);
}
public int checkCodeExit(String code, List<IoCodeEntity> codesList) {
if (StrUtil.isNotEmpty(code)) {
code = code.replace("\r\n", "");
}
if (code.endsWith("\u001D")) {
code = code.replace("\u001D", "");
}
for (IoCodeEntity checkOrderCodesBean : codesList) {
if (checkOrderCodesBean.getCode().toUpperCase(Locale.ROOT).equals(code.toUpperCase(Locale.ROOT))) {
if (checkOrderCodesBean.getStatus() == Constant.DB_CHECK_ED
&& checkOrderCodesBean.getMyCount() == checkOrderCodesBean.getScanCount()) {
return Constant.CHECK_REPEAT;
}
int curCount = checkOrderCodesBean.getScanCount() + calCountUtil.getActCount(checkOrderCodesBean.getNameCode());
if (curCount == checkOrderCodesBean.getMyCount()) {
checkOrderCodesBean.setStatus(Constant.DB_CHECK_ED);
}
checkOrderCodesBean.setScanCount(curCount);
return Constant.CHECK_EXIT;
}
}
return Constant.CHECK_NULL;
}
public IoCodeEntity isExit(List<IoCodeEntity> codeList, String code) {
if (CollUtil.isNotEmpty(codeList)) {
for (IoCodeEntity codeEntity : codeList) {
if (codeEntity.getCode().equals(code)) {
return codeEntity;
}
}
}
return null;
}
public boolean vailFinish(List<IoOrderDetailResultResponse> orderDetailResultResponses) {
if (CollUtil.isNotEmpty(orderDetailResultResponses)) {
for (IoOrderDetailResultResponse stockOrderDetailEntity : orderDetailResultResponses) {
if (stockOrderDetailEntity.getCount() != stockOrderDetailEntity.getAcceptCount()) {
return false;
}
}
return true;
}
return false;
}
@AuthRuleAnnotation("")
@PostMapping("/udiwms/stock/order/acceptClear")
public BaseResponse acceptClear(@RequestBody AcceptOrderResponse acceptOrderEntity) {
String billNo = acceptOrderEntity.getBillNo();
redisUtil.del(ConstantStatus.REDIS_BILLNO + billNo);
redisUtil.del(ConstantStatus.REDIS_BILLNO_CODES + billNo);
FilterOrderDetailResultRequest filterOrderDetailResultRequest = new FilterOrderDetailResultRequest();
filterOrderDetailResultRequest.setOrderIdFk(billNo);
List<IoOrderDetailResultResponse> orderDetailResultResponses = orderDetailResultService.filterList(filterOrderDetailResultRequest);
acceptOrderEntity.setOrderDetailEntities(orderDetailResultResponses);
return ResultVOUtils.success(acceptOrderEntity);
}
public BaseResponse updateReview(AuthAdmin authAdmin, IoOrderEntity orderEntity) {
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED);
orderEntity.setReviewUser(authAdmin.getId() + "");
orderEntity.setUpdateTime(new Date());
orderEntity.setAuditTime(new Date());
orderService.update(orderEntity);
redisUtil.del(ConstantStatus.REDIS_BILLNO + orderEntity.getBillNo());
redisUtil.del(ConstantStatus.REDIS_BILLNO_CODES + orderEntity.getBillNo());
//验收完成->进入流程
ioCheckInoutService.checkSecond(orderEntity);
return ResultVOUtils.success("更新成功");
}
//前端第二次次验收
public BaseResponse thirdUpdateReview(AuthAdmin authAdmin, IoOrderEntity orderEntity) {
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW);
orderEntity.setCheckUser(authAdmin.getId() + "");
orderEntity.setUpdateTime(new Date());
orderEntity.setCheckTime(new Date());
orderEntity.setDeliveryStatus(ConstantStatus.ORDER_DELIVERY_STATUS_ED);
orderService.update(orderEntity);
redisUtil.del(ConstantStatus.REDIS_BILLNO + orderEntity.getBillNo());
redisUtil.del(ConstantStatus.REDIS_BILLNO_CODES + orderEntity.getBillNo());
//验收完成->进入流程
ioCheckInoutService.checkThird(orderEntity);
return ResultVOUtils.success("更新成功");
}
}