package com.microservices.dms.achievementLibrary.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.microservices.common.core.utils.StringUtils;
import com.microservices.dms.achievementLibrary.domain.KeyValueVo;
import com.microservices.system.api.domain.SysDictData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.dms.achievementLibrary.domain.AchievementDictData;
import com.microservices.dms.achievementLibrary.service.IAchievementDictDataService;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.utils.poi.ExcelUtil;
import com.microservices.common.core.web.page.TableDataInfo;

/**
 * 成果相关字典Controller
 * 
 * @author microservices
 * @date 2025-05-23
 */
@Api(tags = "数据管理体系-成果字典管理")
@RestController
@RequestMapping("/achDict")
public class AchievementDictDataController extends BaseController
{
    @Autowired
    private IAchievementDictDataService achievementDictDataService;

    /**
     * 查询成果相关字典列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AchievementDictData achievementDictData)
    {
        startPage();
        List<AchievementDictData> list = achievementDictDataService.selectAchievementDictDataList(achievementDictData);
        return getDataTable(list);
    }

    /**
     * 导出成果相关字典列表
     */
    @Log(title = "成果相关字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AchievementDictData achievementDictData)
    {
        List<AchievementDictData> list = achievementDictDataService.selectAchievementDictDataList(achievementDictData);
        ExcelUtil<AchievementDictData> util = new ExcelUtil<AchievementDictData>(AchievementDictData.class);
        util.exportExcel(response, list, "成果相关字典数据");
    }

    /**
     * 获取成果相关字典详细信息
     */
    @GetMapping(value = "/{dictCode}")
    public AjaxResult getInfo(@PathVariable("dictCode") Long dictCode)
    {
        return success(achievementDictDataService.selectAchievementDictDataByDictCode(dictCode));
    }

    /**
     * 新增成果相关字典
     */
    @Log(title = "成果相关字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AchievementDictData achievementDictData)
    {
        return toAjax(achievementDictDataService.insertAchievementDictData(achievementDictData));
    }

    /**
     * 修改成果相关字典
     */
    @Log(title = "成果相关字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AchievementDictData achievementDictData)
    {
        return toAjax(achievementDictDataService.updateAchievementDictData(achievementDictData));
    }

    /**
     * 删除成果相关字典
     */
    @Log(title = "成果相关字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dictCodes}")
    public AjaxResult remove(@PathVariable Long[] dictCodes)
    {
        return toAjax(achievementDictDataService.deleteAchievementDictDataByDictCodes(dictCodes));
    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @ApiOperation("根据成果字典分类查询成果值")
    @GetMapping(value = "/getDictDateByType")
    public AjaxResult dictType(@PathVariable String dictType)
    {
        List<KeyValueVo> data = achievementDictDataService.selectDictDataByType(dictType);
        return success(data);
    }
}
