Commit 2689f82d5370be81df3e6669d7cda6d3b989fb31

Authored by 王通
1 parent 96584bb1

1.加入电科所用的4个接口,以及接口对应的数据生成

src/main/java/com/bsth/server_rs/dks/BusMileage.java 0 → 100644
  1 +package com.bsth.server_rs.dks;
  2 +
  3 +public class BusMileage {
  4 +
  5 + /**
  6 + *
  7 + */
  8 + private String scheduleDate;
  9 +
  10 + /**
  11 + * 内部编码
  12 + */
  13 + private String nbbm;
  14 +
  15 + /**
  16 + * 计划里程
  17 + */
  18 + private Double jhlc;
  19 +
  20 + /**
  21 + * 实际计划里程
  22 + */
  23 + private Double sjjhlc;
  24 +
  25 + /**
  26 + * 实际出场里程
  27 + */
  28 + private Double sjcclc;
  29 +
  30 + /**
  31 + * 实际进场里程
  32 + */
  33 + private Double sjjclc;
  34 +
  35 + /**
  36 + * 营运里程
  37 + */
  38 + private Double yylc;
  39 +
  40 + /**
  41 + * 空驶里程
  42 + */
  43 + private Double kslc;
  44 +
  45 + /**
  46 + * 抽减里程
  47 + */
  48 + private Double cjlc;
  49 +
  50 + /**
  51 + * 烂班里程
  52 + */
  53 + private Double lblc;
  54 +
  55 + /**
  56 + * 增加里程
  57 + */
  58 + private Double zjlc;
  59 +
  60 + /**
  61 + * 总里程
  62 + */
  63 + private Double zlc;
  64 +
  65 + /**
  66 + * 油耗
  67 + */
  68 + private Double yh;
  69 +
  70 + /**
  71 + * 电耗
  72 + */
  73 + private Double dh;
  74 +
  75 + public String getScheduleDate() {
  76 + return scheduleDate;
  77 + }
  78 +
  79 + public void setScheduleDate(String scheduleDate) {
  80 + this.scheduleDate = scheduleDate;
  81 + }
  82 +
  83 + public String getNbbm() {
  84 + return nbbm;
  85 + }
  86 +
  87 + public void setNbbm(String nbbm) {
  88 + this.nbbm = nbbm;
  89 + }
  90 +
  91 + public Double getJhlc() {
  92 + return jhlc;
  93 + }
  94 +
  95 + public void setJhlc(Double jhlc) {
  96 + this.jhlc = jhlc;
  97 + }
  98 +
  99 + public Double getSjjhlc() {
  100 + return sjjhlc;
  101 + }
  102 +
  103 + public void setSjjhlc(Double sjjhlc) {
  104 + this.sjjhlc = sjjhlc;
  105 + }
  106 +
  107 + public Double getSjcclc() {
  108 + return sjcclc;
  109 + }
  110 +
  111 + public void setSjcclc(Double sjcclc) {
  112 + this.sjcclc = sjcclc;
  113 + }
  114 +
  115 + public Double getSjjclc() {
  116 + return sjjclc;
  117 + }
  118 +
  119 + public void setSjjclc(Double sjjclc) {
  120 + this.sjjclc = sjjclc;
  121 + }
  122 +
  123 + public Double getYylc() {
  124 + return yylc;
  125 + }
  126 +
  127 + public void setYylc(Double yylc) {
  128 + this.yylc = yylc;
  129 + }
  130 +
  131 + public Double getKslc() {
  132 + return kslc;
  133 + }
  134 +
  135 + public void setKslc(Double kslc) {
  136 + this.kslc = kslc;
  137 + }
  138 +
  139 + public Double getCjlc() {
  140 + return cjlc;
  141 + }
  142 +
  143 + public void setCjlc(Double cjlc) {
  144 + this.cjlc = cjlc;
  145 + }
  146 +
  147 + public Double getLblc() {
  148 + return lblc;
  149 + }
  150 +
  151 + public void setLblc(Double lblc) {
  152 + this.lblc = lblc;
  153 + }
  154 +
  155 + public Double getZjlc() {
  156 + return zjlc;
  157 + }
  158 +
  159 + public void setZjlc(Double zjlc) {
  160 + this.zjlc = zjlc;
  161 + }
  162 +
  163 + public Double getZlc() {
  164 + return zlc;
  165 + }
  166 +
  167 + public void setZlc(Double zlc) {
  168 + this.zlc = zlc;
  169 + }
  170 +
  171 + public Double getYh() {
  172 + return yh;
  173 + }
  174 +
  175 + public void setYh(Double yh) {
  176 + this.yh = yh;
  177 + }
  178 +
  179 + public Double getDh() {
  180 + return dh;
  181 + }
  182 +
  183 + public void setDh(Double dh) {
  184 + this.dh = dh;
  185 + }
  186 +}
