|
@@ -1,10 +1,30 @@
|
|
|
package com.management.platform.controller;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.ApplyForm;
|
|
|
+import com.management.platform.entity.Attendance;
|
|
|
+import com.management.platform.entity.AttendanceStaff;
|
|
|
+import com.management.platform.entity.User;
|
|
|
+import com.management.platform.service.ApplyFormService;
|
|
|
+import com.management.platform.service.AttendanceService;
|
|
|
+import com.management.platform.service.UserService;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 前端控制器
|
|
@@ -17,5 +37,83 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RequestMapping("/apply-form")
|
|
|
public class ApplyFormController {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ApplyFormService applyFormService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AttendanceService attendanceService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @RequestMapping("/synchrodataToAttendance")
|
|
|
+ public HttpRespMsg synchrodataToAttendance(String month) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
+ DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ YearMonth yearMonth = YearMonth.parse(month, formatter);
|
|
|
+ // 3. 生成该月所有日期的信息
|
|
|
+ List<AttendanceStaff> allList = new ArrayList<>();
|
|
|
+ LocalDate startDate = yearMonth.atDay(1);
|
|
|
+ LocalDate endDate = startDate.plusMonths(1);
|
|
|
+
|
|
|
+ List<User> userList = userService.list(new QueryWrapper<User>().eq("company_id", 7));
|
|
|
+ List<Attendance> attendanceList = attendanceService.list(new QueryWrapper<Attendance>().eq("month", month));
|
|
|
+
|
|
|
+
|
|
|
+ ArrayList<Attendance> attendances = new ArrayList<>();
|
|
|
+
|
|
|
+ //开始时间,结束时间都在这个月份的申请单数据
|
|
|
+ List<ApplyForm> applyFormList= applyFormService.getListByFirstDateAndLastDate(startDate,endDate);
|
|
|
+ List<ApplyForm> listLittle = applyFormList.stream().filter(a -> a.getSumTime().compareTo(BigDecimal.valueOf(8)) <= 0).collect(Collectors.toList());//申请单时长小于8
|
|
|
+ List<ApplyForm> listBig = applyFormList.stream().filter(a -> a.getSumTime().compareTo(BigDecimal.valueOf(8)) > 0).collect(Collectors.toList());//申请单时长大于8
|
|
|
+ for (ApplyForm applyForm : listLittle) {
|
|
|
+ if (applyForm.getType()!=6){
|
|
|
+ Attendance a = new Attendance();
|
|
|
+ Attendance b = new Attendance();
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
|
|
|
+ Optional<Attendance> first1 = attendanceList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
|
|
|
+ if (first.isPresent()&&first1.isPresent()){
|
|
|
+ a.setMonth(month);
|
|
|
+ a.setJobNumber(applyForm.getApplyId());
|
|
|
+ a.setDeptName(first1.get().getDeptName());
|
|
|
+ a.setName(first.get().getName());
|
|
|
+ a.setClockTime(applyForm.getStartTime());
|
|
|
+ attendances.add(a);
|
|
|
+
|
|
|
+ b.setMonth(month);
|
|
|
+ b.setJobNumber(applyForm.getApplyId());
|
|
|
+ b.setDeptName(first1.get().getDeptName());
|
|
|
+ b.setName(first.get().getName());
|
|
|
+ b.setClockTime(applyForm.getStartTime());
|
|
|
+ attendances.add(b);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Attendance a = new Attendance();
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
|
|
|
+ Optional<Attendance> first1 = attendanceList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
|
|
|
+ if (first.isPresent()&&first1.isPresent()){
|
|
|
+ a.setMonth(month);
|
|
|
+ a.setJobNumber(applyForm.getApplyId());
|
|
|
+ a.setDeptName(first1.get().getDeptName());
|
|
|
+ a.setName(first.get().getName());
|
|
|
+ a.setClockTime(applyForm.getStartTime());
|
|
|
+ attendances.add(a);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (ApplyForm applyForm : listBig) {
|
|
|
+ LocalDateTime startTime = applyForm.getStartTime();
|
|
|
+ LocalDateTime endTime = applyForm.getEndTime();
|
|
|
+
|
|
|
+ for (LocalDate date = startTime.toLocalDate(); !date.isAfter(endTime.toLocalDate()); date = date.plusDays(1)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|