AtsOverTimeBillBatchEditHandlerEx.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. package com.kingdee.shr.customer.gtiit.handler;
  2. import java.sql.SQLException;
  3. import java.text.SimpleDateFormat;
  4. import java.time.Instant;
  5. import java.time.LocalTime;
  6. import java.time.ZoneId;
  7. import java.util.Calendar;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.HashSet;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.Set;
  14. import javax.servlet.http.HttpServletRequest;
  15. import javax.servlet.http.HttpServletResponse;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.apache.log4j.Logger;
  18. import org.springframework.ui.ModelMap;
  19. import org.springframework.util.LinkedMultiValueMap;
  20. import com.kingdee.bos.BOSException;
  21. import com.kingdee.bos.Context;
  22. import com.kingdee.eas.framework.CoreBaseInfo;
  23. import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryCollection;
  24. import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryInfo;
  25. import com.kingdee.eas.hr.ats.AtsOverTimeBillInfo;
  26. import com.kingdee.eas.hr.ats.AttendFileStateEnum;
  27. import com.kingdee.eas.util.app.DbUtil;
  28. import com.kingdee.jdbc.rowset.IRowSet;
  29. import com.kingdee.shr.ats.web.handler.AtsOverTimeBillBatchEditHandler;
  30. import com.kingdee.shr.base.syssetting.context.SHRContext;
  31. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  32. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  33. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  34. import com.kingdee.shr.customer.gtiit.util.BaseUtil;
  35. import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
  36. /**
  37. * 多人加班单表单Handler
  38. * @author xiaoxin
  39. *
  40. */
  41. public class AtsOverTimeBillBatchEditHandlerEx extends AtsOverTimeBillBatchEditHandler{
  42. private static Logger logger =
  43. Logger.getLogger("com.kingdee.shr.customer.gtiit.handler.AtsOverTimeBillBatchEditHandlerEx");
  44. public void workMultipleAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  45. Context ctx = SHRContext.getInstance().getContext();
  46. String otDate = request.getParameter("otDate");
  47. logger.error("加班日期:"+otDate);
  48. 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 <= '"+otDate+"' and b.FENDDATE >= '"+otDate+"'";
  49. logger.error("查询加班类型SQL:"+sql);
  50. Map<String, Map<String, String>> overTimeTypeMap = BaseUtil.getOverTimeType(ctx);
  51. Map<String, String> returnMap = new HashMap<String, String>();
  52. try {
  53. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  54. while (iRowSet.next()){
  55. if(iRowSet.getString("CFWORKMULTIPLE").equals("1")){
  56. //工作日加班
  57. returnMap = overTimeTypeMap.get("001");
  58. }else if(iRowSet.getString("CFWORKMULTIPLE").equals("2")){
  59. //休息日加班
  60. returnMap = overTimeTypeMap.get("002");
  61. }else if(iRowSet.getString("CFWORKMULTIPLE").equals("3")){
  62. //法定节假日加班
  63. returnMap = overTimeTypeMap.get("003");
  64. }
  65. }
  66. } catch (BOSException e) {
  67. e.printStackTrace();
  68. } catch (SQLException throwables) {
  69. throwables.printStackTrace();
  70. }
  71. JSONUtils.writeJson(response, returnMap);
  72. }
  73. public void jobTypeAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  74. Calendar calendar = Calendar.getInstance();
  75. Context ctx = SHRContext.getInstance().getContext();
  76. Map<String, Map<String, String>> overTimeTypeMap = BaseUtil.getOverTimeType(ctx);
  77. Map<String, String> returnMap = new HashMap<String, String>();
  78. String otDate = request.getParameter("otDate");
  79. logger.error("加班日期:"+otDate);
  80. Date parseDate = DateTimeUtils.parseDate(otDate, "yyyy-MM-dd");
  81. calendar.setTime(parseDate);
  82. int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
  83. if(dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
  84. //休息日加班
  85. returnMap = overTimeTypeMap.get("002");
  86. }else {
  87. //工作日加班
  88. returnMap = overTimeTypeMap.get("001");
  89. }
  90. JSONUtils.writeJson(response, returnMap);
  91. }
  92. @Override
  93. protected void verifyModel(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  94. throws SHRWebException {
  95. super.verifyModel(request, response, model);
  96. checkOverTime(model);
  97. checkCompensate(model);
  98. }
  99. @Override
  100. protected void beforeSubmit(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  101. throws SHRWebException {
  102. super.beforeSubmit(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. int gradeLevel = Integer.parseInt(jobGradeName);
  151. if(gradeLevel>=8) {
  152. throw new ShrWebBizException("Employee ("+personIdByNameMap.get(rowSet.getString("fid"))+") with a rank greater than or equal to L8 is not allowed to submit overtime compensation forms with overtime pay as the compensation type");
  153. }
  154. }
  155. }
  156. String personTypeSql = "SELECT a.fid,e.fnumber FROM T_BD_Person a "
  157. + "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 "
  158. + "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 "
  159. + "left join CT_MP_WorkerCategory e on e.fid=d.CFWorkercategoryID "
  160. + "where a.fid in ("+strBuffer.toString()+")";
  161. IRowSet personTypeRow = DbUtil.executeQuery(ctx, personTypeSql);
  162. while(personTypeRow.next()) {
  163. String workCategoryNumber = personTypeRow.getString("fnumber");
  164. if(StringUtils.equals("GTIIT_FACULTY", workCategoryNumber) || StringUtils.equals("GTIIT_OTHER", workCategoryNumber)) {
  165. throw new ShrWebBizException("Employee ("+personIdByNameMap.get(personTypeRow.getString("fid"))+") is an academic staff member and cannot submit overtime compensation forms with overtime pay as the compensation method");
  166. }
  167. }
  168. } catch (BOSException e) {
  169. e.printStackTrace();
  170. } catch (SQLException e) {
  171. e.printStackTrace();
  172. }
  173. }
  174. }
  175. private void checkOverTime(CoreBaseInfo model) throws ShrWebBizException {
  176. Context ctx = SHRContext.getInstance().getContext();
  177. AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo) model;
  178. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  179. LinkedMultiValueMap<String, Map<String, Date>> multiMap = new LinkedMultiValueMap<>();
  180. StringBuffer personIdBuffer = new StringBuffer();
  181. for(int i=0; i<entries.size(); i++) {
  182. AtsOverTimeBillEntryInfo entryInfo = entries.get(i);
  183. if(!entryInfo.getOtType().getString("id").equals("rBy0u1YgQ9C1OxcM85mxyY6C/nU=")) {
  184. continue;
  185. }
  186. Date otDate = entryInfo.getOtDate();
  187. String dateFormat = DateTimeUtils.dateFormat(otDate, "yyyy-MM-dd");
  188. 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 <= '"+dateFormat+"' and b.FENDDATE >= '"+dateFormat+"'";
  189. try {
  190. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  191. if(iRowSet.next()) {
  192. continue;
  193. }
  194. } catch (BOSException e) {
  195. e.printStackTrace();
  196. } catch (SQLException e) {
  197. e.printStackTrace();
  198. }
  199. Map<String, Date> map = new HashMap<>();
  200. map.put("startTime", entryInfo.getStartTime());
  201. map.put("endTime", entryInfo.getEndTime());
  202. multiMap.add(entryInfo.getPerson().getString("id"), map);
  203. personIdBuffer.append("'"+entryInfo.getPerson().getString("id")+"',");
  204. }
  205. Map<String, String> personIdByNameMap = BaseUtil.getPersonIdByName(ctx, multiMap.keySet());
  206. if(personIdBuffer.length()>0) {
  207. 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 "
  208. + "where FPROPOSERID in ("+personIdBuffer.deleteCharAt(personIdBuffer.length()-1)+") and a.FATTENDFILESTATE = '"+AttendFileStateEnum.ENABLE_VALUE+"'";
  209. try {
  210. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  211. while(rowSet.next()) {
  212. String personId = rowSet.getString("FPROPOSERID");
  213. String restStart = rowSet.getObject("FRESTPRETIME")==null?"12:00":rowSet.getString("FRESTPRETIME");
  214. String restEnd = rowSet.getObject("FRESTNEXTTIME")==null?"13:30":rowSet.getString("FRESTNEXTTIME");
  215. List<Map<String, Date>> list = multiMap.get(personId);
  216. for(Map<String, Date> dateMap:list) {
  217. Date startTime = dateMap.get("startTime");
  218. Date endTime = dateMap.get("endTime");
  219. Instant startInstant = startTime.toInstant();
  220. Instant endInstant = endTime.toInstant();
  221. LocalTime startLocalTime = startInstant.atZone(ZoneId.systemDefault()).toLocalTime();
  222. LocalTime endLocalTime = endInstant.atZone(ZoneId.systemDefault()).toLocalTime();
  223. LocalTime shiftStartTime = LocalTime.parse(restStart);
  224. LocalTime shiftendTime = LocalTime.parse(restEnd);
  225. if(startLocalTime.compareTo(shiftendTime)>=0 || endLocalTime.compareTo(shiftStartTime)<=0) {
  226. continue;
  227. }
  228. if((startLocalTime.compareTo(shiftStartTime)>=0 && startLocalTime.compareTo(shiftendTime)<=0)
  229. || (endLocalTime.compareTo(shiftStartTime)>=0 && endLocalTime.compareTo(shiftendTime)<=0)) {
  230. throw new ShrWebBizException("Employee ("+personIdByNameMap.get(personId)+") cannot work overtime during rest time on weekdays");
  231. }
  232. }
  233. }
  234. } catch (BOSException e) {
  235. e.printStackTrace();
  236. } catch (SQLException e) {
  237. e.printStackTrace();
  238. }
  239. }
  240. }
  241. }