package com.ruoyi.project.system.controller; import java.util.List; import jakarta.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.R; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.project.system.domain.SysDictType; import com.ruoyi.project.system.service.ISysDictTypeService; /** * 数据字典信息 * * @author ruoyi */ @RestController @RequestMapping("/system/dict/type") @AllArgsConstructor public class SysDictTypeController extends BaseController { private ISysDictTypeService dictTypeService; @PreAuthorize("@ss.hasPermi('system:dict:list')") @GetMapping("/list") public TableDataInfo list(SysDictType dictType) { startPage(); List list = dictTypeService.selectDictTypeList(dictType); return getDataTable(list); } @Log(title = "字典类型", businessType = BusinessType.EXPORT) @PreAuthorize("@ss.hasPermi('system:dict:export')") @PostMapping("/export") public void export(HttpServletResponse response, SysDictType dictType) { List list = dictTypeService.selectDictTypeList(dictType); ExcelUtil util = new ExcelUtil(SysDictType.class); util.exportExcel(response, list, "字典类型"); } /** * 查询字典类型详细 */ @PreAuthorize("@ss.hasPermi('system:dict:query')") @GetMapping(value = "/{dictId}") public R getInfo(@PathVariable Long dictId) { return R.ok(dictTypeService.selectDictTypeById(dictId)); } /** * 新增字典类型 */ @PreAuthorize("@ss.hasPermi('system:dict:add')") @Log(title = "字典类型", businessType = BusinessType.INSERT) @PostMapping public R add(@Validated @RequestBody SysDictType dict) { if (!dictTypeService.checkDictTypeUnique(dict)) { return R.fail("新增字典'" + dict.getDictName() + "'失败,字典类型已存在"); } dict.setCreateBy(getUsername()); dictTypeService.insertDictType(dict); return R.ok(); } /** * 修改字典类型 */ @PreAuthorize("@ss.hasPermi('system:dict:edit')") @Log(title = "字典类型", businessType = BusinessType.UPDATE) @PutMapping public R edit(@Validated @RequestBody SysDictType dict) { if (!dictTypeService.checkDictTypeUnique(dict)) { return R.fail("修改字典'" + dict.getDictName() + "'失败,字典类型已存在"); } dict.setUpdateBy(getUsername()); dictTypeService.updateDictType(dict); return R.ok(); } /** * 删除字典类型 */ @PreAuthorize("@ss.hasPermi('system:dict:remove')") @Log(title = "字典类型", businessType = BusinessType.DELETE) @DeleteMapping("/{dictIds}") public R remove(@PathVariable Long[] dictIds) { dictTypeService.deleteDictTypeByIds(dictIds); return R.ok(); } /** * 刷新字典缓存 */ @PreAuthorize("@ss.hasPermi('system:dict:remove')") @Log(title = "字典类型", businessType = BusinessType.CLEAN) @DeleteMapping("/refreshCache") public R refreshCache() { dictTypeService.resetDictCache(); return R.ok(); } /** * 获取字典选择框列表 */ @GetMapping("/optionselect") public R optionselect() { List dictTypes = dictTypeService.selectDictTypeAll(); return R.ok(dictTypes); } }