|
@@ -29,6 +29,8 @@ import java.io.FileOutputStream;
|
|
|
import java.time.*;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.startsWith;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -225,7 +227,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getUserCheckInDayData(int companyId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
|
|
|
+ public HttpRespMsg getUserCheckInDayData(int companyId, String userId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
WxCorpInfo corpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
if (corpInfo == null) {
|
|
@@ -248,11 +250,23 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
reqParam.put("starttime", startTime);
|
|
|
reqParam.put("endtime", endTime);
|
|
|
|
|
|
- //获取企业下的全部员工
|
|
|
- List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).isNotNull("corpwx_userid").eq("is_active", 1));
|
|
|
- System.out.println("users size=="+users.size());
|
|
|
- Object[] objects = users.stream().map(User::getCorpwxUserid).toArray();
|
|
|
- reqParam.put("useridlist", objects);
|
|
|
+
|
|
|
+ if (userId == null) {
|
|
|
+ //获取企业下的全部员工
|
|
|
+ List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).isNotNull("corpwx_userid").eq("is_active", 1));
|
|
|
+ System.out.println("获取考勤记录users size=="+users.size());
|
|
|
+ Object[] objects = users.stream().map(User::getCorpwxUserid).toArray();
|
|
|
+ System.out.println(objects);
|
|
|
+ reqParam.put("useridlist", objects);
|
|
|
+ } else {
|
|
|
+ //指定获取员工
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ Object[] objects = new Object[1];
|
|
|
+ objects[0] = user.getCorpwxUserid();
|
|
|
+ reqParam.put("useridlist", objects);
|
|
|
+ System.out.println("获取corpwxuserid=="+user.getCorpwxUserid()+"的考勤记录");
|
|
|
+ }
|
|
|
+
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
|
|
|
ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
HttpMethod.POST, requestEntity, String.class);
|
|
@@ -283,9 +297,53 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
int regular_work_sec = summary_info.getIntValue("regular_work_sec");//秒
|
|
|
Integer standard_work_sec = summary_info.getInteger("standard_work_sec");
|
|
|
|
|
|
+
|
|
|
ct.setStartTime(DateTimeUtil.getTimeFromSeconds(sTime));
|
|
|
ct.setEndTime(DateTimeUtil.getTimeFromSeconds(eTime));
|
|
|
- ct.setCardTime(DateTimeUtil.getHoursFromSeconds(regular_work_sec));
|
|
|
+
|
|
|
+ JSONArray holidayItems = jsonObject.getJSONArray("holiday_infos");
|
|
|
+ if (eTime == sTime) {
|
|
|
+ //开始时间和结束时间一样,说明下班没有打卡,需要提取请假的最晚时间作为下班打卡时间
|
|
|
+ String lastestOffworkTime = null;
|
|
|
+ for (int t=0;t<holidayItems.size(); t++) {
|
|
|
+ JSONObject holiday = holidayItems.getJSONObject(t);
|
|
|
+ JSONObject spTitle = holiday.getJSONObject("sp_title");
|
|
|
+ JSONArray data = spTitle.getJSONArray("data");
|
|
|
+ for (int m=0;m<data.size(); m++) {
|
|
|
+ String leaveText = data.getJSONObject(m).getString("text");
|
|
|
+ if (leaveText.startsWith("请假")) {
|
|
|
+ //获取对应位置的请假时间段
|
|
|
+ String string = holiday.getJSONObject("sp_description").getJSONArray("data").getJSONObject(m).getString("text");
|
|
|
+ String[] s = string.split(" ");
|
|
|
+ //获取到请假的开始时间和结束时间
|
|
|
+ String leaveEnd = s[4];
|
|
|
+ if (leaveEnd.equals("下午")) {
|
|
|
+ leaveEnd = "13:00";//请假的下班打卡时间,算上午结束的时间
|
|
|
+ }
|
|
|
+ if (lastestOffworkTime == null || leaveEnd.compareTo(lastestOffworkTime) > 0) {
|
|
|
+ lastestOffworkTime = leaveEnd;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lastestOffworkTime != null) {
|
|
|
+ ct.setEndTime(lastestOffworkTime);
|
|
|
+ //重新计算打卡时长
|
|
|
+
|
|
|
+ regular_work_sec = DateTimeUtil.getSecondsFromTime(lastestOffworkTime) - sTime;
|
|
|
+ if (lastestOffworkTime.compareTo("13:00") > 0) {
|
|
|
+ //下午请假的,减掉午休的一小时
|
|
|
+ regular_work_sec -= 3600;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //打卡时间先要四舍五入
|
|
|
+ double hoursFromSeconds = DateTimeUtil.getHoursFromSeconds(regular_work_sec);
|
|
|
+ System.out.println("打卡间隔时长为=="+hoursFromSeconds);
|
|
|
+ double hoursFromDouble = DateTimeUtil.getHoursFromDouble(hoursFromSeconds);
|
|
|
+ System.out.println("四舍五入后cardTime时间=="+hoursFromDouble);
|
|
|
+ ct.setCardTime(hoursFromDouble);
|
|
|
+
|
|
|
ct.setName(name);
|
|
|
//解析请假和外出的情况
|
|
|
JSONArray sp_items = jsonObject.getJSONArray("sp_items");
|
|
@@ -311,6 +369,35 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ //获取假期详情
|
|
|
+ //获取请假的最早和最晚时间
|
|
|
+ for (int t=0;t<holidayItems.size(); t++) {
|
|
|
+ JSONObject holiday = holidayItems.getJSONObject(t);
|
|
|
+ JSONObject spTitle = holiday.getJSONObject("sp_title");
|
|
|
+ JSONArray data = spTitle.getJSONArray("data");
|
|
|
+ for (int m=0;m<data.size(); m++) {
|
|
|
+ String leaveText = data.getJSONObject(m).getString("text");
|
|
|
+ if (leaveText.startsWith("请假")) {
|
|
|
+ //获取对应位置的请假时间段
|
|
|
+ String string = holiday.getJSONObject("sp_description").getJSONArray("data").getJSONObject(m).getString("text");
|
|
|
+ String[] s = string.split(" ");
|
|
|
+ //获取到请假的开始时间和结束时间
|
|
|
+ String leaveStart = s[1];
|
|
|
+ String leaveEnd = s[4];
|
|
|
+
|
|
|
+ //检查请假时间段是否在打卡的时间范围内
|
|
|
+ if ("上午".equals(leaveEnd) || "下午".equals(leaveEnd)) {
|
|
|
+ //上下午请假, 上面已经处理过结束时间为请假之前的时间了,此处不需要再处理了
|
|
|
+ System.out.println("====请假 = " + leaveEnd);
|
|
|
+ } else if (ct.getStartTime().compareTo(leaveStart) <= 0 && ct.getEndTime().compareTo(leaveEnd) >= 0) {
|
|
|
+ String hourLeaveTime = leaveText.replaceAll("请假", "").replaceAll("小时", "");
|
|
|
+ System.out.println("请假时长=" + hourLeaveTime);
|
|
|
+ ct.setCardTime(ct.getCardTime() - Double.parseDouble(hourLeaveTime));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
if (regular_work_sec < standard_work_sec) {
|
|
|
ct.setWorkHours(ct.getCardTime() + ct.getOutdoorTime());
|
|
|
} else {
|