| | |
| | | package com.vincent.rsf.server.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | 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.api.controller.params.SaveCheckDiffParams; |
| | | import com.vincent.rsf.server.api.controller.erp.params.SaveCheckDiffParams; |
| | | import com.vincent.rsf.server.api.service.PdaCheckOrderService; |
| | | import com.vincent.rsf.server.common.utils.FieldsUtils; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.CheckDiffExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.OrderType; |
| | |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.system.constant.DictTypeCode; |
| | | import com.vincent.rsf.server.system.entity.DictData; |
| | | import com.vincent.rsf.server.system.entity.FieldsItem; |
| | | import com.vincent.rsf.server.system.service.DictDataService; |
| | | import com.vincent.rsf.server.system.service.DictTypeService; |
| | | import com.vincent.rsf.server.system.service.FieldsItemService; |
| | | import com.vincent.rsf.server.system.service.impl.FieldsItemServiceImpl; |
| | | 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.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | public class PdaCheckOrderServiceImpl implements PdaCheckOrderService { |
| | |
| | | private DictDataService dictDataService; |
| | | @Autowired |
| | | private MatnrService matnrService; |
| | | @Autowired |
| | | private FieldsItemService fieldsItemService; |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | List<CheckDiffItem> checkDiffItems = checkDiffItemService.list(new LambdaQueryWrapper<CheckDiffItem>() |
| | | .eq(CheckDiffItem::getBarcode, barcode) |
| | | .eq(CheckDiffItem::getExceStatus, CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_INIT.val) |
| | | .eq(CheckDiffItem::getOrderCode, checkCode) |
| | | ); |
| | | if (checkDiffItems.isEmpty()) { |
| | |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | } |
| | | |
| | | |
| | | return R.ok(checkDiffItems); |
| | | } |
| | | |
| | |
| | | .setOrderType(OrderType.ORDER_CHECK.type) |
| | | .setSourceCode(diffItem.getOrderCode()) |
| | | .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_CHECK.type)) |
| | | .setAnfme(diffItem.getAnfme()) |
| | | .setAnfme(diffItem.getCheckQty()) |
| | | .setWorkQty(0.0) |
| | | .setBatch(diffItem.getBatch()) |
| | | .setMaktx(matnr.getName()) |
| | |
| | | throw new CoolException("新增盘点明细保存失败!!"); |
| | | } |
| | | |
| | | diffItem.setTaskItemId(taskItem.getId()); |
| | | diffItem.setTaskItemId(taskItem.getId()).setExceStatus(CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_HOLD.val); |
| | | |
| | | if (!checkDiffItemService.updateById(diffItem)) { |
| | | throw new CoolException("明细修改失败!!"); |
| | |
| | | return R.error("数据错误,未找到差异单明细"); |
| | | } |
| | | diffItem.setCheckQty(ckDiffItem.getCheckQty()).setReason(ckDiffItem.getReason()).setMemo(ckDiffItem.getMemo()); |
| | | } |
| | | |
| | | diffItem.setExceStatus(CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_HOLD.val); |
| | | if (!checkDiffItemService.updateById(diffItem)) { |
| | | throw new CoolException("更新差异单明细失败"); |
| | | diffItem.setExceStatus(CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_HOLD.val); |
| | | if (!checkDiffItemService.updateById(diffItem)) { |
| | | throw new CoolException("更新差异单明细失败"); |
| | | } |
| | | |
| | | if (!taskItemService.update(new LambdaUpdateWrapper<TaskItem>() |
| | | .set(TaskItem::getAnfme, diffItem.getCheckQty()) |
| | | .eq(TaskItem::getId, diffItem.getTaskItemId()))) { |
| | | throw new CoolException("任务数量修改失败!!"); |
| | | } |
| | | } |
| | | // Double checkQty = Math.round((checkDiff.getCheckQty() + diffItem.getCheckQty()) * 10000) / 10000.0; |
| | | // checkDiff.setCheckQty(checkQty); |
| | | } |
| | | |
| | | List<CheckDiffItem> diffItems = checkDiffItemService.list(new LambdaQueryWrapper<CheckDiffItem>() |
| | |
| | | ; |
| | | return R.ok(checkDiffItem); |
| | | } |
| | | |
| | | @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("未找到容器号对应任务"); |
| | | } |
| | | 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("未找到该容器码对应的任务明细"); |
| | | } |
| | | String sourceCode = taskItems.stream().findFirst().map(TaskItem::getSourceCode).orElse(null); |
| | | CheckDiff checkDiff = checkDiffService.getOne(new LambdaQueryWrapper<CheckDiff>().eq(CheckDiff::getOrderCode,sourceCode)); |
| | | if (null == checkDiff) { |
| | | return R.error("未找到盘点差异单"); |
| | | } |
| | | List<CheckDiffItem> checkDiffItems = checkDiffItemService.list(new LambdaQueryWrapper<CheckDiffItem>() |
| | | .eq(CheckDiffItem::getBarcode, barcode) |
| | | .eq(CheckDiffItem::getExceStatus, CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_INIT.val) |
| | | .eq(CheckDiffItem::getOrderCode, sourceCode) |
| | | ); |
| | | if (checkDiffItems.isEmpty()) { |
| | | throw new CoolException("此条码不在当前盘点单中"); |
| | | } |
| | | |
| | | return R.ok(Cools.add("checkDiffItems",checkDiffItems).add("checkDiff",checkDiff)); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/11/5 |
| | | * @description: 希日无单据临时盘点 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public R tempCheckItem(String barcode) { |
| | | if (Objects.isNull(barcode)) { |
| | | throw new CoolException("搬盘码不能为空!!"); |
| | | } |
| | | LambdaQueryWrapper<Task> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | 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("未找到该容器码对应的任务明细"); |
| | | } |
| | | taskItems.forEach(taskItem -> { |
| | | if (!Objects.isNull(taskItem.getFieldsIndex())) { |
| | | Map<String, String> fields = FieldsUtils.getFields(taskItem.getFieldsIndex()); |
| | | taskItem.setExtendFields(fields); |
| | | } |
| | | }); |
| | | |
| | | return R.ok().add(taskItems); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/11/5 |
| | | * @description: 盘点添加新物料 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R confirmMatnr(Map<String, Object> map) { |
| | | if (Objects.isNull(map)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(map.get("barcode"))) { |
| | | throw new CoolException("托盘码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(map.get("matnrs"))) { |
| | | throw new CoolException("新增物料不能为空!!"); |
| | | } |
| | | String barcode = map.get("barcode").toString(); |
| | | LambdaQueryWrapper<Task> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | } |
| | | |
| | | List<CheckDiffItem> items = JSONArray.parseArray(JSONArray.toJSONString(map.get("matnrs")), CheckDiffItem.class); |
| | | List<TaskItem> taskItems = new ArrayList<>(); |
| | | |
| | | TaskItem item1 = taskItemService.getOne(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()).last("limit 1")); |
| | | |
| | | items.forEach(item -> { |
| | | TaskItem taskItem = new TaskItem(); |
| | | if (!Objects.isNull(item1)) { |
| | | BeanUtils.copyProperties(item1, taskItem); |
| | | } |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, item.getMatnrCode())); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("物料信息不存在 !!"); |
| | | } |
| | | |
| | | taskItem.setTaskId(task.getId()) |
| | | .setId(null) |
| | | .setFieldsIndex(null) |
| | | .setMatnrId(matnr.getId()) |
| | | .setMatnrCode(matnr.getCode()) |
| | | .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("当前票号不存在库存中,请拿出后重新入库!!"); |
| | | } |
| | | taskItem.setFieldsIndex(fieldsItem.getUuid()); |
| | | |
| | | taskItems.add(taskItem); |
| | | }); |
| | | |
| | | if (!taskItemService.saveBatch(taskItems)) { |
| | | throw new CoolException("新增盘点物料失败!!"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |