Commit 805d17ed authored by lisong's avatar lisong

同步接口修改

parent 5e55a24c
......@@ -40,5 +40,5 @@ public interface CylCylinderFillingCheckMapper extends BaseMapper<CylinderFillin
void batchInsertOrUpdate(@Param("list") List<CylinderFillingRecord> list);
void updateSyncState(@Param("appIds") List<String> appids, @Param("records")List<String> records);
void updateSyncState(@Param("ids") List<Long> ids);
}
......@@ -62,7 +62,7 @@
<foreach collection="appIdList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
and filling_record_id in
and filling_check_id in
<foreach collection="fillingCheckIdList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
......@@ -217,38 +217,29 @@
nonconformances = EXCLUDED.nonconformances
</insert>
<select id="selectCountTotal" resultType="java.lang.Long">
SELECT COUNT
( 1 )
SELECT
count(1)
FROM
(
SELECT
sequence_nbr
FROM
tm_cylinder_filling_record cfr
WHERE
sync_state != 3
tm_cylinder_filling_record cfr
WHERE
sync_state != 3
AND filling_record_id is not null
GROUP BY
cfr.app_id,
cfr.filling_record_id
)
</select>
<select id="fillingRecordSyncRecords"
resultType="com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderFillingRecord">
SELECT
cfr.*,
'3' sync_state_str,
CAST ((
( filling_record_id IS NOT NULL ) + ( filling_before_id IS NOT NULL ) + ( filling_check_id IS NOT NULL ) + ( filling_examine_id IS NOT NULL ) + ( filling_startTime IS NOT NULL ) + ( filling_endTime IS NOT NULL ) + ( filling_user IS NOT NULL ) + ( inspector_name IS NOT NULL ) + ( filling_quantity IS NOT NULL ) + ( temperature IS NOT NULL ) + ( abnormal IS NOT NULL )
) / 11 AS DECIMAL ( 10, 2 )) integrity
FROM tm_cylinder_filling_record cfr where sync_state !=3 and filling_record_id is not null
ORDER BY cfr.sync_date
LIMIT 5000
LIMIT 1000
</select>
<insert id="batchInsertOrUpdate" >
INSERT INTO tz_cylinder_filling_record_2210 (sequence_nbr,
INSERT INTO tz_cylinder_filling_record (sequence_nbr,
filling_record_id,
filling_starttime,
filling_endtime,
......@@ -318,14 +309,14 @@
<update id="updateSyncState">
update tm_cylinder_filling_record set sync_state = 3
<where>
app_id in
<foreach collection="appIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
and filling_record_id in
<foreach collection="records" item="item" index="index" open="(" close=")" separator=",">
sequence_nbr in
<foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
<!-- and filling_record_id in-->
<!-- <foreach collection="records" item="item" index="index" open="(" close=")" separator=",">-->
<!-- #{item}-->
<!-- </foreach>-->
</where>
</update>
</mapper>
......@@ -16,6 +16,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.*;
......@@ -38,20 +39,21 @@ public class CylSyncServiceImpl {
private CylCylinderFillingCheckMapper cylCylinderFillingCheckMapper;
public void syncFillingCheckInfo() {
Integer totalSize = sourceFillingCheckServiceImpl.getFillCheckListTotal();
Integer times;
if (totalSize != 0) {
times = totalSize / 1000;
int last = totalSize % 1000;
if (last > 0) {
times++;
}
} else {
return;
}
for (int i = 0; i < times; i++) {
traverseSave();
}
// Integer totalSize = sourceFillingCheckServiceImpl.getFillCheckListTotal();
// Integer times;
// if (totalSize != 0) {
// times = totalSize / 1000;
// int last = totalSize % 1000;
// if (last > 0) {
// times++;
// }
// } else {
// return;
// }
// for (int i = 0; i < times; i++) {
// traverseSave();
// }
traverseSave();
}
@Transactional
......@@ -75,15 +77,16 @@ public class CylSyncServiceImpl {
fillingCheckIdList.add(e.getFillingCheckId());
appIdList.add(e.getAppId());
});
List<CylinderFillingCheck> clearList = Lists.newArrayList();
fillingChecks.stream().collect(Collectors.groupingBy(item -> item.getAppId() + "-" + item.getFillingCheckId(), Collectors.maxBy(Comparator.comparing(CylinderFillingCheck::getSyncDate)))).forEach((k,v) -> {
clearList.add(v.get());
});
// List<CylinderFillingCheck> clearList = Lists.newArrayList();
// fillingChecks.stream().collect(Collectors.groupingBy(item -> item.getAppId() + "-" + item.getFillingCheckId(), Collectors.maxBy(Comparator.comparing(CylinderFillingCheck::getSyncDate)))).forEach((k,v) -> {
// clearList.add(v.get());
// });
//1.更新或插入业务表
fillingCheckMapper.saveOrUpdateByCondition(clearList);
fillingCheckMapper.saveOrUpdateByCondition(fillingChecks);
//2.更新源表
sourceFillingCheckServiceImpl.updateBatch(appIdList, fillingCheckIdList);
traverseSave();
}
}
......@@ -206,30 +209,55 @@ public class CylSyncServiceImpl {
}
@Transactional
public String fillingRecordSync() {
Long count = sourceFillingCheckServiceImpl.fillingRecordSync();
Long times = 0L;
if (count != 0) {
times = count / 5000;
Long last = count % 5000;
if (last > 0) {
times++;
}
} else {
return "no data sync";
}
for (int i = 0; i < times; i++) {
// StopWatch stopWatch = new StopWatch();
// stopWatch.start();
// Long count = sourceFillingCheckServiceImpl.fillingRecordSync();
// stopWatch.stop();
// System.out.println("统计总数耗时:"+ stopWatch.getTotalTimeSeconds());
return fillingRecordMessage();
}
@Transactional
String fillingRecordMessage(){
// Long times = 0L;
// if (count != 0) {
// times = count / 1000;
// Long last = count % 1000;
// if (last > 0) {
// times++;
// }
// } else {
// return "no data sync";
// }
// times = 2L;
// for (int i = 0; i < times; i++) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
List<CylinderFillingRecord> cylinderFillingRecords = sourceFillingCheckServiceImpl.fillingRecordSyncRecords();
cylinderFillingRecords.forEach(item -> {
item.setAbnormal(item.getAbnormal() == 1 ? 3140 : 3139);
item.setSyncState(3);
});
List<String> appIds = cylinderFillingRecords.stream().map(CylinderFillingRecord::getAppId).collect(Collectors.toList());
List<String> records = cylinderFillingRecords.stream().map(CylinderFillingRecord::getFillingRecordId).collect(Collectors.toList());
cylCylinderFillingCheckMapper.batchInsertOrUpdate(cylinderFillingRecords);
sourceFillingCheckServiceImpl.updateSyncState(appIds, records);
}
stopWatch.stop();
System.out.println("查询1000条记录耗时:"+ stopWatch.getTotalTimeSeconds());
if (!ObjectUtils.isEmpty(cylinderFillingRecords)){
cylinderFillingRecords.forEach(item -> {
item.setAbnormal(item.getAbnormal() == 1 ? 3140 : 3139);
item.setSyncState(3);
});
// List<String> appIds = cylinderFillingRecords.stream().map(CylinderFillingRecord::getAppId).collect(Collectors.toList());
// List<String> records = cylinderFillingRecords.stream().map(CylinderFillingRecord::getFillingRecordId).collect(Collectors.toList());
List<Long> ids = cylinderFillingRecords.stream().map(CylinderFillingRecord::getSequenceNbr).collect(Collectors.toList());
StopWatch stopWatch1 = new StopWatch();
stopWatch1.start();
cylCylinderFillingCheckMapper.batchInsertOrUpdate(cylinderFillingRecords);
stopWatch1.stop();
System.out.println("插入数据耗时:"+ stopWatch1.getTotalTimeSeconds());
StopWatch stopWatch2 = new StopWatch();
stopWatch2.start();
sourceFillingCheckServiceImpl.updateSyncState(ids);
stopWatch2.stop();
System.out.println("修改数据耗时:"+ stopWatch2.getTotalTimeSeconds());
fillingRecordMessage();
}
return "ok";
}
}
......@@ -66,7 +66,7 @@ public class CylinderSyncServiceImpl {
return fillingCheckMapper.fillingRecordSyncRecords();
}
public void updateSyncState(List<String> appIds, List<String> records){
fillingCheckMapper.updateSyncState(appIds, records);
public void updateSyncState(List<Long> ids){
fillingCheckMapper.updateSyncState(ids);
}
}
\ No newline at end of file
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