|
|
@@ -1,8 +1,12 @@
|
|
|
package com.fs.his.task;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baidu.dev2.api.sdk.payment.api.PaymentService;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.service.impl.SmsServiceImpl;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
@@ -20,13 +24,9 @@ import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
|
import com.fs.course.service.ITencentCloudCosService;
|
|
|
import com.fs.erp.domain.ErpDeliverys;
|
|
|
-import com.fs.erp.domain.ErpOrder;
|
|
|
import com.fs.erp.domain.ErpOrderQuery;
|
|
|
-import com.fs.erp.domain.FsErpFinishPush;
|
|
|
import com.fs.erp.dto.ErpOrderQueryRequert;
|
|
|
import com.fs.erp.dto.ErpOrderQueryResponse;
|
|
|
-import com.fs.erp.dto.ErpOrderResponse;
|
|
|
-import com.fs.erp.mapper.FsErpFinishPushMapper;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
import com.fs.fastGpt.domain.FastGptEventTokenLog;
|
|
|
import com.fs.fastGpt.domain.FastgptEventLogTotal;
|
|
|
@@ -34,10 +34,7 @@ import com.fs.fastGpt.mapper.FastGptChatSessionMapper;
|
|
|
import com.fs.fastGpt.service.IFastgptEventLogTotalService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.config.StoreConfig;
|
|
|
-import com.fs.his.domain.FsInquiryOrder;
|
|
|
-import com.fs.his.domain.FsStoreAfterSales;
|
|
|
-import com.fs.his.domain.FsStoreOrder;
|
|
|
-import com.fs.his.domain.FsUser;
|
|
|
+import com.fs.his.domain.*;
|
|
|
import com.fs.his.dto.FsInquiryOrderPatientDTO;
|
|
|
import com.fs.his.enums.FsStoreOrderLogEnum;
|
|
|
import com.fs.his.enums.FsStoreOrderStatusEnum;
|
|
|
@@ -48,6 +45,8 @@ import com.fs.his.service.impl.FsPackageOrderServiceImpl;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.vo.FsSubOrderResultVO;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
+import com.fs.hisStore.domain.FsStorePaymentScrm;
|
|
|
+import com.fs.hisStore.service.IFsStorePaymentScrmService;
|
|
|
import com.fs.im.dto.*;
|
|
|
import com.fs.im.service.IImService;
|
|
|
import com.fs.im.service.OpenIMService;
|
|
|
@@ -56,6 +55,10 @@ import com.fs.qw.service.*;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
+import com.fs.wx.domain.FsWxExpressTask;
|
|
|
+import com.fs.wx.dto.*;
|
|
|
+import com.fs.wx.mapper.FsWxExpressTaskMapper;
|
|
|
+import com.fs.wx.service.ShippingService;
|
|
|
import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -65,6 +68,9 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.OffsetDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -173,6 +179,122 @@ public class Task {
|
|
|
@Autowired
|
|
|
private IFastgptEventLogTotalService fastgptEventLogTotalService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsWxExpressTaskMapper fsWxExpressTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStorePaymentService paymentScrmService;
|
|
|
+ @Autowired
|
|
|
+ ShippingService shippingService;
|
|
|
+ public void syncExpressToWx() {
|
|
|
+ List<FsWxExpressTask> fsWxExpressTasks = fsWxExpressTaskMapper.selectPendingData();
|
|
|
+ if (CollectionUtils.isEmpty(fsWxExpressTasks)) {
|
|
|
+ logger.info("当前没有待同步的数据!已取消");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (FsWxExpressTask fsWxExpressTask : fsWxExpressTasks) {
|
|
|
+
|
|
|
+ try{
|
|
|
+ UploadShippingInfoRequest request = new UploadShippingInfoRequest();
|
|
|
+
|
|
|
+ OrderKey orderKey = new OrderKey();
|
|
|
+ orderKey.setOrderNumberType(2);
|
|
|
+
|
|
|
+
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserById(fsWxExpressTask.getUserId());
|
|
|
+ FsStoreOrderScrm fsStoreOrder = fsStoreOrderMapper.selectFsStoreOrderByOrderCodeScrm(fsWxExpressTask.getOrderCode());
|
|
|
+
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotNull(fsStoreOrder)){
|
|
|
+ List<FsStorePaymentScrm> fsStorePayments = paymentScrmService.selectFsStorePaymentByOrderScrm(fsStoreOrder.getId());
|
|
|
+
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(fsStorePayments)){
|
|
|
+ FsStorePaymentScrm fsStorePayment = fsStorePayments.get(0);
|
|
|
+ orderKey.setTransactionId(fsStorePayment.getBankTransactionId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String userPhone = "";
|
|
|
+ String orderGoodsInfo = "商品";
|
|
|
+ if(fsStoreOrder != null){
|
|
|
+ userPhone = fsStoreOrder.getUserPhone();
|
|
|
+ orderGoodsInfo = getOrderGoodsInfo(fsStoreOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ Payer payer = new Payer();
|
|
|
+ if(StringUtils.isNotBlank(fsUser.getMaOpenId())){
|
|
|
+ payer.setOpenid(fsUser.getMaOpenId());
|
|
|
+ }
|
|
|
+ request.setPayer(payer);
|
|
|
+ request.setOrderKey(orderKey);
|
|
|
+
|
|
|
+ request.setLogisticsType(1);
|
|
|
+ request.setDeliveryMode(1);
|
|
|
+
|
|
|
+ request.setShippingList(Collections.singletonList(ShippingItem.builder()
|
|
|
+ .itemDesc(orderGoodsInfo)
|
|
|
+ .expressCompany(fsWxExpressTask.getExpressCompany())
|
|
|
+ .trackingNo(fsWxExpressTask.getExpressNo())
|
|
|
+ .contact(Contact.builder().consignorContact(userPhone).build())
|
|
|
+ .build()));
|
|
|
+
|
|
|
+ OffsetDateTime now = OffsetDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
+ String formattedTimestamp = now.format(formatter);
|
|
|
+ request.setUploadTime(formattedTimestamp);
|
|
|
+
|
|
|
+
|
|
|
+ WeChatApiResponse response = shippingService.uploadShippingInfo(request);
|
|
|
+ if(ObjectUtil.equal(response.getErrcode(),0)){
|
|
|
+ fsWxExpressTask.setStatus(2);
|
|
|
+ } else {
|
|
|
+ fsWxExpressTask.setRetryCount(fsWxExpressTask.getRetryCount() +1);
|
|
|
+ fsWxExpressTask.setStatus(3);
|
|
|
+ fsWxExpressTask.setData(JSON.toJSONString(request));
|
|
|
+ fsWxExpressTask.setRequestBody(JSON.toJSONString(request));
|
|
|
+ fsWxExpressTask.setResponseBody(JSON.toJSONString(response));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.info("该单 {} 推送到物流失败!",fsWxExpressTask);
|
|
|
+ fsWxExpressTask.setRetryCount(fsWxExpressTask.getRetryCount() +1);
|
|
|
+ fsWxExpressTask.setStatus(3);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (FsWxExpressTask fsWxExpressTask : fsWxExpressTasks) {
|
|
|
+ fsWxExpressTaskMapper.updateById(fsWxExpressTask);
|
|
|
+ }
|
|
|
+// fsWxExpressTaskMapper.batchUpdate(fsWxExpressTasks);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单商品信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getOrderGoodsInfo(FsStoreOrderScrm order){
|
|
|
+ StringBuilder title = new StringBuilder();
|
|
|
+ // 如果是套餐
|
|
|
+ if(ObjectUtil.equal(order.getIsPackage(),1)){
|
|
|
+ String packageJson = order.getPackageJson();
|
|
|
+ JSONObject jsonObject = JSON.parseObject(packageJson);
|
|
|
+ title = new StringBuilder(jsonObject.getString("title"));
|
|
|
+ } else {
|
|
|
+ String itemJson = order.getItemJson();
|
|
|
+ com.alibaba.fastjson.JSONArray arrays = JSON.parseArray(itemJson);
|
|
|
+ for(int i=0;i<arrays.size();i++){
|
|
|
+ JSONObject jsonObject = arrays.getJSONObject(i);
|
|
|
+ String jsonInfo = jsonObject.getString("jsonInfo");
|
|
|
+ JSONObject jsonObject1 = JSON.parseObject(jsonInfo);
|
|
|
+ String productName = jsonObject1.getString("productName");
|
|
|
+ title.append(productName).append("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return title.toString();
|
|
|
+ }
|
|
|
//统计ai事件埋点
|
|
|
public void eventLogTotals() {
|
|
|
// 判断是否是凌晨 00:00 - 00:59
|
|
|
@@ -566,7 +688,11 @@ public class Task {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
logger.error("调用ERP接口异常:",e);
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000); // 1000毫秒 = 1秒
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
|
+ }
|
|
|
continue;
|
|
|
//throw new RuntimeException(e);
|
|
|
}
|
|
|
@@ -589,6 +715,36 @@ public class Task {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ @Autowired
|
|
|
+ IFsStorePaymentScrmService fsStorePaymentScrmService;
|
|
|
+ public void test()
|
|
|
+ {
|
|
|
+ List<FsStoreOrderScrm> orders = fsStoreOrderMapper.selectOrdersBy2();
|
|
|
+ for (FsStoreOrderScrm order : orders) {
|
|
|
+ try{
|
|
|
+ FsWxExpressTask fsWxExpressTask = new FsWxExpressTask();
|
|
|
+ fsWxExpressTask.setUserId(order.getUserId());
|
|
|
+ fsWxExpressTask.setStatus(0);
|
|
|
+ fsWxExpressTask.setRetryCount(0);
|
|
|
+ fsWxExpressTask.setCreateTime(LocalDateTime.now());
|
|
|
+ fsWxExpressTask.setUpdateTime(LocalDateTime.now());
|
|
|
+ fsWxExpressTask.setOrderCode(order.getOrderCode());
|
|
|
+ fsWxExpressTask.setExpressCompany("SF");
|
|
|
+ fsWxExpressTask.setExpressNo(order.getDeliveryId());
|
|
|
+ List<FsStorePaymentScrm> fsStorePayments = fsStorePaymentScrmService.selectFsStorePaymentByOrderIdNew(order.getId());
|
|
|
+ if(fsStorePayments!=null&&!fsStorePayments.isEmpty()){
|
|
|
+ FsStorePaymentScrm fsStorePayment = fsStorePayments.get(0);
|
|
|
+ fsWxExpressTask.setPayCode(fsStorePayment.getPayCode());
|
|
|
+ }
|
|
|
+ fsWxExpressTaskMapper.insert(fsWxExpressTask);
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.info("添加expressTask失败:"+order.getOrderCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void getOrderDeliveryStatus()
|
|
|
{
|
|
|
IErpOrderService erpOrderService = getErpService();
|