package org.jeecg.modules.stm.risk.event.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.risk.event.entity.StRiskEvent;
import org.jeecg.modules.stm.risk.event.service.IStRiskEventService;

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;
import org.jeecg.modules.stm.risk.event.vo.StRiskEventVo;

/**
 * @Description: 风险事件
 * @Author: yzh
 * @Date:   2023-03-05
 * @Version: V1.0
 */
  
@RestController
@RequestMapping("/risk.event/stRiskEvent")
@Slf4j
public class StRiskEventController extends JeecgController<StRiskEvent, IStRiskEventService> {
	@Autowired
	private IStRiskEventService stRiskEventService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stRiskEvent
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "风险事件-分页列表查询")
	  
	@GetMapping(value = "/list")
	public Result<IPage<StRiskEvent>> queryPageList(StRiskEvent stRiskEvent,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
//		QueryWrapper<StRiskEvent> queryWrapper = QueryGenerator.initQueryWrapper(stRiskEvent, req.getParameterMap());
//		Page<StRiskEvent> page = new Page<StRiskEvent>(pageNo, pageSize);
//		IPage<StRiskEvent> pageList = stRiskEventService.page(page, queryWrapper);
		IPage<StRiskEvent> pageList = stRiskEventService.defPage(stRiskEvent,pageNo,pageSize,req.getParameterMap());
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stRiskEvent
	 * @return
	 */
	@AutoLog(value = "风险事件-添加")
	  
	@RequiresPermissions("risk.event:st_risk_event:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StRiskEventVo stRiskEvent) {
		stRiskEventService.save(stRiskEvent);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stRiskEvent
	 * @return
	 */
	@AutoLog(value = "风险事件-编辑")
	  
	@RequiresPermissions("risk.event:st_risk_event:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StRiskEventVo stRiskEvent) {
		stRiskEventService.updateById(stRiskEvent);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "风险事件-通过id删除")
	  
	@RequiresPermissions("risk.event:st_risk_event:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stRiskEventService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "风险事件-批量删除")
	  
	@RequiresPermissions("risk.event:st_risk_event:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stRiskEventService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "风险事件-通过id查询")
	  
	@GetMapping(value = "/queryById")
	public Result<StRiskEvent> queryById(@RequestParam(name="id",required=true) String id) {
		StRiskEvent stRiskEvent = stRiskEventService.getById(id);
		if(stRiskEvent==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stRiskEvent);
	}

	@RequiresPermissions("mine:mine_news:importExcel")
	@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	public Result<?> importExcel(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) {
		return super.importExcel(request, response, StRiskEvent.class);
	}


}