... ...
src/main/java/com/bsth/server_rs/dks/DksRestService.java 0 → 100644
  1 +package com.bsth.server_rs.dks;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.entity.ElecInfo;
  5 +import com.bsth.entity.OilInfo;
  6 +import com.bsth.entity.SchedulePlanInfo;
  7 +import com.bsth.entity.ScheduleRealInfo;
  8 +import com.bsth.redis.ElecRedisService;
  9 +import com.bsth.redis.OilRedisService;
  10 +import com.bsth.redis.ScheduleRedisService;
  11 +import com.bsth.repository.SchedulePlanInfoRepository;
  12 +import com.bsth.repository.ScheduleRealInfoRepository;
  13 +import com.bsth.server_rs.base_info.line.Line;
  14 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  15 +import com.bsth.server_ws.util.ScheduleCalculator;
  16 +import com.bsth.util.Arith;
  17 +import com.google.common.collect.ArrayListMultimap;
  18 +import org.joda.time.DateTime;
  19 +import org.joda.time.format.DateTimeFormat;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
  22 +import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  24 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  25 +import org.springframework.jdbc.core.JdbcTemplate;
  26 +import org.springframework.jdbc.datasource.DataSourceTransactionManager;
  27 +import org.springframework.scheduling.annotation.EnableScheduling;
  28 +import org.springframework.scheduling.annotation.Scheduled;
  29 +import org.springframework.stereotype.Component;
  30 +import org.springframework.transaction.TransactionDefinition;
  31 +import org.springframework.transaction.TransactionStatus;
  32 +import org.springframework.transaction.support.DefaultTransactionDefinition;
  33 +import org.springframework.util.StringUtils;
  34 +
  35 +import javax.ws.rs.*;
  36 +import javax.ws.rs.core.MediaType;
  37 +import java.sql.PreparedStatement;
  38 +import java.sql.SQLException;
  39 +import java.util.*;
  40 +
  41 +/**
  42 + * @author Hill
  43 + * @date 2021-09
  44 + */
  45 +@Component
  46 +@EnableScheduling
  47 +@Path("/dks")
  48 +@Produces({MediaType.APPLICATION_JSON})
  49 +public class DksRestService {
  50 +
  51 + private final static Logger log = LoggerFactory.getLogger(DksRestService.class);
  52 +
  53 + @Autowired
  54 + private JdbcTemplate jdbcTemplate;
  55 +
  56 + @Autowired
  57 + private ScheduleRealInfoRepository scheduleRealInfoRepository;
  58 +
  59 + @Autowired
  60 + private SchedulePlanInfoRepository schedulePlanInfoRepository;
  61 +
  62 + @Autowired
  63 + private ScheduleRedisService scheduleRedisService;
  64 +
  65 + @Autowired
  66 + private OilRedisService oilRedisService;
  67 +
  68 + @Autowired
  69 + private ElecRedisService elecRedisService;
  70 +
  71 + /**
  72 + * 根据日期统计数据重新计算
  73 + * @param rq
  74 + */
  75 + @GET
  76 + @Path("/reCompute/{rq}")
  77 + public void reStatisticalComputation(@PathParam("rq") String rq) {
  78 + DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(rq);
  79 + planComputation(dateTime);
  80 + realComputation(dateTime);
  81 + carMileageComputation(dateTime);
  82 + }
  83 +
  84 + /**
  85 + *
  86 + */
  87 + private List<LineServiceConfigVo> reGroup(List<LineServiceConfig> configs, String month) {
  88 + List<LineServiceConfigVo> result = new ArrayList<>();
  89 + String oldLineCode = "";
  90 + LineServiceConfigVo vo = null;
  91 + for (int i = 0, len = configs.size();i < len;i++) {
  92 + LineServiceConfig config = configs.get(i);
  93 + if (i == 0) {
  94 + vo = new LineServiceConfigVo();
  95 + vo.setLineName(config.getLineName());
  96 + vo.setMonth(month);
  97 + vo.setConductorFirstCount(config.getConductorCount());
  98 + vo.setDriverFirstCount(config.getDriverCount());
  99 + } else if (i == len - 1) {
  100 + result.add(vo);
  101 + } else {
  102 + if (!oldLineCode.equals(config.getLineCode())) {
  103 + result.add(vo);
  104 + vo = new LineServiceConfigVo();
  105 + vo.setLineName(config.getLineName());
  106 + vo.setMonth(month);
  107 + vo.setConductorFirstCount(config.getConductorCount());
  108 + vo.setDriverFirstCount(config.getDriverCount());
  109 + }
  110 + }
  111 + vo.setConductorLastCount(config.getConductorCount());
  112 + vo.setDriverLastCount(config.getDriverCount());
  113 + }
  114 +
  115 + return result;
  116 + }
  117 +
  118 + /**
  119 + * 计划司售配档数
  120 + * @param month
  121 + */
  122 + @GET
  123 + @Path("/plan/{month}")
  124 + public List<LineServiceConfigVo> plan(@PathParam("month") String month) {
  125 + List<LineServiceConfig> configs = jdbcTemplate.query("select * from control_interface.bsth_t_plan where schedule_date like CONCAT(?, '%') order by line_code, schedule_date", new Object[]{ month }, BeanPropertyRowMapper.newInstance(LineServiceConfig.class));
  126 + return reGroup(configs, month);
  127 + }
  128 +
  129 + /**
  130 + * 实际司售配档数
  131 + * @param month
  132 + */
  133 + @GET
  134 + @Path("/actual/{month}")
  135 + public List<LineServiceConfigVo> actual(@PathParam("month") String month) {
  136 + List<LineServiceConfig> configs = jdbcTemplate.query("select * from control_interface.bsth_t_real where schedule_date like CONCAT(?, '%') order by line_code, schedule_date", new Object[]{ month }, BeanPropertyRowMapper.newInstance(LineServiceConfig.class));
  137 + return reGroup(configs, month);
  138 + }
  139 +
  140 + /**
  141 + * 实际配车数
  142 + * @param month
  143 + */
  144 + @GET
  145 + @Path("/bus/{month}")
  146 + public List<BusVo> bus(@PathParam("month") String month) {
  147 + List<LineServiceConfig> configs = jdbcTemplate.query("select * from control_interface.bsth_t_real where schedule_date like CONCAT(?, '%') order by line_code, schedule_date", new Object[]{ month }, BeanPropertyRowMapper.newInstance(LineServiceConfig.class));
  148 + List<BusVo> result = new ArrayList<>();
  149 + String oldLineCode = "";
  150 + BusVo vo = null;
  151 + int max = 0;
  152 + for (int i = 0, len = configs.size();i < len;i++) {
  153 + LineServiceConfig config = configs.get(i);
  154 + if (i == 0) {
  155 + vo = new BusVo();
  156 + vo.setLineName(config.getLineName());
  157 + vo.setMonth(month);
  158 + vo.setBusFirstCount(config.getCarCount());
  159 + } else if (!oldLineCode.equals(config.getLineCode())) {
  160 + vo.setBusMaxCount(max);
  161 + result.add(vo);
  162 + max = 0;
  163 + vo = new BusVo();
  164 + vo.setLineName(config.getLineName());
  165 + vo.setMonth(month);
  166 + vo.setBusFirstCount(config.getCarCount());
  167 + }
  168 + max = Math.max(max, config.getCarCount());
  169 + if (i == len - 1) {
  170 + vo.setBusMaxCount(max);
  171 + result.add(vo);
  172 + }
  173 + vo.setBusLastCount(config.getCarCount());
  174 + }
  175 +
  176 + return result;
  177 + }
  178 +
  179 + /**
  180 + * 车辆公里、油耗数据
  181 + * @param month
  182 + */
  183 + @GET
  184 + @Path("/mileage/{month}")
  185 + public List<BusMileageVo> mileage(@PathParam("month") String month) {
  186 + List<BusMileage> mileages = jdbcTemplate.query("select nbbm, schedule_month schedule_date, sum(zlc) zlc, sum(yh) yh, sum(dh) dh from control_interface.bsth_t_mileage where schedule_month = ? group by nbbm, schedule_month", new Object[]{ month }, BeanPropertyRowMapper.newInstance(BusMileage.class));
  187 + List<BusMileageVo> result = new ArrayList<>();
  188 + for (BusMileage mileage : mileages) {
  189 + BusMileageVo vo = new BusMileageVo();
  190 + vo.setMonth(mileage.getScheduleDate());
  191 + vo.setInsideCode(mileage.getNbbm());
  192 + vo.setTotalMileage(mileage.getZlc());
  193 + vo.setOilConsume(mileage.getYh());
  194 + vo.setElectricConsume(mileage.getDh());
  195 +
  196 + result.add(vo);
  197 + }
  198 +
  199 + return result;
  200 + }
  201 +
  202 + @Scheduled(cron = "0 0 23 * * ?")
  203 + public void statisticalComputation() {
  204 + DateTime dateTime = DateTime.now().plusDays(1);
  205 + try {
  206 + for (int i = 0;i < 3;i++) {
  207 + dateTime = dateTime.minusDays(1);
  208 + planComputation(dateTime);
  209 + realComputation(dateTime);
  210 + carMileageComputation(dateTime);
  211 + }
  212 + } catch (Exception e) {
  213 + e.printStackTrace();
  214 + }
  215 + }
  216 +
  217 + /**
  218 + * 计划排班中的线路司售配档数
  219 + */
  220 + private void planComputation(DateTime dateTime) {
  221 + // 记录实际线路司售配档情况
  222 + List<SchedulePlanInfo> schedulePlanInfos = schedulePlanInfoRepository.findByDate(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(dateTime.toString("yyyy-MM-dd")).toDate());
  223 + Set<String> lineCodes = new HashSet<>();
  224 + Map<String, Set<String>> line2conductors = new HashMap<>(), line2drivers = new HashMap<>();
  225 + final List<LineServiceConfig> objects = new ArrayList<>();
  226 + for (SchedulePlanInfo schedulePlanInfo : schedulePlanInfos) {
  227 + String lineCode = schedulePlanInfo.getXlBm();
  228 + lineCodes.add(lineCode);
  229 + Set<String> conductors = line2conductors.get(lineCode), drivers = line2drivers.get(lineCode);
  230 + if (conductors == null) {
  231 + conductors = new HashSet<>();
  232 + line2conductors.put(lineCode, conductors);
  233 + }
  234 + if (drivers == null) {
  235 + drivers = new HashSet<>();
  236 + line2drivers.put(lineCode, drivers);
  237 + }
  238 + if (!StringUtils.isEmpty(schedulePlanInfo.getsGh())) {
  239 + conductors.add(schedulePlanInfo.getsGh());
  240 + }
  241 + drivers.add(schedulePlanInfo.getjGh());
  242 + }
  243 + for (String lineCode : lineCodes) {
  244 + LineServiceConfig object = new LineServiceConfig();
  245 + Line line = LineBufferData.findOne(lineCode);
  246 + object.setLineCode(lineCode);
  247 + object.setLineName(line == null ? "" : line.getName());
  248 + object.setScheduleDate(dateTime.toString("yyyy-MM-dd"));
  249 + object.setConductorCount(line2conductors.get(lineCode).size());
  250 + object.setDriverCount(line2drivers.get(lineCode).size());
  251 +
  252 + objects.add(object);
  253 + }
  254 +
  255 + //编程式事务
  256 + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());
  257 + DefaultTransactionDefinition def = new DefaultTransactionDefinition();
  258 + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  259 + TransactionStatus status = tran.getTransaction(def);
  260 +
  261 + try {
  262 + jdbcTemplate.update("delete from control_interface.bsth_t_plan where schedule_date = ?", new Object[]{ dateTime.toString("yyyy-MM-dd") });
  263 + jdbcTemplate.batchUpdate("insert into control_interface.bsth_t_plan (line_code, line_name, schedule_date, conductor_count, driver_count) values (?,?,?,?,?)", new BatchPreparedStatementSetter() {
  264 + @Override
  265 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  266 + LineServiceConfig object = objects.get(i);
  267 + ps.setString(1, object.getLineCode());
  268 + ps.setString(2, object.getLineName());
  269 + ps.setString(3, object.getScheduleDate());
  270 + ps.setInt(4, object.getConductorCount());
  271 + ps.setInt(5, object.getDriverCount());
  272 + }
  273 +
  274 + @Override
  275 + public int getBatchSize() {
  276 + return objects.size();
  277 + }
  278 + });
  279 + tran.commit(status);
  280 + } catch (Exception e) {
  281 + tran.rollback(status);
  282 + }
  283 + }
  284 +
  285 + /**
  286 + * 实际排班中的线路司售配档数
  287 + */
  288 + private void realComputation(DateTime dateTime) {
  289 + // 记录实际线路司售配档情况
  290 + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findAll(dateTime.toString("yyyy-MM-dd"));
  291 + Set<String> lineCodes = new HashSet<>();
  292 + Map<String, Set<String>> line2conductors = new HashMap<>(), line2drivers = new HashMap<>(), line2cars = new HashMap<>();
  293 + final List<LineServiceConfig> objects = new ArrayList<>();
  294 + for (ScheduleRealInfo scheduleRealInfo : scheduleRealInfos) {
  295 + // 烂班班次不计入配档数
  296 + if (scheduleRealInfo.getStatus() == -1) { continue; }
  297 + String lineCode = scheduleRealInfo.getXlBm();
  298 + lineCodes.add(lineCode);
  299 + Set<String> conductors = line2conductors.get(lineCode), drivers = line2drivers.get(lineCode), cars = line2cars.get(lineCode);
  300 + if (conductors == null) {
  301 + conductors = new HashSet<>();
  302 + line2conductors.put(lineCode, conductors);
  303 + }
  304 + if (drivers == null) {
  305 + drivers = new HashSet<>();
  306 + line2drivers.put(lineCode, drivers);
  307 + }
  308 + if (cars == null) {
  309 + cars = new HashSet<>();
  310 + line2cars.put(lineCode, cars);
  311 + }
  312 + if (!StringUtils.isEmpty(scheduleRealInfo.getsGh())) {
  313 + conductors.add(scheduleRealInfo.getsGh());
  314 + }
  315 + drivers.add(scheduleRealInfo.getjGh());
  316 + cars.add(scheduleRealInfo.getClZbh());
  317 + }
  318 + for (String lineCode : lineCodes) {
  319 + LineServiceConfig object = new LineServiceConfig();
  320 + Line line = LineBufferData.findOne(lineCode);
  321 + object.setLineCode(lineCode);
  322 + object.setLineName(line == null ? "" : line.getName());
  323 + object.setScheduleDate(dateTime.toString("yyyy-MM-dd"));
  324 + object.setConductorCount(line2conductors.get(lineCode).size());
  325 + object.setDriverCount(line2drivers.get(lineCode).size());
  326 + object.setCarCount(line2cars.get(lineCode).size());
  327 +
  328 + objects.add(object);
  329 + }
  330 +
  331 + //编程式事务
  332 + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());
  333 + DefaultTransactionDefinition def = new DefaultTransactionDefinition();
  334 + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  335 + TransactionStatus status = tran.getTransaction(def);
  336 + try {
  337 + jdbcTemplate.update("delete from control_interface.bsth_t_real where schedule_date = ?", new Object[]{ dateTime.toString("yyyy-MM-dd") });
  338 + jdbcTemplate.batchUpdate("insert into control_interface.bsth_t_real (line_code, line_name, schedule_date, conductor_count, driver_count, car_count) values (?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  339 + @Override
  340 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  341 + LineServiceConfig object = objects.get(i);
  342 + ps.setString(1, object.getLineCode());
  343 + ps.setString(2, object.getLineName());
  344 + ps.setString(3, object.getScheduleDate());
  345 + ps.setInt(4, object.getConductorCount());
  346 + ps.setInt(5, object.getDriverCount());
  347 + ps.setInt(6, object.getCarCount());
  348 + }
  349 +
  350 + @Override
  351 + public int getBatchSize() {
  352 + return objects.size();
  353 + }
  354 + });
  355 + tran.commit(status);
  356 + } catch (Exception e) {
  357 + tran.rollback(status);
  358 + }
  359 + }
  360 +
  361 + private void carMileageComputation(final DateTime dateTime) {
  362 + String rq = dateTime.toString("yyyy-MM-dd");
  363 + // 实际排班信息
  364 + ArrayListMultimap<String, ScheduleRealInfo> nbbm2schedules = scheduleRedisService.findByDate(rq);
  365 + // 油耗信息
  366 + ArrayListMultimap<String, OilInfo> oilInfoMap = oilRedisService.findByNbbmGroup1(nbbm2schedules.keySet(), rq);
  367 + //电耗信息
  368 + ArrayListMultimap<String, ElecInfo> elecInfoMap = elecRedisService.findByNbbmGroup1(nbbm2schedules.keySet(), rq);
  369 + Set<String> nbbms = nbbm2schedules.keySet();
  370 + final List<BusMileage> busMileages = new ArrayList<>();
  371 + for (String nbbm : nbbms) {
  372 + List<ScheduleRealInfo> scheduleRealInfos = nbbm2schedules.get(nbbm);
  373 + if (scheduleRealInfos.size() == 0) {
  374 + continue;
  375 + }
  376 + BusMileage busMileage = new BusMileage();
  377 + busMileage.setScheduleDate(rq);
  378 + busMileage.setNbbm(nbbm);
  379 + busMileage.setJhlc(ScheduleCalculator.calcJHLC(scheduleRealInfos));
  380 + busMileage.setSjjhlc(ScheduleCalculator.calcSJLC(scheduleRealInfos));
  381 + busMileage.setSjcclc(ScheduleCalculator.calcCCLC(scheduleRealInfos));
  382 + busMileage.setSjjclc(ScheduleCalculator.calcJCLC(scheduleRealInfos));
  383 + busMileage.setYylc(ScheduleCalculator.calcYYLC(scheduleRealInfos));
  384 + busMileage.setKslc(ScheduleCalculator.calcKSLC(scheduleRealInfos));
  385 + busMileage.setCjlc(ScheduleCalculator.calcCJLC(scheduleRealInfos));
  386 + busMileage.setLblc(ScheduleCalculator.calcLBLC(scheduleRealInfos));
  387 + busMileage.setZjlc(ScheduleCalculator.calcZJLC(scheduleRealInfos));
  388 + busMileage.setZlc(ScheduleCalculator.calcZLC(scheduleRealInfos));
  389 + List<OilInfo> oilInfos = oilInfoMap.get(nbbm);
  390 + List<ElecInfo> elecInfos = elecInfoMap.get(nbbm);
  391 + Double yh = 0.0, dh = 0.0;
  392 + for (OilInfo oilInfo : oilInfos) {
  393 + yh = Arith.add(yh, oilInfo.getYh());
  394 + }
  395 + for (ElecInfo elecInfo : elecInfos) {
  396 + dh = Arith.add(yh, elecInfo.getHd());
  397 + }
  398 + busMileage.setYh(yh);
  399 + busMileage.setDh(dh);
  400 +
  401 + busMileages.add(busMileage);
  402 + }
  403 +
  404 + //编程式事务
  405 + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());
  406 + DefaultTransactionDefinition def = new DefaultTransactionDefinition();
  407 + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  408 + TransactionStatus status = tran.getTransaction(def);
  409 + try {
  410 + jdbcTemplate.update("delete from control_interface.bsth_t_mileage where schedule_date = ?", new Object[]{ dateTime.toString("yyyy-MM-dd") });
  411 + jdbcTemplate.batchUpdate("insert into control_interface.bsth_t_mileage (schedule_date,nbbm,jhlc,sjjhlc,sjcclc,sjjclc,yylc,kslc,cjlc,lblc,zjlc,zlc,yh,dh,schedule_month) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  412 + @Override
  413 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  414 + BusMileage busMileage = busMileages.get(i);
  415 + ps.setString(1, busMileage.getScheduleDate());
  416 + ps.setString(2, busMileage.getNbbm());
  417 + ps.setDouble(3, busMileage.getJhlc());
  418 + ps.setDouble(4, busMileage.getSjjhlc());
  419 + ps.setDouble(5, busMileage.getSjcclc());
  420 + ps.setDouble(6, busMileage.getSjjclc());
  421 + ps.setDouble(7, busMileage.getYylc());
  422 + ps.setDouble(8, busMileage.getKslc());
  423 + ps.setDouble(9, busMileage.getCjlc());
  424 + ps.setDouble(10, busMileage.getLblc());
  425 + ps.setDouble(11, busMileage.getZjlc());
  426 + ps.setDouble(12, busMileage.getZlc());
  427 + ps.setDouble(13, busMileage.getYh());
  428 + ps.setDouble(14, busMileage.getDh());
  429 + ps.setString(15, dateTime.toString("yyyy-MM"));
  430 + }
  431 +
  432 + @Override
  433 + public int getBatchSize() {
  434 + return busMileages.size();
  435 + }
  436 + });
  437 + tran.commit(status);
  438 + } catch (Exception e) {
  439 + tran.rollback(status);
  440 + }
  441 + }
  442 +
  443 + /**
  444 + * 线路司售配档对象
  445 + */
  446 + private final static class LineServiceConfigVo {
  447 +
  448 + private String lineName;
  449 +
  450 + private String month;
  451 +
  452 + private Integer driverFirstCount;
  453 +
  454 + private Integer driverLastCount;
  455 +
  456 + private Integer conductorFirstCount;
  457 +
  458 + private Integer conductorLastCount;
  459 +
  460 + public String getLineName() {
  461 + return lineName;
  462 + }
  463 +
  464 + public void setLineName(String lineName) {
  465 + this.lineName = lineName;
  466 + }
  467 +
  468 + public String getMonth() {
  469 + return month;
  470 + }
  471 +
  472 + public void setMonth(String month) {
  473 + this.month = month;
  474 + }
  475 +
  476 + public Integer getDriverFirstCount() {
  477 + return driverFirstCount;
  478 + }
  479 +
  480 + public void setDriverFirstCount(Integer driverFirstCount) {
  481 + this.driverFirstCount = driverFirstCount;
  482 + }
  483 +
  484 + public Integer getDriverLastCount() {
  485 + return driverLastCount;
  486 + }
  487 +
  488 + public void setDriverLastCount(Integer driverLastCount) {
  489 + this.driverLastCount = driverLastCount;
  490 + }
  491 +
  492 + public Integer getConductorFirstCount() {
  493 + return conductorFirstCount;
  494 + }
  495 +
  496 + public void setConductorFirstCount(Integer conductorFirstCount) {
  497 + this.conductorFirstCount = conductorFirstCount;
  498 + }
  499 +
  500 + public Integer getConductorLastCount() {
  501 + return conductorLastCount;
  502 + }
  503 +
  504 + public void setConductorLastCount(Integer conductorLastCount) {
  505 + this.conductorLastCount = conductorLastCount;
  506 + }
  507 + }
  508 +
  509 + /**
  510 + * 车辆配档对象
  511 + */
  512 + private final static class BusVo {
  513 +
  514 + private String lineName;
  515 +
  516 + private String month;
  517 +
  518 + private Integer busFirstCount;
  519 +
  520 + private Integer busLastCount;
  521 +
  522 + private Integer busMaxCount;
  523 +
  524 + public String getLineName() {
  525 + return lineName;
  526 + }
  527 +
  528 + public void setLineName(String lineName) {
  529 + this.lineName = lineName;
  530 + }
  531 +
  532 + public String getMonth() {
  533 + return month;
  534 + }
  535 +
  536 + public void setMonth(String month) {
  537 + this.month = month;
  538 + }
  539 +
  540 + public Integer getBusFirstCount() {
  541 + return busFirstCount;
  542 + }
  543 +
  544 + public void setBusFirstCount(Integer busFirstCount) {
  545 + this.busFirstCount = busFirstCount;
  546 + }
  547 +
  548 + public Integer getBusLastCount() {
  549 + return busLastCount;
  550 + }
  551 +
  552 + public void setBusLastCount(Integer busLastCount) {
  553 + this.busLastCount = busLastCount;
  554 + }
  555 +
  556 + public Integer getBusMaxCount() {
  557 + return busMaxCount;
  558 + }
  559 +
  560 + public void setBusMaxCount(Integer busMaxCount) {
  561 + this.busMaxCount = busMaxCount;
  562 + }
  563 + }
  564 +
  565 + /**
  566 + * 车辆公里、油耗对象
  567 + */
  568 + private final static class BusMileageVo {
  569 +
  570 + private String insideCode;
  571 +
  572 + private String month;
  573 +
  574 + private Double totalMileage;
  575 +
  576 + private Double oilConsume;
  577 +
  578 + private Double electricConsume;
  579 +
  580 + public String getInsideCode() {
  581 + return insideCode;
  582 + }
  583 +
  584 + public void setInsideCode(String insideCode) {
  585 + this.insideCode = insideCode;
  586 + }
  587 +
  588 + public String getMonth() {
  589 + return month;
  590 + }
  591 +
  592 + public void setMonth(String month) {
  593 + this.month = month;
  594 + }
  595 +
  596 + public Double getTotalMileage() {
  597 + return totalMileage;
  598 + }
  599 +
  600 + public void setTotalMileage(Double totalMileage) {
  601 + this.totalMileage = totalMileage;
  602 + }
  603 +
  604 + public Double getOilConsume() {
  605 + return oilConsume;
  606 + }
  607 +
  608 + public void setOilConsume(Double oilConsume) {
  609 + this.oilConsume = oilConsume;
  610 + }
  611 +
  612 + public Double getElectricConsume() {
  613 + return electricConsume;
  614 + }
  615 +
  616 + public void setElectricConsume(Double electricConsume) {
  617 + this.electricConsume = electricConsume;
  618 + }
  619 + }
  620 +}
