package com.org.web.honor.controller;

import com.org.system.annotation.Log;
import com.org.system.controller.BaseController;
import com.org.system.enums.BusinessType;
import com.org.utils.AjaxResult;
import com.org.utils.core.IdParams;
import com.org.utils.page.TableDataInfo;
import com.org.web.honor.domain.BcHonorShow;
import com.org.web.honor.service.BcHonorShowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/honor/show")
public class BcHonorShowController extends BaseController {

	@Autowired
	BcHonorShowService bcHonorShowService;

	/**
	 * 新增
	 */
	@PostMapping("/addOrUpdate")
	@PreAuthorize("@ss.hasPermi('honor:show:add')")
	@Log(title = "荣誉橱窗展示新增/编辑", businessType = BusinessType.INSERT)
	public AjaxResult add(@Validated @RequestBody BcHonorShow bcHonorShow) {
		log.info("BcHonorShowController - add bcHonorShow:{}", bcHonorShow);

		return AjaxResult.success(bcHonorShowService.executeSaveOrUpdate(bcHonorShow));
	}

	/**
	 * 删除
	 */
	@PostMapping("/del")
	@PreAuthorize("@ss.hasPermi('honor:show:del')")
	@Log(title = "荣誉橱窗展示删除", businessType = BusinessType.DELETE)
	public AjaxResult del(@Validated @RequestBody IdParams params) {
		log.info("BcHonorShowController - del params:{}", params);

		return AjaxResult.success(bcHonorShowService.del(params.getId()));
	}

	/**
	 * 详情
	 */
	@PostMapping("/detail")
	@PreAuthorize("@ss.hasAnyPermi('honor:show:detail')")
	@Log(title = "荣誉橱窗展示详情", businessType = BusinessType.SELECT)
	public AjaxResult detail(@Validated @RequestBody IdParams params) {
		log.info("BcHonorShowController - detail params:{}", params);

		return AjaxResult.success(bcHonorShowService.getById(params.getId()));
	}

	/**
	 * 列表查询
	 */
	@GetMapping("/list")
	@PreAuthorize("@ss.hasAnyPermi('honor:show:detail')")
	@Log(title = "荣誉橱窗展示列表查询", businessType = BusinessType.SELECT)
	public TableDataInfo list(BcHonorShow params) {

		log.info("BcHonorShowController - list params:{}", params);

		startPage();

		List<BcHonorShow> list = bcHonorShowService.listShow(params);

		TableDataInfo dataTable = getDataTable(list);

		return dataTable;
	}


	/**
	 * 设置置顶
	 */
	@PostMapping("/setTop")
	@PreAuthorize("@ss.hasPermi('honor:show:add')")
	@Log(title = "荣誉橱窗展示置顶", businessType = BusinessType.UPDATE)
	public AjaxResult setTop(@Validated @RequestBody IdParams params) {
		log.info("BcHonorShowController - setTop params:{}", params);

		bcHonorShowService.setTop(params.getId());
		return AjaxResult.success();
	}

}
