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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 
 
import lombok.extern.slf4j.Slf4j;
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.AuditCriteriaConfig;
import org.jeecg.modules.stm.audit.service.IAuditCriteriaConfigService;

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

  
@RestController
@RequestMapping("/audit/auditCriteriaConfig")
@Slf4j
public class AuditCriteriaConfigController extends JeecgController<AuditCriteriaConfig, IAuditCriteriaConfigService> {
	@Autowired
	private IAuditCriteriaConfigService auditCriteriaConfigService;

	//@AutoLog(value = "audit_criteria_config-分页列表查询")
	  
	@GetMapping(value = "/list")
	public Result<List<AuditCriteriaConfig>> queryList(
			AuditCriteriaConfig auditCriteriaConfig,
								   HttpServletRequest req) {
		QueryWrapper<AuditCriteriaConfig> queryWrapper = QueryGenerator.initQueryWrapper(auditCriteriaConfig, req.getParameterMap());
		List<AuditCriteriaConfig> list = auditCriteriaConfigService.list(queryWrapper);
		return Result.OK(list);
	}

	@AutoLog(value = "audit_criteria_config-添加")
	  
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody AuditCriteriaConfig auditCriteriaConfig) {
		auditCriteriaConfigService.save(auditCriteriaConfig);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "audit_criteria_config-编辑")
	  
	//@RequiresPermissions("audit:audit_criteria_config:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AuditCriteriaConfig auditCriteriaConfig) {
		auditCriteriaConfigService.updateById(auditCriteriaConfig);
		return Result.OK("编辑成功!");
	}

	  
	//@RequiresPermissions("audit:audit_criteria_config:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		auditCriteriaConfigService.removeById(id);
		return Result.OK("删除成功!");
	}

	@AutoLog(value = "audit_criteria_config-批量删除")
	  
	//@RequiresPermissions("audit:audit_criteria_config:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.auditCriteriaConfigService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	  
	@GetMapping(value = "/queryById")
	public Result<AuditCriteriaConfig> queryById(@RequestParam(name="id",required=true) String id) {
		AuditCriteriaConfig auditCriteriaConfig = auditCriteriaConfigService.getById(id);
		if(auditCriteriaConfig==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(auditCriteriaConfig);
	}

    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AuditCriteriaConfig auditCriteriaConfig) {
        return super.exportXls(request, auditCriteriaConfig, AuditCriteriaConfig.class, "audit_criteria_config");
    }


    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, AuditCriteriaConfig.class);
    }
}
