|
@@ -0,0 +1,307 @@
|
|
|
+package com.kingdee.shr.customer.gtiit.handler;
|
|
|
+
|
|
|
+import com.kingdee.bos.BOSException;
|
|
|
+import com.kingdee.bos.Context;
|
|
|
+import com.kingdee.eas.basedata.person.PersonInfo;
|
|
|
+import com.kingdee.eas.framework.CoreBaseInfo;
|
|
|
+import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryCollection;
|
|
|
+import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryInfo;
|
|
|
+import com.kingdee.eas.hr.ats.AtsOverTimeBillInfo;
|
|
|
+import com.kingdee.eas.hr.ats.AttendFileStateEnum;
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
+import com.kingdee.shr.ats.web.handler.PerAtsOverTimeBillBatchEditHandler;
|
|
|
+import com.kingdee.shr.base.syssetting.context.SHRContext;
|
|
|
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
|
|
|
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
|
|
|
+import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
|
|
|
+import com.kingdee.shr.customer.gtiit.util.BaseUtil;
|
|
|
+import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * test
|
|
|
+ */
|
|
|
+public class PerAtsOverTimeBillBatchEditHandlerTestEx extends PerAtsOverTimeBillBatchEditHandler {
|
|
|
+ private static Logger logger = Logger
|
|
|
+ .getLogger("com.kingdee.shr.customer.gtiit.handler.PerAtsOverTimeBillBatchEditHandlerExExEx");
|
|
|
+
|
|
|
+
|
|
|
+ public void workMultipleAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
|
|
|
+ throws SHRWebException {
|
|
|
+ Context ctx = SHRContext.getInstance().getContext();
|
|
|
+ String otDate = request.getParameter("otDate");
|
|
|
+ logger.error("加班日期:" + otDate);
|
|
|
+ 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 + "'";
|
|
|
+ logger.error("查询加班类型SQL:" + sql);
|
|
|
+ Map<String, Map<String, String>> overTimeTypeMap = BaseUtil.getOverTimeType(ctx);
|
|
|
+ Map<String, String> returnMap = new HashMap<String, String>();
|
|
|
+ try {
|
|
|
+ IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
|
|
|
+ while (iRowSet.next()) {
|
|
|
+ if (iRowSet.getString("CFWORKMULTIPLE").equals("1")) {
|
|
|
+ // 工作日加班
|
|
|
+ returnMap = overTimeTypeMap.get("001");
|
|
|
+ } else if (iRowSet.getString("CFWORKMULTIPLE").equals("2")) {
|
|
|
+ // 休息日加班
|
|
|
+ returnMap = overTimeTypeMap.get("002");
|
|
|
+ } else if (iRowSet.getString("CFWORKMULTIPLE").equals("3")) {
|
|
|
+ // 法定节假日加班
|
|
|
+ returnMap = overTimeTypeMap.get("003");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (BOSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (SQLException throwables) {
|
|
|
+ throwables.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONUtils.writeJson(response, returnMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void jobTypeAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
|
|
|
+ throws SHRWebException {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ Context ctx = SHRContext.getInstance().getContext();
|
|
|
+ Map<String, Map<String, String>> overTimeTypeMap = BaseUtil.getOverTimeType(ctx);
|
|
|
+ Map<String, String> returnMap = new HashMap<String, String>();
|
|
|
+ String otDate = request.getParameter("otDate");
|
|
|
+ logger.error("加班日期:" + otDate);
|
|
|
+ Date parseDate = DateTimeUtils.parseDate(otDate, "yyyy-MM-dd");
|
|
|
+ calendar.setTime(parseDate);
|
|
|
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
+ if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
|
|
|
+ // 休息日加班
|
|
|
+ returnMap = overTimeTypeMap.get("002");
|
|
|
+ } else {
|
|
|
+ // 工作日加班
|
|
|
+ returnMap = overTimeTypeMap.get("001");
|
|
|
+ }
|
|
|
+ JSONUtils.writeJson(response, returnMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void verifyModel(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
|
|
|
+ throws SHRWebException {
|
|
|
+ super.verifyModel(request, response, model);
|
|
|
+
|
|
|
+ checkOverTime(model);
|
|
|
+ checkCompensate(model);
|
|
|
+ //增加一位员工每个自然月只能提一张加班单校验
|
|
|
+ checkOnlyTakeOneBill(request, response, model);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void beforeSubmit(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
|
|
|
+ throws SHRWebException {
|
|
|
+ super.beforeSubmit(request, response, model);
|
|
|
+ //增加一位员工每个自然月只能提一张加班单校验
|
|
|
+ checkOnlyTakeOneBill(request, response, model);
|
|
|
+ checkOverTime(model);
|
|
|
+ checkCompensate(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkCompensate(CoreBaseInfo model) throws ShrWebBizException {
|
|
|
+ Context ctx = SHRContext.getInstance().getContext();
|
|
|
+ AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo) model;
|
|
|
+ AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
|
|
|
+
|
|
|
+ Set<String> personIdSet = new HashSet<String>();
|
|
|
+ String compenSql = "select fid from T_HR_ATS_OverTimeCompens where fnumber='002'";
|
|
|
+ String compenId = "";
|
|
|
+ try {
|
|
|
+ IRowSet compenRowSet = DbUtil.executeQuery(ctx, compenSql);
|
|
|
+ if (compenRowSet.next()) {
|
|
|
+ compenId = compenRowSet.getString("fid");
|
|
|
+ }
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ } catch (BOSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < entries.size(); i++) {
|
|
|
+ AtsOverTimeBillEntryInfo entryInfo = entries.get(i);
|
|
|
+ if (StringUtils.equals(entryInfo.getOtCompens().getId().toString(), compenId)) {
|
|
|
+ personIdSet.add(entryInfo.getPerson().getId().toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.error("员工ID集合:" + personIdSet.toString());
|
|
|
+ StringBuffer strBuffer = new StringBuffer();
|
|
|
+ for (String personId : personIdSet) {
|
|
|
+ strBuffer.append("'" + personId + "',");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strBuffer.length() > 0) {
|
|
|
+ strBuffer = strBuffer.deleteCharAt(strBuffer.length() - 1);
|
|
|
+ Map<String, String> personIdByNameMap = BaseUtil.getPersonIdByName(ctx, personIdSet);
|
|
|
+ String sql = "SELECT p.fid,emp.jobgradename FROM t_bd_person p "
|
|
|
+ + "left join (select gra.fname_l2 jobgradename,e.fpersonid from "
|
|
|
+ + "(SELECT FPERSONID,max(fleffdt) as maxDate FROM T_HR_EmpPostExperienceHis group by FPERSONID) as h "
|
|
|
+ + "left join T_HR_EmpPostExperienceHis e on e.fpersonid= h.FPERSONID and fleffdt = h.maxDate "
|
|
|
+ + "left join (SELECT * FROM T_HR_EmpPostRank where fislatest='1') r on r.fpersonid = e.fpersonid "
|
|
|
+ + "left join T_HR_JobGrade gra on gra.fid=r.fjobgradeid) emp on p.fid=emp.fpersonid "
|
|
|
+ + "where p.fid in (" + strBuffer.toString() + ")";
|
|
|
+ try {
|
|
|
+ IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
|
|
|
+ while (rowSet.next()) {
|
|
|
+ String jobGradeName = rowSet.getString("jobgradename");
|
|
|
+ if (StringUtils.isNotBlank(jobGradeName)) {
|
|
|
+ jobGradeName = jobGradeName.replace("L", "");
|
|
|
+ int gradeLevel = Integer.parseInt(jobGradeName);
|
|
|
+ if (gradeLevel >= 8) {
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String personTypeSql = "SELECT a.fid,e.fnumber FROM T_BD_Person a "
|
|
|
+ + "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 "
|
|
|
+ + "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 "
|
|
|
+ + "left join CT_MP_WorkerCategory e on e.fid=d.CFWorkercategoryID " + "where a.fid in ("
|
|
|
+ + strBuffer.toString() + ")";
|
|
|
+ IRowSet personTypeRow = DbUtil.executeQuery(ctx, personTypeSql);
|
|
|
+ while (personTypeRow.next()) {
|
|
|
+ String workCategoryNumber = personTypeRow.getString("fnumber");
|
|
|
+ if (StringUtils.equals("GTIIT_FACULTY", workCategoryNumber)
|
|
|
+ || StringUtils.equals("GTIIT_OTHER", workCategoryNumber)) {
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (BOSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkOverTime(CoreBaseInfo model) throws ShrWebBizException {
|
|
|
+ Context ctx = SHRContext.getInstance().getContext();
|
|
|
+ AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo) model;
|
|
|
+ AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
|
|
|
+ LinkedMultiValueMap<String, Map<String, Date>> multiMap = new LinkedMultiValueMap<>();
|
|
|
+ StringBuffer personIdBuffer = new StringBuffer();
|
|
|
+ for (int i = 0; i < entries.size(); i++) {
|
|
|
+ AtsOverTimeBillEntryInfo entryInfo = entries.get(i);
|
|
|
+ if (!entryInfo.getOtType().getString("id").equals("rBy0u1YgQ9C1OxcM85mxyY6C/nU=")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Date otDate = entryInfo.getOtDate();
|
|
|
+ String dateFormat = DateTimeUtils.dateFormat(otDate, "yyyy-MM-dd");
|
|
|
+ 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 + "'";
|
|
|
+ try {
|
|
|
+ IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
|
|
|
+ if (iRowSet.next()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } catch (BOSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Map<String, Date> map = new HashMap<>();
|
|
|
+ map.put("startTime", entryInfo.getStartTime());
|
|
|
+ map.put("endTime", entryInfo.getEndTime());
|
|
|
+ multiMap.add(entryInfo.getPerson().getString("id"), map);
|
|
|
+ personIdBuffer.append("'" + entryInfo.getPerson().getString("id") + "',");
|
|
|
+ }
|
|
|
+ Map<String, String> personIdByNameMap = BaseUtil.getPersonIdByName(ctx, multiMap.keySet());
|
|
|
+ if (personIdBuffer.length() > 0) {
|
|
|
+ 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 "
|
|
|
+ + "where FPROPOSERID in (" + personIdBuffer.deleteCharAt(personIdBuffer.length() - 1)
|
|
|
+ + ") and a.FATTENDFILESTATE = '" + AttendFileStateEnum.ENABLE_VALUE + "'";
|
|
|
+ try {
|
|
|
+ IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
|
|
|
+ while (rowSet.next()) {
|
|
|
+ String personId = rowSet.getString("FPROPOSERID");
|
|
|
+ String restStart = rowSet.getObject("FRESTPRETIME") == null ? "12:00"
|
|
|
+ : rowSet.getString("FRESTPRETIME");
|
|
|
+ String restEnd = rowSet.getObject("FRESTNEXTTIME") == null ? "13:30"
|
|
|
+ : rowSet.getString("FRESTNEXTTIME");
|
|
|
+ List<Map<String, Date>> list = multiMap.get(personId);
|
|
|
+ for (Map<String, Date> dateMap : list) {
|
|
|
+ Date startTime = dateMap.get("startTime");
|
|
|
+ Date endTime = dateMap.get("endTime");
|
|
|
+ Instant startInstant = startTime.toInstant();
|
|
|
+ Instant endInstant = endTime.toInstant();
|
|
|
+ LocalTime startLocalTime = startInstant.atZone(ZoneId.systemDefault()).toLocalTime();
|
|
|
+ LocalTime endLocalTime = endInstant.atZone(ZoneId.systemDefault()).toLocalTime();
|
|
|
+
|
|
|
+ LocalTime shiftStartTime = LocalTime.parse(restStart);
|
|
|
+ LocalTime shiftendTime = LocalTime.parse(restEnd);
|
|
|
+ if (startLocalTime.compareTo(shiftendTime) >= 0
|
|
|
+ || endLocalTime.compareTo(shiftStartTime) <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ((startLocalTime.compareTo(shiftStartTime) >= 0
|
|
|
+ && startLocalTime.compareTo(shiftendTime) <= 0)
|
|
|
+ || (endLocalTime.compareTo(shiftStartTime) >= 0
|
|
|
+ && endLocalTime.compareTo(shiftendTime) <= 0)) {
|
|
|
+ throw new ShrWebBizException("Employee (" + personIdByNameMap.get(personId)
|
|
|
+ + ") cannot work overtime during rest time on weekdays");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (BOSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一位员工每个自然月只能提一张加班单校验
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param model
|
|
|
+ */
|
|
|
+ protected void checkOnlyTakeOneBill(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model) throws ShrWebBizException {
|
|
|
+ Context ctx = SHRContext.getInstance().getContext();
|
|
|
+ try {
|
|
|
+ AtsOverTimeBillInfo billInfo = (AtsOverTimeBillInfo) model;
|
|
|
+ AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
|
|
|
+ StringBuilder sql = new StringBuilder(" select e.fid from T_HR_ATS_OVERTIMEBILL b ");
|
|
|
+ sql.append(" left join T_HR_ATS_OVERTIMEBILLentry e on b.fid= e.fbillid ");
|
|
|
+ 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')<= ? ");
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ for (int i = 0; i < entries.size(); i++) {
|
|
|
+ AtsOverTimeBillEntryInfo ats = entries.get(i);
|
|
|
+ Date otdate = ats.getOtDate();
|
|
|
+ PersonInfo personInfo = ats.getPerson();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(otdate);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ String fotdate1 = sf.format(calendar.getTime());
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
+ String fotdate2 = sf.format(calendar.getTime());
|
|
|
+ IRowSet rs = DbUtil.executeQuery(ctx, sql.toString(), new String[]{personInfo.getId().toString(), fotdate1, fotdate2});
|
|
|
+ if(rs.size()>0){
|
|
|
+ throw new ShrWebBizException("Each employee can apply for overtime only once per natural month.Employee ("+personInfo.getName()+") has already applied.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (BOSException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|