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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.pc.config.cycleCountPreference.domain.CycleCountPreference;
import com.huaheng.pc.config.cycleCountPreference.service.CycleCountPreferenceService;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
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;





    /**
     * 盘点任务首选项
     * @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 id
     * @return
     */
    @Override
    public List<TaskDetail> findByTaskId(Integer id) {
        LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TaskDetail::getTaskId, id);
        return this.list(queryWrapper);
    }


}