mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-11-04 09:01:37 +08:00 
			
		
		
		
	refactor: 优化通知公告部分代码
This commit is contained in:
		@@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated;
 | 
			
		||||
import org.springframework.web.bind.annotation.PathVariable;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
import top.continew.admin.system.enums.NoticeScopeEnum;
 | 
			
		||||
import top.continew.admin.system.model.query.NoticeQuery;
 | 
			
		||||
import top.continew.admin.system.model.req.NoticeReq;
 | 
			
		||||
import top.continew.admin.system.model.resp.NoticeDetailResp;
 | 
			
		||||
@@ -48,26 +49,31 @@ public class NoticeController extends BaseController<NoticeService, NoticeResp,
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody NoticeReq req) {
 | 
			
		||||
        this.checkTime(req);
 | 
			
		||||
        this.check(req);
 | 
			
		||||
        return super.add(req);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody NoticeReq req, @PathVariable Long id) {
 | 
			
		||||
        this.checkTime(req);
 | 
			
		||||
        this.check(req);
 | 
			
		||||
        super.update(req, id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 检查时间
 | 
			
		||||
     * 校验
 | 
			
		||||
     *
 | 
			
		||||
     * @param req 创建或修改信息
 | 
			
		||||
     */
 | 
			
		||||
    private void checkTime(NoticeReq req) {
 | 
			
		||||
    private void check(NoticeReq req) {
 | 
			
		||||
        // 校验生效时间
 | 
			
		||||
        LocalDateTime effectiveTime = req.getEffectiveTime();
 | 
			
		||||
        LocalDateTime terminateTime = req.getTerminateTime();
 | 
			
		||||
        if (null != effectiveTime && null != terminateTime) {
 | 
			
		||||
            ValidationUtils.throwIf(terminateTime.isBefore(effectiveTime), "终止时间必须晚于生效时间");
 | 
			
		||||
        }
 | 
			
		||||
        // 校验通知范围
 | 
			
		||||
        if (NoticeScopeEnum.USER.equals(req.getNoticeScope())) {
 | 
			
		||||
            ValidationUtils.throwIfEmpty(req.getNoticeUsers(), "请选择通知用户");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -46,12 +46,10 @@ import top.continew.starter.core.util.validate.ValidationUtils;
 | 
			
		||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
 | 
			
		||||
import top.continew.starter.extension.crud.controller.BaseController;
 | 
			
		||||
import top.continew.starter.extension.crud.enums.Api;
 | 
			
		||||
import top.continew.starter.extension.crud.model.query.SortQuery;
 | 
			
		||||
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
 | 
			
		||||
import top.continew.starter.extension.crud.util.ValidateGroup;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 用户管理 API
 | 
			
		||||
@@ -63,16 +61,12 @@ import java.util.List;
 | 
			
		||||
@Validated
 | 
			
		||||
@RestController
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
@CrudRequestMapping(value = "/system/user", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT})
 | 
			
		||||
@CrudRequestMapping(value = "/system/user", api = {Api.PAGE, Api.LIST, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE,
 | 
			
		||||
    Api.EXPORT})
 | 
			
		||||
public class UserController extends BaseController<UserService, UserResp, UserDetailResp, UserQuery, UserReq> {
 | 
			
		||||
 | 
			
		||||
    private final UserService userService;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<UserResp> list(UserQuery query, SortQuery sortQuery) {
 | 
			
		||||
        return super.list(query, sortQuery);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) {
 | 
			
		||||
        String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getPassword()));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user