MaterialAPIService.java
6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.huaheng.api.U8.Service;
import com.huaheng.api.U8.domain.ICSMaterialModel;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.DictService;
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.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.mapper.DictDataMapper;
import com.huaheng.pc.system.dict.service.IDictDataService;
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.*;
import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingLong;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
@Service
public class MaterialAPIService {
    @Autowired
    BasicDataApiService basicDataApiService;
    @Autowired
    private ICompanyService companyService;
    @Autowired
    IMaterialService materialService;
    @Resource
    private DictDataMapper dictDataMapper;
    @Autowired
    private IDictDataService dictDataService;
    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;
    @Transactional
    public AjaxResult ICSInventory(List<ICSMaterialModel> iCSInventorys)    {
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        AjaxResult ajaxResult = new AjaxResult();
        List<Material> materials=new ArrayList<>();
        List<DictData> dictData1s=new ArrayList<>();
        for(ICSMaterialModel iCSInventory:iCSInventorys) {
            CompanyWu companyWu=new CompanyWu();
            companyWu.setuCompanyCode(iCSInventory.getCompanyCode());
            companyWu=companyService.selectCompanyWu(companyWu);
            if (companyWu == null) {
                return AjaxResult.error("货主不存在");
            }
            warehouseCompany.setCompanyCode(companyWu.getCompanyCode());
            List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
            if (list == null || list.size() == 0) {
                return AjaxResult.error("系统中没有该货主:" + warehouseCompany.toString() + "  信息,请先录入货主信息!");
            }
            //先查询货主对应的仓库,有几个仓库,就循环几次来添加。
            for (WarehouseCompany item : list) {
//            DictData dictData = new DictData();
//            dictData.setDictType("materialType");
//            dictData.setWarehouseCode(item.getWarehouseCode());
//            dictData.setDictValue(iCSInventory.getcInvCCode());
//            dictData.setDictLabel(iCSInventory.getcInvCName());
//            dictData.setEnable(true);
                Material material = new Material();
                material.setCode(iCSInventory.getcInvCode());
                material.setBarcode(iCSInventory.getcInvAddCode());
                material.setName(iCSInventory.getcInvName());
                material.setUserDef1(iCSInventory.getcInvAddCode());
                material.setSpecification(iCSInventory.getcInvStd());
                material.setMasterUnit(iCSInventory.getcComUnitName());
                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());
                Material mr=new Material();
                mr.setCode(material.getCode());
                mr.setWarehouseCode(material.getWarehouseCode());
                if(materialService.selectFirstEntity(mr)==null) {
                    materials.add(material);
                }
                //字典
                boolean result = dictData1s.stream().anyMatch(x -> x.getDictValue().equals(material.getType()) &&
                                                                    x.getDictType().equals("materialType") &&
                                                                    x.getWarehouseCode().equals(material.getWarehouseCode())) ;
                if (result == false)   {
                    DictData dictData=new DictData();
                    dictData.setHeaderId(17);
                    dictData.setWarehouseId(material.getWarehouseId());
                    dictData.setWarehouseCode(material.getWarehouseCode());
                    dictData.setDictValue(material.getType());
                    dictData.setDictLabel(material.getDictLabel());
                    dictData.setDictType("materialType");
                    dictData.setCreateBy(ShiroUtils.getLoginName());
                    DictData dd=new DictData();
                    dd.setWarehouseCode(dictData.getWarehouseCode());
                    dd.setDictType(dictData.getDictType());
                    dd.setDictValue(dictData.getDictValue());
                    dd=dictDataService.selectModel(dd);
                    if(dd==null) {
                        dictData1s.add(dictData);
                    }
                }
            }
        }
        if(materials.size()>0) {
            materialService.insertList(materials);
        }
        if(dictData1s.size()>0) {
            dictDataMapper.insertDictDatas(dictData1s);
        }
        return AjaxResult.success("成功");
    }
}