SupplierAPIService.java 5.26 KB
package com.huaheng.api.U8.Service;

import com.huaheng.api.U8.domain.ICSVendorModel;
import com.huaheng.api.general.Controller.BasicDataApi;
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.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.general.supplier.domain.Supplier;
import com.huaheng.pc.general.supplier.service.ISupplierService;
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 SupplierAPIService {

    @Autowired
    ISupplierService iSupplierService;

    @Autowired
    BasicDataApiService basicDataApiService;
    @Autowired
    private ICompanyService companyService;


    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;

    @Transactional
    public AjaxResult ICSVendor(ICSVendorModel icsVendor) {
        if(StringUtils.isEmpty(icsVendor.getCompanyCode())){
            return AjaxResult.error("没有货主信息");
        }
        CompanyWu companyWu=new CompanyWu();
        companyWu.setuCompanyCode(icsVendor.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) {
                Supplier supplier = new Supplier();
                supplier.setWarehouseId(item.getWarehouseId());
                supplier.setWarehouseCode(item.getWarehouseCode());
                supplier.setCode(icsVendor.getcVenCode());
                supplier.setName(icsVendor.getcVenName());
                supplier.setPhoneNum(icsVendor.getcVenPerson());
                supplier.setMobile(icsVendor.getcVenHand());
                supplier.setUserDef1(icsVendor.getIsShipComp());
                supplier.setCreated(new Date());
                supplier.setCreatedBy(ShiroUtils.getLoginName());
                supplier.setLastUpdated(new Date());
                supplier.setLastUpdatedBy(ShiroUtils.getLoginName());
                ajaxResult = basicDataApiService.supplier(supplier);
        }
        return ajaxResult;
    }


//        int result;
//        //查询货主有几个仓库,就新增几次
//        for (WarehouseCompany item:list) {
//            //判断系统中是否有该供应商,若有则更新,无则新增
//            if (iSupplierService.selectcode(icsVendor.getcVenCode()) == null){
//                Supplier supplier = new Supplier();
//                supplier.setWarehouseId(item.getWarehouseId());
//                supplier.setWarehouseCode(item.getWarehouseCode());
//                supplier.setCode(icsVendor.getcVenCode());
//                supplier.setName(icsVendor.getcVenName());
//                supplier.setPhoneNum(icsVendor.getcVenPerson());
//                supplier.setMobile(icsVendor.getcVenHand());
//                supplier.setUserDef1(icsVendor.getIsShipComp());
//                supplier.setCreated(new Date());
//                supplier.setCreatedBy(ShiroUtils.getLoginName());
//                result = iSupplierService.insert(supplier);
//                if (result < 1){
//                    return AjaxResult.success("新增供应商失败!");
//                }else {
//                    return AjaxResult.success("新增供应商成功!");
//                }
//            }else {
//                Supplier supplier = new Supplier();
//                supplier.setWarehouseId(item.getWarehouseId());
//                supplier.setWarehouseCode(item.getWarehouseCode());
//                supplier.setCode(icsVendor.getcVenCode());
//                supplier.setName(icsVendor.getcVenName());
//                supplier.setPhoneNum(icsVendor.getcVenPerson());
//                supplier.setMobile(icsVendor.getcVenHand());
//                supplier.setUserDef1(icsVendor.getIsShipComp());
//                supplier.setLastUpdated(new Date());
//                supplier.setLastUpdatedBy(ShiroUtils.getLoginName());
//                result = iSupplierService.updateByModel(supplier);
//                if (result < 1){
//                    return AjaxResult.success("更新供应商失败!");
//                }else {
//                    return AjaxResult.success("更新供应商成功!");
//                }
//            }
}