Procházet zdrojové kódy

fix 配置车队账号发送短信

zoujiajian před 3 roky
rodič
revize
46d3516435

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationMapper.java

@@ -30,4 +30,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	List<GroupsRelationView> selectRelationByGoodsId(@Param("goodsId") Long goodsId, @Param("userId") Long userId);
 
 	GroupsRelationView getGroupRelationViewByUserIdAndRelationId(@Param("userId") Long userId, @Param("relationId") Long relationId);
+
+	String getBindPhoneByUserId(Long userId);
 }

+ 5 - 0
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -79,4 +79,9 @@
                  left join goods_don g on g.id = a.goods_id
         where gr.id = #{relationId} and gr.user_id = #{userId}
     </select>
+
+    <select id="getBindPhoneByUserId" resultType="java.lang.String">
+        select if(login_phone = '',ud.phone,login_phone) as phone from (select id,login_phone from user where id = #{userId} limit 1) u left join user_bind_detail ud
+        on ud.user_id = u.id
+    </select>
 </mapper>

+ 15 - 24
netflix-service/src/main/java/com/cyksj/service/mange/group/CmsGroupServiceImpl.java

@@ -8,15 +8,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
-import com.cyksj.common.util.SmsUtil;
 import com.cyksj.mapper.*;
 import com.cyksj.mapper.manage.GroupsTripsAccountReplaceRecordMapper;
 import com.cyksj.mapper.manage.cms.CmsUserMapper;
-import com.cyksj.mapper.market.task.UserBindDetailMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.ReplaceTripsAccountReq;
 import com.cyksj.model.views.GroupsAccountView;
 import com.cyksj.service.mange.CmsGroupService;
+import com.cyksj.service.sms.SmsService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
@@ -53,9 +52,7 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
 
     private final GoodsDonMapper goodsDonMapper;
 
-    private UserBindDetailMapper userBindDetailMapper;
-
-    private final UserMapper userMapper;
+    private final SmsService smsService;
 
     private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
@@ -109,6 +106,12 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
             throw new BusinessRuntimeException("该账号已发车.请选择未发车账户");
         }
         List<GroupsRelation> groupsRelations = relationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsTrips.getId()).eq(GroupsRelation::getStatus, GroupsRelation.Status.validity));
+        GroupsTrips trips = beanSearcher.searchFirst(GroupsTrips.class, MapUtils.builder().field(GroupsTrips::getId, groupsTrips.getId()).onlySelect(GroupsTrips::getTitle).build());
+        String title = "车票";
+        if (trips != null && StrUtil.isNotBlank(trips.getTitle())) {
+            title = trips.getTitle();
+        }
+        String msg = String.format(Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
        groupsRelations.forEach((relation)->{
            if (relation.getExpiryTime() == null) {
                List<OrderDon> orderDonList = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, relation.getUserId()).eq(OrderDon::getRelationId, relation.getId()).eq(OrderDon::getStatus, OrderDon.Status.hasPayment));
@@ -127,6 +130,8 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
                    orderDonMapper.updateById(orderDon);
                });
            }
+           //发送短信
+           smsService.sendSmsToRelationUser(relation.getUserId(), msg);
        });
        groupsTrips.setStatus(GroupsTrips.Status.validity);
        updateById(groupsTrips);
@@ -201,27 +206,13 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
         TASK_EXECUTOR.execute(() -> sendChangeAccountMsg(groupsId, goodsId));;
     }
 
-    private void sendChangeAccountMsg(Long groupsId,Long goodsId) {
+    private void sendChangeAccountMsg(Long groupsId, Long goodsId) {
         GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
         List<GroupsRelation> groupsRelations = beanSearcher.searchAll(GroupsRelation.class, MapUtils.builder().field(GroupsRelation::getGroupsId, groupsId).build());
-        groupsRelations.forEach(relation->{
-            Long userId = relation.getUserId();
-            User user = userMapper.selectById(userId);
-            String phone = null;
-            if (user != null) {
-                phone = user.getLoginPhone();
-                if (StrUtil.isEmpty(phone)) {
-                    UserBindDetail userBindDetail = userBindDetailMapper.selectById(userId);
-                    if (userBindDetail != null) {
-                        phone = userBindDetail.getPhone();
-                    }
-                }
-            }
-            if (StrUtil.isNotBlank(phone)) {
-                String title = goodsDon != null ? goodsDon.getTitle() : "车票";
-                SmsUtil.sendLuoKey2Msg(phone, String.format(Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title));
-            }
-
+        groupsRelations.forEach(relation -> {
+            String title = goodsDon != null ? goodsDon.getTitle() : "车票";
+            String msg = String.format(Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
+            smsService.sendSmsToRelationUser(relation.getUserId(), msg);
         });
     }
 }

+ 15 - 0
netflix-service/src/main/java/com/cyksj/service/sms/SmsService.java

@@ -0,0 +1,15 @@
+package com.cyksj.service.sms;
+
+/*
+ *项目名: netflix
+ *文件名: SmsService
+ *创建者: JavaZou
+ *创建时间:2023/5/9 9:57
+ */
+public interface SmsService {
+
+	/**
+	 * 发送车队短信通知 车位用户
+	 */
+	void sendSmsToRelationUser(Long userId, String msg);
+}

+ 30 - 0
netflix-service/src/main/java/com/cyksj/service/sms/impl/SmsServiceImpl.java

@@ -0,0 +1,30 @@
+package com.cyksj.service.sms.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.cyksj.common.util.SmsUtil;
+import com.cyksj.mapper.GroupsRelationMapper;
+import com.cyksj.service.sms.SmsService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/*
+ *项目名: netflix
+ *文件名: SmsServiceImpl
+ *创建者: JavaZou
+ *创建时间:2023/5/9 9:58
+ */
+@RequiredArgsConstructor
+@Service
+@Slf4j
+public class SmsServiceImpl implements SmsService {
+	private final GroupsRelationMapper groupsRelationMapper;
+
+	@Override
+	public void sendSmsToRelationUser(Long userId, String msg) {
+		String phone = groupsRelationMapper.getBindPhoneByUserId(userId);
+		if (StrUtil.isNotBlank(phone)) {
+			SmsUtil.sendLuoKey2Msg(phone, msg);
+		}
+	}
+}