# Conflicts:
#	jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/text.java
This commit is contained in:
YuNan 2024-10-17 14:08:22 +08:00
commit 7fc7e8a602
18 changed files with 794 additions and 336 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

@ -0,0 +1,67 @@
package org.jeecg.modules.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.entity.Cet4_major;
import org.jeecg.modules.entity.Cet_4;
import org.jeecg.modules.service.impl.CetMajorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created with IntelliJ IDEA.
*
* @Author: Cool
* @Date: 2024/10/16/17:58
* @Description: 学生信息Controller
*/
@Api(tags = "cetStudent")
@RestController
@RequestMapping("/cetStudent")
@Slf4j
public class CetStudentController extends JeecgController<Cet4_major, CetMajorServiceImpl> {
@Autowired
private CetMajorServiceImpl cetMajorService;
/**
* 导出excel
*
* @param request
* @param
*/
@RequiresPermissions("cet:cetStudent:exportXls")
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, Cet4_major major) {
return super.exportXls(request, major, Cet4_major.class, "cet_4");
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequiresPermissions("cet:cetStudent:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, Cet4_major.class);
}
@RequestMapping("downloadTemplate")
@ApiOperation("四六级导入数据文件模版")
public Result<?> downloadTemplate(HttpServletResponse response) {
return cetMajorService.downloadTemplate(response);
}
}

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;
@ -22,125 +23,125 @@ import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
/**
/**
* @Description: cet_6
* @Author: jeecg-boot
* @Date: 2024-03-26
* @Date: 2024-03-26
* @Version: V1.0
*/
@Api(tags="cet_6")
@Api(tags = "cet_6")
@RestController
@RequestMapping("/cet_6")
@Slf4j
public class Cet_6Controller extends JeecgController<Cet_6, ICet_6Service> {
@Autowired
private ICet_6Service cet_6Service;
/**
* 分页列表查询
*
* @param cet_6
* @param pageNo
* @param pageSize
* @param req
* @return
*/
//@AutoLog(value = "cet_6-分页列表查询")
@ApiOperation(value="cet_6-分页列表查询", notes="cet_6-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<Cet_6>> queryPageList(Cet_6 cet_6,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<Cet_6> queryWrapper = QueryGenerator.initQueryWrapper(cet_6, req.getParameterMap());
Page<Cet_6> page = new Page<Cet_6>(pageNo, pageSize);
IPage<Cet_6> pageList = cet_6Service.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
* @param cet_6
* @return
*/
@AutoLog(value = "cet_6-添加")
@ApiOperation(value="cet_6-添加", notes="cet_6-添加")
@RequiresPermissions("cet:cet_6:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody Cet_6 cet_6) {
cet_6Service.save(cet_6);
return Result.OK("添加成功!");
}
/**
* 编辑
*
* @param cet_6
* @return
*/
@AutoLog(value = "cet_6-编辑")
@ApiOperation(value="cet_6-编辑", notes="cet_6-编辑")
@RequiresPermissions("cet:cet_6:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<String> edit(@RequestBody Cet_6 cet_6) {
cet_6Service.updateById(cet_6);
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "cet_6-通过id删除")
@ApiOperation(value="cet_6-通过id删除", notes="cet_6-通过id删除")
@RequiresPermissions("cet:cet_6:delete")
@DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
cet_6Service.removeById(id);
return Result.OK("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "cet_6-批量删除")
@ApiOperation(value="cet_6-批量删除", notes="cet_6-批量删除")
@RequiresPermissions("cet:cet_6:deleteBatch")
@DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.cet_6Service.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
* @param id
* @return
*/
//@AutoLog(value = "cet_6-通过id查询")
@ApiOperation(value="cet_6-通过id查询", notes="cet_6-通过id查询")
@GetMapping(value = "/queryById")
public Result<Cet_6> queryById(@RequestParam(name="id",required=true) String id) {
Cet_6 cet_6 = cet_6Service.getById(id);
if(cet_6==null) {
return Result.error("未找到对应数据");
}
return Result.OK(cet_6);
}
@Autowired
private ICet_6Service cet_6Service;
/**
* 导出excel
*
* @param request
* @param cet_6
*/
* 分页列表查询
*
* @param cet_6
* @param pageNo
* @param pageSize
* @param req
* @return
*/
//@AutoLog(value = "cet_6-分页列表查询")
@ApiOperation(value = "cet_6-分页列表查询", notes = "cet_6-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<Cet_6>> queryPageList(Cet_6 cet_6,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<Cet_6> queryWrapper = QueryGenerator.initQueryWrapper(cet_6, req.getParameterMap());
Page<Cet_6> page = new Page<Cet_6>(pageNo, pageSize);
IPage<Cet_6> pageList = cet_6Service.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
* @param cet_6
* @return
*/
@AutoLog(value = "cet_6-添加")
@ApiOperation(value = "cet_6-添加", notes = "cet_6-添加")
@RequiresPermissions("cet:cet_6:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody Cet_6 cet_6) {
cet_6Service.save(cet_6);
return Result.OK("添加成功!");
}
/**
* 编辑
*
* @param cet_6
* @return
*/
@AutoLog(value = "cet_6-编辑")
@ApiOperation(value = "cet_6-编辑", notes = "cet_6-编辑")
@RequiresPermissions("cet:cet_6:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
public Result<String> edit(@RequestBody Cet_6 cet_6) {
cet_6Service.updateById(cet_6);
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "cet_6-通过id删除")
@ApiOperation(value = "cet_6-通过id删除", notes = "cet_6-通过id删除")
@RequiresPermissions("cet:cet_6:delete")
@DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
cet_6Service.removeById(id);
return Result.OK("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "cet_6-批量删除")
@ApiOperation(value = "cet_6-批量删除", notes = "cet_6-批量删除")
@RequiresPermissions("cet:cet_6:deleteBatch")
@DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
this.cet_6Service.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
* @param id
* @return
*/
//@AutoLog(value = "cet_6-通过id查询")
@ApiOperation(value = "cet_6-通过id查询", notes = "cet_6-通过id查询")
@GetMapping(value = "/queryById")
public Result<Cet_6> queryById(@RequestParam(name = "id", required = true) String id) {
Cet_6 cet_6 = cet_6Service.getById(id);
if (cet_6 == null) {
return Result.error("未找到对应数据");
}
return Result.OK(cet_6);
}
/**
* 导出excel
*
* @param request
* @param cet_6
*/
@RequiresPermissions("cet:cet_6:exportXls")
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, Cet_6 cet_6) {
@ -148,16 +149,22 @@ public class Cet_6Controller extends JeecgController<Cet_6, ICet_6Service> {
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequiresPermissions("cet:cet_6:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
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;
@ -17,53 +19,96 @@ import lombok.experimental.Accessors;
/**
* @Description: cet_6
* @Author: jeecg-boot
* @Date: 2024-03-26
* @Date: 2024-03-26
* @Version: V1.0
*/
@Data
@TableName("cet_6")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="cet_6对象", description="cet_6")
@ApiModel(value = "cet_6对象", description = "cet_6")
public class Cet_6 implements Serializable {
private static final long serialVersionUID = 1L;
/**学生姓名*/
@Excel(name = "学生姓名", width = 15)
/**
* 学生姓名
*/
@Excel(name = "学生姓名", width = 15)
@AttributeName(4)
@ApiModelProperty(value = "学生姓名")
private java.lang.String name;
/**学生所在学院*/
@Excel(name = "学生所在学院", width = 15)
private String name;
/**
* 学生所在学院
*/
@Excel(name = "学生所在学院", width = 15)
@AttributeName(11)
@ApiModelProperty(value = "学生所在学院")
private java.lang.String college;
/**学生成绩*/
@Excel(name = "学生成绩", width = 15)
private String college;
/**
* 学生成绩
*/
@Excel(name = "学生成绩", width = 15)
@AttributeName(15)
@ApiModelProperty(value = "学生成绩")
private java.lang.Integer result;
/**学生学号*/
@TableId(type = IdType.ASSIGN_ID)
private Integer result;
/**
* 学生学号
*/
@AttributeName(19)
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "学生学号")
private java.lang.String id;
/**考试批次*/
@Excel(name = "考试批次", width = 15, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
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;
/**入学时间*/
@Excel(name = "入学时间", width = 15)
private Date batch;
/**
* 入学时间
*/
@Excel(name = "入学时间", width = 15)
@ApiModelProperty(value = "入学时间")
private java.lang.String entrydate;
/**听力成绩*/
@Excel(name = "听力成绩", width = 15)
private String entrydate;
/**
* 听力成绩
*/
@Excel(name = "听力成绩", width = 15)
@AttributeName(12)
@ApiModelProperty(value = "听力成绩")
private java.lang.Integer listen;
/**阅读成绩*/
@Excel(name = "阅读成绩", width = 15)
private Integer listen;
/**
* 阅读成绩
*/
@Excel(name = "阅读成绩", width = 15)
@AttributeName(13)
@ApiModelProperty(value = "阅读成绩")
private java.lang.Integer reading;
/**作文成绩*/
@Excel(name = "作文成绩", width = 15)
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,20 +1,19 @@
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
* @Date: 2024-03-26
* @Date: 2024-03-26
* @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,35 @@
package org.jeecg.modules.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet4_major;
import org.jeecg.modules.mapper.Cet4_majorMapper;
import org.jeecg.modules.utils.ExportUtil;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created with IntelliJ IDEA.
*
* @Author: Cool
* @Date: 2024/10/11/15:52
* @Description:
*/
@Service
@Slf4j
public class CetMajorServiceImpl extends ServiceImpl<Cet4_majorMapper, Cet4_major> {
private final String CET_STUDENT_IMPORT_TEMPLATE = "template/cetStudentImportTemplate.xls";
private final String CET_STUDENT_FILE_TEMPLATE_NAME = "四六级学生信息导入模版.xlsx";
public Result<?> downloadTemplate(HttpServletResponse response) {
try {
ExportUtil.downloadExcelTemplate(response, CET_STUDENT_FILE_TEMPLATE_NAME, CET_STUDENT_IMPORT_TEMPLATE);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

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,20 +19,27 @@ 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;
/**
* @Description: cet_6
* @Author: jeecg-boot
* @Date: 2024-03-26
* @Date: 2024-03-26
* @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

@ -21,7 +21,6 @@ public class text {
System.err.println("Cet_4Controller 未正确注入");
return;
}
// Result<JSONObject> result = cet_4Controller.getDataByStudent();
// System.out.println(result);
// Result<JSONObject> result = cet_4Controller.getDataByStudent(2023011559, "余映婵");
}
}