b786254394e8b53e4fe1d89025b0ad056837d580.svn-base 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. package com.sinosoft.gps.bgd_duty.service;
  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. import java.io.UnsupportedEncodingException;
  12. import java.net.URL;
  13. import java.net.URLConnection;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.UUID;
  20. import javax.servlet.ServletException;
  21. import javax.servlet.http.HttpServletRequest;
  22. import javax.servlet.http.HttpServletResponse;
  23. import javax.ws.rs.POST;
  24. import javax.ws.rs.Path;
  25. import javax.ws.rs.ProduceMime;
  26. import javax.ws.rs.core.Context;
  27. import jxl.Workbook;
  28. import jxl.write.Label;
  29. import jxl.write.WritableCell;
  30. import jxl.write.WritableCellFormat;
  31. import jxl.write.WritableSheet;
  32. import jxl.write.WritableWorkbook;
  33. import net.sf.json.JSONArray;
  34. import net.sf.json.JSONObject;
  35. import org.apache.cxf.transport.http.AbstractHTTPDestination;
  36. import org.apache.log4j.Logger;
  37. import org.apache.poi.hssf.usermodel.HSSFCell;
  38. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  39. import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
  40. import org.apache.poi.hssf.usermodel.HSSFComment;
  41. import org.apache.poi.hssf.usermodel.HSSFFont;
  42. import org.apache.poi.hssf.usermodel.HSSFPatriarch;
  43. import org.apache.poi.hssf.usermodel.HSSFRichTextString;
  44. import org.apache.poi.hssf.usermodel.HSSFRow;
  45. import org.apache.poi.hssf.usermodel.HSSFSheet;
  46. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  47. import org.apache.poi.hssf.util.CellRangeAddress;
  48. import org.apache.poi.hssf.util.HSSFColor;
  49. import org.apache.poi.hssf.util.Region;
  50. import org.apache.poi.ss.usermodel.Cell;
  51. import org.apache.poi.ss.usermodel.CellRange;
  52. import org.apache.poi.ss.usermodel.CellStyle;
  53. import org.springframework.context.support.ClassPathXmlApplicationContext;
  54. import com.formaction.Parameter;
  55. import com.formaction.Utils;
  56. import com.formaction.dao.OperateAble;
  57. import com.formaction.dao.OperateImpl;
  58. import com.formaction.dao.assistant.AssistantAble;
  59. import com.formaction.dao.assistant.AssistantImpl;
  60. import com.formaction.vo.Msg;
  61. import com.formaction.vo.RowSet;
  62. import com.persistence.service.assitant.generator.IdentityGenerator;
  63. import com.persistence.service.exception.PersistenceException;
  64. import com.persistence.service.exception.TransformTypeException;
  65. import com.sinosoft.common.upLoad.impl.UpLoadFormImpl;
  66. import com.sinosoft.common.upLoad.service.UploadManageImpl;
  67. import com.sinosoft.common.upLoad.service.UploadManageable;
  68. import com.sinosoft.common.upLoad.util.SmartUpload;
  69. import com.sinosoft.common.upLoad.util.SmartUploadException;
  70. import com.sinosoft.common.util.JsonPluginsUtil;
  71. import com.sinosoft.em.alert.duty.records.dao.AlertDutyExcel;
  72. import com.sinosoft.em.alert.duty.records.dao.EcmDutyExcel;
  73. import com.sinosoft.em.alert.duty.records.vo.EcmDutyDetail;
  74. import com.sinosoft.em.alert.duty.records.vo.EcmEmDuty;
  75. import com.sinosoft.em.evaluate.scoreGrade.dao.ScoreGradeDao;
  76. import com.sinosoft.em.response.equipment.records.impl.RespEquipmentImpl;
  77. import com.sinosoft.gps.bgd_duty.dao.BgdDutyDao;
  78. import com.sinosoft.gps.bgd_duty.dao.BgdDutyExcel;
  79. import com.sinosoft.gps.bgd_duty.vo.DutyBean;
  80. import com.sinosoft.lz.system.department.Department;
  81. import com.sinosoft.lz.system.department.DepartmentDao;
  82. import com.sinosoft.lz.system.logon.vo.LoginInfo;
  83. import com.sinosoft.lz.system.userFriend.dao.SendMsgDao;
  84. import com.sysmodel.XFormFactory;
  85. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  86. import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
  87. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  88. import com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl;
  89. import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
  90. import com.system.configer.vo.WSClientConfigure;
  91. @Path("/BgdDutyService/")
  92. public class BgdDutyService {
  93. @Context
  94. private org.apache.cxf.jaxrs.ext.MessageContext mc;
  95. private final Logger log = Logger.getLogger(getClass());
  96. @POST
  97. @ProduceMime("application/json")
  98. @Path("/queryPid/")
  99. public String queryPid(String params){
  100. log.info(params);
  101. String classid = "";
  102. classid = Utils.getParameter("classid", params);
  103. if(classid!=null && !"".equals(classid)){
  104. classid = "335";
  105. }
  106. String fD_OBJECTID = IdentityGenerator.getIdentityGenerator().gerenalIdentity(new Integer(classid));
  107. return "{\"pid\":\""+fD_OBJECTID+"\"}";
  108. }
  109. @POST
  110. @ProduceMime("application/json")
  111. @Path("/queryQui/")
  112. public String queryQui(String params) throws PersistenceException, TransformTypeException {
  113. OperateAble persistence = new OperateImpl();
  114. AssistantAble assistant = new AssistantImpl();
  115. log.info(params);
  116. RowSet rowSet = new RowSet();
  117. String listId = Utils.getParameter("listId", params);
  118. String type = "";
  119. type = Utils.getParameter("type", params);
  120. String firstPageNum = Utils.getParameter("pager.pageNo", params) == null ? "0" : Utils
  121. .getParameter("pager.pageNo", params);
  122. String limit = Utils.getParameter("pager.pageSize", params) == null ? "10" : Utils
  123. .getParameter("pager.pageSize", params);
  124. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listId);
  125. String condition = assistant.getSQLCondition(params, formList);
  126. String sort = Utils.getParameter("sort", params);// 排序字段
  127. String dir = Utils.getParameter("direction", params);// 升序还是降序
  128. // 根据 sort和dir的值判断 是否按照列排序了,如果都为空 说明是初次加载gird否则说明对gird列进行排序了。重新组装排序sql语句
  129. if (sort != null) {
  130. log.info("sort.length()=" + sort.length());
  131. if (sort.indexOf("_SHOW") > -1) {
  132. sort = sort.substring(0, sort.length() - 5);
  133. log.info("排序字段=" + sort);
  134. }
  135. String U_condition = condition.toUpperCase();
  136. if (U_condition.indexOf("ORDER") > -1) {
  137. log.info("------------=" + condition.toUpperCase());
  138. log.info("++++===" + U_condition.substring(0, U_condition.indexOf("ORDER")));
  139. condition = U_condition.substring(0, U_condition.indexOf("ORDER")) + " ORDER BY "
  140. + sort + " " + dir;
  141. } else {
  142. condition = condition + " order by " + sort + " " + dir;
  143. }
  144. log.info("----condition=" + condition);
  145. }
  146. StringBuffer sql = assistant.getSearchSql(formList, condition);
  147. if (formList.getQueryList().getPageSize() == 0 || "excel".equals(type)) {
  148. rowSet = persistence.queryAllDatas(formList, sql);
  149. } else {
  150. rowSet = persistence.queryPagingAllDatas(formList, sql, firstPageNum, limit);
  151. }
  152. rowSet = assistant.transformDate(rowSet, formList);// 修改日期格式化的问题 by
  153. log.info(JSONObject.fromObject(rowSet).toString());
  154. // 处理返回的结果,将结果适用于QuickUI
  155. JSONObject origin = JSONObject.fromObject(rowSet);
  156. String pageNoResult = origin.getString("total");
  157. String rowsResult = origin.getString("rows");
  158. String result = "{\"pager.pageNo\":" + firstPageNum + ",\"pager.totalRows\":"
  159. + pageNoResult + ",\"rows\":" + rowsResult + "}";
  160. log.info("qui====" + result);
  161. return result;
  162. }
  163. @ProduceMime("application/json")
  164. @POST
  165. @Path("/getlei_ZhiBan_Man")
  166. public String getlei_ZhiBan_Man(String params) {
  167. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
  168. try {
  169. BgdDutyDao dutyDao = new BgdDutyDao();
  170. return dutyDao.zhiBanName(deptId);
  171. } catch (PersistenceException e) {
  172. // TODO Auto-generated catch block
  173. e.printStackTrace();
  174. }
  175. return null;
  176. }
  177. @ProduceMime("application/json")
  178. @POST
  179. @Path("/emGetlei_ZhiBan_Man")
  180. public String emGetlei_ZhiBan_Man(String params) {
  181. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
  182. try {
  183. BgdDutyDao dutyDao = new BgdDutyDao();
  184. return dutyDao.emzhiBanName(deptId);
  185. } catch (PersistenceException e) {
  186. // TODO Auto-generated catch block
  187. e.printStackTrace();
  188. }
  189. return null;
  190. }
  191. @ProduceMime("application/json")
  192. @POST
  193. @Path("/getlei_ZhiBan_Man1")
  194. public String getlei_ZhiBan_Man1(String params) {
  195. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
  196. try {
  197. BgdDutyDao dutyDao = new BgdDutyDao();
  198. return dutyDao.zhiBanName1(deptId);
  199. } catch (PersistenceException e) {
  200. // TODO Auto-generated catch block
  201. e.printStackTrace();
  202. }
  203. return null;
  204. }
  205. @ProduceMime("application/json")
  206. @POST
  207. @Path("/getlei_ZhiBan_Man2")
  208. public String getlei_ZhiBan_Man2(String params) {
  209. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
  210. try {
  211. BgdDutyDao dutyDao = new BgdDutyDao();
  212. return dutyDao.zhiBanName2(deptId);
  213. } catch (PersistenceException e) {
  214. // TODO Auto-generated catch block
  215. e.printStackTrace();
  216. }
  217. return null;
  218. }
  219. @SuppressWarnings("unused")
  220. @POST
  221. @ProduceMime("application/json")
  222. @Path("/delDetailByID/")
  223. public Msg delDetailByID(String params){
  224. Msg msg = new Msg();
  225. log.info(params);
  226. String fd_id = "";
  227. fd_id = Utils.getParameter("fd_objectid", params);
  228. log.info(fd_id);
  229. int result = 0;
  230. if(fd_id!= null && !"".equals(fd_id)){
  231. BgdDutyDao dutyDao = new BgdDutyDao();
  232. if(dutyDao.deleteDetail(fd_id)){
  233. msg.setInfo(Parameter.DELETE_SUCSESS);
  234. msg.setSucsess("true");
  235. }else{
  236. msg.setInfo(Parameter.DELETE_FAILURE);
  237. msg.setSucsess("false");
  238. }
  239. }
  240. return msg;
  241. }
  242. @POST
  243. @ProduceMime("application/json")
  244. @Path("/saveDetail/")
  245. public String saveDetail(String params){
  246. String result = "保存失败";
  247. try {
  248. params = new String(params.getBytes("ISO8859-1"), "UTF-8");
  249. log.info(params);
  250. String[] strs = null;
  251. String jsonStr = "";
  252. String duty_id = "";
  253. String fd_id = "";
  254. EcmDutyDetail detail = null;
  255. if(params!=null&&!"".equals(params)){
  256. strs = params.split("#");
  257. jsonStr = strs[0];
  258. duty_id = strs[1];
  259. fd_id = strs[2];
  260. detail = JsonPluginsUtil.jsonToBean(jsonStr.toLowerCase(), EcmDutyDetail.class);
  261. detail.setDuty_id(duty_id);
  262. BgdDutyDao dutyDao = new BgdDutyDao();
  263. if(fd_id!=null && !"".equals(fd_id)&& !"undefined".equalsIgnoreCase(fd_id)){
  264. detail.setFd_objectid(fd_id);
  265. dutyDao.updateDetail(detail);
  266. }else{
  267. dutyDao.saveDetail(detail);
  268. }
  269. result = "保存成功";
  270. }
  271. } catch (UnsupportedEncodingException e) {
  272. e.printStackTrace();
  273. }
  274. return "{\"result\":"+result+"}";
  275. }
  276. @SuppressWarnings("unchecked")
  277. @POST
  278. @ProduceMime("application/json")
  279. @Path("/queryDetailByDutyId/")
  280. public String queryDetailByDutyId(String params){
  281. log.info(params);
  282. String dutyid = Utils.getParameter("dutyid", params);
  283. if(dutyid!=null && !"".equals(dutyid)&& !"undefined".equalsIgnoreCase(dutyid)){
  284. BgdDutyDao dutyDao = new BgdDutyDao();
  285. List<EcmDutyDetail> detailList = dutyDao.queryDetailByDutyid(dutyid);
  286. log.info(JsonPluginsUtil.beanListToJson(detailList));
  287. log.info(JSONArray.fromObject(detailList).toString());
  288. return " {\"rows\":"+JSONArray.fromObject(detailList).toString() +"}";
  289. }
  290. return "";
  291. }
  292. @POST
  293. @ProduceMime("application/json")
  294. @Path("/saveDuty/")
  295. public Msg saveDuty(String params){
  296. Msg msg = new Msg();
  297. log.info(params);
  298. try {
  299. if(params!=null&&!"".equals(params)&&!"undefined".equalsIgnoreCase(params)){
  300. params = java.net.URLDecoder.decode(params, "utf-8");
  301. System.out.println(params);
  302. String jsonString = params;
  303. List<DutyBean> detailList = new ArrayList<DutyBean>();
  304. if(jsonString!=null&&!"".equals(jsonString)&&!"undefined".equalsIgnoreCase(jsonString)){
  305. detailList = JsonPluginsUtil.jsonToBeanList(jsonString, DutyBean.class);
  306. }
  307. //得到任务id
  308. String task_id = detailList.get(0).getTASK_ID();
  309. System.out.println(jsonString);
  310. BgdDutyDao dutyDao = new BgdDutyDao();
  311. if(dutyDao.saveBgdDutyBatch(detailList)){
  312. dutyDao.update_renwu("1",task_id);
  313. msg.setInfo(Parameter.CREATE_SUCSESS);
  314. msg.setSucsess("true");
  315. System.out.println(msg.getSucsess());
  316. }else{
  317. msg.setInfo(Parameter.DELETE_FAILURE);
  318. msg.setSucsess("false");
  319. }
  320. }
  321. } catch (UnsupportedEncodingException e) {
  322. e.printStackTrace();
  323. }
  324. return msg;
  325. }
  326. @POST
  327. @ProduceMime("application/json")
  328. @Path("/updateBgdDuty/")
  329. public Msg updateBgdDuty(String params){
  330. Msg msg = new Msg();
  331. log.info(params);
  332. try {
  333. if(params!=null&&!"".equals(params)&&!"undefined".equalsIgnoreCase(params)){
  334. params = java.net.URLDecoder.decode(params, "utf-8");
  335. System.out.println(params);
  336. String jsonString = params;
  337. List<DutyBean> detailList = new ArrayList<DutyBean>();
  338. if(jsonString!=null&&!"".equals(jsonString)&&!"undefined".equalsIgnoreCase(jsonString)){
  339. detailList = JsonPluginsUtil.jsonToBeanList(jsonString, DutyBean.class);
  340. }
  341. System.out.println(jsonString);
  342. BgdDutyDao dutyDao = new BgdDutyDao();
  343. if(dutyDao.updateBgdDutyBatch(detailList)){
  344. msg.setInfo(Parameter.CREATE_SUCSESS);
  345. msg.setSucsess("true");
  346. System.out.println(msg.getSucsess());
  347. }else{
  348. msg.setInfo(Parameter.DELETE_FAILURE);
  349. msg.setSucsess("false");
  350. }
  351. }
  352. } catch (UnsupportedEncodingException e) {
  353. e.printStackTrace();
  354. }
  355. return msg;
  356. }
  357. /**
  358. * 根据task_id 查询保供电值班表的信息
  359. * @param params
  360. * @return
  361. */
  362. @SuppressWarnings("unchecked")
  363. @POST
  364. @ProduceMime("application/json")
  365. @Path("/getDutyByTaskId/")
  366. public String getDutyById(String params){
  367. log.info(params);
  368. String result="";
  369. String taskid = Utils.getParameter("taskid", params);
  370. DutyBean duty = null;
  371. if(taskid!=null && !"".equals(taskid)){
  372. BgdDutyDao dutyDao = new BgdDutyDao();
  373. List<DutyBean> datailList = dutyDao.getDutyById(taskid);
  374. result=" {\"rows\":"+JSONArray.fromObject(datailList).toString() +"}";
  375. }
  376. log.info(JsonPluginsUtil.beanToJson(duty));
  377. return result;
  378. }
  379. @POST
  380. @ProduceMime("application/json")
  381. @Path("/updateDuty/")
  382. public Msg updateDuty(String params){
  383. Msg msg = new Msg();
  384. log.info(params);
  385. try {
  386. params = java.net.URLDecoder.decode(params, "UTF-8");
  387. String fd_objectid = Utils.getParameter("fd_objectid", params);
  388. String name = Utils.getParameter("name", params);
  389. String dept_names = Utils.getParameter("dept_names", params);
  390. String oper_name = Utils.getParameter("oper_name", params);
  391. String oper_dept = Utils.getParameter("oper_dept", params);
  392. String oper_time = Utils.getParameter("oper_time", params);
  393. EcmEmDuty duty = new EcmEmDuty();
  394. duty.setFd_objectid(fd_objectid);
  395. duty.setName(name);
  396. duty.setDept_names(dept_names);
  397. duty.setOper_dept(oper_dept);
  398. duty.setOper_name(oper_name);
  399. duty.setOper_time(oper_time);
  400. BgdDutyDao dutyDao = new BgdDutyDao();
  401. if(dutyDao.updateDuty(duty)){
  402. msg.setInfo(Parameter.UPDATE_SUCSESS);
  403. msg.setSucsess("true");
  404. }else{
  405. msg.setInfo(Parameter.UPDATE_FAILURE);
  406. msg.setSucsess("false");
  407. }
  408. } catch (UnsupportedEncodingException e) {
  409. e.printStackTrace();
  410. msg.setInfo(Parameter.UPDATE_FAILURE);
  411. msg.setSucsess("false");
  412. }
  413. return msg;
  414. }
  415. @POST
  416. @ProduceMime("application/json")
  417. @Path("/updateStat/")
  418. public Msg updateStat(String params){
  419. Msg msg = new Msg();
  420. try {
  421. params = java.net.URLDecoder.decode(params, "UTF-8");
  422. String objectIDs = Utils.getParameter("objectIDs", params);
  423. String has_duty = Utils.getParameter("has_duty", params);//任务表中的值班流程
  424. String flow_id = Utils.getParameter("flow_id", params); //值班表的流程id
  425. String rolback_info = Utils.getParameter("rolback_info", params); //值班表的流程id
  426. String reporttime = Utils.getParameter("time", params);
  427. BgdDutyDao dutyDao = new BgdDutyDao();
  428. if(dutyDao.updateStat(objectIDs.split(","),has_duty,flow_id,reporttime,rolback_info)){
  429. msg.setInfo(Parameter.OPER_SUCSESS);
  430. msg.setSucsess("true");
  431. }else{
  432. msg.setInfo(Parameter.OPER_FAILURE);
  433. msg.setSucsess("false");
  434. }
  435. } catch (UnsupportedEncodingException e) {
  436. e.printStackTrace();
  437. msg.setInfo(Parameter.OPER_FAILURE);
  438. msg.setSucsess("false");
  439. }
  440. return msg;
  441. }
  442. @POST
  443. @ProduceMime("application/json")
  444. @Path("/deDutyDetail/")
  445. public String deDutyDetail(String params){
  446. Msg msg=new Msg();
  447. try {
  448. params=new String(params.getBytes("ISO8859-1"),"UTF-8");
  449. } catch (UnsupportedEncodingException e1) {
  450. // TODO Auto-generated catch block
  451. e1.printStackTrace();
  452. }
  453. String taskIDs = Utils.getParameter("ids", params) == null ? "" : Utils .getParameter("ids", params);
  454. System.out.println(taskIDs);
  455. String column_name = Utils.getParameter("column_name", params) == null ? "" : Utils .getParameter("column_name", params);
  456. String column_value = Utils.getParameter("column_value", params) == null ? "" : Utils .getParameter("column_value", params);
  457. String[] IDs=taskIDs.split(",");
  458. BgdDutyDao e=new BgdDutyDao();
  459. if(e.deDutyDetail(IDs,column_name,column_value)){
  460. msg.setInfo(Parameter.UPDATE_SUCSESS);
  461. msg.setSucsess("true");
  462. }else{
  463. msg.setInfo(Parameter.UPDATE_FAILURE);
  464. msg.setSucsess("false");
  465. }
  466. String result = JSONObject.fromObject(msg).toString();
  467. return result;
  468. }
  469. @POST
  470. @ProduceMime("application/json")
  471. @Path("/deleteDutyIds/")
  472. public Msg deleteDutyIds(String params){
  473. Msg msg = new Msg();
  474. String objectIDs = Utils.getParameter("objectIDs", params) == null ? "" : Utils .getParameter("objectIDs", params);
  475. BgdDutyDao dutyDao = new BgdDutyDao();
  476. if(dutyDao.deleteDuty(objectIDs.split(","))){
  477. msg.setInfo(Parameter.DELETE_SUCSESS);
  478. msg.setSucsess("true");
  479. }else{
  480. msg.setInfo(Parameter.DELETE_FAILURE);
  481. msg.setSucsess("false");
  482. }
  483. return msg;
  484. }
  485. // 2015-05-16
  486. @SuppressWarnings("unused")
  487. @POST
  488. @ProduceMime("text/html")
  489. @Path("/importExcel/")
  490. public Msg importExcel(@Context HttpServletRequest request,
  491. @Context HttpServletResponse response) {
  492. Msg msg = new Msg();
  493. UploadManageImpl upload = new UploadManageImpl();
  494. msg =upload.uploadDutyFilePath(request, response);
  495. if(msg.getSucsess()=="false"){
  496. String ret="{success : " + msg.getSucsess() + " , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
  497. return msg;
  498. }
  499. String resultString=msg.getInfo();
  500. System.out.println("resultString++++++++++++++++++++++++++++++"+resultString);
  501. LoginInfo loginInfo = (LoginInfo) request.getSession().getAttribute("loginInfo");
  502. if(resultString!=null&& !"".equals(resultString)){
  503. String[] strs = resultString.split(";");
  504. String flag = strs[0];
  505. String info = strs[1];
  506. String path = strs[2];
  507. System.out.println("path"+path);
  508. if("true".equals(flag)){
  509. EcmDutyExcel doExcel = new EcmDutyExcel();
  510. msg=doExcel.readExcel(path,loginInfo.getReal_name(),loginInfo.getDeptids(),loginInfo.getUser_id());
  511. if(msg.getSucsess().equals("false")){
  512. msg.setInfo("2");
  513. }else{
  514. msg.setSucsess("success");
  515. msg.setInfo("success");
  516. }
  517. }
  518. }
  519. String retString = "{success : '" + msg.getSucsess() + "' , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
  520. return msg ;
  521. }
  522. /**
  523. * 保供电 导入值班功能
  524. * @param request
  525. * @param response
  526. * @return
  527. */
  528. @SuppressWarnings( "unused")
  529. @POST
  530. @ProduceMime("text/html")
  531. @Path("/importExcel_bgd/")
  532. public String importExcel_bgd(@Context HttpServletRequest request,
  533. @Context HttpServletResponse response) {
  534. String task_id=request.getParameter("task_id");
  535. String realName=request.getParameter("realName");
  536. String deptId=request.getParameter("deptId");
  537. try {
  538. realName = java.net.URLDecoder.decode(java.net.URLDecoder.decode(realName, "utf-8"), "utf-8");
  539. } catch (UnsupportedEncodingException e) {
  540. // TODO Auto-generated catch block
  541. e.printStackTrace();
  542. }
  543. //获取任务id
  544. Msg msg = new Msg();
  545. UploadManageImpl upload = new UploadManageImpl();
  546. msg =upload.uploadDutyFilePath(request, response);
  547. if(msg.getSucsess()=="false"){
  548. String ret="{success : " + msg.getSucsess() + " , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
  549. return ret;
  550. }
  551. String resultString=msg.getInfo();
  552. System.out.println("resultString++++++++++++++++++++++++++++++"+resultString);
  553. if(resultString!=null&& !"".equals(resultString)){
  554. String[] strs = resultString.split(";");
  555. String flag = strs[0];//true
  556. String info = strs[1];//success
  557. String path = strs[2];//路径
  558. System.out.println("path"+path);
  559. if("true".equals(flag)){
  560. BgdDutyExcel doExcel = new BgdDutyExcel();
  561. msg=doExcel.readExcel_bgd(path,realName,deptId,task_id);
  562. /*if(msg.getSucsess().equals("false")){
  563. msg.setInfo("3");
  564. }else{
  565. msg.setSucsess("success");
  566. msg.setInfo("success");
  567. }*/
  568. }
  569. }
  570. String retString = "{success : '" + msg.getSucsess() + "' , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
  571. return retString ;
  572. }
  573. /**
  574. * 保供电 导入保供电任务
  575. * @param request
  576. * @param response
  577. * @return
  578. */
  579. @SuppressWarnings( "unused")
  580. @POST
  581. @ProduceMime("text/html")
  582. @Path("/importExcel_task/")
  583. public String importExcel_task(@Context HttpServletRequest request,
  584. @Context HttpServletResponse response) {
  585. String realName=request.getParameter("realName");
  586. String deptId=request.getParameter("deptId");
  587. String deptName=request.getParameter("deptName");
  588. String userId=request.getParameter("userId");
  589. try {
  590. realName = java.net.URLDecoder.decode(java.net.URLDecoder.decode(realName, "utf-8"), "utf-8");
  591. deptName = java.net.URLDecoder.decode(java.net.URLDecoder.decode(deptName, "utf-8"), "utf-8");
  592. } catch (UnsupportedEncodingException e) {
  593. // TODO Auto-generated catch block
  594. e.printStackTrace();
  595. }
  596. //获取任务id
  597. Msg msg = new Msg();
  598. UploadManageImpl upload = new UploadManageImpl();
  599. msg =upload.uploadDutyFilePath(request, response);
  600. if(msg.getSucsess()=="false"){
  601. String ret="{success : " + msg.getSucsess() + " , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
  602. return ret;
  603. }
  604. String resultString=msg.getInfo();
  605. System.out.println("resultString++++++++++++++++++++++++++++++"+resultString);
  606. if(resultString!=null&& !"".equals(resultString)){
  607. String[] strs = resultString.split(";");
  608. String flag = strs[0];//true
  609. String info = strs[1];//success
  610. String path = strs[2];//路径
  611. System.out.println("path"+path);
  612. if("true".equals(flag)){
  613. BgdDutyExcel doExcel = new BgdDutyExcel();
  614. msg=doExcel.readExcel_task(path,realName,deptId,userId,deptName);
  615. }
  616. }
  617. String retString = "{success : '" + msg.getSucsess() + "' , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
  618. return retString ;
  619. }
  620. /**
  621. * 根据 任务表的任务id 查询 保供电值班表的数据进行 导出
  622. * @param params
  623. * @return
  624. * @throws FileNotFoundException
  625. */
  626. @POST
  627. @ProduceMime("text/html")
  628. @Path("/exportAlertExcel/")
  629. public String exportAlertExcel(String params) throws FileNotFoundException{
  630. HttpServletRequest request = mc.getHttpServletRequest();
  631. HttpServletResponse response = mc.getHttpServletResponse();
  632. String filePath = request.getRealPath("excels");
  633. String fileName = UUID.randomUUID().toString()+".xls";
  634. FileOutputStream out = new FileOutputStream(filePath+"/"+fileName);
  635. log.info(filePath+"/"+fileName);
  636. String objectID = Utils.getParameter("objectID", params) == null ? "" : Utils.getParameter("objectID", params);
  637. BgdDutyDao dutyDao = new BgdDutyDao();
  638. DutyBean duty = dutyDao.getDutyBeanById(objectID);
  639. List<DutyBean> list = dutyDao.getDutyById(objectID);
  640. try {
  641. HSSFWorkbook workbook = new HSSFWorkbook();
  642. CellStyle cellStyle=workbook.createCellStyle();
  643. cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
  644. cellStyle.setWrapText(true);//设置自动换行
  645. //加边框
  646. cellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
  647. cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
  648. cellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
  649. cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
  650. cellStyle.setRightBorderColor(HSSFColor.BLACK.index);
  651. cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
  652. cellStyle.setTopBorderColor(HSSFColor.BLACK.index);
  653. cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
  654. //一页
  655. HSSFSheet childSheet = workbook.createSheet();
  656. //设置列宽
  657. childSheet.setColumnWidth(0, 5000);
  658. childSheet.setColumnWidth(1, 5000);
  659. childSheet.setColumnWidth(2, 5000);
  660. childSheet.setColumnWidth(3, 5000);
  661. childSheet.setColumnWidth(4, 5000);
  662. childSheet.setColumnWidth(5, 5000);
  663. childSheet.setColumnWidth(6, 5000);
  664. childSheet.setColumnWidth(7, 5000);
  665. // 起始行 // 结束行 // 其实列 // 结束列
  666. // CellRangeAddress region1 = new CellRangeAddress(0,0,0,7); //CellRangeAddress
  667. childSheet.addMergedRegion(new Region(0, (short)0, 0,(short)7));
  668. CellStyle cellStyle1=workbook.createCellStyle();
  669. cellStyle1.setWrapText(true); //换行
  670. HSSFRow row0 = childSheet.createRow(0);
  671. row0.setHeight((short)1000);
  672. HSSFCell cell00 = row0.createCell(0);
  673. cell00.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  674. cell00.setCellValue("填报说明:1、开始时间、结束时间:请按yyyy-MM-dd HH:mm:ss时间格式输入,如2015-10-24 18:30;2、值班领导、值班成员:请输入值班人姓名;3、领导电话、联系电话:分别输入值班领导的电话和值班成员的电话;4、值班方式:请选择在岗值班、电话值班、应急指挥中心值班;");
  675. cell00.setCellStyle(cellStyle1);
  676. HSSFRow row1 = childSheet.createRow(1);
  677. childSheet.addMergedRegion(new Region(1, (short)0, 1,(short)7));
  678. HSSFCell cell10 = childSheet.createRow(1).createCell(0);
  679. cell10.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  680. cell10.setCellValue("保供电值班安排表");
  681. cell10.setCellStyle(cellStyle);
  682. HSSFRow row2 = childSheet.createRow(2);
  683. HSSFCell cell20 = row2.createCell(0);
  684. cell20.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  685. cell20.setCellValue("开始时间");
  686. HSSFCell cell21 = row2.createCell(1);
  687. cell21.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  688. cell21.setCellValue("结束时间");
  689. HSSFCell cell22 = row2.createCell(2);
  690. cell22.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  691. cell22.setCellValue("值班领导");
  692. HSSFCell cell23 = row2.createCell(3);
  693. cell23.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  694. cell23.setCellValue("领导电话");
  695. HSSFCell cell24 = row2.createCell(4);
  696. cell24.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  697. cell24.setCellValue("值班方式");
  698. HSSFCell cell25 = row2.createCell(5);
  699. cell25.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  700. cell25.setCellValue("值班成员");
  701. HSSFCell cell26 = row2.createCell(6);
  702. cell26.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  703. cell26.setCellValue("联系电话");
  704. HSSFCell cell27 = row2.createCell(7);
  705. cell27.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
  706. cell27.setCellValue("值班方式");
  707. System.out.println("list.size()++++++++++++++++++++++++++++++++++++++++++++++++++++++"+list.size());
  708. int listSize=list.size();
  709. for (int r = 3 ; r < list.size()+3; r++) {// 循环该 子sheet row
  710. DutyBean detail = list.get(listSize+2-r);
  711. HSSFRow rows = childSheet.createRow(r);
  712. HSSFCell cell0 = rows.createCell(0);
  713. cell0.setCellType(Cell.CELL_TYPE_STRING);
  714. cell0.setCellValue(detail.getSTART_TIME());
  715. HSSFCell cell1 = rows.createCell(1);
  716. cell1.setCellType(Cell.CELL_TYPE_STRING);
  717. cell1.setCellValue(detail.getEND_TIME());
  718. HSSFCell cell2 = rows.createCell(2);
  719. cell2.setCellType(Cell.CELL_TYPE_STRING);
  720. cell2.setCellValue(detail.getLEADER());
  721. HSSFCell cell3 = rows.createCell(3);
  722. cell3.setCellType(Cell.CELL_TYPE_STRING);
  723. cell3.setCellValue(detail.getLEADER_TEL());
  724. HSSFCell cell4 = rows.createCell(4);
  725. cell4.setCellType(Cell.CELL_TYPE_STRING);
  726. String modeway = detail.getLEADER_DUTY_MODE();
  727. // cell4.setCellValue(detail.getLEADER_DUTY_MODE());
  728. String wayVal1 = "在岗值班";
  729. if(modeway!=null&&"0".equals(modeway)){
  730. wayVal1 = "在岗值班";
  731. }
  732. if(modeway!=null&&"1".equals(modeway)){
  733. wayVal1 = "电话值班";
  734. }
  735. if(modeway!=null&&"2".equals(modeway)){
  736. wayVal1 = "应急指挥中心值班";
  737. }
  738. cell4.setCellValue(wayVal1);
  739. HSSFCell cell5 = rows.createCell(5);
  740. cell5.setCellType(Cell.CELL_TYPE_STRING);
  741. cell5.setCellValue(detail.getWATCH_MAN());
  742. HSSFCell cell6 = rows.createCell(6);
  743. cell6.setCellType(Cell.CELL_TYPE_STRING);
  744. cell6.setCellValue(detail.getWATCH_TEL());
  745. HSSFCell cell7 = rows.createCell(7);
  746. cell7.setCellType(Cell.CELL_TYPE_STRING);
  747. String dutyWay = detail.getDUTY_MODE();
  748. String wayVal = "在岗值班";
  749. if(dutyWay!=null&&"0".equals(dutyWay)){
  750. wayVal = "在岗值班";
  751. }
  752. if(dutyWay!=null&&"1".equals(dutyWay)){
  753. wayVal = "电话值班";
  754. }
  755. if(dutyWay!=null&&"2".equals(dutyWay)){
  756. wayVal = "应急指挥中心值班";
  757. }
  758. cell7.setCellValue(wayVal);
  759. }
  760. workbook.write(out);
  761. out.close();
  762. } catch (IOException e) {
  763. // TODO Auto-generated catch block
  764. e.printStackTrace();
  765. }
  766. log.info(fileName);
  767. return fileName;
  768. }
  769. @SuppressWarnings({ "static-access", "deprecation" })
  770. @ProduceMime("application/json")
  771. @POST
  772. @Path("/CreateToExcel")
  773. public String CreateToExcel(String params) {
  774. log.info("params:" + params);
  775. AssistantAble assistant = new AssistantImpl();
  776. String classID = Utils.getParameter("classId", params);
  777. String listId = Utils.getParameter("listId", params);
  778. String queryField = Utils.getParameter("queryField", params);
  779. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listId);
  780. String condition = assistant.getSQLCondition(params, formList);
  781. log.info("queryField:" + queryField);
  782. log.info("condition:" + condition);
  783. queryField = queryField.substring(0, queryField.lastIndexOf(","));
  784. String[] queryFields = queryField.split(",");
  785. int ClassId = Integer.parseInt(classID);
  786. SysModel sysmodel = ModelFactory.getSysmodel();
  787. MdpClass mdpClass = sysmodel.getMdpClassByClassID(ClassId);
  788. // 获取表名称
  789. String tableName = mdpClass.getName();
  790. // 获取表的描述信息
  791. String description = mdpClass.getDescription();
  792. // 获取各个字段的名称
  793. List<MdpAttributeImpl> list = mdpClass.getAllMdpAttributes();
  794. Map<String,MdpAttributeImpl> map = new HashMap<String, MdpAttributeImpl>();
  795. for(MdpAttributeImpl mdp : list){
  796. map.put(mdp.getName().toUpperCase(), mdp);
  797. }
  798. Workbook wb = null;
  799. WritableWorkbook book = null;
  800. WritableSheet sheet = null;
  801. HttpServletRequest req =mc.getHttpServletRequest();
  802. String fileName = "";
  803. String filePath = req.getRealPath("excels");
  804. try {
  805. fileName =UUID.randomUUID().toString()+".xls";
  806. File myFilePath = new File( filePath+"/"+fileName);
  807. // 1.首先定义个workbook
  808. book = wb.createWorkbook(myFilePath);
  809. // 2.定义个sheet
  810. sheet = book.createSheet("第一页", 0);
  811. // 设置标题
  812. sheet.mergeCells(0, 0, queryFields.length - 1, 0);
  813. // 插入数据.
  814. book.write();
  815. book.close();
  816. } catch (Exception e) {
  817. e.printStackTrace();
  818. }
  819. return fileName;
  820. }
  821. private void download(String path, HttpServletResponse response) {
  822. try {
  823. // path是指欲下载的文件的路径。
  824. File file = new File(path);
  825. // 取得文件名。
  826. String filename = file.getName();
  827. // 以流的形式下载文件。
  828. InputStream fis = new BufferedInputStream(new FileInputStream(path));
  829. byte[] buffer = new byte[fis.available()];
  830. fis.read(buffer);
  831. fis.close();
  832. // 清空response
  833. response.reset();
  834. // 设置response的Header
  835. response.addHeader("Content-Disposition", "attachment;filename="
  836. + new String(filename.getBytes()));
  837. response.addHeader("Content-Length", "" + file.length());
  838. OutputStream toClient = new BufferedOutputStream(
  839. response.getOutputStream());
  840. response.setContentType("application/vnd.ms-excel;charset=gb2312");
  841. toClient.write(buffer);
  842. toClient.flush();
  843. toClient.close();
  844. } catch (IOException ex) {
  845. ex.printStackTrace();
  846. }
  847. }
  848. public org.apache.cxf.jaxrs.ext.MessageContext getMc() {
  849. return mc;
  850. }
  851. public void setMc(org.apache.cxf.jaxrs.ext.MessageContext mc) {
  852. this.mc = mc;
  853. }
  854. @POST
  855. @ProduceMime("application/json")
  856. @Path("/getMyInfo")
  857. public String getMyInfo(String param) {
  858. BgdDutyDao bdDao = new BgdDutyDao();
  859. return bdDao.getParameters(param) ;//保供电值班安排表---发布后的短信用到
  860. }
  861. @POST
  862. @ProduceMime("application/json")
  863. @Path("/getNameTel")
  864. public String getNameTel(String param) {
  865. String[] tempParam = param.split(",");
  866. String compId = "";
  867. String param1 = "";
  868. if(tempParam.length>0){
  869. for(int i=0; i<tempParam.length; i++){
  870. compId+= "'" + tempParam[i] + "'" + ",";
  871. }
  872. }
  873. if(compId.endsWith(",")){
  874. param1 = compId.substring(0,compId.length()-1);
  875. }
  876. String result="";
  877. //String data= Utils.getParameter("data", param);
  878. BgdDutyDao bdDao = new BgdDutyDao();
  879. result = bdDao.getsenMsg(param1);
  880. log.info("result===" + result);
  881. return result;
  882. }
  883. @POST
  884. @ProduceMime("application/json")
  885. @Path("/getNameTel1")
  886. public String getNameTel1(String param) {
  887. String[] tempParam = param.split(",");
  888. String compId = "";
  889. String param1 = "";
  890. if(tempParam.length>0){
  891. for(int i=0; i<tempParam.length; i++){
  892. compId+= "'" + tempParam[i] + "'" + ",";
  893. }
  894. }
  895. param1 = compId.substring(0,compId.length()-1);
  896. String result="";
  897. //String data= Utils.getParameter("data", param);
  898. BgdDutyDao bdDao = new BgdDutyDao();
  899. result = bdDao.getsenMsg1(param1);
  900. log.info("result===" + result);
  901. return result;
  902. }
  903. @POST
  904. @ProduceMime("application/json")
  905. @Path("/getTaskInfos")
  906. public String getTaskInfos(String param) {
  907. BgdDutyDao bdDao = new BgdDutyDao();
  908. return bdDao.getUsersTel(param);//保供电任务---发布后的短信用到
  909. }
  910. /**
  911. * 删除任务
  912. *
  913. * @param params
  914. * 表单参数信息
  915. * @return
  916. * @throws PersistenceException
  917. * @throws TransformTypeException
  918. */
  919. @POST
  920. @ProduceMime("application/json")
  921. @Path("/deleteTask/")
  922. public Msg deleteTask(String params) throws PersistenceException {
  923. BgdDutyDao bdDao = new BgdDutyDao();
  924. String objectIDs = Utils.getParameter("objectIDs", params) == null ? "" : Utils
  925. .getParameter("objectIDs", params);
  926. Msg msg = new Msg();
  927. try {
  928. msg = bdDao.deleteTask(objectIDs.split(","));
  929. return msg;
  930. } catch (Exception e) {
  931. e.printStackTrace();
  932. }
  933. return msg;
  934. }
  935. }