ComputationUnitApiService.java 3.91 KB
package com.huaheng.pc.u8.service;

import com.alibaba.fastjson.JSON;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.config.materialUnit.domain.MaterialUnit;
import com.huaheng.pc.config.materialUnit.service.MaterialUnitService;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;

import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.u8.domain.ICSCustomerModel;
import com.huaheng.pc.u8.domain.ICScomputationUnitModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Service
public class ComputationUnitApiService {

    @Resource
    private WarehouseCompanyService warehouseCompanyService;
    @Resource
    private CompanyU8Service companyU8Service;
    @Resource
    private MaterialUnitService materialUnitService;

    @Resource
    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("没有计量单位名称信息");
        }
        CompanyU8 companyU8=new CompanyU8();
        companyU8.setUCompanyCode(icsComputationUnit.getCompanyCode());
        companyU8=companyU8Service.getCompanyByU8CodeWarehouseCodeV(icsComputationUnit.getCompanyCode(),icsComputationUnit.getWarehosueCode());
        if(companyU8==null){
            return AjaxResult.error("货主不存在");
        }
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        warehouseCompany.setCompanyCode(companyU8.getCompanyCode());
        List<WarehouseCompany> list = warehouseCompanyService.getByDoamin(warehouseCompany);
        if (list == null || list.size() == 0) {
            return AjaxResult.error("系统中没有该货主:" + warehouseCompany.toString() + "  信息,请先录入货主信息!");
        }
        AjaxResult ajaxResult=new AjaxResult();
        for (WarehouseCompany item : list) {
            ajaxResult=saveUnitData(item,icsComputationUnit);
        }
        return ajaxResult;
    }
    public AjaxResult saveUnitData(WarehouseCompany item,ICScomputationUnitModel icsComputationUnit){
        MaterialUnit materialUnit=new MaterialUnit();
        materialUnit.setUnit(icsComputationUnit.getCComunitName());
        materialUnit.setWarehouseCode(item.getWarehouseCode());

        List<MaterialUnit> list=materialUnitService.getMaterialUnitByDoamin(materialUnit);
        if(list==null||list.size()==0){
            materialUnit.setCompanyCode(item.getCompanyCode());
            materialUnit.setCreatedBy(ShiroUtils.getUserName());
            materialUnit.setLastUpdatedBy(ShiroUtils.getUserName());
            materialUnitService.save(materialUnit);
        }
        return AjaxResult.success();
    }



}