Browse Source

Merge remote-tracking branch 'origin/dev' into dev

loovi 1 year ago
parent
commit
e69464c086

+ 7 - 6
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleService.java

@@ -77,7 +77,7 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
 	 * 审核
 	 */
 	boolean judge(TbPeople tbPeople){
-		//获取当前登陆人
+		//获取当前登陆人 todo:
 		String loginUser = "admin";
 		//获取当前被审核人的编号和审核情况
 		Long id = tbPeople.getId();
@@ -121,6 +121,7 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
 		int i = tbPeopleMapper.updateById(tbPeople1);
 		//远程调用停用app user表中的边民账号
 		int lock = adminInterface.isLock(id.toString(), People.PEOPLE_TYPE_ONE.getCode(), isLock);
+		//todo: 处理远程调用后的返回结果
 //		if((lock + i) != 2)throw new RuntimeException("停用失败!");
 //
 //		return i == 1 && lock == 1;
@@ -134,11 +135,11 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
 
 	}
 
-
-	/** 边民账号停用后不能登录app */
-	void loginPeople(String userName,String password){
-
-	}
+//
+//	/** 边民账号停用后不能登录app */
+//	void loginPeople(String userName,String password){
+//
+//	}
 
 
 

+ 56 - 0
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserApiController.java

@@ -0,0 +1,56 @@
+package com.pj.project.app_user;
+
+import com.pj.project.app_user.dto.ForgetPasswordDto;
+import com.pj.project.app_user.dto.RegisterDto;
+import com.pj.utils.sg.AjaxJson;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+
+
+/**
+ * Controller: app_user -- 移动端账号(只针对app端使用)
+ * @author yzs
+ */
+@RestController
+@RequestMapping("/app/AppUser/")
+public class AppUserApiController {
+
+	/** 底层 Service 对象 */
+	@Autowired
+	AppUserService appUserService;
+
+
+	/** 用户注册 */
+	@RequestMapping("register")
+	public AjaxJson register(@Validated @RequestBody RegisterDto registerDto) {
+		boolean register = appUserService.register(registerDto);
+		if(!register)return AjaxJson.getError("注册失败!");
+		return AjaxJson.getSuccess( "注册完成!");
+	}
+
+	/** 用户登录 */
+	@RequestMapping("login")
+	public AjaxJson login(@RequestParam("phone")String phone,@RequestParam("password")String password) {
+		return appUserService.login(phone,password);
+	}
+
+	/** 忘记密码 */
+	@RequestMapping("forgetPassword")
+	public AjaxJson forgetPassword(@Validated @RequestBody ForgetPasswordDto forgetPasswordDto) {
+		return appUserService.forgetPassword(forgetPasswordDto);
+	}
+
+	/** 获取短信验证码 */
+	@RequestMapping("getPhoneSmsCode")
+	public AjaxJson getPhoneSmsCode(String phone) {
+		boolean phoneSmsCode = appUserService.getPhoneSmsCode(phone);
+		if(phoneSmsCode)return AjaxJson.getSuccess("验证码发送成功!");
+		return AjaxJson.getError();
+	}
+
+}

+ 0 - 20
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserController.java

@@ -80,26 +80,6 @@ public class AppUserController {
 		return AjaxJson.getPageData(so.getDataCount(), list);
 	}
 
-	/** 用户注册 */
-	@RequestMapping("register")
-	public AjaxJson register(@Validated @RequestBody RegisterDto registerDto) {
-		boolean register = appUserService.register(registerDto);
-		if(!register)return AjaxJson.getError("注册失败!");
-		return AjaxJson.getSuccess(register + "");
-	}
-
-	/** 用户登录 */
-	@RequestMapping("login")
-	public AjaxJson login(@RequestParam("phone")String phone,@RequestParam("password")String password) {
-		return appUserService.login(phone,password);
-	}
-
-	/** 忘记密码 */
-	@RequestMapping("forgetPassword")
-	public AjaxJson forgetPassword(ForgetPasswordDto forgetPasswordDto) {
-		return appUserService.forgetPassword(forgetPasswordDto);
-	}
-
 
 
 	/*-----               正常业务接口👆👆    不越界     rpc远程调用 👇👇                     -----*/

+ 26 - 7
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java

@@ -40,9 +40,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 	//权限字符
 	@Autowired
 	private ReRoleMenuMapper reRoleMenuMapper;
-	/** 方法抽取 */
-	@Autowired
-	private MethodAppUserService methodAppUserService;
+
 
 
 
@@ -58,6 +56,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 
 	/** 改 */
 	void update(AppUser a){
+		a.setUpdateTime(new Date());
 		updateById(a);
 
 	}
@@ -154,6 +153,8 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 		if(appUser.getStatus().equals("0"))return AjaxJson.getError("该账户 " + appUser.getPhone() + " 已停用!");
 		//设置登录次数
 		appUser.setLoginCount(appUser.getLoginCount() + 1);
+		//保存
+		appUserMapper.updateById(appUser);
 		//开始执行登录
 		StpUtil.login(appUser.getId());
 		// 组织返回参数,直接拿过来用的,然后自己改吧改吧
@@ -183,15 +184,18 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 				  (new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, forgetPasswordDto.getPhone())
 													.eq(AppUser::getDeleteStatus, 1)
 													.eq(AppUser::getStatus, 1));
-		if(appUserList.size() != 1)return AjaxJson.getError("当前账户存在异常,请联系客服进行处理!");
+		//判断其手机号码可能存在的异常情况
+		if(appUserList.size() > 1)
+			return AjaxJson.getError("当前账户存在异常,请联系客服进行处理!");
+		if(appUserList.size() == 0)throw new RuntimeException("您当前手机号尚未进行注册!");
 		//获取当前手机号对象
 		AppUser appUser = appUserList.get(0);
 		//获取短信验证码发送结果
-		boolean sendResult = methodAppUserService.getSmsCode(forgetPasswordDto.getPhone());
-		if(!sendResult)return AjaxJson.getError("验证码发送失败!");
+		boolean phoneSmsCode = getPhoneSmsCode(forgetPasswordDto.getPhone());
+		if(!phoneSmsCode)return AjaxJson.getError("验证码发送失败!");
 		//从缓存中获取验证码
 		String smsCode = RedisUtil.get(forgetPasswordDto.getPhone());
-		if(smsCode == null)return AjaxJson.getError("验证码发送失败!");
+		if(smsCode == null)return AjaxJson.getError("验证码已过期!");
 		//比对用户输入的验证码
 		boolean result = smsCode.equals(forgetPasswordDto.getSmsCode());
 		//进行验证码校验完成后的流程
@@ -209,7 +213,9 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 				if(i != 1)return AjaxJson.getError("密码重置失败!");
 				return AjaxJson.getSuccess("密码找回成功!");
 			}else {
+
 				return AjaxJson.getError("两次密码校验不匹配,请重新尝试!");
+
 			}
 
 		}
@@ -218,4 +224,17 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 		return AjaxJson.getError("验证码输入错误,请检查!");
 	}
 
+	/** 获取验证码 */
+	boolean getPhoneSmsCode(String phone){
+		//todo: 发送短信,其短信商回调验证码
+		String smsCode = "123";
+		//todo: 根据其短信发送情况返回不同的结果
+
+		// return false;
+
+		//todo: 保存到缓存,默认1分钟
+		RedisUtil.setByMINUTES(phone,smsCode, 1);
+
+		return true;
+	}
 }

+ 0 - 23
sp-service/sp-admin/src/main/java/com/pj/project/app_user/MethodAppUserService.java

@@ -1,13 +1,8 @@
 package com.pj.project.app_user;
 
