模板

1.action service dao ibatis ajax

=======================================================
ibatis xml
<select id="getInvalidProjectMgr" parameterClass="java.lang.String" resultClass="java.lang.String">
<![CDATA[
select g.group_id as projectMrg
from ecc_epm.gapm_project_group g
where g.role= 'ContractDeliveryPrincipal' and g.enable_flag = 'F' and rownum = 1 and g.project_id = #projectId#
order by g.last_update_date desc
]]>
</select>

=======================================================
类的注释:
/**
* 类编号:EPM_CJ402_IBudgetReviewDao
* 类名称:IBudgetReviewDao
* 内容摘要:预算评审数据访问接口
* 编码作者:lidaofei
* 完成日期:2016-04-13
*/
dao
/**
* 获取一个最新无效的执行项目经理
* @author lidaofei
* @category V10.3.1
* @date 2015-11-24
* @param projectId 项目ID
* @return String 执行项目经理编号
* @throws Exception
*/
public String getInvalidProjectMgr(String projectId) throws Exception;
=======================================================
daoImpl
/**
* 获取一个最新无效的执行项目经理
* @author lidaofei
* @category V10.3.1
* @date 2015-11-24
* @param projectId 项目ID
* @return String 执行项目经理编号
* @throws Exception
*/
public String getInvalidProjectMgr(String projectId) throws Exception {
String projectMgr="";
try {
projectMgr = (String)getSqlMapClientTemplate().queryForObject("projectQueryVO.getInvalidProjectMgr",projectId);
} catch (Exception e) {
PmInfoException.throwPmInfoException(EccExceptionComm.ERROR_LAYER_DAO, this.getClass().getName(), e);
}
return projectMgr;
}

================================================
service
/**
* 获取一个最新无效的执行项目经理
* @author lidaofei
* @category V10.3.1
* @date 2015-11-24
* @param projectId 项目ID
* @return String 执行项目经理编号
* @throws Exception
*/
public String getInvalidProjectMgr(String projectId) throws Exception;

====================================================
serviceImpl
/**
* 获取一个最新无效的执行项目经理
* @author lidaofei
* @category V10.3.1
* @date 2015-11-24
* @param projectId 项目ID
* @return String 执行项目经理编号
* @throws Exception
*/
public String getInvalidProjectMgr(String projectId) throws Exception {
String result = "";
try {
result = theIprojectQueryDAO.getInvalidProjectMgr(projectId);
} catch (Exception e) {
PmInfoException.throwPmInfoException(EccExceptionComm.ERROR_LAYER_SERVICE, this.getClass().getName(), e);
}
return result;
}

====================================================
action
/**
* 获取一个最新无效的执行项目经理
* @author lidaofei
* @throws Exception
* @category V10.3.1
* @date 2015-11-24
*/
public ActionForward getInvalidProjectMgr(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception {
String projectMrg = "";
String projectId = request.getParameter("projectId");
if(StringUtils.isNotBlank(projectId)) {
IprojectQueryService proQueryService = (IprojectQueryService) getInrepairServiceFactory().getServiceObject("projectQueryServiceImpl");
if (proQueryService == null) {
Debug.println("===get projectQueryService is null====");
} else {
projectMrg = proQueryService.getInvalidProjectMgr(projectId);
JSONObject json = new JSONObject();
json.element("projectMrg", projectMrg);
request.setAttribute("projectMrg", projectMrg);
response.setContentType("text/json; charset=GBK");
response.getWriter().write(json.toString());
}
}
return null;
}

======================================================
ajax
function getInvalidProjectMgr(projectId) {
var projectMrg;
var url = "<%=request.getContextPath()%>/epm/subcontract/newSub/ui/projectQueryAction.do";
$.ajax({
type:"post",
url:url,
data:"operation=getInvalidProjectMgr&projectId="+projectId,
async: false,
dataType:"json",
success:function(data) {
projectMrg = data.projectMrg;
}
});
return projectMrg;
}

====================================================
异常处理
1.在页面上显示异常处理信息时:
PmInfoException.throwPmInfoException(EccExceptionComm.ERROR_LAYER_DAO, this.getClass().getName(), e);

2.不在页面上显示信息时: 参照:com.zte.ecc.epm.subcontract.bidOrNot.web.BidProjectApplyAction的getSmallAmountProjectApply()
dao

try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, requestNo);
pstmt.setInt(2, predictSumS);
rs = pstmt.executeQuery();
while(rs.next()) {
res = rs.getInt(1);
}
} catch (Exception ex) {
throw new Exception(ex.getMessage());
} finally {
BaseDAO.closeAll(rs, pstmt, null); // 关闭所有JDBC对象
}

