新增历史表(0-9),用于分担单表压力。
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package com.gzzn.omms.msgexchangeapi.dao;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import java.util.List;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entity.CminmsgHst;
|
||||
|
||||
|
||||
|
||||
public interface CminmsgHstDao extends CrudRepository<CminmsgHst, Long> {
|
||||
public interface CminmsgHstDao {
|
||||
|
||||
/**
|
||||
* 保存到指定的表
|
||||
* @param tableName 数据库表名
|
||||
* @param lsCminmsgHsts 要插入的记录列表
|
||||
* @return true 成功 false 失败
|
||||
*/
|
||||
public boolean insertToTable(String tableName,List<CminmsgHst> lsCminmsgHsts);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.gzzn.omms.msgexchangeapi.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entity.CminmsgHst;
|
||||
|
||||
@Component
|
||||
public class CminmsgHstDaoImpl implements CminmsgHstDao {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* 保存到指定的表
|
||||
* @return 成功或失败
|
||||
*/
|
||||
@Transactional
|
||||
public boolean insertToTable(String tableName,List<CminmsgHst> lsCminmsgHsts)
|
||||
{
|
||||
if(CollectionUtils.isEmpty(lsCminmsgHsts))
|
||||
{
|
||||
throw new RuntimeException("插入数据库内容不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
for (CminmsgHst cminmsgHst : lsCminmsgHsts) {
|
||||
String sqlStr = "insert into " + tableName + "("
|
||||
+ "CMINMSGS_ID,"
|
||||
+ "CMINMSGS_CLOB_MSG,"
|
||||
+ "CMINMSGS_DATE_RECEIVED,"
|
||||
+ "CMINMSGS_DATE_PROCESSED,"
|
||||
+ "CMINMSGS_SUBSYSTEM_NAME,"
|
||||
+ "CMINMSGS_SUBSYSTEM_SEQUENCE,"
|
||||
+ "CMINMSGS_SUBSYSTEM_DATE_SENT,"
|
||||
+ "CMINMSGS_SUBSYSTEM_SUBTYPE,"
|
||||
+ "CMINMSGS_SUBSYSTEM_TYPE,"
|
||||
+ "CMINMSGS_STATUS) values("
|
||||
+ ":CMINMSGS_ID,"
|
||||
+ ":CMINMSGS_CLOB_MSG,"
|
||||
+ ":CMINMSGS_DATE_RECEIVED,"
|
||||
+ ":CMINMSGS_DATE_PROCESSED,"
|
||||
+ ":CMINMSGS_SUBSYSTEM_NAME,"
|
||||
+ ":CMINMSGS_SUBSYSTEM_SEQUENCE,"
|
||||
+ ":CMINMSGS_SUBSYSTEM_DATE_SENT,"
|
||||
+ ":CMINMSGS_SUBSYSTEM_SUBTYPE,"
|
||||
+ ":CMINMSGS_SUBSYSTEM_TYPE,"
|
||||
+ ":CMINMSGS_STATUS);";
|
||||
|
||||
Query query = entityManager.createNativeQuery(sqlStr);
|
||||
query.setParameter("CMINMSGS_ID", cminmsgHst.getCminmsgsId());
|
||||
query.setParameter("CMINMSGS_CLOB_MSG", cminmsgHst.getCminmsgsClobMsg());
|
||||
query.setParameter("CMINMSGS_DATE_RECEIVED", cminmsgHst.getCminmsgsDateReceived());
|
||||
query.setParameter("CMINMSGS_DATE_PROCESSED", cminmsgHst.getCminmsgsDateProcessed());
|
||||
query.setParameter("CMINMSGS_SUBSYSTEM_NAME", cminmsgHst.getCminmsgsSubsystemName());
|
||||
query.setParameter("CMINMSGS_SUBSYSTEM_SEQUENCE", cminmsgHst.getCminmsgsSubsystemSequence());
|
||||
query.setParameter("CMINMSGS_SUBSYSTEM_DATE_SENT", cminmsgHst.getCminmsgsSubsystemDateSent());
|
||||
query.setParameter("CMINMSGS_SUBSYSTEM_SUBTYPE", cminmsgHst.getCminmsgsSubsystemSubtype());
|
||||
query.setParameter("CMINMSGS_SUBSYSTEM_TYPE", cminmsgHst.getCminmsgsSubsystemType());
|
||||
query.setParameter("CMINMSGS_STATUS", cminmsgHst.getCminmsgsStatus());
|
||||
|
||||
query.executeUpdate();
|
||||
}//end for
|
||||
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return false;
|
||||
}
|
||||
} //end function
|
||||
}
|
||||
Reference in New Issue
Block a user