add 新增 翻译模块 部门名称翻译

update 优化 部门业务增加缓存逻辑
feature/model
疯狂的狮子li 2 years ago
parent fdc6c89bc2
commit 234f74f8f0

@ -35,6 +35,11 @@ public interface CacheNames {
*/
String SYS_USER_NAME = "sys_user_name#30d";
/**
*
*/
String SYS_DEPT = "sys_dept#30d";
/**
* OSS
*/

@ -0,0 +1,18 @@
package com.ruoyi.common.core.service;
/**
*
*
* @author Lion Li
*/
public interface DeptService {
/**
* ID
*
* @param deptIds ID
* @return
*/
String selectDeptNameByIds(String deptIds);
}

@ -10,16 +10,21 @@ public interface TransConstant {
/**
* id
*/
String USER_ID_TO_NAME = "userIdToName";
String USER_ID_TO_NAME = "user_id_to_name";
/**
* id
*/
String DEPT_ID_TO_NAME = "dept_id_to_name";
/**
* typelabel
*/
String DICT_TYPE_TO_LABEL = "dictTypeToLabel";
String DICT_TYPE_TO_LABEL = "dict_type_to_label";
/**
* ossIdurl
*/
String OSS_ID_TO_URL = "ossIdToUrl";
String OSS_ID_TO_URL = "oss_id_to_url";
}

@ -10,7 +10,7 @@ public interface TranslationInterface {
/**
*
*
* @param key
* @param key ()
* @return
*/
String translation(Object key, String other);

@ -0,0 +1,30 @@
package com.ruoyi.common.translation.core.impl;
import com.ruoyi.common.core.service.DeptService;
import com.ruoyi.common.translation.annotation.TranslationType;
import com.ruoyi.common.translation.constant.TransConstant;
import com.ruoyi.common.translation.core.TranslationInterface;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
/**
*
*
* @author Lion Li
*/
@Component
@AllArgsConstructor
@TranslationType(type = TransConstant.DEPT_ID_TO_NAME)
public class DeptNameTranslationImpl implements TranslationInterface {
private final DeptService deptService;
public String translation(Object key, String other) {
if (key instanceof String ids) {
return deptService.selectDeptNameByIds(ids);
} else if (key instanceof Long id) {
return deptService.selectDeptNameByIds(id.toString());
}
return null;
}
}

@ -8,15 +8,19 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.constant.CacheNames;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.SysRole;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.mybatis.helper.DataBaseHelper;
import com.ruoyi.common.satoken.utils.LoginHelper;
import com.ruoyi.common.core.service.DeptService;
import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.TreeBuildUtils;
import com.ruoyi.common.mybatis.helper.DataBaseHelper;
import com.ruoyi.common.redis.utils.CacheUtils;
import com.ruoyi.common.satoken.utils.LoginHelper;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.SysRole;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.bo.SysDeptBo;
import com.ruoyi.system.domain.vo.SysDeptVo;
import com.ruoyi.system.mapper.SysDeptMapper;
@ -24,6 +28,8 @@ import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -37,7 +43,7 @@ import java.util.List;
*/
@RequiredArgsConstructor
@Service
public class SysDeptServiceImpl implements ISysDeptService {
public class SysDeptServiceImpl implements ISysDeptService, DeptService {
private final SysDeptMapper baseMapper;
private final SysRoleMapper roleMapper;
@ -117,6 +123,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param deptId ID
* @return
*/
@Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
@Override
public SysDeptVo selectDeptById(Long deptId) {
SysDeptVo dept = baseMapper.selectVoById(deptId);
@ -126,6 +133,24 @@ public class SysDeptServiceImpl implements ISysDeptService {
return dept;
}
/**
* ID
*
* @param deptIds ID
* @return
*/
@Override
public String selectDeptNameByIds(String deptIds) {
List<String> list = new ArrayList<>();
for (Long id : Arrays.stream(deptIds.split(",")).map(Long::parseLong).toList()) {
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(id);
if (ObjectUtil.isNotNull(vo)) {
list.add(vo.getDeptName());
}
}
return String.join(",", list);
}
/**
* ID
*
@ -222,6 +247,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param bo
* @return
*/
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId")
@Override
public int updateDept(SysDeptBo bo) {
SysDept dept = BeanUtil.toBean(bo, SysDept.class);
@ -273,7 +299,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
list.add(dept);
}
if (CollUtil.isNotEmpty(list)) {
baseMapper.updateBatchById(list);
if (baseMapper.updateBatchById(list)) {
list.forEach(dept -> CacheUtils.evict(CacheNames.SYS_DEPT, dept.getDeptId()));
}
}
}
@ -283,6 +311,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param deptId ID
* @return
*/
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
@Override
public int deleteDeptById(Long deptId) {
return baseMapper.deleteById(deptId);

Loading…
Cancel
Save