Commit 63f45e00 authored by tianbo's avatar tianbo

refactor(jg): 优化设备注册信息的ES数据同步和删除逻辑

- 将selectDataById方法重命名为selectJgAllViewDataById以提高语义清晰度 - 在设备注册服务中实现ES数据删除的回滚机制,确保数据一致性 - 重构删除逻辑,先查询原有ES数据再执行删除操作 - 统一ES数据构建方法,提高代码复用性 - 完善异常处理机制,在操作失败时恢复ES数据状态
parent 8fd6fe17
...@@ -842,7 +842,7 @@ public class DataDockServiceImpl { ...@@ -842,7 +842,7 @@ public class DataDockServiceImpl {
* @param record 设备唯一编码 * @param record 设备唯一编码
*/ */
private void saveEquInfoToEs(String record, String isCompleteXa) { private void saveEquInfoToEs(String record, String isCompleteXa) {
Map<String, Object> map = categoryOtherInfoMapper.selectDataById(record); Map<String, Object> map = categoryOtherInfoMapper.selectJgAllViewDataById(record);
ESEquipmentCategoryDto equipmentCategoryDto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class); ESEquipmentCategoryDto equipmentCategoryDto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class);
if (!ObjectUtils.isEmpty(equipmentCategoryDto)) { if (!ObjectUtils.isEmpty(equipmentCategoryDto)) {
long recTime; long recTime;
...@@ -2949,7 +2949,7 @@ public class DataDockServiceImpl { ...@@ -2949,7 +2949,7 @@ public class DataDockServiceImpl {
idxBizJgUseInfoService.updateById(useInfo); idxBizJgUseInfoService.updateById(useInfo);
// es更新 // es更新
Map<String, Object> map = categoryOtherInfoMapper.selectDataById(useInfo.getRecord()); Map<String, Object> map = categoryOtherInfoMapper.selectJgAllViewDataById(useInfo.getRecord());
ESEquipmentCategoryDto equipmentCategoryDto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class); ESEquipmentCategoryDto equipmentCategoryDto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class);
equipmentCategoryDto.setIS_INTO_MANAGEMENT(Boolean.TRUE); equipmentCategoryDto.setIS_INTO_MANAGEMENT(Boolean.TRUE);
esEquipmentCategory.save(equipmentCategoryDto); esEquipmentCategory.save(equipmentCategoryDto);
......
...@@ -106,7 +106,6 @@ import java.util.concurrent.atomic.AtomicReference; ...@@ -106,7 +106,6 @@ 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 java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport;
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;
...@@ -1141,7 +1140,7 @@ public class DataHandlerServiceImpl { ...@@ -1141,7 +1140,7 @@ public class DataHandlerServiceImpl {
} }
String[] recordArr = records.trim().split(","); String[] recordArr = records.trim().split(",");
for (String record : recordArr) { for (String record : recordArr) {
Map<String, Object> map = categoryOtherInfoMapper.selectDataById(record); Map<String, Object> map = categoryOtherInfoMapper.selectJgAllViewDataById(record);
categoryOtherInfoMapper.updateEsStatus(record); categoryOtherInfoMapper.updateEsStatus(record);
ESEquipmentCategoryDto dto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class); ESEquipmentCategoryDto dto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class);
Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(record); Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(record);
......
...@@ -13,7 +13,9 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisKey; ...@@ -13,7 +13,9 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.biz.common.utils.SnowflakeIdUtil; import com.yeejoin.amos.boot.biz.common.utils.SnowflakeIdUtil;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory; import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dao.EsEquipmentDao;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto; import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.api.entity.ESEquipmentInfo;
import com.yeejoin.amos.boot.module.jg.api.dto.ShCarDto; import com.yeejoin.amos.boot.module.jg.api.dto.ShCarDto;
import com.yeejoin.amos.boot.module.jg.api.entity.*; import com.yeejoin.amos.boot.module.jg.api.entity.*;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum; import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
...@@ -94,6 +96,8 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp ...@@ -94,6 +96,8 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
@Resource @Resource
private ESEquipmentCategory esEquipmentCategory; private ESEquipmentCategory esEquipmentCategory;
@Resource @Resource
private EsEquipmentDao esEquipmentDao;
@Resource
private TzsServiceFeignClient tzsServiceFeignClient; private TzsServiceFeignClient tzsServiceFeignClient;
@Resource @Resource
private JgVehicleInformationServiceImpl vehicleInformationService; private JgVehicleInformationServiceImpl vehicleInformationService;
...@@ -707,13 +711,23 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp ...@@ -707,13 +711,23 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
* 认领过程中报错,回滚第一步的es数据 * 认领过程中报错,回滚第一步的es数据
*/ */
public void handleClaimFailed(List<String> records) { public void handleClaimFailed(List<String> records) {
if (!records.isEmpty()) { esEquipmentCategory.deleteAll(this.buildEquipCategoryData(records));
records.forEach(record -> { esEquipmentDao.deleteAll(this.buildEquipData(records));
Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(record); }
if (!ObjectUtils.isEmpty(data)) {
esEquipmentCategory.deleteById(record); private Iterable<? extends ESEquipmentInfo> buildEquipData(List<String> records) {
} return records.stream().map(record->{
}); ESEquipmentInfo esEquipmentInfo = new ESEquipmentInfo();
} esEquipmentInfo.setSEQUENCE_NBR(record);
return esEquipmentInfo;
}).collect(Collectors.toList());
}
private Iterable<? extends ESEquipmentCategoryDto> buildEquipCategoryData(List<String> records) {
return records.stream().map(record->{
ESEquipmentCategoryDto esEquipmentInfo = new ESEquipmentCategoryDto();
esEquipmentInfo.setSEQUENCE_NBR(record);
return esEquipmentInfo;
}).collect(Collectors.toList());
} }
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ public interface CategoryOtherInfoMapper extends BaseMapper<CategoryOtherInfo> { ...@@ -30,7 +30,7 @@ public interface CategoryOtherInfoMapper extends BaseMapper<CategoryOtherInfo> {
int updateOtherInfo(String supervisorCode, String editStatus); int updateOtherInfo(String supervisorCode, String editStatus);
Map<String, Object> selectDataById(String id); Map<String, Object> selectJgAllViewDataById(String id);
CategoryOtherInfo queryInitCode(@Param("initCode") @NonNull String initCode); CategoryOtherInfo queryInitCode(@Param("initCode") @NonNull String initCode);
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
LEFT JOIN idx_biz_jg_use_info ibjui ON ibjoi.RECORD = ibjui.RECORD LEFT JOIN idx_biz_jg_use_info ibjui ON ibjoi.RECORD = ibjui.RECORD
WHERE ibjoi."RECORD" = #{record} WHERE ibjoi."RECORD" = #{record}
</select> </select>
<select id="selectDataById" resultType="java.util.Map"> <select id="selectJgAllViewDataById" resultType="java.util.Map">
SELECT "SEQUENCE_NBR", SELECT "SEQUENCE_NBR",
"REC_DATE", "REC_DATE",
"CREATE_DATE", "CREATE_DATE",
......
...@@ -1664,7 +1664,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1664,7 +1664,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Override @Override
public void checkEsData(String id) { public void checkEsData(String id) {
Map<String, Object> map = categoryOtherInfoMapper.selectDataById(id); Map<String, Object> map = categoryOtherInfoMapper.selectJgAllViewDataById(id);
categoryOtherInfoMapper.updateEsStatus(id); categoryOtherInfoMapper.updateEsStatus(id);
ESEquipmentCategoryDto dto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class); ESEquipmentCategoryDto dto = JSON.parseObject(toJSONString(map), ESEquipmentCategoryDto.class);
Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(id); Optional<ESEquipmentCategoryDto> data = esEquipmentCategory.findById(id);
......
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