package org.jeecg.modules.stm.inner.order.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.order.service.IStInnerControlOrderService;
import org.jeecg.modules.stm.inner.order.entity.StInnerControlOrder;

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.order/stInnerControlOrder")
@Slf4j
public class StInnerControlOrderController extends JeecgController<StInnerControlOrder, IStInnerControlOrderService> {
	@Autowired
	private IStInnerControlOrderService stInnerControlOrderService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stInnerControlOrder
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "内控制度表-分页列表查询")

	@GetMapping(value = "/list")
	public Result<IPage<StInnerControlOrder>> queryPageList(StInnerControlOrder stInnerControlOrder,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
//		QueryWrapper<StInnerControlOrder> queryWrapper = QueryGenerator.initQueryWrapper(stInnerControlOrder, req.getParameterMap());
//		Page<StInnerControlOrder> page = new Page<StInnerControlOrder>(pageNo, pageSize);
//		IPage<StInnerControlOrder> pageList = stInnerControlOrderService.page(page, queryWrapper);
		IPage<StInnerControlOrder> pageList = stInnerControlOrderService.defPage(stInnerControlOrder,pageNo,pageSize,req.getParameterMap());
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stInnerControlOrder
	 * @return
	 */
	@AutoLog(value = "内控制度表-添加")

	@RequiresPermissions("inner.order:st_inner_control_order:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StInnerControlOrder stInnerControlOrder) {
		stInnerControlOrderService.save(stInnerControlOrder);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stInnerControlOrder
	 * @return
	 */
	@AutoLog(value = "内控制度表-编辑")

	@RequiresPermissions("inner.order:st_inner_control_order:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StInnerControlOrder stInnerControlOrder) {
		stInnerControlOrderService.updateById(stInnerControlOrder);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "内控制度表-通过id删除")

	@RequiresPermissions("inner.order:st_inner_control_order:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stInnerControlOrderService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "内控制度表-批量删除")

	@RequiresPermissions("inner.order:st_inner_control_order:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stInnerControlOrderService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "内控制度表-通过id查询")

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

    /**
    * 导出excel
    *
    * @param request
    * @param stInnerControlOrder
    */
    @RequiresPermissions("inner.order:st_inner_control_order:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StInnerControlOrder stInnerControlOrder) {
        return super.exportXls(request, stInnerControlOrder, StInnerControlOrder.class, "内控制度表");
    }

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

}
