Commit 805d17ed authored by lisong's avatar lisong

同步接口修改

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