package com.xhkjedu.sapi.controller.appversion;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.appversion.TAppthirdMonitor;
import com.xhkjedu.sapi.service.appversion.AppthirdMonitorService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.sapi.vo.appversion.AppSearchVo;
import com.xhkjedu.sapi.vo.appversion.AppthirdMonitorPVo;
import com.xhkjedu.sapi.vo.appversion.AppthirdMonitorVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @author ywx
* @classname TAppthirdMonitorController
* @description
* @date 2020/11/10 10:04
**/
@RestController
@RequestMapping("/appthird_monitor")
public class AppthirdMonitorController {
    @Resource
    private AppthirdMonitorService appthirdMonitorService;

    @PostMapping("/add")
    @Action("三方应用监控-增加")
    public ResultVo add(@RequestBody TAppthirdMonitor monitor) {
        Integer id = appthirdMonitorService.save(monitor);
        return new ResultVo(0, "保存成功",id);
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody AppSearchVo monitor) {
        Integer schoolid = monitor.getSchoolid();
        Integer page = monitor.getPage();
        Integer pageSize = monitor.getPageSize();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        Integer year = appthirdMonitorService.getYear(schoolid);
        if (N_Utils.isEmptyInteger(page)) {//页码不传不分页导出用
            List<AppthirdMonitorVo> list = appthirdMonitorService.listAll(monitor, year);
            return new ResultVo(0, "获取应用外监控未处理列表成功", list);
        } else {
            PageHelper.startPage(page, pageSize);
            List<AppthirdMonitorVo> list = appthirdMonitorService.listAll(monitor, year);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
            return new ResultVo(0, "获取应用外监控未处理列表成功", pageResult);
        }
    }

    @PostMapping("/people")
    public ResultVo people(@RequestBody AppSearchVo monitor) {
        Integer createid = monitor.getCreateid();
        Integer page = monitor.getPage();
        Integer pageSize = monitor.getPageSize();
        N_Utils.validation(new Object[]{createid,"学生id",1,page,"显示页码",1,pageSize,"显示条数",1});
        Integer year = appthirdMonitorService.getYear2(createid);
        PageHelper.startPage(page, pageSize);
        List<AppthirdMonitorPVo> list = appthirdMonitorService.listPeople(monitor, year);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取学生未处理监控详情成功",pageResult);
    }

    @PostMapping("/handle")
    @Action("三方应用监控-标记")
    public ResultVo handle(@RequestBody AppSearchVo monitor) {
        N_Utils.validation(new Object[]{monitor.getCreateid(),"处理人id",1,monitor.getSchoolid(),"学校id",1});
        appthirdMonitorService.handle(monitor);
        return new ResultVo(0,"标记成功");
    }

    @PostMapping("/list2")
    public ResultVo list2(@RequestBody AppSearchVo monitor) {
        Integer schoolid = monitor.getSchoolid();
        Integer page = monitor.getPage();
        Integer pageSize = monitor.getPageSize();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        Integer year = appthirdMonitorService.getYear(schoolid);
        if (N_Utils.isEmptyInteger(page)) {//页码不传不分页导出用
            List<AppthirdMonitorVo> list = appthirdMonitorService.listAll2(monitor, year);
            return new ResultVo(0, "获取应用外监控已处理列表成功", list);
        } else {
            PageHelper.startPage(page, pageSize);
            List<AppthirdMonitorVo> list = appthirdMonitorService.listAll2(monitor, year);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
            return new ResultVo(0, "获取应用外监控已处理列表成功", pageResult);
        }
    }

    @PostMapping("/people2")
    public ResultVo people2(@RequestBody AppSearchVo monitor) {
        Integer createid = monitor.getCreateid();
        Integer page = monitor.getPage();
        Integer pageSize = monitor.getPageSize();
        Integer handlenum = monitor.getHandlenum();
        N_Utils.validation(new Object[]{createid,"学生id",1,page,"显示页码",1,pageSize,"显示条数",1,handlenum,"处理次数",1});
        PageHelper.startPage(page, pageSize);
        List<AppthirdMonitorPVo> list = appthirdMonitorService.listPeople2(monitor);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取学生已处理监控详情成功",pageResult);
    }
}