service

try {
con = BaseDAO.getConnection();
con.setAutoCommit(false);
ProjectApplyDAO projectApplyDAO = new ProjectApplyDAO(con);
//立项金额十万美元
int predictSumS = 100000;
res = projectApplyDAO.getSmallAmountProjectApply(requstNo,predictSumS);
} catch (Exception ex) {
res = -1;
ReceiveEffectBO bo = new ReceiveEffectBO();
String ee = getExceptionDetailsMessage(ex);
if (null != ee && !"".equals(ee)) {
if (ee.length() > 800) {
ee = ee.substring(0, 800);
}
}
bo.setExceptionInfo(ee);
bo.setExceptionOID(requstNo+"");
bo.setExceptionSource("根据需求单,获取小额立项申请单");
try
{
theOper.saveException(bo);
}
catch (Exception e)
{
e.printStackTrace();
}
ex.printStackTrace();
} finally {
try {
if (con != null) {
con.setAutoCommit(true);
BaseDAO.closeConnection(con);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return res;

定义
IReceiveEffectService theOper = (IReceiveEffectService)SpringServiceFactory.getInstance().getServiceObject("receiveEffectService");

加一个方法:
private String getExceptionDetailsMessage(Exception e) {
// 声明输出信息
String input = null;
// 初始化StringWriter
StringWriter sw = new StringWriter();
// 初始化PrintWriter
PrintWriter pw = new PrintWriter(sw);
// 打印堆栈
e.printStackTrace(pw);
// 获得堆栈信息
input = sw.getBuffer().toString();
return input;
}

 

2.异步模板

1. ajax异步处理
jsp页面(post请求)

var requestNo = '<bean:write name="BidProjectApplyForm" property="subcontract.requestNO"/>';
var url = '<%=request.getContextPath()%>/epm/subcontract/bidProjectApplyAction.do';
var flag1 = false;
$.ajax({
type:"post",
url:url,
data:'operation=getSmallAmountProjectApply&requestNo='+requestNo,
async:false,
dataType:'json',
success:function(data){
if(parseInt(data.resultCount)>0) {
alert("<%//该采购需求下已有小额采购立项申请单,不允许再提交采购立项,请提交人删除。%><bean:message key='EPM.LDF.2015111001'/>");
flag1 = true;
}
}
});
if(flag1) {
return;
}

java后台(运用json)
public ActionForward getSmallAmountProjectApply(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
//如果是国际单据才操作
if(IMenuTypeContant.MENU_TYPE_INTERNATIONAL.equals(request.getSession().getAttribute(IMenuTypeContant.MENU_TYPE))) {
String requestNo = request.getParameter("requestNo");
int resultCount=0;
if(StringUtils.isNotBlank(requestNo)) {
ProjectAppyOpr projectAppyOpr = new ProjectAppyOpr();
resultCount = projectAppyOpr.getSmallAmountProjectApply(requestNo);
try {
JSONObject json = new JSONObject();
json.element("resultCount", resultCount);
Debug.debug(json.toString());
response.setContentType("text/json; charset=GBK");
response.getWriter().write(json.toString());
} catch (Exception e) {
Debug.printErr(this.getClass().getName() + ".revoke()" + e.toString() + "\n");
}
}
}
return null;
}

posted @ 2016-10-21 15:29  飞翔.  阅读(104)  评论(0编辑  收藏  举报