package xyz.second.common_module.service.impl;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import xyz.second.common_module.service.CommonService;
import xyz.second.common_module.vo.AnnexDate;
import xyz.second.common.auth.*;
import xyz.second.common.utils.ErrorMessage;
import xyz.second.common.utils.FileUtils;
import xyz.second.common_module.mapper.CommonMapper;
import xyz.second.common_module.mapper.criteria.AttachmentInformation;
import xyz.second.common_module.mapper.criteria.ProjectGroupQuery;
import xyz.second.common_module.mapper.result.Annex;
import xyz.second.common_module.mapper.result.Course;
import xyz.second.common_module.mapper.result.ProjectGroup;
import xyz.second.common_module.mapper.result.TeacherDate;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
@Service
public class CommonServiceImpl implements CommonService {
private final CommonMapper commonMapper;
public CommonServiceImpl(CommonMapper commonMapper) {
this.commonMapper = commonMapper;
}
@Override
public Result upload(MultipartFile file) {
String dirPath = FileUtils.mkdirs(new ApplicationHome(getClass()));
String fileName = file.getOriginalFilename();
String[] fn = fileName.split("\\.");
String fileExtension = fn[1];
System.out.println("后缀:" + fileExtension);
System.out.println(!FileUtils.isFileExtension(fileExtension));
if (!FileUtils.isFileExtension(fileExtension)) return Result.error().message("上传文件失败,含有不被接受的文件名");
String name = "";
int i;
System.out.println("过");
for (i = 0; i < 3; i += 1) {
name = FileUtils.getFileName();
if (!(new File(dirPath + name + "." + fileExtension)).exists()) {
break;
}
}
System.out.println("i:" + i);
if (i >= 3) {
return Result.error().message("上传文件失败,含有不被接收的文件名");
}
try {
//将文件写入磁盘
file.transferTo(new File(dirPath + name + "." + fileExtension));
return Result.ok().data(name + "." + fileExtension).message("上传文件成功");
/*if (commonMapper.initFile(a) == 1) {
return Result.ok().data(a.getAnnexId()).message("上传文件成功");
}*/
} catch (IOException e) {
}
return Result.error().message("上传文件失败");
}
@Override
public Result uploads(MultipartFile[] files) {
String dirPath = FileUtils.mkdirs(new ApplicationHome(getClass()));
int size = files.length;
if (size > 9) {
size = 9;
}
int number = 1;
int state = 0;
String[] fileNames = new String[size];
String[] accessorys = new String[size];
for (MultipartFile file : files) {
String fileName = file.getOriginalFilename();
String[] fn = fileName.split("\\.");
String fileExtension = fn[1];
System.out.println("后缀:" + fileExtension);
System.out.println(!FileUtils.isFileExtension(fileExtension));
if (!FileUtils.isFileExtension(fileExtension)) {
state = 1;
break;
}
String name = null;
int i;
for (i = 0; i < 3; i += 1) {
name = FileUtils.getFileName();
if (!(new File(dirPath + name + "." + fileExtension)).exists()) {
break;
}
}
if (i >= 3) {
state = 2;
break;
}
try {
//将文件写入磁盘
file.transferTo(new File(dirPath + name + "." + fileExtension));
} catch (IOException e) {
state = 3;
break;
}
fileNames[number] = fileName;
accessorys[number] = name + "." + fileExtension;
if (number == 9)
break;
number += 1;
}
if (number < size) {
//删除已经上传的文件
for (String accessory : accessorys) {
File file = new File(dirPath + accessory);
if (file.isDirectory()) {
file.delete();
}
}
if (state == 1) {
return Result.error().message("上传文件失败,含有不被接受的文件名" + ",第" + number + "个文件");
} else if (state == 2) {
return Result.error().message("生成文件名失败,第" + number + "个文件");
}
return Result.error().message("上传失败,第" + number + "个文件");
}
AttachmentInformation a = new AttachmentInformation(String.valueOf(accessorys), String.valueOf(fileNames));
if (commonMapper.initFile(a) == 1) {
return Result.ok().data(a.getAnnexId()).message("上传文件成功");
}
//删除已经上传的文件
for (String accessory : accessorys) {
File file = new File(dirPath + accessory);
if (file.isDirectory()) {
file.delete();
}
}
return Result.error().message("上传文件失败");
}
@Override
public void download(String path, String fileName, HttpServletResponse response) {
String dirPath = FileUtils.mkdirs(new ApplicationHome(getClass()));
try {
// path是指想要下载的文件的路径
File file = new File(dirPath + path);
//文件目录是否存在
if (!file.exists()) {
return;
}
// 将文件写入输入流
FileInputStream fileInputStream = new FileInputStream(file);
InputStream fis = new BufferedInputStream(fileInputStream);
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
// 清空response
response.reset();
// 设置response的Header
response.setCharacterEncoding("UTF-8");
//Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
//attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
// filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
if (fileName == null || fileName.equals("")) {
fileName = path;
}
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
// 告知浏览器文件的大小
response.addHeader("Content-Length", "" + file.length());
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
outputStream.write(buffer);
outputStream.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
//查询附件情况
@Override
public Result getAnnexs(int annexId) {
if (annexId < 1) {
Result.error().message("附件ID不能小于1");
}
Annex annex = commonMapper.getAnnexs(annexId);
if (annex == null) {
Result.error().message("附件查询情况为空");
}
String[] acessorys = annex.getAccessory().split("\\,
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目为基于Java的Web学生实训考勤请假管理系统设计源码,集成了561个文件,包括224个XML配置文件、146个Java源代码文件、142个CSS样式文件、4个JavaScript脚本文件、4个HTML模板文件。系统旨在解决高校管理中请假申请流程繁琐、信息不透明等问题,提供便捷的请假申请功能,确保班主任审批后请假生效。此外,系统还能帮助学生了解个人考勤情况,方便教师统计学生整体出勤状况。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的Web学生实训考勤请假管理系设计源码 (481个子文件)
mvnw.cmd 6KB
chunk-vendors.caacd1e0.css 204KB
app.c3af5212.css 582B
.gitignore 384B
.gitignore 232B
index.html 976B
favicon.ico 4KB
application.iml 15KB
project_course_table_manage_module.iml 15KB
scoring_module.iml 15KB
ask_for_leave_manage_module.iml 14KB
homework_manage_module.iml 14KB
course_manage_module.iml 14KB
project_group_manage_module.iml 14KB
user_info_manage_module.iml 14KB
attendance_manage_module.iml 14KB
auth_module.iml 14KB
personal_info_module.iml 14KB
database.iml 14KB
common.iml 13KB
training_manage_system.iml 12KB
wrapper.iml 666B
.mvn.iml 427B
maven-wrapper.jar 50KB
CommonServiceImpl.java 12KB
ProjectGroupManageInfoServiceImpl.java 11KB
SwaggerConfig.java 10KB
ProjectGroupManageController.java 9KB
HomeworkServiceImpl.java 9KB
AdminManageInfoServiceImpl.java 9KB
ScoreServiceImpl.java 7KB
AskForLeaveManageServiceImpl.java 7KB
CourseArrangementServiceimpl.java 7KB
AdminManageStudentInfoController.java 7KB
ScoreController.java 6KB
FileUtils.java 6KB
ProjectGroupManageInfoService.java 6KB
ManageTeacherInfoImpl.java 6KB
CheckCode.java 6KB
AskForLeaveManageService.java 6KB
StudentInfoServiceImpl.java 6KB
CommonController.java 5KB
MavenWrapperDownloader.java 5KB
ScoreService.java 5KB
HomeworkController.java 4KB
AttendanceServiceImpl.java 4KB
StudentAskForLeaveController.java 4KB
CourseArrangementService.java 4KB
AdminCourseController.java 4KB
AttendanceController.java 4KB
AttendanceManageImpl.java 4KB
SessionFilter.java 4KB
AdminManageTeacherInfoController.java 3KB
StudentInfoController.java 3KB
CheckIdCard.java 3KB
AuthServiceImpl.java 3KB
UserType.java 3KB
ServiceImpl.java 3KB
ProjectGroupManageInfoMapper.java 3KB
Vacation.java 2KB
AdminManageStudentInfoMapper.java 2KB
JwtUtils.java 2KB
AdminManageInfoService.java 2KB
ScoreQuery.java 2KB
StudentAnswerHomeworkInfoImpl.java 2KB
AttendanceService.java 2KB
AdminAskForLeaveController.java 2KB
TeacherAskForLeaveController.java 2KB
ManageTeacherInfo.java 2KB
AuthController.java 2KB
QueryAttendanceRecordRequest.java 2KB
CommonMapper.java 2KB
AttendanceRecordQuery_admin.java 2KB
QueryAttendanceRecordRequest_tea.java 2KB
Common.java 2KB
HomeworkMapper.java 2KB
QueryScoreRequest1.java 2KB
AttendanceRecordQuery_teacher.java 2KB
CourseArrangementinfo.java 2KB
AdmAttendanceController.java 2KB
TeaAttendanceController.java 1KB
PersonalTeamDetails.java 1KB
QueryScoreRequest2.java 1KB
ScoreMapper.java 1KB
StuAttendanceController.java 1KB
AttendanceRecord.java 1KB
HomeworkService.java 1KB
CommonService.java 1KB
Tea_AttendanceRecord.java 1KB
PersonalScoreDetails.java 1KB
StudentAnswerHomeWorkController.java 1KB
InterceptorConfig.java 1KB
Result.java 1KB
AuthService.java 1KB
TeacherHomeWorkState.java 1KB
StudentManageStudentInfoController.java 1KB
TeacherInfoPassController.java 1KB
QueryStuAttendance.java 1KB
ProjectGroupMemberInfo.java 1KB
TeacherSearch.java 1KB
共 481 条
- 1
- 2
- 3
- 4
- 5
资源评论
xyq2024
- 粉丝: 2324
- 资源: 5419
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功