From ab795dcf9b4783682fbb85c37d5c20b2b9006a86 Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: 星期三, 09 七月 2025 09:49:33 +0800
Subject: [PATCH] 优化改造sql
---
multi-system/src/main/java/com/gkhy/exam/system/mapper/SysDeptMapper.java | 5 ++
multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java | 12 +++---
multi-system/src/main/resources/mapper/system/SysDeptMapper.xml | 64 ++++++++++++++++++++++++++++++-
multi-system/src/main/java/com/gkhy/exam/system/service/ISysDeptService.java | 3 +
multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java | 23 ++++++++---
multi-system/src/main/java/com/gkhy/exam/system/domain/req/SysDeptPageReq.java | 10 +++++
6 files changed, 100 insertions(+), 17 deletions(-)
diff --git a/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java b/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java
index 868f6b3..45f5d0c 100644
--- a/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java
+++ b/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java
@@ -7,6 +7,7 @@
import com.gkhy.exam.common.domain.TreeSelect;
import com.gkhy.exam.common.domain.entity.SysDept;
import com.gkhy.exam.system.domain.SysFunctionalDistribution;
+import com.gkhy.exam.system.domain.req.SysDeptPageReq;
import com.gkhy.exam.system.domain.vo.DeptVo;
import com.gkhy.exam.system.domain.vo.FunctionalDistributionVo;
import com.gkhy.exam.system.domain.vo.SysDeptResponsibilityReqVo;
@@ -48,21 +49,29 @@
// @PreAuthorize("hasAnyAuthority('system:dept:list')")
@GetMapping("/list")
@ApiOperation(value = "获取部门列表")
- @ApiImplicitParams({
- @ApiImplicitParam(paramType = "query", name = "pageNum", dataType = "int", required = false, value = "当前页,默认1"),
- @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "int", required = false, value = "每页数目,默认10"),
- })
public CommonResult list(SysDept dept)
{
List<DeptVo> depts = deptService.selectDeptList(dept);
return CommonResult.success(depts);
}
- @GetMapping("/pageList")
- @ApiOperation(value = "获取部门列表分页")
- public CommonResult pageList(SysDept dept)
+ @GetMapping("/getOutDeptList")
+ @ApiOperation(value = "获取部门列表简化版本")
+ public CommonResult getOutDeptList(SysDept dept)
{
+ List<SysDept> outDeptList = deptService.getOutDeptList(dept);
+ return CommonResult.success(outDeptList);
+ }
+
+ @GetMapping("/pageList")
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", name = "pageNum", dataType = "int", required = false, value = "当前页,默认1"),
+ @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "int", required = false, value = "每页数目,默认10"),
+ })
+ @ApiOperation(value = "获取部门列表分页")
+ public CommonResult pageList(SysDeptPageReq dept)
+ {
return CommonResult.success(deptService.selectDeptPageList(dept));
}
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/domain/req/SysDeptPageReq.java b/multi-system/src/main/java/com/gkhy/exam/system/domain/req/SysDeptPageReq.java
new file mode 100644
index 0000000..277e1db
--- /dev/null
+++ b/multi-system/src/main/java/com/gkhy/exam/system/domain/req/SysDeptPageReq.java
@@ -0,0 +1,10 @@
+package com.gkhy.exam.system.domain.req;
+
+import com.gkhy.exam.common.domain.entity.SysDept;
+import lombok.Data;
+
+@Data
+public class SysDeptPageReq extends SysDept {
+ private Integer pageNum;
+ private Integer pageSize;
+}
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/mapper/SysDeptMapper.java b/multi-system/src/main/java/com/gkhy/exam/system/mapper/SysDeptMapper.java
index 9f2fee6..dbbfbf4 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/mapper/SysDeptMapper.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/mapper/SysDeptMapper.java
@@ -3,6 +3,7 @@
import com.gkhy.exam.common.domain.entity.SysDept;
import com.gkhy.exam.system.domain.SysDeptManage;
+import com.gkhy.exam.system.domain.req.SysDeptPageReq;
import com.gkhy.exam.system.domain.vo.DeptVo;
import org.apache.ibatis.annotations.Param;
@@ -23,6 +24,10 @@
*/
public List<DeptVo> selectDeptList(SysDept dept);
+
+ public List<DeptVo> selectDeptPageList(SysDeptPageReq dept);
+
+
int selectDeptListCount(SysDept dept);
/**
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/service/ISysDeptService.java b/multi-system/src/main/java/com/gkhy/exam/system/service/ISysDeptService.java
index 5a2f52d..5563f66 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/service/ISysDeptService.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/service/ISysDeptService.java
@@ -6,6 +6,7 @@
import com.gkhy.exam.common.domain.TreeSelect;
import com.gkhy.exam.common.domain.entity.SysDept;
import com.gkhy.exam.system.domain.SysFunctionalDistribution;
+import com.gkhy.exam.system.domain.req.SysDeptPageReq;
import com.gkhy.exam.system.domain.vo.*;
import java.util.List;
@@ -18,7 +19,7 @@
public interface ISysDeptService
{
- CommonPage selectDeptPageList(SysDept req);
+ CommonPage selectDeptPageList(SysDeptPageReq req);
/**
* 查询部门管理数据
*
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java
index 6b941f5..8f934d1 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java
@@ -19,6 +19,7 @@
import com.gkhy.exam.system.domain.SysDeptManage;
import com.gkhy.exam.system.domain.SysDeptResponsibility;
import com.gkhy.exam.system.domain.SysFunctionalDistribution;
+import com.gkhy.exam.system.domain.req.SysDeptPageReq;
import com.gkhy.exam.system.domain.vo.*;
import com.gkhy.exam.system.mapper.SysDeptMapper;
import com.gkhy.exam.system.mapper.SysDeptResponsibilityMapper;
@@ -60,9 +61,11 @@
,"10.2", "10.3"};
@Override
- public CommonPage selectDeptPageList(SysDept req) {
+ public CommonPage selectDeptPageList(SysDeptPageReq req) {
+
PageUtils.startPage();
- List<DeptVo> deptVos = deptMapper.selectDeptList(req);
+
+ List<DeptVo> deptVos = deptMapper.selectDeptPageList(req);
if (ObjectUtil.isNotEmpty(deptVos)){
for (DeptVo deptVo : deptVos) {
List<CaluseVO1> caluseVO1List = deptVo.getCaluseVO1List();
@@ -72,11 +75,8 @@
}
}
- int i = deptMapper.selectDeptListCount(req);
+
CommonPage<DeptVo> deptVoCommonPage = CommonPage.restPage(deptVos);
- int totalPage = (int) Math.ceil((double) i / deptVoCommonPage.getPageSize());
- deptVoCommonPage.setTotalPage(totalPage);
- deptVoCommonPage.setTotal(Long.valueOf( i));
return deptVoCommonPage;
}
diff --git a/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index 02d875f..a3c6567 100644
--- a/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -47,10 +47,12 @@
d.responsibilities,d.dept_type,d.respons_type
from sys_dept d
</sql>
+
+
<select id="selectDeptList" parameterType="com.gkhy.exam.common.domain.entity.SysDept" resultMap="DeptVoResult">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader_user_id, d.company_id, d.status, d.del_flag, d.create_by, d.create_time,d.person_num,d.internal_auditors,
- d.responsibilities,d.dept_type,d.respons_type,u.name as leader_name,d2.dept_name as parent_name, dr.content ,dr.clause_num,dr.id as data_id,dr.clause_id,
+ d.order_num,d.responsibilities,d.dept_type,d.respons_type,u.name as leader_name,d2.dept_name as parent_name, dr.content ,dr.clause_num,dr.id as data_id,dr.clause_id,
sm.sub_dept_id ,sm2.dept_name sub_dept_name,sm.dept_id as p_dept_id
from sys_dept d
left join sys_user u on d.leader_user_id = u.id
@@ -80,8 +82,64 @@
<if test="status != null and status != ''">
AND d.status = #{status}
</if>
- order by d.order_num
+ order by d.order_num desc
</select>
+ <resultMap type="com.gkhy.exam.system.domain.vo.DeptVo" id="DeptVoPageResult" extends="SysDeptResult">
+ <collection property="caluseVO1List" ofType="com.gkhy.exam.system.domain.vo.CaluseVO1" column="deptId = dept_id" select="getReponseData">
+ <result property="clauseNum" column="clause_num" />
+ <result property="content" column="content" />
+ <result property="clauseId" column="clause_id" />
+ <result property="id" column="id" />
+ </collection>
+ <collection ofType="com.gkhy.exam.system.domain.vo.SysDeptManageVo" property="sysDeptManageVoList" column="deptId = dept_id" select="getSysDeptManageVo">
+ <result property="subDeptId" column="sub_dept_id" />
+ <result property="subDeptName" column="sub_dept_name" />
+ <result property="deptId" column="dept_id" />
+
+ </collection>
+ </resultMap>
+
+ <select id="selectDeptPageList" parameterType="com.gkhy.exam.system.domain.req.SysDeptPageReq" resultMap="DeptVoPageResult">
+ select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader_user_id, d.company_id, d.status, d.del_flag, d.create_by, d.create_time,d.person_num,d.internal_auditors,
+ d.order_num,d.responsibilities,d.dept_type,d.respons_type,u.name as leader_name,d2.dept_name as parent_name
+ from sys_dept d
+ left join sys_user u on d.leader_user_id = u.id
+ left join sys_dept d2 on d.parent_id = d2.dept_id
+ where d.del_flag = '0'
+ <if test="companyId != null and companyId != 0">
+ AND d.company_id = #{companyId}
+ </if>
+ <if test="deptType != null and deptType != '' " >
+ AND d.dept_type = #{deptType}
+ </if>
+ <if test="responsType != null and responsType != '' " >
+ AND d.respons_type = #{responsType}
+ </if>
+ <if test="deptId != null and deptId != 0">
+ AND d.dept_id = #{deptId}
+ </if>
+ <if test="parentId != null and parentId != 0">
+ AND d.parent_id = #{parentId}
+ </if>
+ <if test="deptName != null and deptName != ''">
+ AND d.dept_name like concat('%', #{deptName}, '%')
+ </if>
+ <if test="status != null and status != ''">
+ AND d.status = #{status}
+ </if>
+ order by d.order_num desc
+ </select>
+
+ <select id="getReponseData" resultType="com.gkhy.exam.system.domain.vo.CaluseVO1">
+ select dr.content ,dr.clause_num,dr.id ,dr.clause_id from sys_dept_responsibility dr where dr.dept_id = #{deptId} and dr.del_flag = '0' and data_type = 2
+ </select>
+
+
+ <select id="getSysDeptManageVo" resultType="com.gkhy.exam.system.domain.vo.SysDeptManageVo">
+ select sm.sub_dept_id ,sm2.dept_name as sub_dept_name,sm.dept_id from sys_dept_manage sm
+ left join sys_dept sm2 on sm2.dept_id = sm.sub_dept_id
+ where sm.dept_id = #{deptId}
+ </select>
<select id="selectDeptListCount" parameterType="com.gkhy.exam.common.domain.entity.SysDept" resultType="int">
@@ -131,7 +189,7 @@
<if test="status != null and status != ''">
AND status = #{status}
</if>
- order by d.order_num
+ order by d.order_num desc
</select>
--
Gitblit v1.9.2