zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package com.changhong.epc.form.execute.impl;
 
import com.changhong.autoform.entity.ProcessBudget;
import com.changhong.epc.bean.admin.extend.CorresElFieldExtendFind;
import com.changhong.epc.bean.form.*;
import com.changhong.epc.bean.tenant.cost.budgetlog.IBillCostLog;
import com.changhong.epc.bean.tenant.cost.budgetlog.MoneyExpendLog;
import com.changhong.epc.bean.tenant.cost.extend.CostFromMappingExtend;
import com.changhong.epc.constter.admin.AdminUrlConst;
import com.changhong.epc.constter.system.SystemClients;
import com.changhong.epc.constter.system.businesscode.BudgetBusinessMeaningCode;
import com.changhong.epc.constter.system.run.EpcRestInterface;
import com.changhong.epc.constter.tenant.TenantUrlConst;
import com.changhong.epc.form.execute.BudgetRecord.BudgetMoney;
import com.changhong.epc.form.execute.IFormOthersOperation;
import com.changhong.epc.form.service.budget.impl.RecordLog;
import com.changhong.epc.form.service.data.FormDataService;
import com.changhong.epc.form.service.field.FormFieldService;
import com.changhong.epc.form.tool.FormNameTool;
import com.iemsoft.framework.cloud.core.base.ResMsg;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import com.iemsoft.framework.cloud.ribbon.RestInterface;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * 回写预算需要 依赖的相关资源
 * @author wangZX
 *
 */
@Service("formOthersOperation")
public class FormOthersOperationImpl implements IFormOthersOperation, SystemClients, BudgetBusinessMeaningCode{
    private ConstantMdCode constantMdCode = new ConstantMdCode();
    
    @Resource
    private FormFieldService formFieldService;
    
    @Resource
    private FormDataService formDataService; 
    
