Browse Source

群发功能

Eric 2 years ago
parent
commit
342a3fa9dd

+ 1 - 1
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/CustomerServiceBatchSendingController.java

@@ -172,7 +172,7 @@ public class CustomerServiceBatchSendingController extends BaseController {
 	public HttpResponseResult<Boolean> send(@PathVariable("id") Long id) {
 
 		// 更新群发消息状态
-		//customerServiceBatchSendingService.status(id, sendStatus);
+		customerServiceBatchSendingService.sendMessage(id);
 
 		return HttpResponseResult.succeed(true);
 	}

+ 8 - 2
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/io/request/im/CustomerServiceBatchSendingVo.java

@@ -45,7 +45,10 @@ public class CustomerServiceBatchSendingVo {
                 
 		@ApiModelProperty("发送声部")
         private String sendSubject;
-                
+
+        @ApiModelProperty("发送人数")
+        private Integer sendNumber;
+
 		@ApiModelProperty("接收人数")
         private Integer receiveNumber;
                 
@@ -60,7 +63,10 @@ public class CustomerServiceBatchSendingVo {
                 
 		@ApiModelProperty("发送时间")
         private Date sendTime;
-                
+
+        @ApiModelProperty("消息标题")
+        private String condition;
+
 		@ApiModelProperty("消息标题")
         private String title;
                 

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/CustomerServiceBatchSending.java

@@ -36,6 +36,10 @@ public class CustomerServiceBatchSending implements Serializable {
 	@TableField(value = "send_subject_")
     private String sendSubject;
 
+    @ApiModelProperty("发送人数")
+    @TableField(value = "send_number_")
+    private Integer sendNumber;
+
     @ApiModelProperty("接收人数") 
 	@TableField(value = "receive_number_")
     private Integer receiveNumber;
@@ -56,6 +60,10 @@ public class CustomerServiceBatchSending implements Serializable {
 	@TableField(value = "send_time_")
     private Date sendTime;
 
+    @ApiModelProperty("发送条件")
+    @TableField(value = "condition_")
+    private String condition;
+
     @ApiModelProperty("消息标题") 
 	@TableField(value = "title_")
     private String title;
@@ -72,6 +80,10 @@ public class CustomerServiceBatchSending implements Serializable {
 	@TableField(value = "img_url_")
     private String imgUrl;
 
+    @ApiModelProperty("客户ID")
+    @TableField(value = "sender_id_")
+    private Long senderId;
+
     @ApiModelProperty("创建用户") 
 	@TableField(value = "create_by_")
     private Long createBy;

+ 12 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/CustomerServiceBatchSendingMapper.java

@@ -3,6 +3,7 @@ package com.yonge.cooleshow.biz.dal.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yonge.cooleshow.biz.dal.entity.CustomerServiceBatchSending;
+import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService;
 import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerServiceBatchSendingWrapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -20,6 +21,16 @@ public interface CustomerServiceBatchSendingMapper extends BaseMapper<CustomerSe
 	 * @param param CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery
 	 * @return List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending>
 	 */
-	List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> selectPage(@Param("page") IPage<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> page, @Param("param") CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery param);
+	List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> selectPage(@Param("page") IPage<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> page,
+																					@Param("param") CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery param);
+
+	/**
+	 * 客服消息接收者
+	 * @param message 客服消息
+	 * @return List<CustomerService.MessageReceives>
+	 */
+	List<CustomerService.MessageReceives> selectMessageReceives(@Param("page") IPage<CustomerService.MessageReceives> page,
+																@Param("param") CustomerService.NotifyMessage message);
+
 	
 }

+ 6 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/CustomerServiceBatchSendingService.java

@@ -47,4 +47,10 @@ public interface CustomerServiceBatchSendingService extends IService<CustomerSer
      * @param sendStatus EImSendStatus
      */
     void status(Long id, EImSendStatus sendStatus);
+
+    /**
+     * 发送消息
+     * @param id 群发消息ID
+     */
+    void sendMessage(Long id);
 }

+ 298 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CustomerServiceBatchSendingServiceImpl.java

@@ -3,32 +3,55 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
+import com.yonge.cooleshow.auth.config.CustomerServiceConfig;
+import com.yonge.cooleshow.biz.dal.config.RongCloudConfig;
 import com.yonge.cooleshow.biz.dal.entity.CustomerServiceBatchSending;
 import com.yonge.cooleshow.biz.dal.entity.CustomerServiceReceive;
 import com.yonge.cooleshow.biz.dal.entity.Subject;
+import com.yonge.cooleshow.biz.dal.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
+import com.yonge.cooleshow.biz.dal.enums.im.EImReceiveType;
 import com.yonge.cooleshow.biz.dal.enums.im.EImSendStatus;
+import com.yonge.cooleshow.biz.dal.enums.im.EImSendType;
 import com.yonge.cooleshow.biz.dal.mapper.CustomerServiceBatchSendingMapper;
+import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
 import com.yonge.cooleshow.biz.dal.service.CustomerServiceBatchSendingService;
 import com.yonge.cooleshow.biz.dal.service.CustomerServiceReceiveService;
 import com.yonge.cooleshow.biz.dal.service.SubjectService;
+import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService;
 import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerServiceBatchSendingWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerServiceReceiveWrapper;
 import com.yonge.toolset.base.exception.BizException;
+import com.yonge.toolset.base.util.ImUtil;
+import com.yonge.toolset.base.util.ThreadPool;
+import com.yonge.toolset.mybatis.support.PageUtil;
+import com.yonge.toolset.payment.util.DistributedLock;
+import io.rong.messages.BaseMessage;
+import io.rong.messages.ImgMessage;
+import io.rong.messages.TxtMessage;
+import io.rong.models.message.PrivateMessage;
+import io.rong.models.message.PushExt;
+import io.rong.models.response.ResponseResult;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.text.MessageFormat;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.Random;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /**
  * 客服群发
@@ -42,6 +65,12 @@ public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<Customer
     private CustomerServiceReceiveService customerServiceReceiveService;
     @Autowired
     private SubjectService subjectService;
+    @Autowired
+    private CustomerServiceConfig customerServiceConfig;
+    @Autowired
+    private SysUserMapper sysUserMapper;
+    @Autowired
+    private RedissonClient redissonClient;
 
 	/**
      * 查询详情
@@ -133,9 +162,26 @@ public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<Customer
     @Override
     public Boolean add(CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending info) {
 
+        // 发送客服ID
+        String customerService = customerServiceConfig.getCustomerService();
+        if (StringUtils.isNotEmpty(customerService)) {
+
+            List<String> collect = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
+
+            Random rand = new Random();
+            String mobile = collect.get(rand.nextInt(collect.size()));
+
+            // 查询发送客服ID
+            SysUser senderUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery()
+                    .eq(SysUser::getPhone, mobile));
+            if (Objects.isNull(senderUser)) {
+                throw new BizException("未匹配到客服人员");
+            }
+            info.setSenderId(senderUser.getId());
+        }
+
         // 推送消息
-        CustomerServiceBatchSending sending = JSON.parseObject(info.jsonString(),
-                CustomerServiceBatchSending.class);
+        CustomerServiceBatchSending sending = JSON.parseObject(info.jsonString(), CustomerServiceBatchSending.class);
 
         // 保存推送群发消息
         save(sending);
@@ -149,10 +195,67 @@ public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<Customer
                    CustomerServiceReceive.class));
        }
 
+        // 更新群发消息人数
+        updateBatchSendingSendNumber(sending);
+
+       // 发送推送消息
+        if (EImSendType.IMMEDIATELY == info.getSendType()) {
+            sendMessage(info.getId());
+        }
+
         return true;
     }
 
     /**
+     * 更新群发消息人数
+     * @param info CustomerServiceBatchSending
+     */
+    private void updateBatchSendingSendNumber(CustomerServiceBatchSending info) {
+
+        // 发送条件,接收人数
+        CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery query = CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery
+                .builder()
+                .sendSubject(info.getSendSubject())
+                .targetGroup(info.getTargetGroup())
+                .build();
+        info.setCondition(query.jsonString()); // 发送条件
+
+        // 更新发送人数,接收人数
+        if (EImReceiveType.ALL == info.getReceiveType()) {
+
+            info.setSendNumber(0);
+            List<Integer> receiveNums = Lists.newCopyOnWriteArrayList();
+            // 条件匹配的老师、学生数量
+            query.getClientTypes().parallelStream().forEach(item -> {
+
+                CustomerService.NotifyMessage receiveQuery = CustomerService.NotifyMessage.builder()
+                        .clientType(ClientEnum.valueOf(item))
+                        .subjectIds(Arrays.stream(info.getSendSubject().split(",")).collect(Collectors.toList()))
+                        .build();
+
+                Page<CustomerService.MessageReceives> page = PageUtil.getPage(1, 10);
+                // 统计当前匹配用户数量
+                getBaseMapper().selectMessageReceives(page, receiveQuery);
+
+                receiveNums.add((int) page.getTotal());
+            });
+            info.setSendNumber(receiveNums.stream().mapToInt(Integer::intValue).sum());
+        } else {
+            // 选择的老师、学生数量
+            int sendNumber = customerServiceReceiveService.count(Wrappers.<CustomerServiceReceive>lambdaQuery()
+                    .eq(CustomerServiceReceive::getBatchSendingId, info.getId()));
+            info.setSendNumber(sendNumber);
+        }
+
+        // 更新群发消息人数
+        lambdaUpdate()
+                .eq(CustomerServiceBatchSending::getId, info.getId())
+                .set(CustomerServiceBatchSending::getSendNumber, info.getSendNumber())
+                .set(CustomerServiceBatchSending::getCondition, info.getCondition())
+                .update();
+    }
+
+    /**
      * 更新
      * @param info CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending
      * @return Boolean
@@ -179,6 +282,15 @@ public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<Customer
                     CustomerServiceReceive.class));
         }
 
+        sending = getById(info.getId());
+        // 更新群发消息人数
+        updateBatchSendingSendNumber(sending);
+
+        // 发送推送消息
+        if (EImSendType.IMMEDIATELY == sending.getSendType()) {
+            sendMessage(info.getId());
+        }
+
         return true;
     }
 
@@ -212,4 +324,188 @@ public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<Customer
                 .set(CustomerServiceBatchSending::getSendStatus, sendStatus)
                 .update();
     }
+
+    /**
+     * 发送消息
+     *
+     * @param id 群发消息ID
+     */
+    @Override
+    public void sendMessage(Long id) {
+
+        CustomerServiceBatchSending info = getById(id);
+        if (Objects.isNull(info)) {
+            throw new BizException("无效的群发消息ID");
+        }
+
+        String lockName = MessageFormat.format("batchSending:{0}", String.valueOf(info.getId()));
+        // 消息状态判定,且不能重复发送
+        DistributedLock.of(redissonClient).runIfLockCanGet(lockName, () -> {
+
+            List<BaseMessage> messages = getReceiveMessage(info);
+
+            // 异步发送消息且同步更新已发送人数,稍后可在页面刷新查看已发送用户数
+            ThreadPool.getExecutor().submit(() -> {
+                // 接收消息用户数
+                List<Integer> receiveNums = Lists.newCopyOnWriteArrayList();
+                // 分页数限制
+                int limit = 500;
+
+                try {
+
+                    if (EImReceiveType.ALL == info.getReceiveType()) {
+
+                        // 推送消息给匹配用户
+                        List<String> targetGroupes = Arrays.stream(info.getTargetGroup().split(",")).collect(Collectors.toList());
+
+                        targetGroupes.parallelStream().forEach(clientType -> {
+
+                            CustomerService.NotifyMessage receiveQuery = CustomerService.NotifyMessage.builder()
+                                    .clientType(ClientEnum.valueOf(clientType))
+                                    .subjectIds(Arrays.stream(info.getSendSubject().split(",")).collect(Collectors.toList()))
+                                    .build();
+
+                            Page<CustomerService.MessageReceives> page = PageUtil.getPage(1, 10);
+                            // 统计当前匹配用户数量
+                            getBaseMapper().selectMessageReceives(page, receiveQuery);
+
+                            // 计算总页数
+                            int pages = (int) (page.getTotal() - 1) / limit + 1;
+
+                            List<Integer> collect = IntStream.iterate(1, i -> i + 1).limit(pages).boxed().collect(Collectors.toList());
+
+                            for (Integer pageNum : collect) {
+
+                                List<String> receiveUserIds = getBaseMapper().selectMessageReceives(PageUtil.getPage(pageNum, limit), receiveQuery).stream()
+                                        .map(x -> String.valueOf(x.getUserId()))
+                                        .collect(Collectors.toList());
+
+                                if (ClientEnum.STUDENT.match(clientType)) {
+                                    receiveUserIds = receiveUserIds.stream()
+                                            .map(x -> MessageFormat.format("{0}:STUDENT", x))
+                                            .collect(Collectors.toList());
+                                }
+
+                                batchSendCustomerServiceMessage(info, messages, receiveNums, receiveUserIds);
+                            }
+                        });
+
+                    } else {
+
+                        // 查询条件
+                        CustomerServiceReceiveWrapper.CustomerServiceReceiveQuery receiveQuery = CustomerServiceReceiveWrapper.CustomerServiceReceiveQuery
+                                .builder().build();
+
+                        Page<CustomerServiceReceive> page = PageUtil.getPage(1, 10);
+                        // 推送消息给指定用户
+                        customerServiceReceiveService.selectPage(page, receiveQuery);
+
+                        // 计算总页数
+                        int pages = (int) (page.getTotal() - 1) / limit + 1;
+
+                        List<Integer> collect = IntStream.iterate(1, i -> i + 1).limit(pages).boxed().collect(Collectors.toList());
+
+                        for (Integer pageNum : collect) {
+
+                            List<String> receiveUserIds = customerServiceReceiveService.selectPage(PageUtil.getPage(pageNum, limit), receiveQuery).getRecords().stream()
+                                    .map(x -> {
+                                        if (ClientEnum.STUDENT.match(x.getClientType())) {
+                                            return MessageFormat.format("{0}:STUDENT", String.valueOf(x.getUserId()));
+                                        }
+                                        return String.valueOf(x.getUserId());
+                                    })
+                                    .collect(Collectors.toList());
+
+                            batchSendCustomerServiceMessage(info, messages, receiveNums, receiveUserIds);
+                        }
+                    }
+
+                    // 更新消息状态为已发送
+                    lambdaUpdate()
+                            .eq(CustomerServiceBatchSending::getId, info.getId())
+                            .set(CustomerServiceBatchSending::getSendStatus, EImSendStatus.SEND)
+                            .set(CustomerServiceBatchSending::getReceiveNumber, receiveNums.stream().mapToInt(Integer::intValue).sum())
+                            .update();
+
+                } catch (Exception e) {
+                    log.error("sendMessage id={}", id, e);
+                }
+
+            });
+
+        });
+
+    }
+
+    /**
+     * 批量发送客服消息
+     * @param info CustomerServiceBatchSending
+     * @param messages 推送消息类型
+     * @param receiveNums 接收消息用户数
+     * @param receiveUserIds 接收消息用户Id
+     */
+    private static void batchSendCustomerServiceMessage(CustomerServiceBatchSending info, List<BaseMessage> messages,
+                                                        List<Integer> receiveNums, List<String> receiveUserIds) {
+        // 拓展消息
+        PushExt pushExt = PushExt.build(info.getTitle(), 1,
+                new PushExt.HW("channelId", "NORMAL"), new PushExt.VIVO("1"),
+                new PushExt.APNs("", ""),
+                new PushExt.OPPO(""));
+
+        String senderId = String.valueOf(info.getSenderId());
+        PrivateMessage privateMessage;
+        ResponseResult privateResult;
+        for (List<String> item : Lists.partition(receiveUserIds, 100)) {
+
+            try {
+
+                for (BaseMessage message : messages) {
+
+                    // 发送用户IM通知消息
+                    privateMessage = new PrivateMessage()
+                            .setSenderId(senderId)
+                            .setTargetId(item.toArray(new String[0]))
+                            .setObjectName(message.getType())
+                            .setContent(message)
+                            .setPushExt(pushExt)
+                            .setIsIncludeSender(0);
+
+                    privateResult = RongCloudConfig.rongCloud.message.msgPrivate.send(privateMessage);
+                    log.info("batchSendCustomerServiceMessage senderId={}, ret={}", senderId, privateResult.getCode());
+                }
+
+                receiveNums.add(item.size());
+            } catch (Exception e) {
+                log.error("batchSendCustomerServiceMessage senderId={}", senderId, e);
+            }
+
+        }
+    }
+
+    /**
+     * 推送消息类型
+     * @param info CustomerServiceBatchSending
+     * @return List<BaseMessage>
+     */
+    private static List<BaseMessage> getReceiveMessage(CustomerServiceBatchSending info) {
+        List<BaseMessage> messages = Lists.newArrayList();
+
+        if (StringUtils.isNotEmpty(info.getImgMessage())) {
+
+            // 发送图片消息
+            ImgMessage imgMessage = new ImgMessage(ImUtil.imageToBase64(info.getImgMessage(), "png"), "", info.getImgUrl());
+
+            messages.add(imgMessage);
+        }
+
+        if (StringUtils.isNotEmpty(info.getTextMessage())) {
+
+            // 发送文本消息
+            TxtMessage txtMessage = new TxtMessage(info.getTextMessage(), "");
+
+            messages.add(txtMessage);
+        }
+        return messages;
+    }
+
 }

+ 2 - 31
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImUserFriendServiceImpl.java

@@ -21,6 +21,7 @@ import com.yonge.cooleshow.biz.dal.service.ImUserFriendService;
 import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService;
 import com.yonge.cooleshow.biz.dal.wrapper.im.ImUserWrapper;
 import com.yonge.toolset.base.exception.BizException;
+import com.yonge.toolset.base.util.ImUtil;
 import io.rong.messages.BaseMessage;
 import io.rong.messages.ImgMessage;
 import io.rong.messages.TxtMessage;
@@ -28,8 +29,6 @@ import io.rong.models.message.PrivateMessage;
 import io.rong.models.message.PushExt;
 import io.rong.models.response.ResponseResult;
 import lombok.extern.slf4j.Slf4j;
-import net.coobird.thumbnailator.Thumbnails;
-import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,11 +36,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.URL;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -299,7 +293,7 @@ public class ImUserFriendServiceImpl extends ServiceImpl<ImUserFriendDao, ImUser
         }
 
         // 发送图片消息
-        ImgMessage imgMessage = new ImgMessage(imageToBase64(info.getImgMessage(), "png"), "", info.getImgUrl());
+        ImgMessage imgMessage = new ImgMessage(ImUtil.imageToBase64(info.getImgMessage(), "png"), "", info.getImgUrl());
 
         // 发送文本消息
         TxtMessage txtMessage = new TxtMessage(info.getTxtMessage(), "");
@@ -342,30 +336,7 @@ public class ImUserFriendServiceImpl extends ServiceImpl<ImUserFriendDao, ImUser
 
     }
 
-    public static String imageToBase64(String imgMessage, String suffix) {
 
-        Base64 encoder = new Base64();
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        try {
-            URL url = new URL(imgMessage);
-            BufferedImage bufferedImage = Thumbnails.of(url).scale(0.1f).outputQuality(0.25f).asBufferedImage();
-            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-            ImageIO.write(bufferedImage, suffix, outputStream);
-
-            byte[] bytes = outputStream.toByteArray();
-            outputStream.close();
-            int length = bytes.length;
-            //文件大小不能超过393216 Bytes
-            if (length > 393216) {
-                throw new BizException("文件过大请调整 像素 或 文件大小");
-            }
-
-            ImageIO.write(bufferedImage, suffix, baos);
-        } catch (IOException e) {
-            log.error("imageToBase64", e);
-        }
-        return new String(encoder.encode((baos.toByteArray())));
-    }
 
     /**
      * 用户IM好友列表

+ 1 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/im/CustomerService.java

@@ -29,6 +29,7 @@ public class CustomerService {
         private List<String> receives;
         private ClientEnum clientType;
         private String subjectId;
+        private List<String> subjectIds;
 
         private String title;
         private String txtMessage;

+ 9 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/im/CustomerServiceBatchSendingWrapper.java

@@ -103,6 +103,9 @@ public class CustomerServiceBatchSendingWrapper {
         @ApiModelProperty("发送声部")
         private String sendSubject;
 
+        @ApiModelProperty("发送人数")
+        private Integer sendNumber;
+
         @ApiModelProperty("接收人数")
         private Integer receiveNumber;
 
@@ -119,6 +122,9 @@ public class CustomerServiceBatchSendingWrapper {
         private Date sendTime;
 
         @ApiModelProperty("消息标题")
+        private String condition;
+
+        @ApiModelProperty("消息标题")
         private String title;
 
         @ApiModelProperty("文本消息")
@@ -130,6 +136,9 @@ public class CustomerServiceBatchSendingWrapper {
         @ApiModelProperty("图片地址")
         private String imgUrl;
 
+        @ApiModelProperty("客户ID")
+        private Long senderId;
+
         @ApiModelProperty("创建用户")
         private Long createBy;
 

+ 20 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/CustomerServiceBatchSendingMapper.xml

@@ -9,15 +9,18 @@
          t.id_ AS id
         , t.target_group_ AS targetGroup
         , t.send_subject_ AS sendSubject
+        , t.send_number_ AS sendNumber
         , t.receive_number_ AS receiveNumber
         , t.receive_type_ AS receiveType
         , t.send_type_ AS sendType
         , t.send_status_ AS sendStatus
         , t.send_time_ AS sendTime
+        , t.condition_ AS `condition`
         , t.title_ AS title
         , t.text_message_ AS textMessage
         , t.img_message_ AS imgMessage
         , t.img_url_ AS imgUrl
+        , t.sender_id_ AS senderId
         , t.create_by_ AS createBy
         , t.create_time_ AS createTime
     </sql>
@@ -28,5 +31,21 @@
 		FROM customer_service_batch_sending t
         ORDER BY t.id_ DESC
 	</select>
-    
+
+    <!--客服消息接收者-->
+    <select id="selectMessageReceives"
+            resultType="com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService$MessageReceives">
+        SELECT t1.id_ AS userId, t1.username_ FROM sys_user t1
+        <if test="param.clientType != null">
+            <if test="param.clientType.code == 'TEACHER'"> LEFT JOIN teacher t2 ON (t1.id_ = t2.user_id_)</if>
+            <if test="param.clientType.code == 'STUDENT'"> LEFT JOIN student t2 ON (t1.id_ = t2.user_id_)</if>
+        </if>
+        <where>
+            <if test="param.subjectId != null">
+                AND FIND_IN_SET(#{param.subjectId}, t2.subject_id_)
+            </if>
+        </where>
+    </select>
+    <!--客服消息接收者-->
+
 </mapper>

+ 12 - 0
toolset/toolset-base/pom.xml

@@ -20,5 +20,17 @@
     </properties>
 
     <dependencies>
+
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>net.coobird</groupId>
+            <artifactId>thumbnailator</artifactId>
+            <version>0.4.11</version>
+        </dependency>
+
     </dependencies>
 </project>

+ 44 - 0
toolset/toolset-base/src/main/java/com/yonge/toolset/base/util/ImUtil.java

@@ -0,0 +1,44 @@
+package com.yonge.toolset.base.util;
+
+import com.yonge.toolset.base.exception.BizException;
+import lombok.extern.slf4j.Slf4j;
+import net.coobird.thumbnailator.Thumbnails;
+import org.apache.commons.codec.binary.Base64;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Created by Eric.Shang on 2022/12/12.
+ */
+@Slf4j
+public class ImUtil {
+
+    public static String imageToBase64(String imgMessage, String suffix) {
+
+        Base64 encoder = new Base64();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            URL url = new URL(imgMessage);
+            BufferedImage bufferedImage = Thumbnails.of(url).scale(0.1f).outputQuality(0.25f).asBufferedImage();
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            ImageIO.write(bufferedImage, suffix, outputStream);
+
+            byte[] bytes = outputStream.toByteArray();
+            outputStream.close();
+            int length = bytes.length;
+            //文件大小不能超过393216 Bytes
+            if (length > 393216) {
+                throw new BizException("文件过大请调整 像素 或 文件大小");
+            }
+
+            ImageIO.write(bufferedImage, suffix, baos);
+        } catch (IOException e) {
+            log.error("imageToBase64", e);
+        }
+        return new String(encoder.encode((baos.toByteArray())));
+    }
+}