package com.nantian.cloud.jljc.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jljc.entity.TradeCategory;
import com.nantian.cloud.jljc.service.TradeCategoryService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 行业归类表
 *
 * @author
 * @date 2018-09-27 15:20:44
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/tradeCategory")
@Api(value = "tradeCategory",tags = "行业归类表")
public class TradeCategoryController {
	private final TradeCategoryService tradeCategoryService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param tradeCategory
	 * @return
	 */
	@GetMapping("/page")
	@ApiOperation(value = "分页获取行业归类表", notes = "分页获取行业归类表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "tradeCategory", value = "行业归类表对象", required = false, dataType = "json", paramType = "path")
	})
	public R getTradeCategoryPage(Page page, TradeCategory tradeCategory) {
		return R.ok(tradeCategoryService.page(page, Wrappers.query(tradeCategory)));
	}


	/**
	 * 信息
	 *
	 * @param tradeCategoryId
	 * @return R
	 */
	@GetMapping("/{tradeCategoryId}")
	@ApiOperation(value = "根据id获取行业归类表", notes = "根据id获取行业归类表")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R getById(@PathVariable("tradeCategoryId") Integer tradeCategoryId) {
		return R.ok(tradeCategoryService.getById(tradeCategoryId));
	}

	/**
	 * 保存
	 *
	 * @param tradeCategory
	 * @return R
	 */
	@PostMapping
	@SysLog("新增行业归类表")
	@ApiOperation(value = "新增行业归类表", notes = "新增行业归类表")
	@ApiImplicitParam(name = "tradeCategory", value = "行业归类表对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody TradeCategory tradeCategory) {
		return R.ok(tradeCategoryService.save(tradeCategory));
	}

	/**
	 * 修改
	 *
	 * @param tradeCategory
	 * @return R
	 */
	@PutMapping
	@SysLog("修改行业归类表")
	@ApiOperation(value = "修改行业归类表", notes = "修改行业归类表")
	@ApiImplicitParam(name = "tradeCategory", value = "行业归类表对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody TradeCategory tradeCategory) {
		return R.ok(tradeCategoryService.updateById(tradeCategory));
	}

	/**
	 * 删除
	 *
	 * @param tradeCategoryId
	 * @return R
	 */
	@DeleteMapping("/{tradeCategoryId}")
	@SysLog("删除行业归类表")
	@ApiOperation(value = "删除行业归类表", notes = "删除行业归类表")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R removeById(@PathVariable Integer tradeCategoryId) {
		return R.ok(tradeCategoryService.removeById(tradeCategoryId));
	}

}
