package org.jeecg.modules.stm.inner.control.controller;

import java.util.Arrays;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.stm.inner.control.entity.StInnerControl;
import org.jeecg.modules.stm.inner.control.service.IStInnerControlService;

import com.baomidou.mybatisplus.core.metadata.IPage;
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;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: 内控策略表
 * @Author: yzh
 * @Date:   2023-03-05
 * @Version: V1.0
 */
  
@RestController
@RequestMapping("/inner.control/stInnerControl")
@Slf4j
public class StInnerControlController extends JeecgController<StInnerControl, IStInnerControlService> {
	@Autowired
	private IStInnerControlService stInnerControlService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stInnerControl
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "内控策略表-分页列表查询")
	  
	@GetMapping(value = "/list")
	public Result<IPage<StInnerControl>> queryPageList(StInnerControl stInnerControl,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		IPage<StInnerControl> pageList = stInnerControlService.defPage(stInnerControl,pageNo,pageSize,req.getParameterMap());
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stInnerControl
	 * @return
	 */
	@AutoLog(value = "内控策略表-添加")
	  
	@RequiresPermissions("inner.control:st_inner_control:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StInnerControl stInnerControl) {
		stInnerControlService.save(stInnerControl);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stInnerControl
	 * @return
	 */
	@AutoLog(value = "内控策略表-编辑")
	  
	@RequiresPermissions("inner.control:st_inner_control:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StInnerControl stInnerControl) {
		stInnerControlService.updateById(stInnerControl);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "内控策略表-通过id删除")
	  
	@RequiresPermissions("inner.control:st_inner_control:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stInnerControlService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "内控策略表-批量删除")
	  
	@RequiresPermissions("inner.control:st_inner_control:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stInnerControlService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "内控策略表-通过id查询")
	  
	@GetMapping(value = "/queryById")
	public Result<StInnerControl> queryById(@RequestParam(name="id",required=true) String id) {
		StInnerControl stInnerControl = stInnerControlService.getById(id);
		if(stInnerControl==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stInnerControl);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param stInnerControl
    */
    @RequiresPermissions("inner.control:st_inner_control:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StInnerControl stInnerControl) {
        return super.exportXls(request, stInnerControl, StInnerControl.class, "内控策略表");
    }

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

}
