package com.hotent.baseInfo.controller;


import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.baseInfo.model.CostDictData;
import com.hotent.baseInfo.manager.CostDictTypeManager;
import com.hotent.baseInfo.model.CostDictType;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hotent.base.model.CommonResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 字典类型表 前端控制器
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-09-13
 */
@RestController
@RequestMapping("/api/costDictType/v1/")
@Api(tags = "字典类型")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostDictTypeController {

	@Resource
	private CostDictTypeManager baseService;


    /**
	 * 新增,更新字典类型表
	 * @param costDictType
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="/save")
	@ApiOperation(value = "新增字典类型表数据", httpMethod = "POST", notes = "新增,更新字典类型表数据")
	public CommonResult<String> create(@ApiParam(name="CostDictType",value="字典类型表对象", required = true)@RequestBody CostDictType costDictType) throws Exception{
		String msg = "添加字典类型表成功";
		baseService.create(costDictType);
		return CommonResult.<String>ok().message(msg);
	}

	@PostMapping(value="/update")
	@ApiOperation(value = "修改字典类型表数据", httpMethod = "POST", notes = "修改,更新字典类型表数据")
	public CommonResult<String> update(@ApiParam(name="CostDictType",value="字典类型表对象", required = true)@RequestBody CostDictType costDictType) throws Exception{
		String msg ="更新字典类型表成功";
		baseService.update(costDictType);
		return CommonResult.<String>ok().message(msg);
	}

	@GetMapping(value="/selectDictDataByType")
	@ApiOperation(value="根据字典类型获取数据",httpMethod = "GET",notes = "根据字典类型获取数据")
	public CommonResult<List<CostDictData>> selectDictDataByType(@ApiParam(name="dicType",value="字典类型", required = true)@RequestParam(required=true) String dicType) throws Exception{
		List<CostDictData> costDictData = baseService.selectDictDataByType(dicType);
		CommonResult<List<CostDictData>> result = new CommonResult<>();
		result.setValue(costDictData);
		return result;
	}

	@GetMapping(value="/selectDictTypeAll")
	@ApiOperation(value="字典类型列表数据",httpMethod = "GET",notes = "字典类型列表数据")
	public CommonResult<List<CostDictType>> selectDictTypeAll() throws Exception{
		List<CostDictType> costDictTypes = baseService.selectDictTypeAll();
		CommonResult<List<CostDictType>> result = new CommonResult<>();
		result.setValue(costDictTypes);
		return result;
	}



	@GetMapping(value="/deleteDictTypeByIds")
	@ApiOperation(value="根据字典类型ids删除数据",httpMethod = "GET",notes = "根据字典类型ids删除数据")
	public CommonResult<String> deleteDictTypeByIds(@ApiParam(name="dictIds",value="字典id数组", required = true)@RequestParam(required=true) Long[] dictIds) throws Exception{
		baseService.deleteDictTypeByIds(dictIds);
		return CommonResult.<String>ok().message("删除成功");
	}
}
