zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
commit | author | age
a18bfa 1 package com.changhong.epc.parsing.service.util.impl;
Z 2
3 import com.changhong.epc.bean.form.CpnVal;
4 import com.changhong.epc.bean.form.Fieldsets;
5 import com.changhong.epc.bean.form.FormBaseEntity;
6 import com.changhong.epc.bean.form.FormDataEntity;
7 import com.changhong.epc.bean.parsing.BillInfo;
8 import com.changhong.epc.bean.tenant.bill.OCRBillEntity;
9 import com.changhong.epc.bean.tenant.cost.CostType;
10 import com.changhong.epc.bean.tenant.cost.extend.CostFromMappingExtend;
11 import com.changhong.epc.bean.tenant.master.MasterEleValue;
12 import com.changhong.epc.bean.tenant.master.MasterValue;
13 import com.changhong.epc.constter.form.utf.FormUrlConst;
14 import com.changhong.epc.constter.system.SystemClients;
15 import com.changhong.epc.constter.system.businesscode.BusinessMeaningCode;
16 import com.changhong.epc.constter.system.run.EpcRestInterface;
17 import com.changhong.epc.constter.tenant.TenantUrlConst;
18 import com.changhong.epc.parsing.mapper.tenant.JourneyFormMapper;
19 import com.changhong.epc.parsing.service.util.IFromOperate;
20 import com.google.common.base.Objects;
21 import com.iemsoft.framework.cloud.core.base.ResMsg;
22 import com.iemsoft.framework.cloud.core.tools.JSONTool;
23 import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
24 import com.iemsoft.framework.cloud.core.tools.SpringUtil;
25 import com.iemsoft.framework.cloud.ribbon.RestInterface;
26 import org.springframework.stereotype.Service;
27
28 import javax.annotation.Resource;
29 import java.util.*;
30 import java.util.Map.Entry;
31
32 import static com.changhong.epc.constter.form.utf.FormUrlConst.FORM_DATA_SELECT_ONE;
33 import static com.changhong.epc.constter.form.utf.FormUrlConst.FORM_DATA_UPDATFORM;
34
35 //import org.apache.commons.collections.map.HashedMap;
36
37 @Service("fromOperate")
38 public class FromOperateImpl implements BusinessMeaningCode, SystemClients, IFromOperate {
39
40 //    private CpnVal subForm;
41
42     @Resource
43     private JourneyFormMapper journeyFormMapper;
44
45
46     public Object getFromRest(String fs, Object parm) {
47         RestInterface restInterface = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class);
48         Object data = restInterface.post(fs, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
49 //        // System.out.println("分配成功修改状态返回结果"+JSONTool.toJson(data));
50         return data;
51     }
52
53     public Object getTenantRest(String fs, Object parm) {
54         RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
55         Object data = restInterface.post(fs, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
56
57         return data;
58     }
59
60     @Override
61     public FormBaseEntity selectFromAll(BillInfo billInfo) {
62         Map<String, Object> parm = new HashMap<>();
63         parm.put("formId", billInfo.getFormId());
64         @SuppressWarnings("unchecked")
65         Map<String, Object> billDatas = JSONTool.toObj(billInfo.getInfo(), Map.class);
66         parm.put("tenantId", billDatas.get("tenantId"));
67
68         Object fromRest = getFromRest(FormUrlConst.FORM_PROPERTY_URL, parm);
69         FormBaseEntity formBase = JSONTool.toObj(JSONTool.toJson(fromRest), FormBaseEntity.class);
70         return formBase;
71     }
72
73     /**
74      * 将分配完的数据添加到子表单中
75      */
76     @Override
77     public Integer insertCpnVal(BillInfo billInfo, Map<CpnVal, List<List<CpnVal>>> data) {
78         Map<String, Object> parm = new HashMap<>();
79         CpnVal subForm = new CpnVal();
80         //分配完的行程插入到子表单中
81         List<List<CpnVal>> subFormVals = new ArrayList<>();
82         if(ObjectUtil.notEmpty(data)) {
83             for (Entry<CpnVal, List<List<CpnVal>>> serverDefine : data.entrySet()) {
84                 subForm = serverDefine.getKey();
85                 subFormVals = serverDefine.getValue();
86             }
87         }
88
89         List<Map<String, Object>> cpnVal = new ArrayList<>();
90         for (List<CpnVal> eachJoun : subFormVals) {
91             HashMap<String, Object> eachCpnVal = new HashMap<>();
92             eachCpnVal.put("PARENTDATAROWNUM", billInfo.getFormDataId());
93             for (CpnVal val : eachJoun) {
94                 eachCpnVal.put(val.getAlias(), val.getValCode());
95             }
96             cpnVal.add(eachCpnVal);
97         }
98         parm.put("formId", billInfo.getFormId());
99         parm.put("childAlias", subForm.getAlias());
100         parm.put("data", cpnVal);
101         getFromRest(FormUrlConst.FORM_DATA_INSERT, parm);
102         return null;
103     }
104
105     @Override
106     public List<Integer> insertCpnVal(BillInfo billInfo, CpnVal journeySubForm, List<List<CpnVal>> allJourneyCpn) {
107
108         CpnVal subForm = journeySubForm;
109         Map<String, Object> parm = new HashMap<>();
110
111         List<Map<String, Object>> cpnVal = new ArrayList<>();
112         if(ObjectUtil.notEmpty(allJourneyCpn)) {
113             for (List<CpnVal> eachJoun : allJourneyCpn) {
114                 HashMap<String, Object> eachCpnVal = new HashMap<>();
115                 eachCpnVal.put("PARENTDATAROWNUM", billInfo.getFormDataId());
116                 for (CpnVal val : eachJoun) {
117                     eachCpnVal.put(val.getAlias(), val.getValCode());
118                 }
119                 cpnVal.add(eachCpnVal);
120             }
121         }
122         parm.put("formId", billInfo.getFormId());
123         parm.put("tenantId", JSONTool.toObj(billInfo.getInfo(), Map.class).get("tenantId"));
124         parm.put("childAlias", subForm.getAlias());
125         parm.put("data", cpnVal);
126 //        JSONTool.toJson(parm);
127 //        // System.out.println("保存控件。。。");
128 //        // System.out.println(JSONTool.toJson(parm));
129         // System.out.println("最终添加子表单参数:" + JSONTool.toJson(parm));
130         Object fromRest = getFromRest(FormUrlConst.FORM_DATA_INSERT, parm);
131         List<Map> resList = JSONTool.toList(JSONTool.toJson(fromRest), Map.class);
132         List<Integer> jIds = new ArrayList<>();
133         if(ObjectUtil.notEmpty(resList)) {
134             for (Map map : resList) {
135                 Object object = map.get("dataRowNum");
136                 jIds.add(Integer.valueOf(object.toString()));
137             }
138         }
139 //        // System.out.println("子表单新增数据后返回结果:+++++++++++++++++++++++++++++++++++++++++"+JSONTool.toJson(resList));
140 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
141 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
142 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
143 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
144 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
145 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
146 //        // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
147         // System.out.println("添加子表单返回:" + JSONTool.toJson(jIds));
148         return jIds;
149     }
150
151     @Override
152     public boolean updateCpnVal(BillInfo billInfo, Map<CpnVal, List<List<CpnVal>>> data) {
153         Integer row = 0;
154         if(ObjectUtil.empty(data)){
155             data = Collections.EMPTY_MAP;
156         }
157         for (Entry<CpnVal, List<List<CpnVal>>> forms : data.entrySet()) {
158             FormDataEntity formDataEntity = new FormDataEntity();
159             formDataEntity.setFormId(billInfo.getFormId());
160             List<Map<String, Object>> cpnValData = new ArrayList<>();
161             // 主控件
162             if (forms.getKey() == null) {
163                 formDataEntity.setDataRowNum(billInfo.getFormDataId());
164             }
165             if(ObjectUtil.notEmpty(forms.getValue())) {
166                 for (List<CpnVal> eachJoun : forms.getValue()) {
167                     Map<String, Object> eachCpnVal = new HashMap<>();
168                     formDataEntity.setChildAlias(forms.getKey().getAlias());
169                     eachJoun.stream().forEach(val -> setEachCpnVal(eachCpnVal, val));
170                     cpnValData.add(eachCpnVal);
171                 }
172             }
173             formDataEntity.setData(cpnValData);
174
175             Object fromRest = getFromRest(FormUrlConst.FORM_DATA_UPDATE, formDataEntity);
176             row += (int) fromRest;
177
178         }
179         return row > 0 ? true : false;
180
181     }
182
183     public void setEachCpnVal(Map<String, Object> eachCpnVal, CpnVal val){
184         eachCpnVal.put(val.getAlias(), val.getValCode());
185         if (Objects.equal("dataRowNum", val.getAlias())) {
186             eachCpnVal.put("PARENTDATAROWNUM", val.getValCode());
187         }
188     }
189
190
191     @Override
192     public Boolean deleteFormData(BillInfo billInfo, CpnVal subForm) {
193         Map<String, Object> parm = new HashMap<>();
194         parm.put("formId", billInfo.getFormId());
195         parm.put("childAlias", subForm.getAlias());
196         parm.put("dataRowNum", billInfo.getFormDataId());
197         parm.put("tenantId", JSONTool.toObj(billInfo.getInfo(), Map.class).get("tenantId"));
198         try {
199             getFromRest(FormUrlConst.FORM_DATA_URL, parm);
200         } catch (Exception e) {
201             return false;
202         }
203
204         return true;
205     }
206
207 //    @Override
208 //    public void setJourneySubForm(CpnVal journeySubForm) {
209 //        subForm = journeySubForm;
210 //    }
211
212
213     @Override
214     public Map<CpnVal, List<Map>> selectfromDataAll(BillInfo billInfo, Fieldsets fieldsets) {
215         Map<CpnVal, List<Map>> data = new HashMap<>();
216
217         Map<String, Object> dataKeyVal = new HashMap<>();
218
219
220         FormDataEntity parm = new FormDataEntity();
221         parm.setFormId(billInfo.getFormId());
222 //        parm.setChildAlias(JOURNEY_SUB);
223         parm.setDataRowNum(billInfo.getFormDataId());
224         @SuppressWarnings("unchecked")
225         Map<String, Object> billDatas = JSONTool.toObj(billInfo.getInfo(), Map.class);
226         parm.setTenantId(billDatas.get("tenantId").toString());
227
228         // System.out.println(JSONTool.toJson(parm));
229         Object fromRest = getFromRest(FormUrlConst.FORM_DATA_SEARCH_LIST, parm);
230         List<Map> res = JSONTool.toList(JSONTool.toJson(fromRest), Map.class);
231         data.put(null, res);
232         for (CpnVal group : fieldsets.getSubform().keySet()) {
233             parm = new FormDataEntity();
234             parm.setFormId(billInfo.getFormId());
235             parm.setChildAlias(group.getAlias());
236             parm.setDataRowNum(billInfo.getFormDataId());
237             parm.setTenantId(billDatas.get("tenantId").toString());
238             fromRest = getFromRest(FormUrlConst.FORM_DATA_SEARCH_LIST, parm);
239             res = JSONTool.toList(JSONTool.toJson(fromRest), Map.class);
240             data.put(group, res);
241         }
242
243
244         return data;
245     }
246
247     @Override
248     public Integer getBillType(String formId) {
249         HashMap<String, Object> hashMap = new HashMap<>();
250         hashMap.put("fId", formId);
251         // Object postRest = getPostRestTen(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap);
252         Object postRest = null;
253         try {
254             RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
255             postRest = restInterface.post(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
256         } catch (Exception e) {
257             // System.err.println(e.getMessage());
258         }
259         CostFromMappingExtend obj = JSONTool.toObj(JSONTool.toJson(postRest), CostFromMappingExtend.class);
260
261         return obj.getCtId();
262
263     }
264
265     @Override
266     public void updateForm(Map<String, Object> data) {
267         Object fromRest = getFromRest(FormUrlConst.FORM_DATA_UPDATE2, data);
268         // System.out.println(fromRest);
269     }
270
271     @Override
272     public int updateFormStatus(BillInfo billInfo, Integer status) {
273         Map<String, Object> param = new HashMap<>();
274         param.put("formID", billInfo.getFormId());
275         param.put("dataRowNum", billInfo.getFormDataId());
276         param.put("status", status);
277         param.put("tenantID", billInfo.getFormDataId());
278         getFromRest(FormUrlConst.FORM_STATUS, param);
279         return 0;
280     }
281
282     @Override
283     public FormBaseEntity selectFromAll(OCRBillEntity OCRBillEntity) {
284         Map<String, Object> parm = new HashMap<>();
285         parm.put("formId", OCRBillEntity.getFormId());
286         parm.put("tenantId", OCRBillEntity.getTenantId());
287
288         Object fromRest = getFromRest(FormUrlConst.FORM_PROPERTY_URL, parm);
289         FormBaseEntity formBase = JSONTool.toObj(JSONTool.toJson(fromRest), FormBaseEntity.class);
290         return formBase;
291     }
292
293     @Override
294     public MasterValue billValToCode(MasterEleValue masterEleValue) {
295         Object fromRest = getTenantRest(TenantUrlConst.REST_TENANT_MASTERVALUE_GETCODE, masterEleValue);
296         MasterValue masterValue = JSONTool.toObj(JSONTool.toJson(fromRest), MasterValue.class);
297         return masterValue;
298     }
299
300     @Override
301     public int updateFormStatusTe(BillInfo billInfo, Integer status, Integer tenantId) {
302         Map<String, Object> param = new HashMap<>();
303         param.put("formID", billInfo.getFormId());
304         param.put("dataRowNum", billInfo.getFormDataId());
305         param.put("status", status);
306         param.put("tenantID", tenantId);
307
308         getFromRest(FormUrlConst.FORM_STATUS, param);
309         return 0;
310     }
311
312     @Override
313     public Map<String, Object> selectFromData(BillInfo formData, Fieldsets fieldsets, OCRBillEntity oCRBillEntity) {
314         FormDataEntity formDataEntity = new FormDataEntity();
315         formDataEntity.setFormId(formData.getFormId());
316         formDataEntity.setDataRowNum(formData.getFormDataId());
317         formDataEntity.setChildAliaList(
318                 new ArrayList<>(fieldsets.getSubform() == null
319                         ? Collections.emptyList() :
320                         Arrays.asList(fieldsets.getSubform().keySet().stream().map(cpnVal -> cpnVal.getAlias()).toArray(String[]::new))
321                 ));
322         formDataEntity.setTenantId(java.util.Objects.toString(oCRBillEntity.getTenantId()));
323         return (Map<String, Object>) getFromRest(FORM_DATA_SELECT_ONE, formDataEntity);
324     }
325
326     @Override
327     public int updateFormStatus(String formId, String tenangId, String dataRowNum, Integer status) {
328         Map<String, Object> param = new HashMap<>();
329         param.put("formID", formId);
330         param.put("dataRowNum", dataRowNum);
331         param.put("status", status);
332         param.put("tenantID", tenangId);
333         getFromRest(FormUrlConst.FORM_STATUS, param);
334         return 0;
335     }
336
337     /**
338      * 修改表单数据
339      *
340      * @param formDataEntity
341      */
342     @Override
343     public void updateFormData(FormDataEntity formDataEntity) {
344         getFromRest(FORM_DATA_UPDATFORM, formDataEntity);
345     }
346
347     @Override
348     public Map<String, Object> selectSign(String formId, String tenangId, Integer dataRowNum) {
349         FormDataEntity formDataEntity = new FormDataEntity(formId,dataRowNum,tenangId);
350         return (Map<String, Object>) getFromRest(FORM_DATA_SELECT_ONE, formDataEntity);
351     }
352
353     @Override
354     public List<Map> selectSubList(String formId, String tenangId, Integer dataRowNum, String alias) {
355         FormDataEntity formDataEntity = new FormDataEntity(formId,dataRowNum,tenangId);
356         formDataEntity.setChildAlias(alias);
357         return JSONTool.toList(JSONTool.toJson(getFromRest(FormUrlConst.FORM_DATA_SEARCH_LIST, formDataEntity)),Map.class);
358
359     }
360
361     @Override
362     public String getCostCode(Integer ctId) {
363         CostType cost = new CostType();
364         cost.setId(ctId);
365         Object res = getTenantRest(TenantUrlConst.REST_TENANT_COSTTYPE_ONE, cost);
366         cost = JSONTool.toObj(JSONTool.toJson(res),CostType.class);
367         return cost.getOrderTypeCode();
368     }
369 }