Commit c14c28cc authored by 刘林's avatar 刘林

fix(jg):删除不是已认领的数据接口

parent f1f1879b
...@@ -283,4 +283,15 @@ public class DataHandlerController extends BaseController { ...@@ -283,4 +283,15 @@ public class DataHandlerController extends BaseController {
return ResponseHelper.buildResponse(dataHandlerService.initFactoryCarNumber2Es()); return ResponseHelper.buildResponse(dataHandlerService.initFactoryCarNumber2Es());
} }
/**
* @apiNote 删除ES和数据库中状态≠已认领的设备
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "PUT", value = "删除ES和数据库中状态≠已认领的设备(备份后谨慎操作,不可恢复)", notes = "删除ES和数据库中状态≠已认领的设备(备份后谨慎操作,不可恢复)")
@PutMapping(value = "/equip/deleteEquipWithStatusNotInClaimed")
public ResponseModel<Integer> deleteEquipWithStatusNotInClaimed(@RequestParam(value = "indices",defaultValue = "idx_biz_view_jg_all") String indices) {
return ResponseHelper.buildResponse(dataHandlerService.deleteEquipWithStatusNotInClaimed(indices));
}
} }
\ No newline at end of file
...@@ -53,6 +53,8 @@ import com.yeejoin.amos.boot.module.ymt.api.mapper.*; ...@@ -53,6 +53,8 @@ import com.yeejoin.amos.boot.module.ymt.api.mapper.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
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.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -60,7 +62,7 @@ import org.springframework.util.ObjectUtils; ...@@ -60,7 +62,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch; 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.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -72,7 +74,6 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -72,7 +74,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.alibaba.fastjson.JSON.toJSONString; import static com.alibaba.fastjson.JSON.toJSONString;
import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl.CONSTRUCTION_TYPE; import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl.CONSTRUCTION_TYPE;
import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl.CONSTRUCTION_TYPE_NAME; import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl.CONSTRUCTION_TYPE_NAME;
...@@ -84,7 +85,12 @@ import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNot ...@@ -84,7 +85,12 @@ import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNot
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class DataHandlerServiceImpl { public class DataHandlerServiceImpl {
public static final String IDX_BIZ_VIEW_JG_ALL = "idx_biz_view_jg_all";
public static final String IDX_BIZ_EQUIPMENT_INFO = "idx_biz_equipment_info";
public static final String STATUS = "STATUS";
public static final String record = "record";
public static final String SEQUENCE_NBR = "SEQUENCE_NBR";
private static final int BATCH_SIZE = 1000;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final JgRegistrationHistoryServiceImpl registrationHistoryService; private final JgRegistrationHistoryServiceImpl registrationHistoryService;
private final JgInstallationNoticeServiceImpl installationNoticeService; private final JgInstallationNoticeServiceImpl installationNoticeService;
...@@ -143,6 +149,10 @@ public class DataHandlerServiceImpl { ...@@ -143,6 +149,10 @@ public class DataHandlerServiceImpl {
private final IdxBizJgRegisterInfoMapper registerInfoMapper; private final IdxBizJgRegisterInfoMapper registerInfoMapper;
private final JgUseRegistrationManageServiceImpl registrationManageService;
private final SuperviseInfoMapper superviseInfoMapper;
/** /**
* 安装告知压力管道历史数据修复-详情中的设备列表修改为汇总表格式 * 安装告知压力管道历史数据修复-详情中的设备列表修改为汇总表格式
...@@ -1824,4 +1834,77 @@ public class DataHandlerServiceImpl { ...@@ -1824,4 +1834,77 @@ public class DataHandlerServiceImpl {
watch.stop(); watch.stop();
log.info("增量添加ORG_BRANCH_CODE为50X综合搜索数据-设备信息入库结束,耗时:{}秒", watch.getTotalTimeSeconds()); log.info("增量添加ORG_BRANCH_CODE为50X综合搜索数据-设备信息入库结束,耗时:{}秒", watch.getTotalTimeSeconds());
} }
public Integer deleteEquipWithStatusNotInClaimed(String indices) {
if (!Arrays.asList(IDX_BIZ_VIEW_JG_ALL, IDX_BIZ_EQUIPMENT_INFO).contains(indices)) {
throw new IllegalArgumentException("非法索引名,只允许使用 idx_biz_view_jg_all 或 idx_biz_equipment_info");
}
List<String> records = new ArrayList<>();
if (IDX_BIZ_VIEW_JG_ALL.equals(indices)) {
List<ESEquipmentCategoryDto> esList = queryUnclaimedEquipments(indices, ESEquipmentCategoryDto.class);
if (!CollectionUtils.isEmpty(esList)) {
records = extractSequenceNbr(esList);
esEquipmentCategory.deleteAll(esList);
}
} else {
List<ESEquipmentInfo> esList = queryUnclaimedEquipments(indices, ESEquipmentInfo.class);
if (!CollectionUtils.isEmpty(esList)) {
records = extractSequenceNbr(esList);
esEquipmentDao.deleteAll(esList);
}
}
if (records.isEmpty()) {
return 0;
}
List<List<String>> allDataList = Lists.partition(records, BATCH_SIZE);
for (List<String> tempDataList : allDataList) {
if (!CollectionUtils.isEmpty(tempDataList)) {
superviseInfoMapper.deleteDataAll(tempDataList);
}
}
return records.size();
}
private <T> List<T> queryUnclaimedEquipments(String index, Class<T> clazz) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
BoolQueryBuilder statusFilter = QueryBuilders.boolQuery()
.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery(STATUS, "已认领")))
.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(STATUS)))
.should(QueryBuilders.termQuery(STATUS, ""))
.minimumShouldMatch(1);
boolQuery.must(statusFilter);
try {
return registrationManageService.searchResponse(
index,
boolQuery,
hit -> {
JSONObject json = JSONObject.parseObject(hit.getSourceAsString(), JSONObject.class);
json.put(SEQUENCE_NBR, Objects.toString(json.get(SEQUENCE_NBR), ""));
return json.toJavaObject(clazz);
}
);
} catch (Exception ex) {
log.error("查询未认领设备异常:", ex);
return Collections.emptyList();
}
}
private <T> List<String> extractSequenceNbr(List<T> list) {
return list.stream()
.map(item -> {
try {
Method method = item.getClass().getMethod("getSEQUENCE_NBR");
Object value = method.invoke(item);
return Objects.toString(value, null);
} catch (Exception e) {
log.warn("反射获取 SEQUENCE_NBR 失败", e);
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
} }
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