skyouc
2025-04-03 92ab24176e2f689abefb6a803b5d39ffffa4b443
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/MobileServiceImpl.java
@@ -4,13 +4,8 @@
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.CheckObjParams;
import com.vincent.rsf.server.api.controller.params.OtherReceiptParams;
import com.vincent.rsf.server.api.controller.params.ReceiptParams;
import com.vincent.rsf.server.api.entity.dto.CheckObjDto;
import com.vincent.rsf.server.api.entity.dto.InspectDetlDto;
import com.vincent.rsf.server.api.entity.dto.InspectItemDto;
import com.vincent.rsf.server.api.entity.dto.ReceiptDetlsDto;
import com.vincent.rsf.server.api.controller.params.*;
import com.vincent.rsf.server.api.entity.dto.*;
import com.vincent.rsf.server.api.entity.enums.OrderWorkType;
import com.vincent.rsf.server.api.service.MobileService;
import com.vincent.rsf.server.common.config.ConfigProperties;
@@ -35,7 +30,7 @@
import com.vincent.rsf.server.system.service.FieldsService;
import com.vincent.rsf.server.system.service.UserLoginService;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import org.apache.tika.utils.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -48,6 +43,7 @@
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @author Ryan
@@ -100,13 +96,28 @@
    @Autowired
    private WaitPakinItemService waitPakinItemService;
    @Autowired
    private AsnOrderItemLogService asnOrderItemLogService;
    @Autowired
    private FieldsItemService fieldsItemService;
    @Autowired
    private LocService locService;
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private StockService stockService;
    @Autowired
    private StockItemService stockItemService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskItemService taskItemService;
    @Autowired
    private LocAreaMatRelaMapper locAreaMatRelaMapper;
    @Autowired
    private LocAreaRelaMapper locAreaRelaMapper;
    @Autowired
    private LocAreaMapper locAreaMapper;
    /**
     * @author Ryan
@@ -152,7 +163,7 @@
     */
    @Override
    public R getOrderByCode(String barcode) {
        if (StringUtils.isEmpty(barcode)) {
        if (StringUtils.isBlank(barcode)) {
            return R.error("标签码不能为空!!");
        }
        List<AsnOrderItem> asnOrderItem = asnOrderItemMapper.selectList(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getTrackCode, barcode));
@@ -522,6 +533,7 @@
        CheckObjDto objDto = new CheckObjDto();
        objDto.setIsptCode(inspect.getCode())
                .setAsnCode(inspect.getAsnCode())
                .setId(isptItem.getId())
                .setMatnrCode(isptItem.getMatnrCode())
                .setMaktx(isptItem.getMaktx())
                .setDisQty(isptItem.getDisQty())
@@ -543,7 +555,7 @@
     */
    @Override
    public R checkUpdate(QlyIsptItem params) {
        if (Objects.isNull(params.getId()) || Objects.isNull(params.getIspectId())) {
        if (Objects.isNull(params.getId())) {
            throw new CoolException("参数不能为空!!");
        }
        IsptItemsParams itemsParams = new IsptItemsParams();
@@ -558,6 +570,176 @@
    }
    /**
    * @author Ryan
    * @description 人工上架
    * @param
    * @return
    * @time 2025/4/2 16:33
    */
    @Override
    public R operateToStock(OpStockParams params) {
        if (org.apache.commons.lang3.StringUtils.isBlank(params.getBarcode())) {
            throw new CoolException("拖盘码不能为空!!");
        }
        if (StringUtils.isBlank(params.getAsnCode())) {
            throw new CoolException("单据不能为空!!");
        }
        if (StringUtils.isBlank(params.getMatnrCode())) {
            throw new CoolException("物料编码不能为空!!");
        }
        AsnOrder asnOrders = asnOrderMapper.getOne(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getCode, params.getAsnCode()));
        if (Objects.isNull(asnOrders)) {
            throw new CoolException("单据不存在!!");
        }
        List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, params.getBarcode()));
        if (!locs.isEmpty()) {
            throw new CoolException("拖盘已使用");
        }
        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, params.getBarcode()));
        if (!waitPakins.isEmpty()) {
            throw new CoolException("拖盘已使用!!");
        }
        AsnOrderItem orderItems = asnOrderItemMapper.selectOne(new LambdaQueryWrapper<AsnOrderItem>()
                .eq(AsnOrderItem::getAsnId, asnOrders.getId())
                .eq(AsnOrderItem::getMatnrCode, params.getMatnrCode()));
        if (Objects.isNull(orderItems)) {
            return R.ok(null);
        }
        orderItems.setBarcode(params.getBarcode());
        return R.ok(orderItems);
    }
    /**
     * 人工上架入库
     * @param params
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R publicToStock(PublicToStockParams params) {
        if (Objects.isNull(params.getLocCode()) || StringUtils.isBlank(params.getLocCode())) {
            throw new CoolException("库位不能为空!!");
        }
        if (Objects.isNull(params.getItemList()) || params.getItemList().isEmpty()) {
            throw new CoolException("单据明细不能为空!!");
        }
        Long OrderId = params.getItemList().stream().findFirst().get().getAsnId();
        AsnOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, OrderId));
        if (Objects.isNull(order)) {
            throw new CoolException("单据不存在!!");
        }
        Stock stock = new Stock();
        stock.setAsnId(OrderId).setAsnCode(order.getCode());
        if (!Objects.isNull(order.getPoCode()) && StringUtils.isNotBlank(order.getPoCode())) {
            Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>().eq(Purchase::getCode, order.getPoCode()));
            if (!Objects.isNull(purchase)) {
                stock.setPlatOrderNo(purchase.getPlatCode()).setPlatToken(purchase.getPlatId());
            }
        }
        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
        if (StringUtils.isBlank(ruleCode)) {
            throw new CoolException("当前业务:" + SerialRuleCode.SYS_STOCK_CODE + ",编码规则不存在!!");
        }
        if (!stockService.save(stock)) {
            throw new CoolException("库存保存失败!!");
        }
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, params.getLocCode()));
        if (Objects.isNull(loc)) {
            throw new CoolException("库位不存在!!");
        }
        List<StockItem> stockItems = new ArrayList<>();
        params.getItemList().forEach(orderItem -> {
            StockItem stockItem = new StockItem();
            BeanUtils.copyProperties(orderItem, stockItem);
            stockItem.setAsnItemId(orderItem.getId())
                    .setBarcode(orderItem.getBarcode())
                    .setLocId(loc.getId())
                    .setId(null)
                    .setStockId(stock.getId());
            stockItems.add(stockItem);
        });
        if (!stockItemService.saveBatch(stockItems)) {
            throw new CoolException("任务上架失败!!");
        }
        return R.ok(stock);
    }
    /**
     * 获取任务信息
     * @param code
     * @return
     */
    @Override
    public R taskToStock(String code) {
        if (StringUtils.isBlank(code)) {
            throw new CoolException("拖盘码不能为空!!");
        }
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, code));
        if (Objects.isNull(task)) {
            throw new CoolException("拖盘任务不存在!!");
        }
        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
        if (!taskItems.isEmpty()) {
            throw new CoolException("拖盘任务明细不存在!!");
        }
        TaskQueueDto queueDto = new TaskQueueDto();
        queueDto.setTask(task).setTaskItems(taskItems);
        List<Long> list = taskItems.stream().map(TaskItem::getMatnrId).collect(Collectors.toList());
        List<LocAreaMatRela> matRelas = locAreaMatRelaMapper.selectList(new LambdaQueryWrapper<LocAreaMatRela>().in(LocAreaMatRela::getMatnrId,
                list));
        TaskLocAreaDto locAreaDto = new TaskLocAreaDto();
        /**判断是否为空*/
        if (matRelas.isEmpty()) {
            locAreaDto.setLocs(new ArrayList<>());
        } else {
            Long ids = matRelas.stream().map(LocAreaMatRela::getLocId).collect(Collectors.toList()).stream().findFirst().get();
            List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getId, ids));
            if (locs.isEmpty()) {
                locAreaDto.setLocs(new ArrayList<>());
            } else {
                LocArea locArea = locAreaMapper.selectById(new LambdaQueryWrapper<Loc>().in(Loc::getId, ids));
                if (!Objects.isNull(locArea)) {
                    locAreaDto.setAreaName(locArea.getName()).setAreaCode(locArea.getCode()).setAreaId(locArea.getId());
                }
                locAreaDto.setLocs(locs);
            }
        }
        queueDto.setLocArea(locAreaDto);
        return R.ok(queueDto);
    }
    /**
     * @Author Ryan
     * @param code
     * @desc  任务上架
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R taskGetLocs(String code) throws Exception {
        if (StringUtils.isBlank(code)) {
            throw new CoolException("拖盘码不能为空!!");
        }
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, code));
        if (Objects.isNull(task)) {
            throw new CoolException("拖盘任务不存在!!");
        }
        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
        if (!taskItems.isEmpty()) {
            throw new CoolException("拖盘任务明细不存在!!");
        }
        List<Task> tasks = new ArrayList<>();
        tasks.add(task);
        taskService.completeTask(tasks);
        return R.ok();
    }
    /**
     * 获取ReceiptDetlsDtos
     */
    private R getAsnOrderItem(List<AsnOrderItem> items) {