65c834b0834f834510d84b9a728f72127e17f1a0.svn-base 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. package com.sinosoft.am.duty.records.service;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.io.UnsupportedEncodingException;
  6. import java.text.DateFormat;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.Iterator;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.Vector;
  15. import java.util.regex.Matcher;
  16. import java.util.regex.Pattern;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import javax.ws.rs.POST;
  20. import javax.ws.rs.Path;
  21. import javax.ws.rs.ProduceMime;
  22. import javax.ws.rs.core.Context;
  23. import net.sf.json.JSONObject;
  24. import org.apache.log4j.Logger;
  25. import org.apache.poi.hssf.usermodel.HSSFCell;
  26. import org.apache.poi.hssf.usermodel.HSSFDateUtil;
  27. import org.apache.poi.hssf.usermodel.HSSFRow;
  28. import org.apache.poi.hssf.usermodel.HSSFSheet;
  29. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  30. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  31. import org.apache.poi.ss.usermodel.Cell;
  32. import org.apache.poi.ss.usermodel.DateUtil;
  33. import org.apache.poi.xssf.usermodel.XSSFCell;
  34. import org.apache.poi.xssf.usermodel.XSSFRow;
  35. import org.apache.poi.xssf.usermodel.XSSFSheet;
  36. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  37. import com.sinosoft.am.duty.records.dao.DutyTaskDao;
  38. import com.formaction.Utils;
  39. import com.formaction.vo.Msg;
  40. import com.persistence.service.assitant.generator.IdentityGenerator;
  41. import com.sinosoft.am.duty.records.vo.EcmDutyDetail1;
  42. import com.sinosoft.common.upLoad.service.UploadManageImpl;
  43. import com.sinosoft.em.gps.dao.BaoGongDianTaskDao;
  44. import com.sinosoft.lz.system.util.JsonUtil;
  45. @Path("/DutyImport/")
  46. public class DutyImport {
  47. @Context
  48. private org.apache.cxf.jaxrs.ext.MessageContext mc;
  49. private final Logger log = Logger.getLogger(getClass());
  50. @ProduceMime("text/html")
  51. @POST
  52. @Path("/importdutytask")
  53. public String importdutytask(@Context HttpServletRequest request,
  54. @Context HttpServletResponse response) throws Exception{//新增保存
  55. Msg m=new Msg();
  56. UploadManageImpl upload2 = new UploadManageImpl();
  57. String path = upload2.uploadFilePath(request, response);
  58. String result="";
  59. log.info("saveFile.path===="+path);
  60. if("success".equals(path.split(";")[1])){
  61. //将数据返回到界面
  62. path=path.split(";")[2];
  63. String report_type=request.getParameter("report_type");
  64. result=readExcelByName(path,report_type);
  65. }else{
  66. //返回失败信息
  67. result="";
  68. }
  69. //result = java.net.URLEncoder.encode(result,"UTF-8");
  70. //result = new String(result.getBytes("iso8859-1"),"UTF-8");
  71. //result = java.net.URLDecoder.decode(new String(result.getBytes("iso8859-1"),"UTF-8"));
  72. //result = new String(java.net.URLEncoder.encode(result, "UTF-8").getBytes(), "ISO-8859-1");
  73. return result;
  74. }
  75. /**
  76. * 保存表格编辑后的数据
  77. * @param params
  78. * @return
  79. * @throws ClassNotFoundException
  80. */
  81. @ProduceMime("application/json")
  82. @POST
  83. @Path("/saveGridData")
  84. public Msg saveUser(String params) throws ClassNotFoundException{//保存数据
  85. Msg m=new Msg();
  86. String json=Utils.getParameter("json", params)==null?"":Utils.getParameter("json", params);
  87. //String user_id=Utils.getParameter("user_id", params)==null?"":Utils.getParameter("user_id", params);
  88. String report_type=Utils.getParameter("report_type", params)==null?"":Utils.getParameter("report_type", params);
  89. String comp_id=Utils.getParameter("comp_id", params)==null?"":Utils.getParameter("comp_id", params);//预警编号
  90. String real_name=Utils.getParameter("real_name", params)==null?"":Utils.getParameter("real_name", params);
  91. String task_id=Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);
  92. String user_id=Utils.getParameter("user_id", params)==null?"":Utils.getParameter("user_id", params);
  93. BaoGongDianTaskDao bgdd = new BaoGongDianTaskDao();
  94. if("1".equals(report_type)){
  95. m=bgdd.saveUser(json/*,user_id*/,real_name/*,report_type*/,comp_id,task_id);
  96. }else if("2".equals(report_type)){
  97. m=bgdd.saveBaoBiao(json/*,user_id*/,real_name/*,report_type*/,comp_id,task_id);
  98. }else if("3".equals(report_type)){
  99. m=bgdd.saveDuty(json/*,user_id*/,real_name/*,report_type*/,comp_id,task_id,user_id);
  100. }
  101. return m;
  102. }
  103. /**
  104. * 通过type查询某任务的值班信息:只看本单位、按单位查看、按日期查看
  105. * @param params
  106. * @return
  107. * @throws ClassNotFoundException
  108. */
  109. @ProduceMime("application/json")
  110. @POST
  111. @Path("/quiTaskDutyByType")
  112. public String quiTaskDutyByType(String params) throws ClassNotFoundException{
  113. String result = "";
  114. String type=Utils.getParameter("type", params)==null?"":Utils.getParameter("type", params);
  115. String dept=Utils.getParameter("dept", params)==null?"":Utils.getParameter("dept", params);//预警编号
  116. String task_id=Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);
  117. BaoGongDianTaskDao bgdd = new BaoGongDianTaskDao();
  118. result=bgdd.quiTaskDutyByType(type,dept,task_id);
  119. return result;
  120. }
  121. /**
  122. * 保存附件时,先获取一个fd_id
  123. * @param params
  124. * @return
  125. * @throws ClassNotFoundException
  126. */
  127. /* @ProduceMime("application/json")*/
  128. @POST
  129. @Path("/getMainId")
  130. public String getMainId(){//保存数据
  131. String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(614);
  132. fd_id += "a";
  133. return fd_id;
  134. }
  135. public String readExcelByName(String fileName,String report_type) throws Exception {
  136. int i=fileName.lastIndexOf(".");
  137. String type=fileName.substring(i+1);
  138. log.info("fileName===="+fileName);
  139. String result="";
  140. if("xls".equals(type)){
  141. result=readExcel(fileName,report_type);
  142. }else if("xlsx".equals(type)){
  143. result= readExcel2007(fileName,report_type);
  144. }
  145. result="{\"rows\":"+result+"}";
  146. log.info(result);
  147. return result;
  148. }
  149. public String readExcel( String filePath,String report_type)
  150. throws Exception {
  151. String result="";
  152. try {
  153. POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( filePath));
  154. // 创建工作簿
  155. HSSFWorkbook workBook = new HSSFWorkbook(fs);
  156. log.info(workBook.getNumberOfSheets());
  157. SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
  158. // System.out.println("工作表个数 :" + workBook.getNumberOfSheets());
  159. for (int i = 0; i < workBook.getNumberOfSheets(); i++) {
  160. // 创建工作表
  161. HSSFSheet sheet = workBook.getSheetAt(i);
  162. /**************验证表头****************/
  163. if("3".equals(report_type) && i==0){//保供电值班获得第三行的数据,验证表头
  164. HSSFRow row1 = sheet.getRow(1);
  165. StringBuffer sb1=new StringBuffer();
  166. int cells = row1.getLastCellNum();
  167. for (short c = 0; c < cells; c++) { // 列循环
  168. HSSFCell cell = row1.getCell(c);
  169. String value = getValue(cell);
  170. sb1.append(value+"|");
  171. }
  172. String[] arr1=sb1.toString().split("[|]");
  173. checkTableHeader(arr1,report_type);
  174. }
  175. /**************验证表头****************/
  176. int rows = sheet.getPhysicalNumberOfRows(); // 获得行数
  177. if (rows > 0) {
  178. sheet.getMargin(HSSFSheet.TopMargin);
  179. List list=new ArrayList();
  180. contiFor:for (int r = 2; r < rows; r++) { // 行循环
  181. //boolean flag=false;
  182. HSSFRow row = sheet.getRow(r);
  183. if (row != null && r != 0 && r != 1) {// 不取第一行、第二行
  184. int cells = row.getLastCellNum();// 获得列数
  185. // 定义集合datas用于存Excel中一个行的数据
  186. Vector datas = new Vector();
  187. if(cells==-1 || cells==0){
  188. continue;
  189. }
  190. String[]arr=new String[cells];
  191. List<String>paramList=new ArrayList<String>();
  192. //判断一行数据是否全部为空。lj
  193. //记录一行数据单元格内容空的个数
  194. int num = 0;
  195. for (short c = 0; c < cells; c++) { // 列循环
  196. HSSFCell cell = row.getCell(c);
  197. if (cell != null) {
  198. String value = getValue(cell);
  199. if("".equals(value)){
  200. num++;
  201. if(num==cells){//处置值班,如果单元格空的个数和列数一样则跳过该行
  202. continue contiFor;
  203. }
  204. }
  205. //对导入的数据进行正则验证:
  206. // checkDataType(0,value);
  207. // System.out.println("第" + r + "行 " + "第" + c + "列:" + value);
  208. datas.add(value);
  209. paramList.add(value);
  210. arr[c]=value;
  211. }
  212. }
  213. list.add(arr);
  214. // dataIntoDb(tableName, paramList);
  215. // 向表中插入数据
  216. // DBFactory.insertData(dbConn, tableName, datas);
  217. }
  218. }
  219. result = fillMap(list,report_type);
  220. }
  221. }
  222. } catch (Exception ex) {
  223. ex.printStackTrace();
  224. log.info(ex);
  225. throw ex;
  226. }
  227. return result;
  228. }
  229. /***
  230. * 验证数据类型是否符合正则
  231. * 0:时间格式2016-03-10 11:11年月日时分
  232. * 1:手机号码
  233. * 2:人名(中文汉字或英文?)
  234. 、 * @param i
  235. * @param value
  236. */
  237. private boolean checkDataType(int i, String value) {
  238. String el = "";
  239. if(i==0){//0:验证 时间格式2016-03-10 11:11年月日时分
  240. el = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])"
  241. + "|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|"
  242. + "([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))"
  243. + "[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))"
  244. + "|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))\\s{1}[0-5]{1}[0-9]{1}\\:[0-5]{1}[0-9]{1}$";
  245. }else if(i==1){//1:手机号码
  246. el = "^[1]{1}[0-9]{10}$";
  247. }else if(i==2){//2:人名(中文汉字或英文)
  248. el = "^[A-Za-z\u4e00-\u9fa5]+$";
  249. }
  250. Pattern pat = Pattern.compile(el);
  251. Matcher mat = pat.matcher(value);
  252. boolean dataType = mat.matches();
  253. return dataType;
  254. }
  255. /* public static void main(String[] args) {
  256. String date = "2014-02-28 11:11";
  257. String dat1 = "11111111111";
  258. BaoGongDianTaskService bg = new BaoGongDianTaskService();
  259. System.out.println(bg.checkDataType(0, date));
  260. System.out.println(bg.checkDataType(1, dat1));
  261. }*/
  262. /***
  263. * 检查表头是否符合模版:保供电用户,报表,值班
  264. * @param arr1
  265. * @throws Exception
  266. */
  267. private void checkTableHeader(String[] arr1,String report_type) throws Exception {
  268. if(arr1==null || arr1.length!=6){
  269. throw new Exception("导入文件有误,解析失败!");
  270. }else{
  271. if(!"值班时间".equals(arr1[0]) || !"值班领导".equals(arr1[1]) || !"领导电话".equals(arr1[2])
  272. || !"值班成员".equals(arr1[3]) || !"成员电话".equals(arr1[4])|| !"值班方式".equals(arr1[5])) {
  273. throw new Exception("导入Excel文件与模版不匹配!");
  274. }
  275. }
  276. }
  277. /**8
  278. * 获取Excel中某个单元格的值
  279. *
  280. * @param cell
  281. * @return
  282. * @throws Exception
  283. */
  284. public String getValue(HSSFCell cell) throws Exception {
  285. String value = "";
  286. String value1 = "";
  287. switch (cell.getCellType()) {
  288. case HSSFCell.CELL_TYPE_NUMERIC: // 数值型
  289. System.out.println("数字类型");
  290. // if (HSSFDateUtil.isCellDateFormatted(cell)) {
  291. // // 如果是date类型则 ,获取该cell的date值
  292. // value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue())
  293. // .toString();
  294. // java.util.Date date1 = new Date(value);
  295. // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  296. // value = format.format(date1);
  297. // } else
  298. {// 纯数字
  299. //转换成文本格式
  300. cell.setCellType(Cell.CELL_TYPE_STRING);
  301. value = cell.getStringCellValue();
  302. }
  303. break;
  304. /* 此行表示单元格的内容为string类型 */
  305. case HSSFCell.CELL_TYPE_STRING: // 字符串型
  306. value = cell.getStringCellValue();
  307. break;
  308. case HSSFCell.CELL_TYPE_FORMULA:// 公式型
  309. // 读公式计算值
  310. value = String.valueOf(cell.getNumericCellValue());
  311. if (value.equals("NaN")) {// 如果获取的数据值为非法值,则转换为获取字符串
  312. value = cell.getStringCellValue().toString();
  313. }
  314. cell.getCellFormula();
  315. break;
  316. case HSSFCell.CELL_TYPE_BOOLEAN:// 布尔
  317. value = " " + cell.getBooleanCellValue();
  318. break;
  319. /* 此行表示该单元格值为空 */
  320. case HSSFCell.CELL_TYPE_BLANK: // 空值
  321. value = "";
  322. break;
  323. case HSSFCell.CELL_TYPE_ERROR: // 故障
  324. value = "";
  325. break;
  326. default:
  327. value = cell.getStringCellValue().toString();
  328. }
  329. if(checkValueTrim(value)){
  330. return "";
  331. }
  332. return value;
  333. }
  334. private boolean checkValueTrim(String value) {
  335. boolean flagg = false;
  336. if("".equals(value.trim())){
  337. flagg = true;
  338. }
  339. return flagg;
  340. }
  341. /**
  342. * 將数据转换成json
  343. * @param list
  344. * @return
  345. * @throws Exception
  346. */
  347. public String fillMap(List<String[]> list,String report_type) throws Exception{
  348. List<Map<String, String>>dataList=new ArrayList<Map<String,String>>();
  349. for(int i=0;i<list.size();i++){//保供电值班
  350. Map<String, String>tempMap=new HashMap<String, String>();
  351. String[]arr=list.get(i);
  352. if(arr==null || arr.length!=6){
  353. throw new Exception("导入文件有误,解析失败!");
  354. }else{
  355. tempMap.put("end_time", arr[0]);
  356. //tempMap.put("end_time", arr[1]);
  357. tempMap.put("leader", ecodeStr(arr[1]));
  358. tempMap.put("leader_tel", arr[2].replace("\n", ""));
  359. tempMap.put("administration_duty",ecodeStr(arr[3]));
  360. tempMap.put("administration_duty_tel",arr[4].replace("\n", ""));
  361. /*tempMap.put("everyday_duty",ecodeStr(arr[6]));
  362. tempMap.put("everyday_duty_tel",arr[7].replace("\n", ""));*/
  363. tempMap.put("duty_way",getDutyModelForType(arr[5]));
  364. dataList.add(tempMap);
  365. }
  366. }
  367. System.out.println(JsonUtil.list2json(dataList));
  368. String result=JsonUtil.list2json(dataList);
  369. return result;
  370. }
  371. /**
  372. * 将中文字符串编码,若为空,则返回原值
  373. * @param str
  374. * @return
  375. * @throws Exception
  376. */
  377. private String ecodeStr(String str) throws Exception {
  378. str = str==null||"".equals(str.trim())||"null".equals(str.trim())?"":new String(java.net.URLEncoder.encode( str, "UTF-8").getBytes(), "ISO-8859-1") ;
  379. return str;
  380. }
  381. private String getDutyModelForType(String str) throws UnsupportedEncodingException {
  382. String type = "";
  383. if("在岗值班".equals(str)){
  384. type = "0";
  385. }else if("电话值班".equals(str)){
  386. type = "1";
  387. }else if("应急指挥中心值班".equals(str)){
  388. type = "2";
  389. }else{
  390. type = new String(java.net.URLEncoder.encode(str, "UTF-8").getBytes(), "ISO-8859-1");
  391. }
  392. return type;
  393. }
  394. @SuppressWarnings({ "rawtypes", "unused", "resource", "unchecked" })
  395. public String readExcel2007( String filePath, String report_type)
  396. throws Exception {
  397. String result="";
  398. try {
  399. // InputStream inp = new FileInputStream(filePath);
  400. // Workbook wb = WorkbookFactory.create(inp);
  401. XSSFWorkbook wb = new XSSFWorkbook(filePath);
  402. int sheetSize = wb.getNumberOfSheets();
  403. // for (int i = 0; i < sheetSize; i++) {
  404. List list=new ArrayList();
  405. XSSFSheet sheet = wb.getSheetAt(0);
  406. // Sheet sheet = wb.getSheetAt(i);
  407. /**************验证表头****************/
  408. XSSFRow row1 = sheet.getRow(0);
  409. Vector datas1 = new Vector();
  410. StringBuffer sb1=new StringBuffer();
  411. for (Iterator cit = row1.cellIterator(); cit.hasNext();) {
  412. // 定义集合datas用于存Excel中一个行的数据
  413. XSSFCell cell = (XSSFCell) cit.next();
  414. String value = getValue2007(cell);
  415. sb1.append(value+"|");
  416. // 注意行和列是基于0索引的
  417. // System.out.print(cell.getRowIndex() + ":" + cell.getColumnIndex() + " ");
  418. datas1.add(value);
  419. // System.out.println();
  420. // 开始操作单元格
  421. }
  422. String[] arr1=sb1.toString().split("[|]");
  423. checkTableHeader(arr1,report_type);
  424. /**************验证表头****************/
  425. int lastRow = sheet.getLastRowNum();
  426. for (int i=1;i<=lastRow;i++) {//从第二行开始
  427. // 迭代行
  428. // XSSFRow row = (XSSFRow) rit.next();
  429. XSSFRow row = sheet.getRow(i);
  430. // 迭代单元格
  431. Vector datas = new Vector();
  432. StringBuffer sb=new StringBuffer();
  433. Map<String, String>lineMap=new HashMap<String, String>();
  434. for (Iterator cit = row.cellIterator(); cit.hasNext();) {
  435. // 定义集合datas用于存Excel中一个行的数据
  436. XSSFCell cell = (XSSFCell) cit.next();
  437. String value = getValue2007(cell);
  438. sb.append(value+"|");
  439. // 注意行和列是基于0索引的
  440. // System.out.print(cell.getRowIndex() + ":" + cell.getColumnIndex() + " ");
  441. datas.add(value);
  442. // System.out.println();
  443. // 开始操作单元格
  444. }
  445. String[] arr=sb.toString().split("[|]");
  446. list.add(arr);
  447. // result = fillMap(list);;
  448. // 向表中插入数据
  449. // DBFactory.insertData(dbConn, tableName, datas);
  450. }
  451. result = fillMap(list,report_type);
  452. System.out.println(result);
  453. // }
  454. } catch (FileNotFoundException e) {
  455. e.printStackTrace();
  456. throw e;
  457. } catch (IOException e) {
  458. e.printStackTrace();
  459. throw e;
  460. }
  461. return result;
  462. }
  463. public String getValue2007(XSSFCell cell) {
  464. String value = "";
  465. switch (cell.getCellType()) {
  466. case Cell.CELL_TYPE_STRING:
  467. // System.out.println(cell.getRichStringCellValue().getString());
  468. value=cell.getRichStringCellValue().getString();
  469. break;
  470. case Cell.CELL_TYPE_NUMERIC:
  471. if (DateUtil.isCellDateFormatted(cell)) {
  472. // System.out.println(cell.getDateCellValue());
  473. java.util.Date date = cell.getDateCellValue();
  474. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  475. value = format.format(date);
  476. } else {
  477. // System.out.println(cell.getNumericCellValue());
  478. value = String.valueOf((cell.getNumericCellValue()+"").split("[.]")[0]);
  479. }
  480. break;
  481. case Cell.CELL_TYPE_BOOLEAN:
  482. // System.out.println(cell.getBooleanCellValue());
  483. value = " " + cell.getBooleanCellValue();
  484. break;
  485. case Cell.CELL_TYPE_FORMULA:
  486. // System.out.println(cell.getCellFormula());
  487. value = cell.getCellFormula();
  488. break;
  489. default:
  490. System.out.println();
  491. }
  492. log.info(value);
  493. if(checkValueTrim(value)){
  494. return "";
  495. }
  496. return value;
  497. }
  498. @POST
  499. @ProduceMime("application/json")
  500. @Path("/saveGpsDuty/")
  501. public String saveGpsDuty(String params){
  502. String result = "保存失败";
  503. try {
  504. // params = java.net.URLDecoder.decode(params, "UTF-8");
  505. params = new String(params.getBytes("ISO8859-1"), "UTF-8");
  506. log.info(params);
  507. String[] strs = null;
  508. EcmDutyDetail1 detail = new EcmDutyDetail1();
  509. DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  510. Date date=new Date();
  511. if(params!=null&&!"".equals(params)){
  512. strs = params.split("&");
  513. //系统当前时间
  514. String time=format.format(date);
  515. // detail.setupdatedate(time);
  516. detail.setFd_objectid(strs[0]);
  517. detail.setStart_time(strs[1]);
  518. detail.setEnd_time(strs[2]);
  519. detail.setLeader(strs[3]);
  520. detail.setLeader_tel(strs[4]);
  521. detail.setName(strs[5]);
  522. detail.setDuty_way(strs[6]);
  523. DutyTaskDao DutyDao = new DutyTaskDao();
  524. DutyDao.saveDuty(detail);
  525. result = "保存成功";
  526. }
  527. } catch (UnsupportedEncodingException e) {
  528. e.printStackTrace();
  529. }
  530. //return fD_OBJECTID;
  531. return "{'result':"+result+"}";
  532. }
  533. /**
  534. * 根据部门范围id及当前用户部门id查询相应的组织机构数据,及当前部门id的直属子部门的数据
  535. * @param params
  536. * @return
  537. * @throws ClassNotFoundException
  538. */
  539. @ProduceMime("application/json")
  540. @POST
  541. @Path("/getOrgInfoByareaIdAndUnitId")
  542. public String getOrgInfoById(String params) throws ClassNotFoundException{
  543. String fd_id = Utils.getParameter("fd_id", params) == null ? "" : Utils.getParameter(
  544. "fd_id", params);
  545. String unitId = Utils.getParameter("unitId", params) == null ? "" : Utils.getParameter(
  546. "unitId", params);
  547. BaoGongDianTaskDao dao = new BaoGongDianTaskDao();
  548. String areaId = dao.getAreaId(fd_id);
  549. StringBuffer areaIdsArr = stringIdsToStringBuff(areaId);
  550. String result = dao.getdeptTreeById(areaId,areaIdsArr,unitId);
  551. return result;
  552. }
  553. /*
  554. * 字符串类型ids截出转化为"('','','')"
  555. */
  556. private StringBuffer stringIdsToStringBuff(String areaId) {
  557. StringBuffer strbuff = new StringBuffer();
  558. if(areaId != ""){
  559. String[] array = areaId.split(",");
  560. strbuff.append("(");
  561. for (int i = 0; i < array.length; i++) {
  562. strbuff.append("'"+array[i]+"'");
  563. if(i!=array.length-1){
  564. strbuff.append(",");
  565. }
  566. }
  567. strbuff.append(")");
  568. }
  569. return strbuff;
  570. }
  571. @ProduceMime("application/json")
  572. @POST
  573. @Path("/getDeptMsgByTaskId")
  574. public String getDeptMsgByTaskId(String params) throws ClassNotFoundException{
  575. String TaskId = Utils.getParameter("TaskId", params) == null ? "" : Utils.getParameter(
  576. "TaskId", params);
  577. BaoGongDianTaskDao dao = new BaoGongDianTaskDao();
  578. List<Map<String, String>> list = dao.getDeptMsgByTaskId(TaskId);
  579. String result = JsonUtil.list2json(list);
  580. return result;
  581. }
  582. }