Browse Source

小程序授权改为一一对应

pull/385/head
wanjing 10 months ago
parent
commit
f80dfa20e0
4 changed files with 33 additions and 87 deletions
  1. +14
    -15
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/query/QueryInspectionPageListService.java
  2. +3
    -3
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/WxController.java
  3. +1
    -14
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IWxService.java
  4. +15
    -55
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java

+ 14
- 15
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/query/QueryInspectionPageListService.java View File

@@ -9,7 +9,6 @@ import com.tuoheng.admin.conver.InspectionConverMapper;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.DataPermissionEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.code.inspection.QueryInspectionPageListCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest;
import com.tuoheng.admin.service.inspection.query.handle.GenerateInspectionFieldHander;
@@ -125,14 +124,14 @@ public class QueryInspectionPageListService {
return result;
}

if(StringUtils.isEmpty(request.getDeptId())){
List<String> deptIdList = new ArrayList<>();
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) {
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) {
deptIdList = deptMapper.selectAllChildListById(user.getDeptId());
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) {
deptIdList.add(user.getDeptId());
}
if (StringUtils.isEmpty(request.getDeptId())) {
List<String> deptIdList = new ArrayList<>();
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) {
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) {
deptIdList = deptMapper.selectAllChildListById(user.getDeptId());
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) {
deptIdList.add(user.getDeptId());
}
request.setDeptIdList(deptIdList);
}

@@ -200,8 +199,8 @@ public class QueryInspectionPageListService {

/**
* 管理员和普通用户可查本部门及子部门的任务
* 1)、如果前端检索条件,传了部门Id,则根据deptId来查
* 2)、如果前端检索条件,部门Id为空,则表示查本部门及子部门的任务
* 1)、如果前端检索条件,传了部门Id,则根据deptId来查
* 2)、如果前端检索条件,部门Id为空,则表示查本部门及子部门的任务
*
* @param request
* @return
@@ -221,8 +220,8 @@ public class QueryInspectionPageListService {
}

/**
* 1)、查找已确认问题数、发现问题数字段
* 2)、判断是否有操作权限:立即执行、直播、回放、问题详情、问题核实、重新提交
* 1)、查找已确认问题数、发现问题数字段
* 2)、判断是否有操作权限:立即执行、直播、回放、问题详情、问题核实、重新提交
*
* @param user
* @param dept
@@ -288,8 +287,8 @@ public class QueryInspectionPageListService {
}

/**
* 设置任务列表中每一个任务的部门名称
* 查询到的任务列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中
* 设置任务列表中每一个任务的部门名称
* 查询到的任务列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中
*
* @param inspectionList
* @return

+ 3
- 3
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/WxController.java View File

@@ -20,11 +20,11 @@ public class WxController {
private IWxService iWxService;

//根据code获取openId
/* @GetMapping("/getOpenId/{code}")
@GetMapping("/getOpenId/{code}")
public JsonResult getOpenId(@PathVariable("code") String code) {
log.info("进入获取openId接口");
return iWxService.openid(code);
}*/
return iWxService.openId(code);
}

