Commit 22979784 authored by tianyiming's avatar tianyiming

气瓶基本信息同步es修改

parent 16caeba5
......@@ -87,4 +87,6 @@ public interface CylinderInfoMapper extends BaseMapper<CylinderInfo> {
Integer getInfoTotal();
void updateEsCylinderInfoStatus(@Param("ids")List<String> ids);
}
......@@ -338,4 +338,11 @@
where ci.is_not_es IS NULL
AND region_code is not null
</select>
<update id="updateEsCylinderInfoStatus">
UPDATE tz_cylinder_info SET "is_not_es" = 1 WHERE "sequence_nbr" IN
<foreach collection="ids" separator="," item="id" open="(" close=")">
#{id}
</foreach>
</update>
</mapper>
......@@ -567,7 +567,7 @@ public class CylinderInfoController extends BaseController {
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/saveCyinderInfo")
@ApiOperation(httpMethod = "GET", value = "气瓶基本信息存入es", notes = "气瓶基本信息存入es")
public void saveCyinderInfo() {
......@@ -584,30 +584,27 @@ public class CylinderInfoController extends BaseController {
return;
}
for (int i = 0; i <= times; i++) {
cylinderInfoPage.setCurrent(i);
cylinderInfoPage.setCurrent(0);
cylinderInfoPage.setSize(1000);
cylinderInfoPage = cylinderInfoServiceImpl.getCyinderInfoList(cylinderInfoPage);
if (!ObjectUtils.isEmpty(cylinderInfoPage)) {
if (!ObjectUtils.isEmpty(cylinderInfoPage) && !ObjectUtils.isEmpty(cylinderInfoPage.getRecords())) {
cylinderInfoServiceImpl.saveCylinderInfo2ES(cylinderInfoPage.getRecords());
}
// for (CylinderInfoDto ci : cylinderInfoPage.getRecords()) {
// cylinderInfoServiceImpl.saveCylinderInfoToES(ci);
// }
}
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "/getCyinderInfo")
@ApiOperation(httpMethod = "GET", value = "气瓶基本信息存入es入口", notes = "气瓶基本信息存入es入口")
public Page<CylinderInfoDto> getCyinderInfo() {
public ResponseModel getCyinderInfo() {
Page<CylinderInfoDto> cylinderInfoPage = new Page<>();
cylinderInfoPage.setCurrent(1);
cylinderInfoPage.setSize(1000);
cylinderInfoPage = cylinderInfoServiceImpl.getCyinderInfoList(cylinderInfoPage);
for (CylinderInfoDto ci : cylinderInfoPage.getRecords()) {
cylinderInfoServiceImpl.saveCylinderInfoToES(ci);
}
return cylinderInfoServiceImpl.getCyinderInfoList(cylinderInfoPage);
if (!ObjectUtils.isEmpty(cylinderInfoPage)) {
cylinderInfoServiceImpl.saveCylinderInfo2ES(cylinderInfoPage.getRecords());
}
return ResponseHelper.buildResponse(true);
}
......@@ -661,10 +658,6 @@ public class CylinderInfoController extends BaseController {
for (int i = 0; i <= times; i++) {
recordDtoPage.setCurrent(1);
recordDtoPage.setSize(1000);
// CylinderFillingRecordDto cylinderFillingRecordDto = new CylinderFillingRecordDto();
// if (StringUtils.isEmpty(cylinderFillingRecordDto.getSequenceCode())) {
// cylinderFillingRecordDto.setAppId("9B150BB7D0C21A7A62BD6837E14A44BF");
// }
Page<ESCylinderFillingRecordDto> cyinderFillingRecord = cylinderFillingRecordServiceImpl.getCyinderFillingRecord(recordDtoPage);
if (!ObjectUtils.isEmpty(cyinderFillingRecord)) {
cylinderFillingRecordServiceImpl.saveCylinderFillingRecord2ES(cyinderFillingRecord.getRecords());
......
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.cylinder.api.dto.WarningMsgDto;
import com.yeejoin.amos.boot.module.cylinder.api.entity.ESCylinderInfoDto;
......@@ -40,6 +41,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
......@@ -746,18 +748,17 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
@SchedulerLock(name = "cylinderInfoToESTask", lockAtMostFor = "PT6H")
public void setTimeSaveCylinderInfoToES() {
Page<CylinderInfoDto> cylinderInfoPage = new Page<>();
Page<CylinderInfoDto> cyinderInfoList = cylinderInfoMapper.getCyinderInfoList(cylinderInfoPage);
Long count = cyinderInfoList.getCurrent();
Long times = 0L;
Integer count = getInfoTotal();
Integer times = 0;
if (count != 0) {
times = count / 1000;
Long last = count % 1000;
int last = count % 1000;
if (last > 0) {
times++;
}
}
for (int i = 0; i <= times; i++) {
cylinderInfoPage.setCurrent(1);
cylinderInfoPage.setCurrent(0);
cylinderInfoPage.setSize(1000);
cylinderInfoPage = cylinderInfoMapper.getCyinderInfoList(cylinderInfoPage);
if (!ObjectUtils.isEmpty(cylinderInfoPage)) {
......@@ -772,19 +773,27 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
@Override
public void saveCylinderInfo2ES(List<CylinderInfoDto> records) {
List<ESCylinderInfoDto> esCylinderInfoDto = new ArrayList<>();
List<CylinderInfo> CylinderInfoList = new ArrayList<>();
List<String> ids = Lists.newArrayList();
for (CylinderInfoDto record : records) {
ESCylinderInfoDto esCylinderInfo = new ESCylinderInfoDto();
BeanUtils.copyProperties(record, esCylinderInfo);
esCylinderInfoDto.add(esCylinderInfo);
CylinderInfo cylinderInfo = new CylinderInfo();
BeanUtils.copyProperties(record, cylinderInfo);
cylinderInfo.setSequenceNbr(record.getSequenceNbr());
cylinderInfo.setIsNotEs("1");
CylinderInfoList.add(cylinderInfo);
ids.add(String.valueOf(record.getSequenceNbr()));
}
StopWatch stopWatch = new StopWatch();
stopWatch.start();
esCylinderInfoRepository.saveAll(esCylinderInfoDto);
this.updateBatchById(CylinderInfoList);
stopWatch.stop();
if (log.isInfoEnabled()) {
log.info("批量存入es耗时:{} 秒", stopWatch.getTotalTimeSeconds());
}
StopWatch stopWatch1 = new StopWatch();
stopWatch1.start();
cylinderInfoMapper.updateEsCylinderInfoStatus(ids);
stopWatch1.stop();
if (log.isInfoEnabled()) {
log.info("批量更新业务数据耗时:{} 秒", stopWatch1.getTotalTimeSeconds());
}
}
@Override
......
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