    @Override
    public FormType getBillType(ProcessBudget processBudget) {
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("fId", processBudget.getFormId());
        // Object postRest = getPostRestTen(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap);
        Object postRest = null;
        try {
            RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
            postRest = restInterface.post(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
        } catch (Exception e) {
            //e.printStackTrace();
        }
        //CostFromMappingExtend obj = JSONTool.toObj(JSONTool.toJson(postRest), CostFromMappingExtend.class);
        
        // return FormType.valueOf(obj.getType());
        return FormType.YS;
        
    }
 
 
    @Override
    public String getBillCostType(ProcessBudget processBudget) {
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("fId", processBudget.getFormId());
    //     Object postRest = getPostRestTen(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap);
        
        Object data = null;
        try {
            RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
            data = restInterface.post(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
        } catch (Exception e) {
        }
        
        CostFromMappingExtend obj = JSONTool.toObj(JSONTool.toJson(data), CostFromMappingExtend.class);
        //如果是根目录直接返回费用类型名称  --lym
        return obj.getCostType().getNodeName();
    }
    
    @Override
    public void updateFormFieldProperty(ProcessBudget processBudget, BudgetMoney data) {
        /**
         * 记录日志
         */
        RecordLog.recordFormUpdateLog(FormType.valueOf(processBudget.getFormType()), modelBillCostLog(processBudget, data));
        
        Map<String,Object> param = new HashMap<>();
        param.put(data.alias, data.money);
        FormDataEntity formData = new FormDataEntity();
        
        
        formData.setFormId(processBudget.getFormId());
        formData.setTenantId(processBudget.getTenantID());
        formData.setDataRowNum(processBudget.getDataRowNUm());
        formData.setChildAlias(processBudget.getAlias());
        
        List<Map<String, Object>> arrayList = new ArrayList<>();
        arrayList.add(param);
        formData.setData(arrayList);
        formDataService.updateFormData(formData );
    }
    
    
    /**
     * 转换成日志实体 以便记录
     * @param processBudget
     * @param data
     * @return
     */
    private IBillCostLog modelBillCostLog(ProcessBudget processBudget, BudgetMoney data) {
        MoneyExpendLog moneyLog = new MoneyExpendLog();
        
        String formName = FormNameTool.getSubFormTableName(processBudget.getTenantID(), processBudget.getFormId(), processBudget.getAlias());
        moneyLog.setFormId(formName);
        moneyLog.setRowId(processBudget.getDataRowNUm());
        
        moneyLog.setOperatorMsg("回写预算");
        moneyLog.setAlterAlias(data.alias);
        
        moneyLog.setAlterContentOld(data.oldMoney.toString());
        moneyLog.setAlterContentNew(data.money.toString());
        
        return moneyLog;
    }
 
    @Transactional
    @Override
    public void updateFormFieldProperty(ProcessBudget processBudget,Map<String,Object> param ,FormType formType ,IBillCostLog IBillCostLog) {
    
        RecordLog.recordFormUpdateLog(formType,IBillCostLog);
        
        FormDataEntity formData = new FormDataEntity();
        
        formData.setFormId(processBudget.getFormId());
        formData.setTenantId(processBudget.getTenantID());
        formData.setDataRowNum(processBudget.getDataRowNUm());
        formData.setChildAlias(processBudget.getAlias());
        List<Map<String, Object>> arrayList = new ArrayList<>();
        arrayList.add(param);
        formData.setData(arrayList);
        formDataService.updateFormData(formData );
    }
 
    
    @Override
    public Object recordLog(Object log) {
        return null;
    }
 
    @Override
    public Map<String, Object> getFromInfo(ProcessBudget processBudget) {
        FormDataEntity formData = new FormDataEntity();
        formData.setFormId(processBudget.getFormId());
        formData.setChildAlias(processBudget.getAlias());
        formData.setDataRowNum(processBudget.getDataRowNUm());
        formData.setTenantId(processBudget.getTenantID());
        Map<String, Object> searchFormData = formDataService.searchFormData(formData );
        return searchFormData;
    }
    
    @Override
    public List<BugetSubForm> queryBudgetByCostTypeAndParentId(ProcessBudget processBudget,HashSet<String> costType) {
        FormDataEntity formData = new FormDataEntity();
        formData.setChildAlias(processBudget.getAlias());
        formData.setFormId(processBudget.getFormId());
        return formDataService.searchBudgetSubForm(formData, costType);
    
        
    }
    
    @Override
    public Fieldsets getFormFieldProperty(ProcessBudget processBudget) {
        FormKey formKey = new FormKey();
        formKey.setFormId(processBudget.getFormId());
        formKey.setTenantId(processBudget.getTenantID());
        formKey.setToken(processBudget.getToken());
        FormBaseEntity selectFormFieldProperty = formFieldService.selectFormFieldProperty(formKey);
        // System.err.println(JSONTool.toJson(selectFormFieldProperty));
        
        return formData(selectFormFieldProperty);
    }
 
    
    private Fieldsets formData(FormBaseEntity formBaseEntity) {
        return new Fieldsets(formBaseEntity);
    }
 
 
    @Override
    public String getMoneyCpnMdCode() {
        CorresElFieldExtendFind constEl = getConstEl();
        return constEl.findCode(BX_AMOUNT).getMdCode();
    }
 
    @Override
    public String getBudgetSumMoneyMdCode() {
        CorresElFieldExtendFind constEl = getConstEl();
        return constEl.findCode(YS_SUM_AMOUNT).getMdCode();
    }
 
    @Override
    public String getBudgetBalanceMdCode() {
        CorresElFieldExtendFind constEl = getConstEl();
        return constEl.findCode(YS_SURPLUS_AMOUNT).getMdCode();
    }
 
    @Override
    public String getMoneyAppleyMoneyMdCode() {
        CorresElFieldExtendFind constEl = getConstEl();
        return constEl.findCode(SQ_AMOUNT).getMdCode();
    }
    
    private static Map<String, Object> cache = new HashMap<>();
    
    public Object getPostRestTen(String url,Map<String,Object> parm){
        RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
        Object data = restInterface.post(url, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
        
        return data;
    }
    
    public CorresElFieldExtendFind getConstEl(){
        Object postRest = constantMdCode.getPostRest(AdminUrlConst.REST_ADMIN_CORRESELFIELD_SELECT, 
                new HashMap<>());
        return JSONTool.toObj(JSONTool.toJson(postRest), CorresElFieldExtendFind.class); 
    }
 
 
    @Override
    public Map<String, Object> selectFormDataInfo(ProcessBudget processBudget) {
        
        FormDataEntity formData = new FormDataEntity();
        formData.setChildAlias(processBudget.getAlias());
        formData.setFormId(processBudget.getFormId());
        formData.setDataRowNum(processBudget.getDataRowNUm());
        formData.setTenantId(processBudget.getTenantID());
        return formDataService.searchFormInfo(formData );
    }
 
 
    
}