Commit 00c4f321 authored by hezhen's avatar hezhen

123

parent a33ec3c1
......@@ -11,6 +11,7 @@ import com.github.wxiaoqi.security.admin.vo.InviteMemberVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.sun.corba.se.impl.orbutil.concurrent.Sync;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
......@@ -60,6 +61,25 @@ public class AppUserRelationBiz extends BaseBiz<AppUserRelationMapper, AppUserRe
@Autowired
private AppStaffUserBiz staffUserBiz;
private static final HashMap<Integer, Boolean> map = new HashMap<>();
private static final Object obj = new Object();
private boolean lock(Integer userId) {
synchronized (obj) {
if (map.get(userId) == null) {
map.put(userId, true);
return true;
}
}
return false;
}
private void unLock(Integer userId) {
synchronized (obj) {
map.remove(userId);
}
}
/**
* 关系绑定
* 规则A->B (B无有效上线+无有效下线)
......@@ -84,44 +104,48 @@ public class AppUserRelationBiz extends BaseBiz<AppUserRelationMapper, AppUserRe
log.info("----userId==="+userId+"----parentId===="+parentId+"----该上线用户不存在");
return;
}
AppUserRelation relation=getMyBiz().getRelationByUserId(parentId);
Long time=System.currentTimeMillis();
if(relation==null){
relation=new AppUserRelation();
relation.setUserId(parentId);
relation.setBindType(type);
insertSelective(relation);
}
Long bindTime=time-validTime;
//判断用户是否有有效的下线
if (getCountByParentId(userId,bindTime)==0L){
relation=getMyBiz().getRelationByUserId(userId);
if(relation==null){
relation=new AppUserRelation();
relation.setUserId(userId);
relation.setParentId(parentId);
if (lock(userId)) {
AppUserRelation relation = getMyBiz().getRelationByUserId(parentId);
Long time = System.currentTimeMillis();
if (relation == null) {
relation = new AppUserRelation();
relation.setUserId(parentId);
relation.setBindType(type);
relation.setBindTime(time);
insertSelective(relation);
}else {
//判断用户是否有有效的上线
log.info("----userId==="+userId+"----bindTime===="+bindTime+"----relation.getBindTime()==="+relation.getBindTime());
if(relation.getParentId()==null||relation.getParentId()==0||(relation.getIsForever()!=1&&validTime>0&&relation.getBindTime()<bindTime)){
}
Long bindTime = time - validTime;
//判断用户是否有有效的下线
if (getCountByParentId(userId, bindTime) == 0L) {
relation = getMyBiz().getRelationByUserId(userId);
if (relation == null) {
relation = new AppUserRelation();
relation.setUserId(userId);
relation.setParentId(parentId);
relation.setBindType(type);
relation.setBindTime(time);
getMyBiz().updRelation(relation);
insertSelective(relation);
if (relation != null) {
AppStaffUserDTO staffUserDTO = new AppStaffUserDTO();
staffUserDTO.setSuId(relation.getParentId());
staffUserDTO.setUid(relation.getUserId());
staffUserBiz.addAppStaffUser(staffUserDTO);
}
} else {
//判断用户是否有有效的上线
log.info("----userId===" + userId + "----bindTime====" + bindTime + "----relation.getBindTime()===" + relation.getBindTime());
if (relation.getParentId() == null || relation.getParentId() == 0 || (relation.getIsForever() != 1 && validTime > 0 && relation.getBindTime() < bindTime)) {
relation.setParentId(parentId);
relation.setBindType(type);
relation.setBindTime(time);
getMyBiz().updRelation(relation);
}
}
}
if (relation != null){
AppStaffUserDTO staffUserDTO=new AppStaffUserDTO();
staffUserDTO.setSuId(relation.getParentId());
staffUserDTO.setUid(relation.getUserId());
staffUserBiz.addAppStaffUser(staffUserDTO);
}
}
}catch (Exception e){
log.info("网络异常===" + e.getMessage());
}finally {
unLock(userId);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment