package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.exception.CommonException;
import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.common.security.annotation.RequiresPermissions;
import cn.cecep.talroad.domain.PcLabelValue;
import cn.cecep.talroad.domain.PcPollutant;
import cn.cecep.talroad.service.IPcLabelValueService;
import cn.cecep.talroad.vo.PcLabelValueVo;
import cn.cecep.talroad.vo.query.PcLabelValueQuery;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;


/**
 * * 开发公司：中节能天融科技有限公司
 * 特征标签-参数值Controller 控制层
 *
 * @author szhpt
 * @date 2023-02-02*/
@Api(tags = "基本档案--特征标签-参数值")
@RestController
@RequestMapping("/pcLabelValue")
public class PcLabelValueController extends BasesController
{
    @Autowired
    private IPcLabelValueService pcLabelValueService;

    /**
     * 查询特征标签-参数值列表
     */
    @ApiOperation(value = "查询特征标签-参数值")
    @GetMapping("/list")
    public AjaxResults<IPage<PcLabelValue>> list(PcLabelValueQuery pcLabelValue)
    {
        Page<PcLabelValue> page = new Page<>(pcLabelValue.getPageNum(), pcLabelValue.getPageSize());
        IPage<PcLabelValue> list = pcLabelValueService.page(page, PcLabelValueQuery.createLambdaQueryWrapper(pcLabelValue));
        return AjaxResults.success(list);
    }
    /**
     * 查询特征标签-参数值列表
     */
    @ApiOperation(value = "根据id查询特征标签-参数值下拉列表")
    @GetMapping("/selectLabelById")
    public AjaxResults<List<PcLabelValue>> selectLabelById(String labelId)
    {
        List<PcLabelValue> pcLabelValueList = pcLabelValueService.getBaseMapper().selectList(new QueryWrapper<PcLabelValue>().eq("label_id", labelId));
        return AjaxResults.success(pcLabelValueList);
    }


    /**
     * 导出特征标签-参数值列表
     */
    @ApiOperation(value = "导出特征标签-参数值")
    @Log(title = "特征标签-参数值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcLabelValue pcLabelValue)
    {
        List<PcLabelValue> list = pcLabelValueService.selectPcLabelValueList(pcLabelValue);
        ExcelUtil<PcLabelValue> util = new ExcelUtil<PcLabelValue>(PcLabelValue.class);
        util.exportExcel(response, list, "特征标签-参数值数据");
    }

    /**
     * 获取特征标签-参数值详细信息
     */
    @ApiOperation(value = "获取特征标签-参数值详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResults<PcLabelValue> getInfo(@PathVariable("id") String id) {
        return AjaxResults.success(pcLabelValueService.getById(id));
    }
    /**
     * 新增特征标签-参数值
     */
    @ApiOperation(value = "新增特征标签-参数值")
    @Log(title = "特征标签-参数值", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResults<Boolean> add(@RequestBody PcLabelValue pcLabelValue) {
        pcLabelValueService.add(pcLabelValue);
        return AjaxResults.success(true);

    }
    /**
     * 修改特征标签-参数值
     */
    @ApiOperation(value = "修改特征标签-参数值")
    @Log(title = "特征标签-参数值", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResults<Boolean> edit(@RequestBody PcLabelValue pcLabelValue) {
        pcLabelValueService.edit(pcLabelValue);
        return AjaxResults.success(true);
    }

    /**
     * 删除特征标签-参数值
     */
    @ApiOperation(value = "删除特征标签-参数值")
    @RequiresPermissions("talroad:pcLabelValue:remove")
    @Log(title = "特征标签-参数值", businessType = BusinessType.DELETE)
    @PostMapping("/{id}")
    public AjaxResults<Boolean> remove(@PathVariable String id) {
        pcLabelValueService.delete(id);
        return AjaxResults.success(true);
    }

    /**
     * 手工监测行业类别下拉框
     */
    @ApiOperation(value = "手工监测行业类别下拉框")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "行业类别", required = false, paramType = "query", dataType = "String"),
    })
    @GetMapping("/manualMonitoringIndustry")
    public AjaxResults<List<PcLabelValue>> manualMonitoringIndustry(@RequestParam(value = "name",required = false) String name)
    {
        List<PcLabelValue> list = pcLabelValueService.manualMonitoringIndustry(name);
        return AjaxResults.success(list);
    }
}
