|
@@ -1,422 +1,422 @@
|
|
|
-package com.platform.controller;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.google.code.kaptcha.Constants;
|
|
|
-import com.google.code.kaptcha.Producer;
|
|
|
-import com.platform.annotation.SysLog;
|
|
|
-import com.platform.entity.Result;
|
|
|
-import com.platform.entity.SysSmsLogEntity;
|
|
|
-import com.platform.entity.SysUserEntity;
|
|
|
-import com.platform.enums.ResultCodeEnum;
|
|
|
-import com.platform.exception.CommonBaseException;
|
|
|
-import com.platform.service.impl.SysSmsLogServiceImpl;
|
|
|
-import com.platform.service.impl.SysUserRoleServiceImpl;
|
|
|
-import com.platform.service.impl.SysUserServiceImpl;
|
|
|
-import com.platform.service.impl.ZhiHouseService;
|
|
|
-import com.platform.utils.*;
|
|
|
-import com.platform.vos.CurrentUserLoginVo;
|
|
|
-import com.platform.vos.UserOnlyLoginVo;
|
|
|
-import com.platform.vos.ZhiHouseUserLoginVo;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.shiro.authc.*;
|
|
|
-import org.apache.shiro.subject.Subject;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-import org.springframework.util.ObjectUtils;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
-
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.servlet.ServletOutputStream;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.IOException;
|
|
|
-import java.time.Duration;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 登录相关
|
|
|
- *
|
|
|
- * @author lipengjun
|
|
|
- * @email 939961241@qq.com
|
|
|
- * @date 2016年11月10日 下午1:15:31
|
|
|
- */
|
|
|
-@Api(tags = "系统登录相关")
|
|
|
-@Controller
|
|
|
-@Slf4j
|
|
|
-public class SysLoginController {
|
|
|
-
|
|
|
- public static final String SMS_AUTH_CODE_PRE = "login_sms_code:";
|
|
|
- @Autowired
|
|
|
- private Producer producer;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysUserServiceImpl sysUserService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysSmsLogServiceImpl sysSmsLogService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysUserRoleServiceImpl sysUserRoleService;
|
|
|
-
|
|
|
- @Value("${scenePath}")
|
|
|
- private String zhiHouseHost;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ZhiHouseService zhiHouseService;
|
|
|
-
|
|
|
-
|
|
|
- @RequestMapping("captcha.jpg")
|
|
|
- public void captcha(HttpServletResponse response) throws IOException {
|
|
|
- response.setHeader("Cache-Control", "no-store, no-cache");
|
|
|
- response.setContentType("image/jpeg");
|
|
|
-
|
|
|
- //生成文字验证码
|
|
|
- String text = producer.createText();
|
|
|
- //生成图片验证码
|
|
|
- BufferedImage image = producer.createImage(text);
|
|
|
- //保存到shiro session
|
|
|
- ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
|
|
|
-
|
|
|
- ServletOutputStream out = response.getOutputStream();
|
|
|
- ImageIO.write(image, "jpg", out);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @ApiOperation(value = "验证短信验证码")
|
|
|
- @SysLog("验证短信验证码")
|
|
|
- @ResponseBody
|
|
|
- @PostMapping(value = "/sys/sms/authCodeValid")
|
|
|
- public Result smsAuthCodeValid(@RequestParam(name = "phoneNum") String phoneNum , @RequestParam(name = "smsCode") String smsCode) throws IOException {
|
|
|
-
|
|
|
- if(StringUtils.isBlank(phoneNum) || StringUtils.isBlank(smsCode)){
|
|
|
- return Result.failure("手机号或者验证码不能为空");
|
|
|
- }
|
|
|
- String redisSmsCode = (String) LettuceRedisClientUtils.getValueByKey(SMS_AUTH_CODE_PRE + phoneNum + smsCode);
|
|
|
- log.info("缓存中的缓存码为:{},上送的为: {}" , redisSmsCode , smsCode);
|
|
|
- if(StringUtils.isBlank(redisSmsCode)){
|
|
|
- return Result.failure("验证码不正确或者已失效");
|
|
|
- }
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "发送短信校验码")
|
|
|
- @SysLog("发送短信校验码")
|
|
|
- @ResponseBody
|
|
|
- @PostMapping(value = "/sys/sms/authCode")
|
|
|
- public Result sendSmsMsg(@RequestParam(name = "phoneNum") String phoneNum , Long deptId) throws IOException {
|
|
|
-
|
|
|
- if (StringUtils.isBlank(phoneNum)) {
|
|
|
- return Result.failure("手机号不能为空");
|
|
|
- }
|
|
|
- String regex = "^1[3-9][0-9]\\d{8}$";
|
|
|
- if (!phoneNum.matches(regex)) {
|
|
|
- return Result.failure("手机号不符合格式");
|
|
|
- }
|
|
|
- //校验是否是有效管理员
|
|
|
- if(null != deptId){
|
|
|
- SysUserEntity adminUser = sysUserService.queryByMobileAndDeptId(phoneNum , deptId);
|
|
|
- if(null == adminUser){
|
|
|
- return Result.failure("请正确填写所属公司管理员手机号码");
|
|
|
- }
|
|
|
- List<Long> roleIdList = sysUserRoleService.queryRoleIdList(adminUser.getUserId());
|
|
|
- if(CollectionUtils.isEmpty(roleIdList) || (!roleIdList.contains(5L) && !roleIdList.contains(6L))){
|
|
|
- return Result.failure("此手机对应的用户非管理员");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 一分钟之内不能重复发送短信
|
|
|
- SysSmsLogEntity smsLogVo = sysSmsLogService.querySmsCodeByPhoneNum(phoneNum);
|
|
|
- if (null != smsLogVo && null != smsLogVo.getCreateTime()) {
|
|
|
- Duration duration = Duration.between(smsLogVo.getCreateTime() , LocalDateTime.now());
|
|
|
- long millis = duration.toMillis();
|
|
|
- log.info("当前时间差为:{}[单位毫秒]" , millis);
|
|
|
- if (millis <= 60000L) {
|
|
|
- log.info("一分钟以内不能重复发短信");
|
|
|
- return Result.failure("短信已发送");
|
|
|
- }
|
|
|
- }
|
|
|
- //生成验证码
|
|
|
- String smsCode = CharUtil.getRandomNum(4);
|
|
|
- boolean falg = false;
|
|
|
- try {
|
|
|
- //阿里云短信平台
|
|
|
- falg = SmsUtil.sendAliSms(phoneNum, "{\"code\":\"" + smsCode + "\"}", "SMS_205075406");
|
|
|
- } catch (Exception e) {
|
|
|
- return Result.failure("短信发送失败");
|
|
|
- }
|
|
|
- if (falg) {
|
|
|
- SysSmsLogEntity sysSmsLogEntity = new SysSmsLogEntity();
|
|
|
- sysSmsLogEntity.setCreateTime(LocalDateTime.now());
|
|
|
- sysSmsLogEntity.setMobile(phoneNum);
|
|
|
- sysSmsLogEntity.setCode(smsCode);
|
|
|
- //发送状态 1标识成功,0标识失败
|
|
|
- sysSmsLogEntity.setSendStatus(1);
|
|
|
- sysSmsLogEntity.setContent("{\"code\":\"" + smsCode + "\"}");
|
|
|
- sysSmsLogService.save(sysSmsLogEntity);
|
|
|
- //将验证码存储redis中,有效期为5分钟,也就是300秒
|
|
|
- LettuceRedisClientUtils.setStrKeyValue(SMS_AUTH_CODE_PRE + phoneNum + smsCode , smsCode , 300);
|
|
|
- return Result.success("短信发送成功");
|
|
|
- } else {
|
|
|
- return Result.failure("短信发送失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 登录
|
|
|
- */
|
|
|
- @SysLog("登录")
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping(value = "/sys/loginWithoutAuth", method = RequestMethod.POST)
|
|
|
- public Result onlyLogin(@RequestBody UserOnlyLoginVo userOnlyLoginVo){
|
|
|
-
|
|
|
- ZhiHouseUserLoginVo userLoginVo = new ZhiHouseUserLoginVo();
|
|
|
- userLoginVo.setUserName(userOnlyLoginVo.getUsername());
|
|
|
- //对前端传的密码解密
|
|
|
- String password = Base64Converter.decode(Base64Converter.subText(userOnlyLoginVo.getPassword()));
|
|
|
- userOnlyLoginVo.setPassword(password);
|
|
|
- userLoginVo.setUserPassword(userOnlyLoginVo.getPassword());
|
|
|
- userLoginVo.setArea("1234");
|
|
|
- String url = zhiHouseHost + "api/platform/login";
|
|
|
- ResponseEntity<String> kankanResult = restTemplate.postForEntity(url, userLoginVo,String.class);
|
|
|
- if(kankanResult.getStatusCode()!= HttpStatus.OK){
|
|
|
- return Result.failure("账户验证失败");
|
|
|
- }
|
|
|
- //解析返回结果
|
|
|
- JSONObject res = JSONObject.parseObject(kankanResult.getBody());
|
|
|
- log.info("四维看看返回登录数据:{}", kankanResult.getBody());
|
|
|
- Result result = parseResult(res, "登录失败", userLoginVo);
|
|
|
- if(StringUtils.equals(result.getCode().toString(), String.valueOf(Result.CODE_SUCCESS))){
|
|
|
- SysUserEntity manager = sysUserService.queryByUserMobile(userOnlyLoginVo.getUsername());
|
|
|
- if(!ObjectUtils.isEmpty(manager) && manager.getDeptId() != -1L){
|
|
|
- return Result.failure("操作失败,当前账号已被绑定");
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 登录
|
|
|
- */
|
|
|
- @SysLog("登录")
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping(value = "/sys/login", method = RequestMethod.POST)
|
|
|
- public Result login(String username, String password, String captcha) throws IOException {
|
|
|
-// String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
|
|
|
-// if (null == kaptcha) {
|
|
|
-// return Result.failure("验证码已失效");
|
|
|
+//package com.platform.controller;
|
|
|
+//
|
|
|
+//import com.alibaba.fastjson.JSONArray;
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
|
+//import com.google.code.kaptcha.Constants;
|
|
|
+//import com.google.code.kaptcha.Producer;
|
|
|
+//import com.platform.annotation.SysLog;
|
|
|
+//import com.platform.entity.Result;
|
|
|
+//import com.platform.entity.SysSmsLogEntity;
|
|
|
+//import com.platform.entity.SysUserEntity;
|
|
|
+//import com.platform.enums.ResultCodeEnum;
|
|
|
+//import com.platform.exception.CommonBaseException;
|
|
|
+//import com.platform.service.impl.SysSmsLogServiceImpl;
|
|
|
+//import com.platform.service.impl.SysUserRoleServiceImpl;
|
|
|
+//import com.platform.service.impl.SysUserServiceImpl;
|
|
|
+//import com.platform.service.impl.ZhiHouseService;
|
|
|
+//import com.platform.utils.*;
|
|
|
+//import com.platform.vos.CurrentUserLoginVo;
|
|
|
+//import com.platform.vos.UserOnlyLoginVo;
|
|
|
+//import com.platform.vos.ZhiHouseUserLoginVo;
|
|
|
+//import io.swagger.annotations.Api;
|
|
|
+//import io.swagger.annotations.ApiOperation;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.apache.commons.lang.StringUtils;
|
|
|
+//import org.apache.shiro.authc.*;
|
|
|
+//import org.apache.shiro.subject.Subject;
|
|
|
+//import org.springframework.beans.BeanUtils;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.http.HttpStatus;
|
|
|
+//import org.springframework.http.ResponseEntity;
|
|
|
+//import org.springframework.stereotype.Controller;
|
|
|
+//import org.springframework.transaction.annotation.Propagation;
|
|
|
+//import org.springframework.transaction.annotation.Transactional;
|
|
|
+//import org.springframework.util.CollectionUtils;
|
|
|
+//import org.springframework.util.ObjectUtils;
|
|
|
+//import org.springframework.web.bind.annotation.*;
|
|
|
+//import org.springframework.web.client.RestTemplate;
|
|
|
+//
|
|
|
+//import javax.imageio.ImageIO;
|
|
|
+//import javax.servlet.ServletOutputStream;
|
|
|
+//import javax.servlet.http.HttpServletResponse;
|
|
|
+//import java.awt.image.BufferedImage;
|
|
|
+//import java.io.IOException;
|
|
|
+//import java.time.Duration;
|
|
|
+//import java.time.LocalDateTime;
|
|
|
+//import java.util.HashMap;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Map;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 登录相关
|
|
|
+// *
|
|
|
+// * @author lipengjun
|
|
|
+// * @email 939961241@qq.com
|
|
|
+// * @date 2016年11月10日 下午1:15:31
|
|
|
+// */
|
|
|
+//@Api(tags = "系统登录相关")
|
|
|
+//@Controller
|
|
|
+//@Slf4j
|
|
|
+//public class SysLoginController {
|
|
|
+//
|
|
|
+// public static final String SMS_AUTH_CODE_PRE = "login_sms_code:";
|
|
|
+// @Autowired
|
|
|
+// private Producer producer;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SysUserServiceImpl sysUserService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SysSmsLogServiceImpl sysSmsLogService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SysUserRoleServiceImpl sysUserRoleService;
|
|
|
+//
|
|
|
+// @Value("${scenePath}")
|
|
|
+// private String zhiHouseHost;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private RestTemplate restTemplate;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private ZhiHouseService zhiHouseService;
|
|
|
+//
|
|
|
+//
|
|
|
+// @RequestMapping("captcha.jpg")
|
|
|
+// public void captcha(HttpServletResponse response) throws IOException {
|
|
|
+// response.setHeader("Cache-Control", "no-store, no-cache");
|
|
|
+// response.setContentType("image/jpeg");
|
|
|
+//
|
|
|
+// //生成文字验证码
|
|
|
+// String text = producer.createText();
|
|
|
+// //生成图片验证码
|
|
|
+// BufferedImage image = producer.createImage(text);
|
|
|
+// //保存到shiro session
|
|
|
+// ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
|
|
|
+//
|
|
|
+// ServletOutputStream out = response.getOutputStream();
|
|
|
+// ImageIO.write(image, "jpg", out);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @ApiOperation(value = "验证短信验证码")
|
|
|
+// @SysLog("验证短信验证码")
|
|
|
+// @ResponseBody
|
|
|
+// @PostMapping(value = "/sys/sms/authCodeValid")
|
|
|
+// public Result smsAuthCodeValid(@RequestParam(name = "phoneNum") String phoneNum , @RequestParam(name = "smsCode") String smsCode) throws IOException {
|
|
|
+//
|
|
|
+// if(StringUtils.isBlank(phoneNum) || StringUtils.isBlank(smsCode)){
|
|
|
+// return Result.failure("手机号或者验证码不能为空");
|
|
|
// }
|
|
|
-// if (!captcha.equalsIgnoreCase(kaptcha)) {
|
|
|
-// return Result.failure("验证码不正确");
|
|
|
+// String redisSmsCode = (String) LettuceRedisClientUtils.getValueByKey(SMS_AUTH_CODE_PRE + phoneNum + smsCode);
|
|
|
+// log.info("缓存中的缓存码为:{},上送的为: {}" , redisSmsCode , smsCode);
|
|
|
+// if(StringUtils.isBlank(redisSmsCode)){
|
|
|
+// return Result.failure("验证码不正确或者已失效");
|
|
|
// }
|
|
|
-
|
|
|
- //对前端传的密码解密
|
|
|
- password = Base64Converter.decode(Base64Converter.subText(password));
|
|
|
-
|
|
|
- ResponseEntity<String> loginResult = zhiHouseService.login(username, password);
|
|
|
- if(loginResult.getStatusCode()!= HttpStatus.OK){
|
|
|
- return Result.failure("登录失败");
|
|
|
- }
|
|
|
- //解析返回结果
|
|
|
- JSONObject res = JSONObject.parseObject(loginResult.getBody());
|
|
|
- Result result = parseResultWithoutAddUser(res, "登录失败");
|
|
|
-// if (null != result && result.getCode().equals(Result.CODE_SUCCESS)) {
|
|
|
-// log.info("四维看看登录完成,将执行本地登录验证");
|
|
|
-// try {
|
|
|
-// Subject subject = ShiroUtils.getSubject();
|
|
|
-// UsernamePasswordToken token = new UsernamePasswordToken(username, password);
|
|
|
-// subject.login(token);
|
|
|
-// } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
|
|
|
-// return Result.failure(e.getMessage());
|
|
|
-// } catch (AuthenticationException e) {
|
|
|
-// return Result.failure("账户验证失败");
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @ApiOperation(value = "发送短信校验码")
|
|
|
+// @SysLog("发送短信校验码")
|
|
|
+// @ResponseBody
|
|
|
+// @PostMapping(value = "/sys/sms/authCode")
|
|
|
+// public Result sendSmsMsg(@RequestParam(name = "phoneNum") String phoneNum , Long deptId) throws IOException {
|
|
|
+//
|
|
|
+// if (StringUtils.isBlank(phoneNum)) {
|
|
|
+// return Result.failure("手机号不能为空");
|
|
|
+// }
|
|
|
+// String regex = "^1[3-9][0-9]\\d{8}$";
|
|
|
+// if (!phoneNum.matches(regex)) {
|
|
|
+// return Result.failure("手机号不符合格式");
|
|
|
+// }
|
|
|
+// //校验是否是有效管理员
|
|
|
+// if(null != deptId){
|
|
|
+// SysUserEntity adminUser = sysUserService.queryByMobileAndDeptId(phoneNum , deptId);
|
|
|
+// if(null == adminUser){
|
|
|
+// return Result.failure("请正确填写所属公司管理员手机号码");
|
|
|
+// }
|
|
|
+// List<Long> roleIdList = sysUserRoleService.queryRoleIdList(adminUser.getUserId());
|
|
|
+// if(CollectionUtils.isEmpty(roleIdList) || (!roleIdList.contains(5L) && !roleIdList.contains(6L))){
|
|
|
+// return Result.failure("此手机对应的用户非管理员");
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 一分钟之内不能重复发送短信
|
|
|
+// SysSmsLogEntity smsLogVo = sysSmsLogService.querySmsCodeByPhoneNum(phoneNum);
|
|
|
+// if (null != smsLogVo && null != smsLogVo.getCreateTime()) {
|
|
|
+// Duration duration = Duration.between(smsLogVo.getCreateTime() , LocalDateTime.now());
|
|
|
+// long millis = duration.toMillis();
|
|
|
+// log.info("当前时间差为:{}[单位毫秒]" , millis);
|
|
|
+// if (millis <= 60000L) {
|
|
|
+// log.info("一分钟以内不能重复发短信");
|
|
|
+// return Result.failure("短信已发送");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //生成验证码
|
|
|
+// String smsCode = CharUtil.getRandomNum(4);
|
|
|
+// boolean falg = false;
|
|
|
+// try {
|
|
|
+// //阿里云短信平台
|
|
|
+// falg = SmsUtil.sendAliSms(phoneNum, "{\"code\":\"" + smsCode + "\"}", "SMS_205075406");
|
|
|
+// } catch (Exception e) {
|
|
|
+// return Result.failure("短信发送失败");
|
|
|
+// }
|
|
|
+// if (falg) {
|
|
|
+// SysSmsLogEntity sysSmsLogEntity = new SysSmsLogEntity();
|
|
|
+// sysSmsLogEntity.setCreateTime(LocalDateTime.now());
|
|
|
+// sysSmsLogEntity.setMobile(phoneNum);
|
|
|
+// sysSmsLogEntity.setCode(smsCode);
|
|
|
+// //发送状态 1标识成功,0标识失败
|
|
|
+// sysSmsLogEntity.setSendStatus(1);
|
|
|
+// sysSmsLogEntity.setContent("{\"code\":\"" + smsCode + "\"}");
|
|
|
+// sysSmsLogService.save(sysSmsLogEntity);
|
|
|
+// //将验证码存储redis中,有效期为5分钟,也就是300秒
|
|
|
+// LettuceRedisClientUtils.setStrKeyValue(SMS_AUTH_CODE_PRE + phoneNum + smsCode , smsCode , 300);
|
|
|
+// return Result.success("短信发送成功");
|
|
|
+// } else {
|
|
|
+// return Result.failure("短信发送失败");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 登录
|
|
|
+// */
|
|
|
+// @SysLog("登录")
|
|
|
+// @ResponseBody
|
|
|
+// @RequestMapping(value = "/sys/loginWithoutAuth", method = RequestMethod.POST)
|
|
|
+// public Result onlyLogin(@RequestBody UserOnlyLoginVo userOnlyLoginVo){
|
|
|
+//
|
|
|
+// ZhiHouseUserLoginVo userLoginVo = new ZhiHouseUserLoginVo();
|
|
|
+// userLoginVo.setUserName(userOnlyLoginVo.getUsername());
|
|
|
+// //对前端传的密码解密
|
|
|
+// String password = Base64Converter.decode(Base64Converter.subText(userOnlyLoginVo.getPassword()));
|
|
|
+// userOnlyLoginVo.setPassword(password);
|
|
|
+// userLoginVo.setUserPassword(userOnlyLoginVo.getPassword());
|
|
|
+// userLoginVo.setArea("1234");
|
|
|
+// String url = zhiHouseHost + "api/platform/login";
|
|
|
+// ResponseEntity<String> kankanResult = restTemplate.postForEntity(url, userLoginVo,String.class);
|
|
|
+// if(kankanResult.getStatusCode()!= HttpStatus.OK){
|
|
|
+// return Result.failure("账户验证失败");
|
|
|
+// }
|
|
|
+// //解析返回结果
|
|
|
+// JSONObject res = JSONObject.parseObject(kankanResult.getBody());
|
|
|
+// log.info("四维看看返回登录数据:{}", kankanResult.getBody());
|
|
|
+// Result result = parseResult(res, "登录失败", userLoginVo);
|
|
|
+// if(StringUtils.equals(result.getCode().toString(), String.valueOf(Result.CODE_SUCCESS))){
|
|
|
+// SysUserEntity manager = sysUserService.queryByUserMobile(userOnlyLoginVo.getUsername());
|
|
|
+// if(!ObjectUtils.isEmpty(manager) && manager.getDeptId() != -1L){
|
|
|
+// return Result.failure("操作失败,当前账号已被绑定");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 登录
|
|
|
+// */
|
|
|
+// @SysLog("登录")
|
|
|
+// @ResponseBody
|
|
|
+// @RequestMapping(value = "/sys/login", method = RequestMethod.POST)
|
|
|
+// public Result login(String username, String password, String captcha) throws IOException {
|
|
|
+//// String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
|
|
|
+//// if (null == kaptcha) {
|
|
|
+//// return Result.failure("验证码已失效");
|
|
|
+//// }
|
|
|
+//// if (!captcha.equalsIgnoreCase(kaptcha)) {
|
|
|
+//// return Result.failure("验证码不正确");
|
|
|
+//// }
|
|
|
+//
|
|
|
+// //对前端传的密码解密
|
|
|
+// password = Base64Converter.decode(Base64Converter.subText(password));
|
|
|
+//
|
|
|
+// ResponseEntity<String> loginResult = zhiHouseService.login(username, password);
|
|
|
+// if(loginResult.getStatusCode()!= HttpStatus.OK){
|
|
|
+// return Result.failure("登录失败");
|
|
|
+// }
|
|
|
+// //解析返回结果
|
|
|
+// JSONObject res = JSONObject.parseObject(loginResult.getBody());
|
|
|
+// Result result = parseResultWithoutAddUser(res, "登录失败");
|
|
|
+//// if (null != result && result.getCode().equals(Result.CODE_SUCCESS)) {
|
|
|
+//// log.info("四维看看登录完成,将执行本地登录验证");
|
|
|
+//// try {
|
|
|
+//// Subject subject = ShiroUtils.getSubject();
|
|
|
+//// UsernamePasswordToken token = new UsernamePasswordToken(username, password);
|
|
|
+//// subject.login(token);
|
|
|
+//// } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
|
|
|
+//// return Result.failure(e.getMessage());
|
|
|
+//// } catch (AuthenticationException e) {
|
|
|
+//// return Result.failure("账户验证失败");
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+// @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
|
|
+// public Result parseResultWithoutAddUser(JSONObject res, String defaultFailMsg) {
|
|
|
+// if(ObjectUtils.isEmpty(res)){
|
|
|
+// return Result.failure(defaultFailMsg);
|
|
|
+// }
|
|
|
+// int code = res.containsKey("code") ? res.getIntValue("code") : -10;
|
|
|
+// if (200 != code) {
|
|
|
+// return Result.failure(res.getString("message"));
|
|
|
+// }
|
|
|
+// Map<String, Object> resultMap = new HashMap<>();
|
|
|
+// JSONObject dataObject = null;
|
|
|
+// String tokenFromKankan = "";
|
|
|
+// if (res.get("message") instanceof JSONArray) {
|
|
|
+// log.info("四维看看登录返回的data是json数组");
|
|
|
+// return Result.success();
|
|
|
+// } else if (res.get("message") instanceof JSONObject) {
|
|
|
+// log.info("四维看看登录返回的data是json object");
|
|
|
+// //登录返回的就是jsonObject
|
|
|
+// dataObject = (JSONObject) res.get("message");
|
|
|
+// if(ObjectUtils.isEmpty(dataObject)){
|
|
|
+// return Result.success(resultMap);
|
|
|
// }
|
|
|
+// tokenFromKankan = dataObject.getString("token");
|
|
|
+// if (StringUtils.isBlank(tokenFromKankan)) {
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "四维看看返回的token为空");
|
|
|
+// }
|
|
|
+// resultMap.put("token", tokenFromKankan);
|
|
|
+// String nickName = dataObject.getString("nickName");
|
|
|
+// String userName = dataObject.getString("userName");
|
|
|
+// if (StringUtils.isBlank(userName)) {
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "看看返回用户名为空");
|
|
|
+// }
|
|
|
+// SysUserEntity dbUser = sysUserService.queryByUserMobile(userName);
|
|
|
+// if (null == dbUser) {
|
|
|
+// return Result.failure(11 ,"账号未授权,请联系平台管理员授予相关权限。");
|
|
|
+// }
|
|
|
+// if (null != dbUser.getStatus() && dbUser.getStatus() == 0) {
|
|
|
+// log.info("用户[{}]不可用", dbUser.getUsername());
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "用户已经不可用");
|
|
|
+// }
|
|
|
+// CurrentUserLoginVo userVo = new CurrentUserLoginVo();
|
|
|
+// BeanUtils.copyProperties(dbUser,userVo);
|
|
|
+// if(!ObjectUtils.isEmpty(dbUser.getDeptId())){
|
|
|
+// // 获取用户所在企业信息
|
|
|
+// JSONObject deptEntity = zhiHouseService.getComponyInfo(dbUser.getMobile());
|
|
|
+// userVo.setDeptName(deptEntity.getString("name"));
|
|
|
+// userVo.setDeptId(deptEntity.getLong("id"));
|
|
|
+// userVo.setDeptManagerPhoneNum(deptEntity.getString("phoneNum"));
|
|
|
+// userVo.setDeptExpirationDate(deptEntity.getDate("expirationDate"));
|
|
|
+// userVo.setFdkkPassword(null);
|
|
|
+// }
|
|
|
+// resultMap.put("user", userVo);
|
|
|
+// return Result.success(resultMap);
|
|
|
+// } else {
|
|
|
+// return Result.failure("四维看看返回数据测试异常");
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
|
|
+// public Result parseResult(JSONObject res, String defaultFailMsg, ZhiHouseUserLoginVo adminRegisterVo) {
|
|
|
+// if(ObjectUtils.isEmpty(res)){
|
|
|
+// return Result.failure(defaultFailMsg);
|
|
|
+// }
|
|
|
+// int code =res.containsKey("code")?res.getIntValue("code"): -10;
|
|
|
+// if (200 != code) {
|
|
|
+// return Result.failure(res.getString("message"));
|
|
|
+// }
|
|
|
+// Map<String, Object> resultMap = new HashMap<>();
|
|
|
+// log.info("用户登录成功");
|
|
|
+// if (res.get("message") instanceof JSONArray) {
|
|
|
+// log.info("四维看看登录返回的data是json数组");
|
|
|
+// return Result.success();
|
|
|
+// } else if (res.get("message") instanceof JSONObject) {
|
|
|
+// log.info("四维看看登录返回的data是json object");
|
|
|
+// JSONObject dataObject = (JSONObject) res.get("message");
|
|
|
+// if(ObjectUtils.isEmpty(dataObject)){
|
|
|
+// return Result.success(resultMap);
|
|
|
+// }
|
|
|
+// String tokenFromKankan = dataObject.getString("token");
|
|
|
+// if (StringUtils.isBlank(tokenFromKankan)) {
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "四维看看返回的token为空");
|
|
|
+// }
|
|
|
+// resultMap.put("token", tokenFromKankan);
|
|
|
+// String nickName = dataObject.getString("nickName");
|
|
|
+// String userName = dataObject.getString("userName");
|
|
|
+// String password = dataObject.getString("userPassword");
|
|
|
+// if (StringUtils.isBlank(userName)) {
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "看看返回用户名为空");
|
|
|
+// }
|
|
|
+// SysUserEntity dbUser = sysUserService.queryByUserMobile(userName);
|
|
|
+// if (null == dbUser) {
|
|
|
+// addNewUserWithDeptId(nickName,userName , password, -1L);
|
|
|
+// dbUser = sysUserService.queryByUserMobile(adminRegisterVo.getUserName());
|
|
|
+// if (null == dbUser) {
|
|
|
+// log.error("新插入的用户:{}重新捞取失败", adminRegisterVo.getUserName());
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "获取用户失败");
|
|
|
+// }
|
|
|
+// //默认开通普通公司管理员的权限
|
|
|
+// int insert = sysUserRoleService.onlySave(dbUser.getUserId(), 6L);
|
|
|
+// if(insert != 1){
|
|
|
+// log.error("给用户[{}]开通普通管理员角色失败" , dbUser.getMobile());
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101 , "新增普通管理员权限失败");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if (null != dbUser.getStatus() && dbUser.getStatus() == 0) {
|
|
|
+// log.info("用户[{}]不可用", dbUser.getUsername());
|
|
|
+// throw new CommonBaseException(ResultCodeEnum.D101, "用户已经不可用");
|
|
|
+// }
|
|
|
+// if(!StringUtils.equals(nickName , dbUser.getUsername())){
|
|
|
+// log.info("修改了昵称,这里更新");
|
|
|
+// dbUser.setUsername(nickName);
|
|
|
+// sysUserService.updateOnly(dbUser);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// resultMap.put("user", dbUser);
|
|
|
+// return Result.success(resultMap);
|
|
|
+// } else {
|
|
|
+// return Result.failure("四维看看返回数据测试异常");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// public void addNewUserWithDeptId(String nickName, String phoneNum, String password, long deptId){
|
|
|
+// if (StringUtils.isBlank(phoneNum)) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// SysUserEntity userEntity = new SysUserEntity();
|
|
|
+// userEntity.setPassword(password);
|
|
|
+// userEntity.setMobile(phoneNum);
|
|
|
+// userEntity.setUsername(nickName);
|
|
|
+// if(deptId >= 0){
|
|
|
+// userEntity.setDeptId(deptId);
|
|
|
+// }
|
|
|
+// userEntity.setStatus(1);
|
|
|
+// userEntity.setCreateUserId(1L);
|
|
|
+// userEntity.setDeptId(-1L);
|
|
|
+// sysUserService.addNewUserWithoutCheck(userEntity);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public void addNewUserByPhone(String phoneNum, String password, int kankanUserId) {
|
|
|
+// if (StringUtils.isBlank(phoneNum)) {
|
|
|
+// return;
|
|
|
// }
|
|
|
- return result;
|
|
|
- }
|
|
|
- @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
|
|
- public Result parseResultWithoutAddUser(JSONObject res, String defaultFailMsg) {
|
|
|
- if(ObjectUtils.isEmpty(res)){
|
|
|
- return Result.failure(defaultFailMsg);
|
|
|
- }
|
|
|
- int code = res.containsKey("code") ? res.getIntValue("code") : -10;
|
|
|
- if (200 != code) {
|
|
|
- return Result.failure(res.getString("message"));
|
|
|
- }
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
- JSONObject dataObject = null;
|
|
|
- String tokenFromKankan = "";
|
|
|
- if (res.get("message") instanceof JSONArray) {
|
|
|
- log.info("四维看看登录返回的data是json数组");
|
|
|
- return Result.success();
|
|
|
- } else if (res.get("message") instanceof JSONObject) {
|
|
|
- log.info("四维看看登录返回的data是json object");
|
|
|
- //登录返回的就是jsonObject
|
|
|
- dataObject = (JSONObject) res.get("message");
|
|
|
- if(ObjectUtils.isEmpty(dataObject)){
|
|
|
- return Result.success(resultMap);
|
|
|
- }
|
|
|
- tokenFromKankan = dataObject.getString("token");
|
|
|
- if (StringUtils.isBlank(tokenFromKankan)) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "四维看看返回的token为空");
|
|
|
- }
|
|
|
- resultMap.put("token", tokenFromKankan);
|
|
|
- String nickName = dataObject.getString("nickName");
|
|
|
- String userName = dataObject.getString("userName");
|
|
|
- if (StringUtils.isBlank(userName)) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "看看返回用户名为空");
|
|
|
- }
|
|
|
- SysUserEntity dbUser = sysUserService.queryByUserMobile(userName);
|
|
|
- if (null == dbUser) {
|
|
|
- return Result.failure(11 ,"账号未授权,请联系平台管理员授予相关权限。");
|
|
|
- }
|
|
|
- if (null != dbUser.getStatus() && dbUser.getStatus() == 0) {
|
|
|
- log.info("用户[{}]不可用", dbUser.getUsername());
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "用户已经不可用");
|
|
|
- }
|
|
|
- CurrentUserLoginVo userVo = new CurrentUserLoginVo();
|
|
|
- BeanUtils.copyProperties(dbUser,userVo);
|
|
|
- if(!ObjectUtils.isEmpty(dbUser.getDeptId())){
|
|
|
- // 获取用户所在企业信息
|
|
|
- JSONObject deptEntity = zhiHouseService.getComponyInfo(dbUser.getMobile());
|
|
|
- userVo.setDeptName(deptEntity.getString("name"));
|
|
|
- userVo.setDeptId(deptEntity.getLong("id"));
|
|
|
- userVo.setDeptManagerPhoneNum(deptEntity.getString("phoneNum"));
|
|
|
- userVo.setDeptExpirationDate(deptEntity.getDate("expirationDate"));
|
|
|
- userVo.setFdkkPassword(null);
|
|
|
- }
|
|
|
- resultMap.put("user", userVo);
|
|
|
- return Result.success(resultMap);
|
|
|
- } else {
|
|
|
- return Result.failure("四维看看返回数据测试异常");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
|
|
- public Result parseResult(JSONObject res, String defaultFailMsg, ZhiHouseUserLoginVo adminRegisterVo) {
|
|
|
- if(ObjectUtils.isEmpty(res)){
|
|
|
- return Result.failure(defaultFailMsg);
|
|
|
- }
|
|
|
- int code =res.containsKey("code")?res.getIntValue("code"): -10;
|
|
|
- if (200 != code) {
|
|
|
- return Result.failure(res.getString("message"));
|
|
|
- }
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
- log.info("用户登录成功");
|
|
|
- if (res.get("message") instanceof JSONArray) {
|
|
|
- log.info("四维看看登录返回的data是json数组");
|
|
|
- return Result.success();
|
|
|
- } else if (res.get("message") instanceof JSONObject) {
|
|
|
- log.info("四维看看登录返回的data是json object");
|
|
|
- JSONObject dataObject = (JSONObject) res.get("message");
|
|
|
- if(ObjectUtils.isEmpty(dataObject)){
|
|
|
- return Result.success(resultMap);
|
|
|
- }
|
|
|
- String tokenFromKankan = dataObject.getString("token");
|
|
|
- if (StringUtils.isBlank(tokenFromKankan)) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "四维看看返回的token为空");
|
|
|
- }
|
|
|
- resultMap.put("token", tokenFromKankan);
|
|
|
- String nickName = dataObject.getString("nickName");
|
|
|
- String userName = dataObject.getString("userName");
|
|
|
- String password = dataObject.getString("userPassword");
|
|
|
- if (StringUtils.isBlank(userName)) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "看看返回用户名为空");
|
|
|
- }
|
|
|
- SysUserEntity dbUser = sysUserService.queryByUserMobile(userName);
|
|
|
- if (null == dbUser) {
|
|
|
- addNewUserWithDeptId(nickName,userName , password, -1L);
|
|
|
- dbUser = sysUserService.queryByUserMobile(adminRegisterVo.getUserName());
|
|
|
- if (null == dbUser) {
|
|
|
- log.error("新插入的用户:{}重新捞取失败", adminRegisterVo.getUserName());
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "获取用户失败");
|
|
|
- }
|
|
|
- //默认开通普通公司管理员的权限
|
|
|
- int insert = sysUserRoleService.onlySave(dbUser.getUserId(), 6L);
|
|
|
- if(insert != 1){
|
|
|
- log.error("给用户[{}]开通普通管理员角色失败" , dbUser.getMobile());
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101 , "新增普通管理员权限失败");
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (null != dbUser.getStatus() && dbUser.getStatus() == 0) {
|
|
|
- log.info("用户[{}]不可用", dbUser.getUsername());
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "用户已经不可用");
|
|
|
- }
|
|
|
- if(!StringUtils.equals(nickName , dbUser.getUsername())){
|
|
|
- log.info("修改了昵称,这里更新");
|
|
|
- dbUser.setUsername(nickName);
|
|
|
- sysUserService.updateOnly(dbUser);
|
|
|
- }
|
|
|
- }
|
|
|
- resultMap.put("user", dbUser);
|
|
|
- return Result.success(resultMap);
|
|
|
- } else {
|
|
|
- return Result.failure("四维看看返回数据测试异常");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void addNewUserWithDeptId(String nickName, String phoneNum, String password, long deptId){
|
|
|
- if (StringUtils.isBlank(phoneNum)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- SysUserEntity userEntity = new SysUserEntity();
|
|
|
- userEntity.setPassword(password);
|
|
|
- userEntity.setMobile(phoneNum);
|
|
|
- userEntity.setUsername(nickName);
|
|
|
- if(deptId >= 0){
|
|
|
- userEntity.setDeptId(deptId);
|
|
|
- }
|
|
|
- userEntity.setStatus(1);
|
|
|
- userEntity.setCreateUserId(1L);
|
|
|
- userEntity.setDeptId(-1L);
|
|
|
- sysUserService.addNewUserWithoutCheck(userEntity);
|
|
|
- }
|
|
|
-
|
|
|
- public void addNewUserByPhone(String phoneNum, String password, int kankanUserId) {
|
|
|
- if (StringUtils.isBlank(phoneNum)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- SysUserEntity userEntity = new SysUserEntity();
|
|
|
- userEntity.setPassword(password);
|
|
|
- userEntity.setMobile(phoneNum);
|
|
|
- userEntity.setUsername(phoneNum);
|
|
|
- userEntity.setStatus(1);
|
|
|
- //TODO:看看放这里是否合适
|
|
|
- userEntity.setCreateUserId(1L);
|
|
|
- //TODO:这里默认给76的默认部门
|
|
|
- userEntity.setDeptId(76L);
|
|
|
- sysUserService.addNewUserWithoutCheck(userEntity);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 退出
|
|
|
- */
|
|
|
- @RequestMapping(value = "logout", method = RequestMethod.GET)
|
|
|
- public String logout() {
|
|
|
- ShiroUtils.logout();
|
|
|
- return "redirect:/";
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+// SysUserEntity userEntity = new SysUserEntity();
|
|
|
+// userEntity.setPassword(password);
|
|
|
+// userEntity.setMobile(phoneNum);
|
|
|
+// userEntity.setUsername(phoneNum);
|
|
|
+// userEntity.setStatus(1);
|
|
|
+// //TODO:看看放这里是否合适
|
|
|
+// userEntity.setCreateUserId(1L);
|
|
|
+// //TODO:这里默认给76的默认部门
|
|
|
+// userEntity.setDeptId(76L);
|
|
|
+// sysUserService.addNewUserWithoutCheck(userEntity);
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 退出
|
|
|
+// */
|
|
|
+// @RequestMapping(value = "logout", method = RequestMethod.GET)
|
|
|
+// public String logout() {
|
|
|
+// ShiroUtils.logout();
|
|
|
+// return "redirect:/";
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|