Commit ab5397c2 authored by YangZhaoJun1's avatar YangZhaoJun1

导入排课

parent 1f94dd34
......@@ -5,6 +5,8 @@ package org.rcisoft.business.barrange.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.core.converter.MultipartFile2HSSFWorkbookConverter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -22,6 +24,7 @@ import javax.validation.Valid;
import org.rcisoft.business.barrange.entity.BArrange;
import org.rcisoft.business.barrange.service.BArrangeService;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......@@ -57,4 +60,16 @@ public class BArrangeController extends PaginationController<BArrange> {
MessageConstant.MESSAGE_ALERT_ERROR,
bArrangeServiceImpl.findAll());
}
@ApiOperation(value="excel导入", notes="excel导入排课信息")
@ApiImplicitParam(name = "importFile", value = "excel文件", required = true, dataType = "MultipartFile")
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "excelImport")
public Result excelImport(MultipartFile importFile) throws Exception {
PersistModel data = bArrangeServiceImpl.importExcel(MultipartFile2HSSFWorkbookConverter.convert(importFile),getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
data.getInfluenceReason());
}
}
package org.rcisoft.business.barrange.dao;
import org.rcisoft.business.barrange.entity.ScheduleDto;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.business.barrange.entity.BArrange;
import org.apache.ibatis.annotations.ResultMap;
......@@ -7,6 +8,7 @@ import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -39,5 +41,7 @@ public interface BArrangeRepository extends BaseMapper<BArrange> {
+ "</script>")
@ResultMap(value = "BaseResultMap4" )
List<BArrange> queryBArranges2(String gradeCode);
int insertList(ArrayList<ScheduleDto> scheduleDtos);
}
......@@ -20,8 +20,7 @@ import java.util.List;
@Table(name = "b_arrange")
public class BArrange extends IdEntity<BArrange> {
private static final long serialVersionUID = -5524520301999990921L;
private String termCode;
private String desc;
......
package org.rcisoft.business.barrange.entity;
import lombok.Data;
/**
* Created by Administrator on 2018/4/23.
*/
@Data
public class ScheduleDto {
private String lessonCode;
private String lessonName;
private String teacherCode;
private String teacherName;
private String classCode;
private String className;
private String week;
private String classHour;
private String monday;
private String tuesday;
private String wednesday;
private String thursday;
private String friday;
private String saturday;
private String roomCode;
private String roomName;
}
package org.rcisoft.business.barrange.service;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.rcisoft.business.barrange.entity.BArrange;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil;
......@@ -27,6 +28,5 @@ public interface BArrangeService {
List<BArrange> findAll();
PersistModel importExcel(HSSFWorkbook convert, String token);
}
package org.rcisoft.business.barrange.service.impl;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.rcisoft.business.barrange.entity.ScheduleDto;
import org.rcisoft.business.bclass.dao.BClassRepository;
import org.rcisoft.business.bclass.entity.BClass;
import org.rcisoft.business.blesson.dao.BLessonRepository;
import org.rcisoft.business.blesson.entity.BLesson;
import org.rcisoft.business.brooms.dao.BRoomsRepository;
import org.rcisoft.business.brooms.entity.BRooms;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.ExcelUtil;
import org.rcisoft.core.util.RegexValidateUtil;
import org.rcisoft.core.util.UserUtil;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
......@@ -8,6 +22,8 @@ import org.rcisoft.business.barrange.entity.BArrange;
import org.rcisoft.business.barrange.service.BArrangeService;
import org.rcisoft.sys.user.dao.SysUserMapper;
import org.rcisoft.sys.user.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
......@@ -15,8 +31,10 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import sun.reflect.generics.repository.ClassRepository;
/**
* Created by on 2018-4-19 10:28:59.
......@@ -29,6 +47,18 @@ public class BArrangeServiceImpl implements BArrangeService {
@Autowired
private BArrangeRepository bArrangeRepository;
@Autowired
private BLessonRepository bLessonRepository;
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private BClassRepository bClassRepository;
@Autowired
private BRoomsRepository bRoomsRepository;
/**
* 保存 bArrange
......@@ -58,4 +88,118 @@ public class BArrangeServiceImpl implements BArrangeService {
return list;
}
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override
public PersistModel importExcel(HSSFWorkbook hwb, String token) {
ArrayList<ScheduleDto> scheduleDtos = new ArrayList<ScheduleDto>();
String[] headers = {"课程编号", "教师编号", "班级编号","教室编号","周次","周学时","周一",
"周二","周三","周四","周五","周六"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true); //获取excel数据
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
}
List<String> lessonCodes = new ArrayList<>();
List<String> teacherCodes = new ArrayList<>();
List<String> classCodes = new ArrayList<>();
List<String> roomCodes = new ArrayList<>();
String[] wholeValue = new String[11];
for (String[] value : values) {
ScheduleDto scheduleDto = new ScheduleDto();
//每一次遇到完整数据时将完整数据存放起来
if(!value[0].equals("")&&!value[1].equals("")&&!value[2].equals("")&&!value[3].equals("")){
wholeValue = value;
}
//判断1:根据课程编号查询是否有此门课程;
if(value[0].equals("")){
value[0] = wholeValue[0];
}
if(bLessonRepository.selectOne(new BLesson(value[0]))==null){
lessonCodes.add(value[0]);
continue;
}
//判断2:根据教师编号查询是否有此教师;
if(value[1].equals("")){
value[1] = wholeValue[1];
}
SysUser user1 =new SysUser();
user1.setLoginName(value[1]);
user1.setDelFlag("0");
user1.setFlag("1");
if (sysUserMapper.selectOne(user1) == null) {
teacherCodes.add(value[1]);
continue;
}
//判断3:根据班级编号查询是否有此班级;
if(value[2].equals("")){
value[2] = wholeValue[2];
}
for(String classCode : value[2].split(",")){
if(bClassRepository.selectOne(new BClass(classCode))==null){
classCodes.add(classCode);
continue;
}
}
//判断4:根据教室编号查询是否有此教室;
if(value[3].equals("")){
value[3] = wholeValue[3];
}
if(bRoomsRepository.selectOne(new BRooms(value[3]))==null){
roomCodes.add(value[3]);
continue;
}
//合法:通过了四次判断,证明可建立该排课
scheduleDto.setLessonCode(value[0]);
scheduleDto.setTeacherCode(value[1]);
scheduleDto.setClassCode(value[2]);
scheduleDto.setRoomCode(value[3]);
scheduleDto.setWeek(value[4]);
scheduleDto.setClassHour(value[5]);
scheduleDto.setMonday(value[6]);
scheduleDto.setTuesday(value[7]);
scheduleDto.setWednesday(value[8]);
scheduleDto.setThursday(value[9]);
scheduleDto.setFriday(value[10]);
scheduleDto.setSaturday(value[11]);
scheduleDtos.add(scheduleDto);
}
String result = "";
if (scheduleDtos.size()>0){
int line1 = bArrangeRepository.insertList(scheduleDtos);
if (line1 < 1 ) {
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR);
}else{
result+="成功导入"+scheduleDtos.size()+"条数据。";
}
}
if(lessonCodes.size()>0){
result+="以下课程编号不存在:"+ JSON.toJSONString(lessonCodes)+"。";
}
if(teacherCodes.size()>0){
result+="以下教师编号不存在:"+ JSON.toJSONString(teacherCodes)+"。";
}
if(classCodes.size()>0){
result+="以下班级编号不存在:"+ JSON.toJSONString(classCodes)+"。";
}
if(roomCodes.size()>0){
result+="以下教室编号不存在:"+ JSON.toJSONString(roomCodes)+"。";
}
return new PersistModel(1, result);
}
}
......@@ -35,7 +35,6 @@ public class BClass extends IdEntity<BClass> {
/*学生数量,默认为0*/
@Length(min = 1,max = 3,message = "长度最小为1,最大为3")
@NotBlank
private String studentNum;
/*班级类型*/
......
......@@ -85,7 +85,7 @@ public class BClassServiceImpl implements BClassService {
ArrayList<String> repeatCode = new ArrayList<String>();
String[] headers = {"班级编号","班级名称"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
......
......@@ -42,7 +42,7 @@ public class BEduClassController extends PaginationController<BEduClass> {
@ApiImplicitParam(name = "className", value = "教学班名 length(1~150)", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "agencyId", value = "企业ID", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "type", value = "班级类型", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "classesCode", value = "教学班code串", required = false, dataType = "varchar")})
@ApiImplicitParam(name = "classesId", value = "教学班code串", required = false, dataType = "varchar")})
@PostMapping(value = "/add")
@PreAuthorize("hasRole('ROLE_1001')")
public Result add(BEduClass bEduClass) {
......@@ -75,7 +75,7 @@ public class BEduClassController extends PaginationController<BEduClass> {
@ApiImplicitParam(name = "className", value = "教学班名 length(1~150)", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "agencyId", value = "企业ID", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "type", value = "班级类型 length(1)", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "classedCode", value = "教学班code串 length(1~150)", required = false, dataType = "varchar")})
@ApiImplicitParam(name = "classesId", value = "教学班code串 length(1~150)", required = false, dataType = "varchar")})
@PostMapping("/update")
@PreAuthorize("hasRole('ROLE_1001')")
public Result update(BEduClass bEduClass) {
......
......@@ -41,7 +41,7 @@ public class BEduClass extends IdEntity<BEduClass> {
private String type;
/*子班级ID串*/
private String classesCode;
private String classesId;
/*学年ID*/
private String gradeId;
......
......@@ -89,7 +89,7 @@ public class BEduClassServiceImpl implements BEduClassService {
*/
public BEduClass findById(String id){
BEduClass eduClass = bEduClassRepository.selectDetalInfo(id);
String classNames = this.getclassNames(eduClass.getClassesCode());
String classNames = this.getclassNames(eduClass.getClassesId());
if(classNames.length()>0){
eduClass.setClassNames(classNames.substring(0,classNames.length()-1));
}else{
......@@ -109,7 +109,7 @@ public class BEduClassServiceImpl implements BEduClassService {
bEduClass.setNotDeleted();
List<BEduClass> eduClasses = bEduClassRepository.queryBEduClasss(bEduClass);
for(BEduClass eduClass : eduClasses){
String name = this.getclassNames(eduClass.getClassesCode());
String name = this.getclassNames(eduClass.getClassesId());
if(name.length()>0){
eduClass.setClassNames(name.substring(0,name.length()-1));
}else{
......
......@@ -114,7 +114,7 @@ public class BLessonServiceImpl implements BLessonService {
ArrayList<String> direction = new ArrayList<String>();
String[] headers = {"课程编号","课程名称","课程方向编号","学时","学分"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
if (values.size()<1){
......
......@@ -83,7 +83,7 @@ public class BRClassStudentServiceImpl implements BRClassStudentService {
ArrayList<String> repeatCode = new ArrayList<String>();
String[] headers = {"班级编号","学号"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
......
......@@ -67,6 +67,10 @@ public class BRooms extends IdEntity<BRooms> {
@Transient
private String transitCategory;
public BRooms(String code) {
this.code = code;
}
public String getTransitCampus(){
if(this.transitCampus != null && !this.transitCampus.equals("")){
switch (this.transitCampus) {
......
......@@ -89,7 +89,7 @@ public class BRSlStudentServiceImpl implements BRSlStudentService {
ArrayList<String> gitlabUser = new ArrayList<String>();*/
String[] headers = {"课序号","学号"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
if (values.size()<1){
......
......@@ -161,7 +161,7 @@ public class BSlServiceImpl implements BSlService {
Map map = new HashMap();
String[] headers = {"课序号","课程编号","教师工号","学期编号"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
......
......@@ -127,7 +127,7 @@ public class BStudentServiceImpl implements BStudentService {
ArrayList<SysUser> users = new ArrayList<SysUser>();
ArrayList<UserRole> userRoles = new ArrayList<UserRole>();
String[] headers = {"学号", "学生姓名", "性别","邮箱","年级"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,false); //获取excel数据
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
......
......@@ -83,7 +83,7 @@ public class BTeacherServiceImpl implements BTeacherService {
ArrayList<UserRole> userRoles = new ArrayList<UserRole>();
String[] headers = {"教师工号", "教师姓名", "性别","邮箱"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,false); //获取excel数据
if (values.size() == 0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
}
......
......@@ -23,9 +23,10 @@ public class ExcelUtil {
* 获取excel模板信息
* @param hwb 源数据
* @param headers excel模板头
* @param allowEmpty 是否允许单元格有空数据
* @return 整理好的ArrayList<String[]>
*/
public static ArrayList<String[]> importExcel(HSSFWorkbook hwb, String[] headers){
public static ArrayList<String[]> importExcel(HSSFWorkbook hwb, String[] headers, boolean allowEmpty){
ArrayList<String[]> values = new ArrayList<>();
for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
HSSFSheet hs = hwb.getSheetAt(i);
......@@ -44,7 +45,7 @@ public class ExcelUtil {
int firstcolumnnum = hr.getFirstCellNum();
int lastcolumnnum = hr.getLastCellNum();
String[] value = new String[lastcolumnnum];
boolean hasEmpty = false;
boolean hasEmpty = true;
for (int k = firstcolumnnum; k < lastcolumnnum; k++) {
HSSFCell hc = hr.getCell(k);
if (j==firstrownum + 1) {
......@@ -56,6 +57,14 @@ public class ExcelUtil {
}
}
else {
if(allowEmpty){//允许单元格为空,但不允许整行为空时
if (!parseDB(hc).trim().equals("")&&emptyColList.get(k)!=-1&&hasEmpty) {
//只要一行中有一个值不为空,即为正确数据
hasEmpty = false;
}
}else{//不允许单元格为空,只要一行中有一个值为空,即为错误数据
hasEmpty = false;
if (parseDB(hc).trim().equals("")&&emptyColList.get(k)!=-1) {
//在第j行第k列有空数据,且该列表头不是空的,则舍弃本行数据。
hasEmpty = true;
......@@ -64,6 +73,8 @@ public class ExcelUtil {
}
}
}
value[k] = parseDB(hc);
//parseDB(hc.getCellType(), hc);
}
......
......@@ -14,7 +14,7 @@
<result column="class_name" jdbcType="VARCHAR" property="className"/>
<result column="agency_id" jdbcType="VARCHAR" property="agencyId"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="classes_id" jdbcType="VARCHAR" property="classesCode"/>
<result column="classes_id" jdbcType="VARCHAR" property="classesId"/>
<result column="grade_id" jdbcType="VARCHAR" property="gradeId"/>
</resultMap>
......
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