ICSReceiptDetailServiceImpl.java 9.62 KB
package com.huaheng.pc.u8.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.u8.domain.ICSReceiptDetail;
import com.huaheng.pc.u8.domain.ICSReceiptHeader;
import com.huaheng.pc.u8.mapper.ICSReceiptDetailMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 入库下发或回传子单 实现层
 *
 * @author huaheng
 * @date 2019-1-2
 */

@Service
public class ICSReceiptDetailServiceImpl extends ServiceImpl<ICSReceiptDetailMapper,ICSReceiptDetail> implements ICSReceiptDetailService{

    @Resource
    private CompanyU8Service companyU8Service;

    /**
     * 根据入库单头rId删除
     * @param headerId ICSReceiptHeader rId
     * @return
     */
    @Override
    public boolean removeByHeaderId(Integer headerId) {
        List<ICSReceiptDetail> receiptDetails = this.list(new LambdaQueryWrapper<ICSReceiptDetail>()
                .eq(ICSReceiptDetail::getHeaderId, headerId));
        List<Integer> ids = receiptDetails.stream().map(ICSReceiptDetail::getRid).collect(Collectors.toList());
        return this.removeByIds(ids);
    }

    @Override
    public List<ICSReceiptDetail> getDetailsByPI(List<ReceiptDetail> detailList, ICSReceiptHeader header, Map<Integer, BigDecimal> detailsQtyMap) {
        List<ICSReceiptDetail> details = new ArrayList<>();
        for (ReceiptDetail receiptDetail : detailList) {
            BigDecimal totalQty = detailsQtyMap.get(receiptDetail.getId());
            if(totalQty==null){
                continue;
            }
            ICSReceiptDetail detail = new ICSReceiptDetail();
            detail.setAutoID(receiptDetail.getAutoId());
            detail.setCCode(header.getReferCode());
            if(!StringUtils.isEmpty(receiptDetail.getBatch())){
                detail.setCDefine22(receiptDetail.getBatch());
            }
            if(!StringUtils.isEmpty(receiptDetail.getMoCode())){
                detail.setCDefine22(receiptDetail.getMoCode());
            }
            detail.setCDefine23(receiptDetail.getLot());
            detail.setCComUnitName(receiptDetail.getMaterialUnit());
            detail.setCInvCode(receiptDetail.getMaterialCode());
            detail.setCInvName(receiptDetail.getMaterialName());
            detail.setCInvStd(receiptDetail.getMaterialSpec());
            detail.setCWHCode(receiptDetail.getUWarehouseCode());
            CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(receiptDetail.getCompanyCode(), receiptDetail.getWarehouseCode());
            detail.setCompanyCode(companyU8.getUCompanyCode());
            detail.setIArrsId(receiptDetail.getAutoId());
            detail.setCModifyDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
            detail.setID(receiptDetail.getId());
//            detail.setIrowno(Integer.parseInt(receiptDetail.getReferLineNum()));
            detail.setIPOsID(receiptDetail.getReferId());
            detail.setIQuantity(totalQty);

            detail.setPOCode(receiptDetail.getReferCode());
            detail.setPOID(header.getReferId());
            detail.setPODID(receiptDetail.getReferId());
            detail.setCComUnitName(receiptDetail.getMaterialUnit());
            details.add(detail);
        }
        return details;
    }

    @Override
    public List<ICSReceiptDetail> getDetailsByPCI(List<ReceiptDetail> detailList, ICSReceiptHeader header,Map<Integer,BigDecimal> detailsQtyMap) {
        return null;
    }

    @Override
    public List<ICSReceiptDetail> getDetailsByCI(List<ReceiptDetail> detailList, ICSReceiptHeader header,Map<Integer,BigDecimal> detailsQtyMap) {
        List<ICSReceiptDetail> details = new ArrayList<>();
        for (ReceiptDetail receiptDetail : detailList) {
            BigDecimal totalQty = detailsQtyMap.get(receiptDetail.getId());
            if(totalQty==null){
                continue;
            }
            ICSReceiptDetail detail = new ICSReceiptDetail();
            detail.setAutoID(receiptDetail.getAutoId());
            detail.setCCode(header.getCCode());
            detail.setCComUnitName(receiptDetail.getMaterialUnit());
            detail.setCInvCode(receiptDetail.getMaterialCode());
            detail.setCInvName(receiptDetail.getMaterialName());
            detail.setCInvStd(receiptDetail.getMaterialSpec());
            CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(receiptDetail.getCompanyCode(), receiptDetail.getWarehouseCode());
            detail.setCompanyCode(companyU8.getUCompanyCode());
            detail.setCModifyDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
            detail.setID(header.getReferId());
            detail.setIQuantity(totalQty.negate());
            detail.setMoCode(receiptDetail.getMoCode());
            details.add(detail);
        }
        header.setReferId(null);
        header.setReferCode(null);
        return details;
    }

