JSD-8204 ITASK集成(接口+单点)
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.

163 lines
5.3 KiB

package com.fr.plugin.it.handler;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.webservice.bean.user.DepartmentPostBean;
import com.fr.decision.webservice.bean.user.UserBean;
import com.fr.decision.webservice.bean.user.UserUpdateBean;
import com.fr.plugin.it.dbAccessProvider.DataBean;
import com.fr.plugin.it.dbAccessProvider.DbController;
import com.fr.plugin.it.utils.*;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@FunctionRecorder
public class UserGroup extends BaseHttpHandler {
private static DBAccessor accessor;
public UserGroup() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/userGroup";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res){
//获取xml报文
StringBuilder stb = new StringBuilder();
try{
BufferedReader in = new BufferedReader(new InputStreamReader(req.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
stb.append(line);
}
}catch(Exception e){
FRUtils.FRLogError("获取xml报文异常!");
}
String xml = stb.toString();
FRUtils.FRLogInfo("xml:"+xml);
List<Map<String,String>> map = XMLUtils.xmlToList(xml);
String xmlResponse = ResponseTemplate.xmlTemplate("Y","",xml);
if(map != null && map.size() > 0){
Map<String,String> data = map.get(0);
String username = data.get("ACCOUNT_NO");
String orgCode = data.get("ORG_CODE");
String type = data.get("GROUP_TYPE");
String action = data.get("ACTION_TYPE");
//组织id
String id = DbController.getOrg(orgCode).getDid();
if(Utils.isNullStr(id)){
xmlResponse = ResponseTemplate.xmlTemplate("N","系统中不存在此机构!",xml);
ResponseUtils.responseXml(res,xmlResponse);
return;
}
String gwId = DbController.getOrg(orgCode+type).getDid();
String userId = "";
try {
userId = FRUserUtils.getUserByUserName(username).getId();
} catch (Exception e) {
FRUtils.FRLogError("获取系统用户异常!");
xmlResponse = ResponseTemplate.xmlTemplate("N","获取系统用户异常!",xml);
ResponseUtils.responseXml(res,xmlResponse);
return;
}
//
UserUpdateBean ub = new UserUpdateBean();
if("D".equals(action)){
ub.setDepartmentId(gwId);
ub.setRemoveUserIds(new String[]{userId});
}
if("N".equals(action)){
if(Utils.isNullStr(gwId) && "A".equals(type)){
String dpName = "A".equals(type)?"主岗领导":"兼岗领导";
DepartmentPostBean departmentPostBean = null;
try {
departmentPostBean = FRDepartmentUtils.addDP(id,dpName);
} catch (Exception e) {
FRUtils.FRLogError("添加岗位机构机构异常!");
xmlResponse = ResponseTemplate.xmlTemplate("N","添加岗位机构机构异常!",xml);
ResponseUtils.responseXml(res,xmlResponse);
return;
}
DataBean dataBean = new DataBean();
dataBean.setPid(id);
dataBean.setType(type);
dataBean.setCode(orgCode+type);
dataBean.setDid(departmentPostBean.getId());
DbController.add(dataBean);
gwId =departmentPostBean.getId();
}
else{
String message = "此操作只支持主岗添加!";
FRUtils.FRLogInfo("此操作只支持主岗添加!");
xmlResponse = ResponseTemplate.xmlTemplate("N",message,xml);
ResponseUtils.responseXml(res,xmlResponse);
return;
}
ub.setDepartmentId(gwId);
ub.setAddUserIds(new String[]{userId});
}
try {
FRUserUtils.updateDepartmentPostUsers(ub.getDepartmentId(),"",ub);
} catch (Exception e) {
String message = e.getMessage();
if(Utils.isNullStr(message)){
message = "同步用户组异常";
}
FRUtils.FRLogError("同步用户组异常!");
xmlResponse = ResponseTemplate.xmlTemplate("N",message,xml);
ResponseUtils.responseXml(res,xmlResponse);
return;
}
}
ResponseUtils.responseXml(res,xmlResponse);
}
}