|
@@ -2,16 +2,23 @@ package cn.iocoder.yudao.module.as.service.aidingstudentsmanage;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
|
|
+import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
|
+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;
|
|
@@ -23,6 +30,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;
|
|
|
|
|
@@ -42,7 +51,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);
|
|
@@ -52,31 +61,32 @@ 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");
|
|
|
+ f.deleteOnExit();
|
|
|
if(!f.exists()){
|
|
|
f.createNewFile();
|
|
|
}
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- //从url读取出文件到本地
|
|
|
- URL website = null;
|
|
|
+ //从url读取出文件到已创建的文件中
|
|
|
+ /*URL website = null;
|
|
|
ReadableByteChannel rbc = null;
|
|
|
FileOutputStream fos = null;
|
|
|
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();
|
|
@@ -96,26 +106,53 @@ 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);
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 删除excel文件
|
|
|
+ //file.deleteOnExit();
|
|
|
|
|
|
|
|
|
// 返回
|
|
|
- return aidingStudentsManage.getId();
|
|
|
+ return excelResolver(aidingStudentsManage.getDiImportListFile(), aidingStudentsManage.getId());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public void updateAidingStudentsManage(AidingStudentsManageSaveReqVO updateReqVO) {
|
|
|
- // 校验存在
|
|
|
- validateAidingStudentsManageExists(updateReqVO.getId());
|
|
|
+ public AidingStudentsImportExcelRespVO updateAidingStudentsManage(AidingStudentsManageSaveReqVO updateReqVO) {
|
|
|
+ //根据id查找
|
|
|
+ AidingStudentsManageDO aidingStudentsManage = aidingStudentsManageMapper.selectById(updateReqVO.getId());
|
|
|
+ //判断名单是否重新导入
|
|
|
+ AidingStudentsImportExcelRespVO aidingStudentsImportExcelRespVO = null;
|
|
|
+ if (!aidingStudentsManage.getDiImportListFile().equals(updateReqVO.getDiImportListFile())) {
|
|
|
+ aidingStudentsImportExcelRespVO = excelResolver(updateReqVO.getDiImportListFile(), updateReqVO.getId());
|
|
|
+ }
|
|
|
// 更新
|
|
|
AidingStudentsManageDO updateObj = BeanUtils.toBean(updateReqVO, AidingStudentsManageDO.class);
|
|
|
aidingStudentsManageMapper.updateById(updateObj);
|
|
|
+ return aidingStudentsImportExcelRespVO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -151,6 +188,72 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
|
|
|
aidingStudentsManageMapper.updateById(aidingStudentsManageDO);
|
|
|
}
|
|
|
|
|
|
+ public AidingStudentsImportExcelRespVO excelResolver(String url, Long aidingStudentsManageId){
|
|
|
+ //创建temp.xlsx
|
|
|
+ String path = this.getClass().getResource("").getPath();//注意getResource("")里面是空字符串
|
|
|
+ String path1=path+"importexcel";
|
|
|
+ try {
|
|
|
+ File dir = new File(path1);
|
|
|
+ if(!dir.exists()){
|
|
|
+ dir.mkdirs();//创建目录
|
|
|
+ }
|
|
|
+ File f = new File(path1,"temp.xlsx");
|
|
|
+ f.deleteOnExit();
|
|
|
+ if(!f.exists()){
|
|
|
+ f.createNewFile();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //从url读取出文件到已创建的文件中
|
|
|
+ URL website = null;
|
|
|
+ ReadableByteChannel rbc = null;
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ try {
|
|
|
+ website = new URL(url);
|
|
|
+ rbc = Channels.newChannel(website.openStream());
|
|
|
+ fos = new FileOutputStream(path1+"/temp.xlsx");//本地要存储的文件地址 例如:test.txt
|
|
|
+ fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally{
|
|
|
+ if(fos!=null){
|
|
|
+ try {
|
|
|
+ fos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(rbc!=null){
|
|
|
+ try {
|
|
|
+ rbc.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //导入名单
|
|
|
+ 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(aidingStudentsManageId, list);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw exception(AIDING_STUDENTS_IMPORT_LIST_FILE_IMPORT_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 删除excel文件
|
|
|
+ file.deleteOnExit();
|
|
|
+
|
|
|
+ // 返回
|
|
|
+ return aidingStudentsImportExcelRespVO;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public List<AidingStudentsManageDO> getManagetList(Collection<Long> ids) {
|