Junjie
2024-08-02 71fb0226eba99f4bd9503c1da89925f53fd54d8a
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/WaitPakinController.java
@@ -5,9 +5,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.entity.*;
import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType;
import com.zy.asrs.wms.asrs.service.*;
import com.zy.asrs.wms.common.annotation.OperationLog;
import com.zy.asrs.wms.common.domain.BaseParam;
@@ -29,14 +27,6 @@
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private LocService locService;
    @Autowired
    private TaskService taskService;
    @PreAuthorize("hasAuthority('asrs:waitPakin:list')")
    @PostMapping("/waitPakin/page")
@@ -67,56 +57,12 @@
    @PreAuthorize("hasAuthority('asrs:waitPakin:save')")
    @OperationLog("添加组托通知档")
    @PostMapping("/waitPakin/save")
    @Transactional
    public R save(@RequestBody WaitPakin waitPakin) {
        if (waitPakin.getAnfme() <= 0) {
            return R.error("组托数量错误");
        }
        List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, waitPakin.getBarcode()));
        if (!locList.isEmpty()) {
            return R.error("托盘已在库");
        }
        List<Task> taskList = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, waitPakin.getBarcode()));
        if (!taskList.isEmpty()) {
            return R.error("托盘正在入库中");
        }
        //查询是否存在相同明细和托盘码的组托通知档
        WaitPakin waitPakin1 = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, waitPakin.getBarcode()).eq(WaitPakin::getDetlId, waitPakin.getDetlId()));
        if (waitPakin1 == null) {
            //不存在组托通知档,创建
            if (!waitPakinService.save(waitPakin)) {
                return R.error("添加失败");
            }
        }else {
            //存在组托通知档,更新
            waitPakin1.setAnfme(waitPakin1.getAnfme() + waitPakin.getAnfme());
            waitPakin1.setUpdateTime(new Date());
            if (!waitPakinService.updateById(waitPakin1)) {
                return R.error("添加失败");
            }
        }
        OrderDetl orderDetl = orderDetlService.getById(waitPakin.getDetlId());
        if (orderDetl == null) {
            throw new CoolException("订单明细不存在");
        }
        //获取订单
        Order order = orderService.getById(orderDetl.getOrderId());
        if(order == null){
            throw new CoolException("订单不存在");
        }
        //更新订单状态
        if (order.getOrderSettle().equals(OrderSettleType.INIT.val())) {
            order.setOrderSettle(OrderSettleType.WAIT.val());
            order.setUpdateTime(new Date());
            if (!orderService.updateById(order)) {
                throw new CoolException("订单数据更新失败");
            }
        try {
            waitPakinService.comb(waitPakin);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok("添加成功");
    }