123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- package com.sinosoft.am.filemanger.document.dao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.log4j.Logger;
- import com.formaction.Parameter;
- import com.formaction.vo.Msg;
- import com.persistence.DbConnection;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.am.filemanger.document.vo.DocBean;
- import com.sinosoft.am.filemanger.document.vo.govDoc;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- public class govDocDao{
- private Logger log = Logger.getLogger(this.getClass());
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- private List<govDoc>numList = new ArrayList<govDoc>();
-
- /**
- * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
- * @param id
- * @return
- */
- public String NumInit(String id,String startTime,String endTime,String tempLevel,String deptId,String valueType1){
-
- String sql="select DEPT_ID from sys_department where (parent_id='"+id+"' or DEPT_ID='"+id+"')";
-
- try{
-
- if(deptId != null && !"null".equals(deptId) &&!"".equals(deptId)){
- sql+=" and DEPT_ID in("+deptId+") ";
- }
-
- if(checkId(id)){
-
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- log.info("carNum.tempList.size===="+tempList.size());
- List<String>list=new ArrayList<String>();
- for(int i=0;i<tempList.size();i++){
- list.add(tempList.get(i)[0]);
- }
- getFileNum(list, list.get(0),startTime,endTime,tempLevel,valueType1);
-
- }else{
- List<String>list=new ArrayList<String>();
- list.add(id);
- getNoChildFileNum(list, id,startTime,endTime,tempLevel,valueType1);
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- // log.info("最终JSON==="+json.toString());
- /*if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }
- */
- govDoc numBean = new govDoc();
- for(int i=0;i<numList.size();i++){
- // numBean.setGovDoc(numBean.getGovDoc()+numList.get(i).getGovDoc());
- numBean.setLevel1(numBean.getLevel1()+numList.get(i).getLevel1());
- numBean.setLevel2(numBean.getLevel2()+numList.get(i).getLevel2());
- numBean.setLevel3(numBean.getLevel3()+numList.get(i).getLevel3());
- numBean.setLevel4(numBean.getLevel4()+numList.get(i).getLevel4());
- // numBean.setEnpDoc(numBean.getEnpDoc()+numList.get(i).getEnpDoc());
- // numBean.setEnpSys(numBean.getEnpSys()+numList.get(i).getEnpSys());
- // numBean.setEnpArd(numBean.getEnpArd()+numList.get(i).getEnpArd());
- numBean.setNum(numBean.getNum()+numList.get(i).getNum());
-
- }
- json.append("{ ");
- json.append(" \"level1\":\"" + numBean.getLevel1() + "\",");
- json.append(" \"level2\":\"" + numBean.getLevel2() + "\",");
- json.append(" \"level3\":\"" + numBean.getLevel3() + "\",");
- json.append(" \"level4\":\"" + numBean.getLevel4() + "\",");
- // json.append(" \"enpDoc\":\"" + numBean.getEnpDoc() + "\",");
- // json.append(" \"enpSys\":\"" + numBean.getEnpSys() + "\",");
- // json.append(" \"enpArd\":\"" + numBean.getEnpArd() + "\",");
- json.append(" \"num\":\"" + numBean.getNum() + "\",");
- json.append(" \"name\":\"" +"总计" + "\",");
- json.append(" \"dept_id\":\"" + "11111" + "\",");
- json.append(" \"isParent\":false,");
- json.append(" \"open\":false");
- json.append("} ");
- String result="{\"rows\":["+json.toString()+"]}";
- // List<String>list=getCmpList(id, new ArrayList<String>());
- log.info("result===="+result);
- return result;
- }
-
- public String teamNum(String id,String startTime,String endTime,String tempLevel,String valueType1){
- try{
- if(checkId(id)){
- String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- log.info("teamNum.tempList.size===="+tempList.size());
- for(int i=0;i<tempList.size();i++){
- List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
- getFileNum(list, tempList.get(i)[0],startTime,endTime,tempLevel,valueType1);
- }
- }else{
- List<String>list=new ArrayList<String>();
- list.add(id);
- getNoChildFileNum(list, id,startTime,endTime,tempLevel,valueType1);
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- // log.info("最终JSON==="+json.toString());
- if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }
- String result="{\"rows\":["+json.toString()+"]}";
- // List<String>list=getCmpList(id, new ArrayList<String>());
- log.info("result===="+result);
- return result;
- }
-
- public List<String> getCmpList(String id,List<String>list) {
- try{
- if(checkId(id)){//存在子节点且子节点在明细表中有记录
- list.add(id);
- String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- log.info("getCmpList.tempList.size===="+tempList.size());
- for(int i=0;i<tempList.size();i++){
- getCmpList(tempList.get(i)[0],list);
- }
- }
- else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
- list.add(id);
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- return list;
- }
- //判断是否有下级单位
- public boolean checkId(String id) {
- try{
- // String sql="select * from EMC_AM_BUSINESS_DOCUMENT WHERE UNITE IN(SELECT ID FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"')";
- String sql="select * from EMC_AM_GOVERNMENT_DOCUMENT WHERE UNITE IN(SELECT DEPT_ID FROM SYS_DEPARTMENT WHERE PARENT_ID='"+id+"')";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- if(tempList==null||tempList.size()==0){
- return false;
- }else{
- return true;
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- return false;
- }
- }
-
- //统计
- public void getFileNum(List<String>list,String id,String startTime,String endTime,String tempLevel,String valueType1) throws PersistenceException{
-
- try{
- for(int i=0;i<list.size();i++){
- govDoc fa = new govDoc();
- String sql="select UNITE,sum(case SECRECY_LEVEL when '1' then 1 else 0 end)as 公开,"
- + "sum(case SECRECY_LEVEL when '2' then 1 else 0 end)as 秘密 ,"
- + "sum(case SECRECY_LEVEL when '3' then 1 else 0 end)as 机密,"
- + "sum(case SECRECY_LEVEL when '4' then 1 else 0 end)as 绝密,"
- + "count(SECRECY_LEVEL)as num from EMC_AM_GOVERNMENT_DOCUMENT where is_del='0' and IS_ISSUE = '1' and UNITE='"+list.get(i)+"'";
-
- if(startTime!=null&&!"null".equals(startTime)&&!"".equals(startTime)){
-
- sql+=" and PRINT_DATE between '"+startTime+"' and '"+endTime+"'";
- }
-
- //状态
- if(tempLevel!=null&&!"".equals(tempLevel)&&!"null".equals(tempLevel)){
- sql+=" and STATE in("+tempLevel+")";
- }
-
- //保密级别
- if(valueType1!=null&&!"null".equals(valueType1)&&!"".equals(valueType1)){
- sql+=" and SECRECY_LEVEL in ("+valueType1+")";
- }
-
- sql+=" group by UNITE ";
-
-
- log.info("getTeamNum.sql===="+sql);
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- if(tempList.size()>0){
- fa.setLevel1(Integer.parseInt(tempList.get(0)[1]));
- fa.setLevel2(Integer.parseInt(tempList.get(0)[2]));
- fa.setLevel3(Integer.parseInt(tempList.get(0)[3]));
- fa.setLevel4(Integer.parseInt(tempList.get(0)[4]));
- /*fa.setEnpDoc(Integer.parseInt(tempList.get(0)[1]));
- fa.setEnpSys(Integer.parseInt(tempList.get(0)[2]));
- fa.setEnpArd(Integer.parseInt(tempList.get(0)[3]));*/
- fa.setNum(Integer.parseInt(tempList.get(0)[5]));
-
- numList.add(fa);
- int fff = fa.getNum();
-
- if(fa.getNum()>0){
- if(checkId(id)){
- json.append("{ ");
- json.append(" \"level1\":\"" + fa.getLevel1() + "\",");
- json.append(" \"level2\":\"" + fa.getLevel2() + "\",");
- json.append(" \"level3\":\"" + fa.getLevel3() + "\",");
- json.append(" \"level4\":\"" + fa.getLevel4() + "\",");
- json.append(" \"num\":\"" + fa.getNum() + "\",");
- json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
- json.append(" \"dept_id\":\"" + list.get(i) + "\",");
- json.append(" \"isParent\":true,");
- json.append(" \"open\":false");
- json.append("}, ");
- }else{
- json.append("{ ");
- json.append(" \"level1\":\"" + fa.getLevel1() + "\",");
- json.append(" \"level2\":\"" + fa.getLevel2() + "\",");
- json.append(" \"level3\":\"" + fa.getLevel3() + "\",");
- json.append(" \"level4\":\"" + fa.getLevel4() + "\",");
- json.append(" \"num\":\"" + fa.getNum() + "\",");
- json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
- json.append(" \"dept_id\":\"" + list.get(i) + "\",");
- json.append(" \"isParent\":false,");
- json.append(" \"open\":false");
- json.append("}, ");
- }
- }
- }
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- }
-
- //统计
- public void getNoChildFileNum(List<String>list,String id,String startTime,String endTime,String tempLevel,String valueType1) throws PersistenceException{
- govDoc fa = new govDoc();
- try{
- for(int i=0;i<list.size();i++){
- String sql="select UNITE,sum(case SECRECY_LEVEL when '1' then 1 else 0 end)as 公开,"
- + "sum(case SECRECY_LEVEL when '2' then 1 else 0 end)as 秘密 ,"
- + "sum(case SECRECY_LEVEL when '3' then 1 else 0 end)as 机密,"
- + "sum(case SECRECY_LEVEL when '4' then 1 else 0 end)as 绝密,"
- + "count(SECRECY_LEVEL)as num from EMC_AM_GOVERNMENT_DOCUMENT where is_del='0' and IS_ISSUE = '1' and UNITE='"+list.get(i)+"'";
-
- if(startTime!=null&&!"null".equals(startTime)&&!"".equals(startTime)){
- sql+=" and PRINT_DATE between '"+startTime+"' and '"+endTime+"'";
- }
-
- //状态
- if(tempLevel!=null&&!"".equals(tempLevel)&&!"null".equals(tempLevel)){
- sql+=" and STATE in("+tempLevel+")";
- }
-
- //保密级别
- if(valueType1!=null&&!"null".equals(valueType1)&&!"".equals(valueType1)){
- sql+=" and SECRECY_LEVEL in ("+valueType1+")";
- }
-
- sql+=" group by UNITE ";
-
- log.info("getNoChildTeamNum.sql===="+sql);
- List<String[]>numList= persistence.getSearchResult(99, sql.toString());
- if(numList.size()>0){
- fa.setLevel1(fa.getLevel1()+Integer.parseInt(numList.get(0)[1]));
- fa.setLevel2(fa.getLevel2()+Integer.parseInt(numList.get(0)[2]));
- fa.setLevel3(fa.getLevel3()+Integer.parseInt(numList.get(0)[3]));
- fa.setLevel4(fa.getLevel4()+Integer.parseInt(numList.get(0)[4]));
- /*fa.setEnpDoc(fa.getEnpDoc()+Integer.parseInt(numList.get(0)[1]));
- fa.setEnpSys(fa.getEnpSys()+Integer.parseInt(numList.get(0)[2]));
- fa.setEnpArd(fa.getEnpArd()+Integer.parseInt(numList.get(0)[3]));*/
- fa.setNum(fa.getNum()+Integer.parseInt(numList.get(0)[5]));
-
- }
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- // StringBuffer json=new StringBuffer();
- if(fa.getNum()>0){
- json.append("{ ");
- json.append(" \"level1\":\"" + fa.getLevel1() + "\",");
- json.append(" \"level2\":\"" + fa.getLevel2() + "\",");
- json.append(" \"level3\":\"" + fa.getLevel3() + "\",");
- json.append(" \"level4\":\"" + fa.getLevel4() + "\",");
- json.append(" \"num\":\"" + fa.getNum() + "\",");
- json.append(" \"name\":\"" + getNameById(id) + "\",");
- json.append(" \"dept_id\":\"" + id + "\",");
- json.append(" \"isParent\":false,");
- json.append(" \"open\":true");
- json.append("}, ");
- numList.add(fa);
- }
- }
-
- public String getNameById(String id){
- String sql="select DEPT_NAME from sys_department where DEPT_ID='"+id+"'";
- try {
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- if(tempList==null||tempList.size()==0){
- return "";
- }else{
- String name=tempList.get(0)[0].replace("供电局", "").replace("广东电网有限责任公司", "广东");
- log.info("name===="+name);
- return name;
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return "";
- }
- }
-
-
- /********************************发布、共享********************************************/
-
-
- /**
- *政府公文,,,,改变(更新)发布状态为1
- * @throws ClassNotFoundException
- */
- public Msg getIsIssue(String fd_id) throws ClassNotFoundException{
- Msg m=new Msg();
- String []arr=fd_id.split(",");
- String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_ISSUE='1' where fd_objectid=?";
- Connection conn = null;
- PreparedStatement st = null;
- int num=0;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<arr.length;i++){
- st.setString(1, arr[i]);
- st.executeUpdate();
- num++;
- }
- if(num==arr.length){
- log.info("发布----num===="+num);
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.OPER_SUCSESS);
- conn.commit();
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.OPER_FAILURE);
- conn.rollback();
- return m;
- }
- }catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 发布消息" + sql, e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
-
- /**
- *政府公文,,,,改变(更新)发布状态为1
- * @throws ClassNotFoundException
- */
- public Msg getnoIsIssue(String fd_id) throws ClassNotFoundException{
- Msg m=new Msg();
- String []arr=fd_id.split(",");
- String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_ISSUE='0',IS_SHARE='0' where fd_objectid=?";
- Connection conn = null;
- PreparedStatement st = null;
- int num=0;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<arr.length;i++){
- st.setString(1, arr[i]);
- st.executeUpdate();
- num++;
- }
- if(num==arr.length){
- log.info("发布----num===="+num);
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.OPER_SUCSESS);
- conn.commit();
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.OPER_FAILURE);
- conn.rollback();
- return m;
- }
- }catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 发布消息" + sql, e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
-
-
- /**
- * 共享文件 都可以看到
- * @throws ClassNotFoundException
- */
- //共享
- public Msg getDocuShare(String fd_id) throws ClassNotFoundException{
- Msg m=new Msg();
- String []arr=fd_id.split(",");
- String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_SHARE='1' where fd_objectid=?";
- Connection conn = null;
- PreparedStatement st = null;
- int num=0;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<arr.length;i++){
- st.setString(1, arr[i]);
- st.executeUpdate();
- num++;
- }
- if(num==arr.length){
- log.info("发布----num===="+num);
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.OPER_SUCSESS);
- conn.commit();
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.OPER_FAILURE);
- conn.rollback();
- return m;
- }
- }catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 发布消息" + sql, e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
-
- /**
- * 撤销共享
- * @throws ClassNotFoundException
- */
- //取消共享
- public Msg getnoDocuShare(String fd_id) throws ClassNotFoundException{
- Msg m=new Msg();
- String []arr=fd_id.split(",");
- String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_SHARE='0' where fd_objectid=?";
- Connection conn = null;
- PreparedStatement st = null;
- int num=0;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<arr.length;i++){
- st.setString(1, arr[i]);
- st.executeUpdate();
- num++;
- }
- if(num==arr.length){
- log.info("发布----num===="+num);
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.OPER_SUCSESS);
- conn.commit();
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.OPER_FAILURE);
- conn.rollback();
- return m;
- }
- }catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 发布消息"
- + sql, e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
-
- }
|