package org.jeecg.modules.stm.audit.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 
 
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.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.jeecg.modules.stm.audit.entity.AuditCriteria;
import org.jeecg.modules.stm.audit.service.IAuditCriteriaService;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;


  
@RestController
@RequestMapping("/audit/auditCriteria")
@Slf4j
public class AuditCriteriaController extends JeecgController<AuditCriteria, IAuditCriteriaService> {
	@Autowired
	private IAuditCriteriaService auditCriteriaService;
	
	/**
	 * 分页列表查询
	 *
	 * @param auditCriteria
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "audit_criteria-分页列表查询")
	  
	@GetMapping(value = "/list")
	public Result<List<AuditCriteria>> queryList(AuditCriteria auditCriteria,
								   HttpServletRequest req) {
		QueryWrapper<AuditCriteria> queryWrapper = QueryGenerator.initQueryWrapper(auditCriteria, req.getParameterMap());
		List<AuditCriteria> list = auditCriteriaService.list(queryWrapper);
		return Result.OK(list);
	}
	
	/**
	 *   添加
	 *
	 * @param auditCriteria
	 * @return
	 */
	@AutoLog(value = "audit_criteria-添加")
	  
	//@RequiresPermissions("audit:audit_criteria:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody AuditCriteria auditCriteria) {
		auditCriteriaService.save(auditCriteria);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param auditCriteria
	 * @return
	 */
	@AutoLog(value = "audit_criteria-编辑")
	  
	//@RequiresPermissions("audit:audit_criteria:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AuditCriteria auditCriteria) {
		auditCriteriaService.updateById(auditCriteria);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "audit_criteria-通过id删除")
	  
	//@RequiresPermissions("audit:audit_criteria:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		auditCriteriaService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "audit_criteria-批量删除")
	  
	//@RequiresPermissions("audit:audit_criteria:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.auditCriteriaService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "audit_criteria-通过id查询")
	  
	@GetMapping(value = "/queryById")
	public Result<AuditCriteria> queryById(@RequestParam(name="id",required=true) String id) {
		AuditCriteria auditCriteria = auditCriteriaService.getById(id);
		if(auditCriteria==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(auditCriteria);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param auditCriteria
    */
    @RequiresPermissions("audit:audit_criteria:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AuditCriteria auditCriteria) {
        return super.exportXls(request, auditCriteria, AuditCriteria.class, "audit_criteria");
    }

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

}
