Commit 9bbcb8de authored by tianyiming's avatar tianyiming

feat(statistics): 新增根据传入code及limit修改ORG_BRANCH_CODE为50*X综合搜索数据

parent aaaa0b2a
......@@ -25,7 +25,15 @@ public interface TzsCustomFilterMapper extends BaseMapper<TzsCustomFilter> {
JSONArray queryEquCategory(@Param("type") String type, @Param("description") String description);
Page<String> selectRecords(Page<String> page);
Page<String> selectGasRecords(Page<String> page);
List<String> selectRecords(@Param("code") String code, @Param("limit") long limit);
void addGas(@Param("refreshRecords")List<String> refreshRecords);
Integer selectRecordCount(String code);
void setOrgBranchCodeIsNullByRecords(@Param("records") List<String> records);
void updateOrgBranchCodeByRecords(@Param("dataList") List<Map<String, Object>> dataList);
}
......@@ -34,7 +34,7 @@
<select id="selectEquipmentCategoryCountByParentId" resultType="java.lang.Integer">
select count(1) from tz_equipment_category where is_delete = 0 and parent_id = #{parentId}
</select>
<select id="selectRecords" resultType="java.lang.String">
<select id="selectGasRecords" resultType="java.lang.String">
SELECT
ibjui."RECORD"
FROM
......@@ -50,6 +50,58 @@
AND "CLAIM_STATUS" = '已认领'
order by ibjui."RECORD" desc
</select>
<select id="selectRecords" resultType="java.lang.String">
SELECT
ibjsi."RECORD"
FROM
amos_tzs_biz.idx_biz_jg_supervision_info ibjsi
LEFT JOIN amos_tzs_biz.idx_biz_jg_register_info ibjri ON ibjsi."RECORD" = ibjri."RECORD"
WHERE
"ORG_BRANCH_CODE" = '50*X'
<if test="code != '2300'">
AND ibjri."EQU_LIST" = #{code}
<if test="code == '2000'">
AND ibjri."EQU_CATEGORY" != '2300'
</if>
</if>
<if test="code == '2300'">
AND ibjri."EQU_CATEGORY" = #{code}
</if>
limit #{limit}
</select>
<select id="selectRecordCount" resultType="java.lang.Integer">
SELECT
count(1)
FROM
amos_tzs_biz.idx_biz_jg_supervision_info ibjsi
LEFT JOIN amos_tzs_biz.idx_biz_jg_register_info ibjri ON ibjsi."RECORD" = ibjri."RECORD"
WHERE
"ORG_BRANCH_CODE" = '50*X'
<if test="code != '2300'">
AND ibjri."EQU_LIST" = #{code}
<if test="code == '2000'">
AND ibjri."EQU_CATEGORY" != '2300'
</if>
</if>
<if test="code == '2300'">
AND ibjri."EQU_CATEGORY" = #{code}
</if>
</select>
<update id="setOrgBranchCodeIsNullByRecords">
update amos_tzs_biz.idx_biz_jg_supervision_info set "ORG_BRANCH_CODE" = null where "RECORD" in
<foreach collection="records" separator="," item="record" open="(" close=");">
#{record}
</foreach>
</update>
<update id="updateOrgBranchCodeByRecords">
<foreach collection="dataList" item="data" separator=";">
update amos_tzs_biz.idx_biz_jg_supervision_info
set "ORG_BRANCH_CODE" = #{data.orgBranchCode}
where "RECORD" = #{data.record}
</foreach>
</update>
<insert id="addGas">
INSERT INTO "amos_tzs_biz"."idx_biz_jg_supervision_info" ("SEQUENCE_NBR", "RECORD")
......
......@@ -496,4 +496,16 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController {
public ResponseModel<JSONArray> queryInspectionDate() {
return ResponseHelper.buildResponse(statisticalAnalysisService.queryInspectionDate());
}
/**
* @param
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/updateDataByOrgBranchCode")
@ApiOperation(httpMethod = "GET", value = "修改ORG_BRANCH_CODE为50*X综合搜索数据-设备", notes = "修改ORG_BRANCH_CODE为50*X综合搜索数据-设备")
public ResponseModel<Object> updateDataByOrgBranchCode(@RequestParam(value = "code") String code, @RequestParam(value = "limit") Integer limit) {
return ResponseHelper.buildResponse(statisticalAnalysisService.updateDataByOrgBranchCode(code, limit));
}
}
......@@ -17,6 +17,7 @@ import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RequestContextWrapper;
import com.yeejoin.amos.boot.module.common.api.dao.EsEquipmentDao;
import com.yeejoin.amos.boot.module.common.api.dto.TechParamItem;
import com.yeejoin.amos.boot.module.common.api.entity.ESEquipmentInfo;
import com.yeejoin.amos.boot.module.common.biz.utils.TechParamUtil;
......@@ -125,6 +126,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private final String or = "or";
private final String and = "and";
private final EsEquipmentDao esEquipmentDao;
private final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
......@@ -4039,7 +4042,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
for (int j = 0; j <= times; j++) {
recordDtoPage.setCurrent(j + 1);
recordDtoPage.setSize(5000);
Page<String> refreshRecords = tzsCustomFilterMapper.selectRecords(recordDtoPage);
Page<String> refreshRecords = tzsCustomFilterMapper.selectGasRecords(recordDtoPage);
if (!ObjectUtils.isEmpty(refreshRecords) && refreshRecords.getRecords().size() > 0) {
total += refreshRecords.getRecords().size();
tzsCustomFilterMapper.addGas(refreshRecords.getRecords());
......@@ -4047,4 +4050,65 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
}
return total;
}
public Object updateDataByOrgBranchCode(String code, Integer limit) {
SearchRequest request = new SearchRequest();
request.indices(StatisticalAnalysisEnum.equip.getKey());
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.trackTotalHits(true);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 1、从数据库查询对应设备类型下50*X得数据record
Integer count = tzsCustomFilterMapper.selectRecordCount(code);
if (count == 0) {
return "数据库中该数据分类下无需要修改的数据";
}
limit = count > limit ? limit : count;
List<String> records = tzsCustomFilterMapper.selectRecords(code, limit);
// 2、从es中查询对应record的数据
boolMust.must(QueryBuilders.termsQuery("SEQUENCE_NBR.keyword", records));
builder.query(boolMust);
builder.from(0);
builder.size(limit);
request.source(builder);
// 数据库和es中都为50*X的数据集合
List<String> allNotDateList = new ArrayList<>();
// 数据库中为50*X的数据集合,但es中不为50*X的数据集合
List<Map<String, Object>> dataList = new ArrayList<>();
try {
SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
for (SearchHit hit : response.getHits().getHits()) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hit);
JSONObject dto = jsonObject.getJSONObject("sourceAsMap");
if (dto.containsKey("ORG_BRANCH_CODE")) {
//3、判断查询回来的数据中是否为50*X,如果是50*X,则记录下来进行做置空处理/如果不为50*X,则记录下来进行数据库修复
if ("50*X".equals(dto.getString("ORG_BRANCH_CODE"))) {
allNotDateList.add(dto.getString("SEQUENCE_NBR"));
} else {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("record", dto.getString("SEQUENCE_NBR"));
dataMap.put("orgBranchCode", dto.getString("ORG_BRANCH_CODE"));
dataList.add(dataMap);
}
}
}
//4、是50*X的进行es和数据库的双向修改/不是50*X的只需要做数据库修改
if(!ObjectUtils.isEmpty(allNotDateList)){
tzsCustomFilterMapper.setOrgBranchCodeIsNullByRecords(allNotDateList);
Iterable<ESEquipmentInfo> allById = esEquipmentDao.findAllById(allNotDateList);
if(!ObjectUtils.isEmpty(allById)){
for (ESEquipmentInfo esEquipmentInfo : allById) {
esEquipmentInfo.setORG_BRANCH_CODE("");
}
}
esEquipmentDao.saveAll(allById);
}
// 修改为es中的数据
if(!ObjectUtils.isEmpty(dataList)){
tzsCustomFilterMapper.updateOrgBranchCodeByRecords(dataList);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return records;
}
}
\ 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