0e4d6889a683717636197ff2885bffb081cbe9f9.svn-base 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package com.sinosoft.em.warning.duty;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import org.apache.log4j.Logger;
  9. import net.sf.json.JSONArray;
  10. import net.sf.json.JSONObject;
  11. import com.formaction.Parameter;
  12. import com.formaction.vo.Msg;
  13. import com.persistence.DbConnection;
  14. import com.persistence.service.assitant.generator.IdentityGenerator;
  15. import com.persistence.service.exception.PersistenceException;
  16. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  17. import com.sinosoft.cm.common.ArrayList;
  18. import com.sinosoft.em.alert.report.manage.dao.QueryReportProgrammeDaoImpl;
  19. import com.sinosoft.lz.system.sms.vo.SearchPeople;
  20. import com.sinosoft.lz.system.sms.vo.Tree;
  21. public class WarningDutyDao {
  22. private final static Logger log = Logger.getLogger(QueryReportProgrammeDaoImpl.class);
  23. public String loadDutyDetailByDeptIds(String deptids, String planId) {
  24. String[] deptIdArr = deptids.split(",");
  25. List<Map<String, String>> dateList = getDutyDate(planId);
  26. List<WarningDutyBean> dutyList = new ArrayList<WarningDutyBean>();
  27. for (int i = 0; i < dateList.size(); i++) {
  28. Map<String, String> map = dateList.get(i);
  29. WarningDutyBean duty = new WarningDutyBean();
  30. String dutyDate = map.get("DUTY_DATE");
  31. String dutyTime = map.get("DUTY_TIME");
  32. String fuZhuId = map.get("FD_OBJECTID");
  33. duty.setDutyDate(dutyDate);
  34. duty.setDutyTime(dutyTime);
  35. //循环部门
  36. for (int j = 0; j < deptIdArr.length; j++) {
  37. String deptId = deptIdArr[j];
  38. List<Map<String, String>> list = getDutyDetailByDeptId(deptId,fuZhuId,planId);
  39. if(list!=null && list.size()>0){
  40. Map<String, String> map1 = list.get(0);
  41. String cz = map1.get("CZ");
  42. String zg = map1.get("ZG");
  43. String dutyPer = cz+"</br>"+zg;
  44. if("".equals(cz.trim()) && "".equals(zg.trim())){
  45. dutyPer = "";
  46. }
  47. if("R002105430213".equals(deptId)){//安监部
  48. String dbld = map1.get("DBLD");
  49. duty.setDbld(dbld);
  50. duty.setAjb(dutyPer);
  51. }
  52. if("R002105430210".equals(deptId)){//系统部
  53. duty.setXtb(dutyPer);
  54. }
  55. if("R002105430211".equals(deptId)){//设备部
  56. duty.setSbb(dutyPer);
  57. }
  58. if("R002105430212".equals(deptId)){//市场部
  59. duty.setScb(dutyPer);
  60. }
  61. if("R002105430213".equals(deptId)){//物资部
  62. duty.setAjb(dutyPer);
  63. }
  64. if("R002105430213".equals(deptId)){//办公厅
  65. duty.setAjb(dutyPer);
  66. }
  67. }
  68. }
  69. dutyList.add(duty);
  70. }
  71. return JSONArray.fromObject(dutyList).toString();
  72. }
  73. /**
  74. * 通过任务id查询值班辅助表数据---值班日期和值班时间
  75. * @param planId 任务id
  76. * @return
  77. */
  78. public List<Map<String, String>> getDutyDate(String planId) {
  79. String sql = "select FD_OBJECTID,DUTY_DATE,DUTY_TIME,DUTY_PLAN_ID,SORT from BM_ECM_WARNING_DUTY_TABLE_ROW where DUTY_PLAN_ID='"+planId+"' order by duty_date,duty_time ";
  80. try {
  81. List<Map<String, String>> list = new ORGTemplate().query(sql);
  82. return list;
  83. } catch (Exception e) {
  84. e.printStackTrace();
  85. }
  86. return null;
  87. }
  88. /**
  89. * 通过任务id和部门id查询该部门的值班安排详细
  90. * @param deptId 部门(角色)id
  91. * @param planId 任务id
  92. * @param planId2
  93. * @param dutyTime
  94. * @return
  95. */
  96. public List<Map<String, String>> getDutyDetailByDeptId(String deptId, String fuZhuId, String planId) {
  97. String sql = "select * from (select a.FD_OBJECTID , DUTY_RECORDS_ID, TABLE_ROW_ID , DBLD , CZ , ZG , b.DUTY_DATE , b.DUTY_TIME from BM_ECM_WARNING_DUTY_DETAIL a LEFT JOIN BM_ECM_WARNING_DUTY_TABLE_ROW b ON a.TABLE_ROW_ID=b.FD_OBJECTID where b.fd_objectid='"+fuZhuId+"' order by b.duty_date,b.duty_time ) d, BM_ECM_WARNING_DUTY_RECORDS c where c.fd_objectid=d.DUTY_RECORDS_ID and c.duty_plan_id='"+planId+"' and c.INPUT_PER_DEPT_ID='"+deptId+"' and c.RELEASE_STATE='1'";
  98. try {
  99. List<Map<String, String>> list = new ORGTemplate().query(sql);
  100. return list;
  101. } catch (Exception e) {
  102. e.printStackTrace();
  103. }
  104. return null;
  105. }
  106. /**
  107. * (发布任务时)保存值班辅助表数据
  108. * @param planId
  109. * @param list
  110. * @return
  111. */
  112. public Msg saveDutyFuZhu(String planId, List<Map<String, String>> list) {
  113. Msg m=new Msg();
  114. String sql="insert into BM_ECM_WARNING_DUTY_TABLE_ROW( FD_OBJECTID, DUTY_DATE, DUTY_TIME, DUTY_PLAN_ID, SORT) VALUES(?,?,?,?,?);";
  115. String sql1="delete from BM_ECM_WARNING_DUTY_TABLE_ROW where DUTY_PLAN_ID='"+planId+"'";
  116. Connection conn = null;
  117. PreparedStatement st = null;
  118. PreparedStatement st1 = null;
  119. DbConnection db = new DbConnection();
  120. try {
  121. conn = db.getConnection();
  122. int num=0;
  123. st1 = conn.prepareStatement(sql1);
  124. st1.executeUpdate();
  125. conn.setAutoCommit(false);
  126. st = conn.prepareStatement(sql);
  127. for (int i = 0; i < list.size(); i++) {
  128. Map<String, String> map = list.get(i);
  129. String fd_id=IdentityGenerator.getIdentityGenerator().gerenalIdentity(313);
  130. st.setString(1, fd_id);
  131. st.setString(2, map.get("dutydate"));
  132. st.setString(3, map.get("dutytime"));
  133. st.setString(4, planId);
  134. st.setString(5, ""+i);
  135. st.executeUpdate();
  136. log.info(sql);
  137. num++;
  138. }
  139. if(num==list.size()){
  140. log.info("保存成功");
  141. conn.commit();
  142. m.setSucsess(new Boolean(true).toString());
  143. m.setInfo(Parameter.DELETE_SUCSESS);
  144. return m;
  145. }else{
  146. m.setSucsess(new Boolean(false).toString());
  147. m.setInfo(Parameter.DELETE_FAILURE);
  148. conn.rollback();
  149. log.info("保存失败");
  150. return m;
  151. }
  152. } catch (Exception e) {
  153. e.printStackTrace();
  154. } finally {
  155. db.close(st);
  156. db.close(conn);
  157. try {
  158. if(st1!= null)
  159. st1.close();
  160. } catch (SQLException e) {
  161. // TODO Auto-generated catch block
  162. e.printStackTrace();
  163. }
  164. }
  165. return m;
  166. }
  167. public String loadDutyDetailByRecordsId(String recordsId) {
  168. String sql = "select a.FD_OBJECTID,UPDATEDATE,IS_DEL,DUTY_RECORDS_ID,TABLE_ROW_ID,DBLD,CZ,ZG,b.DUTY_DATE,b.DUTY_TIME from BM_ECM_WARNING_DUTY_DETAIL a LEFT JOIN BM_ECM_WARNING_DUTY_TABLE_ROW b ON a.TABLE_ROW_ID=b.FD_OBJECTID where DUTY_RECORDS_ID='"+recordsId+"' order by b.DUTY_DATE,b.DUTY_TIME ";
  169. try {
  170. List<Map<String, String>> list = new ORGTemplate().query(sql);
  171. return JSONArray.fromObject(list).toString();
  172. } catch (Exception e) {
  173. e.printStackTrace();
  174. }
  175. return null;
  176. }
  177. public String loadPlanByDeptId(String deptId) {
  178. String result = "";
  179. String sql = "select FD_OBJECTID value,UPDATEDATE,IS_DEL,PLAN_NAME key,EVENT_ID,INPUT_PER_NAME,INPUT_PER_ID,INPUT_PER_UNIT_NAME,"
  180. + "INPUT_PER_UNIT_ID,INPUT_PER_DEPT_NAME,INPUT_PER_DEPT_ID,START_DATE,END_DATE,DUTY_NUM,START_TIME,"
  181. + "WAIT_INPUT_LINGDAO_DEPT_ID,WAIT_INPUT_LINGDAO_DEPT_NAME,WAIT_INPUT_DUTY_DEPT_ID,WAIT_INPUT_DUTY_DEPT_NAME,"
  182. + "RELEASE_STATE from BM_ECM_WARNING_DUTY_PLAN where RELEASE_STATE='1' AND IS_DEL='0' "
  183. + "and WAIT_INPUT_DUTY_DEPT_ID like '%"+deptId+"%' order by updatedate desc";
  184. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  185. try {
  186. list = new ORGTemplate().query(sql);
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. }
  190. if(list.size()==0){
  191. Map<String, String> map = new HashMap<String, String>();
  192. map.put("key", "请选择");
  193. map.put("value", "请选择");
  194. list.add(map);
  195. }
  196. result = JSONArray.fromObject(list).toString();
  197. result = result.replaceAll("KEY", "key").replaceAll("VALUE", "value");
  198. return result;
  199. }
  200. public Msg deleteDutyFuZhu(String planId) {
  201. Msg m=new Msg();
  202. String sql="delete from BM_ECM_WARNING_DUTY_TABLE_ROW where DUTY_PLAN_ID=? ";
  203. Connection conn = null;
  204. PreparedStatement st = null;
  205. DbConnection db = new DbConnection();
  206. try {
  207. conn = db.getConnection();
  208. st = conn.prepareStatement(sql);
  209. st.setString(1, planId);
  210. st.executeUpdate();
  211. log.info(sql);
  212. log.info("保存成功");
  213. m.setSucsess(new Boolean(true).toString());
  214. m.setInfo(Parameter.DELETE_SUCSESS);
  215. } catch (Exception e) {
  216. log.info("保存失败");
  217. m.setSucsess(new Boolean(false).toString());
  218. m.setInfo(Parameter.DELETE_FAILURE);
  219. e.printStackTrace();
  220. } finally {
  221. db.close(st);
  222. db.close(conn);
  223. }
  224. return m;
  225. }
  226. public String getPeople(String name,int pageSize,int page,String id) throws PersistenceException{
  227. if(name.contains("'")){
  228. name = name.replaceAll("'", "");
  229. }
  230. String sql = "select distinct top "+(page-1)*pageSize+","+pageSize+" b.user_id,b.dept_id,b.real_name,b.mobile from sys_department a,sys_user_info b where a.dept_id=b.dept_id and (b.real_name like ? or b.login_name like ?)";
  231. String sql1 = "select distinct b.user_id,b.dept_id,b.real_name,b.mobile from sys_department a,sys_user_info b where a.dept_id=b.dept_id and (b.real_name like ? or b.login_name like ? ) ";
  232. if(!"".equals(id)){
  233. sql+="and a.corp_id =? ";
  234. sql1 += " and a.corp_id = ? ";
  235. }
  236. String sql2 = "select distinct count(*) from ("+sql1+")";
  237. List<String[]> list1 = null;
  238. List<String[]> list2 = null;
  239. if(!"".equals(id)){
  240. try {
  241. list1 = new ORGTemplate().getSearchResult(sql,"%"+name+"%","%"+name+"%",id+"_needUsein");
  242. list2 = new ORGTemplate().getSearchResult(sql2,"%"+name+"%","%"+name+"%",id+"_needUsein");
  243. } catch (SQLException e) {
  244. e.printStackTrace();
  245. }
  246. }else{
  247. try {
  248. list1 = new ORGTemplate().getSearchResult(sql,"%"+name+"%","%"+name+"%");
  249. list2 = new ORGTemplate().getSearchResult(sql2,"%"+name+"%","%"+name+"%");
  250. } catch (SQLException e) {
  251. e.printStackTrace();
  252. }
  253. }
  254. List<Object> list = new ArrayList<Object>();
  255. Tree t = new Tree();
  256. SearchPeople sp = null;
  257. for(String[] s:list1){
  258. sp = new SearchPeople();
  259. sp.setKey(s[2]);
  260. sp.setValue(s[3]);
  261. list.add(sp);
  262. }
  263. String totalRows = list2.get(0)[0];
  264. t.setTreeNodes(list);
  265. t.setTotalRows(totalRows);
  266. return JSONObject.fromObject(t).toString();
  267. }
  268. }