数据导入1.1
This commit is contained in:
parent
2878b05b4b
commit
1c7cca09c9
|
@ -49,6 +49,11 @@
|
||||||
<artifactId>flyway-core</artifactId>
|
<artifactId>flyway-core</artifactId>
|
||||||
<version>7.15.0</version>
|
<version>7.15.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.albfernandez</groupId>
|
||||||
|
<artifactId>javadbf</artifactId>
|
||||||
|
<version>1.9.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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<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);
|
||||||
|
|
||||||
|
}
|
|
@ -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<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 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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue