1. 添加部分缓存

This commit is contained in:
zhaowenyuan 2024-06-27 15:17:47 +08:00
parent bff0c4a125
commit 93120f3778
4 changed files with 20 additions and 4 deletions

View File

@ -133,7 +133,8 @@ public class WrkInfoPhoneServiceImpl extends ServiceImpl<WrkInfoPhoneMapper, Wrk
* 导入成功
*/
@Transactional
public Result<String> savePhoneInfo(String params){
public Result<String> savePhoneInfo(String params)
{
if (StringUtils.isEmpty(params)){
return Result.failed("获取信息为空");
}
@ -209,7 +210,7 @@ public class WrkInfoPhoneServiceImpl extends ServiceImpl<WrkInfoPhoneMapper, Wrk
}
// 去获取唯一的 store 集合
}
wrkInfoPhone.setDeptId(SecurityContextHolder.getDeptId());
successList.add(wrkInfoPhone);
}
}
@ -234,12 +235,13 @@ public class WrkInfoPhoneServiceImpl extends ServiceImpl<WrkInfoPhoneMapper, Wrk
return Result.ok("success");
}
private WrkInfoPhone convert(WrkInfoPhoneImportDTO wrkInfoPhoneImportDTO, Map<String, Long> idByUsernames) {
private WrkInfoPhone convert(WrkInfoPhoneImportDTO wrkInfoPhoneImportDTO, Map<String, Long> idByUsernames)
{
WrkInfoPhone wrkInfoPhone = new WrkInfoPhone();
wrkInfoPhone.setDelState(false);
// 理论上这个应该是框架 进行赋值的
String userName = wrkInfoPhoneImportDTO.getUserName();
wrkInfoPhone.setDeptId(SecurityContextHolder.getDeptId());
wrkInfoPhone.setUserId(idByUsernames.get(userName));
wrkInfoPhone.setUserName(userName);
wrkInfoPhone.setWrkStatus(1);

View File

@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.cache.annotation.CacheRemove;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;

View File

@ -8,6 +8,8 @@ import com.chushang.common.core.web.AjaxResult;
import com.chushang.security.utils.SecurityUtils;
import com.chushang.system.entity.dto.ListUserDTO;
import com.chushang.security.entity.po.SysUser;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import java.util.Collection;
import java.util.Map;

View File

@ -20,9 +20,13 @@ import com.chushang.system.entity.po.SysUserRole;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.cache.annotation.CacheRemove;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collection;
@ -40,6 +44,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
@Service
@CacheConfig(cacheNames = "user")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
@Autowired
@ -102,6 +107,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@Transactional
@CacheEvict(allEntries = true)
public void saveUser(SysUser user) {
SpringUtils.getAopProxy(this).checkUsernameUnique(user.getUsername());
@ -123,6 +129,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
@Override
@Transactional
@CacheEvict(allEntries = true)
public void update(SysUser user) {
if(StringUtils.isBlank(user.getPassword())){
user.setPassword(null);
@ -136,6 +144,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@Transactional
@CacheEvict(allEntries = true)
public void deleteBatch(Collection<Long> userIds) {
for (Long userId : userIds)
@ -231,6 +240,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* 根据 userName 获取 用户id
*/
@Override
@Cacheable("getIdByUsernames")
public Map<String, Long> getIdByUsernames(Collection<String> userNames) {
List<SysUser> list = list(new LambdaQueryWrapper<SysUser>()
.in(SysUser::getUsername, userNames));
@ -242,6 +252,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
@Override
@Cacheable("getIdByNicknames")
public Map<String, Long> getIdByNicknames(Collection<String> nickNames) {
List<SysUser> list = list(new LambdaQueryWrapper<SysUser>()
.in(SysUser::getNickName, nickNames));