|
@@ -1,15 +1,21 @@
|
|
|
package cn.iocoder.yudao.module.as.service.aidingstudentsmanage;
|
|
|
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
|
|
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+import cn.iocoder.yudao.module.as.controller.admin.aidingstudentsimportlist.vo.AidingStudentsImportExcelRespVO;
|
|
|
+import cn.iocoder.yudao.module.as.controller.admin.aidingstudentsimportlist.vo.AidingStudentsImportExcelVO;
|
|
|
import cn.iocoder.yudao.module.as.service.aidingstudentsimportlist.AidingStudentsImportListService;
|
|
|
import cn.iocoder.yudao.module.as.service.aidingstudentsimportlist.AidingStudentsImportListServiceImpl;
|
|
|
+import org.apache.tomcat.util.http.fileupload.FileItem;
|
|
|
+import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
|
+import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
import java.net.URL;
|
|
|
import java.nio.channels.Channels;
|
|
|
import java.nio.channels.ReadableByteChannel;
|
|
@@ -21,6 +27,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
|
import cn.iocoder.yudao.module.as.dal.mysql.aidingstudentsmanage.AidingStudentsManageMapper;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
@@ -40,7 +48,7 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
|
|
|
private AidingStudentsImportListServiceImpl aidingStudentsImportListService;
|
|
|
|
|
|
@Override
|
|
|
- public Long createAidingStudentsManage(AidingStudentsManageSaveReqVO createReqVO) {
|
|
|
+ public AidingStudentsImportExcelRespVO createAidingStudentsManage(AidingStudentsManageSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
AidingStudentsManageDO aidingStudentsManage = BeanUtils.toBean(createReqVO, AidingStudentsManageDO.class);
|
|
|
aidingStudentsManageMapper.insert(aidingStudentsManage);
|
|
@@ -50,23 +58,23 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
|
|
|
//解析excel
|
|
|
|
|
|
//创建temp.xlsx
|
|
|
+ String path = this.getClass().getResource("").getPath();//注意getResource("")里面是空字符串
|
|
|
+ String path1=path+"importexcel";
|
|
|
try {
|
|
|
- File dir = new File("src/main/resources/importexcel");
|
|
|
+ File dir = new File(path1);
|
|
|
if(!dir.exists()){
|
|
|
dir.mkdirs();//创建目录
|
|
|
}
|
|
|
- File f = new File("src/main/resources/importexcel","temp.xlsx");
|
|
|
+ File f = new File(path1,"temp.xlsx");
|
|
|
if(!f.exists()){
|
|
|
f.createNewFile();
|
|
|
}
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
//从url读取出文件到本地
|
|
|
URL website = null;
|
|
|
ReadableByteChannel rbc = null;
|
|
@@ -74,7 +82,7 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
|
|
|
try {
|
|
|
website = new URL(aidingStudentsManage.getDiImportListFile());
|
|
|
rbc = Channels.newChannel(website.openStream());
|
|
|
- fos = new FileOutputStream("..\\resources\\importexcel\\temp.xlsx");//本地要存储的文件地址 例如:test.txt
|
|
|
+ fos = new FileOutputStream(path1+"/temp.xlsx");//本地要存储的文件地址 例如:test.txt
|
|
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -100,13 +108,34 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
|
|
|
|
|
|
|
|
|
//导入名单
|
|
|
- //aidingStudentsImportListService.aidingStudentsImportExcelListFromCloud(aidingStudentsManage.getId(),)
|
|
|
+ File file = new File(path1+"/temp.xlsx");
|
|
|
+ AidingStudentsImportExcelRespVO aidingStudentsImportExcelRespVO=null;
|
|
|
+ try {
|
|
|
+ MultipartFile cMultiFile = new MockMultipartFile("file", file.getName(), null, new FileInputStream(file));
|
|
|
+ List<AidingStudentsImportExcelVO> list = ExcelUtils.read(cMultiFile, AidingStudentsImportExcelVO.class);
|
|
|
+ aidingStudentsImportExcelRespVO = aidingStudentsImportListService.aidingStudentsImportExcelListFromCloud(aidingStudentsManage.getId(), list);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw exception(AIDING_STUDENTS_IMPORT_LIST_FILE_IMPORT_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //TODO 删除excel文件
|
|
|
+ file.delete();
|
|
|
|
|
|
|
|
|
// 返回
|
|
|
- return aidingStudentsManage.getId();
|
|
|
+ return aidingStudentsImportExcelRespVO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void updateAidingStudentsManage(AidingStudentsManageSaveReqVO updateReqVO) {
|
|
|
// 校验存在
|