... ...
src/main/java/com/bsth/server_rs/dks/LineServiceConfig.java 0 → 100644
  1 +package com.bsth.server_rs.dks;
  2 +
  3 +/**
  4 + * 线路运营司、售、车辆配档信息
  5 + * @author Hill
  6 + */
  7 +public class LineServiceConfig {
  8 +
  9 + private String lineCode;
  10 +
  11 + private String lineName;
  12 +
  13 + private String month;
  14 +
  15 + private String scheduleDate;
  16 +
  17 + private int driverCount;
  18 +
  19 + private int conductorCount;
  20 +
  21 + private int carCount;
  22 +
  23 + public String getLineCode() {
  24 + return lineCode;
  25 + }
  26 +
  27 + public void setLineCode(String lineCode) {
  28 + this.lineCode = lineCode;
  29 + }
  30 +
  31 + public String getLineName() {
  32 + return lineName;
  33 + }
  34 +
  35 + public void setLineName(String lineName) {
  36 + this.lineName = lineName;
  37 + }
  38 +
  39 + public String getMonth() {
  40 + return month;
  41 + }
  42 +
  43 + public void setMonth(String month) {
  44 + this.month = month;
  45 + }
  46 +
  47 + public String getScheduleDate() {
  48 + return scheduleDate;
  49 + }
  50 +
  51 + public void setScheduleDate(String scheduleDate) {
  52 + this.scheduleDate = scheduleDate;
  53 + }
  54 +
  55 + public int getDriverCount() {
  56 + return driverCount;
  57 + }
  58 +
  59 + public void setDriverCount(int driverCount) {
  60 + this.driverCount = driverCount;
  61 + }
  62 +
  63 + public int getConductorCount() {
  64 + return conductorCount;
  65 + }
  66 +
  67 + public void setConductorCount(int conductorCount) {
  68 + this.conductorCount = conductorCount;
  69 + }
  70 +
  71 + public int getCarCount() {
  72 + return carCount;
  73 + }
  74 +
  75 + public void setCarCount(int carCount) {
  76 + this.carCount = carCount;
  77 + }
  78 +}
... ...