Browse Source

代码优化

woody 1 year ago
parent
commit
d05862f683

+ 6 - 5
pom.xml

@@ -18,6 +18,7 @@
     <properties>
         <uc-api.version>1.0.0-SNAPSHOT</uc-api.version>
         <vehicle-api.version>1.0.0-SNAPSHOT</vehicle-api.version>
+        <framework-dubbo.version>1.0.0-RELEASE</framework-dubbo.version>
         <framework-redis.version>1.0.0-RELEASE</framework-redis.version>
         <framework-oauth.version>1.0.0-RELEASE</framework-oauth.version>
         <framework-security.version>1.0.0-RELEASE</framework-security.version>
@@ -28,31 +29,31 @@
             <groupId>com.chelvc.cloud</groupId>
             <artifactId>uc-api</artifactId>
             <version>${uc-api.version}</version>
-            <optional>true</optional>
         </dependency>
         <dependency>
             <groupId>com.chelvc.cloud</groupId>
             <artifactId>vehicle-api</artifactId>
             <version>${vehicle-api.version}</version>
-            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>com.chelvc.framework</groupId>
+            <artifactId>framework-dubbo</artifactId>
+            <version>${framework-dubbo.version}</version>
         </dependency>
         <dependency>
             <groupId>com.chelvc.framework</groupId>
             <artifactId>framework-redis</artifactId>
             <version>${framework-redis.version}</version>
-            <optional>true</optional>
         </dependency>
         <dependency>
             <groupId>com.chelvc.framework</groupId>
             <artifactId>framework-oauth</artifactId>
             <version>${framework-oauth.version}</version>
-            <optional>true</optional>
         </dependency>
         <dependency>
             <groupId>com.chelvc.framework</groupId>
             <artifactId>framework-security</artifactId>
             <version>${framework-security.version}</version>
-            <optional>true</optional>
         </dependency>
     </dependencies>
 </project>

+ 3 - 3
src/main/java/com/chelvc/cloud/admin/controller/CategoryController.java

