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

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.stm.audit.entity.AuditInnerCheckmethodItem;
import org.jeecg.modules.stm.audit.service.IAuditInnerCheckmethodItemService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

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.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 内控制度检查方法条目
 * @Author: jeecg-boot
 * @Date:   2025-03-19
 * @Version: V1.0
 */

@RestController
@RequestMapping("/audit/auditInnerCheckmethodItem")
@Slf4j
public class AuditInnerCheckmethodItemController extends JeecgController<AuditInnerCheckmethodItem, IAuditInnerCheckmethodItemService> {
	@Autowired
	private IAuditInnerCheckmethodItemService auditInnerCheckmethodItemService;
	
	/**
	 * 分页列表查询
	 *
	 * @param auditInnerCheckmethodItem
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "内控制度检查方法条目-分页列表查询")

	@GetMapping(value = "/list")
	public Result<IPage<AuditInnerCheckmethodItem>> queryPageList(AuditInnerCheckmethodItem auditInnerCheckmethodItem,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<AuditInnerCheckmethodItem> queryWrapper = QueryGenerator.initQueryWrapper(auditInnerCheckmethodItem, req.getParameterMap());
		Page<AuditInnerCheckmethodItem> page = new Page<AuditInnerCheckmethodItem>(pageNo, pageSize);
		IPage<AuditInnerCheckmethodItem> pageList = auditInnerCheckmethodItemService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param auditInnerCheckmethodItem
	 * @return
	 */
	@AutoLog(value = "内控制度检查方法条目-添加")

	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody AuditInnerCheckmethodItem auditInnerCheckmethodItem) {
		auditInnerCheckmethodItemService.save(auditInnerCheckmethodItem);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param auditInnerCheckmethodItem
	 * @return
	 */
	@AutoLog(value = "内控制度检查方法条目-编辑")

	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AuditInnerCheckmethodItem auditInnerCheckmethodItem) {
		auditInnerCheckmethodItemService.updateById(auditInnerCheckmethodItem);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "内控制度检查方法条目-通过id删除")

	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		auditInnerCheckmethodItemService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "内控制度检查方法条目-批量删除")

	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.auditInnerCheckmethodItemService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "内控制度检查方法条目-通过id查询")

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

    /**
    * 导出excel
    *
    * @param request
    * @param auditInnerCheckmethodItem
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AuditInnerCheckmethodItem auditInnerCheckmethodItem) {
        return super.exportXls(request, auditInnerCheckmethodItem, AuditInnerCheckmethodItem.class, "内控制度检查方法条目");
    }

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

	 @GetMapping(value = "/getAllInnerOrderCheckMethodItem")
	 public Result<List<Map<String,Object>>> getAllInnerOrderCheckMethodItem(AuditInnerCheckmethodItem auditInnerCheckmethodItem, HttpServletRequest req) {
		 List<Map<String,Object>> list = auditInnerCheckmethodItemService.getAllInnerOrderCheckMethodItem(auditInnerCheckmethodItem);
		 return Result.OK(list);
	 }

}
