parent
f1bce56864
commit
a2d9657d15
@ -0,0 +1,206 @@
|
||||
package com.markma.leave_manager_spb.controller;
|
||||
|
||||
|
||||
import com.markma.leave_manager_spb.entity.LeaveDetail;
|
||||
import com.markma.leave_manager_spb.entity.OutDetail;
|
||||
import com.markma.leave_manager_spb.repository.LeaveDetailRepository;
|
||||
import com.markma.leave_manager_spb.repository.OutDetailRepository;
|
||||
import com.markma.leave_manager_spb.repository.UserDetailRepository;
|
||||
import com.markma.leave_manager_spb.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dataAnalysis")
|
||||
public class DataAnalysis {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@Autowired
|
||||
private UserDetailRepository userDetailRepository;
|
||||
@Autowired
|
||||
private LeaveDetailRepository leaveDetailRepository;
|
||||
@Autowired
|
||||
private OutDetailRepository outDetailRepository;
|
||||
|
||||
public static void mapCopy(Map paramsMap, Map resultMap) {
|
||||
if (resultMap == null) resultMap = new HashMap();
|
||||
if (paramsMap == null) return;
|
||||
|
||||
Iterator it = paramsMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object key = entry.getKey();
|
||||
resultMap.put(key, paramsMap.get(key) != null ? paramsMap.get(key) : "");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/DATime/{userid}/{time_type}")
|
||||
public List<Map<String, Integer>> DATime(@PathVariable("userid") String userid, @PathVariable("time_type") String time_type) {
|
||||
List<Map<String, Integer>> result = new ArrayList<>();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
String timeL, timeB, timeO, timeR = null;
|
||||
int res;
|
||||
List<LeaveDetail> LDs = leaveDetailRepository.findAll();
|
||||
LeaveDetail LD;
|
||||
List<OutDetail> ODs = outDetailRepository.findAll();
|
||||
OutDetail OD;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Calendar now = Calendar.getInstance();
|
||||
int date_max = now.get(Calendar.DATE);
|
||||
if (time_type.equals("D")) {
|
||||
Map<String, Integer> temp = new HashMap<String, Integer>();
|
||||
for (int j = 0; j <= date_max; j++) {
|
||||
int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
|
||||
for (int i = 0; i < LDs.size(); i++) {
|
||||
LD = LDs.get(i);
|
||||
if (!userid.equals("*")) {
|
||||
if (!LD.getUserid().toString().equals(userid)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
timeL = LD.getLeave_time();
|
||||
timeB = LD.getBack_time();
|
||||
|
||||
try {
|
||||
Date dateL = format.parse(timeL);
|
||||
Date dateB = format.parse(timeB);
|
||||
cal.setTime(dateL);
|
||||
if (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)) {
|
||||
res = cal.get(Calendar.DATE);
|
||||
if (res == j) {
|
||||
sum1++;
|
||||
}
|
||||
}
|
||||
cal.setTime(dateB);
|
||||
if (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)) {
|
||||
res = cal.get(Calendar.DATE);
|
||||
if (res == j) {
|
||||
sum2++;
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < ODs.size(); i++) {
|
||||
OD = ODs.get(i);
|
||||
if (!userid.equals("*")) {
|
||||
if (!OD.getUserid().toString().equals(userid)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
timeO = OD.getOut_time();
|
||||
timeR = OD.getReturn_time();
|
||||
if (timeO == null || timeR == null) continue;
|
||||
try {
|
||||
Date dateO = format.parse(timeO);
|
||||
Date dateR = format.parse(timeR);
|
||||
cal.setTime(dateO);
|
||||
if (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)) {
|
||||
res = cal.get(Calendar.DATE);
|
||||
if (res == j) {
|
||||
sum3++;
|
||||
}
|
||||
}
|
||||
cal.setTime(dateR);
|
||||
if (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)) {
|
||||
res = cal.get(Calendar.DATE);
|
||||
if (res == j) {
|
||||
sum4++;
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
temp.put("日期", j);
|
||||
temp.put("预计离开人数", sum1);
|
||||
temp.put("预计返回人数", sum2);
|
||||
temp.put("实际离开人数", sum3);
|
||||
temp.put("实际返回人数", sum4);
|
||||
Map<String, Integer> temp_cpy = new HashMap<String, Integer>();
|
||||
mapCopy(temp, temp_cpy);
|
||||
result.add(temp_cpy);
|
||||
}
|
||||
|
||||
} else if (time_type.equals("H")) {
|
||||
Map<String, Integer> temp = new HashMap<String, Integer>();
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
|
||||
for (int i = 0; i < LDs.size(); i++) {
|
||||
LD = LDs.get(i);
|
||||
if (!userid.equals("*")) {
|
||||
if (!LD.getUserid().toString().equals(userid)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
timeL = LD.getLeave_time();
|
||||
timeB = LD.getBack_time();
|
||||
|
||||
try {
|
||||
Date dateL = format.parse(timeL);
|
||||
Date dateB = format.parse(timeB);
|
||||
cal.setTime(dateL);
|
||||
res = cal.get(Calendar.HOUR_OF_DAY);
|
||||
if (res == j) {
|
||||
sum1++;
|
||||
}
|
||||
|
||||
cal.setTime(dateB);
|
||||
res = cal.get(Calendar.HOUR_OF_DAY);
|
||||
if (res == j) {
|
||||
sum2++;
|
||||
}
|
||||
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < ODs.size(); i++) {
|
||||
OD = ODs.get(i);
|
||||
if (!userid.equals("*")) {
|
||||
if (!OD.getUserid().toString().equals(userid)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
timeO = OD.getOut_time();
|
||||
timeR = OD.getReturn_time();
|
||||
if (timeO == null || timeR == null) continue;
|
||||
try {
|
||||
Date dateO = format.parse(timeO);
|
||||
Date dateR = format.parse(timeR);
|
||||
cal.setTime(dateO);
|
||||
res = cal.get(Calendar.HOUR_OF_DAY);
|
||||
if (res == j) {
|
||||
sum3++;
|
||||
}
|
||||
|
||||
cal.setTime(dateR);
|
||||
res = cal.get(Calendar.HOUR_OF_DAY);
|
||||
if (res == j) {
|
||||
sum4++;
|
||||
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
temp.put("小时", j);
|
||||
temp.put("预计离开次数", sum1);
|
||||
temp.put("预计返回次数", sum2);
|
||||
temp.put("实际离开次数", sum3);
|
||||
temp.put("实际返回次数", sum4);
|
||||
Map<String, Integer> temp_cpy = new HashMap<String, Integer>();
|
||||
mapCopy(temp, temp_cpy);
|
||||
result.add(temp_cpy);
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
//res = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.markma.leave_manager_spb.repository;
|
||||
|
||||
import com.markma.leave_manager_spb.entity.UserAllDetail;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserAllDetailRepository extends JpaRepository<UserAllDetail, Integer> {
|
||||
}
|
Loading…
Reference in new issue