1、新增一个action类,例如xp/common/actions/
OrgAction.java
,并继承ExtendAction类
添加如下方法(例子):
/**
* @apiNote 获取组织架构对象的层级ID
* @author liquid-xp
* @date 2022年5月23日
* 传入参数-
* fd_id: (可选)组织架构对象id
* fd_login_name: (可选)人员登录名
* 以上参数优先级逐次降低,若均无(空串或null)则选用[当前页面调用人员对象]
* 返回参数-
* fd_hierarchy: 组织架构对象层级ID
*/
public ActionForward getFdHierarchyId(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
JSONObject result = new JSONObject();
response.setHeader("Content-Type", "application/json;charset=utf-8");
String bodyStr = ReadAsChars(request);
JSONObject o = JSONObject.parseObject(bodyStr);
// 获取body参数
String fd_id = o.getString("fd_id");// 组织架构对象fd_id
String fd_login_name = o.getString("fd_login_name");// 组织架构对象fd_id
// 获取架构对象
SysOrgElement orgElm = xpOrgUtil.getOrgObjByOptions(fd_id, fd_login_name, request);
if (xpHibernateUtil.isHbmObjNull(orgElm)) {// 校验失败(还存在问题)
result.put("status", "error");
result.put("msg", "参数错误,请检查[fd_id]和[fd_login_name]");
result.put("fd_id", fd_id);
result.put("fd_login_name", fd_login_name);
}
else {// 校验通过
result.put("status", "success");
result.put("msg", "调用成功");
result.put("fd_id", fd_id);
result.put("fd_hierarchy", orgElm.getFdHierarchyId());
}
xpRequestUtil.setResponseResult(response, result);
return null;
}
2、新增一个spring-mvc.xml文件,例如 WebContent\WEB-INF\KmssConfig\xp\common\
spring-mvc.xml
注入bean:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
class="com.landray.kmss.xp.common.actions.OrgAction"
name="/xp/common/actions/orgAction.do"
lazy-init="true">
</bean>
</beans>
以上修改完后编译重启服务器即可生效。
3、调用示例
// 未封装ajax
let _data = {
fd_id: "17d765adef50beb6c47d3d344e6a7847"
}
$.ajax({
type: "POST",
contentType:"application/json;charset=utf-8",
url: Com_Parameter.ContextPath + 'xp/common/actions/orgAction.do?method=getFdHierarchyId',
data: JSON.stringify(_data),
dataType:"json",
async: false,
success: function(res) {
console.log(res);
}
})
// ajax函数封装
let _data = {fd_id: "17d765adef50beb6c47d3d344e6a7847"}
ajaxOrgAction("getFdHierarchyId", _data, false, {
success: (res)=>{
console.log(res)
}
})