sgj
5 小时以前 67b2e6a3b7e4254be92e3ecbcd7b6e9f61b3aae3
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
246
package com.fzzy.appwx.manager;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.appwx.param.WeChatBaseParam;
import com.fzzy.appwx.util.WeChatUtil;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.constant.RespCodeEnum;
import com.fzzy.igds.data.IgdsBaseParam;
import com.fzzy.igds.data.PageResponse;
import com.fzzy.igds.domain.SnapReply;
import com.fzzy.igds.service.SnapReplyService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Date;
 
@Component
public class WeChatManager {
 
    @Autowired
    private WeChatUtil weChatUtil;
    @Autowired
    private ISysUserService sysUserService;
    @Resource
    private SnapReplyService snapReplyService;
 
 
    public String getOpenid(String code) {
        //根据code获取用户openid
        return weChatUtil.getOpenid(code);
    }
 
 
    public SysUser getUser(String openid) {
        //根据openid获取用户信息
        return sysUserService.selectUserByOpenId(openid);
    }
 
    //获取用户绑定信息
    public PageResponse<SysUser> getUserBindInfo(WeChatBaseParam param) {
        //判断参数
        if (null == param) {
            return new PageResponse<SysUser>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
        }
 
        SysUser user = null;
 
        //微信公众号
        if (StringUtils.isEmpty(param.getOpenid())) {
            return new PageResponse<SysUser>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
 
        }
        //根据openid查询用户是否已经绑定
        user = sysUserService.selectUserByOpenId(param.getOpenid());
        if (user == null) {
            return new PageResponse<SysUser>(RespCodeEnum.CODE_1008.getCode(), "业务数据返回为空");
 
        }
 
        Long deptId = user.getDeptId();
        if (deptId == null) {
            deptId = Long.valueOf(user.getCompanyId());
            user.setDeptId(deptId);
        }
        return new PageResponse(RespCodeEnum.CODE_0000.getCode(), "查询成功", user);
    }
 
    //绑定openId
    public PageResponse<String> bandOpenId(WeChatBaseParam param) {
 
        //判断参数
        if (null == param || StringUtils.isEmpty(param.getOpenid())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
 
        }
        if (StringUtils.isEmpty(param.getMobile())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "手机号为空,请填写");
 
        }
//        if (StringUtils.isEmpty(param.getMsgCode())) {
//            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码不能为空");
//
//        }
//
//        String code = (String) redisService.getCacheObject(WeChatConst.WX_MOBILE_CODE + param.getMobile());
//        if(StringUtils.isEmpty(code)){
//            res.put("code","1007");
//            res.put("msg","验证码已失效,请重新获取");
//            return res;
//        }
//        if(! code.equals(param.getMsgCode())){
//            res.put("code","1007");
//            res.put("msg","验证码错误");
//            return res;
//        }
 
        //根据手机号查看用户是否是系统用户
        SysUser user = sysUserService.selectUserByPhoneNumber(param.getMobile());
        if (user == null || StringUtils.isEmpty(user.getPhonenumber())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1006.getCode(), "手机号不在系统内,请联系管理员!");
        }
 
        //更新数据库,用户信息加入微信认证ID
        user.setOpenId(param.getOpenid());
        sysUserService.updateUserInfo(user);
 
//        redisService.deleteObject(WeChatConst.WX_MOBILE_CODE + param.getMobile());
 
        return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(), "请求成功");
 
    }
 
 
    //解绑openId
    public PageResponse<String> unBandOpenId(WeChatBaseParam param) {
 
        //判断参数
        if (null == param || StringUtils.isEmpty(param.getOpenid())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
 
        }
        if (StringUtils.isEmpty(param.getMobile())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "手机号为空,请填写");
        }
        if (StringUtils.isEmpty(param.getMsgCode())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码不能为空");
 
        }
 
//        String code = (String) redisService.getCacheObject(WeChatConst.WX_MOBILE_CODE + param.getMobile());
//        if(StringUtils.isEmpty(code)){
//            res.put("code","1007");
//            res.put("msg","验证码已失效,请重新获取");
//            return res;
//
//        }
//        if(! code.equals(param.getMsgCode())){
//            res.put("code","1007");
//            res.put("msg","验证码错误");
//            return res;
//        }
 
        //根据手机号查询用户是否已经绑定
        SysUser user = sysUserService.selectUserByPhoneNumber(param.getMobile());
        if (user == null || StringUtils.isEmpty(user.getPhonenumber())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1006.getCode(), "手机号不在系统内,请联系管理员!");
 
        }
 
        user.setOpenId("");
        sysUserService.updateUserInfo(user);
 
//        redisService.deleteObject(WeChatConst.WX_MOBILE_CODE + param.getMobile());
 
        return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(), "请求成功");
 
    }
 
    public PageResponse<Page<SnapReply>> getSnapReplyPage(WeChatBaseParam param) {
 
        if (null == param) {
            return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
        }
 
        SysUser user;
 
        //微信公众号
        if (StringUtils.isEmpty(param.getOpenid())) {
            return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
 
        }
        //根据openid查询用户是否已经绑定
        user = sysUserService.selectUserByOpenId(param.getOpenid());
        if (user == null) {
            return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_1006.getCode(), "尚未绑定服务,请先绑定!");
 
        }
        //分页拼接
        Page<SnapReply> page = new Page<>(param.getPageNo(), param.getPageSize());
        //查询参数组装
        IgdsBaseParam queryParam = new IgdsBaseParam();
        queryParam.setDeptId(String.valueOf(user.getDeptId()));
        queryParam.setCompanyId(user.getCompanyId());
        queryParam.setKey(Constant.YN_N);
        snapReplyService.listPage(page, queryParam);
        return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_0000.getCode(), "请求成功", page);
    }
 
    public PageResponse<SnapReply> getSnapReplyInfoById(WeChatBaseParam param) {
 
        //判断参数
        if (null == param || StringUtils.isEmpty(param.getId())) {
            return new PageResponse<SnapReply>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
 
        }
 
        SnapReply warn = snapReplyService.getById(param.getId());
        if (warn == null) {
            return new PageResponse<SnapReply>(RespCodeEnum.CODE_1007.getCode(), "未获取到该警告信息!");
 
        }
 
        return new PageResponse<SnapReply>(RespCodeEnum.CODE_0000.getCode(), "请求成功", warn);
 
    }
 
    public PageResponse<String> handleSnapReply(WeChatBaseParam param) {
 
        //判断参数
        if (null == param || StringUtils.isEmpty(param.getId())) {
            return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "参数不完整,请核查");
 
        }
 
        //处理时间
        Date date = new Date();
 
//        if(StringUtils.isEmpty(companyId)){
//            companyId = ShiroUtils.getLoginUserCompanyId();
//        }
        String info = (String) param.getRemark();
        String id = param.getId();
        String userName = param.getUserName();
 
        //告警处理
        SnapReply warn = snapReplyService.getById(id);
        if(Constant.YN_N.equals(warn.getIsHandle())){
            return new PageResponse<String>(RespCodeEnum.CODE_1008.getCode(), "改告警已处理,无需重复批复!");
        }
        warn.setId(id);
        warn.setUpdateBy(userName);
        warn.setUpdateTime(date);
        warn.setIsHandle(Constant.YN_Y);
        warn.setReplyText(info);
        warn.setDays(param.getDays());
        snapReplyService.updateData(warn);
 
        return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(), "请求成功");
 
    }
 
}