diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 4548bf2..a60e73a 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -18,12 +18,12 @@ mybatis-flex: # NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息 autoMappingUnknownColumnBehavior: WARNING # 更详细的日志输出 会有性能损耗 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 logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl cacheEnabled: true - useGeneratedKeys: true - defaultExecutorType: SIMPLE + #useGeneratedKeys: true + #defaultExecutorType: SIMPLE # MyBatis-Flex全局配置 global-config: diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictDataController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictDataController.java index c77cce4..bdaa876 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictDataController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictDataController.java @@ -5,11 +5,13 @@ import java.util.List; import cn.dev33.satoken.annotation.SaCheckPermission; 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.enums.BusinessType; import com.ruoyi.common.orm.core.page.TableDataInfo; -import com.ruoyi.common.security.utils.LoginHelper; -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.servlet.http.HttpServletResponse; 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.RestController; 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.poi.ExcelUtil; import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.system.service.ISysDictTypeService; @@ -38,8 +38,7 @@ import com.ruoyi.system.service.ISysDictTypeService; @RequiredArgsConstructor @RestController @RequestMapping("/system/dict/data") -public class SysDictDataController extends BaseController -{ +public class SysDictDataController extends BaseController { @Resource private ISysDictDataService dictDataService; @@ -48,11 +47,8 @@ public class SysDictDataController extends BaseController @SaCheckPermission("system:dict:list") @GetMapping("/list") - public TableDataInfo list(SysDictData dictData) - { - startPage(); - List list = dictDataService.selectDictDataList(dictData); - return getDataTable(list); + public TableDataInfo list(SysDictDataBo dictDataBo) { + return dictDataService.selectPage(dictDataBo); } /** @@ -61,11 +57,9 @@ public class SysDictDataController extends BaseController @SaCheckPermission("system:dict:export") @Log(title = "字典数据", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, SysDictData dictData) - { - List list = dictDataService.selectDictDataList(dictData); - ExcelUtil util = new ExcelUtil<>(SysDictData.class); - util.exportExcel(response, list, "字典数据"); + public void export(HttpServletResponse response, SysDictDataBo dictDataBo) { + List list = dictDataService.selectDictDataList(dictDataBo); + ExcelUtil.exportExcel(list, "字典数据", SysDictDataVo.class, response); } /** @@ -73,9 +67,8 @@ public class SysDictDataController extends BaseController */ @SaCheckPermission("system:dict:query") @GetMapping(value = "/{dictCode}") - public AjaxResult getInfo(@PathVariable Long dictCode) - { - return success(dictDataService.selectDictDataById(dictCode)); + public R getInfo(@PathVariable Long dictCode) { + return R.ok(dictDataService.selectDictDataById(dictCode)); } /** @@ -83,14 +76,12 @@ public class SysDictDataController extends BaseController */ @SaIgnore @GetMapping(value = "/type/{dictType}") - public AjaxResult dictType(@PathVariable String dictType) - { - List data = dictTypeService.selectDictDataByType(dictType); - if (StringUtils.isNull(data)) - { + public R> dictType(@PathVariable String dictType) { + List data = dictTypeService.selectDictDataByType(dictType); + if (StringUtils.isNull(data)) { data = new ArrayList<>(); } - return success(data); + return R.ok(data); } /** @@ -99,10 +90,12 @@ public class SysDictDataController extends BaseController @SaCheckPermission("system:dict:add") @Log(title = "字典数据", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysDictData dict) - { - dict.setCreateBy(LoginHelper.getUserId()); - return toAjax(dictDataService.insertDictData(dict)); + public R add(@Validated @RequestBody SysDictDataBo dictDataBo) { + int insertedRows = dictDataService.insertDictData(dictDataBo); + if (insertedRows == 0) { + return R.fail("新增字典数据记录失败!"); + } + return R.ok(); } /** @@ -111,10 +104,12 @@ public class SysDictDataController extends BaseController @SaCheckPermission("system:dict:edit") @Log(title = "字典数据", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysDictData dict) - { - dict.setUpdateBy(LoginHelper.getUserId()); - return toAjax(dictDataService.updateDictData(dict)); + public R edit(@Validated @RequestBody SysDictDataBo dictDataBo) { + boolean updated = dictDataService.updateDictData(dictDataBo); + if (!updated) { + return R.fail("修改字典数据记录失败!"); + } + return R.ok(); } /** @@ -123,9 +118,11 @@ public class SysDictDataController extends BaseController @SaCheckPermission("system:dict:remove") @Log(title = "字典类型", businessType = BusinessType.DELETE) @DeleteMapping("/{dictCodes}") - public AjaxResult remove(@PathVariable Long[] dictCodes) - { - dictDataService.deleteDictDataByIds(dictCodes); - return success(); + public R remove(@PathVariable Long[] dictCodes) { + boolean deleted = dictDataService.deleteDictDataByIds(dictCodes); + if (!deleted) { + return R.fail("删除字典数据记录失败!"); + } + return R.ok(); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictTypeController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictTypeController.java index 26ac6e7..cac6195 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictTypeController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDictTypeController.java @@ -3,11 +3,13 @@ package com.ruoyi.system.controller.system; import java.util.List; 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.enums.BusinessType; import com.ruoyi.common.orm.core.page.TableDataInfo; -import com.ruoyi.common.security.utils.LoginHelper; -import com.ruoyi.system.domain.SysDictType; +import com.ruoyi.system.domain.bo.SysDictTypeBo; +import com.ruoyi.system.domain.vo.SysDictTypeVo; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; 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.RestController; 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; /** @@ -41,21 +41,18 @@ public class SysDictTypeController extends BaseController @SaCheckPermission("system:dict:list") @GetMapping("/list") - public TableDataInfo list(SysDictType dictType) + public TableDataInfo list(SysDictTypeBo dictTypeBo) { - startPage(); - List list = dictTypeService.selectDictTypeList(dictType); - return getDataTable(list); + return dictTypeService.selectPage(dictTypeBo); } @Log(title = "字典类型", businessType = BusinessType.EXPORT) @SaCheckPermission("system:dict:export") @PostMapping("/export") - public void export(HttpServletResponse response, SysDictType dictType) + public void export(HttpServletResponse response, SysDictTypeBo dictTypeBo) { - List list = dictTypeService.selectDictTypeList(dictType); - ExcelUtil util = new ExcelUtil<>(SysDictType.class); - util.exportExcel(response, list, "字典类型"); + List list = dictTypeService.selectDictTypeList(dictTypeBo); + ExcelUtil.exportExcel(list, "数据字典类型信息数据", SysDictTypeVo.class, response); } /** @@ -63,9 +60,9 @@ public class SysDictTypeController extends BaseController */ @SaCheckPermission("system:dict:query") @GetMapping(value = "/{dictId}") - public AjaxResult getInfo(@PathVariable Long dictId) + public R 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") @Log(title = "字典类型", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysDictType dict) + public R 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()); - return toAjax(dictTypeService.insertDictType(dict)); + dictTypeService.insertDictType(dictTypeBo); + return R.ok(); } /** @@ -90,14 +87,14 @@ public class SysDictTypeController extends BaseController @SaCheckPermission("system:dict:edit") @Log(title = "字典类型", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysDictType dict) + public R 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()); - return toAjax(dictTypeService.updateDictType(dict)); + dictTypeService.updateDictType(dictTypeBo); + return R.ok(); } /** @@ -106,10 +103,13 @@ public class SysDictTypeController extends BaseController @SaCheckPermission("system:dict:remove") @Log(title = "字典类型", businessType = BusinessType.DELETE) @DeleteMapping("/{dictIds}") - public AjaxResult remove(@PathVariable Long[] dictIds) + public R remove(@PathVariable Long[] dictIds) { - dictTypeService.deleteDictTypeByIds(dictIds); - return success(); + boolean deleted = dictTypeService.deleteDictTypeByIds(dictIds); + if (!deleted) { + R.fail("删除字典类型记录失败!"); + } + return R.ok(); } /** @@ -118,19 +118,19 @@ public class SysDictTypeController extends BaseController @SaCheckPermission("system:dict:remove") @Log(title = "字典类型", businessType = BusinessType.CLEAN) @DeleteMapping("/refreshCache") - public AjaxResult refreshCache() + public R refreshCache() { dictTypeService.resetDictCache(); - return success(); + return R.ok(); } /** * 获取字典选择框列表 */ @GetMapping("/optionselect") - public AjaxResult optionselect() + public R> optionselect() { - List dictTypes = dictTypeService.selectDictTypeAll(); - return success(dictTypes); + List dictTypes = dictTypeService.selectDictTypeAll(); + return R.ok(dictTypes); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysNoticeController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysNoticeController.java index bc2ff90..5f61f62 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysNoticeController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysNoticeController.java @@ -42,7 +42,7 @@ public class SysNoticeController extends BaseController @GetMapping("/list") public TableDataInfo list(SysNoticeBo noticeBo) { - return noticeService.selectConfigPage(noticeBo); + return noticeService.selectPage(noticeBo); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java index 028e14a..a3ee24b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java @@ -47,7 +47,7 @@ public class SysPostController extends BaseController @GetMapping("/list") public TableDataInfo list(SysPostBo postBo) { - return postService.selectConfigPage(postBo); + return postService.selectPage(postBo); } @Log(title = "岗位管理", businessType = BusinessType.EXPORT) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java index 8608c61..d9265ca 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java @@ -1,44 +1,37 @@ package com.ruoyi.system.domain; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.core.annotation.Excel; -import com.ruoyi.common.core.annotation.Excel.ColumnType; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.orm.core.domain.BaseEntity; -import java.io.Serial; - /** * 字典数据表 sys_dict_data * * @author ruoyi */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "sys_dict_data") public class SysDictData extends BaseEntity { - @Serial - private static final long serialVersionUID = 1L; - /** 字典编码 */ - @Excel(name = "字典编码", cellType = ColumnType.NUMERIC) + @Id(keyType = KeyType.Auto) private Long dictCode; /** 字典排序 */ - @Excel(name = "字典排序", cellType = ColumnType.NUMERIC) private Long dictSort; /** 字典标签 */ - @Excel(name = "字典标签") private String dictLabel; /** 字典键值 */ - @Excel(name = "字典键值") private String dictValue; /** 字典类型 */ - @Excel(name = "字典类型") private String dictType; /** 样式属性(其他样式扩展) */ @@ -48,130 +41,12 @@ public class SysDictData extends BaseEntity private String listClass; /** 是否默认(Y是 N否) */ - @Excel(name = "是否默认", readConverterExp = "Y=是,N=否") private String isDefault; - /** - * 备注 - */ + /** 备注 */ private String remark; - public Long getDictCode() - { - 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(); + public boolean getDefault() { + return UserConstants.YES.equals(this.isDefault); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictType.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictType.java index b71480c..0a3f141 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictType.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictType.java @@ -1,95 +1,32 @@ package com.ruoyi.system.domain; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.core.annotation.Excel; -import com.ruoyi.common.core.annotation.Excel.ColumnType; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; import com.ruoyi.common.orm.core.domain.BaseEntity; -import java.io.Serial; - /** * 字典类型表 sys_dict_type * * @author ruoyi */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "sys_dict_type") public class SysDictType extends BaseEntity { - @Serial - private static final long serialVersionUID = 1L; - /** 字典主键 */ - @Excel(name = "字典主键", cellType = ColumnType.NUMERIC) + @Id(keyType = KeyType.Auto) private Long dictId; /** 字典名称 */ - @Excel(name = "字典名称") private String dictName; /** 字典类型 */ - @Excel(name = "字典类型") private String dictType; - /** - * 备注 - */ + /** 备注 */ 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(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictDataVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictDataVo.java index 56fd6d5..f0ebd6f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictDataVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictDataVo.java @@ -20,7 +20,6 @@ import java.util.Date; */ @Data @ExcelIgnoreUnannotated -@AutoMapper(target = SysDictData.class) public class SysDictDataVo implements Serializable { @Serial diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictTypeVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictTypeVo.java index 2ff6923..89068ee 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictTypeVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDictTypeVo.java @@ -2,10 +2,6 @@ package com.ruoyi.system.domain.vo; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; 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 java.io.Serial; @@ -20,7 +16,6 @@ import java.util.Date; */ @Data @ExcelIgnoreUnannotated -@AutoMapper(target = SysDictType.class) public class SysDictTypeVo implements Serializable { @Serial diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java index 4986481..745a376 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java @@ -2,7 +2,9 @@ package com.ruoyi.system.mapper; import java.util.List; +import com.mybatisflex.core.BaseMapper; import com.ruoyi.system.domain.SysDictData; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; /** @@ -10,87 +12,8 @@ import org.apache.ibatis.annotations.Param; * * @author ruoyi */ -public interface SysDictDataMapper +@Mapper +public interface SysDictDataMapper extends BaseMapper { - /** - * 根据条件分页查询字典数据 - * - * @param dictData 字典数据信息 - * @return 字典数据集合信息 - */ - List selectDictDataList(SysDictData dictData); - /** - * 根据字典类型查询字典数据 - * - * @param dictType 字典类型 - * @return 字典数据集合信息 - */ - List 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); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictTypeMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictTypeMapper.java index ae47b41..4557f48 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictTypeMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictTypeMapper.java @@ -1,84 +1,86 @@ package com.ruoyi.system.mapper; +import com.mybatisflex.core.BaseMapper; import com.ruoyi.system.domain.SysDictType; +import org.apache.ibatis.annotations.Mapper; -import java.util.List; /** * 字典表 数据层 * * @author ruoyi */ -public interface SysDictTypeMapper +@Mapper +public interface SysDictTypeMapper extends BaseMapper { - /** - * 根据条件分页查询字典类型 - * - * @param dictType 字典类型信息 - * @return 字典类型集合信息 - */ - List selectDictTypeList(SysDictType dictType); - - /** - * 根据所有字典类型 - * - * @return 字典类型集合信息 - */ - List selectDictTypeAll(); - - /** - * 根据字典类型ID查询信息 - * - * @param dictId 字典类型ID - * @return 字典类型 - */ - SysDictType selectDictTypeById(Long dictId); - - /** - * 根据字典类型查询信息 - * - * @param dictType 字典类型 - * @return 字典类型 - */ - SysDictType selectDictTypeByType(String dictType); - - /** - * 通过字典ID删除字典信息 - * - * @param dictId 字典ID - * @return 结果 - */ - int deleteDictTypeById(Long dictId); - - /** - * 批量删除字典类型信息 - * - * @param dictIds 需要删除的字典ID - * @return 结果 - */ - int deleteDictTypeByIds(Long[] dictIds); - - /** - * 新增字典类型信息 - * - * @param dictType 字典类型信息 - * @return 结果 - */ - int insertDictType(SysDictType dictType); - - /** - * 修改字典类型信息 - * - * @param dictType 字典类型信息 - * @return 结果 - */ - int updateDictType(SysDictType dictType); - - /** - * 校验字典类型称是否唯一 - * - * @param dictType 字典类型 - * @return 结果 - */ - SysDictType checkDictTypeUnique(String dictType); +// /** +// * 根据条件分页查询字典类型 +// * +// * @param dictType 字典类型信息 +// * @return 字典类型集合信息 +// */ +// List selectDictTypeList(SysDictType dictType); +// +// /** +// * 根据所有字典类型 +// * +// * @return 字典类型集合信息 +// */ +// List selectDictTypeAll(); +// +// /** +// * 根据字典类型ID查询信息 +// * +// * @param dictId 字典类型ID +// * @return 字典类型 +// */ +// SysDictType selectDictTypeById(Long dictId); +// +// /** +// * 根据字典类型查询信息 +// * +// * @param dictType 字典类型 +// * @return 字典类型 +// */ +// SysDictType selectDictTypeByType(String dictType); +// +// /** +// * 通过字典ID删除字典信息 +// * +// * @param dictId 字典ID +// * @return 结果 +// */ +// int deleteDictTypeById(Long dictId); +// +// /** +// * 批量删除字典类型信息 +// * +// * @param dictIds 需要删除的字典ID +// * @return 结果 +// */ +// int deleteDictTypeByIds(Long[] dictIds); +// +// /** +// * 新增字典类型信息 +// * +// * @param dictType 字典类型信息 +// * @return 结果 +// */ +// int insertDictType(SysDictType dictType); +// +// /** +// * 修改字典类型信息 +// * +// * @param dictType 字典类型信息 +// * @return 结果 +// */ +// int updateDictType(SysDictType dictType); +// +// /** +// * 校验字典类型称是否唯一 +// * +// * @param dictType 字典类型 +// * @return 结果 +// */ +// SysDictType checkDictTypeUnique(String dictType); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java index 2806d5b..f34a769 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java @@ -1,6 +1,10 @@ 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.bo.SysDictDataBo; +import com.ruoyi.system.domain.vo.SysDictDataVo; import java.util.List; @@ -9,15 +13,23 @@ import java.util.List; * * @author ruoyi */ -public interface ISysDictDataService +public interface ISysDictDataService extends IBaseService { /** * 根据条件分页查询字典数据 * - * @param dictData 字典数据信息 + * @param dictDataBo 字典数据信息 * @return 字典数据集合信息 */ - List selectDictDataList(SysDictData dictData); + List selectDictDataList(SysDictDataBo dictDataBo); + + /** + * 分页查询字典数据 + * + * @param dictDataBo 字典类型信息 + * @return 字典数据集合信息 + */ + TableDataInfo selectPage(SysDictDataBo dictDataBo); /** * 根据字典类型和字典键值查询字典数据信息 @@ -34,28 +46,55 @@ public interface ISysDictDataService * @param dictCode 字典数据ID * @return 字典数据 */ - SysDictData selectDictDataById(Long dictCode); + SysDictDataVo selectDictDataById(Long dictCode); + + /** + * 查询字典数据记录数量 + * + * @param dictType 字典类型 + * @return 字典数据 + */ + Integer countDictDataByType(String dictType); + + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + List selectDictDataByType(String dictType); /** * 批量删除字典数据信息 * * @param dictCodes 需要删除的字典数据ID + * @return 结果:true 删除成功,false 删除失败。 */ - void deleteDictDataByIds(Long[] dictCodes); + boolean deleteDictDataByIds(Long[] dictCodes); /** * 新增保存字典数据信息 * - * @param dictData 字典数据信息 - * @return 结果 + * @param dataBo 字典数据信息 + * @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 结果 */ - int updateDictData(SysDictData dictData); + boolean updateDictDataType(String oldDictType, String newDictType); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java index 4a98b2f..286e6e6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java @@ -1,7 +1,12 @@ 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.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; @@ -10,7 +15,7 @@ import java.util.List; * * @author ruoyi */ -public interface ISysDictTypeService +public interface ISysDictTypeService extends IService { /** * 根据条件分页查询字典类型 @@ -18,14 +23,22 @@ public interface ISysDictTypeService * @param dictType 字典类型信息 * @return 字典类型集合信息 */ - List selectDictTypeList(SysDictType dictType); + List selectDictTypeList(SysDictTypeBo dictType); + + /** + * 分页查询公告列表 + * + * @param dictTypeBo 字典类型信息 + * @return 分页字典类型集合信息 + */ + TableDataInfo selectPage(SysDictTypeBo dictTypeBo); /** * 根据所有字典类型 * * @return 字典类型集合信息 */ - List selectDictTypeAll(); + List selectDictTypeAll(); /** * 根据字典类型查询字典数据 @@ -33,7 +46,7 @@ public interface ISysDictTypeService * @param dictType 字典类型 * @return 字典数据集合信息 */ - List selectDictDataByType(String dictType); + List selectDictDataByType(String dictType); /** * 根据字典类型ID查询信息 @@ -41,7 +54,7 @@ public interface ISysDictTypeService * @param dictId 字典类型ID * @return 字典类型 */ - SysDictType selectDictTypeById(Long dictId); + SysDictTypeVo selectDictTypeById(Long dictId); /** * 根据字典类型查询信息 @@ -49,14 +62,15 @@ public interface ISysDictTypeService * @param dictType 字典类型 * @return 字典类型 */ - SysDictType selectDictTypeByType(String dictType); + SysDictTypeVo selectDictTypeByType(String dictType); /** * 批量删除字典信息 * * @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 结果 */ - int insertDictType(SysDictType dictType); + List insertDictType(SysDictTypeBo sysDictTypeBo); /** * 修改保存字典类型信息 * - * @param dictType 字典类型信息 + * @param dictTypeBo 字典类型信息 * @return 结果 */ - int updateDictType(SysDictType dictType); + public List updateDictType(SysDictTypeBo dictTypeBo); /** * 校验字典类型称是否唯一 * - * @param dictType 字典类型 + * @param dictTypeBo 字典类型 * @return 结果 */ - boolean checkDictTypeUnique(SysDictType dictType); + boolean checkDictTypeUnique(SysDictTypeBo dictTypeBo); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java index a1b6660..df19551 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java @@ -37,7 +37,7 @@ public interface ISysNoticeService extends IService * @param noticeBo 公告信息 * @return 公告集合 */ - TableDataInfo selectConfigPage(SysNoticeBo noticeBo); + TableDataInfo selectPage(SysNoticeBo noticeBo); /** * 新增公告 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java index 5f794f4..71504b8 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java @@ -29,7 +29,7 @@ public interface ISysPostService extends IService * @param postBo 公告信息 * @return 公告集合 */ - TableDataInfo selectConfigPage(SysPostBo postBo); + TableDataInfo selectPage(SysPostBo postBo); /** * 查询所有岗位 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java index e446e19..4bd912d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java @@ -4,21 +4,20 @@ import java.util.List; import com.mybatisflex.core.paginate.Page; 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.core.page.PageDomain; import com.ruoyi.common.core.core.page.TableSupport; import com.ruoyi.common.core.service.ConfigService; import com.ruoyi.common.core.utils.MapstructUtils; 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.service.impl.BaseServiceImpl; import com.ruoyi.common.redis.utils.CacheUtils; import com.ruoyi.system.domain.bo.SysConfigBo; import com.ruoyi.system.domain.vo.SysConfigVo; import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; -import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.ruoyi.common.core.constant.UserConstants; @@ -39,7 +38,7 @@ import static com.ruoyi.system.domain.table.SysConfigTableDef.SYS_CONFIG; */ @RequiredArgsConstructor @Service -public class SysConfigServiceImpl extends ServiceImpl implements ISysConfigService, ConfigService { +public class SysConfigServiceImpl extends BaseServiceImpl implements ISysConfigService, ConfigService { @Resource private SysConfigMapper configMapper; @@ -92,12 +91,11 @@ public class SysConfigServiceImpl extends ServiceImpl selectConfigPage(SysConfigBo config) { @@ -159,7 +152,7 @@ public class SysConfigServiceImpl extends ServiceImpl implements ISysDictDataService { @Resource 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 字典数据集合信息 */ @Override - public List selectDictDataList(SysDictData dictData) + public List selectDictDataList(SysDictDataBo dictDataBo) { - return dictDataMapper.selectDictDataList(dictData); + QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo); + return this.listAs(queryWrapper, SysDictDataVo.class); + } + + /** + * 分页查询字典数据 + * + * @param dictDataBo 字典类型信息 + * @return 字典数据集合信息 + */ + @Override + public TableDataInfo selectPage(SysDictDataBo dictDataBo) { + QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo); + + PageDomain pageDomain = TableSupport.buildPageRequest(); + + Page 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 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 字典数据 */ @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 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 + * @return 结果:true 删除成功,false 删除失败。 */ @Override - public void deleteDictDataByIds(Long[] dictCodes) + public boolean deleteDictDataByIds(Long[] dictCodes) { for (Long dictCode : dictCodes) { - SysDictData data = selectDictDataById(dictCode); - dictDataMapper.deleteDictDataById(dictCode); - List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); - //DictUtils.setDictCache(data.getDictType(), dictDatas); + SysDictDataVo data = selectDictDataById(dictCode); CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType()); } + return this.removeByIds(Arrays.asList(dictCodes)); } /** * 新增保存字典数据信息 * - * @param data 字典数据信息 - * @return 结果 + * @param dataBo 字典数据信息 + * @return 结果:受影响的行数 */ - @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") + @CacheEvict(cacheNames = CacheNames.SYS_DICT, key = "#dataBo.dictType") @Override - public int insertDictData(SysDictData data) + public int insertDictData(SysDictDataBo dataBo) { - int row = dictDataMapper.insertDictData(data); - if (row > 0) - { - List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); - //DictUtils.setDictCache(data.getDictType(), dictDatas); - } - return row; + SysDictData data = MapstructUtils.convert(dataBo, SysDictData.class); + return dictDataMapper.insert(data,false); } /** * 修改保存字典数据信息 * - * @param data 字典数据信息 - * @return 结果 + * @param dataBo 字典数据信息 + * @return 结果:true 更新成功,false 更新失败。 */ - @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") + @CacheEvict(cacheNames = CacheNames.SYS_DICT, key = "#dataBo.dictType") @Override - public int updateDictData(SysDictData data) + public boolean updateDictData(SysDictDataBo dataBo) { - int row = dictDataMapper.updateDictData(data); - if (row > 0) - { - List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); - //DictUtils.setDictCache(data.getDictType(), dictDatas); - } - return row; + SysDictData data = MapstructUtils.convert(dataBo, SysDictData.class); + return this.updateById(data); + } + + @Override + public boolean updateDictDataType(String oldDictType, String newDictType){ + return UpdateChain.of(SysDictData.class) + .set(SysDictData::getDictType, newDictType) + .where(SysDictData::getDictType).eq(oldDictType) + .update(); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index c9dc70e..fe89bc5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service.impl; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -7,14 +8,24 @@ import java.util.stream.Collectors; import cn.dev33.satoken.context.SaHolder; 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.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.utils.MapstructUtils; import com.ruoyi.common.core.utils.SpringUtils; 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.system.domain.SysDictData; 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 org.springframework.cache.annotation.CachePut; 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.exception.ServiceException; import com.ruoyi.common.core.utils.StringUtils; -import com.ruoyi.system.mapper.SysDictDataMapper; import com.ruoyi.system.mapper.SysDictTypeMapper; import com.ruoyi.system.service.ISysDictTypeService; +import static com.ruoyi.system.domain.table.SysDictTypeTableDef.SYS_DICT_TYPE; + /** * 字典 业务层处理 * * @author ruoyi */ @Service -public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService +public class SysDictTypeServiceImpl extends BaseServiceImpl implements ISysDictTypeService, DictService { @Resource private SysDictTypeMapper dictTypeMapper; @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() -// { -// loadingDictCache(); -// } + + private QueryWrapper buildQueryWrapper(SysDictTypeBo dictTypeBo){ + QueryWrapper queryWrapper = super.buildBaseQueryWrapper(); + 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 字典类型集合信息 */ @Override - public List selectDictTypeList(SysDictType dictType) + public List selectDictTypeList(SysDictTypeBo dictTypeBo) { - return dictTypeMapper.selectDictTypeList(dictType); + QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo); + + return this.listAs(queryWrapper, SysDictTypeVo.class); + } + + /** + * 分页查询字典类型 + * + * @param dictTypeBo 字典类型信息 + * @return 字典类型集合信息 + */ + @Override + public TableDataInfo selectPage(SysDictTypeBo dictTypeBo) { + QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo); + + PageDomain pageDomain = TableSupport.buildPageRequest(); + + Page 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 字典类型集合信息 */ @Override - public List selectDictTypeAll() + public List 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") @Override - public List selectDictDataByType(String dictType) + public List selectDictDataByType(String dictType) { - List dictDatas = dictDataMapper.selectDictDataByType(dictType); - if (StringUtils.isNotEmpty(dictDatas)) + List lists = sysDictDataService.selectDictDataByType(dictType); + if (StringUtils.isNotEmpty(lists)) { - //DictUtils.setDictCache(dictType, dictDatas); - return dictDatas; + return lists; } return null; } @@ -99,9 +148,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService * @return 字典类型 */ @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 字典类型 */ @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 + * @return true 删除成功,false 删除失败。 */ @Override - public void deleteDictTypeByIds(Long[] dictIds) + public boolean deleteDictTypeByIds(Long[] dictIds) { for (Long dictId : dictIds) { - SysDictType dictType = selectDictTypeById(dictId); - if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) + SysDictTypeVo dictType = selectDictTypeById(dictId); + if (sysDictDataService.countDictDataByType(dictType.getDictType()) > 0) { throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); } - dictTypeMapper.deleteDictTypeById(dictId); - //DictUtils.removeDictCache(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 结果 */ - @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType") + @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#sysDictTypeBo.dictType") @Override - public int insertDictType(SysDictType dict) + public List insertDictType(SysDictTypeBo sysDictTypeBo) { - int row = dictTypeMapper.insertDictType(dict); + SysDictType dict = MapstructUtils.convert(sysDictTypeBo, SysDictType.class); + int row = dictTypeMapper.insert(dict,false); if (row > 0) { - //DictUtils.setDictCache(dict.getDictType(), null); - return row; + // 新增 type 下无 data 数据 返回空防止缓存穿透 + return new ArrayList<>(); } - return 0; + throw new ServiceException("插入操作失败"); } /** * 修改保存字典类型信息 * - * @param dict 字典类型信息 + * @param dictTypeBo 字典类型信息 * @return 结果 */ - @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType") + @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dictTypeBo.dictType") @Override @Transactional - public int updateDictType(SysDictType dict) + public List updateDictType(SysDictTypeBo dictTypeBo) { - SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); - dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); - int row = dictTypeMapper.updateDictType(dict); - if (row > 0) - { - List dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); - //DictUtils.setDictCache(dict.getDictType(), dictDatas); - CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType()); + SysDictType dict = MapstructUtils.convert(dictTypeBo, SysDictType.class); + SysDictTypeVo oldDict = selectDictTypeById(dict.getDictId()); + if (!oldDict.getDictType().equals(dict.getDictType())) { + sysDictDataService.updateDictDataType(oldDict.getDictType(), dict.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 结果 */ @Override - public boolean checkDictTypeUnique(SysDictType dict) + public boolean checkDictTypeUnique(SysDictTypeBo dictTypeBo) { - Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); - SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); + Long dictId = StringUtils.isNull(dictTypeBo.getDictId()) ? -1L : dictTypeBo.getDictId(); + SysDictType dictType = this.getOne(query().where(SYS_DICT_TYPE.DICT_TYPE.eq(dictTypeBo.getDictType()))); if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) { return UserConstants.NOT_UNIQUE; @@ -218,13 +271,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService @Override public String getDictLabel(String dictType, String dictValue, String separator) { // 优先从本地缓存获取 - List datas = (List) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); - if (ObjectUtil.isNull(datas)) { - datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); - SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); + List lists = (List) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); + if (ObjectUtil.isNull(lists)) { + lists = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); + SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, lists); } - Map map = StreamUtils.toMap(datas, SysDictData::getDictValue, SysDictData::getDictLabel); + Map map = StreamUtils.toMap(lists, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); if (StringUtils.containsAny(dictValue, separator)) { return Arrays.stream(dictValue.split(separator)) .map(v -> map.getOrDefault(v, StringUtils.EMPTY)) @@ -246,13 +299,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService @Override public String getDictValue(String dictType, String dictLabel, String separator) { // 优先从本地缓存获取 - List datas = (List) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); - if (ObjectUtil.isNull(datas)) { - datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); - SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); + List lists = (List) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); + if (ObjectUtil.isNull(lists)) { + lists = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); + SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, lists); } - Map map = StreamUtils.toMap(datas, SysDictData::getDictLabel, SysDictData::getDictValue); + Map map = StreamUtils.toMap(lists, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue); if (StringUtils.containsAny(dictLabel, separator)) { return Arrays.stream(dictLabel.split(separator)) .map(l -> map.getOrDefault(l, StringUtils.EMPTY)) @@ -264,7 +317,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService @Override public Map getAllDictByDictType(String dictType) { - List list = selectDictDataByType(dictType); - return StreamUtils.toMap(list, SysDictData::getDictValue, SysDictData::getDictLabel); + List list = selectDictDataByType(dictType); + return StreamUtils.toMap(list, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java index 624160a..96f03e9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java @@ -5,13 +5,13 @@ import java.util.List; import com.mybatisflex.core.paginate.Page; 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.TableSupport; import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.sql.SqlUtil; 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.vo.SysNoticeVo; import jakarta.annotation.Resource; @@ -29,7 +29,7 @@ import static com.ruoyi.system.domain.table.SysNoticeTableDef.SYS_NOTICE; * @author 数据小王子 */ @Service -public class SysNoticeServiceImpl extends ServiceImpl implements ISysNoticeService { +public class SysNoticeServiceImpl extends BaseServiceImpl implements ISysNoticeService { @Resource private SysNoticeMapper noticeMapper; @@ -53,10 +53,10 @@ public class SysNoticeServiceImpl extends ServiceImpl selectConfigPage(SysNoticeBo noticeBo) { + public TableDataInfo selectPage(SysNoticeBo noticeBo) { QueryWrapper queryWrapper = buildQueryWrapper(noticeBo); PageDomain pageDomain = TableSupport.buildPageRequest(); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java index af76bc8..b466236 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java @@ -5,12 +5,12 @@ import java.util.List; import com.mybatisflex.core.paginate.Page; 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.TableSupport; import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.sql.SqlUtil; 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.vo.SysPostVo; import jakarta.annotation.Resource; @@ -31,7 +31,7 @@ import static com.ruoyi.system.domain.table.SysPostTableDef.SYS_POST; * @author ruoyi */ @Service -public class SysPostServiceImpl extends ServiceImpl implements ISysPostService +public class SysPostServiceImpl extends BaseServiceImpl implements ISysPostService { @Resource private SysPostMapper postMapper; @@ -47,10 +47,10 @@ public class SysPostServiceImpl extends ServiceImpl imp /** * 根据postBo构建QueryWrapper查询条件 * @param postBo - * @return + * @return 查询条件 */ private QueryWrapper buildQueryWrapper(SysPostBo postBo) { - QueryWrapper queryWrapper = query(); + QueryWrapper queryWrapper = super.buildBaseQueryWrapper(); PageDomain pageDomain = TableSupport.buildPageRequest(); if (StringUtils.isNotEmpty(postBo.getPostCode())) { @@ -90,7 +90,7 @@ public class SysPostServiceImpl extends ServiceImpl imp * @return 公告集合 */ @Override - public TableDataInfo selectConfigPage(SysPostBo postBo) { + public TableDataInfo selectPage(SysPostBo postBo) { QueryWrapper queryWrapper = buildQueryWrapper(postBo); PageDomain pageDomain = TableSupport.buildPageRequest(); diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictDataMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictDataMapper.xml index a195ee3..8fe1dd8 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictDataMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictDataMapper.xml @@ -24,94 +24,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from sys_dict_data - - - - - - - - - - - delete from sys_dict_data where dict_code = #{dictCode} - - - - delete from sys_dict_data where dict_code in - - #{dictCode} - - - - - update sys_dict_data - - dict_sort = #{dictSort}, - dict_label = #{dictLabel}, - dict_value = #{dictValue}, - dict_type = #{dictType}, - css_class = #{cssClass}, - list_class = #{listClass}, - is_default = #{isDefault}, - remark = #{remark}, - update_by = #{updateBy}, - update_time = sysdate() - - where dict_code = #{dictCode} - - - - update sys_dict_data set dict_type = #{newDictType} where dict_type = #{oldDictType} - - - - insert into sys_dict_data( - dict_sort, - dict_label, - dict_value, - dict_type, - css_class, - list_class, - is_default, - remark, - create_by, - create_time - )values( - #{dictSort}, - #{dictLabel}, - #{dictValue}, - #{dictType}, - #{cssClass}, - #{listClass}, - #{isDefault}, - #{remark}, - #{createBy}, - sysdate() - ) - diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictTypeMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictTypeMapper.xml index 5f738b0..a3fc50c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictTypeMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictTypeMapper.xml @@ -19,80 +19,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from sys_dict_type - - - - - - - - - - - - delete from sys_dict_type where dict_id = #{dictId} - - - - delete from sys_dict_type where dict_id in - - #{dictId} - - - - - update sys_dict_type - - dict_name = #{dictName}, - dict_type = #{dictType}, - remark = #{remark}, - update_by = #{updateBy}, - update_time = sysdate() - - where dict_id = #{dictId} - - - - insert into sys_dict_type( - dict_name, - dict_type, - remark, - create_by, - create_time - )values( - #{dictName}, - #{dictType}, - #{remark}, - #{createBy}, - sysdate() - ) - -