    @Override
    public List<ICSReceiptDetail> getDetailsBySRI(List<ReceiptDetail> detailList, ICSReceiptHeader header,Map<Integer,BigDecimal> detailsQtyMap) {
        List<ICSReceiptDetail> details = new ArrayList<>();
        for (ReceiptDetail receiptDetail : detailList) {
            BigDecimal totalQty = detailsQtyMap.get(receiptDetail.getId());
            if(totalQty==null){
                continue;
            }
            ICSReceiptDetail detail = new ICSReceiptDetail();
            detail.setAutoID(receiptDetail.getReferId());
            detail.setCCode(header.getReferCode());
            detail.setCComUnitName(receiptDetail.getMaterialUnit());
            detail.setCInvCode(receiptDetail.getMaterialCode());
            detail.setCInvName(receiptDetail.getMaterialName());
            detail.setCInvStd(receiptDetail.getMaterialUnit());
            CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(receiptDetail.getCompanyCode(), receiptDetail.getWarehouseCode());
            detail.setCompanyCode(companyU8.getUCompanyCode());
            detail.setCModifyDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
            detail.setID(receiptDetail.getId());
            detail.setIQuantity(totalQty.negate());
            detail.setCSOAutoID(receiptDetail.getReferId());
            detail.setCSOCode(receiptDetail.getReferCode());
            detail.setCSOID(receiptDetail.getSoId());
            detail.setCWHCode(receiptDetail.getUWarehouseCode());
            detail.setDLID(header.getReferId());
            detail.setID(header.getReferId());
            details.add(detail);
        }
        header.setReferId(null);
        header.setReferCode(null);
        return details;
    }

    @Override
    public List<ICSReceiptDetail> getDetailsBySI(List<ReceiptDetail> detailList, ICSReceiptHeader header, Map<Integer, BigDecimal> detailsQtyMap) {
        List<ICSReceiptDetail> details = new ArrayList<>();
        for (ReceiptDetail receiptDetail : detailList) {
            BigDecimal totalQty = detailsQtyMap.get(receiptDetail.getId());
            if(totalQty==null){
                continue;
            }
            ICSReceiptDetail detail = new ICSReceiptDetail();
//            icsReceiptDetailA.setiMPoIds(Integer.valueOf(item.getSourceLine()));
            detail.setIMPoIds(Integer.valueOf(receiptDetail.getReferLineNum()));
            detail.setCDefine22(receiptDetail.getMoCode());
            detail.setCInvCode(receiptDetail.getMaterialCode());
            detail.setCInvName(receiptDetail.getMaterialName());
            detail.setIQuantity(totalQty);
            details.add(detail);

        }
        return details;
    }

    @Override
    public ICSReceiptDetail selectModel(ICSReceiptDetail model){
        LambdaQueryWrapper<ICSReceiptDetail> lamb = Wrappers.lambdaQuery();
        lamb.eq(StringUtils.isNotEmpty(model.getCCode()),ICSReceiptDetail::getCCode,model.getCCode());
        lamb.eq(StringUtils.isNotEmpty(model.getCompanyCode()),ICSReceiptDetail::getCompanyCode,model.getCompanyCode());
        lamb.eq(StringUtils.isNotEmpty(model.getCInvCode()),ICSReceiptDetail::getCInvCode,model.getCInvCode());
        lamb.eq(StringUtils.isNotNull(model.getITrIds()),ICSReceiptDetail::getITrIds,model.getITrIds());
        lamb.eq(StringUtils.isNotNull(model.getAutoID()),ICSReceiptDetail::getAutoID,model.getAutoID());

        lamb.last("limit 1");
        return this.getOne(lamb);
    }
    @Override
    public List<ICSReceiptDetail> selectModelList(ICSReceiptDetail model){
        LambdaQueryWrapper<ICSReceiptDetail> lamb = Wrappers.lambdaQuery();
        lamb.eq(StringUtils.isNotEmpty(model.getCCode()),ICSReceiptDetail::getCCode,model.getCCode());
        lamb.eq(StringUtils.isNotNull(model.getID()),ICSReceiptDetail::getID,model.getID());

        lamb.eq(StringUtils.isNotEmpty(model.getCompanyCode()),ICSReceiptDetail::getCompanyCode,model.getCompanyCode());
        lamb.eq(StringUtils.isNotEmpty(model.getCInvCode()),ICSReceiptDetail::getCInvCode,model.getCInvCode());
        lamb.eq(StringUtils.isNotNull(model.getITrIds()),ICSReceiptDetail::getITrIds,model.getITrIds());
        lamb.eq(StringUtils.isNotNull(model.getAutoID()),ICSReceiptDetail::getAutoID,model.getAutoID());

        return this.list(lamb);
    }
}