Commit e7c701b6 authored by 赵啸非's avatar 赵啸非

测试多线程优化考勤计算

parent 1259cd2d
...@@ -276,120 +276,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -276,120 +276,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
} }
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
String token = authTokenService.getToken(request); String token = authTokenService.getToken(request);
HomeStatInfo homeStatInfo = cacheService.get(RedisKey.KEY_HOME_STAT_CACHE, HomeStatInfo.class); HomeStatInfo homeStatInfo = cacheService.get(RedisKey.KEY_HOME_STAT_CACHE, HomeStatInfo.class);
/* HomeStatInfo homeStatInfo = new HomeStatInfo();
StaffQuery staffQuery = new StaffQuery();
staffQuery.setStatusNotList(Arrays.asList(3));
int totalPersonNum = staffService.count(staffQuery, this.getContext());
homeStatInfo.setTotalPersonNum(totalPersonNum);
staffQuery.setSource(1);
Integer totalAttendPersonNum = staffService.count(staffQuery, this.getContext());
int totalDeptNum = deptService.count(new DeptQuery(), getContext());
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, getContext());
//总打卡记录
*//* 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);*/
data.put("homeStat", homeStatInfo); data.put("homeStat", homeStatInfo);
data.put("token", token); data.put("token", token);
data.put("currUserName", currUserName); data.put("currUserName", currUserName);
......
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
*
*
* @author zxfei
*/
public enum SourceEnum {
海康(1, "海康"),
自定义(2, "自定义");
private Integer value;
private String desc;
SourceEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static SourceEnum getByValue(Integer value) {
for (SourceEnum sourceEnum : SourceEnum.values()) {
if (sourceEnum.getValue() == value) {
return sourceEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (SourceEnum item : SourceEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
...@@ -80,29 +80,20 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -80,29 +80,20 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
private UserService userService; private UserService userService;
@Autowired @Autowired
private DeptService deptService; private DeptService deptService;
@Autowired @Autowired
private RoleUserService roleUserService; private RoleUserService roleUserService;
@Autowired @Autowired
private IHikPersonService hikPersonService; private IHikPersonService hikPersonService;
@Autowired @Autowired
private AttendanceStatService attendanceStatService; private AttendanceStatService attendanceStatService;
@Autowired @Autowired
private AttendanceVacationBalanceService balanceService; private AttendanceVacationBalanceService balanceService;
@Autowired @Autowired
private IdgeneratorService idgeneratorService;
@Autowired
private StaffLeaveService staffLeaveService; private StaffLeaveService staffLeaveService;
@Autowired @Autowired
private AttendanceGroupStaffService attendanceGroupStaffService;
@Autowired
private DoorService doorService; private DoorService doorService;
@Autowired @Autowired
private IHikStaffService hikStaffService; private IHikStaffService hikStaffService;
@Autowired @Autowired
private UploadService uploadService; private UploadService uploadService;
@Autowired @Autowired
...@@ -114,7 +105,6 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -114,7 +105,6 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
protected String getExtKey(StaffEntity data) { protected String getExtKey(StaffEntity data) {
//工号作为redis 扩展key //工号作为redis 扩展key
return StrUtil.padPre(data.getWorkNum(), 8, "0"); return StrUtil.padPre(data.getWorkNum(), 8, "0");
// return "1000"+data.getWorkNum();
} }
@Override @Override
...@@ -132,12 +122,10 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -132,12 +122,10 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
if (count > 0) { if (count > 0) {
throw new AppException("工号重复!工号:" + entity.getWorkNum()); throw new AppException("工号重复!工号:" + entity.getWorkNum());
} }
if (!ObjectUtils.isEmpty(entity.getDeptId())) { if (!ObjectUtils.isEmpty(entity.getDeptId())) {
DeptEntity deptEntity = deptService.get(entity.getDeptId()); DeptEntity deptEntity = deptService.get(entity.getDeptId());
entity.setDeptName(deptEntity == null ? "" : deptEntity.getDeptName()); entity.setDeptName(deptEntity == null ? "" : deptEntity.getDeptName());
} }
} }
...@@ -177,16 +165,14 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -177,16 +165,14 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
@Override @Override
public Rest<Void> syncPersons(Context context) { public Rest<Void> syncPersons(Context context) {
log.info("同步人员!"); log.info("同步人员!");
PersonReq personReq = new PersonReq(); PersonReq personReq = new PersonReq();
personReq.setPageNo(1); personReq.setPageNo(1);
personReq.setPageSize(1000); personReq.setPageSize(1000);
Rest<PersonDataInfo> personRest = hikPersonService.getPersonList(personReq); Rest<PersonDataInfo> personRest = hikPersonService.getPersonList(personReq);
if (personRest.getCode() == YesNoEnum.YES.getValue()) { if (personRest.getCode() == YesNoEnum.YES.getValue()) {
//做差集 更新本地用户为离职员工 //做差集 更新本地用户为离职员工
StaffQuery staffQuery = new StaffQuery(); StaffQuery staffQuery = new StaffQuery();
staffQuery.setSource(1); staffQuery.setSource(SourceEnum.海康.getValue());
staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue())); staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue()));
Map<String, StaffEntity> staffCollect = this.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n)); Map<String, StaffEntity> staffCollect = this.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n));
...@@ -249,6 +235,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -249,6 +235,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
} }
} }
staffEntity.setStatus(StaffSatusEnum.正式.getValue()); staffEntity.setStatus(StaffSatusEnum.正式.getValue());
staffEntity.setSource(SourceEnum.海康.getValue());
staffEntity.setName(personInfo.getPersonName()); staffEntity.setName(personInfo.getPersonName());
staffEntity.setRemarkId(personInfo.getPersonId()); staffEntity.setRemarkId(personInfo.getPersonId());
staffEntity.setPicUri(personInfo.getPersonPhoto() == null ? "" : personInfo.getPersonPhoto().getPicUri()); staffEntity.setPicUri(personInfo.getPersonPhoto() == null ? "" : personInfo.getPersonPhoto().getPicUri());
...@@ -561,7 +548,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -561,7 +548,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
log.info("同步人员!"); log.info("同步人员!");
//todo 门禁获取人员 //todo 门禁获取人员
StaffQuery staffQuery = new StaffQuery(); StaffQuery staffQuery = new StaffQuery();
staffQuery.setSource(1); staffQuery.setSource(SourceEnum.海康.getValue());
staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue())); staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue()));
Map<String, StaffEntity> staffCollect = this.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n)); Map<String, StaffEntity> staffCollect = this.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n));
......
...@@ -10,10 +10,7 @@ import com.mortals.framework.model.Context; ...@@ -10,10 +10,7 @@ import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol; import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.GoWorkResultEnum; import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.code.OffWorkResultEnum;
import com.mortals.xhx.common.code.ProcessStatusEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.attendance.model.*; import com.mortals.xhx.module.attendance.model.*;
import com.mortals.xhx.module.attendance.model.vo.AttendStatInfo; import com.mortals.xhx.module.attendance.model.vo.AttendStatInfo;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService; import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
...@@ -108,7 +105,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ ...@@ -108,7 +105,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
@Override @Override
protected void saveBefore(StaffEntity entity, Map<String, Object> model, Context context) throws AppException { protected void saveBefore(StaffEntity entity, Map<String, Object> model, Context context) throws AppException {
entity.setSource(2); entity.setSource(SourceEnum.自定义.getValue());
//判断手机号码是否包含* 如果包含则不添加更新 //判断手机号码是否包含* 如果包含则不添加更新
if (!entity.newEntity() && !ObjectUtils.isEmpty(entity.getPhoneNumber()) && StrUtil.contains(entity.getPhoneNumber(), "*")) { if (!entity.newEntity() && !ObjectUtils.isEmpty(entity.getPhoneNumber()) && StrUtil.contains(entity.getPhoneNumber(), "*")) {
entity.setPhoneNumber(null); entity.setPhoneNumber(null);
......
...@@ -37,8 +37,8 @@ POST {{baseUrl}}/attendance/record/hik/addAttendanceRecord ...@@ -37,8 +37,8 @@ POST {{baseUrl}}/attendance/record/hik/addAttendanceRecord
Content-Type: application/json Content-Type: application/json
{ {
"attendanceDateStart": "2024-07-21", "attendanceDateStart": "2024-06-01",
"attendanceDateEnd": "2024-08-15" "attendanceDateEnd": "2024-06-30"
} }
###海康考勤打卡记录计算1 ###海康考勤打卡记录计算1
...@@ -48,7 +48,7 @@ Content-Type: application/json ...@@ -48,7 +48,7 @@ Content-Type: application/json
{ {
"attendanceDateStart": "2024-06-01", "attendanceDateStart": "2024-06-01",
"attendanceDateEnd": "2024-06-31", "attendanceDateEnd": "2024-06-31",
"staffId": 447 "staffIdList": [484,234,584,507,561,346,349,196,482,447]
} }
......
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