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.MeasurementUnitBase;
import com.nantian.cloud.jljc.service.MeasurementUnitBaseService;
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("/measurementUnitBase")
@Api(value="measurementUnitBase",tags = "基准单位")
public class MeasurementUnitBaseController {
	private final MeasurementUnitBaseService measurementUnitBaseService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param measurementUnitBase
	 * @return
	 */
	@GetMapping("/page")
	@SysLog("分页获取基准单位")
	@ApiOperation(value = "分页获取基准单位", notes = "分页获取基准单位")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "measurementUnitBase", value = "基准单位对象", required = false, dataType = "json", paramType = "path")
	})
	public R getMeasurementUnitBasePage(Page page, MeasurementUnitBase measurementUnitBase) {
		return R.ok(measurementUnitBaseService.page(page, Wrappers.query(measurementUnitBase)));
	}


	/**
	 * 信息
	 *
	 * @param measurementUnitBaseId
	 * @return R
	 */
	@GetMapping("/{measurementUnitBaseId}")
	@SysLog("根据id获取基准单位")
	@ApiOperation(value = "根据id获取基准单位", notes = "根据id获取基准单位")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R getById(@PathVariable("measurementUnitBaseId") Integer measurementUnitBaseId) {
		return R.ok(measurementUnitBaseService.getById(measurementUnitBaseId));
	}

	/**
	 * 保存
	 *
	 * @param measurementUnitBase
	 * @return R
	 */
	@PostMapping
	@SysLog("新增基准单位")
	@ApiOperation(value = "新增基准单位", notes = "新增基准单位")
	@ApiImplicitParam(name = "measurementUnitBase", value = "基准单位对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody MeasurementUnitBase measurementUnitBase) {
		return R.ok(measurementUnitBaseService.save(measurementUnitBase));
	}

	/**
	 * 修改
	 *
	 * @param measurementUnitBase
	 * @return R
	 */
	@PutMapping
	@SysLog("修改基准单位")
	@ApiOperation(value = "修改基准单位", notes = "修改基准单位")
	@ApiImplicitParam(name = "measurementUnitBase", value = "基准单位对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody MeasurementUnitBase measurementUnitBase) {
		return R.ok(measurementUnitBaseService.updateById(measurementUnitBase));
	}

	/**
	 * 删除
	 *
	 * @param measurementUnitBaseId
	 * @return R
	 */
	@DeleteMapping("/{measurementUnitBaseId}")
	@SysLog("删除基准单位")
	@ApiOperation(value = "删除基准单位", notes = "删除基准单位")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R removeById(@PathVariable Integer measurementUnitBaseId) {
		return R.ok(measurementUnitBaseService.removeById(measurementUnitBaseId));
	}

}
