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