parent
ea48c4e74c
commit
bfa0273c69
31 changed files with 934 additions and 171 deletions
@ -0,0 +1,22 @@ |
||||
package com.msdw.tms.common.utils; |
||||
|
||||
/** |
||||
* 此类用于公用常量设置 |
||||
*/ |
||||
public class ConstantUtils { |
||||
//绑定电子科大的schoolId
|
||||
public static final Integer Keda_schoolId = 2105; |
||||
|
||||
//绑定角色ID
|
||||
public static final Integer STUDENT_ROLE = 4; |
||||
public static final String STR_STUDENT_ROLE = "4"; |
||||
|
||||
//平台id
|
||||
public static final Integer PLATFORMID= 1; |
||||
|
||||
//excel模板信息表id
|
||||
public static final int XLSX_TEMPLATE_ID = 2; |
||||
|
||||
//用户初始密码
|
||||
public static final String INITIAL_PASSWORD = "huoran123"; |
||||
} |
@ -0,0 +1,109 @@ |
||||
package com.msdw.tms.common.utils; |
||||
|
||||
import com.msdw.tms.entity.vo.StudentVo; |
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
import org.apache.poi.ss.usermodel.*; |
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class ExcelImportHelper { |
||||
|
||||
/** |
||||
* 读取学生管理 |
||||
* @param file |
||||
* @return |
||||
*/ |
||||
public static List<StudentVo> readStudent(MultipartFile file) { |
||||
List<StudentVo> list = new ArrayList<StudentVo>(); |
||||
|
||||
Workbook workbook=getWorkbook(file); |
||||
StudentVo student = null; |
||||
// 循环工作表Sheet
|
||||
for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { |
||||
Sheet hssfSheet = workbook.getSheetAt(numSheet); |
||||
if (hssfSheet == null) { |
||||
continue; |
||||
} |
||||
// 循环行Row//开始行2
|
||||
for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { |
||||
Row row = hssfSheet.getRow(rowNum); |
||||
|
||||
Cell phone; |
||||
Cell email; |
||||
if (row != null) { |
||||
student = new StudentVo(); |
||||
row.getCell(0).setCellType(CellType.STRING); |
||||
Cell studentName = row.getCell(0); |
||||
row.getCell(1).setCellType(CellType.STRING); |
||||
Cell schoolAppellationName = row.getCell(1); |
||||
row.getCell(2).setCellType(CellType.STRING); |
||||
Cell account = row.getCell(2); |
||||
row.getCell(3).setCellType(CellType.STRING); |
||||
Cell studentNumber = row.getCell(3); |
||||
if (row.getCell(4)!=null){ |
||||
row.getCell(4).setCellType(CellType.STRING); |
||||
phone = row.getCell(4); |
||||
}else { |
||||
phone = row.createCell(4); |
||||
} |
||||
if (row.getCell(5)!=null){ |
||||
row.getCell(5).setCellType(CellType.STRING); |
||||
email = row.getCell(5); |
||||
}else { |
||||
email = row.createCell(5); |
||||
} |
||||
// row.getCell(4).setCellType(CellType.STRING);
|
||||
// Cell phone = row.getCell(4);
|
||||
// row.getCell(5).setCellType(CellType.STRING);
|
||||
// Cell email = row.getCell(5);
|
||||
|
||||
|
||||
// 学生姓名
|
||||
student.setUserName(studentName.getStringCellValue()); |
||||
// 角色id
|
||||
student.setRoleId(ConstantUtils.STUDENT_ROLE); |
||||
// 学生学号
|
||||
student.setWorkNumber(studentNumber.getStringCellValue()); |
||||
//所属院校
|
||||
student.setSchoolAppellationName(schoolAppellationName.getStringCellValue()); |
||||
//用户账号
|
||||
student.setAccount(account.getStringCellValue()); |
||||
//电话
|
||||
student.setPhone(phone.getStringCellValue()); |
||||
//邮箱
|
||||
student.setEmail(email.getStringCellValue()); |
||||
//学校id
|
||||
student.setSchoolId(ConstantUtils.Keda_schoolId); |
||||
list.add(student); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
return list; |
||||
} |
||||
|
||||
private static Workbook getWorkbook(MultipartFile file) { |
||||
String fileName = file.getOriginalFilename(); |
||||
Workbook workbook = null; |
||||
|
||||
if (fileName.endsWith("xlsx")) { |
||||
try { |
||||
workbook = new XSSFWorkbook(file.getInputStream()); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
}else if (fileName.endsWith("xls")) { |
||||
try { |
||||
workbook = new HSSFWorkbook(file.getInputStream()); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return workbook; |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
package com.msdw.tms.entity.vo; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
@Data |
||||
@Accessors(chain = true) |
||||
public class RulesVo { |
||||
//题型(1单选2多选3判断)
|
||||
private Integer types; |
||||
//试题数量
|
||||
private Integer questionsNumber; |
||||
//测评对应该试题数量
|
||||
// private int rulesNumber;
|
||||
//试题id
|
||||
private Integer questionId; |
||||
|
||||
} |
Binary file not shown.
@ -0,0 +1,25 @@ |
||||
package com.msdw.tms; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import redis.clients.jedis.Jedis; |
||||
|
||||
@SpringBootTest |
||||
public class JedisTest { |
||||
@Test |
||||
public void test() { |
||||
Jedis jedis = null; |
||||
try { |
||||
jedis = new Jedis("127.0.0.1", 6379); |
||||
//120.78.198.231
|
||||
System.out.println(jedis.ping()); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
if (jedis != null) { |
||||
jedis.close(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue