123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- /**
- *
- */
- package com.sinosoft.am.org.dept.indept.service;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import org.apache.log4j.Logger;
- import com.formaction.Parameter;
- import com.formaction.Utils;
- import com.formaction.vo.Msg;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.am.org.dept.indept.busi.PlanGlOrgBean;
- import com.sinosoft.am.org.dept.indept.dao.PlanGlOrgDao;
- import com.sinosoft.am.org.dept.indept.vo.PlanGlOrgVo;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- /**
- * @author 徐威
- * 2015-09-19
- * tel:13811395647
- */
- @Path("/PlanGlOrgService/")
- public class PlanGlOrgService{
- private Logger log = Logger.getLogger(this.getClass());
- /**
- * 根据部门异步加载下一级节点
- *
- * @param params
- * @return 部门树的所有一级子结构json对象
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getDeptTreeByIdAsync/")
- public String getDeptTreeByIdAsync(String params) {
- // 转换参数deptId
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- log.info("deptId"+"****************"+deptId);
- StringBuffer sb = new StringBuffer();
- PlanGlOrgBean deptBean = new PlanGlOrgBean();
- String classId="211";
- // 根据部门Id获得其下的所有子部门
- sb.append("{\"treeNodes\":[");
- ArrayList<PlanGlOrgVo> list;
- try {
- list = deptBean.getInDeptVoByIdAsync(deptId);
- log.info("list"+"**************"+list.size());
- Iterator<PlanGlOrgVo> iter = list.iterator();
- while (iter.hasNext()) {
- PlanGlOrgVo dv = iter.next();
- sb.append("{");
- sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
- + "\", \"name\": \"" + dv.getNAME()
- +"\", \"classId\":\""+classId+"\", \"objectId\":\""+dv.getFD_OBJECTID()
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
- + dv.getIS_VIRTUAL() + "\"");
- sb.append("},");
- }
- } catch (ClassNotFoundException e) {
- log.error("异步加载内部组织机构下一级部门出错", e);
- }
- // 去除多余逗号
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]}");
- log.info("json:" + sb);
- return sb.toString();
- }
- /**
- * 根据当前登录用户所属单位的ID获取当前根节点的信息
- *
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getDeptRootById/")
- public String getDeptRootById(String params) {
- StringBuffer sb = new StringBuffer();
- boolean flag=false;
- PlanGlOrgBean deptBean = new PlanGlOrgBean();
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- if("".equals(id)){
- flag =true;
- id= Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- }
- log.info("传过来的参数 为"+params);
- log.info("根据用户获得的部门Id= "+id);
- sb.append("{\"treeNodes\":[");
- PlanGlOrgVo dv;
- try {
-
- if(flag){
- dv = deptBean.getDeptRootById(id);
- sb.append("{");
- sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
- + "\", \"name\": \"" + dv.getNAME()
- +"\", \"isParent\": \"true"
- +"\", \"open\": \"true"
- +"\", \"nocheck\": \"true"
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
- + dv.getIS_VIRTUAL() + "\"");
- sb.append("},");
- if(checkInLink(id)){
- //该单位下如果有人,加载该单位下人员的数据。
- PlanGlOrgDao pgd = new PlanGlOrgDao();
- sb.append(pgd.getPersonJson(id));
- }
- }
-
- // 去除多余的逗号
- else{if(checkId(id)||checkInLink(id)){
- List<String>childList=new ArrayList<String>();
- childList=getChildList(id);
- for(int i=0;i<childList.size();i++){
- PlanGlOrgVo dvo=new PlanGlOrgVo();
- dvo=deptBean.getDeptRootById(childList.get(i));
- log.info("*****dvo===================****"+childList.size());
- sb.append("{");
- sb.append(" \"id\":\"" + dvo.getID() + "\", \"parentId\":\"" + dvo.getPARENT_ID()
- + "\", \"name\": \"" + dvo.getNAME()
- +"\", \"isParent\": \"true"
- +"\", \"nocheck\": \"true"
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
- + dvo.getIS_VIRTUAL() + "\"");
- sb.append("},");
- }
- if(checkInLink(id)){
- //该单位下如果有人,加载该单位下人员的数据。
- PlanGlOrgDao pgd = new PlanGlOrgDao();
- sb.append(pgd.getPersonJson(id));
- }
- }}
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]}");
- log.info("json:" + sb);
- return sb.toString();
- } catch (Exception e) {
- log.error("查询内部组织机构根节点错误", e);
- }
- return null;
- }
-
- /**
- * 根据当前登录用户所属单位的ID获取上级单位根节点的信息
- *
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getDeptById/")
- public String getDeptById(String params) {
- StringBuffer sb = new StringBuffer();
- PlanGlOrgBean deptBean = new PlanGlOrgBean();
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- if("".equals(id)){
- id= Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- }
- log.info("传过来的参数 为"+params);
- log.info("根据用户获得的部门Id= "+id);
- sb.append("{\"treeNodes\":[");
- PlanGlOrgVo dv;
- try {
- dv = deptBean.getDeptRootById(id);
- sb.append("{");
- sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
- + "\", \"name\": \"" + dv.getNAME()
- +"\", \"isParent\": \"true"
- +"\", \"open\": \"true"
- +"\", \"nocheck\": \"true"
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\", \"isV\":\""
- + dv.getIS_VIRTUAL() + "\"");
- sb.append("},");
- // 去除多余的逗号
- if(checkId(id)){
- List<String>childList=new ArrayList<String>();
- childList=getChildList(id);
- for(int i=0;i<childList.size();i++){
-
- PlanGlOrgVo dvo=new PlanGlOrgVo();
- dvo=deptBean.getDeptRootById(childList.get(i));
- log.info("*****dvo=====****"+dvo);
-
- sb.append("{");
- sb.append(" \"id\":\"" + dvo.getID() + "\", \"parentId\":\"" + dvo.getPARENT_ID()
- + "\", \"name\": \"" + dvo.getNAME()
- +"\", \"isParent\": \"false"
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\", \"isV\":\""
- + dvo.getIS_VIRTUAL() + "\"");
- sb.append("},");
- }
- }
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]}");
- log.info("json:" + sb);
- return sb.toString();
- } catch (Exception e) {
- log.error("查询内部组织机构根节点错误", e);
- }
- return null;
- }
-
- /**
- * 根据当前登录用户所属单位的ID获取上级单位根节点的信息
- *
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getDeptByIdDeptId/")
- public String getDeptByIdDeptId(String params) {
- StringBuffer sb = new StringBuffer();
- PlanGlOrgBean deptBean = new PlanGlOrgBean();
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- if("".equals(id)){
- id= Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- }
- log.info("传过来的参数 为"+params);
- log.info("根据用户获得的部门Id= "+id);
- sb.append("{\"treeNodes\":[");
- PlanGlOrgVo dv;
- try {
- dv = deptBean.getDeptRootById(id);
- sb.append("{");
- sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
- + "\", \"name\": \"" + dv.getNAME()
- +"\", \"isParent\": \"true"
- +"\", \"open\": \"true"
- +"\", \"nocheck\": \"true"
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
- + dv.getIS_VIRTUAL() + "\"");
- sb.append("},");
- // 去除多余的逗号
- if(checkIdDeptID(id)){
- List<String>getChildDeptList=new ArrayList<String>();
- getChildDeptList=getChildList(id);
- for(int i=0;i<getChildDeptList.size();i++){
-
- PlanGlOrgVo dvo=new PlanGlOrgVo();
- dvo=deptBean.getDeptRootById(getChildDeptList.get(i));
- log.info("*****dvo=====****"+dvo);
- sb.append("{");
- sb.append(" \"id\":\"" + dvo.getID() + "\", \"parentId\":\"" + dvo.getPARENT_ID()
- + "\", \"name\": \"" + dvo.getNAME()
- +"\", \"isParent\": \"false"
- + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
- + dvo.getIS_VIRTUAL() + "\"");
- sb.append("},");
- }
- }
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]}");
- log.info("json:" + sb);
- return sb.toString();
- } catch (Exception e) {
- log.error("查询内部组织机构根节点错误", e);
- }
- return null;
- }
-
- /**
- * 查询当前单位下面的子节点(部门或下属单位)
- * 返回的是一个List,里面放着的是部门ID
- *
- * */
- public List<String> getChildList(String id){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- // String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0'";
- String sql="select * from V_DEPARTMENT where parent_id='"+id+"' AND IS_DEL='0' AND (ORG_NAME LIKE '%供电局%' OR ORG_NAME LIKE '%电网公司')";
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- //循环遍历返回的ArrayLiist,判断下面是否有人,有人可以判断为部门。没有人可以判断为单位
- if(list==null||list.size()==0){
- return new ArrayList<String>();
- }else{
- List<String>tempList=new ArrayList<String>();
- for(int i=0;i<list.size();i++){
- tempList.add(list.get(i)[0]);
- }
- return tempList;
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return new ArrayList<String>();
- }
- }
-
- //查询当前部门是否有子部门加载人的时候所用
- public boolean checkId(String id){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0'";
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- if(list==null||list.size()==0){
- return false;
- }else{
- return true;
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- }
-
- //查询当前部门是否有子部门加载单位的时候所用
- public boolean checkIdDeptID(String id){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL!='1' AND IS_DEL='0'";
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- if(list==null||list.size()==0){
- return false;
- }else{
- return true;
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- }
-
- /**
- * 查询当前单位下面的子节点(部门或下属单位)
- * 返回的是一个List,里面放着的是部门ID
- *
- * */
- public List<String> getChildDeptList(String id){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL!='1' AND IS_DEL='0'";
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- //循环遍历返回的ArrayLiist,判断下面是否有人,有人可以判断为部门。没有人可以判断为单位
- if(list==null||list.size()==0){
- return new ArrayList<String>();
- }else{
- List<String>tempList=new ArrayList<String>();
- for(int i=0;i<list.size();i++){
- tempList.add(list.get(i)[0]);
- }
- return tempList;
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return new ArrayList<String>();
- }
- }
-
- //查询该ID在人员信息表里是否有人
- public boolean checkInLink(String id){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- //查询该ID在人员信息表里是否有人
- String sql="SELECT * FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID='"+id+"'";
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- if(list==null||list.size()==0){
- return false;
- }else{
- return true;
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- }
-
-
- @ProduceMime("application/json")
- @POST
- @Path("/addOrgInDept")
- public String addOrgInDept(String params){
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String parentId = Utils.getParameter("parentId", params) == null ? "" : Utils.getParameter(
- "parentId", params);
- String deptName = Utils.getParameter("deptName", params) == null ? "" : Utils.getParameter(
- "deptName", params);
- StringBuffer sb = new StringBuffer();
- log.info(deptId + "-------------------deptId");
- log.info(parentId + "-------------------parentId");
- log.info(deptName + "-------------------deptName");
- PlanGlOrgBean ob = new PlanGlOrgBean();
- if (ob.addOrgInDept(deptId, parentId, deptName)) {
- sb.append("{\"msg\":\"success\"}");
- } else {
- sb.append("{\"msg\":\"fail\"}");
- }
- return sb.toString();
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/shamDeleteOrgInDept")
- public String shamDeleteOrgInDept(String params){
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- log.info("要移出的外部机构Id="+deptId);
- StringBuffer sb = new StringBuffer();
- PlanGlOrgBean ob = new PlanGlOrgBean();
- boolean canDelete =ob.shamDeleteOrgInDept(deptId);
- if (canDelete) {
- sb.append("{\"msg\":\"success\"}");
- } else if(!canDelete){
- sb.append("{\"msg\":\"fail\"}");
- }
- return sb.toString();
-
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/getInOrgDoubleTree")
- public String getInOrgTree(String params) throws Exception{
- String json="";
- String comp_id=Utils.getParameter("comId", params) == null ? "" : Utils.getParameter(
- "comId", params);
- String type=Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
- "type", params);
- log.info("compId===="+comp_id);
-
- if(!"".equals(comp_id)){
- PlanGlOrgDao odd=new PlanGlOrgDao();
- json=odd.getInOrgTree(comp_id, type);
- }
- return json;
-
- }
-
-
- /**加载双向选择树*/
- @ProduceMime("application/json")
- @POST
- @Path("/getDoubleTree")
- public String getDoubleTree(String params) throws Exception{
- String json="";
- String comp_id=Utils.getParameter("comId", params) == null ? "" : Utils.getParameter(
- "comId", params);
- log.info("comp_id===="+comp_id);
- if(!"".equals(comp_id)){
- PlanGlOrgDao odd=new PlanGlOrgDao();
- json=odd.getDoubleTreeRoot(comp_id);
- }
- return json;
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/saveInLinkUser")
- public Msg saveInLinkUser(String params) throws ClassNotFoundException{
- Msg m=new Msg();
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String deptName = Utils.getParameter("deptName", params) == null ? "" : Utils.getParameter(
- "deptName", params);
- String orgName = Utils.getParameter("orgName", params) == null ? "" : Utils.getParameter(
- "orgName", params);
- String orgId = Utils.getParameter("orgId", params) == null ? "" : Utils.getParameter(
- "orgId", params);
- log.info(params);
- if(!"".equals(id)){
- PlanGlOrgDao odd=new PlanGlOrgDao();
- m=odd.saveOrg(id, deptId, deptName, orgName, orgId);
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- }
- return m;
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/saveExpertInfo")
- public Msg saveExpertInfo(String params) throws Exception{
- Msg m=new Msg();
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
- "id", params);
- if(!"".equals(id)){
- PlanGlOrgDao addExpert=new PlanGlOrgDao();
- m=addExpert.saveExpert(id);
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- }
- return m;
- }
- }
|