123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- package com.sinosoft.lz.unitsWH.unitsWHDAO;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.apache.log4j.Logger;
- import com.persistence.DbConnection;
- import com.sinosoft.em.alert.response.service.ResponseService;
- public class unitsWHDAO {
-
- //日志对象
- private static final Logger log = Logger.getLogger(ResponseService.class);
-
- public String getAllUnitShow1(String corpId,String butVal){//查询本单位------根结点(初次加载)
- //dept_id='corp_id'
- // String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where DEPT_ID='"+corpId+"' and CODES_ISSHOW like '%'|| (select fd_code from bm_mapvaluecanst where fd_description='"+butVal+"') ||'%' order by SORT";
- String fdcode = getFdcodeByFddesc(butVal);
- String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where DEPT_ID='"+corpId+"' and CODES_ISSHOW like '%"+fdcode+"%' order by SORT";
- // String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where DEPT_ID='"+corpId+"' order by SORT";
-
- 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, butVal);
- rs = pstm.executeQuery();
- while(rs.next()){
- String dept_id = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");//单位ID
- String dept_name = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");//单位NAME
- String parent_id = rs.getString("PARENT_ID") == null ? "" : rs.getString("PARENT_ID");//上级单位ID
- String dept_type = rs.getString("DEPT_TYPE") == null ? "" : rs.getString("DEPT_TYPE");//单位类型(单位--=1,部门--!=1)
- //根结点
- sb.append("{\"id\":\""+dept_id+"\",\"name\":\""+dept_name+"\",\"parentId\":\"0\",\"open\":\"true\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- //下级部门
- // sb.append("{\"id\":\""+dept_id+";1"+"\",\"name\":\"本部\",\"parentId\":\""+dept_id+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- sb.append(getAllUnitShow3(dept_id,butVal));
- //下级单位
- sb.append(getAllUnitShow2(dept_id,butVal));
- }
- if(sb.lastIndexOf(",")>-1){
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- } 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) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- // System.out.println("111111111111111111111111"+sb.toString());
- return sb.toString();
- }
-
- public String getAllUnitShow5(String corpId,String butVal){//查询本单位------根结点(初次加载)
- //dept_id='corp_id'
- // String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where DEPT_ID='"+corpId+"' and CODES_ISSHOW like '%'|| (select fd_code from bm_mapvaluecanst where fd_description='"+butVal+"') ||'%' order by SORT";
- // String fdcode = getFdcodeByFddesc(butVal);
- // String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where DEPT_ID='"+corpId+"' and CODES_ISSHOW like '%"+fdcode+"%' order by SORT";
- String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where DEPT_ID='"+corpId+"' order by SORT";
-
- 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, butVal);
- rs = pstm.executeQuery();
- while(rs.next()){
- String dept_id = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");//单位ID
- String dept_name = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");//单位NAME
- String parent_id = rs.getString("PARENT_ID") == null ? "" : rs.getString("PARENT_ID");//上级单位ID
- String dept_type = rs.getString("DEPT_TYPE") == null ? "" : rs.getString("DEPT_TYPE");//单位类型(单位--=1,部门--!=1)
- //根结点
- sb.append("{\"id\":\""+dept_id+"\",\"name\":\""+dept_name+"\",\"parentId\":\"0\",\"open\":\"true\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- //下级部门
- // sb.append("{\"id\":\""+dept_id+";1"+"\",\"name\":\"本部\",\"parentId\":\""+dept_id+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- sb.append(getAllUnitShow3(dept_id,butVal));
- //下级单位
- sb.append(getAllUnitShow2(dept_id,butVal));
- }
- if(sb.lastIndexOf(",")>-1){
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- } 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) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- // System.out.println("111111111111111111111111"+sb.toString());
- return sb.toString();
- }
-
- public String getAllUnitShow4(String corpId,String butVal){//查询本单位------根结点(非初次)
- StringBuffer sb = new StringBuffer();
- //下级部门
- // int n = corpId.split(";").length;
- // System.out.println("***/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**8888888888888888888888888888----"+n+"--:"+corpId);
- // if(n<2){
- // sb.append("{\"id\":\""+corpId+";1"+"\",\"name\":\"本部\",\"parentId\":\""+corpId+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- // }
- sb.append(getAllUnitShow3(corpId,butVal));
-
- //下级单位
- sb.append(getAllUnitShow2(corpId,butVal));
-
- if(sb.lastIndexOf(",")>-1){
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- return sb.toString();
- }
-
- public String getAllUnitShow2(String deptId,String butVal){//查询下级所有单位------(非部门)
- String fdcode = getFdcodeByFddesc(butVal);
- String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where PARENT_ID='"+deptId+"' and DEPT_TYPE='1' and CODES_ISSHOW like '%"+fdcode+"%' order by SORT";
- // String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where PARENT_ID='"+deptId+"' and DEPT_TYPE='1' order by SORT";
-
- 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, butVal);
- rs = pstm.executeQuery();
- while(rs.next()){
- String dept_id = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");//单位ID
- String dept_name = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");//单位NAME
- String parent_id = rs.getString("PARENT_ID") == null ? "" : rs.getString("PARENT_ID");//上级单位ID
- String dept_type = rs.getString("DEPT_TYPE") == null ? "" : rs.getString("DEPT_TYPE");//单位类型(单位--=1,部门--!=1)
- sb.append("{\"id\":\""+dept_id+"\",\"name\":\""+dept_name+"\",\"parentId\":\""+deptId+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- }
- // if(sb.lastIndexOf(",")>-1){
- // sb.deleteCharAt(sb.lastIndexOf(","));
- // }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- // System.out.println("22222222222222222222222222"+sb.toString());
- return sb.toString();
- }
-
- public String getAllUnitShow3(String deptId,String butVal){//查询下级所有部门------(部门)
- String fdcode = getFdcodeByFddesc(butVal);
- String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where PARENT_ID='"+deptId+"' and DEPT_TYPE!='1' and CODES_ISSHOW like '%"+fdcode+"%' order by SORT";
- // String sql="select DEPT_ID,DEPT_NAME,PARENT_ID,DEPT_TYPE from SYS_DEPARTMENT where PARENT_ID='"+deptId+"' and DEPT_TYPE!='1' order by SORT";
-
- StringBuffer sb = new StringBuffer();
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;
- ResultSet rs = null;
- int a=0;
- // sb.append("{\"id\":\"benbu\",\"name\":\"本部\",\"parentId\":\""+deptId+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- try {
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- // pstm.setString(1, butVal);
- rs = pstm.executeQuery();
-
- while(rs.next()){
- if(a==0){
- sb.append("{\"id\":\""+deptId+";1"+"\",\"name\":\"本部\",\"parentId\":\""+deptId+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- a++;
- }
-
- String dept_id = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");//单位ID
- String dept_name = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");//单位NAME
- String parent_id = rs.getString("PARENT_ID") == null ? "" : rs.getString("PARENT_ID");//上级单位ID
- String dept_type = rs.getString("DEPT_TYPE") == null ? "" : rs.getString("DEPT_TYPE");//单位类型(单位--=1,部门--!=1)
- sb.append("{\"id\":\""+dept_id+"\",\"name\":\""+dept_name+"\",\"parentId\":\""+deptId+";1"+"\",\"open\":\"false\",\"isParent\":\"true\",\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\",\"orgLevel\":\"null\"},");
- }
- // if(sb.lastIndexOf(",")>-1){
- // sb.deleteCharAt(sb.lastIndexOf(","));
- // }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- // System.out.println("333333333333333333333"+sb.toString());
- return sb.toString();
- }
-
- public String getFdcodeByFddesc(String desc){
- String sql = "select fd_code from bm_mapvaluecanst where fd_description=? and fd_type='BM_SHOW_UNITES'";
-
- 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, desc);
- rs = pstm.executeQuery();
- while(rs.next()){
- String fdCode = rs.getString("fd_code") == null ? "" : rs.getString("fd_code");
- sb.append(fdCode);
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return sb.toString();
- }
-
- public String getAllShowUnitCode(){//获取常量表中所有fd_type='BM_SHOW_UNITES'的fd_code和fd_description
- String sql = "select fd_code,fd_description from bm_mapvaluecanst where fd_type='BM_SHOW_UNITES'";
-
- 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);
- rs = pstm.executeQuery();
- sb.append("\"allrows\":[");
- while(rs.next()){
- String fdCode = rs.getString("fd_code") == null ? "" : rs.getString("fd_code");
- String fdDesc = rs.getString("fd_description") == null ? "" : rs.getString("fd_description");
- sb.append("{\"name\":\""+fdDesc+"\",\"id\":\""+fdCode+"\"},");
- }
- if(sb.lastIndexOf(",")>-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 {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
-
-
- public String getCodeAndDesc(String code){//根据fd_code值从常量表中查询fd_description
- String sql = "select fd_code,fd_description from bm_mapvaluecanst where fd_code=?";
-
- 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, code);
- rs = pstm.executeQuery();
- // sb.append("\"forShow\":[");
- while(rs.next()){
- String fdCode = rs.getString("fd_code") == null ? "" : rs.getString("fd_code");
- String fdDesc = rs.getString("fd_description") == null ? "" : rs.getString("fd_description");
- sb.append("{\"name\":\""+fdDesc+"\",\"id\":\""+fdCode+"\"},");
- }
- // if(sb.lastIndexOf(",")>-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 {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
-
- public int updateCodes(String deptId,String codes){//从组织机构表SYS_DEPARTMENT中查询对应部门下的CODES_ISSHOW字段值
- String sql = "update SYS_DEPARTMENT set CODES_ISSHOW=? where DEPT_ID=?";
-
- StringBuffer sb = new StringBuffer();
-
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;
- int n = 0;
-
- try {
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- pstm.setString(1, codes);
- pstm.setString(2, deptId);
- n = pstm.executeUpdate();
-
- // while(rs.next()){
- // String codesIsShow = rs.getString("CODES_ISSHOW") == null ? "" : rs.getString("CODES_ISSHOW");
- // sb.append(codesIsShow);
- // }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- // rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return n;
- }
-
- public String getcodes(String deptId){//从组织机构表SYS_DEPARTMENT中查询对应部门下的CODES_ISSHOW字段值
- String sql = "select CODES_ISSHOW from SYS_DEPARTMENT where DEPT_ID=?";
-
- 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, deptId);
- rs = pstm.executeQuery();
- while(rs.next()){
- String codesIsShow = rs.getString("CODES_ISSHOW") == null ? "" : rs.getString("CODES_ISSHOW");
- sb.append(codesIsShow);
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
-
- public int getUnitTypeNum(){//获取常量表中fd_type='BM_SHOW_UNITES'记录的条数
- String sql = "select count(1) from bm_mapvaluecanst where fd_type='BM_SHOW_UNITES'";
-
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;
- ResultSet rs = null;
- int n = 0;
- try {
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- rs = pstm.executeQuery();
- while(rs.next()){
- n = rs.getInt("count(1)");
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return n;
- }
-
- public int insertUnitTypes(String fdCode,String description,String fdType,int sortNum){//往常量表中新增记录
- String sql = "insert into bm_mapvaluecanst (FD_CODE,FD_DESCRIPTION,FD_TYPE,FD_SORT) values (?,?,?,?)";
-
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;
- ResultSet rs = null;
- int n = 0;
- try {
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- pstm.setString(1, fdCode);
- pstm.setString(2, description);
- pstm.setString(3, "BM_SHOW_UNITES");
- pstm.setInt(4, sortNum);
- n=pstm.executeUpdate();
- } 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) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return n;
- }
-
- }
|