Java 實(shí)戰(zhàn)項(xiàng)目之疫情防控管理系統(tǒng)詳解
☣基于java疫情防控管理系統(tǒng)
☣項(xiàng)目介紹:通過對(duì)依社區(qū)為單位進(jìn)行人群的管理,以及疫苗的情況,包括小區(qū)狀況,通過RBAC進(jìn)行角色與用戶之間的權(quán)限管理。
☣項(xiàng)目:環(huán)境-IDEA、Mysql數(shù)據(jù)庫,Tomcat服務(wù)器,SpringMVC,SpringBoot,AOP,攔截器,過濾器,全局異常,RBAC權(quán)限控制等。
1、登錄模塊(注冊(cè))


核心代碼:service層
@Service
public class UserService extends BaseService<User,Integer> {
@Resource
//引入dao層
private UserMapper userMapper;
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private CommunityMapper communityMapper;
//用戶登錄
public UserModel userLogin(String userName,String userPwd){
//對(duì)輸入的賬號(hào)密碼進(jìn)行判斷,是否符合格式
checkUserLoginParam(userName,userPwd);
//通過對(duì)數(shù)據(jù)庫的查詢,查看用戶是否存在
User temp = userMapper.queryUserByUserName(userName);
AssertUtil.isTrue(temp == null,"用戶不存在");
//判斷用戶的密碼是否正確,拿數(shù)據(jù)庫查詢到的用戶密碼和用戶輸入的用戶密碼進(jìn)行equest比較
checkUserPwd(userPwd,temp.getUserPwd());
//返回目標(biāo)對(duì)象 對(duì)密碼進(jìn)行加密
return builderUserInfo(temp);
}
/**
* //對(duì)輸入的賬號(hào)密碼進(jìn)行判斷 是否符合格式
* @param userName 賬號(hào)
* @param userPwd 密碼
*/
//對(duì)輸入的賬號(hào)密碼進(jìn)行判斷,是否符合格式
private void checkUserLoginParam(String userName, String userPwd) {
//用戶非空
AssertUtil.isTrue(StringUtils.isBlank(userName),"用戶名不能為空");
//密碼非空
AssertUtil.isTrue(StringUtils.isBlank(userPwd),"密碼不能為空");
}
/**
* //判斷密碼是否正確
* @param userPwd 用戶輸入的密碼
* @param userPwd1 數(shù)據(jù)庫查出來的密碼
*/
//判斷用戶的密碼是否正確,拿數(shù)據(jù)庫查詢到的用戶密碼和用戶輸入的用戶密碼進(jìn)行equest比較
private void checkUserPwd(String userPwd, String userPwd1) {
//對(duì)用戶輸入的密碼進(jìn)行加密
userPwd = Md5Util.encode(userPwd);
AssertUtil.isTrue(!(userPwd.equals(userPwd1)),"密碼不正確");
}
/**
*
* @param temp 當(dāng)前登錄對(duì)象
* @return
*/
//對(duì)密碼進(jìn)行加密 返回目標(biāo)對(duì)象
private UserModel builderUserInfo(User temp) {
UserModel userModel = new UserModel();
//為用戶密碼進(jìn)行加密
userModel.setUserIdStr(UserIDBase64.encoderUserID(temp.getId()));
userModel.setUserName(temp.getUserName());
userModel.setTrueName(temp.getTrueName());
return userModel;
}
/**
*
* @param userId 當(dāng)前Cookie存儲(chǔ)的用戶dId
* @param oldPassword 舊密碼
* @param newPassword 新密碼
* @param confirmPassword 確認(rèn)密碼
*/
//修改密碼
@Transactional(propagation = Propagation.REQUIRED)
public void updateUserPassword(Integer userId, String oldPassword, String newPassword, String confirmPassword) {
//通過Id獲取user對(duì)象
User user = userMapper.selectByPrimaryKey(userId);
//參數(shù)校驗(yàn) (用戶,舊密碼,新密碼,確認(rèn)密碼)
checkPasswordParams(user,oldPassword,newPassword,confirmPassword);
//默認(rèn)參數(shù)設(shè)置,把用戶輸入的新密碼 加密 添加進(jìn)去
user.setUserPwd(Md5Util.encode(newPassword));
//執(zhí)行更新操作
AssertUtil.isTrue(userMapper.updateByPrimaryKeySelective(user)<1,"修改密碼失敗");
}
//修改密碼的參數(shù)校驗(yàn)
private void checkPasswordParams(User user, String oldPassword, String newPassword, String confirmPwd) {
//用戶不能為空 (不存在)
AssertUtil.isTrue(null == user,"用戶不存在");
//原始密碼 非空
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
AssertUtil.isTrue(StringUtils.isBlank(oldPassword),"原始密碼不能為空");
//原始密碼是否和數(shù)據(jù)庫查詢到的密碼一致
AssertUtil.isTrue(!(Md5Util.encode(oldPassword).equals(user.getUserPwd())),"原始密碼不正確");
//新密碼不能為空
AssertUtil.isTrue(StringUtils.isBlank(newPassword),"新密碼不能為空");
//新密碼和原始密碼不能相同
AssertUtil.isTrue(oldPassword.equals(newPassword),"新密碼不能和原始密碼相同");
//確認(rèn)密碼非空
AssertUtil.isTrue(StringUtils.isBlank(confirmPwd),"確認(rèn)密碼不能為空");
//確認(rèn)密碼需要和新密碼一致
AssertUtil.isTrue(!(newPassword.equals(confirmPwd)),"新密碼和確認(rèn)密碼不一致");
}
/**
* 多條件分頁查詢用戶數(shù)據(jù)
* @param query
* @return
*/
public Map<String, Object> queryUserByParams (UserQuery query) {
Map<String, Object> map = new HashMap<>();
PageHelper.startPage(query.getPage(), query.getLimit());
PageInfo<User> 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("執(zhí)行完畢");
return map;
}
/**
* 添加用戶
* @param user
*/
@Transactional(propagation = Propagation.REQUIRED)
public void saveUser(User user){
//參數(shù)校驗(yàn)
checkParams(user.getUserName(),user.getComId(),user.getVc());
//設(shè)置默認(rèn)參數(shù)
user.setCreateDate(new Date());
user.setUpdateDate(new Date());
user.setUserPwd(Md5Util.encode("123456"));
//執(zhí)行添加,判斷結(jié)果
AssertUtil.isTrue(userMapper.insertSelective(user)==null,"用戶添加失??!");
relaionUserRole(user.getId(),user.getRoleIds());
AssertUtil.isTrue(communityMapper.addNumByComId(user.getComId())<1, "社區(qū)用戶添加失敗");
}
/**
* 用戶更新,修改
* @param user
*/
@Transactional(propagation = Propagation.REQUIRED)
public void updateUser(User user){
//1.參數(shù)校驗(yàn)
//通過用戶id獲取用戶對(duì)象
User temp=userMapper.selectByPrimaryKey(user.getId());
//判斷對(duì)象是否存在
AssertUtil.isTrue(temp==null,"待更新記錄不存在");
//驗(yàn)證參數(shù)
checkParams1(user.getUserName(),user.getComId(),user.getVc());
//2.設(shè)置默認(rèn)參數(shù)
user.setUpdateDate(new Date());
//3.執(zhí)行更新,返回結(jié)果
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),"用戶名不能為空");
//驗(yàn)證用戶是否存在
User temp=userMapper.queryUserByUserName(userName);
AssertUtil.isTrue(temp!=null,"用戶名已存在");
AssertUtil.isTrue(comId==null,"請(qǐng)輸入所在社區(qū)");
AssertUtil.isTrue(vc==null,"請(qǐng)選擇疫苗接種狀況");
}
private void checkParams1(String userName, Integer comId, Integer vc) {
AssertUtil.isTrue(StringUtils.isBlank(userName),"用戶名不能為空");
//驗(yàn)證用戶是否存在
AssertUtil.isTrue(comId==null,"請(qǐng)輸入所在社區(qū)");
AssertUtil.isTrue(vc==null,"請(qǐng)選擇疫苗接種狀況");
}
@Transactional(propagation = Propagation.REQUIRED)
public void deleteUser(Integer[] ids){
AssertUtil.isTrue(ids==null||ids.length==0,"請(qǐng)選擇您要?jiǎng)h除的記錄");
for (int id:ids){
User user=userMapper.selectByPrimaryKey(id);
AssertUtil.isTrue(communityMapper.subNumByComId(user.getComId())!=ids.length, "社區(qū)用戶刪除失敗");
}
AssertUtil.isTrue(deleteBatch(ids) != ids.length,"用戶角色刪除失敗");
}
/*SZC*/
/**
* 用戶注冊(cè)
* @param userName
* @param password1
* @param password2
* @param icon
*/
public void registerUser(String userName, String password1, String password2, String icon) {
// 參數(shù)校驗(yàn)
checkRegister(userName, password1, password2, icon);
// 實(shí)例化user
User user = new User();
//設(shè)置默認(rèn)參數(shù)
user.setUserName(userName);
user.setUserPwd(Md5Util.encode(password1));
user.setUserPhone(icon);
user.setCreateDate(new Date());
user.setUpdateDate(new Date());
// 執(zhí)行方法
AssertUtil.isTrue(userMapper.insertSelective(user)<1, "用戶添加失敗");
}
/**
* 用戶注冊(cè)的參數(shù)校驗(yàn)
* @param userName
* @param password1
* @param password2
* @param icon
*/
private void checkRegister(String userName, String password1, String password2, String icon) {
// 用戶名不為空
AssertUtil.isTrue(StringUtils.isBlank(userName), "請(qǐng)輸入用戶名");
// 判斷用戶名是否存在
User user1 = userMapper.selectByName(userName);
AssertUtil.isTrue(user1!=null, "該用戶已存在");
// 判斷手機(jī)號(hào)是否存在
User user2 = userMapper.selectByPhone(icon);
AssertUtil.isTrue(user2!=null, "該手機(jī)號(hào)已注冊(cè)過賬號(hào)");
// 密碼不為空
AssertUtil.isTrue(StringUtils.isBlank(password1), "請(qǐng)輸入密碼");
// 確認(rèn)密碼不為空
AssertUtil.isTrue(StringUtils.isBlank(password2), "請(qǐng)輸入確認(rèn)密碼");
// 密碼長(zhǎng)度校驗(yàn)
AssertUtil.isTrue(password1.length()<6 || password1.length()>12, "密碼長(zhǎng)度為6-12位");
// 密碼和確認(rèn)密碼相等
AssertUtil.isTrue(!password1.equals(password2), "確認(rèn)密碼與密碼不一致");
// 手機(jī)號(hào)合法
AssertUtil.isTrue(!PhoneUtil.isMobile(icon), "請(qǐng)輸入正確的手機(jī)號(hào)");
}
/**
* 刪除用戶原先的角色,并重新賦予新的角色
* @param userId
* @param roleIds
*/
private void relaionUserRole(int userId, String roleIds) {
// 通過id獲取用戶的角色數(shù)量
int count = userRoleMapper.countUserRoleByUserId(userId);
// count>0 說明用戶原先有角色 先刪除所有的角色
if (count>0) {
AssertUtil.isTrue(userRoleMapper.deleteUserRoleByUserId(userId)!=count, "用戶角色刪除失敗");
}
// 傳入的角色信息不為空 添加新的角色
if (StringUtils.isNoneBlank(roleIds)) {
// 將傳入的roleIds轉(zhuǎn)成字符串?dāng)?shù)組
String[] roleStrIds = roleIds.split(",");
// 用來存放用戶的角色信息
List<UserRole> roleList = new ArrayList<>();
// 遍歷roleIds
for (String rid : roleStrIds) {
// 準(zhǔn)備對(duì)象
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 ConfirmedService extends BaseService<Confirmed,Integer> {
@Resource
//引入ConfirmedMapper
private ConfirmedMapper confirmedMapper;
@Resource
//引入user表
private UserMapper userMapper;
@Resource
//引入user表
private CommunityMapper communityMapper;
//角色的條件查詢以及 分頁
public Map<String,Object> findRoleByParam(ConfirmedQuery confirmedQuery){
//實(shí)例化對(duì)象
Map<String,Object> map = new HashMap<>();
//實(shí)例化分頁單位
PageHelper.startPage(confirmedQuery.getPage(), confirmedQuery.getLimit());
//開始分頁
PageInfo<Confirmed> rlist = new PageInfo<>(selectByParams(confirmedQuery));
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) //涉及到事務(wù) 就需要此注解
//用戶模塊的添加
public void addUser(Confirmed user) {
//1、參數(shù)校驗(yàn)
checkConfirmed(user.getTrueName(),user.getState());
if (user.getComId().equals("浦東區(qū)")){
user.setComId(1);
}
if (user.getComId().equals("黃浦區(qū)")){
user.setComId(2);
}
if (user.getComId().equals("松江區(qū)")){
user.setComId(3);
}
if (user.getComId().equals("徐匯區(qū)")){
user.setComId(4);
}
if (user.getComId().equals("虹口區(qū)")){
user.setComId(5);
}
//查詢user表中是否存在此人 不存在 添加上去 設(shè)置默認(rèn)值
User temp = userMapper.selectByPhone(user.getTcPhone());
// 手機(jī)號(hào)查詢用戶
if (temp != null){
//健康狀態(tài)改成2 如果user表里面已經(jīng)有了的情況下
userMapper.updateUserHealthById(temp.getUserPhone());
//默認(rèn)值 確診表中的userId字段
user.setUserId(temp.getId());
}else { //表里沒有這個(gè)人的時(shí)候 添加 這個(gè)用戶 新建一個(gè)user對(duì)象
User u = new User();
//真實(shí)姓名
u.setTrueName(user.getTrueName());
//名字
u.setUserName(user.getTrueName());
//設(shè)置密碼 默認(rèn)值 :123456
u.setUserPwd(Md5Util.encode("123456"));
//設(shè)置社區(qū)ID
u.setComId(user.getComId());
//手機(jī)號(hào) 唯一
u.setUserPhone(user.getTcPhone());
u.setEcPhone(user.getTcPhone());
u.setHealth("2");
//創(chuàng)建時(shí)間
u.setCreateDate(new Date());
//修改時(shí)間
u.setUpdateDate(new Date());
//添加用戶是否成功
AssertUtil.isTrue(userMapper.insertSelective(u)<1,"插入用戶失敗");
//給確診人員添加其 userId
Integer userId = userMapper.selectById(user.getTcPhone());
user.setUserId(userId);
}
//2、默認(rèn)值設(shè)置
//確診日期
user.setCreateDate(new Date());
//添加是否成功
AssertUtil.isTrue(insertSelective(user)<1,"添加失敗");
//relaionUserRole(user.getId(),user.getComId());
}
@Transactional(propagation = Propagation.REQUIRED) //涉及到事務(wù) 就需要此注解
//用戶模塊的修改
public void changeUser(Confirmed user) {
//通過id獲取用戶信息
Confirmed temp = confirmedMapper.selectByPrimaryKey(user.getId());
//判斷用戶信息是否存在
AssertUtil.isTrue(temp == null,"當(dāng)前用戶不存在");
//校驗(yàn)參數(shù)
changeConfirmed(user.getTrueName(),user.getTcPhone(),user.getState());
//修改是否成功 完整版
//AssertUtil.isTrue(updateByPrimaryKeySelective(user)<1,"修改失敗了");
//修改是否成功 完整版
AssertUtil.isTrue(confirmedMapper.uBPKS(user)<1,"修改失敗了");
}
//修改的參數(shù)校驗(yàn)
private void changeConfirmed(String trueName, String tcPhone, Integer state) {
//1、用戶名不能為空
AssertUtil.isTrue(StringUtils.isBlank(trueName),"姓名不能為空");
//2、當(dāng)前狀態(tài)不能為空
AssertUtil.isTrue(StringUtils.isBlank(tcPhone),"請(qǐng)輸入手機(jī)號(hào)");
//3、當(dāng)前狀態(tài)不能為空
AssertUtil.isTrue(state<1 || state>4,"請(qǐng)選擇正確的狀態(tài)碼");
}
//用戶模塊的添加的參數(shù)校驗(yàn)
private void checkConfirmed(String trueName, Integer state) {
//1、用戶名不能為空
AssertUtil.isTrue(StringUtils.isBlank(trueName),"姓名不能為空");
//2、當(dāng)前狀態(tài)不能為空
AssertUtil.isTrue(state<1 || state>3,"請(qǐng)選擇正確的狀態(tài)碼");
}
//添加社區(qū)時(shí)的校驗(yàn)
private void relaionUserRole(Integer id, Integer comId) {
//準(zhǔn)備集合 存儲(chǔ)對(duì)象
List<Community> urlist = new ArrayList<>();
//userId,roleId
//判斷是否選擇了角色信息
//只能選擇一個(gè)社區(qū)
AssertUtil.isTrue(comId>1 || comId<1,"只能選擇一個(gè)社區(qū)");
//通過社區(qū)表的 com_id 查詢到社區(qū)表的對(duì)應(yīng)社區(qū)名
communityMapper.selectaddresComId(comId);
//添加
}
@Transactional(propagation = Propagation.REQUIRED) //涉及到事務(wù) 就需要此注解
//確診人員的批量刪除
public void deleteUserByIds(Integer[] ids) {
//要?jiǎng)h除記錄不能為空
AssertUtil.isTrue(ids == null || ids.length==0,"請(qǐng)選擇要?jiǎng)h除的記錄");
//修改user表的狀態(tài)碼
for(Integer id: ids){
Confirmed confirmed = confirmedMapper.selectId(id);
System.out.println(id+ " -----------------" );
System.out.println(confirmed.getTrueName());
AssertUtil.isTrue(userMapper.updateById(confirmed.getUserId())<1,"修改失敗");
}
//刪除確診表的個(gè)人信息記錄
AssertUtil.isTrue(deleteBatch(ids)!=ids.length,"刪除失敗");
}
//查詢所有社區(qū)
public List<Map<String, Object>> queryComs() {
return confirmedMapper.selectComs();
}
}
3、防疫管理模塊


核心代碼Service:
@Service
public class CommunityService extends BaseService<Community,Integer> {
@Resource
private CommunityMapper communityMapper;
/**
* 多條件分頁查詢
* @param query
* @return
*/
public Map<String,Object> queryComByParams(CommunityQuery query){
Map<String,Object> map=new HashMap<>();
//初始化分頁
PageHelper.startPage(query.getPage(), query.getLimit());
//開始分頁
PageInfo<Community> pageInfo=new PageInfo<>(communityMapper.selectByParams(query));
//準(zhǔn)備數(shù)據(jù)
map.put("code",0);
map.put("msg","");
map.put("count",pageInfo.getTotal());
map.put("data",pageInfo.getList());
return map;
}
//查詢所有角色信息
public List<Map<String, Object>> findRoles(Integer userId) {
return communityMapper.selectRoles(userId);
}
}
//============================================================
@Service
public class VaccinationService {
@Resource
VaccinationMapper vaccinationMapper;
/*多條件查詢*/
public Map<String,Object> selectAll(VaccinationQuery vaccinationQuery) {
//創(chuàng)建map
Map<String,Object> map =new HashMap<String,Object>();
//查數(shù)據(jù)并分頁
PageHelper.startPage(vaccinationQuery.getPage(),vaccinationQuery.getLimit());
PageInfo<Vaccination> 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;
}
/*通過ID獲取對(duì)象*/
public Vaccination selectId(Integer id) {
return vaccinationMapper.selectById(id);
}
/*添加*/
@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 vaccinatio){
AssertUtil.isTrue(vaccinatio==null,"請(qǐng)輸入添加的角色");
AssertUtil.isTrue(StringUtils.isBlank(vaccinatio.getTrueName()),"用戶名不能為空");
AssertUtil.isTrue(StringUtils.isBlank(vaccinatio.getFirst()),"請(qǐng)?zhí)顚?是/否)");
AssertUtil.isTrue(StringUtils.isBlank(vaccinatio.getSecond()),"請(qǐng)?zhí)顚?是/否)");
}
/*刪除*/
public void delete(Integer[] ids) {
AssertUtil.isTrue(ids==null||ids.length==0,"請(qǐng)選擇要?jiǎng)h除的用戶");
AssertUtil.isTrue(vaccinationMapper.deleteVa(ids)!=ids.length,"刪除失敗~~~");
}
/*編輯*/
public void updateVa(Vaccination vaccination) {
checkOK(vaccination);
if(vaccination.getFirst()==null||"否".equals(vaccination.getFirst())){
vaccination.setFirstDate(null);
}
if(vaccination.getSecond()==null||"否".equals(vaccination.getSecond())){
vaccination.setSecondDate(null);
}
if("是".equals(vaccination.getFirst())){
vaccination.setFirstDate(new Date());
}
if("是".equals(vaccination.getSecond())){
vaccination.setSecondDate(new Date());
}
AssertUtil.isTrue(vaccinationMapper.updateByPrimaryKeySelective(vaccination)<1,"修改失敗~");
}
}
4、系統(tǒng)管理模塊


核心代碼:Service:
@Service
public class RoleService extends BaseService<Role,Integer> {
@Autowired(required = false)
RoleMapper roleMapper;
@Autowired(required = false)
RoleQuery roleQuery;
@Resource
private ModuleMapper moduleMapper;
@Resource
private PermissionMapper permissionMapper;
/*多條件查詢*/
public Map<String,Object> selectRole(RoleQuery roleQuery){
//創(chuàng)建map
Map<String,Object> map =new HashMap<String,Object>();
//查數(shù)據(jù)并分頁
PageHelper.startPage(roleQuery.getPage(),roleQuery.getLimit());
PageInfo<Role> 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("就差一點(diǎn)?。。?!");
AssertUtil.isTrue(insertSelective(role)<1,"添加失敗了呢~");
}
private void checkRole(Role role) {
//是否為空
AssertUtil.isTrue(role==null,"請(qǐng)輸入角色信息~");
//判斷是否已經(jīng)重復(fù)
System.out.println("判斷");
Role role1= roleMapper.selectByName(role.getRoleName());
System.out.println("判斷結(jié)束");
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,"編輯失敗啦~");
}
/**
* 刪除角色信息
* @param role
*/
@Transactional(propagation = Propagation.REQUIRED)
public void deleteRole(Role role) {
// 驗(yàn)證
AssertUtil.isTrue(role.getId()==null || selectByPrimaryKey(role.getId())==null, "待刪除角色不存在");
// 設(shè)定默認(rèn)值
role.setUpdateDate(new Date());
// 刪除角色綁定的權(quán)限資源
int count = roleMapper.countPermissionByRoleId(role.getId());
if (count>0) {
int i = roleMapper.deletePermissionsByRoleId(role.getId());
AssertUtil.isTrue(i!=count, "角色綁定的權(quán)限資源刪除失敗");
}
// 判斷是否成功
AssertUtil.isTrue(roleMapper.updateRoleById(role.getId())<1, "角色刪除失敗");
}
/**
* 查詢所有角色
* @return
*/
public List<Map<String, Object>> seleceAllRole(Integer userId) {
return roleMapper.seleceAllRole(userId);
}
/**
* 給角色添加權(quán)限
* @param mids
* @param roleId
*/
@Transactional(propagation = Propagation.REQUIRED)
public void addGrant(Integer[] mids, Integer roleId) {
// 判斷roleId是否存在
AssertUtil.isTrue(roleId==null || roleMapper.selectByPrimaryKey(roleId)==null, "待授權(quán)的角色不存在");
// 統(tǒng)計(jì)當(dāng)前角色的權(quán)限資源數(shù)量
int count = roleMapper.countPermissionByRoleId(roleId);
if (count>0) {
// 如果角色存在權(quán)限資源,就全部刪除
int num = roleMapper.deletePermissionsByRoleId(roleId);
AssertUtil.isTrue(count!=num, "資源刪除失敗");
}
List<Permission> plist = new ArrayList<>();
if (mids!=null && mids.length!=0) {
// 遍歷mids
for (Integer mid : mids) {
// 實(shí)例化對(duì)象
Permission permission = new Permission();
// 設(shè)置數(shù)據(jù)
permission.setRoleId(roleId);
permission.setModuleId(mid);
// 權(quán)限碼
permission.setAclValue(moduleMapper.selectByPrimaryKey(mid).getOptValue());
permission.setCreateDate(new Date());
permission.setUpdateDate(new Date());
// 添加到list
plist.add(permission);
}
}
AssertUtil.isTrue(permissionMapper.insertBatch(plist)!=plist.size(), "角色權(quán)限更新失敗");
}
}
5、用戶模塊


核心代碼Service:
@Service
public class RoleService extends BaseService<Role,Integer> {
@Autowired(required = false)
RoleMapper roleMapper;
@Autowired(required = false)
RoleQuery roleQuery;
@Resource
private ModuleMapper moduleMapper;
@Resource
private PermissionMapper permissionMapper;
/*多條件查詢*/
public Map<String,Object> selectRole(RoleQuery roleQuery){
//創(chuàng)建map
Map<String,Object> map =new HashMap<String,Object>();
//查數(shù)據(jù)并分頁
PageHelper.startPage(roleQuery.getPage(),roleQuery.getLimit());
PageInfo<Role> 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("就差一點(diǎn)?。。?!");
AssertUtil.isTrue(insertSelective(role)<1,"添加失敗了呢~");
}
private void checkRole(Role role) {
//是否為空
AssertUtil.isTrue(role==null,"請(qǐng)輸入角色信息~");
//判斷是否已經(jīng)重復(fù)
System.out.println("判斷");
Role role1= roleMapper.selectByName(role.getRoleName());
System.out.println("判斷結(jié)束");
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,"編輯失敗啦~");
}
/**
* 刪除角色信息
* @param role
*/
@Transactional(propagation = Propagation.REQUIRED)
public void deleteRole(Role role) {
// 驗(yàn)證
AssertUtil.isTrue(role.getId()==null || selectByPrimaryKey(role.getId())==null, "待刪除角色不存在");
// 設(shè)定默認(rèn)值
role.setUpdateDate(new Date());
// 刪除角色綁定的權(quán)限資源
int count = roleMapper.countPermissionByRoleId(role.getId());
if (count>0) {
int i = roleMapper.deletePermissionsByRoleId(role.getId());
AssertUtil.isTrue(i!=count, "角色綁定的權(quán)限資源刪除失敗");
}
// 判斷是否成功
AssertUtil.isTrue(roleMapper.updateRoleById(role.getId())<1, "角色刪除失敗");
}
/**
* 查詢所有角色
* @return
*/
public List<Map<String, Object>> seleceAllRole(Integer userId) {
return roleMapper.seleceAllRole(userId);
}
/**
* 給角色添加權(quán)限
* @param mids
* @param roleId
*/
@Transactional(propagation = Propagation.REQUIRED)
public void addGrant(Integer[] mids, Integer roleId) {
// 判斷roleId是否存在
AssertUtil.isTrue(roleId==null || roleMapper.selectByPrimaryKey(roleId)==null, "待授權(quán)的角色不存在");
// 統(tǒng)計(jì)當(dāng)前角色的權(quán)限資源數(shù)量
int count = roleMapper.countPermissionByRoleId(roleId);
if (count>0) {
// 如果角色存在權(quán)限資源,就全部刪除
int num = roleMapper.deletePermissionsByRoleId(roleId);
AssertUtil.isTrue(count!=num, "資源刪除失敗");
}
List<Permission> plist = new ArrayList<>();
if (mids!=null && mids.length!=0) {
// 遍歷mids
for (Integer mid : mids) {
// 實(shí)例化對(duì)象
Permission permission = new Permission();
// 設(shè)置數(shù)據(jù)
permission.setRoleId(roleId);
permission.setModuleId(mid);
// 權(quán)限碼
permission.setAclValue(moduleMapper.selectByPrimaryKey(mid).getOptValue());
permission.setCreateDate(new Date());
permission.setUpdateDate(new Date());
// 添加到list
plist.add(permission);
}
}
AssertUtil.isTrue(permissionMapper.insertBatch(plist)!=plist.size(), "角色權(quán)限更新失敗");
}
}
大概就是這樣,管理系統(tǒng),基本都差不多,比如圖書管理,CRM等,詳細(xì)源碼見文件上傳~
到此這篇關(guān)于Java 實(shí)戰(zhàn)項(xiàng)目之疫情防控管理系統(tǒng)詳解的文章就介紹到這了,更多相關(guān)Java 疫情防控管理系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 詳解Java如何使用集合來實(shí)現(xiàn)一個(gè)客戶信息管理系統(tǒng)
- Java 實(shí)戰(zhàn)項(xiàng)目之疫情人員流動(dòng)管理系統(tǒng)詳解
- Java 實(shí)現(xiàn)完整功能的學(xué)生管理系統(tǒng)實(shí)例
- JAVA實(shí)現(xiàn)圖書管理系統(tǒng)項(xiàng)目
- java基于jdbc實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
- Java 實(shí)戰(zhàn)項(xiàng)目錘煉之IT設(shè)備固定資產(chǎn)管理系統(tǒng)的實(shí)現(xiàn)流程
相關(guān)文章
SpringBoot+Shiro學(xué)習(xí)之密碼加密和登錄失敗次數(shù)限制示例
本篇文章主要介紹了SpringBoot+Shiro學(xué)習(xí)之密碼加密和登錄失敗次數(shù)限制示例,可以限制登陸次數(shù),有興趣的同學(xué)可以了解一下。2017-03-03
Java中EasyPoi多sheet導(dǎo)出功能實(shí)現(xiàn)
這篇文章主要介紹了Java中EasyPoi多sheet導(dǎo)出功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
idea插件生成jpa實(shí)體類的實(shí)現(xiàn)示例
本文主要介紹了idea插件生成jpa實(shí)體類的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-01-01
springboot 接收List 入?yún)⒌膸追N方法
本文主要介紹了springboot 接收List 入?yún)⒌膸追N方法,本文主要介紹了7種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03
SpringBoot注解@EnableScheduling定時(shí)任務(wù)詳細(xì)解析
這篇文章主要介紹了SpringBoot注解@EnableScheduling定時(shí)任務(wù)詳細(xì)解析,@EnableScheduling 開啟對(duì)定時(shí)任務(wù)的支持,啟動(dòng)類里面使用@EnableScheduling 注解開啟功能,自動(dòng)掃描,需要的朋友可以參考下2024-01-01
Java-Io-RandomAccessFile任意位置讀寫數(shù)據(jù)的操作小結(jié)
RandomAccessFile類支持隨機(jī)訪問方式,可以跳轉(zhuǎn)到文件的任意位置讀寫數(shù)據(jù),這個(gè)類在文件隨機(jī)讀取時(shí)有很大的優(yōu)勢(shì),可利用多線程完成對(duì)一個(gè)大文件的讀寫,本文給大家介紹Java-Io-RandomAccessFile(任意位置讀寫數(shù)據(jù))的相關(guān)知識(shí),需要的朋友可以參考下2022-05-05
Java中的CopyOnWriteArrayList原理詳解
這篇文章主要介紹了Java中的CopyOnWriteArrayList原理詳解,如源碼所示,CopyOnWriteArrayList和ArrayList一樣,都在內(nèi)部維護(hù)了一個(gè)數(shù)組,操作CopyOnWriteArrayList其實(shí)就是在操作內(nèi)部的數(shù)組,需要的朋友可以參考下2023-12-12
淺析mybatis和spring整合的實(shí)現(xiàn)過程
據(jù)官方的說法,在Mybatis3問世之前,Spring3的開發(fā)工作就已經(jīng)完成了,所以Spring3中還是沒有對(duì)Mybatis3的支持。因此由Mybatis社區(qū)自己開發(fā)了一個(gè)Mybatis-Spring用來滿足Mybatis用戶整合Spring的需求,下面通過Mybatis-Spring來整合Mybatis跟Spring的用法做介紹2015-10-10

