diff --git a/jeecg-module-system/jeecg-system-start/pom.xml b/jeecg-module-system/jeecg-system-start/pom.xml index 25051255..a7a7026a 100644 --- a/jeecg-module-system/jeecg-system-start/pom.xml +++ b/jeecg-module-system/jeecg-system-start/pom.xml @@ -10,7 +10,7 @@ 4.0.0 jeecg-system-start - + @@ -49,6 +49,11 @@ flyway-core 7.15.0 + + com.github.albfernandez + javadbf + 1.9.2 + @@ -60,4 +65,4 @@ - \ No newline at end of file + diff --git a/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/anno/AttributeName.java b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/anno/AttributeName.java new file mode 100644 index 00000000..bd9238a3 --- /dev/null +++ b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/anno/AttributeName.java @@ -0,0 +1,10 @@ +package org.jeecg.modules.anno; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AttributeName { + + int value(); +} diff --git a/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/entity/CET.java b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/entity/CET.java new file mode 100644 index 00000000..c5bbdba5 --- /dev/null +++ b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/entity/CET.java @@ -0,0 +1,47 @@ +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; + +} diff --git a/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/mapper/CetMapper.java b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/mapper/CetMapper.java new file mode 100644 index 00000000..2fb91dda --- /dev/null +++ b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/mapper/CetMapper.java @@ -0,0 +1,13 @@ +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 { + @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); + +} diff --git a/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/service/DBFImporter.java b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/service/DBFImporter.java new file mode 100644 index 00000000..18d08a78 --- /dev/null +++ b/jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/modules/service/DBFImporter.java @@ -0,0 +1,108 @@ +package org.jeecg.modules.service; + + +import com.linuxense.javadbf.DBFReader; +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; + +@Service +public class DBFImporter { + @Resource + CetMapper cetMapper; +// @Autowired +// CetMapper_6 cetMapper6; + + public void readDBF(InputStream inputStream, Date batch, String level, String charsetName) { + try { +// List 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 s = String.valueOf(value); + cet.setEntrydate(s.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); +// } + + +}