添加Md5Util工具类进行MD5加密,优化供应商注册逻辑,优化SysOrgServiceImpl类的树形结构查询逻辑,移除冗余代码。
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# 使用官方Java基础镜像
|
||||
FROM openjdk:8-jdk-alpine
|
||||
FROM openjdk:8
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
@ -52,6 +52,7 @@ import com.coscoshipping.ebtp.system.org.service.SysOrgService;
|
||||
import com.coscoshipping.ebtp.system.user.dao.SysExpertUserMapper;
|
||||
import com.coscoshipping.ebtp.system.user.dao.SysSupplierUserMapper;
|
||||
import com.coscoshipping.ebtp.system.user.entity.SysUser;
|
||||
import com.coscoshipping.ebtp.system.user.util.Md5Util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -120,7 +121,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
|
||||
String pw = new String(decode);
|
||||
|
||||
if (!this.encode(pw).equals(user.getPassword())) {
|
||||
if (!Md5Util.encode(pw).equals(user.getPassword())) {
|
||||
throw new RuntimeException("用户名或密码错误!");
|
||||
}
|
||||
|
||||
@ -200,7 +201,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
|
||||
String pw = new String(decode);
|
||||
|
||||
if (!this.encode(pw).equals(user.getPassword())) {
|
||||
if (!Md5Util.encode(pw).equals(user.getPassword())) {
|
||||
throw new RuntimeException("用户名或密码错误!");
|
||||
}
|
||||
|
||||
@ -259,7 +260,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
|
||||
String pw = new String(decode);
|
||||
|
||||
if (!this.encode(pw).equals(user.getPassword())) {
|
||||
if (!Md5Util.encode(pw).equals(user.getPassword())) {
|
||||
throw new RuntimeException("用户名或密码错误!");
|
||||
}
|
||||
|
||||
@ -416,21 +417,6 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
public String encode(String str) {
|
||||
// 生成一个MD5加密计算摘要
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
// 计算md5函数
|
||||
md.update(str.getBytes());
|
||||
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
|
||||
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
|
||||
return new BigInteger(1, md.digest()).toString(16);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserHost() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
@ -621,7 +607,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
throw new RuntimeException("无效用户!");
|
||||
}
|
||||
// 加密新密码
|
||||
String encodedPassword = this.encode(resetPassword);
|
||||
String encodedPassword = Md5Util.encode(resetPassword);
|
||||
|
||||
// 更新数据库
|
||||
SysUser updateUser = new SysUser();
|
||||
@ -648,7 +634,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
// System.out.println(RSA.decrypt(p2,privateKey));
|
||||
|
||||
BaseUserServiceImpl baseUserService = new BaseUserServiceImpl();
|
||||
String mm = baseUserService.encode("cosco2025");
|
||||
String mm = Md5Util.encode("cosco2025");
|
||||
System.out.println(mm);
|
||||
|
||||
String mm2 = RSA.encrypt("cosco2025", publicKey);
|
||||
|
@ -52,48 +52,37 @@ public class SysOrgServiceImpl extends BaseServiceImpl<SysOrgMapper, SysOrg> imp
|
||||
|
||||
@Override
|
||||
public List<SysOrgVO> getTreeByNode(SysOrg org) {
|
||||
// 1. 先查询出所有的组织数据
|
||||
// 1. 如果有orgId或upOrgId,查本级及下级
|
||||
if (StringUtils.isNotBlank(org.getOrgId()) || StringUtils.isNotBlank(org.getUpOrgId())) {
|
||||
String nodeId = StringUtils.isNotBlank(org.getOrgId()) ? org.getOrgId() : org.getUpOrgId();
|
||||
SysOrg currentOrg = this.getById(nodeId);
|
||||
if (currentOrg == null) return new ArrayList<>();
|
||||
List<SysOrg> orgList = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||
.likeRight(SysOrg::getOrgFullId, currentOrg.getOrgFullId()));
|
||||
return buildOrgTree(orgList, org);
|
||||
}
|
||||
|
||||
// 2. 如果有orgName/orgNum等条件
|
||||
if (StringUtils.isNotBlank(org.getOrgName()) || StringUtils.isNotBlank(org.getOrgNum())) {
|
||||
List<SysOrg> matchList = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||
.like(StringUtils.isNotBlank(org.getOrgName()), SysOrg::getOrgName, org.getOrgName())
|
||||
.like(StringUtils.isNotBlank(org.getOrgNum()), SysOrg::getOrgNum, org.getOrgNum()));
|
||||
if (CollectionUtils.isEmpty(matchList)) return new ArrayList<>();
|
||||
// 拿到所有fullId,拆分出所有祖先节点id
|
||||
java.util.Set<String> allIds = new java.util.HashSet<>();
|
||||
for (SysOrg match : matchList) {
|
||||
String[] ids = match.getOrgFullId().split(",");
|
||||
java.util.Collections.addAll(allIds, ids);
|
||||
}
|
||||
// 查出所有相关节点
|
||||
List<SysOrg> orgList = this.list(new LambdaQueryWrapper<SysOrg>().in(SysOrg::getOrgId, allIds));
|
||||
return buildOrgTree(orgList, org);
|
||||
}
|
||||
|
||||
// 3. 没有条件,才全查
|
||||
List<SysOrg> allOrgList = this.list();
|
||||
|
||||
/*// 1. 先查询当前本级
|
||||
LambdaQueryWrapper<SysOrg> currentOrgQuery = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(org.getOrgId())) {
|
||||
currentOrgQuery.eq(SysOrg::getOrgId, org.getOrgId());
|
||||
} else if (StringUtils.isNotBlank(org.getUpOrgId())) {
|
||||
currentOrgQuery.eq(SysOrg::getUpOrgId, org.getUpOrgId());
|
||||
} else {
|
||||
// 没有指定orgId或upOrgId,直接返回空
|
||||
return new ArrayList<>();
|
||||
}
|
||||
SysOrg currentOrg = this.getOne(currentOrgQuery, false);
|
||||
if (currentOrg == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 2. 获取FullId
|
||||
String fullId = currentOrg.getOrgFullId();
|
||||
|
||||
// 3. 用FullId模糊匹配查询本级及下级
|
||||
LambdaQueryWrapper<SysOrg> allOrgQuery = new LambdaQueryWrapper<>();
|
||||
allOrgQuery.likeRight(SysOrg::getOrgFullId, fullId);
|
||||
List<SysOrg> allOrgList = this.list(allOrgQuery);*/
|
||||
|
||||
|
||||
// 如果没有数据,直接返回空列表
|
||||
if (CollectionUtils.isEmpty(allOrgList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 2. 构建完整的树形结构
|
||||
List<SysOrgVO> fullTree = buildOrgTree(allOrgList, org);
|
||||
|
||||
// 3. 如果有查询条件,则根据条件过滤树形结构
|
||||
if (!StringUtils.isEmpty(org.getOrgName()) || !StringUtils.isEmpty(org.getOrgNum())) {
|
||||
return filterTreeByCondition(fullTree, org);
|
||||
}
|
||||
|
||||
// 4. 没有查询条件,直接返回完整树形结构
|
||||
return fullTree;
|
||||
if (CollectionUtils.isEmpty(allOrgList)) return new ArrayList<>();
|
||||
return buildOrgTree(allOrgList, org);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,12 +34,7 @@ public class SysSupplierUserController {
|
||||
@PostMapping("/register")
|
||||
public BaseResponse<SysSupplierUser> register(@ApiParam(value = "注册信息", required = true) @RequestBody @Valid SupplierRegistrationVO registrationVO) {
|
||||
try {
|
||||
SysSupplierUser supplierUser = sysSupplierUserService.createSupplierAccount(
|
||||
registrationVO.getSupplierName(),
|
||||
registrationVO.getCreditCode(),
|
||||
registrationVO.getMobile(),
|
||||
registrationVO.getEmail()
|
||||
);
|
||||
SysSupplierUser supplierUser = sysSupplierUserService.createSupplierAccount(registrationVO);
|
||||
|
||||
if (supplierUser != null) {
|
||||
log.info("供应商注册成功,供应商:{},登录名:{}", registrationVO.getSupplierName(), supplierUser.getUsername());
|
||||
|
@ -3,6 +3,7 @@ package com.coscoshipping.ebtp.system.user.service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseService;
|
||||
import com.coscoshipping.ebtp.system.user.entity.SysSupplierUser;
|
||||
import com.coscoshipping.ebtp.system.user.vo.SupplierRegistrationVO;
|
||||
|
||||
/**
|
||||
* 对数据表 sys_supplier_user 操作的 service
|
||||
@ -41,13 +42,10 @@ public interface SysSupplierUserService extends IBaseService<SysSupplierUser> {
|
||||
|
||||
/**
|
||||
* 供应商注册成功后自动生成账号并设置统一重置密码
|
||||
* @param supplierName 供应商名称
|
||||
* @param creditCode 统一信用代码
|
||||
* @param mobile 手机号
|
||||
* @param email 邮箱
|
||||
* @param registrationVO 注册信息
|
||||
* @return 生成的账号信息(包含重置密码)
|
||||
*/
|
||||
SysSupplierUser createSupplierAccount(String supplierName, String creditCode, String mobile, String email);
|
||||
SysSupplierUser createSupplierAccount(SupplierRegistrationVO registrationVO);
|
||||
|
||||
/**
|
||||
* 供应商首次登录修改密码
|
||||
|
@ -12,6 +12,7 @@ import com.coscoshipping.ebtp.system.user.entity.SysSupplierUser;
|
||||
import com.coscoshipping.ebtp.system.user.service.SysSupplierUserService;
|
||||
import com.coscoshipping.ebtp.system.user.dao.SysSupplierUserMapper;
|
||||
import com.coscoshipping.ebtp.system.user.util.AccountGeneratorUtil;
|
||||
import com.coscoshipping.ebtp.system.user.util.Md5Util;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -21,6 +22,7 @@ import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDateTime;
|
||||
import com.coscoshipping.ebtp.system.user.vo.SupplierRegistrationVO;
|
||||
|
||||
/**
|
||||
* 对数据表 sys_supplier_user 操作的 serviceImpl
|
||||
@ -52,14 +54,12 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
@Override
|
||||
public Boolean insertSupplierUser(SysSupplierUser sysSupplierUser) {
|
||||
// sysSupplierUser.setUserId(PropertyUtils.getSnowflakeId()).setCreateDate(LocalDateTime.now());
|
||||
validEntityBeforeSave(sysSupplierUser, false);
|
||||
boolean flag = baseMapper.insert(sysSupplierUser) > 0;
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateSupplierUser(SysSupplierUser sysSupplierUser) {
|
||||
validEntityBeforeSave(sysSupplierUser, true);
|
||||
boolean flag = baseMapper.updateById(sysSupplierUser) > 0;
|
||||
return flag;
|
||||
}
|
||||
@ -69,13 +69,6 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
return this.removeById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(SysSupplierUser entity, boolean isUpdate) {
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysSupplierUser> buildQueryWrapper(SysSupplierUser entity) {
|
||||
LambdaQueryWrapper<SysSupplierUser> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(entity.getUserId() != null, SysSupplierUser::getUserId, entity.getUserId());
|
||||
@ -98,7 +91,7 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSupplierUser createSupplierAccount(String supplierName, String creditCode, String mobile, String email) {
|
||||
public SysSupplierUser createSupplierAccount(SupplierRegistrationVO registrationVO) {
|
||||
// 生成唯一的用户名
|
||||
String username;
|
||||
do {
|
||||
@ -113,18 +106,18 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
Long userId = Long.valueOf(PropertyUtils.getSnowflakeId());
|
||||
supplierUser.setUserId(userId);
|
||||
supplierUser.setUsername(username);
|
||||
supplierUser.setPassword(encode(tempPassword)); // 加密密码
|
||||
supplierUser.setName(supplierName);
|
||||
supplierUser.setSupplierName(supplierName);
|
||||
supplierUser.setCreditCode(creditCode);
|
||||
supplierUser.setMobile(mobile);
|
||||
supplierUser.setEmail(email);
|
||||
supplierUser.setPassword(Md5Util.encode(tempPassword)); // 加密密码
|
||||
supplierUser.setName(registrationVO.getSupplierName());
|
||||
supplierUser.setSupplierName(registrationVO.getSupplierName());
|
||||
supplierUser.setCreditCode(registrationVO.getCreditCode());
|
||||
supplierUser.setMobile(registrationVO.getMobile());
|
||||
supplierUser.setEmail(registrationVO.getEmail());
|
||||
supplierUser.setStatus(1); // 启用状态
|
||||
supplierUser.setFirstLogin(1); // 首次登录标识
|
||||
supplierUser.setCreateDate(LocalDateTime.now());
|
||||
|
||||
// 设置供应商ID(可以使用统一信用代码作为供应商ID)
|
||||
supplierUser.setSupplierId(creditCode);
|
||||
// 设置供应商ID
|
||||
supplierUser.setSupplierId(registrationVO.getSupplierId());
|
||||
|
||||
// 保存到数据库
|
||||
boolean result = baseMapper.insert(supplierUser) > 0;
|
||||
@ -134,12 +127,12 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
resultUser.setUserId(userId);
|
||||
resultUser.setUsername(username);
|
||||
resultUser.setPassword(tempPassword); // 返回明文密码用于通知
|
||||
resultUser.setName(supplierName);
|
||||
resultUser.setSupplierName(supplierName);
|
||||
resultUser.setCreditCode(creditCode);
|
||||
resultUser.setSupplierId(creditCode);
|
||||
resultUser.setMobile(mobile);
|
||||
resultUser.setEmail(email);
|
||||
resultUser.setName(registrationVO.getSupplierName());
|
||||
resultUser.setSupplierName(registrationVO.getSupplierName());
|
||||
resultUser.setCreditCode(registrationVO.getCreditCode());
|
||||
resultUser.setSupplierId(registrationVO.getSupplierId());
|
||||
resultUser.setMobile(registrationVO.getMobile());
|
||||
resultUser.setEmail(registrationVO.getEmail());
|
||||
|
||||
return resultUser;
|
||||
}
|
||||
@ -155,7 +148,7 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
}
|
||||
|
||||
// 更新密码和首次登录标识
|
||||
user.setPassword(encode(newPassword));
|
||||
user.setPassword(Md5Util.encode(newPassword));
|
||||
user.setFirstLogin(0); // 取消首次登录标识
|
||||
user.setLastLoginTime(LocalDateTime.now());
|
||||
user.setUpdateDate(LocalDateTime.now());
|
||||
@ -169,17 +162,4 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
queryWrapper.eq(SysSupplierUser::getUsername, username);
|
||||
return baseMapper.selectCount(queryWrapper) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*/
|
||||
private String encode(String password) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(password.getBytes());
|
||||
return new BigInteger(1, md.digest()).toString(16);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("MD5加密失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.coscoshipping.ebtp.system.user.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* MD5加密工具类
|
||||
*/
|
||||
public class Md5Util {
|
||||
/**
|
||||
* 对字符串进行MD5加密
|
||||
* @param input 明文
|
||||
* @return 32位小写MD5
|
||||
*/
|
||||
public static String encode(String input) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(input.getBytes());
|
||||
return new BigInteger(1, md.digest()).toString(16);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("MD5加密失败", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -42,4 +42,8 @@ public class SupplierRegistrationVO {
|
||||
|
||||
@ApiModelProperty(value = "企业简介")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(value = "供应商ID", required = true)
|
||||
@NotBlank(message = "供应商ID不能为空")
|
||||
private String supplierId;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.coscoshipping.ebtp.system.userinfo.utils;
|
||||
|
||||
import com.coscoshipping.ebtp.system.userinfo.entity.BaseCert;
|
||||
import com.coscoshipping.ebtp.system.user.util.Md5Util;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -38,7 +39,7 @@ public class BaseCertService {
|
||||
String image = result.substring(index + 1);
|
||||
|
||||
String text = Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd 00:00:00")).format(new Date())) + code;
|
||||
String key = this.encode(text);
|
||||
String key = Md5Util.encode(text);
|
||||
BaseCert cert = new BaseCert().setImage(image).setKey(key);
|
||||
return cert;
|
||||
}
|
||||
@ -100,19 +101,4 @@ public class BaseCertService {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String encode(String str) {
|
||||
// 生成一个MD5加密计算摘要
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
// 计算md5函数
|
||||
md.update(str.getBytes());
|
||||
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
|
||||
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
|
||||
return new BigInteger(1, md.digest()).toString(16);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user