1.applicationContext.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- 打开注解方式 -->
<context:annotation-config />
<!-- <context:property-placeholder location="classpath*:config.properties"/> -->
<context:component-scan base-package="com.sitech.echn" />
<!--<bean id="resources" class="com.sitech.echn.common.token.DecryptPropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:config.properties</value>
</property>
</bean>-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
</bean>
<!-- JNDI
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>ahmobile</value>
</property>
<property name="resourceRef">
<value>false</value>
</property>
</bean>
-->
<!--
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql=true
hibernate.temp.use_jdbc_metadata_defaults=false
hibernate.hbm2ddl.auto=validate
</value>
</property>
<property name="packagesToScan" value="com.sitech.echn.model"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
-->
<!--上线时需要改成JNDI的配置-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<!-- 事务代理拦截器的配置 -->
<bean id="proxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="save*">PROPAGATION_REQUIRES_NEW</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="buiness*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- ibatis sqlMapClient 配置 -->
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<!-- dao配置 -->
<bean id="ibatisDao"
class="com.sitech.core.architecture.ibatis.IbatisDao">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<!-- 添加了事务的管理类 -->
<bean id="ibatisManager" parent="proxyTemplate">
<property name="target">
<bean
class="com.sitech.core.architecture.ibatis.IbatisManager">
<property name="dao">
<ref bean="ibatisDao" />
</property>
</bean>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
</bean>
</beans>
2.SqlMapConfig.xml
<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings useStatementNamespaces="true" />
<sqlMap resource="ibatismap/Comm.xml" />
<sqlMap resource="ibatismap/tw_servopt_log.xml" />
<sqlMap resource="ibatismap/tw_servinvoke_log.xml" />
<sqlMap resource="ibatismap/tw_userlogin_log.xml" />
<sqlMap resource="ibatismap/tw_payprocess_log.xml" />
<sqlMap resource="ibatismap/tw_click_log.xml" />
<sqlMap resource="ibatismap/tw_useradvise_log.xml" />
<sqlMap resource="ibatismap/tixing_log.xml" />
</sqlMapConfig>
3.tixing_log.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="TiXingLog">
<typeAlias type="com.sitech.echn.model.TiXingIbatis" alias="tiXingInfo" />
<insert id="updateTiXingLog" parameterClass="tiXingInfo">
insert into
TB_TIXING_LOG
(ID,PHONE_NO,TYPE,SERVICE_NO,SERVICE_NAME,CITY_CODE,CITY_NAME,MADE_TIME,DEL_FLAG,remark1,remark2)
values
(#id#,#phoneNo#,#type#,#serviceNo#,#serviceName#,#cityCode#,#cityName#,#madeTime#,#delFlag#,#remark1#,#remark2#)
</insert>
<delete id="deleteTiXingLog">
delete from TB_TIXING_LOG where PHONE_NO=#phoneNo#
</delete>
</sqlMap>
4.UpdateRemindByIbatisAction.java
package com.sitech.echn.web.tixing;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.SqlMapClientCallback;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.opensymphony.xwork2.ActionSupport;
import com.sitech.core.architecture.ibatis.IbatisDao;
import com.sitech.core.architecture.spring.PortalJdbcTemplate;
import com.sitech.core.architecture.struts.Struts2Util;
import com.sitech.echn.model.TiXingIbatis;
/**
*
* @Description: 提醒管理页面编辑接口
* @author 陈潇涵
* @date Jan 28, 2015
* @version: V1.0
*
*/
public class UpdateRemindByIbatisAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(QueryRemindAction.class);
private Map<String, Object> map = new HashMap<String, Object>();
@Resource(name = "ibatisDao")
private IbatisDao ibatisDao;
/**
* 提醒管理(提醒定制、提醒编辑)
*/
public String updateRemindListByIbatis() {
String phoneNo = Struts2Util.getRequest().getParameter("phoneNo") == null ? ""
: Struts2Util.getRequest().getParameter("phoneNo").toString()
.trim();
String remindList = Struts2Util.getRequest().getParameter("remindList") == null ? ""
: Struts2Util.getRequest().getParameter("remindList")
.toString().trim();
String editFlag = Struts2Util.getRequest().getParameter("editFlag") == null ? ""
: Struts2Util.getRequest().getParameter("editFlag");
try {
List<TiXingIbatis> txList = new ArrayList<TiXingIbatis>();
if (remindList != null && !"".equals(remindList.trim())) {
String[] tempList = remindList.split("\\|");
for (String temp : tempList) {
String[] subList = temp.split(",", -1);
TiXingIbatis tx = new TiXingIbatis();
tx.setId(getId());
tx.setPhoneNo(phoneNo);
tx.setType(subList[0]);
tx.setServiceNo(subList[1]);
tx.setServiceName(subList[2]);
tx.setCityCode(subList[3]);
tx.setCityName(subList[4]);
tx.setMadeTime(new java.util.Date());
tx.setDelFlag("0");
tx.setRemark1(null);
tx.setRemark2(null);
txList.add(tx);
}
}
// 提醒管理页面标志 0:提醒管理 不为0 :提醒定制
if ("0".equals(editFlag)) {
// 提醒信息批量编辑
doUpdate(txList);
} else {
if (txList.size() > 0) {
String type = txList.get(0).getType();
String serviceNo = txList.get(0).getServiceNo();
String serviceName = txList.get(0).getServiceName();
String cityCode = txList.get(0).getCityCode();
String cityName = txList.get(0).getCityName();
int count = PortalJdbcTemplate
.getJdbcTemplate()
.queryForInt(
"SELECT COUNT(*) FROM TB_TIXING_LOG "
+ "WHERE PHONE_NO = ? AND TYPE = ? AND SERVICE_NO = ? AND CITY_CODE = ? AND DEL_FLAG = '0'",
phoneNo, type, serviceNo, cityCode);
if (count == 0) {
PortalJdbcTemplate
.getJdbcTemplate()
.update("INSERT INTO TB_TIXING_LOG "
+ "(ID,PHONE_NO,TYPE,SERVICE_NO,SERVICE_NAME,CITY_CODE,CITY_NAME,MADE_TIME,DEL_FLAG) "
+ "VALUES(?,?,?,?,?,?,?,?,?)", getId(),
phoneNo, type, serviceNo, serviceName,
cityCode, cityName,
new java.util.Date(), "0");
} else {
map.put("resultCode", "2");
map.put("resultMsg", "该提醒已定制");
}
}
}
map.put("resultCode", "0");
map.put("resultMsg", "编辑成功");
} catch (Throwable e) {
e.printStackTrace();
map.put("resultCode", "1");
map.put("resultMsg", "编辑失败");
logger.info("ibatis异常");
return "success";
}
return "success";
}
/**
* 提醒信息批量编辑操作
*
* @param tiXingInfo
* 提醒列表
* @throws BatchUpdateException
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void doUpdate(final List<TiXingIbatis> tiXingInfo)
throws SQLException {
logger.info("ibatis事物开始");
this.ibatisDao.getSqlMapClientTemplate().execute(
new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) {
try {
String phoneNo = Struts2Util.getRequest()
.getParameter("phoneNo") == null ? ""
: Struts2Util.getRequest()
.getParameter("phoneNo").toString()
.trim();
executor.startBatch();
executor.delete("TiXingLog.deleteTiXingLog",
phoneNo);
for (TiXingIbatis tx : tiXingInfo) {
executor.insert("TiXingLog.updateTiXingLog", tx);
}
executor.executeBatch();
String points = Struts2Util.getRequest()
.getParameter("points") == null ? ""
: Struts2Util.getRequest()
.getParameter("points").toString()
.trim();
String flowData = Struts2Util.getRequest()
.getParameter("flowData") == null ? ""
: Struts2Util.getRequest()
.getParameter("flowData")
.toString().trim();
String phoneBill = Struts2Util.getRequest()
.getParameter("phoneBill") == null ? ""
: Struts2Util.getRequest()
.getParameter("phoneBill")
.toString().trim();
// 取消积分提醒
if ("0".equals(points)) {
PortalJdbcTemplate
.getJdbcTemplate()
.update("INSERT INTO TB_TIXING_LOG "
+ "(ID,PHONE_NO,TYPE,SERVICE_NAME,MADE_TIME,DEL_FLAG) "
+ "VALUES(?,?,?,?,?,?)",
getId(), phoneNo, "0", "积分",
new java.util.Date(), "0");
}
// 取消流量提醒
if ("0".equals(flowData)) {
PortalJdbcTemplate
.getJdbcTemplate()
.update("INSERT INTO TB_TIXING_LOG "
+ "(ID,PHONE_NO,TYPE,SERVICE_NAME,MADE_TIME,DEL_FLAG) "
+ "VALUES(?,?,?,?,?,?)",
getId(), phoneNo, "1", "流量",
new java.util.Date(), "0");
}
// 取消话费提醒
if ("0".equals(phoneBill)) {
PortalJdbcTemplate
.getJdbcTemplate()
.update("INSERT INTO TB_TIXING_LOG "
+ "(ID,PHONE_NO,TYPE,SERVICE_NAME,MADE_TIME,DEL_FLAG) "
+ "VALUES(?,?,?,?,?,?)",
getId(), phoneNo, "2", "话费",
new java.util.Date(), "0");
}
return null;
} catch (Exception e) {
e.printStackTrace();
map.put("resultCode", "1");
map.put("resultMsg", "编辑失败");
logger.info("ibatis事物异常");
}
return null;
}
});
}
public Map<String, Object> getMap() {
return map;
}
public void setMap(Map<String, Object> map) {
this.map = map;
}
/**
* 提醒信息批量编辑操作
*
* @return String 自增长唯一ID
*/
public String getId() {
String sql = "SELECT LPAD(SDM_ORDER_SEQ.nextval,7,'0') AS ID FROM dual";
return (String) PortalJdbcTemplate.getJdbcTemplate().queryForList(sql)
.get(0).get("ID");
}
}