fix: 优化逻辑
This commit is contained in:
parent
459fff4fc5
commit
daa70d3f20
@ -22,6 +22,7 @@ import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
|||||||
import com.yfd.platform.utils.SecurityUtils;
|
import com.yfd.platform.utils.SecurityUtils;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -67,9 +68,7 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
String TM = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "TM");
|
String TM = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "TM");
|
||||||
String startTime=null;
|
String startTime=null;
|
||||||
String endTime=null;
|
String endTime=null;
|
||||||
|
String userId = (SecurityUtils.hasPermission("sjtb:edit-review") || "admin".equals(SecurityUtils.getCurrentUsername())) ?null:SecurityUtils.getUserId();
|
||||||
SecurityUtils.getCurrentUser().getAuthorities();
|
|
||||||
String userId = SecurityUtils.getCurrentUser().getAuthorities().contains("sjtb:import-add") || "admin".equals(SecurityUtils.getCurrentUsername()) ?null:SecurityUtils.getUserId();
|
|
||||||
// 如果 startTime 和 endTime 为空,尝试从 TM 字段解析
|
// 如果 startTime 和 endTime 为空,尝试从 TM 字段解析
|
||||||
if (StrUtil.isNotBlank(TM)&& TM.split( ",").length==2) {
|
if (StrUtil.isNotBlank(TM)&& TM.split( ",").length==2) {
|
||||||
startTime=TM.split(",")[0];
|
startTime=TM.split(",")[0];
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import com.yfd.platform.config.ResponseResult;
|
|||||||
import com.yfd.platform.datasource.DataSource;
|
import com.yfd.platform.datasource.DataSource;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
import com.yfd.platform.system.domain.SysUserRequest;
|
import com.yfd.platform.system.domain.SysUserRequest;
|
||||||
|
import com.yfd.platform.system.service.ISmsVerifyCodeService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -33,6 +34,9 @@ public class UserController {
|
|||||||
@Resource
|
@Resource
|
||||||
private IUserService userService;
|
private IUserService userService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISmsVerifyCodeService smsVerifyCodeService;
|
||||||
|
|
||||||
@Log(module = "系统用户", value = "新增系统用户")
|
@Log(module = "系统用户", value = "新增系统用户")
|
||||||
@PostMapping("/addUser")
|
@PostMapping("/addUser")
|
||||||
@Operation(summary = "新增系统用户")
|
@Operation(summary = "新增系统用户")
|
||||||
@ -157,12 +161,7 @@ public class UserController {
|
|||||||
if (StrUtil.isBlank(id)) {
|
if (StrUtil.isBlank(id)) {
|
||||||
ResponseResult.error("参数为空");
|
ResponseResult.error("参数为空");
|
||||||
}
|
}
|
||||||
boolean ok = userService.resetPassword(id);
|
return userService.resetPassword(id);
|
||||||
if (ok) {
|
|
||||||
return ResponseResult.success();
|
|
||||||
} else {
|
|
||||||
return ResponseResult.error();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
@ -216,8 +215,13 @@ public class UserController {
|
|||||||
if (auditStatus == null || (auditStatus != 1 && auditStatus != 2)) {
|
if (auditStatus == null || (auditStatus != 1 && auditStatus != 2)) {
|
||||||
return ResponseResult.error("审核状态错误:1-通过 2-驳回");
|
return ResponseResult.error("审核状态错误:1-通过 2-驳回");
|
||||||
}
|
}
|
||||||
|
SysUser user = userService.getById(userId);
|
||||||
|
if (user == null) {
|
||||||
|
return ResponseResult.error("用户不存在");
|
||||||
|
}
|
||||||
boolean ok = userService.auditUser(userId, auditStatus);
|
boolean ok = userService.auditUser(userId, auditStatus);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
smsVerifyCodeService.sendAuditNotify(user.getPhone(), auditStatus, sysUserRequest.getCommentInfo());
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
} else {
|
} else {
|
||||||
return ResponseResult.error("审核失败");
|
return ResponseResult.error("审核失败");
|
||||||
|
|||||||
@ -37,4 +37,13 @@ public interface ISmsVerifyCodeService extends IService<SmsVerifyCode> {
|
|||||||
* 生成6位数字验证码
|
* 生成6位数字验证码
|
||||||
*/
|
*/
|
||||||
String generateCode();
|
String generateCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送审核结果通知短信
|
||||||
|
* @param phone 手机号
|
||||||
|
* @param auditStatus 审核状态 1-通过 2-驳回
|
||||||
|
* @param reason 驳回原因(可选)
|
||||||
|
* @return 是否发送成功
|
||||||
|
*/
|
||||||
|
boolean sendAuditNotify(String phone, Integer auditStatus, String reason);
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ public interface IUserService extends IService<SysUser> {
|
|||||||
*id 重置密码的 用户id
|
*id 重置密码的 用户id
|
||||||
* 返回值说明: 判断是否重置成功
|
* 返回值说明: 判断是否重置成功
|
||||||
************************************/
|
************************************/
|
||||||
boolean resetPassword(String id) throws Exception;
|
ResponseResult resetPassword(String id) throws Exception;
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
* 用途说明:设置账号状态(管理员)
|
* 用途说明:设置账号状态(管理员)
|
||||||
|
|||||||
@ -96,4 +96,28 @@ public class SmsVerifyCodeServiceImpl extends ServiceImpl<SmsVerifyCodeMapper, S
|
|||||||
public String generateCode() {
|
public String generateCode() {
|
||||||
return String.format("%06d", RANDOM.nextInt(1000000));
|
return String.format("%06d", RANDOM.nextInt(1000000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean sendAuditNotify(String phone, Integer auditStatus, String reason) {
|
||||||
|
if (phone == null || phone.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String content;
|
||||||
|
if (auditStatus == 1) {
|
||||||
|
content = "您的数据填报系统账号已审核通过,现在可以正常登录系统了。";
|
||||||
|
} else if (auditStatus == 2) {
|
||||||
|
if (reason != null && !reason.isEmpty()) {
|
||||||
|
content = "您的数据填报系统账号审核未通过,原因:" + reason;
|
||||||
|
} else {
|
||||||
|
content = "您的数据填报系统账号审核未通过,请联系管理员。";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return smsSender.send(phone, content);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -425,8 +425,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
|||||||
* 返回值说明: 判断是重置成功
|
* 返回值说明: 判断是重置成功
|
||||||
************************************/
|
************************************/
|
||||||
@Override
|
@Override
|
||||||
public boolean resetPassword(String id) throws Exception {
|
public ResponseResult resetPassword(String id) throws Exception {
|
||||||
boolean isOk = false;
|
|
||||||
//根据当前用户id 查询角色表的级别 currentUser.getUser() 获取当前用户id
|
//根据当前用户id 查询角色表的级别 currentUser.getUser() 获取当前用户id
|
||||||
String level = sysUserMapper.getMaxLevel(id);
|
String level = sysUserMapper.getMaxLevel(id);
|
||||||
//判断是否获取级别
|
//判断是否获取级别
|
||||||
@ -443,10 +442,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
|||||||
new Timestamp(System.currentTimeMillis())).set(
|
new Timestamp(System.currentTimeMillis())).set(
|
||||||
"lastmodifier", getUsername());
|
"lastmodifier", getUsername());
|
||||||
//是否修改成功
|
//是否修改成功
|
||||||
isOk = this.update(updateWrapper);
|
this.update(updateWrapper);
|
||||||
|
return ResponseResult.success("重置密码成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isOk;
|
return ResponseResult.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
|
|||||||
@ -22,10 +22,12 @@ import com.yfd.platform.exception.BadRequestException;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,4 +93,16 @@ public class SecurityUtils {
|
|||||||
return JSONUtil.toList(array,Long.class);
|
return JSONUtil.toList(array,Long.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在 SecurityUtils.java 中
|
||||||
|
public static boolean hasPermission(String permission) {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
if (authentication == null || !authentication.isAuthenticated()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
||||||
|
return authorities != null && authorities.stream()
|
||||||
|
.anyMatch(auth -> permission.equals(auth.getAuthority()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: prod
|
active: devtw
|
||||||
|
|
||||||
jasypt:
|
jasypt:
|
||||||
encryptor:
|
encryptor:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user