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.ReduceEmission;
import com.nantian.cloud.jljc.service.ReduceEmissionService;
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("/reduceEmission")
@Api(value = "reduceEmission",tags = "节能减排项目")
public class ReduceEmissionController {
	private final ReduceEmissionService reduceEmissionService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param reduceEmission
	 * @return
	 */
	@GetMapping("/page")
	@SysLog("分页获取节能减排项目")
	@ApiOperation(value = "分页获取节能减排项目", notes = "分页获取节能减排项目")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "reduceEmission", value = "节能减排项目对象", required = false, dataType = "json", paramType = "path")
	})
	public R getReduceEmissionPage(Page page, ReduceEmission reduceEmission) {
		return R.ok(reduceEmissionService.page(page, Wrappers.query(reduceEmission)));
	}


	/**
	 * 信息
	 *
	 * @param reduceEmissionId
	 * @return R
	 */
	@GetMapping("/{reduceEmissionId}")
	@SysLog("根据id获取节能减排项目")
	@ApiOperation(value = "根据id获取节能减排项目", notes = "根据id获取节能减排项目")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R getById(@PathVariable("reduceEmissionId") Integer reduceEmissionId) {
		return R.ok(reduceEmissionService.getById(reduceEmissionId));
	}

	/**
	 * 保存
	 *
	 * @param reduceEmission
	 * @return R
	 */
	@PostMapping
	@SysLog("新增节能减排项目")
	@ApiOperation(value = "新增节能减排项目", notes = "新增节能减排项目")
	@ApiImplicitParam(name = "reduceEmission", value = "节能减排项目对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody ReduceEmission reduceEmission) {
		return R.ok(reduceEmissionService.save(reduceEmission));
	}

	/**
	 * 修改
	 *
	 * @param reduceEmission
	 * @return R
	 */
	@PutMapping
	@SysLog("修改节能减排项目")
	@ApiOperation(value = "修改节能减排项目", notes = "修改节能减排项目")
	@ApiImplicitParam(name = "reduceEmission", value = "节能减排项目对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody ReduceEmission reduceEmission) {
		return R.ok(reduceEmissionService.updateById(reduceEmission));
	}

	/**
	 * 删除
	 *
	 * @param reduceEmissionId
	 * @return R
	 */
	@DeleteMapping("/{reduceEmissionId}")
	@SysLog("删除节能减排项目")
	@ApiOperation(value = "删除节能减排项目", notes = "删除节能减排项目")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R removeById(@PathVariable Integer reduceEmissionId) {
		return R.ok(reduceEmissionService.removeById(reduceEmissionId));
	}

}
