diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java index 85ee652..06c69d8 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java @@ -11,6 +11,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.transaction.annotation.EnableTransactionManagement; /** @@ -20,9 +21,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableAsync @MapperScan(App.MAPPER_PACKAGES) @EnableScheduling +@EnableGlobalMethodSecurity(prePostEnabled = true) @EnableTransactionManagement @EnableAspectJAutoProxy(exposeProxy = true) -@ComponentScan(basePackages = {"com.ningdatech.kqapi","com.ningdatech.kqapi.common"}) +@ComponentScan(basePackages = {"com.ningdatech.kqapi", "com.ningdatech.kqapi.common"}) public class App { protected static final String MAPPER_PACKAGES = "com.ningdatech.kqapi.**.mapper"; diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java index 9387aef..da06457 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java @@ -6,6 +6,7 @@ import com.ningdatech.kqapi.common.model.Status; import lombok.extern.slf4j.Slf4j; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.HttpStatus; +import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -70,8 +71,15 @@ public class GlobalExceptionHandler { } @ResponseBody + @ExceptionHandler(value = AccessDeniedException.class) + public ApiResponse accessDeniedException(AccessDeniedException e) { + printLog(e); + return ApiResponse.of(Status.BAD_REQUEST.getCode(), "暂无操作权限"); + } + + @ResponseBody @ExceptionHandler(value = BizException.class) - public ApiResponse bizException(Exception e) { + public ApiResponse bizException(BizException e) { printLog(e); return ApiResponse.of(Status.BAD_REQUEST.getCode(), e.getMessage()); } diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java index 1473d1a..a5cee18 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java @@ -74,7 +74,7 @@ public class TaskController { @ApiOperation(value = "同步菜单链接数据", notes = "同步菜单链接数据") @GetMapping("/syn-menu") - public String synMenuData() throws UnknownHostException { + public String synMenuData() { synTask.synMenu(); return "同步成功"; } diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java index 2dbc4f6..f5b3904 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java @@ -7,10 +7,9 @@ import com.github.benmanes.caffeine.cache.LoadingCache; import com.ningdatech.kqapi.common.constant.BizConst; import com.ningdatech.kqapi.common.enumeration.CommonEnum; import com.ningdatech.kqapi.common.helper.MatterCacheHelper; +import com.ningdatech.kqapi.zzsfw.manage.MatterManage; import com.ningdatech.kqapi.zzsfw.model.entity.*; import com.ningdatech.kqapi.zzsfw.service.ComponentsMatterEliminateService; -import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMenu; -import com.ningdatech.kqapi.zzsfw.manage.MatterManage; import com.ningdatech.kqapi.zzsfw.service.IDscSxAdsShareItemQltQlsxCommonIDVKqService; import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMatterDeduplicateService; import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMenuService; @@ -70,86 +69,74 @@ public class SynTask { */ @Scheduled(cron = "0 30 8 * * ?") public void synData() throws UnknownHostException { -// if (!HOST.equals(InetAddress.getLocalHost().getHostName())) { -// log.info("定时器没开启或者host不对! {}:{}", -// HOST,InetAddress.getLocalHost().getHostName()); -// return; -// } -// if(!TaskContant.PROD.equals(active)){ -// log.info("非正式环境不用运行同步任务!"); -// return; -// } - log.info("政务数据 ===================== 同步开始"); StopWatch stopWatch = new StopWatch(); stopWatch.start(); //1.处理 去重数据 - if(matterCacheHelper.refreshAll()){ + if (matterCacheHelper.refreshAll()) { matterManage.removeAllDup(); List allDup = matterCacheHelper.all(); matterDeduplicateService.saveBatch(allDup); //2. 事项 List menus = menuService.list(); - for(KqZzsfwMenu menu : menus){ + for (KqZzsfwMenu menu : menus) { String url = matterCacheHelper.getUrl(menu.getItemName()); - if(StringUtils.isBlank(url)){ + if (StringUtils.isBlank(url)) { menuService.update(Wrappers.lambdaUpdate(KqZzsfwMenu.class) - .eq(KqZzsfwMenu::getId,menu.getId()) - .set(KqZzsfwMenu::getWebapplyurl,null) + .eq(KqZzsfwMenu::getId, menu.getId()) + .set(KqZzsfwMenu::getWebapplyurl, null) .set(KqZzsfwMenu::getHasUrl, CommonEnum.NO.getCode())); - }else{ + } else { menuService.update(Wrappers.lambdaUpdate(KqZzsfwMenu.class) - .eq(KqZzsfwMenu::getId,menu.getId()) - .set(KqZzsfwMenu::getWebapplyurl,url) - .set(KqZzsfwMenu::getHasUrl,CommonEnum.YES.getCode())); + .eq(KqZzsfwMenu::getId, menu.getId()) + .set(KqZzsfwMenu::getWebapplyurl, url) + .set(KqZzsfwMenu::getHasUrl, CommonEnum.YES.getCode())); } } } stopWatch.stop(); - log.info("政务数据 ===================== 同步总共耗时 :{} s",stopWatch.getTotalTimeSeconds()); + log.info("政务数据 ===================== 同步总共耗时 :{} s", stopWatch.getTotalTimeSeconds()); } public void synMenu() { //2. 事项 List menus = menuService.list(); - for(KqZzsfwMenu menu : menus){ + for (KqZzsfwMenu menu : menus) { String url = matterCacheHelper.getUrl(menu.getItemName()); - log.info("当前缓存的数据 : {},{}",menu.getItemName(),url); - if(StringUtils.isBlank(url)){ + log.info("当前缓存的数据 : {},{}", menu.getItemName(), url); + if (StringUtils.isBlank(url)) { menuService.update(Wrappers.lambdaUpdate(KqZzsfwMenu.class) - .eq(KqZzsfwMenu::getId,menu.getId()) - .set(KqZzsfwMenu::getWebapplyurl,null) + .eq(KqZzsfwMenu::getId, menu.getId()) + .set(KqZzsfwMenu::getWebapplyurl, null) .set(KqZzsfwMenu::getHasUrl, CommonEnum.NO.getCode())); - }else{ + } else { menuService.update(Wrappers.lambdaUpdate(KqZzsfwMenu.class) - .eq(KqZzsfwMenu::getId,menu.getId()) - .set(KqZzsfwMenu::getWebapplyurl,url) - .set(KqZzsfwMenu::getHasUrl,CommonEnum.YES.getCode())); + .eq(KqZzsfwMenu::getId, menu.getId()) + .set(KqZzsfwMenu::getWebapplyurl, url) + .set(KqZzsfwMenu::getHasUrl, CommonEnum.YES.getCode())); } } } - public String synEliminate(List keys){ -// kqService.remove(new LambdaQueryWrapper() -// .in(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, keys)); + public String synEliminate(List keys) { // 添加剔除信息 List entityList = new ArrayList<>(); - keys.forEach(key ->{ + keys.forEach(key -> { ComponentsMatterEliminateEntity one = componentsMatterEliminateService.getOne(Wrappers.lambdaQuery(ComponentsMatterEliminateEntity.class) .eq(ComponentsMatterEliminateEntity::getQlName, key)); - if (Objects.isNull(one)){ - entityList.add(new ComponentsMatterEliminateEntity(key,"1")); + if (Objects.isNull(one)) { + entityList.add(new ComponentsMatterEliminateEntity(key, "1")); } // 删除缓存 DscSxAdsShareItemQltQlsxCommonIDVKq matter = getSynUrl(key); String url = KQ_ZZS_BASE_URL.replace("localInnerCode=", "localInnerCode=" + matter.getQlInnerCode()); - MatterKey matterKey = MatterKey.of(matter.getQlName(),url); + MatterKey matterKey = MatterKey.of(matter.getQlName(), url); try { mattersDupCache.invalidate(matterKey); - }catch (Exception e){ + } catch (Exception e) { log.error("mattersDupCache is null", e.getMessage()); } }); @@ -165,8 +152,8 @@ public class SynTask { return "剔除成功"; } - - public DscSxAdsShareItemQltQlsxCommonIDVKq getSynUrl(String key){ + + public DscSxAdsShareItemQltQlsxCommonIDVKq getSynUrl(String key) { DscSxAdsShareItemQltQlsxCommonIDVKq matter = kqService .getOne(Wrappers.lambdaQuery(DscSxAdsShareItemQltQlsxCommonIDVKq.class) .select(DscSxAdsShareItemQltQlsxCommonIDVKq::getRowguid, @@ -185,21 +172,18 @@ public class SynTask { return matter; } - public String synSingle(String key){ + public void synSingle(String key) { DscSxAdsShareItemQltQlsxCommonIDVKq matter = getSynUrl(key); String url = KQ_ZZS_BASE_URL.replace("localInnerCode=", "localInnerCode=" + matter.getQlInnerCode()); List menus = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) .eq(KqZzsfwMenu::getItemName, key)); - menus.forEach(menu->{ - menuService.update(Wrappers.lambdaUpdate(KqZzsfwMenu.class) - .eq(KqZzsfwMenu::getId,menu.getId()) - .set(KqZzsfwMenu::getWebapplyurl,url) - .set(KqZzsfwMenu::getHasUrl,CommonEnum.YES.getCode())); - }); + menus.forEach(menu -> menuService.update(Wrappers.lambdaUpdate(KqZzsfwMenu.class) + .eq(KqZzsfwMenu::getId, menu.getId()) + .set(KqZzsfwMenu::getWebapplyurl, url) + .set(KqZzsfwMenu::getHasUrl, CommonEnum.YES.getCode()))); // 更新缓存 - MatterKey matterKey = MatterKey.of(matter.getQlName(),url); + MatterKey matterKey = MatterKey.of(matter.getQlName(), url); mattersDupCache.invalidate(matterKey); - mattersDupCache.put(matterKey, KqZzsfwMattersDeduplicate.of(matter.getQlName(),url)); - return "更新成功,rul:" + url; + mattersDupCache.put(matterKey, KqZzsfwMattersDeduplicate.of(matter.getQlName(), url)); } } diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserInfoController.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserInfoController.java index d056bbb..aa310ac 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserInfoController.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserInfoController.java @@ -15,9 +15,9 @@ import com.ningdatech.log.annotation.WebLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import javax.annotation.security.RolesAllowed; import javax.validation.Valid; /** @@ -39,7 +39,7 @@ public class UserInfoController { @PostMapping(value = "/save") @ApiOperation(value = "保存用户") @WebLog(value = "保存用户") - @RolesAllowed("SUPER_ADMIN") + @PreAuthorize("hasAuthority('SUPER_ADMIN')") public void saveUser(@Valid @RequestBody SaveUserReq request) { userInfoManage.saveUser(request); } @@ -47,7 +47,7 @@ public class UserInfoController { @PostMapping(value = "/changeAccountStatus") @ApiOperation(value = "账号状态变更") @WebLog(value = "账号状态变更") - @RolesAllowed("SUPER_ADMIN") + @PreAuthorize("hasAuthority('SUPER_ADMIN')") public void changeAccountStatus(@Valid @RequestBody ChangeAccountStatusReq req) { userInfoManage.changeAccountStatus(req); } @@ -62,7 +62,7 @@ public class UserInfoController { @DeleteMapping("/del") @ApiOperation("删除用户") @WebLog(value = "删除用户") - @RolesAllowed("SUPER_ADMIN") + @PreAuthorize("hasAuthority('SUPER_ADMIN')") public void deleteUser(@RequestBody IdVo req) { userInfoManage.deleteUser(req.getId()); } @@ -90,7 +90,7 @@ public class UserInfoController { @PostMapping("/password/mod") @ApiOperation("修改密码") @WebLog(value = "修改密码") - @RolesAllowed("SUPER_ADMIN") + @PreAuthorize("hasAuthority('SUPER_ADMIN')") public void changePassword(@Valid @RequestBody ModifyPasswordReq po) { userInfoManage.changePassword(po); } diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/manage/UserInfoManage.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/manage/UserInfoManage.java index a212e98..3e63f88 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/manage/UserInfoManage.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/manage/UserInfoManage.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ningdatech.basic.exception.BizException; @@ -20,9 +19,9 @@ import com.ningdatech.kqapi.user.model.po.ChangeAccountStatusReq; import com.ningdatech.kqapi.user.model.po.ModifyPasswordReq; import com.ningdatech.kqapi.user.model.po.SaveUserReq; import com.ningdatech.kqapi.user.model.po.UserListReq; -import com.ningdatech.kqapi.user.model.vo.UserListVO; import com.ningdatech.kqapi.user.model.vo.LoginUserDetailVO; import com.ningdatech.kqapi.user.model.vo.UserDetailVO; +import com.ningdatech.kqapi.user.model.vo.UserListVO; import com.ningdatech.kqapi.user.service.IUserAuthService; import com.ningdatech.kqapi.user.service.IUserInfoService; import com.ningdatech.kqapi.user.util.BizUtils; @@ -35,7 +34,10 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.stream.Collectors; @@ -102,9 +104,14 @@ public class UserInfoManage { private void modifyAccount(SaveUserReq req, UserInfo oldUser, Long userId) { // 用户ID不为空时修改账号 + String password = null; + if (StrUtil.isNotBlank(req.getPassword())) { + password = passwordEncoder.encode(req.getPassword()); + } if (!oldUser.getMobile().equals(req.getPhoneNo())) { Wrapper phoneAuth = Wrappers.lambdaUpdate(UserAuth.class) .set(UserAuth::getIdentifier, req.getPhoneNo()) + .set(password != null, UserAuth::getCredential, password) .eq(UserAuth::getUserId, userId) .eq(UserAuth::getAuthType, AuthTypeEnum.PHONE_PASSWORD); userAuthService.update(phoneAuth); @@ -112,6 +119,7 @@ public class UserInfoManage { if (!oldUser.getUsername().equals(req.getUserName())) { Wrapper accountAuth = Wrappers.lambdaUpdate(UserAuth.class) .set(UserAuth::getIdentifier, req.getUserName()) + .set(password != null, UserAuth::getCredential, password) .eq(UserAuth::getUserId, userId) .eq(UserAuth::getAuthType, AuthTypeEnum.ACCOUNT_PASSWORD); userAuthService.update(accountAuth);