Commit 746ff7d8 authored by suhuiguang's avatar suhuiguang

1.总览数据刷新优化33秒左右

parent 18c8b218
package com.yeejoin.amos.boot.module.tzs.api.dto;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class UseUnitCreditCodeCategoryDto {
/**
* 使用单位编码
*/
private String useUnitCreditCode;
/**
* 状态
*/
private String claimStatus;
/**
* 设备定义编码
*/
private String equList;
/**
* 数量
*/
private Long total;
}
...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.tzs.api.mapper; ...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.tzs.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.UseUnitCreditCodeCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.EquipmentCategory; import com.yeejoin.amos.boot.module.tzs.api.entity.EquipmentCategory;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
...@@ -22,6 +23,7 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> { ...@@ -22,6 +23,7 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> {
List<Map<String, Object>> getCategoryCount( @Param("companyCode") String companyCode); List<Map<String, Object>> getCategoryCount( @Param("companyCode") String companyCode);
Map<String, Object> getAdministrativeDivision(@Param("division") String division, @Param("county") String county); Map<String, Object> getAdministrativeDivision(@Param("division") String division, @Param("county") String county);
...@@ -40,4 +42,7 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> { ...@@ -40,4 +42,7 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> {
List<Map<String, Object>> getCategoryData(String level, String orgCode, String companyCode); List<Map<String, Object>> getCategoryData(String level, String orgCode, String companyCode);
String getUnitCodeByRecord(String record); String getUnitCodeByRecord(String record);
List<UseUnitCreditCodeCategoryDto> useUnitCreditCodeCategoryCount();
} }
...@@ -39,7 +39,7 @@ public interface IEquipmentCategoryService { ...@@ -39,7 +39,7 @@ public interface IEquipmentCategoryService {
void checkEsData(String id); void checkEsData(String id);
List<EquipmentCategoryData> createEquipmentCategoryData(); void createEquipmentCategoryData();
EquipmentCategoryData updateEquipmentCategoryData(String id); EquipmentCategoryData updateEquipmentCategoryData(String id);
......
...@@ -135,8 +135,7 @@ ...@@ -135,8 +135,7 @@
idx_biz_jg_use_info ibjui idx_biz_jg_use_info ibjui
LEFT JOIN idx_biz_jg_supervision_info ibjsi ON ibjui."RECORD" = ibjsi."RECORD" LEFT JOIN idx_biz_jg_supervision_info ibjsi ON ibjui."RECORD" = ibjsi."RECORD"
WHERE WHERE
USE_UNIT_CREDIT_CODE is NOT NULL USE_UNIT_CREDIT_CODE <![CDATA[ <> ]]> ''
AND USE_UNIT_CREDIT_CODE <![CDATA[ <> ]]> ''
AND (lengthb(USE_UNIT_CREDIT_CODE)= 15 or lengthb(USE_UNIT_CREDIT_CODE)= 18) AND (lengthb(USE_UNIT_CREDIT_CODE)= 15 or lengthb(USE_UNIT_CREDIT_CODE)= 18)
<if test="unitCodes !=null and unitCodes.size>0"> <if test="unitCodes !=null and unitCodes.size>0">
and USE_UNIT_CREDIT_CODE in and USE_UNIT_CREDIT_CODE in
...@@ -299,4 +298,22 @@ ...@@ -299,4 +298,22 @@
<select id="getUnitCodeByRecord" resultType="java.lang.String"> <select id="getUnitCodeByRecord" resultType="java.lang.String">
select "USE_UNIT_CREDIT_CODE" from idx_biz_jg_use_info where "RECORD" = #{id} select "USE_UNIT_CREDIT_CODE" from idx_biz_jg_use_info where "RECORD" = #{id}
</select> </select>
<select id="useUnitCreditCodeCategoryCount" resultType="com.yeejoin.amos.boot.module.tzs.api.dto.UseUnitCreditCodeCategoryDto">
SELECT
ibjui."USE_UNIT_CREDIT_CODE",
ibjoi."CLAIM_STATUS",
ibjri."EQU_LIST",
COUNT ( * ) as TOTAL
FROM
idx_biz_jg_use_info ibjui
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
where
ibjoi."CLAIM_STATUS" <![CDATA[ <> ]]> ''
and ibjui."USE_UNIT_CREDIT_CODE" <![CDATA[ <> ]]> ''
and ibjri."EQU_LIST" <![CDATA[ <> ]]> ''
GROUP BY ibjui."USE_UNIT_CREDIT_CODE", ibjoi."CLAIM_STATUS",ibjri."EQU_LIST"
ORDER BY ibjui."USE_UNIT_CREDIT_CODE"
</select>
</mapper> </mapper>
...@@ -260,8 +260,8 @@ public class EquipmentCategoryController extends BaseController { ...@@ -260,8 +260,8 @@ public class EquipmentCategoryController extends BaseController {
@RequestMapping(value = "/createEquipmentCategoryData", method = RequestMethod.GET) @RequestMapping(value = "/createEquipmentCategoryData", method = RequestMethod.GET)
@ApiOperation(httpMethod = "get", value = "初始化一码通总览数据", notes = "初始化一码通总览数据") @ApiOperation(httpMethod = "get", value = "初始化一码通总览数据", notes = "初始化一码通总览数据")
public ResponseModel<Object> createEquipmentCategoryData(){ public ResponseModel<Object> createEquipmentCategoryData(){
equipmentCategoryService.createEquipmentCategoryData();
return ResponseHelper.buildResponse(equipmentCategoryService.createEquipmentCategoryData()); return ResponseHelper.buildResponse("SUCCESS");
} }
/** /**
......
...@@ -13,6 +13,7 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; ...@@ -13,6 +13,7 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.ESEquipmentCategoryDto; import com.yeejoin.amos.boot.module.tzs.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquInfoDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.UseUnitCreditCodeCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.*; import com.yeejoin.amos.boot.module.tzs.api.entity.*;
import com.yeejoin.amos.boot.module.tzs.api.enums.EquimentEnum; import com.yeejoin.amos.boot.module.tzs.api.enums.EquimentEnum;
import com.yeejoin.amos.boot.module.tzs.api.enums.EquipmentCategoryEnum; import com.yeejoin.amos.boot.module.tzs.api.enums.EquipmentCategoryEnum;
...@@ -47,10 +48,12 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -47,10 +48,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.DateUtil; import org.typroject.tyboot.core.foundation.utils.DateUtil;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
...@@ -62,6 +65,8 @@ import java.sql.Timestamp; ...@@ -62,6 +65,8 @@ import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.alibaba.fastjson.JSON.toJSONString;
/** /**
* 装备分类服务实现类 * 装备分类服务实现类
* *
...@@ -81,8 +86,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -81,8 +86,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Autowired @Autowired
private UseInfoMapper useInfoMapper; private UseInfoMapper useInfoMapper;
@Autowired
private SuperviseInfoService superviseInfoService;
@Autowired @Autowired
EquipmentCategoryMapper equipmentCategoryMapper; EquipmentCategoryMapper equipmentCategoryMapper;
...@@ -155,6 +158,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -155,6 +158,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Value("${elasticsearch.password}") @Value("${elasticsearch.password}")
private String esPwd; private String esPwd;
private static String USE_CODE = "use_code";
/** /**
* 分页查询 * 分页查询
*/ */
...@@ -820,7 +825,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -820,7 +825,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
UseInfo useInfo = new UseInfo(); UseInfo useInfo = new UseInfo();
useInfo.setIsNotEs(1); useInfo.setIsNotEs(1);
useInfoMapper.update(useInfo, new QueryWrapper<UseInfo>().eq("RECORD", id)); useInfoMapper.update(useInfo, new QueryWrapper<UseInfo>().eq("RECORD", id));
ESEquipmentCategoryDto dto = JSON.parseObject(JSONObject.toJSONString(map), ESEquipmentCategoryDto.class); ESEquipmentCategoryDto dto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class);
Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(id); Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(id);
if (!ObjectUtils.isEmpty(data)) { if (!ObjectUtils.isEmpty(data)) {
esEquipmentCategory.deleteById(id); esEquipmentCategory.deleteById(id);
...@@ -833,65 +838,100 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -833,65 +838,100 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
public List<EquipmentCategoryData> createEquipmentCategoryData() { @Override
@Async
public void createEquipmentCategoryData() {
if(log.isInfoEnabled()){
log.info("初始化一码通总览数据开始");
}
equipmentCategoryDataService.remove(new QueryWrapper<>()); equipmentCategoryDataService.remove(new QueryWrapper<>());
return getCategoryData(null); getCategoryData(null);
} }
private List<EquipmentCategoryData> getCategoryData(List<String> unitCodes) { private List<EquipmentCategoryData> getCategoryData(List<String> unitCodes) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
List<EquipmentCategoryData> list = new ArrayList<>(); List<EquipmentCategoryData> list = new ArrayList<>();
// 查询所有单位
List<Map<String, Object>> allUnitList = equipmentCategoryMapper.getAllUnit(unitCodes); List<Map<String, Object>> allUnitList = equipmentCategoryMapper.getAllUnit(unitCodes);
// 统计查询不同单位、不同装备定义、不同状态下的设备数量
List<UseUnitCreditCodeCategoryDto> equipCountList = equipmentCategoryMapper.useUnitCreditCodeCategoryCount();
// 查询8大类设备定义
List<EquipmentCategory> equipmentCategories = getEquipmentCategories();
for (Map<String, Object> map : allUnitList) { for (Map<String, Object> map : allUnitList) {
EquipmentCategoryData equipmentCategoryData = new EquipmentCategoryData(); EquipmentCategoryData equipmentCategoryData = new EquipmentCategoryData();
equipmentCategoryData.setOrgBranchCode(String.valueOf(map.get("supervise_org_code"))); if(ObjectUtils.isEmpty(map.get("supervise_org_code")) || ObjectUtils.isEmpty(map.get(USE_CODE))){
equipmentCategoryData.setUnitCode(String.valueOf(map.get("use_code"))); continue;
List<Map<String, Object>> listMap = equipmentCategoryMapper.getCategoryCount(String.valueOf(map.get("use_code"))); }
for (Map<String, Object> dataMap : listMap) { equipmentCategoryData.setOrgBranchCode(map.get("supervise_org_code").toString());
equipmentCategoryData.setUnitCode(map.get(USE_CODE).toString());
// 指定单位的设备统计信息
List<UseUnitCreditCodeCategoryDto> unitEquipCountList = equipCountList.stream().filter(r->r.getUseUnitCreditCode().equals(map.get(USE_CODE).toString())).collect(Collectors.toList());
for (EquipmentCategory category : equipmentCategories) {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("waitClaim", dataMap.get("waitClaim")); data.put("waitClaim", unitEquipCountList.stream().filter(r->r.getEquList().equals(category.getCode()) && EquipmentCategoryEnum.DRL.getName().equals(r.getClaimStatus())).collect(Collectors.summarizingLong(UseUnitCreditCodeCategoryDto::getTotal)).getSum());
data.put("alreadyClaim", dataMap.get("alreadyClaim")); data.put("alreadyClaim", unitEquipCountList.stream().filter(r->r.getEquList().equals(category.getCode()) && EquipmentCategoryEnum.YRL.getName().equals(r.getClaimStatus())).collect(Collectors.summarizingLong(UseUnitCreditCodeCategoryDto::getTotal)).getSum());
data.put("refuseClaim", dataMap.get("refuseClaim")); data.put("refuseClaim", unitEquipCountList.stream().filter(r->r.getEquList().equals(category.getCode()) && EquipmentCategoryEnum.YJL.getName().equals(r.getClaimStatus())).collect(Collectors.summarizingLong(UseUnitCreditCodeCategoryDto::getTotal)).getSum());
JSONObject jsonObject = new JSONObject(data); this.set8CategoryCountData(equipmentCategoryData, category, data);
switch (String.valueOf(dataMap.get("category"))) {
case "1000":
equipmentCategoryData.setBoiler(jsonObject + "");
break;
case "2000":
equipmentCategoryData.setVessel(jsonObject + "");
break;
case "3000":
equipmentCategoryData.setElevator(jsonObject + "");
break;
case "4000":
equipmentCategoryData.setLifting(jsonObject + "");
break;
case "5000":
equipmentCategoryData.setVehicle(jsonObject + "");
break;
case "6000":
equipmentCategoryData.setRides(jsonObject + "");
break;
case "8000":
equipmentCategoryData.setPipeline(jsonObject + "");
break;
case "9000":
equipmentCategoryData.setRopeway(jsonObject + "");
break;
}
} }
equipmentCategoryData.setRecDate(new Date());
list.add(equipmentCategoryData); list.add(equipmentCategoryData);
} }
if(ObjectUtils.isEmpty(unitCodes)){ if(ObjectUtils.isEmpty(unitCodes)){
equipmentCategoryDataService.saveBatch(list); equipmentCategoryDataService.saveOrUpdateBatch(list);
} else { } else {
for (EquipmentCategoryData equipmentCategoryData : list) { for (EquipmentCategoryData equipmentCategoryData : list) {
equipmentCategoryDataService.update(equipmentCategoryData, equipmentCategoryDataService.update(equipmentCategoryData,
new QueryWrapper<EquipmentCategoryData>().eq("unit_code", equipmentCategoryData.getUnitCode())); new QueryWrapper<EquipmentCategoryData>().eq("unit_code", equipmentCategoryData.getUnitCode()));
} }
} }
stopWatch.stop();
if(log.isInfoEnabled()){
log.info("总览数据刷新结束,耗时:{} 秒",stopWatch.getTotalTimeSeconds());
}
return list; return list;
} }
private void set8CategoryCountData(EquipmentCategoryData equipmentCategoryData, EquipmentCategory category, Map<String, Object> data) {
switch (category.getCode()) {
case "1000":
equipmentCategoryData.setBoiler(toJSONString(data));
break;
case "2000":
equipmentCategoryData.setVessel(toJSONString(data));
break;
case "3000":
equipmentCategoryData.setElevator(toJSONString(data));
break;
case "4000":
equipmentCategoryData.setLifting(toJSONString(data));
break;
case "5000":
equipmentCategoryData.setVehicle(toJSONString(data));
break;
case "6000":
equipmentCategoryData.setRides(toJSONString(data));
break;
case "8000":
equipmentCategoryData.setPipeline(toJSONString(data));
break;
case "9000":
equipmentCategoryData.setRopeway(toJSONString(data));
break;
default:
log.error("不支持的分类:{}", toJSONString(category));
break;
}
}
private List<EquipmentCategory> getEquipmentCategories() {
LambdaQueryWrapper<EquipmentCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.likeLeft(EquipmentCategory::getCode,"000");
lambdaQueryWrapper.ne(EquipmentCategory::getCode,"7000");
lambdaQueryWrapper.ne(EquipmentCategory::getCode,"F000");
return equipmentCategoryMapper.selectList(lambdaQueryWrapper);
}
@Override @Override
public EquipmentCategoryData updateEquipmentCategoryData(String record) { public EquipmentCategoryData updateEquipmentCategoryData(String record) {
...@@ -1099,7 +1139,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1099,7 +1139,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
} }
long time = Timestamp.valueOf(recDate1).getTime(); long time = Timestamp.valueOf(recDate1).getTime();
e.put("REC_DATE", time); e.put("REC_DATE", time);
ESEquipmentCategoryDto esEquipDto = JSONObject.parseObject(JSONObject.toJSONString(e), ESEquipmentCategoryDto esEquipDto = JSONObject.parseObject(toJSONString(e),
ESEquipmentCategoryDto.class); ESEquipmentCategoryDto.class);
esEquipDtoList.add(esEquipDto); esEquipDtoList.add(esEquipDto);
...@@ -1127,7 +1167,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1127,7 +1167,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
long time = Timestamp.valueOf(recDate1).getTime(); long time = Timestamp.valueOf(recDate1).getTime();
map.put("REC_DATE",time); map.put("REC_DATE",time);
ESEquipmentCategoryDto dto = JSONObject.parseObject(JSONObject.toJSONString(map), ESEquipmentCategoryDto.class); ESEquipmentCategoryDto dto = JSONObject.parseObject(toJSONString(map), ESEquipmentCategoryDto.class);
ESEquipmentCategoryDto save = esEquipmentCategory.save(dto); ESEquipmentCategoryDto save = esEquipmentCategory.save(dto);
if (!ObjectUtils.isEmpty(save)) { if (!ObjectUtils.isEmpty(save)) {
//同步到es后修改 //同步到es后修改
......
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