PerAtsOverTimeBillBatchEditHandlerEx.java 13 KB

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