广州市综治平台后端
xusd
23 hours ago e9de6064cc94d6bc63685c5e62046ff810b96dab
dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java
@@ -29,10 +29,7 @@
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * @author liyj
@@ -201,7 +198,7 @@
    public Boolean checkCredential(String cipher, CtAccount ctAccount) {
        String credentialMd5 = DigestUtils.md5DigestAsHex(cipher.getBytes());
        log.info("xsd:{}", credentialMd5);
        if (StringUtils.equals(credentialMd5, ctAccount.getCipher())) {
        if (StringUtils.equals(cipher, ctAccount.getCipher())) {
            return true;
        } else {
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
@@ -235,9 +232,9 @@
            // 判断账号是否存在
            CtAccount ctAccount = this.getByAccAndType(ctAccountLoginDTO.getAcc(), UserBaseConsts.ACC_TYPE_1);
            if (ObjectUtils.isNotEmpty(ctAccount)) {
                Date nowDate = new Date();
                // 判断账号是否被锁定
                if (ObjectUtils.isNotEmpty(ctAccount.getLimitTime())) {
                    Date nowDate = new Date();
                    if (nowDate.before(ctAccount.getLimitTime())) {
                        SimpleDateFormat sdf = new SimpleDateFormat("HH点mm分");
                        return ReturnFailUtils.getRepInfo("账号已锁定,请于" + sdf.format(ctAccount.getLimitTime()) + "后重试,或者请联系管理员解锁!");
@@ -245,6 +242,13 @@
                }
                // 判断密码是否正确
                if (checkCredential(ctAccountLoginDTO.getCipher(), ctAccount)) {
                    // 密码正确:重置错误次数
                    UpdateWrapper<CtAccount> resetPwdErr = new UpdateWrapper<>();
                    resetPwdErr.set("pwd_error_count", 0)
                            .set("limit_time", null)
                            .set("login_time", DateUtils.getNowDate())
                            .eq("id", ctAccount.getId());
                    this.update(resetPwdErr);
                    //返回结果
                    UserLoginDTO userLoginDTO = new UserLoginDTO();
                    CtUser ctUser = ctUserService.getById(ctAccount.getUserId());
@@ -307,7 +311,25 @@
                    this.update(accountUpdateWrapper);
                    return ReturnSucUtils.getRepInfo(userLoginDTO);
                } else {
                    return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!");
                    // 密码错误:增加错误次数,必要时冻结
                    int currentErrCount = ctAccount.getPwdErrorCount() == null ? 0 : ctAccount.getPwdErrorCount();
                    currentErrCount++;
                    UpdateWrapper<CtAccount> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.set("pwd_error_count", currentErrCount).eq("id", ctAccount.getId());
                    if (currentErrCount >= 5) {
                        // 冻结5分钟
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(nowDate);
                        cal.add(Calendar.MINUTE, 5);
                        updateWrapper.set("limit_time", cal.getTime());
                        this.update(updateWrapper);
                        return ReturnFailUtils.getRepInfo("密码错误已达5次,账号已锁定5分钟,请稍后再试!");
                    } else {
                        this.update(updateWrapper);
                        return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!(" + currentErrCount + "/5)");
                    }
                }
            } else {
                return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!");
@@ -497,8 +519,10 @@
                CtUnit ctUnit = ctUnitService.selectUnitByGridId(userRoleDTO.getOrgId());
                if (ctUnit != null) {
                    userLoginDTO.setUnit(ctUnit.getUnitName());
                    userLoginDTO.setUnitType(ctUnit.getUnitType());
                    ctUser.setUnitName(ctUnit.getUnitName());
                    ctUser.setUnitId(ctUnit.getId());
                    ctUserService.updateCtUser(ctUser);
                } else {
                    int grade = userRoleDTO.getGrade() - 1;