13 大改动 数据分析+注册

master
markma 3 years ago
parent f1bce56864
commit a2d9657d15

@ -31,17 +31,21 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
</dependencies>
<build>
<plugins>

@ -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));
}
}

@ -39,6 +39,35 @@ public class LeaveDetailHandler {
return leaveDetailRepository.findAll();
}
@GetMapping("/findAllNum")
public Integer findAllNums() {
return leaveDetailRepository.findAll().size();
}
@GetMapping("/findAllPaged/{page}/{size}")
public List<LeaveDetail> findAllPaged(@PathVariable("page") int page, @PathVariable("size") int size) {
List<LeaveDetail> LDs = leaveDetailRepository.findAll();
List<LeaveDetail> LeftLDs = new ArrayList<LeaveDetail>();
int num = 0, pagemin = (page - 1) * size + 1, pagemax = page * size;
for (int i = 0; i < LDs.size(); i++) {
num++;
if (num >= pagemin && num <= pagemax) LeftLDs.add(LDs.get(i));
}
return LeftLDs;
}
@GetMapping("/LDUseridToName/{userid}")
public String findAllPaged(@PathVariable("userid") String userid) {
List<UserDetail> UDs = userDetailRepository.findAll();
for (int i = 0; i < UDs.size(); i++) {
if (UDs.get(i).getId().toString().equals(userid)) {
return UDs.get(i).getName();
}
}
return "无名氏";
}
@GetMapping("/findByUserId/{id}")
public List<LeaveDetail> findByUserId(@PathVariable("id") int id) {
List<LeaveDetail> LDs = leaveDetailRepository.findAll();

@ -3,6 +3,7 @@ package com.markma.leave_manager_spb.controller;
import com.markma.leave_manager_spb.entity.User;
import com.markma.leave_manager_spb.entity.UserAllDetail;
import com.markma.leave_manager_spb.entity.UserDetail;
import com.markma.leave_manager_spb.repository.UserAllDetailRepository;
import com.markma.leave_manager_spb.repository.UserDetailRepository;
import com.markma.leave_manager_spb.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,6 +23,9 @@ public class UserDetailHandler {
private UserDetailRepository userDetailRepository;
@Autowired
private UserRepository userRepository;
String absolutePath = "";
@Autowired
private UserAllDetailRepository userAllDetailRepository;
@GetMapping("/hello")
public String hello() {
@ -58,21 +62,132 @@ public class UserDetailHandler {
return UADs;
}
@PostMapping("/import")
public String importData(MultipartFile file, HttpServletRequest req) throws IOException {
public static void delFolder(String folderPath) {
try {
delAllFile(folderPath); //删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); //删除空文件夹
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
return flag;
}
if (!file.isDirectory()) {
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
temp.delete();
}
if (temp.isDirectory()) {
delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);//再删除空文件夹
flag = true;
}
}
return flag;
}
@GetMapping("/findAllStudentUserNum")
public Integer findAllUserNum() {
int max_num = userDetailRepository.findAll().size();
return findAllUserPaged(1, max_num).size();
}
@GetMapping("/findAllStudentUserPaged/{page}/{size}")
public List<UserAllDetail> findAllUserPaged(@PathVariable("page") int page, @PathVariable("size") int size) {
List<UserAllDetail> UADs = new ArrayList<UserAllDetail>();
List<UserDetail> UDs = userDetailRepository.findAll();
List<User> Users = userRepository.findAll();
int num = 0, pagemin = (page - 1) * size + 1, pagemax = page * size;
for (int i = 0; i < Users.size(); i++) {
num++;
if (num >= pagemin && num <= pagemax) {
UserAllDetail UAD = new UserAllDetail();
UserDetail UD = UDs.get(i);
User user = Users.get(i);
if (user.getType().equals("student")) {
UAD.setId(i + 1);
UAD.setUsername(user.getUsername());
UAD.setPassword(user.getPassword());
UAD.setType(user.getType());
UAD.setName(UD.getName());
UAD.setSchool_id(UD.getSchool_id());
UADs.add(UAD);
}
}
}
return UADs;
}
@PostMapping("/importData")
public String importData(MultipartFile file, HttpServletRequest req) throws IOException {
//保存上传的文件//
String realPath = "D:\\vue\\leave_manager\\src\\excel\\importExcels";
File folder = new File(realPath);
if (!folder.exists()) {
folder.mkdirs();
}
delAllFile("D:\\vue\\leave_manager\\src\\excel\\importExcels");
file.transferTo(new File(folder, file.getOriginalFilename()));
String absolutePath = realPath + "\\" + file.getOriginalFilename();
absolutePath = realPath + "\\" + file.getOriginalFilename();
System.out.println("上传的文件的绝对路径:" + absolutePath);
//保存上传的文件//
return "success";
}
@GetMapping("/findImportData")
public String findImportData() {
String result = absolutePath;
absolutePath = "";
return result;
}
@GetMapping("/checkValuable/{username}/{school_id}/{name}")
public String checkValuable(@PathVariable("username") String username, @PathVariable("school_id") String school_id, @PathVariable("name") String name) {
List<UserDetail> UDs = userDetailRepository.findAll();
List<User> Users = userRepository.findAll();
for (int i = 0; i < Users.size(); i++) {
UserDetail UD = UDs.get(i);
User user = Users.get(i);
if (user.getUsername().equals(username)) {
return "用户名";
}
if (UD.getSchool_id().equals(school_id)) {
return "学号";
}
if (UD.getName().equals(name)) {
return "姓名";
}
}
return "success";
}
@PostMapping("/saveUAD")
public String save(@RequestBody UserAllDetail userAllDetail) {
System.out.println(userAllDetail);
UserAllDetail result = userAllDetailRepository.save(userAllDetail);
if (result != null) {
return "success";
} else {
return "error";
}
}
}

@ -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…
Cancel
Save