package com.yx.face.controller.admin;



import com.github.pagehelper.PageInfo;
import com.yx.face.boot.core.BaseController;
import com.yx.face.boot.restful.RestDTO;
import com.yx.face.boot.restful.RestResponse;
import com.yx.face.boot.restful.RestResult;
import com.yx.face.boot.restful.ServiceException;
import com.yx.face.model.query.UserEarlyWarningLogQu;
import com.yx.face.model.vo.UserEarlyWarningLogVO;
import com.yx.face.service.UserControlEarlyWarningListLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 预警日志 前端控制器
 * </p>
 *
 * @author wxg
 * @since 2022-01-24
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "B获取预警信息API")
@RestController
@RequestMapping("admin/controlEarlyWarningListLog")
public class UserControlEarlyWarningListLogController extends BaseController {

    private final UserControlEarlyWarningListLogService userControlEarlyWarningListLogService;


    @ApiOperation("预警信息")
    @GetMapping("/getListLog")
    public RestResult<List<UserEarlyWarningLogVO>> getListLog() {
        Integer adminId = getUserId();
        if (adminId == null || adminId <= 0) {
            throw new ServiceException("无此权限");
        }
        List<UserEarlyWarningLogVO> pageList = this.userControlEarlyWarningListLogService.getListLog(adminId);
        if (pageList != null) {
            return RestResponse.ok(pageList);
        }
        return RestResponse.error("获取常客列表分页失败");
    }


    @ApiOperation("预警确认")
    @GetMapping("/earlyWarningConfirm")
    public RestResult<Boolean> earlyWarningConfirm(@ApiParam(name = "id", value = "预警id") @RequestParam("id") Long id) {
        if (id == null || id <= 0) {
            throw new ServiceException("id为空");
        }
        Integer insert = this.userControlEarlyWarningListLogService.updateEarlyWarningConfirm(id);
        if (insert == 1) return RestResponse.ok(true);
        else return RestResponse.error("更新失败");
    }


    @ApiOperation("查询预警列表-分页")
    @PostMapping("/getListLogPageInfo")
    public RestResult<PageInfo<UserEarlyWarningLogVO>> getListLogPageInfo(@RequestBody RestDTO<UserEarlyWarningLogQu> dto) {
        if (dto.getData() == null) {
            dto.setData(new UserEarlyWarningLogQu());
        }
        dto.getData().setAdminId(getUserIdL());
        PageInfo<UserEarlyWarningLogVO> pageInfo = this.userControlEarlyWarningListLogService.getListLogPageInfo(dto);
        return RestResponse.ok(pageInfo);
    }


    @ApiOperation("导出Excel")
    @PostMapping("/getListLogExcel")
    public void getListLogExcel(@RequestBody UserEarlyWarningLogQu dto, HttpServletResponse response) {
        dto.setAdminId(getUserIdL());
        this.userControlEarlyWarningListLogService.getListLogExcel(dto, response);
    }
}
