package com.dcit.danger.controller;

import com.dcit.common.enums.ResultEnum;
import com.dcit.common.utils.ResultVOUtil;
import com.dcit.common.vo.ResultVO;
import com.dcit.danger.exception.IOCException;
import com.dcit.danger.model.RegulationType;
import com.dcit.danger.service.RegulationTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="监管类型接口")
@RestController
@RequestMapping("regulationType")
@Slf4j
public class RegulationTypeController {
	
	@Autowired
	private RegulationTypeService regulationTypeService;

	@ApiOperation(value = "获取监管类型列表")
    @GetMapping("/getRegulationTypeList")
	public ResultVO<Object> getRegulationTypeList(@RequestParam(required = false, defaultValue = "1") int page,
												  @RequestParam(required = false, defaultValue = "10") int size){
		
		ModelMap modelMap = new ModelMap();
		try {
			PageHelper.offsetPage(page, size);

			List<RegulationType> list = regulationTypeService.selectByExample(null);

			PageInfo<RegulationType> pageInfoList = new PageInfo<RegulationType>(list);

			modelMap.addAttribute("pageData", pageInfoList.getList());
			modelMap.addAttribute("total", pageInfoList.getTotal());
		} catch (Exception e) {
			e.printStackTrace();
			log.error("【监管类型列表查询】操作出错,error={}",e.getMessage());
			throw new IOCException(ResultEnum.OPERATION_FAIL);
		}

		return ResultVOUtil.success(modelMap);
	}

}
