Commit eb00cbe4 authored by kinky2014's avatar kinky2014

增加气瓶数据同步更新

parent bd39c65c
package com.yeejoin.amos.api.openapi.face.service; 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.model.*;
import com.yeejoin.amos.api.openapi.face.orm.dao.ESCylinderFillingRecordRepository; 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.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.cylinder.api.entity.ESCylinderFillingRecordDto; 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.dto.*;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.*; import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.utils.Bean; import org.typroject.tyboot.core.foundation.utils.Bean;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
...@@ -32,6 +38,7 @@ import java.util.ArrayList; ...@@ -32,6 +38,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j
@Component @Component
@DS("tzs") @DS("tzs")
public class SyncCylinderDataService public class SyncCylinderDataService
...@@ -80,6 +87,8 @@ public class SyncCylinderDataService ...@@ -80,6 +87,8 @@ public class SyncCylinderDataService
@Autowired @Autowired
ESCylinderFillingRecordRepository esCylinderFillingRecordRepository; ESCylinderFillingRecordRepository esCylinderFillingRecordRepository;
@Autowired
ESCylinderInfoRepository esCylinderInfoRepository;
public void syncCylinderUnit(List<TmCylinderUnitModel> cylinderUnitDto) { public void syncCylinderUnit(List<TmCylinderUnitModel> cylinderUnitDto) {
// List<CylinderUnit> cylinderUnits = Bean.toModels(cylinderUnitDto,CylinderUnit.class); // List<CylinderUnit> cylinderUnits = Bean.toModels(cylinderUnitDto,CylinderUnit.class);
...@@ -169,4 +178,37 @@ public class SyncCylinderDataService ...@@ -169,4 +178,37 @@ public class SyncCylinderDataService
cylinderFillingRecordMapper.updateCylinderFillingToEsStatus(ids); 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 ...@@ -63,7 +63,6 @@ public class TmCylinderFillingExamineService extends BaseService<TmCylinderFilli
return bizTokenModel.getAppId(); return bizTokenModel.getAppId();
} }
@Transactional(rollbackFor= {Exception.class})
private void syncCylinderFillingExamine(List<TmCylinderFillingExamineModel> model ) { private void syncCylinderFillingExamine(List<TmCylinderFillingExamineModel> model ) {
syncCylinderDataService.syncCylinderFillingExamine(model); syncCylinderDataService.syncCylinderFillingExamine(model);
} }
......
...@@ -71,12 +71,12 @@ public class TmCylinderInfoService extends BaseService<TmCylinderInfoModel, TmCy ...@@ -71,12 +71,12 @@ public class TmCylinderInfoService extends BaseService<TmCylinderInfoModel, TmCy
cylinderInfoModel.setRecDate(new Date()); cylinderInfoModel.setRecDate(new Date());
cylinderInfoModel.setAppId(getAppId()); cylinderInfoModel.setAppId(getAppId());
createCylinderInfo2ES(cylinderInfoModel); syncCylinderDataService.createCylinderInfo2ES(cylinderInfoModel);
this.createWithModel(cylinderInfoModel); this.createWithModel(cylinderInfoModel);
} }
return "OK"; return "OK";
} }
@Transactional(rollbackFor= {Exception.class})
private void syncCylinderInfo(List<TmCylinderInfoModel> model ) { private void syncCylinderInfo(List<TmCylinderInfoModel> model ) {
syncCylinderDataService.syncCylinderInfo(model); syncCylinderDataService.syncCylinderInfo(model);
} }
...@@ -87,34 +87,4 @@ public class TmCylinderInfoService extends BaseService<TmCylinderInfoModel, TmCy ...@@ -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 ...@@ -53,7 +53,6 @@ public class TmCylinderUnitService extends BaseService<TmCylinderUnitModel, TmCy
} }
return "OK"; return "OK";
} }
@Transactional(rollbackFor= {Exception.class})
private void syncCylinderUnitModel(List<TmCylinderUnitModel> model ) { private void syncCylinderUnitModel(List<TmCylinderUnitModel> model ) {
syncCylinderDataService.syncCylinderUnit(model); syncCylinderDataService.syncCylinderUnit(model);
} }
......
...@@ -509,8 +509,8 @@ ...@@ -509,8 +509,8 @@
</foreach> </foreach>
</update> </update>
<insert id="saveOrUpdateBatch"> <insert id="saveOrUpdateBatch" parameterType="com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderInfo">
INSERT INTO "amos_tzs_biz"."tz_cylinder_info" 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 VALUES
<foreach collection="list" item="item" index="index" separator=","> <foreach collection="list" item="item" index="index" separator=",">
(#{item.sequenceNbr}, (#{item.sequenceNbr},
...@@ -548,7 +548,6 @@ ...@@ -548,7 +548,6 @@
null) null)
</foreach> </foreach>
on conflict (app_id,sequence_code) do update set on conflict (app_id,sequence_code) do update set
"sequence_nbr" = EXCLUDED."sequence_nbr",
"unit_name" = EXCLUDED."unit_name", "unit_name" = EXCLUDED."unit_name",
"factory_num" = EXCLUDED."factory_num", "factory_num" = EXCLUDED."factory_num",
"cylinder_status" = EXCLUDED."cylinder_status", "cylinder_status" = EXCLUDED."cylinder_status",
...@@ -579,7 +578,6 @@ ...@@ -579,7 +578,6 @@
"valve_manufactur_unit" = EXCLUDED."valve_manufactur_unit", "valve_manufactur_unit" = EXCLUDED."valve_manufactur_unit",
"nominal_work_pressure" = EXCLUDED."nominal_work_pressure", "nominal_work_pressure" = EXCLUDED."nominal_work_pressure",
"cylinder_variety_name" = EXCLUDED."cylinder_variety_name", "cylinder_variety_name" = EXCLUDED."cylinder_variety_name",
"filling_media_name" = EXCLUDED."filling_media_name", "filling_media_name" = EXCLUDED."filling_media_name"
"is_not_es" = EXCLUDED."is_not_es"
</insert> </insert>
</mapper> </mapper>
...@@ -79,7 +79,7 @@ ...@@ -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} ) 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> </select>
<insert id="saveOrUpdateBatch" parameterType="com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnit"> <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 VALUES
<foreach collection="list" item="item" index="index" separator=","> <foreach collection="list" item="item" index="index" separator=",">
(#{item.sequenceNbr}, (#{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