Commit c42850d4 authored by YangZhaoJun1's avatar YangZhaoJun1

全部导出文件

parent 0f531bea
...@@ -240,5 +240,11 @@ public interface BChapterRepository extends BaseMapper<BChapter> { ...@@ -240,5 +240,11 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
"where del_flag = 0 and flag = 1 " + "where del_flag = 0 and flag = 1 " +
"and business_id = #{businessId}</script>") "and business_id = #{businessId}</script>")
String queryMdFileByChapterId(String businessId); String queryMdFileByChapterId(String businessId);
@Select("select CONCAT((SELECT sort from b_chapter where business_id = #{pid}),\n" +
"'.'," +
"(SELECT sort from b_chapter where business_id = #{businessId})) AS sort \n" +
"from b_chapter where business_id = #{businessId}")
String querySortByPidAndId(@Param("pid") String pid, @Param("businessId") String businessId);
} }
...@@ -9,6 +9,10 @@ import org.rcisoft.business.bcode.model.CodeType; ...@@ -9,6 +9,10 @@ import org.rcisoft.business.bcode.model.CodeType;
import org.rcisoft.business.bcode.service.BCodeService; import org.rcisoft.business.bcode.service.BCodeService;
import org.rcisoft.business.brslstudent.dao.BRSlStudentRepository; import org.rcisoft.business.brslstudent.dao.BRSlStudentRepository;
import org.rcisoft.business.brslstudent.entity.BRSlStudent; import org.rcisoft.business.brslstudent.entity.BRSlStudent;
import org.rcisoft.business.bsl.dao.BSlRepository;
import org.rcisoft.business.bsl.entity.BSl;
import org.rcisoft.business.bstudent.entity.BStudent;
import org.rcisoft.business.bstudent.entity.BStudentDto;
import org.rcisoft.common.component.Global; import org.rcisoft.common.component.Global;
import org.rcisoft.core.service.RcRedisService; import org.rcisoft.core.service.RcRedisService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -16,11 +20,12 @@ import org.springframework.stereotype.Service; ...@@ -16,11 +20,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.File; import java.io.*;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* Created by lcy on 18/1/3. * Created by lcy on 18/1/3.
...@@ -42,6 +47,9 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -42,6 +47,9 @@ public class BCodeServiceImpl implements BCodeService {
@Autowired @Autowired
private BRSlStudentRepository brSlStudentRepository; private BRSlStudentRepository brSlStudentRepository;
@Autowired
private BSlRepository bSlRepository;
/** /**
* 读文件 * 读文件
* @param slId * @param slId
...@@ -124,7 +132,7 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -124,7 +132,7 @@ public class BCodeServiceImpl implements BCodeService {
+ global.getCOURSE_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator
+ global.getSL_LOCATION() + File.separator + global.getSL_LOCATION() + File.separator
+ slId + File.separator + slId + File.separator
+ chapterId +File.separator //+ chapterId +File.separator
+ global.getCOURSE_PROJECT_LOCATION() + File.separator + global.getCOURSE_PROJECT_LOCATION() + File.separator
+ userInfo; + userInfo;
try{ try{
...@@ -253,12 +261,14 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -253,12 +261,14 @@ public class BCodeServiceImpl implements BCodeService {
@Override @Override
public String exportFiles(String slId, String studentId, String type, String slCode) { public String exportFiles(String slId, String studentId, String type, String slCode) {
if(type.equals("1")){//全部导出 if(type.equals("1")){//全部导出
String compressPath = "";
String SlPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator String SlPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator
+ global.getSL_LOCATION() +File.separator + global.getSL_LOCATION() +File.separator
+ slId + File.separator; + slId + File.separator;
//得到开课的编号和名称
List<String> students = brSlStudentRepository.queryStudentBySlCode(slCode); BSl sl = bSlRepository.queryBSlById(slId);
List<BStudentDto> students = brSlStudentRepository.queryStudentBySlCode(slCode);
//查询该课程的所有章节 //查询该课程的所有章节
List<BChapter> chapterList = bChapterRepository.queryChapterBySlId(slId); List<BChapter> chapterList = bChapterRepository.queryChapterBySlId(slId);
if(chapterList!=null){ if(chapterList!=null){
...@@ -269,38 +279,102 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -269,38 +279,102 @@ public class BCodeServiceImpl implements BCodeService {
codeType = global.getCOURSE_PROJECT_LOCATION() + File.separator; codeType = global.getCOURSE_PROJECT_LOCATION() + File.separator;
} }
//将要导出的文件放入这个文件夹中 //得到节的排序 如 1.1 2.2
String sort = bChapterRepository.querySortByPidAndId(bChapter.getPid(),bChapter.getBusinessId());
//将要导出的文件暂存入这个文件夹中
String copyPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator String copyPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getTEMP_LOCATION() + File.separator + global.getTEMP_LOCATION() + File.separator
+ "studentCode" + File.separator + "studentCode" + File.separator
+ slId + File.separator + sl.getCode()+sl.getLessonName() + File.separator
+ bChapter.getBusinessId() + File.separator; + sort + File.separator;
//+ studentId + File.separator; compressPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
for(String student : students){ + global.getTEMP_LOCATION() + File.separator
String finalPath = copyPath + student +File.separator; + "studentCode" + File.separator
+ sl.getCode()+sl.getLessonName();
for(BStudentDto student : students){
String finalPath = copyPath + student.getStudentCode()
+ "+"
+ student.getStudentName()
+ File.separator;
File copyFile = new File(finalPath); File copyFile = new File(finalPath);
if(!copyFile.exists()){ if(!copyFile.exists()){
copyFile.mkdirs(); copyFile.mkdirs();
} }
String codePath = SlPath + bChapter.getBusinessId() +File.separator String codePath = SlPath + bChapter.getBusinessId() +File.separator
+ codeType + student + File.separator; + codeType + student.getBusinessId() + File.separator;
File userFile = new File(codePath); File userFile = new File(codePath);
File javaFile[] = userFile.listFiles(); File javaFile[] = userFile.listFiles();
for(File simpleFile : javaFile){ for(File simpleFile : javaFile){
String fileName = simpleFile.getName(); //将文件复制出去
File finalFile = new File(codePath+fileName); try {
int bytesum = 0;
int byteread = 0;
InputStream inStream = new FileInputStream(simpleFile.getPath()); //读入原文件
FileOutputStream fs = new FileOutputStream(finalPath + simpleFile.getName());
byte[] buffer = new byte[102400];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
}
catch (Exception e) {
System.out.println("复制时出错");
e.printStackTrace();
}
} }
} }
} }
} }
//将文件打包
try {
this.compressFiles(compressPath);
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
return null; return null;
} }
private void compressFiles(String compressPath) throws IOException {
if (!compressPath.equals("")) {
File file = new File(compressPath);
String copyPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getTEMP_LOCATION() + File.separator
+ "studentCode";
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(copyPath+file.getName()));
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(
files[i]));
zos.putNextEntry(new ZipEntry(file
.getName()
+ file.separator
+ files[i].getName()));
while (true) {
byte[] b = new byte[100];
int len = bis.read(b);
if (len == -1)
break;
zos.write(b, 0, len);
}
bis.close();
}
}
zos.close();
}
}
} }
package org.rcisoft.business.bdirection.dao; package org.rcisoft.business.bdirection.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap; import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.bdirection.entity.BDirection; import org.rcisoft.business.bdirection.entity.BDirection;
import org.rcisoft.business.blesson.entity.BLessonDirection;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -37,5 +39,8 @@ public interface BDirectionRepository extends BaseMapper<BDirection> { ...@@ -37,5 +39,8 @@ public interface BDirectionRepository extends BaseMapper<BDirection> {
@Select("<script>select * from b_direction where del_flag != 1 and flag = 1</script>") @Select("<script>select * from b_direction where del_flag != 1 and flag = 1</script>")
@ResultMap(value = "BaseResultMap") @ResultMap(value = "BaseResultMap")
List<BDirection> queryDirectionsList(); List<BDirection> queryDirectionsList();
@Insert("insert into b_lesson_direction (business_id,direction_id,sl_id) values (#{businessId},#{directionId},#{slId})")
int insertBLessonDirection(BLessonDirection bDirection);
} }
...@@ -24,5 +24,8 @@ public class BDirection extends IdEntity<BDirection> { ...@@ -24,5 +24,8 @@ public class BDirection extends IdEntity<BDirection> {
private String code; private String code;
private String name; private String name;
public BDirection(String code) {
this.code = code;
}
} }
...@@ -2,6 +2,8 @@ package org.rcisoft.business.brslstudent.dao; ...@@ -2,6 +2,8 @@ package org.rcisoft.business.brslstudent.dao;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.rcisoft.business.brslstudent.entity.BRSlStudent; import org.rcisoft.business.brslstudent.entity.BRSlStudent;
import org.rcisoft.business.bstudent.entity.BStudent;
import org.rcisoft.business.bstudent.entity.BStudentDto;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -76,9 +78,10 @@ public interface BRSlStudentRepository extends BaseMapper<BRSlStudent> { ...@@ -76,9 +78,10 @@ public interface BRSlStudentRepository extends BaseMapper<BRSlStudent> {
"\tb2.business_id = #{stuId}</script>") "\tb2.business_id = #{stuId}</script>")
int selectSlNumByStuId(String stuId); int selectSlNumByStuId(String stuId);
@Select("<script>SELECT t2.business_id FROM b_r_sl_student t1 " + @Select("<script>SELECT t2.business_id as businessId t1.student_code as studentCode t2.name as studentName " +
"FROM b_r_sl_student t1 " +
"left join s_user t2 on t1.student_code = t2.login_name " + "left join s_user t2 on t1.student_code = t2.login_name " +
"WHERE t1.sl_code = #{slCode}</script>") "WHERE t1.sl_code = #{slCode}</script>")
List<String> queryStudentBySlCode(String slCode); List<BStudentDto> queryStudentBySlCode(String slCode);
} }
...@@ -137,7 +137,7 @@ public interface BSlRepository extends BaseMapper<BSl> { ...@@ -137,7 +137,7 @@ public interface BSlRepository extends BaseMapper<BSl> {
* @return * @return
*/ */
@Select("<script>SELECT t1.business_id as businessId,t1.credits AS credits,t1.class_hour AS classHour,\n" + @Select("<script>SELECT t1.business_id as businessId,t1.credits AS credits,t1.class_hour AS classHour,\n" +
"t1.audit_status AS auditStatus,t8.`name` AS directionName,t9.`name` AS termName,\n" + "t1.audit_status AS auditStatus,t8.`name` AS directionName,t8.`code` AS directionCode,t9.`name` AS termName,\n" +
"t1.`code` AS slCode,t1.sl_notes as slNotes,t1.sl_cover_url as coverUrl,\n" + "t1.`code` AS slCode,t1.sl_notes as slNotes,t1.sl_cover_url as coverUrl,\n" +
"t6.lesson_name as lessonName,t5.head_pic as teaPic,t5.`name` AS teaName,\n" + "t6.lesson_name as lessonName,t5.head_pic as teaPic,t5.`name` AS teaName,\n" +
"t5.t_num as teaSlNum,t5.`code` AS teaCode,\n" + "t5.t_num as teaSlNum,t5.`code` AS teaCode,\n" +
...@@ -240,5 +240,11 @@ public interface BSlRepository extends BaseMapper<BSl> { ...@@ -240,5 +240,11 @@ public interface BSlRepository extends BaseMapper<BSl> {
@Select("select audit_status from b_sl where business_id = #{slId}") @Select("select audit_status from b_sl where business_id = #{slId}")
String queryStateById(@Param("slId") String slId); String queryStateById(@Param("slId") String slId);
@Select("select sl.code le.lesson_name as lessonName from b_sl sl " +
"left join b_lesson le on sl.lesson_code = le.code " +
"where sl.business_id = #{slId}")
@ResultMap(value = "BaseResultMap" )
BSl queryBSlById(String slId);
} }
...@@ -26,6 +26,7 @@ public class SlDetailDTO { ...@@ -26,6 +26,7 @@ public class SlDetailDTO {
private String credits; private String credits;
private String classHour; private String classHour;
private String directionName; private String directionName;
private String directionCode;
private String termName; private String termName;
private String auditStatus; private String auditStatus;
} }
...@@ -6,6 +6,8 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; ...@@ -6,6 +6,8 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.rcisoft.business.bchapter.dao.BChapterRepository; import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.rcisoft.business.bchapter.entity.BChapter; import org.rcisoft.business.bchapter.entity.BChapter;
import org.rcisoft.business.bchapter.service.BChapterService; import org.rcisoft.business.bchapter.service.BChapterService;
import org.rcisoft.business.bdirection.dao.BDirectionRepository;
import org.rcisoft.business.bdirection.entity.BDirection;
import org.rcisoft.business.blesson.dao.BLessonRepository; import org.rcisoft.business.blesson.dao.BLessonRepository;
import org.rcisoft.business.blesson.entity.BLesson; import org.rcisoft.business.blesson.entity.BLesson;
import org.rcisoft.business.blesson.entity.BLessonDirection; import org.rcisoft.business.blesson.entity.BLessonDirection;
...@@ -61,6 +63,8 @@ public class BSlServiceImpl implements BSlService { ...@@ -61,6 +63,8 @@ public class BSlServiceImpl implements BSlService {
private BRSlStudentRepository brSlStudentRepository; private BRSlStudentRepository brSlStudentRepository;
@Autowired @Autowired
private BChapterService bChapterService; private BChapterService bChapterService;
@Autowired
private BDirectionRepository bDirectionRepository;
@Autowired @Autowired
private BOpinionRepository bOpinionRepository; private BOpinionRepository bOpinionRepository;
...@@ -154,10 +158,11 @@ public class BSlServiceImpl implements BSlService { ...@@ -154,10 +158,11 @@ public class BSlServiceImpl implements BSlService {
ArrayList<String> lessonCode = new ArrayList<String>(); ArrayList<String> lessonCode = new ArrayList<String>();
ArrayList<String> teacherCode = new ArrayList<String>(); ArrayList<String> teacherCode = new ArrayList<String>();
ArrayList<String> termCode = new ArrayList<String>(); ArrayList<String> termCode = new ArrayList<String>();
ArrayList<String> direction = new ArrayList<String>();
List<BSl> repeatSl = new ArrayList<>(); List<BSl> repeatSl = new ArrayList<>();
Map map = new HashMap(); Map map = new HashMap();
String[] headers = {"课序号","课程编号","教师工号","学期编号","课时","学分"}; String[] headers = {"课序号","课程编号","教师工号","学期编号","课时","学分","课程方向"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据 ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据
if (values.size()<0){ if (values.size()<0){
...@@ -165,7 +170,7 @@ public class BSlServiceImpl implements BSlService { ...@@ -165,7 +170,7 @@ public class BSlServiceImpl implements BSlService {
} }
for(String[] value:values){ //将数据封装到entity for(String[] value:values){ //将数据封装到entity
if(value.length>=6) { if(value.length>=7) {
//1. 检查数据正确性 //1. 检查数据正确性
BSl bSl = null; BSl bSl = null;
BSl b = new BSl(value[0]); BSl b = new BSl(value[0]);
...@@ -175,6 +180,7 @@ public class BSlServiceImpl implements BSlService { ...@@ -175,6 +180,7 @@ public class BSlServiceImpl implements BSlService {
bSl1.setLessonCode(value[1]); bSl1.setLessonCode(value[1]);
bSl1.setClassHour(value[4]); bSl1.setClassHour(value[4]);
bSl1.setCredits(value[5]); bSl1.setCredits(value[5]);
bSl1.setDirectionId(value[6]);
if (StringUtils.isAnyEmpty(value[0]) || value[1] == null || value[1].equals("")) { if (StringUtils.isAnyEmpty(value[0]) || value[1] == null || value[1].equals("")) {
continue; continue;
} }
...@@ -198,6 +204,11 @@ public class BSlServiceImpl implements BSlService { ...@@ -198,6 +204,11 @@ public class BSlServiceImpl implements BSlService {
termCode.add(value[3]); termCode.add(value[3]);
continue; continue;
} }
if ((bDirectionRepository.selectOne(new BDirection(value[6]))) == null) {
if (!direction.contains(value[6]))
direction.add(value[6]);
continue;
}
if ( bSlRepository.selectOne(bSl1) != null) { if ( bSlRepository.selectOne(bSl1) != null) {
repeatSl.add(bSl1); repeatSl.add(bSl1);
continue; continue;
...@@ -208,10 +219,17 @@ public class BSlServiceImpl implements BSlService { ...@@ -208,10 +219,17 @@ public class BSlServiceImpl implements BSlService {
bSl.setSlCoverUrl(bLessonRepository.queryBLessonByCode(value[1]).getDefaultUrl()); bSl.setSlCoverUrl(bLessonRepository.queryBLessonByCode(value[1]).getDefaultUrl());
UserUtil.setCurrentPersistOperation(bSl); UserUtil.setCurrentPersistOperation(bSl);
BLessonDirection bDirection = new BLessonDirection();
if (!bSls.contains(bSl)) { if (!bSls.contains(bSl)) {
bSls.add(bSl); bSls.add(bSl);
bDirection.setDirectionId(bDirectionRepository.selectOne(new BDirection(value[6])).getBusinessId());
bDirection.setBusinessId(IdGen.uuid());
bDirection.setSlId(bSl.getBusinessId());
bDirectionRepository.insertBLessonDirection(bDirection);
map.put(bSl.getLessonCode(), bSl.getBusinessId());
} }
map.put(bSl.getLessonCode(), bSl.getBusinessId());
} }
} }
String result =""; String result ="";
...@@ -243,6 +261,9 @@ public class BSlServiceImpl implements BSlService { ...@@ -243,6 +261,9 @@ public class BSlServiceImpl implements BSlService {
if(termCode.size()>0){ if(termCode.size()>0){
nullResult.append("以下学期编号不存在:").append(JSON.toJSONString(termCode)).append("。 "); nullResult.append("以下学期编号不存在:").append(JSON.toJSONString(termCode)).append("。 ");
} }
if(termCode.size()>0){
nullResult.append("以下课程方向编号不存在:").append(JSON.toJSONString(direction)).append("。 ");
}
result+=nullResult; result+=nullResult;
if(bSls.size()<1){ if(bSls.size()<1){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result); throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result);
......
package org.rcisoft.business.bstudent.entity; package org.rcisoft.business.bstudent.entity;
import lombok.Data;
/** /**
* Created by Administrator on 2018/1/11. * Created by Administrator on 2018/1/11.
*/ */
@Data
public class BStudentDto { public class BStudentDto {
private String businessId;
private String studentName;
private String StudentCode;
} }
...@@ -13,7 +13,7 @@ server: ...@@ -13,7 +13,7 @@ server:
druid: druid:
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root username: root
password: cy password: root
initial-size: 1 initial-size: 1
min-idle: 1 min-idle: 1
max-active: 20 max-active: 20
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment