使用mybatis-flex重构“字典管理”模块代码

This commit is contained in:
dataprince 2023-09-20 10:35:05 +08:00
parent 5212d4fb68
commit 7a4a0d926d
22 changed files with 509 additions and 762 deletions

View File

@ -18,12 +18,12 @@ mybatis-flex:
# NONE不做处理 WARNING打印相关警告 FAILING抛出异常和详细信息 # NONE不做处理 WARNING打印相关警告 FAILING抛出异常和详细信息
autoMappingUnknownColumnBehavior: WARNING autoMappingUnknownColumnBehavior: WARNING
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl # 关闭日志记录 org.apache.ibatis.logging.nologging.NoLoggingImpl
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
cacheEnabled: true cacheEnabled: true
useGeneratedKeys: true #useGeneratedKeys: true
defaultExecutorType: SIMPLE #defaultExecutorType: SIMPLE
# MyBatis-Flex全局配置 # MyBatis-Flex全局配置
global-config: global-config:

View File

@ -5,11 +5,13 @@ import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore; import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.security.utils.LoginHelper; import com.ruoyi.system.domain.bo.SysDictDataBo;
import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.domain.vo.SysDictDataVo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -23,9 +25,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.web.core.BaseController; import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.core.domain.AjaxResult;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService; import com.ruoyi.system.service.ISysDictTypeService;
@ -38,8 +38,7 @@ import com.ruoyi.system.service.ISysDictTypeService;
@RequiredArgsConstructor @RequiredArgsConstructor
@RestController @RestController
@RequestMapping("/system/dict/data") @RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController public class SysDictDataController extends BaseController {
{
@Resource @Resource
private ISysDictDataService dictDataService; private ISysDictDataService dictDataService;
@ -48,11 +47,8 @@ public class SysDictDataController extends BaseController
@SaCheckPermission("system:dict:list") @SaCheckPermission("system:dict:list")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysDictData dictData) public TableDataInfo<SysDictDataVo> list(SysDictDataBo dictDataBo) {
{ return dictDataService.selectPage(dictDataBo);
startPage();
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
return getDataTable(list);
} }
/** /**
@ -61,11 +57,9 @@ public class SysDictDataController extends BaseController
@SaCheckPermission("system:dict:export") @SaCheckPermission("system:dict:export")
@Log(title = "字典数据", businessType = BusinessType.EXPORT) @Log(title = "字典数据", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, SysDictData dictData) public void export(HttpServletResponse response, SysDictDataBo dictDataBo) {
{ List<SysDictDataVo> list = dictDataService.selectDictDataList(dictDataBo);
List<SysDictData> list = dictDataService.selectDictDataList(dictData); ExcelUtil.exportExcel(list, "字典数据", SysDictDataVo.class, response);
ExcelUtil<SysDictData> util = new ExcelUtil<>(SysDictData.class);
util.exportExcel(response, list, "字典数据");
} }
/** /**
@ -73,9 +67,8 @@ public class SysDictDataController extends BaseController
*/ */
@SaCheckPermission("system:dict:query") @SaCheckPermission("system:dict:query")
@GetMapping(value = "/{dictCode}") @GetMapping(value = "/{dictCode}")
public AjaxResult getInfo(@PathVariable Long dictCode) public R<SysDictDataVo> getInfo(@PathVariable Long dictCode) {
{ return R.ok(dictDataService.selectDictDataById(dictCode));
return success(dictDataService.selectDictDataById(dictCode));
} }
/** /**
@ -83,14 +76,12 @@ public class SysDictDataController extends BaseController
*/ */
@SaIgnore @SaIgnore
@GetMapping(value = "/type/{dictType}") @GetMapping(value = "/type/{dictType}")
public AjaxResult dictType(@PathVariable String dictType) public R<List<SysDictDataVo>> dictType(@PathVariable String dictType) {
{ List<SysDictDataVo> data = dictTypeService.selectDictDataByType(dictType);
List<SysDictData> data = dictTypeService.selectDictDataByType(dictType); if (StringUtils.isNull(data)) {
if (StringUtils.isNull(data))
{
data = new ArrayList<>(); data = new ArrayList<>();
} }
return success(data); return R.ok(data);
} }
/** /**
@ -99,10 +90,12 @@ public class SysDictDataController extends BaseController
@SaCheckPermission("system:dict:add") @SaCheckPermission("system:dict:add")
@Log(title = "字典数据", businessType = BusinessType.INSERT) @Log(title = "字典数据", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@Validated @RequestBody SysDictData dict) public R<Void> add(@Validated @RequestBody SysDictDataBo dictDataBo) {
{ int insertedRows = dictDataService.insertDictData(dictDataBo);
dict.setCreateBy(LoginHelper.getUserId()); if (insertedRows == 0) {
return toAjax(dictDataService.insertDictData(dict)); return R.fail("新增字典数据记录失败!");
}
return R.ok();
} }
/** /**
@ -111,10 +104,12 @@ public class SysDictDataController extends BaseController
@SaCheckPermission("system:dict:edit") @SaCheckPermission("system:dict:edit")
@Log(title = "字典数据", businessType = BusinessType.UPDATE) @Log(title = "字典数据", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@Validated @RequestBody SysDictData dict) public R<Void> edit(@Validated @RequestBody SysDictDataBo dictDataBo) {
{ boolean updated = dictDataService.updateDictData(dictDataBo);
dict.setUpdateBy(LoginHelper.getUserId()); if (!updated) {
return toAjax(dictDataService.updateDictData(dict)); return R.fail("修改字典数据记录失败!");
}
return R.ok();
} }
/** /**
@ -123,9 +118,11 @@ public class SysDictDataController extends BaseController
@SaCheckPermission("system:dict:remove") @SaCheckPermission("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.DELETE) @Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictCodes}") @DeleteMapping("/{dictCodes}")
public AjaxResult remove(@PathVariable Long[] dictCodes) public R<Void> remove(@PathVariable Long[] dictCodes) {
{ boolean deleted = dictDataService.deleteDictDataByIds(dictCodes);
dictDataService.deleteDictDataByIds(dictCodes); if (!deleted) {
return success(); return R.fail("删除字典数据记录失败!");
}
return R.ok();
} }
} }

View File

@ -3,11 +3,13 @@ package com.ruoyi.system.controller.system;
import java.util.List; import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.security.utils.LoginHelper; import com.ruoyi.system.domain.bo.SysDictTypeBo;
import com.ruoyi.system.domain.SysDictType; import com.ruoyi.system.domain.vo.SysDictTypeVo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -21,8 +23,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.web.core.BaseController; import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.core.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysDictTypeService; import com.ruoyi.system.service.ISysDictTypeService;
/** /**
@ -41,21 +41,18 @@ public class SysDictTypeController extends BaseController
@SaCheckPermission("system:dict:list") @SaCheckPermission("system:dict:list")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysDictType dictType) public TableDataInfo<SysDictTypeVo> list(SysDictTypeBo dictTypeBo)
{ {
startPage(); return dictTypeService.selectPage(dictTypeBo);
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
return getDataTable(list);
} }
@Log(title = "字典类型", businessType = BusinessType.EXPORT) @Log(title = "字典类型", businessType = BusinessType.EXPORT)
@SaCheckPermission("system:dict:export") @SaCheckPermission("system:dict:export")
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, SysDictType dictType) public void export(HttpServletResponse response, SysDictTypeBo dictTypeBo)
{ {
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType); List<SysDictTypeVo> list = dictTypeService.selectDictTypeList(dictTypeBo);
ExcelUtil<SysDictType> util = new ExcelUtil<>(SysDictType.class); ExcelUtil.exportExcel(list, "数据字典类型信息数据", SysDictTypeVo.class, response);
util.exportExcel(response, list, "字典类型");
} }
/** /**
@ -63,9 +60,9 @@ public class SysDictTypeController extends BaseController
*/ */
@SaCheckPermission("system:dict:query") @SaCheckPermission("system:dict:query")
@GetMapping(value = "/{dictId}") @GetMapping(value = "/{dictId}")
public AjaxResult getInfo(@PathVariable Long dictId) public R<SysDictTypeVo> getInfo(@PathVariable Long dictId)
{ {
return success(dictTypeService.selectDictTypeById(dictId)); return R.ok(dictTypeService.selectDictTypeById(dictId));
} }
/** /**
@ -74,14 +71,14 @@ public class SysDictTypeController extends BaseController
@SaCheckPermission("system:dict:add") @SaCheckPermission("system:dict:add")
@Log(title = "字典类型", businessType = BusinessType.INSERT) @Log(title = "字典类型", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@Validated @RequestBody SysDictType dict) public R<Void> add(@Validated @RequestBody SysDictTypeBo dictTypeBo)
{ {
if (!dictTypeService.checkDictTypeUnique(dict)) if (!dictTypeService.checkDictTypeUnique(dictTypeBo))
{ {
return error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在"); return R.fail("新增字典'" + dictTypeBo.getDictName() + "'失败,字典类型已存在");
} }
dict.setCreateBy(LoginHelper.getUserId()); dictTypeService.insertDictType(dictTypeBo);
return toAjax(dictTypeService.insertDictType(dict)); return R.ok();
} }
/** /**
@ -90,14 +87,14 @@ public class SysDictTypeController extends BaseController
@SaCheckPermission("system:dict:edit") @SaCheckPermission("system:dict:edit")
@Log(title = "字典类型", businessType = BusinessType.UPDATE) @Log(title = "字典类型", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@Validated @RequestBody SysDictType dict) public R<Void> edit(@Validated @RequestBody SysDictTypeBo dictTypeBo)
{ {
if (!dictTypeService.checkDictTypeUnique(dict)) if (!dictTypeService.checkDictTypeUnique(dictTypeBo))
{ {
return error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在"); return R.fail("修改字典'" + dictTypeBo.getDictName() + "'失败,字典类型已存在");
} }
dict.setUpdateBy(LoginHelper.getUserId()); dictTypeService.updateDictType(dictTypeBo);
return toAjax(dictTypeService.updateDictType(dict)); return R.ok();
} }
/** /**
@ -106,10 +103,13 @@ public class SysDictTypeController extends BaseController
@SaCheckPermission("system:dict:remove") @SaCheckPermission("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.DELETE) @Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictIds}") @DeleteMapping("/{dictIds}")
public AjaxResult remove(@PathVariable Long[] dictIds) public R<Void> remove(@PathVariable Long[] dictIds)
{ {
dictTypeService.deleteDictTypeByIds(dictIds); boolean deleted = dictTypeService.deleteDictTypeByIds(dictIds);
return success(); if (!deleted) {
R.fail("删除字典类型记录失败!");
}
return R.ok();
} }
/** /**
@ -118,19 +118,19 @@ public class SysDictTypeController extends BaseController
@SaCheckPermission("system:dict:remove") @SaCheckPermission("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.CLEAN) @Log(title = "字典类型", businessType = BusinessType.CLEAN)
@DeleteMapping("/refreshCache") @DeleteMapping("/refreshCache")
public AjaxResult refreshCache() public R<Void> refreshCache()
{ {
dictTypeService.resetDictCache(); dictTypeService.resetDictCache();
return success(); return R.ok();
} }
/** /**
* 获取字典选择框列表 * 获取字典选择框列表
*/ */
@GetMapping("/optionselect") @GetMapping("/optionselect")
public AjaxResult optionselect() public R<List<SysDictTypeVo>> optionselect()
{ {
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll(); List<SysDictTypeVo> dictTypes = dictTypeService.selectDictTypeAll();
return success(dictTypes); return R.ok(dictTypes);
} }
} }

