From 90a1495b9d765c9e1d48f689dbcf977cbdb2768e Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期二, 31 十二月 2024 17:23:13 +0800 Subject: [PATCH] 模型结果修改为存在唯一索引则修改,不存在插入。避免死锁问题 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java | 17 ++++++++--------- iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml | 8 ++++++++ iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java | 4 ++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java index be97905..264c9f9 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java @@ -4,7 +4,9 @@ import com.iailab.framework.tenant.core.db.dynamic.TenantDS; import com.iailab.module.model.mcs.pre.entity.MmItemResultEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; import java.util.Map; /** @@ -19,5 +21,7 @@ void savePredictValue(Map<String, Object> params); + void saveOrUpdateItemResult(@Param("list") List<MmItemResultEntity> list); + void savePredictJsonValue(Map<String, Object> params); } diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java index 26ec871..26f58e5 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java @@ -15,8 +15,6 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -85,14 +83,15 @@ map4.put("entity", resultJson); mmItemResultDao.savePredictJsonValue(map4); - Map<String, Object> params = new HashMap(4); - params.put("TABLENAME", T_MM_ITEM_RESULT); - params.put("OUTPUTID", entry.getKey()); - params.put("STARTTIME", importList.get(0).getDatatime()); - params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); - mmItemResultDao.deletePredictValue(params); +// Map<String, Object> params = new HashMap(4); +// params.put("TABLENAME", T_MM_ITEM_RESULT); +// params.put("OUTPUTID", entry.getKey()); +// params.put("STARTTIME", importList.get(0).getDatatime()); +// params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); +// mmItemResultDao.deletePredictValue(params); } - mmItemResultDao.insertBatch(importList,max_group_count); + // 存在则修改,不存在插入 + mmItemResultDao.saveOrUpdateItemResult(importList); Map<String, Object> map3 = new HashMap<>(2); map3.put("TABLENAME", "T_MM_ITEM_RESULT_LAST_POINT"); diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml index ec7a065..a0a6838 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml +++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml @@ -28,5 +28,13 @@ VALUES (#{entity.id},#{entity.outputid},#{entity.predicttime},#{entity.jsonvalue},#{entity.cumulant}) </insert> + <insert id="saveOrUpdateItemResult" parameterType="com.iailab.module.model.mcs.pre.entity.MmItemResultEntity"> + INSERT INTO t_mm_item_result (id,outputid, datatime, datavalue) VALUES + <foreach item="item" collection="list" separator=","> + (#{item.id},#{item.outputid},#{item.datatime},#{item.datavalue}) + </foreach> + ON DUPLICATE KEY UPDATE datavalue = VALUES(datavalue) + </insert> + </mapper> \ No newline at end of file -- Gitblit v1.9.3