| | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigInteger; |
| | | import java.util.Date; |
| | | |
| | | public class VocVals implements Serializable { |
| | | private static final long serialVersionUID = -20230605145412000L; |
| | | |
| | | @ApiModelProperty(value = "主键") |
| | | private Integer id; |
| | | private BigInteger id; |
| | | |
| | | @CsvProperty(index = 0) |
| | | @ApiModelProperty(value = "X") |
| | |
| | | public VocVals() { |
| | | } |
| | | |
| | | public Integer getId() { |
| | | public BigInteger getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Integer id) { |
| | | public void setId(BigInteger id) { |
| | | this.id = id; |
| | | } |
| | | |
| | |
| | | package com.yssh.run; |
| | | |
| | | import com.yssh.scheduled.ReadCsvTask; |
| | | import com.yssh.utils.CacheUtils; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | |
| | | import com.yssh.service.ICommonService; |
| | | import com.yssh.service.IDictRecordService; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Component |
| | | public class InitDataRunner implements ApplicationRunner { |
| | | //protected final Log logger = LogFactory.getLog(this.getClass()); |
| | |
| | | @Autowired |
| | | private IDictRecordService dictRecordService; |
| | | |
| | | @Resource |
| | | ReadCsvTask task; |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | | CacheUtils.init(); |
| | |
| | | if (!tableExists) { |
| | | dictRecordService.createDictRecoTable(); |
| | | } |
| | | //读取dat数据 |
| | | // 读取dat数据 |
| | | commonService.readDatData(); |
| | | |
| | | //task.corpReserveDataSync(); |
| | | |
| | | logger.info("***************** 系统启动完毕 *****************" + "\n"); |
| | | } |
| | | } |
| | |
| | | |
| | | int count = vocValsService.countByTime(time); |
| | | if (count > 0) { |
| | | continue; |
| | | //continue; |
| | | } |
| | | |
| | | EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, calendar.getTime())).doRead(); |
| | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | public class VocParser extends AbstractCsvFileParser<VocVals> { |
| | | protected final Log logger = LogFactory.getLog(this.getClass()); |
| | | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH0000"); |
| | | |
| | | /** |
| | | * 每隔5000条入库一次 |
| | | */ |
| | | public static final int BATCH_COUNT = 5000; |
| | | public static final int BATCH_COUNT = 100000; |
| | | |
| | | private BigInteger startId; |
| | | |
| | | private VocValsService vocValsService; |
| | | |
| | | private Date date; |
| | | |
| | | private List<VocVals> list = new ArrayList<>(); |
| | | private List<VocVals> list = new ArrayList<>(BATCH_COUNT); |
| | | |
| | | public VocParser(VocValsService vocValsService, Date date) { |
| | | this.vocValsService = vocValsService; |
| | | this.date = date; |
| | | this.startId = new BigInteger(format.format(date)); |
| | | } |
| | | |
| | | public BigInteger getId() { |
| | | startId = startId.add(BigInteger.valueOf(1)); |
| | | |
| | | return startId; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | vv.setCreateTime(this.date); |
| | | vv.setId(getId()); |
| | | list.add(vv); |
| | | |
| | | if (list.size() >= BATCH_COUNT) { |
| | | inserts(); |
| | | list = new ArrayList<>(); |
| | | list = new ArrayList<>(BATCH_COUNT); |
| | | } |
| | | } |
| | | |
| | | private void inserts() { |
| | | try { |
| | | this.vocValsService.insertVocVals(list); |
| | | if (list.size() > 0) { |
| | | this.vocValsService.insertVocVals(list); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | |
| | | csv: |
| | | cron: '0 1 * * * ? ' |
| | | cron: '0 5 * * * ? ' |
| | |
| | | where date_format(create_time, '%Y%m%d%H') = ${time}; |
| | | </select> |
| | | |
| | | <insert id="insert" parameterType="com.yssh.entity.VocVals" useGeneratedKeys="true" keyProperty="id"> |
| | | insert into voc_vals (x, y, val, create_time) values |
| | | (${x}, ${y}, ${val}, ${createTime}); |
| | | <insert id="insert" parameterType="com.yssh.entity.VocVals" useGeneratedKeys="false" keyProperty="id"> |
| | | insert into voc_vals (id, x, y, val, create_time) values |
| | | (${id}, ${x}, ${y}, ${val}, ${createTime}); |
| | | </insert> |
| | | |
| | | <insert id="inserts" parameterType="com.yssh.entity.VocVals" useGeneratedKeys="true" keyProperty="id"> |
| | | insert into voc_vals (x, y, val, create_time) values |
| | | <insert id="inserts" parameterType="com.yssh.entity.VocVals" useGeneratedKeys="false" keyProperty="id"> |
| | | insert into voc_vals (id, x, y, val, create_time) values |
| | | <foreach collection="list" item="item" index="index" separator=","> |
| | | (#{item.x},#{item.y},#{item.val},#{item.createTime}) |
| | | (${item.id}, #{item.x},#{item.y},#{item.val},#{item.createTime}) |
| | | </foreach> |
| | | </insert> |
| | | |