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.DictDevSetting;
import com.nantian.cloud.jly.service.DictDevService;
import com.nantian.cloud.jly.service.DictDevSettingService;
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 = "dictDevSetting",tags = "能源计量器具配备率")
@RequestMapping("/dictDevSetting")
public class DictDevSettingController {
	private final DictDevSettingService dictDevSettingService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param dictDevSetting 能源计量器具配备率对象
	 * @return
	 */
	@SysLog("能源计量器具配备率-分页查询")
	@ApiOperation(value = "查询能源计量器具配备率",notes = "条件查询能源计量器具配备率")
	@ApiImplicitParams({
			@ApiImplicitParam(name ="DictDevSetting",value = "能源计量器具配备率",required = false,dataType = "json",paramType = "path"),
			@ApiImplicitParam(name ="Page",value = "分页对象",required = false,dataType = "json",paramType = "path")
	})
	@GetMapping("/page")
	public R getcheckDevPage(Page page, DictDevSetting dictDevSetting) {
		dictDevSetting.setDelFlag("1"); //查询未删除数据
		return R.ok(dictDevSettingService.page(page, Wrappers.query(dictDevSetting)));
	}


	/**
	 * 信息
	 *
	 * @param dictDevSettingId
	 * @return R
	 */
	@SysLog("能源计量器具配备率-通过id查询能源计量器具配备率")
	@ApiOperation(value = "通过id查询能源计量器具配备率",notes = "通过id条件查询能源计量器具配备率")
	@ApiImplicitParam(name ="dictDevSettingId",value = "能源计量器具配备率ID",required = true,paramType = "path",dataType = "int")
	@GetMapping("/{dictDevSettingId}")
	public R getById(@PathVariable("dictDevSettingId") Integer dictDevSettingId) {
		return R.ok(dictDevSettingService.getById(dictDevSettingId));
	}

	/**
	 * 保存
	 *
	 * @param dictDevSetting
	 * @return R
	 */
	@SysLog("能源计量器具配备率-保存")
	@ApiOperation(value = "新增能源计量器具配备率",notes = "新增能源计量器具配备率")
	@ApiImplicitParam(name ="DictDevSetting",value = "能源计量器具配备率",required = true,dataType = "json",paramType = "path")
	@PostMapping
	public R save(@RequestBody DictDevSetting dictDevSetting) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictDevSetting.setUserid(u.getId());
		}
		if (u.getDeptId() != null) {
			dictDevSetting.setDeptId(u.getDeptId());
		}
		dictDevSetting.setDelFlag("1");
		dictDevSetting.setUpdateTime(new Date());
		return R.ok(dictDevSettingService.save(dictDevSetting));
	}

	/**
	 * 修改
	 *
	 * @param dictDevSetting
	 * @return R
	 */
	@SysLog("能源计量器具配备率-修改")
	@ApiOperation(value = "修改能源计量器具配备率",notes = "修改能源计量器具配备率")
	@ApiImplicitParam(name ="DictDevSetting",value = "能源计量器具配备率",required = true,dataType = "json",paramType = "path")
	@PutMapping
	public R updateById(@RequestBody DictDevSetting dictDevSetting) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictDevSetting.setUserid(u.getId());
		}
		dictDevSetting.setUpdateTime(new Date());
		return R.ok(dictDevSettingService.updateById(dictDevSetting));
	}

	/**
	 * 删除
	 *
	 * @param dictDevSettingId
	 * @return R
	 */
	@SysLog("能源计量器具配备率-删除")
	@ApiOperation(value = "删除能源计量器具配备率",notes = "删除能源计量器具配备率")
	@ApiImplicitParam(name ="dictDevSettingId",value = "能源计量器具配备率id",required = true,dataType = "int",paramType = "path")
	@DeleteMapping("/{dictDevSettingId}")
	public R removeById(@PathVariable("dictDevSettingId") Long dictDevSettingId) {
		DictDevSetting dictDevSetting = dictDevSettingService.getById(dictDevSettingId);
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			dictDevSetting.setUserid(u.getId());
		}
		dictDevSetting.setDelFlag("4");
		dictDevSetting.setUpdateTime(new Date());
		return R.ok(dictDevSettingService.updateById(dictDevSetting));
	}

}
