Backend Development 23 min read

Java Backend Project for Community COVID‑19 Management System with RBAC and Service Layer Implementation

This article presents a complete Java backend project for community‑based COVID‑19 management, detailing its architecture, modules such as login, daily epidemic tracking, prevention management, system administration and user management, and provides extensive SpringBoot service‑layer code examples with RBAC permission control.

Architect's Guide
Architect's Guide
Architect's Guide
Java Backend Project for Community COVID‑19 Management System with RBAC and Service Layer Implementation

Project introduction: a community‑level COVID‑19 management system built with IDEA, MySQL, Tomcat, Spring MVC, Spring Boot, AOP, interceptors, filters, global exception handling and RBAC permission control.

1. Login module (registration)

Core service‑layer code for user login, password validation, registration and password update, including parameter checks and transaction management.

@Service
public class UserService extends BaseService
{
@Resource
private UserMapper userMapper;
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private CommunityMapper communityMapper;
// User login
public UserModel userLogin(String userName, String userPwd){
checkUserLoginParam(userName,userPwd);
User temp = userMapper.queryUserByUserName(userName);
AssertUtil.isTrue(temp == null,"用户不存在");
checkUserPwd(userPwd,temp.getUserPwd());
return builderUserInfo(temp);
}
private void checkUserLoginParam(String userName, String userPwd) {
AssertUtil.isTrue(StringUtils.isBlank(userName),"用户名不能为空");
AssertUtil.isTrue(StringUtils.isBlank(userPwd),"密码不能为空");
}
private void checkUserPwd(String userPwd, String userPwd1) {
userPwd = Md5Util.encode(userPwd);
AssertUtil.isTrue(!(userPwd.equals(userPwd1)),"密码不正确");
}
private UserModel builderUserInfo(User temp) {
UserModel userModel = new UserModel();
userModel.setUserIdStr(UserIDBase64.encoderUserID(temp.getId()));
userModel.setUserName(temp.getUserName());
userModel.setTrueName(temp.getTrueName());
return userModel;
}
@Transactional(propagation = Propagation.REQUIRED)
public void updateUserPassword(Integer userId, String oldPassword, String newPassword, String confirmPassword) {
User user = userMapper.selectByPrimaryKey(userId);
        checkPasswordParams(user,oldPassword,newPassword,confirmPassword);
        user.setUserPwd(Md5Util.encode(newPassword));
        AssertUtil.isTrue(userMapper.updateByPrimaryKeySelective(user)<1,"修改密码失败");
    }
private void checkPasswordParams(User user, String oldPassword, String newPassword, String confirmPwd) {
AssertUtil.isTrue(user == null,"用户不存在");
        AssertUtil.isTrue(StringUtils.isBlank(oldPassword),"原始密码不能为空");
        AssertUtil.isTrue(!(Md5Util.encode(oldPassword).equals(user.getUserPwd())),"原始密码不正确");
        AssertUtil.isTrue(StringUtils.isBlank(newPassword),"新密码不能为空");
        AssertUtil.isTrue(oldPassword.equals(newPassword),"新密码不能和原始密码相同");
        AssertUtil.isTrue(StringUtils.isBlank(confirmPwd),"确认密码不能为空");
        AssertUtil.isTrue(!(newPassword.equals(confirmPwd)),"新密码和确认密码不一致");
    }
public Map
queryUserByParams(UserQuery query) {
Map
map = new HashMap<>();
PageHelper.startPage(query.getPage(), query.getLimit());
PageInfo
pageInfo = new PageInfo<>(userMapper.selectByParams(query));
map.put("code",0); map.put("msg",""); map.put("count",pageInfo.getTotal()); map.put("data",pageInfo.getList());
return map;
}
// Additional CRUD methods (saveUser, updateUser, deleteUser, registerUser, etc.) follow the same pattern with validation and transaction handling.

2. Daily epidemic module

Service code for handling confirmed cases, including pagination, role‑based queries, adding, updating and deleting confirmed users, and community statistics.

@Service
public class ConfirmedService extends BaseService
{
@Resource private ConfirmedMapper confirmedMapper;
@Resource private UserMapper userMapper;
@Resource private CommunityMapper communityMapper;
public Map
findRoleByParam(ConfirmedQuery confirmedQuery){
Map
map = new HashMap<>();
PageHelper.startPage(confirmedQuery.getPage(), confirmedQuery.getLimit());
PageInfo
rlist = new PageInfo<>(selectByParams(confirmedQuery));
map.put("code",0); map.put("msg","success"); map.put("count",rlist.getTotal()); map.put("data",rlist.getList());
return map;
}
@Transactional(propagation = Propagation.REQUIRED)
public void addUser(Confirmed user) {
checkConfirmed(user.getTrueName(),user.getState());
// map community names to IDs
// ... (logic omitted for brevity) ...
// Insert or update user record and link to confirmed entry
AssertUtil.isTrue(insertSelective(user)<1,"添加失败");
}
@Transactional(propagation = Propagation.REQUIRED)
public void changeUser(Confirmed user) {
Confirmed temp = confirmedMapper.selectByPrimaryKey(user.getId());
AssertUtil.isTrue(temp == null,"当前用户不存在");
changeConfirmed(user.getTrueName(),user.getTcPhone(),user.getState());
AssertUtil.isTrue(confirmedMapper.uBPKS(user)<1,"修改失败了");
}
// Parameter validation methods omitted for brevity

3. Prevention management module

Service for community queries, role retrieval, and vaccination record management with pagination and CRUD operations.

@Service
public class CommunityService extends BaseService
{
@Resource private CommunityMapper communityMapper;
public Map
queryComByParams(CommunityQuery query){
Map
map = new HashMap<>();
PageHelper.startPage(query.getPage(), query.getLimit());
PageInfo
pageInfo = new PageInfo<>(communityMapper.selectByParams(query));
map.put("code",0); map.put("msg",""); map.put("count",pageInfo.getTotal()); map.put("data",pageInfo.getList());
return map;
}
public List
> findRoles(Integer userId){ return communityMapper.selectRoles(userId); }
}
@Service
public class VaccinationService {
@Resource VaccinationMapper vaccinationMapper;
public Map
selectAll(VaccinationQuery vaccinationQuery){
Map
map = new HashMap<>();
PageHelper.startPage(vaccinationQuery.getPage(),vaccinationQuery.getLimit());
PageInfo
pageInfo = new PageInfo<>(vaccinationMapper.selectByParams(vaccinationQuery));
map.put("code",0); map.put("msg","success"); map.put("data",pageInfo.getList()); map.put("count",pageInfo.getTotal());
return map;
}
@Transactional(propagation = Propagation.REQUIRED)
public void insertVaccination(Vaccination vaccination){
        checkOK(vaccination);
        vaccination.setFirstDate(new Date());
        vaccination.setSecondDate(new Date());
        AssertUtil.isTrue(vaccinationMapper.insertSelective(vaccination)<1,"插入失败");
    }
private void checkOK(Vaccination v){
        AssertUtil.isTrue(v==null,"请输入添加的角色");
        AssertUtil.isTrue(StringUtils.isBlank(v.getTrueName()),"用户名不能为空");
        AssertUtil.isTrue(StringUtils.isBlank(v.getFirst()),"请填写(是/否)");
        AssertUtil.isTrue(StringUtils.isBlank(v.getSecond()),"请填写(是/否)");
    }
// update and delete methods follow the same validation pattern
}

4. System management module

Role service handling role CRUD, permission assignment, and role‑based permission cleanup with transactional safety.

@Service
public class RoleService extends BaseService
{
@Autowired(required = false) RoleMapper roleMapper;
@Autowired(required = false) RoleQuery roleQuery;
@Resource private ModuleMapper moduleMapper;
@Resource private PermissionMapper permissionMapper;
public Map
selectRole(RoleQuery roleQuery){
        Map
map = new HashMap<>();
        PageHelper.startPage(roleQuery.getPage(),roleQuery.getLimit());
        PageInfo
pageInfo = new PageInfo<>(roleMapper.selectByParams(roleQuery));
        map.put("code",0); map.put("msg","success"); map.put("data",pageInfo.getList()); map.put("count",pageInfo.getTotal());
        return map;
    }
@Transactional(propagation = Propagation.REQUIRED)
    public void insertRole(Role role){
        checkRole(role);
        role.setCreateDate(new Date());
        role.setUpdateDate(new Date());
        AssertUtil.isTrue(insertSelective(role)<1,"添加失败了呢~");
    }
private void checkRole(Role role){
        AssertUtil.isTrue(role==null,"请输入角色信息~");
        Role existing = roleMapper.selectByName(role.getRoleName());
        AssertUtil.isTrue(existing!=null,"已添加过啦~");
    }
@Transactional(propagation = Propagation.REQUIRED)
    public void addGrant(Integer[] mids, Integer roleId){
        AssertUtil.isTrue(roleId==null || roleMapper.selectByPrimaryKey(roleId)==null,"待授权的角色不存在");
        int count = roleMapper.countPermissionByRoleId(roleId);
        if(count>0){
            int removed = roleMapper.deletePermissionsByRoleId(roleId);
            AssertUtil.isTrue(count!=removed,"资源删除失败");
        }
        List
plist = new ArrayList<>();
        if(mids!=null && mids.length!=0){
            for(Integer mid : mids){
                Permission p = new Permission();
                p.setRoleId(roleId);
                p.setModuleId(mid);
                p.setAclValue(moduleMapper.selectByPrimaryKey(mid).getOptValue());
                p.setCreateDate(new Date());
                p.setUpdateDate(new Date());
                plist.add(p);
            }
        }
        AssertUtil.isTrue(permissionMapper.insertBatch(plist)!=plist.size(),"角色权限更新失败");
    }
}

5. User module

Repeats the role service implementation for user‑related role management, demonstrating consistent CRUD and permission‑grant patterns.

The article concludes with promotional messages encouraging readers to follow the public account, like the post, and request additional Java learning resources.

backendJavaMySQLSpringBootRBACServiceLayer
Architect's Guide
Written by

Architect's Guide

Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.