OutEntrance.java 3.15 KB
package com.bsth.data.zndd;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.data.BasicData;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.util.SignUtils;
import com.bsth.websocket.handler.SendUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 对外接口
 * 与站牌、小程序对接接口
 * 调度预案通用接口
 */
@RestController
@RequestMapping("/out")
public class OutEntrance {

    @Autowired
    SendUtils sendUtils;
    @Autowired
    DayOfSchedule dayOfSchedule;



    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    JdbcTemplate jdbcTemplate;


    @RequestMapping(value = "/klyj", method = RequestMethod.POST)
    public Map klyj(@RequestBody JSONObject jsonObject) {
        Map rtn = new HashMap<>();
        try {
            logger.info("大客流接口调用----");
            if(!SignUtils.validation(Long.parseLong(jsonObject.getString("timestamp")),jsonObject.getString("sign"))){
                rtn.put("status", "验证失败");
               // return rtn;
            }
            String num=jsonObject.getString("num");
            JSONArray jsonArray = jsonObject.getJSONArray("stations");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject line=jsonArray.getJSONObject(i);
                String lineCode = line.get("lineCode").toString();
                String stationCode = line.get("stationCode").toString();
                String dir = line.get("dir").toString();
                String lineName=BasicData.lineCode2NameMap.get(lineCode);
                String stationName=BasicData.stationCode2NameMap.get(lineCode+"_"+dir+"_"+stationCode);

                Map m = new HashMap();
                m.put("stationCode", stationCode);
                m.put("lineCode", lineCode);
                m.put("stationName",stationName);
                m.put("lineName",lineName);
                m.put("num",num);
                m.put("xlDir",dir);
                sendUtils.klyj(m);//推送
            }
            rtn.put("status",ResponseCode.SUCCESS);
        } catch (Exception e) {
            rtn.put("err", ResponseCode.ERROR);
            logger.error("",e);
        }
        return rtn;
    }



    //调度获取站台视频
    @RequestMapping(value = "/getStationVideo", method = RequestMethod.GET)
    public String getStationVideo(@RequestParam Map m) {
        if (m.get("lineCode")==null || m.get("upDown")==null){
            return null;
        }
        String sql="select url from station_video where line_code ='"+m.get("lineCode")+"' and up_down ='"+m.get("upDown")+"'";
        String url= null;
        try {
            url = jdbcTemplate.queryForObject(sql,String.class);
        } catch (DataAccessException e) {
            return null;
        }
        return url;
    }


}