package org.jeecg.modules.stm.act.check.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;


import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
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.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.stm.act.check.entity.StCaMainCheck;
import org.jeecg.modules.stm.act.check.service.IStCaMainCheckService;
import org.jeecg.modules.stm.act.main.entity.StCaMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import retrofit2.http.Tag;

import java.util.Arrays;

/**
 * @Description: 检查方法
 * @Author: yzh
 * @Date:   2023-03-06
 * @Version: V1.0
 */

@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 = "检查方法-分页列表查询")
	@Operation(summary="检查方法-分页列表查询")
	@GetMapping(value = "/list")
	@IgnoreAuth
	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 = "检查方法-添加")
	@Operation(summary="检查方法-添加")
	@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 = "检查方法-编辑")
	@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删除")
	@RequiresPermissions("act.check:st_ca_main_check:delete")
	@DeleteMapping(value = "/delete")
	@IgnoreAuth
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stCaMainCheckService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "检查方法-批量删除")
	@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查询")
	@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);
	}


}
