123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package com.gyee.benchmarkinghive.util;
- import com.gyee.benchmarkinghive.model.auto.Equipmentdaydetailed;
- import com.gyee.benchmarkinghive.model.auto.Equipmentdayinfo;
- import com.gyee.benchmarkinghive.service.GenericService;
- import org.springframework.jdbc.core.JdbcOperations;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * @ClassName : BatchUpdateUtils
- * @Author : xieshengjie
- * @Date: 2021/6/15 23:47
- * @Description : 批量保存工具类
- */
- public class BatchUpdateUtils extends GenericService {
- private static final Integer BATCH_SIZE = 100;
- private JdbcOperations jdbcTemplate;
- public void batchEquipmentinfoInsert(List<Equipmentdayinfo> list) {
- String sql =" INSERT INTO gyee_test.equipmentdayinfo (id, windturbineid, projectid, lineid, windpowerstationid, " +
- " recorddate, genecapacity, therogenecapacity, speed, daynhwhssdl, daynhgzssdl, " +
- " daynhxdssdl, daynhqfdl, daynhcfdl) " +
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
- List<Object[]> args = transformFlowCarReportDayBoToObjects(list);
- int fromIndex = 0; int toIndex = BATCH_SIZE;
- while (fromIndex != args.size()) {
- if (toIndex > args.size()) {
- toIndex = args.size();
- }
- jdbcTemplate.batchUpdate(sql,args.subList(fromIndex, toIndex));
- fromIndex = toIndex;
- toIndex += BATCH_SIZE;
- if (toIndex > args.size())
- toIndex = args.size();
- }
- }
- private List<Object[]> transformFlowCarReportDayBoToObjects(List<Equipmentdayinfo> equipmentdayinfoList) {
- List<Object[]> list = new ArrayList<>();
- Object[] object = null;
- for(Equipmentdayinfo equipmentdayinfo :equipmentdayinfoList){
- object = new Object[]{
- equipmentdayinfo.getId(),
- equipmentdayinfo.getWindturbineid(),
- equipmentdayinfo.getProjectid(),
- equipmentdayinfo.getLineid(),
- equipmentdayinfo.getWindpowerstationid(),
- equipmentdayinfo.getRecorddate(),
- equipmentdayinfo.getGenecapacity(),
- equipmentdayinfo.getTherogenecapacity(),
- equipmentdayinfo.getSpeed(),
- equipmentdayinfo.getDaynhwhssdl(),
- equipmentdayinfo.getDaynhgzssdl(),
- equipmentdayinfo.getDaynhxdssdl(),
- equipmentdayinfo.getDaynhqfdl(),
- equipmentdayinfo.getDaynhcfdl()
- };
- list.add(object);
- }
- return list ;
- }
- public void batchEquipmentdetailedInsert(List<Equipmentdaydetailed> list) {
- String sql =" INSERT INTO gyee_test.equipmentdaydetailed (id, windturbineid, projectid, lineid, windpowerstationid, " +
- " recorddate, genecapacity, therogenecapacity, speed, daynhwhssdl1, daynhwhssdl2,daynhgzssdl1,daynhgzssdl2, " +
- " daynhxdssdl1, daynhxdssdl2,daynhqfdl1, daynhqfdl12,daynhqfdl3,daynhqfdl4, daynhcfdl1,daynhcfdl2 ) " +
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
- List<Object[]> args = transformFlowCarReportDetailedBoToObjects(list);
- int fromIndex = 0; int toIndex = BATCH_SIZE;
- while (fromIndex != args.size()) {
- if (toIndex > args.size()) {
- toIndex = args.size();
- }
- jdbcTemplate.batchUpdate(sql,args.subList(fromIndex, toIndex));
- fromIndex = toIndex;
- toIndex += BATCH_SIZE;
- if (toIndex > args.size())
- toIndex = args.size();
- }
- }
- private List<Object[]> transformFlowCarReportDetailedBoToObjects(List<Equipmentdaydetailed> equipmentdayinfoList) {
- List<Object[]> list = new ArrayList<>();
- Object[] object = null;
- for(Equipmentdaydetailed equipmentdayinfo :equipmentdayinfoList){
- object = new Object[]{
- equipmentdayinfo.getId(),
- equipmentdayinfo.getWindturbineid(),
- equipmentdayinfo.getProjectid(),
- equipmentdayinfo.getLineid(),
- equipmentdayinfo.getWindpowerstationid(),
- equipmentdayinfo.getRecorddate(),
- equipmentdayinfo.getGenecapacity(),
- equipmentdayinfo.getTherogenecapacity(),
- equipmentdayinfo.getSpeed(),
- equipmentdayinfo.getDaynhwhssdl1(),
- equipmentdayinfo.getDaynhwhssdl2(),
- equipmentdayinfo.getDaynhgzssdl1(),
- equipmentdayinfo.getDaynhgzssdl2(),
- equipmentdayinfo.getDaynhxdssdl1(),
- equipmentdayinfo.getDaynhxdssdl2(),
- equipmentdayinfo.getDaynhqfdl1(),
- equipmentdayinfo.getDaynhqfdl2(),
- equipmentdayinfo.getDaynhcfdl1(),
- equipmentdayinfo.getDaynhcfdl2()
- };
- list.add(object);
- }
- return list ;
- }
- }
|