package com.bonus.material.expectations.controller;

import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.utils.ServletUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.expectations.domain.ExpectationsEntity;
import com.bonus.material.expectations.service.ExpectationsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "检验预警")
@RestController
@RequestMapping("/expectations")
public class ExpectationsController {
    @Resource
    private ExpectationsService expectationsService;

    /**
     * 查询现场维修列表
     */
    @ApiOperation(value = "查询检验预警列表")
    @GetMapping("/list")
    public AjaxResult list(ExpectationsEntity entity) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ExpectationsEntity> expectationsList = expectationsService.getExpectationsList(entity);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, expectationsList));
    }

    @ApiOperation(value = "查询检验预警数量")
    @PostMapping("/getCountExpectations")
    public AjaxResult getCountExpectations(@RequestBody ExpectationsEntity entity) {
        return expectationsService.getCountExpectations(entity);
    }


    @ApiOperation(value = "查询检验预警列表")
    @GetMapping("/listDetails")
    public AjaxResult getListDetails(ExpectationsEntity entity) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ExpectationsEntity> expectationsList = expectationsService.getListDetails(entity);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, expectationsList));
    }

}
