RealTimeDataController.java 5.3 KB
package com.skua.modules.realtimedata.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.modules.realtimedata.service.IRealTimeDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 实时数据
 */
@Slf4j
@RestController
@RequestMapping("/sys/duplicate")
@Api(tags = "实时数据")
public class RealTimeDataController {

    @Autowired
    private IRealTimeDataService realTimeDataService;

    /**
     * 获取实时数据
     *
     * @return
     */
    @RequestMapping(value = "/queryRealTimeData", method = RequestMethod.GET)
    @ApiOperation("获取实时数据")
    public Result<IPage> queryRealTimeData(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, String departId, String type, String structId,String nmName, HttpServletRequest request) {
        Result<IPage> result = new Result();
        List<Map<String, Object>> data = realTimeDataService.queryRealTimeData(departId, type, structId,nmName);
        IPage iPage = new IPage() {
            @Override
            public List<OrderItem> orders() {
                return null;
            }

            @Override
            public List getRecords() {
                List list;
                if (pageNo * pageSize <= data.size()) {
                    list = data.subList((pageNo - 1) * pageSize, pageNo * pageSize);
                } else {
                    list = data.subList((pageNo - 1) * pageSize, data.size());
                }
                return list;
            }

            @Override
            public IPage setRecords(List records) {
                return null;
            }

            @Override
            public long getTotal() {
                return data.size();
            }

            @Override
            public IPage setTotal(long total) {
                return null;
            }

            @Override
            public long getSize() {
                return pageSize;
            }

            @Override
            public IPage setSize(long size) {
                return null;
            }

            @Override
            public long getCurrent() {
                return pageNo;
            }

            @Override
            public IPage setCurrent(long current) {
                return null;
            }
        };
        result.setResult(iPage);
        result.setSuccess(true);
        return result;
    }


    /**
     * 获取实时数据
     *
     * @return
     */
    @RequestMapping(value = "/queryStructData", method = RequestMethod.GET)
    @ApiOperation("获取实时数据工艺区间")
    public Result<List<Map<String, Object>>> queryStructData(String departId) {
        Result<List<Map<String, Object>>> result = new Result();
        if(StringUtils.isEmpty(departId)) {
        	departId = BaseContextHandler.getRealDepartId();
        }
        List<Map<String, Object>> data = realTimeDataService.queryStructData(departId);
        result.setResult(data);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "web趋势")
    @ApiOperation(value = "web趋势", notes = "web趋势")
    @GetMapping(value = "/getSZTreadWeb")
    public Result<Map<String, Object>> getSZTreadWeb(String factoryId, String timeType, String startTime, String endTime, String id) {
        Result<Map<String, Object>> result = new Result<>();
        Map<String, Object> data = realTimeDataService.getSZTreadWeb(factoryId, timeType, startTime,endTime,id);
        result.setResult(data);
        result.setSuccess(true);
        return result;
    }
    /**
     * 获取实时数据
     *
     * @return
     */
    @RequestMapping(value = "/queryStructDataApp", method = RequestMethod.GET)
    @ApiOperation("APP获取实时数据工艺区间")
    public Result<List<Map<String, Object>>> queryStructDataApp(String departId, HttpServletRequest request) {
        Result<List<Map<String, Object>>> result = new Result();
        List<Map<String, Object>> data = realTimeDataService.queryStructDataApp(departId);
        result.setResult(data);
        result.setSuccess(true);
        return result;
    }

    /**
     * 获取实时数据
     *
     * @return
     */
    @RequestMapping(value = "/queryRealTimeDataApp", method = RequestMethod.GET)
    @ApiOperation("APP获取实时数据")
    public Result<List<Map<String, Object>>> queryRealTimeDataApp(String departId, String type, String structId, String sortType,String nmName, HttpServletRequest request) {
        Result<List<Map<String, Object>>> result = new Result();
        List<Map<String, Object>> data = realTimeDataService.queryRealTimeDataApp(departId, type, structId, sortType,nmName);
        result.setResult(data);
        result.setSuccess(true);
        return result;
    }
}