package org.security.trans.prevent.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.security.trans.prevent.entity.PreventRisk;
import org.security.trans.prevent.service.IPreventRiskService;
import org.security.trans.prevent.vo.PreventRiskVO;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 风险提示表 控制器
 *
 * @author BladeX
 * @since 2022-07-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/preventrisk")
@Api(value = "风险提示表", tags = "风险提示表接口")
public class PreventRiskController extends BladeController {

	private final IPreventRiskService preventRiskService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入preventRisk")
	public R<PreventRiskVO> detail(PreventRisk preventRisk) {
		PreventRiskVO detail = preventRiskService.getDetail(preventRisk);
		return R.data(detail);
	}

	/**
	 * 分页 风险提示表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入preventRisk")
	public R<IPage<PreventRiskVO>> list(PreventRiskVO preventRiskVO, Query query) {
		IPage<PreventRiskVO> page = preventRiskService.getPage(preventRiskVO, query);
		return R.data(page);
	}

	/**
	 * 暂存 风险提示表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "暂存", notes = "传入preventRisk")
	public R save(@Valid @RequestBody PreventRiskVO preventRiskVO) {
		return R.status(preventRiskService.saveRisk(preventRiskVO));
	}

	/**
	 * 提交 风险提示表
	 */
	@PostMapping("/handin")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "提交", notes = "传入preventRisk")
	public R update(@Valid @RequestBody PreventRiskVO preventRiskVO) {
		return R.status(preventRiskService.handinRisk(preventRiskVO));
	}

	/**
	 * 删除 风险提示表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(preventRiskService.removeByIds(Func.toLongList(ids)));
	}


}
