123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- /**
- *
- */
- package com.cockpit.service;
- import java.io.UnsupportedEncodingException;
- import java.net.URLDecoder;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.StringTokenizer;
- import javax.servlet.http.HttpServletRequest;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import net.sf.json.JSONArray;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import com.formaction.Utils;
- import com.google.gson.JsonArray;
- import com.persistence.DbConnection;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.exception.PersistenceException;
- import com.cockpit.dao.OrganizationsBusi;
- import com.sinosoft.common.excel.JsonPluginsUtil;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- /**
- * @author 蒋云涛
- *
- */
- @Path("/IcingOrganizationsService/")
- public class OrganizationsService{
-
- /**
- * 将params 字符串转化为 map集合
- * @param params
- * @return
- */
- public Map<String,String> getMap(String params){
- Map<String,String> paramsMap = new HashMap<String,String>();
- StringTokenizer commaToker = new StringTokenizer(params, "&");
- String temp_str = "";
- while (commaToker.hasMoreTokens()) {
- temp_str = commaToker.nextToken();
- String[] key_value = temp_str.split("=");
- try {
- if(key_value.length==2){
-
- paramsMap.put(URLDecoder.decode(key_value[0], "utf-8"), URLDecoder.decode(key_value[1], "utf-8"));
-
- }else{
- paramsMap.put(URLDecoder.decode(key_value[0], "utf-8"),"");
-
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- }
-
- return paramsMap;
-
- }
-
- /**
- * 根据传来的的deptId 和id 判断是否为初次加载(因为初次加载时不会有id的值传入)
- * 如果是初次加载就加载传来id的机构信息和id下的一级子id 非初次加载就只显示 id下的一级子机构信息
- * 如果传来的参数中存在 per 表示要加载人员
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getOrgInfoById")
- public String getOrgInfoById(String params){
- boolean isFirstLoad=false;
- boolean getPerson = false;
- String deptid = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
- "type", params);
- String LoadCorp = Utils.getParameter("loadCorp", params) == null ? "" : Utils.getParameter(
- "loadCorp", params);
- boolean isOnlyLoadCorp = "loadCorp".equals(LoadCorp);
- String result = "";
-
- if(id==null||"".equals(id)){
- id=deptid;
- isFirstLoad=true;
- }
- if(type=="per"||"per".equals(type)){
-
- getPerson = true;
- }
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- if(isOnlyLoadCorp){
-
- result = orgbusi.getOrgCorpById(id,isFirstLoad);
- }else{
-
- result = orgbusi.getOrgInfoById(id,getPerson,isFirstLoad);
-
- }
- return result;
- }
- /**
- * 内部机构的加载方法(也可以加载应急机构信息需在参数传入时添加loadOrgTable="emcOrg")
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/loadSysOrgInfo")
- public String loadSysOrgInfo(String params){
- String result ="";
- Map<String,String> loadSysOrgInfo = new HashMap<String,String>();
- loadSysOrgInfo = getMap(params);
- OrganizationsBusi ob = new OrganizationsBusi();
- result = ob.loadSysOrgInfo2(loadSysOrgInfo);
- return result;
- }
- //新单位树除文件外的
- @ProduceMime("application/json")
- @POST
- @Path("/loadSysOrgInfo2")
- public String loadSysOrgInfo2(String params){
- String result ="";
- Map<String,String> loadSysOrgInfo = new HashMap<String,String>();
- loadSysOrgInfo = getMap(params);
- OrganizationsBusi ob = new OrganizationsBusi();
- result = ob.loadSysOrgInfo3(loadSysOrgInfo);
- return result;
- }
- @ProduceMime("application/json")
- @POST
- @Path("/loadSysOrgInfo20")
- public String loadSysOrgInfo20(String params){//通知单左侧数--gel
- String result ="";
- String uniteId = params.split("&")[0].split("=")[1];
- Map<String,String> loadSysOrgInfo = new HashMap<String,String>();
- loadSysOrgInfo = getMap(params);
- OrganizationsBusi ob = new OrganizationsBusi();
- result = ob.loadSysOrgInfo3(loadSysOrgInfo);
-
- //获取上级单位的ID和NAME
- String parentUnitMsg = getParentUnitMsg(uniteId);
- //System.out.println("//////////////"+parentUnitMsg);//78D3C3942A7E434DAB0D79F55C645232,广东电网有限责任公司
-
- Map<String, String> resultMap = JsonPluginsUtil.jsonToMap(result);
- Map<String, List<Map<String, String>>>tempList=new HashMap<String, List<Map<String,String>>>();
- String res = resultMap.get("treeNodes");
- List<Map<String, String>>resList=JsonPluginsUtil.jsonToMapList(res);
- Map<String, String> temMap = new HashMap<String, String>();
-
-
- temMap.put("id", parentUnitMsg.split(",")[0]);
- temMap.put("icon", "/nwyj/scripts/qui/libs/icons/folder.png");
- temMap.put("open", "true");
- temMap.put("parentId", "0");
- temMap.put("name", parentUnitMsg.split(",")[1]);
- temMap.put("isParent", "false");
- temMap.put("orgLevel", "null");
- resList.add(temMap);
- //resList=getTopComp(parentUnitMsg.split(",")[0],resList);
- tempList.put("treeNodes", resList);
- result=JSONArray.fromObject(tempList).toString();
- result=result.substring(1, result.length()-1);
- //System.out.println("***************"+result);
- return result;
- }
-
- public List<Map<String, String>> getTopComp(String dept_id,List<Map<String, String>>resultList){//递归钻去上级单位
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select dept_id,dept_name,parent_id from sys_department where dept_id='"+dept_id+"'";
- if(dept_id!="BBD3C37F68094363AABC3CAD5FEE0AF8"){//网公司ID
- try {
- List<String[]> colList = persistence.getSearchResult(99, sql.toString());
- if(colList!=null&&colList.size()>0){
- Map<String, String>temMap=new HashMap<String, String>();
- temMap.put("id",colList.get(0)[0]);
- temMap.put("icon", "/nwyj/scripts/qui/libs/icons/folder.png");
- temMap.put("open", "true");
- temMap.put("parentId", colList.get(0)[2]);
- temMap.put("name", colList.get(0)[1]);
- temMap.put("isParent", "false");
- temMap.put("orgLevel", "null");
- resultList.add(temMap);
- return getTopComp(colList.get(0)[2], resultList);
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- return resultList;
- }
- return resultList;
- }
-
- public String getParentUnitMsg(String uniteId){//获取上级单位的单位ID和单位名称
- StringBuffer sb = new StringBuffer();
- String sql = "select DEPT_ID,DEPT_NAME from SYS_DEPARTMENT where DEPT_ID in (select PARENT_ID from SYS_DEPARTMENT where DEPT_ID='"+uniteId+"')";
- DbConnection dbConn = new DbConnection();//数据库连接
- Connection conn = null;
- PreparedStatement pstm = null;//sql语句的执行者
- ResultSet rs = null;//结果集
- try {
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- rs = pstm.executeQuery();
- while(rs.next()){
- String a = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");
- String b = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");
- sb.append(a+","+b+",");
- }
- if(sb.lastIndexOf(",") > -1){
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }finally{
- try {
- if(rs!=null)
- rs.close();
- if(pstm!=null)
- pstm.close();
- if(conn!=null)
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
- /**
- * 内部机构的加载方法(也可以加载应急机构信息需在参数传入时添加loadOrgTable="emcOrg")
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/loadSysOrgInfo3")
- public String loadSysOrgInfo3(String params){
- String result ="";
- Map<String,String> loadSysOrgInfo = new HashMap<String,String>();
- loadSysOrgInfo = getMap(params);
- OrganizationsBusi ob = new OrganizationsBusi();
- result = ob.loadSysOrgInfo4(loadSysOrgInfo);
- return result;
- }
- //制度文件用简化型单位树
- @ProduceMime("application/json")
- @POST
- @Path("/loadSysOrgInfo4")
- public String loadSysOrgInfo4(String params){
- String result ="";
- Map<String,String> loadSysOrgInfo = new HashMap<String,String>();
- loadSysOrgInfo = getMap(params);
- OrganizationsBusi ob = new OrganizationsBusi();
- result = ob.loadSysOrgInfo5(loadSysOrgInfo);
- return result;
- }
- /**
- *
- * 外部机构的加载方法
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/loadSysOrgOuterInfo")
- public String loadSysOrgOuterInfo(String params){
- String result ="";
- Map<String,String> loadSysOrgOuterInfo = new HashMap<String,String>();
- loadSysOrgOuterInfo = getMap(params);
- OrganizationsBusi ob = new OrganizationsBusi();
- result = ob.loadSysOrgOuterInfo(loadSysOrgOuterInfo);
- return result;
-
-
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/getOrgCorpById")
- public String getOrgCorpById(String params){
- boolean isFirstLoad=false;
- String deptid = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- if(id==null||"".equals(id)){
- id=deptid;
- isFirstLoad=true;
- }
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.getOrgCorpById(id,isFirstLoad);
- return result;
- }
- /**
- * 根据传来的id加载出未显示的机构(人员)信息
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/addOrgInfoById")
- public String addOrgInfoById(String params){
- HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
- String targetOrg = request.getParameter("targetOrg");
- /*String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);*/
- String orgLevel = Utils.getParameter("orgLevel", params) == null ? "" : Utils.getParameter(
- "orgLevel", params);
- String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
- "type", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String LoadCorp = Utils.getParameter("loadCorp", params) == null ? "" : Utils.getParameter(
- "loadCorp", params);
- boolean isOnlyLoadCorp = "loadCorp".equals(LoadCorp);
- System.out.println(LoadCorp);
- String result = "";
- result = orgbusi.addOrgInfoById(targetOrg,orgLevel,type,isOnlyLoadCorp);
- return result;
- }
- /**
- * 根据传来的id 查询机构信息
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/queryOrgInfo")
- public String queryOrgInfo(String params){
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String role = Utils.getParameter("role", params) == null ? "" : Utils.getParameter(
- "role", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.getParentOrgsInfoById(id,role);
- return result;
-
- }
- @ProduceMime("application/json")
- @POST
- @Path("/queryOrgByName")
- public String queryOrgByName(String params){
- String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter(
- "name", params);
- String type =Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
- "type", params);
- String role =Utils.getParameter("role", params) == null ? "" : Utils.getParameter(
- "role", params);
- String LoadCorp = Utils.getParameter("loadCorp", params) == null ? "" : Utils.getParameter(
- "loadCorp", params);
- boolean isOnlyLoadCorp = "loadCorp".equals(LoadCorp);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result ="";
- if(isOnlyLoadCorp){
-
- result = orgbusi.getOrgCorpInfoByName(name,type,role);
-
- }else{
-
-
- result = orgbusi.getOrgInfoByName(name,type,role);
-
- }
- return result;
- }
- /***********************常用组织*****************************************/
- @ProduceMime("application/json")
- @POST
- @Path("/getCommonOrgInfoById")
- public String getCommonOrgInfoById(String params){
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String type =Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
- "type", params);
- String userId =Utils.getParameter("userId", params) == null ? "" : Utils.getParameter(
- "userId", params);
- String groupType =Utils.getParameter("groupType", params) == null ? "" : Utils.getParameter(
- "groupType", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.getCommonOrgInfoById(id,type,userId,groupType);
- return result;
-
- }
- @ProduceMime("application/json")
- @POST
- @Path("/queryCommonOrgByName")
- public String queryCommonOrgByName(String params){
- String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter(
- "name", params);
- /*String type =Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
- "type", params);*/
- String link_id =Utils.getParameter("link_id", params) == null ? "" : Utils.getParameter(
- "link_id", params);
- String userId =Utils.getParameter("userId", params) == null ? "" : Utils.getParameter(
- "userId", params);
- String groupType =Utils.getParameter("groupType", params) == null ? "" : Utils.getParameter(
- "groupType", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.getCommonOrgInfoByName(name,link_id,userId,groupType);
- return result;
-
-
- }
- @ProduceMime("application/json")
- @POST
- @Path("/updateCommomGroupById")
- public String updateCommomGroupById(String params){
-
- String id = Utils.getParameter("id", params) == null ? "" :Utils.getParameter(
- "id", params);
- String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter(
- "name", params);
- String result="";
- if(!"".equalsIgnoreCase(id)){
- OrganizationsBusi orgbusi = new OrganizationsBusi();
-
- result = orgbusi.updateCommomGroupById(id,name);
-
- }
- return result;
- }
- @ProduceMime("application/json")
- @POST
- @Path("/addCommonOrgInfoById")
- public String addCommonOrgInfoById(String params){
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String group_id = Utils.getParameter("group_id", params) == null ? "" : Utils.getParameter(
- "group_id", params);
- String groupType = Utils.getParameter("groupType", params) == null ? "" : Utils.getParameter(
- "groupType", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- //String[] ids=id.split(",");
- //Log.info(id+"========"+group_id);
- //String result = orgbusi.addCommonOrgInfoById(id,group_id);
- String result="";
- result = orgbusi.addCommonOrgInfoById(id,group_id,groupType);
- return result;
- }
- @ProduceMime("application/json")
- @POST
- @Path("/getCommonOrgGroupList")
- public String getCommonOrgGroupList(String params){
-
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String userId =Utils.getParameter("userId", params) == null ? "" : Utils.getParameter(
- "userId", params);
- String groupType =Utils.getParameter("groupType", params) == null ? "" : Utils.getParameter(
- "groupType", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.getCommonOrgGroupList(id,userId,groupType);
- return result;
-
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/addDiyGroup")
- public String addDiyGroup(String params){
-
- String linkCommId = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String diyName = Utils.getParameter("diyName", params) == null ? "" : Utils.getParameter(
- "diyName", params);
- String userId =Utils.getParameter("userId", params) == null ? "" : Utils.getParameter(
- "userId", params);
- String outerOrInner =Utils.getParameter("outerOrInner", params) == null ? "" : Utils.getParameter(
- "outerOrInner", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.addDiyGroup(linkCommId,diyName,userId,outerOrInner);
- return result;
-
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/deleteCommGroupById")
- public String deleteCommGroupById(String params){
-
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String nodeType = Utils.getParameter("nodeType", params) == null ? "" : Utils.getParameter(
- "nodeType", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.deleteCommGroupById(id,nodeType);
-
- return result;
-
- }
-
- /******************人员角色处理*****************/
- @ProduceMime("application/json")
- @POST
- @Path("/updateInlinkRole")
- public String updateInlinkRole(String params){
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter(
- "userId", params);
- String roleId = Utils.getParameter("roleId", params) == null ? "" : Utils.getParameter(
- "roleId", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.updateInlinkRole(deptId,userId,roleId);
-
- return result;
- }
- @ProduceMime("application/json")
- @POST
- @Path("/deleteInlinkRole")
- public String deleteInlinkRole(String params){
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter(
- "userId", params);
- OrganizationsBusi orgbusi = new OrganizationsBusi();
- String result = orgbusi.deleteInlinkRole(deptId,userId);
-
- return result;
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/getUnitTree")
- public String getUnitTree(String params){//应急处置下的通知单,政府应急动态页面左侧的单位树
- String unitId = params.split("&")[0].split("=")[1];//本级单位ID
- StringBuffer sb = new StringBuffer();
-
- OrganizationsBusi ob = new OrganizationsBusi();
- String parentUnitId = ob.getParentUnitMsg(unitId);//获取上级单位的单位ID和单位NAME
- String unit_Id = ob.getUnitMsg(unitId);//获取本单位的单位NAME
- String childrenUnitId = ob.getchlidrenUnitMsg(unitId);//获取下级单位的单位ID和单位NAME
- int n = childrenUnitId.split(";").length;
-
- sb.append("{\"treeNodes\":[");
- if("".equals(parentUnitId)){
-
- }else{
- //上级单位
- sb.append("{\"id\":\""+parentUnitId.split(",")[0]+"\",\"name\":\""+parentUnitId.split(",")[1]+"\",\"parentId\":\"0\",\"open\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/folder.png\"},");
- }
- //本级单位
- sb.append("{\"id\":\""+unit_Id.split(",")[0]+"\",\"name\":\""+unit_Id.split(",")[1]+"\",\"parentId\":\""+parentUnitId.split(",")[0]+"\",\"open\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/folder.png\"},");
- if("".equals(childrenUnitId)){
-
- }else{
- //下级单位
- for(int i=0;i<n;i++){
- sb.append("{\"id\":\""+childrenUnitId.split(";")[i].split(",")[0]+"\",\"name\":\""+childrenUnitId.split(";")[i].split(",")[1]+"\",\"parentId\":\""+unitId+"\",\"open\":\"false\",\"icon\":\"/nwyj/scripts/qui/libs/icons/folder.png\"},");
- }
- }
- if(sb.lastIndexOf(",") > -1){
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]}");
- //System.out.println("************************"+sb.toString());
- return sb.toString();
- }
-
- }
|