package com.nantian.cloud.query.controller.jljc;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.query.entity.jljc.MultiDimensionDict;
import com.nantian.cloud.query.service.jljc.MultiDimensionDataSourceService;
import com.nantian.cloud.query.service.jljc.MultiDimensionDictService;
import com.nantian.sc.cloud.common.core.util.R;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 多维度查询字典库服务控制器
 *
 * @author kancy
 * @since 2022-02-17 10:46:10
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@RestController
@CrossOrigin
@AllArgsConstructor
@RequestMapping("/multiDimensionDict")
public class MultiDimensionDictController{
    private final MultiDimensionDictService multiDimensionDictService;
    private final MultiDimensionDataSourceService jljcMultiDimensionDataSourceService;

    @GetMapping("/page")
    @ApiOperation(value = "分页获取元数据", notes = "分页获取元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
    })
    public R getPageScope(Page page, MultiDimensionDict multiDimensionDict) {
        multiDimensionDict.setDelFlag("0"); //筛选未删除项
        return R.ok(multiDimensionDictService.getPageScope(page, multiDimensionDict));
    }

    @GetMapping("/query")
    @ApiOperation(value = "获取元数据列表", notes = "获取元数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
    })
    public R getList(MultiDimensionDict multiDimensionDict) {
        multiDimensionDict.setDelFlag("0"); //筛选未删除项
        multiDimensionDict.setDictType("1");
        return R.ok(multiDimensionDictService.list(Wrappers.query(multiDimensionDict)));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增元数据", notes = "新增元数据")
    @ApiImplicitParam(name = "multiDimensionDict", value = "元数据对象", required = true, dataType = "json", paramType = "path")
    public R save(@RequestBody MultiDimensionDict multiDimensionDict){
        multiDimensionDict.setDelFlag("1");
        return R.ok(multiDimensionDictService.save(multiDimensionDict));
    }

    @PutMapping("/update")
	@ApiOperation(value = "修改元数据", notes = "修改元数据")
	@ApiImplicitParam(name = "multiDimensionDict", value = "元数据对象", required = true, dataType = "json", paramType = "path")
	public R updateById(@RequestBody MultiDimensionDict multiDimensionDict) {
		return R.ok(multiDimensionDictService.updateById(multiDimensionDict));
	}

    @DeleteMapping("/deleted")
    @ApiOperation(value = "删除万家企业节能目标设定", notes = "删除万家企业节能目标设定")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
    public R removeById(@RequestBody MultiDimensionDict multiDimensionDict) {
        return R.ok(multiDimensionDictService.removeById(multiDimensionDict.getId()));
    }
}
