VideoController.java 7.49 KB
package com.bsth.controller.video;

import com.alibaba.dubbo.container.page.Page;
import com.alibaba.fastjson.JSON;
import com.bsth.common.ResponseCode;
import com.bsth.controller.schedule.basicinfo.legacy.CarsController;
import com.bsth.entity.Business;
import com.bsth.entity.Cars;
import com.bsth.entity.Line;
import com.bsth.entity.video.CarsTreeTable;
import com.bsth.entity.video.VideoChannel;
import com.bsth.entity.video.VideoTree;
import com.bsth.service.BusinessService;
import com.bsth.service.LineService;
import com.bsth.service.impl.videoimpl.WvpConfig;
import com.bsth.service.video.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @author liujun
 * @date 2024年07月01日 12:52
 */
@RestController
@Slf4j
@RequestMapping("video")
public class VideoController {
    @Autowired
    private VideoService videoService;
    @Autowired
    private CarsController carsController;

    @Autowired
    private WvpConfig wvpConfig;

    @GetMapping("/tree")
    public Map<String, Object> combinationTree() {
        Map<String, Object> result = new HashMap<>();
        try {
            List<VideoTree> trees = videoService.combinationTree();
            result.put("status", ResponseCode.SUCCESS);
            result.put("data", trees);
        } catch (Exception e) {
            log.error("查询视频树异常", e);
            result.put("status", ResponseCode.ERROR);
        }

        return result;
    }

    @GetMapping("/tree/carNo/{parentId}")
    public List<VideoTree> layTreeNodeCarNo(@PathVariable("parentId") String parentId) {
        return videoService.combinationTreeOfCar(parentId);
    }

    @GetMapping("/tree/search")
    public Map<String, Object> searchLayTreeNode(HttpServletRequest request) {
        String carNo = request.getParameter("insideCode_like");
        if (StringUtils.isEmpty(carNo)) {
            return combinationTree();
        }
        List<VideoTree> groups = videoService.searchTreeDataByCarNo(carNo);

        Map<String, Object> result = new HashMap<>();
        result.put("status", ResponseCode.SUCCESS);
        result.put("data", groups);

        return result;
    }


    @GetMapping("/tree/table")
    public Map<String, Object> queryTreeTable(@RequestParam Map<String, Object> map,
                                              @RequestParam(defaultValue = "0") int page,
                                              @RequestParam(defaultValue = "10") int limit,
                                              @RequestParam(defaultValue = "id") String order,
                                              @RequestParam(defaultValue = "DESC") String direction) {
        Map<String, Object> result = new HashMap<>();
        page = page - 1;
        Map<String, Object> queryResult = carsController.list(map, page, limit, order, direction);
        if (MapUtils.isEmpty(queryResult)) {
            result.put("status", ResponseCode.ERROR);
            return result;
        }

        if (Objects.equals(queryResult.get("status"), ResponseCode.ERROR.name())) {
            result.put("status", ResponseCode.ERROR);
            return result;
        }


        PageImpl<Cars> page1 = (PageImpl<Cars>) queryResult.get("data");
        if (Objects.nonNull(page1)) {
            result.put("count", page1.getTotalElements());
            int contentSize = CollectionUtils.size(page1.getContent());
            if (contentSize > 0) {
                List<CarsTreeTable> carsTreeTables = new ArrayList<>(contentSize);
                for (Object car : page1.getContent()) {
                    CarsTreeTable treeTable = new CarsTreeTable();
                    BeanUtils.copyProperties(car, treeTable);
                    carsTreeTables.add(treeTable);
                }
                result.put("data", carsTreeTables);
            }

            result.put("code", 0);
        }


        return result;
    }


    @GetMapping("/car/channel/{carNo}")
    public Map<String, Object> queryChannels(@PathVariable String carNo) {
        Map<String, Object> result = new HashMap<>();
        try {


            List<Map<String, Object>> videoChannels = videoService.getVideoChannel(carNo);
            result.put("status", ResponseCode.SUCCESS);
            result.put("data", videoChannels);
            result.put("channelImageURL", wvpConfig.getChannelListOfImgURL());
            result.put("wvpPlayURL", wvpConfig.getWvpPlayURL());
            result.put("wvpLiveBroadcast", wvpConfig.getWvpLiveBroadcast());

        } catch (Exception e) {
            log.error("查询车辆通道异常:[{}]", carNo, e);
            result.put("status", ResponseCode.ERROR);
        }
        return result;
    }

    @GetMapping("/car/channel/tree/{carNo}")
    public Map<String, Object> queryChannelsTree(@PathVariable String carNo) {
        Map<String, Object> result = new HashMap<>();
        try {


            List<Map<String, Object>> videoChannels = videoService.getVideoChannel(carNo);
            List<VideoTree> trees = new ArrayList<>();

            if (CollectionUtils.isNotEmpty(videoChannels)) {
                for (Map<String, Object> map : videoChannels) {
                    VideoTree tree = new VideoTree();
                    tree.setId(map.get("channelId"));
                    tree.setCode(map.get("channelId"));
                    tree.setSourceId(map.get("deviceId"));
                    tree.setType(401);
                    tree.setIcon("layui-icon-video");
                    String name = Objects.isNull(map.get("name")) ? map.get("channelId") + "_" + map.get("deviceId") : map.get("name").toString();
                    tree.setText("<img src='/metronic_v4.5.4/layui/icon/movie.ico' class ='imageIcon' />"+name);
                    tree.setNodePValue(carNo);

                    trees.add(tree);
                }
            }
            result.put("status", ResponseCode.SUCCESS);
            result.put("data", trees);
            result.put("channelImageURL", wvpConfig.getChannelListOfImgURL());
            result.put("wvpPlayURL", wvpConfig.getWvpPlayURL());
            result.put("wvpLiveBroadcast", wvpConfig.getWvpLiveBroadcast());

        } catch (Exception e) {
            log.error("查询车辆通道异常:[{}]", carNo, e);
            result.put("status", ResponseCode.ERROR);
        }
        return result;
    }

    @GetMapping("/car/channel/history/{device}/{channel}/{dateStr}")
    public Map<String, Object> queryChannelHistoryList(@PathVariable("device") String device, @PathVariable("channel") String channel, @PathVariable("dateStr") String dateStr) {
        Map<String, Object> result = new HashMap<>();
        try {
            String token = videoService.getToken();

            List<Map<String, Object>> videoChannels = videoService.getVideoChannelHistoryList(device, channel, dateStr, token);
            result.put("status", ResponseCode.SUCCESS);
            result.put("data", videoChannels);
            result.put("wvpPlayURL", wvpConfig.getWvpPlayURL());
        } catch (Exception e) {
            log.error("查询通道历史数据异常:[{}],[{}],[{}]", device, channel, dateStr, e);
            result.put("status", ResponseCode.ERROR);
        }
        return result;
    }
}