Commit fb427873 authored by 李博今's avatar 李博今

增加排序以及排课导入的新方法(未使用)

parent d3529fda
......@@ -10,6 +10,8 @@ delete from b_term where 1=1;
-- 删除公司信息
delete from b_agency where 1=1;
delete from b_company where 1=1;
update b_teacher set agency_code = NULL where 1=1;
-- 删除教学班
delete from b_edu_class where 1=1;
......
......@@ -105,3 +105,7 @@ ADD COLUMN `subtask_seq` varchar(10) NULL AFTER `grade_code`;
/*子公司表新增排序*/
ALTER TABLE `b_sub_agency`
ADD COLUMN `sub_agency_seq` varchar(10) NULL AFTER `status`;
/*列表查询增加排序*/
ALTER TABLE `b_schedule_dto`
ADD COLUMN `dto_seq` varchar(10) NULL AFTER `sunday`;
\ No newline at end of file
......@@ -91,7 +91,11 @@ public class ScheduleDto extends IdEntity<ScheduleDto>{
@NotBlank
private String subAgencyId;
/*排序*/
private String dtoSeq;
@Transient
private String roomName;
}
......@@ -207,6 +207,7 @@ public class BArrangeServiceImpl implements BArrangeService {
BSubtask bSubtask = new BSubtask();
bSubtask.setName(subtask.getString("name"));
bSubtask.setArrangeId(arrange.getString("businessId"));
bSubtask.setSubtaskSeq(String.valueOf(i));
UserUtil.setCurrentPersistOperation(bSubtask);
bSubtaskRepository.insertSelective(bSubtask);
JSONArray childList2 = subtask.getJSONArray("childList");
......@@ -217,6 +218,7 @@ public class BArrangeServiceImpl implements BArrangeService {
bSubAgency.setAgencyCode(agency.getString("agencyCode"));
}
//再插入新记录
bSubAgency.setSubAgencySeq(String.valueOf(j));
UserUtil.setCurrentPersistOperation(bSubAgency);
bSubAgency.setSubtaskId(bSubtask.getBusinessId());
bSubAgencyRepository.insertSelective(bSubAgency);
......@@ -255,12 +257,6 @@ public class BArrangeServiceImpl implements BArrangeService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override
public PersistModel importExcel(HSSFWorkbook hwb, String token , String subAgencyId) {
//String termCode = bArrangeRepository.selectTermCodeByBSubtaskId(subAgencyId);
//BTerm bTerm = bTermRepository.queryBtermByCode(termCode).get(0);
//获取学期信息
//List<String> list = Week.buildList(bTerm.getStartDate(),bTerm.getEndDate());
//获取周数
//int weekNum = list.size();
ArrayList<ScheduleDto> scheduleDtos = new ArrayList<ScheduleDto>();
Boolean contanSunday = ExcelUtil.containSunday(hwb);
String[] headers = {"方案计划名","方案人数","方案课组","课程号","课程名","开课院系","课程属性","总学分","总学时",
......@@ -271,6 +267,7 @@ public class BArrangeServiceImpl implements BArrangeService {
"授课学时", "上机学时", "实验学时", "考试类型", "任课教师", "教师编号", "教学班组名", "教学班组编号", "周次", "周学时", "周一",
"周二", "周三", "周四", "周五", "周六","周日", "上课地点", "教室编号", "备注"};
}
//ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true,2); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true,2); //获取excel数据
if(values.get(0)[3]==null || values.get(0)[14]==null ||values.get(0)[16]==null ||values.get(0)[26]==null ||
values.get(0)[3].equals("") || values.get(0)[14].equals("") ||values.get(0)[16].equals("") ||values.get(0)[26].equals("")){
......@@ -284,103 +281,80 @@ public class BArrangeServiceImpl implements BArrangeService {
List<String> teacherCodes = new ArrayList<>();
List<String> classCodes = new ArrayList<>();
List<String> roomCodes = new ArrayList<>();
List<String> weekErrors = new ArrayList<>();
String[] wholeValue = new String[28];
int index = 0;
for (String[] value : values) {
ScheduleDto scheduleDto = new ScheduleDto();
//每一次遇到完整数据时将完整数据存放起来
if(!value[3].equals("")&&!value[14].equals("")&&!value[16].equals("")&&!value[26].equals("")){
wholeValue = value;
}
//判断1:根据课程编号查询是否有此门课程;
if(value[3].equals("")){
value[3] = wholeValue[3];
}
if(bLessonRepository.selectOne(new BLesson(value[3]))==null){
lessonCodes.add(value[3]);
continue;
}else{
if(bLessonRepository.selectOne(new BLesson(value[3].trim()))==null){
lessonCodes.add(value[3]);
continue;
}else{
wholeValue[3] = value[3];
}
}
//判断2:根据教师编号查询是否有此教师;
SysUser user1 =new SysUser();
if(value[14].equals("")){
value[14] = wholeValue[14];
}
SysUser user1 =new SysUser();
user1.setLoginName(value[14]);
user1.setDelFlag("0");
user1.setFlag("1");
if (sysUserMapper.selectOne(user1) == null) {
teacherCodes.add(value[14]);
continue;
}else{
user1.setLoginName(value[14]);
user1.setDelFlag("0");
user1.setFlag("1");
if (sysUserMapper.selectOne(user1) == null) {
teacherCodes.add(value[14]);
continue;
}else{
wholeValue[14] = value[14];
}
}
//判断3:根据班级编号查询是否有此班级;
if(value[16].equals("")){
value[16] = wholeValue[16];
}else{
if (bEduClassRepository.selectOne(new BEduClass(value[16].trim())) == null) {
classCodes.add(value[16]);
continue;
}else{
wholeValue[16] = value[16];
}
}
if (bEduClassRepository.selectOne(new BEduClass(value[16])) == null) {
classCodes.add(value[16]);
continue;
}
//判断4:根据教室编号查询是否有此教室;
//如果存在星期日,向后推一格
if(contanSunday){
if(value[27].equals("")){
value[27] = wholeValue[27];
}
if(bRoomsRepository.selectOne(new BRooms(value[27]))==null){
roomCodes.add(value[27]);
continue;
}else{
if(bRoomsRepository.selectOne(new BRooms(value[27].trim()))==null){
roomCodes.add(value[27]);
continue;
}else{
wholeValue[27] = value[27];
}
}
}else {
if(value[26].equals("")){
value[26] = wholeValue[26];
}
if(bRoomsRepository.selectOne(new BRooms(value[26]))==null){
roomCodes.add(value[26]);
continue;
}else{
if(bRoomsRepository.selectOne(new BRooms(value[26].trim()))==null){
roomCodes.add(value[26]);
continue;
}else{
wholeValue[26] = value[26];
}
}
}
//判断5:判断周数是否超过学期最大周数;
// int location = value[17].indexOf("-");
// if(location != -1){
// String maxWeek = value[17].substring(location + 1,value[17].length());
// if(Integer.valueOf(maxWeek) > weekNum){
// weekErrors.add(value[17]);
// continue;
// }
// else{
// //如果是第一周
// if(value.equals(values.get(0))){
// //如果第一周不存在周一,并且周一又有数据的话,抛弃此条数据
// if(value[18] != null && !value[18].equals("")){
// String[] s = list.get(0).split(",");
// if(s[0].equals("0")){
// continue;
// }
// }
// if(value[19] != null && !value[19].equals("")){
// String[] s = list.get(0).split(",");
// if(s[1].equals("0")){
// continue;
// }
// }
//
// }
//
// }
// }else{
// if(Integer.valueOf(value[17]) > weekNum){
// weekErrors.add(value[17]);
// continue;
// }
// }
//合法:通过了四次判断,证明可建立该排课
scheduleDto.setLessonCode(value[3]);
......@@ -402,6 +376,12 @@ public class BArrangeServiceImpl implements BArrangeService {
if(contanSunday)
scheduleDto.setSunday(value[25]);
scheduleDto.setSubAgencyId(subAgencyId);
//设置序号
if(value[16].equals(values.get(values.indexOf(value) -1 ))){
scheduleDto.setDtoSeq(String.valueOf(index));
}else{
scheduleDto.setDtoSeq(String.valueOf(++index));
}
scheduleDto.setCommonBusinessId();
UserUtil.setCurrentPersistOperation(scheduleDto);
scheduleDtos.add(scheduleDto);
......@@ -445,11 +425,6 @@ public class BArrangeServiceImpl implements BArrangeService {
result+="以下教室编号不存在:"+ JSON.toJSONString(roomCodes)+"。";
resultFlag = 0;
}
// if(weekErrors.size()>0){
// result+="以下周超过最大周数:"+ JSON.toJSONString(weekErrors)+"。";
// resultFlag = 0;
// }
return new PersistModel(resultFlag, result);
}
......@@ -457,8 +432,6 @@ public class BArrangeServiceImpl implements BArrangeService {
public PersistModel importExcel2(HSSFWorkbook hwb, String token, String subAgencyId) {
String termCode = bArrangeRepository.selectTermCodeByBSubtaskId(subAgencyId);
BTerm bTerm = bTermRepository.queryBtermByCode(termCode).get(0);
//List list1 = Week.buildList(bTerm.getStartDate(),bTerm.getEndDate());
//int weekNum = list1.size();
//获取时间集合
Map<String,Date> timeMap = FindTime.findTime(bTerm.getStartDate(),bTerm.getEndDate());
Boolean contanSunday = ExcelUtil.containSunday(hwb);
......@@ -470,6 +443,7 @@ public class BArrangeServiceImpl implements BArrangeService {
"授课学时", "上机学时", "实验学时", "考试类型", "任课教师", "教师编号", "教学班组名", "教学班组编号", "周次", "周学时", "周一",
"周二", "周三", "周四", "周五", "周六","周日", "上课地点", "教室编号", "备注"};
}
//ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true,2); //获取excel数据
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true,2); //获取excel数据
if(values.get(0)[3]==null || values.get(0)[14]==null ||values.get(0)[16]==null ||values.get(0)[26]==null ||
values.get(0)[3].equals("") || values.get(0)[14].equals("") ||values.get(0)[16].equals("") ||values.get(0)[26].equals("")){
......@@ -488,75 +462,76 @@ public class BArrangeServiceImpl implements BArrangeService {
String[] wholeValue = new String[28];
for (String[] value : values) {
//每一次遇到完整数据时将完整数据存放起来
if(!value[3].equals("")&&!value[14].equals("")&&!value[16].equals("")&&!value[26].equals("")){
wholeValue = value;
}
//每一次遇到完整数据时将完整数据存放起来
if(!value[3].equals("")&&!value[14].equals("")&&!value[16].equals("")&&!value[26].equals("")){
wholeValue = value;
}
//判断1:根据课程编号查询是否有此门课程;
if(value[3].equals("")){
value[3] = wholeValue[3];
}
if(bLessonRepository.selectOne(new BLesson(value[3]))==null){
lessonCodes.add(value[3]);
continue;
}else{
if(bLessonRepository.selectOne(new BLesson(value[3].trim()))==null){
lessonCodes.add(value[3]);
continue;
}else{
wholeValue[3] = value[3];
}
}
//判断2:根据教师编号查询是否有此教师;
SysUser user1 =new SysUser();
if(value[14].equals("")){
value[14] = wholeValue[14];
}
SysUser user1 =new SysUser();
user1.setLoginName(value[14]);
user1.setDelFlag("0");
user1.setFlag("1");
}else{
user1.setLoginName(value[14]);
user1.setDelFlag("0");
user1.setFlag("1");
if (sysUserMapper.selectOne(user1) == null) {
teacherCodes.add(value[14]);
continue;
if (sysUserMapper.selectOne(user1) == null) {
teacherCodes.add(value[14]);
continue;
}else{
wholeValue[14] = value[14];
}
}
//判断3:根据班级编号查询是否有此班级;
if(value[16].equals("")){
value[16] = wholeValue[16];
}
if (bEduClassRepository.selectOne(new BEduClass(value[16])) == null) {
classCodes.add(value[16]);
continue;
}else{
if (bEduClassRepository.selectOne(new BEduClass(value[16].trim())) == null) {
classCodes.add(value[16]);
continue;
}else{
wholeValue[16] = value[16];
}
}
//判断4:根据教室编号查询是否有此教室;
//如果存在星期日,向后推一格
if(contanSunday){
if(value[27].equals("")){
value[27] = wholeValue[27];
}
if(bRoomsRepository.selectOne(new BRooms(value[27]))==null){
roomCodes.add(value[27]);
continue;
}else{
if(bRoomsRepository.selectOne(new BRooms(value[27].trim()))==null){
roomCodes.add(value[27]);
continue;
}else{
wholeValue[27] = value[27];
}
}
}else {
if(value[26].equals("")){
value[26] = wholeValue[26];
}
if(bRoomsRepository.selectOne(new BRooms(value[26]))==null){
roomCodes.add(value[26]);
continue;
}else{
if(bRoomsRepository.selectOne(new BRooms(value[26].trim()))==null){
roomCodes.add(value[26]);
continue;
}else{
wholeValue[26] = value[26];
}
}
}
//判断5:判断周数是否超过学期最大周数;
// int subStringlocation = value[17].indexOf("-");
// String maxWeek = value[17].substring(subStringlocation + 1,value[17].length());
// if(Integer.valueOf(maxWeek) > weekNum){
// weekErrors.add(value[17]);
// continue;
// }
String week = value[17];
if(week.contains("-")){
......
......@@ -130,7 +130,7 @@ public class BRoomsController extends FileController<BRooms> {
PersistModel data = bRoomsServiceImpl.uploadExcel(MultipartFile2HSSFWorkbookConverter.convert(uploadFile));
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
data.getInfluenceReason());
data.getInfluenceReason(),
null);
}
}
......@@ -129,30 +129,30 @@ public class BRoomsServiceImpl implements BRoomsService {
String result = "";
for(String[] value : values){
int index = values.indexOf(value) + 1;
if(value[0] == null || value[1] == null || value[2] == null || value[3] == null || value[4] == null || value[5] == null
&& value[0].equals("") && value[1].equals("") && value[2].equals("") && value[3].equals("") && value[4].equals("") && value[5].equals("")){
result += "表中存在空数据";
|| value[0].equals("") || value[1].equals("") || value[2].equals("") || value[3].equals("") || value[4].equals("") || value[5].equals("")){
result += "表中第 " + index + " 行存在空数据 \n";
continue;
}
if(allCode.contains(value[1])){
result += "编号 " + value[1] + " 已经存在于数据库 ";
result += "表中第 " + index + " 行,编号 " + value[1] + " 已经存在于数据库 \n";
continue;
}
if(currentlyCode.contains(value[1])){
result += "编号 " + value[1] + " 在表中重复 ";
result += "表中第 " + index + " 行,编号 " + value[1] + " 在表中重复 \n";
continue;
}
//Int最大值为2147483648,所以不能超过9位数
if(value[5].length() >= 9){
result += "编号 " + value[1] + " 的数据座位数不合法 ";
result += "表中第 " + index + " 行,编号 " + value[1] + " 的数据座位数不合法 \n";
continue;
}
try{
int seat = Integer.valueOf(value[5]);
}catch (Exception e){
result += "编号 " + value[1] + " 的数据座位数不合法 ";
result += "表中第 " + index + " 行,编号 " + value[1] + " 的数据座位数不合法 \n";
continue;
}
BRooms bRooms = new BRooms();
......@@ -205,9 +205,9 @@ public class BRoomsServiceImpl implements BRoomsService {
}
if(list.size() != 0){
int i = bRoomsRepository.addExcel(list);
result += "成功插入了 " + i + "条数据";
result += "成功插入了 " + i + "条数据 \n";
}else {
result += "没有输入被插入";
result += "没有输入被插入 \n";
flag = 0;
}
......
......@@ -5,6 +5,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellRangeAddress;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultServiceEnums;
......@@ -129,6 +130,139 @@ public class ExcelUtil {
return repeatMessage.toString();
}
public static ArrayList<String[]> importExcelv2(HSSFWorkbook hwb, String[] headers, boolean allowEmpty , int headNum){
ArrayList<String[]> values = new ArrayList<>();
for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
HSSFSheet hs = hwb.getSheetAt(i);
if (hs == null)
continue;
else {
List<CellRangeAddress> cellRangeAddressList = hs.getMergedRegions();
int firstrownum = hs.getFirstRowNum(); //第一行
int lastrownum = hs.getLastRowNum(); //最后一行
List<Integer> emptyColList=new ArrayList<>();
for (int j = firstrownum + headNum; j <= lastrownum; j++) {
HSSFRow hr = hs.getRow(j);
if(hr==null||hr.getLastCellNum()<0){
continue;
}
int firstcolumnnum = hr.getFirstCellNum();
int lastcolumnnum = hr.getLastCellNum();
String[] value = new String[lastcolumnnum + 2];
boolean hasEmpty = true;
//修改过!!!!!!!!!!!!
for (int k = 0; k < lastcolumnnum; k++) {
HSSFCell hc = hr.getCell(k);
if(hc == null){
value[k] = "";
continue;
}
if (j==firstrownum + headNum) {
//判断表头那一列为空数据并记录。
if(parseDB(hc).trim().equals("")) {
emptyColList.add(-1);
}else{
emptyColList.add(k);
}
}
else {
if(allowEmpty){//允许单元格为空,但不允许整行为空时
//hc != null &&
if (hc != null && !parseDB(hc).trim().equals("")&&emptyColList.get(k)!=-1&&hasEmpty) {
//只要一行中有一个值不为空,即为正确数据
hasEmpty = false;
}
}else{//不允许单元格为空,只要一行中有一个值为空,即为错误数据
hasEmpty = false;
//hc != null &&
if (hc != null && parseDB(hc) != null && parseDB(hc).trim().equals("")&&emptyColList.get(k)!=-1) {
//在第j行第k列有空数据,且该列表头不是空的,则舍弃本行数据。
hasEmpty = true;
break;
}
}
}
//如果此单元格为空则插入""
if(hc == null){
value[k] = "";
}else {
value[k] = parseDB(hc);
}
}
if(j==firstrownum + headNum){
for(int h=0;h<headers.length;h++){
if(!value[h].trim().equals(headers[h])){
System.out.println("导入头错误");
return null;
}
}
}else{
if (!hasEmpty) {
//判断是否是空数据并且存在空数据不是合并单元格
if(containSunday(hwb)){
CellRangeAddress value3 = belongBigCell(cellRangeAddressList,j,3,hs);
CellRangeAddress value14 = belongBigCell(cellRangeAddressList,j,14,hs);
CellRangeAddress value16 = belongBigCell(cellRangeAddressList,j,16,hs);
CellRangeAddress value27 = belongBigCell(cellRangeAddressList,j,27,hs);
if((value[3] == null || value[3].equals("")) && value3 == null
|| (value[14] == null || value[14].equals("")) && value14 == null
|| (value[16] == null || value[16].equals("")) && value16 == null
|| (value[27] == null || value[27].equals("")) && value27 == null){
//如果存在,跳过插入
continue;
}
if((value[3] == null || value[3].equals("")) && value3 != null){
value[3] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
if((value[14] == null || value[14].equals("")) && value3 != null){
value[14] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
if((value[16] == null || value[16].equals("")) && value3 != null){
value[16] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
if((value[27] == null || value[27].equals("")) && value3 != null){
value[27] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
}else{
CellRangeAddress value3 = belongBigCell(cellRangeAddressList,j,3,hs);
CellRangeAddress value14 = belongBigCell(cellRangeAddressList,j,14,hs);
CellRangeAddress value16 = belongBigCell(cellRangeAddressList,j,16,hs);
CellRangeAddress value26 = belongBigCell(cellRangeAddressList,j,26,hs);
if((value[3] == null || value[3].equals("")) && value3 == null
|| (value[14] == null || value[14].equals("")) && value14 == null
|| (value[16] == null || value[16].equals("")) && value16 == null
|| (value[26] == null || value[26].equals("")) && value26 == null){
//如果存在,跳过插入
continue;
}
//如果属于合并单元格并且为空,则插入此合并单元格数据
if((value[3] == null || value[3].equals("")) && value3 != null){
value[3] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
if((value[14] == null || value[14].equals("")) && value3 != null){
value[14] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
if((value[16] == null || value[16].equals("")) && value3 != null){
value[16] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
if((value[26] == null || value[26].equals("")) && value3 != null){
value[26] = parseDB(hs.getRow(value3.getFirstRow()).getCell(value3.getFirstColumn()));
}
}
values.add(value);
}
}
}
}
}
return values;
}
/**
* 准备工作
* @param hc
......@@ -157,4 +291,19 @@ public class ExcelUtil {
return i == 29;
}
public static CellRangeAddress belongBigCell(List<CellRangeAddress> list , int rowIndex , int columnIndex , HSSFSheet hssfSheet){
for(CellRangeAddress cellRangeAddress : list){
//判断是否是合并单元格
if(cellRangeAddress.containsRow(rowIndex) && cellRangeAddress.containsColumn(columnIndex)){
HSSFRow hssfRow = hssfSheet.getRow(cellRangeAddress.getFirstRow());
HSSFCell hssfCell = hssfRow.getCell(cellRangeAddress.getFirstColumn());
//判断整个合并单元格是否为空
if(hssfCell != null && !parseDB(hssfCell).trim().equals("")){
return cellRangeAddress;
}
}
}
return null;
}
}
......@@ -103,7 +103,7 @@
<insert id="insertList">
insert into b_schedule_dto(business_id,flag,del_flag,update_by,create_by,create_date,update_date,remarks,
lesson_code,teacher_code,class_code,week,class_hour,
monday,tuesday,wednesday,thursday,friday,saturday,sunday,room_code,sub_agency_id)
monday,tuesday,wednesday,thursday,friday,saturday,sunday,room_code,sub_agency_id,dto_seq)
values
<foreach collection="list" item="item" separator=",">
(#{item.businessId},#{item.flag},#{item.delFlag},#{item.updateBy},#{item.createBy},
......@@ -111,7 +111,7 @@
#{item.lessonCode},#{item.teacherCode},#{item.classCode},
#{item.week},#{item.classHour},
#{item.monday},#{item.tuesday},#{item.wednesday},#{item.thursday},#{item.friday},#{item.saturday},
#{item.sunday},#{item.roomCode},#{item.subAgencyId})
#{item.sunday},#{item.roomCode},#{item.subAgencyId},#{item.dtoSeq})
</foreach>
</insert>
......
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