2023.6.15
1. 添加课表导入 2. 获取未使用教室列表 3. 修复了部分BUG
This commit is contained in:
parent
0a85101c5d
commit
8bd543e9ba
@ -29,27 +29,6 @@ public class ExperimentFactory {
|
||||
log.error("解析实验名称失败");
|
||||
}
|
||||
|
||||
try {
|
||||
experiment.setTime(jsonObject.getString("time"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析实验时间失败");
|
||||
}
|
||||
|
||||
try {
|
||||
experiment.setDate(jsonObject.getDate("date"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析实验日期失败");
|
||||
}
|
||||
|
||||
try {
|
||||
experiment.setRoomName(jsonObject.getString("roomName"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析实验教室名称失败");
|
||||
}
|
||||
|
||||
try {
|
||||
experiment.setStatus(jsonObject.getInteger("status"));
|
||||
} catch (Exception e) {
|
||||
|
69
src/main/java/com/sdut/labex/Factory/UserFactory.java
Normal file
69
src/main/java/com/sdut/labex/Factory/UserFactory.java
Normal file
@ -0,0 +1,69 @@
|
||||
package com.sdut.labex.Factory;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sdut.labex.entity.User;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* File: UserFactory
|
||||
* Created: 2023/6/15
|
||||
* Author: springforest
|
||||
* Description:
|
||||
*/
|
||||
@Slf4j
|
||||
public class UserFactory {
|
||||
public static User createUser(JSONObject jsonObject) {
|
||||
User user = new User();
|
||||
log.info("解析用户信息");
|
||||
try {
|
||||
user.setId(jsonObject.getString("id"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析用户id失败");
|
||||
}
|
||||
|
||||
try {
|
||||
user.setUsername(jsonObject.getString("username"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析用户姓名失败");
|
||||
}
|
||||
|
||||
try {
|
||||
user.setPassword(jsonObject.getString("password"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析用户密码失败");
|
||||
}
|
||||
|
||||
try {
|
||||
user.setClassName(jsonObject.getString("className"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析班级失败");
|
||||
}
|
||||
|
||||
try {
|
||||
user.setEmail(jsonObject.getString("email"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析邮箱失败");
|
||||
}
|
||||
|
||||
try {
|
||||
user.setDepartment(jsonObject.getString("department"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析学院失败");
|
||||
}
|
||||
|
||||
try {
|
||||
user.setRole(jsonObject.getString("role"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解析用户角色失败");
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import com.sdut.labex.Factory.ExperimentFactory;
|
||||
import com.sdut.labex.entity.Experiment;
|
||||
import com.sdut.labex.service.ExperimentsService;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import com.sdut.labex.utils.UserHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -32,7 +31,9 @@ public class ExperimentsController {
|
||||
public ResVo applyExperiment(@RequestBody JSONObject jsonObject) {
|
||||
Experiment experiment = ExperimentFactory.createExperiment(jsonObject);
|
||||
//设置申请人
|
||||
experiment.setApplyUser(UserHolder.getUser().getId());
|
||||
//experiment.setApplyUser(UserHolder.getUser().getId());
|
||||
//todo:上线删除
|
||||
experiment.setApplyUser("测试");
|
||||
//获取当前时间
|
||||
LocalDateTime currentDateTime = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
@ -69,7 +70,7 @@ public class ExperimentsController {
|
||||
}
|
||||
|
||||
//设置实验审核状态
|
||||
@PutMapping("/isAdmitted/{id}{status}")
|
||||
@PutMapping("/isAdmitted/{id}/{status}")
|
||||
public ResVo isAdmit(@PathVariable Integer id, @PathVariable Integer status) {
|
||||
return experimentsService.isAdmitted(id, status);
|
||||
}
|
||||
|
35
src/main/java/com/sdut/labex/controller/TableController.java
Normal file
35
src/main/java/com/sdut/labex/controller/TableController.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.sdut.labex.controller;
|
||||
|
||||
import com.sdut.labex.service.TableService;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* File: TableController
|
||||
* Created: 2023/6/15
|
||||
* Author: springforest
|
||||
* Description:
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class TableController {
|
||||
@Resource
|
||||
private TableService tableService;
|
||||
|
||||
@GetMapping("/getUnusedTable/{date}/{roomName}")
|
||||
public ResVo getUnusedTable(@PathVariable("date") String date,
|
||||
@PathVariable("roomName") String roomName) {
|
||||
if (roomName.equals("")) {
|
||||
roomName = "9教207";
|
||||
}
|
||||
return tableService.getUnUsedTable(roomName, date);
|
||||
}
|
||||
|
||||
@PostMapping("/uploadTable")
|
||||
public ResVo uploadTable(MultipartFile file, @RequestPart("date") String date, @RequestPart("room") String room) {
|
||||
return tableService.uploadTable(file, date, room);
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
package com.sdut.labex.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sdut.labex.Factory.UserFactory;
|
||||
import com.sdut.labex.entity.User;
|
||||
import com.sdut.labex.service.UserService;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ -31,4 +34,20 @@ public class UserController {
|
||||
String newPassword = jsonObject.getString("newPassword");
|
||||
return userService.changePassword(id, oldPassword, newPassword);
|
||||
}
|
||||
|
||||
@PostMapping("/addUserBatch")
|
||||
public ResVo addBatch(MultipartFile file) {
|
||||
return userService.addBatch(file);
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/{id}")
|
||||
public ResVo delete(@PathVariable("id") String id) {
|
||||
return userService.delete(id);
|
||||
}
|
||||
|
||||
@PutMapping("/user")
|
||||
public ResVo update(@RequestBody JSONObject jsonObject) {
|
||||
User user = UserFactory.createUser(jsonObject);
|
||||
return userService.update(user);
|
||||
}
|
||||
}
|
||||
|
66
src/main/java/com/sdut/labex/dto/TimeTable.java
Normal file
66
src/main/java/com/sdut/labex/dto/TimeTable.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.sdut.labex.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* File: TimeTable
|
||||
* Created: 2023/6/15
|
||||
* Author: springforest
|
||||
* Description:
|
||||
*/
|
||||
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TimeTable {
|
||||
|
||||
public int startWeek;
|
||||
public int endWeek;
|
||||
public String name;
|
||||
public String[] time;
|
||||
public String reason;
|
||||
|
||||
public TimeTable(String rawData) {
|
||||
String[] temp = rawData.split("/");
|
||||
this.time = new String[2];
|
||||
this.reason = temp[0];
|
||||
|
||||
String tt = new String(temp[1].substring(1, 5));
|
||||
switch (tt) {
|
||||
case "1-2节":
|
||||
this.time[0] = "第一节";
|
||||
this.time[1] = "第二节";
|
||||
break;
|
||||
case "3-4节":
|
||||
this.time[0] = "第三节";
|
||||
this.time[1] = "第四节";
|
||||
break;
|
||||
case "5-6节":
|
||||
this.time[0] = "第五节";
|
||||
this.time[1] = "第六节";
|
||||
break;
|
||||
case "7-8节":
|
||||
this.time[0] = "第七节";
|
||||
this.time[1] = "第八节";
|
||||
break;
|
||||
case "9-10":
|
||||
this.time[0] = "第九节";
|
||||
this.time[1] = "第十节";
|
||||
break;
|
||||
}
|
||||
|
||||
String startWeekTemp = temp[1].substring(temp[1].length() - 4, temp[1].length() - 3);
|
||||
String endWeekTemp = temp[1].substring(temp[1].length() - 2, temp[1].length() - 1);
|
||||
if (startWeekTemp.equals("-")) {
|
||||
startWeekTemp = temp[1].substring(temp[1].length() - 5, temp[1].length() - 4);
|
||||
endWeekTemp = temp[1].substring(temp[1].length() - 3, temp[1].length() - 1);
|
||||
}
|
||||
this.startWeek = Integer.parseInt(startWeekTemp);
|
||||
this.endWeek = Integer.parseInt(endWeekTemp);
|
||||
|
||||
this.name = temp[2];
|
||||
}
|
||||
}
|
@ -28,21 +28,6 @@ public class Experiment implements Serializable {
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 上课时间
|
||||
*/
|
||||
private String time;
|
||||
|
||||
/**
|
||||
* 上课日期
|
||||
*/
|
||||
private Date date;
|
||||
|
||||
/**
|
||||
* 上课教室
|
||||
*/
|
||||
private String roomName;
|
||||
|
||||
/**
|
||||
* 审核状态(0未审,1通过,2拒绝)
|
||||
*/
|
||||
|
@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sdut.labex.entity.BorrowInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author springforest
|
||||
* @description 针对表【borrowInfo(借用记录)】的数据库操作Mapper
|
||||
@ -14,6 +17,10 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface BorrowInfoMapper extends BaseMapper<BorrowInfo> {
|
||||
public Page<BorrowInfo> queryBorrowInfoByOptions(Page<BorrowInfo> page, BorrowInfo borrowInfo);
|
||||
|
||||
public void addTimeTable(Map<String, String> map);
|
||||
|
||||
public List<BorrowInfo> listAllByDateAndRoom(String date, String room);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sdut.labex.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* File: UserMapper
|
||||
* Created: 2023/6/11
|
||||
@ -12,4 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
public void insertBatch(List<User> list);
|
||||
}
|
||||
|
18
src/main/java/com/sdut/labex/service/TableService.java
Normal file
18
src/main/java/com/sdut/labex/service/TableService.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.sdut.labex.service;
|
||||
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* File: TableService
|
||||
* Created: 2023/6/15
|
||||
* Author: springforest
|
||||
* Description:
|
||||
* 课程表相关服务
|
||||
*/
|
||||
|
||||
public interface TableService {
|
||||
public ResVo getUnUsedTable(String room, String date);
|
||||
|
||||
public ResVo uploadTable(MultipartFile file, String startDate, String roomName);
|
||||
}
|
@ -3,6 +3,7 @@ package com.sdut.labex.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sdut.labex.entity.User;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* File: UserService
|
||||
@ -22,5 +23,5 @@ public interface UserService extends IService<User> {
|
||||
|
||||
public ResVo update(User user);
|
||||
|
||||
public ResVo insertBatch();
|
||||
public ResVo addBatch(MultipartFile file);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.sdut.labex.entity.Experiment;
|
||||
import com.sdut.labex.mapper.ExperimentsMapper;
|
||||
import com.sdut.labex.service.ExperimentsService;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -19,6 +20,7 @@ import java.util.Map;
|
||||
* @description 针对表【experiments(实验)】的数据库操作Service实现
|
||||
* @createDate 2023-06-12 08:07:15
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ExperimentsServiceImpl extends ServiceImpl<ExperimentsMapper, Experiment>
|
||||
implements ExperimentsService {
|
||||
@ -33,7 +35,7 @@ public class ExperimentsServiceImpl extends ServiceImpl<ExperimentsMapper, Exper
|
||||
e.printStackTrace();
|
||||
return ResVo.error();
|
||||
}
|
||||
return ResVo.ok();
|
||||
return ResVo.ok("申请成功,请等待审核");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,6 +82,7 @@ public class ExperimentsServiceImpl extends ServiceImpl<ExperimentsMapper, Exper
|
||||
|
||||
@Override
|
||||
public ResVo getExperiments(Experiment experiment, int pageNum, int pageSize) {
|
||||
log.info("getExperiments: experiment = " + experiment + ", pageNum = " + pageNum + ", pageSize = " + pageSize);
|
||||
Page<Experiment> page = new Page<>(pageNum, pageSize);
|
||||
experimentsMapper.getExperimentsByPage(page, experiment);
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
|
167
src/main/java/com/sdut/labex/service/impl/TableServiceImpl.java
Normal file
167
src/main/java/com/sdut/labex/service/impl/TableServiceImpl.java
Normal file
@ -0,0 +1,167 @@
|
||||
package com.sdut.labex.service.impl;
|
||||
|
||||
import com.sdut.labex.dto.TimeTable;
|
||||
import com.sdut.labex.entity.BorrowInfo;
|
||||
import com.sdut.labex.entity.Room;
|
||||
import com.sdut.labex.entity.TimeOption;
|
||||
import com.sdut.labex.mapper.BorrowInfoMapper;
|
||||
import com.sdut.labex.mapper.RoomMapper;
|
||||
import com.sdut.labex.mapper.TimeOptionMapper;
|
||||
import com.sdut.labex.service.TableService;
|
||||
import com.sdut.labex.utils.ExcelUtils;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import com.sdut.labex.utils.SFFileUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* File: TableServiceImpl
|
||||
* Created: 2023/6/15
|
||||
* Author: springforest
|
||||
* Description:
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TableServiceImpl implements TableService {
|
||||
|
||||
@Resource
|
||||
private BorrowInfoMapper borrowInfoMapper;
|
||||
@Resource
|
||||
private RoomMapper roomMapper;
|
||||
@Resource
|
||||
private TimeOptionMapper timeOptionMapper;
|
||||
|
||||
@Override
|
||||
public ResVo getUnUsedTable(String room, String date) {
|
||||
List<BorrowInfo> borrowedList = borrowInfoMapper.listAllByDateAndRoom(room, date);
|
||||
log.info("borrowedList: " + borrowedList.toString());
|
||||
Map<String, List<String>> tempMap = new HashMap<>();
|
||||
// 获取所有教室
|
||||
List<Room> roomList = roomMapper.selectList(null);
|
||||
// 获取所有时间(按顺序)
|
||||
List<TimeOption> timeOptionList = timeOptionMapper.selectList(null);
|
||||
|
||||
try {
|
||||
for (TimeOption time : timeOptionList) {
|
||||
List<String> rooms = new ArrayList<>();
|
||||
tempMap.put(time.getName(), rooms);
|
||||
}
|
||||
for (BorrowInfo item : borrowedList) {
|
||||
log.info(item.toString());
|
||||
tempMap.get(item.getTime()).add(item.getRoomName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("解析时间或记录出错");
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<List<String>> res = new ArrayList<>();
|
||||
|
||||
// 获取不在borrowedList中的教室
|
||||
for (TimeOption key : timeOptionList) {
|
||||
List<String> rooms = new ArrayList<>();
|
||||
for (Room item : roomList) {
|
||||
if (!tempMap.get(key.getName()).contains(item.getName())) {
|
||||
rooms.add(item.getName());
|
||||
}
|
||||
}
|
||||
res.add(rooms);
|
||||
}
|
||||
|
||||
if (room != null && !room.isEmpty()) {
|
||||
for (List<String> rooms : res) {
|
||||
rooms.removeIf(r -> !r.equals(room));
|
||||
}
|
||||
}
|
||||
|
||||
map.put("list", res);
|
||||
return ResVo.ok(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResVo uploadTable(MultipartFile file, String startDate, String roomName) {
|
||||
try {
|
||||
// 使用SFFileUtils类封装文件操作
|
||||
SFFileUtils sfFile = new SFFileUtils(file);
|
||||
|
||||
// 使用ExcelUtils类封装Excel操作
|
||||
ExcelUtils excel = new ExcelUtils(sfFile.getFile(), sfFile.getEndName());
|
||||
if (excel.isEmpty) {
|
||||
return ResVo.error("Excel文件为空");
|
||||
}
|
||||
|
||||
// 解析文件,将单元格内容解析为List
|
||||
// 处理list
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
// 获取当前日期
|
||||
Date today = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
// 解析开始日期
|
||||
Date date;
|
||||
SimpleDateFormat formatter;
|
||||
try {
|
||||
formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
date = formatter.parse(startDate); // 使用开始日期
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("开始日期解析失败");
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date); // 设置时间为学期开始日期
|
||||
|
||||
for (int i = 2; i <= 8; i++) { // 列
|
||||
int dayFix = i - 2; // 周内日期修正(偏移量)
|
||||
|
||||
for (int j = 2; j <= 6; j++) { // 行
|
||||
calendar.setTime(date); // 每次循环前重置时间为学期开始日期
|
||||
calendar.add(Calendar.DATE, dayFix); // 周内时间偏移
|
||||
|
||||
String temp = excel.readCell(j, i);
|
||||
if (temp != null) {
|
||||
String[] ttmp = temp.split("/");
|
||||
if (ttmp.length <= 10) {
|
||||
TimeTable timeTable = new TimeTable(temp);
|
||||
map.put("name", timeTable.getName());
|
||||
map.put("reason", timeTable.getReason());
|
||||
map.put("roomName", roomName);
|
||||
map.put("applyDate", dateFormat.format(today));
|
||||
map.put("isAdmit", "1");
|
||||
calendar.add(Calendar.DATE, 7 * (timeTable.getStartWeek() - 1)); // 设置开始周
|
||||
|
||||
try {
|
||||
for (int k = timeTable.getStartWeek(); k <= timeTable.getEndWeek(); k++) {
|
||||
map.put("date", formatter.format(calendar.getTime())); // 日期单独处理
|
||||
map.put("time", timeTable.getTime()[0]);
|
||||
// 插入记录
|
||||
borrowInfoMapper.addTimeTable(map);
|
||||
|
||||
map.put("time", timeTable.getTime()[1]);
|
||||
borrowInfoMapper.addTimeTable(map);
|
||||
|
||||
calendar.add(Calendar.DATE, 7); // 增加7天
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ResVo.ok("上传成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("文件读取失败");
|
||||
}
|
||||
}
|
||||
}
|
@ -4,13 +4,18 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sdut.labex.entity.User;
|
||||
import com.sdut.labex.mapper.UserMapper;
|
||||
import com.sdut.labex.service.UserService;
|
||||
import com.sdut.labex.utils.ExcelUtils;
|
||||
import com.sdut.labex.utils.JWTUtil;
|
||||
import com.sdut.labex.utils.ResVo;
|
||||
import com.sdut.labex.utils.SFFileUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -97,7 +102,72 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResVo insertBatch() {
|
||||
return null;
|
||||
public ResVo addBatch(MultipartFile file) {
|
||||
SFFileUtils sfFile;
|
||||
try {
|
||||
sfFile = new SFFileUtils(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("文件读取失败");
|
||||
}
|
||||
ExcelUtils excel;
|
||||
try {
|
||||
excel = new ExcelUtils(sfFile.getFile(), sfFile.getEndName());
|
||||
if (excel.isEmpty) {
|
||||
return ResVo.error("Excel文件为空");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("解析Excel出错");
|
||||
}
|
||||
|
||||
int startRow = 0;
|
||||
int endRow = excel.totalRows;
|
||||
List<User> list = new ArrayList<>();
|
||||
for (int i = startRow; i < endRow; i++) {
|
||||
User user = new User();
|
||||
|
||||
//学号
|
||||
try {
|
||||
user.setId(excel.readCell(i, 0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("Excel格式错误:第" + (i + 1) + "行第1列");
|
||||
}
|
||||
//姓名
|
||||
try {
|
||||
user.setUsername(excel.readCell(i, 1));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("Excel格式错误:第" + (i + 1) + "行第2列");
|
||||
}
|
||||
//默认密码为123456
|
||||
user.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
|
||||
//身份
|
||||
user.setRole("student");
|
||||
//班级
|
||||
try {
|
||||
user.setClassName(excel.readCell(i, 2));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("Excel格式错误:第" + (i + 1) + "行第3列");
|
||||
}
|
||||
//学院
|
||||
try {
|
||||
user.setDepartment(excel.readCell(i, 3));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("Excel格式错误:第" + (i + 1) + "行第4列");
|
||||
}
|
||||
|
||||
list.add(user);
|
||||
}
|
||||
try {
|
||||
userMapper.insertBatch(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResVo.error("批量添加失败");
|
||||
}
|
||||
return ResVo.ok();
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class ExcelUtils {
|
||||
}
|
||||
|
||||
//读取指定位置的单元格
|
||||
public String getCertainCell(int rowNum, int columnNum) {
|
||||
public String readCell(int rowNum, int columnNum) {
|
||||
Row row = this.sheet.getRow(rowNum);//获取行
|
||||
Cell cell = row.getCell(columnNum);//获取列
|
||||
|
||||
|
@ -11,12 +11,28 @@
|
||||
<result property="date" column="date" jdbcType="DATE"/>
|
||||
<result property="applyDate" column="apply_date" jdbcType="TIMESTAMP"/>
|
||||
<result property="isAdmit" column="is_admit" jdbcType="INTEGER"/>
|
||||
<result property="roomName" column="room_name" jdbcType="INTEGER"/>
|
||||
<result property="roomName" column="room_name" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
<insert id="addTimeTable" parameterType="map">
|
||||
insert into borrow_info (apply_user, time, date, apply_date, is_admit, room_name)
|
||||
VALUES (#{applyUser}, #{time}, #{date}, #{applyDate}, 1, #{roomName});
|
||||
</insert>
|
||||
|
||||
<select id="queryBorrowInfoByOptions" resultType="com.sdut.labex.entity.BorrowInfo">
|
||||
select *
|
||||
from borrow_info
|
||||
|
||||
|
||||
</select>
|
||||
<select id="listAllByDateAndRoom" resultType="com.sdut.labex.entity.BorrowInfo">
|
||||
select *
|
||||
from borrow_info
|
||||
<where>
|
||||
<if test="date != null">
|
||||
date = #{date}
|
||||
</if>
|
||||
<if test="room != null">
|
||||
and room_name = #{room}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -7,21 +7,21 @@
|
||||
<resultMap id="BaseResultMap" type="com.sdut.labex.entity.Experiment">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="time" column="time" jdbcType="VARCHAR"/>
|
||||
<result property="date" column="date" jdbcType="DATE"/>
|
||||
<result property="roomName" column="room_name" jdbcType="VARCHAR"/>
|
||||
<result property="status" column="status" jdbcType="INTEGER"/>
|
||||
<result property="className" column="class_name" jdbcType="VARCHAR"/>
|
||||
<result property="applyTime" column="apply_time" jdbcType="VARCHAR"/>
|
||||
<result property="applyUser" column="apply_user" jdbcType="VARCHAR"/>
|
||||
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,name,time,
|
||||
date,room_name,status,
|
||||
class_name
|
||||
</sql>
|
||||
<select id="getExperimentsByPage" resultType="com.sdut.labex.entity.Experiment">
|
||||
|
||||
<select id="getExperimentsByPage" resultType="com.sdut.labex.entity.Experiment" parameterType="object">
|
||||
select *
|
||||
from experiments
|
||||
<where>
|
||||
<if test="experiment.applyUser != null">and apply_user = #{experiment.applyUser}</if>
|
||||
<if test="experiment.className != null">and class_name = #{experiment.className}</if>
|
||||
<if test="experiment.status != null">and status = #{experiment.status}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -13,4 +13,12 @@
|
||||
<result property="department" column="department" jdbcType="VARCHAR"/>
|
||||
<result property="role" column="role" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
<insert id="insertBatch">
|
||||
insert into user (id, username, password, class_name, email, department, role)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.id}, #{item.username}, #{item.password}, #{item.className}, #{item.email}, #{item.department},
|
||||
#{item.role})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user