PerAtsOverTimeBillBatchEditHandlerEx.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. package com.kingdee.shr.customer.gtiit.handler;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.eas.framework.CoreBaseInfo;
  5. import com.kingdee.eas.hr.ats.*;
  6. import com.kingdee.eas.util.app.DbUtil;
  7. import com.kingdee.jdbc.rowset.IRowSet;
  8. import com.kingdee.shr.ats.web.handler.PerAtsOverTimeBillBatchEditHandler;
  9. import com.kingdee.shr.base.syssetting.context.SHRContext;
  10. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  11. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  12. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  13. import com.kingdee.shr.customer.gtiit.util.BaseUtil;
  14. import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.apache.log4j.Logger;
  17. import org.springframework.ui.ModelMap;
  18. import org.springframework.util.LinkedMultiValueMap;
  19. import javax.servlet.http.HttpServletRequest;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.math.BigDecimal;
  22. import java.sql.SQLException;
  23. import java.time.Instant;
  24. import java.time.LocalTime;
  25. import java.time.ZoneId;
  26. import java.util.*;
  27. public class PerAtsOverTimeBillBatchEditHandlerEx extends PerAtsOverTimeBillBatchEditHandler {
  28. private static Logger logger = Logger
  29. .getLogger("com.kingdee.shr.customer.gtiit.handler.PerAtsOverTimeBillBatchEditHandlerEx");
  30. public void workMultipleAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  31. throws SHRWebException {
  32. Context ctx = SHRContext.getInstance().getContext();
  33. String otDate = request.getParameter("otDate");
  34. logger.error("加班日期:" + otDate);
  35. String sql = "SELECT b.CFWORKMULTIPLE FROM T_HR_ATS_LegalHoliday a left join T_HR_ATS_LegalHolidayItem b on a.fid = b.FGROUPID where a.FSTATE = '1' and b.FSTARTDATE <= '"
  36. + otDate + "' and b.FENDDATE >= '" + otDate + "'";
  37. logger.error("查询加班类型SQL:" + sql);
  38. Map<String, Map<String, String>> overTimeTypeMap = BaseUtil.getOverTimeType(ctx);
  39. Map<String, String> returnMap = new HashMap<String, String>();
  40. try {
  41. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  42. while (iRowSet.next()) {
  43. if (iRowSet.getString("CFWORKMULTIPLE").equals("1")) {
  44. // 工作日加班
  45. returnMap = overTimeTypeMap.get("001");
  46. } else if (iRowSet.getString("CFWORKMULTIPLE").equals("2")) {
  47. // 休息日加班
  48. returnMap = overTimeTypeMap.get("002");
  49. } else if (iRowSet.getString("CFWORKMULTIPLE").equals("3")) {
  50. // 法定节假日加班
  51. returnMap = overTimeTypeMap.get("003");
  52. }
  53. }
  54. } catch (BOSException e) {
  55. e.printStackTrace();
  56. } catch (SQLException throwables) {
  57. throwables.printStackTrace();
  58. }
  59. JSONUtils.writeJson(response, returnMap);
  60. }
  61. public void jobTypeAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  62. throws SHRWebException {
  63. Calendar calendar = Calendar.getInstance();
  64. Context ctx = SHRContext.getInstance().getContext();
  65. Map<String, Map<String, String>> overTimeTypeMap = BaseUtil.getOverTimeType(ctx);
  66. Map<String, String> returnMap = new HashMap<String, String>();
  67. String otDate = request.getParameter("otDate");
  68. logger.error("加班日期:" + otDate);
  69. Date parseDate = DateTimeUtils.parseDate(otDate, "yyyy-MM-dd");
  70. calendar.setTime(parseDate);
  71. int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
  72. if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
  73. // 休息日加班
  74. returnMap = overTimeTypeMap.get("002");
  75. } else {
  76. // 工作日加班
  77. returnMap = overTimeTypeMap.get("001");
  78. }
  79. JSONUtils.writeJson(response, returnMap);
  80. }
  81. @Override
  82. protected void verifyModel(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  83. throws SHRWebException {
  84. super.verifyModel(request, response, model);
  85. checkOverTime(model);
  86. checkCompensate(model);
  87. }
  88. @Override
  89. protected void beforeSubmit(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  90. throws SHRWebException {
  91. super.beforeSubmit(request, response, model);
  92. checkOverSubmitDate();
  93. checkOverTime(model);
  94. checkCompensate(model);
  95. countSumTime(model);
  96. }
  97. private void countSumTime(CoreBaseInfo model)
  98. throws ShrWebBizException
  99. {
  100. logger.error("进入多人加班单提交重算时间方法");
  101. AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo)model;
  102. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  103. BigDecimal weekdayHour = BigDecimal.ZERO;
  104. BigDecimal restdayHour = BigDecimal.ZERO;
  105. BigDecimal holidayHour = BigDecimal.ZERO;
  106. BigDecimal totalDuration = BigDecimal.ZERO;
  107. BigDecimal compensatoryTotal = BigDecimal.ZERO;
  108. BigDecimal totalOvertimePay = BigDecimal.ZERO;
  109. for (int i = 0; i < entries.size(); i++) {
  110. AtsOverTimeBillEntryInfo entryInfo = entries.get(i);
  111. String otTypeId = "";
  112. String otCompensId = "";
  113. OverTimeTypeInfo otType = entryInfo.getOtType();
  114. BigDecimal applyOtTime = entryInfo.getApplyOTTime() == null ? BigDecimal.ZERO : entryInfo.getApplyOTTime();
  115. OverTimeCompensInfo otCompens = entryInfo.getOtCompens();
  116. if (otType != null) {
  117. otTypeId = otType.getId().toString();
  118. }
  119. if (otCompens != null) {
  120. otCompensId = otCompens.getId().toString();
  121. }
  122. if (StringUtils.equals(otTypeId, "rBy0u1YgQ9C1OxcM85mxyY6C/nU="))
  123. weekdayHour = weekdayHour.add(applyOtTime);
  124. else if (StringUtils.equals(otTypeId, "zr+ur5D4RA+2bdVZ2VPqp46C/nU="))
  125. restdayHour = restdayHour.add(applyOtTime);
  126. else if (StringUtils.equals(otTypeId, "sRWUOt7sRpOY0TCo6NMqGY6C/nU=")) {
  127. holidayHour = holidayHour.add(applyOtTime);
  128. }
  129. if (StringUtils.equals(otCompensId, "AERg0TIcSnaM40EKvJCdRKlrTmA="))
  130. compensatoryTotal = compensatoryTotal.add(applyOtTime);
  131. else if (StringUtils.equals(otCompensId, "zkbt5bMLQ3ehUivmKbtBOqlrTmA=")) {
  132. totalOvertimePay = totalOvertimePay.add(applyOtTime);
  133. }
  134. }
  135. totalDuration = weekdayHour.add(restdayHour).add(holidayHour);
  136. billInfo.put("weekdayHour", weekdayHour);
  137. billInfo.put("restdayHour", restdayHour);
  138. billInfo.put("holidayHour", holidayHour);
  139. billInfo.put("totalDuration", totalDuration);
  140. billInfo.put("compensatoryTotal", compensatoryTotal);
  141. billInfo.put("totalOvertimePay", totalOvertimePay);
  142. }
  143. /**
  144. * 校验当月x号后不允许已经上月加班申请
  145. *
  146. * @throws ShrWebBizException
  147. */
  148. private void checkOverSubmitDate() throws ShrWebBizException {
  149. Context ctx = SHRContext.getInstance().getContext();
  150. String sql = "select fname_l1 from T_HR_ATS_OverTimeReason where fnumber = 'zbjbsj001'";
  151. int day = 0;
  152. try {
  153. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  154. if (rowSet.next()) {
  155. day = rowSet.getInt("fname_l1");
  156. }
  157. } catch (BOSException e) {
  158. e.printStackTrace();
  159. } catch (SQLException e) {
  160. e.printStackTrace();
  161. }
  162. if (day == 0) {
  163. return;
  164. }
  165. Calendar calendar = Calendar.getInstance();
  166. int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
  167. if (thisDay > day) {
  168. throw new ShrWebBizException(
  169. "Not allowed to submit last month's overtime application after the " + day + "th");
  170. }
  171. }
  172. private void checkCompensate(CoreBaseInfo model) throws ShrWebBizException {
  173. Context ctx = SHRContext.getInstance().getContext();
  174. AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo) model;
  175. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  176. Set<String> personIdSet = new HashSet<String>();
  177. String compenSql = "select fid from T_HR_ATS_OverTimeCompens where fnumber='002'";
  178. String compenId = "";
  179. try {
  180. IRowSet compenRowSet = DbUtil.executeQuery(ctx, compenSql);
  181. if (compenRowSet.next()) {
  182. compenId = compenRowSet.getString("fid");
  183. }
  184. } catch (SQLException e1) {
  185. e1.printStackTrace();
  186. } catch (BOSException e) {
  187. e.printStackTrace();
  188. }
  189. for (int i = 0; i < entries.size(); i++) {
  190. AtsOverTimeBillEntryInfo entryInfo = entries.get(i);
  191. if (StringUtils.equals(entryInfo.getOtCompens().getId().toString(), compenId)) {
  192. personIdSet.add(entryInfo.getPerson().getId().toString());
  193. }
  194. }
  195. logger.error("员工ID集合:" + personIdSet.toString());
  196. StringBuffer strBuffer = new StringBuffer();
  197. for (String personId : personIdSet) {
  198. strBuffer.append("'" + personId + "',");
  199. }
  200. if (strBuffer.length() > 0) {
  201. strBuffer = strBuffer.deleteCharAt(strBuffer.length() - 1);
  202. Map<String, String> personIdByNameMap = BaseUtil.getPersonIdByName(ctx, personIdSet);
  203. String sql = "SELECT p.fid,emp.jobgradename FROM t_bd_person p "
  204. + "left join (select gra.fname_l2 jobgradename,e.fpersonid from "
  205. + "(SELECT FPERSONID,max(fleffdt) as maxDate FROM T_HR_EmpPostExperienceHis group by FPERSONID) as h "
  206. + "left join T_HR_EmpPostExperienceHis e on e.fpersonid= h.FPERSONID and fleffdt = h.maxDate "
  207. + "left join (SELECT * FROM T_HR_EmpPostRank where fislatest='1') r on r.fpersonid = e.fpersonid "
  208. + "left join T_HR_JobGrade gra on gra.fid=r.fjobgradeid) emp on p.fid=emp.fpersonid "
  209. + "where p.fid in (" + strBuffer.toString() + ")";
  210. try {
  211. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  212. while (rowSet.next()) {
  213. String jobGradeName = rowSet.getString("jobgradename");
  214. if (StringUtils.isNotBlank(jobGradeName)) {
  215. jobGradeName = jobGradeName.replace("L", "");
  216. jobGradeName = jobGradeName.replace("-", ".");
  217. Double gradeLevel = Double.parseDouble(jobGradeName);
  218. if (gradeLevel >= 13D) {
  219. throw new ShrWebBizException("Employee (" + personIdByNameMap.get(rowSet.getString("fid"))
  220. + ") with a rank greater than or equal to L13 is not allowed to submit overtime compensation forms with overtime pay as the compensation type");
  221. }
  222. }
  223. }
  224. String personTypeSql = "SELECT a.fid,e.fnumber FROM T_BD_Person a "
  225. + "left join (select b.fpersonid,c.CFWorkercategoryID from (SELECT FPERSONID,max(FEFFDT) as maxDate FROM T_HR_EmpOrgRelation where fassignType = '1' group by FPERSONID) b "
  226. + "left join T_HR_EmpOrgRelation c on b.fpersonid = c.fpersonid and b.maxdate=c.FEFFDT and c.fassignType = '1') d on a.fid=d.fpersonid "
  227. + "left join CT_MP_WorkerCategory e on e.fid=d.CFWorkercategoryID " + "where a.fid in ("
  228. + strBuffer.toString() + ")";
  229. IRowSet personTypeRow = DbUtil.executeQuery(ctx, personTypeSql);
  230. while (personTypeRow.next()) {
  231. String workCategoryNumber = personTypeRow.getString("fnumber");
  232. if (StringUtils.equals("GTIIT_FACULTY", workCategoryNumber)
  233. || StringUtils.equals("GTIIT_OTHER", workCategoryNumber)) {
  234. throw new ShrWebBizException("Employee ("
  235. + personIdByNameMap.get(personTypeRow.getString("fid"))
  236. + ") is an academic staff member and cannot submit overtime compensation forms with overtime pay as the compensation method");
  237. }
  238. }
  239. } catch (BOSException e) {
  240. e.printStackTrace();
  241. } catch (SQLException e) {
  242. e.printStackTrace();
  243. }
  244. }
  245. }
  246. private void checkOverTime(CoreBaseInfo model) throws ShrWebBizException {
  247. Context ctx = SHRContext.getInstance().getContext();
  248. AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo) model;
  249. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  250. LinkedMultiValueMap<String, Map<String, Date>> multiMap = new LinkedMultiValueMap<>();
  251. StringBuffer personIdBuffer = new StringBuffer();
  252. for (int i = 0; i < entries.size(); i++) {
  253. AtsOverTimeBillEntryInfo entryInfo = entries.get(i);
  254. if (!entryInfo.getOtType().getString("id").equals("rBy0u1YgQ9C1OxcM85mxyY6C/nU=")) {
  255. continue;
  256. }
  257. Date otDate = entryInfo.getOtDate();
  258. String dateFormat = DateTimeUtils.dateFormat(otDate, "yyyy-MM-dd");
  259. String sql = "SELECT b.CFWORKMULTIPLE FROM T_HR_ATS_LegalHoliday a left join T_HR_ATS_LegalHolidayItem b on a.fid = b.FGROUPID where a.FSTATE = '1' and b.FSTARTDATE <= '"
  260. + dateFormat + "' and b.FENDDATE >= '" + dateFormat + "'";
  261. try {
  262. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  263. if (iRowSet.next()) {
  264. continue;
  265. }
  266. } catch (BOSException e) {
  267. e.printStackTrace();
  268. } catch (SQLException e) {
  269. e.printStackTrace();
  270. }
  271. Map<String, Date> map = new HashMap<>();
  272. map.put("startTime", entryInfo.getStartTime());
  273. map.put("endTime", entryInfo.getEndTime());
  274. multiMap.add(entryInfo.getPerson().getString("id"), map);
  275. personIdBuffer.append("'" + entryInfo.getPerson().getString("id") + "',");
  276. }
  277. Map<String, String> personIdByNameMap = BaseUtil.getPersonIdByName(ctx, multiMap.keySet());
  278. if (personIdBuffer.length() > 0) {
  279. String sql = "SELECT a.FPROPOSERID,c.FRESTPRETIME,c.FRESTNEXTTIME FROM T_HR_ATS_AttendanceFile a left join T_HR_ATS_Shift b on a.FATSSHIFTID = b.fid left join T_HR_ATS_ShiftItem c on c.FGROUPID = b.fid "
  280. + "where FPROPOSERID in (" + personIdBuffer.deleteCharAt(personIdBuffer.length() - 1)
  281. + ") and a.FATTENDFILESTATE = '" + AttendFileStateEnum.ENABLE_VALUE + "'";
  282. try {
  283. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  284. while (rowSet.next()) {
  285. String personId = rowSet.getString("FPROPOSERID");
  286. String restStart = rowSet.getObject("FRESTPRETIME") == null ? "12:00"
  287. : rowSet.getString("FRESTPRETIME");
  288. String restEnd = rowSet.getObject("FRESTNEXTTIME") == null ? "13:30"
  289. : rowSet.getString("FRESTNEXTTIME");
  290. List<Map<String, Date>> list = multiMap.get(personId);
  291. for (Map<String, Date> dateMap : list) {
  292. Date startTime = dateMap.get("startTime");
  293. Date endTime = dateMap.get("endTime");
  294. Instant startInstant = startTime.toInstant();
  295. Instant endInstant = endTime.toInstant();
  296. LocalTime startLocalTime = startInstant.atZone(ZoneId.systemDefault()).toLocalTime();
  297. LocalTime endLocalTime = endInstant.atZone(ZoneId.systemDefault()).toLocalTime();
  298. LocalTime shiftStartTime = LocalTime.parse(restStart);
  299. LocalTime shiftendTime = LocalTime.parse(restEnd);
  300. if (startLocalTime.compareTo(shiftendTime) >= 0
  301. || endLocalTime.compareTo(shiftStartTime) <= 0) {
  302. continue;
  303. }
  304. if ((startLocalTime.compareTo(shiftStartTime) >= 0
  305. && startLocalTime.compareTo(shiftendTime) <= 0)
  306. || (endLocalTime.compareTo(shiftStartTime) >= 0
  307. && endLocalTime.compareTo(shiftendTime) <= 0)) {
  308. throw new ShrWebBizException("Employee (" + personIdByNameMap.get(personId)
  309. + ") cannot work overtime during rest time on weekdays");
  310. }
  311. }
  312. }
  313. } catch (BOSException e) {
  314. e.printStackTrace();
  315. } catch (SQLException e) {
  316. e.printStackTrace();
  317. }
  318. }
  319. }
  320. }