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.
109 lines
3.2 KiB
109 lines
3.2 KiB
package com.fr.plugin.it.handler; |
|
|
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
import com.fr.decision.webservice.bean.user.DepartmentPostBean; |
|
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.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.List; |
|
import java.util.Map; |
|
|
|
@FunctionRecorder |
|
public class AddDepartment extends BaseHttpHandler { |
|
|
|
public AddDepartment() { |
|
} |
|
|
|
@Override |
|
public RequestMethod getMethod() { |
|
return RequestMethod.POST; |
|
} |
|
|
|
@Override |
|
public String getPath() { |
|
return "/addOrg"; |
|
} |
|
|
|
@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 = ""; |
|
String orgCode2 = ""; |
|
|
|
for(Map<String,String> data : map){ |
|
String orgCode = data.get("ORG_CODE"); |
|
orgCode2 = orgCode; |
|
String orgName = data.get("ORG_NAME"); |
|
String pCode = data.get("PARENT_CODE"); |
|
String pId = ""; |
|
|
|
if(Utils.isNullStr(pCode)){ |
|
pId = "decision-dep-root"; |
|
}else{ |
|
pId = DbController.getOrg(pCode).getDid(); |
|
} |
|
|
|
if(Utils.isNullStr(pId)){ |
|
xmlResponse = ResponseTemplate.xmlTemplate("N","请先添加上级机构!",xml); |
|
ResponseUtils.responseXml(res,xmlResponse); |
|
return; |
|
} |
|
|
|
try { |
|
DepartmentPostBean dpb = FRDepartmentUtils.addDP(pId,orgName); |
|
DataBean dataBean = new DataBean(); |
|
dataBean.setDid(dpb.getId()); |
|
dataBean.setCode(orgCode); |
|
FRUtils.FRLogInfo("did:"+dpb.getId()+";orgCode="+orgCode); |
|
DbController.add(dataBean); |
|
} 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; |
|
} |
|
} |
|
|
|
xmlResponse = ResponseTemplate.xmlTemplate("Y","",orgCode2,xml); |
|
|
|
ResponseUtils.responseXml(res,xmlResponse); |
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|