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.CheckDev;
import com.nantian.cloud.jly.entity.DictDev;
import com.nantian.cloud.jly.service.CheckDevService;
import com.nantian.cloud.jly.service.DictDevService;
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 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 = "dictDev",tags = "主要用能设备能源消耗量")
@RequestMapping("/dictDev")
public class DictDevController {
	private final DictDevService dictDevService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param dictDev 主要用能设备能源消耗量对象
	 * @return
	 */
	@SysLog("主要用能设备能源消耗量-分页查询")
	@ApiOperation(value = "查询主要用能设备能源消耗量",notes = "条件查询主要用能设备能源消耗量")
	@ApiImplicitParams({
			@ApiImplicitParam(name ="DictDev",value = "主要用能设备能源消耗量",required = false,dataType = "json",paramType = "path"),
			@ApiImplicitParam(name ="Page",value = "分页对象",required = false,dataType = "json",paramType = "path")
	})
	@GetMapping("/page")
	public R getcheckDevPage(Page page, DictDev dictDev) {
		dictDev.setDelFlag("1"); //查询未删除数据
		return R.ok(dictDevService.page(page, Wrappers.query(dictDev)));
	}


	/**
	 * 信息
	 *
	 * @param dictDevId
	 * @return R
	 */
	@SysLog("主要用能设备能源消耗量-通过id查询主要用能设备能源消耗量")
	@ApiOperation(value = "通过id查询主要用能设备能源消耗量",notes = "通过id条件查询主要用能设备能源消耗量")
	@ApiImplicitParam(name ="dictDevId",value = "主要用能设备能源消耗量ID",required = true,paramType = "path",dataType = "int")
	@GetMapping("/{dictDevId}")
	public R getById(@PathVariable("dictDevId") Integer dictDevId) {
		return R.ok(dictDevService.getById(dictDevId));
	}

	/**
	 * 保存
	 *
	 * @param dictDev
	 * @return R
	 */
	@SysLog("主要用能设备能源消耗量-保存")
	@ApiOperation(value = "新增主要用能设备能源消耗量",notes = "新增主要用能设备能源消耗量")
	@ApiImplicitParam(name ="DictDev",value = "主要用能设备能源消耗量",required = true,dataType = "json",paramType = "path")
	@PostMapping
	public R save(@RequestBody DictDev dictDev) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictDev.setUserid(u.getId());
		}
		if (u.getDeptId() != null) {
			dictDev.setDeptId(u.getDeptId());
		}
		dictDev.setDelFlag("1");
		dictDev.setUpdateTime(new Date());
		return R.ok(dictDevService.save(dictDev));
	}

	/**
	 * 修改
	 *
	 * @param dictDev
	 * @return R
	 */
	@SysLog("主要用能设备能源消耗量-修改")
	@ApiOperation(value = "修改主要用能设备能源消耗量",notes = "修改主要用能设备能源消耗量")
	@ApiImplicitParam(name ="DictDev",value = "主要用能设备能源消耗量",required = true,dataType = "json",paramType = "path")
	@PutMapping
	public R updateById(@RequestBody DictDev dictDev) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictDev.setUserid(u.getId());
		}
		dictDev.setUpdateTime(new Date());
		return R.ok(dictDevService.updateById(dictDev));
	}

	/**
	 * 删除
	 *
	 * @param dictDevId
	 * @return R
	 */
	@SysLog("主要用能设备能源消耗量-删除")
	@ApiOperation(value = "删除主要用能设备能源消耗量",notes = "删除主要用能设备能源消耗量")
	@ApiImplicitParam(name ="dictDevId",value = "主要用能设备能源消耗量id",required = true,dataType = "int",paramType = "path")
	@DeleteMapping("/{dictDevId}")
	public R removeById(@PathVariable("dictDevId") Long dictDevId) {
		DictDev dictDev = dictDevService.getById(dictDevId);
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictDev.setUserid(u.getId());
		}
		dictDev.setDelFlag("4");
		dictDev.setUpdateTime(new Date());
		return R.ok(dictDevService.updateById(dictDev));
	}

}
