四六级数据导入接口以及文件模版下载接口

This commit is contained in:
Cool 2024-10-11 20:22:54 +08:00
parent 633ca01ac8
commit 489efb0ae4
16 changed files with 710 additions and 335 deletions

View File

@ -3,6 +3,11 @@ package org.jeecg.modules.anno;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* @Description DBF行标识
* @Author Cool
* @Date 13:03 2024/10/11
**/
@Retention(RetentionPolicy.RUNTIME)
public @interface AttributeName {

View File

@ -0,0 +1,59 @@
package org.jeecg.modules.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.service.CetDataImport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* Created with IntelliJ IDEA.
*
* @Author: Cool
* @Date: 2024/10/10/22:06
* @Description:
*/
@RestController
@RequestMapping("cetDataImport")
@Api(value = "四六级数据导入接口")
@Slf4j
public class CetDataImportController {
@Autowired
private CetDataImport cetDataImport;
/**
* @param file dbf文件
* @param batch 考试批次
* @param level cet等级(cet4/cet6)
* @Author Cool
* @Date 22:08 2024/10/10
* DBF数据导入
**/
@RequestMapping("dbfImport")
@ApiOperation("DBF数据导入")
public Result<?> DBFImport(@RequestParam("file") MultipartFile file, @RequestParam("batch") String batch, @RequestParam("level") String level) {
return cetDataImport.readDBF(file, batch, level);
}
@RequestMapping("downloadTemplate")
@ApiOperation("四六级导入数据文件模版")
public Result<?> downloadTemplate(HttpServletResponse response) {
return cetDataImport.downloadTemplate(response);
}
// @RequestMapping("test")
// @ApiOperation("DBF数据导入")
// public Result<?> test() throws FileNotFoundException {
// return cetDataImport.readDBF1();
// }
}

View File

@ -3,6 +3,7 @@ package org.jeecg.modules.controller;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.entity.Cet_6;
@ -160,4 +161,10 @@ public class Cet_6Controller extends JeecgController<Cet_6, ICet_6Service> {
return super.importExcel(request, response, Cet_6.class);
}
@RequestMapping("getRate")
public Result<?> getRate() {
return cet_6Service.getGrateRate();
}
}

View File

@ -1,47 +0,0 @@
package org.jeecg.modules.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.modules.anno.AttributeName;
import java.io.Serializable;
import java.util.Date;
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "cet_english对象", description = "四六级英语")
public class CET implements Serializable {
private static final long serialVersionUID = 1L;
@AttributeName(4)
@ApiModelProperty(value = "学生姓名")
private String name;
@AttributeName(11)
@ApiModelProperty(value = "学生所在学院")
private String college;
@AttributeName(15)
@ApiModelProperty(value = "学生成绩")
private Integer result;
@AttributeName(19)
@ApiModelProperty(value = "学生学号")
private String id;
@ApiModelProperty(value = "考试批次")
private Date batch;
@ApiModelProperty(value = "学生入学时间")
private String entrydate;
@AttributeName(12)
@ApiModelProperty(value = "学生听力成绩")
private Integer listen;
@AttributeName(13)
@ApiModelProperty(value = "阅读成绩")
private Integer reading;
@AttributeName(14)
@ApiModelProperty(value = "写作成绩")
private Integer writing;
}

View File

