ComputationUnitApiService.java 2.9 KB
package com.huaheng.api.U8.Service;

import com.huaheng.api.U8.domain.ICScomputationUnitModel;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.CompanyWu;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.general.company.service.ICompanyService;
import com.huaheng.pc.system.dict.domain.DictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
public class ComputationUnitApiService {

    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;
    @Autowired
    private ICompanyService companyService;

    @Autowired
    BasicDataApiService basicDataApiService;

    @Transactional
    public AjaxResult ICSUnit(ICScomputationUnitModel icsComputationUnit) {
        if(StringUtils.isEmpty(icsComputationUnit.getCompanyCode())){
            return AjaxResult.error("没有货主信息");
        }
        if(StringUtils.isEmpty(icsComputationUnit.getcComunitCode())){
            return AjaxResult.error("没有计量单位编码信息");
        }
        if(StringUtils.isEmpty(icsComputationUnit.getcComunitName())){
            return AjaxResult.error("没有计量单位名称信息");
        }
        CompanyWu companyWu=new CompanyWu();
        companyWu.setuCompanyCode(icsComputationUnit.getCompanyCode());
        companyWu=companyService.selectCompanyWu(companyWu);
        if(companyWu==null){
            return AjaxResult.error("货主不存在");
        }
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        warehouseCompany.setCompanyCode(companyWu.getCompanyCode());
        List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
        if (list == null || list.size() == 0) {
            return AjaxResult.error("系统中没有该货主:" + warehouseCompany.toString() + "  信息,请先录入货主信息!");
        }
        AjaxResult ajaxResult=new AjaxResult();
        for (WarehouseCompany item : list) {
            DictData dictData = new DictData();
            dictData.setHeaderId(334);
            dictData.setDictType("unitType");
            dictData.setWarehouseCode(item.getWarehouseCode());
            dictData.setWarehouseId(item.getWarehouseId());
            dictData.setDictValue(icsComputationUnit.getcComunitCode());
            dictData.setDictLabel(icsComputationUnit.getcComunitName());
            dictData.setCreateTime(new Date());
            ajaxResult=basicDataApiService.dict(dictData);
        }
        return ajaxResult;
    }
}