patch: 日志修补,缓存模块,标准化开发

This commit is contained in:
筱锋xiao_lfeng 2024-01-23 19:16:45 +08:00
parent 4adf738e5d
commit 8ff0c29374
Signed by: XiaoLFeng
GPG Key ID: F693AA12AABBFA87
3 changed files with 59 additions and 28 deletions

View File

@ -9,9 +9,9 @@ import com.jsl.oa.model.doData.RoleUserDO;
import com.jsl.oa.utils.redis.RoleRedisUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@ -22,24 +22,18 @@ public class RoleDAO {
private final Gson gson;
private final RoleRedisUtil<String> roleRedisUtil;
public void roleAddUser(Long uid, Long rid) {
log.info("\t> 执行 DAO 层 RoleDAO.roleAddUser 方法");
public void addRoleUser(Long uid, Long rid) {
log.info("\t> 执行 DAO 层 RoleDAO.addRoleUser 方法");
log.info("\t\t> 从 MySQL 获取数据");
roleMapper.roleAddUser(uid, rid);
roleRedisUtil.setData(BusinessConstants.USER, uid.toString(), gson.toJson(roleMapper.getRoleUserByUid(uid)), 120);
}
public void roleRemoveUser(Long uid) {
log.info("\t> 执行 DAO 层 RoleDAO.roleRemoveUser 方法");
public void delRoleUser(Long uid) {
log.info("\t> 执行 DAO 层 RoleDAO.delRoleUser 方法");
log.info("\t\t> 从 MySQL 获取数据");
roleMapper.roleRemoveUser(uid);
}
public List<RoleDO> getRolesById(String id) {
log.info("\t> 执行 DAO 层 RoleDAO.getRolesById 方法");
ArrayList<RoleDO> getRoleList = new ArrayList<>();
log.info("\t\t> 从 MySQL 获取数据");
getRoleList.add(roleMapper.getRoleById(Long.valueOf(id)));
return getRoleList;
roleRedisUtil.delData(BusinessConstants.USER, uid.toString());
}
public RoleDO getRoleById(Long id) {
@ -79,7 +73,7 @@ public class RoleDAO {
log.info("\t\t> 从 MySQL 获取数据");
roleMapper.roleAdd(roleDO);
List<RoleDO> roleList = roleMapper.getRole();
roleRedisUtil.setData(BusinessConstants.NONE, "all", gson.toJson(roleList), 1440);
roleRedisUtil.setData(BusinessConstants.NONE, "all", gson.toJson(roleList), 120);
}
@ -114,15 +108,26 @@ public class RoleDAO {
return roleDO != null;
}
public boolean roleChangeUser(Long uid, Long rid) {
public boolean roleChangeUser(@NotNull Long uid, Long rid) {
log.info("\t> 执行 DAO 层 RoleDAO.roleChangeUser 方法");
log.info("\t\t> 从 MySQL 获取数据");
return roleMapper.roleChangeUser(uid, rid);
if (roleMapper.roleChangeUser(uid, rid)) {
roleRedisUtil.setData(BusinessConstants.USER, uid.toString(), gson.toJson(roleMapper.getRoleUserByUid(uid)), 120);
return true;
} else {
return false;
}
}
public RoleUserDO getRoleUserByUid(Long uid) {
public RoleUserDO getRoleUserByUid(@NotNull Long uid) {
log.info("\t> 执行 DAO 层 RoleDAO.getRoleUserByUid 方法");
log.info("\t\t> 从 MySQL 获取数据");
return roleMapper.getRoleUserByUid(uid);
String getRedisData = roleRedisUtil.getData(BusinessConstants.USER, uid.toString());
if (getRedisData == null) {
log.info("\t\t> 从 MySQL 获取数据");
return roleMapper.getRoleUserByUid(uid);
} else {
log.info("\t\t> 从 Redis 获取数据");
return gson.fromJson(getRedisData, RoleUserDO.class);
}
}
}

View File

@ -12,6 +12,13 @@ import org.apache.ibatis.annotations.Update;
import java.util.List;
/**
* <h1>用户 Mapper</h1>
* <hr/>
* 用于用户的增删改查
*
* @author xiao_lfeng | 176yunxuan | xiangZr-hhh
*/
@Mapper
public interface UserMapper {
@ -74,7 +81,6 @@ public interface UserMapper {
"signature = #{signature}, sex = #{sex}, avatar = #{avatar}, nickname = #{nickname}, " +
"description = #{description} ,updated_at = current_timestamp " +
"WHERE id = #{id}")
void updateUser(UserDO userDO);
@Select("SELECT * FROM organize_oa.oa_user WHERE email = #{email}")

View File

@ -19,6 +19,18 @@ import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.regex.Pattern;
/**
* <h1>权限服务层实现类</h1>
* <hr/>
* 用于权限服务层的实现类,实现权限的增删改查,以及用户权限的获取
*
* @since v1.1.0
* @version v1.1.0
* @see com.jsl.oa.services.RoleService
* @see com.jsl.oa.dao.RoleDAO
* @see com.jsl.oa.dao.UserDAO
* @author xiao_lfeng | 176yunxuan | xiangZr-hhh
*/
@Slf4j
@Service
@RequiredArgsConstructor
@ -29,20 +41,24 @@ public class RoleServiceImpl implements RoleService {
@Override
public BaseResponse roleAddUser(HttpServletRequest request, Long uid, Long rid) {
log.info("\t> 执行 Service 层 RoleService.roleAddUser 方法");
log.info("\t> 执行 Service 层 RoleService.addRoleUser 方法");
if (Processing.checkUserIsAdmin(request, roleDAO.roleMapper)) {
roleDAO.roleAddUser(uid, rid);
roleDAO.addRoleUser(uid, rid);
return ResultUtil.success();
} else return ResultUtil.error(ErrorCode.NOT_ADMIN);
} else {
return ResultUtil.error(ErrorCode.NOT_ADMIN);
}
}
@Override
public BaseResponse roleRemoveUser(HttpServletRequest request, Long uid) {
log.info("\t> 执行 Service 层 RoleService.roleRemoveUser 方法");
log.info("\t> 执行 Service 层 RoleService.delRoleUser 方法");
if (Processing.checkUserIsAdmin(request, roleDAO.roleMapper)) {
roleDAO.roleRemoveUser(uid);
roleDAO.delRoleUser(uid);
return ResultUtil.success();
} else return ResultUtil.error(ErrorCode.NOT_ADMIN);
} else {
return ResultUtil.error(ErrorCode.NOT_ADMIN);
}
}
@Override
@ -63,7 +79,9 @@ public class RoleServiceImpl implements RoleService {
} else {
return ResultUtil.error(ErrorCode.PLEASE_ASSIGN_ROLE_TO_USER);
}
} else return ResultUtil.error(ErrorCode.NOT_ADMIN);
} else {
return ResultUtil.error(ErrorCode.NOT_ADMIN);
}
}
@Override
@ -77,7 +95,9 @@ public class RoleServiceImpl implements RoleService {
ArrayList<RoleDO> getRoleList;
if (id != null && !id.isEmpty()) {
if (Pattern.matches("^[0-9]+$", id)) {
getRoleList = (ArrayList<RoleDO>) roleDAO.getRolesById(id);
RoleDO getRole = roleDAO.getRoleById(Long.valueOf(id));
getRoleList = new ArrayList<>();
getRoleList.add(getRole);
} else {
ArrayList<String> error = new ArrayList<>();
error.add("id 只能为数字");