@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.modules.anno.AttributeName;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
@ -32,17 +33,21 @@ public class Cet_4 implements Serializable {
/**学生姓名*/
@Excel(name = "学生姓名", width = 15)
@AttributeName(4)
@ApiModelProperty(value = "学生姓名")
private String name;
/**学生所在学院*/
@Excel(name = "学生所在学院", width = 15)
@AttributeName(11)
@ApiModelProperty(value = "学生所在学院")
private String college;
/**学生成绩*/
@Excel(name = "学生成绩", width = 15)
@AttributeName(15)
@ApiModelProperty(value = "学生成绩")
private Integer result;
/**学生学号*/
@AttributeName(19)
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "学生学号")
private String id;
@ -58,14 +63,17 @@ public class Cet_4 implements Serializable {
private String entrydate;
/**听力成绩*/
@Excel(name = "听力成绩", width = 15)
@AttributeName(12)
@ApiModelProperty(value = "听力成绩")
private Integer listen;
/**阅读成绩*/
@Excel(name = "阅读成绩", width = 15)
@AttributeName(13)
@ApiModelProperty(value = "阅读成绩")
private Integer reading;
/**作文成绩*/
@Excel(name = "作文成绩", width = 15)
@AttributeName(14)
@ApiModelProperty(value = "作文成绩")
private Integer writing;
/**专业名字*/

View File

@ -1,12 +1,14 @@
package org.jeecg.modules.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.modules.anno.AttributeName;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
@ -28,42 +30,85 @@ import lombok.experimental.Accessors;
public class Cet_6 implements Serializable {
private static final long serialVersionUID = 1L;
/**学生姓名*/
/**
* 学生姓名
*/
@Excel(name = "学生姓名", width = 15)
@AttributeName(4)
@ApiModelProperty(value = "学生姓名")
private java.lang.String name;
/**学生所在学院*/
private String name;
/**
* 学生所在学院
*/
@Excel(name = "学生所在学院", width = 15)
@AttributeName(11)
@ApiModelProperty(value = "学生所在学院")
private java.lang.String college;
/**学生成绩*/
private String college;
/**
* 学生成绩
*/
@Excel(name = "学生成绩", width = 15)
@AttributeName(15)
@ApiModelProperty(value = "学生成绩")
private java.lang.Integer result;
/**学生学号*/
private Integer result;
/**
* 学生学号
*/
@AttributeName(19)
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "学生学号")
private java.lang.String id;
/**考试批次*/
private String id;
/**
* 考试批次
*/
@Excel(name = "考试批次", width = 15, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty(value = "考试批次")
private java.util.Date batch;
/**入学时间*/
private Date batch;
/**
* 入学时间
*/
@Excel(name = "入学时间", width = 15)
@ApiModelProperty(value = "入学时间")
private java.lang.String entrydate;
/**听力成绩*/
private String entrydate;
/**
* 听力成绩
*/
@Excel(name = "听力成绩", width = 15)
@AttributeName(12)
@ApiModelProperty(value = "听力成绩")
private java.lang.Integer listen;
/**阅读成绩*/
private Integer listen;
/**
* 阅读成绩
*/
@Excel(name = "阅读成绩", width = 15)
@AttributeName(13)
@ApiModelProperty(value = "阅读成绩")
private java.lang.Integer reading;
/**作文成绩*/
private Integer reading;
/**
* 作文成绩
*/
@Excel(name = "作文成绩", width = 15)
@AttributeName(14)
@ApiModelProperty(value = "作文成绩")
private java.lang.Integer writing;
private Integer writing;
/**
* 专业名字
*/
@Excel(name = "专业名称", width = 15)
@ApiModelProperty(value = "专业名称")
private String majorname;
/**
* 培养层次
*/
@Excel(name = "培养层次", width = 15)
@ApiModelProperty(value = "培养层次")
private String level;
/**
* 在校状态
*/
@Excel(name = "在校状态", width = 15)
@ApiModelProperty(value = "在校状态")
private String state;
}

View File

@ -1,13 +0,0 @@
package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.jeecg.modules.entity.CET;
public interface CetMapper extends BaseMapper<CET> {
@Insert("insert into cet_4 (name, college, result, id, batch, entrydate, listen, reading, writing) values (#{name}, #{college}, #{result}, #{id},#{batch}, #{entrydate}, #{listen}, #{reading}, #{writing})")
void insertCET_4(CET cet);
@Insert("insert into cet_6 (name, college, result, id, batch, entrydate, listen, reading, writing)values (#{name}, #{college}, #{result}, #{id},#{batch}, #{entrydate}, #{listen}, #{reading}, #{writing})")
void insertCET_6(CET cet);
}

View File

@ -0,0 +1,276 @@
package org.jeecg.modules.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linuxense.javadbf.DBFField;
import com.linuxense.javadbf.DBFReader;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.anno.AttributeName;
import org.jeecg.modules.entity.Cet_4;
import org.jeecg.modules.entity.Cet_6;
import org.jeecg.modules.utils.DateUtil;
import org.jeecg.modules.utils.ExportUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.sql.Timestamp;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Slf4j
@Service
public class CetDataImport {
private final String CET_DATA_IMPORT_TEMPLATE="template/cetDataImportTemplate.xlsx";
private final String CET_DATE_FILE_TEMPLATE_NAME = "四六级数据导入模版.xlsx";
// @Autowired
// CetMapper_6 cetMapper6;
@Autowired
ICet_4Service cet4Service;
@Autowired
ICet_6Service cet6Service;
/**
* @Author Cool
* @Date 12:58 2024/10/11
**/
@Transactional(rollbackFor = Exception.class)
public Result<?> readDBF(MultipartFile file, String batchStr, String level) {
if (!(level.equals("cet4") || level.equals("cet6"))) {
return Result.error("请选择正确的考试水平");
}
Set<String> collegeSet = getColleges();
Date batch = DateUtil.formatDateToDay(batchStr);
boolean isCet4 = level.equals("cet4");
try {
List<Cet_6> cet6List = new ArrayList<>();
List<Cet_4> cet4List = new ArrayList<>();
DBFReader dbfReader = new DBFReader(file.getInputStream(), Charset.forName("GBK"));
if (!checkFileFormat(dbfReader)) {
return Result.error("上传文件格式错误");
}
Object[] rowValues;
while ((rowValues = dbfReader.nextRecord()) != null) {
Cet_6 cet6 = new Cet_6();
Cet_4 cet4 = new Cet_4();
Class<?> cetClass;
if (isCet4) {
cetClass = cet4.getClass();
} else {
cetClass = cet6.getClass();
}
Field[] fields = cetClass.getDeclaredFields();
//对单个学生对象进行属性注入
for (Field field : fields) {
if (field.getDeclaredAnnotation(AttributeName.class) == null) continue;
int fieldIndex = field.getDeclaredAnnotation(AttributeName.class).value();
field.setAccessible(true);
// 获取字段的类型
Class<?> fieldType = field.getType();
//进行类型区分
if (fieldType == String.class) {
Object value = rowValues[fieldIndex - 1];
if (isCet4) {
field.set(cet4, String.valueOf(value));
} else {
field.set(cet6, String.valueOf(value));
}
if (field.getName().equals("college")) {
if (!collegeSet.contains(String.valueOf(value))) {
break;
}
}
if (field.getName().equals("id")) {
// System.out.println(field.getName());
String entryDate = String.valueOf(value);
//对学生信息进行检查
entryDate = entryDate.substring(0, 4);
int entry = Integer.parseInt(entryDate);
int year = DateUtils.getYear();
if (entry < 2010 || entry > year + 1 || Pattern.compile("[a-zA-Z]").matcher(entryDate).find())
continue;
if (isCet4) {
cet4.setEntrydate(entryDate);
} else {
cet6.setEntrydate(entryDate);
}
}
} else if (fieldType == int.class || fieldType == Integer.class) {
Object value = rowValues[fieldIndex - 1];
if (isCet4) {
field.set(cet4, (int) Double.parseDouble(String.valueOf(value)));
} else {
field.set(cet6, (int) Double.parseDouble(String.valueOf(value)));
}
} else if (fieldType == Date.class) {
Object value = rowValues[fieldIndex - 1];
if (isCet4) {
field.set(cet4, new Date(((Timestamp) value).getTime()));
} else {
field.set(cet6, new Date(((Timestamp) value).getTime()));
}
}
}
cet6.setBatch(batch);
cet4.setBatch(batch);
if (isCet4) {
if (collegeSet.contains(cet4.getCollege())) {
cet4List.add(cet4);
}
if (cet4List.size() >= 500) {
cet4Service.save(cet4);
cet4Service.saveBatch(cet4List);
log.info("Cet学生{}", cet4);
cet4List.clear();
}
} else {
if (collegeSet.contains(cet6.getCollege())) {
cet6List.add(cet6);
}
if (cet6List.size() >= 500) {
cet6Service.save(cet6);
cet6Service.saveBatch(cet6List);
cet6List.clear();
}
}
}
if (isCet4) {
cet4Service.saveBatch(cet4List);
} else {
cet6Service.saveBatch(cet6List);
}
return Result.ok();
} catch (Exception e) {
e.printStackTrace();
return Result.error("出现异常,请联系管理员");
}
}
public Set<String> getColleges() {
LambdaQueryWrapper<Cet_4> wrapper = new LambdaQueryWrapper<>();
wrapper.groupBy(Cet_4::getCollege);
List<Cet_4> list = cet4Service.list(wrapper);
return list.stream().map(Cet_4::getCollege).collect(Collectors.toSet());
}
private boolean checkFileFormat(DBFReader dbfReader) {
if (!"ks_xm".equals(dbfReader.getField(3).getName())) {
return false;
}
if (!"ks_xy_dm".equals(dbfReader.getField(10).getName())) {
return false;
}
if (!"tl".equals(dbfReader.getField(11).getName())) {
return false;
}
if (!"yd".equals(dbfReader.getField(12).getName())) {
return false;
}
if (!"xz".equals(dbfReader.getField(13).getName())) {
return false;
}
if (!"zf".equals(dbfReader.getField(14).getName())) {
return false;
}
if (!"Ks_xh".equals(dbfReader.getField(18).getName())) {
return false;
}
return true;
}
/**
* 测试用
*
* @Author Cool
* @Date 19:03 2024/10/11
**/
@Transactional(rollbackFor = Exception.class)
public Result<?> readDBF1() throws FileNotFoundException {
Set<String> collegeSet = getColleges();
String batchStr = "2020-12-01";
String level = "";
File file = new File("C:\\Users\\86183\\Desktop\\202012-202406六级成绩\\2021下半年英语六级成绩.dbf");
InputStream inputStream = new FileInputStream(file);
Date batch = DateUtil.formatDateToDay(batchStr);
try {
List<Cet_6> cet6List = new ArrayList<>();
DBFReader dbfReader = new DBFReader(inputStream, Charset.forName("GBK"));
DBFField field1 = dbfReader.getField(0);
Object[] rowValues = dbfReader.nextRecord();
while ((rowValues = dbfReader.nextRecord()) != null) {
Cet_6 cet6 = new Cet_6();
Class<?> cetClass = cet6.getClass();
Field[] fields = cetClass.getDeclaredFields();
//对单个学生对象进行属性注入
for (Field field : fields) {
if (field.getDeclaredAnnotation(AttributeName.class) == null) continue;
int fieldIndex = field.getDeclaredAnnotation(AttributeName.class).value();
field.setAccessible(true);
// 获取字段的类型
Class<?> fieldType = field.getType();
//进行类型区分
if (fieldType == String.class) {
Object value = rowValues[fieldIndex - 1];
field.set(cet6, String.valueOf(value));
if (field.getName().equals("college")) {
if (!collegeSet.contains(String.valueOf(value))) {
break;
}
}
if (field.getName().equals("id")) {
// System.out.println(field.getName());
String entryDate = String.valueOf(value);
//对学生信息进行检查
entryDate = entryDate.substring(0, 4);
int entry = Integer.parseInt(entryDate);
int year = DateUtils.getYear();
if (entry < 2010 || entry > year + 1 || Pattern.compile("[a-zA-Z]").matcher(entryDate).find())
continue;
cet6.setEntrydate(entryDate);
}
} else if (fieldType == int.class || fieldType == Integer.class) {
Object value = rowValues[fieldIndex - 1];
field.set(cet6, (int) Double.parseDouble(String.valueOf(value)));
} else if (fieldType == Date.class) {
Object value = rowValues[fieldIndex - 1];
field.set(cet6, new Date(((Timestamp) value).getTime()));
}
}
}
return Result.ok();
} catch (Exception e) {
e.printStackTrace();
return Result.error("出现异常,请联系管理员");
}
}
public Result<?> downloadTemplate(HttpServletResponse response) {
try {
ExportUtil.downloadExcelTemplate(response, CET_DATE_FILE_TEMPLATE_NAME, CET_DATA_IMPORT_TEMPLATE);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -1,115 +0,0 @@
package org.jeecg.modules.service;
import com.linuxense.javadbf.DBFReader;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.anno.AttributeName;
import org.jeecg.modules.entity.CET;
import org.jeecg.modules.mapper.CetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
@Service
public class DBFImporter {
@Resource
CetMapper cetMapper;
// @Autowired
// CetMapper_6 cetMapper6;
public void readDBF(InputStream inputStream, Date batch, String level, String charsetName) {
try {
// List<CET> cetList = new ArrayList<>();
DBFReader dbfReader = new DBFReader(inputStream, Charset.forName(charsetName));
Object[] rowValues;
while ((rowValues = dbfReader.nextRecord()) != null) {
CET cet = new CET();
Class<?> cetClass = cet.getClass();
Field[] fields = cetClass.getDeclaredFields();
//对单个学生对象进行属性注入
for (Field field : fields) {
if (field.getDeclaredAnnotation(AttributeName.class) == null) continue;
int fieldIndex = field.getDeclaredAnnotation(AttributeName.class).value();
field.setAccessible(true);
// 获取字段的类型
Class<?> fieldType = field.getType();
//进行类型区分
if (fieldType == String.class) {
Object value = rowValues[fieldIndex - 1];
field.set(cet, String.valueOf(value));
if (field.getName().equals("id")) {
// System.out.println(field.getName());
String entryDate = String.valueOf(value);
//对学生信息进行检查
int entry = Integer.parseInt(entryDate);
int year = DateUtils.getYear();
if (entry<2010||entry>year+1||Pattern.compile("[a-zA-Z]").matcher(entryDate).find()) continue;
cet.setEntrydate(entryDate.substring(0, 4));
}
} else if (fieldType == int.class || fieldType == Integer.class) {
Object value = rowValues[fieldIndex - 1];
field.set(cet, (int) Double.parseDouble(String.valueOf(value)));
} else if (fieldType == Date.class) {
Object value = rowValues[fieldIndex - 1];
field.set(cet, new Date(((Timestamp) value).getTime()));
}
}
cet.setBatch(batch);
// System.out.println(cet);
// cetList.add(cet);
System.out.println(cet);
if (level.equals("英语四级")) {
cetMapper.insertCET_4(cet);
}
if (level.equals("英语六级")) {
cetMapper.insertCET_6(cet);
}
}
// System.out.println(cetList.size());
} catch (Exception e) {
e.printStackTrace();
}
}
// private static Date extractDateFromPath(String filePath) {
// // 在文件路径中找到日期部分的起始位置
// String[] pathArray = filePath.split("\\\\");
// String date = pathArray[pathArray.length - 2];
//
//
// // 截取日期部分
// String dateStr = date.substring(0, 7) + "-01";
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// try {
//
// return simpleDateFormat.parse(dateStr);
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
//
// }
//
// private String getLevel(String filePath) {
// String[] pathArray = filePath.split("\\\\");
// String level = pathArray[pathArray.length - 1];
// return level.substring(0, 4);
// }
}

View File

@ -1,14 +1,11 @@
package org.jeecg.modules.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet_6;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Date;
/**
* @Description: cet_6
* @Author: jeecg-boot
@ -16,5 +13,7 @@ import java.util.Date;
* @Version: V1.0
*/
public interface ICet_6Service extends IService<Cet_6> {
public Result<JSONObject> getRate(Cet_6 data);
Result<JSONObject> getRate(Cet_6 data);
Result<?> getGrateRate();
}

View File

@ -0,0 +1,19 @@
package org.jeecg.modules.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.entity.Cet4_major;
import org.jeecg.modules.mapper.Cet4_majorMapper;
import org.springframework.stereotype.Service;
/**
* Created with IntelliJ IDEA.
*
* @Author: Cool
* @Date: 2024/10/11/15:52
* @Description:
*/
@Service
@Slf4j
public class CetMajorServiceImpl extends ServiceImpl<Cet4_majorMapper, Cet4_major> {
}

View File

@ -1,13 +1,16 @@
package org.jeecg.modules.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet4_major;
import org.jeecg.modules.entity.Cet_4;
import org.jeecg.modules.entity.Cet_6;
import org.jeecg.modules.mapper.Cet_6Mapper;
import org.jeecg.modules.service.ICet_6Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -16,6 +19,7 @@ import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
@ -25,11 +29,17 @@ import java.util.stream.Collectors;
* @Version: V1.0
*/
@Service
@Slf4j
public class Cet_6ServiceImpl extends ServiceImpl<Cet_6Mapper, Cet_6> implements ICet_6Service {
@Resource
Cet_6Mapper cet6Mapper;
@Autowired
Cet_4ServiceImpl cet4Service;
@Autowired
CetMajorServiceImpl cetMajorService;
@Override
public Result<JSONObject> getRate(Cet_6 cet) {
JSONObject jsonObject = new JSONObject();
@ -45,8 +55,7 @@ public class Cet_6ServiceImpl extends ServiceImpl<Cet_6Mapper, Cet_6> implements
double sum = (double) getNum(cet);
double size = entry.getValue().size();
double passRate = sum / size;
jsonObject.put(String.valueOf(entry.getKey()),
passRate);
jsonObject.put(String.valueOf(entry.getKey()), passRate);
}
return Result.OK(jsonObject);
@ -60,15 +69,42 @@ public class Cet_6ServiceImpl extends ServiceImpl<Cet_6Mapper, Cet_6> implements
double sum = (double) getNum(cet);
double size = entry.getValue().size();
double passRate = sum / size;
jsonObject.put(String.valueOf(entry.getKey()),
passRate);
jsonObject.put(String.valueOf(entry.getKey()), passRate);
}
return Result.OK(jsonObject);
}
else return null;
} else return null;
}
@Override
public Result<?> getGrateRate() {
LambdaQueryWrapper<Cet_6> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Cet_6::getEntrydate, "2020");
List<Cet_6> list1 = list(wrapper);
Set<String> allStudent1 = list1.stream().map(Cet_6::getId).collect(Collectors.toSet());
log.info("六级总考试人数,{}",allStudent1.size());
wrapper.ge(Cet_6::getResult, 425);
List<Cet_6> list = list(wrapper);
log.info("六级总通过人数,{}", list.size());
Set<String> passStudent = list.stream().map(Cet_6::getId).collect(Collectors.toSet());
log.info("六级通过人数,{}", passStudent.size());
LambdaQueryWrapper<Cet4_major> majorWrapper = new LambdaQueryWrapper<>();
majorWrapper.eq(Cet4_major::getEntrydate, "2020")
.eq(Cet4_major::getState, "在校");
List<Cet4_major> majorList = cetMajorService.list(majorWrapper);
Set<String> allStudent = majorList.stream().map(Cet4_major::getId).collect(Collectors.toSet());
log.info("所有学生人数{}", allStudent.size());
log.info("通过率,{}", (double) passStudent.size() / allStudent.size());
LambdaQueryWrapper<Cet_4> cet4Wrapper=new LambdaQueryWrapper<>();
cet4Wrapper.eq(Cet_4::getEntrydate,"2020");
cet4Wrapper.ge(Cet_4::getResult,425);
List<Cet_4> cet4PassedStudent = cet4Service.list(cet4Wrapper);
Set<String> cet4AllPassedStudent = cet4PassedStudent.stream().map(Cet_4::getId).collect(Collectors.toSet());
log.info("四级通过人数,{}",cet4AllPassedStudent.size());
return null;
}
private long getNum(Cet_6 cet) {
LambdaQueryWrapper<Cet_6> queryWrapper = new LambdaQueryWrapper<>();

View File

@ -0,0 +1,30 @@
package org.jeecg.modules.utils;
import lombok.extern.slf4j.Slf4j;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created with IntelliJ IDEA.
*
* @Author: Cool
* @Date: 2024/10/11/18:33
* @Description: 日期工具类
*/
@Slf4j
public class DateUtil {
public static Date formatDateToDay(String dateStr) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
return format.parse(dateStr);
} catch (ParseException e) {
log.error("DateUtil格式化日期错误,{}", e);
return null;
}
}
}

