package com.nantian.cloud.jly.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jly.entity.DictDev;
import com.nantian.cloud.jly.entity.DictLevelRequest;
import com.nantian.cloud.jly.service.DictDevService;
import com.nantian.cloud.jly.service.DictLevelRequestService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * 用能单位能源计量器具准确度等级
 *
 * @author
 * @date 2018-09-27 15:20:44
 */
@RestController
@AllArgsConstructor
@Api(value = "dictLevelRequest",tags = "用能单位能源计量器具准确度等级")
@RequestMapping("/dictLevelRequest")
public class DictLevelRequestController {
	private final DictLevelRequestService dictLevelRequestService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param dictLevelRequest 用能单位能源计量器具准确度等级对象
	 * @return
	 */

	@ApiOperation(value = "查询用能单位能源计量器具准确度等级",notes = "条件查询用能单位能源计量器具准确度等级")
	@ApiImplicitParams({
			@ApiImplicitParam(name ="DictLevelRequest",value = "用能单位能源计量器具准确度等级",required = false,dataType = "json",paramType = "path"),
			@ApiImplicitParam(name ="Page",value = "分页对象",required = false,dataType = "json",paramType = "path")
	})
	@GetMapping("/page")
	public R getcheckDevPage(Page page, DictLevelRequest dictLevelRequest) {
		dictLevelRequest.setDelFlag("1"); //查询未删除数据
		return R.ok(dictLevelRequestService.page(page, Wrappers.query(dictLevelRequest)));
	}


	/**
	 * 信息
	 *
	 * @param dictLevelRequestId
	 * @return R
	 */
	@ApiOperation(value = "通过id查询用能单位能源计量器具准确度等级",notes = "通过id条件查询用能单位能源计量器具准确度等级")
	@ApiImplicitParam(name ="dictLevelRequestId",value = "用能单位能源计量器具准确度等级ID",required = true,paramType = "path",dataType = "int")
	@GetMapping("/{dictLevelRequestId}")
	public R getById(@PathVariable("dictLevelRequestId") Integer dictLevelRequestId) {
		return R.ok(dictLevelRequestService.getById(dictLevelRequestId));
	}

	/**
	 * 保存
	 *
	 * @param dictLevelRequest
	 * @return R
	 */
	@ApiOperation(value = "新增用能单位能源计量器具准确度等级",notes = "新增用能单位能源计量器具准确度等级")
	@ApiImplicitParam(name ="DictLevelRequest",value = "用能单位能源计量器具准确度等级",required = true,dataType = "json",paramType = "path")
	@PostMapping
	public R save(@RequestBody DictLevelRequest dictLevelRequest) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictLevelRequest.setUserid(u.getId());
		}
		if (u.getDeptId() != null) {
			dictLevelRequest.setDeptId(u.getDeptId());
		}
		dictLevelRequest.setDelFlag("1");
		dictLevelRequest.setUpdateTime(new Date());
		return R.ok(dictLevelRequestService.save(dictLevelRequest));
	}

	/**
	 * 修改
	 *
	 * @param dictLevelRequest
	 * @return R
	 */
	@ApiOperation(value = "修改用能单位能源计量器具准确度等级",notes = "修改用能单位能源计量器具准确度等级")
	@ApiImplicitParam(name ="DictLevelRequest",value = "用能单位能源计量器具准确度等级",required = true,dataType = "json",paramType = "path")
	@PutMapping
	public R updateById(@RequestBody DictLevelRequest dictLevelRequest) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictLevelRequest.setUserid(u.getId());
		}
		dictLevelRequest.setUpdateTime(new Date());
		return R.ok(dictLevelRequestService.updateById(dictLevelRequest));
	}

	/**
	 * 删除
	 *
	 * @param dictLevelRequestId
	 * @return R
	 */
	@ApiOperation(value = "删除用能单位能源计量器具准确度等级",notes = "删除用能单位能源计量器具准确度等级")
	@ApiImplicitParam(name ="dictLevelRequestId",value = "用能单位能源计量器具准确度等级id",required = true,dataType = "int",paramType = "path")
	@DeleteMapping("/{dictLevelRequestId}")
	public R removeById(@PathVariable("dictLevelRequestId") Long dictLevelRequestId) {
		DictLevelRequest dictLevelRequest = dictLevelRequestService.getById(dictLevelRequestId);
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictLevelRequest.setUserid(u.getId());
		}
		dictLevelRequest.setDelFlag("4");
		dictLevelRequest.setUpdateTime(new Date());
		return R.ok(dictLevelRequestService.updateById(dictLevelRequest));
	}

}
