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
package com.changhong.epc.count.controller;
 
import com.changhong.epc.bean.count.format.FormInfo;
import com.changhong.epc.bean.count.format.SystemFunFormInfo;
import com.changhong.epc.constter.base.BaseConst;
import com.changhong.epc.constter.count.nomr.CountUrlConst;
import com.changhong.epc.count.service.count.IExpendCostCount;
import com.changhong.epc.count.service.count.model.CountParamMax;
import com.changhong.epc.count.service.count.model.CountResultLast;
import com.changhong.epc.count.service.format.FormatFormInfo;
import com.changhong.epc.count.service.system.IExpendSystemCount;
import com.iemsoft.framework.cloud.core.thread.ThreadData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.Objects;
 
/**
 * 计算费用
 * @author wangZhenXin
 *
 */
@RestController
@Slf4j
public class CountController implements CountUrlConst{
    
    @Resource
    private IExpendCostCount expendCostCount;
    
    @Resource(name="formatXECount")
    private FormatFormInfo<CountParamMax, CountResultLast> formatFormInfoCount;
 
    @Resource
    private IExpendSystemCount iExpendSystemCount;
 
    /**
     * 系统变量
     * @param systemFunFormInfo
     * @return
     */
    @RequestMapping(value=COUNT_SYSTEM_URL, method={RequestMethod.OPTIONS, RequestMethod.POST})
    public FormInfo systemCount(@RequestBody SystemFunFormInfo systemFunFormInfo){
        ThreadData.set(BaseConst.FORMID,systemFunFormInfo.getFormInfo().getFormId());
        ThreadData.set(BaseConst.ORDER_CODE,systemFunFormInfo.getFormInfo().getOrderCode());
        ThreadData.set(BaseConst.DATA_ROW_NUM,systemFunFormInfo.getFormInfo().getId());
        return iExpendSystemCount.systemCount(systemFunFormInfo);
    }
 
    /**
     * 计算费用  
     * @param formInfo
     * @return
     */
    @RequestMapping(value=COUNT_COST_URL, method={RequestMethod.OPTIONS, RequestMethod.POST})
    public FormInfo costCount(@RequestBody FormInfo formInfo){
        try {
            ThreadData.set(BaseConst.FORMID, formInfo.getFormId());
            ThreadData.set(BaseConst.ORDER_CODE, formInfo.getOrderCode());
            ThreadData.set(BaseConst.DATA_ROW_NUM, Objects.toString(formInfo.getId()));
            //格式化参数
            CountParamMax p = formatFormInfoCount.formatParam(formInfo);
            //计算费用
            CountResultLast sun = expendCostCount.costCount(p);
            //格式化返回结果
            formatFormInfoCount.formatResult(formInfo, sun);
 
            return formInfo;
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return formInfo;
        }
    }
 
    /**
     * 计算费用和系统变量
     * @param systemFunFormInfo
     * @return
     */
    @RequestMapping(value=COUNT_AND_SYSTEM_COST_URL, method={RequestMethod.OPTIONS, RequestMethod.POST})
    public FormInfo countAndSystem(@RequestBody SystemFunFormInfo systemFunFormInfo){
        ThreadData.set(BaseConst.FORMID,systemFunFormInfo.getFormInfo().getFormId());
        ThreadData.set(BaseConst.ORDER_CODE,systemFunFormInfo.getFormInfo().getOrderCode());
        ThreadData.set(BaseConst.DATA_ROW_NUM,systemFunFormInfo.getFormInfo().getId());
        // 计算系统变量
        iExpendSystemCount.systemCount(systemFunFormInfo);
        // 计算费用
        formatFormInfoCount.formatResult(systemFunFormInfo.getFormInfo(), expendCostCount.costCount(formatFormInfoCount.formatParam(systemFunFormInfo.getFormInfo())));
        // 计算系统变量
        iExpendSystemCount.systemCount(systemFunFormInfo);
        return systemFunFormInfo.getFormInfo();
    }
 
}