package com.vincent.rsf.server.api.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.service.PdaCheckOrderService; import com.vincent.rsf.server.manager.entity.*; import com.vincent.rsf.server.manager.enums.CheckDiffExceStatus; import com.vincent.rsf.server.manager.enums.TaskStsType; 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.service.DictDataService; import com.vincent.rsf.server.system.service.DictTypeService; 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; @Service public class PdaCheckOrderServiceImpl implements PdaCheckOrderService { @Autowired private CheckDiffService checkDiffService; @Autowired private CheckDiffItemService checkDiffItemService; @Autowired private TaskService taskService; @Autowired private TaskItemService taskItemService; @Autowired private DictTypeService dictTypeService; @Autowired private DictDataService dictDataService; @Override public R getCheckList(String code) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(!Cools.isEmpty(code),CheckDiff::getOrderCode,code); List waveList = checkDiffService.list(lambdaQueryWrapper); return R.ok(waveList); } @Override public R getCheckTaskItemList(String barcode,String checkCode) { List checkDiffItems = checkDiffItemService.list(new LambdaQueryWrapper() .eq(CheckDiffItem::getBarcode, barcode) .eq(CheckDiffItem::getOrderCode, checkCode) ); if (checkDiffItems.isEmpty()){ throw new CoolException("此条码不在当前盘点单中"); } LambdaQueryWrapper 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("任务状态不是等待确认"); } return R.ok(checkDiffItems); } @Override public R getCheckDiffReasonList() { List list = dictDataService.list(new LambdaQueryWrapper() .eq(DictData::getDictTypeCode, DictTypeCode.SYS_CHECK_DIFF_REASON) ); return R.ok(list); } @Override @Transactional(rollbackFor = Exception.class) public R saveCheckDiff(SaveCheckDiffParams params,Long loginUserId) { CheckDiff checkDiff = checkDiffService.getById(params.getCheckId()); if (null == checkDiff){ return R.error("未找到盘点差异单"); } if (checkDiff.getExceStatus().equals(CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val)){ return R.error("该盘点单已完成"); } for (CheckDiffItem checkDiffItem: params.getCheckDiffItems()){ CheckDiffItem diffItem = checkDiffItemService.getById(checkDiffItem.getId()); if (null == diffItem){ return R.error("数据错误,未找到差异单明细"); } checkDiffItem.setExceStatus(CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_HOLD.val); if(!checkDiffItemService.updateById(checkDiffItem)){ throw new CoolException("更新差异单明细失败"); } checkDiff.setCheckQty(checkDiff.getCheckQty()+checkDiffItem.getCheckQty()); } checkDiff.setExceStatus(CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_HOLD.val); if(!checkDiffService.updateById(checkDiff)){ throw new CoolException("更新差异单失败"); } Task task = taskService.getOne(new LambdaQueryWrapper().eq(Task::getBarcode, params.getContainer())); if (null == task){ throw new CoolException("数据错误,未找到容器码对应盘点任务"); } task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); task.setUpdateBy(loginUserId); task.setUpdateTime(new Date()); if (!taskService.updateById(task)){ throw new CoolException("更新任务失败"); } return R.ok("盘点完成"); } }