|
|
|
@ -2,27 +2,29 @@ package com.huoran.nakadai.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.huoran.common.constant.SMSTemplate; |
|
|
|
|
import com.huoran.common.exception.CustomException; |
|
|
|
|
import com.huoran.common.exception.ExceptionEnum; |
|
|
|
|
import com.huoran.common.response.R; |
|
|
|
|
import com.huoran.common.utils.HttpClientUtils; |
|
|
|
|
import com.huoran.common.utils.JwtUtils; |
|
|
|
|
import com.huoran.common.utils.MD5; |
|
|
|
|
import com.huoran.common.utils.TokenUtils; |
|
|
|
|
import com.huoran.nakadai.entity.*; |
|
|
|
|
import com.huoran.nakadai.entity.req.AccountRegisterReq; |
|
|
|
|
import com.huoran.nakadai.entity.req.AppletCallbackReq; |
|
|
|
|
import com.huoran.nakadai.entity.req.InviteJoinInfo; |
|
|
|
|
import com.huoran.nakadai.entity.req.PlatformTeamAccountListReq; |
|
|
|
|
import com.huoran.nakadai.entity.res.PartnerAccountResp; |
|
|
|
|
import com.huoran.nakadai.entity.res.PlatformTeamAccountResp; |
|
|
|
|
import com.huoran.nakadai.entity.res.TeamAccountResp; |
|
|
|
|
import com.huoran.nakadai.mapper.HrStaffMapper; |
|
|
|
|
import com.huoran.nakadai.mapper.PlatformTeamAccountMapper; |
|
|
|
|
import com.huoran.nakadai.mapper.PlatformTeamClassificationMapper; |
|
|
|
|
import com.huoran.nakadai.mapper.PlatformTeamMapper; |
|
|
|
|
import com.huoran.nakadai.mapper.*; |
|
|
|
|
import com.huoran.nakadai.service.PlatformTeamAccountService; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.huoran.nakadai.utils.QrCodeUtil; |
|
|
|
@ -31,6 +33,7 @@ import org.apache.commons.collections4.map.HashedMap; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
@ -51,6 +54,12 @@ public class PlatformTeamAccountServiceImpl extends ServiceImpl<PlatformTeamAcco |
|
|
|
|
@Autowired |
|
|
|
|
private HrStaffMapper staffMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private RedisTemplate<String, String> redisTemplate; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private PartnerAccountMapper partnerAccountMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private PlatformTeamClassificationMapper platformTeamClassificationMapper; |
|
|
|
|
|
|
|
|
@ -102,10 +111,29 @@ public class PlatformTeamAccountServiceImpl extends ServiceImpl<PlatformTeamAcco |
|
|
|
|
//更新登录时间
|
|
|
|
|
baseMapper.updateUserInfo(userAccount.getUserId()); |
|
|
|
|
data.put("state", "login"); |
|
|
|
|
data.put("teamName", userAccount.getAccount() + "的团队"); |
|
|
|
|
data.put("platformId", platformId); |
|
|
|
|
data.put("token", JwtUtils.getJwtToken(userAccount.getId().toString())); |
|
|
|
|
userExists = true; // 如果用户存在,将标志位设为true
|
|
|
|
|
break; // 如果找到用户,就不需要继续查找
|
|
|
|
|
}else { |
|
|
|
|
//根据手机号查询用户
|
|
|
|
|
UserAccount userAccountByPhone = baseMapper.selectAccount(appletCallbackReq.getPhone(),platformId.toString()); |
|
|
|
|
if (userAccountByPhone!= null){ |
|
|
|
|
if (!userAccount.getIsEnable()){ |
|
|
|
|
throw new CustomException(ExceptionEnum.ACCOUNT_DISABLED); |
|
|
|
|
} |
|
|
|
|
//邀请添加用户没有openid,登录更新openId
|
|
|
|
|
baseMapper.updateAccountOpenId(openid,userAccountByPhone.getId()); |
|
|
|
|
//更新登录时间
|
|
|
|
|
baseMapper.updateUserInfo(userAccount.getUserId()); |
|
|
|
|
data.put("state", "login"); |
|
|
|
|
data.put("teamName", userAccount.getAccount() + "的团队"); |
|
|
|
|
data.put("platformId", platformId); |
|
|
|
|
data.put("token", JwtUtils.getJwtToken(userAccount.getId().toString())); |
|
|
|
|
userExists = true; // 如果用户存在,将标志位设为true
|
|
|
|
|
break; // 如果找到用户,就不需要继续查找
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -122,6 +150,13 @@ public class PlatformTeamAccountServiceImpl extends ServiceImpl<PlatformTeamAcco |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R kindergartenWeChatApplication(AppletCallbackReq appletCallbackReq) { |
|
|
|
|
UserAccount userAccount = baseMapper.selectAccountByOpenId(appletCallbackReq.getOpenId(), appletCallbackReq.getPlatformId()); |
|
|
|
|
//根据手机号查询用户
|
|
|
|
|
UserAccount userAccountByPhone = baseMapper.selectAccount(appletCallbackReq.getPhone(),appletCallbackReq.getPlatformId().toString()); |
|
|
|
|
if (userAccount != null || userAccountByPhone!= null){ |
|
|
|
|
return R.error("该用户已存在"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Map<String, Object> data = new HashedMap<String, Object>(); |
|
|
|
|
String randomNumbers = cn.hutool.core.util.RandomUtil.randomNumbers(6); |
|
|
|
|
Integer accountId ; |
|
|
|
@ -187,6 +222,7 @@ public class PlatformTeamAccountServiceImpl extends ServiceImpl<PlatformTeamAcco |
|
|
|
|
|
|
|
|
|
// 注册成功返回token
|
|
|
|
|
data.put("token", JwtUtils.getJwtToken(accountId.toString())); |
|
|
|
|
data.put("registerId", accountId); |
|
|
|
|
data.put("openId", appletCallbackReq.getOpenId()); |
|
|
|
|
return R.ok().put("data",data); |
|
|
|
|
} |
|
|
|
@ -246,4 +282,99 @@ public class PlatformTeamAccountServiceImpl extends ServiceImpl<PlatformTeamAcco |
|
|
|
|
String result = HttpClientUtils.doPost(REQUEST_URL, requestUrlParam); |
|
|
|
|
return JSON.parseObject(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R inviteJoinOrganization(InviteJoinInfo inviteJoinInfo) { |
|
|
|
|
//验证邀请码是否过期
|
|
|
|
|
String uniqueIdentification = inviteJoinInfo.getPlatformId()+ inviteJoinInfo.getAccountId()+"kindergartenInvitationCode"; |
|
|
|
|
String code = redisTemplate.opsForValue().get(uniqueIdentification); |
|
|
|
|
if (StringUtils.isEmpty(code)) { |
|
|
|
|
throw new CustomException(ExceptionEnum.INVITATION_CODE_EXPIRED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String key = StringUtils.join(inviteJoinInfo.getPhone(), SMSTemplate.AUTHENTICATION_CODE); |
|
|
|
|
String value = redisTemplate.opsForValue().get(key); |
|
|
|
|
if (StringUtils.isEmpty(value)) { |
|
|
|
|
throw new CustomException(ExceptionEnum.CODE_EXPIRED); |
|
|
|
|
} |
|
|
|
|
//验证手机验证码
|
|
|
|
|
if (inviteJoinInfo.getCode().equals(value)) { |
|
|
|
|
|
|
|
|
|
//查询邀请用户是否存在账号
|
|
|
|
|
UserAccount userAccount = baseMapper.selectAccount(inviteJoinInfo.getPlatformId().toString(), inviteJoinInfo.getPhone()); |
|
|
|
|
|
|
|
|
|
Integer manageId ; |
|
|
|
|
//邀请人为成员且账号存在,则直接拉入该团队,不可重复拉入
|
|
|
|
|
if (userAccount != null) { |
|
|
|
|
//无法加入自己的团队
|
|
|
|
|
if (inviteJoinInfo.getAccountId().equals(userAccount.getId().toString())) { |
|
|
|
|
throw new CustomException(ExceptionEnum.CANT_JOIN_TEAM); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//查询合伙人账号
|
|
|
|
|
PlatformTeamAccount platformTeamAccount = baseMapper.selectOne(new QueryWrapper<PlatformTeamAccount>(). |
|
|
|
|
eq("account_id", userAccount.getId())); |
|
|
|
|
manageId = platformTeamAccount.getManageId(); |
|
|
|
|
|
|
|
|
|
//被邀请人有合伙人账号,判断是否已经存在当前团队中
|
|
|
|
|
if (ObjectUtil.isNotNull(platformTeamAccount)){ |
|
|
|
|
List<PlatformTeam> platformTeamList = platformTeamMapper.selectList(new QueryWrapper<PlatformTeam>(). |
|
|
|
|
eq("manage_id", platformTeamAccount.getManageId())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询团队下的成员是否存在团队中
|
|
|
|
|
List<PlatformTeamClassification> teamMeb = platformTeamClassificationMapper.selectList(new QueryWrapper<PlatformTeamClassification>(). |
|
|
|
|
eq("parent_id", inviteJoinInfo.getClassificationId())); |
|
|
|
|
|
|
|
|
|
for (PlatformTeam platformTeam : platformTeamList) { |
|
|
|
|
for (PlatformTeamClassification platformTeamClassification : teamMeb) { |
|
|
|
|
if (platformTeam!=null&&platformTeamClassification!=null){ |
|
|
|
|
if (platformTeam.getClassificationId().equals(platformTeamClassification.getId())){ |
|
|
|
|
throw new CustomException(ExceptionEnum.USER_ALREADY_EXISTS_GROUP); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
//不存在创建账号,拉入组织
|
|
|
|
|
AppletCallbackReq appletCallbackReq = new AppletCallbackReq(); |
|
|
|
|
appletCallbackReq.setPlatformId(inviteJoinInfo.getPlatformId()); |
|
|
|
|
appletCallbackReq.setPhone(inviteJoinInfo.getPhone()); |
|
|
|
|
appletCallbackReq.setOpenId("0"); |
|
|
|
|
R r = kindergartenWeChatApplication(appletCallbackReq); |
|
|
|
|
Map<String, Object> data =(Map<String, Object>) r.get("data"); |
|
|
|
|
Integer registerId =(Integer) data.get("registerId"); |
|
|
|
|
//添加团队管理账号
|
|
|
|
|
PlatformTeamAccount platformTeamAccount = new PlatformTeamAccount(); |
|
|
|
|
platformTeamAccount.setAccountId(registerId); |
|
|
|
|
platformTeamAccount.setPlatformId(inviteJoinInfo.getPlatformId()); |
|
|
|
|
String username = partnerAccountMapper.selectUsername(inviteJoinInfo.getAccountId()); |
|
|
|
|
platformTeamAccount.setInvitationAccount(username); |
|
|
|
|
baseMapper.insert(platformTeamAccount); |
|
|
|
|
|
|
|
|
|
manageId = platformTeamAccount.getManageId(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PlatformTeamClassification platformTeamAdmin = platformTeamClassificationMapper.selectById(inviteJoinInfo.getClassificationId()); |
|
|
|
|
//新增团队成员
|
|
|
|
|
PlatformTeamClassification platformTeamMeb = new PlatformTeamClassification(); |
|
|
|
|
platformTeamMeb.setIsTeam(0); |
|
|
|
|
platformTeamMeb.setParentId(inviteJoinInfo.getClassificationId()); |
|
|
|
|
platformTeamMeb.setLevel(platformTeamAdmin.getLevel() + 1); |
|
|
|
|
platformTeamMeb.setClassificationName(platformTeamAdmin.getClassificationName()); |
|
|
|
|
int insert = platformTeamClassificationMapper.insert(platformTeamMeb); |
|
|
|
|
|
|
|
|
|
//团队分类
|
|
|
|
|
if (insert > 0) { |
|
|
|
|
PlatformTeam platformTeam = new PlatformTeam(); |
|
|
|
|
platformTeam.setManageId(manageId); |
|
|
|
|
platformTeam.setClassificationId(platformTeamMeb.getId()); |
|
|
|
|
platformTeamMapper.insert(platformTeam); |
|
|
|
|
} |
|
|
|
|
return insert > 0 ? R.ok() : R.error(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
throw new CustomException(ExceptionEnum.CODE_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|