diff --git a/attendance-performance-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java b/attendance-performance-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java index 2d092cf58bb228ca1e97814e7208d1d198e4ec5d..fcbedd9c850b7d0613d5933fc8af95597b31e134 100644 --- a/attendance-performance-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java +++ b/attendance-performance-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java @@ -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); diff --git a/attendance-performance-manager/src/main/java/com/mortals/xhx/common/key/RedisKey.java b/attendance-performance-manager/src/main/java/com/mortals/xhx/common/key/RedisKey.java index b4a8a4ecc055915ca49de5cbdf6673c66ddf4879..b233a70e102faa6c3d13e7888f14d0b95db4605d 100644 --- a/attendance-performance-manager/src/main/java/com/mortals/xhx/common/key/RedisKey.java +++ b/attendance-performance-manager/src/main/java/com/mortals/xhx/common/key/RedisKey.java @@ -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"; + } diff --git a/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java b/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java index f0f54a03af5a5fd26ea985f93e754ec09b79a0a8..8e4adc5dd9376dfe82088b5e20e36f09bb2464b8 100644 --- a/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java +++ b/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java @@ -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,23 +47,30 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService { @Autowired private IHikDoorService hikDoorService; + @Autowired + private AttendanceStatService attendanceStatService; @Override public void excuteTask(ITask task) throws AppException { - // syncDoorEvents(); + // 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){ - calculateAttendByDay(); - } + if (in) { + calculateAttendByDay(); + } + //缁熻褰撴棩 + log.info("缁熻褰撴棩鑰冨嫟"); + attendanceStatService.homeStat(null); + log.info("缁熻褰撴棩鑰冨嫟缁撴潫"); } + private void calculateAttendByDay() { Context context = new Context(); UserEntity userEntity = new UserEntity(); @@ -115,7 +123,7 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService { doorEventReq.setPageNo(i); doorEventReq.setPageSize(1000); doorEventsRest = hikDoorService.getDoorEvents(doorEventReq); - // log.info("doorEventsRest:{} msg:{},page:{}", doorEventsRest.getCode(), doorEventsRest.getMsg(), doorEventReq.getPageNo()); + // log.info("doorEventsRest:{} msg:{},page:{}", doorEventsRest.getCode(), doorEventsRest.getMsg(), doorEventReq.getPageNo()); getDoorEvents(doorEventsRest); } } diff --git a/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/AttendanceStatService.java b/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/AttendanceStatService.java index 4963556dfa118712f6f146e6be3395704ef8f5ce..402a75cd3dd26fa96969dd62f689469af96eee73 100644 --- a/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/AttendanceStatService.java +++ b/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/AttendanceStatService.java @@ -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 diff --git a/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/impl/AttendanceStatServiceImpl.java b/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/impl/AttendanceStatServiceImpl.java index eb061aceab4724c42b2c4634ba3e501a387ef3c5..3e7a673130b05f0aea69bc960b22f44f2a10cbd2 100644 --- a/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/impl/AttendanceStatServiceImpl.java +++ b/attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/impl/AttendanceStatServiceImpl.java @@ -1,37 +1,49 @@ package com.mortals.xhx.module.attendance.service.impl; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.Result; +import com.mortals.framework.service.ICacheService; import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.StringUtils; +import com.mortals.xhx.common.code.GoWorkResultEnum; import com.mortals.xhx.common.code.LeaveTypeEnum; +import com.mortals.xhx.common.code.OffWorkResultEnum; +import com.mortals.xhx.common.code.ProcessStatusEnum; +import com.mortals.xhx.common.key.RedisKey; +import com.mortals.xhx.common.pdu.HomeStatInfo; import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.module.attendance.dao.AttendanceSummaryDao; -import com.mortals.xhx.module.attendance.model.AttendanceStaffStatEntity; -import com.mortals.xhx.module.attendance.model.AttendanceStaffStatQuery; -import com.mortals.xhx.module.attendance.model.AttendanceStatQuery; +import com.mortals.xhx.module.attendance.model.*; import com.mortals.xhx.module.attendance.model.vo.AttendanceSummaryQuery; import com.mortals.xhx.module.attendance.model.vo.ErrorSummaryVo; import com.mortals.xhx.module.attendance.model.vo.LeaveSummaryVo; import com.mortals.xhx.module.attendance.model.vo.VacationBalanceSummaryVo; +import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService; +import com.mortals.xhx.module.attendance.service.AttendanceRecordService; import com.mortals.xhx.module.attendance.service.AttendanceStaffStatService; +import com.mortals.xhx.module.dept.model.DeptQuery; +import com.mortals.xhx.module.dept.service.DeptService; import com.mortals.xhx.module.holiday.model.HolidayEntity; import com.mortals.xhx.module.holiday.model.HolidayQuery; import com.mortals.xhx.module.holiday.service.HolidayService; +import com.mortals.xhx.module.staff.model.StaffQuery; +import com.mortals.xhx.module.staff.service.StaffService; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.cache.CacheProperties; import org.springframework.stereotype.Service; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.exception.AppException; import com.mortals.framework.model.Context; import com.mortals.xhx.module.attendance.dao.AttendanceStatDao; -import com.mortals.xhx.module.attendance.model.AttendanceStatEntity; import com.mortals.xhx.module.attendance.service.AttendanceStatService; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -52,6 +64,19 @@ public class AttendanceStatServiceImpl extends AbstractCRUDServiceImpl<Attendanc @Autowired private HolidayService holidayService; + @Autowired + private StaffService staffService; + @Autowired + private DeptService deptService; + + @Autowired + private AttendanceRecordService recordService; + + @Autowired + private AttendanceLeaveRecordService leaveRecordService; + @Autowired + private ICacheService cacheService; + @Override protected void findAfter(AttendanceStatEntity entity, Context context, List<AttendanceStatEntity> list) throws AppException { // DateUtil.parse(entity.getStartTime()).year(); @@ -169,12 +194,12 @@ public class AttendanceStatServiceImpl extends AbstractCRUDServiceImpl<Attendanc holidayQuery.setStartTimeStart(query.getSummaryTime()); holidayQuery.setStartTimeEnd(query.getSummaryTime()); HolidayEntity holidayEntity = holidayService.selectOne(holidayQuery); - if(holidayEntity!=null){ - if(holidayEntity.getWorkorholiday()==0){ + if (holidayEntity != null) { + if (holidayEntity.getWorkorholiday() == 0) { //鐗瑰畾鑺傚亣鏃� isReturn = true; } - }else { + } else { //鍒ゆ柇鏄惁涓哄懆鏈� Calendar calendar = Calendar.getInstance(); calendar.setTime(DateUtils.StrToDate(query.getSummaryTime())); @@ -189,7 +214,7 @@ public class AttendanceStatServiceImpl extends AbstractCRUDServiceImpl<Attendanc //褰撳ぉ涓嶇粺璁� isReturn = true; } - if(isReturn){ + if (isReturn) { return; } log.info("寮€濮嬫眹鎬籟" + query.getSummaryTime() + "]鑰冨嫟....."); @@ -231,7 +256,7 @@ public class AttendanceStatServiceImpl extends AbstractCRUDServiceImpl<Attendanc if (temp != null) { BeanUtils.copyProperties(item, temp, BeanUtil.getNullPropertyNames(item)); temp.setGoTimes(0); //榛樿鍙鏈夊紓甯歌€冨嫟锛屽綋澶╁氨涓嶇畻鍏ㄥ嫟 - if(item.getMorningTimes()>0){ + if (item.getMorningTimes() > 0) { temp.setNonCompliancePunch(new BigDecimal(item.getMorningTimes())); } this.dao.update(temp); @@ -432,4 +457,120 @@ public class AttendanceStatServiceImpl extends AbstractCRUDServiceImpl<Attendanc return result; } + @Override + public void homeStat(Context context) throws AppException { + HomeStatInfo homeStatInfo = new HomeStatInfo(); + + + StaffQuery staffQuery = new StaffQuery(); + staffQuery.setStatusNotList(Arrays.asList(3)); + + int totalPersonNum = staffService.count(staffQuery, context); + homeStatInfo.setTotalPersonNum(totalPersonNum); + staffQuery.setSource(1); + + + Integer totalAttendPersonNum = staffService.count(staffQuery, context); + + int totalDeptNum = deptService.count(new DeptQuery(), context); + homeStatInfo.setTotalDeptNum(totalDeptNum); + + AttendanceRecordHikQuery hikQuery = new AttendanceRecordHikQuery(); +/* hikQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr()); + hikQuery.setAttendanceDateEnd(DateUtil.today()); */ + hikQuery.setAttendanceDateStart(DateUtil.yesterday().toDateStr()); + hikQuery.setAttendanceDateEnd(DateUtil.yesterday().toDateStr()); + + + AttendanceRecordQuery attendanceRecordQuery = new AttendanceRecordQuery(); + // attendanceRecordQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr()); + //attendanceRecordQuery.setAttendanceDateEnd(DateUtil.today()); + attendanceRecordQuery.setAttendanceDateStart(DateUtil.yesterday().toDateStr()); + attendanceRecordQuery.setAttendanceDateEnd(DateUtil.yesterday().toDateStr()); + List<AttendanceRecordEntity> attendanceRecordEntities = recordService.find(attendanceRecordQuery); + + + //鑾峰彇褰撴湀鎵撳崱浜烘暟锛屽鏋滃瓨鍦� +/* 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); + 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); + }*/ + + + //杩熷埌娆℃暟 + long beLate = attendanceRecordEntities.parallelStream() + .flatMap(item -> item.getAttendanceRecordDetailList().stream()) + .filter(f -> GoWorkResultEnum.杩熷埌.getValue() == f.getGoWorkResult() || OffWorkResultEnum.杩熷埌.getValue() == f.getOffWorkResult()) + .map(i -> i.getStaffId()) + .distinct() + .count(); + + //鏃╅€€娆℃暟 + long leaveEarly = attendanceRecordEntities.parallelStream() + .flatMap(item -> item.getAttendanceRecordDetailList().stream()) + .filter(f -> GoWorkResultEnum.鏃╅€€.getValue() == f.getGoWorkResult() || OffWorkResultEnum.鏃╅€€.getValue() == f.getOffWorkResult()) + .map(i -> i.getStaffId()) + .distinct() + .count(); + + //缂哄崱娆℃暟 + long lackOfCards = attendanceRecordEntities.parallelStream() + .flatMap(item -> item.getAttendanceRecordDetailList().stream()) + .filter(f -> GoWorkResultEnum.缂哄崱.getValue() == f.getGoWorkResult() || OffWorkResultEnum.缂哄崱.getValue() == f.getOffWorkResult()) + .map(i -> i.getStaffId()) + .distinct() + .count(); + + +/* AttendanceVacationRecordQuery vacationRecordQuery = new AttendanceVacationRecordQuery(); + vacationRecordQuery.setCreateTimeStart(DateUtil.beginOfMonth(new Date()).toDateStr()); + vacationRecordQuery.setCreateTimeEnd(DateUtil.today()); + int levealPersonNum = vacationRecordService.count(vacationRecordQuery, getContext());*/ + + AttendanceLeaveRecordQuery leaveRecordQuery = new AttendanceLeaveRecordQuery(); +/* 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()); + int levealPersonNum = leaveRecordService.count(leaveRecordQuery, context); + + + //鎬绘墦鍗¤褰� +/* 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();*/ + //寮傚父鑰冨嫟璁板綍 + //鏈€冨嫟 + // long noAtt=lackOfCards; + long att = totalAttendPersonNum - lackOfCards; + // long att = totalAttend - lackOfCardsAttend; + if (att != 0L) { + + BigDecimal bigDecimal = new BigDecimal(att).divide(new BigDecimal(totalAttendPersonNum), 4, BigDecimal.ROUND_CEILING).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_CEILING); + homeStatInfo.setAttendRadio(bigDecimal.toString() + "%"); + } else { + homeStatInfo.setAttendRadio("0%"); + } + + homeStatInfo.setLevealPersonNum(levealPersonNum); + homeStatInfo.setLatePersonNum(beLate); + homeStatInfo.setLeftEarlyPersonNum(leaveEarly); + homeStatInfo.setMissCardPersonNum(lackOfCards); + homeStatInfo.setAttendPersonNum(totalAttendPersonNum); + + cacheService.set(RedisKey.KEY_HOME_STAT_CACHE, JSON.toJSONString(homeStatInfo)); + + } + } \ No newline at end of file