|
@@ -9,16 +9,19 @@ import api.common.pojo.vo.system.UserVO;
|
|
|
import api.common.util.EncryptUtil;
|
|
|
import api.common.util.ObjectUtil;
|
|
|
import api.common.util.StringUtil;
|
|
|
+import api.common.util.TencentSMSUtil;
|
|
|
import com.css.simulation.resource.common.oauth.OauthParameter;
|
|
|
import com.css.simulation.resource.common.utils.AuthUtil;
|
|
|
import com.css.simulation.resource.common.utils.PageUtil;
|
|
|
import com.css.simulation.resource.common.utils.PoUtil;
|
|
|
+import com.css.simulation.resource.configuration.sms.SmsConfiguration;
|
|
|
import com.css.simulation.resource.log.service.LogService;
|
|
|
import com.css.simulation.resource.system.mapper.UserMapper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -27,20 +30,18 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class UserService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
UserMapper userMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
OauthParameter oauthParameter;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
LogService logService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
DictService dictService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
ParameterService parameterService;
|
|
|
+ @Resource
|
|
|
+ SmsConfiguration smsConfiguration;
|
|
|
|
|
|
public UserVO getCurrentUserInfo() {
|
|
|
String userId = AuthUtil.getCurrentUserId();
|
|
@@ -54,106 +55,131 @@ public class UserService {
|
|
|
|
|
|
public PageInfo<UserVO> getUserPageList(UserParam pageParam) {
|
|
|
PageUtil.setPageInfo(pageParam);
|
|
|
- List<UserVO> list = null;
|
|
|
+ List<UserVO> list;
|
|
|
String currentUserRoleCode = AuthUtil.getCurrentUserRoleCode();
|
|
|
- if(DictConstants.ROLE_CODE_SYSADMIN.equals(currentUserRoleCode)){//超级管理员
|
|
|
+ if (DictConstants.ROLE_CODE_SYSADMIN.equals(currentUserRoleCode)) {//超级管理员
|
|
|
list = userMapper.getUserPageLista(pageParam);
|
|
|
- }else if(DictConstants.ROLE_CODE_ADMIN.equals(currentUserRoleCode)){//子管理员
|
|
|
+ } else if (DictConstants.ROLE_CODE_ADMIN.equals(currentUserRoleCode)) {//子管理员
|
|
|
list = userMapper.getUserPageListb(pageParam);
|
|
|
- }else if(DictConstants.ROLE_CODE_UESR.equals(currentUserRoleCode)){//普通用户
|
|
|
+ } else if (DictConstants.ROLE_CODE_UESR.equals(currentUserRoleCode)) {//普通用户
|
|
|
//只查询自己创建的子账户
|
|
|
pageParam.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
|
list = userMapper.getUserPageListc(pageParam);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return null;
|
|
|
}
|
|
|
//字典翻译
|
|
|
Map<String, Map<String, String>> dictMaps = dictService.getDictMapsByTypes(DictConstants.ROLE_CODE);
|
|
|
- list.forEach(po ->{
|
|
|
+ list.forEach(po -> {
|
|
|
po.setRoleCode(dictMaps.get(DictConstants.ROLE_CODE).get(po.getRoleCode()));
|
|
|
});
|
|
|
return new PageInfo<>(list);
|
|
|
}
|
|
|
|
|
|
- public UserPO saveUser(UserPO userPO) throws NoSuchAlgorithmException {
|
|
|
+ @SneakyThrows
|
|
|
+ public UserPO saveUser(UserPO userPO) {
|
|
|
//权限校验
|
|
|
String currentUserRoleCode = AuthUtil.getCurrentUserRoleCode();
|
|
|
- if(DictConstants.ROLE_CODE_SYSADMIN.equals(currentUserRoleCode)){//超级管理员
|
|
|
- if(DictConstants.ROLE_CODE_ADMIN.equals(userPO.getRoleCode())){
|
|
|
+ if (DictConstants.ROLE_CODE_SYSADMIN.equals(currentUserRoleCode)) {// 超级管理员
|
|
|
+ if (DictConstants.ROLE_CODE_ADMIN.equals(userPO.getRoleCode())) {
|
|
|
userPO.setRoleCode(DictConstants.ROLE_CODE_ADMIN);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
userPO.setRoleCode(DictConstants.ROLE_CODE_UESR);
|
|
|
}
|
|
|
- }else if(DictConstants.ROLE_CODE_ADMIN.equals(currentUserRoleCode)){//子管理员
|
|
|
+ } else if (DictConstants.ROLE_CODE_ADMIN.equals(currentUserRoleCode)) {// 子管理员
|
|
|
userPO.setRoleCode(DictConstants.ROLE_CODE_UESR);
|
|
|
- }else if(DictConstants.ROLE_CODE_UESR.equals(currentUserRoleCode)){//普通用户
|
|
|
+ } else if (DictConstants.ROLE_CODE_UESR.equals(currentUserRoleCode)) { //普通用户
|
|
|
//新增参数校验
|
|
|
- if(ObjectUtil.isNull(userPO.getId())){
|
|
|
+ if (ObjectUtil.isNull(userPO.getId())) {
|
|
|
ParameterVO parameter = parameterService.getParameterByUserId();
|
|
|
- if(ObjectUtil.isNull(parameter)){
|
|
|
+ if (ObjectUtil.isNull(parameter)) {
|
|
|
return null;
|
|
|
}
|
|
|
- int num = parameter.getNumCreateUser();//最大用户数
|
|
|
+ int num = parameter.getNumCreateUser(); // 最大用户数
|
|
|
int subUserNum = 0;
|
|
|
String userId = AuthUtil.getCurrentUserId();
|
|
|
List<UserPO> subUsers = userMapper.getSubUser(userId);
|
|
|
- if(ObjectUtil.isNotNull(subUsers)){
|
|
|
+ if (ObjectUtil.isNotNull(subUsers)) {
|
|
|
subUserNum = subUsers.size();
|
|
|
}
|
|
|
- if(subUserNum >= num ){
|
|
|
+ if (subUserNum >= num) {
|
|
|
userPO.setId("subUserNum");
|
|
|
return userPO;
|
|
|
}
|
|
|
}
|
|
|
userPO.setRoleCode(DictConstants.ROLE_CODE_SUBUESR);
|
|
|
- //普通用户创建子账户时,占用类型继承
|
|
|
+ // 普通用户创建子账户时,占用类型继承
|
|
|
userPO.setUseType(AuthUtil.getCurrentUseType());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return null;
|
|
|
}
|
|
|
//重名校验
|
|
|
List<UserPO> list = userMapper.checkUsername(userPO);
|
|
|
- if(ObjectUtil.isNotNull(list)){
|
|
|
+ if (ObjectUtil.isNotNull(list)) {
|
|
|
userPO.setId("checkUsername");
|
|
|
return userPO;
|
|
|
}
|
|
|
PoUtil.initAddPo(userPO);
|
|
|
String id = userPO.getId();
|
|
|
- if(ObjectUtil.isNull(id)){//新增
|
|
|
+ if (ObjectUtil.isNull(id)) {//新增
|
|
|
userPO.setId(StringUtil.getRandomUUID());
|
|
|
- //初始密码
|
|
|
+ // 初始密码
|
|
|
userPO.setPassword(EncryptUtil.getLowerMD5(oauthParameter.getSimulationDefaultPassword()));
|
|
|
userPO.setVisible("1");
|
|
|
userMapper.insert(userPO);
|
|
|
- logService.logUser(LogConstants.SYS_LOG_USER_INSERT,userPO);
|
|
|
- }else{
|
|
|
+ logService.logUser(LogConstants.SYS_LOG_USER_INSERT, userPO);
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ TencentSMSUtil.send(
|
|
|
+ smsConfiguration.getSecretId(),
|
|
|
+ smsConfiguration.getSecretKey(),
|
|
|
+ smsConfiguration.getSdkAppId(),
|
|
|
+ smsConfiguration.getSignName(),
|
|
|
+ smsConfiguration.getTemplateIdForCreate(),
|
|
|
+ new String[]{},
|
|
|
+ new String[]{userPO.getPhone()}
|
|
|
+ );
|
|
|
+
|
|
|
+ } else {
|
|
|
userMapper.update(userPO);
|
|
|
- logService.logUser(LogConstants.SYS_LOG_USER_UPDATE,userPO);
|
|
|
+ logService.logUser(LogConstants.SYS_LOG_USER_UPDATE, userPO);
|
|
|
}
|
|
|
- //密码清空
|
|
|
+ // 密码清空
|
|
|
userPO.setPassword(null);
|
|
|
return userPO;
|
|
|
}
|
|
|
|
|
|
- public void saveDefaultPassword(UserPO userPO) throws NoSuchAlgorithmException {
|
|
|
+ @SneakyThrows
|
|
|
+ public void saveDefaultPassword(UserPO userPO) {
|
|
|
userPO.setPassword(EncryptUtil.getLowerMD5(oauthParameter.getSimulationDefaultPassword()));
|
|
|
PoUtil.initUpdatePo(userPO);
|
|
|
userMapper.saveDefaultPassword(userPO);
|
|
|
- logService.logUser(LogConstants.SYS_LOG_USER_RESET,userPO);
|
|
|
+ logService.logUser(LogConstants.SYS_LOG_USER_RESET, userPO);
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ TencentSMSUtil.send(
|
|
|
+ smsConfiguration.getSecretId(),
|
|
|
+ smsConfiguration.getSecretKey(),
|
|
|
+ smsConfiguration.getSdkAppId(),
|
|
|
+ smsConfiguration.getSignName(),
|
|
|
+ smsConfiguration.getTemplateIdForReset(),
|
|
|
+ new String[]{},
|
|
|
+ new String[]{userPO.getPhone()}
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public void saveVisible(UserPO userPO) {
|
|
|
PoUtil.initUpdatePo(userPO);
|
|
|
userMapper.saveVisible(userPO);
|
|
|
- if("1".equals(userPO.getVisible())){
|
|
|
- logService.logUser(LogConstants.SYS_LOG_USER_START,userPO);
|
|
|
- }else{//停用
|
|
|
+ if ("1".equals(userPO.getVisible())) {
|
|
|
+ logService.logUser(LogConstants.SYS_LOG_USER_START, userPO);
|
|
|
+ } else { // 停用
|
|
|
UserVO userInfo = userMapper.getUserInfo(userPO.getId());
|
|
|
String roleCode = userInfo.getRoleCode();
|
|
|
- if(DictConstants.ROLE_CODE_UESR.equals(roleCode)){//停用普通用户时-停用子账户
|
|
|
+ if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) { // 停用普通用户时-停用子账户
|
|
|
List<UserPO> subUsers = userMapper.getSubUser(userPO.getId());
|
|
|
- if(ObjectUtil.isNotNull(subUsers)){
|
|
|
- subUsers.forEach(po->{
|
|
|
+ if (ObjectUtil.isNotNull(subUsers)) {
|
|
|
+ subUsers.forEach(po -> {
|
|
|
PoUtil.initUpdatePo(po);
|
|
|
po.setVisible("0");
|
|
|
userMapper.saveVisible(po);
|
|
@@ -161,7 +187,7 @@ public class UserService {
|
|
|
}
|
|
|
}
|
|
|
//只记录普通账户日志
|
|
|
- logService.logUser(LogConstants.SYS_LOG_USER_STOP,userPO);
|
|
|
+ logService.logUser(LogConstants.SYS_LOG_USER_STOP, userPO);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -175,7 +201,7 @@ public class UserService {
|
|
|
//确认原密码是否正确
|
|
|
userVO.setPassword(EncryptUtil.getLowerMD5(userVO.getPassword()));
|
|
|
List<UserVO> list = userMapper.checkPassword(userVO);
|
|
|
- if(ObjectUtil.isNull(list)){
|
|
|
+ if (ObjectUtil.isNull(list)) {
|
|
|
return null;
|
|
|
}
|
|
|
//修改密码
|