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.TradeProduct;
import com.nantian.cloud.jljc.service.TradeProductService;
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("/tradeProduct")
@Api(value = "tradeProduct",tags = "通俗行业")
public class TradeProductController {
	private final TradeProductService tradeProductService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param tradeProduct
	 * @return
	 */
	@GetMapping("/page")
	@ApiOperation(value = "分页获取通俗行业表", notes = "分页获取通俗行业表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "tradeProduct", value = "通俗行业表对象", required = false, dataType = "json", paramType = "path")
	})
	public R getTradeProductPage(Page page, TradeProduct tradeProduct) {
		return R.ok(tradeProductService.page(page, Wrappers.query(tradeProduct)));
	}

	@GetMapping("/list")
	@ApiOperation(value = "获取全部通俗行业列表", notes = "获取全部通俗行业列表")
	public R getTradeProductPage() {
		return R.ok(tradeProductService.list());
	}

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

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

	/**
	 * 修改
	 *
	 * @param tradeProduct
	 * @return R
	 */
	@PutMapping
	@SysLog("修改通俗行业表")
	@ApiOperation(value = "修改通俗行业表", notes = "修改通俗行业表")
	@ApiImplicitParam(name = "tradeProduct", value = "通俗行业表对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody TradeProduct tradeProduct) {
		return R.ok(tradeProductService.updateById(tradeProduct));
	}

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

}
