CustomerAPIService.java 3.09 KB
package com.huaheng.pc.u8.service;


import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
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.customer.domain.Customer;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;

import com.huaheng.pc.u8.domain.ICSCustomerModel;
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 CustomerAPIService {

//    @Autowired
//    ICustomerService iCustomerService;

    @Resource
    private WarehouseCompanyService warehouseCompanyService;

    @Autowired
    BasicDataApiService basicDataApiService;
    @Autowired
    private CompanyU8Service companyU8Service;

    @Transactional
    public AjaxResult ICSCustomer(ICSCustomerModel ICSCustomer) {
        if(StringUtils.isEmpty(ICSCustomer.getCompanyCode())){
            return AjaxResult.error("没有货主信息");
        }
        CompanyU8 companyWu=new CompanyU8();
        companyWu.setUCompanyCode(ICSCustomer.getCompanyCode());
        companyWu=companyU8Service.getCompanyByU8CodeWarehouseCodeV(ICSCustomer.getCompanyCode(),ICSCustomer.getWarehouseCode());
        if(companyWu==null){
            return AjaxResult.error("货主不存在");
        }
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        warehouseCompany.setCompanyCode(companyWu.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) {
                Customer customer = new Customer();
//                customer.setWarehouseId(item.getWarehouseId());
                customer.setWarehouseCode(item.getWarehouseCode());
                customer.setCompanyCode(item.getCompanyCode());
                customer.setCode(ICSCustomer.getcCusCode());
                customer.setName(ICSCustomer.getcCusName());
                customer.setAttentionTo(ICSCustomer.getcCusPerson());
                customer.setMobile(ICSCustomer.getcCusPhone());
                customer.setCreated(new Date());
                customer.setCreatedBy(ShiroUtils.getLoginName());
                customer.setLastUpdated(new Date());
                customer.setLastUpdatedBy(ShiroUtils.getLoginName());
                ajaxResult = basicDataApiService.customer(customer);

        }
        return ajaxResult;
    }
}