sgj
6 小时以前 3a5e49666af1da441633b0a9bae4c3c2b18974b3
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
package com.fzzy.appwx.controller;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.appwx.constant.WeChatConst;
import com.fzzy.appwx.manager.WeChatManager;
import com.fzzy.appwx.param.WeChatBaseParam;
import com.fzzy.group.manager.GroupManager;
import com.fzzy.igds.data.ConfigData;
import com.fzzy.igds.data.PageResponse;
import com.fzzy.igds.domain.Dept;
import com.fzzy.igds.domain.SnapReply;
import com.ruoyi.common.core.domain.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
@Slf4j
@Controller
@RequestMapping("/wx")
public class WeChatController {
 
    @Resource
    private ConfigData configData;
    @Resource
    private WeChatManager weChatManager;
    @Resource
    private GroupManager groupManager;
 
 
    /**
     * 微信菜单重定向获取code
     *
     * @param tag
     * @return
     * @throws Exception
     */
    @RequestMapping
    public String redirect(
            @RequestParam(value = "tag", required = false) String tag) throws Exception {
 
        String url = configData.getWxServeUrl() + "/wx/view-gateway";
 
        if (StringUtils.isEmpty(tag)) {
            tag = "home";
        }
 
//        String newUrl = WeChatConst.USER_AUTH_UPR
//                .replace("APPID", configData.getWxAppId())
//                .replace("REDIRECT_URI", URLEncoder.encode(url, "UTF-8"))
//                .replace("STATE", tag);
//
//        return "redirect:" + newUrl;
        return "redirect:" + url + "?state=" + tag;
    }
 
 
    /**
     * 页面分发
     *
     * @param
     * @return
     */
    @RequestMapping("/view-gateway")
    public ModelAndView viewGateway(
            @RequestParam(value = "code", required = false) String code,
            @RequestParam(value = "state") String state,
            @RequestParam(value = "id", required = false) String id,
            @RequestParam(value = "companyId", required = false) String companyId,
            @RequestParam(value = "loginType", required = false) String loginType,
            @RequestParam(value = "userName", required = false) String userName) {
 
        ModelAndView mv = new ModelAndView();
 
        //code不为空则获取openid
        if (StringUtils.isNotEmpty(code)) {
            String openid = weChatManager.getOpenid(code);
            mv.addObject("openid", openid);
            SysUser user = weChatManager.getUser(openid);
            if (StringUtils.isEmpty(userName)) {
                if (user != null) {
                    userName = user.getUserName();
                }
            }
 
        }
 
        if (StringUtils.isNotEmpty(id)) {
            mv.addObject("id", id);
            mv.addObject("companyId", companyId);
        }
        //判断是公众号还是APP,默认为公众号
        if (StringUtils.isEmpty(loginType)) {
            loginType = WeChatConst.LOGIN_TYPE_WECHAT;
        }
        mv.addObject("loginType", loginType);
 
        if (StringUtils.isNotEmpty(userName)) {
            mv.addObject("userName", userName);
        }
        mv.setViewName("/wx/" + state);
        //验证码类型
        if("bind".equals( state) || "unbind".equals( state)){
            mv.addObject("captchaType", "math");
        }
 
 
        //查询库区信息
        List<Dept> deptList = groupManager.getDeptList();
        mv.addObject("deptList", deptList);
 
 
//        //测试代码开启
        String openid = "testOpenId";
        mv.addObject("openid", openid);
        SysUser user = weChatManager.getUser(openid);
        if (StringUtils.isEmpty(userName)) {
            if (user != null) {
                userName = user.getUserName();
            }
        }
 
        if (StringUtils.isNotEmpty(userName)) {
            mv.addObject("userName", userName);
        }
//        //测试代码结束
 
        return mv;
    }
 
 
    /**
     * 获取用户的绑定信息
     *
     * @param param
     * @author sgj
     * @since 2026/04/11
     */
    @PostMapping(value = "/getUserBindInfo")
    @ResponseBody
    public PageResponse<SysUser> getUserBindInfo(  @RequestBody WeChatBaseParam param) {
        return weChatManager.getUserBindInfo(param);
    }
 
 
    /**
     * 绑定openId
     *
     * @param param
     * @author sgj
     * @since 2026/04/11
     */
    @PostMapping(value = "/bandOpenId")
    @ResponseBody
    public PageResponse<String> bandOpenId(HttpServletRequest httpRequest,  @RequestBody WeChatBaseParam param) {
        return weChatManager.bandOpenId(httpRequest,param);
    }
 
    /**
     * 解绑openId
     *
     * @param param
     * @author sgj
     * @since 2026/04/11
     */
    @PostMapping(value = "/unBandOpenId")
    @ResponseBody
    public PageResponse<String> unBandOpenId( HttpServletRequest httpRequest, @RequestBody WeChatBaseParam param) {
        //在这里调用验证码校验
 
        return weChatManager.unBandOpenId(httpRequest,param);
    }
 
 
 
    /**
     * 获取出入库告警批复分页数据
     *
     * @param param
     * @author sgj
     * @since 2026/04/11
     */
    @PostMapping(value = "/getSnapReplyPage")
    @ResponseBody
    public PageResponse<Page<SnapReply>> getSnapReplyPage(@RequestBody WeChatBaseParam param) {
        return weChatManager.getSnapReplyPage(param);
    }
 
    /**
     * 根据id获取告警批复详细内容
     *
     * @param param
     * @author sgj
     * @since 2026/04/11
     */
    @PostMapping(value = "/getSnapReplyInfoById")
    @ResponseBody
    public PageResponse<SnapReply> getSnapReplyInfoById(@RequestBody WeChatBaseParam param) {
        return weChatManager.getSnapReplyInfoById(param);
    }
 
 
    /**
     * 根据id获取告警批复详细内容
     *
     * @param param
     * @author sgj
     * @since 2026/04/11
     */
    @PostMapping(value = "/handleSnapReply")
    @ResponseBody
    public PageResponse<String> handleSnapReply(@RequestBody WeChatBaseParam param) {
        return weChatManager.handleSnapReply(param);
    }
 
}