Переглянути джерело

Merge branch 'develop/v1.0' of http://git.kdan.cc:8865/Server_Service/pdf_office_back_end into develop/v1.0

Bob 4 місяців тому
батько
коміт
11b60d0876

+ 4 - 0
pdf-office-account/src/main/resources/sqlmap/ext/ExtUserSubscriptionInfoMapper.xml

@@ -15,6 +15,8 @@
     <result column="max_device_num" jdbcType="INTEGER" property="maxDeviceNum" />
     <result column="levels" jdbcType="VARCHAR" property="levels" />
     <result column="platforms" jdbcType="VARCHAR" property="platforms" />
+    <result column="simplified_chinese_name" jdbcType="VARCHAR" property="simplifiedChineseName" />
+    <result column="traditional_chinese_name" jdbcType="VARCHAR" property="traditionalChineseName" />
     <result column="payment_model" jdbcType="VARCHAR" property="paymentModel" />
     <result column="is_ai" jdbcType="VARCHAR" property="isAi" />
     <result column="code" jdbcType="VARCHAR" property="code" />
@@ -36,6 +38,8 @@
       p.payment_model,
       p.is_ai,
       p.cycle,
+      p.simplified_chinese_name,
+      p.traditional_chinese_name,
       GROUP_CONCAT(Distinct r.level) AS levels,
       GROUP_CONCAT(Distinct p2.name) AS platforms
     FROM

+ 3 - 0
pdf-office-common/src/main/java/cn/kdan/cloud/pdf/office/common/vo/SimpleUserSubscriptionInfoVO.java

@@ -66,4 +66,7 @@ public class SimpleUserSubscriptionInfoVO {
      */
     private Integer cycle;
 
+    private String simplifiedChineseName;
+    private String traditionalChineseName;
+
 }

+ 2 - 0
pdf-office-common/src/main/java/cn/kdan/cloud/pdf/office/common/vo/UserSubscriptionInfoVO.java

@@ -53,4 +53,6 @@ public class UserSubscriptionInfoVO {
 
     private String code;
     private Integer cycle;
+    private String simplifiedChineseName;
+    private String traditionalChineseName;
 }

+ 9 - 6
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/impl/OrderGiftLogServiceImpl.java

@@ -40,8 +40,9 @@ public class OrderGiftLogServiceImpl extends ServiceImpl<OrderGiftLogMapper, Ord
     @Override
     public OrderGiftLog logGift(String userId, String email, String name, String orderGiftId) {
        //根据赠送者id userId,接受者邮箱,接受者name,插入记录表,状态为"待接收"
+        String id = CommonUtils.generateId();
         OrderGiftLog orderGiftLog = new OrderGiftLog();
-        orderGiftLog.setId(CommonUtils.generateId());
+        orderGiftLog.setId(id);
         orderGiftLog.setUserId(userId);
         orderGiftLog.setEmail(email);
         orderGiftLog.setName(name);
@@ -50,19 +51,21 @@ public class OrderGiftLogServiceImpl extends ServiceImpl<OrderGiftLogMapper, Ord
         this.save(orderGiftLog);
         rabbitTemplate.convertAndSend(RabbitMqConstant.ORDER_GIFT_DELAY_EXCHANGE,
                 RabbitMqConstant.ORDER_GIFT_DELAY_ROUTING_KEY,
-                orderGiftId,
+                id,
                 (msg -> {
-                    msg.getMessageProperties().setHeader("x-delay", (24 * 60 * 60 * 1000) + "");
+                    //msg.getMessageProperties().setHeader("x-delay", (24 * 60 * 60 * 1000) + "");
+                    msg.getMessageProperties().setHeader("x-delay", (60 * 1000) + "");
                     return msg;
                 }));
         return orderGiftLog;
     }
 
     @Override
