|
@@ -0,0 +1,213 @@
|
|
|
+package com.jsjty.jdc.web.train.ctl;
|
|
|
+
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import javax.persistence.criteria.Subquery;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+
|
|
|
+import com.jsjty.jdc.util.DateUtil;
|
|
|
+import com.jsjty.jdc.web.train.bean.TrainBean;
|
|
|
+import com.jsjty.jdc.web.train.entity.BTlztHuoccc;
|
|
|
+import com.jsjty.jdc.web.train.service.BTlztHuocccService;
|
|
|
+import com.xtframe.sec.support.SecurityMgr;
|
|
|
+import com.xtframe.util.StringUtils;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping("/train2")
|
|
|
+public class BTlztHuocccCtl {
|
|
|
+ /** 核心接口 */
|
|
|
+ @Autowired
|
|
|
+ private SecurityMgr securityMgr;
|
|
|
+ @Autowired
|
|
|
+ private BTlztHuocccService bTlztHuocccService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前站点列车时刻表
|
|
|
+ *
|
|
|
+ * @param name 车站名
|
|
|
+ * @param trainCode 车次
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/findTrainTimes")
|
|
|
+ public String findTrainTimes(String name, String trainCode, Model model) {
|
|
|
+ // 查询所有机队信息
|
|
|
+ List<TrainBean> trainTimesList = findTrainsTimes(name, trainCode);
|
|
|
+ model.addAttribute("trainTimesList", trainTimesList);
|
|
|
+ model.addAttribute("name", name);
|
|
|
+ model.addAttribute("trainCode", trainCode);
|
|
|
+ return "railway/trainTimes";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据站点获取列车时刻信息
|
|
|
+ *
|
|
|
+ * @param name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<TrainBean> findTrainsTimes(final String name, final String code) {
|
|
|
+ /*Specification<BTlztHuoccc> spec = new Specification<BTlztHuoccc>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<BTlztHuoccc> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ List<Predicate> list = new ArrayList<Predicate>();
|
|
|
+ if(StringUtils.isNotEmpty(name) && StringUtils.isEmpty(code)) {
|
|
|
+ list.add(cb.equal(root.get("stationname").as(String.class), name));
|
|
|
+ list.add(cb.notEqual(root.get("departtime").as(String.class), "-"));
|
|
|
+ } else if(StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(code)) {
|
|
|
+ list.add(cb.equal(root.get("stationname").as(String.class), name));
|
|
|
+ list.add(cb.like(root.get("traincode").as(String.class), "%" + code + "%"));
|
|
|
+ list.add(cb.notEqual(root.get("departtime").as(String.class), "-"));
|
|
|
+ } else if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(code)){
|
|
|
+ list.add(cb.like(root.get("traincode").as(String.class), "%" + code + "%"));
|
|
|
+ list.add(cb.equal(root.get("arrivetime").as(String.class), "-"));
|
|
|
+ } else {
|
|
|
+ list.add(cb.equal(root.get("arrivetime").as(String.class), "-"));
|
|
|
+ }
|
|
|
+ return cb.and(list.toArray(new Predicate[] {}));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Sort newsort = new Sort(Direction.ASC, new String[] { "departtime" });
|
|
|
+ List<BTlztHuoccc> bTlztHuocccs = securityMgr.getQueryService().findAll(spec, newsort, BTlztHuoccc.class);
|
|
|
+ List<TrainBean> beans = new ArrayList<TrainBean>(bTlztHuocccs.size());
|
|
|
+ StringBuilder costSb = new StringBuilder();
|
|
|
+ DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm");
|
|
|
+ DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd");
|
|
|
+ for (BTlztHuoccc train : bTlztHuocccs) {
|
|
|
+ TrainBean bean = new TrainBean();
|
|
|
+ String trainCode = train.getTraincode();
|
|
|
+ bean.setTrainno(train.getTrainno());
|
|
|
+ bean.setTrainCode(train.getTraincode());
|
|
|
+ bean.setDepartName(train.getStationname());
|
|
|
+ bean.setDepartTime(train.getDeparttime());
|
|
|
+ List<BTlztHuoccc> lastInfos = bTlztHuocccService.findLastByTraincode(trainCode);
|
|
|
+ if (lastInfos.size() > 0) {
|
|
|
+ BTlztHuoccc last = lastInfos.get(0);
|
|
|
+ bean.setArriveName(last.getStationname());
|
|
|
+ bean.setArriveTime(last.getArrivetime());
|
|
|
+ int startDay = Integer.parseInt(train.getDays());
|
|
|
+ int arriveDay = Integer.parseInt(last.getDays());
|
|
|
+ bean.setDays(String.valueOf(arriveDay - startDay));
|
|
|
+ try {
|
|
|
+ Date departDate = dateFormat.parse(dayFormat.format(new Date()) + " " + bean.getDepartTime());
|
|
|
+ Date arriveDate = dateFormat.parse(dayFormat.format(new Date()) + " " + bean.getArriveTime());
|
|
|
+ long cost = arriveDate.getTime() - departDate.getTime()
|
|
|
+ + (arriveDay - startDay) * 24 * 60 * 60 * 1000;
|
|
|
+ int h = (int) (cost / 3600000);
|
|
|
+ int m = (int) (cost % 3600000) / 60000;
|
|
|
+ costSb.setLength(0);
|
|
|
+ if (h < 10) {
|
|
|
+ costSb.append("0");
|
|
|
+ }
|
|
|
+ costSb.append(h);
|
|
|
+ costSb.append(":");
|
|
|
+ if (m < 10) {
|
|
|
+ costSb.append("0");
|
|
|
+ }
|
|
|
+ costSb.append(m);
|
|
|
+ bean.setCost(costSb.toString());
|
|
|
+ }
|
|
|
+ catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ beans.add(bean);
|
|
|
+ }
|
|
|
+ return beans;*/
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前车次时刻信息
|
|
|
+ *
|
|
|
+ * @param traincode
|
|
|
+ * 车次
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/findTrainInfo")
|
|
|
+ public String findTrainInfo(String trainCode, String sfz, String ddz, Model model) {
|
|
|
+ // 查询所有火车信息
|
|
|
+ List<BTlztHuoccc> trainTimesList = findTrainDetail(trainCode, sfz, ddz);
|
|
|
+ List<TrainBean> trainBeanList = new ArrayList<TrainBean>(trainTimesList.size());
|
|
|
+ TrainBean trainBean = null;
|
|
|
+ /*for (BTlztHuoccc bTlztHuoccc : trainTimesList) {
|
|
|
+ trainBean = new TrainBean();
|
|
|
+ trainBean.setTrainno(bTlztHuoccc.getTrainno());
|
|
|
+ trainBean.setStationname(bTlztHuoccc.getStationname());
|
|
|
+ trainBean.setArriveTime(bTlztHuoccc.getArrivetime());
|
|
|
+ trainBean.setDepartTime(bTlztHuoccc.getDeparttime());
|
|
|
+ trainBean.setStayTime(bTlztHuoccc.getStayTime());
|
|
|
+ trainBean.setIsbefore(bTlztHuoccc.getIsbefore());
|
|
|
+ // 到达日
|
|
|
+ if (StringUtils.isNotEmpty(bTlztHuoccc.getDays())) {
|
|
|
+ String ddr = "当日到达";
|
|
|
+ int day = Integer.parseInt(bTlztHuoccc.getDays());
|
|
|
+ if (0 == day) ddr = "当日到达";
|
|
|
+ else if (1 == day) ddr = "次日到达";
|
|
|
+ else if (2 == day) ddr = "第三日到达";
|
|
|
+ trainBean.setDdr(ddr);
|
|
|
+ }
|
|
|
+ trainBeanList.add(trainBean);
|
|
|
+ }
|
|
|
+ model.addAttribute("bTlztHuocccList", trainBeanList);*/
|
|
|
+ return "railway/bTlztHuoccc";
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BTlztHuoccc> findTrainDetail(String trainCode, String sfz, String ddz) {
|
|
|
+ List<BTlztHuoccc> trains = bTlztHuocccService.findByTraincode(trainCode);
|
|
|
+ /*String dateFormat = "yy-MM-dd HH:mm";
|
|
|
+ String dayFormat = "yy-MM-dd";
|
|
|
+ Integer sfzzx = 0;
|
|
|
+ Integer ddzzx = Integer.MAX_VALUE;
|
|
|
+ for (BTlztHuoccc t : trains) {
|
|
|
+ if (sfz.equals(t.getStationname())) {
|
|
|
+ sfzzx = t.getTrainno();
|
|
|
+ }
|
|
|
+ if (ddz.equals(t.getStationname())) {
|
|
|
+ ddzzx = t.getTrainno();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (BTlztHuoccc t : trains) {
|
|
|
+ if (t.getTrainno() < sfzzx || t.getTrainno() > ddzzx) {
|
|
|
+ t.setIsbefore("1");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ t.setIsbefore("0");
|
|
|
+ }
|
|
|
+ if ("-".equals(t.getDeparttime()) || "-".equals(t.getArrivetime())) {
|
|
|
+ t.setStayTime("-");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Date date = new Date();
|
|
|
+ long departDate = DateUtil
|
|
|
+ .format(DateUtil.format(date, dayFormat) + " " + t.getDeparttime(), dateFormat).getTime();
|
|
|
+ long arriveDate = DateUtil
|
|
|
+ .format(DateUtil.format(date, dayFormat) + " " + t.getArrivetime(), dateFormat).getTime();
|
|
|
+ if (departDate < arriveDate) {
|
|
|
+ departDate += 24 * 60 * 60 * 1000;
|
|
|
+ }
|
|
|
+ int costM = (int) ((departDate - arriveDate) / (1000 * 60));
|
|
|
+ t.setStayTime(String.valueOf(costM));
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ return trains;
|
|
|
+ }
|
|
|
+}
|