@PostMapping("/send/message")
public JsonResult sendMessage(@RequestBody WxMessageRequest wxMessageRequest) {

+ 1
- 14
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IWxService.java View File

@@ -14,7 +14,7 @@ public interface IWxService {
* @param code
* @return
*/
// JsonResult openid(String code);
JsonResult openId(String code);

/**
* 发送消息
@@ -23,17 +23,4 @@ public interface IWxService {
*/
JsonResult sendMessage(WxMessageRequest wxMessageRequest);

/**
* 根据code获取openId且判断用户是否授权
* @param code
* @return
*/
JsonResult checkAuthorize(String code);

/**
* 微信授权
* @param openId
* @return
*/
JsonResult bind(String openId);
}

+ 15
- 55
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java View File

@@ -20,7 +20,6 @@ import com.tuoheng.miniprogram.param.WxSendMessageParam;
import com.tuoheng.miniprogram.service.IWxService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import com.tuoheng.miniprogram.utils.GetOpenIdUtil;
import com.tuoheng.miniprogram.vo.WxAuthorizeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@@ -59,7 +58,10 @@ public class WxServiceImpl implements IWxService {
* @return
*/
@Override
public JsonResult checkAuthorize(String code) {
public JsonResult openId(String code) {
if (StringUtils.isEmpty(code)) {
return JsonResult.error("code为空");
}
String userId = CurrentUserUtil.getUserId();
String openidResult = GetOpenIdUtil.getopenid(code, CommonConfig.appId, CommonConfig.appSecret);
if (null != JSONObject.parseObject(openidResult).getInteger("errcode") ||
@@ -72,64 +74,23 @@ public class WxServiceImpl implements IWxService {
log.error("获取openid失败:", openidResult);
return JsonResult.error("获取openid失败");
}

//默认为false未授权(对应标识1 弹出授权页面给用户)
boolean flag = false;
//根据当前登录用户id和vx查询授权表是否存在一条授权数据
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery()
.eq(UserAuthorize::getUserId, userId)
.eq(UserAuthorize::getOpenId,openid)
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode()));

//有: 该vx和当前账号绑定过 置为true (对应标识2)
if (!ObjectUtil.isNull(beforeUserAuthorize)) {
flag = true;
}

WxAuthorizeVo wxAuthorizeVo = new WxAuthorizeVo();
wxAuthorizeVo.setIsAuthroize(flag);
wxAuthorizeVo.setOpenId(openid);
return JsonResult.success(wxAuthorizeVo);
}

@Override
public JsonResult bind(String openId) {
String userId = CurrentUserUtil.getUserId();
if(StringUtils.isEmpty(openId)){
return JsonResult.error(UserCodeEnum.USER_ID_IS_NULL.getCode(), UserCodeEnum.USER_ID_IS_NULL.getMsg());
}
if(StringUtils.isEmpty(userId)){
return JsonResult.error(UserCodeEnum.USER_0PENID_IS_NULL.getCode(), UserCodeEnum.USER_0PENID_IS_NULL.getMsg());
}
//openId入库
//根据当前登录用户id查询授权表是否存在一条授权数据
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery()
.eq(UserAuthorize::getUserId, userId)
.eq(UserAuthorize::getOpenId, code)
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNotNull(beforeUserAuthorize)) {
beforeUserAuthorize.setOpenId(openId);
beforeUserAuthorize.setUserId(userId);
beforeUserAuthorize.setUpdateUser(userId);
beforeUserAuthorize.setUpdateTime(DateUtils.now());
int count = userAuthorizeMapper.updateById(beforeUserAuthorize);
if (count <= 0) {
return JsonResult.error("用户更新绑定微信账号失败");
if (ObjectUtil.isEmpty(beforeUserAuthorize)) {
UserAuthorize userAuthorize = new UserAuthorize();
userAuthorize.setOpenId(openid);
userAuthorize.setUserId(userId);
userAuthorize.setCreateTime(DateUtils.now());
userAuthorize.setCreateUser(userId);
int result = userAuthorizeMapper.insert(userAuthorize);
if (result <= 0) {
return JsonResult.error("授权数据入库失败");
}
return JsonResult.success();
}

UserAuthorize userAuthorize = new UserAuthorize();
userAuthorize.setOpenId(openId);
userAuthorize.setUserId(userId);
userAuthorize.setCreateUser(userId);
userAuthorize.setCreateTime(DateUtils.now());
int result = userAuthorizeMapper.insert(userAuthorize);

if (result <= 0) {
return JsonResult.error("授权数据入库失败");
}
//修改authorize为已授权到用户表中
//关联登录用户,已经做过授权 修改授权标识
User user = CurrentUserUtil.getUserInfo();
if (ObjectUtil.isEmpty(user)) {
return JsonResult.error(UserCodeEnum.USER_IS_NULL.getCode(), UserCodeEnum.USER_IS_NULL.getMsg());
@@ -173,7 +134,6 @@ public class WxServiceImpl implements IWxService {
//失效时间 = 当前时间+有效期(提前一分钟,也可以不提前)
expiresTime = System.currentTimeMillis() + (expires_in - 60) * 1000;
}

return accessToken;
}


Loading…
Cancel
Save