diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java index d4b1b995f..9792b390d 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java @@ -2,7 +2,6 @@ package cn.iocoder.mall.admin.application; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.admin"}) @@ -10,14 +9,7 @@ import org.springframework.scheduling.annotation.EnableAsync; public class SystemApplication { public static void main(String[] args) { - ConfigurableApplicationContext ctx = SpringApplication.run(SystemApplication.class, args); -// Object bean = ctx.getBean("test"); -// System.out.println(AopUtils.getTargetClass(bean)); - -// System.out.println(bean); - -// ConfigurableApplicationContext ctx = -// System.out.println(); // TODO 后面去掉,这里是临时的 + SpringApplication.run(SystemApplication.class, args); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java index 1af446e62..59b64fa44 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java @@ -7,14 +7,12 @@ import cn.iocoder.mall.admin.api.dto.datadict.DataDictAddDTO; import cn.iocoder.mall.admin.api.dto.datadict.DataDictUpdateDTO; import cn.iocoder.mall.admin.application.convert.DataDictConvert; import cn.iocoder.mall.admin.application.vo.datadict.DataDictEnumVO; -import cn.iocoder.mall.admin.application.vo.datadict.DataDictVO; import cn.iocoder.mall.admin.sdk.annotation.RequiresPermissions; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Multimaps; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; import org.springframework.web.bind.annotation.*; @@ -22,6 +20,8 @@ import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping("admins/data_dict") @Api("数据字典模块") @@ -33,9 +33,8 @@ public class DataDictController { @GetMapping("/list") @ApiOperation(value = "数据字典全列表") @RequiresPermissions("system.dataDict.list") - public CommonResult> list() { - CommonResult> result = dataDictService.selectDataDictList(); - return DataDictConvert.INSTANCE.convert(result); + public CommonResult> list() { + return success( dataDictService.selectDataDictList()); } @GetMapping("/tree") @@ -43,12 +42,9 @@ public class DataDictController { @ApiOperation(value = "数据字典树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。") public CommonResult> tree() { // 查询数据字典全列表 - CommonResult> result = dataDictService.selectDataDictList(); - if (result.isError()) { - return CommonResult.error(result); - } + List dataDicts = dataDictService.selectDataDictList(); // 构建基于 enumValue 聚合的 Multimap - ImmutableListMultimap dataDictMap = Multimaps.index(result.getData(), DataDictBO::getEnumValue); // KEY 是 enumValue ,VALUE 是 DataDictBO 数组 + ImmutableListMultimap dataDictMap = Multimaps.index(dataDicts, DataDictBO::getEnumValue); // KEY 是 enumValue ,VALUE 是 DataDictBO 数组 // 构建返回结果 List dataDictEnumVOs = new ArrayList<>(dataDictMap.size()); dataDictMap.keys().forEach(enumValue -> { @@ -56,53 +52,21 @@ public class DataDictController { .setValues(DataDictConvert.INSTANCE.convert2(dataDictMap.get(enumValue))); dataDictEnumVOs.add(dataDictEnumVO); }); - return CommonResult.success(dataDictEnumVOs); + return success(dataDictEnumVOs); } @PostMapping("/add") @RequiresPermissions("system.dataDict.add") @ApiOperation(value = "创建数据字典") - @ApiImplicitParams({ - @ApiImplicitParam(name = "enumValue", value = "大类枚举值", required = true, example = "gender"), - @ApiImplicitParam(name = "value", value = "小类数值", required = true, example = "1"), - @ApiImplicitParam(name = "displayName", value = "展示名", required = true, example = "男"), - @ApiImplicitParam(name = "sort", required = true, value = "排序值", defaultValue = "10"), - @ApiImplicitParam(name = "memo", value = "备注", example = "你猜我猜不猜"), - }) - public CommonResult add(@RequestParam("enumValue") String enumValue, - @RequestParam("value") String value, - @RequestParam("displayName") String displayName, - @RequestParam("sort") Integer sort, - @RequestParam(value = "memo", required = false) String memo) { - // 创建 DataDictAddDTO 对象 - DataDictAddDTO dataDictAddDTO = new DataDictAddDTO().setEnumValue(enumValue).setValue(value).setDisplayName(displayName) - .setSort(sort).setMemo(memo); - // 保存数据字典 - CommonResult result = dataDictService.addDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictAddDTO); - // 返回结果 - return DataDictConvert.INSTANCE.convert2(result); + public CommonResult add(DataDictAddDTO dataDictAddDTO) { + return success(dataDictService.addDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictAddDTO)); } @PostMapping("/update") @RequiresPermissions("system.dataDict.update") @ApiOperation(value = "更新数据字典") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "100"), - @ApiImplicitParam(name = "value", value = "小类数值", required = true, example = "1"), - @ApiImplicitParam(name = "displayName", value = "展示名", required = true, example = "男"), - @ApiImplicitParam(name = "sort", required = true, value = "排序值", defaultValue = "10"), - @ApiImplicitParam(name = "memo", value = "备注", example = "你猜我猜不猜"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("value") String value, - @RequestParam("displayName") String displayName, - @RequestParam("sort") Integer sort, - @RequestParam(value = "memo", required = false) String memo) { - // 创建 DataDictAddDTO 对象 - DataDictUpdateDTO dataDictUpdateDTO = new DataDictUpdateDTO().setId(id).setValue(value).setDisplayName(displayName) - .setSort(sort).setMemo(memo); - // 更新数据字典 - return dataDictService.updateDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictUpdateDTO); + public CommonResult update(DataDictUpdateDTO dataDictUpdateDTO) { + return success(dataDictService.updateDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictUpdateDTO)); } @PostMapping("/delete") @@ -110,7 +74,7 @@ public class DataDictController { @ApiOperation(value = "删除数据字典") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "100") public CommonResult delete(@RequestParam("id") Integer id) { - return dataDictService.deleteDataDict(AdminSecurityContextHolder.getContext().getAdminId(), id); + return success(dataDictService.deleteDataDict(AdminSecurityContextHolder.getContext().getAdminId(), id)); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java index 8d875c4d9..c9b8a867f 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java @@ -1,9 +1,7 @@ package cn.iocoder.mall.admin.application.convert; -import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; -import cn.iocoder.mall.admin.application.vo.datadict.DataDictVO; -import cn.iocoder.mall.admin.application.vo.datadict.DataDictValueVO; +import cn.iocoder.mall.admin.application.vo.datadict.DataDictEnumVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -16,18 +14,6 @@ public interface DataDictConvert { DataDictConvert INSTANCE = Mappers.getMapper(DataDictConvert.class); @Mappings({}) - DataDictVO convert(DataDictBO dataDictBO); - - @Mappings({}) - List convert(List dataDictBOs); - - @Mappings({}) - CommonResult> convert(CommonResult> result); - - @Mappings({}) - CommonResult convert2(CommonResult result); - - @Mappings({}) - List convert2(List dataDictBOs); + List convert2(List dataDictBOs); } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java index d9814747b..936b0496e 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java @@ -14,7 +14,21 @@ public class DataDictEnumVO { @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") private String enumValue; + @ApiModelProperty(value = "小类数值数组", required = true) - private List values; + private List values; + + @ApiModel("数据字典枚举值 VO") + @Data + @Accessors(chain = true) + public static class Value { + + @ApiModelProperty(value = "小类数值", required = true, example = "1") + private String value; + + @ApiModelProperty(value = "展示名", required = true, example = "男") + private String displayName; + + } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java deleted file mode 100644 index 1524ce4c6..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.admin.application.vo.datadict; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -@ApiModel("数据字典 VO") -@Data -@Accessors(chain = true) -public class DataDictVO { - - @ApiModelProperty(value = "编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") - private String enumValue; - @ApiModelProperty(value = "小类数值", required = true, example = "1") - private String value; - @ApiModelProperty(value = "展示名", required = true, example = "男") - private String displayName; - @ApiModelProperty(value = "排序值", required = true, example = "10") - private Integer sort; - @ApiModelProperty(value = "备注", example = "你猜") - private String memo; - -} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java deleted file mode 100644 index 7ed6eeff4..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.mall.admin.application.vo.datadict; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -@ApiModel("数据字典枚举值 VO") -@Data -@Accessors(chain = true) -public class DataDictValueVO { - - @ApiModelProperty(value = "小类数值", required = true, example = "1") - private String value; - @ApiModelProperty(value = "展示名", required = true, example = "男") - private String displayName; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java index 7d92b8bee..2d3da6bd3 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java @@ -10,13 +10,13 @@ import java.util.List; public interface DataDictService { - CommonResult> selectDataDictList(); + List selectDataDictList(); - CommonResult addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO); + DataDictBO addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO); - CommonResult updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO); + Boolean updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO); - CommonResult deleteDataDict(Integer adminId, Integer dataDictId); + Boolean deleteDataDict(Integer adminId, Integer dataDictId); /** * 获取字典值 - 单个 @@ -28,6 +28,7 @@ public interface DataDictService { * @return */ CommonResult getDataDict(String dictKey, Object dictValue); + CommonResult> getDataDict(String dictKey); /** diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java index 574a66ae5..378dc5bcb 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.admin.api.dto.datadict; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -7,36 +9,28 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.Serializable; -/** - * 数据字典添加 DTO - */ +@ApiModel("数据字典添加 DTO") @Data @Accessors(chain = true) public class DataDictAddDTO implements Serializable { - /** - * 大类枚举值 - */ + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") @NotEmpty(message = "大类枚举值不能为空") private String enumValue; - /** - * 小类数值 - */ + + @ApiModelProperty(value = "小类数值", required = true, example = "1") @NotEmpty(message = "小类数值不能为空") private String value; - /** - * 展示名 - */ + + @ApiModelProperty(value = "展示名", required = true, example = "男") @NotEmpty(message = "展示名不能为空") private String displayName; - /** - * 排序值 - */ + + @ApiModelProperty(required = true, value = "排序值", example = "123") @NotNull(message = "排序值不能为空") private Integer sort; - /** - * 备注 - */ + + @ApiModelProperty(value = "备注", example = "你猜我猜不猜") private String memo; } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java index 9653beb2b..bfaa8b747 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.admin.api.dto.datadict; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -14,29 +15,27 @@ import java.io.Serializable; @Accessors(chain = true) public class DataDictUpdateDTO implements Serializable { - /** - * 编号 - */ - @NotNull(message = "编号不能为空") + @ApiModelProperty(value = "数据字典编号", required = true, example = "1") + @NotNull(message = "数据字典编号不能为空") private Integer id; - /** - * 小类数值 - */ + + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + + @ApiModelProperty(value = "小类数值", required = true, example = "1") @NotEmpty(message = "小类数值不能为空") private String value; - /** - * 展示名 - */ + + @ApiModelProperty(value = "展示名", required = true, example = "男") @NotEmpty(message = "展示名不能为空") private String displayName; - /** - * 排序值 - */ + + @ApiModelProperty(required = true, value = "排序值", example = "123") @NotNull(message = "排序值不能为空") private Integer sort; - /** - * 备注 - */ + + @ApiModelProperty(value = "备注", example = "你猜我猜不猜") private String memo; } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java index 5b6e5e5f6..90bb43f15 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java @@ -1,6 +1,8 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.DataDictDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -8,9 +10,7 @@ import java.util.Collection; import java.util.List; @Repository -public interface DataDictMapper { - - DataDictDO selectById(@Param("id") Integer id); +public interface DataDictMapper extends BaseMapper { DataDictDO selectByEnumValueAndValue( @Param("enumValue") String enumValue, @@ -26,10 +26,9 @@ public interface DataDictMapper { @Param("enumValue") String enumValue ); - List selectList(); + default List selectList() { + return selectList(new QueryWrapper<>()); + } - void insert(DataDictDO dataDict); - - int update(DataDictDO dataDict); } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java index e5ad899b1..9f113ac36 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java @@ -1,13 +1,17 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.OAuth2AccessTokenDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @Repository public interface OAuth2AccessTokenMapper extends BaseMapper { - int updateToInvalidByAdminId(@Param("adminId") Integer adminId); + default int updateToInvalidByAdminId(Integer adminId) { + QueryWrapper query = new QueryWrapper() + .eq("admin_id", adminId).eq("valid", true); + return update(new OAuth2AccessTokenDO().setValid(false), query); + } } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java index a96b35456..9d9caec75 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java @@ -1,13 +1,17 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.OAuth2RefreshTokenDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @Repository public interface OAuth2RefreshTokenMapper extends BaseMapper { - int updateToInvalidByAdminId(@Param("adminId") Integer adminId); + default int updateToInvalidByAdminId(Integer adminId) { + QueryWrapper query = new QueryWrapper() + .eq("admin_id", adminId).eq("valid", true); + return update(new OAuth2RefreshTokenDO().setValid(false), query); + } } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java index e054abc3f..473065670 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java @@ -13,7 +13,7 @@ import java.util.Set; @Repository public interface ResourceMapper extends BaseMapper { - @Deprecated + // TODO 芋艿,后续改造。 List selectListByTypeAndRoleIds(@Param("type") Integer type, @Param("roleIds") Set roleIds); diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java index b65a853c0..091ed72a8 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.admin.dataobject; import cn.iocoder.common.framework.dataobject.DeletableDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; @@ -13,6 +14,7 @@ import lombok.experimental.Accessors; * value:1 男 * value:2 女 */ +@TableName("data_dict") @Data @Accessors(chain = true) public class DataDictDO extends DeletableDO { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java index 348d7bbf7..f0f566d24 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -31,16 +31,16 @@ public class DataDictServiceImpl implements DataDictService { private DataDictMapper dataDictMapper; @Override - public CommonResult> selectDataDictList() { + public List selectDataDictList() { List dataDicts = dataDictMapper.selectList(); - return CommonResult.success(DataDictConvert.INSTANCE.convert(dataDicts)); + return DataDictConvert.INSTANCE.convert(dataDicts); } @Override - public CommonResult addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO) { + public DataDictBO addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO) { // 校验数据字典重复 if (dataDictMapper.selectByEnumValueAndValue(dataDictAddDTO.getEnumValue(), dataDictAddDTO.getValue()) != null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); } // 保存到数据库 DataDictDO dataDict = DataDictConvert.INSTANCE.convert(dataDictAddDTO); @@ -49,45 +49,43 @@ public class DataDictServiceImpl implements DataDictService { dataDictMapper.insert(dataDict); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(DataDictConvert.INSTANCE.convert(dataDict)); + return DataDictConvert.INSTANCE.convert(dataDict); } @Override - public CommonResult updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO) { + public Boolean updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO) { // 校验数据字典不存在 DataDictDO existsDataDict = dataDictMapper.selectById(dataDictUpdateDTO.getId()); if (existsDataDict == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); } // 校验数据字典重复 DataDictDO duplicateDataDict = dataDictMapper.selectByEnumValueAndValue(existsDataDict.getEnumValue(), dataDictUpdateDTO.getValue()); if (duplicateDataDict != null && !duplicateDataDict.getId().equals(dataDictUpdateDTO.getId())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); } // 更新到数据库 DataDictDO updateDataDict = DataDictConvert.INSTANCE.convert(dataDictUpdateDTO); - dataDictMapper.update(updateDataDict); + dataDictMapper.updateById(updateDataDict); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } // 一般情况下,不要删除数据字典。 // 因为,业务数据正在使用该数据字典,删除后,可能有不可预知的问题。 @Override - public CommonResult deleteDataDict(Integer adminId, Integer dataDictId) { + public Boolean deleteDataDict(Integer adminId, Integer dataDictId) { // 校验数据字典不存在 DataDictDO existsDataDict = dataDictMapper.selectById(dataDictId); if (existsDataDict == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); } - // 更新到数据库 - DataDictDO updateDataDict = new DataDictDO().setId(dataDictId); - updateDataDict.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - dataDictMapper.update(updateDataDict); + // 标记删除 + dataDictMapper.deleteById(dataDictId); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @@ -106,7 +104,7 @@ public class DataDictServiceImpl implements DataDictService { @Override public CommonResult> getDataDictList(String dictKey, Collection dictValueList) { - Set convertDictValueList = dictValueList.stream().map(o -> String.valueOf(o)).collect(Collectors.toSet()); + Set convertDictValueList = dictValueList.stream().map(String::valueOf).collect(Collectors.toSet()); List dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList); List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); return CommonResult.success(dataDictBOList); diff --git a/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml b/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml index e5b588a49..546d268c2 100644 --- a/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml +++ b/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml @@ -29,21 +29,6 @@ - - - - - - INSERT INTO data_dict ( - id, enum_value, value, display_name, sort, - memo, create_time, deleted - ) VALUES ( - #{id}, #{enumValue}, #{value}, #{displayName}, #{sort}, - #{memo}, #{createTime}, #{deleted} - ) - - - - UPDATE data_dict - - - enum_value = #{enumValue}, - - - value = #{value}, - - - display_name = #{displayName}, - - - sort = #{sort}, - - - memo = #{memo}, - - - deleted = #{deleted} - - - WHERE id = #{id} - - - \ No newline at end of file + diff --git a/system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml b/system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml deleted file mode 100644 index 1497e4570..000000000 --- a/system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - UPDATE oauth2_access_token - SET valid = 0 - WHERE admin_id = #{adminId} - AND valid = 1 - - - diff --git a/system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml b/system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml deleted file mode 100644 index 1b7a70cd6..000000000 --- a/system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - UPDATE oauth2_refresh_token - SET valid = 0 - WHERE admin_id = #{adminId} - AND valid = 1 - - -