ChmConsignmentDetailService.java 6.48 KB
package com.erry.iclear.dateInterface.service;

import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.*;
import com.erry.iclear.dateInterface.repository.ChmConsignmentDetailRepository;
import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author Administrator
 */
@Service
@Slf4j
public class ChmConsignmentDetailService {


    @Autowired
    private ChmConsignmentDetailRepository chmConsignmentDetailRepository;


    /**
     * 转换运单明细
     * @param mawbDetail
     * @return
     */
    public ChmConsignmentDetail convertToChmConsignmentDetail(MawbDetail mawbDetail,ChmConsignment chmConsignment){
        ChmConsignmentDetail result = new ChmConsignmentDetail();
        try{
            result.setChmConsignment(chmConsignment);

            //归类标志

            //商品编号
            result.setSkuCode(mawbDetail.getCodeTS());
            //申报单价
            result.setOriRegion(mawbDetail.getDeclPrice());
            //申报总价
            result.setAmount(mawbDetail.getDeclTotal());
            //征免方式
            DictionaryEntries levyTypeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.LEVY_TYPE+mawbDetail.getDutyMode());
            result.setLevyTypeDic(levyTypeDictionaryEntries);
            result.setLevyType(levyTypeDictionaryEntries.getChineseName());
            //货号
            //版本号
            //第一计量单位(法定单位)
            DictionaryEntries firstUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getFirstUnit());
            result.setUnitLegalFirstId(firstUnitDictionaryEntries);
            result.setKnockdownUnit(firstUnitDictionaryEntries.getChineseName());

            //第一法定数量
            result.setQtyLegalFirst(BigDecimal.valueOf(mawbDetail.getFirstQty().doubleValue()));
            //成交计量单位
            DictionaryEntries knockdownUnitEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getFirstUnit());
            result.setKnockdownUnitDic(knockdownUnitEntries);
            result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
            //商品规格、型号
            result.setModel(mawbDetail.getGmodel());
            //商品名称
            result.setSkuName(mawbDetail.getGname());
            //商品序号
            //成交数量
            result.setKnockdownNumber(BigDecimal.valueOf(mawbDetail.getGqty().doubleValue()));
            //原产国
            DictionaryEntries habitatDictonaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+ mawbDetail.getOriginCountry());
            result.setHabitatDic(habitatDictonaryEntries);
            result.setHabitat(habitatDictonaryEntries.getChineseName());

            //第二计量单位
            DictionaryEntries secondUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getSecondUnit());
            result.setUnitLegalSecondId(secondUnitDictionaryEntries);
            result.setUnitLegalSecond(secondUnitDictionaryEntries.getChineseName());
            //第二法定数量
            result.setQtyLegalSecond(BigDecimal.valueOf(mawbDetail.getSecondQty().doubleValue()));
            //成交币制
            DictionaryEntries currencyDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+ mawbDetail.getTradeCurr());
            result.setCurrencyDic(currencyDictionaryEntries);
            result.setCurrency(currencyDictionaryEntries.getChineseName());

            //用途/生产厂家
            //工缴费
            //最终目的国
            DictionaryEntries destinationCountryDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+ mawbDetail.getDestinationCountry());
            result.setDestinationCountryDic(destinationCountryDictionaryEntries);
            result.setDestinationCountry(destinationCountryDictionaryEntries.getChineseName());


            //检验检疫编码
            //申报货物英文名称
            result.setContentDescription(mawbDetail.getDeclGoodsEname());
            //目的地代码
            if(StringUtils.isNotBlank(mawbDetail.getDestCode())){
                OrigplacecodeMapping origplacecodeMapping = Constant.origplacecodeMappingCache.get(mawbDetail.getDestCode());
                result.setOrigplacecodeMapping(origplacecodeMapping);
                result.setOrigplacecode(origplacecodeMapping.getOrigplaceName());
            }



            //境内目的地/境内货源地
            DomesticDestinationMapping domesticDestinationDictionaryEntries = Constant.domesticDestinationMappingCache.get(mawbDetail.getDistrictCode());
            result.setDomesticDestinationMapping(domesticDestinationDictionaryEntries);
            result.setDomesticDestination(destinationCountryDictionaryEntries.getChineseName());

            result.setDetailId(mawbDetail.getDetailId());

        }catch (Exception e){
            log.error("convertToChmConsignmentDetail() error:"+e.getMessage());
        }

        return result;
    }




    public List<ChmConsignmentDetail> findChmConsignmentDetailListByConsignmentCode(Long consignmentId){
        List<ChmConsignmentDetail> result = new ArrayList<>();
        try{
            result= chmConsignmentDetailRepository.findChmConsignmentDetailByConsignmentCode(consignmentId);
        }catch (Exception e){
            log.error("findChmConsignmentDetailListByConsignmentCode() error:"+e.getMessage());
        }
        return result;
    }





    public void saveDetailList(List<ChmConsignmentDetail> chmConsignmentDetailList){
        chmConsignmentDetailRepository.saveAll(chmConsignmentDetailList);
    }


    public void saveChmConsignmentDetail(ChmConsignmentDetail consignmentDetail){
        chmConsignmentDetailRepository.save(consignmentDetail);
    }


    public void deleteChmConsignmentDetail(Long id){
        chmConsignmentDetailRepository.deleteById(id);
    }


    public void deleteChmConsignmentDetailBatch(List<Long> idList){
        chmConsignmentDetailRepository.deleteChmConsignmentDetailByChnConIdList(idList);
    }


}