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.dto.PreventMaterialDTO;
import org.security.trans.prevent.entity.PreventMaterial;
import org.security.trans.prevent.service.IPreventMaterialService;
import org.security.trans.prevent.vo.PreventMaterialVO;
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("/preventmaterial")
@Api(value = "案件材料报送表", tags = "案件材料报送表接口")
public class PreventMaterialController extends BladeController {

	private final IPreventMaterialService preventMaterialService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入preventMaterial")
	public R<PreventMaterialVO> detail(PreventMaterial preventMaterial) {
		PreventMaterialVO detail = preventMaterialService.getDetail(preventMaterial);
		return R.data(detail);
	}

	/**
	 * 分页 案件材料报送表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入preventMaterial")
	public R<IPage<PreventMaterialVO>> list(PreventMaterialVO preventMaterialVO, Query query) {
		IPage<PreventMaterialVO> page = preventMaterialService.getPage(preventMaterialVO, query);
		return R.data(page);
	}

	/**
	 * 暂存 案件材料报送表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "暂存", notes = "传入preventMaterial")
	public R save(@Valid @RequestBody PreventMaterialDTO preventMaterialDTO) {
		return preventMaterialService.saveMaterial(preventMaterialDTO);
	}


	/**
	 * 删除 案件材料报送表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(preventMaterialService.removeByIds(Func.toLongList(ids)));
	}

	/**
	 * 提交 案件材料报送表
	 */
	@PostMapping("/handin")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "提交", notes = "传入preventMaterial")
	public R handin(@Valid @RequestBody PreventMaterialDTO preventMaterial) {
		return R.status(preventMaterialService.handin(preventMaterial));
	}
}
