Commit 2dca6124 authored by tianbo's avatar tianbo

bugfix(tcm,elevator):大屏-应急统计

parent 1f7dbf97
package com.yeejoin.amos.boot.module.elevator.api.service;
import com.alibaba.fastjson.JSONArray;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertStatistics;
import java.text.ParseException;
import java.time.LocalDate;
import java.util.List;
public interface IAlertStatisticsService {
......@@ -11,4 +13,6 @@ public interface IAlertStatisticsService {
void statisticalGeneration(String type);
List<AlertStatistics> getList(String date) throws ParseException;
JSONArray statisticInfoByRegionAndDate(String regionCode, LocalDate startDate, LocalDate endDate);
}
package com.yeejoin.amos.boot.module.elevator.biz.controller;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
......@@ -23,6 +24,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
......@@ -346,4 +348,11 @@ public class StatisticsController extends BaseController {
}
ExcelUtil.createTemplate(response, "困人救援超时情况统计", "困人救援超时情况统计", exportVos, AlertDispatchStatisticsExportVo.class, null, false);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/region/info")
@ApiOperation(httpMethod = "GET", value = "查询区域统计信息", notes = "查询区域统计信息")
public ResponseModel<JSONArray> statisticsRegionInfo(@RequestParam(value = "cityCode") String regionCode, @RequestParam(value = "startDate", required = false) LocalDate startDate, @RequestParam(value = "endDate", required = false) LocalDate endDate) {
return ResponseHelper.buildResponse(alertStatisticsService.statisticInfoByRegionAndDate(regionCode, startDate, endDate));
}
}
package com.yeejoin.amos.boot.module.common.api.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
/**
* @Author cpp
* @Description
* @Date 2023/6/5
*/
@Data
@Accessors(chain = true)
@Document(indexName = "idx_biz_view_jg_all", shards = 6, replicas = 2)
public class ESEquipmentCategoryDto {
@Id
private String SEQUENCE_NBR;
@Field(type = FieldType.Text)
private String ORG_BRANCH_NAME;
@Field(type = FieldType.Text)
private String ORG_BRANCH_CODE;
@Field(type = FieldType.Text)
private String USE_UNIT_NAME;
@Field(type = FieldType.Text)
private String USE_UNIT_CREDIT_CODE;
@Field(type = FieldType.Keyword)
private String EQU_LIST_CODE;
@Field(type = FieldType.Text)
private String EQU_LIST;
@Field(type = FieldType.Text)
private String EQU_CATEGORY;
@Field(type = FieldType.Keyword)
private String EQU_CATEGORY_CODE;
@Field(type = FieldType.Keyword)
private String USE_ORG_CODE;
@Field(type = FieldType.Text)
private String CODE96333;
@Field(type = FieldType.Text)
private String EQU_CODE;
@Field(type = FieldType.Keyword)
private String SUPERVISORY_CODE;
@Field(type = FieldType.Text)
private String USE_PLACE;
@Field(type = FieldType.Text)
private String ADDRESS;
@Field(type = FieldType.Integer)
private Integer EQU_STATE;
@Field(type = FieldType.Keyword)
private String STATUS;
@Field(type = FieldType.Long)
private Long REC_DATE;
@Field(type = FieldType.Text)
private String SAFETY_MANAGER;
@Field(type = FieldType.Text)
private String PHONE;
@Field(type = FieldType.Text)
private String MAINTAIN_UNIT;
@Field(type = FieldType.Text)
private String USE_INNER_CODE;
@Field(type = FieldType.Text)
private String FACTORY_NUM;
@Field(type = FieldType.Text)
private String PRODUCE_UNIT_NAME;
@Field(type = FieldType.Text)
private String INSPECT_REPORT;
@Field(type = FieldType.Text)
private String NEXT_INSPECT_DATE;
@Field(type = FieldType.Text)
private String CONSTRUCTION_TYPE;
@Field(type = FieldType.Text)
private String USC_UNIT_CREDIT_CODE;
@Field(type = FieldType.Text)
private String USC_UNIT_NAME;
@Field(type = FieldType.Text)
private String USC_DATE;
@Field(type = FieldType.Text)
private String EQU_DEFINE;
@Field(type = FieldType.Text)
private String EQU_DEFINE_CODE;
@Field(type = FieldType.Text)
private String PRODUCT_NAME;
@Field(type = FieldType.Text)
private String BRAND_NAME;
@Field(type = FieldType.Text)
private String EQU_TYPE;
@Field(type = FieldType.Text)
private String PRODUCE_DATE;
@Field(type = FieldType.Text)
private String DATA_SOURCE;
@Field(type = FieldType.Text)
private String WHETHER_VEHICLE_CYLINDER;
@Field(type = FieldType.Text)
private String WHETHER_SKID_MOUNTED_PRESSURE_VESSEL;
/**
* 问题状态
*/
@Field(type = FieldType.Text)
private String problemStatus;
/**
* 是否纳管:true - 已纳管 false-未纳管
*/
@Field(type = FieldType.Boolean)
private Boolean IS_INTO_MANAGEMENT;
/**
* 设备使用地点区域码610000#610100#610101
*/
@Field(type = FieldType.Keyword)
private String USE_PLACE_CODE;
/**
* 设备使用场所代码-来源数据字典ADDRESS
*/
@Field(type = FieldType.Keyword)
private String USE_SITE_CODE;
}
......@@ -26,14 +26,13 @@ public class ESEquipmentCategoryDto {
@Field(type = FieldType.Text)
private String ORG_BRANCH_CODE;
@Field(type = FieldType.Text)
private String USE_UNIT_NAME;
@Field(type = FieldType.Text)
private String USE_UNIT_CREDIT_CODE;
@Field(type = FieldType.Text)
@Field(type = FieldType.Keyword)
private String EQU_LIST_CODE;
@Field(type = FieldType.Text)
......@@ -42,7 +41,10 @@ public class ESEquipmentCategoryDto {
@Field(type = FieldType.Text)
private String EQU_CATEGORY;
@Field(type = FieldType.Text)
@Field(type = FieldType.Keyword)
private String EQU_CATEGORY_CODE;
@Field(type = FieldType.Keyword)
private String USE_ORG_CODE;
@Field(type = FieldType.Text)
......@@ -51,7 +53,7 @@ public class ESEquipmentCategoryDto {
@Field(type = FieldType.Text)
private String EQU_CODE;
@Field(type = FieldType.Text)
@Field(type = FieldType.Keyword)
private String SUPERVISORY_CODE;
@Field(type = FieldType.Text)
......@@ -63,11 +65,85 @@ public class ESEquipmentCategoryDto {
@Field(type = FieldType.Integer)
private Integer EQU_STATE;
@Field(type = FieldType.Text)
@Field(type = FieldType.Keyword)
private String STATUS;
@Field(type = FieldType.Long)
private Long REC_DATE;
@Field(type = FieldType.Text)
private String SAFETY_MANAGER;
@Field(type = FieldType.Text)
private String PHONE;
@Field(type = FieldType.Text)
private String MAINTAIN_UNIT;
@Field(type = FieldType.Text)
private String USE_INNER_CODE;
@Field(type = FieldType.Text)
private String FACTORY_NUM;
@Field(type = FieldType.Text)
private String PRODUCE_UNIT_NAME;
@Field(type = FieldType.Text)
private String INSPECT_REPORT;
@Field(type = FieldType.Text)
private String NEXT_INSPECT_DATE;
@Field(type = FieldType.Text)
private String CONSTRUCTION_TYPE;
@Field(type = FieldType.Text)
private String USC_UNIT_CREDIT_CODE;
@Field(type = FieldType.Text)
private String USC_UNIT_NAME;
@Field(type = FieldType.Text)
private String USC_DATE;
@Field(type = FieldType.Text)
private String EQU_DEFINE;
@Field(type = FieldType.Text)
private String EQU_DEFINE_CODE;
@Field(type = FieldType.Text)
private String PRODUCT_NAME;
@Field(type = FieldType.Text)
private String BRAND_NAME;
@Field(type = FieldType.Text)
private String EQU_TYPE;
@Field(type = FieldType.Text)
private String PRODUCE_DATE;
@Field(type = FieldType.Text)
private String DATA_SOURCE;
@Field(type = FieldType.Text)
private String WHETHER_VEHICLE_CYLINDER;
@Field(type = FieldType.Text)
private String WHETHER_SKID_MOUNTED_PRESSURE_VESSEL;
/**
* 问题状态
*/
@Field(type = FieldType.Text)
private String problemStatus;
/**
* 是否纳管:true - 已纳管 false-未纳管
*/
@Field(type = FieldType.Boolean)
private Boolean IS_INTO_MANAGEMENT;
}
......@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.tcm.api.dto.EquipExportDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.UseUnitCreditCodeCategoryDto;
import com.yeejoin.amos.boot.module.tcm.api.vo.EquipExportVo;
import com.yeejoin.amos.boot.module.tcm.api.entity.EquipmentCategory;
import com.yeejoin.amos.boot.module.tcm.api.vo.EquipExportVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
......@@ -50,4 +50,7 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> {
List<EquipExportVo> getEquipExportData(@Param("dto") EquipExportDto dto);
List<Map<String, Object>> selectJgUseInfo();
}
......@@ -362,4 +362,8 @@
</where>
</select>
<select id="selectJgUseInfo" resultType="java.util.Map">
select record, PROVINCE, CITY, COUNTY, USE_PLACE from idx_biz_jg_use_info
</select>
</mapper>
......@@ -25,15 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
......@@ -45,12 +37,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -76,7 +63,6 @@ public class EquipmentCategoryController extends BaseController {
@Value("${regulatory_code_prefix}")
String REGULATORY_CODE_PREFIX;
/**
* 新增装备分类
*
......@@ -458,5 +444,10 @@ public class EquipmentCategoryController extends BaseController {
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PutMapping(value = "/jg/all/update")
@ApiOperation(httpMethod = "PUT", value = "更新监管设备es", notes = "更新监管设备es")
public void jgAllUpdate(){
equipmentCategoryServiceImpl.updateJgAllEs();
}
}
package com.yeejoin.amos.boot.module.tcm.biz.dao;
import com.yeejoin.amos.boot.module.tcm.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
......
......@@ -10,26 +10,17 @@ import com.google.common.collect.Lists;
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.tcm.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.EquInfoDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.EquipExportDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.UseUnitCreditCodeCategoryDto;
import com.yeejoin.amos.boot.module.tcm.api.entity.CategoryOtherInfo;
import com.yeejoin.amos.boot.module.tcm.api.entity.EquipmentCategory;
import com.yeejoin.amos.boot.module.tcm.api.entity.EquipmentCategoryData;
import com.yeejoin.amos.boot.module.tcm.api.entity.SupervisoryCodeInfo;
import com.yeejoin.amos.boot.module.tcm.api.entity.UseInfo;
import com.yeejoin.amos.boot.module.tcm.api.entity.*;
import com.yeejoin.amos.boot.module.tcm.api.enums.EquimentEnum;
import com.yeejoin.amos.boot.module.tcm.api.enums.EquipmentCategoryEnum;
import com.yeejoin.amos.boot.module.tcm.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.tcm.api.enums.UnitTypeEnum;
import com.yeejoin.amos.boot.module.tcm.api.mapper.CategoryOtherInfoMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.EquipmentCategoryDataMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.SuperviseInfoMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.SupervisoryCodeInfoMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.UseInfoMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.*;
import com.yeejoin.amos.boot.module.tcm.api.service.IEquipmentCategoryService;
import com.yeejoin.amos.boot.module.tcm.api.vo.EquipExportVo;
import com.yeejoin.amos.boot.module.tcm.biz.dao.ESEquipmentCategory;
......@@ -41,10 +32,13 @@ import com.yeejoin.amos.component.feign.utils.FeignUtil;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.search.ClearScrollRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
......@@ -66,20 +60,12 @@ import org.typroject.tyboot.core.foundation.utils.DateUtil;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
......@@ -126,6 +112,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
private static final String LEVEL = "company";
private static final String EQUSTATE = "EQU_STATE";
private static final String USEPLACE = "USE_PLACE";
private static final int BATCH_SIZE = 1000;
private static String USE_CODE = "use_code";
private static String ORG_BRANCH_CODE = "supervise_org_code";
......@@ -162,6 +149,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Autowired
private RedisUtils redisUtils;
private final static String JG_ALL_ES_INDEX = "idx_biz_view_jg_all";
/**
* 分页查询
*/
......@@ -1374,4 +1363,98 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
}
return unitEquipCategoryList;
}
public void updateJgAllEs() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
List<Map<String, Object>> jgAllEsPage = equipmentCategoryMapper.selectJgUseInfo();
stopWatch.stop();
log.info("查询selectJgUseInfo耗时:{}", stopWatch.getTotalTimeMillis());
stopWatch.start();
// 设置查询条件和scroll参数
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
searchSourceBuilder.size(BATCH_SIZE); // 每次滚动返回的结果数
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
// 发送初始搜索请求
SearchRequest searchRequest = new SearchRequest(JG_ALL_ES_INDEX);
searchRequest.scroll(new TimeValue(60, TimeUnit.SECONDS)); // 设置Scroll上下文的持续时间
searchRequest.source(searchSourceBuilder);
List<ESEquipmentCategoryDto> recordList = Lists.newArrayList();
int saveCount = 0;
String scrollId = null;
try {
SearchResponse searchResponse;
while (true) {
if (scrollId == null) {
searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
log.info("查询jg_all_es耗时:{}", stopWatch.getTotalTimeMillis());
scrollId = searchResponse.getScrollId();
} else {
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
scrollRequest.scroll(new TimeValue(60, TimeUnit.SECONDS));
searchResponse = restHighLevelClient.scroll(scrollRequest, RequestOptions.DEFAULT);
log.info("处理es scroll 耗时:{}", stopWatch.getTotalTimeMillis());
if (searchResponse.getHits().getHits().length == 0) {
break;
}
}
processSearchHits(searchResponse.getHits().getHits(), jgAllEsPage, recordList);
if (recordList.size() >= BATCH_SIZE) {
esEquipmentCategory.saveAll(recordList);
recordList.clear();
log.info("处理es saveAll 耗时:{}", stopWatch.getTotalTimeMillis());
}
if (!ValidationUtil.isEmpty(recordList)) {
esEquipmentCategory.saveAll(recordList);
log.info("处理最后剩余数据完成~~");
}
saveCount++;
}
if (!recordList.isEmpty()) {
esEquipmentCategory.saveAll(recordList);
}
log.info("更新jg_all_es saveAll 次数:{},总耗时:{},", saveCount, stopWatch.getTotalTimeMillis());
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
restHighLevelClient.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
log.error("处理Elasticsearch数据时发生异常:", e);
}
}
private void processSearchHits(SearchHit[] hits, List<Map<String, Object>> jgAllEsPage, List<ESEquipmentCategoryDto> recordList) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (SearchHit hit : hits) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hit);
JSONObject dto2 = jsonObject.getJSONObject("sourceAsMap");
if (dto2 != null) {
ESEquipmentCategoryDto esDto = JSONObject.parseObject(JSON.toJSONString(dto2), ESEquipmentCategoryDto.class);
Map<String, Object> resultMap = jgAllEsPage.stream()
.filter(i -> i.get("record").equals(esDto.getSEQUENCE_NBR()))
.findFirst()
.orElse(null);
if (resultMap != null) {
Object province = resultMap.get("PROVINCE");
Object city = resultMap.get("CITY");
Object county = resultMap.get("COUNTY");
Object usePlace = resultMap.get("USE_PLACE");
esDto.setUSE_PLACE_CODE((province != null ? province + "#" : "")
+ (city != null ? city + "#" : "")
+ (county != null ? county.toString() : ""));
esDto.setUSE_SITE_CODE(usePlace != null ? usePlace.toString() : "");
recordList.add(esDto);
}
}
}
stopWatch.stop();
log.info("处理es 数据耗时:{}", stopWatch.getTotalTimeMillis());
}
}
\ No newline at end of file
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