123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- 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.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- public class DocDao{
- private Logger log = Logger.getLogger(this.getClass());
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- private List<DocBean>numList=new ArrayList<DocBean>();
- /**
- * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
- * @param id
- * @return
- */
- public String NumInit(String id,String StartTime,String EndTime,String mimiLevel,String tempLevel,String valueType,String deptId){
-
- 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,mimiLevel,tempLevel,valueType);
-
- }else{
- List<String>list=new ArrayList<String>();
- list.add(id);
- getNoChildFileNum(list, id,StartTime,EndTime,mimiLevel,tempLevel,valueType);
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- // log.info("最终JSON==="+json.toString());
- /* if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }*/
- DocBean numBean = new DocBean();
- for(int i=0;i<numList.size();i++){
- 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(" \"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 mimiLevel,String tempLevel,String valueType){
- 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,mimiLevel,tempLevel,valueType);
- }
- }else{
- List<String>list=new ArrayList<String>();
- list.add(id);
- getNoChildFileNum(list, id,StartTime,EndTime,mimiLevel,tempLevel,valueType);
- }}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 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 mimiLevel,String tempLevel,String valueType) throws PersistenceException{
-
- try{
- for(int i=0;i<list.size();i++){
- DocBean fa = new DocBean();
- String sql="select UNITE,sum(case CLASSES when '1' then 1 else 0 end)as 企业公文,"
- + "sum(case CLASSES when '2' then 1 else 0 end)as 企业制度 ,"
- + "sum(case CLASSES when '3' then 1 else 0 end)as 企业标准,"
- + "count(CLASSES)as num from EMC_AM_BUSINESS_DOCUMENT where is_del='0' and COLUMN_3='1' and UNITE='"+list.get(i)+"'";
-
- if(StartTime!=null&&!"".equals(StartTime)&&!"null".equals(StartTime)){
- sql+=" and PRINT_DATE between '"+StartTime+"' and '"+EndTime+"'";
- }
-
-
- //状态
- if(tempLevel!=null&&!"".equals(tempLevel)&&!"null".equals(tempLevel)){
- sql+=" and STATE in("+tempLevel+")";
- }
-
- //分类
- if(valueType!=null&&!"".equals(valueType)&&!"null".equals(valueType)){
- sql+=" and CLASSES in ("+valueType+")";
- }
-
- //保密级别
- if(mimiLevel!=null&&!"".equals(mimiLevel)&&!"null".equals(mimiLevel)){
- sql+=" and SECRECY_LEVEL in ("+mimiLevel+")";
- }
-
- sql+=" group by UNITE ";
-
-
- log.info("getTeamNum.sql===="+sql);
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- if(tempList.size()>0){
- 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)[4]));
-
- numList.add(fa);
-
- if(fa.getNum()>0){
- if(checkId(id)){
- json.append("{ ");
- json.append(" \"enpdoc\":\"" + fa.getEnpDoc() + "\",");
- json.append(" \"enpsys\":\"" + fa.getEnpSys() + "\",");
- json.append(" \"enpard\":\"" + fa.getEnpArd() + "\",");
- 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(" \"enpdoc\":\"" + fa.getEnpDoc() + "\",");
- json.append(" \"enpsys\":\"" + fa.getEnpSys() + "\",");
- json.append(" \"enpard\":\"" + fa.getEnpArd() + "\",");
- 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 mimiLevel,String tempLevel,String valueType) throws PersistenceException{
- DocBean fa = new DocBean();
- try{
- for(int i=0;i<list.size();i++){
- String sql="select UNITE,sum(case CLASSES when '1' then 1 else 0 end)as 企业公文,"
- + "sum(case CLASSES when '2' then 1 else 0 end)as 企业制度 ,"
- + "sum(case CLASSES when '3' then 1 else 0 end)as 企业标准,"
- + "count(CLASSES)as num from EMC_AM_BUSINESS_DOCUMENT where is_del='0' and COLUMN_3='1' and UNITE='"+list.get(i)+"'";
-
-
- if(StartTime!=null&&!"".equals(StartTime)&&!"null".equals(StartTime)){
- sql+=" and PRINT_DATE between '"+StartTime+"' and '"+EndTime+"'";
- }
-
-
- //状态
- if(tempLevel!=null&&!"".equals(tempLevel)&&!"null".equals(tempLevel)){
- sql+=" and STATE in("+tempLevel+")";
- }
-
- //分类
- if(valueType!=null&&!"".equals(valueType)&&!"null".equals(valueType)){
- sql+=" and CLASSES in ("+valueType+")";
- }
-
- //保密级别
- if(mimiLevel!=null&&!"".equals(mimiLevel)&&!"null".equals(mimiLevel)){
- sql+=" and SECRECY_LEVEL in ("+mimiLevel+")";
- }
-
- sql+=" group by UNITE ";
-
-
- log.info("getNoChildTeamNum.sql===="+sql);
- List<String[]>numList= persistence.getSearchResult(99, sql.toString());
- if(numList.size()>0){
- 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)[4]));
-
- }
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- // StringBuffer json=new StringBuffer();
- if(fa.getNum()>0){
- json.append("{ ");
- json.append(" \"enpdoc\":\"" + fa.getEnpDoc() + "\",");
- json.append(" \"enpsys\":\"" + fa.getEnpSys() + "\",");
- json.append(" \"enpard\":\"" + fa.getEnpArd() + "\",");
- 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 "";
- }
- }
-
-
- /********************************发布、共享********************************************/
-
-
- /**
- * 发布文件 除本级外都可以看到
- * @throws ClassNotFoundException
- */
- public Msg getDocuFabu(String fd_id) throws ClassNotFoundException{
- Msg m=new Msg();
- String []arr=fd_id.split(",");
- String sql="UPDATE EMC_AM_BUSINESS_DOCUMENT SET COLUMN_3='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 getnoDocuFabu(String fd_id) throws ClassNotFoundException{
- Msg m=new Msg();
- String []arr=fd_id.split(",");
- String sql="UPDATE EMC_AM_BUSINESS_DOCUMENT SET COLUMN_3='0',COLUMN_4='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_BUSINESS_DOCUMENT SET COLUMN_4='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_BUSINESS_DOCUMENT SET COLUMN_4='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);
- }
- }
-
- }
|