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.RegulationInfo;
import com.nantian.cloud.jljc.service.RegulationInfoService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
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;

import java.util.Date;

/**
 * 节能法规和标准
 *
 * @author
 * @date 2018-09-27 15:20:44
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/regulationInfo")
@Api(value = "regulationInfo",tags = "节能法规和标准")
public class RegulationInfoController {
	private final RegulationInfoService regulationInfoService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param regulationInfo
	 * @return
	 */
	@GetMapping("/page")
	@SysLog("分页获取节能法规和标准")
	@ApiOperation(value = "分页获取节能法规和标准", notes = "分页获取节能法规和标准")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "regulationInfo", value = "节能法规和标准对象", required = false, dataType = "json", paramType = "path")
	})
	public R getRegulationInfoPage(Page page, RegulationInfo regulationInfo) {
		regulationInfo.setDelFlag("1"); //筛选未删除项
		return R.ok(regulationInfoService.page(page, Wrappers.query(regulationInfo)));
	}


	/**
	 * 信息
	 *
	 * @param regulationInfoId
	 * @return R
	 */
	@GetMapping("/{regulationInfoId}")
	@SysLog("根据id获取节能法规和标准")
	@ApiOperation(value = "根据id获取节能法规和标准", notes = "根据id获取节能法规和标准")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R getById(@PathVariable("regulationInfoId") Integer regulationInfoId) {
		return R.ok(regulationInfoService.getById(regulationInfoId));
	}

	/**
	 * 保存
	 *
	 * @param regulationInfo
	 * @return R
	 */
	@PostMapping
	@SysLog("新增节能法规和标准")
	@ApiOperation(value = "新增节能法规和标准", notes = "新增节能法规和标准")
	@ApiImplicitParam(name = "regulationInfo", value = "节能法规和标准对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody RegulationInfo regulationInfo) {
		ScUser u = SecurityUtils.getUser();
		regulationInfo.setUserid(u.getId());
		regulationInfo.setDeptId(u.getDeptId());
		regulationInfo.setDelFlag("1");
		regulationInfo.setUpdateTime(new Date());
		return R.ok(regulationInfoService.save(regulationInfo));
	}

	/**
	 * 修改
	 *
	 * @param regulationInfo
	 * @return R
	 */
	@PutMapping
	@SysLog("修改节能法规和标准")
	@ApiOperation(value = "修改节能法规和标准", notes = "修改节能法规和标准")
	@ApiImplicitParam(name = "regulationInfo", value = "节能法规和标准对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody RegulationInfo regulationInfo) {
		ScUser u = SecurityUtils.getUser();
		regulationInfo.setUserid(u.getId());
		regulationInfo.setUpdateTime(new Date());
		return R.ok(regulationInfoService.updateById(regulationInfo));
	}

	/**
	 * 删除
	 *
	 * @param regulationInfoId
	 * @return R
	 */
	@DeleteMapping("/{regulationInfoId}")
	@SysLog("删除节能法规和标准")
	@ApiOperation(value = "删除节能法规和标准", notes = "删除节能法规和标准")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R removeById(@PathVariable Integer regulationInfoId) {
		RegulationInfo regulationInfo = regulationInfoService.getById(regulationInfoId);
		ScUser u = SecurityUtils.getUser();
		regulationInfo.setUserid(u.getId());
		regulationInfo.setDeptId(u.getDeptId());
		regulationInfo.setDelFlag("1");
		regulationInfo.setUpdateTime(new Date());
		return R.ok(regulationInfoService.updateById(regulationInfo));
	}

}
