diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 459007d..ac73dee 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,16 +2,41 @@ + + + + + - + + + + - + + + - - - + + + + + + + + + + + + + + + + + + + @@ -66,7 +92,7 @@ - + @@ -2458,7 +2484,8 @@ - + + @@ -2495,10 +2522,10 @@ - + - + @@ -2511,66 +2538,66 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - + diff --git a/src/main/java/com/coderman/api/biz/controller/ConsumerController.java b/src/main/java/com/coderman/api/biz/controller/ConsumerController.java index 74a5d9f..9c947ae 100644 --- a/src/main/java/com/coderman/api/biz/controller/ConsumerController.java +++ b/src/main/java/com/coderman/api/biz/controller/ConsumerController.java @@ -3,7 +3,7 @@ package com.coderman.api.biz.controller; import com.coderman.api.biz.service.ConsumerService; import com.coderman.api.biz.vo.ConsumerVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/com/coderman/api/biz/controller/HealthController.java b/src/main/java/com/coderman/api/biz/controller/HealthController.java index e53f77b..bed0dd6 100644 --- a/src/main/java/com/coderman/api/biz/controller/HealthController.java +++ b/src/main/java/com/coderman/api/biz/controller/HealthController.java @@ -4,8 +4,8 @@ import com.coderman.api.common.pojo.biz.Health; import com.coderman.api.biz.service.HealthService; import com.coderman.api.biz.vo.HealthVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ActiveUser; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ActiveUser; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/com/coderman/api/biz/controller/InStockController.java b/src/main/java/com/coderman/api/biz/controller/InStockController.java index 0995319..bf2268e 100644 --- a/src/main/java/com/coderman/api/biz/controller/InStockController.java +++ b/src/main/java/com/coderman/api/biz/controller/InStockController.java @@ -7,7 +7,7 @@ import com.coderman.api.biz.vo.InStockDetailVO; import com.coderman.api.biz.vo.InStockVO; import com.coderman.api.biz.vo.SupplierVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/com/coderman/api/biz/controller/NcovAPIController.java b/src/main/java/com/coderman/api/biz/controller/NcovAPIController.java index e493c84..0c4b951 100644 --- a/src/main/java/com/coderman/api/biz/controller/NcovAPIController.java +++ b/src/main/java/com/coderman/api/biz/controller/NcovAPIController.java @@ -3,7 +3,7 @@ package com.coderman.api.biz.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import io.swagger.annotations.Api; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; diff --git a/src/main/java/com/coderman/api/biz/controller/OutStockController.java b/src/main/java/com/coderman/api/biz/controller/OutStockController.java index aecfcf8..cccf8a5 100644 --- a/src/main/java/com/coderman/api/biz/controller/OutStockController.java +++ b/src/main/java/com/coderman/api/biz/controller/OutStockController.java @@ -7,7 +7,7 @@ import com.coderman.api.biz.vo.ConsumerVO; import com.coderman.api.biz.vo.OutStockDetailVO; import com.coderman.api.biz.vo.OutStockVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/com/coderman/api/biz/controller/ProductCategoryController.java b/src/main/java/com/coderman/api/biz/controller/ProductCategoryController.java index 3b9e75b..f42a86a 100644 --- a/src/main/java/com/coderman/api/biz/controller/ProductCategoryController.java +++ b/src/main/java/com/coderman/api/biz/controller/ProductCategoryController.java @@ -3,7 +3,7 @@ package com.coderman.api.biz.controller; import com.coderman.api.biz.service.ProductCategoryService; import com.coderman.api.biz.vo.ProductCategoryTreeNodeVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import com.coderman.api.biz.vo.ProductCategoryVO; import io.swagger.annotations.Api; diff --git a/src/main/java/com/coderman/api/biz/controller/ProductController.java b/src/main/java/com/coderman/api/biz/controller/ProductController.java index 60a9032..2d22d79 100644 --- a/src/main/java/com/coderman/api/biz/controller/ProductController.java +++ b/src/main/java/com/coderman/api/biz/controller/ProductController.java @@ -4,7 +4,7 @@ import com.coderman.api.biz.service.ProductService; import com.coderman.api.biz.vo.ProductStockVO; import com.coderman.api.biz.vo.ProductVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/com/coderman/api/biz/controller/SupplierController.java b/src/main/java/com/coderman/api/biz/controller/SupplierController.java index 5f8843f..939c763 100644 --- a/src/main/java/com/coderman/api/biz/controller/SupplierController.java +++ b/src/main/java/com/coderman/api/biz/controller/SupplierController.java @@ -3,7 +3,7 @@ package com.coderman.api.biz.controller; import com.coderman.api.biz.service.SupplierService; import com.coderman.api.biz.vo.SupplierVO; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/com/coderman/api/biz/service/imp/InStockServiceImpl.java b/src/main/java/com/coderman/api/biz/service/imp/InStockServiceImpl.java index 89205c3..80f30f4 100644 --- a/src/main/java/com/coderman/api/biz/service/imp/InStockServiceImpl.java +++ b/src/main/java/com/coderman/api/biz/service/imp/InStockServiceImpl.java @@ -8,7 +8,7 @@ import com.coderman.api.biz.vo.InStockItemVO; import com.coderman.api.biz.vo.InStockVO; import com.coderman.api.biz.vo.SupplierVO; import com.coderman.api.common.pojo.biz.*; -import com.coderman.api.system.bean.ActiveUser; +import com.coderman.api.common.bean.ActiveUser; import com.coderman.api.common.exception.ErrorCodeEnum; import com.coderman.api.common.exception.ServiceException; import com.coderman.api.system.vo.PageVO; diff --git a/src/main/java/com/coderman/api/biz/service/imp/OutStockServiceImpl.java b/src/main/java/com/coderman/api/biz/service/imp/OutStockServiceImpl.java index 7a32431..39753fc 100644 --- a/src/main/java/com/coderman/api/biz/service/imp/OutStockServiceImpl.java +++ b/src/main/java/com/coderman/api/biz/service/imp/OutStockServiceImpl.java @@ -5,7 +5,7 @@ import com.coderman.api.biz.mapper.*; import com.coderman.api.biz.service.OutStockService; import com.coderman.api.biz.vo.*; import com.coderman.api.common.pojo.biz.*; -import com.coderman.api.system.bean.ActiveUser; +import com.coderman.api.common.bean.ActiveUser; import com.coderman.api.common.exception.ErrorCodeEnum; import com.coderman.api.common.exception.ServiceException; import com.coderman.api.system.vo.PageVO; diff --git a/src/main/java/com/coderman/api/common/aspect/ControllerEndpointAspect.java b/src/main/java/com/coderman/api/common/aspect/ControllerEndpointAspect.java index d642ab1..f228650 100644 --- a/src/main/java/com/coderman/api/common/aspect/ControllerEndpointAspect.java +++ b/src/main/java/com/coderman/api/common/aspect/ControllerEndpointAspect.java @@ -2,7 +2,7 @@ package com.coderman.api.common.aspect; import com.alibaba.fastjson.JSON; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ActiveUser; +import com.coderman.api.common.bean.ActiveUser; import com.coderman.api.common.pojo.system.Log; import com.coderman.api.system.service.LogService; import com.coderman.api.common.utils.AddressUtil; diff --git a/src/main/java/com/coderman/api/system/bean/ActiveUser.java b/src/main/java/com/coderman/api/common/bean/ActiveUser.java similarity index 97% rename from src/main/java/com/coderman/api/system/bean/ActiveUser.java rename to src/main/java/com/coderman/api/common/bean/ActiveUser.java index 867f7d6..ea0cab1 100644 --- a/src/main/java/com/coderman/api/system/bean/ActiveUser.java +++ b/src/main/java/com/coderman/api/common/bean/ActiveUser.java @@ -1,4 +1,4 @@ -package com.coderman.api.system.bean; +package com.coderman.api.common.bean; import com.coderman.api.common.pojo.system.Menu; import com.coderman.api.common.pojo.system.Role; diff --git a/src/main/java/com/coderman/api/system/bean/ResponseBean.java b/src/main/java/com/coderman/api/common/bean/ResponseBean.java similarity index 97% rename from src/main/java/com/coderman/api/system/bean/ResponseBean.java rename to src/main/java/com/coderman/api/common/bean/ResponseBean.java index 7495278..d9b60cd 100644 --- a/src/main/java/com/coderman/api/system/bean/ResponseBean.java +++ b/src/main/java/com/coderman/api/common/bean/ResponseBean.java @@ -1,4 +1,4 @@ -package com.coderman.api.system.bean; +package com.coderman.api.common.bean; import lombok.Data; diff --git a/src/main/java/com/coderman/api/common/config/shiro/JWTFilter.java b/src/main/java/com/coderman/api/common/config/shiro/JWTFilter.java index 33c5755..c0acc0d 100644 --- a/src/main/java/com/coderman/api/common/config/shiro/JWTFilter.java +++ b/src/main/java/com/coderman/api/common/config/shiro/JWTFilter.java @@ -1,6 +1,6 @@ package com.coderman.api.common.config.shiro; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.common.config.jwt.JWTToken; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/coderman/api/common/config/shiro/UserRealm.java b/src/main/java/com/coderman/api/common/config/shiro/UserRealm.java index deb2360..3cb4ceb 100644 --- a/src/main/java/com/coderman/api/common/config/shiro/UserRealm.java +++ b/src/main/java/com/coderman/api/common/config/shiro/UserRealm.java @@ -1,12 +1,12 @@ package com.coderman.api.common.config.shiro; -import com.coderman.api.system.bean.ActiveUser; +import com.coderman.api.common.bean.ActiveUser; import com.coderman.api.common.config.jwt.JWTToken; import com.coderman.api.common.pojo.system.Menu; import com.coderman.api.common.pojo.system.Role; import com.coderman.api.common.pojo.system.User; -import com.coderman.api.system.service.UserService; import com.coderman.api.common.utils.JWTUtils; +import com.coderman.api.system.service.UserService; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.apache.shiro.authz.AuthorizationInfo; @@ -102,7 +102,7 @@ public class UserRealm extends AuthorizingRealm { //如果验证通过,获取用户的角色 List roles= userService.findRolesById(userBean.getId()); //查询用户的所有菜单(包括了菜单和按钮) - List menus=userService.findMenuById(roles); + List menus=userService.findMenuByRoles(roles); Set urls=new HashSet<>(); Set perms=new HashSet<>(); @@ -125,7 +125,6 @@ public class UserRealm extends AuthorizingRealm { activeUser.setMenus(menus); activeUser.setUrls(urls); activeUser.setPermissions(perms); - return new SimpleAuthenticationInfo(activeUser, token, getName()); } } diff --git a/src/main/java/com/coderman/api/common/config/web/GlobalExceptionHandler.java b/src/main/java/com/coderman/api/common/config/web/GlobalExceptionHandler.java index f66e6e5..791456e 100644 --- a/src/main/java/com/coderman/api/common/config/web/GlobalExceptionHandler.java +++ b/src/main/java/com/coderman/api/common/config/web/GlobalExceptionHandler.java @@ -1,7 +1,7 @@ package com.coderman.api.common.config.web; import com.coderman.api.common.exception.ServiceException; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.ShiroException; import org.springframework.context.support.DefaultMessageSourceResolvable; diff --git a/src/main/java/com/coderman/api/common/exception/ErrorCodeEnum.java b/src/main/java/com/coderman/api/common/exception/ErrorCodeEnum.java index 0701ff3..a65de08 100644 --- a/src/main/java/com/coderman/api/common/exception/ErrorCodeEnum.java +++ b/src/main/java/com/coderman/api/common/exception/ErrorCodeEnum.java @@ -3,7 +3,10 @@ package com.coderman.api.common.exception; import lombok.Getter; /** + * * 业务错误码:返回结果的状态码 + * + * 如果想要代码更具维护性一点,可以定义不同种类的错误码,都实现 BaseCodeInterface * @Author zhangyukang * @Date 2020/3/1 14:51 * @Version 1.0 diff --git a/src/main/java/com/coderman/api/common/utils/JWTUtils.java b/src/main/java/com/coderman/api/common/utils/JWTUtils.java index d24a3bf..76c2f47 100644 --- a/src/main/java/com/coderman/api/common/utils/JWTUtils.java +++ b/src/main/java/com/coderman/api/common/utils/JWTUtils.java @@ -16,9 +16,9 @@ import java.util.Date; public class JWTUtils { /** - * 过期时间2小时 + * 过期时间6小时 */ - private static final long EXPIRE_TIME = 3*60*60*1000; + private static final long EXPIRE_TIME = 6*60*60*1000; /** * 校验token是否正确 diff --git a/src/main/java/com/coderman/api/system/controller/DepartmentController.java b/src/main/java/com/coderman/api/system/controller/DepartmentController.java index b1dc99a..205231f 100644 --- a/src/main/java/com/coderman/api/system/controller/DepartmentController.java +++ b/src/main/java/com/coderman/api/system/controller/DepartmentController.java @@ -1,7 +1,7 @@ package com.coderman.api.system.controller; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.common.pojo.system.Department; import com.coderman.api.system.service.DepartmentService; import com.coderman.api.system.vo.DeanVO; diff --git a/src/main/java/com/coderman/api/system/controller/FileUploadController.java b/src/main/java/com/coderman/api/system/controller/FileUploadController.java index 350c43a..55fa3c4 100644 --- a/src/main/java/com/coderman/api/system/controller/FileUploadController.java +++ b/src/main/java/com/coderman/api/system/controller/FileUploadController.java @@ -1,7 +1,7 @@ package com.coderman.api.system.controller; import com.coderman.api.common.utils.CommonFileUtil; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.mapper.ImageAttachmentMapper; import com.coderman.api.common.pojo.system.ImageAttachment; import com.coderman.api.system.vo.ImageAttachmentVO; diff --git a/src/main/java/com/coderman/api/system/controller/LogController.java b/src/main/java/com/coderman/api/system/controller/LogController.java index e5a0d78..2221cb4 100644 --- a/src/main/java/com/coderman/api/system/controller/LogController.java +++ b/src/main/java/com/coderman/api/system/controller/LogController.java @@ -1,6 +1,6 @@ package com.coderman.api.system.controller; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.service.LogService; import com.coderman.api.system.vo.LogVO; import com.coderman.api.system.vo.PageVO; diff --git a/src/main/java/com/coderman/api/system/controller/LoginLogController.java b/src/main/java/com/coderman/api/system/controller/LoginLogController.java index b48fc77..d71d9e7 100644 --- a/src/main/java/com/coderman/api/system/controller/LoginLogController.java +++ b/src/main/java/com/coderman/api/system/controller/LoginLogController.java @@ -1,7 +1,7 @@ package com.coderman.api.system.controller; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.service.LoginLogService; import com.coderman.api.system.vo.LoginLogVO; import com.coderman.api.system.vo.PageVO; diff --git a/src/main/java/com/coderman/api/system/controller/MenuController.java b/src/main/java/com/coderman/api/system/controller/MenuController.java index 5519d3c..517d111 100644 --- a/src/main/java/com/coderman/api/system/controller/MenuController.java +++ b/src/main/java/com/coderman/api/system/controller/MenuController.java @@ -1,7 +1,7 @@ package com.coderman.api.system.controller; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.common.pojo.system.Menu; import com.coderman.api.system.service.MenuService; import com.coderman.api.system.vo.MenuNodeVO; diff --git a/src/main/java/com/coderman/api/system/controller/RoleController.java b/src/main/java/com/coderman/api/system/controller/RoleController.java index 110c071..9e58af3 100644 --- a/src/main/java/com/coderman/api/system/controller/RoleController.java +++ b/src/main/java/com/coderman/api/system/controller/RoleController.java @@ -1,7 +1,7 @@ package com.coderman.api.system.controller; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.common.pojo.system.Role; import com.coderman.api.system.service.MenuService; import com.coderman.api.system.service.RoleService; diff --git a/src/main/java/com/coderman/api/system/controller/UserController.java b/src/main/java/com/coderman/api/system/controller/UserController.java index 75e1e6c..41047be 100644 --- a/src/main/java/com/coderman/api/system/controller/UserController.java +++ b/src/main/java/com/coderman/api/system/controller/UserController.java @@ -1,7 +1,7 @@ package com.coderman.api.system.controller; import com.coderman.api.common.annotation.ControllerEndpoint; -import com.coderman.api.system.bean.ResponseBean; +import com.coderman.api.common.bean.ResponseBean; import com.coderman.api.system.converter.RoleConverter; import com.coderman.api.common.pojo.system.Role; import com.coderman.api.common.pojo.system.User; @@ -56,7 +56,7 @@ public class UserController { */ @ApiOperation(value = "用户登入", notes = "接收参数用户名和密码,登入成功后,返回JWTToken") @PostMapping("/login") - public ResponseBean login(@NotBlank(message = "用户名必填") String username, + public ResponseBean login(@NotBlank(message = "账号必填") String username, @NotBlank(message = "密码必填") String password, HttpServletRequest request) { String token=userService.login(username,password); @@ -192,13 +192,8 @@ public class UserController { @RequiresPermissions({"user:add"}) @PostMapping("/add") public ResponseBean add(@RequestBody @Validated UserVO userVO) { - User user = userService.findUserByName(userVO.getUsername()); - if (user == null) { - userService.add(userVO); - return ResponseBean.success(); - } else { - return ResponseBean.error("用户名已被占用"); - } + userService.add(userVO); + return ResponseBean.success(); } /** diff --git a/src/main/java/com/coderman/api/system/enums/RoleStatusEnum.java b/src/main/java/com/coderman/api/system/enums/RoleStatusEnum.java new file mode 100644 index 0000000..798904c --- /dev/null +++ b/src/main/java/com/coderman/api/system/enums/RoleStatusEnum.java @@ -0,0 +1,27 @@ +package com.coderman.api.system.enums; + +/** + * @Author zhangyukang + * @Date 2020/5/29 16:52 + * @Version 1.0 + **/ + + +public enum RoleStatusEnum { + DISABLE(0), + AVAILABLE(1); + + private int statusCode; + + RoleStatusEnum(int statusCode) { + this.statusCode = statusCode; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } +} diff --git a/src/main/java/com/coderman/api/system/service/UserService.java b/src/main/java/com/coderman/api/system/service/UserService.java index 0b3efd4..515751c 100644 --- a/src/main/java/com/coderman/api/system/service/UserService.java +++ b/src/main/java/com/coderman/api/system/service/UserService.java @@ -33,7 +33,7 @@ public interface UserService { * @param roles 用户的角色 * @return */ - List findMenuById(List roles); + List findMenuByRoles(List roles); /** * 加载用户菜单 diff --git a/src/main/java/com/coderman/api/system/service/impl/DepartmentServiceImpl.java b/src/main/java/com/coderman/api/system/service/impl/DepartmentServiceImpl.java index a5c684d..967c9a8 100644 --- a/src/main/java/com/coderman/api/system/service/impl/DepartmentServiceImpl.java +++ b/src/main/java/com/coderman/api/system/service/impl/DepartmentServiceImpl.java @@ -1,15 +1,18 @@ package com.coderman.api.system.service.impl; -import com.coderman.api.system.converter.DepartmentConverter; import com.coderman.api.biz.enums.BizUserTypeEnum; -import com.coderman.api.system.mapper.DepartmentMapper; -import com.coderman.api.system.mapper.RoleMapper; -import com.coderman.api.system.mapper.UserMapper; -import com.coderman.api.system.mapper.UserRoleMapper; +import com.coderman.api.common.exception.ServiceException; import com.coderman.api.common.pojo.system.Department; import com.coderman.api.common.pojo.system.Role; import com.coderman.api.common.pojo.system.User; import com.coderman.api.common.pojo.system.UserRole; +import com.coderman.api.system.converter.DepartmentConverter; +import com.coderman.api.system.enums.UserStatusEnum; +import com.coderman.api.system.enums.UserTypeEnum; +import com.coderman.api.system.mapper.DepartmentMapper; +import com.coderman.api.system.mapper.RoleMapper; +import com.coderman.api.system.mapper.UserMapper; +import com.coderman.api.system.mapper.UserRoleMapper; import com.coderman.api.system.service.DepartmentService; import com.coderman.api.system.vo.DeanVO; import com.coderman.api.system.vo.DepartmentVO; @@ -22,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import tk.mybatis.mapper.entity.Example; +import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -72,7 +76,7 @@ public class DepartmentServiceImpl implements DepartmentService { d.setMgrName(user.getUsername()); Example o1 = new Example(User.class); o1.createCriteria().andEqualTo("departmentId",department.getId()) - .andNotEqualTo("type",0); + .andNotEqualTo("type", UserTypeEnum.SYSTEM_ADMIN.getTypeCode()); d.setTotal(userMapper.selectCountByExample(o1)); departmentVOS.add(d); } @@ -107,7 +111,7 @@ public class DepartmentServiceImpl implements DepartmentService { for (Long userId : userIds) { User user = userMapper.selectByPrimaryKey(userId); //所有可用的 - if(user!=null&&user.getStatus()==1){ + if(user!=null&&user.getStatus()== UserStatusEnum.AVAILABLE.getStatusCode()){ DeanVO deanVO = new DeanVO(); deanVO.setName(user.getUsername()); deanVO.setId(user.getId()); @@ -126,6 +130,8 @@ public class DepartmentServiceImpl implements DepartmentService { */ @Override public void add(DepartmentVO departmentVO) { + @NotNull(message = "系主任不能为空") Long mgrId = departmentVO.getMgrId(); + checkMgr(mgrId); Department department = new Department(); BeanUtils.copyProperties(departmentVO,department); department.setCreateTime(new Date()); @@ -133,6 +139,27 @@ public class DepartmentServiceImpl implements DepartmentService { departmentMapper.insert(department); } + /** + * 验证部门主任 + * @param mgrId + */ + private void checkMgr(@NotNull(message = "系主任不能为空") Long mgrId) { + User user = userMapper.selectByPrimaryKey(mgrId); + if (user==null){ + throw new ServiceException("不存在该部门主任"); + } + List deanList = findDeanList(); + boolean isMgr=false; + for (DeanVO deanVO : deanList) { + if(deanVO.getId().equals(user.getId())){ + isMgr=true; + } + } + if(!isMgr){ + throw new ServiceException("不存在该部门主任"); + } + } + /** * 编辑院系 * @param id @@ -141,17 +168,25 @@ public class DepartmentServiceImpl implements DepartmentService { @Override public DepartmentVO edit(Long id) { Department department = departmentMapper.selectByPrimaryKey(id); - DepartmentVO departmentVO = DepartmentConverter.converterToDepartmentVO(department); - return departmentVO; + if(department==null){ + throw new ServiceException("编辑的部门不存在"); + } + return DepartmentConverter.converterToDepartmentVO(department); } /** - * 更新院系 + * 更新部门 * @param id * @param departmentVO */ @Override public void update(Long id, DepartmentVO departmentVO) { + Department dbDepartment = departmentMapper.selectByPrimaryKey(id); + @NotNull(message = "系主任不能为空") Long mgrId = departmentVO.getMgrId(); + if(dbDepartment==null){ + throw new ServiceException("要更新的部门不存在"); + } + checkMgr(mgrId); Department department = new Department(); BeanUtils.copyProperties(departmentVO,department); department.setId(id); @@ -159,8 +194,16 @@ public class DepartmentServiceImpl implements DepartmentService { departmentMapper.updateByPrimaryKeySelective(department); } + /** + * 删除部门信息 + * @param id + */ @Override public void delete(Long id) { + Department department = departmentMapper.selectByPrimaryKey(id); + if(department==null){ + throw new ServiceException("要删除的部门不存在"); + } departmentMapper.deleteByPrimaryKey(id); } diff --git a/src/main/java/com/coderman/api/system/service/impl/LogServiceImpl.java b/src/main/java/com/coderman/api/system/service/impl/LogServiceImpl.java index 48e10ad..898b03f 100644 --- a/src/main/java/com/coderman/api/system/service/impl/LogServiceImpl.java +++ b/src/main/java/com/coderman/api/system/service/impl/LogServiceImpl.java @@ -1,8 +1,9 @@ package com.coderman.api.system.service.impl; -import com.coderman.api.system.mapper.LogMapper; +import com.coderman.api.common.exception.ServiceException; import com.coderman.api.common.pojo.system.Log; import com.coderman.api.common.pojo.system.LoginLog; +import com.coderman.api.system.mapper.LogMapper; import com.coderman.api.system.service.LogService; import com.coderman.api.system.vo.LogVO; import com.coderman.api.system.vo.PageVO; @@ -38,6 +39,7 @@ public class LogServiceImpl implements LogService { logMapper.deleteByPrimaryKey(id); } + @Override public PageVO findLogList(Integer pageNum, Integer pageSize, LogVO logVO) { PageHelper.startPage(pageNum,pageSize); @@ -66,9 +68,17 @@ public class LogServiceImpl implements LogService { return new PageVO<>(info.getTotal(),logVOS); } + /** + * 批量删除 + * @param list + */ @Override public void batchDelete(List list) { for (Long id : list) { + Log log = logMapper.selectByPrimaryKey(id); + if(log==null){ + throw new ServiceException("id="+id+",操作日志不存在"); + } delete(id); } } diff --git a/src/main/java/com/coderman/api/system/service/impl/LoginLogServiceImpl.java b/src/main/java/com/coderman/api/system/service/impl/LoginLogServiceImpl.java index 48682ac..58ad2e5 100644 --- a/src/main/java/com/coderman/api/system/service/impl/LoginLogServiceImpl.java +++ b/src/main/java/com/coderman/api/system/service/impl/LoginLogServiceImpl.java @@ -1,11 +1,12 @@ package com.coderman.api.system.service.impl; -import com.coderman.api.system.bean.ActiveUser; -import com.coderman.api.system.mapper.LoginLogMapper; +import com.coderman.api.common.bean.ActiveUser; +import com.coderman.api.common.exception.ServiceException; import com.coderman.api.common.pojo.system.LoginLog; -import com.coderman.api.system.service.LoginLogService; import com.coderman.api.common.utils.AddressUtil; import com.coderman.api.common.utils.IPUtil; +import com.coderman.api.system.mapper.LoginLogMapper; +import com.coderman.api.system.service.LoginLogService; import com.coderman.api.system.vo.LoginLogVO; import com.coderman.api.system.vo.PageVO; import com.coderman.api.system.vo.UserVO; @@ -18,6 +19,7 @@ import org.apache.shiro.SecurityUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import tk.mybatis.mapper.entity.Example; @@ -80,6 +82,10 @@ public class LoginLogServiceImpl implements LoginLogService { @Override public void batchDelete(List list) { for (Long id : list) { + LoginLog loginLog = loginLogMapper.selectByPrimaryKey(id); + if(loginLog==null){ + throw new ServiceException("id="+id+"登入日志不存在"); + } delete(id); } } @@ -98,6 +104,7 @@ public class LoginLogServiceImpl implements LoginLogService { * 插入登入日志 * @param request */ + @Transactional @Override public void add(HttpServletRequest request) { loginLogMapper.insert(createLoginLog(request)); @@ -128,8 +135,13 @@ public class LoginLogServiceImpl implements LoginLogService { * 删除登入日志 * @param id */ + @Transactional @Override public void delete(Long id) { + LoginLog loginLog = loginLogMapper.selectByPrimaryKey(id); + if(loginLog==null){ + throw new ServiceException("登入日志不存在"); + } loginLogMapper.deleteByPrimaryKey(id); } diff --git a/src/main/java/com/coderman/api/system/service/impl/MenuServiceImpl.java b/src/main/java/com/coderman/api/system/service/impl/MenuServiceImpl.java index b38255d..910b450 100644 --- a/src/main/java/com/coderman/api/system/service/impl/MenuServiceImpl.java +++ b/src/main/java/com/coderman/api/system/service/impl/MenuServiceImpl.java @@ -1,5 +1,6 @@ package com.coderman.api.system.service.impl; +import com.coderman.api.common.exception.ServiceException; import com.coderman.api.system.converter.MenuConverter; import com.coderman.api.system.mapper.MenuMapper; import com.coderman.api.system.mapper.RoleMenuMapper; @@ -63,6 +64,10 @@ public class MenuServiceImpl implements MenuService { @Override public void delete(Long id) { + Menu menu = menuMapper.selectByPrimaryKey(id); + if(menu==null){ + throw new ServiceException("菜单节点不存在"); + } menuMapper.deleteByPrimaryKey(id); } diff --git a/src/main/java/com/coderman/api/system/service/impl/RoleServiceImpl.java b/src/main/java/com/coderman/api/system/service/impl/RoleServiceImpl.java index f6fad9f..6e9178c 100644 --- a/src/main/java/com/coderman/api/system/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/coderman/api/system/service/impl/RoleServiceImpl.java @@ -1,11 +1,12 @@ package com.coderman.api.system.service.impl; -import com.coderman.api.system.converter.RoleConverter; -import com.coderman.api.system.mapper.MenuMapper; -import com.coderman.api.system.mapper.RoleMapper; -import com.coderman.api.system.mapper.RoleMenuMapper; +import com.coderman.api.common.exception.ServiceException; import com.coderman.api.common.pojo.system.Role; import com.coderman.api.common.pojo.system.RoleMenu; +import com.coderman.api.system.converter.RoleConverter; +import com.coderman.api.system.enums.RoleStatusEnum; +import com.coderman.api.system.mapper.RoleMapper; +import com.coderman.api.system.mapper.RoleMenuMapper; import com.coderman.api.system.service.RoleService; import com.coderman.api.system.vo.PageVO; import com.coderman.api.system.vo.RoleVO; @@ -18,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import tk.mybatis.mapper.entity.Example; +import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -36,9 +38,6 @@ public class RoleServiceImpl implements RoleService { @Autowired private RoleMenuMapper roleMenuMapper; - @Autowired - private MenuMapper menuMapper; - /** * 角色列表 * @param pageNum @@ -66,11 +65,18 @@ public class RoleServiceImpl implements RoleService { */ @Override public void add(RoleVO roleVO) { + @NotBlank(message = "角色名必填") String roleName = roleVO.getRoleName(); + Example o = new Example(Role.class); + o.createCriteria().andEqualTo("roleName",roleName); + int i = roleMapper.selectCountByExample(o); + if(i!=0){ + throw new ServiceException("该角色名已被占用"); + } Role role = new Role(); BeanUtils.copyProperties(roleVO,role); role.setCreateTime(new Date()); role.setModifiedTime(new Date()); - role.setStatus(1); + role.setStatus(RoleStatusEnum.AVAILABLE.getStatusCode());//默认启用添加的角色 roleMapper.insert(role); } @@ -81,6 +87,10 @@ public class RoleServiceImpl implements RoleService { @Transactional @Override public void deleteById(Long id) { + Role role = roleMapper.selectByPrimaryKey(id); + if(role==null){ + throw new ServiceException("要删除的角色不存在"); + } roleMapper.deleteByPrimaryKey(id); //删除对应的[角色-菜单]记录 Example o = new Example(RoleMenu.class); @@ -88,27 +98,64 @@ public class RoleServiceImpl implements RoleService { roleMenuMapper.deleteByExample(o); } + /** + * 编辑角色信息 + * @param id + * @return + */ @Override public RoleVO edit(Long id) { Role role = roleMapper.selectByPrimaryKey(id); + if(role==null){ + throw new ServiceException("编辑的角色不存在"); + } RoleVO roleVO = new RoleVO(); BeanUtils.copyProperties(role,roleVO); return roleVO; } + /** + * 更新角色信息 + * @param id + * @param roleVO + */ @Override public void update(Long id, RoleVO roleVO) { + @NotBlank(message = "角色名必填") String roleName = roleVO.getRoleName(); + Role dbRole = roleMapper.selectByPrimaryKey(id); + if(dbRole==null){ + throw new ServiceException("要更新的角色不存在"); + } + Example o = new Example(Role.class); + o.createCriteria().andEqualTo("roleName",roleName); + List roles = roleMapper.selectByExample(o); + if(!CollectionUtils.isEmpty(roles)){ + Role role = roles.get(0); + if(!role.getId().equals(id)){ + throw new ServiceException("该角色名已被占用"); + } + } Role role = new Role(); BeanUtils.copyProperties(roleVO,role); role.setModifiedTime(new Date()); roleMapper.updateByPrimaryKeySelective(role); } + /** + * 角色状态 + * @param id + * @param status + */ @Override public void updateStatus(Long id, Boolean status) { + Role role = roleMapper.selectByPrimaryKey(id); + if(role==null){ + throw new ServiceException("角色不存在"); + } Role t = new Role(); t.setId(id); - t.setStatus(status?0:1); + t.setStatus(status?RoleStatusEnum.DISABLE.getStatusCode(): + RoleStatusEnum.AVAILABLE.getStatusCode()); roleMapper.updateByPrimaryKeySelective(t); } diff --git a/src/main/java/com/coderman/api/system/service/impl/UserServiceImpl.java b/src/main/java/com/coderman/api/system/service/impl/UserServiceImpl.java index 02c00dd..0a41b57 100644 --- a/src/main/java/com/coderman/api/system/service/impl/UserServiceImpl.java +++ b/src/main/java/com/coderman/api/system/service/impl/UserServiceImpl.java @@ -1,5 +1,6 @@ package com.coderman.api.system.service.impl; +import com.coderman.api.common.bean.ActiveUser; import com.coderman.api.common.config.jwt.JWTToken; import com.coderman.api.common.exception.ErrorCodeEnum; import com.coderman.api.common.exception.ServiceException; @@ -7,7 +8,6 @@ import com.coderman.api.common.pojo.system.*; import com.coderman.api.common.utils.JWTUtils; import com.coderman.api.common.utils.MD5Utils; import com.coderman.api.common.utils.MenuTreeBuilder; -import com.coderman.api.system.bean.ActiveUser; import com.coderman.api.system.converter.MenuConverter; import com.coderman.api.system.converter.UserConverter; import com.coderman.api.system.enums.UserStatusEnum; @@ -27,6 +27,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import tk.mybatis.mapper.entity.Example; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.util.*; import java.util.stream.Collectors; @@ -83,9 +85,13 @@ public class UserServiceImpl implements UserService { */ @Override public List findRolesById(Long id) { + User dbUser = userMapper.selectByPrimaryKey(id); + if(dbUser==null){ + throw new ServiceException("该用户不存在"); + } List roles=new ArrayList<>(); UserRole t = new UserRole(); - t.setUserId(id); + t.setUserId(dbUser.getId()); List userRoleList = userRoleMapper.select(t); List rids=new ArrayList<>(); if(!CollectionUtils.isEmpty(userRoleList)){ @@ -105,12 +111,12 @@ public class UserServiceImpl implements UserService { } /** - * 查询用户的权限 + * 查询权限 * @param roles 用户的角色 * @return */ @Override - public List findMenuById(List roles) { + public List findMenuByRoles(List roles) { List menus=new ArrayList<>(); if(!CollectionUtils.isEmpty(roles)){ Set menuIds=new HashSet<>();//存放用户的菜单id @@ -208,6 +214,10 @@ public class UserServiceImpl implements UserService { @Transactional @Override public void deleteById(Long id) { + User user = userMapper.selectByPrimaryKey(id); + if(user==null){ + throw new ServiceException("要删除的用户不存在"); + } userMapper.deleteByPrimaryKey(id); //删除对应[用户-角色]记录 Example o = new Example(UserRole.class); @@ -223,6 +233,9 @@ public class UserServiceImpl implements UserService { @Override public void updateStatus(Long id, Boolean status) { User dbUser = userMapper.selectByPrimaryKey(id); + if(dbUser==null){ + throw new ServiceException("要更新状态的用户不存在"); + } ActiveUser activeUser= (ActiveUser) SecurityUtils.getSubject().getPrincipal(); if(dbUser.getId().equals(activeUser.getUser().getId())){ throw new ServiceException(ErrorCodeEnum.DoNotAllowToDisableTheCurrentUser); @@ -239,8 +252,21 @@ public class UserServiceImpl implements UserService { * 添加用户 * @param userVO */ + @Transactional @Override public void add(UserVO userVO) { + @NotBlank(message = "用户名不能为空") String username = userVO.getUsername(); + @NotNull(message = "部门id不能为空") Long departmentId = userVO.getDepartmentId(); + Example o = new Example(User.class); + o.createCriteria().andEqualTo("username",username); + int i = userMapper.selectCountByExample(o); + if(i!=0){ + throw new ServiceException("该用户名已被占用"); + } + Department department = departmentMapper.selectByPrimaryKey(departmentId); + if(department==null){ + throw new ServiceException("该部门不存在"); + } User user = new User(); BeanUtils.copyProperties(userVO,user); String salt=UUID.randomUUID().toString().substring(0,32); @@ -259,12 +285,31 @@ public class UserServiceImpl implements UserService { * @param id * @param userVO */ + @Transactional @Override public void update(Long id,UserEditVO userVO) { + User dbUser = userMapper.selectByPrimaryKey(id); + @NotBlank(message = "用户名不能为空") String username = userVO.getUsername(); + @NotNull(message = "部门不能为空") Long departmentId = userVO.getDepartmentId(); + if(dbUser==null){ + throw new ServiceException("要删除的用户不存在"); + } + Department department = departmentMapper.selectByPrimaryKey(departmentId); + if(department==null){ + throw new ServiceException("该部门不存在"); + } + Example o = new Example(User.class); + o.createCriteria().andEqualTo("username",username); + List users = userMapper.selectByExample(o); + if(!CollectionUtils.isEmpty(users)){ + if(!users.get(0).getId().equals(id)){ + throw new ServiceException("该用户名已被占用"); + } + } User user = new User(); BeanUtils.copyProperties(userVO,user); user.setModifiedTime(new Date()); - user.setId(id); + user.setId(dbUser.getId()); userMapper.updateByPrimaryKeySelective(user); } @@ -273,9 +318,13 @@ public class UserServiceImpl implements UserService { * @param id * @return */ + @Transactional @Override public UserEditVO edit(Long id) { User user = userMapper.selectByPrimaryKey(id); + if(user==null){ + throw new ServiceException("要编辑的用户不存在"); + } UserEditVO userEditVO = new UserEditVO(); BeanUtils.copyProperties(user,userEditVO); Department department = departmentMapper.selectByPrimaryKey(user.getDepartmentId()); @@ -290,15 +339,23 @@ public class UserServiceImpl implements UserService { * @param id 用户id * @return */ + @Transactional @Override public List roles(Long id) { + User user = userMapper.selectByPrimaryKey(id); + if(user==null){ + throw new ServiceException("该用户不存在"); + } Example o = new Example(UserRole.class); - o.createCriteria().andEqualTo("userId",id); + o.createCriteria().andEqualTo("userId",user.getId()); List userRoleList = userRoleMapper.selectByExample(o); List roleIds=new ArrayList<>(); if(!CollectionUtils.isEmpty(userRoleList)){ for (UserRole userRole : userRoleList) { - roleIds.add(userRole.getRoleId()); + Role role = roleMapper.selectByPrimaryKey(userRole.getRoleId()); + if(role!=null){ + roleIds.add(role.getId()); + } } } return roleIds; @@ -313,12 +370,25 @@ public class UserServiceImpl implements UserService { @Transactional public void assignRoles(Long id, Long[] rids) { //删除之前用户的所有角色 + User user = userMapper.selectByPrimaryKey(id); + if(user==null){ + throw new ServiceException("用户不存在"); + } + //删除之前分配的 Example o = new Example(UserRole.class); - o.createCriteria().andEqualTo("userId",id); + o.createCriteria().andEqualTo("userId",user.getId()); userRoleMapper.deleteByExample(o); //增加现在分配的 if(rids.length>0){ for (Long rid : rids) { + Role role = roleMapper.selectByPrimaryKey(rid); + if(role==null){ + throw new ServiceException("roleId="+rid+",该角色不存在"); + } + //判断角色状态 + if(role.getStatus()==0){ + throw new ServiceException("roleName="+role.getRoleName()+",该角色已禁用"); + } UserRole userRole = new UserRole(); userRole.setUserId(id); userRole.setRoleId(rid); diff --git a/src/main/java/com/coderman/api/system/vo/UserVO.java b/src/main/java/com/coderman/api/system/vo/UserVO.java index 094d36b..4ae49a6 100644 --- a/src/main/java/com/coderman/api/system/vo/UserVO.java +++ b/src/main/java/com/coderman/api/system/vo/UserVO.java @@ -48,6 +48,7 @@ public class UserVO{ private String departmentName; + @NotNull(message = "部门id不能为空") private Long departmentId; }