package com.sinosoft.lz.system.department; import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.ProduceMime; import net.sf.json.JSONObject; import org.apache.log4j.Logger; import com.formaction.Utils; import com.persistence.DbConnection; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.exception.PersistenceException; import com.sinosoft.em.response.equipment.records.service.RespEquipmentService; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; /** * * 1 组织机构管理tree,通过循环查询表800,807返回json数据 * */ @Path("/DeptService/") public class DepartExc{ private Logger log = Logger.getLogger(this.getClass()); @ProduceMime("application/json") @POST @Path("/getDepartTree") public String getDepartTree(String params) { String id = Utils.getParameter("id", params) == null ? "" : Utils .getParameter("id", params); String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name", params); /** * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info */ String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type", params); String dept = Utils.getParameter("dept", params) == null ? "" : Utils.getParameter("dept", params); log.info("id-- " + id + " -------name---" + name); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); sql.append("-- 查询组织机构根节点 \n"); sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n"); sql.append(" from Sys_Department where 1=1 \n"); if (id.equals("")) { sql.append(" and PARENT_ID='0'"); } else { sql.append(" and PARENT_ID='" + id + "'"); } if(!dept.equals("")){ sql.append(" and dept_type='"+dept+"'"); } sql.append(" ORDER BY SORT asc \n"); log.info(sql.toString()); try { ArrayList listRoot = persistence.getSearchResult(99, sql.toString()); String[] temp = listRoot.get(0); String deptId = temp[0]; String deptName = temp[1]; String objectId = temp[2]; json.append("{treeNodes:["); if (listRoot.size() > 1) { if(this.hasPersonLeaf(id)&&"per".equals(type)){ json.append(this.getPersonJson(id)); } json.append(this.getDeptChlidrenJson(id, type)); } else { json.append("{"); json.append(" id:'" + deptId + "',parentId:'0', "); json.append(" classId:'800',objectId:'" + objectId + "', "); json.append(" name:'" + deptName + "', "); json.append(" type:'unit',menuType:'nonLeafMenu',"); json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'"); json.append("},"); /** 加载人员信息 */ if (this.hasPersonLeaf(deptId) && "per".equals(type)) { json.append(this.getPersonJson(deptId)); } json.append(this.getDeptChlidrenJson(deptId, type)); } if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("]}"); } catch (PersistenceException e) { log.error("查询组织机构错误", e); } log.info(JSONObject.fromObject(json.toString()).toString()); return JSONObject.fromObject(json.toString()).toString(); } @ProduceMime("application/json") @POST @Path("/getCompanyTree") public String getCompanyTree(String params) { String id = Utils.getParameter("id", params) == null ? "" : Utils .getParameter("id", params); String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name", params); /** * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info */ String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type", params); log.info("id-- " + id + " -------name---" + name); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); sql.append("-- 查询组织机构根节点 \n"); sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n"); sql.append(" from Sys_Department where 1=1 \n"); // sql.append(" from Sys_Department where sort>=11 and sort<=29 and fd_objectid!='03E6F6D693F94335B242739D5D2A53E0' and fd_objectid!='0C1FE77E3C314D24B3D15FE38A3250AB' and fd_objectid!='106E3F1BC3914EA5B8E69E6EED7E4F0A' \n"); if (id.equals("")) { sql.append(" and PARENT_ID='0'"); } else { sql.append(" and PARENT_ID='" + id + "'"); } sql.append(" ORDER BY SORT asc \n"); log.info("*********"+sql.toString()); try { ArrayList listRoot = persistence.getSearchResult(99, sql.toString()); String[] temp = listRoot.get(0); String deptId = temp[0]; String deptName = temp[1]; String objectId = temp[2]; json.append("{fromList:["); if (listRoot.size() > 1) { if(this.hasPersonLeaf(id)&&"per".equals(type)){ json.append(this.getPersonJson(id)); } json.append(this.getCompanyChlidrenJson(id, type)); } else { json.append("{"); json.append(" value:'" + deptId + "',parentId:'0', "); json.append(" key:'" + deptName + "'"); json.append("},"); json.append(this.getCompanyChlidrenJson(deptId, type)); } if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("],'toList':[]}"); } catch (PersistenceException e) { log.error("查询组织机构错误", e); } log.info(JSONObject.fromObject(json.toString()).toString()); return JSONObject.fromObject(json.toString()).toString(); } @ProduceMime("application/json") @POST @Path("/getCompanyTreeTeamAndEquip") public String getCompanyTreeTeamAndEquip(String params) {//队伍需求(之前的------备份--20160815) String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params); String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",params); String needUnit = Utils.getParameter("deptId_self", params) == null ? "" : Utils.getParameter("deptId_self", params);//需求单位 /** * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info */ String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",params); log.info("id-- " + id + " -------name---" + name); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); String sql1=" select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where 1=1"+ " and PARENT_ID='"+id+"' and dept_type='1' and dept_level=3 and DEPT_ID != '"+needUnit+"' ORDER BY SORT asc "; ArrayList listRoot; try { json.append("{'fromList':[ "); listRoot = persistence.getSearchResult(99, sql1); if(listRoot!=null&&listRoot.size()>0){ for(int i=0;i -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("],'toList':[]}"); log.info(JSONObject.fromObject(json.toString()).toString()); return JSONObject.fromObject(json.toString()).toString(); } @ProduceMime("application/json") @POST @Path("/getEquipType") public String getEquipType(String params) {//装备需求 String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//装备需求ID StringBuffer sb = new StringBuffer(); RespEquipmentService res = new RespEquipmentService(); sb.append("{\"equipTypes\":[");//单选下拉框 /** *需求信息表--ID:383--表名:ECM_EM_EQUIPMENT_DEMAND_DETAIL 该表中EQUIPMENT_NAME字段的值代表装备类型 *(0:发电车--ID:265--表名:EMC_AM_GENERATOR_CAR--状态:IS_USED='1') *(1:发电机--ID:266--表名:EMC_AM_GENERATOR--状态:USED_STAT='1') *(2:移动餐车--ID:270--表名:EMC_AM_DINING_CAR--状态:IS_USED='1') *(3:指挥通信车--ID:269--表名:EMC_AM_EMERGENCY_COMMAND_CAR--状态:USED_STAT='1') * */ //1 通过需求id382在表ECM_EM_EQUIPMENT_DEMAND_DETAIL中查出需求下的各种装备类型(可能不是一个) String equipTypes = res.getEquipTypes(fdId_382); int n = equipTypes.split(",").length;//装备类型的个数 for(int i=0;i -1) { sb.deleteCharAt(sb.lastIndexOf(",")); } sb.append("]}"); System.out.println("**********"+sb.toString()); // log.info(JSONObject.fromObject(sb.toString()).toString()); return sb.toString(); } /*@ProduceMime("application/json") @POST @Path("/getCompanyTreeTeamAndEquip") public String getCompanyTreeTeamAndEquip(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 needUnit = Utils.getParameter("deptId_self", params) == null ? "" : Utils.getParameter("deptId_self", params);//需求单位 String recipDept = Utils.getParameter("deptid", params) == null ? "" : Utils.getParameter("deptid",params);//需求申请单位 String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//队伍需求ID // 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",params); log.info("id-- " + id + " -------name---" + name); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); // String sql1=" select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where 1=1 and PARENT_ID='"+id+"' and dept_type='1' and dept_name like'%供电%' and DEPT_ID != '"+needUnit+"' ORDER BY SORT asc "; String sql1=" select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where 1=1 and PARENT_ID='"+id+"' and dept_type='1' and dept_name like'%供电%' and DEPT_ID != '"+recipDept+"' ORDER BY SORT asc "; ArrayList listRoot; try { listRoot = persistence.getSearchResult(99, sql1); if(listRoot!=null&&listRoot.size()>0){ // json.append("{'fromList':[ ");//双选器 // json.append("{'list':[ ");//单选下拉框 json.append("{'treeNodes':[ ");//多选下拉框 for(int i=0;i -1) { json.deleteCharAt(json.lastIndexOf(",")); } // json.append("],'toList':[]}"); json.append("]}"); log.info(JSONObject.fromObject(json.toString()).toString()); return JSONObject.fromObject(json.toString()).toString(); }*/ @ProduceMime("application/json") @POST @Path("/getCompanyTreeEquip") public String getCompanyTreeEquip(String params) {//装备需求 String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);//登录人单位id String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",params);//空值(“”) String recipDept = Utils.getParameter("deptid", params) == null ? "" : Utils.getParameter("deptid",params);//需求申请单位ID String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//装备需求ID /** * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info */ String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",params); log.info("id-- " + id + " -------name---" + name); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); RespEquipmentService res = new RespEquipmentService(); String sql1 = " select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where '1'='1' and PARENT_ID='"+id+"' and dept_type='1' and dept_name like'%供电%' and DEPT_ID!='"+recipDept+"' ORDER BY SORT asc "; ArrayList listRoot; try { listRoot = persistence.getSearchResult(99, sql1); if(listRoot!=null&&listRoot.size()>0){ //json.append("{'treeNodes':[ ");//多选下拉框 json.append("{\"treeNodes\":[");//多选下拉框 for(int i=0;i -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("]}"); log.info(JSONObject.fromObject(json.toString()).toString()); return JSONObject.fromObject(json.toString()).toString(); } private String getCompanyChlidrenJsonTeamAndEquip(String unitCode, String type) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); sql.append("-- 查询组织机构子节点 \n"); sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n"); // sql.append(" from Sys_Department where dept_type='CORP' and parent_id='" + unitCode + "' \n"); sql.append(" from Sys_Department where dept_type='CORP' and parent_id='" + unitCode + "' \n"); sql.append(" and sort>=11 and sort<=29 and fd_objectid!='03E6F6D693F94335B242739D5D2A53E0' and fd_objectid!='0C1FE77E3C314D24B3D15FE38A3250AB' and fd_objectid!='106E3F1BC3914EA5B8E69E6EED7E4F0A' \n"); sql.append(" ORDER BY SORT asc \n"); log.info("=="+sql); try { ArrayList listDept = persistence.getSearchResult(99, sql.toString()); int num = listDept.size(); for (int i = 0; i < num; i++) { String[] temp = listDept.get(i); String deptId = temp[0]; String deptName = temp[1]; String objectId = temp[2]; json.append("{ "); json.append(" value:'" + deptId + "', parentId:'" + unitCode + "',"); json.append(" key:'" + deptName + "',"); json.append("}, "); /** * 加载人员信息 if(this.hasPersonLeaf(deptId)&&"per".equals(type)){ * json.append(this.getPersonJson(deptId)); } */ /*if (this.isExitLeaf(deptId)) { json.append(this.getDeptChlidrenJson(deptId, type)); }*/ } } catch (PersistenceException e) { log.error("查询组织机构子节点错误", e); } return json.toString(); } /** * 返回部门节点json字符串 * * @param unitCode * @return */ private String getDeptChlidrenJson(String unitCode, String type) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); sql.append("-- 查询组织机构子节点 \n"); sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n"); sql.append(" from Sys_Department where parent_id='" + unitCode + "' \n"); sql.append(" ORDER BY SORT asc \n"); log.info("=="+sql); try { ArrayList listDept = persistence.getSearchResult(99, sql.toString()); int num = listDept.size(); for (int i = 0; i < num; i++) { String[] temp = listDept.get(i); String deptId = temp[0]; String deptName = temp[1]; String objectId = temp[2]; json.append("{ "); json.append(" id:'" + deptId + "', parentId:'" + unitCode + "',"); json.append(" classId:'800',objectId:'" + objectId + "',"); json.append(" name:'" + deptName + "',"); json.append(" type:'unit',menuType:'nonLeafMenu',"); json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'"); json.append("}, "); /** * 加载人员信息 if(this.hasPersonLeaf(deptId)&&"per".equals(type)){ * json.append(this.getPersonJson(deptId)); } */ /*if (this.isExitLeaf(deptId)) { json.append(this.getDeptChlidrenJson(deptId, type)); }*/ } } catch (PersistenceException e) { log.error("查询组织机构子节点错误", e); } return json.toString(); } /** * 返回部门节点json字符串 * * @param unitCode * @return */ private String getCompanyChlidrenJson(String unitCode, String type) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); sql.append("-- 查询组织机构子节点 \n"); sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n"); sql.append(" from Sys_Department where dept_type='CORP' and parent_id='" + unitCode + "' \n"); sql.append(" ORDER BY SORT asc \n"); log.info("=="+sql); try { ArrayList listDept = persistence.getSearchResult(99, sql.toString()); int num = listDept.size(); for (int i = 0; i < num; i++) { String[] temp = listDept.get(i); String deptId = temp[0]; String deptName = temp[1]; String objectId = temp[2]; json.append("{ "); json.append(" value:'" + deptId + "', parentId:'" + unitCode + "',"); json.append(" key:'" + deptName + "',"); json.append("}, "); /** * 加载人员信息 if(this.hasPersonLeaf(deptId)&&"per".equals(type)){ * json.append(this.getPersonJson(deptId)); } */ /*if (this.isExitLeaf(deptId)) { json.append(this.getDeptChlidrenJson(deptId, type)); }*/ } } catch (PersistenceException e) { log.error("查询组织机构子节点错误", e); } return json.toString(); } /** * 判断是否有子节点 * * @param persistence * @param mId * @return */ private boolean isExitLeaf(String unitCode) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); boolean flag = false; try { String sql = " select count(dept_id) from Sys_Department where parent_ID='" + unitCode + "' "; ArrayList list = persistence.getSearchResult(99, sql); int num = Integer.parseInt(list.get(0)[0]); if (num > 0) { flag = true; } } catch (PersistenceException e) { log.error("是否存在子节点-- ", e); } return flag; } /** * 根据部门id 查询人员 返回人员数据json * * @param deptId * @return */ private String getPersonJson(String deptId) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); // String sql = // "select FD_OBJECTID,PERSON_CODE,NAME ,SEX from Sys_Person where IS_DEL='0' and DEPT_ID='"+deptId+"' ORDER BY PERSON_CODE ASC "; String sql = "select FD_OBJECTID,USER_ID,DISPLAY_NAME,NAME from sys_user_info where IS_DEL='0' and UNIT_CODE='" + deptId + "' ORDER BY user_id ASC "; // log.info("=="+sql); try { ArrayList list = persistence.getSearchResult(99, sql.toString()); int num = list.size(); for (int i = 0; i < num; i++) { String[] temp = list.get(i); String objectId = temp[0]; String pCode = temp[1]; String name = temp[2]; // String sex = temp[3]== null ? "0" : temp[3]; json.append("{ "); json.append(" id:'" + pCode + "', parentId:'" + deptId + "',"); json.append(" classId:'807',objectId:'" + objectId + "',"); // json.append(" name:'"+name+"',nocheck:true,"); json.append(" type:'per',name:'" + name + "',"); json.append(" menuType:'leafMenu'"); /* * if(sex.equals("0")){ json.append( * " icon:'../../../scripts/qui/libs/icons/user_female.gif'"); * }else{ * json.append(" icon:'../../../scripts/qui/libs/icons/user.gif'" * ); } */ json.append("}, "); } } catch (PersistenceException e) { log.error("查询人员数据错误-- ", e); } return json.toString(); } private boolean hasPersonLeaf(String deptId) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); /*String sql = "select count(FD_OBJECTID) from sys_user_info where IS_DEL='0' and UNIT_CODE='" + deptId + "' ORDER BY user_id ASC ";*/ String sql = "select count(FD_OBJECTID) from sys_user_info where IS_DEL='0' ORDER BY user_id ASC "; // log.info("=="+sql); boolean flag = false; try { ArrayList list = persistence.getSearchResult(99, sql); int num = Integer.parseInt(list.get(0)[0]); if (num > 0) { flag = true; } } catch (PersistenceException e) { log.error("是否存在人员-- ", e); } return flag; } /** * 新增机构或人员时,生成编号Id * * @param params * @return */ @ProduceMime("application/json") @POST @Path("/getCreateNodeNum") public String getCreateNodeNum(String params) { params = decode(params); // 树节点id String node = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter( "deptId", params); // 800 机构; 807人员 Integer classid = Integer.parseInt(Utils.getParameter("classid", params) == null ? "" : Utils.getParameter("classid", params)); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); String num = ""; try { String sql = ""; if (classid == 800) { sql = "select Max(Dept_Id) from Sys_Department where Depts_Id='" + node + "'"; } else if (classid == 807) { sql = "select Max(user_id) from sys_user_info where UNIT_CODE='" + node + "'"; } ArrayList list = persistence.getSearchResult(classid, sql); // 如果节点下没有子节点,返回节点nodeid+‘01’,作为该节点的第一个子节点。 if (list.get(0)[0] == null) { num = node + "01"; } else { String deptCode = list.get(0)[0]; num = Long.valueOf(deptCode) + 1 + ""; } } catch (PersistenceException e) { log.error("生成机构人员编码错误", e); } log.info("num--- " + num); return num; } // 根据单位deptid获取单位名称 public String getBMTableByNameIds(String tablename, String fdCode) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); String sql = ""; // 单位部门表时,查询字段特殊 if (tablename.equalsIgnoreCase("Sys_Department")) { sql = "select DEPT_NAME,Dept_Id from " + tablename + " where is_del ='0' and Dept_Id='" + fdCode + "'"; } else { sql = "select fd_description,fd_code from BM$_MapValueCanst where fd_type='" + tablename + "' and fd_code='" + fdCode + "' "; } ArrayList codes; String value = ""; try { codes = persistence.getSearchResult(99, sql); if (codes.size() > 0) { for (String[] s : codes) { if (s[1].equals(fdCode)) { value = s[0]; } } } } catch (Exception e) { e.printStackTrace(); log.error("" + e); } return value; } // 编码解析 protected String decode(String params) { try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return params; } /** * 根据部门deptid删除人员信息 * * @param params */ @ProduceMime("application/json") @POST @Path("/delPersonByDeptId") public void delPersonByDeptId(String params) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); String depts = Utils.getParameter("DEPT_ID", params).trim() == null ? "" : Utils .getParameter("DEPT_ID", params).trim(); String sql = "update sys_user_info set is_del='1' where UNIT_CODE='" + depts + "'"; log.info(sql); try { persistence.getSearchResult(99, sql); } catch (Exception e) { log.error("" + e); } } /** * 根据人员Id删除人员信息 * * @param params */ @ProduceMime("application/json") @POST @Path("/delPersonByPid") public String delPersonByPid(String params) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); String objectId = Utils.getParameter("ObjectID", params).trim() == null ? "" : Utils .getParameter("ObjectID", params).trim(); String sql = "update sys_user_info set is_del='1' where FD_OBJECTID='" + objectId + "'"; log.info(sql); boolean flag = false; try { int num = persistence.executeUpdateSQL(99, sql); if (num > 0) { flag = true; } } catch (Exception e) { log.error("" + e); } return new Boolean(flag).toString(); } /** * 根据人员Id删除人员信息 * * @param params */ @ProduceMime("application/json") @POST @Path("/delDeptById") public String delDeptById(String params) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); String objectId = Utils.getParameter("ObjectID", params).trim() == null ? "" : Utils .getParameter("ObjectID", params).trim(); String sql = "update Sys_Department set is_del='1' where FD_OBJECTID='" + objectId + "'"; log.info(sql); boolean flag = false; try { int num = persistence.executeUpdateSQL(99, sql); if (num > 0) { flag = true; } } catch (Exception e) { log.error("" + e); } return new Boolean(flag).toString(); } @ProduceMime("application/json") @POST @Path("/getEquipArg") public String getEquipArg(String params) {////查询装备属性(通过工器具类型ID) try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String equipmentTypeID = Utils.getParameter("equipTypeID", params) == null ? "" : Utils.getParameter("equipTypeID", params);//工器具类型ID // String sql = "select ID,COLUMN_NAME from NWYJ_SERVICE.SP_SS_EMERGENCY_PARAMETER where INSTRUMENT_TYPE_ID in ( select ID from NWYJ_SERVICE.SP_SS_INSTRUMENT_TYPE where PROVINCE_CODE=? and BUREAU_CODE=? and INSTRUMENT_NAME=? )"; String sql = "select ID,COLUMN_NAME from NWYJ_SERVICE.SP_SS_EMERGENCY_PARAMETER where INSTRUMENT_TYPE_ID=?"; StringBuffer sb = new StringBuffer(); sb.append("{\"equipResult\":["); DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql); pstm.setString(1, equipmentTypeID); rs = pstm.executeQuery(); while(rs.next()){ // sb.append(rs.getString("EQUIPMENT_NAME") == null ? "" : rs.getString("EQUIPMENT_NAME")); // sb.append(","); sb.append("{\"equipArg\":\""+(rs.getString("COLUMN_NAME") == null ? "" : rs.getString("COLUMN_NAME"))+"\"," +"\"equipArgId\":\""+(rs.getString("ID") == null ? "" : rs.getString("ID"))+"\"" +"},"); } if (sb.lastIndexOf(",") > -1) { sb.deleteCharAt(sb.lastIndexOf(",")); // sb.deleteCharAt(sb.length()-1); } sb.append("]}"); } 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(); } } // System.out.println("******************"+sb.toString()); return sb.toString(); } @ProduceMime("application/json") @POST @Path("/getEquipArgVal") public String getEquipArgVal(String params) {//获取满足条件的装备类型属性的值和id try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // String equipArg = Utils.getParameter("equipArg", params) == null ? "" : Utils.getParameter("equipArg", params);//装备属性 String equipArgId = Utils.getParameter("equipArgId", params) == null ? "" : Utils.getParameter("equipArgId",params);//装备属性值 // String equipArg = Utils.getParameter("equipArg", params) == null ? "" : Utils.getParameter("equipArg",params);//装备属性值 String sql = "select ID,COLUMN_NAME,COLUMN_CODE,COLUMN_VALUE from NWYJ_SERVICE.SP_SS_EMERGENCY_PARAMETER_VAL where EMERGENCY_PARAMETER_ID=?"; StringBuffer sb = new StringBuffer(); sb.append("{\"equipVal\":["); DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql); pstm.setString(1, equipArgId); rs = pstm.executeQuery(); while(rs.next()){ sb.append("{"+ "\"equipArgValId\":\""+(rs.getString("ID") == null ? "" : rs.getString("ID"))+"\","+ "\"equipArgValName\":\""+(rs.getString("COLUMN_NAME") == null ? "" : rs.getString("COLUMN_NAME"))+"\","+ "\"equipArgValCode\":\""+(rs.getString("COLUMN_CODE") == null ? "" : rs.getString("COLUMN_CODE"))+"\","+ "\"equipArgVal\":\""+(rs.getString("COLUMN_VALUE") == null ? "" : rs.getString("COLUMN_VALUE"))+"\""+ "},"); } if (sb.lastIndexOf(",") > -1) { sb.deleteCharAt(sb.lastIndexOf(",")); // sb.deleteCharAt(sb.length()-1); } sb.append("]}"); } 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(); } } // System.out.println("******************"+sb.toString()); return sb.toString(); } @POST @ProduceMime("application/json") @Path("/getIdByEquipMsg") public String getIdByEquipMsg(String params) {//获取工器具类型ID try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String equipmentType = Utils.getParameter("jkEquipmentType", params) == null ? "" : Utils.getParameter("jkEquipmentType",params);//装备类型(PARENT_NAME) String sql = "select ID from NWYJ_SERVICE.SP_SS_INSTRUMENT_TYPE where INSTRUMENT_NAME=?"; StringBuffer sb = new StringBuffer(); DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql); pstm.setString(1, params); rs = pstm.executeQuery(); while(rs.next()){ sb.append(rs.getString("ID") == null ? "" : rs.getString("ID")); } } 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(); } } // System.out.println("******************"+sb.toString()); return sb.toString(); } @POST @ProduceMime("application/json") @Path("/getTeamMsg") public String getTeamMsg(String params) {//获取队伍 try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String unite_id = Utils.getParameter("uniteID", params) == null ? "" : Utils.getParameter("uniteID",params);//单位ID String teamType = Utils.getParameter("teamType", params) == null ? "" : Utils.getParameter("teamType",params);//队伍类型 String teamTypeCode = "";//队伍类型常量值(select * from bm_mapvaluecanst where fd_type='BM_TEAMTYPE') if(teamType == "输电"){//"输电".equals(teamType) teamTypeCode="124"; } else if(teamType == "变电"){ teamTypeCode="125"; } else if(teamType == "配电"){ teamTypeCode="126"; } else if(teamType == "通信"){ teamTypeCode="127"; } else if(teamType.equals("网络信息")){//-------------------------------------- teamTypeCode="124";//-------------------------------------- } else if(teamType == "试验"){ teamTypeCode="129"; } else if(teamType == "其他"){ teamTypeCode="130"; } String sql = "select FD_OBJECTID,TEAM_NAME,TEAM_MEMBER_NUMBER from ECM_AM_EMERGENCY_TEAM where TEAM_COMP_ID=? and TEAM_TYPE=? and TEAM_STAT='1'"; StringBuffer sb = new StringBuffer(); DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql); pstm.setString(1, unite_id); pstm.setString(2, teamTypeCode); rs = pstm.executeQuery(); sb.append("{\"treeNodes\":["); while(rs.next()){ // sb.append("{\"id\":\""+rs.getString("FD_OBJECTID")==null ? "" : rs.getString("FD_OBJECTID")+"\",\"parentId\":\"0\",\"name\":\""+rs.getString("TEAM_NAME")==null ? "" : rs.getString("TEAM_NAME")+"("+rs.getString("TEAM_MEMBER_NUMBER") == null ? "" : rs.getString("TEAM_MEMBER_NUMBER")+")\"},"); sb.append("{\"id\":\""+rs.getString("FD_OBJECTID")+"\",\"parentId\":\"0\",\"name\":\""+rs.getString("TEAM_NAME")+"("+rs.getString("TEAM_MEMBER_NUMBER")+")\"},"); } if(sb.lastIndexOf(",")>-1){ sb.deleteCharAt(sb.lastIndexOf(",")); } sb.append("]}"); } 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(); } } // System.out.println("******************"+sb.toString()); return sb.toString(); } @ProduceMime("application/json") @POST @Path("/initZtree_unitAndEquipMsg") public String initZtree_unitAndEquipMsg(String params) {//单位及装备、装备属性、属性值的下拉树 try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String id = Utils.getParameter("corpId", params) == null ? "" : Utils.getParameter("corpId", params);//登录人单位id String corpName = Utils.getParameter("corpName", params) == null ? "" : Utils.getParameter("corpName",params);//登录人单位name String recipDept = Utils.getParameter("equipNeedUnit", params) == null ? "" : Utils.getParameter("equipNeedUnit",params);//需求申请单位ID String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//装备需求ID StringBuffer sb = new StringBuffer(); RespEquipmentService res = new RespEquipmentService(); String sql =" select DEPT_ID,DEPT_NAME,FD_OBJECTID,UNICODE "+ " from Sys_Department "+ " where 1=1 and "+ " PARENT_ID='"+id+"' and "+ " dept_type='1' and "+ " dept_name like'%供电%' and "+ " DEPT_ID!='"+recipDept+"' "+ " ORDER BY SORT asc "; DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql); rs = pstm.executeQuery(); sb.append("{\"treeNodes\":["); sb.append("{\"id\":\""+id+"\",\"parentId\":\"99999\",\"name\":\""+corpName+"\",\"open\":\"true\"},");//第一级--本级单位(制定调拨令的人的单位) while(rs.next()){ String deptId = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");//下级单位id String deptName = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");//下级单位NAME String unitcode = rs.getString("UNICODE") == null ? "" : rs.getString("UNICODE");//单位编码 /******************************************************************************************************/ sb.append("{\"id\":\""+deptId+"\",\"parentId\":\""+id+"\",\"name\":\""+deptName+"\"},");//第二级--下级单位 /** *需求信息表--ID:383--表名:ECM_EM_EQUIPMENT_DEMAND_DETAIL 该表中EQUIPMENT_NAME字段的值代表装备类型 *(0:发电车--ID:265--表名:EMC_AM_GENERATOR_CAR--状态:IS_USED='1') *(1:发电机--ID:266--表名:EMC_AM_GENERATOR--状态:USED_STAT='1') *(2:移动餐车--ID:270--表名:EMC_AM_DINING_CAR--状态:IS_USED='1') *(3:指挥通信车--ID:269--表名:EMC_AM_EMERGENCY_COMMAND_CAR--状态:USED_STAT='1') */ //先通过需求id382在表ECM_EM_EQUIPMENT_DEMAND_DETAIL中查出需求下的各种装备类型(可能不是一个) String equipTypes = res.getEquipTypes(fdId_382); int equipTypesNum = 0;//装备类型的数量(多少种装备) equipTypesNum = equipTypes.split(",").length; for(int i=0;i -1){ sb.deleteCharAt(sb.lastIndexOf(",")); } sb.append("]}"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(rs!=null) rs.close(); if(pstm!=null) pstm.close(); if(conn!=null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } //System.out.println("///////////****************"+sb.toString()); return sb.toString(); } }