Commit 58f8cd80 authored by 姬鋆屾's avatar 姬鋆屾
parents c5684aa6 494272f1
......@@ -190,7 +190,10 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
JSONObject data = new JSONObject();
String token = authTokenService.getToken(request);
HomeStatInfo homeStatInfo = new HomeStatInfo();
HomeStatInfo homeStatInfo = cacheService.get(RedisKey.KEY_HOME_STAT_CACHE, HomeStatInfo.class);
/* HomeStatInfo homeStatInfo = new HomeStatInfo();
StaffQuery staffQuery = new StaffQuery();
......@@ -207,8 +210,8 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
homeStatInfo.setTotalDeptNum(totalDeptNum);
AttendanceRecordHikQuery hikQuery = new AttendanceRecordHikQuery();
/* hikQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr());
hikQuery.setAttendanceDateEnd(DateUtil.today()); */
*//* hikQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr());
hikQuery.setAttendanceDateEnd(DateUtil.today()); *//*
hikQuery.setAttendanceDateStart(DateUtil.yesterday().toDateStr());
hikQuery.setAttendanceDateEnd(DateUtil.yesterday().toDateStr());
......@@ -222,17 +225,17 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
//获取当月打卡人数,如果存在
/* Long totalCache = cacheService.hget(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.format(new Date(), "yyyy-MM"), Long.class);
*//* Long totalCache = cacheService.hget(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.format(new Date(), "yyyy-MM"), Long.class);
if (ObjectUtils.isEmpty(totalCache)) {
totalCache = recordHikService.find(hikQuery).parallelStream().map(item -> item.getStaffId()).distinct().count();
cacheService.hset(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.format(new Date(), "yyyy-MM"), totalCache);
}*/
}*//*
/* Long totalCache = cacheService.hget(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.yesterday().toDateStr(), Long.class);
*//* Long totalCache = cacheService.hget(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.yesterday().toDateStr(), Long.class);
if (ObjectUtils.isEmpty(totalCache)) {
totalCache = recordHikService.find(hikQuery).parallelStream().map(item -> item.getStaffId()).distinct().count();
cacheService.hset(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.yesterday().toDateStr(), totalCache);
}*/
}*//*
//迟到次数
......@@ -260,14 +263,14 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
.count();
/* AttendanceVacationRecordQuery vacationRecordQuery = new AttendanceVacationRecordQuery();
*//* AttendanceVacationRecordQuery vacationRecordQuery = new AttendanceVacationRecordQuery();
vacationRecordQuery.setCreateTimeStart(DateUtil.beginOfMonth(new Date()).toDateStr());
vacationRecordQuery.setCreateTimeEnd(DateUtil.today());
int levealPersonNum = vacationRecordService.count(vacationRecordQuery, getContext());*/
int levealPersonNum = vacationRecordService.count(vacationRecordQuery, getContext());*//*
AttendanceLeaveRecordQuery leaveRecordQuery = new AttendanceLeaveRecordQuery();
/* leaveRecordQuery.setCreateTimeStart(DateUtil.beginOfMonth(new Date()).toDateStr());
leaveRecordQuery.setCreateTimeEnd(DateUtil.today());*/
*//* leaveRecordQuery.setCreateTimeStart(DateUtil.beginOfMonth(new Date()).toDateStr());
leaveRecordQuery.setCreateTimeEnd(DateUtil.today());*//*
leaveRecordQuery.setCreateTimeStart(DateUtil.yesterday().toDateStr());
leaveRecordQuery.setCreateTimeEnd(DateUtil.yesterday().toDateStr());
leaveRecordQuery.setProcessStatus(ProcessStatusEnum.已处理.getValue());
......@@ -275,12 +278,12 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
//总打卡记录
/* long totalAttend = attendanceRecordEntities.parallelStream().flatMap(item -> item.getAttendanceRecordDetailList().parallelStream()).count();
*//* long totalAttend = attendanceRecordEntities.parallelStream().flatMap(item -> item.getAttendanceRecordDetailList().parallelStream()).count();
long lackOfCardsAttend = attendanceRecordEntities.parallelStream()
.flatMap(item -> item.getAttendanceRecordDetailList().stream())
.filter(f -> GoWorkResultEnum.缺卡.getValue() == f.getGoWorkResult() || OffWorkResultEnum.缺卡.getValue() == f.getOffWorkResult())
.count();*/
.count();*//*
//异常考勤记录
//未考勤
// long noAtt=lackOfCards;
......@@ -298,7 +301,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
homeStatInfo.setLatePersonNum(beLate);
homeStatInfo.setLeftEarlyPersonNum(leaveEarly);
homeStatInfo.setMissCardPersonNum(lackOfCards);
homeStatInfo.setAttendPersonNum(totalAttendPersonNum);
homeStatInfo.setAttendPersonNum(totalAttendPersonNum);*/
data.put("homeStat", homeStatInfo);
data.put("token", token);
......
......@@ -26,4 +26,7 @@ public class RedisKey {
/** 考勤统计 **/
public static final String KEY_ATTENDANCE_STAT_CACHE = "attendance:stat";
public static final String KEY_HOME_STAT_CACHE = "attendance:home:stat";
}
......@@ -15,6 +15,7 @@ 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.attendance.service.AttendanceStatService;
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;
......@@ -46,6 +47,8 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
@Autowired
private IHikDoorService hikDoorService;
@Autowired
private AttendanceStatService attendanceStatService;
@Override
......@@ -53,16 +56,21 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
// syncDoorEvents();
//判断时间段 不在时间段的 不做计算
//早上9点 子晚上8点 计算
Date beginDateTime=DateUtil.parseDateTime(DateUtil.today()+" 09:00:00");
Date endDateTime=DateUtil.parseDateTime(DateUtil.today()+" 20:30:00");
Date beginDateTime = DateUtil.parseDateTime(DateUtil.today() + " 09:00:00");
Date endDateTime = DateUtil.parseDateTime(DateUtil.today() + " 20:30:00");
boolean in = DateUtil.isIn(new Date(), beginDateTime, endDateTime);
if(in){
if (in) {
calculateAttendByDay();
}
//统计当日
log.info("统计当日考勤");
attendanceStatService.homeStat(null);
log.info("统计当日考勤结束");
}
private void calculateAttendByDay() {
Context context = new Context();
UserEntity userEntity = new UserEntity();
......
......@@ -24,4 +24,8 @@ public interface AttendanceStatService extends ICRUDService<AttendanceStatEntity
void doAttendanceSummary(AttendanceSummaryQuery query);
Result<AttendanceStatEntity> findExt(AttendanceSummaryQuery params, PageInfo pageInfo, Context context) throws AppException;
void homeStat(Context context) throws AppException;
}
\ No newline at end of file
package com.mortals.xhx.module.attendance.web;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ReflectUtil;
import com.alibaba.fastjson.JSONObject;
......@@ -50,6 +51,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
......@@ -338,16 +342,55 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
super.doListBefore(query, model, context);
}
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object,Boolean> seen = new ConcurrentHashMap<>();
//putIfAbsent方法添加键值对,如果map集合中没有该key对应的值,则直接添加,并返回null,如果已经存在对应的值,则依旧为原来的值。
//如果返回null表示添加数据成功(不重复),不重复(null==null :TRUE)
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
@Override
protected int doListAfter(AttendanceRecordEntity query, Map<String, Object> model, Context context) throws AppException {
List<AttendanceRecordEntity> list = (List<AttendanceRecordEntity>) model.get(KEY_RESULT_DATA);
//求出列表中最多detail 的 添加动态列
List<AttendanceRecordDetailEntity> collect = list.parallelStream()
.flatMap(item -> item.getAttendanceRecordDetailList().stream())
.distinct()
.filter(distinctByKey(f->f.getOrderNum()))
.sorted(Comparator.comparingInt(AttendanceRecordDetailEntity::getOrderNum))
.collect(Collectors.toList());
//list.parallelStream().collect(Collectors.groupingBy())
List<AttDsyncColumn> dsyncColumns = new ArrayList<>();
/* for (int i = 1; i <= collect.size(); i++) {
AttDsyncColumn attDsyncColumn = new AttDsyncColumn();
attDsyncColumn.setName(String.format("上班%s打卡时间", i));
attDsyncColumn.setProperty("goWorkDate");
attDsyncColumn.setOrderNum(i);
dsyncColumns.add(attDsyncColumn);
attDsyncColumn = new AttDsyncColumn();
attDsyncColumn.setName(String.format("上班%s打卡结果", i));
attDsyncColumn.setProperty("goWorkResult");
attDsyncColumn.setOrderNum(i);
dsyncColumns.add(attDsyncColumn);
attDsyncColumn = new AttDsyncColumn();
attDsyncColumn.setName(String.format("下班%s打卡时间", i));
attDsyncColumn.setProperty("offWorkDate");
attDsyncColumn.setOrderNum(i);
dsyncColumns.add(attDsyncColumn);
attDsyncColumn = new AttDsyncColumn();
attDsyncColumn.setName(String.format("下班%s打卡结果",i));
attDsyncColumn.setProperty("offWorkResult");
attDsyncColumn.setOrderNum(i);
dsyncColumns.add(attDsyncColumn);
}*/
collect.forEach(item -> {
AttDsyncColumn attDsyncColumn = new AttDsyncColumn();
attDsyncColumn.setName(String.format("上班%s打卡时间", item.getOrderNum()));
......@@ -391,7 +434,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (ObjectUtils.isEmpty(addDetailList)) {
if (!ObjectUtils.isEmpty(addDetailList)) {
recordEntity.getAttendanceRecordDetailList().addAll(addDetailList);
List<AttendanceRecordDetailEntity> orderList = recordEntity.getAttendanceRecordDetailList().stream().sorted(Comparator.comparingInt(AttendanceRecordDetailEntity::getOrderNum))
.collect(Collectors.toList());
......@@ -399,57 +442,6 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
}
}
model.put("dyncColumns", dsyncColumns);
/* //出勤情况
//总人数
Integer total = (Integer)model.get("total");
//未出勤
Integer noAtt = 0;
//迟到
Integer beLate = 0;
//早退
Integer leaveEarly = 0;
//缺卡
Integer lackOfCards = 0;
for (AttendanceRecordEntity attendanceRecordEntity : list) {
boolean a = true;
for (AttendanceRecordDetailEntity item : attendanceRecordEntity.getAttendanceRecordDetailList()) {
if (item.getGoWorkResult()==3){
lackOfCards=lackOfCards+1;
}
if (item.getGoWorkResult()==4){
beLate = beLate+1;
}
if (item.getOffWorkResult()==3){
lackOfCards=lackOfCards+1;
}
if (item.getOffWorkResult()==5){
leaveEarly = leaveEarly +1;
}
if (item.getGoWorkResult()!=3 || item.getOffWorkResult()!=3){
a = false;
}
}
if (a){
noAtt = noAtt+1;
}
}
String attPercentage = "";
if (total!=0){
float l = ((total - noAtt) / total)*100;
attPercentage =l+"%";
}else {
attPercentage = "0";
}
AttendanceStatus attendanceStatus = new AttendanceStatus();
attendanceStatus.setNeedAttNum(total);
attendanceStatus.setAttPercentage(attPercentage);
attendanceStatus.setNoAtt(noAtt);
attendanceStatus.setBeLate(beLate);
attendanceStatus.setLeaveEarly(leaveEarly);
attendanceStatus.setLackOfCards(lackOfCards);
model.put("attendanceStatus",attendanceStatus);*/
return super.doListAfter(query, 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