-    public void expire(String orderGiftId) {
-        this.update(Wrappers.<OrderGiftLog>lambdaUpdate().set(OrderGiftLog::getValidFlag, OrderGiftLogVaildFlagEnum.RECEIVE_FAIL.getCode()).eq(OrderGiftLog::getOrderGiftId, orderGiftId));
+    public void expire(String orderGiftLogId) {
+        this.update(Wrappers.<OrderGiftLog>lambdaUpdate().set(OrderGiftLog::getValidFlag, OrderGiftLogVaildFlagEnum.RECEIVE_FAIL.getCode()).eq(OrderGiftLog::getId, orderGiftLogId));
+        OrderGiftLog log1 = this.getById(orderGiftLogId);
         //并且更新orderGift表中对应记录的validFlag
-        orderGiftMapper.update(null, Wrappers.<OrderGift>lambdaUpdate().set(OrderGift::getValidFlag, OrderGiftVaildFlagEnum.GIFT_ABLE.getCode()).eq(OrderGift::getId, orderGiftId));
+        orderGiftMapper.update(null, Wrappers.<OrderGift>lambdaUpdate().set(OrderGift::getValidFlag, OrderGiftVaildFlagEnum.GIFT_ABLE.getCode()).eq(OrderGift::getId, log1.getOrderGiftId()));
     }
     //接收会员
     @Override

+ 20 - 20
pdf-office-pdf-website/src/main/java/cn/kdan/cloud/pdf/office/website/config/CustomRemoteTokenServices.java

@@ -20,27 +20,27 @@ public class CustomRemoteTokenServices extends RemoteTokenServices {
         try {
             return super.loadAuthentication(accessToken);
         } catch (Exception ex) {
-//            Map<String, Object> map = new HashMap<>(7);
-//            map.put("code", ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID.value());
-//            map.put("msg", ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID.msg());
-//            map.put("data", "invalid_token");
-//            map.put("path", "path");
-//            map.put("timestamp", String.valueOf(System.currentTimeMillis()));
-//            // Token失效时的异常处理
-//            // 设置HTTP状态码为401
-//            HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
-////            if (response != null) {
-////                // 设置HTTP状态码为401
-////                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
-////            }
-//            response.setStatus(HttpServletResponse.SC_OK);
-//            response.setContentType("application/json");
-//            try {
-//                ObjectMapper mapper = new ObjectMapper();
-//                mapper.writeValue(response.getOutputStream(), map);
-//            } catch (Exception e) {
-//                throw new BackendRuntimeException(ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID);
+            Map<String, Object> map = new HashMap<>(7);
+            map.put("code", ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID.value());
+            map.put("msg", ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID.msg());
+            map.put("data", "invalid_token");
+            map.put("path", "path");
+            map.put("timestamp", String.valueOf(System.currentTimeMillis()));
+            // Token失效时的异常处理
+            // 设置HTTP状态码为401
+            HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
+//            if (response != null) {
+//                // 设置HTTP状态码为401
+//                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
 //            }
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType("application/json");
+            try {
+                ObjectMapper mapper = new ObjectMapper();
+                mapper.writeValue(response.getOutputStream(), map);
+            } catch (Exception e) {
+                throw new BackendRuntimeException(ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID);
+            }
             // Token失效时的异常处理
             throw new BackendRuntimeException(ExceptionEnum.EXCEPTION_MSG_TOKEN_IS_INVALID);
         }

+ 57 - 19
pdf-office-pdf-website/src/main/java/cn/kdan/cloud/pdf/office/website/service/impl/OrderGiftServiceImpl.java

@@ -20,10 +20,9 @@ import cn.kdan.cloud.pdf.office.common.exception.BackendRuntimeException;
 import cn.kdan.cloud.pdf.office.common.pojo.ResultMap;
 import cn.kdan.cloud.pdf.office.common.utils.CommonUtils;
 import cn.kdan.cloud.pdf.office.common.vo.UserInfoVO;
+import cn.kdan.cloud.pdf.office.common.vo.UserSubscriptionInfoVO;
 import cn.kdan.cloud.pdf.office.common.vo.UserVO;
 import cn.kdan.cloud.pdf.office.website.service.OrderGiftService;
-import cn.kdan.cloud.pdf.office.website.utils.SecurityUtils;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -32,8 +31,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
 
 
 @Service
@@ -47,7 +47,7 @@ public class OrderGiftServiceImpl implements OrderGiftService {
     private final ProductApi productApi;
     @Resource
     private UserSubscriptionInfoApi userSubscriptionInfoApi;
-    @Value("${orderGiftUrl:www.baidu.com}")
+    @Value("${orderGiftUrl:}")
     private String orderGiftUrl;
 
     @Override
@@ -61,6 +61,7 @@ public class OrderGiftServiceImpl implements OrderGiftService {
         //判断接受人是否已经有账号
         UserVO userVO = userApi.getByEmail(email).getResult();
         String giftEmail = userApi.getById(userId).getResult().getEmail();
+        AtomicBoolean gifted = new AtomicBoolean(false);
         //如果没有账号直接发送赠送邮件,并且记录赠送日志
         if (ObjectUtils.isEmpty(userVO)) {
             OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
@@ -81,7 +82,7 @@ public class OrderGiftServiceImpl implements OrderGiftService {
                     throw new BackendRuntimeException(ExceptionEnum.USER_ALREADY_SUBSCRIBED_PACKAGE);
                 }
                 //是订阅中的订阅会员, //3.如果是订阅会员,如果有isGift且为ture,则直接赠送,如果没有则提醒你已经是订阅会员了
-                if (userSubscriptionInfoVO.getPaymentModel().equals("1")) {
+                if (userSubscriptionInfoVO.getPaymentModel().equals("1")&&userSubscriptionInfoVO.getPlatform().equals(2)) {
                     if (isGift) {
                         OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
                         String orderGiftId = orderGiftLogVO.getId();
@@ -89,23 +90,24 @@ public class OrderGiftServiceImpl implements OrderGiftService {
                         EmailSendBO bo = new EmailSendBO();
                         bo.setToEmail(email);
                         handleEmailSendBO(EmailCodeTypeEnum.GIVE_AWAY, bo, giftEmail,email,orderGiftId);
+                        gifted.set(true);
                     } else {
                         throw new BackendRuntimeException(ExceptionEnum.USER_ALREADY_SUBSCRIBED_PLAN);
                     }
                 }
-                if (userSubscriptionInfoVO.getPaymentModel().equals("2")
-                        && userSubscriptionInfoVO.getStatus().equals(PDFOfficeUserSubscriptionStatusEnum.REGISTER.value())) {
-                    //发送赠送邮件
-                    //1.如果是免费用户,接收人是免费用户,则直接发送邮件 (赠送邮件24小时有效,超过24小时未确认,邮件失效,【接收会员】按钮点击提示已失效,需要用户重新发起赠送邀请)
-                    //修改orderGift中的一条记录为赠送中,且记录赠送日志为未接收
-                    OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
-                    String orderGiftId = orderGiftLogVO.getId();
-                    //存到redis里
-                    EmailSendBO bo = new EmailSendBO();
-                    bo.setToEmail(email);
-                    handleEmailSendBO(EmailCodeTypeEnum.GIVE_AWAY, bo, giftEmail,email,orderGiftId);
-                }
             });
+            if(!gifted.get()){
+                //发送赠送邮件
+                //1.如果是免费用户,接收人是免费用户,则直接发送邮件 (赠送邮件24小时有效,超过24小时未确认,邮件失效,【接收会员】按钮点击提示已失效,需要用户重新发起赠送邀请)
+                //修改orderGift中的一条记录为赠送中,且记录赠送日志为未接收
+                OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
+                String orderGiftId = orderGiftLogVO.getId();
+                //存到redis里
+                EmailSendBO bo = new EmailSendBO();
+                bo.setToEmail(email);
+                handleEmailSendBO(EmailCodeTypeEnum.GIVE_AWAY, bo, giftEmail,email,orderGiftId);
+            }
+
         }
     }
 
@@ -118,12 +120,48 @@ public class OrderGiftServiceImpl implements OrderGiftService {
         Map<String, String> contentMap = new HashMap<>();
         contentMap.put("@userEmail@", userEmail);
         contentMap.put("@receviceEmail@", receiveEmail);
-        contentMap.put("@url@", orderGiftUrl+"?orderGiftLogId="+orderGiftLogId);
+        contentMap.put("@url@", orderGiftUrl+orderGiftLogId);
         bo.setSendTitleContent(titleMap);
         //设置内容
         bo.setSendContent(contentMap);
+        emailApi.sendEmail(bo);
     }
 
+    public UserSubscriptionInfoVO findActiveSubscription(List<UserSubscriptionInfoVO> subscriptionInfoList) {
+        // 过滤掉isAi为true的记录
+        List<UserSubscriptionInfoVO> filteredList = subscriptionInfoList.stream()
+                .filter(info -> ObjectUtils.isEmpty(info.getIsAi())||ValidStatusEnum.INVALID.value().equals(info.getIsAi())) // 排除AI记录
+                .collect(Collectors.toList());
+
+        // 找到一条生效的记录,按优先级排序
+        Optional<UserSubscriptionInfoVO> activeSubscription = filteredList.stream()
+                .sorted(Comparator.comparingInt(this::getLevelPriority)
+                        .reversed() // 按优先级降序排列
+                        .thenComparing(Comparator.comparingInt(UserSubscriptionInfoVO::getMaxDeviceNum).reversed()) // 如果优先级相同按max_device_num降序
+                )
+                .findFirst(); // 找到优先级最高的记录
+
+        return activeSubscription.orElse(null); // 返回结果,如果没有找到则返回null
+    }
+
+    private int getLevelPriority(UserSubscriptionInfoVO info) {
+        // 假设 levels 是以逗号分隔的字符串
+        String[] levels = info.getLevels().split(",");
+        int maxPriority = Integer.MIN_VALUE;
+
+        for (String level : levels) {
+            int lvl = Integer.parseInt(level.trim());
+            maxPriority = Math.max(maxPriority, lvl);
+        }
+
+        // 定义优先级
+        switch (maxPriority) {
+            case 3: return 3; // 高级版
+            case 2: return 2; // 标准版
+            case 1: return 1; // 免费版
+            default: return 0; // 未知或无效等级
+        }
+    }
     @Override
     //链接过期的逻辑(已完成)
     //接受会员接口

+ 1 - 1
pdf-office-sso/src/main/java/cn/kdan/cloud/pdf/office/sso/service/impl/AuthServiceImpl.java

@@ -395,7 +395,7 @@ public class AuthServiceImpl implements AuthService {
         // 获取当前的时间,设置为 GMT 时区
         ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
         // 定义目标日期时间格式
-        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm (GMT)");
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm '(GMT)'");
         // 格式化当前时间
         String formattedTime = now.format(formatter);
         contentMap.put("@time@",formattedTime);