标签:
Ajax.js
1 /**通用ajax服务的定义对象 2 3 * services可以是单个服务对象,也可以是service服务数组 4 * 具体服务的定义请参考appendServices成员函数 5 */ 6 function Service(services){ 7 this.services=[]; 8 this.shareParameters={}; 9 /**添加共享参数,在这里统一设置共享参数 10 */ 11 this.addShareParameters=function(shareParameters){ 12 this.shareParameters=shareParameters; 13 return this; 14 }; 15 /** 16 * 批量调用一般服务 17 18 * 入参可以是一个调用服务的数组或者单个调用服务 19 20 * 每个调用服务有下面的属性 21 22 * serviceId 服务Id,不可为空 23 24 * method 服务方法名,不可为空 25 * parameters 服务参数,必须是object,object的属性名代表参数名,属性值代表参数值。 26 27 * transform:结果集的转换规则(返回结果集合List<Map<String,Object>>时才会用到):null(无转换)、‘firstRow‘(取首行)、‘breakdown‘(分列),值不区分大小写 28 * shareResults 共享服务的返回结果,默认不共享false,如果后续服务需要使用到结果里面的参数, 29 * 那么就需要明确指定。该参数可以是 boolean,array或者object,为true时表示全部共享; 30 * 数组可以指定返回值中需要共享的值的名,这样返回值的键值对应关系共享; 31 * object可以额外指定共享名的别名,当要求返回值以新的字段名共享、 32 33 * 或者一个以多个新别名共享时就需要用到这种类型,object的属性名表示结果集中需要共享的字段名, 34 * 属性值表示新的字段名; 35 36 * 参数共享处理列表结果集时,整个结果集的数据存放在别名为空串的特殊key上。如果本业务没有返回结果,那么参数共享无效。 37 38 * useShare 使用共享参数标志,定义方式与shareResults一样,意义正好想对应。该参数指明如果从共享参数中获取要的值。 39 40 * shareNotNull 校验共享参数是否为空,作为useShare的附属属性。 41 42 * 有时希望如果获取到的共享参数是空的,那么不继续执行,那么可以在这里指定哪些一定不能为空。 43 44 * 目前只允许三种取值,null,true和别名数组,null表示不校验,true表示全校验,别名数组表示只校验指定的值(别名是指useShare中新的别名,并非共享池里面的共享别名)。 45 46 */ 47 this.appendServices=function(services){ 48 if(!services){ 49 return this; 50 } 51 //默认按批量形式添加服务,如果是单个,那么用数组包装 52 53 var tmp_services=services; 54 if(!$.isArray(tmp_services)){ 55 tmp_services = [tmp_services]; 56 } 57 //每个service必须有serviceId,method 58 for(index in tmp_services){ 59 //检查必录项 60 if(!tmp_services[index].serviceId||!tmp_services[index].method){ 61 FWalert(‘服务定义的serviceId和method不可为空‘); 62 return this; 63 } 64 //检查可选项 65 if(tmp_services[index].parameters){ 66 if(typeof tmp_services[index].parameters !=‘object‘ 67 ||jQuery.isArray(tmp_services[index].parameters)){ 68 FWalert(‘服务定义的参数必须是map!‘); 69 return; 70 } 71 } 72 //如果指定了transform,那么值只能是规定的 73 74 if(tmp_services[index].transform){ 75 if(‘FIRSTROW‘!=tmp_services[index].transform.toUpperCase() 76 &&‘BREAKDOWN‘!=tmp_services[index].transform.toUpperCase()){ 77 FWalert(‘transform属性不正确‘); 78 return this; 79 } 80 } 81 //shareResults 82 //转换shareResults,统一转换成map,或者boolean 83 shareResults = tmp_services[index].shareResults; 84 if(shareResults){ 85 if(typeof shareResults ==‘boolean‘){ 86 if(!shareResults){ 87 shareResults =null; 88 } 89 }else if(jQuery.isArray(shareResults)){ 90 //转化为map 91 shareResults={}; 92 $.each(tmp_services[index].shareResults,function(indexInArray, valueOfElement){ 93 shareResults[valueOfElement]=valueOfElement; 94 }); 95 tmp_services[index].shareResults =shareResults; 96 } 97 } 98 //useShare 99 useShare = tmp_services[index].useShare; 100 if(useShare){ 101 if(typeof useShare ==‘boolean‘){ 102 if(!useShare){ 103 tmp_services[index].useShare =null; 104 } 105 }else if(jQuery.isArray(useShare)){ 106 //转化为map 107 useShare={}; 108 $.each(tmp_services[index].useShare,function(indexInArray, valueOfElement){ 109 useShare[valueOfElement]=valueOfElement; 110 }); 111 tmp_services[index].useShare =useShare; 112 } 113 } 114 //shareNotNull,只允许true和字符串数组 115 shareNotNull = tmp_services[index].shareNotNull; 116 if(shareNotNull){ 117 if(typeof shareNotNull !==‘boolean‘ && !jQuery.isArray(shareNotNull)){ 118 FWalert(‘参数[shareNotNull]的取值必须是true或者字符串数组!‘); 119 return this; 120 }else if(shareNotNull ===false){ 121 tmp_services[index].shareNotNull = null; 122 } 123 } 124 } 125 this.services=this.services.concat(tmp_services); 126 return this; 127 }; 128 /**定义添加直接调用存储过程的服务 129 130 * 可以批量添加存储过程。每个存储过程服务的有以下属性: 131 * procName、parameters、shareResults、useShare, 132 133 * 其中procName指明存储过程的名称,其他的请参考appendServices;parameters中的参数名不能是procName 134 * 批量添加存储过程时,用数组存储各个存储过程作为参数传入即可。 135 136 * ... 137 */ 138 this.appendProc=function(procedures){ 139 if(!procedures){ 140 return this; 141 } 142 //默认按批量形式添加服务,如果是单个,那么用数组包装 143 144 tmp_procedures=procedures; 145 if(!$.isArray(tmp_procedures)){ 146 tmp_procedures = [tmp_procedures]; 147 } 148 //遍历,一个一个的处理 149 procedure_services =[]; 150 for (index in tmp_procedures){ 151 //必须有configId属性 152 153 procedure = tmp_procedures[index]; 154 if(!procedure.procName){ 155 FWalert(‘存储过程服务必须指定procName属性‘); 156 return this; 157 } 158 procedure = $.extend(true,{},procedure, 159 {serviceId:‘directJdbcService‘,method:‘savePointProcedure‘ 160 ,parameters:{‘‘:procedure.procName}}); 161 //去掉存储过程名称 162 delete procedure.procName; 163 //添加到服务列表 164 165 procedure_services.push(procedure); 166 } 167 return this.appendServices(procedure_services); 168 }; 169 /**定义添加调用预定义查询语句的服务 170 * 可以批量添加查询语句。每个查询服务的包括以下属性: 171 * configId、transform、indices,parameters、shareResults、useShare。 172 173 * configId是Mapper.xml中的配置ID(注意写上空间名) 174 * parameters是传递给configId的参数 175 176 * transform:结果集的转换规则:null(无转换)、‘firstRow‘(取首行)、‘breakdown‘(分列),值不区分大小写 177 178 * ,该参数要求传入字符串数组类型,元素值指明参数Map中的一个参数名。 179 180 * 其它属性将作为查询语句的备用参数。其他的请参考appendServices; 181 182 * 批量添加查询服务时,用数组存储各个查询服务作为参数传入即可。 183 184 * ... 185 */ 186 this.appendQuery=function(querys){ 187 if(!querys){ 188 return this; 189 } 190 //默认按批量形式添加服务,如果是单个,那么用数组包装 191 192 tmp_querys=querys; 193 if(!$.isArray(tmp_querys)){ 194 tmp_querys = [tmp_querys]; 195 } 196 //遍历,一个一个的处理 197 query_services = []; 198 for (index in tmp_querys){ 199 //必须有configId属性 200 201 var query = tmp_querys[index]; 202 if(!query.configId){ 203 FWalert(‘查询服务必须指定configId属性‘); 204 return this; 205 } 206 //参数索引放入参数串中 207 query = $.extend(true,{},query, 208 {serviceId:‘commService‘,method:‘query‘ 209 ,parameters:{‘_commDo‘:query.configId}}); 210 211 //去掉存储过程名称,和参数索引 212 delete query.configId; 213 214 //添加到服务列表 215 216 query_services.push(query); 217 } 218 return this.appendServices(query_services); 219 }; 220 /**定义触发ajax的事件 221 222 * message:本次ajax请求的名称,可选。 223 224 * success:处理成功后触发的函数,原型是function(data)。 225 226 * error:处理是否时触发的函数,原型是function(XMLHttpRequest, textStatus, errorThrown); 227 * async:同步或是异步,同步为false、异步是true 228 */ 229 this.sentAjax=function(message,success,error,async){ 230 if(this.services.length==0){ 231 FWalert(‘请至少添加一个服务‘); 232 return; 233 } 234 var t_async = true; 235 var t_message = message; 236 var t_success = success; 237 var t_error = error; 238 if(jQuery.isFunction(message)){ 239 t_message = ‘正在请求服务,请稍候...‘; 240 t_success =message; 241 t_error = success; 242 }else if (typeof message != ‘string‘){ 243 FWalert(‘入参错误,请检查程序!‘); 244 return ; 245 } 246 if(async!=null&&typeof async==‘boolean‘){ 247 if(!async){ 248 t_async = false; 249 } 250 } 251 var thisrequest={}; 252 $.ajax({ 253 url:contextPath+‘/ajax.do‘ 254 ,data:{parameters:JSON.stringify(this.services),shareArguments:JSON.stringify(this.shareParameters)} 255 ,dataType :‘json‘ 256 ,cache:false 257 ,async:t_async 258 ,type:‘post‘ 259 ,error:function (request, textStatus, errorThrown) { 260 if(!t_error){ 261 FWalert(‘数据请求错误!‘); 262 }else{ 263 t_error(request, textStatus, errorThrown); 264 } 265 } 266 ,success:function (data, textStatus) { 267 //校验业务处理是否正确执行 268 if("1"!=data.FHZ){//出错了,弹出错误提醒 269 if ("loginTimeout" == data.FHZ) { 270 if(window.confirm(data.MSG||‘‘)){ 271 window.top.location.href=_selfUrl; 272 } 273 } else { 274 if(t_error){ 275 t_error(data.MSG||‘‘, ‘serviceErr‘, data.MSG); 276 }else{ 277 FWalert(data.MSG||‘‘); 278 } 279 } 280 }else if(!t_success){ 281 }else{ 282 t_success(data.RTN); 283 } 284 } 285 ,beforeSend:function( ){ 286 $.data(thisrequest,‘msg‘,showMsg(t_message,-1)); 287 //createProgressBar(); 288 } 289 ,complete:function( ){ 290 hideMsg($.data(thisrequest,‘msg‘)); 291 } 292 }); 293 }; 294 //添加参数 295 if(services){ 296 this.appendServices(services); 297 } 298 } 299 /** 300 * 在页面的左上角显示错误消息 301 302 * @param msg 消息内容 303 * @param timeout 秒为单位,0或者负数表示不自动隐藏 304 * @author 吴英德 305 306 **/ 307 var framework_message_layer; 308 var clearIntervalID; 309 function showMsg(msg,delay){ 310 311 var recurrectLocation=function(){ 312 if(framework_message_layer==null) 313 {clearInterval(clearIntervalID);return;} 314 var posX,posY; 315 if (window.innerHeight) { 316 posX = window.pageXOffset; 317 posY = window.pageYOffset; 318 } 319 else if (document.documentElement && document.documentElement.scrollTop) { 320 posX = document.documentElement.scrollLeft; 321 posY = document.documentElement.scrollTop; 322 } 323 else if (document.body) { 324 posX = document.body.scrollLeft; 325 posY = document.body.scrollTop; 326 } 327 framework_message_layer.style.top=String(posY+10)+‘px‘; 328 framework_message_layer.style.right=String(posX+10)+‘px‘; 329 }; 330 if(framework_message_layer == null){ 331 framework_message_layer=document.createElement(‘div‘); 332 framework_message_layer.className=‘err_message_blank_board‘; 333 document.body.appendChild(framework_message_layer); 334 clearIntervalID=window.setInterval(recurrectLocation,100); 335 recurrectLocation(); 336 } 337 var my_div = document.createElement(‘div‘); 338 my_div.className=‘err_message‘; 339 //Element.extend(my_div); 340 my_div.innerHTML=msg; 341 framework_message_layer.appendChild(my_div); 342 recurrectLocation(); 343 if(delay>0){ 344 setTimeout(function(){ 345 jQuery(my_div).remove(); 346 if(jQuery(framework_message_layer).is(‘:empty‘)){ 347 jQuery(framework_message_layer).remove(); 348 window.clearInterval(clearIntervalID); 349 framework_message_layer=null; 350 } 351 },delay*1000); 352 }else{ 353 return my_div; 354 } 355 } 356 357 /**隐藏右上角对应的消息 358 * @param object 某消息对象,来自showMsg的返回值 359 360 */ 361 function hideMsg(object){ 362 jQuery(object).remove(); 363 }
AjaxAction:
1 package cn.sinobest.framework.web; 2 3 import cn.sinobest.framework.comm.iface.IDTO; 4 import cn.sinobest.framework.comm.iface.IOperator; 5 import cn.sinobest.framework.service.CommService; 6 import cn.sinobest.framework.service.json.JSONUtilities; 7 import cn.sinobest.framework.service.tags.TreeService; 8 import cn.sinobest.framework.util.DTOUtil; 9 import cn.sinobest.framework.util.Util; 10 import java.io.ByteArrayInputStream; 11 import java.io.InputStream; 12 import java.util.HashMap; 13 import java.util.Map; 14 import javax.servlet.http.HttpServletRequest; 15 import org.apache.log4j.Logger; 16 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.context.annotation.Scope; 18 19 @Scope("prototype") 20 public class AjaxAction extends BaseActionSupport { 21 private static Logger log = Logger.getLogger(AjaxAction.class); 22 private static final long serialVersionUID = 1L; 23 private InputStream inputStream; 24 @Autowired 25 TreeService treeService; 26 @Autowired 27 CommService commService; 28 29 public InputStream getInputStream() { 30 return this.inputStream; 31 } 32 33 public String execute() throws Exception { 34 /** 35 * getValue是从封装好的ajax中获取的,如项目中的身份证修改js中的sentAjax,实际上 36 * 这个sentAjax是封装了的,具体的在ajax.js中的256行的data,这个data是一个json字符串, 37 * 这个json字符串有两个属性,一个是parameters,一个是shareArguments, 38 * 正好在这个execute()方法里通过request.getParameters可以获取到ajax中发过来的 39 * 这两个参数 40 */ 41 42 /** 43 * 封装的$.sentAjax具体如下 44 * $.ajax({ 45 url:contextPath+‘/ajax.do‘ 46 ,data:{parameters:JSON.stringify(this.services),shareArguments:JSON.stringify(this.shareParameters)} 47 ,dataType :‘json‘ 48 ,cache:false 49 ,async:t_async 50 ,type:‘post‘ 51 ,error:function (request, textStatus, errorThrown) { 52 if(!t_error){ 53 FWalert(‘数据请求错误!‘); 54 }else{ 55 t_error(request, textStatus, errorThrown); 56 } 57 } 58 ,success:function (data, textStatus) { 59 //校验业务处理是否正确执行 60 if("1"!=data.FHZ){//出错了,弹出错误提醒 61 if ("loginTimeout" == data.FHZ) { 62 if(window.confirm(data.MSG||‘‘)){ 63 window.top.location.href=_selfUrl; 64 } 65 } else { 66 if(t_error){ 67 t_error(data.MSG||‘‘, ‘serviceErr‘, data.MSG); 68 }else{ 69 FWalert(data.MSG||‘‘); 70 } 71 } 72 }else if(!t_success){ 73 }else{ 74 t_success(data.RTN); 75 } 76 } 77 ,beforeSend:function( ){ 78 $.data(thisrequest,‘msg‘,showMsg(t_message,-1)); 79 //createProgressBar(); 80 } 81 ,complete:function( ){ 82 hideMsg($.data(thisrequest,‘msg‘)); 83 } 84 }); 85 */ 86 // var proParams ={ 87 // PI_AAC002:aac002, 88 // PI_AAC002_NEW:aac002n, 89 // PI_AAE013:aae013, 90 // PI_AAE011:aae011, 91 // PI_BAE001:bae001 92 // }; 93 //// var mm = new WeiAjax(‘hha‘).hint(); 94 //// alert(typeof mm); 95 // 96 // new Service().appendProc({ 97 // procName:‘pkg_weiyl.updateIDCard‘, 98 // parameters:proParams 99 // }).sentAjax(‘正在进行数据处理‘,function(datass){ 100 // if(datass[0][‘PO_FHZ‘] !=‘1‘){ 101 // alert(datass[0][‘PO_FHZ‘]+" "+ datass[0][‘PO_MSG‘]); 102 // }else{ 103 // closeWindow(); 104 // getListData(‘glt_sfzxg‘,‘ 1=0 ‘); 105 // alert(‘身份证修改成功‘); 106 //// setTimeout(alert(‘身份证修改成功‘),1000); 107 // } 108 // },function(data){ 109 // docx(); 110 // getListData(‘glt_sfzxg‘,‘ 1=0 ‘); 111 // closeWindow(); 112 // alert("修改失败");},false); 113 114 String inParameters = (String) getValue("parameters"); 115 String inShareParameters = (String) getValue("shareParameters"); 116 Map<String, Object> actionResult = new HashMap(); 117 try { 118 Object[] inParams = (Object[]) JSONUtilities.parseJSON(inParameters); 119 Map[] params = (Map[]) null; 120 /** 121 * 绝对不会为空,因为这是 比如miposdz_test.js中 122 * serviceCl.appendServices({ 123 serviceId: ‘miposdzService‘, 124 method: ‘insertData‘, 125 parameters: { 126 CRXX: path 127 } 128 }).sentAjax(‘正在请求服务‘,function(){ 129 ...; 130 },function(){ 131 ...; 132 },false); 133 中的入参,即 134 { 135 serviceId: ‘miposdzService‘, 136 method: ‘insertData‘, 137 parameters: { 138 CRXX: path 139 } 140 这个对象 141 * 142 * 143 */ 144 if (inParams != null) { 145 params = (Map[]) Util.toTypedArray(inParams, Map.class); 146 } 147 Map<String, Object> shareArguments = null; 148 if (inShareParameters.length() > 0) { 149 shareArguments = (Map) JSONUtilities.parseJSON(inShareParameters); 150 } else { 151 shareArguments = new HashMap(); 152 } 153 /** 154 * 所以 params不可能为空, 这里在dto里以 parameters 为键, 以 155 * { 156 serviceId: ‘miposdzService‘, 157 method: ‘insertData‘, 158 parameters: { 159 CRXX: path 160 } 161 为值 162 * 163 */ 164 this.dto.setValue("parameters", params); 165 /** 166 * shareParameters :可能为空 167 */ 168 this.dto.setValue("shareParameters", shareArguments); 169 Object rtn = this.commService.doAjaxService(this.dto); 170 171 actionResult.put("RTN", rtn); 172 actionResult.put("FHZ", "1"); 173 } catch (Exception e) { 174 log.warn(null, e); 175 actionResult.put("FHZ", e.getLocalizedMessage()); 176 actionResult.put("MSG", e.getLocalizedMessage()); 177 String url = this.request.getRequestURI(); 178 String operId = ""; 179 if (DTOUtil.getUserInfo() != null) { 180 operId = DTOUtil.getUserInfo().getOperID(); 181 } 182 this.commService.storeException(url, DTOUtil.getDTO(), operId, e); 183 } 184 StringBuffer rstString = new JSONUtilities(1).parseObject(actionResult); 185 this.inputStream = new ByteArrayInputStream(rstString.toString().getBytes()); 186 return "success"; 187 } 188 }
CommService.java
1 package cn.sinobest.framework.service; 2 3 import cn.sinobest.framework.comm.dto.DTO; 4 import cn.sinobest.framework.comm.exception.AppException; 5 import cn.sinobest.framework.comm.iface.IDAO; 6 import cn.sinobest.framework.comm.iface.IDTO; 7 import cn.sinobest.framework.comm.iface.IOperator; 8 import cn.sinobest.framework.comm.transcation.DataSourceCallBack; 9 import cn.sinobest.framework.comm.transcation.IDataSourceCallBack; 10 import cn.sinobest.framework.dao.CommDAO; 11 import cn.sinobest.framework.dao.workflow.WfActionDef; 12 import cn.sinobest.framework.dao.workflow.WfWorkItem; 13 import cn.sinobest.framework.service.json.JSONUtilities; 14 import cn.sinobest.framework.service.tags.WfService; 15 import cn.sinobest.framework.service.workflow.IWorkflow.Attr; 16 import cn.sinobest.framework.service.workflow.IWorkflow.ProcStartOrEnd; 17 import cn.sinobest.framework.service.workflow.IWorkflow.RightMsg; 18 import cn.sinobest.framework.service.workflow.IWorkflowService; 19 import cn.sinobest.framework.util.ConfUtil; 20 import cn.sinobest.framework.util.DateUtil.CurDate; 21 import cn.sinobest.framework.util.Util; 22 import java.lang.reflect.Array; 23 import java.lang.reflect.InvocationTargetException; 24 import java.lang.reflect.Method; 25 import java.util.ArrayList; 26 import java.util.Collection; 27 import java.util.Collections; 28 import java.util.HashMap; 29 import java.util.List; 30 import java.util.Map; 31 import java.util.Map.Entry; 32 import org.slf4j.Logger; 33 import org.slf4j.LoggerFactory; 34 import org.springframework.beans.factory.annotation.Autowired; 35 import org.springframework.stereotype.Service; 36 37 @Service("commService") 38 public class CommService 39 { 40 private static final Logger LOGGER = LoggerFactory.getLogger(CommService.class); 41 public static final String COMM_DO = "_commDo"; 42 public static final String ACTION_AFTER = "_afterAction"; 43 public static final String ACTION_BEFORE = "_beforeAction"; 44 public static final String DS = "_ds"; 45 @Autowired 46 private CommDAO commDAO; 47 48 static enum Transform 49 { 50 FIRSTROW, BREAKDOWN; 51 } 52 53 private static enum ExecType 54 { 55 MAPSQL, PROCEDURE, SERVICE; 56 } 57 58 private static enum MapSQLSuffix 59 { 60 I("_I"), D("_D"), U("_U"), NONE(""); 61 62 private String suffix = ""; 63 64 private MapSQLSuffix(String suffix) 65 { 66 this.suffix = suffix; 67 } 68 69 public String getName() 70 { 71 return this.suffix; 72 } 73 } 74 75 private class ExecMsg 76 { 77 private CommService.ExecType execType; 78 private String execStr; 79 private String objectName = ""; 80 private String methodName = ""; 81 82 private ExecMsg() {} 83 84 public String getObjectName() 85 { 86 return this.objectName; 87 } 88 89 public void setObjectName(String objectName) 90 { 91 this.objectName = objectName; 92 } 93 94 public String getMethodName() 95 { 96 return this.methodName; 97 } 98 99 public void setMethodName(String methodName) 100 { 101 this.methodName = methodName; 102 } 103 104 public CommService.ExecType getExecType() 105 { 106 return this.execType; 107 } 108 109 public void setExecType(CommService.ExecType execType) 110 { 111 this.execType = execType; 112 } 113 114 public String getExecStr() 115 { 116 return this.execStr; 117 } 118 119 public void setExecStr(String execStr) 120 { 121 this.execStr = execStr; 122 } 123 } 124 125 private int insert(String sqlId, Map<String, ?> paramsMap) 126 throws Exception 127 { 128 return this.commDAO.insert(sqlId, paramsMap); 129 } 130 131 private int delete(String sqlId, Map<String, ?> paramsMap) 132 throws Exception 133 { 134 return this.commDAO.delete(sqlId, paramsMap); 135 } 136 137 private int update(String sqlId, Map<String, ?> paramsMap) 138 throws Exception 139 { 140 return this.commDAO.update(sqlId, paramsMap); 141 } 142 143 public List<Map<String, Object>> query(IDTO dto) 144 throws Exception 145 { 146 String sqlId = (String)dto.getData().get("_commDo"); 147 return this.commDAO.select(sqlId, dto.getData()); 148 } 149 150 private Map<String, Object> doOneService(ExecMsg executeMsg, IDTO dto) 151 throws Throwable 152 { 153 String doActionCode = ""; 154 String actionMsg = "没有执行任何操作"; 155 Map<String, Object> paramsMap = dto.getData(); 156 Map<String, Object> rtnMap = new HashMap(); 157 String rtnURL = (String)paramsMap.get("_rtnURL"); 158 StringBuffer wfRtnURL = new StringBuffer(100); 159 String wId = ""; 160 String pId = ""; 161 Object rtnObj = null; 162 boolean startFlag = false; 163 boolean nextFlag = false; 164 boolean commitFlag = false; 165 boolean isSubWf = ((Boolean)(paramsMap.get("_isSubWf") == null ? Boolean.valueOf(false) : paramsMap.get("_isSubWf"))).booleanValue(); 166 paramsMap.put("_isSubWf", Boolean.valueOf(isSubWf)); 167 Util.nvl(paramsMap); 168 169 String wfDefineID = (String)paramsMap.get("_processDefId"); 170 String curActDefID = (String)paramsMap.get("_curActDefId"); 171 String workItemId = (String)paramsMap.get("wid"); 172 String wfState = ((String)Util.nvl(paramsMap.get("_wfState"))).toLowerCase(); 173 String pInsId = (String)paramsMap.get("pid"); 174 String keyData = (String)paramsMap.get("_keyData"); 175 String wfBZ = (String)paramsMap.get("_comment"); 176 String accepter = (String)paramsMap.get("_accepterId"); 177 String nextActDefID = (String)paramsMap.get("_nextActDefId"); 178 String isWfStart = ((String)(paramsMap.get("_isWfStart") != null ? paramsMap.get("_isWfStart") : "false")).toLowerCase(); 179 String jar = (String)paramsMap.get("_operId"); 180 LOGGER.info("/*******传入流程参数******************************/"); 181 LOGGER.info("_processDefId=" + wfDefineID); 182 LOGGER.info("_curActDefId=" + curActDefID); 183 LOGGER.info("_nextActDefId=" + nextActDefID); 184 LOGGER.info("wid=" + workItemId); 185 LOGGER.info("_wfState=" + wfState); 186 LOGGER.info("_isWfStart=" + isWfStart); 187 LOGGER.info("pid=" + pInsId); 188 LOGGER.info("_accepterId=" + accepter); 189 LOGGER.info("_keyData=" + keyData); 190 LOGGER.info("_comment=" + wfBZ); 191 LOGGER.info("/************end*********************************/"); 192 193 Map<String, String> respParams = new HashMap(); 194 195 IWorkflowService wfService = (IWorkflowService)Util.getBean("workflowService"); 196 if ("true".equals(isWfStart)) 197 { 198 if ("wf".equals(wfState)) 199 { 200 doActionCode = "001"; 201 actionMsg = "【001开始流程】"; 202 LOGGER.info(actionMsg); 203 respParams = wfService.startWf(wfDefineID, paramsMap); 204 pId = (String)respParams.get("pid"); 205 wId = (String)respParams.get("wid"); 206 if ((pId != null) && (pId.length() > 0)) { 207 startFlag = true; 208 } 209 if (startFlag) { 210 commitFlag = true; 211 } 212 } 213 else if ("data".equals(wfState)) 214 { 215 doActionCode = "002"; 216 actionMsg = "【002开始流程,保存数据】"; 217 LOGGER.info(actionMsg); 218 219 respParams = wfService.startWf(wfDefineID, paramsMap); 220 pId = (String)respParams.get("pid"); 221 wId = (String)respParams.get("wid"); 222 paramsMap.put("pid", pId); 223 if ((pId != null) && (pId.length() > 0)) { 224 startFlag = true; 225 } 226 rtnObj = doOperService(executeMsg, dto); 227 if (startFlag) { 228 commitFlag = true; 229 } 230 } 231 else if ("all".equals(wfState)) 232 { 233 doActionCode = "003"; 234 actionMsg = "【003开始流程,保存数据,提交下一环节】"; 235 LOGGER.info(actionMsg); 236 237 respParams = wfService.startWf(wfDefineID, paramsMap); 238 239 pId = (String)respParams.get("pid"); 240 wId = (String)respParams.get("wid"); 241 paramsMap.put("pid", pId); 242 if ((pId != null) && (pId.length() > 0)) { 243 startFlag = true; 244 } 245 rtnObj = doOperService(executeMsg, dto); 246 247 248 nextFlag = wfService.submitWorkItem(pId, wId, paramsMap); 249 if ((startFlag) && (nextFlag)) 250 { 251 pId = (String)paramsMap.get("pid"); 252 wId = (String)paramsMap.get("wid"); 253 commitFlag = true; 254 } 255 } 256 } 257 else 258 { 259 pId = pInsId; 260 wId = workItemId; 261 if ("wf".equals(wfState)) 262 { 263 if (("".equals(pId)) || ("".equals(wId))) { 264 throw new AppException("业务流水号和环节号不能为空!"); 265 } 266 doActionCode = "004"; 267 actionMsg = "【004提交到下一环节】"; 268 LOGGER.info(actionMsg); 269 270 commitFlag = wfService.submitWorkItem(pId, wId, paramsMap); 271 pId = (String)paramsMap.get("pid"); 272 wId = (String)paramsMap.get("wid"); 273 } 274 else if ("all".equals(wfState)) 275 { 276 if (("".equals(pId)) || ("".equals(wId))) { 277 throw new AppException("业务流水号和环节号不能为空!"); 278 } 279 doActionCode = "006"; 280 actionMsg = "【006保存数据,提交下一环节】"; 281 LOGGER.info(actionMsg); 282 283 rtnObj = doOperService(executeMsg, dto); 284 285 286 287 288 289 nextFlag = wfService.submitWorkItem(pId, wId, paramsMap); 290 LOGGER.info("提交环节" + (nextFlag ? "成功" : "失败")); 291 if (nextFlag) 292 { 293 pId = (String)paramsMap.get("pid"); 294 wId = (String)paramsMap.get("wid"); 295 commitFlag = true; 296 } 297 } 298 else 299 { 300 doActionCode = "005"; 301 actionMsg = "【005保存数据】"; 302 if (!Util.isEmpty(workItemId)) 303 { 304 WfWorkItem wfWorkItem = new WfWorkItem(); 305 wfWorkItem.setWORK_ITEM_ID(Long.valueOf(Long.parseLong(workItemId))); 306 wfWorkItem.setMEMO((String)Util.nvl(wfBZ)); 307 wfService.updateWorkItem(wfWorkItem); 308 } 309 LOGGER.info(actionMsg); 310 rtnObj = doOperService(executeMsg, dto); 311 commitFlag = true; 312 } 313 } 314 if (!commitFlag) { 315 throw new AppException("系统错误,数据提交失败!"); 316 } 317 boolean isGD = false; 318 if ((!isSubWf) && (pId != null) && (pId.trim().length() > 0)) 319 { 320 String isEnd = ""; 321 if (!"".equals(nextActDefID)) 322 { 323 WfActionDef wfDef = wfService.getWfByActionDef(wfDefineID, WfService.getNextDefId(nextActDefID)); 324 if (wfDef == null) 325 { 326 isEnd = "no"; 327 } 328 else 329 { 330 isEnd = wfDef.getSTART_OR_END(); 331 isGD = Boolean.parseBoolean((String)Util.nvl(Util.searchByKey(IWorkflow.Attr.GD.toString(), wfDef.getATTR()))); 332 String afterAction = (String)Util.nvl(Util.searchByKey("afterAction", wfDef.getATTR())); 333 if (!Util.isEmpty(afterAction)) 334 { 335 ExecMsg execMsg = getExecMsg(afterAction); 336 rtnObj = doOperService(execMsg, dto); 337 pId = (String)dto.getValue("pid"); 338 wId = (String)dto.getValue("wid"); 339 } 340 } 341 } 342 String rightId = (String)Util.nvl(wfService.getRightIdByWfDefId(wfDefineID)); 343 if ((Util.isEmpty(rightId)) && (!Util.isEmpty(wId))) 344 { 345 Map<String, String> url = wfService.getActionForward(Long.valueOf(wId)); 346 rightId = (String)url.get(IWorkflow.RightMsg.ID.toString()); 347 } 348 String menuId = (String)Util.nvl(wfService.getRightIdByPid(pId)); 349 if (("001".equals(doActionCode)) || 350 ("002".equals(doActionCode)) || 351 ("005".equals(doActionCode))) 352 { 353 Map<String, String> forward = wfService.getActionForward(curActDefID); 354 String rightIdStr = (String)forward.get("RIGHTID"); 355 wfRtnURL.append((String)forward.get(IWorkflow.RightMsg.URL.toString())).append(IWorkflow.RightMsg.URL.toString().indexOf("?") >= 0 ? "&" : "?") 356 .append("pid").append("=").append(pId) 357 .append("&") 358 .append("wid").append("=").append(wId) 359 .append("&RightID=").append(rightIdStr) 360 .append("&_menuID=").append(menuId) 361 .append("&").append("funcID").append("=").append(Util.nvl(forward.get(IWorkflow.RightMsg.BUSSFUNCID.toString()))); 362 } 363 else if (IWorkflow.ProcStartOrEnd.PSE_END.getState().equalsIgnoreCase(isEnd)) 364 { 365 wfRtnURL.append("/jsp/framework/blank.jsp"); 366 } 367 else if (jar.equals(accepter)) 368 { 369 Map<String, String> forward = wfService.getActionForward(curActDefID); 370 wfRtnURL.append("/Workflow.do?") 371 .append("pid").append("=").append(pId) 372 .append("&").append("wid").append("=").append(wId) 373 .append("&RightID=").append(rightId) 374 .append("&_menuID=").append(menuId) 375 .append("&").append("funcID").append("=").append(Util.nvl(forward.get(IWorkflow.RightMsg.BUSSFUNCID.toString()))); 376 } 377 else 378 { 379 wfRtnURL.append("/jsp/framework/blank.jsp"); 380 } 381 if ((rtnURL.equals("")) || (rtnURL.equalsIgnoreCase("null"))) { 382 rtnURL = wfRtnURL.toString(); 383 } 384 } 385 Map<String, Object> oMap = uniformResult(rtnObj); 386 rtnMap.putAll(oMap); 387 388 rtnMap.put("pid", pId); 389 rtnMap.put("wid", wId); 390 rtnMap.put("_rtnURL", rtnURL); 391 rtnMap.put(IWorkflow.Attr.GD.toString(), Boolean.toString(isGD)); 392 return rtnMap; 393 } 394 395 private ExecMsg getExecMsg(String execStr) 396 throws Exception 397 { 398 String[] exec = execStr.split("\\."); 399 String prefx = exec[0]; 400 ExecMsg execMsg = new ExecMsg(null); 401 if (Util.isEmpty(prefx)) { 402 throw new AppException("_commDo不合法!"); 403 } 404 if (prefx.lastIndexOf("Service") > 0) 405 { 406 execMsg.setExecType(ExecType.SERVICE); 407 execMsg.setObjectName(prefx); 408 execMsg.setMethodName(exec[1]); 409 return execMsg; 410 } 411 if (Util.isMatches(prefx, "^pkg_\\w+\\.\\w+$")) 412 { 413 execMsg.setExecType(ExecType.PROCEDURE); 414 execMsg.setExecStr(execStr); 415 return execMsg; 416 } 417 execMsg.setExecType(ExecType.MAPSQL); 418 execMsg.setExecStr(execStr); 419 return execMsg; 420 } 421 422 private Map<String, ?> doExecute(IDTO dto, String execStr) 423 throws Throwable 424 { 425 ExecMsg execMsg = getExecMsg(execStr); 426 427 Map<String, Object> rtnMap = null; 428 switch (execMsg.getExecType()) 429 { 430 case SERVICE: 431 rtnMap = doOneService(execMsg, dto); 432 break; 433 case PROCEDURE: 434 rtnMap = doProcedure(execMsg.getExecStr(), dto.getData(), (String)dto.getValue("_ds")); 435 break; 436 default: 437 switch (getMapSQLSuffix(execMsg.getExecStr())) 438 { 439 case D: 440 insert(execStr, dto.getData()); break; 441 case I: 442 update(execStr, dto.getData()); break; 443 case NONE: 444 delete(execStr, dto.getData()); break; 445 default: 446 throw new AppException("_commDo中" + execStr + "没有包含后缀_I、_U、_D"); 447 } 448 break; 449 } 450 return rtnMap; 451 } 452 453 private MapSQLSuffix getMapSQLSuffix(String execStr) 454 { 455 String actType = execStr.substring(execStr.lastIndexOf("_"), execStr.lastIndexOf("_") + 2).toUpperCase(); 456 if (MapSQLSuffix.I.getName().equalsIgnoreCase(actType)) { 457 return MapSQLSuffix.I; 458 } 459 if (MapSQLSuffix.D.getName().equalsIgnoreCase(actType)) { 460 return MapSQLSuffix.D; 461 } 462 if (MapSQLSuffix.U.getName().equalsIgnoreCase(actType)) { 463 return MapSQLSuffix.U; 464 } 465 return MapSQLSuffix.NONE; 466 } 467 468 public void doService(IDTO dto) 469 throws Throwable 470 { 471 try 472 { 473 final String[] execStrs = ((String)dto.getData().get("_commDo")).split("\\|"); 474 if (execStrs.length <= 0) { 475 throw new AppException("参数_commDo为指定操作"); 476 } 477 final IDTO dto2 = new DTO(); 478 dto2.setUserInfo(dto.getUserInfo()); 479 final Map<String, Object> argsMap = Util.mapClone(dto.getData()); 480 final Map<String, Object> rtnsMap = new HashMap(); 481 String ds = (String)dto.getValue("_ds"); 482 if (Util.isEmpty(ds)) { 483 for (String exec : execStrs) 484 { 485 dto2.setData(Util.mapClone(argsMap)); 486 487 488 Map<String, ?> rtnMap = doExecute(dto2, exec); 489 if (rtnMap != null) 490 { 491 rtnsMap.putAll(rtnMap); 492 argsMap.putAll(rtnsMap); 493 } 494 } 495 } else { 496 DataSourceCallBack.execute(ds, new IDataSourceCallBack() 497 { 498 public String doAction() 499 throws AppException 500 { 501 try 502 { 503 for (String exec : execStrs) 504 { 505 dto2.setData(Util.mapClone(argsMap)); 506 507 508 Map<String, ?> rtnMap = CommService.this.doExecute(dto2, exec); 509 if (rtnMap != null) 510 { 511 rtnsMap.putAll(rtnMap); 512 argsMap.putAll(rtnsMap); 513 } 514 } 515 } 516 catch (Throwable e) 517 { 518 throw new AppException(e.getLocalizedMessage(), e); 519 } 520 return ""; 521 } 522 }); 523 } 524 dto.setData(rtnsMap); 525 } 526 catch (Throwable t) 527 { 528 throw t; 529 } 530 } 531 532 private Object doOperService(ExecMsg executeMsg, IDTO dto) 533 throws Throwable 534 { 535 try 536 { 537 Object service = Util.getBean(executeMsg.getObjectName()); 538 Class<?> cls = service.getClass(); 539 LOGGER.debug("执行service:" + executeMsg.getObjectName() + "." + executeMsg.getMethodName()); 540 Method method = cls.getMethod(executeMsg.getMethodName(), new Class[] { IDTO.class }); 541 return method.invoke(service, new Object[] { dto }); 542 } 543 catch (InvocationTargetException e) 544 { 545 throw e.getTargetException(); 546 } 547 } 548 549 public void submitWf(IDTO dto) 550 throws AppException 551 { 552 try 553 { 554 IWorkflowService wfService = (IWorkflowService)Util.getBean("workflowService"); 555 if (wfService.submitWorkItem(dto)) 556 { 557 String execStr = (String)dto.getValue("_commDo"); 558 if (Util.isEmpty(execStr)) { 559 return; 560 } 561 ExecMsg execMsg = getExecMsg(execStr); 562 if (execMsg.getExecType() == ExecType.SERVICE) { 563 doOperService(execMsg, dto); 564 } else { 565 throw new AppException("未指定要执行业务处理的Serivce对象!"); 566 } 567 } 568 } 569 catch (AppException e) 570 { 571 throw e; 572 } 573 catch (Throwable e) 574 { 575 throw new AppException("提交任务失败!", e); 576 } 577 } 578 579 private Map<String, Object> doProcedure(String procedureName, Map<String, ?> values, String dataSource) 580 throws Exception 581 { 582 JdbcCallService service = (JdbcCallService)Util.getBean("jdbcCallService"); 583 return service.doProcedure(procedureName, values, dataSource); 584 } 585 586 public List<Object> doAjaxService(IDTO dto) 587 throws AppException 588 { 589 Map[] parameters = (Map[])dto.getValue("parameters"); 590 Map<String, Object> shareArguments = (Map)dto.getValue("shareParameters"); 591 if (LOGGER.isDebugEnabled()) 592 { 593 LOGGER.debug("处理ajax业务,入参串是:" + new JSONUtilities().parseObject(parameters)); 594 LOGGER.debug(">>>共享参数是:" + shareArguments); 595 } 596 List<Object> resultList = new ArrayList(); 597 for (Map<String, Object> serviceMap : parameters) 598 { 599 String serviceId = (String)serviceMap.get("serviceId"); 600 String methodName = (String)serviceMap.get("method"); 601 Object useShare = serviceMap.get("useShare"); 602 Object shareNotNull = serviceMap.get("shareNotNull"); 603 String transform = (String)serviceMap.get("transform"); 604 Map dtoData = dto.getData(); 605 if ((serviceId.length() == 0) || (methodName.length() == 0)) { 606 throw new AppException("EFW0001", null, new Object[] { "serviceId和method" }); 607 } 608 Map<String, Object> serviceParameters = (Map)serviceMap.get("parameters"); 609 610 Map<String, Object> arguments = new HashMap(); 611 if ((shareArguments != null) && (useShare != null)) 612 { 613 if (Boolean.TRUE.equals(useShare)) { 614 arguments.putAll(shareArguments); 615 } else { 616 for (Map.Entry<String, Object> entry : ((Map)useShare).entrySet()) 617 { 618 Object value = entry.getValue(); 619 if ((value instanceof Collection)) { 620 for (String c_value : (Collection)value) { 621 arguments.put(c_value, shareArguments.get(entry.getKey())); 622 } 623 } else { 624 arguments.put((String)value, shareArguments.get(entry.getKey())); 625 } 626 } 627 } 628 if (shareNotNull != null) { 629 if (Boolean.TRUE.equals(shareNotNull)) 630 { 631 for (Map.Entry<String, Object> entry : arguments.entrySet()) 632 { 633 if (entry.getValue() == null) { 634 throw new AppException("EFW0001", null, new Object[] { entry.getKey() }); 635 } 636 if (((entry.getValue() instanceof String)) && 637 (((String)entry.getValue()).length() == 0)) { 638 throw new AppException("EFW0001", null, new Object[] { entry.getKey() }); 639 } 640 } 641 } 642 else 643 { 644 int arrayLength = Array.getLength(shareNotNull); 645 for (int i = 0; i < arrayLength; i++) 646 { 647 Object one = Array.get(shareNotNull, i); 648 if (one != null) 649 { 650 String str = one.toString(); 651 Object value = arguments.get(str); 652 if (value == null) { 653 throw new AppException("EFW0001", null, new Object[] { str }); 654 } 655 if (((value instanceof String)) && 656 (((String)value).length() == 0)) { 657 throw new AppException("EFW0001", null, new Object[] { str }); 658 } 659 } 660 } 661 } 662 } 663 } 664 if (serviceParameters != null) { 665 arguments.putAll(serviceParameters); 666 } 667 dto.getData().clear(); 668 669 dto.getData().putAll(dtoData); 670 671 dto.setData(arguments); 672 673 Object service = Util.getBean(serviceId); 674 Object cls = service.getClass(); 675 LOGGER.debug("执行" + serviceId + "." + methodName); 676 677 Object rst = null; 678 try 679 { 680 Method method = ((Class)cls).getMethod(methodName, new Class[] { IDTO.class }); 681 rst = method.invoke(service, new Object[] { dto }); 682 } 683 catch (SecurityException e) 684 { 685 throw new AppException("无访问权限", e); 686 } 687 catch (InvocationTargetException e) 688 { 689 throw new AppException(e.getTargetException().getMessage(), e.getTargetException()); 690 } 691 catch (NoSuchMethodException e) 692 { 693 throw new AppException(serviceId + "中未找到方法" + methodName, e); 694 } 695 catch (IllegalArgumentException e) 696 { 697 throw new AppException("非法参数", e); 698 } 699 catch (IllegalAccessException e) 700 { 701 throw new AppException("非法访问", e); 702 } 703 Method method; 704 if ((rst != null) && ((rst instanceof List)) && (!((List)rst).isEmpty()) && (transform != null)) { 705 switch (Transform.valueOf(transform.toUpperCase())) 706 { 707 case BREAKDOWN: 708 rst = ((List)rst).get(0); 709 break; 710 default: 711 rst = breakDown((List)rst); 712 } 713 } 714 resultList.add(rst); 715 if ((rst != null) && (serviceMap.get("shareResults") != null)) 716 { 717 Object shareResult = serviceMap.get("shareResults"); 718 if (!Boolean.FALSE.equals(shareResult)) { 719 if (Boolean.TRUE.equals(shareResult)) 720 { 721 Object t = uniformResult(rst); 722 if (t != null) { 723 shareArguments.putAll(uniformResult(rst)); 724 } 725 } 726 else 727 { 728 Map<String, Object> resultMap = uniformResult(rst); 729 for (Map.Entry<String, Object> entry : ((Map)shareResult).entrySet()) 730 { 731 Object value = entry.getValue(); 732 if ((value instanceof Collection)) { 733 for (String c_value : (Collection)value) { 734 shareArguments.put(c_value, resultMap.get(entry.getKey())); 735 } 736 } else { 737 shareArguments.put((String)value, resultMap.get(entry.getKey())); 738 } 739 } 740 } 741 } 742 } 743 } 744 return resultList; 745 } 746 747 public Map<String, String> startWf(IDTO dto) 748 throws AppException 749 { 750 String SERVER_OBJECT = "object"; 751 752 753 754 String SERVER_METHOD = "method"; 755 756 757 Map<String, Object> params = dto.getData(); 758 String processDefId = (String)params.get("_processDefId"); 759 String keyData = (String)params.get("_keyData"); 760 String OPERID = (String)params.get("_operId"); 761 if (Util.isEmpty(processDefId)) { 762 throw new AppException("未指定流程定义ID,key=_processDefId"); 763 } 764 if (Util.isEmpty(OPERID)) 765 { 766 if (dto.getUserInfo() == null) { 767 throw new AppException("未指定经办人,key=_operId"); 768 } 769 dto.setValue("_operId", dto.getUserInfo().getLoginID()); 770 } 771 if (Util.isEmpty(keyData)) { 772 LOGGER.warn("未指定关键信息,key=_keyData"); 773 } 774 try 775 { 776 String commDo = (String)params.get("_commDo"); 777 String wfstate = (String)params.get("_wfState"); 778 779 String serverObject = (String)params.get("object"); 780 String serverMethod = (String)params.get("method"); 781 if (Util.isEmpty(wfstate)) 782 { 783 wfstate = "wf"; 784 } 785 else 786 { 787 if (Util.isEmpty(commDo)) { 788 commDo = serverObject + "." + serverMethod; 789 } 790 if (Util.isEmpty(commDo)) { 791 LOGGER.warn("未指定_commDo"); 792 } 793 } 794 dto.setValue("_isWfStart", params.get("_isWfStart")); 795 dto.setValue("_wfState", wfstate); 796 dto.setValue("_isSubWf", Boolean.valueOf(true)); 797 dto.setValue("_commDo", commDo); 798 CommService commService = (CommService)Util.getBean("commService"); 799 commService.doService(dto); 800 Map<String, String> respMap = new HashMap(); 801 respMap.put("pid", (String)dto.getValue("pid")); 802 respMap.put("wid", (String)dto.getValue("wid")); 803 return respMap; 804 } 805 catch (Throwable e) 806 { 807 LOGGER.error("开启流程失败,详细:" + e.getMessage(), e); 808 throw new AppException("开启流程失败,详细:" + e.getMessage(), e); 809 } 810 } 811 812 private Map<String, Object> breakDown(List<Map<String, Object>> rst) 813 { 814 if ((rst == null) || (rst.isEmpty())) { 815 return null; 816 } 817 Object row = rst.get(0); 818 819 Map<String, Object> rest = new HashMap(); 820 for (String key : ((Map)row).keySet()) { 821 rest.put(key, new ArrayList(rst.size())); 822 } 823 for (Map.Entry<String, Object> key : ((Map)row).entrySet()) { 824 ((Collection)rest.get(key.getKey())).add(key.getValue()); 825 } 826 return rest; 827 } 828 829 private Map<String, Object> uniformResult(Object rst) 830 { 831 if ((rst instanceof Map)) { 832 return (Map)rst; 833 } 834 if ((rst instanceof List)) { 835 return Collections.singletonMap("", rst); 836 } 837 return Collections.singletonMap("", rst); 838 } 839 840 public void storeException(String url, IDTO dto, String operId, Throwable e) 841 { 842 try 843 { 844 if ("1".equals(ConfUtil.getParam("STORE_EXCEPTION"))) 845 { 846 LOGGER.debug("保存异常信息到FW_LOG4EXCEPTION表"); 847 IDAO dao = (IDAO)Util.getBean("commDAO"); 848 849 StringBuffer ex = new StringBuffer(); 850 if (e != null) 851 { 852 ex.append(e.getLocalizedMessage()); 853 StackTraceElement[] st = e.getStackTrace(); 854 for (StackTraceElement ste : st) { 855 ex.append(ste.toString()); 856 } 857 } 858 String exStr = ex.toString(); 859 if (exStr.getBytes().length > 1333) { 860 exStr = Util.subStringByte(exStr, 1333); 861 } 862 String paramStr = ""; 863 if (dao != null) 864 { 865 dto.getData().remove("struts.valueStack"); 866 dto.getData().remove("struts.actionMapping"); 867 dto.getData().remove("CharacterEncodingFilter.FILTERED"); 868 dto.getData().remove("__cleanup_recursion_counter"); 869 dto.getData().remove("org.springframework.web.context.request.RequestContextListener.REQUEST_ATTRIBUTES"); 870 dto.getData().remove("OPERATOR"); 871 JSONUtilities jsonUtil = new JSONUtilities(); 872 paramStr = jsonUtil.parseObject(dto.getData()).toString(); 873 } 874 if (paramStr.getBytes().length > 1333) { 875 paramStr = Util.subStringByte(paramStr, 1333); 876 } 877 Object err = new HashMap(5); 878 ((Map)err).put("EXCEPTIONSTACK", exStr); 879 ((Map)err).put("URL", (String)Util.nvl(url)); 880 ((Map)err).put("PARAMS", paramStr); 881 ((Map)err).put("OPERID", (String)Util.nvl(operId)); 882 ((Map)err).put("EVENTTIME", DateUtil.CurDate.YYYYMMDDHHmmss.getDate()); 883 dao.insert("FW_CONFIG.FW_LOG4EXCEPTION_I", (Map)err); 884 } 885 } 886 catch (Exception ex) 887 { 888 LOGGER.error(ex.getLocalizedMessage(), ex); 889 } 890 } 891 892 public <T> T autoActoin(IDataSourceCallBack<T> action) 893 { 894 return action.doAction(); 895 } 896 }
标签:
原文地址:http://www.cnblogs.com/Sunnor/p/5771297.html