Browse Source

APP角色新增角色类型

wjj 6 ngày trước cách đây
mục cha
commit
771574de45

+ 34 - 5
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -4,6 +4,8 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
+import com.fs.app.domain.FsAppRole;
+import com.fs.app.mapper.FsAppRoleMapper;
 import com.fs.common.exception.CustomException;
 import com.fs.core.utils.OrderCodeUtils;
 import com.fs.doctor.service.IFsDoctorOnlineService;
@@ -19,8 +21,6 @@ import com.fs.huifuPay.domain.HuifuOrderConfirmResult;
 import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
 import com.fs.huifuPay.sdk.opps.core.utils.DateTools;
 import com.fs.huifuPay.service.HuiFuService;
-import com.fs.qw.domain.FsSopCompanyUserTask;
-import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.mapper.FsSopCompanyUserTaskMapper;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.sop.domain.QwSopTempVoice;
@@ -80,7 +80,6 @@ import com.fs.qw.mapper.QwRestrictionPushRecordMapper;
 import com.fs.qw.service.*;
 import com.fs.qwApi.service.QwApiService;
 import com.fs.sop.domain.SopOrderLog;
-import com.fs.sop.domain.SopUserLogsInfo;
 import com.fs.sop.mapper.SopOrderLogMapper;
 import com.fs.sop.mapper.SopUserLogsInfoMapper;
 import com.fs.sop.service.IQwSopTempVoiceService;