View File

@ -0,0 +1,67 @@
package org.jeecg.modules.utils;
import org.apache.poi.util.IOUtils;
import org.springframework.core.io.ClassPathResource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class ExportUtil {
/**
* 下载
* @param response
* @param fileName
* @param filePath
* @throws IOException
*/
public static void download(HttpServletResponse response, String fileName, String filePath) throws IOException {
File file = new File(filePath);
FileInputStream in = new FileInputStream(file);
try (OutputStream os = response.getOutputStream()) {
fileName = String.format("%s", fileName);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
response.addHeader("Cache-Control", "no-cache");
byte[] bs = new byte[1024];
int count = 0;
while ((count=in.read(bs, 0, bs.length))!=-1) {
os.write(bs,0,count);
}
in.close();
os.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 下载Excel模板
* @param response
* @param resourceFileName
* @param resourceFilePath
* @throws IOException
*/
public static void downloadExcelTemplate(HttpServletResponse response, String resourceFileName, String resourceFilePath) throws IOException {
ClassPathResource file = new ClassPathResource(resourceFilePath);
InputStream inputStream = file.getInputStream();
try (OutputStream os = response.getOutputStream()) {
String fileName = String.format("%s", resourceFileName);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
response.addHeader("Cache-Control", "no-cache");
IOUtils.copy(inputStream, os);
inputStream.close();
os.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -22,6 +22,5 @@ public class text {
return;
}
// Result<JSONObject> result = cet_4Controller.getDataByStudent(2023011559, "余映婵");
System.out.println(result);
}
}