ICSReceiptHeaderServiceImpl.java 7.89 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.config.customer.service.CustomerServiceImpl;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.u8.domain.ICSReceiptHeader;
import com.huaheng.pc.u8.mapper.ICSReceiptHeaderMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

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

@Service
public class ICSReceiptHeaderServiceImpl extends ServiceImpl<ICSReceiptHeaderMapper, ICSReceiptHeader> implements ICSReceiptHeaderService{
    @Resource
    private CompanyU8Service companyU8Service;
    @Resource
    private CustomerServiceImpl customerService;
    @Resource
    private IUserService userService;

    @Override
    public ICSReceiptHeader getHeaderByPI(ReceiptHeader header) {
        String warehouseCode = header.getWarehouseCode();
        header.getCompanyCode();
        CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(header.getCompanyCode(), header.getWarehouseCode());
        ICSReceiptHeader rh = new ICSReceiptHeader();
        rh.setReferCode(header.getReferCode());
        rh.setReferId(header.getReferId());
        rh.setCCode(header.getReferCode());
        rh.setCompanyCode(companyU8.getUCompanyCode());
        rh.setCWHCode(header.getUWarehouseCode());
        rh.setCVenCode(header.getSupplierCode());
        rh.setCVenName(header.getSupplierName());
        rh.setCWHCode(header.getUWarehouseCode());
        rh.setCBusType("普通采购");
        rh.setCDepCode(header.getDeptCode());
        rh.setCDepName(header.getCDeptName());
        rh.setID(header.getId());
        rh.setDPODate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        rh.setCModifyDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        rh.setCMemo(header.getReceiptNote());
        rh.setCMaker(header.getLastUpdatedBy());
        rh.setVoucherType("CreateICSRdRecord_01");
        rh.setType(header.getReceiptType());
        return rh;
    }

    @Override
    public ICSReceiptHeader getHeaderByPCI(ReceiptHeader header) {
        ICSReceiptHeader rh = new ICSReceiptHeader();
        return null;
    }

    @Override
    public ICSReceiptHeader getHeaderByCI(ReceiptHeader header) {
        ICSReceiptHeader rh = new ICSReceiptHeader();
        CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(header.getCompanyCode(), header.getWarehouseCode());
        rh.setCCode(header.getReferCode());
        rh.setCompanyCode(companyU8.getUCompanyCode());
        rh.setCWHCode(header.getUWarehouseCode());
        rh.setCBusType(header.getTypeName());
        rh.setID(header.getReferId());
        rh.setDDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        rh.setCModifyDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        rh.setCMemo(header.getReceiptNote());
        rh.setCMaker(header.getLastUpdatedBy());
        rh.setVoucherType("UpdateICSRdRecord_11_Return_Confirm");
        rh.setType(header.getReceiptType());
        return rh;
    }

    @Override
    public ICSReceiptHeader getHeaderBySRI(ReceiptHeader header) {
        ICSReceiptHeader rh = new ICSReceiptHeader();
        CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(header.getCompanyCode(), header.getWarehouseCode());
        rh.setCBusType("普通销售");
        rh.setCCode(header.getReferCode());
        rh.setCCusCode(header.getCustomerCode());
        rh.setCDLCode(header.getReferCode());
        rh.setCDepCode(header.getDeptCode());
        rh.setCMaker(header.getLastUpdatedBy());
        rh.setCModifyDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        rh.setCPersonCode(header.getPersonCode());
        rh.setCSTName("普通销售");
        rh.setCWHCode(header.getUWarehouseCode());
        rh.setCompanyCode(companyU8.getUCompanyCode());
        rh.setCMemo(header.getReceiptNote());
        rh.setDDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        rh.setDLID(header.getReferId());
        rh.setID(header.getReferId());
        rh.setType(header.getReceiptType());
        rh.setVoucherType("CreateICSRdRecord_32_Return");
        rh.setReferCode(header.getReferCode());
        rh.setReferId(header.getReferId());
        return rh;
    }

    @Override
    public ICSReceiptHeader getHeaderBySI(ReceiptHeader receiptHeader, TaskHeader taskHeader) {
        String warehouseCode = taskHeader.getWarehouseCode();
        String companyCode = taskHeader.getCompanyCode();
        CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(companyCode, warehouseCode);
        ICSReceiptHeader icsReceiptHeader = new ICSReceiptHeader();
        icsReceiptHeader.setCBusType("产品入库");
        icsReceiptHeader.setCWHCode(receiptHeader.getUWarehouseCode());
        icsReceiptHeader.setVoucherType("CreateICSRdRecord_10");
        User user=new User();
        user.setUserName(taskHeader.getCreatedBy());
        List<User> users = userService.selectUserList(user);
        if(CollectionUtils.isNotEmpty(users)){
            icsReceiptHeader.setCMaker(users.get(0).getLoginName());
        }else {
            icsReceiptHeader.setCMaker(taskHeader.getCreatedBy());
        }
        icsReceiptHeader.setCDepCode(receiptHeader.getDeptCode());
        icsReceiptHeader.setCMemo("");
        icsReceiptHeader.setCompanyCode(companyU8.getUCompanyCode());
        icsReceiptHeader.setDPODate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,taskHeader.getLastUpdated()));
        return icsReceiptHeader;
    }

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

    @Override
    public List<ICSReceiptHeader> selectModelList(ICSReceiptHeader model){
        LambdaQueryWrapper<ICSReceiptHeader> lamb = Wrappers.lambdaQuery();
        lamb.eq(StringUtils.isNotEmpty(model.getCTVCode()),ICSReceiptHeader::getCTVCode,model.getCTVCode());
        lamb.eq(StringUtils.isNotNull(model.getID()),ICSReceiptHeader::getID,model.getID());

        lamb.eq(StringUtils.isNotEmpty(model.getIWHCode()),ICSReceiptHeader::getIWHCode,model.getIWHCode());
        lamb.eq(StringUtils.isNotEmpty(model.getCompanyCode()),ICSReceiptHeader::getCompanyCode,model.getCompanyCode());
        lamb.eq(StringUtils.isNotEmpty(model.getCCode()),ICSReceiptHeader::getCCode,model.getCCode());
        lamb.eq(StringUtils.isNotEmpty(model.getWarehouseCode()),ICSReceiptHeader::getWarehouseCode,model.getWarehouseCode());
        return this.list(lamb);
    }
}