From b47d4a7accabce974e19d2a1ffb3c5c67507d74b Mon Sep 17 00:00:00 2001
From: wangwh <2397901735@qq.com>
Date: Wed, 28 Aug 2024 15:11:59 +0800
Subject: [PATCH] 1、组织架构的接口 2、事项登记接口
---
dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java | 195 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 190 insertions(+), 5 deletions(-)
diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java
index 33acd57..f9c4a3d 100644
--- a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java
+++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtAccountService.java
@@ -1,22 +1,33 @@
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;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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 +50,10 @@
@Autowired
private UtilsClientImpl utilsClient;
+ @Autowired
+ private CtUserService ctUserService;
+ @Autowired
+ private CtUseroleService ctUseroleService;
/**
* 更新对象
@@ -116,7 +131,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 +145,174 @@
}
}
+ /**
+ * 根据账号和类型查询
+ * @param acc 账号
+ * @param accType 账号类型
+ * @return
+ */
+ public CtAccount getByAccAndType(String acc, int accType){
+ QueryWrapper<CtAccount> accountWrapper = new QueryWrapper<>();
+ accountWrapper.eq("acc", acc)
+ .eq("acc_type", accType);
+ CtAccount ctAccount = this.getOne(accountWrapper);
+ return ctAccount;
+ }
+
+ /**
+ * 根据用户编号和类型查询
+ * @param userId 用户编号
+ * @param accType 账号类型
+ * @return
+ */
+ public CtAccount getByUserIdAndType(String userId, int accType){
+ QueryWrapper<CtAccount> accountWrapper = new QueryWrapper<>();
+ accountWrapper.eq("user_id", userId)
+ .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.getById(ctAccount.getUserId());
+ if (ObjectUtils.isEmpty(ctUser)){
+ return ReturnFailUtils.getRepInfo("账号或密码错误,请确认后重试!");
+ }
+ if (ctUser.getStatus() != UserBaseConsts.USER_STATUS_1){
+ 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{
+ CtUser loginUser = ctUserService.getById(userId);
+ CtAccount ctAccount = this.getByAccAndType(loginUser.getAcc(), UserBaseConsts.ACC_TYPE_1);
+// QueryWrapper<CtAccount> ctAccountQueryWrapper = new QueryWrapper<>();
+// ctAccountQueryWrapper.eq("user_id", loginUser.getId()).
+// eq("acc_type", UserBaseConsts.ACC_TYPE_1);
+// CtAccount ctAccount =mapper.selectOne(ctAccountQueryWrapper);
+ 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);
+ }
+ }
+
}
--
Gitblit v1.8.0