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;
}
......@@ -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