From 2fa2fb8cf2df59d46a6a52a462a09e59621c6d5b Mon Sep 17 00:00:00 2001
From: lin <sbla5888@163.com>
Date: Mon, 01 Apr 2024 14:57:05 +0800
Subject: [PATCH] 消防整改记录统计优化

---
 src/main/java/org/springblade/modules/task/service/impl/TaskPlaceRectificationServiceImpl.java |   45 ++++++++------
 src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.java            |   11 +++
 src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.xml             |   77 +++++++++++++++++++++++--
 3 files changed, 107 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.java b/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.java
index 39aa8e5..3fa919d 100644
--- a/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.java
+++ b/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.java
@@ -77,5 +77,14 @@
 											 @Param("gridCodeList") List<String> gridCodeList,
 											 @Param("nineTypeList") List<String> nineTypeList);
 
-    Integer getCount(String neiCode, int i, Long userId);
+	/**
+	 * 统计消防整改记录
+	 * @param taskPlaceRectificationDTO
+	 * @param regionChildCodesList
+	 * @param isAdministrator
+	 * @return
+	 */
+    Integer getCount(@Param("taskPalce") TaskPlaceRectificationDTO taskPlaceRectificationDTO,
+					 @Param("regionChildCodesList") List<String> regionChildCodesList,
+					 @Param("isAdministrator") Integer isAdministrator);
 }
diff --git a/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.xml b/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.xml
index a2f62ba..6d14cbd 100644
--- a/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.xml
+++ b/src/main/java/org/springblade/modules/task/mapper/TaskPlaceRectificationMapper.xml
@@ -613,12 +613,77 @@
     </select>
 
     <select id="getCount" resultType="java.lang.Integer">
-        SELECT count(1)
-        FROM jczz_task_place_rectification jtpr
-                 LEFT JOIN jczz_place jp ON jp.house_code = jtpr.house_code
-        WHERE jp.jw_grid_code IN
-              (SELECT jpag.jw_grid_code FROM jczz_police_affairs_grid jpag WHERE jpag.police_user_id like concat('%',${userId},'%'))
-          AND jtpr.`status` = 1
+
+        SELECT   count(1)
+        FROM
+        jczz_task_place_rectification jtpr
+        LEFT JOIN jczz_place jp ON jtpr.house_code = jp.house_code
+        LEFT JOIN jczz_grid jg ON jg.grid_code = jp.grid_code
+        LEFT JOIN blade_region br ON br.`code` = jg.community_code
+        LEFT JOIN jczz_place_ext jpe ON jpe.place_id = jp.id
+        LEFT JOIN blade_user bu ON bu.id = jtpr.create_user
+        LEFT JOIN jczz_police_affairs_grid jpag on jp.jw_grid_code= jpag.jw_grid_code
+        <where>
+            <if test="taskPalce.communityCode != null ">and jg.community_code = #{taskPalce.communityCode}</if>
+            <if test="taskPalce.status != null ">and jtpr.status = #{taskPalce.status}</if>
+            <if test="isAdministrator==2">
+                <choose>
+                    <when test="taskPalce.roleName != null and taskPalce.roleName != ''">
+                        <if test="taskPalce.roleName=='wgy'">
+                            <choose>
+                                <when test="gridCodeList !=null and gridCodeList.size()>0">
+                                    and jp.grid_code in
+                                    <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
+                                        #{code}
+                                    </foreach>
+                                </when>
+                                <otherwise>
+                                    and jp.grid_code in ('')
+                                </otherwise>
+                            </choose>
+                        </if>
+                        <if test="taskPalce.roleName=='mj'">
+                            <choose>
+                                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
+                                    and br.village_code in
+                                    <foreach collection="regionChildCodesList" item="code" open="(" close=")"
+                                             separator=",">
+                                        #{code}
+                                    </foreach>
+                                </when>
+                                <otherwise>
+                                    and br.village_code in ('')
+                                </otherwise>
+                            </choose>
+                        </if>
+                    </when>
+                    <otherwise>
+                        <choose>
+                            <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
+                                and
+                                (
+                                jg.grid_code in
+                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
+                                    #{code}
+                                </foreach>
+                                or
+                                jpag.community_code in
+                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
+                                    #{code}
+                                </foreach>
+                                )
+                            </when>
+                            <otherwise>
+                                and
+                                (
+                                jg.grid_code in ('') or jpag.community_code in ('')
+                                )
+                            </otherwise>
+                        </choose>
+                    </otherwise>
+                </choose>
+            </if>
+        </where>
     </select>
 
 
diff --git a/src/main/java/org/springblade/modules/task/service/impl/TaskPlaceRectificationServiceImpl.java b/src/main/java/org/springblade/modules/task/service/impl/TaskPlaceRectificationServiceImpl.java
index bb104d4..76ed7bf 100644
--- a/src/main/java/org/springblade/modules/task/service/impl/TaskPlaceRectificationServiceImpl.java
+++ b/src/main/java/org/springblade/modules/task/service/impl/TaskPlaceRectificationServiceImpl.java
@@ -107,20 +107,20 @@
 		// 数据过滤 todo
 		String roleName = SpringUtils.getRequestParam("roleName");
 		String communityCode = SpringUtils.getRequestParam("communityCode");
