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.KQHolidaySetBiz; import com.engine.kq.biz.KQOvertimeRulesBiz; import com.engine.kq.biz.KQWorkTime; import org.apache.commons.lang.StringUtils; import weaver.conn.RecordSet; import weaver.general.BaseBean; import weaver.general.Util; import java.time.LocalDate; import java.time.format.DateTimeFormatter; 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 getEndWorkDate(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); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate start = LocalDate.parse(kqDate, formatter); if (offset > 0 ) { for (int i = 0 ; i < offset ; ) { start = start.plusDays(1); boolean holiday = KQHolidaySetBiz.isHoliday(resourceId, start.format(formatter), true); if ( !holiday) { i++; } } } else if (offset < 0 ) { for (int i = 0 ; i > offset ; ) { start = start.minusDays(1); boolean holiday = KQHolidaySetBiz.isHoliday(resourceId, start.format(formatter), true); if ( !holiday) { i--; } } } String endDate = start.format(formatter); result.put("code",200); result.put("msg","请求成功"); result.put("data",endDate); return result; } @Override public Map signDelete(Map params) { bb.writeLog("---signDelete start---"); Map result = new HashMap<>(); try { String dataid = Util.null2String(params.get("id"));//申请人 bb.writeLog("dataid: " + dataid); if ( StringUtils.isBlank(dataid)) { result.put("code",500); result.put("msg","请先选择要删除的数据"); return result; } //将需要删除的打卡数据记录到日志表后再执行删除 RecordSet rs = new RecordSet(); List deleteParams = new ArrayList<>(); List logParams = new ArrayList<>(); String signDelLogModeId = bb.getPropValue("project_hostar", "signDelLogModeId"); bb.writeLog("signDelLogModeId: " + signDelLogModeId); Integer modedatacreater = user.getUID(); Integer modedatacreatertype = user.getType(); String modedatacreatedate = DateUtil.format(new Date(), "yyyy-MM-dd"); String modedatacreatetime = DateUtil.format(new Date(), "HH:mm:ss"); String acqMaxIdSql = " select max(id) as id from uf_schsigndellog"; String logSignSql = "insert into uf_schsigndellog (userid, usertype, signtype, signdate, signtime, clientaddress, isincom, " + " signfrom, longitude, latitude, addr, isimport, suuid, timezone, belongdate, memo, deviceinfo, showaddress, " + " formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime ) " + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; String acqSchSignSql = "select userid, usertype, signtype, signdate, signtime, clientaddress, isincom," + " signfrom, longitude, latitude, addr, isimport, suuid, timezone, belongdate, memo, " + " deviceinfo, showaddress from hrmschedulesign where id in (" + dataid + ")"; rs.executeQuery(acqSchSignSql); while (rs.next()) { String userid = Util.null2String(rs.getString("userid")); String usertype = Util.null2String(rs.getString("usertype")); String signtype = Util.null2String(rs.getString("signtype")); String signdate = Util.null2String(rs.getString("signdate")); String signtime = Util.null2String(rs.getString("signtime")); String clientaddress = Util.null2String(rs.getString("clientaddress")); String isincom = Util.null2String(rs.getString("isincom")); String signfrom = Util.null2String(rs.getString("signfrom")); String longitude = Util.null2String(rs.getString("longitude")); String latitude = Util.null2String(rs.getString("latitude")); String addr = Util.null2String(rs.getString("addr")); String isimport = Util.null2String(rs.getString("isimport")); String suuid = Util.null2String(rs.getString("suuid")); String timezone = Util.null2String(rs.getString("timezone")); String belongdate = Util.null2String(rs.getString("belongdate")); String memo = Util.null2String(rs.getString("memo")); String deviceinfo = Util.null2String(rs.getString("deviceinfo")); String showaddress = Util.null2String(rs.getString("showaddress")); List logPa = new ArrayList<>(); logPa.add(userid); logPa.add(usertype); logPa.add(signtype); logPa.add(signdate); logPa.add(signtime); logPa.add(clientaddress); logPa.add(isincom); logPa.add(signfrom); logPa.add(longitude); logPa.add(latitude); logPa.add(addr); logPa.add(isimport); logPa.add(suuid); logPa.add(timezone); logPa.add(belongdate); logPa.add(memo); logPa.add(deviceinfo); logPa.add(showaddress); logPa.add(signDelLogModeId); logPa.add(modedatacreater); logPa.add(modedatacreatertype); logPa.add(modedatacreatedate); logPa.add(modedatacreatetime); logParams.add(logPa); } int maxLogId = -1; rs.executeQuery(acqMaxIdSql); while (rs.next()) { maxLogId = Util.getIntValue(Util.null2String(rs.getString("id"))); } bb.writeLog("maxLogId: " + maxLogId); boolean addLogFlag = rs.executeBatchSql(logSignSql, logParams); bb.writeLog("addLogFlag: " + addLogFlag); if (addLogFlag) { List billids = new ArrayList<>(); Map billidCreator = new HashMap<>(); String acqBillidsSql = "select id from uf_schsigndellog where id > ?"; rs.executeQuery(acqBillidsSql, maxLogId); while (rs.next()) { Integer id = Util.getIntValue(Util.null2String(rs.getString("id"))); billids.add(id); billidCreator.put(id, 1); } bb.writeLog("billids: " + billids); bb.writeLog("billidCreator: " + billidCreator); if (billids != null && billids.size() > 0) { HostarUtil hsutil = new HostarUtil(); hsutil.modePerReconBatch(billidCreator, signDelLogModeId, billids); } } else { result.put("code",500); result.put("msg","删除失败"); return result; } boolean delFlag = rs.executeUpdate("delete from hrmschedulesign where id in (" + dataid + ")"); if (delFlag) { result.put("code",200); result.put("msg","删除成功"); return result; } else { result.put("code",500); result.put("msg","删除失败"); return result; } }catch (Exception e ) { bb.writeLog("signDelete Exception: " + e); } result.put("code",500); result.put("msg","删除失败"); return result; } }