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.TradeType;
import com.nantian.cloud.jljc.service.TradeTypeService;
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("/tradeType")
@Api(value = "tradeType",tags = "行业分类")
public class TradeTypeController {
	private final TradeTypeService tradeTypeService;


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


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

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

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

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

}
