admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
package com.yeshi.fanli.service.impl.msg;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.google.gson.Gson;
import com.yeshi.fanli.dto.msg.MsgCommonDTO;
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.exception.config.ConfigException;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.msg.MsgConfigService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class MsgConfigServiceImpl implements MsgConfigService {
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
 
    @Override
    public void addZhuShouMsg(MsgCommonDTO dto) throws ConfigException {
        Config value = configService.getConfig(KEY_ZHUSHOU);
        if (StringUtil.isNullOrEmpty(dto.getContent()) || StringUtil.isNullOrEmpty(dto.getParams())
                || dto.getShow() == null)
            throw new ConfigException(1, "参数不完整");
        if (value != null) {
            MsgCommonDTO old = new Gson().fromJson(value.getValue(), MsgCommonDTO.class);
            old.setStartTime(dto.getStartTime());
            old.setShow(dto.getShow());
            old.setParams(dto.getParams());
            old.setEndTime(dto.getEndTime());
            old.setContent(dto.getContent());
            if (!StringUtil.Md5(dto.getContent() + "#" + dto.getParams()).equalsIgnoreCase(old.getContentMd5())) {
                old.setUpdateTime(new Date());
            }
            Config cf = new Config();
            cf.setId(value.getId());
            cf.setValue(new Gson().toJson(old));
            configService.update(cf);
        } else {
            dto.setContentMd5(StringUtil.Md5(dto.getContent() + "#" + dto.getParams()));
            dto.setIcon("http://img.flqapp.com/resource/msg/icon_zhushou.png");
            dto.setTitle(Constant.systemCommonConfig.getProjectChineseName() + "小助手");
            dto.setUpdateTime(new Date());
            dto.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
            Config config = new Config();
            config.setCreatetime(System.currentTimeMillis() + "");
            config.setKey(KEY_ZHUSHOU);
            config.setName("消息-板栗快省小助手");
            config.setValue(new Gson().toJson(dto));
            configService.save(config);
        }
    }
 
    @Override
    public void addGuanXuanMsg(MsgCommonDTO dto) throws ConfigException {
        Config value = configService.getConfig(KEY_GUANXUAN);
        if (StringUtil.isNullOrEmpty(dto.getContent()) || StringUtil.isNullOrEmpty(dto.getParams())
                || dto.getShow() == null)
            throw new ConfigException(1, "参数不完整");
        if (value != null) {
            MsgCommonDTO old = new Gson().fromJson(value.getValue(), MsgCommonDTO.class);
            old.setStartTime(dto.getStartTime());
            old.setShow(dto.getShow());
            old.setParams(dto.getParams());
            old.setEndTime(dto.getEndTime());
            old.setContent(dto.getContent());
            if (!StringUtil.Md5(dto.getContent() + "#" + dto.getParams()).equalsIgnoreCase(old.getContentMd5())) {
                old.setUpdateTime(new Date());
            }
            Config cf = new Config();
            cf.setId(value.getId());
            cf.setValue(new Gson().toJson(old));
            configService.update(cf);
        } else {
            dto.setContentMd5(StringUtil.Md5(dto.getContent() + "#" + dto.getParams()));
            dto.setIcon("http://img.flqapp.com/resource/msg/icon_guanxuan.png");
            dto.setTitle("官宣任务");
            dto.setUpdateTime(new Date());
            dto.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
            Config config = new Config();
            config.setCreatetime(System.currentTimeMillis() + "");
            config.setKey(KEY_GUANXUAN);
            config.setName("消息-官宣任务");
            config.setValue(new Gson().toJson(dto));
            configService.save(config);
        }
    }
 
    @Override
    public MsgCommonDTO getZhuShouMsg() {
        Config value = configService.getConfig(KEY_ZHUSHOU);
        if (value == null)
            return null;
        return new Gson().fromJson(value.getValue(), MsgCommonDTO.class);
    }
 
    @Override
    public MsgCommonDTO getGuanXuanMsg() {
        Config value = configService.getConfig(KEY_GUANXUAN);
        if (value == null)
            return null;
        return new Gson().fromJson(value.getValue(), MsgCommonDTO.class);
    }
 
    @Override
    public void addNotifyMsg(MsgCommonDTO dto) throws ConfigException {
        Config value = configService.getConfig(KEY_NOTIFY);
        if (StringUtil.isNullOrEmpty(dto.getContent()) || StringUtil.isNullOrEmpty(dto.getParams())
                || dto.getShow() == null)
            throw new ConfigException(1, "参数不完整");
        if (value != null) {
            MsgCommonDTO old = new Gson().fromJson(value.getValue(), MsgCommonDTO.class);
            old.setStartTime(dto.getStartTime());
            old.setShow(dto.getShow());
            old.setParams(dto.getParams());
            old.setEndTime(dto.getEndTime());
            old.setContent(dto.getContent());
            if (!StringUtil.Md5(dto.getContent() + "#" + dto.getPicture() + "#" + dto.getParams())
                    .equalsIgnoreCase(old.getContentMd5())) {
                old.setUpdateTime(new Date());
            }
            old.setPicture(dto.getPicture());
            Config cf = new Config();
            cf.setId(value.getId());
            cf.setValue(new Gson().toJson(old));
            configService.update(cf);
        } else {
            dto.setContentMd5(StringUtil.Md5(dto.getContent() + "#" + dto.getPicture() + "#" + dto.getParams()));
            dto.setUpdateTime(new Date());
            Config config = new Config();
            config.setCreatetime(System.currentTimeMillis() + "");
            config.setKey(KEY_NOTIFY);
            config.setName("消息-大图通知");
            config.setValue(new Gson().toJson(dto));
            configService.save(config);
        }
    }
 
    @Override
    public MsgCommonDTO getNotifyMsg() {
        Config value = configService.getConfig(KEY_NOTIFY);
        if (value == null)
            return null;
        return new Gson().fromJson(value.getValue(), MsgCommonDTO.class);
    }
 
}