package com.engine.hostar.service.impl; import cn.hutool.core.date.DateUtil; import com.engine.core.impl.Service; import com.engine.hostar.service.KqDevService; import com.engine.hostar.util.HostarUtil; import com.engine.kq.biz.KQOvertimeRulesBiz; import com.engine.kq.biz.KQWorkTime; import org.apache.commons.lang.StringUtils; import weaver.general.BaseBean; import weaver.general.Util; import java.util.*; /** * @author chenwnj * @date 2023/12/11 * @description **/ public class KqDevServiceImpl extends Service implements KqDevService { BaseBean bb = new BaseBean(); @Override public Map getKqType(Map params) { bb.writeLog("---getKqType start---"); Map result = new HashMap<>(); String resourceId = Util.null2String(params.get("resourceId")); bb.writeLog("resourceId: " + resourceId); String kqDate = Util.null2String(params.get("kqDate")); bb.writeLog("kqDate: " + kqDate); if ( StringUtils.isBlank(resourceId)) { result.put("code",500); result.put("msg","请先选择人员"); return result; } if ( StringUtils.isBlank(kqDate)) { result.put("code",500); result.put("msg","请先选择日期"); return result; } int changeType = -1; try { //1-节假日、2-工作日、3-休息日、-1-数据异常,无效数据 changeType = KQOvertimeRulesBiz.getChangeType(resourceId, kqDate); bb.writeLog("changeType: " + changeType); } catch (Exception e) { bb.writeLog("getKqType Exception: " + e); } if (changeType == -1) { result.put("code", 500); result.put("msg", "日期判断异常,请联系管理员"); return result; } else { result.put("code", 200); result.put("data", changeType); return result; } } @Override public Map checkApplyDate(Map params) { bb.writeLog("---checkApplyDate start---"); Map result = new HashMap<>(); String resourceId = Util.null2String(params.get("resourceId"));//申请人 bb.writeLog("resourceId: " + resourceId); String kqDate = Util.null2String(params.get("kqDate"));//申请日期 bb.writeLog("kqDate: " + kqDate); String offsetStr = Util.null2String(params.get("offset"));//允许的偏移量 bb.writeLog("offsetStr: " + offsetStr); if ( StringUtils.isBlank(resourceId)) { result.put("code",500); result.put("msg","请先选择人员"); return result; } if ( StringUtils.isBlank(kqDate)) { result.put("code",500); result.put("msg","请先选择申请日期"); return result; } if ( StringUtils.isBlank(offsetStr)) { result.put("code",500); result.put("msg","请先设置偏移量"); return result; } Integer offset = Util.getIntValue(offsetStr); bb.writeLog("offset: " + offset); KQWorkTime kqWorkTime = new KQWorkTime(); HostarUtil hostarUtil = new HostarUtil(); String today = DateUtil.format(new Date(), "yyyy-MM-dd"); bb.writeLog("today: " + today); List allDates = new ArrayList<>(); if (today.compareTo(kqDate) < 0 ) { if ( offset < 0) { result.put("code",500); result.put("msg","该流程只能提前"+Math.abs(offset)+"个工作日申请"); return result; } allDates = hostarUtil.getAllDates(today, kqDate); } else if (today.compareTo(kqDate) > 0 ){ if ( offset > 0) { result.put("code",500); result.put("msg","该流程只能延后"+Math.abs(offset)+"个工作日申请"); return result; } allDates = hostarUtil.getAllDates(kqDate, today); } else if (today.compareTo(kqDate) == 0) { if ( offset != 0) { result.put("code",500); result.put("msg","该流程只能当天申请"); return result; } allDates = hostarUtil.getAllDates(kqDate, today); } bb.writeLog("allDates: " + allDates); int workdays = -1; for ( String date: allDates) { //判断是否是工作日 boolean isWorkDay = kqWorkTime.isWorkDay(resourceId, date); if (isWorkDay){ workdays ++; } } bb.writeLog("workdays: " + workdays); if (workdays <= Math.abs(offset)) { result.put("code",200); result.put("msg","允许申请"); return result; } else { result.put("code",500); result.put("msg","超出允许申请的时间限制,允许申请的时间为:申请日期" + (offset>= 0?(offset>0 ?"延迟"+Math.abs(offset) + "天" : "当天" ):"提前" + Math.abs(offset) + "天") ); return result; } } }