Commit 52cf7d35 by 墨竹

fix:收费、删除无效代码

parent 287a9110
......@@ -68,19 +68,6 @@ public interface MemberUnionidRelatedApiService {
*/
List<MemberStoreDTO> listByExTernalUseridAndWxUserId(String externalUserid, String wxUserId, String storeId);
@Deprecated
String add(String wxEnterpriseId, String selfExternalUserId, String userId1, String storeId);
/**
* 刷新企微好友
*
* @param wxEnterpriseId
* @param wxUserId
* @param storeId
*/
void freshWxFrend(String wxEnterpriseId, String wxUserId, String storeId);
void cleanByCid(String cid);
Page<MemberUnionidRelatedDTO> pageMemberUnionByParams(List<String> userIdList, List<String> sendMemberIds,
......@@ -146,14 +133,6 @@ public interface MemberUnionidRelatedApiService {
String addMemberUnionidRelatedNew(MemberUnionidRelatedDTO dto);
/**
* 刷新企微好友
*
* @param res
*/
@Deprecated
void mqFreshWxFrend(String res);
/**
* 清楚不存在的好友关系
*
* @param wxEnterpriseId
......
......@@ -74,7 +74,7 @@ public interface TabHaobanQywxFeeAccountStaffMapper {
Date lastFeeInterceptTime(@Param("wxEnterpriseId") String wxEnterpriseId);
/**
* 最后费用过期拦截数
* 未来30天过期拦截数
*
* @param wxEnterpriseId wx企业标识
* @return int
......
......@@ -67,4 +67,15 @@ public interface HaobanQywxFeeAccountStaffService {
*/
HaobanQywxFeeDetailDTO feeIntercept(String wxEnterpriseId);
/**
* 未来30天将拦截数量
*
* @param wxEnterpriseId wx企业标识
* @return int
* @author mozhu
* @date 2022-08-12 13:57:00
*/
int monthWillInterceptNum(String wxEnterpriseId);
}
......@@ -81,4 +81,9 @@ public class HaobanQywxFeeAccountStaffServiceImpl implements HaobanQywxFeeAccoun
haobanQywxFeeDetailDTO.setInterceptUserNum(count);
return haobanQywxFeeDetailDTO;
}
@Override
public int monthWillInterceptNum(String wxEnterpriseId) {
return tabHaobanQywxFeeAccountStaffMapper.lastFeeInterceptCount(wxEnterpriseId);
}
}
......@@ -1032,67 +1032,6 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
return pojo;
}
@Override
public String add(String wxEnterpriseId, String selfExternalUserId, String userId, String storeId) {
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if (qwDTO == null) {
return "";
}
TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(userId, wxEnterpriseId);
if (staff == null) {
return "";
}
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.CONTACT_CUSTOMER.getVal());
if (null == secretSetting) {
log.info("没有配置secret");
return "";
}
String unionIdJson = qywxUserApiService.getCorpSelfExternalUseridInfo(qwDTO.getDkCorpid(), secretSetting.getSecretVal(), selfExternalUserId);
ExternalUserPojo pojo = getExternalUserPojo(unionIdJson, userId, wxEnterpriseId);
String unionId = pojo.getUnionId();
String name = pojo.getName();
String createTime = pojo.getAddCreateTime();
MemberUnionidRelatedDTO dto = new MemberUnionidRelatedDTO();
String externalUserId = getExternalUserId(qwDTO.getThirdCorpid(), userId, createTime, name);
if (StringUtils.isBlank(externalUserId)) {
log.error("请求外部联系人id失败,userId:{}", userId);
return "";
}
dto.setExternalUserid(externalUserId);
dto.setWxEnterpriseId(wxEnterpriseId);
dto.setUnionid(unionId);
dto.setExternalName(name);
dto.setAddCreateTime(createTime);
dto.setWxUserId(userId);
dto.setAvatar(pojo.getAvatar());
if (StringUtils.isBlank(unionId)) {
return "";
}
dto.setSuiteid(secretSetting.getSecretVal());
MemberUnionidRelatedDTO exsitDTO = memberUnionRelatedService.getByParams(userId, wxEnterpriseId, name, createTime);
String uuid = "";
if (exsitDTO == null) {
dto.setUnionid(unionId);
//更新对外联系人id
dto.setSelfExternalUserid(selfExternalUserId);
uuid = memberUnionRelatedService.addMemberUnionidRelated(dto);
} else {
exsitDTO.setExternalUserid(externalUserId);
exsitDTO.setUnionid(unionId);
//更新对外联系人id
exsitDTO.setSelfExternalUserid(selfExternalUserId);
memberUnionRelatedService.update(exsitDTO);
uuid = exsitDTO.getMemberUnionidRelatedId();
}
//新增门店和导购的关联关系
insertExternalClerkRelated(dto);
return uuid;
}
@Deprecated
private void insertExternalClerkRelated(MemberUnionidRelatedDTO dto) {
log.info("新增外部联系人开始:{}", JSONObject.toJSONString(dto));
......@@ -1316,59 +1255,6 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
return EntityUtil.changeEntityListByJSON(MemberUnionidRelatedDTO.class, list);
}
@Override
public void freshWxFrend(String wxEnterpriseId, String wxUserId, String storeId) {
log.info("【刷下好友】wxUserId={}", wxUserId);
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
String wxRes = qywxUserApiService.listExternalUserid(qwDTO.getThirdCorpid(), config.getWxSuiteid(), wxUserId);
List<MemberUnionidRelatedDTO> list = this.getByWxUserIdAndWxEnterpriseId(wxUserId, wxEnterpriseId);
List<String> externalUserIdList = list.stream().map(external -> external.getExternalUserid())
.collect(Collectors.toList());
JSONArray externalArr = JSON.parseArray(wxRes);
for (String externalUserId : externalUserIdList) {
if (!externalArr.contains(externalUserId)) {
//删除成员和外部联系人关系
MemberUnionidRelatedDTO dto = new MemberUnionidRelatedDTO();
dto.setExternalUserid(externalUserId);
dto.setWxUserId(wxUserId);
memberUnionRelatedService.delMemberUnionidRelated(dto);
//删除导购和外部联系人关系
externalClerkRelatedService.delByUserIdAndExternalUserId(dto);
}
}
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.CONTACT_CUSTOMER.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
log.info("没有配置客户联系secret:{}", wxEnterpriseId);
return;
}
String res = qywxUserApiService.listSelfExternalUserid(qwDTO.getDkCorpid(), secretSetting.getSecretVal(), wxUserId);
log.info("【刷下好友】res={}", res);
if (StringUtils.isBlank(res)) {
return;
}
JSONArray jsonArr = JSON.parseArray(res);
if (jsonArr.size() == 0) {
return;
}
for (Object object : jsonArr) {
this.add(wxEnterpriseId, object.toString(), wxUserId, storeId);
}
}
@Override
public void mqFreshWxFrend(String res) {
JSONObject json = JSON.parseObject(res);
String wxEnterpriseId = json.getString("wxEnterpriseId");
String wxUserId = json.getString("wxUserId");
String storeId = json.getString("storeId");
log.info("【刷下微信好友】wxEnterpriseId={}.wxUserId={},storeId={}", wxEnterpriseId, wxUserId, storeId);
if (StringUtils.isAnyBlank(wxEnterpriseId, wxUserId, storeId)) {
return;
}
freshWxFrend(wxEnterpriseId, wxUserId, storeId);
}
@Override
public void cleanByCid(String cid) {
......
......@@ -104,8 +104,8 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
FeeOrderListQDTO feeOrderListQDTO = new FeeOrderListQDTO();
feeOrderListQDTO.setCorpid(corpid);
if (hasOrder) {
feeOrderListQDTO.setStart_time(DateUtil.beginOfDay(new Date()).offsetNew(DateField.HOUR_OF_DAY, -1).getTime());
feeOrderListQDTO.setEnd_time(DateUtil.endOfDay(new Date()).offsetNew(DateField.HOUR_OF_DAY, -1).getTime());
feeOrderListQDTO.setStartTime(DateUtil.beginOfDay(new Date()).offsetNew(DateField.HOUR_OF_DAY, -1).getTime());
feeOrderListQDTO.setEndTime(DateUtil.endOfDay(new Date()).offsetNew(DateField.HOUR_OF_DAY, -1).getTime());
}
feeOrderListQDTO.setLimit(Manage3Constants.QW_LIMIT);
FeeOrderResponseList feeOrderResponseList = qywxUserApiService.listOrder(corpid, serviceCorpid, feeOrderListQDTO);
......@@ -129,7 +129,11 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
}
}
List<String> activeCodes = new ArrayList<>();
if (CollectionUtils.isEmpty(orderIds)) {
logger.error("订单为空");
return;
}
for (String orderId : orderIds) {
FeeOrderDeatilResponseDTO order = qywxUserApiService.getOrder(corpid, serviceCorpid, orderId);
if (order.getErrcode() != 0) {
......@@ -156,42 +160,87 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
tabHaobanQywxFeeOrder.setBaseCount(orderDTO.getAccountCount().getBaseCount());
tabHaobanQywxFeeOrder.setExternalContactCount(orderDTO.getAccountCount().getExternalContactCount());
tabHaobanQywxFeeOrder.setMonths(orderDTO.getAccountDuration().getMonths());
tabHaobanQywxFeeOrder.setCreateTime(DateUtil.date(orderDTO.getCreateTime()));
tabHaobanQywxFeeOrder.setPayTime(DateUtil.date(orderDTO.getPayTime()));
tabHaobanQywxFeeOrder.setCreateTime(DateUtil.date(orderDTO.getCreateTime() * 1000));
tabHaobanQywxFeeOrder.setPayTime(DateUtil.date(orderDTO.getPayTime() * 1000));
haobanQywxFeeOrderService.insert(tabHaobanQywxFeeOrder);
}
//更新账号
while (true) {
FeeOrderListQDTO feeOrderListQDTO = new FeeOrderListQDTO();
feeOrderListQDTO.setCorpid(corpid);
feeOrderListQDTO.setOrderId(orderId);
feeOrderListQDTO.setLimit(Manage3Constants.QW_LIMIT);
AccountListResponseDTO accountListResponseDTO = qywxUserApiService.listActivedAccount(corpid, serviceCorpid, feeOrderListQDTO);
AccountListResponseDTO accountListResponseDTO = qywxUserApiService.listOrderAccount(corpid, serviceCorpid, feeOrderListQDTO);
if (accountListResponseDTO.getErrcode() != 0) {
logger.info("订单账号列表报错:{}", accountListResponseDTO.getErrmsg());
break;
}
List<AccountListDTO> accountList = accountListResponseDTO.getAccountList();
for (AccountListDTO accountListDTO : accountList) {
activeCodes.add(accountListDTO.getActiveCode());
}
addOrderAccount(wxEnterpriseId,serviceCorpid,corpid,orderId,accountListResponseDTO.getAccountList());
Integer hasMore = accountListResponseDTO.getHasMore();
if (hasMore == 0) {
logger.error("无更多账号");
logger.error("订单无更多账号");
break;
}
feeOrderListQDTO.setCursor(feeOrderListQDTO.getCursor());
accountListResponseDTO = qywxUserApiService.listActivedAccount(corpid, serviceCorpid, feeOrderListQDTO);
for (AccountListDTO accountListDTO : accountListResponseDTO.getAccountList()) {
activeCodes.add(accountListDTO.getActiveCode());
accountListResponseDTO = qywxUserApiService.listOrderAccount(corpid, serviceCorpid, feeOrderListQDTO);
addOrderAccount(wxEnterpriseId,serviceCorpid,corpid,orderId,accountListResponseDTO.getAccountList());
}
//更新企微状态
wxEnterpriseService.updateAutoActiveFlagById(1, wxEnterpriseId);
//更新收费
HaobanQywxFeeDetailDTO haobanQywxFeeDetailDTO = haobanQywxFeeAccountStaffService.feeIntercept(wxEnterpriseId);
int permissionUserNum = haobanQywxFeeOrderAccountService.countOrderAccountStatus(1, wxEnterpriseId);
if (haobanQywxFeeDetailDTO != null) {
TabHaobanQywxFee tabHaobanQywxFee = new TabHaobanQywxFee();
tabHaobanQywxFee.setQwFeeId(UniqueIdUtils.uniqueLong());
tabHaobanQywxFee.setCorpName(corpName);
tabHaobanQywxFee.setCorpId(corpid);
tabHaobanQywxFee.setWxEnterpriseId(wxEnterpriseId);
tabHaobanQywxFee.setInterceptTime(haobanQywxFeeDetailDTO.getInterceptTime());
tabHaobanQywxFee.setInterceptUserNum(haobanQywxFeeDetailDTO.getInterceptUserNum());
tabHaobanQywxFee.setPermissionUserNum(permissionUserNum);
tabHaobanQywxFee.setBuyPermissionUserNum(haobanQywxFeeOrderService.countExternalContactCount(wxEnterpriseId));
tabHaobanQywxFee.setInterceptFlag(0);
haobanQywxFeeService.insert(tabHaobanQywxFee);
//判断今天是否是本月最后一天
if (DateUtil.isSameDay(DateUtil.endOfMonth(new Date()), new Date())) {
int monthWillInterceptNum = haobanQywxFeeAccountStaffService.monthWillInterceptNum(wxEnterpriseId);
String content = "30天将有" + monthWillInterceptNum + "个接口许可证即将过期,您总共还剩余" + permissionUserNum + "个可用的接口许可证,请保证数量充足,如需增加请及时联系相关人员续费,避免影响使用";
//告警
messageAlert(wxEnterpriseId, corpName, corpid, AlertTypeEnum.FEE_ALARM.getName(), content);
}
}
for (String activeCode : activeCodes) {
List<TabHaobanQywxFeeAccountInterceptLog> tabHaobanQywxFeeAccountInterceptLogs = haobanQywxFeeAccountInterceptLogService.queryByWxEnterpriseId(wxEnterpriseId);
if (CollectionUtils.isNotEmpty(tabHaobanQywxFeeAccountInterceptLogs)) {
TabHaobanQywxFee tabHaobanQywxFee = new TabHaobanQywxFee();
tabHaobanQywxFee.setQwFeeId(UniqueIdUtils.uniqueLong());
tabHaobanQywxFee.setCorpName(corpName);
tabHaobanQywxFee.setCorpId(corpid);
tabHaobanQywxFee.setWxEnterpriseId(wxEnterpriseId);
tabHaobanQywxFee.setInterceptTime(DateUtil.offsetDay(new Date(), -1));
tabHaobanQywxFee.setInterceptUserNum(tabHaobanQywxFeeAccountInterceptLogs.size());
tabHaobanQywxFee.setPermissionUserNum(permissionUserNum);
tabHaobanQywxFee.setBuyPermissionUserNum(haobanQywxFeeOrderService.countExternalContactCount(wxEnterpriseId));
tabHaobanQywxFee.setInterceptFlag(1);
haobanQywxFeeService.insert(tabHaobanQywxFee);
}
}
private void addOrderAccount(String wxEnterpriseId, String serviceCorpid, String corpid, String orderId, List<AccountListDTO> accountList) {
if (CollectionUtils.isEmpty(accountList)) {
logger.error("订单账号无激活码");
return;
}
for (AccountListDTO orderListAccount : accountList) {
String activeCode = orderListAccount.getActiveCode();
if (StringUtils.isBlank(activeCode)) {
logger.error("订单无激活码");
continue;
}
ActiveInfoCodeResponseDTO activeInfoCodeResponseDTO = qywxUserApiService.getActiveInfoByCode(corpid, serviceCorpid, activeCode);
if (activeInfoCodeResponseDTO.getErrcode() != 0) {
logger.error("激活码详情报错:{}", activeInfoCodeResponseDTO.getErrmsg());
......@@ -200,15 +249,15 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
String userid = activeInfoCodeResponseDTO.getUserid();
TabHaobanQywxFeeOrderAccount tabHaobanQywxFeeOrderAccount = new TabHaobanQywxFeeOrderAccount();
tabHaobanQywxFeeOrderAccount.setFeeAccountId(UniqueIdUtils.uniqueLong());
//tabHaobanQywxFeeOrderAccount.setOrderId();
tabHaobanQywxFeeOrderAccount.setOrderId(orderId);
tabHaobanQywxFeeOrderAccount.setCorpId(corpid);
tabHaobanQywxFeeOrderAccount.setWxEnterpriseId(wxEnterpriseId);
tabHaobanQywxFeeOrderAccount.setWxUserId(userid);
tabHaobanQywxFeeOrderAccount.setActiveCode(activeInfoCodeResponseDTO.getActiveCode());
tabHaobanQywxFeeOrderAccount.setAccountType(activeInfoCodeResponseDTO.getType());
tabHaobanQywxFeeOrderAccount.setStatus(activeInfoCodeResponseDTO.getStatus());
tabHaobanQywxFeeOrderAccount.setExpireTime(DateUtil.date(activeInfoCodeResponseDTO.getExpireTime()));
tabHaobanQywxFeeOrderAccount.setActiveTime(DateUtil.date(activeInfoCodeResponseDTO.getActiveTime()));
tabHaobanQywxFeeOrderAccount.setExpireTime(DateUtil.date(activeInfoCodeResponseDTO.getExpireTime() * 1000));
tabHaobanQywxFeeOrderAccount.setActiveTime(DateUtil.date(activeInfoCodeResponseDTO.getActiveTime() * 1000));
haobanQywxFeeOrderAccountService.insert(tabHaobanQywxFeeOrderAccount);
//更新成员
......@@ -232,8 +281,8 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
}
tabHaobanQywxFeeAccountStaff.setActiveCode(accountListDTO.getActiveCode());
tabHaobanQywxFeeAccountStaff.setAccountType(accountListDTO.getType());
tabHaobanQywxFeeAccountStaff.setExpireTime(DateUtil.date(accountListDTO.getExpireTime()));
tabHaobanQywxFeeAccountStaff.setActiveTime(DateUtil.date(accountListDTO.getActiveTime()));
tabHaobanQywxFeeAccountStaff.setExpireTime(DateUtil.date(accountListDTO.getExpireTime() * 1000));
tabHaobanQywxFeeAccountStaff.setActiveTime(DateUtil.date(accountListDTO.getActiveTime()* 1000));
haobanQywxFeeAccountStaffService.insert(tabHaobanQywxFeeAccountStaff);
}
if (tabHaobanStaff != null) {
......@@ -241,48 +290,6 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
staffService.updateActiveStatusById(activeStatus, staffId);
}
}
//更新企微状态
wxEnterpriseService.updateAutoActiveFlagById(1, wxEnterpriseId);
//更新收费
HaobanQywxFeeDetailDTO haobanQywxFeeDetailDTO = haobanQywxFeeAccountStaffService.feeIntercept(wxEnterpriseId);
int permissionUserNum = haobanQywxFeeOrderAccountService.countOrderAccountStatus(1, wxEnterpriseId);
if (haobanQywxFeeDetailDTO != null) {
TabHaobanQywxFee tabHaobanQywxFee = new TabHaobanQywxFee();
tabHaobanQywxFee.setQwFeeId(UniqueIdUtils.uniqueLong());
tabHaobanQywxFee.setCorpName(corpName);
tabHaobanQywxFee.setCorpId(corpid);
tabHaobanQywxFee.setWxEnterpriseId(wxEnterpriseId);
tabHaobanQywxFee.setInterceptTime(haobanQywxFeeDetailDTO.getInterceptTime());
tabHaobanQywxFee.setInterceptUserNum(haobanQywxFeeDetailDTO.getInterceptUserNum());
tabHaobanQywxFee.setPermissionUserNum(permissionUserNum);
tabHaobanQywxFee.setBuyPermissionUserNum(haobanQywxFeeOrderService.countExternalContactCount(wxEnterpriseId));
tabHaobanQywxFee.setInterceptFlag(0);
haobanQywxFeeService.insert(tabHaobanQywxFee);
//判断今天是否是本月最后一天
if (DateUtil.isSameDay(DateUtil.endOfMonth(new Date()), new Date())) {
int day1 = 0;
String content = "30天将有" + day1 + "个接口许可证即将过期,您总共还剩余" + permissionUserNum + "个可用的接口许可证,请保证数量充足,如需增加请及时联系相关人员续费,避免影响使用";
//告警
messageAlert(wxEnterpriseId, corpName, corpid, AlertTypeEnum.FEE_ALARM.getName(), content);
}
}
List<TabHaobanQywxFeeAccountInterceptLog> tabHaobanQywxFeeAccountInterceptLogs = haobanQywxFeeAccountInterceptLogService.queryByWxEnterpriseId(wxEnterpriseId);
if (CollectionUtils.isNotEmpty(tabHaobanQywxFeeAccountInterceptLogs)) {
TabHaobanQywxFee tabHaobanQywxFee = new TabHaobanQywxFee();
tabHaobanQywxFee.setQwFeeId(UniqueIdUtils.uniqueLong());
tabHaobanQywxFee.setCorpName(corpName);
tabHaobanQywxFee.setCorpId(corpid);
tabHaobanQywxFee.setWxEnterpriseId(wxEnterpriseId);
tabHaobanQywxFee.setInterceptTime(DateUtil.offsetDay(new Date(), -1));
tabHaobanQywxFee.setInterceptUserNum(tabHaobanQywxFeeAccountInterceptLogs.size());
tabHaobanQywxFee.setPermissionUserNum(permissionUserNum);
tabHaobanQywxFee.setBuyPermissionUserNum(haobanQywxFeeOrderService.countExternalContactCount(wxEnterpriseId));
tabHaobanQywxFee.setInterceptFlag(1);
haobanQywxFeeService.insert(tabHaobanQywxFee);
}
}
@Override
......
......@@ -49,6 +49,7 @@
and intercept_time <![CDATA[ >= ]]> #{endDate}
</if>
</where>
order by intercept_time desc
</select>
......
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