package com.nantian.cloud.jljc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jljc.entity.EcAbnormalVolatility;
import com.nantian.cloud.jljc.entity.EcAbnormalVolatilityInfo;
import com.nantian.cloud.jljc.service.EcAbnormalVolatilityService;
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
 */
@RestController
@AllArgsConstructor
@RequestMapping("/ecAbnormalVolatility")
@CrossOrigin
@Api(value = "ecAbnormalVolatility",tags = "企业能耗异常波动表")
public class EcAbnormalVolatilityController {
	private final EcAbnormalVolatilityService ecAbnormalVolatilityService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param ecAbnormalVolatility
	 * @return
	 */
	@GetMapping("/page")
	@SysLog("分页获取企业能耗异常波动表")
	@ApiOperation(value = "分页获取企业能耗异常波动表", notes = "分页获取企业能耗异常波动表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
			@ApiImplicitParam(name = "ecAbnormalVolatility", value = "企业能耗异常波动表对象（查询条件：地区area,area2、行业tradeNum,tradeNum2" +
					"、年度year、数据状态dataStatus、企业名称epcName）", required = false, dataType = "json", paramType = "path")
	})
	public R getEcAbnormalVolatilityPage(Page page, EcAbnormalVolatility ecAbnormalVolatility) {
		//area、area2、dataStatus、epcName、tradeNum、tradeNum2、year
		//return R.ok(ecAbnormalVolatilityService.page(page, Wrappers.query(ecAbnormalVolatility)));
		ecAbnormalVolatility.setDelFlag("1");  //筛选未删除项
		return R.ok(ecAbnormalVolatilityService.getPageScope(page, ecAbnormalVolatility));
	}


	/**
	 * 信息
	 *
	 * @param ecAbnormalVolatilityId
	 * @return R
	 */
	@GetMapping("/{ecAbnormalVolatilityId}")
	@SysLog("根据id获取企业能耗异常波动表")
	@ApiOperation(value = "根据id获取企业能耗异常波动表", notes = "根据id获取企业能耗异常波动表")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R getById(@PathVariable("ecAbnormalVolatilityId") Integer ecAbnormalVolatilityId) {
		return R.ok(ecAbnormalVolatilityService.getById(ecAbnormalVolatilityId));
	}

	/**
	 * 保存
	 *
	 * @param ecAbnormalVolatility
	 * @return R
	 */
	@PostMapping
	@SysLog("新增企业能耗异常波动表")
	@ApiOperation(value = "新增企业能耗异常波动表", notes = "新增企业能耗异常波动表")
	@ApiImplicitParam(name = "ecAbnormalVolatility", value = "企业能耗异常波动表对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody EcAbnormalVolatility ecAbnormalVolatility) {
		ScUser u= SecurityUtils.getUser();
		ecAbnormalVolatility.setUserid(u.getId());
		ecAbnormalVolatility.setDeptId(u.getDeptId());
		ecAbnormalVolatility.setUpdateTime(new Date());
		ecAbnormalVolatility.setDelFlag("1");
		return R.ok(ecAbnormalVolatilityService.save(ecAbnormalVolatility));
	}

	/**
	 * 修改
	 *
	 * @param ecAbnormalVolatility
	 * @return R
	 */
	@PutMapping
	@SysLog("修改企业能耗异常波动表")
	@ApiOperation(value = "修改企业能耗异常波动表", notes = "修改企业能耗异常波动表")
	@ApiImplicitParam(name = "ecAbnormalVolatility", value = "企业能耗异常波动表对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody EcAbnormalVolatility ecAbnormalVolatility) {
		ScUser u= SecurityUtils.getUser();
		ecAbnormalVolatility.setUserid(u.getId());
		ecAbnormalVolatility.setUpdateTime(new Date());
		return R.ok(ecAbnormalVolatilityService.updateById(ecAbnormalVolatility));
	}

	/**
	 * 删除
	 *
	 * @param ecAbnormalVolatilityId
	 * @return R
	 */
	@DeleteMapping("/{ecAbnormalVolatilityId}")
	@SysLog("删除企业能耗异常波动表")
	@ApiOperation(value = "删除企业能耗异常波动表", notes = "删除企业能耗异常波动表")
	@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
	public R removeById(@PathVariable Integer ecAbnormalVolatilityId) {
		EcAbnormalVolatility ecAbnormalVolatility = ecAbnormalVolatilityService.getById(ecAbnormalVolatilityId);
		ScUser u= SecurityUtils.getUser();
		ecAbnormalVolatility.setUserid(u.getId());
		ecAbnormalVolatility.setUpdateTime(new Date());
		ecAbnormalVolatility.setDelFlag("4");
		return R.ok(ecAbnormalVolatilityService.updateById(ecAbnormalVolatility));
	}

}
