Commit aff4bd00 authored by 曹盼盼's avatar 曹盼盼

es数据同步

parent 0ef4d2aa
......@@ -63,6 +63,11 @@ public class SuperviseInfo extends AbstractEquipBaseEntity {
@TableField(value ="\"IMPORTANT_PLACES\"")
private String importantPlaces;
/**
* 是否同步到es中
*/
@TableField(value ="\"IS_NOT_ES\"")
private Integer isNotEs;
......
......@@ -17,6 +17,7 @@ import com.yeejoin.amos.boot.module.tzs.api.enums.EquipmentCategoryEnum;
import com.yeejoin.amos.boot.module.tzs.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.tzs.api.mapper.CategoryOtherInfoMapper;
import com.yeejoin.amos.boot.module.tzs.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.tzs.api.mapper.SuperviseInfoMapper;
import com.yeejoin.amos.boot.module.tzs.api.mapper.SupervisoryCodeInfoMapper;
import com.yeejoin.amos.boot.module.tzs.api.service.IEquipmentCategoryService;
import com.yeejoin.amos.boot.module.tzs.biz.dao.ESCylinderFillingRecordRepository;
......@@ -60,6 +61,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
ESEquipmentCategory esEquipmentCategory;
@Autowired
private SuperviseInfoMapper superviseInfoMapper;
@Autowired
EquipmentCategoryMapper equipmentCategoryMapper;
@Value("classpath:/json/equipCategory.json")
......@@ -744,4 +748,69 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
esEquipmentCategory.save(dto);
}
}
//分页查询所有数据
public Page<Map<String, Object>> getAll(Map<String, Object> map) {
String tableName = map.get(TABLENAME).toString();
Assert.hasText(tableName, "表名不能为空");
String selectSql = " SELECT * FROM " + tableName ;
Integer number = ValidationUtil.isEmpty(map.get("number")) ? 0 : Integer.valueOf(map.get("number").toString());
Integer size = ValidationUtil.isEmpty(map.get("size")) ? 0 : Integer.valueOf(map.get("size").toString());
Page<Map<String, Object>> page = new Page<>(number, size);
int begin = (number - 1) * size;
if (size > 0) {
selectSql = selectSql+" LIMIT " + begin + "," + size;
}
List<Map<String, Object>> mapList = bizJdbcTemplate.queryForList(selectSql);
page.setRecords(mapList);
return page;
}
//查询总条数
public Long counts(Map<String, Object> map){
String tableName = map.get(TABLENAME).toString();
Assert.hasText(tableName, "表名不能为空");
String countSql = " SELECT COUNT(SEQUENCE_NBR) count FROM " + tableName;
Long count = bizJdbcTemplate.queryForObject(countSql, Long.class);
return count;
}
/**
* es数据同步
* @return
*/
@Scheduled(cron = "${tzs.equipmentCategory.cron}")
public void saveEs() {
Map<String, Object> map = new HashMap<>();
map.put(TABLENAME,"idx_biz_view_jg_all");
Long counts = counts(map);
Long times = counts / 1000;
Long yushu = counts % 1000;
if (yushu > 0) {
times++;
}
for (int i = 1; i <=times; i++) {
map.put("number",i);
map.put("size",1000);
Page<Map<String, Object>> page = getAll(map);
for (Map<String, Object> record : page.getRecords()) {
if (ValidationUtil.isEmpty(record.get("IS_NOT_ES")) ) {
saveESEquipmentCategory(record);
}
}
}
}
/**es保存设备数据*/
public ESEquipmentCategoryDto saveESEquipmentCategory(Map<String, Object> map) {
ESEquipmentCategoryDto dto = JSONObject.parseObject(JSONObject.toJSONString(map), ESEquipmentCategoryDto.class);
ESEquipmentCategoryDto save = esEquipmentCategory.save(dto);
if (!ObjectUtils.isEmpty(save)) {
//同步到es后修改
SuperviseInfo superviseInfo = new SuperviseInfo();
superviseInfo.setIsNotEs(1);
superviseInfoMapper.update(superviseInfo, new QueryWrapper<SuperviseInfo>().eq("SEQUENCE_NBR", map.get("SEQUENCE_NBR").toString()));
}
return save;
}
}
\ No newline at end of file
spring.application.name=TZS
spring.application.name=TZS-cpp
server.servlet.context-path=/tzs
server.port=11000
spring.profiles.active=dev3
......@@ -10,7 +10,7 @@ mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
##liquibase
spring.liquibase.change-log = classpath:/db/changelog/changelog-master.xml
spring.liquibase.enabled= true
spring.liquibase.enabled= false
......
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