From a9406b6b18ee5a8e29cad3248f46320a36ac9749 Mon Sep 17 00:00:00 2001 From: yyt <306727702@qq.com> Date: 星期三, 21 二月 2024 00:19:44 +0800 Subject: [PATCH] 批量数据采集方法更新 --- jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java b/jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java index 4cfa0c6..0ab83b0 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java +++ b/jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java @@ -6,8 +6,13 @@ import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper; import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import javax.annotation.Resource; /** * 璁惧浜у搧杩囩▼鍙傛暟閲囬泦Service涓氬姟灞傚鐞� @@ -23,6 +28,9 @@ @Autowired private IDaParamCollectionService daParamCollectionService; + + @Resource + private SqlSessionFactory sqlSessionFactory; /** * 鏌ヨ璁惧浜у搧杩囩▼鍙傛暟閲囬泦 @@ -102,4 +110,25 @@ { return daParamCollectionMapper.deleteDaParamCollectionById(id); } + + @Override + public void saveBeachDaParamCollection(List<DaParamCollection> list) { + // ExecutorType.SIMPLE: 杩欎釜鎵ц鍣ㄧ被鍨嬩笉鍋氱壒娈婄殑浜嬫儏銆傚畠涓烘瘡涓鍙ョ殑鎵ц鍒涘缓涓�涓柊鐨勯澶勭悊璇彞銆� + // ExecutorType.REUSE: 杩欎釜鎵ц鍣ㄧ被鍨嬩細澶嶇敤棰勫鐞嗚鍙ャ�� + // ExecutorType.BATCH: 杩欎釜鎵ц鍣ㄤ細鎵归噺鎵ц鎵�鏈夋洿鏂拌鍙�,濡傛灉 SELECT 鍦ㄥ畠浠腑闂存墽琛岃繕浼氭爣瀹氬畠浠槸 蹇呴』鐨�,鏉ヤ繚璇佷竴涓畝鍗曞苟鏄撲簬鐞嗚В鐨勮涓恒�� + + // 鍏抽棴session鐨勮嚜鍔ㄦ彁浜� + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + try { + DaParamCollectionMapper userMapper = sqlSession.getMapper(DaParamCollectionMapper.class); + list.stream().forEach(DaParamCollection -> userMapper.insertDaParamCollection(DaParamCollection)); + // 鎻愪氦鏁版嵁 + sqlSession.commit(); + sqlSession.rollback(); + } catch (Exception e) { + sqlSession.rollback(); + } finally { + sqlSession.close(); + } + } } -- Gitblit v1.9.3