修改字典,菜单相关问题
This commit is contained in:
17
pom.xml
17
pom.xml
@ -19,18 +19,6 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<version>2.2.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring.cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
@ -64,6 +52,7 @@
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>1.11.358</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -73,9 +62,9 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.10.2</version>
|
||||
<version>3.17.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
@ -7,6 +7,7 @@ import com.coscoshipping.ebtp.system.login.common.CaptchaGenerator;
|
||||
import com.coscoshipping.ebtp.system.login.entity.BaseSelf;
|
||||
import com.coscoshipping.ebtp.system.login.service.BaseUserService;
|
||||
|
||||
import com.coscoshipping.ebtp.system.login.vo.ChangePasswordVo;
|
||||
import com.coscoshipping.ebtp.system.login.vo.LoginUserVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -97,4 +98,10 @@ public class LoginController {
|
||||
public BaseResponse<Boolean> resetPassword(@RequestBody LoginUserVo vo) {
|
||||
return BaseResponse.success(iBaseUserService.resetPassword(vo.getAccount()));
|
||||
}
|
||||
|
||||
@ApiOperation("供应商首次登录强制修改密码")
|
||||
@PostMapping("/supplier/changePasswordOnFirstLogin")
|
||||
public BaseResponse<Boolean> changePasswordOnFirstLogin(@RequestBody ChangePasswordVo vo) {
|
||||
return BaseResponse.success(iBaseUserService.changeSupplierPasswordOnFirstLogin(vo.getUserId(), vo.getNewPassword()));
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,9 @@ public class BaseSelf {
|
||||
* 所属机构
|
||||
*/
|
||||
private List<SysOrg> orgnList;
|
||||
|
||||
/**
|
||||
* 是否首次登录
|
||||
*/
|
||||
private boolean firstLogin;
|
||||
}
|
||||
|
@ -35,4 +35,12 @@ public interface BaseUserService extends IBaseService<SysUser> {
|
||||
* @return 是否重置成功
|
||||
*/
|
||||
boolean resetPassword(String account);
|
||||
|
||||
/**
|
||||
* 供应商首次登录强制修改密码
|
||||
* @param userId 用户ID
|
||||
* @param newPassword 新密码
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
boolean changeSupplierPasswordOnFirstLogin(Long userId, String newPassword);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
|
||||
|
||||
import com.coscoshipping.ebtp.system.user.entity.SysExpertUser;
|
||||
import com.coscoshipping.ebtp.system.user.entity.SysSupplierUser;
|
||||
import com.coscoshipping.ebtp.system.user.service.SysSupplierUserService;
|
||||
import com.coscoshipping.ebtp.system.login.common.Constants;
|
||||
import com.coscoshipping.ebtp.system.login.common.RSA;
|
||||
import com.coscoshipping.ebtp.system.login.dao.BaseUserMapper;
|
||||
@ -90,6 +91,8 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
|
||||
@Autowired
|
||||
private SysOrgService sysOrgService;
|
||||
@Autowired
|
||||
private SysSupplierUserService sysSupplierUserService;
|
||||
@Autowired(required = false)
|
||||
@Qualifier("cacheRedisTemplate")
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@ -126,7 +129,11 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
// 1. 查询角色信息
|
||||
List<AuthorityEntity> authorityList = baseUserMapper.selectRoleByUserId(user.getUserId());
|
||||
|
||||
// 2. 组装BaseCacheUser
|
||||
// 2. 查询部门信息
|
||||
String orgId = user.getOrgId();
|
||||
SysOrg sysOrg = sysOrgService.getById(orgId); // 通过orgId查询sys_org
|
||||
|
||||
// 3. 组装BaseCacheUser
|
||||
BaseCacheUser baseCacheUser = new BaseCacheUser();
|
||||
baseCacheUser.setUserId(user.getUserId());
|
||||
baseCacheUser.setFullName(user.getName());
|
||||
@ -136,8 +143,10 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
baseCacheUser.setSex(user.getSex() != null ? user.getSex().toString() : null);
|
||||
baseCacheUser.setEmployeeNumber(user.getEmployeeNumber());
|
||||
baseCacheUser.setEmailAddress(user.getEmail());
|
||||
baseCacheUser.setOrganizationId(user.getOrgId());
|
||||
baseCacheUser.setOrganizationName(user.getOrgName());
|
||||
baseCacheUser.setDeptId(orgId);
|
||||
baseCacheUser.setDeptName(sysOrg.getOrgName());
|
||||
baseCacheUser.setOrganizationId(sysOrg.getCuCompanyNumber());
|
||||
baseCacheUser.setOrganizationName(sysOrg.getCuCompanyName());
|
||||
baseCacheUser.setUserType("0");
|
||||
baseCacheUser.setAuthorityList(authorityList);
|
||||
// 角色ID字符串拼接
|
||||
@ -151,7 +160,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
baseCacheUser.setRoleIds(roleIds.toString());
|
||||
}
|
||||
|
||||
// 3. 存入redis
|
||||
// 4. 存入redis
|
||||
String token = baseSelf.getToken();
|
||||
userinfoRedisTemplate.opsForValue().set(
|
||||
REDIS_USER_KEY + token,
|
||||
@ -195,12 +204,24 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
throw new RuntimeException("用户名或密码错误!");
|
||||
}
|
||||
|
||||
// 检查是否为首次登录
|
||||
if (user.getFirstLogin() != null && user.getFirstLogin() == 1) {
|
||||
// 首次登录需要强制修改密码,返回特殊状态
|
||||
BaseSelf baseSelf = userSupplierLogin(user);
|
||||
baseSelf.setFirstLogin(true); // 设置首次登录标识
|
||||
return baseSelf;
|
||||
}
|
||||
|
||||
// 更新最后登录时间
|
||||
user.setLastLoginTime(LocalDateTime.now());
|
||||
sysSupplierUserMapper.updateById(user);
|
||||
|
||||
BaseSelf baseSelf = userSupplierLogin(user);
|
||||
// String token = baseSelf.getToken();
|
||||
//
|
||||
// //缓存用户信息
|
||||
// BaseCacheUser baseCacheUser = new BaseCacheUser();
|
||||
// BeanUtils.copyProperties(user, baseCacheUser);
|
||||
// BeanUtils.copyProperties(user, baseSelf);
|
||||
// //存入缓存redis
|
||||
// userinfoRedisTemplate.opsForValue().set(REDIS_USER_KEY + token,
|
||||
// baseCacheUser, Long.parseLong(valid_time_limit), TimeUnit.HOURS);
|
||||
@ -639,4 +660,19 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
String pw = new String(decode);
|
||||
System.out.println(pw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeSupplierPasswordOnFirstLogin(Long userId, String newPassword) {
|
||||
try {
|
||||
// 使用RSA解密新密码
|
||||
byte[] decode = RSA.decryptByPrivateKey(RSA.decryptBASE64(newPassword), privateKey);
|
||||
String pw = new String(decode);
|
||||
|
||||
// 调用供应商用户服务修改密码
|
||||
return sysSupplierUserService.changePasswordOnFirstLogin(userId, pw);
|
||||
} catch (Exception e) {
|
||||
log.error("供应商首次登录修改密码失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.coscoshipping.ebtp.system.login.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("修改密码信息")
|
||||
public class ChangePasswordVo {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("新密码")
|
||||
private String newPassword;
|
||||
|
||||
@ApiModelProperty("确认新密码")
|
||||
private String confirmPassword;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.coscoshipping.ebtp.system.menu.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MenuTreeVO {
|
||||
private String id;
|
||||
private String parentId;
|
||||
private String label;
|
||||
private Integer weight;
|
||||
private List<MenuTreeVO> children;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Integer getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(Integer weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public List<MenuTreeVO> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<MenuTreeVO> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
@ -55,6 +55,30 @@ public class SysOrgServiceImpl extends BaseServiceImpl<SysOrgMapper, SysOrg> imp
|
||||
// 1. 先查询出所有的组织数据
|
||||
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<>();
|
||||
|
@ -0,0 +1,120 @@
|
||||
package com.coscoshipping.ebtp.system.user.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.coscoshipping.ebtp.system.user.entity.SysSupplierUser;
|
||||
import com.coscoshipping.ebtp.system.user.service.SysSupplierUserService;
|
||||
import com.coscoshipping.ebtp.system.user.vo.SupplierRegistrationVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "供应商用户管理")
|
||||
@RequestMapping("/v1/supplieruser")
|
||||
public class SysSupplierUserController {
|
||||
|
||||
@Resource
|
||||
private SysSupplierUserService sysSupplierUserService;
|
||||
|
||||
/**
|
||||
* 供应商注册(自动生成账号并设置统一重置密码)
|
||||
*
|
||||
* @param registrationVO 注册信息
|
||||
* @return 生成的账号信息(包含重置密码)
|
||||
*/
|
||||
@ApiOperation("供应商注册(自动生成账号并设置统一重置密码)")
|
||||
@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()
|
||||
);
|
||||
|
||||
if (supplierUser != null) {
|
||||
log.info("供应商注册成功,供应商:{},登录名:{}", registrationVO.getSupplierName(), supplierUser.getUsername());
|
||||
return BaseResponse.success(supplierUser);
|
||||
} else {
|
||||
return BaseResponse.success(null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("供应商注册异常", e);
|
||||
return BaseResponse.success(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 供应商用户分页查询
|
||||
*
|
||||
* @param sysSupplierUser 查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
@ApiOperation("供应商用户分页查询")
|
||||
@PostMapping("/getPage")
|
||||
public BaseResponse<IPage<SysSupplierUser>> getPage(@ApiParam(value = "查询条件", required = true) @RequestBody SysSupplierUser sysSupplierUser) {
|
||||
return BaseResponse.success(sysSupplierUserService.getPage(sysSupplierUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询供应商用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 供应商用户信息
|
||||
*/
|
||||
@ApiOperation("根据用户ID查询供应商用户")
|
||||
@GetMapping("/{userId}")
|
||||
public BaseResponse<SysSupplierUser> getById(@ApiParam(value = "用户ID", required = true) @PathVariable Long userId) {
|
||||
SysSupplierUser supplierUser = sysSupplierUserService.getById(userId);
|
||||
if (supplierUser != null) {
|
||||
// 隐藏密码
|
||||
supplierUser.setPassword("***");
|
||||
}
|
||||
return BaseResponse.success(supplierUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改供应商用户信息
|
||||
*
|
||||
* @param sysSupplierUser 供应商用户信息
|
||||
* @return 修改结果
|
||||
*/
|
||||
@ApiOperation("修改供应商用户信息")
|
||||
@PostMapping("/update")
|
||||
public BaseResponse<Boolean> update(@ApiParam(value = "供应商用户信息", required = true) @RequestBody SysSupplierUser sysSupplierUser) {
|
||||
return BaseResponse.success(sysSupplierUserService.updateSupplierUser(sysSupplierUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除供应商用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@ApiOperation("删除供应商用户")
|
||||
@DeleteMapping("/{userId}")
|
||||
public BaseResponse<Boolean> delete(@ApiParam(value = "用户ID", required = true) @PathVariable Long userId) {
|
||||
return BaseResponse.success(sysSupplierUserService.deleteSupplierUserById(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户名是否唯一
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 是否唯一
|
||||
*/
|
||||
@ApiOperation("检查用户名是否唯一")
|
||||
@GetMapping("/checkUsername")
|
||||
public BaseResponse<Boolean> checkUsername(@ApiParam(value = "用户名", required = true) @RequestParam String username) {
|
||||
return BaseResponse.success(sysSupplierUserService.checkUsernameUnique(username));
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 实体类 SysSupplierUser-供应商用户表
|
||||
@ -48,5 +49,19 @@ public class SysSupplierUser extends BaseEntity implements Serializable {
|
||||
@ApiModelProperty(value = "性别")
|
||||
private String sex;
|
||||
|
||||
@ApiModelProperty(value = "供应商id")
|
||||
private String supplierId;
|
||||
|
||||
@ApiModelProperty(value = "是否首次登录 0:否 1:是")
|
||||
private Integer firstLogin;
|
||||
|
||||
@ApiModelProperty(value = "最后登录时间")
|
||||
private LocalDateTime lastLoginTime;
|
||||
|
||||
@ApiModelProperty(value = "统一信用代码")
|
||||
private String creditCode;
|
||||
|
||||
@ApiModelProperty(value = "供应商名称")
|
||||
private String supplierName;
|
||||
|
||||
}
|
||||
|
@ -38,4 +38,29 @@ public interface SysSupplierUserService extends IBaseService<SysSupplierUser> {
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean deleteSupplierUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 供应商注册成功后自动生成账号并设置统一重置密码
|
||||
* @param supplierName 供应商名称
|
||||
* @param creditCode 统一信用代码
|
||||
* @param mobile 手机号
|
||||
* @param email 邮箱
|
||||
* @return 生成的账号信息(包含重置密码)
|
||||
*/
|
||||
SysSupplierUser createSupplierAccount(String supplierName, String creditCode, String mobile, String email);
|
||||
|
||||
/**
|
||||
* 供应商首次登录修改密码
|
||||
* @param userId 用户ID
|
||||
* @param newPassword 新密码
|
||||
* @return 修改结果
|
||||
*/
|
||||
Boolean changePasswordOnFirstLogin(Long userId, String newPassword);
|
||||
|
||||
/**
|
||||
* 检查用户名是否唯一
|
||||
* @param username 用户名
|
||||
* @return 是否唯一
|
||||
*/
|
||||
Boolean checkUsernameUnique(String username);
|
||||
}
|
||||
|
@ -11,9 +11,15 @@ import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
||||
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 org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@ -24,6 +30,12 @@ import java.time.LocalDateTime;
|
||||
@Service
|
||||
public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserMapper, SysSupplierUser> implements SysSupplierUserService {
|
||||
|
||||
@Autowired
|
||||
private AccountGeneratorUtil accountGeneratorUtil;
|
||||
|
||||
@Value("${login.reset_password}")
|
||||
private String resetPassword;
|
||||
|
||||
@Override
|
||||
public IPage<SysSupplierUser> getPage(SysSupplierUser sysSupplierUser) {
|
||||
LambdaQueryWrapper<SysSupplierUser> query = buildQueryWrapper(sysSupplierUser);
|
||||
@ -67,12 +79,16 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
private LambdaQueryWrapper<SysSupplierUser> buildQueryWrapper(SysSupplierUser entity) {
|
||||
LambdaQueryWrapper<SysSupplierUser> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(entity.getUserId() != null, SysSupplierUser::getUserId, entity.getUserId());
|
||||
lqw.eq(StringUtils.isNotBlank(entity.getSupplierId()), SysSupplierUser::getSupplierId, entity.getSupplierId());
|
||||
lqw.like(StringUtils.isNotBlank(entity.getUsername()), SysSupplierUser::getUsername, entity.getUsername());
|
||||
lqw.like(StringUtils.isNotBlank(entity.getName()), SysSupplierUser::getName, entity.getName());
|
||||
lqw.eq(entity.getStatus() != null, SysSupplierUser::getStatus, entity.getStatus());
|
||||
lqw.like(StringUtils.isNotBlank(entity.getMobile()), SysSupplierUser::getMobile, entity.getMobile());
|
||||
lqw.like(StringUtils.isNotBlank(entity.getEmail()), SysSupplierUser::getEmail, entity.getEmail());
|
||||
lqw.eq(StringUtils.isNotBlank(entity.getSex()), SysSupplierUser::getSex, entity.getSex());
|
||||
lqw.eq(StringUtils.isNotBlank(entity.getCreditCode()), SysSupplierUser::getCreditCode, entity.getCreditCode());
|
||||
lqw.like(StringUtils.isNotBlank(entity.getSupplierName()), SysSupplierUser::getSupplierName, entity.getSupplierName());
|
||||
lqw.eq(entity.getFirstLogin() != null, SysSupplierUser::getFirstLogin, entity.getFirstLogin());
|
||||
lqw.eq(StringUtils.isNotBlank(entity.getTenantId()), SysSupplierUser::getTenantId, entity.getTenantId());
|
||||
lqw.like(StringUtils.isNotBlank(entity.getTenantName()), SysSupplierUser::getTenantName, entity.getTenantName());
|
||||
lqw.eq(entity.getCreateBy() != null, SysSupplierUser::getCreateBy, entity.getCreateBy());
|
||||
@ -80,4 +96,90 @@ public class SysSupplierUserServiceImpl extends BaseServiceImpl<SysSupplierUserM
|
||||
lqw.orderByDesc(SysSupplierUser::getCreateDate);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSupplierUser createSupplierAccount(String supplierName, String creditCode, String mobile, String email) {
|
||||
// 生成唯一的用户名
|
||||
String username;
|
||||
do {
|
||||
username = accountGeneratorUtil.generateSupplierUsername();
|
||||
} while (!checkUsernameUnique(username));
|
||||
|
||||
// 使用配置中的重置密码
|
||||
String tempPassword = resetPassword;
|
||||
|
||||
// 创建供应商用户
|
||||
SysSupplierUser supplierUser = new SysSupplierUser();
|
||||
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.setStatus(1); // 启用状态
|
||||
supplierUser.setFirstLogin(1); // 首次登录标识
|
||||
supplierUser.setCreateDate(LocalDateTime.now());
|
||||
|
||||
// 设置供应商ID(可以使用统一信用代码作为供应商ID)
|
||||
supplierUser.setSupplierId(creditCode);
|
||||
|
||||
// 保存到数据库
|
||||
boolean result = baseMapper.insert(supplierUser) > 0;
|
||||
if (result) {
|
||||
// 返回包含明文密码的用户信息(仅用于通知)
|
||||
SysSupplierUser resultUser = new SysSupplierUser();
|
||||
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);
|
||||
|
||||
return resultUser;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean changePasswordOnFirstLogin(Long userId, String newPassword) {
|
||||
SysSupplierUser user = baseMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新密码和首次登录标识
|
||||
user.setPassword(encode(newPassword));
|
||||
user.setFirstLogin(0); // 取消首次登录标识
|
||||
user.setLastLoginTime(LocalDateTime.now());
|
||||
user.setUpdateDate(LocalDateTime.now());
|
||||
|
||||
return baseMapper.updateById(user) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkUsernameUnique(String username) {
|
||||
LambdaQueryWrapper<SysSupplierUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,12 +117,10 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
|
||||
|
||||
public SysInnerUserInfo getInnerUserInfo(String employeeNumber) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(employeeNumber)
|
||||
) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(employeeNumber)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
SysUser sysUser = this.baseMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getEmployeeNumber, employeeNumber));
|
||||
if (sysUser == null) {
|
||||
return null;
|
||||
@ -133,12 +131,12 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
sysInnerUserInfo.setCompanyName(company != null ? company.getOrgName() : "");
|
||||
sysInnerUserInfo.setCompanyId(company != null ? company.getOrgId() : "");
|
||||
AllRolesAndAssignRoleVO allRolesAndAssignRole = sysUserRoleService.getAllRolesAndAssignRole(sysUser.getUserId());
|
||||
if ((allRolesAndAssignRole != null)&&(allRolesAndAssignRole.getAllRole() != null)){
|
||||
if ((allRolesAndAssignRole != null) && (allRolesAndAssignRole.getAllRole() != null)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (SysRole role : allRolesAndAssignRole.getAllRole()) {
|
||||
sb.append(role.getRoleName()).append(",");
|
||||
}
|
||||
sysInnerUserInfo.setRoles(sb.toString().substring(0,sb.length()-1));
|
||||
sysInnerUserInfo.setRoles(sb.toString().substring(0, sb.length() - 1));
|
||||
}
|
||||
return sysInnerUserInfo;
|
||||
|
||||
|
@ -0,0 +1,83 @@
|
||||
package com.coscoshipping.ebtp.system.user.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 账号生成工具类
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
@Component
|
||||
public class AccountGeneratorUtil {
|
||||
|
||||
private static final String UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
private static final SecureRandom random = new SecureRandom();
|
||||
|
||||
/**
|
||||
* 生成供应商登录名
|
||||
* 规则:SPL + 8位随机数字 + 2位字母检验码
|
||||
*
|
||||
* @return 生成的登录名
|
||||
*/
|
||||
public String generateSupplierUsername() {
|
||||
StringBuilder username = new StringBuilder();
|
||||
|
||||
// 添加前缀
|
||||
username.append("SPL");
|
||||
|
||||
// 添加8位随机数字
|
||||
for (int i = 0; i < 8; i++) {
|
||||
username.append(random.nextInt(10));
|
||||
}
|
||||
|
||||
// 添加2位字母检验码
|
||||
for (int i = 0; i < 2; i++) {
|
||||
username.append(UPPERCASE.charAt(random.nextInt(UPPERCASE.length())));
|
||||
}
|
||||
|
||||
return username.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证登录名格式
|
||||
*
|
||||
* @param username 登录名
|
||||
* @return 是否有效
|
||||
*/
|
||||
public boolean validateSupplierUsername(String username) {
|
||||
if (StringUtils.isBlank(username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查长度
|
||||
if (username.length() != 13) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查前缀
|
||||
if (!username.startsWith("SPL")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查中间8位是否为数字
|
||||
String middle = username.substring(3, 11);
|
||||
if (!middle.matches("\\d{8}")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查后2位是否为字母
|
||||
String suffix = username.substring(11);
|
||||
if (!suffix.matches("[A-Z]{2}")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.coscoshipping.ebtp.system.user.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Data
|
||||
@ApiModel("供应商注册信息")
|
||||
public class SupplierRegistrationVO {
|
||||
|
||||
@ApiModelProperty(value = "供应商名称", required = true)
|
||||
@NotBlank(message = "供应商名称不能为空")
|
||||
private String supplierName;
|
||||
|
||||
@ApiModelProperty(value = "统一信用代码", required = true)
|
||||
@NotBlank(message = "统一信用代码不能为空")
|
||||
@Pattern(regexp = "^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$", message = "统一信用代码格式不正确")
|
||||
private String creditCode;
|
||||
|
||||
@ApiModelProperty(value = "手机号", required = true)
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
|
||||
private String mobile;
|
||||
|
||||
@ApiModelProperty(value = "邮箱", required = true)
|
||||
@NotBlank(message = "邮箱不能为空")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "联系人")
|
||||
private String contactName;
|
||||
|
||||
@ApiModelProperty(value = "联系人职务")
|
||||
private String contactTitle;
|
||||
|
||||
@ApiModelProperty(value = "企业地址")
|
||||
private String address;
|
||||
|
||||
@ApiModelProperty(value = "企业简介")
|
||||
private String description;
|
||||
}
|
@ -92,6 +92,24 @@ public class UserInfoController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* 通过ID查询用户信息
|
||||
* @param token (认证token)
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getU")
|
||||
public ResponseEntity<BaseCacheUser> getU(
|
||||
@RequestHeader(name = "Authorization", required = false) String token) {
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
log.error("access token is empty");
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
return ResponseEntity.ok(cacheUserService.getCacheUser());
|
||||
// return ResponseEntity.ok(userInfoService.getUserInfo(token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 刷新redis缓存的信息
|
||||
*
|
||||
|
Reference in New Issue
Block a user