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.CheckEnterpriceReport;
import com.nantian.cloud.jly.service.CheckEnterpriceReportService;
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 = "checkEnterpriceReport",tags = "企业提交能源计量审查附件表")
@RequestMapping("/checkEnterpriceReport")
public class CheckEnterpriceReportController {
	private final CheckEnterpriceReportService checkEnterpriceReportService;


	/**
	 * 分页查询
	 *
	 * @param page      分页对象
	 * @param checkEnterpriceReport 请假审批单
	 * @return
	 */
	@SysLog("查询企业提交能源计量审查附件表")
	@ApiOperation(value = "查询企业提交能源计量审查附件表",notes = "条件查询企业提交能源计量审查附件表")
	@ApiImplicitParams({
			@ApiImplicitParam(name ="CheckEnterpriceReport",value = "企业提交能源计量审查附件表",required = false,dataType = "json",paramType = "path"),
			@ApiImplicitParam(name ="Page",value = "分页对象",required = false,dataType = "json",paramType = "path")
	})
	@GetMapping("/page")
	public R getcheckEnterpriceReportPage(Page page, CheckEnterpriceReport checkEnterpriceReport) {
		checkEnterpriceReport.setDelFlag("1"); //查询未删除数据
		return R.ok(checkEnterpriceReportService.page(page, Wrappers.query(checkEnterpriceReport)));
	}


	/**
	 * 信息
	 *
	 * @param checkEnterpriceReportId
	 * @return R
	 */
	@SysLog("通过ID查询企业提交能源计量审查附件表")
	@ApiOperation(value = "通过ID查询企业提交能源计量审查附件表",notes = "通过ID企业提交能源计量审查附件表")
	@ApiImplicitParam(name ="checkEnterpriceReportId",value = "企业提交能源计量审查附件表ID",required = true,paramType = "path",dataType = "int")
	@GetMapping("/{checkEnterpriceReportId}")
	public R getById(@PathVariable("checkEnterpriceReportId") Integer checkEnterpriceReportId) {
		return R.ok(checkEnterpriceReportService.getById(checkEnterpriceReportId));
	}

	/**
	 * 保存
	 *
	 * @param checkEnterpriceReport
	 * @return R
	 */
	@SysLog("保存企业提交能源计量审查附件表")
	@ApiOperation(value = "保存企业提交能源计量审查附件表",notes = "新增企业提交能源计量审查附件表")
	@ApiImplicitParam(name ="CheckEnterpriceReport",value = "企业提交能源计量审查附件表",required = true,dataType = "json",paramType = "path")
	@PostMapping
	public R save(@RequestBody CheckEnterpriceReport checkEnterpriceReport) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			checkEnterpriceReport.setUserid(u.getId());
		}
		if (u.getDeptId() != null) {
			checkEnterpriceReport.setDeptId(u.getDeptId());
		}
		checkEnterpriceReport.setDelFlag("1");
		checkEnterpriceReport.setUpdateTime(new Date());
		return R.ok(checkEnterpriceReportService.save(checkEnterpriceReport));
	}

	/**
	 * 修改
	 *
	 * @param checkEnterpriceReport
	 * @return R
	 */
	@SysLog("修改企业提交能源计量审查附件表")
	@ApiOperation(value = "修改企业提交能源计量审查附件表",notes = "修改企业提交能源计量审查附件表")
	@ApiImplicitParam(name ="CheckEnterpriceReport",value = "企业提交能源计量审查附件表",required = true,dataType = "json",paramType = "path")
	@PutMapping
	public R updateById(@RequestBody CheckEnterpriceReport checkEnterpriceReport) {
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			checkEnterpriceReport.setUserid(u.getId());
		}
		checkEnterpriceReport.setUpdateTime(new Date());
		return R.ok(checkEnterpriceReportService.updateById(checkEnterpriceReport));
	}

	/**
	 * 删除
	 *
	 * @param checkEnterpriceReportId
	 * @return R
	 */
	@SysLog("删除企业提交能源计量审查附件表信息")
	@ApiOperation(value = "删除企业提交能源计量审查附件表信息",notes = "删除企业提交能源计量审查附件表信息")
	@ApiImplicitParam(name ="companyCalculaterId",value = "企业提交能源计量审查附件表ID",required = true,dataType = "int",paramType = "path")
	@DeleteMapping("/{checkEnterpriceReportId}")
	public R removeById(@PathVariable("checkEnterpriceReportId") Long checkEnterpriceReportId) {
		CheckEnterpriceReport checkEnterpriceReport = checkEnterpriceReportService.getById(checkEnterpriceReportId);
		ScUser u= SecurityUtils.getUser();
		if(u.getId()!=null){
			checkEnterpriceReport.setUserid(u.getId());
		}
		checkEnterpriceReport.setDelFlag("4");
		checkEnterpriceReport.setUpdateTime(new Date());
		return R.ok(checkEnterpriceReportService.updateById(checkEnterpriceReport));
	}

}
