package com.jay.monitor.data.server.controllers;//package com.jay.monitor.data.server.controllers;

import com.jay.monitor.data.core.model.response.PageResponseModel;
import com.jay.monitor.data.server.controllers.crud.BaseSimpleCrudController;
import com.jay.monitor.data.server.models.request.alert.AlertPlatformConfigRequest;
import com.jay.monitor.data.server.models.store.AlertPlatformConfig;
import com.jay.monitor.data.server.store.IAlertPlatformProcess;
import com.jay.monitor.data.server.store.ISimpleCrudProcess;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.jay.monitor.data.server.controllers.AlertPlatformController.PREFIX_URL;

//import com.jay.monitor.data.server.services.impl.DefaultBackstageRouteService;

/**
 * 后台路由管理
 *
 * @author liukx
 * @Date 2019-02-28 15:16
 */
@Controller
@RequestMapping(value = PREFIX_URL)
public class AlertPlatformController extends BaseSimpleCrudController<AlertPlatformConfig> {

    public final static String PREFIX_URL = "/alert/platform";
    public final static String LIST_URL = PREFIX_URL + "/pageList";
    public final static String ADD_URL = PREFIX_URL + "/add";
    public final static String UPDATE_URL = PREFIX_URL + "/update";
    public final static String DEL_URL = PREFIX_URL + "/del";
    public final static String TYPE_LIST_URL = PREFIX_URL + "/typeList";

    @Autowired
    private IAlertPlatformProcess alertPlatformProcess;

    @Override
    public ISimpleCrudProcess getCrudProcess() {
        return alertPlatformProcess;
    }

    @RequestMapping(value = "/pageList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public PageResponseModel<AlertPlatformConfig> pageList(@RequestBody AlertPlatformConfigRequest request)
        throws Exception {
        AlertPlatformConfig config = new AlertPlatformConfig();
        BeanUtils.copyProperties(request, config);
        // 将参数对应的全部匹配赋值
        PageResponseModel pageResponseModel =
            alertPlatformProcess.searchDataByList(request.getPageNo(), request.getPageSize(), config);
        return pageResponseModel;
    }

    @RequestMapping(value = "/typeList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<AlertPlatformConfig> typeList(@RequestBody AlertPlatformConfigRequest request) throws Exception {
        AlertPlatformConfig config = new AlertPlatformConfig();
        config.setPlatformType(request.getPlatformType());
        config.setStatus(1);
        return alertPlatformProcess.queryList(config);
    }

    @Override
    protected void addBefore(AlertPlatformConfig req) {

    }
}
