wuxw
2022-07-19 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54
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
package com.java110.common.listener.msg;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.common.dao.IMsgServiceDao;
import com.java110.entity.center.Business;
import com.java110.core.event.service.AbstractBusinessServiceDataFlowListener;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.constant.StatusConstant;
import com.java110.utils.exception.ListenerExecuteException;
import org.slf4j.Logger;
import com.java110.core.log.LoggerFactory;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 消息 服务侦听 父类
 * Created by wuxw on 2018/7/4.
 */
public abstract class AbstractMsgBusinessServiceDataFlowListener extends AbstractBusinessServiceDataFlowListener {
    private static Logger logger = LoggerFactory.getLogger(AbstractMsgBusinessServiceDataFlowListener.class);
 
 
    /**
     * 获取 DAO工具类
     *
     * @return
     */
    public abstract IMsgServiceDao getMsgServiceDaoImpl();
 
    /**
     * 刷新 businessMsgInfo 数据
     * 主要将 数据库 中字段和 接口传递字段建立关系
     *
     * @param businessMsgInfo
     */
    protected void flushBusinessMsgInfo(Map businessMsgInfo, String statusCd) {
        businessMsgInfo.put("newBId", businessMsgInfo.get("b_id"));
        businessMsgInfo.put("msgType", businessMsgInfo.get("msg_type"));
        businessMsgInfo.put("operate", businessMsgInfo.get("operate"));
        businessMsgInfo.put("msgId", businessMsgInfo.get("msg_id"));
        businessMsgInfo.put("viewObjId", businessMsgInfo.get("view_obj_id"));
        businessMsgInfo.put("title", businessMsgInfo.get("title"));
        businessMsgInfo.put("viewTypeCd", businessMsgInfo.get("view_type_cd"));
        businessMsgInfo.put("url", businessMsgInfo.get("url"));
        businessMsgInfo.remove("bId");
        businessMsgInfo.put("statusCd", statusCd);
    }
 
 
    /**
     * 当修改数据时,查询instance表中的数据 自动保存删除数据到business中
     *
     * @param businessMsg 消息信息
     */
    protected void autoSaveDelBusinessMsg(Business business, JSONObject businessMsg) {
//自动插入DEL
        Map info = new HashMap();
        info.put("msgId", businessMsg.getString("msgId"));
        info.put("statusCd", StatusConstant.STATUS_CD_VALID);
        List<Map> currentMsgInfos = getMsgServiceDaoImpl().getMsgInfo(info);
        if (currentMsgInfos == null || currentMsgInfos.size() != 1) {
            throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR, "未找到需要修改数据信息,入参错误或数据有问题,请检查" + info);
        }
 
        Map currentMsgInfo = currentMsgInfos.get(0);
 
        currentMsgInfo.put("bId", business.getbId());
 
        currentMsgInfo.put("msgType", currentMsgInfo.get("msg_type"));
        currentMsgInfo.put("operate", currentMsgInfo.get("operate"));
        currentMsgInfo.put("msgId", currentMsgInfo.get("msg_id"));
        currentMsgInfo.put("viewObjId", currentMsgInfo.get("view_obj_id"));
        currentMsgInfo.put("title", currentMsgInfo.get("title"));
        currentMsgInfo.put("viewTypeCd", currentMsgInfo.get("view_type_cd"));
        currentMsgInfo.put("url", currentMsgInfo.get("url"));
 
 
        currentMsgInfo.put("operate", StatusConstant.OPERATE_DEL);
        getMsgServiceDaoImpl().saveBusinessMsgInfo(currentMsgInfo);
        for (Object key : currentMsgInfo.keySet()) {
            if (businessMsg.get(key) == null) {
                businessMsg.put(key.toString(), currentMsgInfo.get(key));
            }
        }
    }
 
 
}