Sfoglia il codice sorgente

add
固定推广者连续两天低于7天内平均销售额的一半发送短信给对应商务

zoujiajian 3 anni fa
parent
commit
858d35354c

+ 3 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -88,4 +88,7 @@ public interface Constant {
 	 * chatGPT Plus指定规格限购
 	 */
 	String CHAT_GPT_PLUS_SKU_PURCHASE_LIMIT = "chat_gpt_plus_sku_purchase_limit";
+
+	//发给商务
+	String BUSINESS_CHANNEL_MSG = "你的渠道%s(id%s)分销数据已低于7天平均值的50%%,请尽快与渠道沟通。【银河录像局】";
 }

+ 86 - 0
netflix-service/src/main/java/com/cyksj/task/Scheduler.java

@@ -6,16 +6,21 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.EnvCommonService;
+import com.cyksj.common.constant.Constant;
 import com.cyksj.common.constant.TemplateEnum;
 import com.cyksj.common.util.Jsons;
+import com.cyksj.common.util.SmsUtil;
 import com.cyksj.dto.RedisKey;
 import com.cyksj.mapper.*;
+import com.cyksj.mapper.manage.cms.CmsUserMapper;
 import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
+import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
 import com.cyksj.model.dto.WxMpTemplateData;
 import com.cyksj.model.dto.WxMpTemplateMessage;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.AccountView;
 import com.cyksj.model.views.CmsUserVO;
+import com.cyksj.model.views.UserDistributeViews;
 import com.cyksj.model.views.WxAppTemplateView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.mange.CmsAccountService;
@@ -35,7 +40,10 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 @Component
@@ -85,6 +93,10 @@ public class Scheduler {
 
         private final EnvCommonService envCommonService;
 
+        private final UserDistributeMapper userDistributeMapper;
+
+        private final CmsUserMapper cmsUserMapper;
+
 
     /**
      * 每5分钟清理过期账号
@@ -319,4 +331,78 @@ public class Scheduler {
         }
 
     }
+
+    /**
+     * 推广者渠道昨天订单金额是否小于过去7天平均订单金额的一半
+     * 若小于 则发送短信到对应商务
+     */
+    @Scheduled(cron = "0 30 8 * * ?")
+    public void distributeOrderDetailAndSendMsgToBusiness() {
+	    Integer daysRule = 7;
+	    DateTime thisZero = DateUtil.beginOfDay(DateTime.now());
+
+	    DateTime yesZero = DateUtil.offsetDay(thisZero, -1);
+	    DateTime thePast7dZero = DateUtil.offsetDay(yesZero, -daysRule);
+
+	    DateTime twoYesZero = DateUtil.offsetDay(thisZero, -2);
+	    DateTime theTwoPast7dZero = DateUtil.offsetDay(twoYesZero, -daysRule);
+	    //总销量小于1000的 不算、建立天数低于7天的不算、 连续2天销量低于7天平均值的50%的 提醒
+	    List<UserDistributeViews> userDistributeViews = beanSearcher.searchAll(UserDistributeViews.class, MapUtils.builder()
+			    .field(UserDistributeViews::getCreatedTime, theTwoPast7dZero).op(Operator.LessEqual)
+			    .field(UserDistribute::getBusinessId, 0).op(Operator.GreaterThan)
+			    .put("time", String.format("and od.created_time < '%s'", thisZero))
+			    .field(UserDistributeViews::getDistributeOrdersMoney, BigDecimal.valueOf(100000)).op(Operator.GreaterEqual)
+			    .build());
+	    String thePast7dTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", thePast7dZero, yesZero);
+	    String yesTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", yesZero, thisZero);
+
+	    String theTwoPast7dTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", theTwoPast7dZero, twoYesZero);
+	    String twoYesTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", twoYesZero, yesZero);
+
+	    Map<Long, String> phoneMap = new ConcurrentHashMap<>();
+	    userDistributeViews.forEach(data -> {
+		    //昨天过去7天总订单金额
+		    Number yesPastFtMoneySum = beanSearcher.searchSum(UserDistributeViews.class, MapUtils.builder()
+				    .field(UserDistributeViews::getUserId, data.getUserId())
+				    .put("time", thePast7dTimeSql).build(), "distributeOrdersMoney");
+		    //前天过去7天总订单金额
+		    Number towYesPastMoneySum = beanSearcher.searchSum(UserDistributeViews.class, MapUtils.builder()
+				    .field(UserDistributeViews::getUserId, data.getUserId())
+				    .put("time", theTwoPast7dTimeSql).build(), "distributeOrdersMoney");
+
+		    int theYes7dPastMoney = yesPastFtMoneySum.intValue();
+
+		    int theTwoYes7dPastMoney = towYesPastMoneySum.intValue();
+		    UserDistributeViews yesDistribute = beanSearcher.searchFirst(UserDistributeViews.class, MapUtils.builder()
+				    .field(UserDistributeViews::getUserId, data.getUserId())
+				    .put("time", yesTimeSql).build());
+
+		    UserDistributeViews twoYesDistribute = beanSearcher.searchFirst(UserDistributeViews.class, MapUtils.builder()
+				    .field(UserDistributeViews::getUserId, data.getUserId())
+				    .put("time", twoYesTimeSql).build());
+		    BigDecimal yesDistributeOrdersMoney = yesDistribute.getDistributeOrdersMoney();
+		    BigDecimal twoYesDistributeOrdersMoney = twoYesDistribute.getDistributeOrdersMoney();
+
+		    BigDecimal thePast7dAverage = BigDecimal.valueOf(theYes7dPastMoney).divide(BigDecimal.valueOf(daysRule).multiply(BigDecimal.valueOf(2)), 2, RoundingMode.HALF_DOWN);
+		    BigDecimal theTwoPast7dAverage = BigDecimal.valueOf(theTwoYes7dPastMoney).divide(BigDecimal.valueOf(daysRule).multiply(BigDecimal.valueOf(2)), 2, RoundingMode.HALF_DOWN);
+		    if (yesDistributeOrdersMoney.compareTo(thePast7dAverage) < 0 && twoYesDistributeOrdersMoney.compareTo(theTwoPast7dAverage) < 0) {
+			    User user = userMapper.selectById(data.getUserId());
+			    String msg = String.format(Constant.BUSINESS_CHANNEL_MSG, (user == null ? "用户" : user.getNickname()), data.getUserId());
+			    String phone = phoneMap.get(data.getUserId());
+			    if (StrUtil.isBlank(phone)) {
+				    CmsUser cmsUser = cmsUserMapper.selectById(data.getBusinessId());
+				    if (cmsUser != null) {
+					    phone = cmsUser.getPhone();
+					    phoneMap.putIfAbsent(data.getBusinessId(), phone);
+				    }
+			    }
+			    if (StrUtil.isNotBlank(phone)) {
+				    log.info("商务businessId:{}所下渠道用户id:{}分销数据已低于7天平均值的50%%", data.getBusinessId(), data.getUserId());
+				    //发短信
+				    SmsUtil.send(phone, msg);
+			    }
+			    return;
+		    }
+	    });
+    }
 }