...
|
...
|
@@ -3,15 +3,13 @@ package com.yoho.unions.server.service.impl; |
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONException;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.common.utils.JsonUtil;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.service.model.union.bo.*;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareUserApplyListReqBo;
|
|
|
import com.yoho.service.model.union.request.UnionShareUserBankListReqBo;
|
|
|
import com.yoho.service.model.union.request.*;
|
|
|
import com.yoho.service.model.union.response.*;
|
|
|
import com.yoho.unions.common.enums.*;
|
|
|
import com.yoho.unions.common.redis.RedisHashCache;
|
...
|
...
|
@@ -26,7 +24,6 @@ import com.yoho.unions.server.service.IUnionShareService; |
|
|
import com.yoho.unions.utils.DateUtils;
|
|
|
import com.yoho.unions.utils.ImagesHelper;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -290,7 +287,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
List<UnionShareUserApplyListBo> applys=this.unionShareUserApplyMapper.selectByCondition(parm);
|
|
|
for(UnionShareUserApplyListBo bo:applys){
|
|
|
bo.setSocialMediaType(null==bo.getSocialMediaType()?null:SocialMediaTypeEnum.getNameByType(Integer.parseInt(bo.getSocialMediaType())));
|
|
|
covertSocialMedia(bo);
|
|
|
}
|
|
|
PageResponseBO<UnionShareUserApplyListBo> result=new PageResponseBO<>();
|
|
|
result.setList(applys);
|
...
|
...
|
@@ -299,6 +296,21 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
result.setTotal(total);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private void covertSocialMedia(UnionShareUserApplyListBo bo) {
|
|
|
if (null != bo.getSocialMedia()) {
|
|
|
List<SocialMediaBo> socialMediaBos = JsonUtil.jsonToList(bo.getSocialMedia(), SocialMediaBo.class);
|
|
|
StringBuilder socialMediaBuilder = new StringBuilder();
|
|
|
socialMediaBos.forEach(s->{
|
|
|
socialMediaBuilder.append(SocialMediaTypeEnum.getNameByType(s.getSocialMediaType()));
|
|
|
socialMediaBuilder.append("("+s.getSocialMediaAccount()+"):");
|
|
|
socialMediaBuilder.append(s.getSocialMediaFans());
|
|
|
socialMediaBuilder.append("<br>");
|
|
|
});
|
|
|
bo.setSocialMedia(socialMediaBuilder.toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 拒绝用户申请
|
|
|
* @param req
|
...
|
...
|
@@ -306,8 +318,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
*/
|
|
|
@Override
|
|
|
public int refuseApply(IdOrIdsBo req){
|
|
|
logger.info("refuseApply,req is {}", req);
|
|
|
UnionShareUserApply unionShareUserApply = unionShareUserApplyMapper.selectByPrimaryKey(req.getId());
|
|
|
if (unionShareUserApply == null || unionShareUserApply.getStatus() > 1) {
|
|
|
logger.info("refuseApply end,selectByPrimaryKey null,req is {}", req);
|
|
|
return 0;
|
|
|
}
|
|
|
UnionShareUserApply updateReq = new UnionShareUserApply();
|
...
|
...
|
@@ -326,11 +340,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
*/
|
|
|
@Override
|
|
|
public int agreeApply(IdOrIdsBo req){
|
|
|
|
|
|
logger.info("agreeApply,req is {}", req);
|
|
|
if (req.getId() != null) {
|
|
|
logger.info("agreeApply,id opt,req is {}", req);
|
|
|
//单个操作
|
|
|
UnionShareUserApply unionShareUserApply = unionShareUserApplyMapper.selectByPrimaryKey(req.getId());
|
|
|
if (unionShareUserApply == null || unionShareUserApply.getStatus() > 1) {
|
|
|
logger.info("agreeApply,selectByPrimaryKey null,req is {}", req);
|
|
|
return 0;
|
|
|
}
|
|
|
UnionShareUserApply updateReq = new UnionShareUserApply();
|
...
|
...
|
@@ -340,11 +356,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int result=unionShareUserApplyMapper.updateByPrimaryKeySelective(updateReq);
|
|
|
if (result > 0) {
|
|
|
// 绑定unionType
|
|
|
relateUnionType(unionShareUserApply.getUid());
|
|
|
relateUnionType(unionShareUserApply.getUid(),updateReq.getId());
|
|
|
}
|
|
|
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),unionShareUserApply.getUid());
|
|
|
return result;
|
|
|
} else {
|
|
|
logger.info("agreeApply,ids opt,req is {}", req);
|
|
|
//批量操作
|
|
|
Set<Integer> idSet = Arrays.stream(req.getIds().split(",")).map(s->{
|
|
|
Integer skn = null;
|
...
|
...
|
@@ -358,24 +375,45 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int currentTimeSecond = DateUtil.getCurrentTimeSecond();
|
|
|
int result=unionShareUserApplyMapper.updateStatus(idSet,1,2, currentTimeSecond);
|
|
|
if (result == 0) {
|
|
|
logger.info("agreeApply,updateStatus null,req is {}", req);
|
|
|
return 0;
|
|
|
}
|
|
|
List<UnionShareUserApply> unionShareUserApplies = unionShareUserApplyMapper.selectByIds(idSet);
|
|
|
if (CollectionUtils.isEmpty(unionShareUserApplies)) {
|
|
|
logger.info("agreeApply,selectByIds null,req is {}", req);
|
|
|
return 0;
|
|
|
}
|
|
|
unionShareUserApplies.forEach(u->{
|
|
|
if (u.getCheckTime() != currentTimeSecond) {
|
|
|
return;
|
|
|
}
|
|
|
relateUnionType(u.getUid());
|
|
|
try {
|
|
|
relateUnionType(u.getUid(),u.getId());
|
|
|
} catch (Exception e) {
|
|
|
logger.error("relateUnionType error ,uid is {}",u.getUid());
|
|
|
}
|
|
|
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),u.getUid());
|
|
|
});
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void relateUnionType(int uid) {
|
|
|
public void relateUnionType(int uid,int applyId) {
|
|
|
logger.info("relateUnionType,uid is {}", uid);
|
|
|
UnionShareUser unionShareUser1 = unionShareUserMapper.selectByUid(uid);
|
|
|
if (null != unionShareUser1) {
|
|
|
logger.info("relateUnionType,uid is {},has unionType,record is {}", uid,unionShareUser1);
|
|
|
//用户已绑定生成unionType
|
|
|
//todo 直接返回成功
|
|
|
//是否删除:1-正常,0-删除
|
|
|
if (unionShareUser1.getStatus() == 0) {
|
|
|
//todo 目前没有删除操作,不会存在这个情况
|
|
|
}
|
|
|
if (unionShareUser1.getApplyId() == null || unionShareUser1.getApplyId() == 0) {
|
|
|
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
//生成unionType
|
|
|
MktMarketingUrl unionDepartmentUrl = buildMktMarketingUrl(uid);
|
|
|
mktMarketingUrlDAO.insertSelective(unionDepartmentUrl);
|
...
|
...
|
@@ -385,10 +423,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
unionShareUser.setUnionType(unionDepartmentUrl.getUnionType().toString());
|
|
|
unionShareUser.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionShareUser.setUpdateTime(unionShareUser.getCreateTime());
|
|
|
unionShareUser.setApplyId(applyId);
|
|
|
unionShareUserMapper.insertSelective(unionShareUser);
|
|
|
}
|
|
|
|
|
|
public MktMarketingUrl buildMktMarketingUrl(int uid) {
|
|
|
logger.info("buildMktMarketingUrl,uid is {}", uid);
|
|
|
MktMarketingUrl mktMarketingUrl = new MktMarketingUrl();
|
|
|
mktMarketingUrl.setChannelType(1);//渠道类型:0-机构 1-个人
|
|
|
mktMarketingUrl.setPayChannel(1);
|
...
|
...
|
@@ -424,19 +464,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
logger.info("UnionShareServiceImpl :: queryUnionTypeByUid get redis cache ,uid is {},cacheResult is {}",uid,cacheResult);
|
|
|
return cacheResult;
|
|
|
}
|
|
|
//获取数据库
|
|
|
UnionShareUser unionShareUser = unionShareUserMapper.selectByUid(uid);
|
|
|
if (null == unionShareUser){
|
|
|
return null;
|
|
|
}
|
|
|
UnionShareUserBo bo = new UnionShareUserBo();
|
|
|
BeanUtils.copyProperties(unionShareUser,bo);
|
|
|
//是否已同意协议:1-同意,0-未同意
|
|
|
bo.setContractAgree(1==unionShareUser.getContractStatus());
|
|
|
if (uid == 0) {
|
|
|
//获取数据库
|
|
|
UnionShareUser unionShareUser = unionShareUserMapper.selectByUid(uid);
|
|
|
if (null != unionShareUser && unionShareUser.getStatus() == 1) {
|
|
|
BeanUtils.copyProperties(unionShareUser, bo);
|
|
|
}
|
|
|
|
|
|
//是否存在申请中的请求
|
|
|
bo.setHasApply(hasApply(uid));
|
|
|
}
|
|
|
|
|
|
//设置返回文案
|
|
|
bo.setShareId(configReader.getString(UNION_SHAREID, ""));
|
|
|
bo.setImageUrl(configReader.getString(UNION_CPS_IMAGEURL, ""));
|
|
|
bo.setApplyImageUrl(configReader.getString(UNION_CPS_APPLY_IMAGEURL, ""));
|
|
|
bo.setShareId(configReader.getString(UNION_SHAREID, ""));//列表分享的活动id
|
|
|
bo.setImageUrl(configReader.getString(UNION_CPS_IMAGEURL, ""));//分享banner
|
|
|
bo.setApplyImageUrl(configReader.getString(UNION_CPS_APPLY_IMAGEURL, ""));//申请banner
|
|
|
|
|
|
//设置缓存
|
|
|
addToRedis(ShareOrdersKeyEnum.UNION_TYPE, uid, bo, key);
|
...
|
...
|
@@ -444,22 +487,47 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同意协议
|
|
|
* @param uid
|
|
|
* 是否存在申请中的请求
|
|
|
* */
|
|
|
@Override
|
|
|
public boolean hasApply(int uid) {
|
|
|
UnionShareUserApply record = new UnionShareUserApply();
|
|
|
record.setUid(uid);
|
|
|
record.setStatus((byte)1);
|
|
|
int count = unionShareUserApplyMapper.selectCountByUid(record);
|
|
|
if (count > 0) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 申请
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public int agreeContract(int uid){
|
|
|
logger.info("agreeContract,uid is {}",uid);
|
|
|
if (uid < 1) {
|
|
|
return 0;
|
|
|
public int userApply(UnionShareUserApplyReqBo req){
|
|
|
if (req.getUid() == null) {
|
|
|
throw new ServiceException(ServiceError.USER_ID_ERROR);
|
|
|
}
|
|
|
UnionShareUser updateReq = new UnionShareUser();
|
|
|
updateReq.setUid(uid);
|
|
|
updateReq.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
updateReq.setContractStatus(1);//是否已同意协议:1-同意,0-未同意
|
|
|
int result = unionShareUserMapper.updateByUid(updateReq);
|
|
|
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),uid);
|
|
|
UnionShareUser unionShareUser = unionShareUserMapper.selectByUid(req.getUid());
|
|
|
if (unionShareUser != null) {
|
|
|
//已是联盟用户
|
|
|
throw new ServiceException(ServiceError.UNION_HAS_UNIONTYPE_ERROR);
|
|
|
}
|
|
|
if (hasApply(req.getUid())) {
|
|
|
//已有申请中的
|
|
|
throw new ServiceException(ServiceError.UNION_HAS_APPLY_ERROR);
|
|
|
}
|
|
|
//申请
|
|
|
UnionShareUserApply unionShareUserApply = new UnionShareUserApply();
|
|
|
BeanUtils.copyProperties(req,unionShareUserApply);
|
|
|
unionShareUserApply.setStatus((byte) 1);
|
|
|
unionShareUserApply.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionShareUserApply.setSocialMedia(JsonUtil.objectToJSON(req.getSocialMediaList()));
|
|
|
int result = unionShareUserApplyMapper.insertSelective(unionShareUserApply);
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
...
|
...
|
|