소스 검색

Merge remote-tracking branch 'origin/saas' into saas

zouxuan 3 년 전
부모
커밋
87df3a1f47

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java

@@ -49,7 +49,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
     public Map<String, Object> executePayment(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) throws Exception {
         PaymentParam payParam = new PaymentParam(amount, orderNo, payChannel, returnUrl,
                 orderSubject, orderBody, sign, code, platform);
-        log.info("executePayment >>>>>> "+JSON.toJSONString(payParam));
+        log.info("executePayment >>>>> {}", JSON.toJSONString(payParam));
         //签名验证
         checkSing(payParam);
 
@@ -101,7 +101,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
         String originalStr = JSONObject.toJSONString(signParams);
         String newSign = DigestUtils.md5DigestAsHex(originalStr.getBytes());
         if (!newSign.equals(param.getSign())) {
-            log.info("executePayment >>>>>> checkSing : "+newSign);
+            log.info("executePayment >>>>>> checkSing : {}", newSign);
             throw new BizException("请勿非法请求");
         }
     }
@@ -122,6 +122,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
         paymentParams.put("expend", getExpend(payParam));
         //获取第三方的支付的信息
         Map<String, Object> payment = Payment.executePayment(paymentParams);
+        log.info("executePayment create order param >>>>> {}", JSON.toJSONString(payment));
         String transNo = (String) payment.get("id");
         //修改流水
         setTransNoByApply(transNo, clazz, setOption, action);

+ 36 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java

@@ -8,6 +8,7 @@ import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
 import com.ym.mec.biz.dal.entity.TenantConfig;
 import com.ym.mec.biz.dal.entity.TenantConfigDetail;
 import com.ym.mec.biz.dal.entity.TenantConfigDetail.CloudRoomRule;
+import com.ym.mec.biz.dal.enums.TeachModeEnum;
 import com.ym.mec.biz.service.TenantAssetsInfoService;
 import com.ym.mec.biz.service.TenantConfigService;
 import com.ym.mec.common.exception.BizException;
@@ -28,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * 机构资产信息(TenantAssetsInfo)表服务实现类
@@ -51,7 +53,41 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void courseDeductionRules(List<CourseSchedule> dto) {
+        dto = Optional.ofNullable(dto)
+                .filter(CollectionUtils::isNotEmpty)
+                .orElseThrow(() -> new BizException("请传入课程表参数!"))
+                .stream()
+                .filter(c -> c.getTeachMode().equals(TeachModeEnum.ONLINE))
+                .collect(Collectors.toList());
 
+        Integer tenantId = TenantContextHolder.getTenantId();
+        TenantConfig tenantConfig = tenantConfigService.getOne(new WrapperUtil<TenantConfig>()
+                .hasEq("tenant_id_", tenantId).queryWrapper());
+        if (Objects.isNull(tenantConfig)) {
+            throw new BizException("未查询到机构云教室规则信息!");
+        }
+        //获取云教室规则
+        Map<String, BigDecimal> rule = Optional.ofNullable(tenantConfig.getConfig())
+                .map(c -> JSON.parseObject(c, TenantConfigDetail.class))
+                .map(TenantConfigDetail::getCloud_room_rule)
+                .map(CloudRoomRule::getCloud_room_config)
+                .orElseThrow(() -> new BizException("未查询到机构云教室规则!"));
+        BigDecimal total = BigDecimal.ZERO;
+//        dto.forEach(course -> {
+//            Integer peopleNum = course.getPeopleNum();
+//            BigDecimal minutePrice = rule.get(String.valueOf(peopleNum));
+//            BigDecimal duration = BigDecimal.valueOf(course.getCourseDuration());
+//            BigDecimal coursePrice = minutePrice.multiply(duration, new MathContext(2, RoundingMode.HALF_UP));
+//
+//        });
+
+        System.out.println(1);
+
+        TenantAssetsInfo assetsInfo = this.getOne(new WrapperUtil<TenantAssetsInfo>()
+                .hasEq("tenant_id_", tenantId).queryWrapper());
+        if (Objects.isNull(assetsInfo)) {
+            throw new BizException("未查询到该机构的账户资产信息!");
+        }
     }
 
 

+ 12 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -311,6 +311,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         e.setRoleIds(roles);
         e.setOrganIdList(String.valueOf(orgId));
         try {
+            log.info("createUser >>>> {}", e);
             employeeService.add(e);
         } catch (Exception ex) {
             throw new BizException("开通账号信息异常!");
@@ -395,7 +396,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             result.put("payMap", payMap);
         }
         createOrderRecord(tenantId, productInfo.getPayAmount(), orderNo, tenantEnum, orderState);
-        log.info("tenant pay >>>>> " + JSON.toJSONString(result));
+        log.info("tenant pay >>>>> {} ", result);
         return result;
     }
 
@@ -409,7 +410,12 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         record.setExpectAmount(payAmount);
         record.setActualAmount(payAmount);
         record.setOrderState(orderState);
-        record.setCreatedTime(new Date());
+        LocalDateTime now = LocalDateTime.now();
+        if (orderState == 1) {
+            record.setPayDate(now.toLocalDate().toDate());
+            record.setPayTime(now.toDate());
+        }
+        record.setCreatedTime(now.toDate());
         tenantOrderRecordService.save(record);
     }
 
