package com.uas.platform.b2b.manage.controller;

import com.uas.platform.b2b.manage.controller.support.PageResultBean;
import com.uas.platform.b2b.manage.model.Listen;
import com.uas.platform.b2b.manage.model.UseType;
import com.uas.platform.b2b.manage.page.PageInfo;
import com.uas.platform.b2b.manage.page.PageParams;
import com.uas.platform.b2b.manage.service.ListenService;
import com.uas.platform.b2b.manage.web.BaseController;
import com.uas.platform.core.util.AgentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 监控数据查询接口
 * @Author: huj
 * @Date: Created in 17:56 2018/11/27.
 */
@RequestMapping("/listen")
@RestController
public class ListenController extends BaseController {

    @Autowired
    ListenService listenService;

    /**
     * 分页查询
     * @return
     */
    @RequestMapping("/list")
    public PageResultBean<Listen> findAll(PageParams params, String keyword) {
        PageInfo info = new PageInfo(params);
        Sort sort = new Sort(Sort.Direction.ASC, "status");
        info.setSort(sort);
        if (!StringUtils.isEmpty(keyword)) {
            keyword = keyword.trim();
        }
        useLogService.appendLog(UseType.MONITORING_SEARCH.code(), keyword, AgentUtils.getIp(request));
        PageResultBean resultBean = new PageResultBean(listenService.findAll(info, keyword));
        return resultBean;
    }
}
