package org.stm.act.check.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.stm.act.check.entity.StCaMainCheck;
import org.stm.act.check.service.IStCaMainCheckService;
import org.stm.act.main.entity.StCaMain;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 检查方法
 * @Author: yzh
 * @Date:   2023-03-06
 * @Version: V1.0
 */
@Api(tags="检查方法")
@RestController
@RequestMapping("/act.check/stCaMainCheck")
@Slf4j
public class StCaMainCheckController extends JeecgController<StCaMainCheck, IStCaMainCheckService> {
	@Autowired
	private IStCaMainCheckService stCaMainCheckService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stCaMain
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "检查方法-分页列表查询")
	@ApiOperation(value="检查方法-分页列表查询", notes="检查方法-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<StCaMainCheck>> queryPageList(StCaMain stCaMain,
													  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													  HttpServletRequest req) {
//		QueryWrapper<StCaMainCheck> queryWrapper = QueryGenerator.initQueryWrapper(stCaMainCheck, req.getParameterMap());
//		Page<StCaMainCheck> page = new Page<StCaMainCheck>(pageNo, pageSize);
//		IPage<StCaMainCheck> pageList = stCaMainCheckService.page(page, queryWrapper);
		IPage<StCaMainCheck> pageList = stCaMainCheckService.defPage(stCaMain,pageNo,pageSize,req.getParameterMap());
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stCaMainCheck
	 * @return
	 */
	@AutoLog(value = "检查方法-添加")
	@ApiOperation(value="检查方法-添加", notes="检查方法-添加")
	@RequiresPermissions("act.check:st_ca_main_check:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StCaMainCheck stCaMainCheck) {
		stCaMainCheckService.save(stCaMainCheck);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stCaMainCheck
	 * @return
	 */
	@AutoLog(value = "检查方法-编辑")
	@ApiOperation(value="检查方法-编辑", notes="检查方法-编辑")
	@RequiresPermissions("act.check:st_ca_main_check:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StCaMainCheck stCaMainCheck) {
		stCaMainCheckService.updateById(stCaMainCheck);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "检查方法-通过id删除")
	@ApiOperation(value="检查方法-通过id删除", notes="检查方法-通过id删除")
	@RequiresPermissions("act.check:st_ca_main_check:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stCaMainCheckService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "检查方法-批量删除")
	@ApiOperation(value="检查方法-批量删除", notes="检查方法-批量删除")
	@RequiresPermissions("act.check:st_ca_main_check:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stCaMainCheckService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "检查方法-通过id查询")
	@ApiOperation(value="检查方法-通过id查询", notes="检查方法-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<StCaMainCheck> queryById(@RequestParam(name="id",required=true) String id) {
		StCaMainCheck stCaMainCheck = stCaMainCheckService.getById(id);
		if(stCaMainCheck==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stCaMainCheck);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param stCaMainCheck
    */
    @RequiresPermissions("act.check:st_ca_main_check:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StCaMainCheck stCaMainCheck) {
        return super.exportXls(request, stCaMainCheck, StCaMainCheck.class, "检查方法");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("act.check:st_ca_main_check:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, StCaMainCheck.class);
    }

}
