一、ibatIS调用存储过程(调用存储过程,统一使用StoredProcedure.xml)
1.SaleManagerAction代码:
/**
* 导入单边
* @return
* @author Invalid
* @throws Exception
* @date 2011-11-9 上午09:46:51
*/
public String importUnilateralSaleUpload() throws Exception{
Map<String,Object> result = new HashMap<String,Object>();
String uid = getUserId();
if(StringUtils.isEmpty(uid) || qqfile == null){
result.put("success", false);
result.put("message", "3014");
outPrint(JSON.toJSONString(result));
return null;
}
try{
Workbook workBook = getWorkbook(new FileInputStream(qqfile));
if(workBook!=null){
Sheet sheet = workBook.getSheetAt(0);
Iterator<Row> it = sheet.iterator();
importTotalNum = (sheet.getLastRowNum()+1);
List<Map<String,Object>> importList = new ArrayList<Map<String,Object>>();
Row row = null;
Map<String,Object> temp = null;
String date = null;
try{
while(it.hasNext()){
row = it.next();
temp = new HashMap<String,Object>();
temp.put("employeeId", uid);
temp.put("phone", String.format("%.0f", row.getCell(0).getNumericCellValue()));
temp.put("money", row.getCell(1).getNumericCellValue());
date = row.getCell(2).getStringCellValue();
temp.put("refundDate", DateUtils.parseDate(date, DATEFORMAT));
importList.add(temp);
}
}catch(Exception e){
result.put("message", "3013");
result.put("success", false);
log.error("SaleManagerAction importUnilateralSaleUpload:"+uid+","+qqfile.getName(), e);
outPrint(JSON.toJSONString(result));
return null;
}
List<Map<String,Object>> importErrorList = new ArrayList<Map<String,Object>>();
Map<String,Object> presult = null;
String code = null;
for( Map<String,Object> saleImport : importList )
{
presult = saleManager
.updateSaleUnilateralStateLoad(
(String)saleImport.get("employeeId"),
(String)saleImport.get("phone"),
(Double)saleImport.get("money"),
(Date)saleImport.get("refundDate"));
code = (String) presult.get("p_err_code");
if( "0".equals(code))//退款成功
importSuccess++;
if("-11".equals(code))//退款重复
importRepeat++;
if("-21".equals(code)){//退款失败
importError++;
importErrorList.add(saleImport);
}
}
result.put("importTotalNum", importTotalNum);
result.put("importSuccess", importSuccess);
result.put("importRepeat", importRepeat);
result.put("importError", importError);
result.put("importErrorList", importErrorList);
result.put("success", true);
}else{
result.put("message", "3015");
result.put("success", false);
}
log.info(uid+" Upload UnilateralSale Excel File:"+qqfile.getName()+",State:"+result.get("success"));
}catch(Exception e){
result.put("success", false);
log.error("SaleManagerAction importUnilateralSaleUpload:"+uid+","+qqfile.getName(), e);
}
outPrint(JSON.toJSONString(result));
return null;
}
===============================================================================================================================
2.SaleManagerServiceImpl:
@Override
public Map<String, Object> updateSaleUnilateralStateLoad(String employeeId,
String phone, Double money, Date refundDate) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("p_employee_id", employeeId);
model.put("p_phone", phone);
model.put("p_money", money);
model.put("p_refund_date", refundDate);
phoneSaleDao.updateSaleUnilateralStateLoad(model);
return model;
}
3.PhoneSaleDAOImpl:
@Override
public void updateSaleUnilateralStateLoad(Map<String, Object> model) {
getSqlMapClientTemplate().queryForObject("StoredProcedure.updateSaleUnilateralStateLoad",model);
}
4.StoredProcedure.xml(sqlMap文件):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="StoredProcedure">
<!-- updateSaleUnilateralStateMap 更新业务退款状态 -->
<parameterMap class="map" id="updateSaleUnilateralStateLoadMap">
<parameter property="p_employee_id" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN" />
<parameter property="p_phone" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN" />
<parameter property="p_money" jdbcType="DOUBLE" javaType="java.lang.Double" mode="IN" />
<parameter property="p_refund_date" jdbcType="DATE" javaType="java.util.Date" mode="IN" />
<parameter property="p_err_code" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT" />
<parameter property="p_err_info" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT" />
</parameterMap>
<procedure id="updateSaleUnilateralStateLoad" parameterMap="updateSaleUnilateralStateLoadMap">
{CALL SP_PHONE_REFUND_LOAD(?,?,?,?,?,?)}
</procedure>
</sqlMap>