View File

@ -42,7 +42,7 @@ public class SysNoticeController extends BaseController
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo<SysNoticeVo> list(SysNoticeBo noticeBo) public TableDataInfo<SysNoticeVo> list(SysNoticeBo noticeBo)
{ {
return noticeService.selectConfigPage(noticeBo); return noticeService.selectPage(noticeBo);
} }
/** /**

View File

@ -47,7 +47,7 @@ public class SysPostController extends BaseController
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo<SysPostVo> list(SysPostBo postBo) public TableDataInfo<SysPostVo> list(SysPostBo postBo)
{ {
return postService.selectConfigPage(postBo); return postService.selectPage(postBo);
} }
@Log(title = "岗位管理", businessType = BusinessType.EXPORT) @Log(title = "岗位管理", businessType = BusinessType.EXPORT)

View File

@ -1,44 +1,37 @@
package com.ruoyi.system.domain; package com.ruoyi.system.domain;
import jakarta.validation.constraints.NotBlank; import com.mybatisflex.annotation.Id;
import jakarta.validation.constraints.Size; import com.mybatisflex.annotation.KeyType;
import org.apache.commons.lang3.builder.ToStringBuilder; import com.mybatisflex.annotation.Table;
import org.apache.commons.lang3.builder.ToStringStyle; import lombok.Data;
import com.ruoyi.common.core.annotation.Excel; import lombok.EqualsAndHashCode;
import com.ruoyi.common.core.annotation.Excel.ColumnType;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.orm.core.domain.BaseEntity;
import java.io.Serial;
/** /**
* 字典数据表 sys_dict_data * 字典数据表 sys_dict_data
* *
* @author ruoyi * @author ruoyi
*/ */
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "sys_dict_data")
public class SysDictData extends BaseEntity public class SysDictData extends BaseEntity
{ {
@Serial
private static final long serialVersionUID = 1L;
/** 字典编码 */ /** 字典编码 */
@Excel(name = "字典编码", cellType = ColumnType.NUMERIC) @Id(keyType = KeyType.Auto)
private Long dictCode; private Long dictCode;
/** 字典排序 */ /** 字典排序 */
@Excel(name = "字典排序", cellType = ColumnType.NUMERIC)
private Long dictSort; private Long dictSort;
/** 字典标签 */ /** 字典标签 */
@Excel(name = "字典标签")
private String dictLabel; private String dictLabel;
/** 字典键值 */ /** 字典键值 */
@Excel(name = "字典键值")
private String dictValue; private String dictValue;
/** 字典类型 */ /** 字典类型 */
@Excel(name = "字典类型")
private String dictType; private String dictType;
/** 样式属性(其他样式扩展) */ /** 样式属性(其他样式扩展) */
@ -48,130 +41,12 @@ public class SysDictData extends BaseEntity
private String listClass; private String listClass;
/** 是否默认Y是 N否 */ /** 是否默认Y是 N否 */
@Excel(name = "是否默认", readConverterExp = "Y=是,N=否")
private String isDefault; private String isDefault;
/** /** 备注 */
* 备注
*/
private String remark; private String remark;
public Long getDictCode() public boolean getDefault() {
{ return UserConstants.YES.equals(this.isDefault);
return dictCode;
}
public void setDictCode(Long dictCode)
{
this.dictCode = dictCode;
}
public Long getDictSort()
{
return dictSort;
}
public void setDictSort(Long dictSort)
{
this.dictSort = dictSort;
}
@NotBlank(message = "字典标签不能为空")
@Size(min = 0, max = 100, message = "字典标签长度不能超过100个字符")
public String getDictLabel()
{
return dictLabel;
}
public void setDictLabel(String dictLabel)
{
this.dictLabel = dictLabel;
}
@NotBlank(message = "字典键值不能为空")
@Size(min = 0, max = 100, message = "字典键值长度不能超过100个字符")
public String getDictValue()
{
return dictValue;
}
public void setDictValue(String dictValue)
{
this.dictValue = dictValue;
}
@NotBlank(message = "字典类型不能为空")
@Size(min = 0, max = 100, message = "字典类型长度不能超过100个字符")
public String getDictType()
{
return dictType;
}
public void setDictType(String dictType)
{
this.dictType = dictType;
}
@Size(min = 0, max = 100, message = "样式属性长度不能超过100个字符")
public String getCssClass()
{
return cssClass;
}
public void setCssClass(String cssClass)
{
this.cssClass = cssClass;
}
public String getListClass()
{
return listClass;
}
public void setListClass(String listClass)
{
this.listClass = listClass;
}
public boolean getDefault()
{
return UserConstants.YES.equals(this.isDefault) ? true : false;
}
public String getIsDefault()
{
return isDefault;
}
public void setIsDefault(String isDefault)
{
this.isDefault = isDefault;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("dictCode", getDictCode())
.append("dictSort", getDictSort())
.append("dictLabel", getDictLabel())
.append("dictValue", getDictValue())
.append("dictType", getDictType())
.append("cssClass", getCssClass())
.append("listClass", getListClass())
.append("isDefault", getIsDefault())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
} }
} }