@@ -97,15 +96,14 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.OffsetDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -280,6 +278,12 @@ public class Task {
     @Autowired
     private IFsDoctorOnlineService doctorOnlineService;
 
+    @Autowired
+    private FsAppRoleMapper appRoleMapper;
+
+    @Autowired
+    private IFsUserService fsUserService;
+
     public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
 
     // sop升单客户类型
@@ -291,6 +295,10 @@ public class Task {
         TYPE_MAPPING.put("3,1,2", 3); // 小品未购 主品已购 -> 3
         TYPE_MAPPING.put("4,2,2", 4); // 小品已购 主品已购 -> 4
     }
+
+    @Autowired
+    private FsAppRoleMapper fsAppRoleMapper;
+
     public void syncExpressToWx() {
         List<FsWxExpressTask> fsWxExpressTasks = fsWxExpressTaskMapper.selectPendingData();
         if (CollectionUtils.isEmpty(fsWxExpressTasks)) {
@@ -2364,4 +2372,25 @@ public class Task {
         }
     }
 
+    //添加用户角色
+    public void userAddAppRole(){
+        long start = System.nanoTime();
+        List<Long> userIds = fsUserMapper.selectFsUserNoAppRole();
+        List<FsAppRole> roles = fsAppRoleMapper.selectFsAppRoleList(new FsAppRole());
+        if (CollectionUtils.isNotEmpty(userIds) && CollectionUtils.isNotEmpty(roles)) {
+            for (Long userId : userIds) {
+                try {
+                    fsUserService.userAddAppRole(userId, roles);
+                    Thread.sleep(1000);
+                } catch (Exception e) {
+                    logger.info("添加用户角色信息失败,原因:{},用户id:{}",e.getMessage(),userId);
+                    continue;
+                }
+            }
+        }
+        long durationMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
+        log.info("方法执行完成,耗时: {} ms", durationMs);
+
+    }
+
 }

+ 1 - 1
fs-service/src/main/java/com/fs/app/domain/FsAppRole.java

@@ -26,7 +26,7 @@ public class FsAppRole extends BaseEntity{
     private String roleName;
 
     /** APP角色类型:1-通用 2-积分 3-套餐包 4-商城商品 */
-    @Excel(name = "APP角色类型:1-通用 2-积分 3-套餐包 4-商城商品")
+    @Excel(name = "APP角色类型:1-通用 2-标签 3-套餐包 4-商城商品 5.标签+套餐包 6. 标签+商城商品 7.标签+商品")
     private Integer roleType;
 
     /** 注册奖励类型:1-红包 2-积分 3-商品 */

+ 102 - 4
fs-service/src/main/java/com/fs/his/service/impl/FsUserServiceImpl.java

@@ -10,6 +10,7 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.hutool.json.JSONUtil;
@@ -1433,7 +1434,28 @@ public class FsUserServiceImpl implements IFsUserService {
                 .stream()
                 .filter(fsAppRole -> fsAppRole.getRoleType() == 4)
                 .collect(Collectors.toList());
+        //标签+套餐包角色
+        List<FsAppRole> tagAndPackageRoleList = appRoleList
+                .stream()
+                .filter(fsAppRole -> fsAppRole.getRoleType() == 5)
+                .collect(Collectors.toList());
+        //标签+商城角色
+        List<FsAppRole> tagAndMallRoleList = appRoleList
+                .stream()
+                .filter(fsAppRole -> fsAppRole.getRoleType() == 6)
+                .collect(Collectors.toList());
+        //标签+套餐包+商城商品
+        List<FsAppRole> tagAndProductRoleList = appRoleList
+                .stream()
+                .filter(fsAppRole -> fsAppRole.getRoleType() == 7)
+                .collect(Collectors.toList());
         //2.匹配添加角色
+        //用户标签
+        List<String> userTags = qwExternalContactService.selectTagsByFsUserId(userId);
+        //用户购买的套餐包id
+        List<Long> userBuyPackageId = fsStoreOrderMapper.selectUserBuyOrderList(userId);
+        //用户购买的商城商品id
+        List<Long> userProductIds = storeOrderMapper.selectUserBuyProductIds(userId);
         //通用
         if (CollectionUtils.isNotEmpty(commonRoleList)) {
             List<Long> commonIds = commonRoleList.stream().map(FsAppRole::getId).collect(Collectors.toList());
@@ -1441,8 +1463,6 @@ public class FsUserServiceImpl implements IFsUserService {
         }
         //角色标签
         if (CollectionUtils.isNotEmpty(tagRoleList)) {
-            //用户标签
-            List<String> userTags = qwExternalContactService.selectTagsByFsUserId(userId);
             if (CollectionUtils.isNotEmpty(userTags)) {
                 tagRoleList.forEach(tagAppRole -> {
                     if (StringUtils.isNotEmpty(tagAppRole.getRoleTags())) {
@@ -1457,7 +1477,6 @@ public class FsUserServiceImpl implements IFsUserService {
         }
         //角色套餐包
         if (CollectionUtils.isNotEmpty(packageRoleList)) {
-            List<Long> userBuyPackageId = fsStoreOrderMapper.selectUserBuyOrderList(userId);
             if (CollectionUtils.isNotEmpty(userBuyPackageId)) {
                 packageRoleList.forEach(packageAppRole -> {
                     if (StringUtils.isNotEmpty(packageAppRole.getRolePackageProductIds())) {
@@ -1476,7 +1495,6 @@ public class FsUserServiceImpl implements IFsUserService {
 
         //角色商城商品
         if (CollectionUtils.isNotEmpty(productRoleList)) {
-            List<Long> userProductIds = storeOrderMapper.selectUserBuyProductIds(userId);
             if (CollectionUtils.isNotEmpty(userProductIds)) {
                 productRoleList.forEach(productAppRole -> {
                    if (StringUtils.isNotEmpty(productAppRole.getRoleStoreProductIds())) {
@@ -1493,6 +1511,86 @@ public class FsUserServiceImpl implements IFsUserService {
                 });
             }
         }
+        //标签+套餐包
+        if (CollectionUtils.isNotEmpty(tagAndPackageRoleList)) {
+            if (CollectionUtils.isNotEmpty(userTags) && CollectionUtils.isNotEmpty(userBuyPackageId)) {
+                tagAndPackageRoleList.forEach(tagAndPackageRole -> {
+                    boolean tagMatch = false;
+                    boolean buyMatch = false;
+                    if (StringUtils.isNotEmpty(tagAndPackageRole.getRoleTags())) {
+                        List<String> tags = Arrays.stream(tagAndPackageRole.getRoleTags().split(",")).collect(Collectors.toList());
+                        tagMatch = userTags.stream().anyMatch(tags::contains);
+                    }
+                    if (StringUtils.isNotEmpty(tagAndPackageRole.getRolePackageProductIds())) {
+                        List<Long> packages = Arrays.stream(tagAndPackageRole.getRolePackageProductIds().split(","))
+                                .map(String::trim)
+                                .map(Long::parseLong)
+                                .collect(Collectors.toList());;
+                        buyMatch = userBuyPackageId.stream().anyMatch(packages::contains);
+                    }
+                    if (tagMatch && buyMatch) {
+                        addRoleList.add(tagAndPackageRole.getId());
+                    }
+                });
+            }
+        }
+
+        //标签+商城商品
+        if (CollectionUtils.isNotEmpty(tagAndMallRoleList)) {
+            if (CollectionUtils.isNotEmpty(userTags) && CollectionUtils.isNotEmpty(userProductIds)) {
+                tagAndPackageRoleList.forEach(tagAndMallRole -> {
+                    boolean tagMatch = false;
+                    boolean productMatch = false;
+                    if (StringUtils.isNotEmpty(tagAndMallRole.getRoleTags())) {
+                        List<String> tags = Arrays.stream(tagAndMallRole.getRoleTags().split(",")).collect(Collectors.toList());
+                        tagMatch = userTags.stream().anyMatch(tags::contains);
+                    }
+                    if (StringUtils.isNotEmpty(tagAndMallRole.getRolePackageProductIds())) {
+                        List<Long> packages = Arrays.stream(tagAndMallRole.getRoleStoreProductIds().split(","))
+                                .map(String::trim)
+                                .map(Long::parseLong)
+                                .collect(Collectors.toList());;
+                        productMatch = userProductIds.stream().anyMatch(packages::contains);
+                    }
+                    if (tagMatch && productMatch) {
+                        addRoleList.add(tagAndMallRole.getId());
+                    }
+                });
+            }
+        }
+
+        //标签+商城商品+套餐包
+        if (CollectionUtils.isNotEmpty(tagAndProductRoleList)) {
+            if (CollectionUtils.isNotEmpty(userTags) && CollectionUtils.isNotEmpty(userProductIds) && CollectionUtils.isNotEmpty(userBuyPackageId)) {
+                tagAndProductRoleList.forEach(tagAndProductRole -> {
+                    boolean tagMatch = false;
+                    boolean buyMatch = false;
+                    boolean productMatch = false;
+
+                    if (StringUtils.isNotEmpty(tagAndProductRole.getRoleTags())) {
+                        List<String> tags = Arrays.stream(tagAndProductRole.getRoleTags().split(",")).collect(Collectors.toList());
+                        tagMatch = userTags.stream().anyMatch(tags::contains);
+                    }
+                    if (StringUtils.isNotEmpty(tagAndProductRole.getRolePackageProductIds())) {
+                        List<Long> packages = Arrays.stream(tagAndProductRole.getRoleStoreProductIds().split(","))
+                                .map(String::trim)
+                                .map(Long::parseLong)
+                                .collect(Collectors.toList());;
+                        productMatch = userProductIds.stream().anyMatch(packages::contains);
+                    }
+                    if (StringUtils.isNotEmpty(tagAndProductRole.getRolePackageProductIds())) {
+                        List<Long> packages = Arrays.stream(tagAndProductRole.getRolePackageProductIds().split(","))
+                                .map(String::trim)
+                                .map(Long::parseLong)
+                                .collect(Collectors.toList());;
+                        buyMatch = userBuyPackageId.stream().anyMatch(packages::contains);
+                    }
+                    if (tagMatch && productMatch && buyMatch) {
+                        addRoleList.add(tagAndProductRole.getId());
+                    }
+                });
+            }
+        }
         //3.更新用户角色信息
         if (CollectionUtils.isNotEmpty(addRoleList)) {
             FsUser map = new FsUser();