Commit be13eabb by 徐高华

订单拉取日期bug

parent 68c6abd5
......@@ -15,21 +15,17 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.commons.util.UniqueIdUtils;
import com.gic.dubbo.entity.ProviderLocalTag;
import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.constants.Manage3Constants;
import com.gic.haoban.manage.api.dto.AlertMessageDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.dto.fee.HaobanQywxFeeAccountInterceptLogDTO;
import com.gic.haoban.manage.api.dto.fee.HaobanQywxFeeDTO;
import com.gic.haoban.manage.api.dto.fee.HaobanQywxFeeDetailDTO;
import com.gic.haoban.manage.api.dto.qdto.QywxFeeListQDTO;
import com.gic.haoban.manage.api.enums.AlertTypeEnum;
import com.gic.haoban.manage.api.service.fee.HaobanQywxFeeApiService;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
......@@ -85,7 +81,7 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
@Autowired
private HaobanQywxFeeAccountInterceptLogService haobanQywxFeeAccountInterceptLogService;
@Autowired
private WxEnterpriseActiveDataService wxEnterpriseActiveDataService ;
private WxEnterpriseActiveDataService wxEnterpriseActiveDataService;
@Override
public void run(String param) {
......@@ -104,12 +100,14 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
List<String> orderIds = new ArrayList<>();
FeeOrderListQDTO feeOrderListQDTO = new FeeOrderListQDTO();
feeOrderListQDTO.setCorpid(corpid);
if(null == RedisUtil.getCache("qywx-order-search-date")) {
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());
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());
}
feeOrderListQDTO.setLimit(Manage3Constants.QW_LIMIT);
FeeOrderResponseList feeOrderResponseList = qywxUserApiService.listOrder(corpid, config.getCorpid(), feeOrderListQDTO);
FeeOrderResponseList feeOrderResponseList = qywxUserApiService.listOrder(corpid, config.getCorpid(),
feeOrderListQDTO);
logger.error("查询激活码订单,{}", JSON.toJSONString(feeOrderResponseList));
int errcode = feeOrderResponseList.getErrcode();
if (errcode == 0) {
......@@ -117,31 +115,33 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
orderIds.add(orderListDTO.getOrderId());
}
}
return orderIds ;
return orderIds;
}
// 查询订单下的激活码code列表
private void getOrderAccount(String orderId , String corpid , String cursor , List<Map<String, String>> activeCodeList) {
logger.info("处理订单激活码,orderid={}",orderId);
private void getOrderAccount(String orderId, String corpid, String cursor,
List<Map<String, String>> activeCodeList) {
logger.info("处理订单激活码,orderid={}", orderId);
FeeOrderListQDTO feeOrderListQDTO = new FeeOrderListQDTO();
feeOrderListQDTO.setOrderId(orderId);
feeOrderListQDTO.setCursor(cursor);
feeOrderListQDTO.setLimit(Manage3Constants.QW_LIMIT);
AccountListResponseDTO accountListResponseDTO = qywxUserApiService.listOrderAccount(corpid, config.getCorpid(), feeOrderListQDTO);
AccountListResponseDTO accountListResponseDTO = qywxUserApiService.listOrderAccount(corpid, config.getCorpid(),
feeOrderListQDTO);
if (accountListResponseDTO.getErrcode() != 0) {
logger.info("订单账号列表报错:{}", accountListResponseDTO.getErrmsg());
return ;
return;
}
// 只记录互通账号
for (AccountListDTO accountListDTO : accountListResponseDTO.getAccountList()) {
if(accountListDTO.getType()==2) {
if (accountListDTO.getType() == 2) {
Map<String, String> map = new HashMap<>();
map.put("orderId", orderId);
map.put("activeCode", accountListDTO.getActiveCode());
activeCodeList.add(map);
}
}
cursor = accountListResponseDTO.getNextCursor() ;
cursor = accountListResponseDTO.getNextCursor();
Integer hasMore = accountListResponseDTO.getHasMore();
if (hasMore == 1 && StringUtils.isNotBlank(cursor)) {
this.getOrderAccount(orderId, corpid, cursor, activeCodeList);
......@@ -157,15 +157,15 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
}
String serviceCorpid = config.getCorpid();
WxEnterpriseDTO wxEnterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
if(wxEnterpriseDTO.getWxSecurityType()<=0) {
logger.info("WxSecurityType=0,wxEnterpriseId={}",wxEnterpriseId);
return ;
if (wxEnterpriseDTO.getWxSecurityType() <= 0) {
logger.info("WxSecurityType=0,wxEnterpriseId={}", wxEnterpriseId);
return;
}
String corpid = wxEnterpriseDTO.getOpenCorpid() ;
String corpid = wxEnterpriseDTO.getOpenCorpid();
String corpName = wxEnterpriseDTO.getCorpName();
String autoActiveStatus = qywxUserApiService.getAutoActiveStatus(corpid, serviceCorpid);
if (!"1".equals(autoActiveStatus)) {
logger.info("未开启自动激活:{},wxeid={}", corpid,wxEnterpriseId);
logger.info("未开启自动激活:{},wxeid={}", corpid, wxEnterpriseId);
this.wxEnterpriseService.updateAutoActiveFlagById(0, wxEnterpriseId);
return;
}
......@@ -173,14 +173,14 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
if (autoActiveFlag != null && autoActiveFlag != 1) {
this.wxEnterpriseService.updateAutoActiveFlagById(1, wxEnterpriseId);
}
List<String> orderIdList = this.listOrderId(corpid) ;
List<String> orderIdList = this.listOrderId(corpid);
for (String orderId : orderIdList) {
FeeOrderDeatilResponseDTO order = qywxUserApiService.getOrder(corpid, serviceCorpid, orderId);
if (order.getErrcode() != 0) {
logger.error("请求企微失败:{}", orderId);
continue;
}
//插入订单
// 插入订单
FeeOrderDeatilResponseDTO.OrderDTO orderDTO = order.getOrder();
Integer orderStatus = orderDTO.getOrderStatus();
if (orderStatus != 1) {
......@@ -205,13 +205,13 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
}
// 更新订单的激活码状态
List<TabHaobanQywxFeeOrder> orderList = this.haobanQywxFeeOrderService.listOrder(wxEnterpriseId) ;
if(CollectionUtils.isEmpty(orderList)) {
List<TabHaobanQywxFeeOrder> orderList = this.haobanQywxFeeOrderService.listOrder(wxEnterpriseId);
if (CollectionUtils.isEmpty(orderList)) {
logger.error("无企微订单:{}", wxEnterpriseId);
return ;
return;
}
// 查询订单下的激活码code列表,记录到activeCodeList
for(TabHaobanQywxFeeOrder order : orderList) {
for (TabHaobanQywxFeeOrder order : orderList) {
List<Map<String, String>> activeCodeList = new ArrayList<>();
// 查询订单下的激活码code列表
this.getOrderAccount(order.getOrderId(), corpid, null, activeCodeList);
......@@ -223,15 +223,15 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
this.staffService.activedAccountTimer(wxEnterpriseId);
// 更新企业的激活数量统计
this.wxEnterpriseActiveDataService.saveOrUpdate(wxEnterpriseId) ;
this.wxEnterpriseActiveDataService.saveOrUpdate(wxEnterpriseId);
//统计 haobanQywxFeeDetailDTO 30天内最新过期的时间和人数
// 统计 haobanQywxFeeDetailDTO 30天内最新过期的时间和人数
HaobanQywxFeeDetailDTO haobanQywxFeeDetailDTO = haobanQywxFeeAccountStaffService.feeIntercept(wxEnterpriseId);
// 未激活数(状态1)
int permissionUserNum = haobanQywxFeeOrderAccountService.countOrderAccountStatus(1, wxEnterpriseId);
// 待转移数(状态4)
int transferUserNum = haobanQywxFeeOrderAccountService.countOrderAccountStatus(4, wxEnterpriseId);
int totalCount = this.haobanQywxFeeOrderService.countExternalContactCount(wxEnterpriseId) ;
int totalCount = this.haobanQywxFeeOrderService.countExternalContactCount(wxEnterpriseId);
if (haobanQywxFeeDetailDTO != null && permissionUserNum > 0) {
TabHaobanQywxFee tabHaobanQywxFee = new TabHaobanQywxFee();
tabHaobanQywxFee.setQwFeeId(UniqueIdUtils.uniqueLong());
......@@ -245,17 +245,22 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
tabHaobanQywxFee.setBuyPermissionUserNum(totalCount);
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);
// int monthWillInterceptNum =
// haobanQywxFeeAccountStaffService.monthWillInterceptNum(wxEnterpriseId);
// String content = "30天将有" + monthWillInterceptNum +
// "个接口许可证即将过期,您总共还剩余" + permissionUserNum +
// "个可用的接口许可证,请保证数量充足,如需增加请及时联系相关人员续费,避免影响使用";
// 告警
// messageAlert(wxEnterpriseId, corpName, corpid,
// AlertTypeEnum.FEE_ALARM.getName(), content);
}
}
// 更加企微通知记录已拦截数
List<TabHaobanQywxFeeAccountInterceptLog> interceptLogs = haobanQywxFeeAccountInterceptLogService.queryByWxEnterpriseId(wxEnterpriseId);
List<TabHaobanQywxFeeAccountInterceptLog> interceptLogs = haobanQywxFeeAccountInterceptLogService
.queryByWxEnterpriseId(wxEnterpriseId);
if (CollectionUtils.isNotEmpty(interceptLogs)) {
TabHaobanQywxFee tabHaobanQywxFee = new TabHaobanQywxFee();
tabHaobanQywxFee.setQwFeeId(UniqueIdUtils.uniqueLong());
......@@ -273,34 +278,36 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
}
// 保存订单下的激活码信息-tab_haoban_qywx_fee_order_account
private void addOrderAccount(String wxEnterpriseId, String serviceCorpid, String corpid, List<Map<String, String>> activeCodeList) {
private void addOrderAccount(String wxEnterpriseId, String serviceCorpid, String corpid,
List<Map<String, String>> activeCodeList) {
if (CollectionUtils.isEmpty(activeCodeList)) {
logger.error("订单账号无激活码");
return;
}
List<String> codeList = new ArrayList<>();
Map<String,String> keyMap = new HashMap<>();
Map<String, String> keyMap = new HashMap<>();
for (Map<String, String> activeCodeMap : activeCodeList) {
String activeCode = activeCodeMap.get("activeCode");
String orderId = activeCodeMap.get("orderId");
codeList.add(activeCode) ;
keyMap.put(activeCode,orderId) ;
codeList.add(activeCode);
keyMap.put(activeCode, orderId);
}
TabHaobanQywxFeeOrderAccount activeAccount = new TabHaobanQywxFeeOrderAccount();
// 查询激活码的详情
List<ActiveInfoCodeResponseDTO> respList = qywxUserApiService.getActiveInfoByCodeList(corpid, serviceCorpid, codeList);
if(CollectionUtils.isNotEmpty(respList)) {
List<List<ActiveInfoCodeResponseDTO>> list = Lists.partition(respList, 800) ;
for(int i=0;i<list.size();i++) {
List<ActiveInfoCodeResponseDTO> respList = qywxUserApiService.getActiveInfoByCodeList(corpid, serviceCorpid,
codeList);
if (CollectionUtils.isNotEmpty(respList)) {
List<List<ActiveInfoCodeResponseDTO>> list = Lists.partition(respList, 800);
for (int i = 0; i < list.size(); i++) {
List<ActiveInfoCodeResponseDTO> subList = list.get(i);
for(ActiveInfoCodeResponseDTO activeDetail : subList) {
for (ActiveInfoCodeResponseDTO activeDetail : subList) {
String userid = activeDetail.getUserid();
String activeCode = activeDetail.getActiveCode() ;
String activeCode = activeDetail.getActiveCode();
activeAccount.setWxUserId(userid);
activeAccount.setStatus(activeDetail.getStatus());
if(null != activeDetail.getExpireTime()) {
if (null != activeDetail.getExpireTime()) {
activeAccount.setExpireTime(DateUtil.date(activeDetail.getExpireTime() * 1000));
activeAccount.setActiveTime(DateUtil.date(activeDetail.getActiveTime() * 1000));
}
......@@ -328,24 +335,28 @@ public class HaobanQywxFeeApiServiceImpl implements HaobanQywxFeeApiService {
@Override
public void addInterceptLog(String param) {
HaobanQywxFeeAccountInterceptLogDTO logDTO = JSON.toJavaObject(JSON.parseObject(param), HaobanQywxFeeAccountInterceptLogDTO.class);
HaobanQywxFeeAccountInterceptLogDTO logDTO = JSON.toJavaObject(JSON.parseObject(param),
HaobanQywxFeeAccountInterceptLogDTO.class);
logDTO.setFeeAccountInterceptId(UniqueIdUtils.uniqueLong());
TabHaobanWxEnterprise haobanWxEnterprise = wxEnterpriseService.getEnterpriseBycorpId(logDTO.getCorpId());
if(null == haobanWxEnterprise) {
return ;
if (null == haobanWxEnterprise) {
return;
}
String wxEnterpriseId = haobanWxEnterprise.getWxEnterpriseId();
logDTO.setWxEnterpriseId(wxEnterpriseId);
TabHaobanStaff tabHaobanStaff = staffService.selectByUserIdAndEnterpriseId(logDTO.getWxUserId(), wxEnterpriseId);
if(null == tabHaobanStaff) {
return ;
TabHaobanStaff tabHaobanStaff = staffService.selectByUserIdAndEnterpriseId(logDTO.getWxUserId(),
wxEnterpriseId);
if (null == tabHaobanStaff) {
return;
}
logDTO.setStaffId(tabHaobanStaff.getStaffId());
haobanQywxFeeAccountInterceptLogService.insert(EntityUtil.changeEntityNew(TabHaobanQywxFeeAccountInterceptLog.class, logDTO));
haobanQywxFeeAccountInterceptLogService
.insert(EntityUtil.changeEntityNew(TabHaobanQywxFeeAccountInterceptLog.class, logDTO));
}
@Override
public HaobanQywxFeeDTO queryByWxEnterpriseId(String wxEnterpriseId) {
return EntityUtil.changeEntityNew(HaobanQywxFeeDTO.class, haobanQywxFeeService.queryByWxEnterpriseId(wxEnterpriseId));
return EntityUtil.changeEntityNew(HaobanQywxFeeDTO.class,
haobanQywxFeeService.queryByWxEnterpriseId(wxEnterpriseId));
}
}
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