-import com.pj.utils.cache.RedisUtil;
-import org.omg.CORBA.TIMEOUT;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.concurrent.TimeUnit;
-
 /**
  * @Author Mechrevo
  * @Date 2023 07 25 15 05
@@ -16,24 +11,6 @@ import java.util.concurrent.TimeUnit;
 @Transactional(rollbackFor = Exception.class)
 public class MethodAppUserService {
 
-    /** App User mapper */
-    @Autowired
-    private AppUserMapper appUserMapper;
-
-
-    /** 获取手机验证码 */
-    boolean getSmsCode(String phone){
-        //todo: 发送短信,其短信商回调验证码
-        String smsCode = "123";
-        //todo: 可能存在短信发送失败情况
-//        if(false)return null;
-//        return false;
-
-
-        //todo: 保存到缓存,默认1分钟
-        RedisUtil.setByMINUTES(phone,smsCode, 1);
 
-        return true;
-    }
 
 }

+ 4 - 4
sp-service/sp-admin/src/main/java/com/pj/project/app_user/dto/ForgetPasswordDto.java

@@ -12,16 +12,16 @@ import javax.validation.constraints.NotNull;
 public class ForgetPasswordDto {
 
     /** 手机号码 */
-    @NotNull
+    @NotNull(message = "手机号不能为空!")
     private String phone;
     /** 短信验证码 */
-    @NotNull
+    @NotNull(message = "短信验证码不能为空!")
     private String smsCode;
     /** 密码 */
-    @NotNull
+    @NotNull(message = "密码不能为空!")
     private String password;
     /** 再次输入密码 */
-    @NotNull
+    @NotNull(message = "再次输入密码不能为空!")
     private String rePassword;
 
 }

+ 37 - 0
sp-service/sp-admin/src/main/java/com/pj/project/re_role_menu/MethodRoleMenuService.java

@@ -0,0 +1,37 @@
+package com.pj.project.re_role_menu;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 07 25 17 30
+ **/
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class MethodRoleMenuService {
+
+    @Autowired
+    private ReRoleMenuMapper reRoleMenuMapper;
+
+    /** 获取该权限的集合 */
+    public List<Long> getPerList(Long roleId){
+        if (roleId == null)throw new RuntimeException("职务不能为空!");
+        //查询该职务下属权限
+        List<ReRoleMenu> reRoleMenus = reRoleMenuMapper.selectList
+                (new LambdaQueryWrapper<ReRoleMenu>().eq(ReRoleMenu::getAppRoleId, roleId));
+        //创建返回值集合
+        List<Long> perList = new ArrayList<>();
+        //遍历集合封装数据
+        reRoleMenus.forEach(item -> {
+            perList.add(item.getId());
+        });
+        return perList;
+    }
+
+}

+ 9 - 2
sp-service/sp-admin/src/main/java/com/pj/project/re_role_menu/ReRoleMenu.java

@@ -3,9 +3,11 @@ package com.pj.project.re_role_menu;
 import java.io.Serializable;
 import com.baomidou.mybatisplus.annotation.*;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.AllArgsConstructor;
 import lombok.EqualsAndHashCode;
 
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 
 /**
@@ -16,6 +18,8 @@ import lombok.experimental.Accessors;
 @Accessors(chain = true)
 @TableName(ReRoleMenu.TABLE_NAME)
 @EqualsAndHashCode(callSuper = false)
+@AllArgsConstructor
+@NoArgsConstructor
 public class ReRoleMenu extends Model<ReRoleMenu> implements Serializable {
 
 	// ---------- 模块常量 ----------
@@ -35,10 +39,13 @@ public class ReRoleMenu extends Model<ReRoleMenu> implements Serializable {
 	public static final String PERMISSION_CODE_EDIT = "re-role-menu-edit";
 	public static final String PERMISSION_CODE_DEL = "re-role-menu-del";
 
+	public ReRoleMenu(Long appRoleId, Long appMenuId) {
+		this.appRoleId = appRoleId;
+		this.appMenuId = appMenuId;
+	}
 
 
-
-	// ---------- 表中字段 ----------
+// ---------- 表中字段 ----------
 	/**
 	 * 主键 
 	 */

+ 17 - 1
sp-service/sp-admin/src/main/java/com/pj/project/re_role_menu/ReRoleMenuController.java

@@ -1,9 +1,12 @@
 package com.pj.project.re_role_menu;
 
 import java.util.List;
