dyh-gateway/src/main/java/cn/huge/gateway/filter/AuthFilter.java
@@ -1,5 +1,6 @@ package cn.huge.gateway.filter; import cn.huge.gateway.utils.ReturnBO; import cn.huge.gateway.utils.SpringContextUtil; import com.auth0.jwt.JWT; import com.auth0.jwt.JWTVerifier; @@ -87,6 +88,7 @@ if (status) { return chain.filter(exchange); } else { ReturnBO returnBO = new ReturnBO(); //从请求头中取出token String token = exchange.getRequest().getHeaders().getFirst("Authorization"); //未携带token或token在黑名单内 @@ -94,34 +96,26 @@ ServerHttpResponse originalResponse = exchange.getResponse(); originalResponse.setStatusCode(HttpStatus.OK); originalResponse.getHeaders().add("Content-Type", "application/json;charset=UTF-8"); byte[] response = "{\"code\": \"401\",\"msg\": \"用户未登录,请进行登录!\"}" .getBytes(StandardCharsets.UTF_8); returnBO.setCode(401); returnBO.setMsg("您尚未登录,请登录后重试!"); byte[] response = returnBO.toString().getBytes(StandardCharsets.UTF_8); DataBuffer buffer = originalResponse.bufferFactory().wrap(response); return originalResponse.writeWith(Flux.just(buffer)); } else { //取出token包含的身份 Map<String, Object> result = verifyJWT(token); int code = (int) result.get("code"); if (code != 0) { returnBO = verifyJWT(token); if (returnBO.getCode() != 0) { ServerHttpResponse originalResponse = exchange.getResponse(); originalResponse.setStatusCode(HttpStatus.OK); originalResponse.getHeaders().add("Content-Type", "application/json;charset=UTF-8"); String responseResult = "{\"code\": \"" + code + "\", \"msg\": \"" + result.get("msg") + "\"}"; byte[] response = responseResult.getBytes(StandardCharsets.UTF_8); byte[] response = returnBO.toString().getBytes(StandardCharsets.UTF_8); DataBuffer buffer = originalResponse.bufferFactory().wrap(response); return originalResponse.writeWith(Flux.just(buffer)); } else { //将现在的request,添加当前身份 String userId = (String) result.get("userId"); String userId = (String) returnBO.getData(); ServerHttpRequest mutableReq = null; String custId = (String) result.get("custId"); if (StringUtils.isNotEmpty(custId)) { URI uri = exchange.getRequest().getURI(); URI newUri = assembleUri(uri, custId); exchange.getRequest().mutate().uri(newUri).header("Authorization-userId", userId).header("Authorization-custId", custId).build(); } else { exchange.getRequest().mutate().header("Authorization-userId", userId).build(); } exchange.getRequest().mutate().header("Authorization-userId", userId).build(); ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build(); return chain.filter(mutableExchange); } @@ -135,8 +129,8 @@ * @param token 授权信息 * @return Map */ private Map<String, Object> verifyJWT(String token){ Map<String, Object> result = new HashMap<>(); private ReturnBO verifyJWT(String token){ ReturnBO returnBO = new ReturnBO(); try { Algorithm algorithm = Algorithm.HMAC256(secretKey); JWTVerifier verifier = JWT.require(algorithm) @@ -145,25 +139,23 @@ DecodedJWT jwt = verifier.verify(token); String userId = jwt.getClaim("userId").asString(); if (userId.isEmpty()){ result.put("code", 401); result.put("msg", "登录用户已失效,请重新登录"); returnBO.setCode(401); returnBO.setMsg("您尚未登录,请登录后重试!"); }else{ result.put("code", 0); result.put("userId", userId); String custId = jwt.getClaim("custId").asString(); result.put("custId", custId); returnBO.setCode(0); returnBO.setData(userId); } } catch (JWTVerificationException e){ log.error("AuthFilter方法[verifyJWT]调用异常:"+e, e); if (e.getMessage().indexOf("The Token has expired") != -1){ result.put("code", 401); result.put("msg", "登录用户已失效,请重新登录!"); returnBO.setCode(401); returnBO.setMsg("您尚未登录,请登录后重试!"); }else{ result.put("code", 401); result.put("msg", "登录用户已失效,请重新登录"); returnBO.setCode(401); returnBO.setMsg("您尚未登录,请登录后重试!"); } } return result; return returnBO; } /** dyh-service/dyh-base/src/main/java/cn/huge/base/common/utils/DateUtils.java
@@ -174,7 +174,7 @@ * 获取当前时间 * @return Date */ public static Date getMowDate(){ public static Date getNowDate(){ return new Date(); } dyh-service/dyh-base/src/main/java/cn/huge/module/cust/constant/UserBaseConsts.java
@@ -16,6 +16,13 @@ public static final String MR_CIPHER = "byzfw2023!"; /** * 用户状态,1:在职/有效(默认),2:停用,3:离职 */ public static final String USER_STATUS_1 = "1"; public static final String USER_STATUS_2 = "2"; public static final String USER_STATUS_3 = "3"; /** * 部门类型,1:正常部门,2:特殊部门(调委会等) */ public static final String DEPT_TYPE_1 = "1"; @@ -33,13 +40,6 @@ */ public static final String IS_ROLE_1 = "1"; public static final String NO_ROLE_2 = "2"; /** * 用户状态,1:在职/有效(默认),2:停用,99:离职 */ public static final String USER_STATUS_1 = "1"; public static final String USER_STATUS_2 = "2"; public static final String USER_STATUS_99 = "99"; /** * 帐号类型,22_00027-1:pc帐号(默认),22_00027-2:微信小程序,22_00027-3:政数局统一平台 dyh-service/dyh-base/src/main/resources/template/service.ftl
@@ -116,7 +116,7 @@ */ public void save${className}(${className} ${lowerName}){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(${lowerName}.getId())){ ${lowerName}.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctrole/service/CRoleService.java
@@ -116,7 +116,7 @@ */ public void saveCRole(CRole cRole){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(cRole.getId())){ cRole.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctrole/service/CtRoledataService.java
@@ -116,7 +116,7 @@ */ public void saveCtRoledata(CtRoledata ctRoledata){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctRoledata.getId())){ ctRoledata.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctrole/service/CtRolefunService.java
@@ -116,7 +116,7 @@ */ public void saveCtRolefun(CtRolefun ctRolefun){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctRolefun.getId())){ ctRolefun.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/controller/web/CtAccountWebController.java
@@ -1,9 +1,15 @@ package cn.huge.module.ctuser.controller; import cn.huge.base.common.bo.ReturnBO; import cn.huge.base.common.utils.ReturnFailUtils; import cn.huge.base.common.utils.ReturnSucUtils; import cn.huge.base.config.CurrentUser; import cn.huge.module.constant.BaseConsts; import cn.huge.module.ctuser.domain.po.CtAccount; import cn.huge.module.ctuser.dto.CtAccountLoginDTO; import cn.huge.module.ctuser.dto.CtCipherDTO; import cn.huge.module.ctuser.service.CtAccountService; import cn.huge.module.utils.JwtUtils; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -38,160 +44,52 @@ private CtAccountService service; /** * 获取请求URL参数 * @return Map<String, Object> */ private Map<String, Object> getParameter(){ Map<String, Object> terms = Maps.newHashMap(); // 账号编号 String id = request.getParameter("id"); if (StringUtils.isNotBlank(id)){ terms.put("id", id); * web端-工作人员-用户登录 * @url {ctx}/api/web/ctAccount/login * @param ctAccountLoginDTO 登录对象 * @return Object */ @PostMapping(value = "login") public Object login(@RequestBody CtAccountLoginDTO ctAccountLoginDTO) { try { ReturnBO returnBO = service.webLogin(ctAccountLoginDTO); return returnBO; } catch (Exception e) { return ReturnFailUtils.getRepInfo(e.getMessage()); } // 用户编号 String userId = request.getParameter("userId"); if (StringUtils.isNotBlank(userId)){ terms.put("userId", userId); } // 帐号类型,1:平台web端,2:平台小程序 String accType = request.getParameter("accType"); if (StringUtils.isNotBlank(accType)){ terms.put("accType", accType); } // 身份唯一标识(存储唯一标识,比如账号、邮箱、手机号、第三方获取的唯一标识等) String acc = request.getParameter("acc"); if (StringUtils.isNotBlank(acc)){ terms.put("acc", acc); } // 授权凭证(比如密码 第三方登录的token等) String cipher = request.getParameter("cipher"); if (StringUtils.isNotBlank(cipher)){ terms.put("cipher", cipher); } // 授权凭证明文 String cipherOpen = request.getParameter("cipherOpen"); if (StringUtils.isNotBlank(cipherOpen)){ terms.put("cipherOpen", cipherOpen); } // 密码最新更新时间 String cipherTime = request.getParameter("cipherTime"); if (StringUtils.isNotBlank(cipherTime)){ terms.put("cipherTime", cipherTime); } // 最新登录时间 String loginTime = request.getParameter("loginTime"); if (StringUtils.isNotBlank(loginTime)){ terms.put("loginTime", loginTime); } // 限制登录时间(密码错误次数超过限制,默认30分钟) String limitTime = request.getParameter("limitTime"); if (StringUtils.isNotBlank(limitTime)){ terms.put("limitTime", limitTime); } // 删除状态,0:已删除,1:未删除 String deleteStatus = request.getParameter("deleteStatus"); if (StringUtils.isNotBlank(deleteStatus)){ terms.put("deleteStatus", deleteStatus); } // 顾客编号 String custId = request.getParameter("custId"); if (StringUtils.isNotBlank(custId)){ terms.put("custId", custId); } // 创建时间区间 String createStart = request.getParameter("createStart"); String createEnd = request.getParameter("createEnd"); if(StringUtils.isNotBlank(createStart) && StringUtils.isNotBlank(createEnd)) { terms.put("createStart", createStart); terms.put("createEnd", createEnd); } // 更新时间区间 String updateStart = request.getParameter("updateStart"); String updateEnd = request.getParameter("updateEnd"); if(StringUtils.isNotBlank(updateStart) && StringUtils.isNotBlank(updateEnd)) { terms.put("updateStart", updateStart); terms.put("updateEnd", updateEnd); } return terms; } /** * 条件查询多个 * @url {ctx}/api/web/ctAccount/listQuery * @return Object */ @GetMapping("/listQuery") public Object listQuery() { * web端-工作人员-用户选择/切换角色 * @url {ctx}/api/web/ctAccount/switchRole * @return Object */ @GetMapping(value = "switchRole") public Object switchRole(@RequestParam(value = "roleCode") String roleCode, @CurrentUser String userId) { try { Map<String, Object> terms = getParameter(); return ReturnSucUtils.getRepInfo(service.listTerms(terms)); StringBuffer result = new StringBuffer(); if (userId.indexOf(BaseConsts.AND) != -1){ String[] userIds = userId.split(BaseConsts.AND); result.append(userIds[0]).append(BaseConsts.AND).append(roleCode); }else { result.append(userId).append(BaseConsts.AND).append(roleCode); } return ReturnSucUtils.getRepInfo(JwtUtils.buildJWT(result.toString())); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 条件分页查询 * @url {ctx}/api/web/ctAccount/pageQuery * @param page 页码 * @param size 每页数量 * @return Object */ @GetMapping("/pageQuery") public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) { * web端-工作人员-修改密码 * @url {ctx}/api/v1/ctAccount/changeCipher * @param ctCipherDTO 修改密码对象 * @return Object */ @PostMapping(value = "changeCipher") public Object changeCipher(@CurrentUser String userId, @RequestBody CtCipherDTO ctCipherDTO) { try { Map<String, Object> terms = getParameter(); Sort sort = Sort.by(Sort.Direction.DESC, "create_time"); PageRequest pageRequest = PageRequest.of(page-1, size, sort); Page<CtAccount> ctAccountPage = service.pageQuery(pageRequest, terms); return ReturnSucUtils.getRepInfo( "处理成功", ctAccountPage); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 根据编号查询单个 * @url {ctx}/api/web/ctAccount/getById * @param id 主键编号 * @return Object */ @GetMapping("/getById") public Object getById(@RequestParam(value = "id") String id) { try { return ReturnSucUtils.getRepInfo(service.getById(id)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 根据主键单个 * @url {ctx}/api/web/ctAccount/deleteById * @param id 主键编号 * @return Object */ @GetMapping("/deleteById") public Object deleteById(@RequestParam(value = "id") String id) { try { service.removeById(id); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 新增或更新对象 * @url {ctx}/api/web/ctAccount/saveCtAccount * @param ctAccount 实体对象 * @return Object */ @PostMapping("/saveCtAccount") public Object saveCtAccount(@RequestBody CtAccount ctAccount) { try { service.saveCtAccount(ctAccount); return ReturnSucUtils.getRepInfo(); return service.webChangeCipher(userId, ctCipherDTO); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/controller/web/CtUserWebController.java
@@ -2,6 +2,7 @@ import cn.huge.base.common.utils.ReturnFailUtils; import cn.huge.base.common.utils.ReturnSucUtils; import cn.huge.base.config.CurrentUser; import cn.huge.module.ctuser.domain.po.CtUser; import cn.huge.module.ctuser.service.CtUserService; import com.google.common.collect.Maps; @@ -241,81 +242,17 @@ } /** * 条件查询多个 * @url {ctx}/api/web/ctUser/listQuery * @return Object */ @GetMapping("/listQuery") public Object listQuery() { try { Map<String, Object> terms = getParameter(); return ReturnSucUtils.getRepInfo(service.listTerms(terms)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 条件分页查询 * @url {ctx}/api/web/ctUser/pageQuery * @param page 页码 * @param size 每页数量 * @return Object */ @GetMapping("/pageQuery") public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) { try { Map<String, Object> terms = getParameter(); Sort sort = Sort.by(Sort.Direction.DESC, "create_time"); PageRequest pageRequest = PageRequest.of(page-1, size, sort); Page<CtUser> ctUserPage = service.pageQuery(pageRequest, terms); return ReturnSucUtils.getRepInfo( "处理成功", ctUserPage); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 根据编号查询单个 * @url {ctx}/api/web/ctUser/getById * @param id 主键编号 * @return Object */ @GetMapping("/getById") public Object getById(@RequestParam(value = "id") String id) { try { return ReturnSucUtils.getRepInfo(service.getById(id)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 根据主键单个 * @url {ctx}/api/web/ctUser/deleteById * @param id 主键编号 * @return Object */ @GetMapping("/deleteById") public Object deleteById(@RequestParam(value = "id") String id) { try { service.removeById(id); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 新增或更新对象 * @url {ctx}/api/web/ctUser/saveCtUser * @param ctUser 实体对象 * @return Object */ * web端-人员信息管理-新增/新用户信息 * @url {ctx}/api/v1/ctUser/saveCtUser * @param userId * @return Object * @throws Exception */ @PostMapping("/saveCtUser") public Object saveCtUser(@RequestBody CtUser ctUser) { public Object saveCtUser(@RequestBody CtUser ctUser, @CurrentUser String userId) { try { service.saveCtUser(ctUser); // 保存更新用户信息 service.webSaveCtUser(ctUser, userId); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/domain/po/CtUser.java
@@ -183,7 +183,7 @@ private Integer realStatus; /** * 用户状态,1:有效(默认),2:停用,99:离职 * 用户状态,1:有效(默认),2:停用,3:离职 */ @TableField(value = "status") private Integer status; dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/dto/CtAccountLoginDTO.java
New file @@ -0,0 +1,36 @@ package cn.huge.module.ctuser.dto; import lombok.Data; /** * @title: 客户用户账号登录数据传输类 * @description: 客户用户账号登录数据传输类 * @company:hugeinfo * @author: chenx * @time: 2022-02-22 15:24:51 * @version 1.0.0 */ @Data public class CtAccountLoginDTO { /** * 身份唯一标识(存储唯一标识,比如账号、邮箱、手机号、第三方获取的唯一标识等) */ private String acc; /** * 授权凭证(比如密码 第三方登录的token等) */ private String cipher; /** * 顾客编号 */ private String custId; /** * 验证码 */ private String loginCode; } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/dto/CtCipherDTO.java
New file @@ -0,0 +1,26 @@ package cn.huge.module.ctuser.dto; import lombok.Data; /** * @title: 客户用户修改密码数据传输类 * @description: 客户用户修改密码数据传输类 * @company:hugeinfo * @author: chenx * @time: 2022-02-22 15:24:51 * @version 1.0.0 */ @Data public class CtCipherDTO { /** * 旧密码 */ private String oldCipher; /** * 新密码 */ private String newCipher; } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/dto/CtUserAddrDTO.java
New file @@ -0,0 +1,66 @@ package cn.huge.module.ctuser.dto; import lombok.Data; /** * @title: 登录用户地址数据传输类 * @description: 登录用户地址数据传输类 * @company:hugeinfo * @author: chenx * @time: 2022-02-22 15:24:51 * @version 1.0.0 */ @Data public class CtUserAddrDTO { /** * 现居地省 */ private String prov; /** * 现居地省名称 */ private String provName; /** * 现居地市 */ private String city; /** * 现居地市名称 */ private String cityName; /** * 现居地区 */ private String area; /** * 现居地区名称 */ private String areaName; /** * 现居地街道 */ private String road; /** * 现居地街道名称 */ private String roadName; /** * 现居地社区 */ private String village; /** * 现居地社区名称 */ private String villageName; } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/dto/UserLoginDTO.java
New file @@ -0,0 +1,66 @@ package cn.huge.module.ctuser.dto; import cn.huge.module.ctuser.domain.po.CtUserole; import cn.huge.module.user.domain.po.CtUser; import cn.huge.module.user.domain.po.CtUserole; import lombok.Data; import java.util.Date; import java.util.List; /** * @title: 登录后返回前端用户实体类 * @description: 登录后返回前端用户实体类 * @company: hugeinfo * @author: liyj * @time: 2022-02-22 15:24:51 * @version: 1.0.0 */ @Data public class UserLoginDTO { /** * JWT token */ private String token; /** * 用户编号 */ private String userId; /** * 用户名称 */ private String trueName; /** * 用户单位 */ private String unit; /** * 用户部门 */ private String dept; /** * 客户编号 */ private String custId; /** * 上一次登录时间 */ private Date lastLoginTime; /** * 人员角色信息 */ private List<CtUserole> ctUseroleList; /** * 人员地址信息 */ private CtUserAddrDTO ctUserAddrDTO; } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java
@@ -1,12 +1,23 @@ package cn.huge.module.ctuser.service; import cn.huge.base.common.bo.ReturnBO; import cn.huge.base.common.exception.ServiceException; import cn.huge.base.common.utils.DateUtils; import cn.huge.base.common.utils.IdUtils; import cn.huge.base.common.utils.*; import cn.huge.module.client.api.impl.UtilsClientImpl; import cn.huge.module.ctuser.dao.mapper.CtAccountMapper; import cn.huge.module.ctuser.domain.po.CtAccount; import cn.huge.module.ctuser.domain.po.CtUser; import cn.huge.module.ctuser.domain.po.CtUserole; import cn.huge.module.ctuser.dto.CtAccountLoginDTO; import cn.huge.module.ctuser.dto.CtCipherDTO; import cn.huge.module.ctuser.dto.CtUserAddrDTO; import cn.huge.module.ctuser.dto.UserLoginDTO; import cn.huge.module.cust.constant.UserBaseConsts; import cn.huge.module.utils.JwtUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; @@ -15,8 +26,10 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; import javax.annotation.PostConstruct; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; @@ -39,6 +52,10 @@ @Autowired private UtilsClientImpl utilsClient; @Autowired private CtUserService ctUserService; @Autowired private CtUseroleService ctUseroleService; /** * 更新对象 @@ -116,7 +133,7 @@ */ public void saveCtAccount(CtAccount ctAccount){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctAccount.getId())){ ctAccount.setId(utilsClient.getNewTimeId()); @@ -130,4 +147,155 @@ } } /** * 根据账号和类型查询 * @param acc 账号 * @param accType 账号类型 * @return */ public CtAccount getByAccAndType(String acc, String accType){ QueryWrapper<CtAccount> accountWrapper = new QueryWrapper<>(); accountWrapper.eq("acc", acc) .eq("acc_type", accType); CtAccount ctAccount = this.getOne(accountWrapper); return ctAccount; } /** * 判断密码是否正确 * @param cipher 密码 * @param ctAccount 账号信息 * @return Boolean */ public Boolean checkCredential(String cipher, CtAccount ctAccount){ String credentialMd5 = DigestUtils.md5DigestAsHex(cipher.getBytes()); if (StringUtils.equals(credentialMd5, ctAccount.getCipher())) { return true; }else { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String createTime = sdf.format(ctAccount.getCreateTime()); String credentialTime = sdf.format(ctAccount.getCreateTime()); //是否修改过密码,未修改过可以用默认密码登录 if (createTime.equals(credentialTime)) { if (cipher.equals(UserBaseConsts.MR_CIPHER)) { return true; }else{ return false; } }else{ return false; } } } /** * web端-工作人员用户登录 * @param ctAccountLoginDTO 登录账号信息 * @return UserLoginDTO */ public ReturnBO webLogin(CtAccountLoginDTO ctAccountLoginDTO) { try{ // 判断账号密码是否为空 if (StringUtils.isBlank(ctAccountLoginDTO.getAcc()) || StringUtils.isBlank(ctAccountLoginDTO.getCipher())) { return ReturnSucUtils.getRepInfo("账号或密码不能为空", null); } // 判断账号是否存在 CtAccount ctAccount = this.getByAccAndType(ctAccountLoginDTO.getAcc(), UserBaseConsts.ACC_TYPE_1); if (ObjectUtils.isNotEmpty(ctAccount)){ // 判断账号是否被锁定 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()) + "后重试,或者请联系管理员解锁!"); } } // 判断密码是否正确 if (checkCredential(ctAccountLoginDTO.getCipher(), ctAccount)) { //返回结果 UserLoginDTO userLoginDTO = new UserLoginDTO(); CtUser ctUser = ctUserService.getByIdFromRedis(ctAccount.getUserId()); if (ObjectUtils.isEmpty(ctUser)){ return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!"); } if (UserBaseConsts.USER_STATUS_2.equals(ctUser.getStatus()) || UserBaseConsts.USER_STATUS_3.equals(ctUser.getStatus())){ return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!"); } // 封装用户信息 userLoginDTO.setToken(JwtUtils.buildJWT(ctUser.getId())); userLoginDTO.setUserId(ctUser.getId()); userLoginDTO.setTrueName(ctUser.getTrueName()); userLoginDTO.setUnit(ctUser.getUnitName()); userLoginDTO.setDept(ctUser.getDeptName()); userLoginDTO.setCustId(ctUser.getCustId()); // 登录用户角色 List<CtUserole> ctUseroleList = ctUseroleService.listByUserId(ctUser.getId()); userLoginDTO.setCtUseroleList(ctUseroleList); // 登录用户地址信息 CtUserAddrDTO ctUserAddrDTO = new CtUserAddrDTO(); ctUserAddrDTO.setProv(ctUser.getProv()); ctUserAddrDTO.setProvName(ctUser.getProvName()); ctUserAddrDTO.setCity(ctUser.getCity()); ctUserAddrDTO.setCityName(ctUser.getCityName()); ctUserAddrDTO.setArea(ctUser.getArea()); ctUserAddrDTO.setAreaName(ctUser.getAreaName()); ctUserAddrDTO.setRoad(ctUser.getRoad()); ctUserAddrDTO.setRoadName(ctUser.getRoadName()); ctUserAddrDTO.setVillage(ctUser.getVillage()); ctUserAddrDTO.setVillageName(ctUser.getVillageName()); userLoginDTO.setCtUserAddrDTO(ctUserAddrDTO); // 最后登录时间 Date loginTime = ctAccount.getLoginTime(); if (ObjectUtils.isEmpty(ctAccount.getLoginTime())){ loginTime = DateUtils.getNowDate(); } userLoginDTO.setLastLoginTime(loginTime); // 更新最新登录时间 UpdateWrapper<CtAccount> accountUpdateWrapper = new UpdateWrapper<>(); accountUpdateWrapper.set("login_time", loginTime).eq("id", ctAccount.getId()); this.update(accountUpdateWrapper); return ReturnSucUtils.getRepInfo(userLoginDTO); } else { return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!"); } }else{ return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!"); } }catch (Exception e){ log.error("service方法[AccountService.webLogin]调用失败,异常信息:"+e, e); throw new ServiceException("CtAccountService.webLogin", e); } } /** * web端-工作人员-修改密码 * @param userId 用户编号 * @param ctCipherDTO 修改密码信息 * @return */ public ReturnBO webChangeCipher(String userId, CtCipherDTO ctCipherDTO){ try{ CtAccount ctAccount = this.getByAccAndType(userId, UserBaseConsts.ACC_TYPE_1); if (ObjectUtils.isEmpty(ctAccount)){ return ReturnFailUtils.getRepInfo("输入账号或密码不正确,请确认后重试!"); } String oldCredentialMd5 = DigestUtils.md5DigestAsHex(ctCipherDTO.getOldCipher().getBytes()); if (!StringUtils.equals(oldCredentialMd5, ctAccount.getCipher())) { return ReturnFailUtils.getRepInfo("输入账号或密码不正确,请确认后重试!"); } String newCredentialMd5 = DigestUtils.md5DigestAsHex(ctCipherDTO.getNewCipher().getBytes()); if (StringUtils.equals(newCredentialMd5, ctAccount.getCipher())) { return ReturnFailUtils.getRepInfo("新密码不能和旧密码相同!"); } UpdateWrapper<CtAccount> accountUpdateWrapper = new UpdateWrapper<>(); accountUpdateWrapper.set("cipher", newCredentialMd5).set("cipher_open", ctCipherDTO.getNewCipher()) .set("update_time", DateUtils.getNowDate()).eq("id", ctAccount.getId()); this.update(accountUpdateWrapper); return ReturnSucUtils.getRepInfo(); }catch (Exception e){ log.error("service方法[AccountService.webChangeCipher]调用失败,异常信息:"+e, e); throw new ServiceException("CtAccountService.webChangeCipher", e); } } } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java
@@ -116,7 +116,7 @@ */ public void saveCtDept(CtDept ctDept){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctDept.getId())){ ctDept.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtPostService.java
@@ -116,7 +116,7 @@ */ public void saveCtPost(CtPost ctPost){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctPost.getId())){ ctPost.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java
@@ -116,7 +116,7 @@ */ public void saveCtUnit(CtUnit ctUnit){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctUnit.getId())){ ctUnit.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUsepostService.java
@@ -116,7 +116,7 @@ */ public void saveCtUsepost(CtUsepost ctUsepost){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctUsepost.getId())){ ctUsepost.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java
@@ -1,13 +1,22 @@ package cn.huge.module.ctuser.service; import cn.huge.base.common.exception.MethodException; import cn.huge.base.common.exception.ServiceException; import cn.huge.base.common.utils.DateUtils; import cn.huge.base.common.utils.IdUtils; import cn.huge.base.common.utils.ObjectUtils; import cn.huge.module.client.api.impl.UtilsClientImpl; import cn.huge.module.constant.BaseConsts; import cn.huge.module.ctuser.dao.mapper.CtUserMapper; import cn.huge.module.ctuser.domain.po.CtUser; import cn.huge.module.cust.constant.UserBaseConsts; import cn.huge.module.redis.constant.RedisKeyConsts; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +24,7 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; import javax.annotation.PostConstruct; import java.util.Date; @@ -33,6 +43,9 @@ @Service @Transactional(rollbackFor = Exception.class) public class CtUserService extends ServiceImpl<CtUserMapper, CtUser>{ @Autowired private RedisTemplate<String, Object> redisTemplate; @Autowired private CtUserMapper mapper; @@ -111,23 +124,74 @@ } /** * 新增或更新对象 * @param ctUser 实体对象 */ public void saveCtUser(CtUser ctUser){ * 新增对象 * @param ctUser 实体对象 */ public void saveToRedis(CtUser ctUser){ try{ Date nowDate = DateUtils.getMowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctUser.getId())){ ctUser.setId(utilsClient.getNewTimeId()); ctUser.setCreateTime(nowDate); } ctUser.setUpdateTime(nowDate); this.saveOrUpdate(ctUser); mapper.insert(ctUser); // 清楚redis缓存 String key = RedisKeyConsts.CTUSER + ctUser.getId(); redisTemplate.delete(key); // 重新set redisTemplate.opsForValue().set(key, ctUser); }catch (Exception e){ log.error("[CtUserService.saveCtUser]调用失败,异常信息:"+e, e); throw new ServiceException("CtUserService.saveCtUser", e); } } /** * 更新对象 * @param ctUser 实体对象 */ public void updateToRedis(CtUser ctUser){ try{ mapper.updateById(ctUser); // 清楚redis缓存 String key = RedisKeyConsts.CTUSER + ctUser.getId(); redisTemplate.delete(key); // 重新set redisTemplate.opsForValue().set(key, ctUser); }catch (Exception e){ log.error("[CtUserService.saveCtUser]调用失败,异常信息:"+e, e); throw new ServiceException("CtUserService.saveCtUser", e); } } /** * 根据id查询 * @param id 编号 * @return */ public CtUser getByIdFromRedis(String id){ String key = RedisKeyConsts.CTUSER + id; // 从redis获取 CtUser ctUser = (CtUser) redisTemplate.opsForValue().get(key); if (ObjectUtils.isEmpty(ctUser)){ ctUser = mapper.selectById(id); if (ObjectUtils.isNotEmpty(ctUser)){ redisTemplate.opsForValue().set(key, ctUser); } } return ctUser; } /** * web端-人员信息管理-新增/新用户信息 * @param ctUser * @param userId */ public void webSaveCtUser(CtUser ctUser, String userId) { try { // 获取当前登录用户 CtUser loginUser = this.getByIdFromRedis(userId); Date nowDate = DateUtils.getNowDate(); } catch (Exception e) { log.error("service方法[CtUserService.webSaveCtUser]调用异常:" + e, e); throw new MethodException(e.getMessage()); } } } dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUseroleService.java
@@ -6,8 +6,10 @@ import cn.huge.module.client.api.impl.UtilsClientImpl; import cn.huge.module.ctuser.dao.mapper.CtUseroleMapper; import cn.huge.module.ctuser.domain.po.CtUserole; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -33,6 +35,9 @@ @Service @Transactional(rollbackFor = Exception.class) public class CtUseroleService extends ServiceImpl<CtUseroleMapper, CtUserole>{ @Autowired private RedisTemplate<String, Object> redisTemplate; @Autowired private CtUseroleMapper mapper; @@ -116,7 +121,7 @@ */ public void saveCtUserole(CtUserole ctUserole){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctUserole.getId())){ ctUserole.setId(utilsClient.getNewTimeId()); @@ -130,4 +135,16 @@ } } } /** * 根据userId查询 * @param userId 用户编号 * @return */ public List<CtUserole> listByUserId(String userId){ QueryWrapper<CtUserole> ctUseroleQueryWrapper = new QueryWrapper<>(); ctUseroleQueryWrapper.eq("user_id", userId); List<CtUserole> ctUseroleList = mapper.selectList(ctUseroleQueryWrapper); return ctUseroleList; } } dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaAccountService.java
@@ -116,7 +116,7 @@ */ public void savePaAccount(PaAccount paAccount){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(paAccount.getId())){ paAccount.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaUserService.java
@@ -116,7 +116,7 @@ */ public void savePaUser(PaUser paUser){ try{ Date nowDate = DateUtils.getMowDate(); Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(paUser.getId())){ paUser.setId(utilsClient.getNewTimeId()); dyh-service/dyh-cust/src/main/java/cn/huge/module/redis/constant/RedisKeyConsts.java
New file @@ -0,0 +1,42 @@ package cn.huge.module.redis.constant; /** * @title: redis缓存key标识 * @description: redis缓存key标识 * @company: hugeinfo * @author: liyj * @time: 2021-11-05 16:51:48 * @version: 1.0.0 */ public class RedisKeyConsts { /** * ctUser标识 */ public static final String CTUSER = "ctuser"; } /** * -------------------_ooOoo_------------------- * ------------------o8888888o------------------ * ------------------88" . "88------------------ * ------------------(| -_- |)------------------ * ------------------O\ = /O------------------ * ---------------____/`---'\____--------------- * -------------.' \\| |// `.------------- * ------------/ \\||| : |||// \------------ * -----------/ _||||| -:- |||||- \----------- * -----------| | \\\ - /// | |----------- * -----------| \_| ''\---/'' | |----------- * -----------\ .-\__ `-` ___/-. /----------- * ---------___`. .' /--.--\ `. . __---------- * ------."" '< `.___\_<|>_/___.' >'"".------- * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- * -----\ \ `-. \_ __\ /__ _/ .-` / /----- * ======`-.____`-.___\_____/___.-`____.-'====== * -------------------`=---=' * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * ---------佛祖保佑---hugeinfo---永无BUG---------- */ dyh-service/dyh-utils/src/main/java/cn/huge/module/common/utils/CaseNoUtils.java
@@ -28,7 +28,7 @@ */ public synchronized static String getCaseNo(){ CASE_NO_SIGN += 1; int year = DateUtils.getYear(DateUtils.getMowDate()); int year = DateUtils.getYear(DateUtils.getNowDate()); String cloudMediateId = "(" + year + ")粤云调" + (CASE_NO_SIGN) + "号"; System.out.println(cloudMediateId); return cloudMediateId; dyh-service/dyh-utils/src/main/java/cn/huge/module/common/utils/JudicNoUtils.java
@@ -28,7 +28,7 @@ */ public synchronized static String getJudicNo(){ JUDIC_NO_SIGN += 1; int year = DateUtils.getYear(DateUtils.getMowDate()); int year = DateUtils.getYear(DateUtils.getNowDate()); String cloudMediateId = "(" + year + ")司法确认" + (JUDIC_NO_SIGN) + "号"; System.out.println(cloudMediateId); return cloudMediateId;