|
@@ -6,11 +6,9 @@ import com.tianhu.common.core.constant.Constants;
|
|
|
import com.tianhu.common.core.constant.SalaryConstants;
|
|
|
import com.tianhu.common.core.constant.UserConstants;
|
|
|
import com.tianhu.common.core.domain.R;
|
|
|
+import com.tianhu.common.core.enums.UserStatus;
|
|
|
import com.tianhu.common.core.exception.BaseException;
|
|
|
-import com.tianhu.common.core.utils.CommonUtil;
|
|
|
-import com.tianhu.common.core.utils.IdUtils;
|
|
|
-import com.tianhu.common.core.utils.SecurityUtils;
|
|
|
-import com.tianhu.common.core.utils.StringUtils;
|
|
|
+import com.tianhu.common.core.utils.*;
|
|
|
import com.tianhu.common.core.utils.poi.ExcelUtil;
|
|
|
import com.tianhu.common.core.web.controller.BaseController;
|
|
|
import com.tianhu.common.core.web.domain.AjaxResult;
|
|
@@ -19,7 +17,9 @@ import com.tianhu.common.log.enums.BusinessType;
|
|
|
import com.tianhu.common.redis.service.RedisService;
|
|
|
import com.tianhu.common.security.annotation.PreAuthorize;
|
|
|
import com.tianhu.common.security.service.TokenService;
|
|
|
+import com.tianhu.system.api.RemoteLogService;
|
|
|
import com.tianhu.system.api.RemoteSystemService;
|
|
|
+import com.tianhu.system.api.RemoteUserService;
|
|
|
import com.tianhu.system.api.domain.SysDept;
|
|
|
import com.tianhu.system.api.domain.SysRole;
|
|
|
import com.tianhu.system.api.domain.SysUser;
|
|
@@ -34,6 +34,7 @@ import com.tianhu.system.mapper.SysUserRoleMapper;
|
|
|
import com.tianhu.system.service.*;
|
|
|
import com.tianhu.system.utils.FlowableService;
|
|
|
import com.tianhu.system.utils.SysConstant;
|
|
|
+import io.micrometer.core.lang.Nullable;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -43,7 +44,14 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Matcher;
|
|
@@ -100,6 +108,10 @@ public class SysUserController extends BaseController
|
|
|
private ISysCompanyService sysCompanyService;
|
|
|
@Autowired
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
+ @Autowired
|
|
|
+ private RemoteLogService remoteLogService;
|
|
|
+ @Autowired
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
/**
|
|
|
* 用户注册成功
|
|
|
*/
|
|
@@ -143,13 +155,14 @@ public class SysUserController extends BaseController
|
|
|
* 获取当前用户信息
|
|
|
*/
|
|
|
@PostMapping("/zcInfo")
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public R<Map<String, Object>> info(@RequestParam(value = "type", required = false) String type,
|
|
|
+ @Log(title = "用户登录", businessType = BusinessType.UPDATE)
|
|
|
+ public R info(@RequestParam(value = "type", required = false) String type,
|
|
|
@RequestParam(value = "code", required = false) String code,
|
|
|
@RequestParam(value = "uuid", required = false) String uuid,
|
|
|
@RequestParam(value = "unionId", required = false) String unionId,
|
|
|
@RequestParam(value = "username") String username,
|
|
|
- @RequestParam(value = "shortMessageCode", required = false) String shortMessageCode)
|
|
|
+ @RequestParam(value = "password") String password,
|
|
|
+ @RequestParam(value = "shortMessageCode", required = false) String shortMessageCode) throws ParseException
|
|
|
{
|
|
|
Map<String, Object> resMap = new HashMap<>();
|
|
|
|
|
@@ -167,24 +180,24 @@ public class SysUserController extends BaseController
|
|
|
List<PubVerifyCode> staffInf = iPubVerifyCodeService.findPubVerifyCodes(pubVerifyCode);
|
|
|
if(staffInf.size()>0){
|
|
|
if("01".equals(staffInf.get(0).getPvcState())){
|
|
|
- throw new BaseException("验证码已失效,请重新获取!");
|
|
|
+ return R.fail("验证码已失效,请重新获取!");
|
|
|
}
|
|
|
//取得指定时间间隔后的系统时间
|
|
|
GregorianCalendar calendar = (GregorianCalendar) Calendar.getInstance();
|
|
|
calendar.add( Calendar.MINUTE, -5);
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
if(formatter.format(calendar.getTime()).compareTo(formatter.format(staffInf.get(0).getPvcLastTime()))>0){
|
|
|
- throw new BaseException("验证码已失效,请重新获取!");
|
|
|
+ return R.fail("验证码已失效,请重新获取!");
|
|
|
}
|
|
|
|
|
|
staffInf.get(0).setPvcState("01");
|
|
|
iPubVerifyCodeService.updatePubVerifyCode(staffInf.get(0));
|
|
|
|
|
|
}else{
|
|
|
- throw new BaseException("验证码错误,请重新输入!");
|
|
|
+ return R.fail("验证码错误,请重新输入!");
|
|
|
}
|
|
|
}else{
|
|
|
- throw new BaseException("请填写验证码!");
|
|
|
+ return R.fail("请填写验证码");
|
|
|
}
|
|
|
|
|
|
// 未注册账号,自动注册一个账号
|
|
@@ -192,8 +205,8 @@ public class SysUserController extends BaseController
|
|
|
sysUser = new SysUser();
|
|
|
sysUser.setUserName(username);
|
|
|
sysUser.setNickName(username);
|
|
|
- String password = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
- sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
+ String passwords = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(passwords));
|
|
|
userService.insertUser(sysUser);
|
|
|
sysUser = userService.selectUserByUserName(username);
|
|
|
|
|
@@ -208,10 +221,11 @@ public class SysUserController extends BaseController
|
|
|
// 扫码后注册
|
|
|
if ("2".equals(type)) {
|
|
|
if (StringUtils.isNotNull(sysUser)) {
|
|
|
- throw new BaseException("手机号已被注册!");
|
|
|
+ return R.fail("手机号已被注册");
|
|
|
+
|
|
|
}
|
|
|
if (StringUtils.isEmpty(unionId)) {
|
|
|
- throw new BaseException("unionId数据错误!");
|
|
|
+ return R.fail("unionId数据错误");
|
|
|
}
|
|
|
|
|
|
//查询微信关联表找到员工信息
|
|
@@ -219,14 +233,14 @@ public class SysUserController extends BaseController
|
|
|
weChatLambdaQueryWrapper.eq(SysWeChat::getSwcWxUuid, unionId);
|
|
|
List<SysWeChat> list = iSysWeChatService.findSysWeChats(weChatLambdaQueryWrapper);
|
|
|
if (list.size() != 0) {
|
|
|
- throw new BaseException("此微信已绑定账号!");
|
|
|
+ return R.fail("此微信已绑定账号");
|
|
|
}
|
|
|
|
|
|
sysUser = new SysUser();
|
|
|
sysUser.setUserName(username);
|
|
|
sysUser.setNickName(username);
|
|
|
- String password = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
- sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
+ String spassword = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(spassword));
|
|
|
userService.insertUser(sysUser);
|
|
|
sysUser = userService.selectUserByUserName(username);
|
|
|
|
|
@@ -250,8 +264,144 @@ public class SysUserController extends BaseController
|
|
|
} else {
|
|
|
if (StringUtils.isNull(sysUser))
|
|
|
{
|
|
|
- throw new BaseException("用户名或密码错误");
|
|
|
+ return R.fail("用户不存在");
|
|
|
+ }
|
|
|
+ int compareTo = 0;
|
|
|
+ //冻结开始时间
|
|
|
+ Date frozenDate = sysUser.getFrozen_date();
|
|
|
+ String startDate = "";
|
|
|
+ //到期时间
|
|
|
+ String endDate = "";
|
|
|
+ //当前时间
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateTime = simpleDateFormat.format(nowDate);
|
|
|
+ //登录错误次数
|
|
|
+ String frozenSecond = sysUser.getFrozen_second();
|
|
|
+ if(frozenDate != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ startDate = sdf.format(frozenDate);
|
|
|
+ //解冻时间
|
|
|
+ SysUser endUser = userService.selectUserByUserName(username);
|
|
|
+ Date time = endUser.getFrozen_date();
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(time);
|
|
|
+ c.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date nomalDate = c.getTime();
|
|
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ endDate = sdf1.format(nomalDate);
|
|
|
+ //时间比较
|
|
|
+ compareTo = dateTime.compareTo(endDate);
|
|
|
+ //冻结时间的第二天
|
|
|
+ if(compareTo == 0 || compareTo == 1){
|
|
|
+ Nullable dtiTime = null;
|
|
|
+ SysUser suser = new SysUser();
|
|
|
+ suser.setUserId(sysUser.getUserId());
|
|
|
+ suser.setStatus("0");
|
|
|
+ suser.setFrozen_second("0");
|
|
|
+ suser.setFrozen_date((Date)dtiTime);
|
|
|
+ userService.updateUserLogin(suser);
|
|
|
+ }
|
|
|
+ //如果当前时间比冻结结束时间早
|
|
|
+ if (compareTo == -1 && UserStatus.DELETED.getCode().equals(sysUser.getStatus())) {
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已冻结,请"+ endDate +"尝试登陆",sysUser.getCompanyId());
|
|
|
+ return R.fail("对不起,您的账号:" + username + " 已冻结,请"+ endDate +"尝试登陆");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //登录错误到达五次就转为冻结
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(frozenSecond);
|
|
|
+ BigDecimal decimal = new BigDecimal("4");
|
|
|
+ if (decimal.compareTo(bigDecimal) == 0) {
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setUserId(sysUser.getUserId());
|
|
|
+ user.setStatus("2");
|
|
|
+ user.setFrozen_date(DateUtils.getNowDate());
|
|
|
+ userService.updateUserLogin(user);
|
|
|
+ //算出到期时间
|
|
|
+ SysUser endUser = userService.selectUserByUserName(username);
|
|
|
+ Date time = endUser.getFrozen_date();
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(time);
|
|
|
+ c.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date nomalDate = c.getTime();
|
|
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ endDate = sdf1.format(nomalDate);
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已冻结,请"+ endDate +"尝试登陆",sysUser.getCompanyId());
|
|
|
+ return R.fail("对不起,您的账号:" + username + " 已冻结,请"+ endDate +"尝试登陆");
|
|
|
+ }
|
|
|
+ if (StringUtils.isAnyBlank(username, password))
|
|
|
+ {
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写",sysUser.getCompanyId());
|
|
|
+ return R.fail("用户/密码不可为空");
|
|
|
+ }
|
|
|
+ if (UserStatus.DELETED.getCode().equals(sysUser.getDelFlag()))
|
|
|
+ {
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号状态异常,请联系管理员",sysUser.getCompanyId());
|
|
|
+ return R.fail("对不起,您的账号:" + username + " 状态异常,请联系管理员");
|
|
|
}
|
|
|
+ // 密码如果不在指定范围内 错误
|
|
|
+ if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
+ || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|
|
+ {
|
|
|
+ //错误次数加一次
|
|
|
+ BigDecimal firstDecimal = new BigDecimal(frozenSecond);
|
|
|
+ BigDecimal twoDecimal = new BigDecimal("1");
|
|
|
+ BigDecimal result = firstDecimal.add(twoDecimal);
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setUserId(sysUser.getUserId());
|
|
|
+ user.setFrozen_second(result.toString());
|
|
|
+ userService.updateUserLogin(user);
|
|
|
+ //算出剩余次数
|
|
|
+ BigDecimal threeDecimal = new BigDecimal("5");
|
|
|
+ BigDecimal resultDecimal = new BigDecimal(result.toString());
|
|
|
+ BigDecimal surplus = threeDecimal.subtract(resultDecimal);
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "密码或账号错误,请重新输入,当日还有"+ surplus +"次试错机会!!",sysUser.getCompanyId());
|
|
|
+ return R.fail("密码或账号错误,请重新输入,当日还有"+ surplus +"次试错机会!!!");
|
|
|
+ }
|
|
|
+ // 用户名不在指定范围内 错误
|
|
|
+ if (username.length() < UserConstants.USERNAME_MIN_LENGTH || username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|
|
+ {
|
|
|
+ //错误次数加一次
|
|
|
+ BigDecimal firstDecimal = new BigDecimal(frozenSecond);
|
|
|
+ BigDecimal twoDecimal = new BigDecimal("1");
|
|
|
+ BigDecimal result = firstDecimal.add(twoDecimal);
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setUserId(sysUser.getUserId());
|
|
|
+ user.setFrozen_second(result.toString());
|
|
|
+ userService.updateUserLogin(user);
|
|
|
+ //算出剩余次数
|
|
|
+ BigDecimal threeDecimal = new BigDecimal("5");
|
|
|
+ BigDecimal resultDecimal = new BigDecimal(result.toString());
|
|
|
+ BigDecimal surplus = threeDecimal.subtract(resultDecimal);
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "密码或账号错误,请重新输入,当日还有"+ surplus +"次试错机会!!",sysUser.getCompanyId());
|
|
|
+ return R.fail("密码或账号错误,请重新输入,当日还有"+ surplus +"次试错机会!!!");
|
|
|
+ }
|
|
|
+ // 账号 + 密码登陆
|
|
|
+ if ("0".equals(type) && !SecurityUtils.matchesPassword(password, sysUser.getPassword()))
|
|
|
+ {
|
|
|
+ //错误次数加一次
|
|
|
+ BigDecimal firstDecimal = new BigDecimal(frozenSecond);
|
|
|
+ BigDecimal twoDecimal = new BigDecimal("1");
|
|
|
+ BigDecimal result = firstDecimal.add(twoDecimal);
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setUserId(sysUser.getUserId());
|
|
|
+ user.setFrozen_second(result.toString());
|
|
|
+ userService.updateUserLogin(user);
|
|
|
+ //算出剩余次数
|
|
|
+ BigDecimal threeDecimal = new BigDecimal("5");
|
|
|
+ BigDecimal resultDecimal = new BigDecimal(result.toString());
|
|
|
+ BigDecimal surplus = threeDecimal.subtract(resultDecimal);
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "密码或账号错误,请重新输入,当日还有"+ surplus +"次试错机会!!",sysUser.getCompanyId());
|
|
|
+ return R.fail("密码或账号错误,请重新输入,当日还有"+ surplus +"次试错机会!!!");
|
|
|
+ }
|
|
|
+ //正常登录,冻结时间清空,错误次数归零
|
|
|
+ Nullable dtiTime = null;
|
|
|
+ SysUser suser = new SysUser();
|
|
|
+ suser.setUserId(sysUser.getUserId());
|
|
|
+ suser.setFrozen_second("0");
|
|
|
+ suser.setFrozen_date((Date) dtiTime);
|
|
|
+ userService.updateUserLogin(suser);
|
|
|
+ remoteLogService.saveLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功",sysUser.getCompanyId());
|
|
|
}
|
|
|
// 查询是否实名认证
|
|
|
LambdaQueryWrapper<SysUserCompanyRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
@@ -282,7 +432,7 @@ public class SysUserController extends BaseController
|
|
|
SysCompany company = companyService.getById(userCompanyRelList.get(0).getSucrCompanyId());
|
|
|
sysUser.setCompanyType(company.getScyType());
|
|
|
if ("01".equals(company.getScyStatus()) || "99".equals(company.getScyStatus())) {
|
|
|
- throw new BaseException("企业状态异常,请联系管理员!");
|
|
|
+ return R.fail("企业状态异常,请联系管理员!");
|
|
|
}
|
|
|
sysUser.setCompanyStatus(company.getScyStatus());
|
|
|
// 平台用户
|
|
@@ -659,4 +809,19 @@ public class SysUserController extends BaseController
|
|
|
return ajax;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据手机号获取用户姓名
|
|
|
+ */
|
|
|
+ @GetMapping("selectNormalUser")
|
|
|
+ public AjaxResult selectNormalUser(String userName)
|
|
|
+ {
|
|
|
+ Map map = new HashMap();
|
|
|
+ if(CommonUtil.isNotEmpty(userName)) {
|
|
|
+ map.put("userName", userName);
|
|
|
+ List<Map> list = userService.selectNormalUser(map);
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
}
|