+
+import com.pj.project.re_role_menu.dto.AssignPermissionsDto;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import com.pj.utils.sg.*;
@@ -80,7 +83,20 @@ public class ReRoleMenuController {
 		return AjaxJson.getPageData(so.getDataCount(), list);
 	}
 	
-	
+	/**
+	 * pc端:可以根据不同app角色进行菜单权限分配
+	 * @param assignPermissionsDto 职务ID和该职务下属的权限的集合
+	 * @return
+	 */
+	@RequestMapping("assignPermissions")
+		@SaCheckPermission(ReRoleMenu.PERMISSION_CODE)
+	public AjaxJson assignPermissions(@Validated @RequestBody AssignPermissionsDto assignPermissionsDto) {
+		boolean permissions = reRoleMenuService.assignPermissions(assignPermissionsDto);
+		if(permissions)return AjaxJson.getSuccess("权限分配成功!");
+		return AjaxJson.getError("权限分配失败!");
+	}
+
+
 	
 	
 

+ 39 - 1
sp-service/sp-admin/src/main/java/com/pj/project/re_role_menu/ReRoleMenuService.java

@@ -1,13 +1,17 @@
 package com.pj.project.re_role_menu;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.pj.project.re_role_menu.dto.AssignPermissionsDto;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
-import com.pj.utils.sg.*;
 
 /**
  * Service: re_role_menu -- app用户菜单中间表
@@ -20,6 +24,9 @@ public class ReRoleMenuService extends ServiceImpl<ReRoleMenuMapper, ReRoleMenu>
 	/** 底层 Mapper 对象 */
 	@Autowired
 	ReRoleMenuMapper reRoleMenuMapper;
+	/** 方法抽取,优化代码 */
+	@Autowired
+	private MethodRoleMenuService methodRoleMenuService;
 
 	/** 增 */
 	void add(ReRoleMenu r){
@@ -47,6 +54,37 @@ public class ReRoleMenuService extends ServiceImpl<ReRoleMenuMapper, ReRoleMenu>
 		so.set("app_role_id",appRoleId);
 		return reRoleMenuMapper.getList(so);	
 	}
+
+	/** 给app角色分配权限 */
+	boolean assignPermissions(AssignPermissionsDto assignPermissionsDto){
+		//取出数据
+		Long roleId = assignPermissionsDto.getRoleId();
+		List<Long> permissionsDtoList = assignPermissionsDto.getList().stream().distinct().collect(Collectors.toList());
+		//情况1:传进来的集合为空,默认删除该职务下属的所有权限
+		if(permissionsDtoList.size() == 0){
+			//删除所有权限
+			List<Long> perList = methodRoleMenuService.getPerList(roleId);
+			//清除
+			int i = reRoleMenuMapper.deleteBatchIds(perList);
+			return i == perList.size();
+		}
+		//情况2: 传进来的集合不为空
+		//2.1 先清除该职务的权限
+		List<Long> perList = methodRoleMenuService.getPerList(roleId);
+		//执行清除
+		int i = reRoleMenuMapper.deleteBatchIds(perList);
+		if(i != perList.size())throw new RuntimeException("权限分配失败Ⅰ!");
+		//2.2 再添加新的权限给到该职务
+		//定义计数器
+		int count = 0;
+		for(Long item : permissionsDtoList){
+			int insert = reRoleMenuMapper.insert(new ReRoleMenu(roleId, item));
+			count += insert;
+		}
+		if(count != permissionsDtoList.size())throw new RuntimeException("权限分配失败Ⅱ!");
+
+		return count == permissionsDtoList.size();
+	}
 	
 
 }

+ 20 - 0
sp-service/sp-admin/src/main/java/com/pj/project/re_role_menu/dto/AssignPermissionsDto.java

@@ -0,0 +1,20 @@
+package com.pj.project.re_role_menu.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 07 25 17 11
+ **/
+@Data
+public class AssignPermissionsDto {
+
+    @NotNull(message = "职务ID")
+    private Long roleId;
+    @NotNull(message = "集合可以没有值,但不能为null")
+    private List<Long> list;
+
+}