-		if (!Strings.isBlank(communityCode)){
+		if (!Strings.isBlank(communityCode)) {
 			// 校验社区编号是否合规
-			if(null!=SpringUtils.getBean(IRegionService.class).getById(communityCode)) {
+			if (null != SpringUtils.getBean(IRegionService.class).getById(communityCode)) {
 				taskPlaceRectificationDTO.setCommunityCode(communityCode);
 			}
 		}
 		List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
-		Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2;
+		Integer isAdministrator = AuthUtil.isAdministrator() == true ? 1 : 2;
 		// 网格编号集合
 		List<String> gridCodeList = new ArrayList<>();
 		// 民警角色
-		if (!Strings.isBlank(roleName)){
+		if (!Strings.isBlank(roleName)) {
 			taskPlaceRectificationDTO.setRoleName(roleName);
-			if(roleName.equals("mj")) {
+			if (roleName.equals("mj")) {
 				regionChildCodesList = SpringUtil.getBean(IPoliceAffairsGridService.class).getCommunityCodeListByUserId(AuthUtil.getUserId());
 			}
 			if (roleName.equals("wgy")) {
@@ -128,16 +128,16 @@
 			}
 		}
 		List<String> strings = new ArrayList<>();
-		if (null!=taskPlaceRectificationDTO.getNineType()){
+		if (null != taskPlaceRectificationDTO.getNineType()) {
 			QueryWrapper<DictBiz> queryWrapper = new QueryWrapper<>();
-			queryWrapper.eq("is_deleted",0).eq("dict_key",taskPlaceRectificationDTO.getNineType()).eq("code","nineType");
+			queryWrapper.eq("is_deleted", 0).eq("dict_key", taskPlaceRectificationDTO.getNineType()).eq("code", "nineType");
 			// 先查询当前
 			DictBiz one = dictBizService.getOne(queryWrapper);
 			// 查询本身和子集的key
 			List<DictBiz> list = dictBizService.getList("nineType", one.getId());
-			if (list.size()==0){
+			if (list.size() == 0) {
 				strings.add(taskPlaceRectificationDTO.getNineType());
-			}else {
+			} else {
 				strings = list.stream().map(DictBiz::getDictKey).collect(Collectors.toList());
 			}
 		}
@@ -218,20 +218,20 @@
 		// 数据过滤 todo
 		String roleName = SpringUtils.getRequestParam("roleName");
 		String communityCode = SpringUtils.getRequestParam("communityCode");
-		if (!Strings.isBlank(communityCode)){
+		if (!Strings.isBlank(communityCode)) {
 			// 校验社区编号是否合规
-			if(null!=SpringUtils.getBean(IRegionService.class).getById(communityCode)) {
+			if (null != SpringUtils.getBean(IRegionService.class).getById(communityCode)) {
 				taskPlaceRectificationVO.setCommunityCode(communityCode);
 			}
 		}
 		List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
-		Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2;
+		Integer isAdministrator = AuthUtil.isAdministrator() == true ? 1 : 2;
 		// 网格编号集合
 		List<String> gridCodeList = new ArrayList<>();
 		// 民警角色
-		if (!Strings.isBlank(roleName)){
+		if (!Strings.isBlank(roleName)) {
 			taskPlaceRectificationVO.setRoleName(roleName);
-			if(roleName.equals("mj")) {
+			if (roleName.equals("mj")) {
 				regionChildCodesList = SpringUtil.getBean(IPoliceAffairsGridService.class).getCommunityCodeListByUserId(AuthUtil.getUserId());
 			}
 			if (roleName.equals("wgy")) {
@@ -239,16 +239,16 @@
 			}
 		}
 		List<String> strings = new ArrayList<>();
-		if (null!=taskPlaceRectificationVO.getNineType()){
+		if (null != taskPlaceRectificationVO.getNineType()) {
 			QueryWrapper<DictBiz> queryWrapper = new QueryWrapper<>();
-			queryWrapper.eq("is_deleted",0).eq("dict_key",taskPlaceRectificationVO.getNineType()).eq("code","nineType");
+			queryWrapper.eq("is_deleted", 0).eq("dict_key", taskPlaceRectificationVO.getNineType()).eq("code", "nineType");
 			// 先查询当前
 			DictBiz one = dictBizService.getOne(queryWrapper);
 			// 查询本身和子集的key
 			List<DictBiz> list = dictBizService.getList("nineType", one.getId());
-			if (list.size()==0){
+			if (list.size() == 0) {
 				strings.add(taskPlaceRectificationVO.getNineType());
-			}else {
+			} else {
 				strings = list.stream().map(DictBiz::getDictKey).collect(Collectors.toList());
 			}
 		}
@@ -446,7 +446,14 @@
 		// 获取请求头中的角色别名
 		String roleName = SpringUtils.getRequestParam("roleName");
 		if (AuthUtils.isMj(roleName)) {
-			return baseMapper.getCount(neiCode, i, AuthUtil.getUserId());
+			// 民警角色
+			List<String> regionChildCodesList  = SpringUtil.getBean(IPoliceAffairsGridService.class)
+					.getCommunityCodeListByUserId(AuthUtil.getUserId());
+			TaskPlaceRectificationDTO taskPlaceRectificationDTO = new TaskPlaceRectificationDTO();
+			taskPlaceRectificationDTO.setCommunityCode(neiCode);
+			taskPlaceRectificationDTO.setStatus(i);
+			taskPlaceRectificationDTO.setRoleName(roleName);
+			return baseMapper.getCount(taskPlaceRectificationDTO, regionChildCodesList, 2);
 		}
 		return 0;
 	}

--
Gitblit v1.9.3