|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.utils.StringUtils; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.codec.digest.DigestUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | return userMapper.selectUserInfo(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 小程序登陆 | 
|---|
|  |  |  | * @param parameters | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> loginSmallRoutine(Map<String, Object> parameters) { | 
|---|
|  |  |  | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //校验密码 | 
|---|
|  |  |  | String password = parameters.get("password").toString(); | 
|---|
|  |  |  | //密码解密 | 
|---|
|  |  |  | password = AESUtils.decrypt(password, AESKey); | 
|---|
|  |  |  | if (!MD5Utils.saltMD5Verify(password, userBo.getPassword())) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //校验是否删除 | 
|---|
|  |  |  | if (Constants.DELETE.equals(userBo.getIsDelete())) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.ACCOUNT_IS_DELETE.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //校验是否过期 | 
|---|
|  |  |  | if (userBo.getExpireTime() != null && userBo.getExpireTime().getTime() < System.currentTimeMillis()) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        JSONObject SessionKeyOpenId = WechatUtils.getSessionKeyOrOpenId(parameters.get("code").toString()); | 
|---|
|  |  |  | //        String openid = SessionKeyOpenId.getString("openid"); | 
|---|
|  |  |  | //        String sessionKey = SessionKeyOpenId.getString("session_key"); | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(userBo.getUnitId()); | 
|---|
|  |  |  | //封装用户信息 | 
|---|
|  |  |  | Map<String, Object> userInfo = new LinkedHashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //生成token,并存入redis | 
|---|
|  |  |  | String token = TokenUtils.getToken(userBo.getId().toString(), userInfo); | 
|---|
|  |  |  | String token = TokenUtils.getTokenApp(new StringBuffer("00").append(userBo.getId().toString()).toString(),userInfo); | 
|---|
|  |  |  | result.put("token", token); | 
|---|
|  |  |  | result.put("userName", userBo.getUserName()); | 
|---|
|  |  |  | result.put("unitId",userBo.getUnitId()); | 
|---|
|  |  |  | result.put("userId", userBo.getId()); | 
|---|
|  |  |  | result.put("account", userBo.getAccount()); | 
|---|
|  |  |  | result.put("unName",Objects.nonNull(responsibilityUnit.getAreaName())?responsibilityUnit.getAreaName():"未选择责任单位"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("token生成异常:" + e.getMessage()); | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | UserLog userLog = new UserLog(); | 
|---|
|  |  |  | userLog.setType(Constants.LOGIN_OPERTATE_TYPE); | 
|---|
|  |  |  | userLog.setIp(WebUtils.getIpAddr(request)); | 
|---|
|  |  |  | userLog.setOperateId(userBo.getId()); | 
|---|
|  |  |  | userLog.setOrganizationId(userBo.getOrganizationId()); | 
|---|
|  |  |  | userLog.setContent("登陆了用户:" + userBo.getAccount()); | 
|---|
|  |  |  | userLogMapper.insert(userLog); | 
|---|
|  |  |  | sysLog("登陆了用户:" + userBo.getAccount()+";openId:"+openId,userBo); | 
|---|
|  |  |  | //添加openId到user表中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | User user = userMapper.selectById(userBo.getId()); | 
|---|
|  |  |  | user.setOpenId(openId); | 
|---|
|  |  |  | userMapper.updateById(user); | 
|---|
|  |  |  | 
|---|
|  |  |  | userInfo.put("wechat", user.getWechat()); | 
|---|
|  |  |  | userInfo.put("expireTime", DateUtils.dateToDateString(user.getExpireTime())); | 
|---|
|  |  |  | userInfo.put("isAdmin", user.getIsAdmin()); | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(user.getUnitId()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //生成token,并存入redis | 
|---|
|  |  |  | String token = TokenUtils.getToken(user.getId().toString(), userInfo); | 
|---|
|  |  |  | String token = TokenUtils.getTokenApp(new StringBuffer("00").append(user.getId().toString()).toString(),userInfo); | 
|---|
|  |  |  | result.put("token", token); | 
|---|
|  |  |  | result.put("token", token); | 
|---|
|  |  |  | result.put("userName", user.getUserName()); | 
|---|
|  |  |  | result.put("unitId",user.getUnitId()); | 
|---|
|  |  |  | result.put("userId", user.getId()); | 
|---|
|  |  |  | result.put("account", user.getAccount()); | 
|---|
|  |  |  | result.put("unName",Objects.nonNull(responsibilityUnit.getAreaName())?responsibilityUnit.getAreaName():"未选择责任单位"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("token生成异常:" + e.getMessage()); | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | sysLog("登陆了用户:" + user.getAccount()+" ;openId:"+openid,user); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean updateUserId(Integer userId) { | 
|---|
|  |  |  | User user = userMapper.selectById(userId); | 
|---|
|  |  |  | user.setOpenId("0"); | 
|---|
|  |  |  | userMapper.updateById(user); | 
|---|
|  |  |  | sysLog(userId+"退出了小程序",user); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private void sysLog(String cont,User user){ | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | UserLog userLog = new UserLog(); | 
|---|
|  |  |  | userLog.setType(Constants.LOGIN_OPERTATE_APP); | 
|---|
|  |  |  | userLog.setIp(WebUtils.getIpAddr(request)); | 
|---|
|  |  |  | userLog.setOperateId(user.getId()); | 
|---|
|  |  |  | userLog.setOrganizationId(user.getOrganizationId()); | 
|---|
|  |  |  | userLog.setContent(cont); | 
|---|
|  |  |  | userLogMapper.insert(userLog); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> login(Map<String, Object> parameters) { | 
|---|
|  |  |  | UserBO userBo = selectUserInfo(parameters); | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<>(); | 
|---|