|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.CodeRes; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.GlobalConfigCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.controller.param.LoginParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.controller.result.LoginResult; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.mapper.FieldsMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.mapper.TenantMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.ConfigService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.FieldsItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.UserLoginService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.UserService; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private LocAreaMapper locAreaMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceSiteMapper deviceSiteMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ConfigService configService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanysService companysService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("数据错误:主单不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //TODO /**收货数量累加,1. 会出超收情况 2. 会有收货不足情况*/ | 
|---|
|  |  |  | Double rcptedQty = asnOrder.getQty() + receiptQty; | 
|---|
|  |  |  | asnOrder.setQty(rcptedQty).setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_EXCE_ING.val); | 
|---|
|  |  |  | Double rcptedQty = Math.round((asnOrder.getQty() + receiptQty) * 10000) / 10000.0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | asnOrder.setQty(rcptedQty).setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_EXCE_ING.val); | 
|---|
|  |  |  | if (!asnOrderMapper.updateById(asnOrder)) { | 
|---|
|  |  |  | throw new CoolException("已收货数量修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.ALLOW_OVER_CHANGE)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> receipts1 = (List<Map<String, Object>>) params.get("receipts"); | 
|---|
|  |  |  | for (Map<String, Object> rcpt : receipts1) { | 
|---|
|  |  |  | if (null == rcpt || Objects.isNull(rcpt)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Objects.isNull(dto.getReceiptQty()) || Double.compare(dto.getReceiptQty(), 0.0) == 0) { | 
|---|
|  |  |  | throw new CoolException("物料:" + dto.getMaktx() + "收货数量不能为零!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Double itemRcptQty = dto.getReceiptQty() + orderItem.getQty(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (!Objects.isNull(dto.getProdTime())) { | 
|---|
|  |  |  | sdf.parse(dto.getProdTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (ParseException e) { | 
|---|
|  |  |  | throw new CoolException("请输入正确的时间格式!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double itemRcptQty = Math.round((dto.getReceiptQty() + orderItem.getQty()) * 10000) / 10000.0; | 
|---|
|  |  |  | Boolean allowOver = false; | 
|---|
|  |  |  | if (!Objects.isNull(config)) { | 
|---|
|  |  |  | if (Boolean.parseBoolean(config.getVal())) { | 
|---|
|  |  |  | allowOver = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (itemRcptQty.compareTo(orderItem.getAnfme()) > 0 && !allowOver) { | 
|---|
|  |  |  | throw new CoolException("收货数量不能大于计划数量!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderItem.setQty(itemRcptQty) | 
|---|
|  |  |  | //                    .setSplrBatch(dto.getSplrBatch()) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void extracted(Long loginUserId, ReceiptDetlsDto dto, WarehouseAreas areasItem, AsnOrderItem orderItem, AsnOrder asnOrder, Matnr matnr) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Companys companys = new Companys(); | 
|---|
|  |  |  | if (StringUtils.isNoneBlank(orderItem.getSplrCode())) { | 
|---|
|  |  |  | companys = companysService.getOne(new LambdaQueryWrapper<Companys>().eq(Companys::getCode, orderItem.getSplrCode())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WarehouseAreasItem item = new WarehouseAreasItem(); | 
|---|
|  |  |  | item.setTrackCode(dto.getBarcode()) | 
|---|
|  |  |  | .setAreaName(areasItem.getName()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .setAsnCode(asnOrder.getCode()) | 
|---|
|  |  |  | .setAsnId(asnOrder.getId()) | 
|---|
|  |  |  | .setProdTime(dto.getProdTime()) | 
|---|
|  |  |  | .setSplrId(companys.getId()) | 
|---|
|  |  |  | .setWeight(dto.getWeigth()) | 
|---|
|  |  |  | .setPlatOrderCode(orderItem.getPlatOrderCode()) | 
|---|
|  |  |  | .setPlatWorkCode(orderItem.getPlatWorkCode()) | 
|---|
|  |  |  | .setProjectCode(orderItem.getProjectCode()) | 
|---|
|  |  |  | //库存单位为最小单位 | 
|---|
|  |  |  | .setUnit(orderItem.getStockUnit()) | 
|---|
|  |  |  | .setStockUnit(orderItem.getStockUnit()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .setFieldsIndex(orderItem.getFieldsIndex()) | 
|---|
|  |  |  | .setShipperId(matnr.getShipperId()); | 
|---|
|  |  |  | //TODO 供应商标识未设置,标识由PO单供应商编码转换 | 
|---|
|  |  |  | WarehouseAreasItem serviceOne = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new LambdaQueryWrapper<WarehouseAreasItem>() | 
|---|
|  |  |  | //                .eq(WarehouseAreasItem::getAsnItemId, item.getAsnItemId()) | 
|---|
|  |  |  | .eq(WarehouseAreasItem::getMatnrCode, item.getMatnrCode()) | 
|---|
|  |  |  | .eq(!Cools.isEmpty(item.getFieldsIndex()), WarehouseAreasItem::getFieldsIndex, item.getFieldsIndex()) | 
|---|
|  |  |  | .eq(WarehouseAreasItem::getAsnCode, item.getAsnCode()) | 
|---|
|  |  |  | .eq(!Cools.isEmpty(item.getIsptResult()), WarehouseAreasItem::getIsptResult, item.getIsptResult()) | 
|---|
|  |  |  | .eq(StringUtils.isNotBlank(item.getSplrBatch()), WarehouseAreasItem::getSplrBatch, item.getSplrBatch())); | 
|---|
|  |  |  | .eq(StringUtils.isNotBlank(item.getSplrBatch()), WarehouseAreasItem::getSplrBatch, item.getSplrBatch()); | 
|---|
|  |  |  | if (Objects.isNull(orderItem.getIsptResult())) { | 
|---|
|  |  |  | queryWrapper.isNull(WarehouseAreasItem::getIsptResult); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.eq(WarehouseAreasItem::getIsptResult, orderItem.getIsptResult()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WarehouseAreasItem serviceOne = warehouseAreasItemService.getOne(queryWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Objects.isNull(serviceOne)) { | 
|---|
|  |  |  | item.setId(serviceOne.getId()); | 
|---|
|  |  |  | item.setAnfme(item.getAnfme() + serviceOne.getAnfme()); | 
|---|
|  |  |  | Double anfme = Math.round((item.getAnfme() + serviceOne.getAnfme()) * 10000) / 10000.0; | 
|---|
|  |  |  | item.setAnfme(anfme); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //未质检 | 
|---|
|  |  |  | 
|---|
|  |  |  | * 快速质检 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param params | 
|---|
|  |  |  | * @param loginUserId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R checkUpdate(List<QlyIsptItem> params) { | 
|---|
|  |  |  | public R checkUpdate(List<QlyIsptItem> params, Long loginUserId) { | 
|---|
|  |  |  | if (Objects.isNull(params) || params.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IsptItemsParams itemsParams = new IsptItemsParams(); | 
|---|
|  |  |  | itemsParams.setIsptItem(params).setType("0"); | 
|---|
|  |  |  | if (qlyIsptItemService.batchUpdate(itemsParams)) { | 
|---|
|  |  |  | if (qlyIsptItemService.batchUpdate(itemsParams, loginUserId)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.error("保存失败!!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | /**获取平库订单*/ | 
|---|
|  |  |  | AsnOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<AsnOrder>() | 
|---|
|  |  |  | .eq(AsnOrder::getId, OrderId) | 
|---|
|  |  |  | .eq(AsnOrder::getType, OrderType.ORDER_PLAT_IN.type)); | 
|---|
|  |  |  | .eq(AsnOrder::getWkType, OrderWorkType.ORDER_WORK_TYPE_OTHER_IN.type) | 
|---|
|  |  |  | .eq(AsnOrder::getType, OrderType.ORDER_IN.type)); | 
|---|
|  |  |  | if (Objects.isNull(order)) { | 
|---|
|  |  |  | throw new CoolException("非平库单据不可执行人工上架!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R getUnItemByContainer(Map<String, Object> params) { | 
|---|
|  |  |  | if (Objects.isNull(params.get("barcode"))) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | if (Cools.isEmpty(params.get("barcode")) && Cools.isEmpty(params.get("code"))){ | 
|---|
|  |  |  | throw new CoolException("容器号与组托档编码不能全为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取组拖未生成任务的组拖档 | 
|---|
|  |  |  | //        List<Short> asList = Arrays.asList(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val), Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>() | 
|---|
|  |  |  | .eq(WaitPakin::getBarcode, params.get("barcode").toString()) | 
|---|
|  |  |  | .eq(!Cools.isEmpty(params.get("barcode")),WaitPakin::getBarcode, params.get("barcode")) | 
|---|
|  |  |  | .eq(!Cools.isEmpty(params.get("code")),WaitPakin::getCode, params.get("code")) | 
|---|
|  |  |  | .eq(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_DONE.val)); | 
|---|
|  |  |  | if (Objects.isNull(waitPakin)) { | 
|---|
|  |  |  | return R.error("未找到该容器码的组托明细,请检查组托状态"); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Objects.isNull(stockItem)) { | 
|---|
|  |  |  | detlsDto.setStockQty(0.0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | detlsDto.setStockQty(stockItem.getAnfme() + stockItem.getWorkQty()); | 
|---|
|  |  |  | Double anfme = Math.round((stockItem.getAnfme() + stockItem.getWorkQty()) * 10000) / 10000.0; | 
|---|
|  |  |  | detlsDto.setStockQty(anfme); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Objects.isNull(asnOrderItem.getPoDetlId())) { | 
|---|