|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | import com.core.common.*; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.common.SnowflakeIdWorker; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.CombParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.MobileAdjustParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.OffSaleParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.OpenOrderPakinParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.*; | 
|---|
|  |  |  | import com.zy.asrs.mapper.LocMastMapper; | 
|---|
|  |  |  | import com.zy.asrs.mapper.ManLocDetlMapper; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.MatUtils; | 
|---|
|  |  |  | import com.zy.common.CodeRes; | 
|---|
|  |  |  | import com.zy.common.constant.MesConstant; | 
|---|
|  |  |  | import com.zy.common.entity.Parameter; | 
|---|
|  |  |  | import com.zy.asrs.utils.MathUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.OrderInAndOutUtil; | 
|---|
|  |  |  | import com.zy.common.model.DetlDto; | 
|---|
|  |  |  | import com.zy.common.model.MesCombParam; | 
|---|
|  |  |  | import com.zy.common.model.enums.WorkNoType; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.nc.service.NccJcQilibcBarcodeflowWmsService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.Iterator; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 移动端服务核心类 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class MobileServiceImpl implements MobileService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wcs.url}") | 
|---|
|  |  |  | private String wcsUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatService matService; | 
|---|
|  |  |  | 
|---|
|  |  |  | private BasDevpService basDevpService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WrkMastService wrkMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WorkService workService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WrkDetlService wrkDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | private ManLocDetlService manLocDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManLocDetlMapper manLocDetlMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ReportToThirdService reportToThirdService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private InventoryCheckOrderService inventoryCheckOrderService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private InventoryCheckOrderDetlService inventoryCheckOrderDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AdjDetlService adjDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private LocMastMapper locMastMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private DocTypeService docTypeService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderDetlPakinService orderDetlPakinService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderPakinService orderPakinService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderPakoutService orderPakoutService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderDetlPakoutService orderDetlPakoutService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NccJcQilibcBarcodeflowWmsService barcodeflowWmsService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R WarehouseOutPickMergeV1(WarehouseOutPickMergeParam param, Long hostId, Long userId) { | 
|---|
|  |  |  | //判断库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getLocNo())); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | return R.error("该库位不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("P")) { | 
|---|
|  |  |  | return R.error("该库位状态为:" + locMast.getLocSts() + ",不满足拣料途中并板条件!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 创建入库工作主档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | wrkMast.setWrkNo(commonService.getWorkNo(0)); | 
|---|
|  |  |  | wrkMast.setIoTime(now); | 
|---|
|  |  |  | wrkMast.setWrkSts(4L); // 工作状态:入库完成 | 
|---|
|  |  |  | wrkMast.setIoType(8); // 入出库状态:8.拣料途中并板 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级 | 
|---|
|  |  |  | wrkMast.setCrnNo(1); | 
|---|
|  |  |  | wrkMast.setSourceStaNo(1); | 
|---|
|  |  |  | wrkMast.setStaNo(1); | 
|---|
|  |  |  | wrkMast.setLocNo(param.getLocNo()); | 
|---|
|  |  |  | wrkMast.setBarcode(param.getBarcode()); // 托盘码 | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setLinkMis("Y"); | 
|---|
|  |  |  | wrkMast.setCtnType(0); // 容器类型 | 
|---|
|  |  |  | // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setAppeUser(userId); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | wrkMastService.insert(wrkMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (OrderDetl orderDetl : param.getCombMats()) { | 
|---|
|  |  |  | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", orderDetl.getMatnr())); | 
|---|
|  |  |  | if (mat == null) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,物料信息不存在:" + orderDetl.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | wrkDetl.sync(mat); | 
|---|
|  |  |  | wrkDetl.setOrderNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | wrkDetl.setWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | wrkDetl.setIoTime(now); | 
|---|
|  |  |  | wrkDetl.setAnfme(orderDetl.getAnfme()); // 数量 | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setAppeUser(userId); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(userId); | 
|---|
|  |  |  | wrkDetl.setZpallet(wrkMast.getBarcode()); | 
|---|
|  |  |  | wrkDetl.setBatch(orderDetl.getBatch()); | 
|---|
|  |  |  | if (Cools.isEmpty(orderDetl.getBatch())) { | 
|---|
|  |  |  | wrkDetl.setBatch(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrkDetl.setBoxType1(orderDetl.getBoxType1()); | 
|---|
|  |  |  | wrkDetl.setBoxType2(orderDetl.getBoxType2()); | 
|---|
|  |  |  | wrkDetl.setBoxType3(orderDetl.getBoxType3()); | 
|---|
|  |  |  | wrkDetl.setStandby1(orderDetl.getStandby1()); | 
|---|
|  |  |  | wrkDetl.setStandby2(orderDetl.getStandby2()); | 
|---|
|  |  |  | wrkDetl.setStandby3(orderDetl.getStandby3()); | 
|---|
|  |  |  | // 生成工作档明细 | 
|---|
|  |  |  | wrkDetlService.insert(wrkDetl); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(orderDetl.getOrderNo())) { | 
|---|
|  |  |  | OrderPakin order = orderPakinService.selectByNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | if (Cools.isEmpty(order)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3()); | 
|---|
|  |  |  | if (Cools.isEmpty(orderDetlPakin)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (orderDetlPakin.getAnfme() < (orderDetlPakin.getWorkQty() + orderDetl.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("并板数量出错,订单剩余出库数量小于已出库数量与将并板数量之和!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细作业数量 | 
|---|
|  |  |  | if (!orderDetlPakinService.increaseWorkQty(orderDetlPakin.getOrderId(), orderDetlPakin.getMatnr(), orderDetlPakin.getBatch(), orderDetlPakin.getBrand(), | 
|---|
|  |  |  | orderDetlPakin.getStandby1(), orderDetlPakin.getStandby2(), orderDetlPakin.getStandby3(), orderDetlPakin.getBoxType1(), orderDetlPakin.getBoxType2(), orderDetlPakin.getBoxType3(), orderDetl.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("修改单据明细工作数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (order.getSettle() == 1) { | 
|---|
|  |  |  | orderPakinService.updateSettle(order.getId(), 2L, userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R pickConfirm(PickConfirmParam param, Long userId) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() | 
|---|
|  |  |  | .eq("loc_no", param.getLocNo())); | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | return R.error("库位状态不是在库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断库位是否冻结 | 
|---|
|  |  |  | String sourceLocFrozen = locMastMapper.findFirstFrozenLocNo(Collections.singletonList(locMast.getLocNo())); | 
|---|
|  |  |  | if (sourceLocFrozen != null) { | 
|---|
|  |  |  | throw new CoolException(sourceLocFrozen + "库位已被冻结!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() | 
|---|
|  |  |  | .eq("type_no", 104) | 
|---|
|  |  |  | .eq("stn_no", param.getStaNo())); | 
|---|
|  |  |  | if (staDesc == null) { | 
|---|
|  |  |  | return R.error("站点不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetlPakin orderDetlPakin = null; | 
|---|
|  |  |  | //检验传参是否和订单明细匹配 | 
|---|
|  |  |  | for (PickMatParam matParam : param.getList()) { | 
|---|
|  |  |  | orderDetlPakin = orderDetlPakinService.selectItem | 
|---|
|  |  |  | (matParam.getOrderNo(), matParam.getMatnr(), matParam.getBatch(), matParam.getBrand(), | 
|---|
|  |  |  | matParam.getStandby1(), matParam.getStandby2(), matParam.getStandby3(), | 
|---|
|  |  |  | matParam.getBoxType1(), matParam.getBoxType2(), matParam.getBoxType3()); | 
|---|
|  |  |  | if (orderDetlPakin == null) { | 
|---|
|  |  |  | return R.error("物料数据不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //剩余可用数量 | 
|---|
|  |  |  | double count = orderDetlPakin.getAnfme() - orderDetlPakin.getWorkQty(); | 
|---|
|  |  |  | if (matParam.getCount() != count) { | 
|---|
|  |  |  | return R.error("物料数据已过期"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (matParam.getUseCount() > count) { | 
|---|
|  |  |  | return R.error("可用数量不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(104)); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | wrkMast.setWrkNo(workNo); | 
|---|
|  |  |  | wrkMast.setIoTime(now); | 
|---|
|  |  |  | wrkMast.setWrkSts(11L); // 工作状态:101.生成出库 | 
|---|
|  |  |  | wrkMast.setIoType(104); // 入出库状态 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级:13 | 
|---|
|  |  |  | wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 | 
|---|
|  |  |  | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 | 
|---|
|  |  |  | wrkMast.setSourceLocNo(param.getLocNo()); // 源库位 | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("Y"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setBarcode(locMast.getBarcode()); | 
|---|
|  |  |  | wrkMast.setAppeUser(userId); // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setCrnNo(staDesc.getCrnNo()); | 
|---|
|  |  |  | if (!wrkMastService.insert(wrkMast)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,出库库位号:" + param.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成工作档明细 | 
|---|
|  |  |  | for (PickMatParam matParam : param.getList()) { | 
|---|
|  |  |  | Wrapper<Mat> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("status", 1); | 
|---|
|  |  |  | wrapper.eq("matnr", matParam.getMatnr()); | 
|---|
|  |  |  | Mat mat = matService.selectOne(wrapper); | 
|---|
|  |  |  | if (mat == null) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,物料信息不存在:" + matParam.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | wrkDetl.sync(mat); | 
|---|
|  |  |  | wrkDetl.setBatch(matParam.getBatch()); | 
|---|
|  |  |  | wrkDetl.setOrderNo(matParam.getOrderNo()); | 
|---|
|  |  |  | wrkDetl.setWrkNo(workNo); | 
|---|
|  |  |  | wrkDetl.setIoTime(now); | 
|---|
|  |  |  | wrkDetl.setAnfme(matParam.getUseCount()); // 数量 | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setAppeUser(userId); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(userId); | 
|---|
|  |  |  | wrkDetl.setZpallet(wrkMast.getBarcode()); | 
|---|
|  |  |  | if (Cools.isEmpty(matParam.getBatch())) { | 
|---|
|  |  |  | wrkDetl.setBatch(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!wrkDetlService.insert(wrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新订单工作数量 | 
|---|
|  |  |  | orderDetlPakinService.increaseWorkQty(orderDetlPakin.getOrderId(), matParam.getMatnr(), | 
|---|
|  |  |  | matParam.getBatch(), matParam.getBrand(), matParam.getStandby1(), matParam.getStandby2(), matParam.getStandby3(), | 
|---|
|  |  |  | matParam.getBoxType1(), matParam.getBoxType2(), matParam.getBoxType3(), matParam.getUseCount()); | 
|---|
|  |  |  | // 更新工作档状态 | 
|---|
|  |  |  | orderPakinService.updateSettle(orderDetlPakin.getOrderId(), 2L, userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
|---|
|  |  |  | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getLocNo())); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | locMast.setLocSts("P"); | 
|---|
|  |  |  | locMast.setModiUser(userId); | 
|---|
|  |  |  | locMast.setModiTime(now); | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)) { | 
|---|
|  |  |  | throw new CoolException("预约库位状态失败,库位号:" + param.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException(param.getLocNo() + "库位不是在库状态"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R WarehouseOutV1(CombParam combParam, Long hostId, Long userId) { | 
|---|
|  |  |  | //判断库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", combParam.getLocNo())); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | return R.error("该库位不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("P")) { | 
|---|
|  |  |  | return R.error("该库位状态为:" + locMast.getLocSts() + ",不满足并板途中拣选条件!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //查询库存数据 | 
|---|
|  |  |  | for (CombParam.CombMat combMat : combParam.getCombMats()) { | 
|---|
|  |  |  | List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>() | 
|---|
|  |  |  | .eq("loc_no", combParam.getLocNo()) | 
|---|
|  |  |  | .eq("matnr", combMat.getMatnr()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (locDetlList.isEmpty()) { | 
|---|
|  |  |  | return R.error("未查询到库存数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (locDetlList.size() > 1) { | 
|---|
|  |  |  | return R.error("库存数据大于1条,为保证数据准确性,请用正常流程出库!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LocDetl locDetl = locDetlList.get(0); | 
|---|
|  |  |  | if (combMat.getAnfme() > locDetl.getAnfme()) { | 
|---|
|  |  |  | return R.error("拣选数量错误,超出库存数量"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(combMat.getOrderNo())) { | 
|---|
|  |  |  | OrderPakout orderPakout = orderPakoutService.selectByNo(combMat.getOrderNo()); | 
|---|
|  |  |  | if (Cools.isEmpty(orderPakout)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (orderPakout.getSettle() == 1) { | 
|---|
|  |  |  | OrderInAndOutUtil.updateOrder(false, orderPakout.getId(), 2L, 9527L); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(orderPakout.getId(), combMat.getMatnr(), combMat.getBatch(), | 
|---|
|  |  |  | combMat.getBrand(), combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3()); | 
|---|
|  |  |  | if (Cools.isEmpty(orderDetlPakout)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (orderDetlPakout.getAnfme() < (orderDetlPakout.getWorkQty() + combMat.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("拣选数量出错,订单剩余出库数量小于已出库数量与将拣选数量之和!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细作业数量 | 
|---|
|  |  |  | if (!orderDetlPakoutService.increaseWorkQty(orderDetlPakout.getOrderId(), combMat.getMatnr(), combMat.getBatch(), combMat.getBrand(), | 
|---|
|  |  |  | combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3(), combMat.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("修改单据明细工作数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                // 修改订单明细完成数量 | 
|---|
|  |  |  | //                if (!orderDetlPakoutService.increase(orderPakout.getId(),combMat.getMatnr(), combMat.getBatch(), combMat.getBrand(), | 
|---|
|  |  |  | //                        combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3(),combMat.getAnfme())) { | 
|---|
|  |  |  | //                    throw new CoolException("修改单据明细完成数量失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                // 修改订单状态 作业中 ===>> 已完成 | 
|---|
|  |  |  | //                orderPakoutService.checkComplete(combMat.getOrderNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 创建入库工作档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | wrkMast.setWrkNo(commonService.getWorkNo(2)); | 
|---|
|  |  |  | wrkMast.setIoTime(now); | 
|---|
|  |  |  | wrkMast.setWrkSts(14L); // 工作状态:出库完成 | 
|---|
|  |  |  | wrkMast.setIoType(108); // 入出库状态:出库,拣料入库 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级 | 
|---|
|  |  |  | wrkMast.setCrnNo(1); | 
|---|
|  |  |  | wrkMast.setSourceStaNo(1); | 
|---|
|  |  |  | wrkMast.setStaNo(1); | 
|---|
|  |  |  | wrkMast.setSourceLocNo(combParam.getLocNo()); | 
|---|
|  |  |  | wrkMast.setBarcode(combParam.getBarcode()); // 托盘码 | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setLinkMis("Y"); | 
|---|
|  |  |  | wrkMast.setCtnType(0); // 容器类型 | 
|---|
|  |  |  | // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setAppeUser(userId); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | wrkMastService.insert(wrkMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", combMat.getMatnr())); | 
|---|
|  |  |  | if (mat == null) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,物料信息不存在:" + combMat.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | wrkDetl.sync(mat); | 
|---|
|  |  |  | wrkDetl.setOrderNo(combMat.getOrderNo()); | 
|---|
|  |  |  | wrkDetl.setWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | wrkDetl.setIoTime(now); | 
|---|
|  |  |  | wrkDetl.setAnfme(combMat.getAnfme()); // 数量 | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setAppeUser(userId); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(userId); | 
|---|
|  |  |  | wrkDetl.setZpallet(wrkMast.getBarcode()); | 
|---|
|  |  |  | wrkDetl.setBatch(combMat.getBatch()); | 
|---|
|  |  |  | if (Cools.isEmpty(combMat.getBatch())) { | 
|---|
|  |  |  | wrkDetl.setBatch(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrkDetl.setBoxType1(combMat.getBoxType1()); | 
|---|
|  |  |  | wrkDetl.setBoxType2(combMat.getBoxType2()); | 
|---|
|  |  |  | wrkDetl.setBoxType3(combMat.getBoxType3()); | 
|---|
|  |  |  | wrkDetl.setStandby1(combMat.getStandby1()); | 
|---|
|  |  |  | wrkDetl.setStandby2(combMat.getStandby2()); | 
|---|
|  |  |  | wrkDetl.setStandby3(combMat.getStandby3()); | 
|---|
|  |  |  | // 生成工作档明细 | 
|---|
|  |  |  | wrkDetlService.insert(wrkDetl); | 
|---|
|  |  |  | System.out.println("正常"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException("操作数据异常:" + e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("操作成功!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R orderOutListOrder(String barcode, Long userId) { | 
|---|
|  |  |  | ArrayList<WrkMast> wrkMastArrayList = new ArrayList<>(); | 
|---|
|  |  |  | if (Cools.isEmpty(barcode) || barcode.isEmpty()) { | 
|---|
|  |  |  | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .eq("wrk_sts", 14L) | 
|---|
|  |  |  | .eq("io_type", 104)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts); | 
|---|
|  |  |  | List<WrkMast> wrkMasts1 = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .eq("wrk_sts", 14L) | 
|---|
|  |  |  | .eq("io_type", 107)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .like("barcode", barcode) | 
|---|
|  |  |  | .eq("wrk_sts", 199L) | 
|---|
|  |  |  | .eq("io_type", 104)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts); | 
|---|
|  |  |  | List<WrkMast> wrkMasts1 = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .like("barcode", barcode) | 
|---|
|  |  |  | .eq("wrk_sts", 199L) | 
|---|
|  |  |  | .eq("io_type", 107)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(wrkMastArrayList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R orderOutListOrderPick(String barcode, Long userId) { | 
|---|
|  |  |  | ArrayList<WrkMast> wrkMastArrayList = new ArrayList<>(); | 
|---|
|  |  |  | if (Cools.isEmpty(barcode) || barcode.isEmpty()) { | 
|---|
|  |  |  | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .eq("wrk_sts", 199L) | 
|---|
|  |  |  | .eq("io_type", 103)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts); | 
|---|
|  |  |  | List<WrkMast> wrkMasts1 = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .eq("wrk_sts", 199L) | 
|---|
|  |  |  | .eq("io_type", 107)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .like("barcode", barcode) | 
|---|
|  |  |  | .eq("wrk_sts", 199L) | 
|---|
|  |  |  | .eq("io_type", 103) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts); | 
|---|
|  |  |  | List<WrkMast> wrkMasts1 = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .like("barcode", barcode) | 
|---|
|  |  |  | .eq("wrk_sts", 199L) | 
|---|
|  |  |  | .eq("io_type", 107)); | 
|---|
|  |  |  | wrkMastArrayList.addAll(wrkMasts1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(wrkMastArrayList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R pickMats(String matnr, String orderNo) { | 
|---|
|  |  |  | List<DocType> docTypes = docTypeService.selectList(new EntityWrapper<DocType>().like("pakin", "1")); | 
|---|
|  |  |  | ArrayList<Long> typeList = new ArrayList<>(); | 
|---|
|  |  |  | for (DocType docType : docTypes) { | 
|---|
|  |  |  | typeList.add(docType.getDocId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Wrapper<Order> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("status", 1); | 
|---|
|  |  |  | wrapper.in("doc_type", typeList); | 
|---|
|  |  |  | List<Order> orders = orderService.selectList(wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ArrayList<Long> orderIds = new ArrayList<>(); | 
|---|
|  |  |  | for (Order order : orders) { | 
|---|
|  |  |  | orderIds.add(order.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //搜索明细 | 
|---|
|  |  |  | Wrapper<OrderDetl> wrapper1 = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper1.eq("status", 1); | 
|---|
|  |  |  | wrapper1.in("order_id", orderIds); | 
|---|
|  |  |  | wrapper1.orderBy("create_time", false); | 
|---|
|  |  |  | if (!Cools.isEmpty(matnr)) { | 
|---|
|  |  |  | wrapper1.like("matnr", matnr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(orderNo)) { | 
|---|
|  |  |  | wrapper1.like("order_no", orderNo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<OrderDetl> list = orderDetlService.selectList(wrapper1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ArrayList<PickMatParam> maps = new ArrayList<>(); | 
|---|
|  |  |  | for (OrderDetl orderDetl : list) { | 
|---|
|  |  |  | //剩余可用数量 | 
|---|
|  |  |  | double count = MathUtils.subtract(orderDetl.getAnfme(), orderDetl.getWorkQty()); | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PickMatParam matParam = new PickMatParam(); | 
|---|
|  |  |  | matParam.setMatnr(orderDetl.getMatnr()); | 
|---|
|  |  |  | matParam.setBatch(orderDetl.getBatch()); | 
|---|
|  |  |  | matParam.setOrderNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | matParam.setOrderId(orderDetl.getOrderId()); | 
|---|
|  |  |  | matParam.setCount(count); | 
|---|
|  |  |  | matParam.setUseCount(count); | 
|---|
|  |  |  | maps.add(matParam); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(maps); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> codes = param.getCombMats().stream().map(CombParam.CombMat::getTiaoma).collect(Collectors.toList()); | 
|---|
|  |  |  | Set<String> sets = new HashSet<>(); | 
|---|
|  |  |  | if (codes.stream().anyMatch(item -> !sets.add(item))) { | 
|---|
|  |  |  | throw new CoolException("条码重复扫码了"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (param.getCombMats().size() > 1) { | 
|---|
|  |  |  | //            throw new CoolException("请提取一个商品,或者刷新重新组托!"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断是否有相同条码的数据 | 
|---|
|  |  |  | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). | 
|---|
|  |  |  | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "数据正在进行入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); | 
|---|
|  |  |  | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())); | 
|---|
|  |  |  | if (countLoc > 0 || countWrk > 0) { | 
|---|
|  |  |  | throw new CoolException("工作档/库存条码数据已存在===>>" + param.getBarcode()); | 
|---|
|  |  |  | if (param.getBarcode().length() != 8) { | 
|---|
|  |  |  | throw new CoolException("条码长度不是8位===>>" + param.getBarcode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (param.getCombMats().size() > 1) { | 
|---|
|  |  |  | //            throw new CoolException("不允许混料===>>" + param.getBarcode()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | if (countLoc > 0 || countWrk > 0 || countwait > 0) { | 
|---|
|  |  |  | throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 无单组托 | 
|---|
|  |  |  | if (Cools.isEmpty(param.getOrderNo())) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getCombMats().get(0).getOrderNo())) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成入库通知档 | 
|---|
|  |  |  | List<DetlDto> detlDtos = new ArrayList<>(); | 
|---|
|  |  |  | param.getCombMats().forEach(elem -> { | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), | 
|---|
|  |  |  | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); | 
|---|
|  |  |  | detlDto.setWeight(elem.getWeight()); | 
|---|
|  |  |  | detlDto.setCstateid(elem.getCstateid()); | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); | 
|---|
|  |  |  | DetlDto one = DetlDto.findDto(detlDtos, detlDto); | 
|---|
|  |  |  | assert one != null; | 
|---|
|  |  |  | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|---|
|  |  |  | one.setWeight(one.getWeight() + detlDto.getWeight()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | detlDtos.add(detlDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WaitPakin waitPakin = new WaitPakin(); | 
|---|
|  |  |  | waitPakin.sync(mat); | 
|---|
|  |  |  | waitPakin.setWeight(detlDto.getWeight()); | 
|---|
|  |  |  | waitPakin.setBatch(detlDto.getBatch()); | 
|---|
|  |  |  | waitPakin.setZpallet(param.getBarcode());   // 托盘码 | 
|---|
|  |  |  | waitPakin.setIoStatus("N");     // 入出状态 | 
|---|
|  |  |  | 
|---|
|  |  |  | waitPakin.setAppeTime(now); | 
|---|
|  |  |  | waitPakin.setModiUser(userId); | 
|---|
|  |  |  | waitPakin.setModiTime(now); | 
|---|
|  |  |  | waitPakin.setBoxType1(detlDto.getBoxType1()); | 
|---|
|  |  |  | waitPakin.setBoxType2(detlDto.getBoxType2()); | 
|---|
|  |  |  | waitPakin.setBoxType3(detlDto.getBoxType3()); | 
|---|
|  |  |  | waitPakin.setStandby1(detlDto.getStandby1()); | 
|---|
|  |  |  | waitPakin.setStandby2(detlDto.getStandby2()); | 
|---|
|  |  |  | waitPakin.setStandby3(detlDto.getStandby3()); | 
|---|
|  |  |  | waitPakin.setTkFlag(param.getTkFlag()); | 
|---|
|  |  |  | waitPakin.setCstateid(detlDto.getCstateid()); | 
|---|
|  |  |  | if (!waitPakinService.insert(waitPakin)) { | 
|---|
|  |  |  | throw new CoolException("保存入库通知档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 关联组托 | 
|---|
|  |  |  | // 关联组托 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Order order = orderService.selectByNo(param.getOrderNo()); | 
|---|
|  |  |  | if (order.getSettle() > 2) { | 
|---|
|  |  |  | throw new CoolException("单据编号已过期"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            Order order = orderService.selectByNo(param.getOrderNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成入库通知档 | 
|---|
|  |  |  | List<DetlDto> detlDtos = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | param.getCombMats().forEach(elem -> { | 
|---|
|  |  |  | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, elem.getOrderNo()); | 
|---|
|  |  |  | if (Cools.isEmpty(order)) { | 
|---|
|  |  |  | throw new CoolException("单据编号不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (order.getSettle() > 2) { | 
|---|
|  |  |  | throw new CoolException("单据编号已作业完成"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<WaitPakin> waitPakinList = waitPakinService.selectList(new EntityWrapper<WaitPakin>() | 
|---|
|  |  |  | .eq("matnr", elem.getMatnr()) | 
|---|
|  |  |  | .eq("batch", elem.getBatch()) | 
|---|
|  |  |  | .eq("order_no", elem.getOrderNo()) | 
|---|
|  |  |  | .eq("anfme", elem.getAnfme()) | 
|---|
|  |  |  | .eq("standby1", elem.getStandby1()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (!waitPakinList.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("该订单物料已经组托!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 订单明细数量校验 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); | 
|---|
|  |  |  | OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), | 
|---|
|  |  |  | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3()); | 
|---|
|  |  |  | if (elem.getAnfme() > orderDetl.getEnableQty()) { | 
|---|
|  |  |  | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|---|
|  |  |  | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法,已经超过单据入库数量"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单作业数量 | 
|---|
|  |  |  | if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("修改单据作业数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); | 
|---|
|  |  |  | //                if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { | 
|---|
|  |  |  | //                    throw new CoolException("修改单据作业数量失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), | 
|---|
|  |  |  | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), | 
|---|
|  |  |  | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); | 
|---|
|  |  |  | detlDto.setOrderNo(elem.getOrderNo()); | 
|---|
|  |  |  | detlDto.setWeight(elem.getWeight()); | 
|---|
|  |  |  | detlDto.setCstateid(elem.getCstateid()); | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); | 
|---|
|  |  |  | DetlDto one = DetlDto.findDto(detlDtos, detlDto); | 
|---|
|  |  |  | assert one != null; | 
|---|
|  |  |  | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|---|
|  |  |  | one.setWeight(one.getWeight() + detlDto.getWeight()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | detlDtos.add(detlDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WaitPakin waitPakin = new WaitPakin(); | 
|---|
|  |  |  | waitPakin.sync(mat); | 
|---|
|  |  |  | waitPakin.setOrderNo(order.getOrderNo());   // 单据编号 | 
|---|
|  |  |  | waitPakin.setOrderNo(detlDto.getOrderNo());   // 单据编号 | 
|---|
|  |  |  | waitPakin.setBatch(detlDto.getBatch());     // 序列码 | 
|---|
|  |  |  | waitPakin.setZpallet(param.getBarcode());   // 托盘码 | 
|---|
|  |  |  | waitPakin.setIoStatus("N");     // 入出状态 | 
|---|
|  |  |  | 
|---|
|  |  |  | waitPakin.setAppeTime(now); | 
|---|
|  |  |  | waitPakin.setModiUser(userId); | 
|---|
|  |  |  | waitPakin.setModiTime(now); | 
|---|
|  |  |  | waitPakin.setBoxType1(detlDto.getBoxType1()); | 
|---|
|  |  |  | waitPakin.setBoxType2(detlDto.getBoxType2()); | 
|---|
|  |  |  | waitPakin.setBoxType3(detlDto.getBoxType3()); | 
|---|
|  |  |  | waitPakin.setStandby1(detlDto.getStandby1()); | 
|---|
|  |  |  | waitPakin.setStandby2(detlDto.getStandby2()); | 
|---|
|  |  |  | waitPakin.setStandby3(detlDto.getStandby3()); | 
|---|
|  |  |  | waitPakin.setWeight(detlDto.getWeight()); | 
|---|
|  |  |  | waitPakin.setCstateid(detlDto.getCstateid()); | 
|---|
|  |  |  | if (!waitPakinService.insert(waitPakin)) { | 
|---|
|  |  |  | throw new CoolException("保存入库通知档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderService.updateSettle(order.getId(), 2L, userId); | 
|---|
|  |  |  | //            orderService.updateSettle(order.getId(), 2L, userId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void combCancel(CombCancelParam param, Long userId) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode())) { | 
|---|
|  |  |  | throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<WaitPakin> waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>(). | 
|---|
|  |  |  | eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | if (waitPakins.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("托盘未组托"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (WaitPakin waitPakin : waitPakins) { | 
|---|
|  |  |  | if (!Cools.isEmpty(waitPakin.getOrderNo())) { | 
|---|
|  |  |  | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, waitPakin.getOrderNo()); | 
|---|
|  |  |  | if (Cools.isEmpty(order)) { | 
|---|
|  |  |  | throw new CoolException("单据编号不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (order.getSettle() > 2) { | 
|---|
|  |  |  | throw new CoolException("单据编号已作业完成"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 订单明细数量校验 | 
|---|
|  |  |  | OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getBrand(), waitPakin.getStandby1(), waitPakin.getStandby2(), waitPakin.getStandby3(), | 
|---|
|  |  |  | waitPakin.getBoxType1(), waitPakin.getBoxType2(), waitPakin.getBoxType3()); | 
|---|
|  |  |  | if (orderDetlPakin == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double workQty = orderDetlPakin.getWorkQty(); | 
|---|
|  |  |  | BigDecimal workQtyDecimal = new BigDecimal(workQty); | 
|---|
|  |  |  | workQtyDecimal = workQtyDecimal.subtract(BigDecimal.valueOf(waitPakin.getAnfme())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | double newWorkQty = workQtyDecimal.doubleValue(); | 
|---|
|  |  |  | if (newWorkQty <= 0) { | 
|---|
|  |  |  | newWorkQty = 0D; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderDetlPakin.setWorkQty(newWorkQty); | 
|---|
|  |  |  | orderDetlPakinService.updateById(orderDetlPakin); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | waitPakinService.delete(new EntityWrapper<WaitPakin>() | 
|---|
|  |  |  | .eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 商品上架 | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onSale(CombParam param) { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 获取库位号 | 
|---|
|  |  |  | String locno = param.getLocno(); | 
|---|
|  |  |  | String locno = param.getLocNo(); | 
|---|
|  |  |  | Node node = nodeService.selectByUuid(locno); | 
|---|
|  |  |  | if (Cools.isEmpty(node)) { | 
|---|
|  |  |  | throw new CoolException(param.getLocno() + ":库位不存在"); | 
|---|
|  |  |  | throw new CoolException(param.getLocNo() + ":库位不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取商品列表 | 
|---|
|  |  |  | for(CombParam.CombMat combMat : param.getCombMats()){ | 
|---|
|  |  |  | for (CombParam.CombMat combMat : param.getCombMats()) { | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(combMat.getMatnr()); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)){ | 
|---|
|  |  |  | if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | throw new CoolException(combMat.getMatnr() + ":商品档案不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme()==0){ | 
|---|
|  |  |  | if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme() == 0) { | 
|---|
|  |  |  | throw new CoolException(combMat.getMatnr() + ":商品数量有误!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Cools.isEmpty(combMat.getBatch())){ | 
|---|
|  |  |  | throw new CoolException(combMat.getMatnr() + ":商品批号有误!"); | 
|---|
|  |  |  | if (Cools.isEmpty(combMat.getBatch())) { | 
|---|
|  |  |  | //                throw new CoolException(combMat.getMatnr() + ":商品批号有误!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ManLocDetl manLocDetl = new ManLocDetl(); | 
|---|
|  |  |  | manLocDetl.setLocNo(locno); | 
|---|
|  |  |  | manLocDetl.setNodeId(node.getId()); | 
|---|
|  |  |  | manLocDetl.setMaktx(mat.getMaktx()); | 
|---|
|  |  |  | manLocDetl.setMatnr(mat.getMatnr()); | 
|---|
|  |  |  | manLocDetl.setBatch(combMat.getBatch()); | 
|---|
|  |  |  | manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch()); | 
|---|
|  |  |  | manLocDetl.setAnfme(combMat.getAnfme()); | 
|---|
|  |  |  | manLocDetl.setModiTime(now); | 
|---|
|  |  |  | if (!manLocDetlService.insert(manLocDetl)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 商品下架 | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void offSale(OffSaleParam offSaleParam) { | 
|---|
|  |  |  | ManLocDetl manLocDetl = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); | 
|---|
|  |  |  | if (Cools.isEmpty(manLocDetl)){ | 
|---|
|  |  |  | if (Cools.isEmpty(manLocDetl)) { | 
|---|
|  |  |  | throw new CoolException("无此商品!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | double anfme = manLocDetl.getAnfme() - offSaleParam.getAnfme(); | 
|---|
|  |  |  | if (anfme < 0) { | 
|---|
|  |  |  | throw new CoolException("商品库存不足!"); | 
|---|
|  |  |  | } else if (anfme == 0){ | 
|---|
|  |  |  | } else if (anfme == 0) { | 
|---|
|  |  |  | manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manLocDetlMapper.updateAnfme0(anfme,manLocDetl.getNodeId()); | 
|---|
|  |  |  | manLocDetlMapper.updateAnfme0(anfme, manLocDetl.getNodeId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 查找商品 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void adjust(MobileAdjustParam param, Long userId) { | 
|---|
|  |  |  | BasDevp basDevp = basDevpService.selectById(param.getStaNo()); | 
|---|
|  |  |  | if (null == basDevp || basDevp.getWrkNo() == null) { | 
|---|
|  |  |  | throw new CoolException(param.getStaNo() + "盘点站无效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!param.getWrkNo().equals(basDevp.getWrkNo())) { | 
|---|
|  |  |  | throw new CoolException(param.getStaNo() + "盘点站更新,请重新检索"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectById(param.getWrkNo()); | 
|---|
|  |  |  | //        BasDevp basDevp = basDevpService.selectById(param.getStaNo()); | 
|---|
|  |  |  | //        if (null == basDevp || basDevp.getWrkNo() == null) { | 
|---|
|  |  |  | //            throw new CoolException(param.getStaNo() + "盘点站无效"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        if (!param.getWrkNo().equals(basDevp.getWrkNo())) { | 
|---|
|  |  |  | //            throw new CoolException(param.getStaNo() + "盘点站更新,请重新检索"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode()); | 
|---|
|  |  |  | if (wrkMast.getWrkSts() < 10) { | 
|---|
|  |  |  | throw new CoolException("盘点无效,任务已盘点再入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<WrkDetl> list = param.getWrkDetls(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<WrkDetl> list = JSON.parseArray(JSON.toJSONString(param.getWrkDetls()), WrkDetl.class); | 
|---|
|  |  |  | // 修改数量 | 
|---|
|  |  |  | Iterator<WrkDetl> iterator = wrkDetls.iterator(); | 
|---|
|  |  |  | while (iterator.hasNext()) { | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号修改数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果已经拣料回库,就需要取locNo字段 | 
|---|
|  |  |  | iterator.remove(); | 
|---|
|  |  |  | iterator1.remove(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 添加明细 | 
|---|
|  |  |  | for (WrkDetl wrkDetl : list) { | 
|---|
|  |  |  | if (wrkDetl.getAnfme() == 0.0D) { continue; } | 
|---|
|  |  |  | if (wrkDetl.getAnfme() == 0.0D) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // todo 盘点记录、保存调整记录 | 
|---|
|  |  |  | String orderNo = wrkDetl.getOrderNo(); | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<WrkDetl> paramWrkDetls = JSON.parseArray(JSON.toJSONString(param.getWrkDetls()), WrkDetl.class); | 
|---|
|  |  |  | for (WrkDetl wrkDetl : paramWrkDetls) { | 
|---|
|  |  |  | String locNo = Cools.isEmpty(wrkMast.getLocNo()) ? wrkMast.getSourceLocNo() : wrkMast.getLocNo(); | 
|---|
|  |  |  | List<InventoryCheckOrderDetl> checkOrderDetls = inventoryCheckOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>() | 
|---|
|  |  |  | .eq("loc_no", locNo) | 
|---|
|  |  |  | .eq("area", wrkDetl.getWrkNo()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (InventoryCheckOrderDetl checkOrderDetl : checkOrderDetls) { | 
|---|
|  |  |  | if (wrkDetl.getMatnr().equals(checkOrderDetl.getMatnr()) && Cools.eq(wrkDetl.getBatch(), checkOrderDetl.getBatch())) { | 
|---|
|  |  |  | checkOrderDetl.setCheckAnfme(wrkDetl.getAnfme()); | 
|---|
|  |  |  | checkOrderDetl.setStatus("2"); | 
|---|
|  |  |  | inventoryCheckOrderDetlService.updateById(checkOrderDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改盘点任务主档状态 | 
|---|
|  |  |  | wrkMast.setFullPlt(wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()).size() != 0?"Y":"N"); | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | if (!wrkMastService.updateById(wrkMast)) { | 
|---|
|  |  |  | throw new CoolException("修改盘点任务主档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void packComb(CombParam param, Long userId) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断是否有相同条码的数据 | 
|---|
|  |  |  | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). | 
|---|
|  |  |  | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "数据正在进行入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | boolean packDown = Parameter.get().getPackDown().equals("true"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 无单组托 | 
|---|
|  |  |  | if (Cools.isEmpty(param.getOrderNo())) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成入库通知档 | 
|---|
|  |  |  | List<DetlDto> detlDtos = new ArrayList<>(); | 
|---|
|  |  |  | param.getCombMats().forEach(elem -> { | 
|---|
|  |  |  | // 打包上线数据校验 | 
|---|
|  |  |  | if (packDown) { | 
|---|
|  |  |  | Pack pack = packService.selectByBarcode(elem.getMatnr()); | 
|---|
|  |  |  | if (pack == null) { | 
|---|
|  |  |  | throw new CoolException(elem.getMatnr() + "条码冗余,请检查!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pack.getSettle() != 1) { | 
|---|
|  |  |  | throw new CoolException(elem.getMatnr() + "条码已下线,请检查!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Mat analyse = MatUtils.analyseMat(elem.getMatnr()); | 
|---|
|  |  |  | // 条码、物料代码、序列号、数量 | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(), analyse.getBarcode(), elem.getAnfme()); | 
|---|
|  |  |  | //                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); | 
|---|
|  |  |  | assert one != null; | 
|---|
|  |  |  | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | detlDtos.add(detlDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (packDown) { | 
|---|
|  |  |  | MesCombParam mesCombParam = new MesCombParam(); | 
|---|
|  |  |  | mesCombParam.setZpallet(param.getBarcode()); | 
|---|
|  |  |  | mesCombParam.setPakinTime(DateUtils.convert(now)); | 
|---|
|  |  |  | mesCombParam.setLgort("5008"); | 
|---|
|  |  |  | mesCombParam.setPlantCode("5000"); | 
|---|
|  |  |  | mesCombParam.setFromCode("5012-20"); | 
|---|
|  |  |  | mesCombParam.setStationCode("JJQ-PFZPDB-XX"); | 
|---|
|  |  |  | for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  | mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String response = ""; | 
|---|
|  |  |  | boolean success = false; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(MesConstant.URL) | 
|---|
|  |  |  | .setPath(MesConstant.PACK_DOWN_URL) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(mesCombParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | success = true; | 
|---|
|  |  |  | } else if (jsonObject.getInteger("code").equals(500)) { | 
|---|
|  |  |  | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); | 
|---|
|  |  |  | throw new CoolException(jsonObject.getString("msg")); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); | 
|---|
|  |  |  | throw new CoolException("上报mes系统失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("fail", e); | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 保存接口日志 | 
|---|
|  |  |  | apiLogService.save( | 
|---|
|  |  |  | "打包下线帮托上报", | 
|---|
|  |  |  | MesConstant.URL + MesConstant.PACK_DOWN_URL, | 
|---|
|  |  |  | null, | 
|---|
|  |  |  | "127.0.0.1", | 
|---|
|  |  |  | JSON.toJSONString(mesCombParam), | 
|---|
|  |  |  | response, | 
|---|
|  |  |  | success | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } catch (Exception e) { log.error("", e); } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成入库单据 | 
|---|
|  |  |  | String orderNo = "PACK" + snowflakeIdWorker.nextId(); | 
|---|
|  |  |  | OpenOrderPakinParam openParam = new OpenOrderPakinParam(); | 
|---|
|  |  |  | openParam.setOrderNo(orderNo); | 
|---|
|  |  |  | openParam.setOrderTime(DateUtils.convert(now)); | 
|---|
|  |  |  | openParam.setOrderType("打包入库单"); | 
|---|
|  |  |  | openParam.setOrderDetails(detlDtos); | 
|---|
|  |  |  | openService.pakinOrderCreate(openParam); | 
|---|
|  |  |  | Order order = orderService.selectByNo(orderNo); | 
|---|
|  |  |  | if (null == order) { | 
|---|
|  |  |  | throw new CoolException("生成单据失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!orderService.updateSettle(order.getId(), 2L, userId)) { | 
|---|
|  |  |  | throw new CoolException("修改单据状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成入库通知档 | 
|---|
|  |  |  | for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改作业数量 ---------------------------------------- | 
|---|
|  |  |  | // 订单明细数量校验 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch()); | 
|---|
|  |  |  | if (detlDto.getAnfme() > orderDetl.getEnableQty()) { | 
|---|
|  |  |  | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单作业数量 | 
|---|
|  |  |  | if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("修改单据作业数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 保存入库通知档 | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WaitPakin waitPakin = new WaitPakin(); | 
|---|
|  |  |  | waitPakin.sync(mat); | 
|---|
|  |  |  | waitPakin.setOrderNo(orderNo); | 
|---|
|  |  |  | waitPakin.setBatch(detlDto.getBatch()); | 
|---|
|  |  |  | waitPakin.setZpallet(param.getBarcode());   // 托盘码 | 
|---|
|  |  |  | waitPakin.setIoStatus("N");     // 入出状态 | 
|---|
|  |  |  | waitPakin.setAnfme(detlDto.getAnfme());  // 数量 | 
|---|
|  |  |  | waitPakin.setStatus("Y");    // 状态 | 
|---|
|  |  |  | waitPakin.setAppeUser(userId); | 
|---|
|  |  |  | waitPakin.setAppeTime(now); | 
|---|
|  |  |  | waitPakin.setModiUser(userId); | 
|---|
|  |  |  | waitPakin.setModiTime(now); | 
|---|
|  |  |  | if (!waitPakinService.insert(waitPakin)) { | 
|---|
|  |  |  | throw new CoolException("保存入库通知档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改打包数据状态 | 
|---|
|  |  |  | Pack pack = packService.selectByBarcode(detlDto.getOrderNo()); | 
|---|
|  |  |  | pack.setSettle(2L); | 
|---|
|  |  |  | pack.setUpdateTime(now); | 
|---|
|  |  |  | pack.setUpdateBy(userId); | 
|---|
|  |  |  | if (!packService.updateById(pack)) { | 
|---|
|  |  |  | throw new CoolException("修改打包数据异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | //            throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        // 判断是否有相同条码的数据 | 
|---|
|  |  |  | //        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). | 
|---|
|  |  |  | //                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { | 
|---|
|  |  |  | //            throw new CoolException(param.getBarcode() + "数据正在进行入库"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        Date now = new Date(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        boolean packDown = Parameter.get().getPackDown().equals("true"); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 无单组托 | 
|---|
|  |  |  | //        if (Cools.isEmpty(param.getOrderNo())) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            // 生成入库通知档 | 
|---|
|  |  |  | //            List<DetlDto> detlDtos = new ArrayList<>(); | 
|---|
|  |  |  | //            param.getCombMats().forEach(elem -> { | 
|---|
|  |  |  | //                // 打包上线数据校验 | 
|---|
|  |  |  | //                if (packDown) { | 
|---|
|  |  |  | //                    Pack pack = packService.selectByBarcode(elem.getMatnr()); | 
|---|
|  |  |  | //                    if (pack == null) { | 
|---|
|  |  |  | //                        throw new CoolException(elem.getMatnr() + "条码冗余,请检查!"); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    if (pack.getSettle() != 1) { | 
|---|
|  |  |  | //                        throw new CoolException(elem.getMatnr() + "条码已下线,请检查!"); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                Mat analyse = MatUtils.analyseMat(elem.getMatnr()); | 
|---|
|  |  |  | //                // 条码、物料代码、序列号、数量 | 
|---|
|  |  |  | //                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(),analyse.getBrand(),elem.getStandby1(),elem.getStandby2(),elem.getStandby3(), | 
|---|
|  |  |  | //                        elem.getBoxType1(),elem.getBoxType2(),elem.getBoxType3(),  elem.getAnfme()); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | ////                DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(), analyse.getBarcode(), elem.getAnfme()); | 
|---|
|  |  |  | ////                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); | 
|---|
|  |  |  | //                if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | //                    DetlDto one = DetlDto.findDto(detlDtos, detlDto); | 
|---|
|  |  |  | //                    assert one != null; | 
|---|
|  |  |  | //                    one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    detlDtos.add(detlDto); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            }); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            if (packDown) { | 
|---|
|  |  |  | //                MesCombParam mesCombParam = new MesCombParam(); | 
|---|
|  |  |  | //                mesCombParam.setZpallet(param.getBarcode()); | 
|---|
|  |  |  | //                mesCombParam.setPakinTime(DateUtils.convert(now)); | 
|---|
|  |  |  | //                mesCombParam.setLgort("5008"); | 
|---|
|  |  |  | //                mesCombParam.setPlantCode("5000"); | 
|---|
|  |  |  | //                mesCombParam.setFromCode("5012-20"); | 
|---|
|  |  |  | //                mesCombParam.setStationCode("JJQ-PFZPDB-XX"); | 
|---|
|  |  |  | //                for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  | //                    mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme())); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                String response = ""; | 
|---|
|  |  |  | //                boolean success = false; | 
|---|
|  |  |  | //                try { | 
|---|
|  |  |  | //                    response = new HttpHandler.Builder() | 
|---|
|  |  |  | //                            .setUri(MesConstant.URL) | 
|---|
|  |  |  | //                            .setPath(MesConstant.PACK_DOWN_URL) | 
|---|
|  |  |  | //                            .setJson(JSON.toJSONString(mesCombParam)) | 
|---|
|  |  |  | //                            .build() | 
|---|
|  |  |  | //                            .doPost(); | 
|---|
|  |  |  | //                    JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | //                    if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | //                        success = true; | 
|---|
|  |  |  | //                    } else if (jsonObject.getInteger("code").equals(500)) { | 
|---|
|  |  |  | //                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); | 
|---|
|  |  |  | //                        throw new CoolException(jsonObject.getString("msg")); | 
|---|
|  |  |  | //                    } else { | 
|---|
|  |  |  | //                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); | 
|---|
|  |  |  | //                        throw new CoolException("上报mes系统失败"); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } catch (Exception e) { | 
|---|
|  |  |  | //                    log.error("fail", e); | 
|---|
|  |  |  | //                    throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | //                } finally { | 
|---|
|  |  |  | //                    try { | 
|---|
|  |  |  | //                        // 保存接口日志 | 
|---|
|  |  |  | //                        apiLogService.save( | 
|---|
|  |  |  | //                                "打包下线帮托上报", | 
|---|
|  |  |  | //                                MesConstant.URL + MesConstant.PACK_DOWN_URL, | 
|---|
|  |  |  | //                                null, | 
|---|
|  |  |  | //                                "127.0.0.1", | 
|---|
|  |  |  | //                                JSON.toJSONString(mesCombParam), | 
|---|
|  |  |  | //                                response, | 
|---|
|  |  |  | //                                success | 
|---|
|  |  |  | //                        ); | 
|---|
|  |  |  | //                    } catch (Exception e) { log.error("", e); } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            // 生成入库单据 | 
|---|
|  |  |  | //            String orderNo = "PACK" + snowflakeIdWorker.nextId(); | 
|---|
|  |  |  | //            OpenOrderPakinParam openParam = new OpenOrderPakinParam(); | 
|---|
|  |  |  | //            openParam.setOrderNo(orderNo); | 
|---|
|  |  |  | //            openParam.setOrderTime(DateUtils.convert(now)); | 
|---|
|  |  |  | //            openParam.setOrderType("打包入库单"); | 
|---|
|  |  |  | //            openParam.setOrderDetails(detlDtos); | 
|---|
|  |  |  | //            openService.pakinOrderCreate(openParam); | 
|---|
|  |  |  | ////            Order order = orderService.selectByNo(orderNo); | 
|---|
|  |  |  | //            Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo()); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            if (null == order) { | 
|---|
|  |  |  | //                throw new CoolException("生成单据失败"); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | ////            if (!orderService.updateSettle(order.getId(), 2L, userId)) { | 
|---|
|  |  |  | ////                throw new CoolException("修改单据状态失败"); | 
|---|
|  |  |  | ////            } | 
|---|
|  |  |  | //            OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            // 生成入库通知档 | 
|---|
|  |  |  | //            for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                // 修改作业数量 ---------------------------------------- | 
|---|
|  |  |  | //                // 订单明细数量校验 | 
|---|
|  |  |  | ////                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch()); | 
|---|
|  |  |  | //                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(),detlDto.getBrand(),detlDto.getStandby1(),detlDto.getStandby2(),detlDto.getStandby3() | 
|---|
|  |  |  | //                        ,detlDto.getBoxType1(),detlDto.getBoxType2(),detlDto.getBoxType3()); | 
|---|
|  |  |  | //                if (detlDto.getAnfme() > orderDetl.getEnableQty()) { | 
|---|
|  |  |  | //                    throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                // 修改订单作业数量 | 
|---|
|  |  |  | ////                if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { | 
|---|
|  |  |  | ////                    throw new CoolException("修改单据作业数量失败"); | 
|---|
|  |  |  | ////                } | 
|---|
|  |  |  | //                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE,order.getId(), detlDto.getMatnr(), detlDto.getBatch(),detlDto.getBrand(),detlDto.getStandby1(),detlDto.getStandby2(),detlDto.getStandby3() | 
|---|
|  |  |  | //                        ,detlDto.getBoxType1(),detlDto.getBoxType2(),detlDto.getBoxType3(), detlDto.getAnfme()); | 
|---|
|  |  |  | //                // 保存入库通知档 | 
|---|
|  |  |  | //                Mat mat = matService.selectByMatnr(detlDto.getMatnr()); | 
|---|
|  |  |  | //                if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | //                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                WaitPakin waitPakin = new WaitPakin(); | 
|---|
|  |  |  | //                waitPakin.sync(mat); | 
|---|
|  |  |  | //                waitPakin.setOrderNo(orderNo); | 
|---|
|  |  |  | //                waitPakin.setBatch(detlDto.getBatch()); | 
|---|
|  |  |  | //                waitPakin.setZpallet(param.getBarcode());   // 托盘码 | 
|---|
|  |  |  | //                waitPakin.setIoStatus("N");     // 入出状态 | 
|---|
|  |  |  | //                waitPakin.setAnfme(detlDto.getAnfme());  // 数量 | 
|---|
|  |  |  | //                waitPakin.setStatus("Y");    // 状态 | 
|---|
|  |  |  | //                waitPakin.setAppeUser(userId); | 
|---|
|  |  |  | //                waitPakin.setAppeTime(now); | 
|---|
|  |  |  | //                waitPakin.setModiUser(userId); | 
|---|
|  |  |  | //                waitPakin.setModiTime(now); | 
|---|
|  |  |  | //                if (!waitPakinService.insert(waitPakin)) { | 
|---|
|  |  |  | //                    throw new CoolException("保存入库通知档失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                // 修改打包数据状态 | 
|---|
|  |  |  | //                Pack pack = packService.selectByBarcode(detlDto.getOrderNo()); | 
|---|
|  |  |  | //                pack.setSettle(2L); | 
|---|
|  |  |  | //                pack.setUpdateTime(now); | 
|---|
|  |  |  | //                pack.setUpdateBy(userId); | 
|---|
|  |  |  | //                if (!packService.updateById(pack)) { | 
|---|
|  |  |  | //                    throw new CoolException("修改打包数据异常"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BasDevp sta = basDevpService.checkSiteStatus(staNo); | 
|---|
|  |  |  | //根据订单号生成出库任务工作档 | 
|---|
|  |  |  | Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo)); | 
|---|
|  |  |  | if (order.getSettle() != 1 && order.getSettle() != 2){ | 
|---|
|  |  |  | Order order = OrderInAndOutUtil.selectByNo(Boolean.FALSE, orderNo); | 
|---|
|  |  |  | //        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo)); | 
|---|
|  |  |  | if (order.getSettle() != 1 && order.getSettle() != 2) { | 
|---|
|  |  |  | throw new CoolException("该订单已处理"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); | 
|---|
|  |  |  | //        List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); | 
|---|
|  |  |  | List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(Boolean.FALSE, order.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | for(OrderDetl orderDetl : orderDetls){ | 
|---|
|  |  |  | for (OrderDetl orderDetl : orderDetls) { | 
|---|
|  |  |  | //查询所有库位状态为F的库位信息 | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),null,null); | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null); | 
|---|
|  |  |  | if (locDetls.size() == 0) { | 
|---|
|  |  |  | throw new CoolException("库存中没有该物料"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(LocDetl locDetl : locDetls){ | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | //如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() | 
|---|
|  |  |  | .eq("loc_no", locDetl.getLocNo())); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>() | 
|---|
|  |  |  | .eq("crn_no", locMast.getCrnNo())); | 
|---|
|  |  |  | if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")){ | 
|---|
|  |  |  | if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //可出库数量 = 订单数量 - 作业中数量 | 
|---|
|  |  |  | Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty(); | 
|---|
|  |  |  | if(outQty <= 0){ | 
|---|
|  |  |  | Double outQty = MathUtils.subtract(orderDetl.getAnfme(), orderDetl.getWorkQty()); | 
|---|
|  |  |  | if (outQty <= 0) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断入出库类型:101.全板出库 or 103.拣料出库 | 
|---|
|  |  |  | 
|---|
|  |  |  | order.setSettle(2L); | 
|---|
|  |  |  | order.setUpdateBy(userId); | 
|---|
|  |  |  | order.setUpdateTime(now); | 
|---|
|  |  |  | if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){ | 
|---|
|  |  |  | throw new CoolException("更新订单状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){ | 
|---|
|  |  |  | //                    throw new CoolException("更新订单状态失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(), order.getId(), 2L, userId); | 
|---|
|  |  |  | orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty); | 
|---|
|  |  |  | orderDetl.setUpdateBy(userId); | 
|---|
|  |  |  | orderDetl.setUpdateTime(now); | 
|---|
|  |  |  | Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo) | 
|---|
|  |  |  | .eq("matnr",orderDetl.getMatnr()); | 
|---|
|  |  |  | if(!Cools.isEmpty(orderDetl.getBatch())){ | 
|---|
|  |  |  | .eq("matnr", orderDetl.getMatnr()); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderDetl.getBatch())) { | 
|---|
|  |  |  | wrapper.eq("batch", orderDetl.getBatch()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!orderDetlService.update(orderDetl, wrapper)){ | 
|---|
|  |  |  | throw new CoolException("更新订单明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                if(!orderDetlService.update(orderDetl, wrapper)){ | 
|---|
|  |  |  | //                    throw new CoolException("更新订单明细失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | OrderInAndOutUtil.updateOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException(locDetl.getLocNo() + "库位不是在库状态"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void checkOutSubmit(Integer orderId, Long userId) { | 
|---|
|  |  |  | InventoryCheckOrder inventoryCheckOrder = inventoryCheckOrderService.selectOne(new EntityWrapper<InventoryCheckOrder>() | 
|---|
|  |  |  | .eq("id", orderId)); | 
|---|
|  |  |  | if (inventoryCheckOrder == null) { | 
|---|
|  |  |  | throw new CoolException("盘点单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!inventoryCheckOrder.getStatus().equals("1")) { | 
|---|
|  |  |  | throw new CoolException("盘点单状态已上报"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<InventoryCheckOrderDetl> checkOrderDetlList = inventoryCheckOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>() | 
|---|
|  |  |  | .eq("order_no", inventoryCheckOrder.getOrderNo()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (checkOrderDetlList.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("盘点单无物料明细"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | boolean complete = true; | 
|---|
|  |  |  | for (InventoryCheckOrderDetl checkOrderDetl : checkOrderDetlList) { | 
|---|
|  |  |  | if (!checkOrderDetl.getStatus().equals("2")) { | 
|---|
|  |  |  | complete = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (complete) { | 
|---|
|  |  |  | boolean result = reportToThirdService.reportCheckOrder(checkOrderDetlList); | 
|---|
|  |  |  | if (!result) { | 
|---|
|  |  |  | throw new CoolException("盘点单上报失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new CoolException("盘点未完成无法上报"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void toOutSta(PalletToOutStaParam param, Long userId) { | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode()); | 
|---|
|  |  |  | if (wrkMast == null) { | 
|---|
|  |  |  | throw new CoolException("工作档不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (wrkMast.getIoType() != 103) { | 
|---|
|  |  |  | throw new CoolException("工作档类型不是拣料出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (wrkMast.getWrkSts() != 14) { | 
|---|
|  |  |  | throw new CoolException("工作状态未处于已出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String response = ""; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("wrkNo", wrkMast.getWrkNo()); | 
|---|
|  |  |  | map.put("sourceStaNo", wrkMast.getStaNo()); | 
|---|
|  |  |  | map.put("staNo", 1075); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wcsUrl) | 
|---|
|  |  |  | .setPath("/open/toOutSta") | 
|---|
|  |  |  | .setJson(JSON.toJSONString(map)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | log.info("toOutSta:{},{}",map, response); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("fail", e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void toAllOut(PalletToAllOutParam param, Long userId) { | 
|---|
|  |  |  | String barcodeSize = param.getBarcode().substring(0, 2); | 
|---|
|  |  |  | String newBarcodeSize = param.getNewBarcode().substring(0, 2); | 
|---|
|  |  |  | if (!barcodeSize.equals(newBarcodeSize)) { | 
|---|
|  |  |  | throw new CoolException("托盘尺寸不一致"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode()); | 
|---|
|  |  |  | if (wrkMast == null) { | 
|---|
|  |  |  | throw new CoolException("工作档不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (wrkMast.getIoType() != 103) { | 
|---|
|  |  |  | throw new CoolException("工作档类型不是拣料出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (wrkMast.getWrkSts() != 14) { | 
|---|
|  |  |  | throw new CoolException("工作状态未处于已出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getSourceLocNo())); | 
|---|
|  |  |  | if (locMast == null) { | 
|---|
|  |  |  | throw new CoolException("库位不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("P")) { | 
|---|
|  |  |  | throw new CoolException("库位类型不是拣料出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | wrkMast.setBarcode(param.getNewBarcode()); | 
|---|
|  |  |  | wrkMast.setModiTime(new Date()); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | wrkMastService.updateById(wrkMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | wrkDetlService.updateBarcode(wrkMast.getWrkNo(), param.getNewBarcode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locMast.setBarcode(param.getNewBarcode()); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locDetlService.updateBarcode(locMast.getLocNo(), param.getNewBarcode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|