|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.jlw.token.TokenService;
|
|
|
|
|
import com.ibeetl.admin.core.conf.WxMpConfig;
|
|
|
|
|
import com.ibeetl.admin.core.rbac.UserLoginInfo;
|
|
|
|
|
import com.ibeetl.admin.core.service.CoreUserService;
|
|
|
|
|
import com.ibeetl.jlw.entity.CoreUserWx;
|
|
|
|
|
import com.ibeetl.jlw.entity.Student;
|
|
|
|
|
import com.ibeetl.jlw.entity.Teacher;
|
|
|
|
|
import com.ibeetl.jlw.web.query.CoreUserWxQuery;
|
|
|
|
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
|
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
@ -23,10 +26,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
public class MsgHandler extends AbstractHandler {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CoreUserService coreUserService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CoreUserWxService coreUserWxService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private WebPlatformService webPlatformService;
|
|
|
|
|
private StudentService studentService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TeacherService teacherService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TokenService tokenService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxMpConfig wxConfig;
|
|
|
|
|
|
|
|
|
@ -59,34 +69,19 @@ public class MsgHandler extends AbstractHandler {
|
|
|
|
|
coreUserWxQuery.setOpenid(fromUser);
|
|
|
|
|
List<CoreUserWx> info = coreUserWxService.getValuesByQueryNotWithPermission(coreUserWxQuery);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(info)) {
|
|
|
|
|
// 查询关联的状态正常的用户,是否存在
|
|
|
|
|
CoreUserWx coreUserWx = info.get(0);
|
|
|
|
|
if (null == coreUserWx) {
|
|
|
|
|
map.put("type", "login");
|
|
|
|
|
map.put("status", "error");
|
|
|
|
|
map.put("token", "关联用户不存在,或者状态未启用!");
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("关联用户不存在,或者状态未启用!").toUser(fromUser)
|
|
|
|
|
.fromUser(wxMessage.getToUser())
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserLoginInfo userLoginInfo = coreUserWxService.buildLoginInfoWithWx(coreUserWx);
|
|
|
|
|
if (userLoginInfo == null) {
|
|
|
|
|
map.put("type", "login");
|
|
|
|
|
map.put("status", "error");
|
|
|
|
|
String value = "绑定的用户,处于不存在或者未启用状态!";
|
|
|
|
|
map.put("token", value);
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content(value).toUser(fromUser)
|
|
|
|
|
.fromUser(wxMessage.getToUser())
|
|
|
|
|
.build();
|
|
|
|
|
String token = "";
|
|
|
|
|
Student student = studentService.getByUserId(info.get(0).getUserId());
|
|
|
|
|
if (student != null) {
|
|
|
|
|
token = tokenService.getToken(student);
|
|
|
|
|
}else {
|
|
|
|
|
Teacher teacher = teacherService.getByUserId(info.get(0).getUserId());
|
|
|
|
|
if (teacher !=null) {
|
|
|
|
|
token = tokenService.getToken(teacher);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 登录信息存放Session
|
|
|
|
|
String tokenNullable = webPlatformService.setLoginUser(userLoginInfo);
|
|
|
|
|
map.put("type", "login");
|
|
|
|
|
map.put("status", "success");
|
|
|
|
|
map.put("token", tokenNullable);
|
|
|
|
|
map.put("token", token);
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
// WebSocketServer.sendToUser("token="+token, userId);
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("登录成功").toUser(fromUser)
|
|
|
|
|