package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.Industry.IndustryDataAddRequest;
import com.ruoyi.web.domain.dto.Industry.IndustryDataEditRequest;
import com.ruoyi.web.domain.dto.Industry.IndustryDataQueryRequest;
import com.ruoyi.web.domain.entity.IndustryData;
import com.ruoyi.web.domain.vo.TimeAndValueVo.TimeAndValueVo;
import com.ruoyi.web.service.IndustryDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

@Api(tags ="产业数据管理")
@RestController
@RequestMapping("/system/industry")
public class IndustryController {

    @Autowired
    private IndustryDataService industryDataService;

    /**
     * 添加产业数据
     *
     * @param industryDataAddRequest
     * @return
     */
    @ApiOperation("添加产业数据")
    @PostMapping("/add")
    public AjaxResult addIndustryData(@RequestBody IndustryDataAddRequest industryDataAddRequest) {
        if (industryDataAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = industryDataService.addIndustryData(industryDataAddRequest);
        return success(id);
    }

    /**
     * 删除产业数据
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除产业数据")
    @PostMapping("/delete")
    public AjaxResult deleteIndustryData(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = industryDataService.deleteIndustryData(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑产业数据
     *
     * @param industryDataEditRequest
     * @return
     */
    @ApiOperation("编辑产业数据")
    @PostMapping("/edit")
    public AjaxResult editIndustryData(@RequestBody IndustryDataEditRequest industryDataEditRequest) {
        if (industryDataEditRequest == null) {
            return error("请求参数为空");
        }
        industryDataService.editIndustryData(industryDataEditRequest);
        return AjaxResult.success();
    }

    /**
     * 根据id获取产业数据
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取产业数据")
    @GetMapping("/get")
    public AjaxResult getIndustryDataById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        IndustryData industryData = industryDataService.getIndustryDataById(id);
        return success(industryData);
    }

    /**
     * 分页获取产业数据列表
     *
     * @param industryDataQueryRequest
     * @return
     */
    @ApiOperation("分页获取产业数据列表")
    @PostMapping("/list/page")
    public AjaxResult listIndustryDataByPage(@RequestBody IndustryDataQueryRequest industryDataQueryRequest) {
        if (industryDataQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<IndustryData> listIndustryDataByPage = industryDataService.getListIndustryDataByPage(industryDataQueryRequest);
        return success(listIndustryDataByPage);
    }

}
