You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
7.7 KiB
215 lines
7.7 KiB
package com.fr.plugin.jkIT.handler; |
|
|
|
import com.fr.decision.authority.data.User; |
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
import com.fr.decision.webservice.bean.user.UserBean; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.jkIT.utils.FRUserUtils; |
|
import com.fr.plugin.jkIT.utils.FRUtils; |
|
import com.fr.plugin.jkIT.utils.ResponseUtils; |
|
import com.fr.plugin.jkIT.utils.Utils; |
|
import com.fr.plugin.transform.FunctionRecorder; |
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
@FunctionRecorder |
|
public class ITHandler extends BaseHttpHandler { |
|
|
|
|
|
public ITHandler() { |
|
} |
|
|
|
@Override |
|
public RequestMethod getMethod() { |
|
return RequestMethod.POST; |
|
} |
|
|
|
@Override |
|
public String getPath() { |
|
return "/operateUser"; |
|
} |
|
|
|
@Override |
|
public boolean isPublic() { |
|
return true; |
|
} |
|
|
|
@Override |
|
public void handle(HttpServletRequest req, HttpServletResponse res){ |
|
JSONObject object = Utils.getRequestBody(req); |
|
FRUtils.FRLogInfo("json:"+object.toString()); |
|
//获取请求参数 |
|
|
|
//同步任务流水号 |
|
String requestId = object.getString("requestId"); |
|
String appId = object.getString("appId"); |
|
String appKey = object.getString("appKey"); |
|
//操作类型 1、Add-新增 |
|
//2、Disable-停用 |
|
//3、Enable-启用 |
|
//4、Delete-删除 |
|
//5、Modify-修改 |
|
//6、ModifyPassword-修改密码 |
|
//8、TestConnection-测试服务通信 |
|
String actionType = object.getString("actionType"); |
|
//账户列表 |
|
// String accountList = req.getParameter("accountList"); |
|
JSONObject account = object.getJSONArray("accountList").getJSONObject(0); |
|
|
|
if(Utils.isNullStr(actionType)){ |
|
FRUtils.FRLogInfo("必填参数不能为空!"); |
|
return; |
|
} |
|
|
|
FRUtils.FRLogInfo("param:"+requestId+";"+appId+";"+appKey+";"+actionType); |
|
|
|
//返回json |
|
JSONObject result = new JSONObject(); |
|
|
|
if("Add".equals(actionType)){ |
|
|
|
String username = account.getString("accountId"); |
|
String email = account.getString("email"); |
|
String mobile = account.getString("mobile"); |
|
String realName = account.getString("cn"); |
|
|
|
UserBean userBean = new UserBean(); |
|
userBean.setRealName(realName); |
|
userBean.setPassword("1"); |
|
userBean.setUsername(username); |
|
userBean.setEmail(email); |
|
userBean.setMobile(mobile); |
|
|
|
try { |
|
FRUserUtils.addUser(userBean); |
|
JSONArray resultArray = new JSONArray(); |
|
JSONObject resultObject = new JSONObject(); |
|
resultObject.put("accountId",username); |
|
resultObject.put("accountCode",username); |
|
|
|
resultArray.add(resultObject); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",true); |
|
result.put("returnCode",0); |
|
result.put("returnMessage",""); |
|
result.put("accountList",resultArray); |
|
|
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("账号添加异常:"+e.getMessage()); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",false); |
|
result.put("returnCode",5); |
|
result.put("returnMessage","账号添加异常"); |
|
} |
|
} |
|
else if("Disable".equals(actionType)){ |
|
// JSONObject account = new JSONArray(accountList).getJSONObject(0); |
|
String username = account.getString("accountId"); |
|
|
|
try { |
|
User user = FRUserUtils.getUserByUserName(username); |
|
FRUserUtils.forbidUser(user.getId(),false); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",true); |
|
result.put("returnCode",0); |
|
result.put("returnMessage",""); |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("账号删除异常:"+e.getMessage()); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",false); |
|
result.put("returnCode",5); |
|
result.put("returnMessage","账号删除异常"); |
|
} |
|
} |
|
else if("Enable".equals(actionType)){ |
|
// JSONObject account = new JSONArray(accountList).getJSONObject(0); |
|
String username = account.getString("accountId"); |
|
|
|
try { |
|
User user = FRUserUtils.getUserByUserName(username); |
|
FRUserUtils.forbidUser(user.getId(),true); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",true); |
|
result.put("returnCode",0); |
|
result.put("returnMessage",""); |
|
|
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("账号删除异常:"+e.getMessage()); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",false); |
|
result.put("returnCode",5); |
|
result.put("returnMessage","账号删除异常"); |
|
} |
|
} |
|
else if("Delete".equals(actionType)){ |
|
// JSONObject account = new JSONArray(accountList).getJSONObject(0); |
|
String username = account.getString("accountId"); |
|
|
|
try { |
|
User user = FRUserUtils.getUserByUserName(username); |
|
FRUserUtils.deleteUser(user); |
|
|
|
result.put("requestId",requestId); |
|
result.put("returnFlag",true); |
|
result.put("returnCode",0); |
|
result.put("returnMessage",""); |
|
|
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("账号删除异常:"+e.getMessage()); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",false); |
|
result.put("returnCode",5); |
|
result.put("returnMessage","账号删除异常"); |
|
} |
|
} |
|
else if("Modify".equals(actionType)){ |
|
// JSONObject account = new JSONArray(accountList).getJSONObject(0); |
|
|
|
String username = account.getString("accountId"); |
|
String email = account.getString("email"); |
|
String mobile = account.getString("mobile"); |
|
String realName = account.getString("cn"); |
|
|
|
try { |
|
User user = FRUserUtils.getUserByUserName(username); |
|
UserBean userBean = new UserBean(); |
|
userBean.setId(user.getId()); |
|
userBean.setRealName(realName); |
|
userBean.setEmail(email); |
|
userBean.setMobile(mobile); |
|
FRUserUtils.updateUser(userBean); |
|
|
|
result.put("requestId",requestId); |
|
result.put("returnFlag",true); |
|
result.put("returnCode",0); |
|
result.put("returnMessage",""); |
|
|
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("账号修改异常:"+e.getMessage()); |
|
result.put("requestId",requestId); |
|
result.put("returnFlag",false); |
|
result.put("returnCode",5); |
|
result.put("returnMessage","账号修改异常"); |
|
} |
|
} |
|
else if("ModifyPassword".equals(actionType)){ |
|
|
|
} |
|
else if("TestConnection".equals(actionType)){ |
|
result.put("requestId",requestId); |
|
result.put("appId",appId); |
|
result.put("appKey",appKey); |
|
result.put("actionType",actionType); |
|
} |
|
|
|
FRUtils.FRLogInfo("result:"+result.toString()); |
|
ResponseUtils.response(res,result); |
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|