TaskDetailServiceImpl.java 7.02 KB
package com.huaheng.pc.task.taskDetail.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.pc.config.FilterConfigDetail.domain.FilterConfigDetail;
import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService;
import com.huaheng.pc.config.cycleCountPreference.domain.CycleCountPreference;
import com.huaheng.pc.config.cycleCountPreference.service.CycleCountPreferenceService;
import com.huaheng.pc.config.receiptPreference.domain.ReceiptPreference;
import com.huaheng.pc.config.receiptPreference.service.ReceiptPreferenceService;
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.task.taskDetail.mapper.TaskDetailMapper;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TaskDetailServiceImpl extends ServiceImpl<TaskDetailMapper, TaskDetail> implements TaskDetailService{


    @Resource
    private CycleCountDetailService cycleCountDetailService;
    @Resource
    private CycleCountPreferenceService cycleCountPreferenceService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private ReceiptPreferenceService receiptPreferenceService;
    @Resource
    private ShipmentPreferenceService shipmentPreferenceService;
    @Resource
    private FilterConfigDetailService filterConfigDetailService;

    /**
     * 盘点任务首选项
     * @param taskDetailList
     * @return
     */
    @Transactional
    @Override
    public List<TaskDetail> preferenceRealize(List<TaskDetail> taskDetailList) {
        /*查出盘点明细,找出盘点首选项,根据首选项显示字段*/
        List<TaskDetail> taskDetails = new ArrayList<>();

        for (TaskDetail item:taskDetailList){
            //盘点明细
            CycleCountDetail cycleCountDetailtemp = new CycleCountDetail();
            cycleCountDetailtemp.setCycleCountHeadCode(item.getBillCode());
            cycleCountDetailtemp.setId(item.getBillDetailId());
            LambdaQueryWrapper<CycleCountDetail> detailLambdaQueryWrapper = Wrappers.lambdaQuery(cycleCountDetailtemp);
            CycleCountDetail cycleCountDetail = cycleCountDetailService.getOne(detailLambdaQueryWrapper);
            if(cycleCountDetail == null){
                throw new SecurityException("没有找到子任务对应的盘点明细!");
            }
            //找盘点首选项
            CycleCountPreference cycleCountPreferenceTemp = new CycleCountPreference();
            cycleCountPreferenceTemp.setCode(cycleCountDetail.getPreferenceCode());
            cycleCountPreferenceTemp.setWarehouseCode(cycleCountDetail.getWarehouseCode());
            LambdaQueryWrapper<CycleCountPreference> preferenceLambdaQueryWrapper = Wrappers.lambdaQuery(cycleCountPreferenceTemp);
            CycleCountPreference cycleCountPreference = cycleCountPreferenceService.getOne(preferenceLambdaQueryWrapper);
            if(cycleCountPreference == null){
                throw new SecurityException("没有找到盘点首选项!");
            }
            //根据首选项判断数据
            if(cycleCountPreference.getPromptLocation() == false){
                //库位
                item.setFromLocation("");
                item.setToLocation("");
            }
            if(cycleCountPreference.getPromptLpn() == false){
                //容器
                item.setContainerCode("");
            }
            if(cycleCountPreference.getPromptItem() == false){
                //物料
                item.setMaterialCode("");
                item.setMaterialName("");
                item.setMaterialUnit("");
                item.setMaterialSpec("");
            }
            if(cycleCountPreference.getPromptQuantity() == false){
                //系统数量
                item.setQty(null);
            }
            taskDetails.add(item);
        }
        return taskDetails;
    }

    /**
     * 任务位置拣货单打印
     * 根据任务头表id查询任务明细,根据上架或拣货货规则排序
     * @param ids 头表id数组
     * @return
     */
    @Override
    public List<TaskDetail> findByTaskId(Integer[] ids) {
        Integer taskType = taskHeaderService.getById(ids[0]).getTaskType();
        String filterConfigCode = "";
        if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLERECEIPT) || taskType.equals(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT)) {
            ReceiptPreference receiptPreference = receiptPreferenceService.list().get(0);
            filterConfigCode = receiptPreference.getListingRules();
        }
        if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT) || taskType.equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)) {
            ShipmentPreference shipmentPreference = shipmentPreferenceService.list().get(0);
            filterConfigCode = shipmentPreference.getShipmentPickingRule();
        }
        FilterConfigDetail filterConfigDetail = new FilterConfigDetail();
        if (StringUtils.isNotEmpty(filterConfigCode)) {
            LambdaQueryWrapper<FilterConfigDetail> detailQueryWrapper = Wrappers.lambdaQuery();
            detailQueryWrapper.eq(FilterConfigDetail::getCode, filterConfigCode);
            filterConfigDetail = filterConfigDetailService.getOne(detailQueryWrapper);
        }
        //Integer数组转object数组
        Object[] objects = new Object[ids.length];
        try{
            for(int i = 0; i < ids.length ; i++){
                Object a =  (ids[i]);
                objects[i] = a;
            }
        }catch (Exception e){
            throw new ServiceException(e.toString());
        }
        LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper
                .in(TaskDetail::getTaskId, objects)
                .last(StringUtils.isNotEmpty(filterConfigDetail.getStatement()), filterConfigDetail.getStatement());
        return this.list(queryWrapper);
    }

    /**
     * 根据任务头表id查询任务明细
     * @param id
     * @return
     */
    @Override
    public List<TaskDetail> findByTaskId(Integer id) {
        LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TaskDetail::getTaskId, id);
        return this.list(queryWrapper);
    }


}