View File

@ -1,95 +1,32 @@
package com.ruoyi.system.domain; package com.ruoyi.system.domain;
import jakarta.validation.constraints.NotBlank; import com.mybatisflex.annotation.Id;
import jakarta.validation.constraints.Size; import com.mybatisflex.annotation.KeyType;
import org.apache.commons.lang3.builder.ToStringBuilder; import com.mybatisflex.annotation.Table;
import org.apache.commons.lang3.builder.ToStringStyle; import lombok.Data;
import com.ruoyi.common.core.annotation.Excel; import lombok.EqualsAndHashCode;
import com.ruoyi.common.core.annotation.Excel.ColumnType;
import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.orm.core.domain.BaseEntity;
import java.io.Serial;
/** /**
* 字典类型表 sys_dict_type * 字典类型表 sys_dict_type
* *
* @author ruoyi * @author ruoyi
*/ */
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "sys_dict_type")
public class SysDictType extends BaseEntity public class SysDictType extends BaseEntity
{ {
@Serial
private static final long serialVersionUID = 1L;
/** 字典主键 */ /** 字典主键 */
@Excel(name = "字典主键", cellType = ColumnType.NUMERIC) @Id(keyType = KeyType.Auto)
private Long dictId; private Long dictId;
/** 字典名称 */ /** 字典名称 */
@Excel(name = "字典名称")
private String dictName; private String dictName;
/** 字典类型 */ /** 字典类型 */
@Excel(name = "字典类型")
private String dictType; private String dictType;
/** /** 备注 */
* 备注
*/
private String remark; private String remark;
public Long getDictId()
{
return dictId;
}
public void setDictId(Long dictId)
{
this.dictId = dictId;
}
@NotBlank(message = "字典名称不能为空")
@Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符")
public String getDictName()
{
return dictName;
}
public void setDictName(String dictName)
{
this.dictName = dictName;
}
@NotBlank(message = "字典类型不能为空")
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符")
public String getDictType()
{
return dictType;
}
public void setDictType(String dictType)
{
this.dictType = dictType;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("dictId", getDictId())
.append("dictName", getDictName())
.append("dictType", getDictType())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
} }

View File

@ -20,7 +20,6 @@ import java.util.Date;
*/ */
@Data @Data
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
@AutoMapper(target = SysDictData.class)
public class SysDictDataVo implements Serializable { public class SysDictDataVo implements Serializable {
@Serial @Serial

View File

@ -2,10 +2,6 @@ package com.ruoyi.system.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.common.excel.annotation.ExcelDictFormat;
import com.ruoyi.common.excel.convert.ExcelDictConvert;
import com.ruoyi.system.domain.SysDictType;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data; import lombok.Data;
import java.io.Serial; import java.io.Serial;
@ -20,7 +16,6 @@ import java.util.Date;
*/ */
@Data @Data
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
@AutoMapper(target = SysDictType.class)
public class SysDictTypeVo implements Serializable { public class SysDictTypeVo implements Serializable {
@Serial @Serial

View File

@ -2,7 +2,9 @@ package com.ruoyi.system.mapper;
import java.util.List; import java.util.List;
import com.mybatisflex.core.BaseMapper;
import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.domain.SysDictData;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
/** /**
@ -10,87 +12,8 @@ import org.apache.ibatis.annotations.Param;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface SysDictDataMapper @Mapper
public interface SysDictDataMapper extends BaseMapper<SysDictData>
{ {
/**
* 根据条件分页查询字典数据
*
* @param dictData 字典数据信息
* @return 字典数据集合信息
*/
List<SysDictData> selectDictDataList(SysDictData dictData);
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
List<SysDictData> selectDictDataByType(String dictType);
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue);
/**
* 根据字典数据ID查询信息
*
* @param dictCode 字典数据ID
* @return 字典数据
*/
SysDictData selectDictDataById(Long dictCode);
/**
* 查询字典数据
*
* @param dictType 字典类型
* @return 字典数据
*/
int countDictDataByType(String dictType);
/**
* 通过字典ID删除字典数据信息
*
* @param dictCode 字典数据ID
* @return 结果
*/
int deleteDictDataById(Long dictCode);
/**
* 批量删除字典数据信息
*
* @param dictCodes 需要删除的字典数据ID
* @return 结果
*/
int deleteDictDataByIds(Long[] dictCodes);
/**
* 新增字典数据信息
*
* @param dictData 字典数据信息
* @return 结果
*/
int insertDictData(SysDictData dictData);
/**
* 修改字典数据信息
*
* @param dictData 字典数据信息
* @return 结果
*/
int updateDictData(SysDictData dictData);
/**
* 同步修改字典类型
*
* @param oldDictType 旧字典类型
* @param newDictType 新旧字典类型
* @return 结果
*/
int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType);
} }

View File

@ -1,84 +1,86 @@
package com.ruoyi.system.mapper; package com.ruoyi.system.mapper;
import com.mybatisflex.core.BaseMapper;
import com.ruoyi.system.domain.SysDictType; import com.ruoyi.system.domain.SysDictType;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* 字典表 数据层 * 字典表 数据层
* *
* @author ruoyi * @author ruoyi
*/ */
public interface SysDictTypeMapper @Mapper
public interface SysDictTypeMapper extends BaseMapper<SysDictType>
{ {
/** // /**
* 根据条件分页查询字典类型 // * 根据条件分页查询字典类型
* // *
* @param dictType 字典类型信息 // * @param dictType 字典类型信息
* @return 字典类型集合信息 // * @return 字典类型集合信息
*/ // */
List<SysDictType> selectDictTypeList(SysDictType dictType); // List<SysDictType> selectDictTypeList(SysDictType dictType);
//
/** // /**
* 根据所有字典类型 // * 根据所有字典类型
* // *
* @return 字典类型集合信息 // * @return 字典类型集合信息
*/ // */
List<SysDictType> selectDictTypeAll(); // List<SysDictType> selectDictTypeAll();
//
/** // /**
* 根据字典类型ID查询信息 // * 根据字典类型ID查询信息
* // *
* @param dictId 字典类型ID // * @param dictId 字典类型ID
* @return 字典类型 // * @return 字典类型
*/ // */
SysDictType selectDictTypeById(Long dictId); // SysDictType selectDictTypeById(Long dictId);
//
/** // /**
* 根据字典类型查询信息 // * 根据字典类型查询信息
* // *
* @param dictType 字典类型 // * @param dictType 字典类型
* @return 字典类型 // * @return 字典类型
*/ // */
SysDictType selectDictTypeByType(String dictType); // SysDictType selectDictTypeByType(String dictType);
//
/** // /**
* 通过字典ID删除字典信息 // * 通过字典ID删除字典信息
* // *
* @param dictId 字典ID // * @param dictId 字典ID
* @return 结果 // * @return 结果
*/ // */
int deleteDictTypeById(Long dictId); // int deleteDictTypeById(Long dictId);
//
/** // /**
* 批量删除字典类型信息 // * 批量删除字典类型信息
* // *
* @param dictIds 需要删除的字典ID // * @param dictIds 需要删除的字典ID
* @return 结果 // * @return 结果
*/ // */
int deleteDictTypeByIds(Long[] dictIds); // int deleteDictTypeByIds(Long[] dictIds);
//
/** // /**
* 新增字典类型信息 // * 新增字典类型信息
* // *
* @param dictType 字典类型信息 // * @param dictType 字典类型信息
* @return 结果 // * @return 结果
*/ // */
int insertDictType(SysDictType dictType); // int insertDictType(SysDictType dictType);
//
/** // /**
* 修改字典类型信息 // * 修改字典类型信息
* // *
* @param dictType 字典类型信息 // * @param dictType 字典类型信息
* @return 结果 // * @return 结果
*/ // */
int updateDictType(SysDictType dictType); // int updateDictType(SysDictType dictType);
//
/** // /**
* 校验字典类型称是否唯一 // * 校验字典类型称是否唯一
* // *
* @param dictType 字典类型 // * @param dictType 字典类型
* @return 结果 // * @return 结果
*/ // */
SysDictType checkDictTypeUnique(String dictType); // SysDictType checkDictTypeUnique(String dictType);
} }

View File

@ -1,6 +1,10 @@
package com.ruoyi.system.service; package com.ruoyi.system.service;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.IBaseService;
import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.bo.SysDictDataBo;
import com.ruoyi.system.domain.vo.SysDictDataVo;
import java.util.List; import java.util.List;
@ -9,15 +13,23 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface ISysDictDataService public interface ISysDictDataService extends IBaseService<SysDictData>
{ {
/** /**
* 根据条件分页查询字典数据 * 根据条件分页查询字典数据
* *
* @param dictData 字典数据信息 * @param dictDataBo 字典数据信息
* @return 字典数据集合信息 * @return 字典数据集合信息
*/ */
List<SysDictData> selectDictDataList(SysDictData dictData); List<SysDictDataVo> selectDictDataList(SysDictDataBo dictDataBo);
/**
* 分页查询字典数据
*
* @param dictDataBo 字典类型信息
* @return 字典数据集合信息
*/
TableDataInfo<SysDictDataVo> selectPage(SysDictDataBo dictDataBo);
/** /**
* 根据字典类型和字典键值查询字典数据信息 * 根据字典类型和字典键值查询字典数据信息
@ -34,28 +46,55 @@ public interface ISysDictDataService
* @param dictCode 字典数据ID * @param dictCode 字典数据ID
* @return 字典数据 * @return 字典数据
*/ */
SysDictData selectDictDataById(Long dictCode); SysDictDataVo selectDictDataById(Long dictCode);
/**
* 查询字典数据记录数量
*
* @param dictType 字典类型
* @return 字典数据
*/
Integer countDictDataByType(String dictType);
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
List<SysDictDataVo> selectDictDataByType(String dictType);
/** /**
* 批量删除字典数据信息 * 批量删除字典数据信息
* *
* @param dictCodes 需要删除的字典数据ID * @param dictCodes 需要删除的字典数据ID
* @return 结果:true 删除成功false 删除失败
*/ */
void deleteDictDataByIds(Long[] dictCodes); boolean deleteDictDataByIds(Long[] dictCodes);
/** /**
* 新增保存字典数据信息 * 新增保存字典数据信息
* *
* @param dictData 字典数据信息 * @param dataBo 字典数据信息
* @return 结果 * @return 结果:受影响的行数
*/ */
int insertDictData(SysDictData dictData); int insertDictData(SysDictDataBo dataBo);
/** /**
* 修改保存字典数据信息 * 修改保存字典数据信息
* *
* @param dictData 字典数据信息 * @param dataBo 字典数据信息
* @return 结果:true 更新成功false 更新失败
*/
boolean updateDictData(SysDictDataBo dataBo);
/**
* 同步修改字典类型
*
* @param oldDictType 旧字典类型
* @param newDictType 新旧字典类型
* @return 结果 * @return 结果
*/ */
int updateDictData(SysDictData dictData); boolean updateDictDataType(String oldDictType, String newDictType);
} }

View File

@ -1,7 +1,12 @@
package com.ruoyi.system.service; package com.ruoyi.system.service;
import com.mybatisflex.core.service.IService;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.SysDictType; import com.ruoyi.system.domain.SysDictType;
import com.ruoyi.system.domain.bo.SysDictTypeBo;
import com.ruoyi.system.domain.vo.SysDictDataVo;
import com.ruoyi.system.domain.vo.SysDictTypeVo;
import java.util.List; import java.util.List;
@ -10,7 +15,7 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface ISysDictTypeService public interface ISysDictTypeService extends IService<SysDictType>
{ {
/** /**
* 根据条件分页查询字典类型 * 根据条件分页查询字典类型
@ -18,14 +23,22 @@ public interface ISysDictTypeService
* @param dictType 字典类型信息 * @param dictType 字典类型信息
* @return 字典类型集合信息 * @return 字典类型集合信息
*/ */
List<SysDictType> selectDictTypeList(SysDictType dictType); List<SysDictTypeVo> selectDictTypeList(SysDictTypeBo dictType);
/**
* 分页查询公告列表
*
* @param dictTypeBo 字典类型信息
* @return 分页字典类型集合信息
*/
TableDataInfo<SysDictTypeVo> selectPage(SysDictTypeBo dictTypeBo);
/** /**
* 根据所有字典类型 * 根据所有字典类型
* *
* @return 字典类型集合信息 * @return 字典类型集合信息
*/ */
List<SysDictType> selectDictTypeAll(); List<SysDictTypeVo> selectDictTypeAll();
/** /**
* 根据字典类型查询字典数据 * 根据字典类型查询字典数据
@ -33,7 +46,7 @@ public interface ISysDictTypeService
* @param dictType 字典类型 * @param dictType 字典类型
* @return 字典数据集合信息 * @return 字典数据集合信息
*/ */
List<SysDictData> selectDictDataByType(String dictType); List<SysDictDataVo> selectDictDataByType(String dictType);
/** /**
* 根据字典类型ID查询信息 * 根据字典类型ID查询信息
@ -41,7 +54,7 @@ public interface ISysDictTypeService
* @param dictId 字典类型ID * @param dictId 字典类型ID
* @return 字典类型 * @return 字典类型
*/ */
SysDictType selectDictTypeById(Long dictId); SysDictTypeVo selectDictTypeById(Long dictId);
/** /**
* 根据字典类型查询信息 * 根据字典类型查询信息
@ -49,14 +62,15 @@ public interface ISysDictTypeService
* @param dictType 字典类型 * @param dictType 字典类型
* @return 字典类型 * @return 字典类型
*/ */
SysDictType selectDictTypeByType(String dictType); SysDictTypeVo selectDictTypeByType(String dictType);
/** /**
* 批量删除字典信息 * 批量删除字典信息
* *
* @param dictIds 需要删除的字典ID * @param dictIds 需要删除的字典ID
* @return true 删除成功false 删除失败
*/ */
void deleteDictTypeByIds(Long[] dictIds); boolean deleteDictTypeByIds(Long[] dictIds);
/** /**
* 加载字典缓存数据 * 加载字典缓存数据
@ -76,26 +90,26 @@ public interface ISysDictTypeService
/** /**
* 新增保存字典类型信息 * 新增保存字典类型信息
* *
* @param dictType 字典类型信息 * @param sysDictTypeBo 字典类型信息
* @return 结果 * @return 结果
*/ */
int insertDictType(SysDictType dictType); List<SysDictDataVo> insertDictType(SysDictTypeBo sysDictTypeBo);
/** /**
* 修改保存字典类型信息 * 修改保存字典类型信息
* *
* @param dictType 字典类型信息 * @param dictTypeBo 字典类型信息
* @return 结果 * @return 结果
*/ */
int updateDictType(SysDictType dictType); public List<SysDictDataVo> updateDictType(SysDictTypeBo dictTypeBo);
/** /**
* 校验字典类型称是否唯一 * 校验字典类型称是否唯一
* *
* @param dictType 字典类型 * @param dictTypeBo 字典类型
* @return 结果 * @return 结果
*/ */
boolean checkDictTypeUnique(SysDictType dictType); boolean checkDictTypeUnique(SysDictTypeBo dictTypeBo);
} }

View File

@ -37,7 +37,7 @@ public interface ISysNoticeService extends IService<SysNotice>
* @param noticeBo 公告信息 * @param noticeBo 公告信息
* @return 公告集合 * @return 公告集合
*/ */
TableDataInfo<SysNoticeVo> selectConfigPage(SysNoticeBo noticeBo); TableDataInfo<SysNoticeVo> selectPage(SysNoticeBo noticeBo);
/** /**
* 新增公告 * 新增公告

View File

@ -29,7 +29,7 @@ public interface ISysPostService extends IService<SysPost>
* @param postBo 公告信息 * @param postBo 公告信息
* @return 公告集合 * @return 公告集合
*/ */
TableDataInfo<SysPostVo> selectConfigPage(SysPostBo postBo); TableDataInfo<SysPostVo> selectPage(SysPostBo postBo);
/** /**
* 查询所有岗位 * 查询所有岗位

View File

@ -4,21 +4,20 @@ import java.util.List;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.CacheNames; import com.ruoyi.common.core.constant.CacheNames;
import com.ruoyi.common.core.core.page.PageDomain; import com.ruoyi.common.core.core.page.PageDomain;
import com.ruoyi.common.core.core.page.TableSupport; import com.ruoyi.common.core.core.page.TableSupport;
import com.ruoyi.common.core.service.ConfigService; import com.ruoyi.common.core.service.ConfigService;
import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.utils.sql.SqlUtil;
import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.redis.utils.CacheUtils; import com.ruoyi.common.redis.utils.CacheUtils;
import com.ruoyi.system.domain.bo.SysConfigBo; import com.ruoyi.system.domain.bo.SysConfigBo;
import com.ruoyi.system.domain.vo.SysConfigVo; import com.ruoyi.system.domain.vo.SysConfigVo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
@ -39,7 +38,7 @@ import static com.ruoyi.system.domain.table.SysConfigTableDef.SYS_CONFIG;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService, ConfigService { public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService, ConfigService {
@Resource @Resource
private SysConfigMapper configMapper; private SysConfigMapper configMapper;
@ -92,12 +91,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
/** /**
* 构造查询条件 * 构造查询条件
* @param config * @param config
* @return * @return 查询条件
*/ */
private QueryWrapper buildQueryWrapper(SysConfigBo config) { private QueryWrapper buildQueryWrapper(SysConfigBo config) {
QueryWrapper queryWrapper = query(); QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
PageDomain pageDomain = TableSupport.buildPageRequest();
if (StringUtils.isNotEmpty(config.getConfigName())) { if (StringUtils.isNotEmpty(config.getConfigName())) {
queryWrapper.and(SYS_CONFIG.CONFIG_NAME.like(config.getConfigName())); queryWrapper.and(SYS_CONFIG.CONFIG_NAME.like(config.getConfigName()));
@ -116,11 +114,6 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
queryWrapper.and(SYS_CONFIG.CREATE_TIME.le(config.getParams().get("endTime"))); queryWrapper.and(SYS_CONFIG.CREATE_TIME.le(config.getParams().get("endTime")));
} }
if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) {
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
queryWrapper.orderBy(orderBy);
}
return queryWrapper; return queryWrapper;
} }
@ -141,7 +134,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
* 分页查询参数配置 * 分页查询参数配置
* *
* @param config 参数配置信息 * @param config 参数配置信息
* @return * @return 分页数据
*/ */
@Override @Override
public TableDataInfo<SysConfigVo> selectConfigPage(SysConfigBo config) { public TableDataInfo<SysConfigVo> selectConfigPage(SysConfigBo config) {
@ -159,7 +152,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
* @param configBo 参数配置信息 * @param configBo 参数配置信息
* @return 插入行数 * @return 插入行数
*/ */
@CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#configBo.configKey") @CacheEvict(cacheNames = CacheNames.SYS_CONFIG, key = "#configBo.configKey")
@Override @Override
public int insertConfig(SysConfigBo configBo) { public int insertConfig(SysConfigBo configBo) {
SysConfig sysConfig = MapstructUtils.convert(configBo, SysConfig.class); SysConfig sysConfig = MapstructUtils.convert(configBo, SysConfig.class);
@ -177,15 +170,10 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
* @param configBo 参数配置信息 * @param configBo 参数配置信息
* @return true 更新成功false 更新失败 * @return true 更新成功false 更新失败
*/ */
@CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#configBo.configKey") @CacheEvict(cacheNames = CacheNames.SYS_CONFIG, key = "#configBo.configKey")
@Override @Override
public boolean updateConfig(SysConfigBo configBo) { public boolean updateConfig(SysConfigBo configBo) {
SysConfig config = MapstructUtils.convert(configBo, SysConfig.class); SysConfig config = MapstructUtils.convert(configBo, SysConfig.class);
SysConfig temp = this.getById(config.getConfigId());
if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
CacheUtils.evict(CacheNames.SYS_CONFIG, temp.getConfigKey());
}
return this.updateById(config); return this.updateById(config);
} }

View File

@ -1,16 +1,32 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import java.util.Arrays;
import java.util.List; import java.util.List;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.ruoyi.common.core.constant.CacheNames; import com.ruoyi.common.core.constant.CacheNames;
import com.ruoyi.common.core.core.page.PageDomain;
import com.ruoyi.common.core.core.page.TableSupport;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.redis.utils.CacheUtils; import com.ruoyi.common.redis.utils.CacheUtils;
import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.bo.SysDictDataBo;
import com.ruoyi.system.domain.vo.SysDictDataVo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysDictDataMapper; import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.cache.annotation.CachePut;
import static com.ruoyi.system.domain.table.SysDictDataTableDef.SYS_DICT_DATA;
/** /**
* 字典 业务层处理 * 字典 业务层处理
@ -19,21 +35,61 @@ import org.springframework.cache.annotation.CachePut;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
public class SysDictDataServiceImpl implements ISysDictDataService public class SysDictDataServiceImpl extends BaseServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService
{ {
@Resource @Resource
private SysDictDataMapper dictDataMapper; private SysDictDataMapper dictDataMapper;
@Override
public QueryWrapper query() {
return super.query().from(SYS_DICT_DATA);
}
/** /**
* 根据条件分页查询字典数据 * 构造查询条件
* @param dictDataBo
* @return QueryWrapper
*/
private QueryWrapper buildQueryWrapper(SysDictDataBo dictDataBo) {
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
if (StringUtils.isNotEmpty(dictDataBo.getDictType())) {
queryWrapper.and(SYS_DICT_DATA.DICT_TYPE.eq(dictDataBo.getDictType()));
}
if (StringUtils.isNotEmpty(dictDataBo.getDictLabel())) {
queryWrapper.and(SYS_DICT_DATA.DICT_LABEL.eq(dictDataBo.getDictLabel()));
}
queryWrapper.orderBy(SYS_DICT_DATA.DICT_SORT.asc());
return queryWrapper;
}
/**
* 根据条件查询字典数据
* *
* @param dictData 字典数据信息 * @param dictDataBo 字典数据信息
* @return 字典数据集合信息 * @return 字典数据集合信息
*/ */
@Override @Override
public List<SysDictData> selectDictDataList(SysDictData dictData) public List<SysDictDataVo> selectDictDataList(SysDictDataBo dictDataBo)
{ {
return dictDataMapper.selectDictDataList(dictData); QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo);
return this.listAs(queryWrapper, SysDictDataVo.class);
}
/**
* 分页查询字典数据
*
* @param dictDataBo 字典类型信息
* @return 字典数据集合信息
*/
@Override
public TableDataInfo<SysDictDataVo> selectPage(SysDictDataBo dictDataBo) {
QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo);
PageDomain pageDomain = TableSupport.buildPageRequest();
Page<SysDictDataVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysDictDataVo.class);
return TableDataInfo.build(page);
} }
/** /**
@ -46,7 +102,13 @@ public class SysDictDataServiceImpl implements ISysDictDataService
@Override @Override
public String selectDictLabel(String dictType, String dictValue) public String selectDictLabel(String dictType, String dictValue)
{ {
return dictDataMapper.selectDictLabel(dictType, dictValue); QueryWrapper queryWrapper = QueryWrapper.create()
.select(SYS_DICT_DATA.DICT_LABEL)
.from(SYS_DICT_DATA)
.where(SYS_DICT_DATA.DICT_TYPE.eq(dictType))
.and(SYS_DICT_DATA.DICT_VALUE.eq(dictValue));
return dictDataMapper.selectObjectByQueryAs(queryWrapper,String.class);
} }
/** /**
@ -56,64 +118,91 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* @return 字典数据 * @return 字典数据
*/ */
@Override @Override
public SysDictData selectDictDataById(Long dictCode) public SysDictDataVo selectDictDataById(Long dictCode)
{ {
return dictDataMapper.selectDictDataById(dictCode); return this.getOneAs(query().where(SYS_DICT_DATA.DICT_CODE.eq(dictCode)),SysDictDataVo.class);
}
/**
* 查询字典数据记录数量
*
* @param dictType 字典类型
* @return 字典数据
*/
@Override
public Integer countDictDataByType(String dictType) {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(QueryMethods.count(SYS_DICT_DATA.DICT_CODE))
.from(SYS_DICT_DATA)
.where(SYS_DICT_DATA.DICT_TYPE.eq(dictType));
return dictDataMapper.selectObjectByQueryAs(queryWrapper,Integer.class);
}
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
@Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType")
@Override
public List<SysDictDataVo> selectDictDataByType(String dictType){
QueryWrapper queryWrapper=query().and(SYS_DICT_DATA.DICT_TYPE.eq(dictType)).orderBy(SYS_DICT_DATA.DICT_CODE.desc());
return this.listAs(queryWrapper, SysDictDataVo.class);
} }
/** /**
* 批量删除字典数据信息 * 批量删除字典数据信息
* *
* @param dictCodes 需要删除的字典数据ID * @param dictCodes 需要删除的字典数据ID
* @return 结果:true 删除成功false 删除失败
*/ */
@Override @Override
public void deleteDictDataByIds(Long[] dictCodes) public boolean deleteDictDataByIds(Long[] dictCodes)
{ {
for (Long dictCode : dictCodes) for (Long dictCode : dictCodes)
{ {
SysDictData data = selectDictDataById(dictCode); SysDictDataVo data = selectDictDataById(dictCode);
dictDataMapper.deleteDictDataById(dictCode);
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
//DictUtils.setDictCache(data.getDictType(), dictDatas);
CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType()); CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType());
} }
return this.removeByIds(Arrays.asList(dictCodes));
} }
/** /**
* 新增保存字典数据信息 * 新增保存字典数据信息
* *
* @param data 字典数据信息 * @param dataBo 字典数据信息
* @return 结果 * @return 结果:受影响的行数
*/ */
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") @CacheEvict(cacheNames = CacheNames.SYS_DICT, key = "#dataBo.dictType")
@Override @Override
public int insertDictData(SysDictData data) public int insertDictData(SysDictDataBo dataBo)
{ {
int row = dictDataMapper.insertDictData(data); SysDictData data = MapstructUtils.convert(dataBo, SysDictData.class);
if (row > 0) return dictDataMapper.insert(data,false);
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
//DictUtils.setDictCache(data.getDictType(), dictDatas);
}
return row;
} }
/** /**
* 修改保存字典数据信息 * 修改保存字典数据信息
* *
* @param data 字典数据信息 * @param dataBo 字典数据信息
* @return 结果 * @return 结果:true 更新成功false 更新失败
*/ */
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") @CacheEvict(cacheNames = CacheNames.SYS_DICT, key = "#dataBo.dictType")
@Override @Override
public int updateDictData(SysDictData data) public boolean updateDictData(SysDictDataBo dataBo)
{ {
int row = dictDataMapper.updateDictData(data); SysDictData data = MapstructUtils.convert(dataBo, SysDictData.class);
if (row > 0) return this.updateById(data);
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
//DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row;
@Override
public boolean updateDictDataType(String oldDictType, String newDictType){
return UpdateChain.of(SysDictData.class)
.set(SysDictData::getDictType, newDictType)
.where(SysDictData::getDictType).eq(oldDictType)
.update();
} }
} }

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -7,14 +8,24 @@ import java.util.stream.Collectors;
import cn.dev33.satoken.context.SaHolder; import cn.dev33.satoken.context.SaHolder;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.CacheNames; import com.ruoyi.common.core.constant.CacheNames;
import com.ruoyi.common.core.core.page.PageDomain;
import com.ruoyi.common.core.core.page.TableSupport;
import com.ruoyi.common.core.service.DictService; import com.ruoyi.common.core.service.DictService;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.utils.StreamUtils; import com.ruoyi.common.core.utils.StreamUtils;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.redis.utils.CacheUtils; import com.ruoyi.common.redis.utils.CacheUtils;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.SysDictType; import com.ruoyi.system.domain.SysDictType;
import com.ruoyi.system.domain.bo.SysDictTypeBo;
import com.ruoyi.system.domain.vo.SysDictDataVo;
import com.ruoyi.system.domain.vo.SysDictTypeVo;
import com.ruoyi.system.service.ISysDictDataService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
@ -23,43 +34,82 @@ import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysDictTypeMapper; import com.ruoyi.system.mapper.SysDictTypeMapper;
import com.ruoyi.system.service.ISysDictTypeService; import com.ruoyi.system.service.ISysDictTypeService;
import static com.ruoyi.system.domain.table.SysDictTypeTableDef.SYS_DICT_TYPE;
/** /**
* 字典 业务层处理 * 字典 业务层处理
* *
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService, DictService
{ {
@Resource @Resource
private SysDictTypeMapper dictTypeMapper; private SysDictTypeMapper dictTypeMapper;
@Resource @Resource
private SysDictDataMapper dictDataMapper; private ISysDictDataService sysDictDataService;
@Override
public QueryWrapper query() {
return super.query().from(SYS_DICT_TYPE);
}
/** /**
* 项目启动时初始化字典到缓存 * 构造查询条件
* @param dictTypeBo
* @return QueryWrapper
*/ */
// @PostConstruct
// public void init() private QueryWrapper buildQueryWrapper(SysDictTypeBo dictTypeBo){
// { QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
// loadingDictCache(); if (StringUtils.isNotEmpty(dictTypeBo.getDictName())) {
// } queryWrapper.and(SYS_DICT_TYPE.DICT_NAME.like(dictTypeBo.getDictName()));
}
if (StringUtils.isNotEmpty(dictTypeBo.getDictType())) {
queryWrapper.and(SYS_DICT_TYPE.DICT_TYPE.eq(dictTypeBo.getDictType()));
}
if (StringUtils.isNotEmpty((String) dictTypeBo.getParams().get("beginTime")) ) {
queryWrapper.and(SYS_DICT_TYPE.CREATE_TIME.ge(dictTypeBo.getParams().get("beginTime")));
}
if (StringUtils.isNotEmpty((String) dictTypeBo.getParams().get("endTime")) ) {
queryWrapper.and(SYS_DICT_TYPE.CREATE_TIME.le(dictTypeBo.getParams().get("endTime")));
}
return queryWrapper;
}
/** /**
* 根据条件分页查询字典类型 * 根据条件分页查询字典类型
* *
* @param dictType 字典类型信息 * @param dictTypeBo 字典类型信息
* @return 字典类型集合信息 * @return 字典类型集合信息
*/ */
@Override @Override
public List<SysDictType> selectDictTypeList(SysDictType dictType) public List<SysDictTypeVo> selectDictTypeList(SysDictTypeBo dictTypeBo)
{ {
return dictTypeMapper.selectDictTypeList(dictType); QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo);
return this.listAs(queryWrapper, SysDictTypeVo.class);
}
/**
* 分页查询字典类型
*
* @param dictTypeBo 字典类型信息
* @return 字典类型集合信息
*/
@Override
public TableDataInfo<SysDictTypeVo> selectPage(SysDictTypeBo dictTypeBo) {
QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo);
PageDomain pageDomain = TableSupport.buildPageRequest();
Page<SysDictTypeVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysDictTypeVo.class);
return TableDataInfo.build(page);
} }
/** /**
@ -68,9 +118,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @return 字典类型集合信息 * @return 字典类型集合信息
*/ */
@Override @Override
public List<SysDictType> selectDictTypeAll() public List<SysDictTypeVo> selectDictTypeAll()
{ {
return dictTypeMapper.selectDictTypeAll(); return this.listAs(query(), SysDictTypeVo.class);
} }
/** /**
@ -81,13 +131,12 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
*/ */
@Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType") @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType")
@Override @Override
public List<SysDictData> selectDictDataByType(String dictType) public List<SysDictDataVo> selectDictDataByType(String dictType)
{ {
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType); List<SysDictDataVo> lists = sysDictDataService.selectDictDataByType(dictType);
if (StringUtils.isNotEmpty(dictDatas)) if (StringUtils.isNotEmpty(lists))
{ {
//DictUtils.setDictCache(dictType, dictDatas); return lists;
return dictDatas;
} }
return null; return null;
} }
@ -99,9 +148,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @return 字典类型 * @return 字典类型
*/ */
@Override @Override
public SysDictType selectDictTypeById(Long dictId) public SysDictTypeVo selectDictTypeById(Long dictId)
{ {
return dictTypeMapper.selectDictTypeById(dictId); return this.getOneAs(query().where(SYS_DICT_TYPE.DICT_ID.eq(dictId)),SysDictTypeVo.class);
} }
/** /**
@ -111,30 +160,30 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @return 字典类型 * @return 字典类型
*/ */
@Override @Override
public SysDictType selectDictTypeByType(String dictType) public SysDictTypeVo selectDictTypeByType(String dictType)
{ {
return dictTypeMapper.selectDictTypeByType(dictType); return this.getOneAs(query().where(SYS_DICT_TYPE.DICT_TYPE.eq(dictType)),SysDictTypeVo.class);
} }
/** /**
* 批量删除字典类型信息 * 批量删除字典类型信息
* *
* @param dictIds 需要删除的字典ID * @param dictIds 需要删除的字典ID
* @return true 删除成功false 删除失败
*/ */
@Override @Override
public void deleteDictTypeByIds(Long[] dictIds) public boolean deleteDictTypeByIds(Long[] dictIds)
{ {
for (Long dictId : dictIds) for (Long dictId : dictIds)
{ {
SysDictType dictType = selectDictTypeById(dictId); SysDictTypeVo dictType = selectDictTypeById(dictId);
if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) if (sysDictDataService.countDictDataByType(dictType.getDictType()) > 0)
{ {
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
} }
dictTypeMapper.deleteDictTypeById(dictId);
//DictUtils.removeDictCache(dictType.getDictType());
CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType()); CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
} }
return this.removeByIds(Arrays.asList(dictIds));
} }
/** /**
@ -149,56 +198,60 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
/** /**
* 新增保存字典类型信息 * 新增保存字典类型信息
* *
* @param dict 字典类型信息 * @param sysDictTypeBo 字典类型信息
* @return 结果 * @return 结果
*/ */
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType") @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#sysDictTypeBo.dictType")
@Override @Override
public int insertDictType(SysDictType dict) public List<SysDictDataVo> insertDictType(SysDictTypeBo sysDictTypeBo)
{ {
int row = dictTypeMapper.insertDictType(dict); SysDictType dict = MapstructUtils.convert(sysDictTypeBo, SysDictType.class);
int row = dictTypeMapper.insert(dict,false);
if (row > 0) if (row > 0)
{ {
//DictUtils.setDictCache(dict.getDictType(), null); // 新增 type 下无 data 数据 返回空防止缓存穿透
return row; return new ArrayList<>();
} }
return 0; throw new ServiceException("插入操作失败");
} }
/** /**
* 修改保存字典类型信息 * 修改保存字典类型信息
* *
* @param dict 字典类型信息 * @param dictTypeBo 字典类型信息
* @return 结果 * @return 结果
*/ */
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType") @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dictTypeBo.dictType")
@Override @Override
@Transactional @Transactional
public int updateDictType(SysDictType dict) public List<SysDictDataVo> updateDictType(SysDictTypeBo dictTypeBo)
{ {
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); SysDictType dict = MapstructUtils.convert(dictTypeBo, SysDictType.class);
dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); SysDictTypeVo oldDict = selectDictTypeById(dict.getDictId());
int row = dictTypeMapper.updateDictType(dict); if (!oldDict.getDictType().equals(dict.getDictType())) {
if (row > 0) sysDictDataService.updateDictDataType(oldDict.getDictType(), dict.getDictType());
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
//DictUtils.setDictCache(dict.getDictType(), dictDatas);
CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
} }
return row;
boolean updated = this.updateById(dict);
if (updated)
{
CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
return sysDictDataService.selectDictDataByType(dict.getDictType());
}
throw new ServiceException("修改操作失败");
} }
/** /**
* 校验字典类型称是否唯一 * 校验字典类型称是否唯一
* *
* @param dict 字典类型 * @param dictTypeBo 字典类型
* @return 结果 * @return 结果
*/ */
@Override @Override
public boolean checkDictTypeUnique(SysDictType dict) public boolean checkDictTypeUnique(SysDictTypeBo dictTypeBo)
{ {
Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); Long dictId = StringUtils.isNull(dictTypeBo.getDictId()) ? -1L : dictTypeBo.getDictId();
SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); SysDictType dictType = this.getOne(query().where(SYS_DICT_TYPE.DICT_TYPE.eq(dictTypeBo.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.NOT_UNIQUE;
@ -218,13 +271,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
@Override @Override
public String getDictLabel(String dictType, String dictValue, String separator) { public String getDictLabel(String dictType, String dictValue, String separator) {
// 优先从本地缓存获取 // 优先从本地缓存获取
List<SysDictData> datas = (List<SysDictData>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); List<SysDictDataVo> lists = (List<SysDictDataVo>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType);
if (ObjectUtil.isNull(datas)) { if (ObjectUtil.isNull(lists)) {
datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); lists = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, lists);
} }
Map<String, String> map = StreamUtils.toMap(datas, SysDictData::getDictValue, SysDictData::getDictLabel); Map<String, String> map = StreamUtils.toMap(lists, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel);
if (StringUtils.containsAny(dictValue, separator)) { if (StringUtils.containsAny(dictValue, separator)) {
return Arrays.stream(dictValue.split(separator)) return Arrays.stream(dictValue.split(separator))
.map(v -> map.getOrDefault(v, StringUtils.EMPTY)) .map(v -> map.getOrDefault(v, StringUtils.EMPTY))
@ -246,13 +299,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
@Override @Override
public String getDictValue(String dictType, String dictLabel, String separator) { public String getDictValue(String dictType, String dictLabel, String separator) {
// 优先从本地缓存获取 // 优先从本地缓存获取
List<SysDictData> datas = (List<SysDictData>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); List<SysDictDataVo> lists = (List<SysDictDataVo>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType);
if (ObjectUtil.isNull(datas)) { if (ObjectUtil.isNull(lists)) {
datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); lists = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, lists);
} }
Map<String, String> map = StreamUtils.toMap(datas, SysDictData::getDictLabel, SysDictData::getDictValue); Map<String, String> map = StreamUtils.toMap(lists, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue);
if (StringUtils.containsAny(dictLabel, separator)) { if (StringUtils.containsAny(dictLabel, separator)) {
return Arrays.stream(dictLabel.split(separator)) return Arrays.stream(dictLabel.split(separator))
.map(l -> map.getOrDefault(l, StringUtils.EMPTY)) .map(l -> map.getOrDefault(l, StringUtils.EMPTY))
@ -264,7 +317,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
@Override @Override
public Map<String, String> getAllDictByDictType(String dictType) { public Map<String, String> getAllDictByDictType(String dictType) {
List<SysDictData> list = selectDictDataByType(dictType); List<SysDictDataVo> list = selectDictDataByType(dictType);
return StreamUtils.toMap(list, SysDictData::getDictValue, SysDictData::getDictLabel); return StreamUtils.toMap(list, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel);
} }
} }

View File

@ -5,13 +5,13 @@ import java.util.List;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.ruoyi.common.core.core.page.PageDomain; import com.ruoyi.common.core.core.page.PageDomain;
import com.ruoyi.common.core.core.page.TableSupport; import com.ruoyi.common.core.core.page.TableSupport;
import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.sql.SqlUtil; import com.ruoyi.common.core.utils.sql.SqlUtil;
import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.system.domain.bo.SysNoticeBo; import com.ruoyi.system.domain.bo.SysNoticeBo;
import com.ruoyi.system.domain.vo.SysNoticeVo; import com.ruoyi.system.domain.vo.SysNoticeVo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -29,7 +29,7 @@ import static com.ruoyi.system.domain.table.SysNoticeTableDef.SYS_NOTICE;
* @author 数据小王子 * @author 数据小王子
*/ */
@Service @Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService { public class SysNoticeServiceImpl extends BaseServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService {
@Resource @Resource
private SysNoticeMapper noticeMapper; private SysNoticeMapper noticeMapper;
@ -53,10 +53,10 @@ public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice
* 根据noticeBo构建QueryWrapper查询条件 * 根据noticeBo构建QueryWrapper查询条件
* *
* @param noticeBo * @param noticeBo
* @return * @return 查询条件
*/ */
private QueryWrapper buildQueryWrapper(SysNoticeBo noticeBo) { private QueryWrapper buildQueryWrapper(SysNoticeBo noticeBo) {
QueryWrapper queryWrapper = query(); QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();
if (StringUtils.isNotEmpty(noticeBo.getNoticeTitle())) { if (StringUtils.isNotEmpty(noticeBo.getNoticeTitle())) {
@ -95,7 +95,7 @@ public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice
* @return 公告集合 * @return 公告集合
*/ */
@Override @Override
public TableDataInfo<SysNoticeVo> selectConfigPage(SysNoticeBo noticeBo) { public TableDataInfo<SysNoticeVo> selectPage(SysNoticeBo noticeBo) {
QueryWrapper queryWrapper = buildQueryWrapper(noticeBo); QueryWrapper queryWrapper = buildQueryWrapper(noticeBo);
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();

View File

@ -5,12 +5,12 @@ import java.util.List;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.ruoyi.common.core.core.page.PageDomain; import com.ruoyi.common.core.core.page.PageDomain;
import com.ruoyi.common.core.core.page.TableSupport; import com.ruoyi.common.core.core.page.TableSupport;
import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.sql.SqlUtil; import com.ruoyi.common.core.utils.sql.SqlUtil;
import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.system.domain.bo.SysPostBo; import com.ruoyi.system.domain.bo.SysPostBo;
import com.ruoyi.system.domain.vo.SysPostVo; import com.ruoyi.system.domain.vo.SysPostVo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -31,7 +31,7 @@ import static com.ruoyi.system.domain.table.SysPostTableDef.SYS_POST;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements ISysPostService public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost> implements ISysPostService
{ {
@Resource @Resource
private SysPostMapper postMapper; private SysPostMapper postMapper;
@ -47,10 +47,10 @@ public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> imp
/** /**
* 根据postBo构建QueryWrapper查询条件 * 根据postBo构建QueryWrapper查询条件
* @param postBo * @param postBo
* @return * @return 查询条件
*/ */
private QueryWrapper buildQueryWrapper(SysPostBo postBo) { private QueryWrapper buildQueryWrapper(SysPostBo postBo) {
QueryWrapper queryWrapper = query(); QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();
if (StringUtils.isNotEmpty(postBo.getPostCode())) { if (StringUtils.isNotEmpty(postBo.getPostCode())) {
@ -90,7 +90,7 @@ public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> imp
* @return 公告集合 * @return 公告集合
*/ */
@Override @Override
public TableDataInfo<SysPostVo> selectConfigPage(SysPostBo postBo) { public TableDataInfo<SysPostVo> selectPage(SysPostBo postBo) {
QueryWrapper queryWrapper = buildQueryWrapper(postBo); QueryWrapper queryWrapper = buildQueryWrapper(postBo);
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();

View File

@ -24,94 +24,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from sys_dict_data from sys_dict_data
</sql> </sql>
<select id="selectDictDataList" parameterType="SysDictData" resultMap="SysDictDataResult">
<include refid="selectDictDataVo"/>
<where>
<if test="dictType != null and dictType != ''">
AND dict_type = #{dictType}
</if>
<if test="dictLabel != null and dictLabel != ''">
AND dict_label like concat('%', #{dictLabel}, '%')
</if>
</where>
order by dict_sort asc
</select>
<select id="selectDictDataByType" parameterType="SysDictData" resultMap="SysDictDataResult">
<include refid="selectDictDataVo"/>
where dict_type = #{dictType} order by dict_sort asc
</select>
<select id="selectDictLabel" resultType="String">
select dict_label from sys_dict_data
where dict_type = #{dictType} and dict_value = #{dictValue}
</select>
<select id="selectDictDataById" parameterType="Long" resultMap="SysDictDataResult">
<include refid="selectDictDataVo"/>
where dict_code = #{dictCode}
</select>
<select id="countDictDataByType" resultType="Integer">
select count(1) from sys_dict_data where dict_type=#{dictType}
</select>
<delete id="deleteDictDataById" parameterType="Long">
delete from sys_dict_data where dict_code = #{dictCode}
</delete>
<delete id="deleteDictDataByIds" parameterType="Long">
delete from sys_dict_data where dict_code in
<foreach collection="array" item="dictCode" open="(" separator="," close=")">
#{dictCode}
</foreach>
</delete>
<update id="updateDictData" parameterType="SysDictData">
update sys_dict_data
<set>
<if test="dictSort != null">dict_sort = #{dictSort},</if>
<if test="dictLabel != null and dictLabel != ''">dict_label = #{dictLabel},</if>
<if test="dictValue != null and dictValue != ''">dict_value = #{dictValue},</if>
<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
<if test="cssClass != null">css_class = #{cssClass},</if>
<if test="listClass != null">list_class = #{listClass},</if>
<if test="isDefault != null and isDefault != ''">is_default = #{isDefault},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where dict_code = #{dictCode}
</update>
<update id="updateDictDataType" parameterType="String">
update sys_dict_data set dict_type = #{newDictType} where dict_type = #{oldDictType}
</update>
<insert id="insertDictData" parameterType="SysDictData">
insert into sys_dict_data(
<if test="dictSort != null">dict_sort,</if>
<if test="dictLabel != null and dictLabel != ''">dict_label,</if>
<if test="dictValue != null and dictValue != ''">dict_value,</if>
<if test="dictType != null and dictType != ''">dict_type,</if>
<if test="cssClass != null and cssClass != ''">css_class,</if>
<if test="listClass != null and listClass != ''">list_class,</if>
<if test="isDefault != null and isDefault != ''">is_default,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="dictSort != null">#{dictSort},</if>
<if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
<if test="dictValue != null and dictValue != ''">#{dictValue},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="cssClass != null and cssClass != ''">#{cssClass},</if>
<if test="listClass != null and listClass != ''">#{listClass},</if>
<if test="isDefault != null and isDefault != ''">#{isDefault},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
</mapper> </mapper>

View File

@ -19,80 +19,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from sys_dict_type from sys_dict_type
</sql> </sql>
<select id="selectDictTypeList" parameterType="SysDictType" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
<where>
<if test="dictName != null and dictName != ''">
AND dict_name like concat('%', #{dictName}, '%')
</if>
<if test="dictType != null and dictType != ''">
AND dict_type like concat('%', #{dictType}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectDictTypeAll" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
</select>
<select id="selectDictTypeById" parameterType="Long" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
where dict_id = #{dictId}
</select>
<select id="selectDictTypeByType" parameterType="String" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
where dict_type = #{dictType}
</select>
<select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
where dict_type = #{dictType} limit 1
</select>
<delete id="deleteDictTypeById" parameterType="Long">
delete from sys_dict_type where dict_id = #{dictId}
</delete>
<delete id="deleteDictTypeByIds" parameterType="Long">
delete from sys_dict_type where dict_id in
<foreach collection="array" item="dictId" open="(" separator="," close=")">
#{dictId}
</foreach>
</delete>
<update id="updateDictType" parameterType="SysDictType">
update sys_dict_type
<set>
<if test="dictName != null and dictName != ''">dict_name = #{dictName},</if>
<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where dict_id = #{dictId}
</update>
<insert id="insertDictType" parameterType="SysDictType">
insert into sys_dict_type(
<if test="dictName != null and dictName != ''">dict_name,</if>
<if test="dictType != null and dictType != ''">dict_type,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="dictName != null and dictName != ''">#{dictName},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
</mapper> </mapper>