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.TradeKind;
import com.nantian.cloud.jljc.service.TradeKindService;
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("/tradeKind")
@Api(value = "tradeKind",tags = "行业门类、大类、行业编码（统计局）")
public class TradeKindController {
	private final TradeKindService tradeKindService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param tradeKind
	 * @return
	 */
	@GetMapping("/page")
	@ApiOperation(value = "分页获取行业门类、大类、行业编码（统计局）", notes = "分页获取行业门类、大类、行业编码（统计局）")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "tradeKind", value = "行业门类、大类、行业编码（统计局）对象", required = false, dataType = "json", paramType = "path")
	})
	public R getTradeKindPage(Page page, TradeKind tradeKind) {
		return R.ok(tradeKindService.page(page, Wrappers.query(tradeKind)));
	}


	/**
	 *获取全部行业门类、大类、行业编码（统计局）
	 */
	@GetMapping("/selectAll")
	@ApiOperation(value = "获取全部行业门类、大类、行业编码（统计局）", notes = "获取全部行业门类、大类、行业编码（统计局）")
	@ApiImplicitParam(name = "tradeKind", value = "行业门类、大类、行业编码（统计局）对象", required = false, dataType = "json", paramType = "path")
	public R selectAll( TradeKind tradeKind) {
		return R.ok(tradeKindService.list( Wrappers.query(tradeKind)));
	}

	/**
	 *根据行业信息管理 获取大类行业目录
	 */
	@GetMapping("/category")
	//@ApiOperation(value = "获取全部行业门类", notes = "获取全部行业门类")
	@ApiOperation(value = "根据行业信息管理 获取大类行业目录", notes = "根据行业信息管理 获取大类行业目录")
	public R selectCategory() {
		return R.ok(tradeKindService.selectCategory());
	}

	/**
	 * 信息
	 *
	 * @param tradeKindId
	 * @return R
	 */
	@GetMapping("/{tradeKindId}")
	@ApiOperation(value = "根据id获取行业门类、大类、行业编码（统计局）", notes = "根据id获取行业门类、大类、行业编码（统计局）")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R getById(@PathVariable("tradeKindId") Integer tradeKindId) {
		return R.ok(tradeKindService.getById(tradeKindId));
	}

	/**
	 * 获取树形结构
	 * @return
	 */
	@GetMapping("/tree")
	@ApiOperation(value = "获取树形结构", notes = "获取树形结构")
	public R getDictRegionTree() {
		return R.ok(tradeKindService.getTradeKindTree());
	}

	/**
	 * 保存
	 *
	 * @param tradeKind
	 * @return R
	 */
	@PostMapping
	@SysLog("新增国民经济行业")
	@ApiOperation(value = "新增行业门类、大类、行业编码（统计局）", notes = "新增行业门类、大类、行业编码（统计局）")
	@ApiImplicitParam(name = "tradeKind", value = "行业门类、大类、行业编码（统计局）对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody TradeKind tradeKind) {
		return R.ok(tradeKindService.save(tradeKind));
	}

	/**
	 * 修改
	 *
	 * @param tradeKind
	 * @return R
	 */
	@PutMapping
	@SysLog("修改国民经济行业")
	@ApiOperation(value = "修改行业门类、大类、行业编码（统计局）", notes = "修改行业门类、大类、行业编码（统计局）")
	@ApiImplicitParam(name = "tradeKind", value = "行业门类、大类、行业编码（统计局）对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody TradeKind tradeKind) {
		return R.ok(tradeKindService.updateById(tradeKind));
	}

	/**
	 * 删除
	 *
	 * @param tradeKindId
	 * @return R
	 */
	@DeleteMapping("/{tradeKindId}")
	@SysLog("删除国民经济行业")
	@ApiOperation(value = "删除行业门类、大类、行业编码（统计局）", notes = "删除行业门类、大类、行业编码（统计局）")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R removeById(@PathVariable Integer tradeKindId) {
		return R.ok(tradeKindService.removeById(tradeKindId));
	}

}
