shiqian 3 жил өмнө
parent
commit
2f02ef2e67

+ 3 - 0
boman-common/boman-common-redis/src/main/java/com/boman/common/redis/RedisKey.java

@@ -37,4 +37,7 @@ public class RedisKey {
      * 异步下载时,判断是否下载完成
      */
     public static final String ASYNC_DOWNLOAD_YMJZ = "download:ymjz:";
+
+    /** 常住人口统计 **/
+    public static final String STS_CZRK_ = "sts:czrk:";
 }

+ 11 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/CzrkController.java

@@ -25,6 +25,17 @@ public class CzrkController extends BaseController {
     @Autowired
     private IVaccineInfoService vaccineInfoService;
 
+    /**
+     * 功能描述: 项目首页统计信息,
+     * 当前单位:镇,村:7个,组:300个,常住人口:5000人,新增 2人  减少 2人
+     *
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @GetMapping("/stsByCzrkHomePage")
+    public AjaxResult stsByCzrkHomePage() {
+        return AjaxResult.success("成功", vaccineInfoService.stsByCzrkHomePage());
+    }
+
     /**
      * 功能描述: 当前单位:镇,村:7个,组:300个,常住人口:5000人,新增 2人  减少 2人
      *

+ 1 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/VaccineInfoMapper.java

@@ -113,6 +113,7 @@ public interface VaccineInfoMapper
     List<VaccineInfoOperation> listByXz(VaccineInfoOperation condition);
     int countByJs(VaccineInfoOperation condition);
     int countByXz(VaccineInfoOperation condition);
+
     /**
      * 功能描述: 根据deptIdList查找多少已经认领的(常住人口数量)
      *

+ 1 - 0
boman-web-core/src/main/java/com/boman/web/core/service/vaccineInfo/IVaccineInfoService.java

@@ -97,6 +97,7 @@ public interface IVaccineInfoService
     JSONObject stsByApplet();
 
     JSONObject stsByCzrk();
+    JSONObject stsByCzrkHomePage();
     int countByJs(VaccineInfoOperation condition);
     int countByXz(VaccineInfoOperation condition);
     List<VaccineInfoOperation> listByXz(VaccineInfoOperation condition);

+ 172 - 23
boman-web-core/src/main/java/com/boman/web/core/service/vaccineInfo/impl/VaccineInfoServiceImpl.java

@@ -10,8 +10,10 @@ import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.common.core.utils.sql.SqlUtil;
 import com.boman.common.core.web.page.PageDomain;
 import com.boman.common.core.web.page.TableSupport;
+import com.boman.common.redis.service.RedisService;
 import com.boman.domain.*;
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.utils.ThreadPoolService;
 import com.boman.system.api.RemoteDeptService;
 import com.boman.system.api.RemoteDictDataService;
 import com.boman.web.core.mapper.StandardlyMapper;
@@ -24,6 +26,7 @@ import com.boman.web.core.utils.AuthUtils;
 import com.boman.web.core.utils.IdUtils;
 import com.boman.web.core.utils.VaccineUtils;
 import com.github.pagehelper.PageHelper;
+import org.apache.commons.lang3.BooleanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -37,11 +40,13 @@ import java.sql.Timestamp;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import static com.boman.common.core.utils.StringUtils.isNotEmpty;
 import static com.boman.common.core.utils.obj.ObjectUtils.*;
+import static com.boman.common.redis.RedisKey.STS_CZRK_;
 
 /**
  * 疫苗信息Service业务层处理
@@ -57,6 +62,7 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
     private static final String INSERT = "insert";
     private static final String EDIT = "edit";
     private static final String DELETE = "delete";
+    private static JSONObject QIANSHANSHI = null, ZHEN = null, QIANSHANSHI_SINGEL = null;
 
     @Resource
     private VaccineInfoMapper vaccineInfoMapper;
@@ -72,6 +78,8 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
     private IBaseSaveService saveService;
     @Resource
     private StandardlyMapper standardlyMapper;
+    @Resource
+    private RedisService redisService;
 
     /**
      * 查询疫苗信息
@@ -1173,13 +1181,11 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
      */
     @Override
     public JSONObject stsByCzrk() {
-        JSONObject result = new JSONObject(6);
-        // 当前登陆人的deptId
+        JSONObject result = new JSONObject(16);
         SysUser sysUser = AuthUtils.getLoginUser().getSysUser();
         String deptName = sysUser.getDept().getDeptName();
-        Long deptId = sysUser.getDeptId();
-        // 当前单位
-        result.put("dqdw", deptName);
+        Long deptId = sysUser.getDeptId(); // 当前登陆人的deptId
+        result.put("dqdw", deptName);  // 当前单位
 
         List<SysRole> roles = sysUser.getRoles();
         List<String> roleKeySets = map(roles, SysRole::getRoleKey);
@@ -1188,8 +1194,14 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
         VaccineInfoOperation condition = new VaccineInfoOperation();
         condition.setStartTime(todayStart);
         condition.setEndTime(todayEnd);
+        condition.setRyrl(true);
         // 市领导
         if (roleKeySets.contains("city") || roleKeySets.contains("admin") || roleKeySets.contains("yanshi")) {
+            JSONObject jsonObject = redisService.getCacheObject(packRedisKey("single:" + deptId));
+            if (isNotEmpty(jsonObject)) {
+                return jsonObject;
+            }
+            
             List<SysDept> allDepts = remoteDeptService.listChildrenDepts(1L);
             List<SysDept> townsDepts = new ArrayList<>(16);
             for (SysDept allDept : allDepts) {
@@ -1220,38 +1232,171 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
                 }
             }
             result.put("zu", isEmpty(zuDept) ? 0 : zuDept.size());
+            int xz = vaccineInfoMapper.countByXz(condition);
+            int js = vaccineInfoMapper.countByJs(condition);
+            result.put("xz", xz);
+            result.put("js", js);
+            result.put("czrk", vaccineInfoMapper.countCzrk(condition));
+            redisService.setCacheObject(packRedisKey("single:" + deptId), result, 1L, TimeUnit.DAYS);
         } else if (roleKeySets.contains("sys:town")) {
-            // 乡镇以下的所有部门
-            List<SysDept> depts = remoteDeptService.listChildrenDepts(deptId);
+            JSONObject jsonObject = redisService.getCacheObject(packRedisKey("town:" + deptId));
+            if (isNotEmpty(jsonObject)) {
+                return jsonObject;
+            }
 
-            List<SysDept> cunDepts = new ArrayList<>(16);
-            for (SysDept dept : depts) {
-                if (isEmpty(dept.getParentId())) continue;
-                if (deptId.equals(dept.getParentId())) {
-                    cunDepts.add(dept);
-                }
+            townSts(result, condition, deptId, deptName, true);
+            redisService.setCacheObject(packRedisKey("town:" + deptId), result, 1L, TimeUnit.DAYS);
+        }
+
+        return result;
+    }
+
+    /**
+     * 功能描述: 项目首页统计信息,
+     * 当前单位:镇,村:7个,组:300个,常住人口:5000人,新增 2人  减少 2人
+     *
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @Override
+    public JSONObject stsByCzrkHomePage() {
+        JSONObject result = new JSONObject(16);
+        // 当前登陆人的deptId
+        SysUser sysUser = AuthUtils.getLoginUser().getSysUser();
+        String deptName = sysUser.getDept().getDeptName();
+        result.put("dqdw", deptName); // 当前单位
+
+        List<String> roleKeySets = map(sysUser.getRoles(), SysRole::getRoleKey);
+
+        VaccineInfoOperation condition = new VaccineInfoOperation();
+        condition.setStartTime(DateUtils.getTodayStartStr());
+        condition.setEndTime(DateUtils.getTodayEndStr());
+        condition.setRyrl(true);
+        Long deptId = sysUser.getDeptId();
+
+        // 市领导 todo 此处不应该写死
+        if (roleKeySets.contains("city") || roleKeySets.contains("admin") || roleKeySets.contains("yanshi")) {
+            JSONObject jsonObject = redisService.getCacheObject(packRedisKey(deptId + ""));
+            if (isNotEmpty(jsonObject)) {
+                QIANSHANSHI = jsonObject;
+                return jsonObject;
             }
-            result.put("cun", isEmpty(cunDepts) ? 0 : cunDepts.size());
 
-            List<SysDept> zuDept = new ArrayList<>(16);
-            for (SysDept cunDept : cunDepts) {
-                for (SysDept dept : depts) {
-                    if (cunDept.getId().equals(dept.getParentId())) {
-                        zuDept.add(dept);
+            ThreadPoolService.execute(()->{
+                List<SysDept> allDepts = remoteDeptService.listChildrenDepts(1L);
+                List<SysDept> townsDepts = new ArrayList<>(16);
+                for (SysDept allDept : allDepts) {
+                    if (isEmpty(allDept.getParentId())) continue;
+                    if (allDept.getParentId() == (1L)) {
+                        townsDepts.add(allDept);
+                    }
+                }
+                result.put("zhen", townsDepts.size()); // 镇
+
+                List<SysDept> cunDepts = new ArrayList<>(16);
+                for (SysDept townsDept : townsDepts) {
+                    for (SysDept allDept : allDepts) {
+                        if (isEmpty(allDept.getParentId())) continue;
+                        if (townsDept.getId().equals(allDept.getParentId())) {
+                            cunDepts.add(allDept);
+                        }
+                    }
+                }
+                result.put("cun", isEmpty(cunDepts) ? 0 : cunDepts.size());
+
+                List<SysDept> zuDept = new ArrayList<>(16);
+                for (SysDept cunDept : cunDepts) {
+                    for (SysDept allDept : allDepts) {
+                        if (cunDept.getId().equals(allDept.getParentId())) {
+                            zuDept.add(allDept);
+                        }
                     }
                 }
+
+                result.put("zu", isEmpty(zuDept) ? 0 : zuDept.size()); // 组
+                int czrk = vaccineInfoMapper.countCzrk(condition); // 常住人口
+                result.put("czrk", czrk);
+
+                int xz = vaccineInfoMapper.countByXz(condition); // 新增
+                int js = vaccineInfoMapper.countByJs(condition);// 减少
+                result.put("xz", xz);
+                result.put("js", js);
+
+                condition.setRyrl(null); // 查全部
+                int zrs = vaccineInfoMapper.countCzrk(condition);
+                String bfb = NumberUtils.percent(czrk, zrs);
+                result.put("bfb", bfb);
+                result.put("zrs", zrs);
+
+                // 以各个镇为单位单独处理 townsDepts
+                ArrayList<JSONObject> towsDataList = new ArrayList<>(20);
+                for (SysDept townsDept : townsDepts) {
+                    JSONObject townsResult = new JSONObject(16);
+                    townSts(townsResult, condition, townsDept.getId(), townsDept.getDeptName(), false);
+                    towsDataList.add(townsResult);
+                }
+
+                result.put("townDatas", towsDataList);
+                redisService.setCacheObject(packRedisKey(deptId + ""), result, 1L, TimeUnit.DAYS);
+            });
+
+            return QIANSHANSHI;
+        } else if (roleKeySets.contains("sys:town")) {
+            JSONObject jsonObject = redisService.getCacheObject(packRedisKey("town:" + deptId));
+            if (isNotEmpty(jsonObject)) {
+                ZHEN = jsonObject;
+                return jsonObject;
             }
 
-            result.put("zu", isEmpty(zuDept) ? 0 : zuDept.size());
-            condition.setDeptIdList(map(depts, SysDept::getId));
+            ThreadPoolService.execute(() -> {
+                townSts(result, condition, deptId, deptName, true);
+                redisService.setCacheObject(packRedisKey("town:" + deptId), result, 1L, TimeUnit.DAYS);
+            });
+
+            return ZHEN;
+        }
+
+        return result;
+    }
+
+    private void townSts(JSONObject result, VaccineInfoOperation condition, Long deptId, String deptName, boolean percent) {
+        // 乡镇以下的所有部门
+        List<SysDept> depts = remoteDeptService.listChildrenDepts(deptId);
+        List<SysDept> cunDepts = new ArrayList<>(16);
+        for (SysDept dept : depts) {
+            if (isEmpty(dept.getParentId())) continue;
+            if (deptId.equals(dept.getParentId())) {
+                cunDepts.add(dept);
+            }
+        }
+        result.put("cun", isEmpty(cunDepts) ? 0 : cunDepts.size());
+
+        List<SysDept> zuDept = new ArrayList<>(16);
+        for (SysDept cunDept : cunDepts) {
+            for (SysDept dept : depts) {
+                if (cunDept.getId().equals(dept.getParentId())) {
+                    zuDept.add(dept);
+                }
+            }
+        }
+
+        result.put("zu", isEmpty(zuDept) ? 0 : zuDept.size());
+        condition.setDeptIdList(map(depts, SysDept::getId));
+        int czrk = vaccineInfoMapper.countCzrk(condition);
+        result.put("czrk", czrk);
+
+        // 常住人口占总人口的百分比
+        if (BooleanUtils.isTrue(percent)) {
+            condition.setRyrl(null); // 查全部
+            int zrs = vaccineInfoMapper.countCzrk(condition);
+            String bfb = NumberUtils.percent(czrk, zrs);
+            result.put("bfb", bfb);
         }
 
         int xz = vaccineInfoMapper.countByXz(condition);
         int js = vaccineInfoMapper.countByJs(condition);
         result.put("xz", xz);
         result.put("js", js);
-        result.put("czrk", vaccineInfoMapper.countCzrk(condition));
-        return result;
+        result.put("zhen", deptName);
     }
 
     @Override
@@ -1451,4 +1596,8 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
 
         return infoOperations;
     }
+
+    private String packRedisKey(String deptId){
+        return STS_CZRK_ + ":" + deptId + ":" + DateUtils.getDate();
+    }
 }

+ 14 - 7
boman-web-core/src/main/resources/mapper/VaccineInfoMapper.xml

@@ -143,7 +143,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
              , vi.gender, vi.province, vi.city, vi.region, vi.now_in, vi.house_type, vi.update_by, vi.code
         from vaccine_info vi
         where vi.is_del = 'N' and vi.create_time &gt;= #{startTime} and vi.create_time &lt;= #{endTime}
-        <!--where vi.is_del = 'N' and vi.create_time &gt;= #{startTime, jdbcType=DATE} and vi.create_time &lt;= #{startTime, jdbcType=DATE} -->
+        <if test="userName != null  and userName != ''">
+            and (vi.user_name like concat('%', #{userName}, '%') or vi.id_card like concat('%', #{userName}, '%'))
+        </if>
         <if test="villageTowns != null  and villageTowns != ''">
             and vi.village_towns = #{villageTowns}
         </if>
@@ -157,7 +159,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="vaccineName != null  and vaccineName != ''"> and vi.vaccine_name like concat('%', #{vaccineName}, '%')</if>
         <if test="vaccinationTime != null "> and DATE_FORMAT(vi.vaccination_time,'%Y-%m-%d') = DATE_FORMAT(#{vaccinationTime},'%Y-%m-%d')</if>
         <if test="region != null  and region != ''"> and vi.region = #{region}</if>
-        <if test="userName != null  and userName != ''"> and vi.user_name like concat('%', #{userName}, '%')</if>
+<!--        <if test="userName != null  and userName != ''"> and vi.user_name like concat('%', #{userName}, '%')</if>-->
         <if test="gender != null  and gender != ''"> and vi.gender = #{gender}</if>
         <if test="idCard != null  and idCard != ''"> and vi.id_card like concat('%', #{idCard}, '%')</if>
         <if test="phoneNum != null  and phoneNum != ''"> and vi.phone_num = #{phoneNum}</if>
@@ -198,7 +200,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="countByXz" resultType="int">
         select count(1)
         from vaccine_info vi
-        where vi.is_del = 'N' and vi.create_time &gt;= date_format(#{startTime}, '%y-%m-%d %H:%i:%s') and vi.create_time &lt;= date_format(#{endTime}, '%y-%m-%d %H:%i:%s')
+        where vi.is_del = 'N' and vi.create_time &gt;= #{startTime} and vi.create_time &lt;= #{endTime}
         <if test="villageTowns != null  and villageTowns != ''">
             and vi.village_towns = #{villageTowns}
         </if>
@@ -253,8 +255,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select vi.id, vi.create_time, vi.update_time, vi.is_del, vi.update_by, vi.user_name, vi.phone_num, vi.id_card
         , vi.gender, vi.province, vi.city, vi.region, vi.now_in, vi.house_type, vi.update_by, vi.code
         from vaccine_info vi
-        where vi.is_del = 'N' and vi.update_time &gt;= date_format(#{startTime}, '%y-%m-%d %H:%i:%s') and vi.update_time &lt;= date_format(#{endTime}, '%y-%m-%d %H:%i:%s')
-        <if test="villageTowns != null  and villageTowns != ''">
+        where vi.is_del = 'N' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
+        <if test="userName != null  and userName != ''">
+            and (vi.user_name like concat('%', #{userName}, '%') or vi.id_card like concat('%', #{userName}, '%'))
+        </if>
+          <if test="villageTowns != null  and villageTowns != ''">
             and vi.village_towns = #{villageTowns}
         </if>
         <if test="village != null  and village != ''"> and vi.village = #{village}</if>
@@ -267,7 +272,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="vaccineName != null  and vaccineName != ''"> and vi.vaccine_name like concat('%', #{vaccineName}, '%')</if>
         <if test="vaccinationTime != null "> and DATE_FORMAT(vi.vaccination_time,'%Y-%m-%d') = DATE_FORMAT(#{vaccinationTime},'%Y-%m-%d')</if>
         <if test="region != null  and region != ''"> and vi.region = #{region}</if>
-        <if test="userName != null  and userName != ''"> and vi.user_name like concat('%', #{userName}, '%')</if>
+        <!--<if test="userName != null  and userName != ''"> and vi.user_name like concat('%', #{userName}, '%')</if>-->
         <if test="gender != null  and gender != ''"> and vi.gender = #{gender}</if>
         <if test="idCard != null  and idCard != ''"> and vi.id_card like concat('%', #{idCard}, '%')</if>
         <if test="phoneNum != null  and phoneNum != ''"> and vi.phone_num = #{phoneNum}</if>
@@ -307,7 +312,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="countByJs" resultType="int">
         select count(1)
         from vaccine_info vi
-        where vi.is_del = 'N' and vi.update_time &gt;= date_format(#{startTime}, '%y-%m-%d %H:%i:%s') and vi.update_time &lt;= date_format(#{endTime}, '%y-%m-%d %H:%i:%s')
+        where vi.is_del = 'N' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
         <if test="villageTowns != null  and villageTowns != ''">
             and vi.village_towns = #{villageTowns}
         </if>
@@ -392,6 +397,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="ryrl == false">and (vi.village_towns is null or vi.village_towns = '')</if>
 
 
+            <if test="villageTowns != null  and villageTowns != ''">and vi.village_towns = #{villageTowns}</if>
+            <if test="village != null  and village != ''">and vi.village = #{village}</if>
             <if test="houseType != null  and houseType != ''">and vi.house_type = #{houseType}</if>
             <if test="domicile != null  and domicile != ''">and vi.domicile = #{domicile}</if>
             <if test="province != null  and province != ''">and vi.province = #{province}</if>