Commit eb00cbe4 authored by kinky2014's avatar kinky2014

增加气瓶数据同步更新

parent bd39c65c
package com.yeejoin.amos.api.openapi.face.service;
import com.google.common.collect.Lists;
import com.yeejoin.amos.api.openapi.face.model.*;
import com.yeejoin.amos.api.openapi.face.orm.dao.ESCylinderFillingRecordRepository;
import com.yeejoin.amos.api.openapi.face.orm.dao.ESCylinderInfoRepository;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.cylinder.api.entity.ESCylinderFillingRecordDto;
import com.yeejoin.amos.boot.module.cylinder.api.entity.ESCylinderInfoDto;
import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.*;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.utils.Bean;
import com.baomidou.dynamic.datasource.annotation.DS;
......@@ -32,6 +38,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Component
@DS("tzs")
public class SyncCylinderDataService
......@@ -80,6 +87,8 @@ public class SyncCylinderDataService
@Autowired
ESCylinderFillingRecordRepository esCylinderFillingRecordRepository;
@Autowired
ESCylinderInfoRepository esCylinderInfoRepository;
public void syncCylinderUnit(List<TmCylinderUnitModel> cylinderUnitDto) {
// List<CylinderUnit> cylinderUnits = Bean.toModels(cylinderUnitDto,CylinderUnit.class);
......@@ -169,4 +178,37 @@ public class SyncCylinderDataService
cylinderFillingRecordMapper.updateCylinderFillingToEsStatus(ids);
}
public void createCylinderInfo2ES(TmCylinderInfoModel cylinderInfoModel) {
CylinderInfoDto cylinderInfoDto = Bean.toModel(cylinderInfoModel, new CylinderInfoDto());
List<ESCylinderInfoDto> esCylinderInfoDto = new ArrayList<>();
ESCylinderInfoDto esCylinderInfo = new ESCylinderInfoDto();
BeanUtils.copyProperties(cylinderInfoDto, esCylinderInfo);
esCylinderInfoDto.add(esCylinderInfo);
try {
esCylinderInfo.setInspectionDateMs(ObjectUtils.isEmpty(esCylinderInfo.getInspectionDate()) ? 0L : DateUtils.dateParse(esCylinderInfo.getInspectionDate(), DateUtils.DATE_TIME_PATTERN).getTime());
} catch (ParseException e) {
throw new RuntimeException(e);
}
List<String> ids = Lists.newArrayList();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
esCylinderInfoRepository.saveAll(esCylinderInfoDto);
ids.add(String.valueOf(cylinderInfoDto.getSequenceNbr()));
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());
}
}
}
......@@ -63,7 +63,6 @@ public class TmCylinderFillingExamineService extends BaseService<TmCylinderFilli
return bizTokenModel.getAppId();
}
@Transactional(rollbackFor= {Exception.class})
private void syncCylinderFillingExamine(List<TmCylinderFillingExamineModel> model ) {
syncCylinderDataService.syncCylinderFillingExamine(model);
}
......
......@@ -71,12 +71,12 @@ public class TmCylinderInfoService extends BaseService<TmCylinderInfoModel, TmCy
cylinderInfoModel.setRecDate(new Date());
cylinderInfoModel.setAppId(getAppId());
createCylinderInfo2ES(cylinderInfoModel);
syncCylinderDataService.createCylinderInfo2ES(cylinderInfoModel);
this.createWithModel(cylinderInfoModel);
}
return "OK";
}
@Transactional(rollbackFor= {Exception.class})
private void syncCylinderInfo(List<TmCylinderInfoModel> model ) {
syncCylinderDataService.syncCylinderInfo(model);
}
......@@ -87,34 +87,4 @@ public class TmCylinderInfoService extends BaseService<TmCylinderInfoModel, TmCy
}
public void createCylinderInfo2ES(TmCylinderInfoModel cylinderInfoModel) {
CylinderInfoDto cylinderInfoDto = Bean.toModel(cylinderInfoModel, new CylinderInfoDto());
List<ESCylinderInfoDto> esCylinderInfoDto = new ArrayList<>();
ESCylinderInfoDto esCylinderInfo = new ESCylinderInfoDto();
BeanUtils.copyProperties(cylinderInfoDto, esCylinderInfo);
esCylinderInfoDto.add(esCylinderInfo);
try {
esCylinderInfo.setInspectionDateMs(ObjectUtils.isEmpty(esCylinderInfo.getInspectionDate()) ? 0L : DateUtils.dateParse(esCylinderInfo.getInspectionDate(), DateUtils.DATE_TIME_PATTERN).getTime());
} catch (ParseException e) {
throw new RuntimeException(e);
}
List<String> ids = Lists.newArrayList();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
esCylinderInfoRepository.saveAll(esCylinderInfoDto);
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());
}
}
}
......@@ -53,7 +53,6 @@ public class TmCylinderUnitService extends BaseService<TmCylinderUnitModel, TmCy
}
return "OK";
}
@Transactional(rollbackFor= {Exception.class})
private void syncCylinderUnitModel(List<TmCylinderUnitModel> model ) {
syncCylinderDataService.syncCylinderUnit(model);
}
......
......@@ -509,8 +509,8 @@
</foreach>
</update>
<insert id="saveOrUpdateBatch">
INSERT INTO "amos_tzs_biz"."tz_cylinder_info"
<insert id="saveOrUpdateBatch" parameterType="com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderInfo">
INSERT INTO "tz_cylinder_info" ("sequence_nbr","unit_name","factory_num","cylinder_status","cylinder_variety","volume","manufacturing_date","manufacturing_unit","unit_inner_code","sequence_code","early_warning_level","early_warning_level_cal_date","end_custom_code","rec_date","rec_user_id","sync_date","sync_state","app_id","integrity","longitude","latitude","credit_code","filling_media","product_name","product_qualified","proof_quality","supervision_inspec","type_experiments","valve_manufactur_unit","nominal_work_pressure","cylinder_variety_name","filling_media_name","is_not_es")
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.sequenceNbr},
......@@ -548,7 +548,6 @@
null)
</foreach>
on conflict (app_id,sequence_code) do update set
"sequence_nbr" = EXCLUDED."sequence_nbr",
"unit_name" = EXCLUDED."unit_name",
"factory_num" = EXCLUDED."factory_num",
"cylinder_status" = EXCLUDED."cylinder_status",
......@@ -579,7 +578,6 @@
"valve_manufactur_unit" = EXCLUDED."valve_manufactur_unit",
"nominal_work_pressure" = EXCLUDED."nominal_work_pressure",
"cylinder_variety_name" = EXCLUDED."cylinder_variety_name",
"filling_media_name" = EXCLUDED."filling_media_name",
"is_not_es" = EXCLUDED."is_not_es"
"filling_media_name" = EXCLUDED."filling_media_name"
</insert>
</mapper>
......@@ -79,7 +79,7 @@
and not EXISTS (select 1 from tz_cylinder_question_info q where u.credit_code = q.question_object_id and q.question_type = #{questionType} )
</select>
<insert id="saveOrUpdateBatch" parameterType="com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnit">
INSERT INTO "tz_cylinder_unit"(sequence_nbr,unit_id,region_code,unit_name,credit_code,address,unit_person,person_mobile_phone,person_telephone,postal_code,rec_date,rec_user_id,sync_date,sync_state,app_id,security_adm,security_adm_phone,region_name)
INSERT INTO "tz_cylinder_unit" ("sequence_nbr","unit_id","region_code","unit_name","credit_code","address","unit_person","person_mobile_phone","person_telephone","postal_code","rec_date","rec_user_id","sync_date","sync_state","app_id","security_adm","security_adm_phone","region_name")
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.sequenceNbr},
......
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