Commit 5886b187 by 徐高华

Merge branch 'feature/xgh/代开发调整25年' into 'master'

Feature/xgh/代开发调整25年

See merge request !2801
parents ab36cf27 a85c8a8b
......@@ -81,7 +81,7 @@ public class WxEnterpriseQwDTO implements Serializable {
}
public boolean isSelf() {
return this.wxSecurityType == 5 ;
return this.wxSecurityType == 5 || this.wxSecurityType == 6;
}
public int getWxSecurityType() {
......
......@@ -18,6 +18,17 @@ public class ChatEventDTO implements Serializable {
private String corpid;
// 是否自建应用的回调
private int selfCallback = 0 ;
// 用于判断是否代开发应用的回调
private String suiteId;
public String getSuiteId() {
return suiteId;
}
public void setSuiteId(String suiteId) {
this.suiteId = suiteId;
}
public int getSelfCallback() {
return selfCallback;
}
......
......@@ -12,19 +12,19 @@ import java.util.Set;
*/
public class QywxSyncTagFormatPojo implements Serializable {
/**
* 企业微信与gic标签项对应map
* 企业微信标签值ID -> gic标签值ID
*/
private Map<String, String> qywxToGicTagItemIdMap;
/**
* gic与企业微信标签项对应map
* gic标签值ID -> 企业微信标签值ID
*/
private Map<String, String> gicToQywxTagItemIdMap;
/**
* 商户对应的企业微信标签列表
* gic企业ID -> 企业微信标签值ID LIST
*/
private Map<String, Set<String>> entQywxTagKeysMap;
/**
* 商户对应的gic标签列表
* gic企业ID -> gic标签值ID LIST
*/
private Map<String, Set<String>> entGicTagItemIdMap;
......
......@@ -77,7 +77,7 @@ public class SecretSettingServiceImpl implements SecretSettingService {
return null;
}
// 如果是纯自建,使用自建的token
if(qwDTO.isSelf()) {
if(qwDTO.isSelf() && StringUtils.isNotBlank(qwDTO.getUrlHost())) {
secretType = SecretTypeEnum.SELF_APP.getVal() ;
}
TabSecretSetting secretSetting = secretSettingMapper.getSecretSetting(wxEnterpriseId, secretType, null);
......
......@@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import cn.hutool.core.collection.CollUtil;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
......@@ -52,6 +53,16 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService {
@Override
public String add(WxEnterpriseDTO wxDTO) {
String wxCorpid = wxDTO.getWxCorpid() ;
if(StringUtils.isBlank(wxCorpid)) {
wxCorpid = wxDTO.getOpenCorpid() ;
}
String key = "wxEnterpriseId:"+wxCorpid ;
RedisUtil.lock(key,3L);
TabHaobanWxEnterprise en = this.getEnterpriseBycorpId(wxCorpid);
if(null != en) {
return en.getWxEnterpriseId() ;
}
logger.info("新增wx_enterprise,dto={}",JSON.toJSONString(wxDTO));
Date now = new Date();
wxDTO.setWxEnterpriseId(StringUtil.randomUUID());
......@@ -61,6 +72,7 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService {
tabHaobanWxEnterprise.setStatusFlag(1);
tabHaobanWxEnterprise.setBindFlag(1);
mapper.insertSelective(tabHaobanWxEnterprise);
RedisUtil.unlock(key);
return wxDTO.getWxEnterpriseId();
}
......@@ -119,8 +131,22 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService {
}
qw.setSelfAppid(wxEnterprise.getWxaAppid());
}
qw.setHbWxaAppid(this.getHbAppid(qw, config.getAppid()));
qw.setSelf3thSecret(this.getSecret(qw, config.getWxSuiteid()));
// 只使用代开发(用于从自建转代开发)
if(qw.getWxSecurityType()==6) {
qw.setUrlHost(null);
qw.setDkCorpid(wxEnterprise.getWxCorpid());
qw.setThirdCorpid(wxEnterprise.getWxCorpid());
qw.setMemberCorpid(wxEnterprise.getWxCorpid());
TabSecretSetting secret = secretSettingMapper.getSecretSetting(wxEnterpriseId, SecretTypeEnum.CUSTOMIZED_APP.getVal(), null);
qw.setSelfSecret(secret.getSecretVal());
qw.setSelf3thSecret(secret.getSecretVal());
qw.setSelfAppid(wxEnterprise.getWxaAppid());
TabHaobanWxApplication app = this.wxApplicationMapper.selectByWxEnterpriseIdAndApplicationType(wxEnterpriseId,3) ;
qw.setAgentId(app.getAgentId());
qw.setAgentName(app.getAgentName());
}
qw.setHbWxaAppid(this.getHbAppid(qw, config.getAppid()));
logger.info("企微所有corpid信息={}",JSON.toJSON(qw));
return qw;
}
......
......@@ -426,6 +426,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
@Override
public String addMemberUnionidRelated(QwFrientNoticeDTO dto) {
log.info("加好友={}",JSONObject.toJSONString(dto));
DealQywxExternalUserPojo dealQywxExternalUserPojo = new DealQywxExternalUserPojo();
dealQywxExternalUserPojo.setType(DealQywxExternalUserPojo.DealType.add.getType());
dealQywxExternalUserPojo.setData(dto);
......@@ -445,7 +446,18 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
private void sendWelcome(QwFrientNoticeDTO dto) {
String suiteid = dto.getSuiteid();
if (SELF_APP.equals(suiteid)) {
String corpId = dto.getCorpid();
TabHaobanWxEnterprise wxEnterprise = this.wxEnterpriseService.getEnterpriseBycorpId(corpId) ;
if(null == wxEnterprise) {
log.info("企业查不到={}",corpId);
return ;
}
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterprise.getWxEnterpriseId());
if (qwDTO == null) {
log.info("企业不存在,wxEnterpriseId={}", wxEnterprise.getWxEnterpriseId());
return;
}
if (SELF_APP.equals(suiteid) && qwDTO.getWxSecurityType()!=6) {
return ;
}
if(StringUtils.isEmpty(dto.getWelcomeCode())) {
......@@ -979,7 +991,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
String externalUserid = dto.getExternalUserid();
ExternalUserDTO externalUserDTO;
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
if(qwDTO.isSelf() && dto.getSelfCallback()==0) {
if(qwDTO.isSelf() && dto.getSelfCallback()==0 && qwDTO.getWxSecurityType()==5) {
log.info("非自建应用回调");
return null ;
}
......@@ -1214,8 +1226,8 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
if (null == wxEnterprise) {
return;
}
if (dto.getSuiteid().equals(SELF_APP)) {
log.info("self不执行");
if (dto.getSuiteid().equals(SELF_APP) && wxEnterprise.getWxSecurityType()!=6) {
log.info("self代开发不执行");
return;
}
pushTagSync(dto.getExternalUserid(), wxUserId
......
......@@ -489,7 +489,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
//获取需要同步的标签
QywxSyncTagFormatPojo syncTagFormat = listSyncTagItems(wxEnterpriseId);
if (syncTagFormat == null) {
logger.info("没有需要同步的标签");
logger.info("没有和企微同步的标签={}",wxEnterpriseId);
resp.setCode(2);
resp.setMessage("没有要同步的标签");
return resp;
......@@ -586,6 +586,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
if (MapUtils.isEmpty(relationMap)) {
return null;
}
// 标签项
List<String> syncTagItemsIds = relationMap.keySet().stream().collect(Collectors.toList());
//同步的标签项
......@@ -614,12 +615,13 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
@Override
public ServiceResponse syncQywxTagToGicByExternalUserId(String wxEnterpriseId, String externalUserId, String wxUserId , String externalUserInfo) {
logger.info("staff打标同步gic={},{}",externalUserId,wxUserId);
//刷新标签的时候不允许同步
ServiceResponse resp = new ServiceResponse();
//所有以及关联同步的标签
QywxSyncTagFormatPojo syncTagFormatPojo = listSyncTagItems(wxEnterpriseId);
if (syncTagFormatPojo == null) {
logger.info("没有需要同步的标签,wxUserId:{},externalUserId:{},wxId:{}", wxUserId, externalUserId, wxEnterpriseId);
logger.info("没有和企微同步的标签,wxUserId:{},externalUserId:{},wxId:{}", wxUserId, externalUserId, wxEnterpriseId);
resp.setMessage("没有需要同步的标签");
return resp;
}
......@@ -651,14 +653,14 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
}
Map<String, Set<String>> externalTagMap = getExternalTagMap(externalUseridInfo, wxEnterpriseId);
if (MapUtils.isEmpty(externalTagMap)) {
logger.info("该用户没有不存在好友关系,获取不到关联导购打的标签,:externalUseridInfo:{}", externalUseridInfo);
logger.info("没有staff打的企微标签,externalUseridInfo={}", externalUseridInfo);
resp.setMessage("该用户没有不存在好友关系,获取不到关联导购打的标签");
return resp;
}
//当前操作用户企业打的标签
Set<String> staffChangeTagKeys = externalTagMap.get(wxUserId);
if (CollectionUtils.isEmpty(staffChangeTagKeys)) {
logger.info("该用户没有不存在好友关系,获取不到关联导购打的标签,wxUserId:{}", wxUserId);
logger.info("没有staff打的企微标签,staff-qwUserId={}", wxUserId);
resp.setMessage("该用户没有不存在好友关系,获取不到关联导购打的标签");
return resp;
}
......@@ -667,7 +669,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
//获取该外部联系人的所有会员
List<TabHaobanExternalClerkRelated> clerkRelateds = externalClerkRelatedService.listExternalByExternalUserid(wxEnterpriseId, externalUserId);
if (CollectionUtils.isEmpty(clerkRelateds)) {
logger.info("该用户没关联对应的好友:{}", externalUserId);
logger.info("没有好友={}", externalUserId);
resp.setMessage("该用户没关联对应的好友");
return resp;
}
......@@ -708,7 +710,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
Sets.SetView<String> entMemberNeedSetQywxKeys = Sets.intersection(staffHasSetTagKeys, entQywxSyncTagKeys);
Set<String> saveTagIds = entMemberNeedSetQywxKeys.stream().map(qywxKey -> syncTagFormatPojo.getQywxToGicTagItemIdMap().get(qywxKey)).collect(Collectors.toSet());
saveTagIds.addAll(noSyncTagItemIds);
logger.info("该企业会员需要打的标签:{}", JSONObject.toJSONString(entMemberNeedSetQywxKeys));
logger.info("会员需要打的企微标签:{}", JSONObject.toJSONString(entMemberNeedSetQywxKeys));
//更新标签 会自动同步
if (CollectionUtils.isEmpty(saveTagIds)) {
saveMemberTags(new HashSet<>(), clerkRelated.getEnterpriseId(), memberId, clerkRelated.getClerkId());
......
......@@ -75,6 +75,7 @@ public class GroupChatApiServiceImpl implements GroupChatApiService {
private GroupChatMapper groupChatMapper ;
@Autowired
private GroupChatUserMapper groupChatUserMapper ;
private static final String SELF_APP = "selfSuiteId";
@Override
public ServiceResponse<Page<GroupChatDTO>> listPage(GroupChatSearchQDTO qdto, BasePageInfo basePageInfo) {
......@@ -229,8 +230,14 @@ public class GroupChatApiServiceImpl implements GroupChatApiService {
}
String wxEnterpriseId = wxEnterprise.getWxEnterpriseId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if(qwDTO.isSelf() && dto.getSelfCallback()==0) {
logger.info("非自建应用回调");
if(qwDTO.getWxSecurityType()==5) {
if (qwDTO.isSelf() && dto.getSelfCallback() == 0) {
logger.info("非自建应用回调");
return ServiceResponse.success();
}
}
if(qwDTO.getWxSecurityType() !=6 && StringUtils.isNotBlank(dto.getSuiteId()) && SELF_APP.equals(dto.getSuiteId())) {
logger.info("非仅代开的不处理代发的回调");
return ServiceResponse.success();
}
// 群解散事件
......
......@@ -114,8 +114,8 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
feeOrderListQDTO.setCorpid(corpid);
if (null == RedisUtil.getCache("qywx-order-search-date")) {
feeOrderListQDTO
.setStartTime(DateUtil.beginOfDay(new Date()).offsetNew(DateField.HOUR_OF_DAY, -24).getTime());
feeOrderListQDTO.setEndTime(new Date().getTime());
.setStartTime(DateUtil.beginOfDay(new Date()).offsetNew(DateField.HOUR_OF_DAY, -24).getTime()/1000);
feeOrderListQDTO.setEndTime(new Date().getTime()/1000);
}
feeOrderListQDTO.setLimit(Manage3Constants.QW_LIMIT);
FeeOrderResponseList feeOrderResponseList = qywxUserApiService.listOrder(corpid, config.getCorpid(),
......
......@@ -66,7 +66,7 @@
select
<include refid="Base_Column_List"/>
from tab_haoban_wx_enterprise
where wxa_appid = #{appid} and wx_security_type = 5 and status_flag = 1
where wxa_appid = #{appid} and wx_security_type in ( 5 , 6) and status_flag = 1
</select>
<insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise">
......
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.service.QywxTagApiService;
import com.gic.haoban.manage.service.pojo.QywxSyncTagFormatPojo;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.*;
import java.util.stream.Collectors;
/**
* 标签同步
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class TagSyncTest {
public static void main(String[] args) {
JSONObject json = JSONObject.parseObject(getText()) ;
JSONArray list = json.getJSONObject("result").getJSONArray("tag_group") ;
System.out.println(JSONArray.toJSONString(list,true));
}
@Autowired
private QywxTagApiService qywxTagApiService ;
// com.gic.haoban.manage.service.service.out.impl.QywxTagApiServiceImpl.syncQywxTagToGicByExternalUserId
@Test
public void test1() {
String wxEnterpriseId = "b18ffdc9d0644912865a248859914d80" ;
String externalUserId = "wm59NLDQAAhf0x3cc8FLo4wxYBWZtVYw" ;
String wxUserId = "wo59NLDQAAf5VM3RJ04BBznuqq2M3K3g" ;
this.qywxTagApiService.syncQywxTagToGicByExternalUserId(wxEnterpriseId,externalUserId,wxUserId,null) ;
}
public static QywxSyncTagFormatPojo get() {
QywxSyncTagFormatPojo pojo = new QywxSyncTagFormatPojo() ;
Map<String, String> qywxToGicTagItemIdMap = new HashMap<>();
qywxToGicTagItemIdMap.put("et59NLDQAArYF4RnhIExLDXOuV7ncSCA","beb3634744fa40249980100d7bf1f6f1") ;
qywxToGicTagItemIdMap.put("et59NLDQAAOe2bxm8ylLMxG_dfXlTGCg","3f8e9920614d4008a1cb511f15ea759e") ;
qywxToGicTagItemIdMap.put("et59NLDQAAXBDE5t_33GtCHWVEre4sfQ","e48e0d8e1a7f4ca58f5bbdcd5009cc90") ;
/**
* gic标签值ID -> 企业微信标签值ID
*/
Map<String, String> gicToQywxTagItemIdMap= new HashMap<>();
gicToQywxTagItemIdMap.put("beb3634744fa40249980100d7bf1f6f1","et59NLDQAArYF4RnhIExLDXOuV7ncSCA") ;
gicToQywxTagItemIdMap.put("3f8e9920614d4008a1cb511f15ea759e","et59NLDQAAOe2bxm8ylLMxG_dfXlTGCg") ;
gicToQywxTagItemIdMap.put("e48e0d8e1a7f4ca58f5bbdcd5009cc90","et59NLDQAAXBDE5t_33GtCHWVEre4sfQ") ;
/**
* gic企业ID -> 企业微信标签值ID LIST
*/
Map<String, Set<String>> entQywxTagKeysMap = new HashMap<>();
entQywxTagKeysMap.put("ff8080815dacd3a2015dacd3ef5c0000",Arrays.asList("et59NLDQAArYF4RnhIExLDXOuV7ncSCA","et59NLDQAAOe2bxm8ylLMxG_dfXlTGCg","et59NLDQAAXBDE5t_33GtCHWVEre4sfQ").stream().collect(Collectors.toSet())) ;
/**
* gic企业ID -> gic标签值ID LIST
*/
Map<String, Set<String>> entGicTagItemIdMap = new HashMap<>();
entGicTagItemIdMap.put("ff8080815dacd3a2015dacd3ef5c0000",Arrays.asList("beb3634744fa40249980100d7bf1f6f1","3f8e9920614d4008a1cb511f15ea759e","e48e0d8e1a7f4ca58f5bbdcd5009cc90").stream().collect(Collectors.toSet())) ;
pojo.setQywxToGicTagItemIdMap(qywxToGicTagItemIdMap);
pojo.setGicToQywxTagItemIdMap(gicToQywxTagItemIdMap);
pojo.setEntGicTagItemIdMap(entGicTagItemIdMap);
pojo.setEntQywxTagKeysMap(entQywxTagKeysMap);
return pojo ;
}
// com.gic.haoban.manage.service.service.out.impl.QywxTagApiServiceImpl.syncQywxTagToGicByExternalUserId
public static String getText(){
try {
BufferedReader bw = new BufferedReader(new FileReader(new File("d:\\bq.txt"))) ;
StringBuilder sb = new StringBuilder() ;
while(true) {
String s = bw.readLine() ;
if(StringUtils.isBlank(s)) {
break ;
}else {
String ss = new String(s.getBytes(),"UTF-8") ;
sb.append(ss) ;
}
}
bw.close();
return sb.toString() ;
}catch(Exception e) {
}
return null ;
}
}
......@@ -83,7 +83,8 @@ public class WxEnterpriseController extends WebBaseController {
private SecretSettingApiService secretSettingApiService ;
@Autowired
private ClerkService clerkService;
@Autowired
private WxApplicationApiService wxApplicationApiService ;
//授权企业列表
@RequestMapping("wxa-enterprise-list")
public HaobanResponse wxEnterpriseList() {
......@@ -163,10 +164,16 @@ public class WxEnterpriseController extends WebBaseController {
return resultResponse(HaoBanErrCode.ERR_10012);
}
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseApiService.getQwInfo(wxEnterpriseId) ;
if(qwDTO.isSelf()) {
if(qwDTO.isSelf() && StringUtils.isNotBlank(qwDTO.getUrlHost())) {
return this.fail("已刷新");
}
QywxCorpInfoDTO dto = qywxTokenManageService.getCorpInfo(qwDTO.getThirdCorpid(), config.getWxSuiteid());
QywxCorpInfoDTO dto = null ;
if(qwDTO.getWxSecurityType()==6) {
WxApplicationDTO application = wxApplicationApiService.selectByWxEnterpriseIdAndApplicationType(wxEnterpriseId,3);
dto = qywxTokenManageService.getCorpInfo(qwDTO.getThirdCorpid(), application.getSiteId());
}else {
dto = qywxTokenManageService.getCorpInfo(qwDTO.getThirdCorpid(), config.getWxSuiteid());
}
if (dto == null) {
return resultResponse(HaoBanErrCode.ERR_10012);
}
......@@ -211,9 +218,12 @@ public class WxEnterpriseController extends WebBaseController {
if(wxType==5) {
desc = " ( "+wxEnterpriseDTO.getWxaAppid() +" / " + wxEnterpriseDTO.getUrlHost()+") " ;
}
if(wxType==6) {
desc = "仅代开发" ;
}
int newType = this.wxEnterpriseApiService.calcSecretType(wxEnterpriseId) ;
String diff = "";
if(null != wxType && wxType.intValue() != newType && wxType != 5) {
if(null != wxType && wxType.intValue() != newType && wxType != 5 && wxType != 6) {
diff = "*";
}
return Arrays.asList(wxEnterpriseDTO.getWxCorpid(),wxEnterpriseDTO.getOpenCorpid()).stream().filter(str -> StringUtils.isNotBlank(str)).collect(Collectors.joining(" / ")) + desc + diff;
......
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