@@ -1,19 +1,5 @@ | |||
package com.ruoyi.web.controller.system; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import javax.servlet.http.HttpServletResponse; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
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.annotation.Log; | |||
import com.ruoyi.common.core.controller.BaseController; | |||
import com.ruoyi.common.core.domain.AjaxResult; | |||
@@ -24,16 +10,23 @@ import com.ruoyi.common.utils.StringUtils; | |||
import com.ruoyi.common.utils.poi.ExcelUtil; | |||
import com.ruoyi.system.service.ISysDictDataService; | |||
import com.ruoyi.system.service.ISysDictTypeService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.validation.annotation.Validated; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* 数据字典信息 | |||
* | |||
* | |||
* @author ruoyi | |||
*/ | |||
@RestController | |||
@RequestMapping("/system/dict/data") | |||
public class SysDictDataController extends BaseController | |||
{ | |||
public class SysDictDataController extends BaseController { | |||
@Autowired | |||
private ISysDictDataService dictDataService; | |||
@@ -42,8 +35,7 @@ public class SysDictDataController extends BaseController | |||
@PreAuthorize("@ss.hasPermi('system:dict:list')") | |||
@GetMapping("/list") | |||
public TableDataInfo list(SysDictData dictData) | |||
{ | |||
public TableDataInfo list(SysDictData dictData) { | |||
startPage(); | |||
List<SysDictData> list = dictDataService.selectDictDataList(dictData); | |||
return getDataTable(list); | |||
@@ -52,8 +44,7 @@ public class SysDictDataController extends BaseController | |||
@Log(title = "字典数据", businessType = BusinessType.EXPORT) | |||
@PreAuthorize("@ss.hasPermi('system:dict:export')") | |||
@PostMapping("/export") | |||
public void export(HttpServletResponse response, SysDictData dictData) | |||
{ | |||
public void export(HttpServletResponse response, SysDictData dictData) { | |||
List<SysDictData> list = dictDataService.selectDictDataList(dictData); | |||
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class); | |||
util.exportExcel(response, list, "字典数据"); | |||
@@ -64,8 +55,7 @@ public class SysDictDataController extends BaseController | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('system:dict:query')") | |||
@GetMapping(value = "/{dictCode}") | |||
public AjaxResult getInfo(@PathVariable Long dictCode) | |||
{ | |||
public AjaxResult getInfo(@PathVariable Long dictCode) { | |||
return success(dictDataService.selectDictDataById(dictCode)); | |||
} | |||
@@ -73,11 +63,21 @@ public class SysDictDataController extends BaseController | |||
* 根据字典类型查询字典数据信息 | |||
*/ | |||
@GetMapping(value = "/type/{dictType}") | |||
public AjaxResult dictType(@PathVariable String dictType) | |||
{ | |||
public AjaxResult dictType(@PathVariable String dictType) { | |||
List<SysDictData> data = dictTypeService.selectDictDataByType(dictType); | |||
if (StringUtils.isNull(data)) | |||
{ | |||
if (StringUtils.isNull(data)) { | |||
data = new ArrayList<SysDictData>(); | |||
} | |||
return success(data); | |||
} | |||
/** | |||
* 根据字典类型查询字典数据信息 | |||
*/ | |||
@GetMapping(value = "/type/all/{dictType}") | |||
public AjaxResult dictTypeAll(@PathVariable String dictType) { | |||
List<SysDictData> data = dictTypeService.selectAllDictDataByType(dictType); | |||
if (StringUtils.isNull(data)) { | |||
data = new ArrayList<SysDictData>(); | |||
} | |||
return success(data); | |||
@@ -89,8 +89,7 @@ public class SysDictDataController extends BaseController | |||
@PreAuthorize("@ss.hasPermi('system:dict:add')") | |||
@Log(title = "字典数据", businessType = BusinessType.INSERT) | |||
@PostMapping | |||
public AjaxResult add(@Validated @RequestBody SysDictData dict) | |||
{ | |||
public AjaxResult add(@Validated @RequestBody SysDictData dict) { | |||
dict.setCreateBy(getUsername()); | |||
return toAjax(dictDataService.insertDictData(dict)); | |||
} | |||
@@ -101,8 +100,7 @@ public class SysDictDataController extends BaseController | |||
@PreAuthorize("@ss.hasPermi('system:dict:edit')") | |||
@Log(title = "字典数据", businessType = BusinessType.UPDATE) | |||
@PutMapping | |||
public AjaxResult edit(@Validated @RequestBody SysDictData dict) | |||
{ | |||
public AjaxResult edit(@Validated @RequestBody SysDictData dict) { | |||
dict.setUpdateBy(getUsername()); | |||
return toAjax(dictDataService.updateDictData(dict)); | |||
} | |||
@@ -113,8 +111,7 @@ public class SysDictDataController extends BaseController | |||
@PreAuthorize("@ss.hasPermi('system:dict:remove')") | |||
@Log(title = "字典类型", businessType = BusinessType.DELETE) | |||
@DeleteMapping("/{dictCodes}") | |||
public AjaxResult remove(@PathVariable Long[] dictCodes) | |||
{ | |||
public AjaxResult remove(@PathVariable Long[] dictCodes) { | |||
dictDataService.deleteDictDataByIds(dictCodes); | |||
return success(); | |||
} | |||
@@ -1,19 +1,20 @@ | |||
package com.ruoyi.system.service; | |||
import java.util.List; | |||
import com.ruoyi.common.core.domain.entity.SysDictData; | |||
import com.ruoyi.common.core.domain.entity.SysDictType; | |||
import java.util.List; | |||
/** | |||
* 字典 业务层 | |||
* | |||
* | |||
* @author ruoyi | |||
*/ | |||
public interface ISysDictTypeService | |||
{ | |||
/** | |||
* 根据条件分页查询字典类型 | |||
* | |||
* | |||
* @param dictType 字典类型信息 | |||
* @return 字典类型集合信息 | |||
*/ | |||
@@ -21,22 +22,24 @@ public interface ISysDictTypeService | |||
/** | |||
* 根据所有字典类型 | |||
* | |||
* | |||
* @return 字典类型集合信息 | |||
*/ | |||
public List<SysDictType> selectDictTypeAll(); | |||
/** | |||
* 根据字典类型查询字典数据 | |||
* | |||
* | |||
* @param dictType 字典类型 | |||
* @return 字典数据集合信息 | |||
*/ | |||
public List<SysDictData> selectDictDataByType(String dictType); | |||
public List<SysDictData> selectAllDictDataByType(String dictType); | |||
/** | |||
* 根据字典类型ID查询信息 | |||
* | |||
* | |||
* @param dictId 字典类型ID | |||
* @return 字典类型 | |||
*/ | |||
@@ -44,7 +47,7 @@ public interface ISysDictTypeService | |||
/** | |||
* 根据字典类型查询信息 | |||
* | |||
* | |||
* @param dictType 字典类型 | |||
* @return 字典类型 | |||
*/ | |||
@@ -52,7 +55,7 @@ public interface ISysDictTypeService | |||
/** | |||
* 批量删除字典信息 | |||
* | |||
* | |||
* @param dictIds 需要删除的字典ID | |||
*/ | |||
public void deleteDictTypeByIds(Long[] dictIds); | |||
@@ -74,7 +77,7 @@ public interface ISysDictTypeService | |||
/** | |||
* 新增保存字典类型信息 | |||
* | |||
* | |||
* @param dictType 字典类型信息 | |||
* @return 结果 | |||
*/ | |||
@@ -82,7 +85,7 @@ public interface ISysDictTypeService | |||
/** | |||
* 修改保存字典类型信息 | |||
* | |||
* | |||
* @param dictType 字典类型信息 | |||
* @return 结果 | |||
*/ | |||
@@ -90,7 +93,7 @@ public interface ISysDictTypeService | |||
/** | |||
* 校验字典类型称是否唯一 | |||
* | |||
* | |||
* @param dictType 字典类型 | |||
* @return 结果 | |||
*/ | |||
@@ -1,13 +1,5 @@ | |||
package com.ruoyi.system.service.impl; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.PostConstruct; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import com.ruoyi.common.constant.UserConstants; | |||
import com.ruoyi.common.core.domain.entity.SysDictData; | |||
import com.ruoyi.common.core.domain.entity.SysDictType; | |||
@@ -17,15 +9,23 @@ import com.ruoyi.common.utils.StringUtils; | |||
import com.ruoyi.system.mapper.SysDictDataMapper; | |||
import com.ruoyi.system.mapper.SysDictTypeMapper; | |||
import com.ruoyi.system.service.ISysDictTypeService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import javax.annotation.PostConstruct; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 字典 业务层处理 | |||
* | |||
* | |||
* @author ruoyi | |||
*/ | |||
@Service | |||
public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
{ | |||
public class SysDictTypeServiceImpl implements ISysDictTypeService { | |||
@Autowired | |||
private SysDictTypeMapper dictTypeMapper; | |||
@@ -36,94 +36,89 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
* 项目启动时,初始化字典到缓存 | |||
*/ | |||
@PostConstruct | |||
public void init() | |||
{ | |||
public void init() { | |||
loadingDictCache(); | |||
} | |||
/** | |||
* 根据条件分页查询字典类型 | |||
* | |||
* | |||
* @param dictType 字典类型信息 | |||
* @return 字典类型集合信息 | |||
*/ | |||
@Override | |||
public List<SysDictType> selectDictTypeList(SysDictType dictType) | |||
{ | |||
public List<SysDictType> selectDictTypeList(SysDictType dictType) { | |||
return dictTypeMapper.selectDictTypeList(dictType); | |||
} | |||
/** | |||
* 根据所有字典类型 | |||
* | |||
* | |||
* @return 字典类型集合信息 | |||
*/ | |||
@Override | |||
public List<SysDictType> selectDictTypeAll() | |||
{ | |||
public List<SysDictType> selectDictTypeAll() { | |||
return dictTypeMapper.selectDictTypeAll(); | |||
} | |||
/** | |||
* 根据字典类型查询字典数据 | |||
* | |||
* | |||
* @param dictType 字典类型 | |||
* @return 字典数据集合信息 | |||
*/ | |||
@Override | |||
public List<SysDictData> selectDictDataByType(String dictType) | |||
{ | |||
public List<SysDictData> selectDictDataByType(String dictType) { | |||
List<SysDictData> dictDatas = DictUtils.getDictCache(dictType); | |||
if (StringUtils.isNotEmpty(dictDatas)) | |||
{ | |||
if (StringUtils.isNotEmpty(dictDatas)) { | |||
return dictDatas; | |||
} | |||
dictDatas = dictDataMapper.selectDictDataByType(dictType); | |||
if (StringUtils.isNotEmpty(dictDatas)) | |||
{ | |||
if (StringUtils.isNotEmpty(dictDatas)) { | |||
DictUtils.setDictCache(dictType, dictDatas); | |||
return dictDatas; | |||
} | |||
return null; | |||
} | |||
@Override | |||
public List<SysDictData> selectAllDictDataByType(String dictType) { | |||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType); | |||
return dictDatas; | |||
} | |||
/** | |||
* 根据字典类型ID查询信息 | |||
* | |||
* | |||
* @param dictId 字典类型ID | |||
* @return 字典类型 | |||
*/ | |||
@Override | |||
public SysDictType selectDictTypeById(Long dictId) | |||
{ | |||
public SysDictType selectDictTypeById(Long dictId) { | |||
return dictTypeMapper.selectDictTypeById(dictId); | |||
} | |||
/** | |||
* 根据字典类型查询信息 | |||
* | |||
* | |||
* @param dictType 字典类型 | |||
* @return 字典类型 | |||
*/ | |||
@Override | |||
public SysDictType selectDictTypeByType(String dictType) | |||
{ | |||
public SysDictType selectDictTypeByType(String dictType) { | |||
return dictTypeMapper.selectDictTypeByType(dictType); | |||
} | |||
/** | |||
* 批量删除字典类型信息 | |||
* | |||
* | |||
* @param dictIds 需要删除的字典ID | |||
*/ | |||
@Override | |||
public void deleteDictTypeByIds(Long[] dictIds) | |||
{ | |||
for (Long dictId : dictIds) | |||
{ | |||
public void deleteDictTypeByIds(Long[] dictIds) { | |||
for (Long dictId : dictIds) { | |||
SysDictType dictType = selectDictTypeById(dictId); | |||
if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) | |||
{ | |||
if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) { | |||
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); | |||
} | |||
dictTypeMapper.deleteDictTypeById(dictId); | |||
@@ -135,13 +130,11 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
* 加载字典缓存数据 | |||
*/ | |||
@Override | |||
public void loadingDictCache() | |||
{ | |||
public void loadingDictCache() { | |||
SysDictData dictData = new SysDictData(); | |||
dictData.setStatus("0"); | |||
Map<String, List<SysDictData>> dictDataMap = dictDataMapper.selectDictDataList(dictData).stream().collect(Collectors.groupingBy(SysDictData::getDictType)); | |||
for (Map.Entry<String, List<SysDictData>> entry : dictDataMap.entrySet()) | |||
{ | |||
for (Map.Entry<String, List<SysDictData>> entry : dictDataMap.entrySet()) { | |||
DictUtils.setDictCache(entry.getKey(), entry.getValue().stream().sorted(Comparator.comparing(SysDictData::getDictSort)).collect(Collectors.toList())); | |||
} | |||
} | |||
@@ -150,8 +143,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
* 清空字典缓存数据 | |||
*/ | |||
@Override | |||
public void clearDictCache() | |||
{ | |||
public void clearDictCache() { | |||
DictUtils.clearDictCache(); | |||
} | |||
@@ -159,24 +151,21 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
* 重置字典缓存数据 | |||
*/ | |||
@Override | |||
public void resetDictCache() | |||
{ | |||
public void resetDictCache() { | |||
clearDictCache(); | |||
loadingDictCache(); | |||
} | |||
/** | |||
* 新增保存字典类型信息 | |||
* | |||
* | |||
* @param dict 字典类型信息 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
public int insertDictType(SysDictType dict) | |||
{ | |||
public int insertDictType(SysDictType dict) { | |||
int row = dictTypeMapper.insertDictType(dict); | |||
if (row > 0) | |||
{ | |||
if (row > 0) { | |||
DictUtils.setDictCache(dict.getDictType(), null); | |||
} | |||
return row; | |||
@@ -184,19 +173,17 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
/** | |||
* 修改保存字典类型信息 | |||
* | |||
* | |||
* @param dict 字典类型信息 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
@Transactional | |||
public int updateDictType(SysDictType dict) | |||
{ | |||
public int updateDictType(SysDictType dict) { | |||
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); | |||
dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); | |||
int row = dictTypeMapper.updateDictType(dict); | |||
if (row > 0) | |||
{ | |||
if (row > 0) { | |||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); | |||
DictUtils.setDictCache(dict.getDictType(), dictDatas); | |||
} | |||
@@ -205,17 +192,15 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | |||
/** | |||
* 校验字典类型称是否唯一 | |||
* | |||
* | |||
* @param dict 字典类型 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
public boolean checkDictTypeUnique(SysDictType dict) | |||
{ | |||
public boolean checkDictTypeUnique(SysDictType dict) { | |||
Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); | |||
SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); | |||
if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) | |||
{ | |||
if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) { | |||
return UserConstants.NOT_UNIQUE; | |||
} | |||
return UserConstants.UNIQUE; | |||