| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.CheckTaskListParam; |
| | | import com.zy.asrs.enums.CheckStatusEnum; |
| | | import com.zy.asrs.mapper.CheckOrderMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.zy.common.model.LocDto; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service("checkOrderService") |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R pdaComplete(CheckTaskListParam checkTaskListParam) { |
| | | public R pdaComplete(CheckTaskListParam checkTaskListParam, Long userId) { |
| | | |
| | | WrkMast wrkMast = wrkMastService.selectByBarcode(checkTaskListParam.getBarcode()); |
| | | if (Cools.isEmpty(wrkMast)) { |
| | | throw new CoolException("未找到任务"); |
| | | } |
| | | |
| | | for (CheckOrderDetl checkOrderDetl: checkTaskListParam.getCheckOrderDetlList()){ |
| | | checkOrderDetl.setStatus(3); |
| | | if (!checkOrderDetlService.updateById(checkOrderDetl)){ |
| | | throw new CoolException("更新盘点状态失败"); |
| | | } |
| | | } |
| | | CheckOrder checkOrder = this.selectOne(new EntityWrapper<CheckOrder>().eq("order_no", checkTaskListParam.getCheckOrderDetlList().get(0).getOrderNo())); |
| | | for (CheckOrderDetl checkOrderDetl: checkTaskListParam.getCheckOrderDetlList()){ |
| | | if (Cools.isEmpty(checkOrderDetl.getId()) && !Cools.isEmpty(checkOrderDetl.getWorkQty())){ |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("barcode", checkTaskListParam.getBarcode())); |
| | | if (Cools.isEmpty(locMast)){ |
| | | throw new CoolException("未找到库位数据"); |
| | | } |
| | | LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .eq("matnr", checkOrderDetl.getMatnr()) |
| | | .eq(!Cools.isEmpty(checkOrderDetl.getBatch()),"batch", checkOrderDetl.getBatch()) |
| | | .eq("supp_code", checkOrderDetl.getSuppCode()) |
| | | ); |
| | | if (!Cools.isEmpty(locDetl)){ |
| | | throw new CoolException("当前库位有相同库存信息"); |
| | | } |
| | | Date now = new Date(); |
| | | CheckOrderDetl checkOrderDetl1 = new CheckOrderDetl(); |
| | | checkOrderDetl1.sync(checkOrderDetl); |
| | | checkOrderDetl1.setLocNo(locMast.getLocNo()); |
| | | checkOrderDetl1.setOrderId(checkOrder.getId()); |
| | | checkOrderDetl1.setOrderNo(checkOrder.getOrderNo()); |
| | | checkOrderDetl1.setAnfme(checkOrderDetl.getAnfme()); |
| | | checkOrderDetl1.setDiffQty(checkOrderDetl.getWorkQty().subtract(checkOrderDetl.getAnfme())); |
| | | checkOrderDetl1.setWorkQty(checkOrderDetl.getWorkQty()); |
| | | checkOrderDetl1.setStatus(3); |
| | | checkOrderDetl1.setZpallet(checkTaskListParam.getBarcode()); |
| | | checkOrderDetl1.setCreateBy(userId); |
| | | checkOrderDetl1.setCreateTime(now); |
| | | checkOrderDetl1.setUpdateBy(userId); |
| | | checkOrderDetl1.setUpdateTime(now); |
| | | checkOrderDetlService.insert(checkOrderDetl1); |
| | | LocDetl locDetl1 = new LocDetl(); |
| | | locDetl1.sync(checkOrderDetl); |
| | | BeanUtils.copyProperties(checkOrderDetl, locDetl1); |
| | | locDetl1.setLocNo(locMast.getLocNo()); |
| | | locDetl1.setZpallet(checkTaskListParam.getBarcode()); |
| | | locDetl1.setAnfme(checkOrderDetl.getAnfme().doubleValue()); |
| | | locDetl1.setDiffQty(checkOrderDetl.getWorkQty().subtract(checkOrderDetl.getAnfme())); |
| | | locDetl1.setAppeUser(userId); |
| | | locDetl1.setAppeTime(now); |
| | | locDetl1.setModiUser(userId); |
| | | locDetl1.setModiTime(now); |
| | | locDetlService.insert(locDetl1); |
| | | }else if (!Cools.isEmpty(checkOrderDetl.getId())){ |
| | | checkOrderDetl.setDiffQty(checkOrderDetl.getWorkQty().subtract(checkOrderDetl.getAnfme())); |
| | | checkOrderDetl.setStatus(3); |
| | | if (!checkOrderDetlService.updateById(checkOrderDetl)){ |
| | | throw new CoolException("更新盘点状态失败"); |
| | | } |
| | | }else { |
| | | throw new CoolException("数据错误"); |
| | | } |
| | | |
| | | } |
| | | |
| | | List<CheckOrderDetl> checkOrderDetls = checkOrderDetlService.selectList(new EntityWrapper<CheckOrderDetl>().eq("order_id", checkOrder.getId())); |
| | | boolean is = checkOrderDetls.stream().allMatch(item -> item.getStatus().equals(3)); |
| | | if (is){ |
| | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void adjustOrderComplete(Long orderId, Long userId) { |
| | | CheckOrder checkOrder = this.selectById(orderId); |
| | | if (Cools.isEmpty(checkOrder)) { |
| | | throw new CoolException("数据错误"); |
| | | } |
| | | List<CheckOrderDetl> selectList = checkOrderDetlService.selectList(new EntityWrapper<CheckOrderDetl>().eq("order_id", orderId)); |
| | | for (CheckOrderDetl checkOrderDetl : selectList) { |
| | | |
| | | LocDetl locDetl = locDetlService.selectById(checkOrderDetl.getLocDetlId()); |
| | | if (Cools.isEmpty(locDetl)) { |
| | | throw new CoolException("未找到库存数据,数据错误"); |
| | | } |
| | | if (locDetl.getDiffQty().compareTo(BigDecimal.ZERO) == 0) { |
| | | throw new CoolException("库存无盘点差异记录,数据错误"); |
| | | } |
| | | if (checkOrderDetl.getStatus().equals(CheckStatusEnum.ALLOW.type)) { |
| | | BigDecimal decimal = locDetl.getBookQty().add(checkOrderDetl.getDiffQty()); |
| | | locDetl.setAnfme(decimal.doubleValue()); |
| | | }else if (checkOrderDetl.getStatus().equals(CheckStatusEnum.FORBID.type)) { |
| | | if (locDetl.getDiffQty().compareTo(BigDecimal.ZERO) < 0) { |
| | | BigDecimal subtract = new BigDecimal(locDetl.getAnfme().toString()).subtract(locDetl.getDiffQty()); |
| | | locDetl.setAnfme(subtract.doubleValue()); |
| | | } |
| | | } |
| | | |
| | | locDetl.setDiffQty(BigDecimal.ZERO); |
| | | locDetl.setModiTime(new Date()); |
| | | if (!locDetlService.updateById(locDetl)){ |
| | | throw new CoolException("更新库存数据失败"); |
| | | } |
| | | } |
| | | |
| | | checkOrder.setSettle(4L); |
| | | checkOrder.setUpdateTime(new Date()); |
| | | if (!this.updateById(checkOrder)){ |
| | | throw new CoolException("更新调整单状态失败"); |
| | | } |
| | | } |
| | | } |