Commit 8b0d63ed authored by 赵啸非's avatar 赵啸非

修改考勤汇总

parent 4ab7b745
package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.PageUtil;
import cn.hutool.core.util.StrUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery;
import com.mortals.xhx.module.attendance.service.AttendanceRecordHikService;
import com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq;
import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo;
import com.mortals.xhx.module.hik.door.service.IHikDoorService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 同步获取下午海康门禁事件
*/
@Slf4j
@Service("SyncDoorsEventAfterTask")
public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
@Autowired
private AttendanceRecordHikService recordHikService;
@Autowired
private StaffService staffService;
@Autowired
private IHikDoorService hikDoorService;
@Override
public void excuteTask(ITask task) throws AppException {
syncDoorEvents();
calculateAttendByDay();
}
private void calculateAttendByDay() {
Context context = new Context();
UserEntity userEntity = new UserEntity();
userEntity.setCreateUserId(1L);
userEntity.setCreateUserName("system");
userEntity.setCreateTime(new Date());
context.setUser(userEntity);
AttendanceRecordHikQuery recordHikEntity = new AttendanceRecordHikQuery();
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// recordHikEntity.setAttendanceDateStart(DateUtils.getCurrStrDate());
recordHikEntity.setAttendanceDateStart(DateUtil.offsetHour(new Date(), -5).toString());
recordHikEntity.setAttendanceDateEnd(DateUtils.getCurrStrDate());
try {
recordHikService.addAttendanceRecordByQuery(recordHikEntity, context);
} catch (Exception e) {
log.error("计算考勤异常", e);
}
}
private void syncDoorEvents() {
DoorEventReq doorEventReq = new DoorEventReq();
List<Integer> eventTypes = new ArrayList<>();
eventTypes.add(196885);
eventTypes.add(196887);
eventTypes.add(196893);
eventTypes.add(196888);
eventTypes.add(196889);
eventTypes.add(196890);
eventTypes.add(196891);
doorEventReq.setEventTypes(eventTypes);
// 获取当天的开始时间
Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// Date todayStart = DateUtil.beginOfDay(new Date());
// 获取当天的结束时间
Date todayEnd = DateUtil.endOfDay(new Date());
doorEventReq.setStartTime(todayStart);
doorEventReq.setEndTime(todayEnd);
doorEventReq.setPageNo(1);
doorEventReq.setPageSize(1);
Rest<DoorEventDataInfo> doorEventsRest = hikDoorService.getDoorEvents(doorEventReq);
log.info("doorEventsRest:{} msg:{}", doorEventsRest.getCode(), doorEventsRest.getMsg());
if (doorEventsRest.getCode() == YesNoEnum.YES.getValue()) {
//分页获取考勤数据
Integer total = doorEventsRest.getData().getTotal();
int pageCount = PageUtil.totalPage(total, 1000);
for (int i = 1; i <= pageCount; i++) {
doorEventReq.setPageNo(i);
doorEventReq.setPageSize(1000);
doorEventsRest = hikDoorService.getDoorEvents(doorEventReq);
log.info("doorEventsRest:{} msg:{},page:{}", doorEventsRest.getCode(), doorEventsRest.getMsg(), doorEventReq.getPageNo());
getDoorEvents(doorEventsRest);
}
}
}
private void getDoorEvents(Rest<DoorEventDataInfo> doorEventsRest) {
//同步当前考勤数据
List<AttendanceRecordHikEntity> attRecords = doorEventsRest.getData().getList().stream().map(item -> {
AttendanceRecordHikEntity recordHikEntity = new AttendanceRecordHikEntity();
recordHikEntity.initAttrValue();
StaffEntity staffCache = staffService.getExtCache(StrUtil.padPre(item.getJobNo(), 8, "0"));
if (ObjectUtils.isEmpty(staffCache)) {
log.info("staff is null !staffCode:{}", item.getJobNo());
return null;
}
recordHikEntity.setStaffId(staffCache.getId());
recordHikEntity.setStaffName(staffCache.getName());
recordHikEntity.setWorkNum(staffCache.getWorkNum());
recordHikEntity.setDeptId(staffCache.getDeptId());
recordHikEntity.setDeptName(staffCache.getDeptName());
recordHikEntity.setPositionId(staffCache.getPositionId());
recordHikEntity.setPositionName(staffCache.getPositionName());
recordHikEntity.setAttendanceDate(item.getEventTime());
recordHikEntity.setAttendanceAddress(item.getDoorName());
recordHikEntity.setEventSource("门禁点");
recordHikEntity.setRemark(item.getEventId());
recordHikEntity.setCreateTime(new Date());
recordHikEntity.setCreateUserName("系统管理员");
recordHikEntity.setCreateUserId(1L);
return recordHikEntity;
}).filter(f -> f != null).collect(Collectors.toList());
log.info("attRecords size:{}", attRecords.size());
List<String> eventIds = attRecords.parallelStream().filter(f -> !ObjectUtils.isEmpty(f) && !ObjectUtils.isEmpty(f.getRemark())).map(i -> i.getRemark()).collect(Collectors.toList());
//查询当天考勤记录是否有重复的 有的 则不添加
AttendanceRecordHikQuery recordHikQuery = new AttendanceRecordHikQuery();
recordHikQuery.setAttendanceDateStart(DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyy-MM-dd"));
recordHikQuery.setAttendanceDateEnd(DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyy-MM-dd"));
recordHikQuery.setRemarkList(eventIds);
Set<String> eventIdSet = recordHikService.find(recordHikQuery).parallelStream().map(i -> i.getRemark()).collect(Collectors.toSet());
//去重 时分秒打卡的 也要去掉重复。
List<AttendanceRecordHikEntity> saveRecordList = attRecords.stream().filter(f -> !eventIdSet.contains(f.getRemark())).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveRecordList)) {
//单个插入 去掉重复时间段的打卡记录
for (AttendanceRecordHikEntity recordHikEntity : saveRecordList) {
try {
recordHikService.save(recordHikEntity);
} catch (Exception e) {
log.error("基础考勤数据保存异常", e.getMessage());
}
}
// recordHikService.save(saveRecordList);
}
log.info("saveRecordList size:{}", saveRecordList.size());
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.PageUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
......@@ -23,12 +20,10 @@ import com.mortals.xhx.module.hik.door.service.IHikDoorService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.time.Year;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -68,12 +63,12 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
context.setUser(userEntity);
AttendanceRecordHikQuery recordHikEntity = new AttendanceRecordHikQuery();
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// recordHikEntity.setAttendanceDateStart(DateUtils.getCurrStrDate());
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// recordHikEntity.setAttendanceDateStart(DateUtils.getCurrStrDate());
recordHikEntity.setAttendanceDateStart(DateUtil.offsetHour(new Date(), -5).toString());
recordHikEntity.setAttendanceDateEnd(DateUtils.getCurrStrDate());
try {
recordHikService.addAttendanceRecord(recordHikEntity, context);
recordHikService.addAttendanceRecordByQuery(recordHikEntity, context);
} catch (Exception e) {
log.error("计算考勤异常", e);
}
......@@ -92,7 +87,7 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
doorEventReq.setEventTypes(eventTypes);
// 获取当天的开始时间
Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// Date todayStart = DateUtil.beginOfDay(new Date());
// Date todayStart = DateUtil.beginOfDay(new Date());
// 获取当天的结束时间
Date todayEnd = DateUtil.endOfDay(new Date());
doorEventReq.setStartTime(todayStart);
......@@ -123,7 +118,7 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
recordHikEntity.initAttrValue();
StaffEntity staffCache = staffService.getExtCache(StrUtil.padPre(item.getJobNo(), 8, "0"));
if (ObjectUtils.isEmpty(staffCache)) {
log.info("staff is null !staffCode:{}",item.getJobNo());
log.info("staff is null !staffCode:{}", item.getJobNo());
return null;
}
......@@ -140,13 +135,11 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
recordHikEntity.setEventSource("门禁点");
recordHikEntity.setRemark(item.getEventId());
recordHikEntity.setCreateTime(new Date());
recordHikEntity.setCreateUserName("system");
recordHikEntity.setCreateUserName("系统管理员");
recordHikEntity.setCreateUserId(1L);
return recordHikEntity;
}).filter(f->f!=null).collect(Collectors.toList());
}).filter(f -> f != null).collect(Collectors.toList());
log.info("attRecords size:{}", attRecords.size());
List<String> eventIds = attRecords.parallelStream().filter(f -> !ObjectUtils.isEmpty(f) && !ObjectUtils.isEmpty(f.getRemark())).map(i -> i.getRemark()).collect(Collectors.toList());
//查询当天考勤记录是否有重复的 有的 则不添加
......@@ -156,9 +149,18 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
recordHikQuery.setRemarkList(eventIds);
Set<String> eventIdSet = recordHikService.find(recordHikQuery).parallelStream().map(i -> i.getRemark()).collect(Collectors.toSet());
//去重 时分秒打卡的 也要去掉重复。
List<AttendanceRecordHikEntity> saveRecordList = attRecords.stream().filter(f -> !eventIdSet.contains(f.getRemark())).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveRecordList)) {
recordHikService.save(saveRecordList);
//单个插入 去掉重复时间段的打卡记录
for (AttendanceRecordHikEntity recordHikEntity : saveRecordList) {
try {
recordHikService.save(recordHikEntity);
} catch (Exception e) {
log.error("基础考勤数据保存异常", e.getMessage());
}
}
// recordHikService.save(saveRecordList);
}
log.info("saveRecordList size:{}", saveRecordList.size());
}
......@@ -168,20 +170,4 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
public void stopTask(ITask task) throws AppException {
}
public static void main(String[] args) {
// 获取当前时间的小时数
int hour = DateUtil.hour(new Date(), true);
// 获取当前时间所在小时的开始时间和结束时间
Date startTime = DateUtil.beginOfHour(new Date());
Date endTime = DateUtil.endOfHour(new Date());
// 格式化时间为指定格式
String startTimeStr = DateUtil.format(startTime, "yyyy-MM-dd HH:00:00");
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:59:59");
// 输出结果
System.out.println("当前时间所在小时的开始时间:" + startTimeStr);
System.out.println("当前时间所在小时的结束时间:" + endTimeStr);
}
}
package com.mortals.xhx.module.attendance.model;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
......@@ -29,6 +32,7 @@ public class AttendanceStatEntity extends AttendanceStatVo {
/**
* 员工姓名
*/
@Excel(name = "员工姓名")
private String staffName;
/**
* 所属部门
......@@ -37,6 +41,7 @@ public class AttendanceStatEntity extends AttendanceStatVo {
/**
* 所属部门名称
*/
@Excel(name = "部门名称")
private String deptName;
/**
* 回单位(天)
......@@ -312,11 +317,11 @@ public class AttendanceStatEntity extends AttendanceStatVo {
this.earlyLeaveMeeting = BigDecimal.valueOf(0);
this.year = -1;
this.year = DateUtil.year(new Date());
this.month = -1;
this.month = DateUtil.month(new Date())+1;
this.day = -1;
this.day = DateUtil.dayOfMonth(new Date());
this.remark = "";
......@@ -338,4 +343,8 @@ public class AttendanceStatEntity extends AttendanceStatVo {
this.afternoonTimes = 0;
}
public static void main(String[] args) {
System.out.println(DateUtil.dayOfMonth(new Date()));
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.attendance.dao.AttendanceRecordHikDao;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity;
import java.util.List;
/**
* AttendanceRecordHikService
*
......@@ -17,9 +19,26 @@ public interface AttendanceRecordHikService extends ICRUDService<AttendanceRecor
AttendanceRecordHikDao getDao();
/**
* 将原始数据导入打卡记录表
* @param entity
* 根据查询条件生成打卡记录
* @param attendanceRecordHikQuery
*/
void addAttendanceRecordByQuery(AttendanceRecordHikEntity attendanceRecordHikQuery, Context context) throws Exception;
/**
* 根据查询条件生成打卡记录
* @param hikEntity
*/
void addAttendanceRecord(AttendanceRecordHikEntity entity, Context context) throws Exception;
void addAttendanceRecord(AttendanceRecordHikEntity hikEntity, Context context) throws Exception;
/**
* 根据查原始记录列表生成打卡记录
* @param hikEntityList
*/
void addAttendanceRecordList(List<AttendanceRecordHikEntity> hikEntityList, Context context) throws Exception;
}
......@@ -127,7 +127,7 @@ public class AttendanceRecordHikController extends BaseCRUDJsonBodyMappingContro
if (ObjectUtils.isEmpty(hikEntity.getAttendanceDateStart())) {
throw new AppException("请选择开始日期");
}
hikService.addAttendanceRecord(hikEntity, getContext());
hikService.addAttendanceRecordByQuery(hikEntity, getContext());
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
package com.mortals.xhx.module.dept.model;
import java.math.BigDecimal;
import java.util.List;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.dept.model.vo.DeptPerformStatVo;
import lombok.Data;
/**
* 部门绩效分数统计实体对象
*
* @author zxfei
* @date 2023-07-14
*/
* 部门绩效分数统计实体对象
*
* @author zxfei
* @date 2023-07-20
*/
@Data
public class DeptPerformStatEntity extends DeptPerformStatVo {
private static final long serialVersionUID = 1L;
/**
* 部门id号
*/
* 部门id号
*/
private Long deptId;
/**
* 部门名称
*/
* 部门名称
*/
private String deptName;
/**
* 部门绩效总分数
*/
* 部门绩效总分数
*/
@Excel(name = "部门绩效总分数")
private BigDecimal totalScore;
/**
* 部门绩效加分总分数汇总
*/
* 部门绩效加分总分数汇总
*/
@Excel(name = "部门绩效加分总分数汇总")
private BigDecimal totalAddScore;
/**
* 部门绩效减分总分数汇总
*/
* 部门绩效减分总分数汇总
*/
@Excel(name = "部门绩效减分总分数汇总")
private BigDecimal totalSubScore;
/**
* 考勤绩效指标增加分数
*/
* 考勤绩效指标增加分数
*/
private BigDecimal attendScoreAdd;
/**
* 考勤绩效指标扣减分数
*/
* 考勤绩效指标扣减分数
*/
private BigDecimal attendScoreSub;
/**
* 评价绩效指标增加分数
*/
* 评价绩效指标增加分数
*/
private BigDecimal reviewScoreAdd;
/**
* 评价绩效指标扣减分数
*/
* 评价绩效指标扣减分数
*/
private BigDecimal reviewScoreSub;
/**
* 投诉绩效指标增加分数
*/
* 投诉绩效指标增加分数
*/
private BigDecimal complainScoreAdd;
/**
* 投诉绩效指标扣减分数
*/
* 投诉绩效指标扣减分数
*/
private BigDecimal complainScoreSub;
/**
* 办件绩效指标增加分数
*/
* 办件绩效指标增加分数
*/
private BigDecimal goworkScoreAdd;
/**
* 办件绩效指标扣减分数
*/
* 办件绩效指标扣减分数
*/
private BigDecimal goworkScoreSub;
/**
* 效能绩效指标增加分数
*/
* 效能绩效指标增加分数
*/
private BigDecimal effectScoreAdd;
/**
* 效能绩效指标扣减分数
*/
* 效能绩效指标扣减分数
*/
private BigDecimal effectScoreSub;
/**
* 其它绩效指标增加分数
*/
* 其它绩效指标增加分数
*/
private BigDecimal otherScoreAdd;
/**
* 其它绩效指标扣减分数
*/
* 其它绩效指标扣减分数
*/
private BigDecimal otherScoreSub;
/**
* 部门绩效平均分数,根据部门所属人数平均
*/
* 部门绩效平均分数,根据部门所属人数平均
*/
@Excel(name = "部门绩效平均分数,根据部门所属人数平均")
private BigDecimal averageScore;
/**
* 备注
*/
* 备注
*/
private String remark;
/**
* 年
*/
* 年
*/
private Integer year;
/**
* 月
*/
* 月
*/
private Integer month;
/**
* 日
*/
* 日
*/
private Integer day;
@Override
public int hashCode() {
return this.getId().hashCode();
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
......@@ -119,7 +117,7 @@ public class DeptPerformStatEntity extends DeptPerformStatVo {
if (obj instanceof DeptPerformStatEntity) {
DeptPerformStatEntity tmp = (DeptPerformStatEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
return true;
}
}
return false;
......@@ -127,48 +125,48 @@ public class DeptPerformStatEntity extends DeptPerformStatVo {
public void initAttrValue(){
this.deptId = 0L;
this.deptId = 0L;
this.deptName = "";
this.deptName = "";
this.totalScore = new BigDecimal(0);
this.totalScore = new BigDecimal(0);
this.totalAddScore = new BigDecimal(0);
this.totalAddScore = new BigDecimal(0);
this.totalSubScore = new BigDecimal(0);
this.totalSubScore = new BigDecimal(0);
this.attendScoreAdd = new BigDecimal(0);
this.attendScoreAdd = new BigDecimal(0);
this.attendScoreSub = new BigDecimal(0);
this.attendScoreSub = new BigDecimal(0);
this.reviewScoreAdd = new BigDecimal(0);
this.reviewScoreAdd = new BigDecimal(0);
this.reviewScoreSub = new BigDecimal(0);
this.reviewScoreSub = new BigDecimal(0);
this.complainScoreAdd = new BigDecimal(0);
this.complainScoreAdd = new BigDecimal(0);
this.complainScoreSub = new BigDecimal(0);
this.complainScoreSub = new BigDecimal(0);
this.goworkScoreAdd = new BigDecimal(0);
this.goworkScoreAdd = new BigDecimal(0);
this.goworkScoreSub = new BigDecimal(0);
this.goworkScoreSub = new BigDecimal(0);
this.effectScoreAdd = new BigDecimal(0);
this.effectScoreAdd = new BigDecimal(0);
this.effectScoreSub = new BigDecimal(0);
this.effectScoreSub = new BigDecimal(0);
this.otherScoreAdd = new BigDecimal(0);
this.otherScoreAdd = new BigDecimal(0);
this.otherScoreSub = new BigDecimal(0);
this.otherScoreSub = new BigDecimal(0);
this.averageScore = new BigDecimal(0);
this.averageScore = new BigDecimal(0);
this.remark = "";
this.remark = "";
this.year = -1;
this.year = DateUtil.year(new Date());
this.month = -1;
this.month = DateUtil.month(new Date())+1;
this.day = -1;
this.day = DateUtil.dayOfMonth(new Date());
}
}
\ No newline at end of file
......@@ -12,6 +12,8 @@ import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.perform.model.PerformRulesQuery;
import com.mortals.xhx.module.perform.model.vo.AppealInfo;
import com.mortals.xhx.module.perform.model.vo.AppealSummaryQuery;
......@@ -65,6 +67,8 @@ public class PerformAttendAppealController extends BaseCRUDJsonBodyMappingContro
private UserService userService;
@Autowired
private PerformRulesService rulesService;
@Autowired
private DeptService deptService;
public PerformAttendAppealController() {
......@@ -84,8 +88,9 @@ public class PerformAttendAppealController extends BaseCRUDJsonBodyMappingContro
this.addDict(model, "reviewResult", paramService.getParamBySecondOrganize("PerformAttendAppeal", "reviewResult"));
this.addDict(model, "reviewSource", paramService.getParamBySecondOrganize("PerformAttendAppeal", "reviewSource"));
this.addDict(model, "irregularType", IrregularTypeEnum.getEnumMap());
this.addDict(model, "irregularOtherType", IrregularOtherTypeEnum.getEnumMap());
this.addDict(model, "deptId", deptService.find(new DeptQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getDeptName())));
super.init(model, context);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment