43e0254e7e7b300c3f7c71ffd4da3af9f603f1dc.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. package com.sinosoft.am.file.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import org.apache.log4j.Logger;
  8. import com.formaction.Parameter;
  9. import com.formaction.vo.Msg;
  10. import com.persistence.DbConnection;
  11. import com.persistence.service.PersistenceFactory;
  12. import com.persistence.service.SysPersistence;
  13. import com.persistence.service.exception.PersistenceException;
  14. import com.sinosoft.am.file.vo.FileAM;
  15. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  16. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  17. public class FileEMDao{
  18. private Logger log = Logger.getLogger(this.getClass());
  19. SysModel sysmodel = ModelFactory.getSysmodel();
  20. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  21. StringBuffer json = new StringBuffer();
  22. private List<FileAM> numList=new ArrayList<FileAM>();
  23. //
  24. // var gridData={"rows":[
  25. // {"value":1,"key":"南京分公司","isParent":true,"open":false},
  26. // {"value":7,"key":"杭州办事处","isParent":true,"open":false}
  27. // ]}
  28. /**
  29. * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
  30. * @param id
  31. * @return
  32. */
  33. public String NumInit(String id,String StartTime,String EndTime,String valueType,String deptId){
  34. String sql="select DEPT_ID from sys_department where (parent_id='"+id+"' or DEPT_ID='"+id+"')";
  35. log.info("carNum.tempList.size===="+deptId);
  36. try{
  37. if(deptId != null && !"null".equals(deptId) &&!"".equals(deptId)){
  38. sql+=" and DEPT_ID in("+deptId+") ";
  39. }
  40. if(checkId(id)){
  41. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  42. log.info("carNum.tempList.size===="+tempList.size());
  43. List<String>list=new ArrayList<String>();
  44. for(int i=0;i<tempList.size();i++){
  45. list.add(tempList.get(i)[0]);
  46. }
  47. getFileNum(list, list.get(0),StartTime,EndTime,valueType);
  48. }else{
  49. List<String>list=new ArrayList<String>();
  50. list.add(id);
  51. getNoChildFileNum(list, id,StartTime,EndTime,valueType);
  52. }}catch(Exception e){
  53. this.log.error(e.getMessage(), e);
  54. }
  55. // log.info("最终JSON==="+json.toString());
  56. // if (json.lastIndexOf(",") > -1) {
  57. // json.deleteCharAt(json.lastIndexOf(","));
  58. // }
  59. FileAM numBean = new FileAM();
  60. for(int i=0;i<numList.size();i++){
  61. numBean.setNetclass(numBean.getNetclass()+numList.get(i).getNetclass());
  62. numBean.setProvincial(numBean.getProvincial()+numList.get(i).getProvincial());
  63. numBean.setMunicipal(numBean.getMunicipal()+numList.get(i).getMunicipal());
  64. numBean.setSubcorps(numBean.getSubcorps()+numList.get(i).getSubcorps());
  65. numBean.setDishiju(numBean.getDishiju()+numList.get(i).getDishiju());
  66. numBean.setAdministrative(numBean.getAdministrative()+numList.get(i).getAdministrative());
  67. numBean.setNum(numBean.getNum()+numList.get(i).getNum());
  68. }
  69. json.append("{ ");
  70. json.append(" \"netclass\":\"" + numBean.getNetclass() + "\",");
  71. json.append(" \"provincial\":\"" + numBean.getProvincial() + "\",");
  72. json.append(" \"municipal\":\"" + numBean.getMunicipal() + "\",");
  73. json.append(" \"subcorps\":\"" + numBean.getSubcorps() + "\",");
  74. json.append(" \"dishiju\":\"" + numBean.getDishiju() + "\",");
  75. json.append(" \"administrative\":\"" + numBean.getAdministrative() + "\",");
  76. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  77. json.append(" \"name\":\"" +"总计" + "\",");
  78. json.append(" \"dept_id\":\"" + "11111" + "\",");
  79. json.append(" \"isParent\":false,");
  80. json.append(" \"open\":false");
  81. json.append("} ");
  82. String result="{\"rows\":["+json.toString()+"]}";
  83. // List<String>list=getCmpList(id, new ArrayList<String>());
  84. log.info("result===="+result);
  85. return result;
  86. }
  87. public String teamNum(String id,String StartTime,String EndTime,String valueType,String deptId){
  88. try{
  89. String sql="select dept_id from sys_department where parent_id='"+id+"'";
  90. if(deptId!=null){
  91. sql+=" and id in("+deptId+")";
  92. }
  93. if(checkId(id)){
  94. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  95. log.info("teamNum.tempList.size===="+tempList.size());
  96. for(int i=0;i<tempList.size();i++){
  97. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  98. getFileNum(list, tempList.get(i)[0],StartTime,EndTime,valueType);
  99. }
  100. }else{
  101. List<String>list=new ArrayList<String>();
  102. list.add(id);
  103. getNoChildFileNum(list, id,StartTime,EndTime,valueType);
  104. }}catch(Exception e){
  105. this.log.error(e.getMessage(), e);
  106. }
  107. // log.info("最终JSON==="+json.toString());
  108. if (json.lastIndexOf(",") > -1) {
  109. json.deleteCharAt(json.lastIndexOf(","));
  110. }
  111. String result="{\"rows\":["+json.toString()+"]}";
  112. // List<String>list=getCmpList(id, new ArrayList<String>());
  113. log.info("result===="+result);
  114. return result;
  115. }
  116. public List<String> getCmpList(String id,List<String>list) {
  117. try{
  118. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  119. list.add(id);
  120. String sql="select dept_id from sys_department where parent_id='"+id+"'";
  121. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  122. log.info("getCmpList.tempList.size===="+tempList.size());
  123. for(int i=0;i<tempList.size();i++){
  124. getCmpList(tempList.get(i)[0],list);
  125. }
  126. }
  127. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  128. list.add(id);
  129. }}catch(Exception e){
  130. this.log.error(e.getMessage(), e);
  131. }
  132. return list;
  133. }
  134. public boolean checkId(String id) {
  135. try{
  136. String sql="select * from ECM_AM_PPS_FILE_MANAGEMANET WHERE PUBLISH_COMP_ID IN(SELECT dept_id FROM SYS_DEPARTMENT WHERE PARENT_ID='"+id+"')";
  137. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  138. if(tempList==null||tempList.size()==0){
  139. return false;
  140. }else{
  141. return true;
  142. }}catch(Exception e){
  143. this.log.error(e.getMessage(), e);
  144. return false;
  145. }
  146. }
  147. public void getFileNum(List<String>list,String id,String StartTime,String EndTime,String valueType) throws PersistenceException{
  148. try{
  149. for(int i=0;i<list.size();i++){
  150. FileAM fa = new FileAM();
  151. String sql="select PUBLISH_COMP_ID,sum(case FILE_CLASSIFY when '1' then 1 else 0 end)as 网级,"
  152. + "sum(case FILE_CLASSIFY when '2' then 1 else 0 end)as 省级,"
  153. + "sum(case FILE_CLASSIFY when '3' then 1 else 0 end)as 市级,"
  154. + "sum(case FILE_CLASSIFY when '4' then 1 else 0 end)as 分子公司, "
  155. + "sum(case FILE_CLASSIFY when '5' then 1 else 0 end)as 地市局,"
  156. + "sum(case FILE_CLASSIFY when '6' then 1 else 0 end)as 规范, "
  157. + "count(FILE_CLASSIFY)as num from ECM_AM_PPS_FILE_MANAGEMANET where is_del='0' and FABU='1' and PUBLISH_COMP_ID='"+list.get(i)+"'";
  158. if(StartTime!=null&&!"null".equals(StartTime)&&!"".equals(StartTime)){
  159. sql+=" and FILE_ADD_DATE between '"+StartTime+"' and '"+EndTime+"'";
  160. }
  161. //分类
  162. if(valueType!=null&&!"null".equals(valueType)&&!"".equals(valueType)){
  163. sql+=" and FILE_CLASSIFY in ("+valueType+")";
  164. }
  165. sql+=" group by PUBLISH_COMP_ID";
  166. log.info("getTeamNum.sql===="+sql);
  167. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  168. if(tempList.size()>0){
  169. // fa.setTeamCount(Integer.parseInt(tempList.get(0)[1]));
  170. // fa.setTeamMember(Integer.parseInt(tempList.get(0)[2]));
  171. // fa.setSdXianLu(Integer.parseInt(tempList.get(0)[3]));
  172. // fa.setSdXianLang(Integer.parseInt(tempList.get(0)[4]));
  173. // fa.setSdSum(Integer.parseInt(tempList.get(0)[5]));
  174. fa.setNetclass(Integer.parseInt(tempList.get(0)[1]));
  175. fa.setProvincial(Integer.parseInt(tempList.get(0)[2]));
  176. fa.setMunicipal(Integer.parseInt(tempList.get(0)[3]));
  177. fa.setSubcorps(Integer.parseInt(tempList.get(0)[4]));
  178. fa.setDishiju(Integer.parseInt(tempList.get(0)[5]));
  179. fa.setAdministrative(Integer.parseInt(tempList.get(0)[6]));
  180. fa.setNum(Integer.parseInt(tempList.get(0)[7]));
  181. numList.add(fa);
  182. if(fa.getNum()>0){
  183. if(checkId(id)){
  184. json.append("{ ");
  185. json.append(" \"netclass\":\"" + fa.getNetclass() + "\",");
  186. json.append(" \"provincial\":\"" + fa.getProvincial() + "\",");
  187. json.append(" \"municipal\":\"" + fa.getMunicipal() + "\",");
  188. json.append(" \"subcorps\":\"" + fa.getSubcorps() + "\",");
  189. json.append(" \"dishiju\":\"" + fa.getDishiju() + "\",");
  190. json.append(" \"administrative\":\"" + fa.getAdministrative() + "\",");
  191. json.append(" \"num\":\"" + fa.getNum() + "\",");
  192. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  193. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  194. json.append(" \"isParent\":true,");
  195. json.append(" \"open\":false");
  196. json.append("}, ");
  197. }else{
  198. json.append("{ ");
  199. json.append(" \"netclass\":\"" + fa.getNetclass() + "\",");
  200. json.append(" \"provincial\":\"" + fa.getProvincial() + "\",");
  201. json.append(" \"municipal\":\"" + fa.getMunicipal() + "\",");
  202. json.append(" \"subcorps\":\"" + fa.getSubcorps() + "\",");
  203. json.append(" \"dishiju\":\"" + fa.getDishiju() + "\",");
  204. json.append(" \"administrative\":\"" + fa.getAdministrative() + "\",");
  205. json.append(" \"num\":\"" + fa.getNum() + "\",");
  206. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  207. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  208. json.append(" \"isParent\":false,");
  209. json.append(" \"open\":false");
  210. json.append("}, ");
  211. }
  212. }
  213. }
  214. }}catch(Exception e){
  215. this.log.error(e.getMessage(), e);
  216. }
  217. }
  218. public void getNoChildFileNum(List<String>list,String id,String StartTime,String EndTime,String valueType) throws PersistenceException{
  219. FileAM fa = new FileAM();
  220. try{
  221. for(int i=0;i<list.size();i++){
  222. String sql="select PUBLISH_COMP_ID,sum(case FILE_CLASSIFY when '1' then 1 else 0 end)as 网级,"
  223. + "sum(case FILE_CLASSIFY when '2' then 1 else 0 end)as 省级,"
  224. + "sum(case FILE_CLASSIFY when '3' then 1 else 0 end)as 市级,"
  225. + "sum(case FILE_CLASSIFY when '4' then 1 else 0 end)as 分子公司, "
  226. + "sum(case FILE_CLASSIFY when '5' then 1 else 0 end)as 地市局,"
  227. + "sum(case FILE_CLASSIFY when '4' then 1 else 0 end)as 规范, "
  228. + "count(FILE_TITLE)as num from ECM_AM_PPS_FILE_MANAGEMANET where is_del='0' and FABU='1' and PUBLISH_COMP_ID='"+list.get(i)+"'";
  229. if(StartTime!=null&&!"null".equals(StartTime)&&!"".equals(StartTime)){
  230. sql+=" and FILE_ADD_DATE between '"+StartTime+"' and '"+EndTime+"'";
  231. }
  232. //分类
  233. if(valueType!=null&&!"null".equals(valueType)&&!"".equals(valueType)){
  234. sql+=" and FILE_CLASSIFY in ("+valueType+")";
  235. }
  236. sql+=" group by PUBLISH_COMP_ID";
  237. log.info("getNoChildTeamNum.sql===="+sql);
  238. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  239. if(numList.size()>0){
  240. fa.setNetclass(fa.getNetclass()+Integer.parseInt(numList.get(0)[1]));
  241. fa.setProvincial(fa.getProvincial()+Integer.parseInt(numList.get(0)[2]));
  242. fa.setMunicipal(fa.getMunicipal()+Integer.parseInt(numList.get(0)[3]));
  243. fa.setSubcorps(fa.getSubcorps()+Integer.parseInt(numList.get(0)[4]));
  244. fa.setDishiju(fa.getDishiju()+Integer.parseInt(numList.get(0)[5]));
  245. fa.setAdministrative(fa.getAdministrative()+Integer.parseInt(numList.get(0)[6]));
  246. fa.setNum(fa.getNum()+Integer.parseInt(numList.get(0)[7]));
  247. }
  248. }}catch(Exception e){
  249. this.log.error(e.getMessage(), e);
  250. }
  251. // StringBuffer json=new StringBuffer();
  252. if(fa.getNum()>0){
  253. json.append("{ ");
  254. json.append(" \"netclass\":\"" + fa.getNetclass() + "\",");
  255. json.append(" \"provincial\":\"" + fa.getProvincial() + "\",");
  256. json.append(" \"municipal\":\"" + fa.getMunicipal() + "\",");
  257. json.append(" \"subcorps\":\"" + fa.getSubcorps() + "\",");
  258. json.append(" \"dishiju\":\"" + fa.getDishiju() + "\",");
  259. json.append(" \"administrative\":\"" + fa.getAdministrative() + "\",");
  260. json.append(" \"num\":\"" + fa.getNum() + "\",");
  261. json.append(" \"name\":\"" + getNameById(id) + "\",");
  262. json.append(" \"dept_id\":\"" + id + "\",");
  263. json.append(" \"isParent\":false,");
  264. json.append(" \"open\":true");
  265. json.append("}, ");
  266. numList.add(fa);
  267. }
  268. }
  269. public String getNameById(String id){
  270. String sql="select dept_name from sys_department where dept_id='"+id+"'";
  271. try {
  272. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  273. if(tempList==null||tempList.size()==0){
  274. return "";
  275. }else{
  276. String name=tempList.get(0)[0];
  277. log.info("name===="+name);
  278. return name;
  279. }
  280. } catch (PersistenceException e) {
  281. // TODO Auto-generated catch block
  282. e.printStackTrace();
  283. return "";
  284. }
  285. }
  286. /*****************************************共享***********************************************/
  287. /**
  288. * 共享文件 都可以看到
  289. * @throws ClassNotFoundException
  290. */
  291. public Msg getDocuShare(String fd_id) throws ClassNotFoundException{
  292. Msg m=new Msg();
  293. String []arr=fd_id.split(",");
  294. String sql="UPDATE ECM_AM_PPS_FILE_MANAGEMANET SET IS_SHARE='1' where fd_objectid=?";
  295. Connection conn = null;
  296. PreparedStatement st = null;
  297. int num=0;
  298. DbConnection db = new DbConnection();
  299. try {
  300. conn = db.getConnection();
  301. conn.setAutoCommit(false);
  302. st = conn.prepareStatement(sql);
  303. for(int i=0;i<arr.length;i++){
  304. st.setString(1, arr[i]);
  305. st.executeUpdate();
  306. num++;
  307. }
  308. if(num==arr.length){
  309. log.info("发布----num===="+num);
  310. m.setSucsess(new Boolean(true).toString());
  311. m.setInfo(Parameter.OPER_SUCSESS);
  312. conn.commit();
  313. return m;
  314. }else{
  315. m.setSucsess(new Boolean(false).toString());
  316. m.setInfo(Parameter.OPER_FAILURE);
  317. conn.rollback();
  318. return m;
  319. }
  320. }catch (SQLException e) {
  321. this.log.error(e.getMessage(), e);
  322. throw new ClassNotFoundException("DAO Layou: 发布消息"
  323. + sql, e);
  324. } finally {
  325. db.close(st);
  326. db.close(conn);
  327. }
  328. }
  329. /**
  330. * 撤销共享
  331. * @throws ClassNotFoundException
  332. */
  333. public Msg getnoDocuShare(String fd_id) throws ClassNotFoundException{
  334. Msg m=new Msg();
  335. String []arr=fd_id.split(",");
  336. String sql="UPDATE ECM_AM_PPS_FILE_MANAGEMANET SET IS_SHARE='0' where fd_objectid=?";
  337. Connection conn = null;
  338. PreparedStatement st = null;
  339. int num=0;
  340. DbConnection db = new DbConnection();
  341. try {
  342. conn = db.getConnection();
  343. conn.setAutoCommit(false);
  344. st = conn.prepareStatement(sql);
  345. for(int i=0;i<arr.length;i++){
  346. st.setString(1, arr[i]);
  347. st.executeUpdate();
  348. num++;
  349. }
  350. if(num==arr.length){
  351. log.info("发布----num===="+num);
  352. m.setSucsess(new Boolean(true).toString());
  353. m.setInfo(Parameter.OPER_SUCSESS);
  354. conn.commit();
  355. return m;
  356. }else{
  357. m.setSucsess(new Boolean(false).toString());
  358. m.setInfo(Parameter.OPER_FAILURE);
  359. conn.rollback();
  360. return m;
  361. }
  362. }catch (SQLException e) {
  363. this.log.error(e.getMessage(), e);
  364. throw new ClassNotFoundException("DAO Layou: 发布消息"
  365. + sql, e);
  366. } finally {
  367. db.close(st);
  368. db.close(conn);
  369. }
  370. }
  371. /**
  372. * 撤销发布
  373. * @throws ClassNotFoundException
  374. */
  375. public Msg getnoPublish(String fd_id) throws ClassNotFoundException{
  376. Msg m=new Msg();
  377. String []arr=fd_id.split(",");
  378. String sql="UPDATE ECM_AM_PPS_FILE_MANAGEMANET SET FABU='0',IS_SHARE='0' where fd_objectid=?";
  379. Connection conn = null;
  380. PreparedStatement st = null;
  381. int num=0;
  382. DbConnection db = new DbConnection();
  383. try {
  384. conn = db.getConnection();
  385. conn.setAutoCommit(false);
  386. st = conn.prepareStatement(sql);
  387. for(int i=0;i<arr.length;i++){
  388. st.setString(1, arr[i]);
  389. st.executeUpdate();
  390. num++;
  391. }
  392. if(num==arr.length){
  393. log.info("发布----num===="+num);
  394. m.setSucsess(new Boolean(true).toString());
  395. m.setInfo(Parameter.OPER_SUCSESS);
  396. conn.commit();
  397. return m;
  398. }else{
  399. m.setSucsess(new Boolean(false).toString());
  400. m.setInfo(Parameter.OPER_FAILURE);
  401. conn.rollback();
  402. return m;
  403. }
  404. }catch (SQLException e) {
  405. this.log.error(e.getMessage(), e);
  406. throw new ClassNotFoundException("DAO Layou: 发布消息"
  407. + sql, e);
  408. } finally {
  409. db.close(st);
  410. db.close(conn);
  411. }
  412. }
  413. /***********************************************常量表借用*****************************************************/
  414. public Msg getaddMapValue(String code,String description,String type,String sort,String parentId) throws ClassNotFoundException{
  415. Msg m=new Msg();
  416. String sql="INSERT INTO BM_MAPVALUECANST (FD_CODE,FD_DESCRIPTION,FD_TYPE,FD_SORT,PARENT_ID) VALUES (?,?,?,?,?)";
  417. Connection conn = null;
  418. PreparedStatement st = null;
  419. DbConnection db = new DbConnection();
  420. try {
  421. conn = db.getConnection();
  422. conn.setAutoCommit(false);
  423. st = conn.prepareStatement(sql);
  424. st.setString(1, code);
  425. st.setString(2, description);
  426. st.setString(3, type);
  427. st.setString(4, sort);
  428. st.setString(5, parentId);
  429. st.executeUpdate();
  430. // if(num==arr.length){
  431. // log.info("发布----num===="+num);
  432. m.setSucsess(new Boolean(true).toString());
  433. m.setInfo(Parameter.OPER_SUCSESS);
  434. conn.commit();
  435. return m;
  436. // }else{
  437. // m.setSucsess(new Boolean(false).toString());
  438. // m.setInfo(Parameter.OPER_FAILURE);
  439. // conn.rollback();
  440. // return m;
  441. // }
  442. }catch (SQLException e) {
  443. this.log.error(e.getMessage(), e);
  444. throw new ClassNotFoundException("DAO Layou: 发布消息"
  445. + sql, e);
  446. } finally {
  447. db.close(st);
  448. db.close(conn);
  449. }
  450. }
  451. }