Commit 20a8832b authored by tianyiming's avatar tianyiming

一码通总览sql优化

parent b1eae7c5
......@@ -20,7 +20,7 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> {
@Select("select * from tz_equipment_category where code in('1000','2000','3000','4000','5000','6000','8000','9000')")
List<EquipmentCategoryDto> selectClassify();
Map<String, Object> getCategoryCount(@Param("code") String code, @Param("level") String level,
List<Map<String, Object>> getCategoryCount(@Param("level") String level,
@Param("orgCode") String orgCode, @Param("companyCode") String companyCode);
Map<String, Object> getAdministrativeDivision(@Param("division") String division, @Param("county") String county);
......
......@@ -3,37 +3,44 @@
<mapper namespace="com.yeejoin.amos.boot.module.tzs.api.mapper.EquipmentCategoryMapper">
<select id="getCategoryCount" resultType="java.util.Map">
SELECT (SELECT
count(*)
SELECT A."EQU_LIST" category,
IFNULL ( A.count, 0 ) waitClaim,
IFNULL ( b.count, 0 ) alreadyClaim,
IFNULL ( C.count, 0 ) refuseClaim
FROM
(
SELECT
"EQU_LIST",
COUNT ( * )
FROM
idx_biz_jg_use_info ibjui
LEFT JOIN idx_biz_jg_supervision_info ibjsi ON ibjui.RECORD = ibjsi.RECORD
LEFT JOIN idx_biz_jg_register_info ibjri ON ibjui.RECORD = ibjri.RECORD
LEFT JOIN idx_biz_jg_other_info ibjoi ON ibjui.RECORD = ibjoi.RECORD
LEFT JOIN tz_equipment_category tec ON ibjri.EQU_CATEGORY = tec.code
LEFT JOIN tz_equipment_category tec1 ON ibjri.EQU_LIST = tec1.code
WHERE
ibjoi.claim_status = '待认领' AND ibjri."EQU_LIST" = #{code}
ibjoi.claim_status = '待认领'
<if test="level == 'company'">
AND ibjui."USE_UNIT_CREDIT_CODE"
LIKE CONCAT('%',#{companyCode},'%')
LIKE CONCAT('%',#{companyCode},'%')
</if>
<if test="level != 'company'">
AND ibjsi."ORG_BRANCH_CODE"
LIKE CONCAT('%',#{orgCode},'%')
AND ibjsi."ORG_BRANCH_CODE"
LIKE CONCAT('%',#{orgCode},'%')
</if>
) waitClaim ,
(SELECT
COUNT( * )
GROUP BY
"EQU_LIST"
)
A LEFT JOIN (
SELECT
"EQU_LIST",
COUNT ( * )
FROM
idx_biz_jg_use_info ibjui
LEFT JOIN idx_biz_jg_supervision_info ibjsi ON ibjui.RECORD = ibjsi.RECORD
LEFT JOIN idx_biz_jg_register_info ibjri ON ibjui.RECORD = ibjri.RECORD
LEFT JOIN idx_biz_jg_other_info ibjoi ON ibjui.RECORD = ibjoi.RECORD
LEFT JOIN tz_equipment_category tec ON ibjri.EQU_CATEGORY = tec.code
LEFT JOIN tz_equipment_category tec1 ON ibjri.EQU_LIST = tec1.code
WHERE
ibjoi.claim_status = '已认领' AND ibjri."EQU_LIST" = #{code}
ibjoi.claim_status = '已认领'
<if test="level == 'company'">
AND ibjui."USE_UNIT_CREDIT_CODE"
LIKE CONCAT('%',#{companyCode},'%')
......@@ -42,18 +49,20 @@
AND ibjsi."ORG_BRANCH_CODE"
LIKE CONCAT('%',#{orgCode},'%')
</if>
) alreadyClaim,
(SELECT
COUNT( * )
GROUP BY
"EQU_LIST"
) b ON A."EQU_LIST" = b."EQU_LIST"
LEFT JOIN (
SELECT
"EQU_LIST",
COUNT ( * )
FROM
idx_biz_jg_use_info ibjui
LEFT JOIN idx_biz_jg_supervision_info ibjsi ON ibjui.RECORD = ibjsi.RECORD
LEFT JOIN idx_biz_jg_register_info ibjri ON ibjui.RECORD = ibjri.RECORD
LEFT JOIN idx_biz_jg_other_info ibjoi ON ibjui.RECORD = ibjoi.RECORD
LEFT JOIN tz_equipment_category tec ON ibjri.EQU_CATEGORY = tec.code
LEFT JOIN tz_equipment_category tec1 ON ibjri.EQU_LIST = tec1.code
WHERE
ibjoi.claim_status = '已拒领' AND ibjri."EQU_LIST" = #{code}
ibjoi.claim_status = '已拒领'
<if test="level == 'company'">
AND ibjui."USE_UNIT_CREDIT_CODE"
LIKE CONCAT('%',#{companyCode},'%')
......@@ -62,7 +71,9 @@
AND ibjsi."ORG_BRANCH_CODE"
LIKE CONCAT('%',#{orgCode},'%')
</if>
) refuseClaim
GROUP BY
"EQU_LIST"
) C ON A."EQU_LIST" = C."EQU_LIST"
</select>
<select id="getAdministrativeDivision" resultType="java.util.Map">
......
package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto;
......@@ -29,6 +32,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
......@@ -123,17 +127,24 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
Map<String, List<Map<String, Object>>> resourceJson = JsonUtils.getResourceJson(equipCategory);
List<Map<String, Object>> mapList = resourceJson.get(EquipmentClassifityEnum.BDLS.getCode());
List<Map<String, Object>> list = new ArrayList<>();
JSONObject object = getCompanyType();
String level = object.getString("level");
String orgCode = object.getString("orgCode");
String companyCode = object.getString("companyCode");
for (Map map : mapList) {
Map<String, Object> categoryCountMap = equipmentCategoryMapper.getCategoryCount(map.get("code").toString(), level, orgCode, companyCode);
categoryCountMap.put("name", map.get("name"));
categoryCountMap.put("image", map.get("image"));
Long sum = Long.valueOf(categoryCountMap.get("waitClaim").toString()) + Long.valueOf(categoryCountMap.get("alreadyClaim").toString()) + Long.valueOf(categoryCountMap.get("refuseClaim").toString());
categoryCountMap.put("sum", sum);
list.add(categoryCountMap);
ReginParams reginParams = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
if(ObjectUtils.isEmpty(reginParams)){
return null;
}
String level = reginParams.getUserModel().getCompanys().get(0).getLevel();
String orgCode = reginParams.getUserModel().getCompanys().get(0).getOrgCode();
String companyCode = reginParams.getUserModel().getCompanys().get(0).getCompanyCode();
List<Map<String, Object>> listMap = equipmentCategoryMapper.getCategoryCount(level, orgCode, companyCode);
for (Map<String, Object> map : mapList) {
for (Map<String, Object> map1 : listMap) {
if (map.get("code").equals(map1.get("category"))) {
map1.put("name", map.get("name"));
map1.put("image", map.get("image"));
Long sum = Long.valueOf(map1.get("waitClaim").toString()) + Long.valueOf(map1.get("alreadyClaim").toString()) + Long.valueOf(map1.get("refuseClaim").toString());
map1.put("sum", sum);
list.add(map1);
}
}
}
page.setCurrent(1);
page.setTotal(list.size());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment