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
package com.changhong.epc.parsing.service.loop.impl;
 
import com.changhong.epc.bean.parsing.BillInfo;
import com.changhong.epc.bean.parsing.RuleMsgColumn;
import com.changhong.epc.bean.tenant.bill.RuleCheckMsg;
import com.changhong.epc.bean.tenant.bill.RuleMsg;
import com.changhong.epc.bean.tenant.bill.RuleMsgExtend;
import com.changhong.epc.bean.tenant.master.MasterValue;
import com.changhong.epc.constter.parsing.ConstRuleMsg;
import com.changhong.epc.constter.system.SystemClients;
import com.changhong.epc.parsing.mapper.tenant.BillInfoMapper;
import com.changhong.epc.parsing.mapper.tenant.RuleCheckMsgMapper;
import com.changhong.epc.parsing.mapper.tenant.RuleMapper;
import com.changhong.epc.parsing.mapper.tenant.RuleMsgMapper;
import com.changhong.epc.parsing.service.loop.IRuleMsgHandService;
import com.changhong.epc.rely.api.epc.admin.CorresElFieldApi;
import com.changhong.epc.rely.api.epc.tenant.MasterApi;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
 
/**
 * 
 * @ClassName: RuleMsgHandServiceImpl
 * @author [九鼎联合科技]
 * @date 2017年6月19日 下午6:36:15
 */
@Component("ruleMsgHandService")
@Slf4j
public class RuleMsgHandServiceImpl extends LoopSuper implements SystemClients, IRuleMsgHandService, ConstRuleMsg {
    
    @Resource
    private RuleMsgMapper ruleMsgMapper;
    
    @Resource
    private RuleMapper ruleMapper;
    
    @Resource
    private BillInfoMapper billInfoMapper;
    
    @Resource
    private RuleCheckMsgMapper ruleCheckMsgMapper;
 
    @Override
    public String getThreadName() {
        return "解析规则检查服务";
    }
 
    @Override
    public void businessHandle() {
        Manager();
    }
 
    /**
     * 取出te_bill_check_msg表规则信息的json字符串数据 解析 
     * void 返回类型 @throws
     */
    private void Manager() {
        insertRuleMsg(ruleCheckMsgMapper.selectUntreatedRuleCheckMsg());
}
    
    /**
     * 传入json字符串集合解析存入rule_msg数据表 @Title: insertRuleMsg @param @param rcmList
     * 设定文件 @return void 返回类型 @throws
     */
    public void insertRuleMsg(List<RuleCheckMsg> rcmList) {
        if(ObjectUtil.empty(rcmList)){
            return;
        }
        for (RuleCheckMsg rcm : rcmList) {
            log.debug("----------------开始解析规则检查结果--------------");
            BillInfo billInfo = billInfoMapper.selectByOrderCode(rcm.getOrderCode());
            if(billInfo == null ||billInfo.getInfo() == null || Objects.equals("",billInfo.getInfo())){
                log.debug("当前订单号:-->"+rcm.getOrderCode());
                log.debug("当前不可规则检查-->"+ JSONTool.toJson(billInfo));
                continue;
            }
            RuleMsg t = new RuleMsg();
            t.setCouldNumber(rcm.getOrderCode());
            ruleMapper.delete(t);
            /*将解析后的数据添加到rule_msg表中*/
            RuleMsgExtend rList = JSONTool.toObj(rcm.getMsg(), RuleMsgExtend.class);
            Optional.ofNullable(rList)
                    .map(RuleMsgExtend::getCheckResultList)
                    .orElse(new ArrayList<>())
                    .stream().forEach(rl ->{
                        RuleMsg ruleMsg = new RuleMsg();
                        ruleMsg.setResult(rl.getResult());
                        ruleMsg.setBillCode(rl.getBillCode());
                        ruleMsg.setCouldNumber(rList.getOrderCode());
                        ruleMsg.setRulecode(rl.getRulecode());
                        ruleMsg.setRulename(rl.getRulename());
                        ruleMsg.setLevel(getLevel(rl.getRulecode()));
                        ruleMsg.setType(RU_TYPE3);
                        ruleMsg.setStatus(RU_STATUS1);
                        ruleMsg.initParam();
                        ruleMapper.insert(ruleMsg);
 
                    });
            /*将原始检查票据表状态更新*/
            rcm.setDataStart(99);
            ruleCheckMsgMapper.updateByPrimaryKey(rcm);
            log.debug("修改订单标号为" + rList.getOrderCode() + "的状态为可分配行程状态");
            //修改票据状态
            billInfoMapper.updateBillState(rList.getOrderCode());
        }
    }
            
    /**
     * 获取错误级别level,code错误则默认level等级为10 @Title: getLevel @param @param
     * code @param @return 设定文件 @return int 返回类型 @throws
     */
    @SuppressWarnings("unchecked")
    public int getLevel(String code) {
        String mdCode = SpringUtil.getBean(CorresElFieldApi.class).getCorresElField(RULE_MSG_MDCODE).getMdCode();
 
        MasterValue masterValue = SpringUtil.getBean(MasterApi.class).getMasterVal(mdCode, code);
        if(!ObjectUtil.notEmpty(masterValue) && !ObjectUtil.notEmpty(masterValue.getEleValue())){
            return NumberUtils.createInteger(masterValue.getEleValue());
        }else{
            return LEVEL_10;
        }
    }
 
    @Override
    public void insertRuleMsg(RuleMsgColumn ruleMsg) {
        // TODO Auto-generated method stub
        
    }
 
    @Override
    public void Manager(RuleCheckMsg ruleCheckMsg) {
        // TODO Auto-generated method stub
        
    }
 
    
}