PerAtsOverTimeBillBatchEditHandlerTestEx.java 13 KB

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