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