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.ConfigureGridding;
import com.nantian.cloud.jly.entity.DictDev;
import com.nantian.cloud.jly.service.ConfigureGriddingService;
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 = "configureGridding", tags = "能源计量网络图")
@RequestMapping("/configureGridding")
public class ConfigureGriddingController {
    private final ConfigureGriddingService configureGriddingService;


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


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

    /**
     * 保存
     *
     * @param configureGridding
     * @return R
     */
    @SysLog("能源计量网络图-新增能源计量网络图")
    @ApiOperation(value = "新增能源计量网络图", notes = "新增能源计量网络图")
    @ApiImplicitParam(name = "ConfigureGridding", value = "能源计量网络图", required = true, dataType = "json", paramType = "path")
    @PostMapping
    public R save(@RequestBody ConfigureGridding configureGridding) {
        ScUser u= SecurityUtils.getUser();
        if(u.getId()!=null){
            configureGridding.setUserid(u.getId());
        }
        if (u.getDeptId() != null) {
            configureGridding.setDeptId(u.getDeptId());
        }
        configureGridding.setDelFlag("1");
        configureGridding.setUpdateTime(new Date());
        return R.ok(configureGriddingService.saveOrUpdate(configureGridding));
    }

    /**
     * 修改
     *
     * @param configureGridding
     * @return R
     */
    @SysLog("能源计量网络图-修改")
    @ApiOperation(value = "修改能源计量网络图", notes = "修改能源计量网络图")
    @ApiImplicitParam(name = "ConfigureGridding", value = "能源计量网络图", required = true, dataType = "json", paramType = "path")
    @PutMapping
    public R updateById(@RequestBody ConfigureGridding configureGridding) {
        ScUser u= SecurityUtils.getUser();
        if(u.getId()!=null){
            configureGridding.setUserid(u.getId());
        }
        configureGridding.setUpdateTime(new Date());
        return R.ok(configureGriddingService.updateById(configureGridding));
    }

    /**
     * 删除
     *
     * @param configureGriddingId
     * @return R
     */
    @SysLog("能源计量网络图-删除")
    @ApiOperation(value = "删除能源计量网络图", notes = "删除能源计量网络图")
    @ApiImplicitParam(name = "configureGriddingId", value = "能源计量网络图id", required = true, dataType = "int", paramType = "path")
    @DeleteMapping("/{configureGriddingId}")
    public R removeById(@PathVariable("configureGriddingId") Long configureGriddingId) {
        ConfigureGridding configureGridding = configureGriddingService.getById(configureGriddingId);
        ScUser u= SecurityUtils.getUser();
        if(u.getId()!=null){
            configureGridding.setUserid(u.getId());
        }
        configureGridding.setDelFlag("4");
        configureGridding.setUpdateTime(new Date());
        return R.ok(configureGriddingService.updateById(configureGridding));
    }

    /**
     * 分页查询企业能源计量网络图
     *
     * @param page
     * @param cmpName
     * @return R
     */
    @SysLog("能源计量网络图-分页查询企业能源计量网络图")
    @ApiOperation(value = "分页查询能源计量网络图", notes = "分页查询能源计量网络图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
            @ApiImplicitParam(name = "areaCodes", value = "地区编码", required = false, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "industryCode", value = "行业编码", required = false, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "cmpName", value = "企业名称", required = false, dataType = "string", paramType = "path")
    })
    @GetMapping("/getPageGridding")
    public R getpageGridding(Page page, String areaCodes, String industryCode, String cmpName,String epc) {
        return R.ok(configureGriddingService.getpageGridding(page,areaCodes,industryCode,cmpName,epc));
    }

}
