AtsOverTimeBillBatchEditHandlerEx.java 14 KB

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