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.MeasurementUnitType;
import com.nantian.cloud.jljc.service.MeasurementUnitTypeService;
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("/measurementUnitType")
@Api(value = "measurementUnitType",tags = "单位类型")
public class MeasurementUnitTypeController {
	private final MeasurementUnitTypeService measurementUnitTypeService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param measurementUnitType
	 * @return
	 */
	@GetMapping("/page")
	@SysLog("分页获取单位类型")
	@ApiOperation(value = "分页获取单位类型", notes = "分页获取单位类型")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "measurementUnitType", value = "单位类型对象", required = false, dataType = "json", paramType = "path")
	})
	public R getMeasurementUnitTypePage(Page page, MeasurementUnitType measurementUnitType) {
		return R.ok(measurementUnitTypeService.page(page, Wrappers.query(measurementUnitType)));
	}


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

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

	/**
	 * 修改
	 *
	 * @param measurementUnitType
	 * @return R
	 */
	@PutMapping
	@SysLog("修改单位类型")
	@ApiOperation(value = "修改单位类型", notes = "修改单位类型")
	@ApiImplicitParam(name = "measurementUnitType", value = "单位类型对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody MeasurementUnitType measurementUnitType) {
		return R.ok(measurementUnitTypeService.updateById(measurementUnitType));
	}

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

}
