☣项目介绍:通过对依社区为单位进行人群的管理,以及疫苗的情况,包括小区状况,通过RBAC进行角色与用户之间的权限管理。
☣项目:环境-IDEA、Mysql数据库,Tomcat服务器,SpringMVC,SpringBoot,AOP,拦截器,过滤器,全局异常,RBAC权限控制等。
目录
- ☣基于java疫情防控管理系统
- 1、登录模块(注册)
- 2、今日疫情模块
- 3、防疫管理模块
- 4、系统管理模块
- 5、用户模块
1、登录模块(注册)
核心代码:service层
@Service public class UserService extends baseService{ @Resource //引入dao层 private UserMapper userMapper; @Resource private UserRoleMapper userRoleMapper; @Resource private CommunityMapper communityMapper; //用户登录 public UserModel userLogin(String userName,String userPwd){ //对输入的账号密码进行判断,是否符合格式 checkUserLoginParam(userName,userPwd); //通过对数据库的查询,查看用户是否存在 User temp = userMapper.queryUserByUserName(userName); AssertUtil.isTrue(temp == null,"用户不存在"); //判断用户的密码是否正确,拿数据库查询到的用户密码和用户输入的用户密码进行equest比较 checkUserPwd(userPwd,temp.getUserPwd()); //返回目标对象 对密码进行加密 return builderUserInfo(temp); } //对输入的账号密码进行判断,是否符合格式 private void checkUserLoginParam(String userName, String userPwd) { //用户非空 AssertUtil.isTrue(StringUtils.isBlank(userName),"用户名不能为空"); //密码非空 AssertUtil.isTrue(StringUtils.isBlank(userPwd),"密码不能为空"); } //判断用户的密码是否正确,拿数据库查询到的用户密码和用户输入的用户密码进行equest比较 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 /confirm/iPassword) { //通过Id获取user对象 User user = userMapper.selectByPrimaryKey(userId); //参数校验 (用户,旧密码,新密码,确认密码) checkPasswordParams(user,oldPassword,newPassword,/confirm/iPassword); //默认参数设置,把用户输入的新密码 加密 添加进去 user.setUserPwd(Md5Util.encode(newPassword)); //执行更新操作 AssertUtil.isTrue(userMapper.updateByPrimaryKeySelective(user)<1,"修改密码失败"); } //修改密码的参数校验 private void checkPasswordParams(User user, String oldPassword, String newPassword, String /confirm/iPwd) { //用户不能为空 (不存在) AssertUtil.isTrue(null == user,"用户不存在"); //原始密码 非空 System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 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(/confirm/iPwd),"确认密码不能为空"); //确认密码需要和新密码一致 AssertUtil.isTrue(!(newPassword.equals(/confirm/iPwd)),"新密码和确认密码不一致"); } 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()); System.out.println("执行完毕"); return map; } @Transactional(propagation = Propagation.REQUIRED) public void saveUser(User user){ //参数校验 checkParams(user.getUserName(),user.getComId(),user.getVc()); //设置默认参数 user.setCreateDate(new Date()); user.setUpdateDate(new Date()); user.setUserPwd(Md5Util.encode("123456")); //执行添加,判断结果 AssertUtil.isTrue(userMapper.insertSelective(user)==null,"用户添加失败!"); relaionUserRole(user.getId(),user.getRoleIds()); AssertUtil.isTrue(communityMapper.addNumByComId(user.getComId())<1, "社区用户添加失败"); } @Transactional(propagation = Propagation.REQUIRED) public void updateUser(User user){ //1.参数校验 //通过用户id获取用户对象 User temp=userMapper.selectByPrimaryKey(user.getId()); //判断对象是否存在 AssertUtil.isTrue(temp==null,"待更新记录不存在"); //验证参数 checkParams1(user.getUserName(),user.getComId(),user.getVc()); //2.设置默认参数 user.setUpdateDate(new Date()); //3.执行更新,返回结果 AssertUtil.isTrue(userMapper.updateByPrimaryKeySelective(user)<1,"用户更新失败!"); relaionUserRole(user.getId(),user.getRoleIds()); } private void checkParams(String userName, Integer comId, Integer vc) { AssertUtil.isTrue(StringUtils.isBlank(userName),"用户名不能为空"); //验证用户是否存在 User temp=userMapper.queryUserByUserName(userName); AssertUtil.isTrue(temp!=null,"用户名已存在"); AssertUtil.isTrue(comId==null,"请输入所在社区"); AssertUtil.isTrue(vc==null,"请选择疫苗接种状况"); } private void checkParams1(String userName, Integer comId, Integer vc) { AssertUtil.isTrue(StringUtils.isBlank(userName),"用户名不能为空"); //验证用户是否存在 AssertUtil.isTrue(comId==null,"请输入所在社区"); AssertUtil.isTrue(vc==null,"请选择疫苗接种状况"); } @Transactional(propagation = Propagation.REQUIRED) public void deleteUser(Integer[] ids){ AssertUtil.isTrue(ids==null||ids.length==0,"请选择您要删除的记录"); for (int id:ids){ User user=userMapper.selectByPrimaryKey(id); AssertUtil.isTrue(communityMapper.subNumByComId(user.getComId())!=ids.length, "社区用户删除失败"); } AssertUtil.isTrue(deleteBatch(ids) != ids.length,"用户角色删除失败"); } public void registerUser(String userName, String password1, String password2, String icon) { // 参数校验 checkRegister(userName, password1, password2, icon); // 实例化user User user = new User(); //设置默认参数 user.setUserName(userName); user.setUserPwd(Md5Util.encode(password1)); user.setUserPhone(icon); user.setCreateDate(new Date()); user.setUpdateDate(new Date()); // 执行方法 AssertUtil.isTrue(userMapper.insertSelective(user)<1, "用户添加失败"); } private void checkRegister(String userName, String password1, String password2, String icon) { // 用户名不为空 AssertUtil.isTrue(StringUtils.isBlank(userName), "请输入用户名"); // 判断用户名是否存在 User user1 = userMapper.selectByName(userName); AssertUtil.isTrue(user1!=null, "该用户已存在"); // 判断手机号是否存在 User user2 = userMapper.selectByPhone(icon); AssertUtil.isTrue(user2!=null, "该手机号已注册过账号"); // 密码不为空 AssertUtil.isTrue(StringUtils.isBlank(password1), "请输入密码"); // 确认密码不为空 AssertUtil.isTrue(StringUtils.isBlank(password2), "请输入确认密码"); // 密码长度校验 AssertUtil.isTrue(password1.length()<6 || password1.length()>12, "密码长度为6-12位"); // 密码和确认密码相等 AssertUtil.isTrue(!password1.equals(password2), "确认密码与密码不一致"); // 手机号合法 AssertUtil.isTrue(!PhoneUtil.isMobile(icon), "请输入正确的手机号"); } private void relaionUserRole(int userId, String roleIds) { // 通过id获取用户的角色数量 int count = userRoleMapper.countUserRoleByUserId(userId); // count>0 说明用户原先有角色 先删除所有的角色 if (count>0) { AssertUtil.isTrue(userRoleMapper.deleteUserRoleByUserId(userId)!=count, "用户角色删除失败"); } // 传入的角色信息不为空 添加新的角色 if (StringUtils.isNoneBlank(roleIds)) { // 将传入的roleIds转成字符串数组 String[] roleStrIds = roleIds.split(","); // 用来存放用户的角色信息 List roleList = new ArrayList<>(); // 遍历roleIds for (String rid : roleStrIds) { // 准备对象 UserRole userRole = new UserRole(); userRole.setUserId(userId); userRole.setRoleId(Integer.parseInt(rid)); userRole.setCreateDate(new Date()); userRole.setUpdateDate(new Date()); roleList.add(userRole); } AssertUtil.isTrue(userRoleMapper.insertBatch(roleList) != roleList.size(), "用户角色分配失败"); } } }
2、今日疫情模块
核心代码Service
@Service
public class /confirm/iedService extends baseService {
@Resource
//引入/confirm/iedMapper
private /confirm/iedMapper /confirm/iedMapper;
@Resource
//引入user表
private UserMapper userMapper;
@Resource
//引入user表
private CommunityMapper communityMapper;
//角色的条件查询以及 分页
public Map findRoleByParam(/confirm/iedQuery /confirm/iedQuery){
//实例化对象
Map map = new HashMap<>();
//实例化分页单位
PageHelper.startPage(/confirm/iedQuery.getPage(), /confirm/iedQuery.getLimit());
//开始分页
PageInfo rlist = new PageInfo<>(selectByParams(/confirm/iedQuery));
map.put("code",0);
map.put("msg","success");
map.put("count",rlist.getTotal());
map.put("data",rlist.getList());
//返回Map
return map;
}
@Transactional(propagation = Propagation.REQUIRED) //涉及到事务 就需要此注解
//用户模块的添加
public void addUser(/confirm/ied user) {
//1、参数校验
check/confirm/ied(user.getTrueName(),user.getState());
if (user.getComId().equals("浦东区")){
user.setComId(1);
}
if (user.getComId().equals("黄浦区")){
user.setComId(2);
}
if (user.getComId().equals("松江区")){
user.setComId(3);
}
if (user.getComId().equals("徐汇区")){
user.setComId(4);
}
if (user.getComId().equals("虹口区")){
user.setComId(5);
}
//查询user表中是否存在此人 不存在 添加上去 设置默认值
User temp = userMapper.selectByPhone(user.getTcPhone());
// 手机号查询用户
if (temp != null){
//健康状态改成2 如果user表里面已经有了的情况下
userMapper.updateUserHealthById(temp.getUserPhone());
//默认值 确诊表中的userId字段
user.setUserId(temp.getId());
}else { //表里没有这个人的时候 添加 这个用户 新建一个user对象
User u = new User();
//真实姓名
u.setTrueName(user.getTrueName());
//名字
u.setUserName(user.getTrueName());
//设置密码 默认值 :123456
u.setUserPwd(Md5Util.encode("123456"));
//设置社区ID
u.setComId(user.getComId());
//手机号 唯一
u.setUserPhone(user.getTcPhone());
u.setEcPhone(user.getTcPhone());
u.setHealth("2");
//创建时间
u.setCreateDate(new Date());
//修改时间
u.setUpdateDate(new Date());
//添加用户是否成功
AssertUtil.isTrue(userMapper.insertSelective(u)<1,"插入用户失败");
//给确诊人员添加其 userId
Integer userId = userMapper.selectById(user.getTcPhone());
user.setUserId(userId);
}
//2、默认值设置
//确诊日期
user.setCreateDate(new Date());
//添加是否成功
AssertUtil.isTrue(insertSelective(user)<1,"添加失败");
//relaionUserRole(user.getId(),user.getComId());
}
@Transactional(propagation = Propagation.REQUIRED) //涉及到事务 就需要此注解
//用户模块的修改
public void changeUser(/confirm/ied user) {
//通过id获取用户信息
/confirm/ied temp = /confirm/iedMapper.selectByPrimaryKey(user.getId());
//判断用户信息是否存在
AssertUtil.isTrue(temp == null,"当前用户不存在");
//校验参数
change/confirm/ied(user.getTrueName(),user.getTcPhone(),user.getState());
//修改是否成功 完整版
//AssertUtil.isTrue(updateByPrimaryKeySelective(user)<1,"修改失败了");
//修改是否成功 完整版
AssertUtil.isTrue(/confirm/iedMapper.uBPKS(user)<1,"修改失败了");
}
//修改的参数校验
private void change/confirm/ied(String trueName, String tcPhone, Integer state) {
//1、用户名不能为空
AssertUtil.isTrue(StringUtils.isBlank(trueName),"姓名不能为空");
//2、当前状态不能为空
AssertUtil.isTrue(StringUtils.isBlank(tcPhone),"请输入手机号");
//3、当前状态不能为空
AssertUtil.isTrue(state<1 || state>4,"请选择正确的状态码");
}
//用户模块的添加的参数校验
private void check/confirm/ied(String trueName, Integer state) {
//1、用户名不能为空
AssertUtil.isTrue(StringUtils.isBlank(trueName),"姓名不能为空");
//2、当前状态不能为空
AssertUtil.isTrue(state<1 || state>3,"请选择正确的状态码");
}
//添加社区时的校验
private void relaionUserRole(Integer id, Integer comId) {
//准备集合 存储对象
List urlist = new ArrayList<>();
//userId,roleId
//判断是否选择了角色信息
//只能选择一个社区
AssertUtil.isTrue(comId>1 || comId<1,"只能选择一个社区");
//通过社区表的 com_id 查询到社区表的对应社区名
communityMapper.selectaddresComId(comId);
//添加
}
@Transactional(propagation = Propagation.REQUIRED) //涉及到事务 就需要此注解
//确诊人员的批量删除
public void deleteUserByIds(Integer[] ids) {
//要删除记录不能为空
AssertUtil.isTrue(ids == null || ids.length==0,"请选择要删除的记录");
//修改user表的状态码
for(Integer id: ids){
/confirm/ied confirmed = /confirm/iedMapper.selectId(id);
System.out.println(id+ " -----------------" );
System.out.println(/confirm/ied.getTrueName());
AssertUtil.isTrue(userMapper.updateById(/confirm/ied.getUserId())<1,"修改失败");
}
//删除确诊表的个人信息记录
AssertUtil.isTrue(deleteBatch(ids)!=ids.length,"删除失败");
}
//查询所有社区
public List
3、防疫管理模块
核心代码Service:
@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
4、系统管理模块
核心代码:Service:
@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 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()); System.out.println("就差一点!!!!"); AssertUtil.isTrue(insertSelective(role)<1,"添加失败了呢~"); } private void checkRole(Role role) { //是否为空 AssertUtil.isTrue(role==null,"请输入角色信息~"); //判断是否已经重复 System.out.println("判断"); Role role1= roleMapper.selectByName(role.getRoleName()); System.out.println("判断结束"); System.out.println(role1!=null); AssertUtil.isTrue(role1!=null,"已添加过啦~"); System.out.println("退出@"); } @Transactional(propagation = Propagation.REQUIRED) public void updateRole(Role role) { role.setUpdateDate(new Date()); AssertUtil.isTrue(updateByPrimaryKeySelective(role)<1,"编辑失败啦~"); } @Transactional(propagation = Propagation.REQUIRED) public void deleteRole(Role role) { // 验证 AssertUtil.isTrue(role.getId()==null || selectByPrimaryKey(role.getId())==null, "待删除角色不存在"); // 设定默认值 role.setUpdateDate(new Date()); // 删除角色绑定的权限资源 int count = roleMapper.countPermissionByRoleId(role.getId()); if (count>0) { int i = roleMapper.deletePermissionsByRoleId(role.getId()); AssertUtil.isTrue(i!=count, "角色绑定的权限资源删除失败"); } // 判断是否成功 AssertUtil.isTrue(roleMapper.updateRoleById(role.getId())<1, "角色删除失败"); } public List
5、用户模块
核心代码Service:
@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 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()); System.out.println("就差一点!!!!"); AssertUtil.isTrue(insertSelective(role)<1,"添加失败了呢~"); } private void checkRole(Role role) { //是否为空 AssertUtil.isTrue(role==null,"请输入角色信息~"); //判断是否已经重复 System.out.println("判断"); Role role1= roleMapper.selectByName(role.getRoleName()); System.out.println("判断结束"); System.out.println(role1!=null); AssertUtil.isTrue(role1!=null,"已添加过啦~"); System.out.println("退出@"); } @Transactional(propagation = Propagation.REQUIRED) public void updateRole(Role role) { role.setUpdateDate(new Date()); AssertUtil.isTrue(updateByPrimaryKeySelective(role)<1,"编辑失败啦~"); } @Transactional(propagation = Propagation.REQUIRED) public void deleteRole(Role role) { // 验证 AssertUtil.isTrue(role.getId()==null || selectByPrimaryKey(role.getId())==null, "待删除角色不存在"); // 设定默认值 role.setUpdateDate(new Date()); // 删除角色绑定的权限资源 int count = roleMapper.countPermissionByRoleId(role.getId()); if (count>0) { int i = roleMapper.deletePermissionsByRoleId(role.getId()); AssertUtil.isTrue(i!=count, "角色绑定的权限资源删除失败"); } // 判断是否成功 AssertUtil.isTrue(roleMapper.updateRoleById(role.getId())<1, "角色删除失败"); } public List
大概就是这样,管理系统,基本都差不多,比如图书管理,CRM等,详细源码见文件上传~