@@ -421,7 +427,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      */
     @Override
     public Msg orderNotify(Msg msg) {
-        log.info("tenant orderNotify >>>>> " + msg.toString());
+        log.info("tenant orderNotify >>>>> {}", msg);
         msg.setMsg("fail");
         Map<String, String> notifyMap = JSON.parseObject(msg.getResponseParameters(), Map.class);
         String orderNo = notifyMap.get("merMerOrderNo");
@@ -445,9 +451,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             //支付失败
             record.setOrderState(2);
         }
-        tenantOrderRecordService.update(record, new QueryWrapper<TenantOrderRecord>()
-                .eq("order_no_", record.getOrderNo()));
-        log.info("tenant orderNotify return>>>>> " + msg.toString());
+        log.info("tenant orderNotify return>>>>> {}", record);
+        tenantOrderRecordService.updateById(record);
+        log.info("tenant orderNotify return>>>>> {}", msg);
         return msg;
     }
 

+ 47 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -1,29 +1,30 @@
 package com.ym.mec.biz.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ym.mec.biz.dal.dao.TenantOrderRecordDao;
 import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
-import com.ym.mec.biz.dal.entity.PlatformServe;
-import com.ym.mec.biz.dal.entity.PlatformServeDetail;
-import com.ym.mec.biz.dal.entity.TenantOrderRecord;
-import com.ym.mec.biz.dal.entity.TenantProductInfo;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 import com.ym.mec.biz.dal.enums.TenantOrderRecordEnum;
-import com.ym.mec.biz.service.PlatformServeDetailService;
-import com.ym.mec.biz.service.PlatformServeService;
-import com.ym.mec.biz.service.TenantOrderRecordService;
-import com.ym.mec.biz.service.TenantProductInfoService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
 import com.ym.mec.common.page.WrapperUtil;
+import com.ym.mec.thirdparty.adapay.Payment;
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.LocalDateTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * 机构付款记录表(TenantOrderRecord)表服务实现类
@@ -41,6 +42,8 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
     private PlatformServeService platformServeService;
     @Autowired
     private PlatformServeDetailService platformServeDetailService;
+    @Autowired
+    private TenantInfoService tenantInfoService;
 
     @Override
     public PageInfo<TenantOrderRecord> queryPage(TenantOrderRecordDto dto) {
@@ -55,6 +58,24 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
     public Map<String, Object> checkTenantOrder(String orderNo) {
         TenantOrderRecord orderRecord = this.getOne(new WrapperUtil<TenantOrderRecord>()
                 .hasEq("order_no_", orderNo).queryWrapper());
+        if (StringUtils.equals(orderRecord.getPaymentChannel(), PaymentChannelEnum.ADAPAY.getCode())) {
+            Map<String, Object> payment = null;
+            try {
+                payment = Payment.queryPayment(orderRecord.getTransNo());
+                if (Objects.nonNull(payment.get("status"))) {
+                    String status = (String) payment.get("status");
+                    if (status.equals("succeeded")) {
+                        orderRecord.setOrderState(1);
+                    } else if (status.equals("failed")) {
+                        orderRecord.setOrderState(2);
+                    }
+                }
+                log.info("checkTenantOrder  payment >>>>> {}", JSON.toJSONString(orderRecord));
+            } catch (Exception e) {
+                log.error("checkTenantOrder  payment error>>>>> {}", JSON.toJSONString(orderRecord));
+            }
+        }
+
         //返回
         Map<String, Object> result = new HashMap<>();
         result.put("groupType", orderRecord.getOrderType());
@@ -68,6 +89,7 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
         Map<String, Object> detail = new HashMap<>();
         result.put("detail", detail);
 
+        log.info("checkTenantOrder  getOrderState>>>>> {}", JSON.toJSONString(orderRecord));
         getOrderState(orderRecord, result);
         return result;
     }
@@ -83,9 +105,16 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
                     tenantOrderSuccess(orderRecord, detail);
                 }
                 code = DealStatusEnum.SUCCESS.getCode();
+                LocalDateTime now = LocalDateTime.now();
+                orderRecord.setPayDate(now.toLocalDate().toDate());
+                orderRecord.setPayTime(now.toDate());
+                //修改流水
+                baseMapper.updateById(orderRecord);
                 break;
             case 2:
                 code = DealStatusEnum.FAILED.getCode();
+                //修改流水
+                baseMapper.updateById(orderRecord);
                 break;
             default:
                 code = DealStatusEnum.ING.getCode();
@@ -105,7 +134,16 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
                 .hasEq("id_", productInfo.getServeDetailId()).queryWrapper());
         detail.put("platformServeName", platformServe.getName());
         detail.put("mode", serveDetail.getMode());
-        detail.put("num",productInfo.getExpiryCount());
+        detail.put("num", productInfo.getExpiryCount());
+
+        TenantInfo tenantInfo = new TenantInfo();
+        tenantInfo.setId(orderRecord.getTenantId());
+        tenantInfo.setPayState(1);
+        tenantInfoService.updateById(tenantInfo);
+
+        productInfo.setPayDate(new Date());
+        productInfo.setTenantId(orderRecord.getTenantId());
+        tenantProductInfoService.updateById(productInfo);
     }
 
 }