Blame view

src/main/java/com/huaheng/pc/u8/service/MaterialAPIService.java 5.43 KB
周鸿 authored
1
2
package com.huaheng.pc.u8.service;
3
import com.huaheng.common.constant.QuantityConstant;
周鸿 authored
4
import com.huaheng.common.utils.StringUtils;
周鸿 authored
5
6
7
8
9
10
11
12
13
14
15
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.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;

import com.huaheng.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;
周鸿 authored
16
周鸿 authored
17
18
19
20
21
22
23
24
25
26
27
import com.huaheng.pc.u8.domain.ICSMaterialModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
public class MaterialAPIService {
周鸿 authored
28
周鸿 authored
29
30
31
32
    @Resource
    private CompanyU8Service companyU8Service;
    @Resource
    MaterialService materialService;
周鸿 authored
33
周鸿 authored
34
35
36
37
38
39
40
41
42
43
44
45
    @Resource
    private WarehouseCompanyService warehouseCompanyService;
    @Resource
    private MaterialTypeService materialTypeService;

    @Transactional
    public AjaxResult ICSInventory(List<ICSMaterialModel> iCSInventorys)    {
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        AjaxResult ajaxResult = new AjaxResult();
        List<Material> materials=new ArrayList<>();
        List<MaterialType> materialTypeList=new ArrayList<>();
        for(ICSMaterialModel iCSInventory:iCSInventorys) {
周鸿 authored
46
47
48
49
            String warehouseCode=iCSInventory.getWarehouseCode();
            if(StringUtils.isEmpty(warehouseCode)){
                return AjaxResult.error("仓库code不存在");
            }
周鸿 authored
50
51
            CompanyU8 companyWu=new CompanyU8();
            companyWu.setUCompanyCode(iCSInventory.getCompanyCode());
周鸿 authored
52
            companyWu=companyU8Service.getCompanyByU8CodeWarehouseCodeV(iCSInventory.getCompanyCode(),warehouseCode);
周鸿 authored
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
            if (companyWu == null) {
                return AjaxResult.error("货主不存在");
            }
            warehouseCompany.setCompanyCode(companyWu.getCompanyCode());
            List<WarehouseCompany> list = warehouseCompanyService.getByDoamin(warehouseCompany);
            if (list == null || list.size() == 0) {
                return AjaxResult.error("系统中没有该货主:" + warehouseCompany.toString() + "  信息,请先录入货主信息!");
            }
            //先查询货主对应的仓库,有几个仓库,就循环几次来添加。
            for (WarehouseCompany item : list) {
                Material material = new Material();
                material.setCode(iCSInventory.getcInvCode());
                material.setBarcode(iCSInventory.getcInvAddCode());
                material.setName(iCSInventory.getcInvName());
                material.setUserDef1(iCSInventory.getcInvAddCode());
                material.setSpec(iCSInventory.getcInvStd());
                material.setUnit(iCSInventory.getcComUnitName());
70
                material.setWarehouseCode(companyWu.getWarehouseCode());
周鸿 authored
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//                material.setAssistUnit(iCSInventory.getcAssComUnitCode());
//                material.setConvertRate(iCSInventory.getfConvertRate());
                material.setType(iCSInventory.getcInvCCode());
//                material.setDictLabel(iCSInventory.getcInvCName());
//                material.setCompanyId(item.getCompanyId());
                material.setCompanyCode(item.getCompanyCode());
//                material.setWarehouseId(item.getWarehouseId());
                material.setWarehouseCode(item.getWarehouseCode());
                material.setLastUpdatedBy(ShiroUtils.getLoginName());
                material.setCreatedBy(ShiroUtils.getLoginName());

                if(materialService.getMaterialByCode(material.getCode(),material.getWarehouseCode())==null) {
                    materials.add(material);
                }
                //查找MaterialType有无该数据
                MaterialType materialType=new MaterialType();
                materialType.setCode(material.getType());
                materialType.setWarehouseCode(material.getWarehouseCode());
                List<MaterialType> materialTypelist=materialTypeService.getMaterialTypeByDoamin(materialType);

                if(materialTypelist==null||materialTypelist.size()==0){
                    MaterialType materialType1=createMaterialType(material, iCSInventory);
                    materialTypeList.add(materialType1);
                }
            }
        }
        if(materials.size()>0) {
            materialService.saveBatch(materials);
        }
        if(materialTypeList.size()>0) {
            materialTypeService.saveBatch(materialTypeList);
        }
        return AjaxResult.success("成功");
    }

    public MaterialType createMaterialType(Material material,ICSMaterialModel iCSInventory){
        MaterialType materialType=new MaterialType();
        materialType.setCode(material.getType());
        materialType.setWarehouseCode(material.getWarehouseCode());
        materialType.setName(iCSInventory.getcInvCName());
        materialType.setCompanyCode(material.getCompanyCode());
        materialType.setCreatedBy(ShiroUtils.getUserName());
        materialType.setLastUpdatedBy(ShiroUtils.getUserName());
        return materialType;
    }



}