| | |
| | | import com.vincent.rsf.server.manager.enums.*; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.system.constant.DictTypeCode; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.entity.DictData; |
| | | import com.vincent.rsf.server.system.entity.FieldsItem; |
| | | import com.vincent.rsf.server.system.entity.User; |
| | |
| | | import com.vincent.rsf.server.system.service.UserService; |
| | | import com.vincent.rsf.server.system.service.impl.FieldsItemServiceImpl; |
| | | import com.vincent.rsf.server.system.service.impl.UserServiceImpl; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import com.vincent.rsf.server.system.utils.SystemAuthUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | 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.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class PdaCheckOrderServiceImpl implements PdaCheckOrderService { |
| | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private CheckOrderItemService checkOrderItemService; |
| | | |
| | | @Autowired |
| | | private CheckOrderService checkOrderService; |
| | | |
| | | @Autowired |
| | | private CusBarcodeSyncViewQueryService cusBarcodeSyncViewQueryService; |
| | | |
| | | |
| | | @Override |
| | | public R getCheckList(String code) { |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | |
| | | } |
| | | Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, params.getContainer())); |
| | | if (null == task) { |
| | | throw new CoolException("数据错误,未找到容器码对应盘点任务"); |
| | | throw new CoolException("数据错误,未找到料箱码对应盘点任务"); |
| | | } |
| | | for (CheckDiffItem ckDiffItem : params.getCheckDiffItems()) { |
| | | CheckDiffItem diffItem = new CheckDiffItem(); |
| | |
| | | taskItem.setTaskId(task.getId()) |
| | | .setOrderType(OrderType.ORDER_CHECK.type) |
| | | .setSourceCode(diffItem.getOrderCode()) |
| | | .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_CHECK.type)) |
| | | .setWkType(OrderWorkType.ORDER_WORK_TYPE_STOCK_CHECK.type) |
| | | .setAnfme(diffItem.getCheckQty()) |
| | | .setWorkQty(0.0) |
| | | .setBatch(diffItem.getBatch()) |
| | |
| | | throw new CoolException("更新差异单失败"); |
| | | } |
| | | |
| | | // 按盘点单明细汇总实盘数量并回写 |
| | | Set<Long> taskItemIds = diffItems.stream().map(CheckDiffItem::getTaskItemId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | if (!taskItemIds.isEmpty()) { |
| | | List<TaskItem> taskItems = taskItemService.listByIds(taskItemIds); |
| | | Map<Long, BigDecimal> orderItemIdToCheckQty = new HashMap<>(); |
| | | for (CheckDiffItem di : diffItems) { |
| | | if (di.getTaskItemId() == null) { |
| | | continue; |
| | | } |
| | | TaskItem ti = taskItems.stream().filter(t -> t.getId().equals(di.getTaskItemId())).findFirst().orElse(null); |
| | | if (ti == null || ti.getOrderItemId() == null) { |
| | | continue; |
| | | } |
| | | Double cq = di.getCheckQty() != null ? di.getCheckQty() : 0.0; |
| | | orderItemIdToCheckQty.merge(ti.getOrderItemId(), BigDecimal.valueOf(cq), BigDecimal::add); |
| | | } |
| | | for (Map.Entry<Long, BigDecimal> e : orderItemIdToCheckQty.entrySet()) { |
| | | double workQty = e.getValue().setScale(6, RoundingMode.HALF_UP).doubleValue(); |
| | | if (!checkOrderItemService.update(new LambdaUpdateWrapper<WkOrderItem>() |
| | | .eq(WkOrderItem::getId, e.getKey()) |
| | | .set(WkOrderItem::getWorkQty, workQty))) { |
| | | throw new CoolException("盘点单明细实盘数量更新失败"); |
| | | } |
| | | } |
| | | if (checkDiff.getOrderId() != null) { |
| | | List<WkOrderItem> orderItems = checkOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, checkDiff.getOrderId())); |
| | | BigDecimal orderWorkQty = orderItems.stream() |
| | | .map(oi -> oi.getWorkQty() != null ? BigDecimal.valueOf(oi.getWorkQty()) : BigDecimal.ZERO) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (!checkOrderService.update(new LambdaUpdateWrapper<WkOrder>() |
| | | .eq(WkOrder::getId, checkDiff.getOrderId()) |
| | | .set(WkOrder::getWorkQty, orderWorkQty.setScale(6, RoundingMode.HALF_UP).doubleValue()))) { |
| | | throw new CoolException("盘点单主表实盘数量更新失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); |
| | | task.setUpdateBy(loginUserId); |
| | | task.setUpdateTime(new Date()); |
| | |
| | | if (Cools.isEmpty(matnrCode)) { |
| | | return R.error("物料码为空"); |
| | | } |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, matnrCode)); |
| | | Matnr matnr = getMatnrByCodePreferView(matnrCode); |
| | | if (null == matnr) { |
| | | return R.error("未找到编码对应的明细"); |
| | | } |
| | |
| | | return R.ok(checkDiffItem); |
| | | } |
| | | |
| | | private Matnr findLocalMatnrByCode(String matnrCode) { |
| | | String t = StringUtils.trimToNull(matnrCode); |
| | | if (t == null) { |
| | | return null; |
| | | } |
| | | return matnrService.getOneByCodeAndBatch(t, ""); |
| | | } |
| | | |
| | | /** 视图 barcode 即物料号,与 man_matnr.code 一致 */ |
| | | private Matnr getMatnrByCodePreferView(String matnrCode) { |
| | | String code = StringUtils.trimToNull(matnrCode); |
| | | if (code == null) { |
| | | return null; |
| | | } |
| | | List<Map<String, Object>> viewItems = null; |
| | | try { |
| | | viewItems = cusBarcodeSyncViewQueryService.listByItemNos(Collections.singletonList(code)); |
| | | } catch (Exception ignore) { |
| | | } |
| | | Map<String, Object> row = null; |
| | | if (viewItems != null) { |
| | | row = viewItems.stream() |
| | | .filter(v -> CusBarcodeSyncViewQueryService.rowMatchesOrderMatnr(code, Objects.toString(v.get("barcode"), null))) |
| | | .findFirst() |
| | | .orElse(null); |
| | | } |
| | | if (row == null) { |
| | | return findLocalMatnrByCode(code); |
| | | } |
| | | String fullCode = CusBarcodeSyncViewQueryService.matnrCodeFromBarcode(Objects.toString(row.get("barcode"), null)); |
| | | String viewSpec = StringUtils.trimToEmpty(Objects.toString(row.get("item_spec"), "")); |
| | | String viewUnit = StringUtils.trimToNull(Objects.toString(row.get("unit_no"), null)); |
| | | String viewName = StringUtils.trimToNull(Objects.toString(row.get("item_name"), null)); |
| | | Long loginUserId = SystemAuthUtils.getLoginUserId() == null ? 1L : SystemAuthUtils.getLoginUserId(); |
| | | Matnr local = findLocalMatnrByCode(fullCode); |
| | | if (local == null) { |
| | | Matnr matnr = new Matnr(); |
| | | matnr.setCode(fullCode) |
| | | .setBatch("") |
| | | .setName(viewName != null ? viewName : fullCode) |
| | | .setSpec(viewSpec) |
| | | .setUnit(viewUnit) |
| | | .setStockUnit(viewUnit) |
| | | .setStatus(1) |
| | | .setCreateBy(loginUserId) |
| | | .setUpdateBy(loginUserId) |
| | | .setCreateTime(new Date()) |
| | | .setUpdateTime(new Date()); |
| | | if (!matnrService.save(matnr)) { |
| | | throw new CoolException("物料信息保存失败"); |
| | | } |
| | | return matnr; |
| | | } |
| | | boolean specDiff = !StringUtils.equals(StringUtils.trimToEmpty(local.getSpec()), viewSpec); |
| | | boolean unitDiff = viewUnit != null |
| | | && (!StringUtils.equals(StringUtils.trimToEmpty(local.getUnit()), viewUnit) |
| | | || !StringUtils.equals(StringUtils.trimToEmpty(local.getStockUnit()), viewUnit)); |
| | | if (specDiff || unitDiff) { |
| | | Matnr update = new Matnr(); |
| | | update.setId(local.getId()); |
| | | if (specDiff) { |
| | | update.setSpec(viewSpec); |
| | | local.setSpec(viewSpec); |
| | | } |
| | | if (unitDiff) { |
| | | update.setUnit(viewUnit).setStockUnit(viewUnit); |
| | | local.setUnit(viewUnit); |
| | | local.setStockUnit(viewUnit); |
| | | } |
| | | update.setUpdateBy(loginUserId).setUpdateTime(new Date()); |
| | | if (!matnrService.updateById(update)) { |
| | | throw new CoolException("物料信息更新失败"); |
| | | } |
| | | } |
| | | return local; |
| | | } |
| | | |
| | | @Override |
| | | public R getCheckTaskItemList2(String barcode) { |
| | | LambdaQueryWrapper<Task> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | } |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (Cools.isEmpty(taskItems)) { |
| | | throw new CoolException("未找到该容器码对应的任务明细"); |
| | | throw new CoolException("未找到该料箱码对应的任务明细"); |
| | | } |
| | | String sourceCode = taskItems.stream().findFirst().map(TaskItem::getSourceCode).orElse(null); |
| | | CheckDiff checkDiff = checkDiffService.getOne(new LambdaQueryWrapper<CheckDiff>().eq(CheckDiff::getOrderCode, sourceCode)); |
| | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/11/5 |
| | | * @description: 希日无单据临时盘点 |
| | | * @description: 无单据临时盘点 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | // 允许WAVE_SEED(199,等待确认/盘点中)和AWAIT(196,等待确认)两种状态 |
| | | if (!task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id) |
| | | && !task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认,当前状态:" + task.getTaskStatus()); |
| | | } |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (Cools.isEmpty(taskItems)) { |
| | | throw new CoolException("未找到该容器码对应的任务明细"); |
| | | throw new CoolException("未找到该料箱码对应的任务明细"); |
| | | } |
| | | taskItems.forEach(taskItem -> { |
| | | if (!Objects.isNull(taskItem.getFieldsIndex())) { |
| | |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(map.get("barcode"))) { |
| | | throw new CoolException("托盘码不能为空!!"); |
| | | throw new CoolException("料箱码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(map.get("matnrs"))) { |
| | | throw new CoolException("新增物料不能为空!!"); |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | |
| | | .setMaktx(matnr.getName()) |
| | | .setAnfme(item.getCheckQty()); |
| | | |
| | | FieldsItem fieldsItem = fieldsItemService.getOne(new LambdaQueryWrapper<FieldsItem>().eq(FieldsItem::getValue, item.getFieldsIndex()).last("limit 1")); |
| | | if (Objects.isNull(fieldsItem)) { |
| | | throw new CoolException("当前票号不存在库存中,请拿出后重新入库!!"); |
| | | // 票号暂不使用,不校验票号是否存在 |
| | | FieldsItem fieldsItem = null; |
| | | if (StringUtils.isNotBlank(item.getFieldsIndex())) { |
| | | fieldsItem = fieldsItemService.getOne(new LambdaQueryWrapper<FieldsItem>().eq(FieldsItem::getValue, item.getFieldsIndex()).last("limit 1")); |
| | | // if (Objects.isNull(fieldsItem)) { |
| | | // throw new CoolException("当前票号不存在库存中,请拿出后重新入库!!"); |
| | | // } |
| | | } |
| | | taskItem.setFieldsIndex(fieldsItem.getUuid()); |
| | | if (fieldsItem != null) { |
| | | taskItem.setFieldsIndex(fieldsItem.getUuid()); |
| | | } |
| | | |
| | | taskItems.add(taskItem); |
| | | }); |
| | |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(map.get("barcode"))) { |
| | | throw new CoolException("托盘码不能为空!!"); |
| | | throw new CoolException("料箱码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(map.get("matnrs"))) { |
| | | if (Objects.isNull(map.get("items"))) { |
| | | throw new CoolException("新增物料不能为空!!"); |
| | | } |
| | | String barcode = map.get("barcode").toString(); |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | // 允许WAVE_SEED(199,等待确认/盘点中)和AWAIT(196,等待确认)两种状态 |
| | | if (!task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id) |
| | | && !task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认,当前状态:" + task.getTaskStatus()); |
| | | } |
| | | //任务号不能重复,生成新任务号下发至RCS |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null); |
| | | |
| | | task.setTaskStatus(TaskStsType.GENERATE_IN.id) |
| | | .setTaskCode(ruleCode) |
| | | .setTargLoc(task.getOrgLoc()) |
| | | .setOrgSite(task.getTargSite()) |
| | | .setTaskType(TaskType.TASK_TYPE_CHECK_IN.type) |
| | | .setUpdateTime(new Date()); |
| | | |
| | | if (!taskService.updateById(task)) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | } |
| | | |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (Objects.isNull(taskItems) || taskItems.isEmpty()) { |
| | | throw new CoolException("数据错误,任务明细不存在!!"); |
| | | } |
| | | |
| | | List<TaskItem> items = JSONArray.parseArray(JSONArray.toJSONString(map.get("items")), TaskItem.class); |
| | | items.forEach(taskItem -> { |
| | | taskItems.forEach(item -> { |
| | | if (taskItem.getFieldsIndex().equals(item.getFieldsIndex())) { |
| | | item.setAnfme(taskItem.getCheckQty()); |
| | | if (!taskItemService.updateById(item)) { |
| | | throw new CoolException("盘点明细修改失败!!"); |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | uploadCheckResult(task); |
| | | |
| | |
| | | ReportParams params = new ReportParams(); |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (Objects.isNull(taskItems) || taskItems.isEmpty()) { |
| | | throw new CoolException("托盘明细为空!1"); |
| | | throw new CoolException("料箱明细为空!1"); |
| | | } |
| | | List<ReportDataParam> reportDataParams = new ArrayList<>(); |
| | | taskItems.forEach(taskItem -> { |
| | | ReportDataParam dataParam = new ReportDataParam(); |
| | | |
| | | User user = userService.getById(taskItem.getUpdateBy()); |
| | | String nickName = null; |
| | | if (!Objects.isNull(user)) { |
| | |
| | | .setPDQty(taskItem.getAnfme()) |
| | | .setEditUser(nickName) |
| | | .setEditDate(taskItem.getUpdateTime()) |
| | | .setGoodsNO(fields.get("crushNo")) |
| | | // .setGoodsNO(fields.get("crushNo")) // 票号暂不使用 |
| | | .setIsBad(0 + "") |
| | | .setMemoDtl(taskItem.getMemo()); |
| | | |