@@ -7,8 +7,8 @@ import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
 import com.chelvc.cloud.vehicle.api.param.CategoryModifyParam;
 import com.chelvc.cloud.vehicle.api.param.CategoryPagingParam;
 import com.chelvc.cloud.vehicle.api.service.CategoryService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.model.Pagination;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.common.model.Pagination;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
  **/
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class CategoryController {
     @DubboReference

+ 5 - 7
src/main/java/com/chelvc/cloud/admin/controller/ClientController.java

@@ -7,9 +7,9 @@ import com.chelvc.cloud.uc.api.dto.ClientDTO;
 import com.chelvc.cloud.uc.api.param.ClientModifyParam;
 import com.chelvc.cloud.uc.api.param.ClientPagingParam;
 import com.chelvc.cloud.uc.api.service.ClientService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.model.Pagination;
-import com.chelvc.framework.base.util.ErrorUtils;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.util.ResourceUtils;
+import com.chelvc.framework.common.model.Pagination;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class ClientController {
     @DubboReference
@@ -65,9 +65,7 @@ public class ClientController {
      */
     @GetMapping("/client/{id}")
     public ClientDTO getClient(@PathVariable("id") @Min(value = 1, message = "客户端主键不能小于1") Long id) {
-        ClientDTO client = this.clientService.getClient(id);
-        ErrorUtils.requireResource(client, "客户端不存在");
-        return client;
+        return ResourceUtils.required(this.clientService.getClient(id), "客户端不存在");
     }
 
     /**

+ 4 - 6
src/main/java/com/chelvc/cloud/admin/controller/DepartmentController.java

@@ -8,8 +8,8 @@ import com.chelvc.cloud.uc.api.dto.DepartmentDTO;
 import com.chelvc.cloud.uc.api.param.DepartmentModifyParam;
 import com.chelvc.cloud.uc.api.param.DepartmentQueryParam;
 import com.chelvc.cloud.uc.api.service.DepartmentService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.util.ErrorUtils;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.util.ResourceUtils;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class DepartmentController {
     @DubboReference
@@ -65,9 +65,7 @@ public class DepartmentController {
      */
     @GetMapping("/department/{id}")
     public DepartmentDTO getDepartment(@PathVariable("id") @Min(value = 1, message = "部门主键不能小于1") Long id) {
-        DepartmentDTO department = this.departmentService.getDepartment(id);
-        ErrorUtils.requireResource(department, "部门不存在");
-        return department;
+        return ResourceUtils.required(this.departmentService.getDepartment(id), "部门不存在");
     }
 
     /**

+ 5 - 33
src/main/java/com/chelvc/cloud/admin/controller/EmployeeController.java

@@ -9,13 +9,10 @@ import com.chelvc.cloud.uc.api.dto.EmployeeDTO;
 import com.chelvc.cloud.uc.api.dto.EmployeeDetailDTO;
 import com.chelvc.cloud.uc.api.param.EmployeeModifyParam;
 import com.chelvc.cloud.uc.api.param.EmployeePagingParam;
-import com.chelvc.cloud.uc.api.param.PasswordResetParam;
-import com.chelvc.cloud.uc.api.param.PasswordUpdateParam;
 import com.chelvc.cloud.uc.api.service.EmployeeService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.context.SessionContextHolder;
-import com.chelvc.framework.base.model.Pagination;
-import com.chelvc.framework.base.util.ErrorUtils;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.util.ResourceUtils;
+import com.chelvc.framework.common.model.Pagination;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -34,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class EmployeeController {
     @DubboReference
@@ -63,29 +60,6 @@ public class EmployeeController {
         this.employeeService.updateEmployee(id, param);
     }
 
-    /**
-     * 需改当前员工密码
-     *
-     * @param param 修改参数
-     */
-    @PutMapping("/employee/mine/password")
-    public void updateMinePassword(@RequestBody @Valid PasswordUpdateParam param) {
-        Long id = SessionContextHolder.getSession().getId();
-        this.employeeService.updateEmployeePassword(id, param);
-    }
-
-    /**
-     * 重置员工密码
-     *
-     * @param id    员工主键
-     * @param param 修改参数
-     */
-    @PutMapping("/employee/{id}/password")
-    public void updateEmployeePassword(@PathVariable("id") @Min(value = 1, message = "员工主键不能小于1") Long id,
-                                       @RequestBody @Valid PasswordResetParam param) {
-        this.employeeService.resetEmployeePassword(id, param);
-    }
-
     /**
      * 获取当前员工个人信息
      *
@@ -105,9 +79,7 @@ public class EmployeeController {
      */
     @GetMapping("/employee/{id}")
     public EmployeeDTO getEmployee(@PathVariable("id") @Min(value = 1, message = "员工主键不能小于1") Long id) {
-        EmployeeDTO employee = this.employeeService.getEmployee(id);
-        ErrorUtils.requireResource(employee, "员工不存在");
-        return employee;
+        return ResourceUtils.required(this.employeeService.getEmployee(id), "员工不存在");
     }
 
     /**

+ 4 - 6
src/main/java/com/chelvc/cloud/admin/controller/MenuController.java

@@ -8,8 +8,8 @@ import com.chelvc.cloud.uc.api.dto.MenuDTO;
 import com.chelvc.cloud.uc.api.param.MenuModifyParam;
 import com.chelvc.cloud.uc.api.param.MenuQueryParam;
 import com.chelvc.cloud.uc.api.service.MenuService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.util.ErrorUtils;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.util.ResourceUtils;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class MenuController {
     @DubboReference
@@ -65,9 +65,7 @@ public class MenuController {
      */
     @GetMapping("/menu/{id}")
     public MenuDTO getMenu(@PathVariable("id") @Min(value = 1, message = "菜单主键不能小于1") Long id) {
-        MenuDTO menu = this.menuService.getMenu(id);
-        ErrorUtils.requireResource(menu, "菜单不存在");
-        return menu;
+        return ResourceUtils.required(this.menuService.getMenu(id), "菜单不存在");
     }
 
     /**

+ 5 - 7
src/main/java/com/chelvc/cloud/admin/controller/ResourceController.java

@@ -7,9 +7,9 @@ import com.chelvc.cloud.uc.api.dto.ResourceDTO;
 import com.chelvc.cloud.uc.api.param.ResourceModifyParam;
 import com.chelvc.cloud.uc.api.param.ResourcePagingParam;
 import com.chelvc.cloud.uc.api.service.ResourceService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.model.Pagination;
-import com.chelvc.framework.base.util.ErrorUtils;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.util.ResourceUtils;
+import com.chelvc.framework.common.model.Pagination;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class ResourceController {
     @DubboReference
@@ -65,9 +65,7 @@ public class ResourceController {
      */
     @GetMapping("/resource/{id}")
     public ResourceDTO getResource(@PathVariable("id") @Min(value = 1, message = "资源主键不能小于1") Long id) {
-        ResourceDTO resource = this.resourceService.getResource(id);
-        ErrorUtils.requireResource(resource, "资源不存在");
-        return resource;
+        return ResourceUtils.required(this.resourceService.getResource(id), "资源不存在");
     }
 
     /**

+ 6 - 10
src/main/java/com/chelvc/cloud/admin/controller/RoleController.java

@@ -9,9 +9,9 @@ import com.chelvc.cloud.uc.api.param.PermissionModifyParam;
 import com.chelvc.cloud.uc.api.param.RoleModifyParam;
 import com.chelvc.cloud.uc.api.param.RolePagingParam;
 import com.chelvc.cloud.uc.api.service.RoleService;
-import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.model.Pagination;
-import com.chelvc.framework.base.util.ErrorUtils;
+import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.util.ResourceUtils;
+import com.chelvc.framework.common.model.Pagination;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Validated
 @RestController
-@UnifiedResponseBody
+@ResponseWrapping
 @PreAuthorize("isBusiness('EMPLOYEE')")
 public class RoleController {
     @DubboReference
@@ -79,9 +79,7 @@ public class RoleController {
      */
     @GetMapping("/role/{id}")
     public RoleDTO getRole(@PathVariable("id") @Min(value = 1, message = "角色主键不能小于1") Long id) {
-        RoleDTO role = this.roleService.getRole(id);
-        ErrorUtils.requireResource(role, "角色不存在");
-        return role;
+        return ResourceUtils.required(this.roleService.getRole(id), "角色不存在");
     }
 
     /**
@@ -92,9 +90,7 @@ public class RoleController {
      */
     @GetMapping("/role/{id}/detail")
     public RoleDetailDTO getRoleDetail(@PathVariable("id") @Min(value = 1, message = "角色主键不能小于1") Long id) {
-        RoleDetailDTO detail = this.roleService.getRoleDetail(id);
-        ErrorUtils.requireResource(detail, "角色不存在");
-        return detail;
+        return ResourceUtils.required(this.roleService.getRoleDetail(id), "角色不存在");
     }
 
     /**

+ 1 - 1
src/main/java/com/chelvc/cloud/admin/vo/EmployeePersonalVO.java

@@ -3,7 +3,7 @@ package com.chelvc.cloud.admin.vo;
 import java.io.Serializable;
 import java.util.List;
 
-import com.chelvc.framework.base.model.Tree;
+import com.chelvc.framework.common.model.Tree;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.EqualsAndHashCode;

+ 8 - 1
src/main/resources/logback-spring.xml

@@ -4,6 +4,8 @@
 
 	<springProperty name="LOG_PATH" source="logging.path" defaultValue="./"/>
 
+	<turboFilter class="com.chelvc.framework.base.interceptor.DynamicLoggingInterceptor"/>
+
 	<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
 		<encoder>
 			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger: %msg%n</pattern>
@@ -24,10 +26,15 @@
 		</rollingPolicy>
 	</appender>
 
-	<logger name="RocketmqClient" level="error"/>
+	<appender name="ASYNC_FILE_APPENDER" class="ch.qos.logback.classic.AsyncAppender">
+		<queueSize>256</queueSize>
+		<discardingThreshold>0</discardingThreshold>
+		<appender-ref ref="FILE_APPENDER"/>
+	</appender>
 
 	<root level="info">
 		<appender-ref ref="CONSOLE_APPENDER"/>
 		<appender-ref ref="FILE_APPENDER"/>
+		<appender-ref ref="ASYNC_FILE_APPENDER"/>
 	</root>
 </configuration>