734942af89dab8693ea8fd24d6e382da4e28686c.svn-base 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. package com.kingdee.shr.customer.gtiit.rpt;
  2. import java.math.BigDecimal;
  3. import java.math.RoundingMode;
  4. import java.sql.SQLException;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.time.Instant;
  8. import java.time.LocalDate;
  9. import java.time.ZoneId;
  10. import java.time.format.DateTimeFormatter;
  11. import java.time.temporal.ChronoUnit;
  12. import java.util.ArrayList;
  13. import java.util.Calendar;
  14. import java.util.Date;
  15. import java.util.HashMap;
  16. import java.util.HashSet;
  17. import java.util.LinkedHashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import java.util.concurrent.ConcurrentHashMap;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import org.springframework.ui.ModelMap;
  25. import com.alibaba.fastjson.JSON;
  26. import com.alibaba.fastjson.JSONObject;
  27. import com.kingdee.bos.BOSException;
  28. import com.kingdee.bos.Context;
  29. import com.kingdee.eas.util.app.DbUtil;
  30. import com.kingdee.jdbc.rowset.IRowSet;
  31. import com.kingdee.shr.base.syssetting.context.SHRContext;
  32. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  33. import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
  34. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  35. import com.kingdee.shr.customer.gtiit.util.ExportAllUtils;
  36. //import com.kingdee.shr.customer.gtiit.util.FacutilyExportUtils;
  37. import com.kingdee.shr.customer.gtiit.util.RptUtils;
  38. //教员缺勤报告
  39. public class FacultyAbseceReporttoMorisListHandler extends ListHandler {
  40. Context ctx = SHRContext.getInstance().getContext();
  41. private int totalCount;
  42. static BigDecimal hours = new BigDecimal(60 * 60 * 1000);
  43. public FacultyAbseceReporttoMorisListHandler() {
  44. }
  45. public String getGridColModelAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  46. throws SHRWebException, BOSException, SQLException {
  47. try {
  48. String parameter = request.getParameter("postData");
  49. JSONObject paramJson = JSON.parseObject(parameter);
  50. JSONObject fastJson = paramJson.getJSONObject("fastFilterItems");
  51. JSONObject qeryTimeJson = fastJson.getJSONObject("queryTime");
  52. JSONObject valuesJson = qeryTimeJson.getJSONObject("values");
  53. String tostartDate = null;
  54. String toendDate = null;
  55. if (valuesJson != null && !valuesJson.equals("")) {
  56. tostartDate = valuesJson.getString("startDate");
  57. toendDate = valuesJson.getString("endDate");
  58. }
  59. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  60. Date startDates = sdf.parse(tostartDate);
  61. Date endDates = sdf.parse(toendDate);
  62. List<String> colNames = this.getcolNamesAction(startDates, endDates);
  63. List<Map<String, Object>> colModel = this.getcolModelAction(startDates, endDates);
  64. LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
  65. map.put("colNames", colNames);
  66. map.put("colModel", colModel);
  67. JSONUtils.writeJson(response, map);
  68. } catch (ParseException e) {
  69. // TODO 自动生成的 catch 块
  70. e.printStackTrace();
  71. }
  72. return null;
  73. }
  74. public void getGridDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  75. throws BOSException, SQLException, SHRWebException, ParseException {
  76. int rows = Integer.parseInt(request.getParameter("rows"));
  77. int page = Integer.parseInt(request.getParameter("page"));
  78. //List<Map<String, Object>> maplist = new ArrayList<Map<String, Object>>();
  79. int num = 0;
  80. // 获取报表查询过滤条件
  81. List<String> qfNames = new ArrayList<>();
  82. qfNames.add("queryTime");
  83. String parameter = request.getParameter("fastFilterItems");
  84. JSONObject paramJson = JSON.parseObject(parameter);
  85. Map<String, Object> rptSQLFilterate = RptUtils.getRptSQLFilterate(paramJson, qfNames);
  86. JSONObject queyTimeJson = paramJson.getJSONObject("queryTime");
  87. String pervalues = queyTimeJson.getString("values");
  88. String tostartDate = null;
  89. String toendDate = null;
  90. if (pervalues != null && !pervalues.equals("")) {
  91. JSONObject queryTimeValues = queyTimeJson.getJSONObject("values");
  92. tostartDate = queryTimeValues.getString("startDate");
  93. toendDate = queryTimeValues.getString("endDate");
  94. }
  95. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  96. Date startDates = sdf.parse(tostartDate);
  97. // String formattoendDate = sdf.format(toendDate);
  98. Date endDates = sdf.parse(toendDate);
  99. // 获取过滤条件的开始时间和结束时间
  100. List<String> fiterDate = this.getDateList(startDates, endDates, "dd/MM");
  101. // 获取报表数据源
  102. String sqlInfo = getSql(rptSQLFilterate);
  103. IRowSet rs = DbUtil.executeQuery(this.ctx, sqlInfo);
  104. // key 人员工号 value 1.存放部门等相关信息 key为 界面name value值
  105. // 2.key 每天的日期 value 为 假期类型 xx小时 ,假期类型 xx小时
  106. // LinkedHashMap<String, Map<String, Object>> allDataMap = new LinkedHashMap<>();
  107. //SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
  108. //SimpleDateFormat sdf3 = new SimpleDateFormat("dd/MM");
  109. //boolean first = true;
  110. //SimpleDateFormat sdf4 = new SimpleDateFormat("yy/MM");
  111. // key是工号 value存储日期和请假类型
  112. //Map<String, Map<String, String>> numberMap = new HashMap<>();
  113. // Set存放人员的工号
  114. Set<String> numberSet = new HashSet<>();
  115. Map<String, Map<String, String>> numberMap = this.getAllmap(rs, numberSet, fiterDate);
  116. List<Map<String, Object>> tomaplist = new ArrayList<Map<String, Object>>();
  117. rs.beforeFirst();
  118. while (rs.next()) {
  119. Map<String, Object> map = new HashMap<String, Object>();
  120. // 工号
  121. String fnumber = rs.getString("StaffID");
  122. // 姓名
  123. String name = rs.getString("name");
  124. // 请假开始时间
  125. //Date fbegintime = rs.getDate("FBEGINTIME");
  126. // 请假结束时间
  127. //Date fendtime = rs.getDate("FENDTIME");
  128. // 岗位 title
  129. String title = rs.getString("title");
  130. // 请假类型
  131. //String atsType = rs.getString("atsType");
  132. // Academic
  133. String academic = rs.getString("AcademicTitle");
  134. // Program 部门
  135. String program = rs.getString("program");
  136. // 获取请假开始日期和结束日期的所有时间段
  137. //List<String> dateList = this.getDateList(fbegintime, fendtime, "dd/MM");
  138. // 用掉一个Set就去除一个对应元素
  139. if (numberSet.contains(fnumber)) {
  140. Map<String, String> tofnumberMap = numberMap.get(fnumber);
  141. map.put("StaffID", fnumber);
  142. map.put("Name", name);
  143. map.put("Title", title);
  144. map.put("Academic Title", academic);
  145. map.put("Program", program);
  146. for (Map.Entry<String, String> entry : tofnumberMap.entrySet()) {
  147. // 截取工号和姓名
  148. String key = entry.getKey();
  149. String subKey = key.substring(0, 5);
  150. String value = entry.getValue();
  151. // String tokey = key.substring(5);
  152. map.put(subKey, value);
  153. }
  154. numberSet.remove(fnumber);
  155. tomaplist.add(map);
  156. }
  157. }
  158. this.totalCount = num;
  159. Map<String, Object> gridDataMap = new LinkedHashMap<String, Object>();
  160. if (this.totalCount % rows == 0) {
  161. gridDataMap.put("total", this.totalCount / rows);
  162. } else {
  163. gridDataMap.put("total", this.totalCount / rows + 1);
  164. }
  165. gridDataMap.put("page", page);
  166. gridDataMap.put("records", this.totalCount);
  167. gridDataMap.put("rows", tomaplist);
  168. JSONUtils.writeJson(response, gridDataMap);
  169. }
  170. /**
  171. * 拆分两个日期中的规定上班时间
  172. *
  173. * @param start
  174. * 请假开始日期
  175. * @param end
  176. * 请假结束日期
  177. * @return LinkedHashMap<Date, Date>
  178. */
  179. public static List<LinkedHashMap<String, Date>> splitDateRange(Date start, Date end) {
  180. List<LinkedHashMap<String, Date>> rs = new ArrayList<>();
  181. LinkedHashMap<String, Date> dateMap = new LinkedHashMap<>();
  182. // 获取两个日期之间的天数
  183. long daysBetween = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000); // 转换为天数差
  184. Calendar calendar = Calendar.getInstance();
  185. calendar.setTime(start);
  186. int year = calendar.get(Calendar.YEAR); // 获取年份
  187. int month = calendar.get(Calendar.MONTH); // 获取月份(注意,月份是从0开始的,所以要加1)
  188. int day = calendar.get(Calendar.DAY_OF_MONTH); // 获取日期
  189. // 当天的午休时间
  190. calendar.set(year, month, day, 12, 00, 0); // 年 月(从0开始) 日 时 分 秒
  191. Date lunchStartDate = calendar.getTime();
  192. dateMap.put("lunchStartDate", lunchStartDate);
  193. calendar.set(year, month, day, 13, 30, 0); // 年 月(从0开始) 日 时 分 秒
  194. Date lunchEndDate = calendar.getTime();
  195. dateMap.put("lunchEndDate", lunchEndDate);
  196. // 单天 直接返回
  197. if (daysBetween == 0) {
  198. calendar.set(year, month, day, 8, 30, 0); // 年 月(从0开始) 日 时 分 秒
  199. Date toDayMinStartTime = calendar.getTime();
  200. if (start.compareTo(toDayMinStartTime) < 1) {
  201. start = toDayMinStartTime;
  202. }
  203. calendar.set(year, month, day, 17, 30, 0); // 年 月(从0开始) 日 时 分 秒
  204. Date toDayMinEndTime = calendar.getTime();
  205. if (end.compareTo(toDayMinEndTime) == 1) {
  206. end = toDayMinEndTime;
  207. }
  208. dateMap.put("startDate", start);
  209. dateMap.put("endDate", end);
  210. rs.add(dateMap);
  211. return rs;
  212. } else {
  213. // 多天初始话第一天晚上
  214. calendar.set(year, month, day, 17, 30, 0); // 年 月(从0开始) 日 时 分 秒
  215. dateMap.put("startDate", start);
  216. dateMap.put("endDate", calendar.getTime());
  217. rs.add(dateMap);
  218. }
  219. // 拆分日期范围并添加到Map中(从第二天开始)
  220. for (int i = 1; i <= daysBetween; i++) { // 从第二天开始计算,所以循环从1开始而不是从0开始
  221. LinkedHashMap<String, Date> nextDateMap = new LinkedHashMap<>();
  222. // 对应的第二到第N天的上下班时间
  223. Calendar calendarStart = Calendar.getInstance();
  224. calendarStart.set(year, month, day, 8, 30, 0); // 年 月(从0开始) 日 时 分 秒
  225. calendarStart.add(Calendar.DAY_OF_MONTH, 1); // 加一天
  226. Date newStartDate = calendarStart.getTime();
  227. // 当天结束日期
  228. Calendar calendarEnd = Calendar.getInstance();
  229. calendarEnd.set(year, month, day, 17, 30, 0); // 年 月(从0开始) 日 时 分 秒
  230. calendarEnd.add(Calendar.DAY_OF_MONTH, 1); // 加一天
  231. Date newEndDate = calendarEnd.getTime();
  232. // 获取第二天到第N天的 年月日
  233. year = calendarStart.get(Calendar.YEAR); // 获取年份
  234. month = calendarStart.get(Calendar.MONTH); // 获取月份(注意,月份是从0开始的,所以要加1)
  235. day = calendarStart.get(Calendar.DAY_OF_MONTH); // 获取日期
  236. // 加一天
  237. Date newLunchStartDate = new Date(lunchStartDate.getTime() + (24 * 60 * 60 * 1000));
  238. nextDateMap.put("lunchStartDate", newLunchStartDate);
  239. lunchStartDate = newLunchStartDate;
  240. Date newLunchEndDate = new Date(lunchEndDate.getTime() + (24 * 60 * 60 * 1000));
  241. nextDateMap.put("lunchEndDate", newLunchEndDate);
  242. lunchEndDate = newLunchEndDate;
  243. if (newEndDate.compareTo(end) < 1) {
  244. nextDateMap.put("startDate", newStartDate);
  245. nextDateMap.put("endDate", newEndDate);
  246. rs.add(nextDateMap);
  247. } else {
  248. nextDateMap.put("startDate", newStartDate);
  249. nextDateMap.put("endDate", end);
  250. rs.add(nextDateMap);
  251. }
  252. }
  253. return rs;
  254. }
  255. /**
  256. * @param startTime
  257. * 请假开始时间
  258. * @param endTime
  259. * 请假结束时间
  260. * @param lunchStart
  261. * 午休开始时间
  262. * @param lunchEnd
  263. * 午休结束时间
  264. * @return 当天的请假 小时数
  265. */
  266. public static double getLeaveHoursBetween(Date startTime, Date endTime, Date lunchStart, Date lunchEnd) {
  267. // 请假总时长
  268. long workDiffInMilliseconds = Math.abs(endTime.getTime() - startTime.getTime());
  269. BigDecimal work = new BigDecimal(workDiffInMilliseconds);
  270. BigDecimal workHour = work.divide(hours, 2, RoundingMode.HALF_UP);
  271. // 1. 开始-结束(半天) 2.开始到午休 3.午休到结束 4 开始到结束(整天)
  272. if (startTime.before(lunchStart) && endTime.after(lunchEnd)) {
  273. // 2.请假开始时间午休前 请假结束日期午休结束后
  274. long diffInMilliseconds = Math.abs(lunchEnd.getTime() - lunchStart.getTime());
  275. BigDecimal noWork = new BigDecimal(diffInMilliseconds);
  276. BigDecimal noWorkHours = noWork.divide(hours, 2, RoundingMode.HALF_UP);
  277. return workHour.subtract(noWorkHours).doubleValue();
  278. } else if (startTime.after(lunchStart) && startTime.before(lunchEnd) && endTime.after(lunchEnd)) {
  279. // 3. 请假开始时间午休中 请假结束日期是午休后 (需剔除午休请假时间 午休接受时间-请假开始时间)
  280. // 非工作时间
  281. long diffInMilliseconds = Math.abs(lunchEnd.getTime() - startTime.getTime());
  282. BigDecimal noWork = new BigDecimal(diffInMilliseconds);
  283. BigDecimal noWorkHours = noWork.divide(hours, 2, RoundingMode.HALF_UP);
  284. return workHour.subtract(noWorkHours).doubleValue();
  285. } else if (startTime.before(lunchStart) && endTime.before(lunchEnd) && endTime.after(lunchStart)) {
  286. // 4.开始时间在午休前 结束时间在午休中
  287. long diffInMilliseconds = Math.abs(endTime.getTime() - lunchStart.getTime());
  288. BigDecimal noWork = new BigDecimal(diffInMilliseconds);
  289. BigDecimal noWorkHours = noWork.divide(hours, 2, RoundingMode.HALF_UP);
  290. return workHour.subtract(noWorkHours).doubleValue();
  291. } else {
  292. return workHour.doubleValue();
  293. }
  294. }
  295. /**
  296. * 获取两个日期中的所有日期
  297. *
  298. * @param start
  299. * @param end
  300. * @return
  301. */
  302. private List<Date> getBetweenDates(Date start, Date end) {
  303. List<Date> result = new ArrayList<Date>();
  304. Calendar tempStart = Calendar.getInstance();
  305. tempStart.setTime(start);
  306. tempStart.add(Calendar.DAY_OF_YEAR, 1);
  307. Calendar tempEnd = Calendar.getInstance();
  308. tempEnd.setTime(end);
  309. while (tempStart.before(tempEnd)) {
  310. result.add(tempStart.getTime());
  311. tempStart.add(Calendar.DAY_OF_YEAR, 1);
  312. }
  313. return result;
  314. }
  315. public ArrayList<String> getcolNamesAction(Date startDate, Date endDate) throws SHRWebException {
  316. ArrayList<String> list = new ArrayList<String>();
  317. list.add("StaffID");
  318. list.add("Name");
  319. list.add("Title");
  320. list.add("Academic Title");
  321. list.add("Program");
  322. List<String> dateList = this.getDateList(startDate, endDate, "dd/MM");
  323. for (String localDate : dateList) {
  324. list.add(localDate);
  325. }
  326. return list;
  327. }
  328. /**
  329. *
  330. * @param staffId
  331. * 工号
  332. * @param data
  333. * 存放转换后的数据
  334. * @param type
  335. * 假期类型
  336. * @param sdf
  337. * yyyy-MM-dd
  338. * @param sdf2
  339. * MM/dd
  340. * @param start
  341. * 请假开始时间 yyyy-MM-dd HH:MM
  342. * @param end
  343. * 请假结束时间 yyyy-MM-dd HH:MM
  344. * @param lunchStart
  345. * 午休开始时间 yyyy-MM-dd HH:MM
  346. * @param lunchEnd
  347. * 午休结束时间 yyyy-MM-dd HH:MM
  348. * @return 存放转换后的数据
  349. */
  350. private static void getDate(String staffId, Map<String, Object> data, String type, SimpleDateFormat sdf,
  351. SimpleDateFormat sdf2, Date start, Date end, Date lunchStart, Date lunchEnd) {
  352. // 获取请假小时数
  353. double leaveHoursBetween = getLeaveHoursBetween(start, end, lunchStart, lunchEnd);
  354. // 请假日期
  355. String key = sdf2.format(start);
  356. // 判断是否在同一天
  357. if (data.containsKey(key)) {
  358. Map<String, Double> holidayTypeAndHours = (Map<String, Double>) data.get(key);
  359. // 判断当天是否存在同一假勤类型的请假单 多张请假单 一个类型
  360. if (holidayTypeAndHours.containsKey(type)) {
  361. // 获取请假类型的的请假时间
  362. Double holidayHoursHis = holidayTypeAndHours.get(type);
  363. holidayTypeAndHours.put(type, holidayHoursHis + leaveHoursBetween);
  364. } else {
  365. holidayTypeAndHours = new HashMap<String, Double>();
  366. holidayTypeAndHours.put(type, leaveHoursBetween);
  367. }
  368. data.put(key, holidayTypeAndHours);
  369. } else {
  370. Map<String, Double> holidayTypeAndHours = new HashMap<>();
  371. // key是请假类型 vlues是请假小时数
  372. holidayTypeAndHours.put(type, leaveHoursBetween);
  373. // 可以是开始时间的yymm value的key是请假类型 value是请假小时数
  374. data.put(key, holidayTypeAndHours);
  375. }
  376. }
  377. /**
  378. * mapkey是日期 vlue为考勤类型 可能会有多个
  379. *
  380. * @param startDate
  381. * // 请假开始时间
  382. * @param endDate
  383. * // 请假结束时间
  384. * @param checkType
  385. * // 请假类型
  386. * @return
  387. */
  388. // public void getCheck(Date startDate, Date endDate, String format, String checkType) {
  389. // // 获取请假时间和请假结束时间之间的所有日期
  390. // List<String> dateList = this.getDateList(startDate, endDate, format);
  391. //
  392. // }
  393. /**
  394. * 获取开始日期和结束日期之间的所有日期
  395. *
  396. * @param startDate
  397. * @param endDate
  398. * @return
  399. */
  400. public List<String> getDateList(Date startDate, Date endDate, String format) {
  401. List<String> dateList = new ArrayList<String>();
  402. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
  403. LocalDate startLocal = Instant.ofEpochMilli(startDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
  404. LocalDate endLocal = Instant.ofEpochMilli(endDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
  405. // 计算开始日期和结束日期之间的天数
  406. long daysBetween = ChronoUnit.DAYS.between(startLocal, endLocal);
  407. for (int i = 0; i <= daysBetween; i++) {
  408. LocalDate date = startLocal.plusDays(i);
  409. String tofromat = date.format(formatter);
  410. dateList.add(tofromat);
  411. }
  412. return dateList;
  413. }
  414. // 请假类型的转换
  415. public String getLeaveType(String type) {
  416. String leavetype = null;
  417. if (type.equals("年假")) {
  418. leavetype = "A";
  419. } else if (type.equals("出差")) {
  420. leavetype = "B";
  421. } else {
  422. leavetype = "O";
  423. }
  424. return leavetype;
  425. }
  426. public List<Map<String, Object>> getcolModelAction(Date startDate, Date endDate) {
  427. List<Map<String, Object>> modelColList = new ArrayList<Map<String, Object>>();
  428. modelColList.add(this.buildColModelMap("StaffID", "StaffID", 120));
  429. modelColList.add(this.buildColModelMap("Name", "Name", 120));
  430. modelColList.add(this.buildColModelMap("Title", "Title", 120));
  431. modelColList.add(this.buildColModelMap("Academic Title", "Academic Title", 120));
  432. modelColList.add(this.buildColModelMap("Program", "Program", 120));
  433. List<String> dateList = this.getDateList(startDate, endDate, "dd/MM");
  434. for (String localDate : dateList) {
  435. String local = localDate;
  436. modelColList.add(this.buildColModelMap(localDate, localDate, 60));
  437. }
  438. return modelColList;
  439. }
  440. private Map<String, Object> buildColModelMap(String index, String label, int width) {
  441. return this.buildColModelMap(index, label, width, false, false, false);
  442. }
  443. private Map<String, Object> buildColModelMap(String index, String label, int width, boolean rowspan, boolean isKey,
  444. boolean isHedden) {
  445. Map<String, Object> gridIdMap = new LinkedHashMap<String, Object>();
  446. gridIdMap.put("index", index);
  447. gridIdMap.put("name", index);
  448. gridIdMap.put("label", label);
  449. gridIdMap.put("width", width);
  450. if (rowspan) {
  451. gridIdMap.put("rowspan", rowspan);
  452. }
  453. if (isKey) {
  454. gridIdMap.put("key", isKey);
  455. }
  456. if (isHedden) {
  457. gridIdMap.put("hidden", isHedden);
  458. }
  459. return gridIdMap;
  460. }
  461. // map存放工号和加勤数据
  462. public Map<String, Map<String, String>> getAllmap(IRowSet rs, Set<String> numberSet, List<String> fiterDate)
  463. throws SQLException {
  464. // key是工号 value存储日期和请假类型
  465. boolean first = true;
  466. Map<String, Map<String, String>> numberMap = new HashMap<>();
  467. while (rs.next()) {
  468. // key是日期+工号,value是请假类型
  469. Map<String, String> dateMap = new ConcurrentHashMap<>();
  470. // Map<String, Object> map = new HashMap<String, Object>();
  471. // 工号
  472. String fnumber = rs.getString("StaffID");
  473. numberSet.add(fnumber);
  474. // 请假开始时间
  475. Date fbegintime = rs.getDate("FBEGINTIME");
  476. // 请假结束时间
  477. Date fendtime = rs.getDate("FENDTIME");
  478. // 请假类型
  479. String atsType = rs.getString("ATSTYPE");
  480. // 获取请假开始日期和结束日期的所有时间段
  481. List<String> dateList = this.getDateList(fbegintime, fendtime, "dd/MM");
  482. // 获取假期类型返回的字符
  483. String leaveType = this.getLeaveType(atsType);
  484. // 判断是否是第一次循环 第一次玄幻先添加
  485. if (first) {
  486. first = false;
  487. // map.put("StaffID", fnumber);
  488. // map.put("Name", name);
  489. // map.put("Title", fnumber);
  490. // map.put("Academic Title", academic);
  491. // map.put("Program", program);
  492. for (String fiterdate : fiterDate) {
  493. for (String datelist : dateList) {
  494. // 过滤条件的日期段和请假时间的日期段比较,判断日期是否在一个时间段内
  495. if (fiterdate.equals(datelist)) {
  496. dateMap.put(datelist + fnumber, leaveType);
  497. }
  498. }
  499. }
  500. numberMap.put(fnumber, dateMap);
  501. } else {
  502. // 判断是否是同一个人
  503. if (numberMap.containsKey(fnumber)) {
  504. Map<String, String> todatemap = numberMap.get(fnumber);
  505. synchronized (todatemap) {
  506. for (Map.Entry<String, String> entry : todatemap.entrySet()) {
  507. // 截取工号和时间
  508. String key = entry.getKey();
  509. // 工号
  510. String subKey = key.substring(0, 5);
  511. // 时间
  512. String value = entry.getValue();
  513. //String tokey = key.substring(5);
  514. // 判断是否是同一个人
  515. for (String datelist : dateList) {
  516. // 判断是否是同一天
  517. if (subKey.equals(datelist)) {
  518. // 如果请假类型不相等就更新vlue
  519. if (!value.equals(leaveType)) {
  520. todatemap.put(key, value + leaveType);
  521. }
  522. // 如果不是同一天key和value都要更新
  523. } else {
  524. todatemap.put(datelist + fnumber, leaveType);
  525. }
  526. }
  527. }
  528. }
  529. numberMap.put(fnumber, todatemap);
  530. } else {
  531. // 如果不是同一个人
  532. for (String fiterdate : fiterDate) {
  533. for (String datelist : dateList) {
  534. // 过滤条件的日期段和请假时间的日期段比较,判断日期是否在一个时间段内
  535. if (fiterdate.equals(datelist)) {
  536. dateMap.put(datelist + fnumber, leaveType);
  537. }
  538. }
  539. }
  540. numberMap.put(fnumber, dateMap);
  541. }
  542. }
  543. }
  544. return numberMap;
  545. }
  546. private String getSql(Map<String, Object> params) {
  547. StringBuffer sql = new StringBuffer();
  548. Map<String, Object> contractDateMap = (Map<String, Object>) params.get("queryTime");
  549. Object startDate = contractDateMap.get("startDate");
  550. Object endDate = contractDateMap.get("endDate");
  551. sql.append(
  552. "SELECT b.FPERSONID,b.FBEGINTIME,b.FENDTIME,d.fnumber as StaffID,d.fname_l1 name,e.FName_L1 as Program,c.FName_L1 as Title,p.FName_L1 as AcademicTitle,\r\n"
  553. + "f.fnumber holidayTypeNumber,f.fname_l2 as atsType, f.fname_l1 HolidayName FROM T_HR_ATS_LeaveBill a \r\n"
  554. + "left join T_HR_ATS_LeaveBillentry b on a.fid=b.fbillid \r\n"
  555. + " left join (select b.fpersonid, d.cflongname_l1 positionName,e.fname_l1 depName ,at.FName_l1 as AcademicTitle,c.CFAcademicTitleID,d.FName_L1 from \r\n"
  556. + " (SELECT FPERSONID,max(FleFFDT) as maxDate FROM T_HR_EmpOrgRelation where fassignType = '1' group by FPERSONID ) b \r\n"
  557. + " left join T_HR_EmpOrgRelation c on b.fpersonid = c.fpersonid and b.maxdate=FleFFDT \r\n"
  558. + " left join CT_MP_AcademicTitle at on at.fid = c.CFAcademicTitleID\r\n"
  559. + " left join T_ORG_Position d on c.fpositionid=d.fid \r\n"
  560. + " left join T_ORG_BaseUnit e on e.fid = c.FAdminOrgID \r\n"
  561. + " left join CT_MP_WorkerCategory f on f.fid=c.CFWorkercategoryID where c.fassignType = '1' and f.fnumber = 'GTIIT_FACULTY') c \r\n"
  562. + " on b.fpersonid = c.fpersonid \r\n"
  563. + " left join T_BD_Person d on d.fid=b.fpersonid \r\n"
  564. + "left join T_HR_ATS_HolidayPolicy e on e.fid=b.fpolicyid \r\n"
  565. + "left join T_HR_ATS_HolidayType f on f.fid=e.fholidaytypeid\r\n"
  566. + "left join CT_MP_AcademicTitle p on c.CFAcademicTitleID=p.fid");
  567. sql.append(" where b.FBeginTime>=");
  568. sql.append("'");
  569. sql.append(startDate);
  570. sql.append("'");
  571. sql.append(" and b.FEndTime<=");
  572. sql.append("'");
  573. sql.append(endDate);
  574. sql.append("'");
  575. System.out.println(sql.toString());
  576. return sql.toString();
  577. }
  578. // 导出
  579. public String toExcelAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  580. throws BOSException, SQLException, SHRWebException, ParseException {
  581. // 获取报表查询过滤条件
  582. List<String> qfNames = new ArrayList<>();
  583. qfNames.add("queryTime");
  584. String parameter = request.getParameter("fastFilterItems");
  585. JSONObject paramJson = JSON.parseObject(parameter);
  586. Map<String, Object> rptSQLFilterate = RptUtils.getRptSQLFilterate(paramJson, qfNames);
  587. JSONObject queyTimeJson = paramJson.getJSONObject("queryTime");
  588. String pervalues = queyTimeJson.getString("values");
  589. String tostartDate = null;
  590. String toendDate = null;
  591. if (pervalues != null && !pervalues.equals("")) {
  592. JSONObject queryTimeValues = queyTimeJson.getJSONObject("values");
  593. tostartDate = queryTimeValues.getString("startDate");
  594. toendDate = queryTimeValues.getString("endDate");
  595. }
  596. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  597. Date startDates = sdf.parse(tostartDate);
  598. Date endDates = sdf.parse(toendDate);
  599. // 转换日期格式为dd/MM/yyyy
  600. SimpleDateFormat tosdf = new SimpleDateFormat("dd/MM/yyyy");
  601. String formatstartDate = tosdf.format(startDates);
  602. String formatendDate = tosdf.format(endDates);
  603. // 获取过滤条件的开始时间和结束时间
  604. List<String> fiterDate = this.getDateList(startDates, endDates, "dd/MM");
  605. // 获取报表数据源
  606. String sqlInfo = getSql(rptSQLFilterate);
  607. IRowSet rs = DbUtil.executeQuery(this.ctx, sqlInfo);
  608. LinkedHashMap<String, String> selectFieldsTypeMap = new LinkedHashMap<String, String>();
  609. String stringType = "String_@";
  610. selectFieldsTypeMap.put("StaffID", stringType);
  611. selectFieldsTypeMap.put("name", stringType);
  612. selectFieldsTypeMap.put("title", stringType);
  613. selectFieldsTypeMap.put("AcademicTitle", stringType);
  614. selectFieldsTypeMap.put("program", stringType);
  615. List<String> dateList = this.getDateList(startDates, endDates, "dd/MM");
  616. for (String localDate : dateList) {
  617. selectFieldsTypeMap.put(localDate, stringType);
  618. }
  619. Set<String>numberSet=new HashSet<>();
  620. while (rs.next()) {
  621. // key是日期+工号,value是请假类型
  622. // Map<String, String> dateMap = new ConcurrentHashMap<>();
  623. // Map<String, Object> map = new HashMap<String, Object>();
  624. // 工号
  625. String fnumber = rs.getString("StaffID");
  626. numberSet.add(fnumber);
  627. }
  628. // 获取对应人员的工号和考勤数据
  629. rs.beforeFirst();
  630. Map<String, Map<String, String>> allmap = this.getAllmap(rs, numberSet, fiterDate);
  631. ArrayList<String> list = this.getcolNamesAction(startDates, endDates);
  632. ExportAllUtils.morisExportData(response, rs, "FacultyAbsenceReport.xlsx", selectFieldsTypeMap, list,allmap,numberSet,
  633. formatstartDate,formatendDate);
  634. return null;
  635. }
  636. }