|
@@ -0,0 +1,183 @@
|
|
|
+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.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+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.enums.ClientEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.CustomerServiceBatchSendingMapper;
|
|
|
+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.CustomerServiceBatchSendingWrapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerServiceReceiveWrapper;
|
|
|
+import com.yonge.toolset.base.exception.BizException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 客服群发
|
|
|
+ * 2022-12-09 10:49:10
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<CustomerServiceBatchSendingMapper, CustomerServiceBatchSending> implements CustomerServiceBatchSendingService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomerServiceReceiveService customerServiceReceiveService;
|
|
|
+ @Autowired
|
|
|
+ private SubjectService subjectService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询详情
|
|
|
+ * @param id 详情ID
|
|
|
+ * @return CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending detail(Long id) {
|
|
|
+
|
|
|
+ CustomerServiceBatchSending sending = baseMapper.selectById(id);
|
|
|
+ if (Objects.isNull(sending)) {
|
|
|
+ throw new BizException("无效的请求ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending record = CustomerServiceBatchSendingWrapper
|
|
|
+ .CustomerServiceBatchSending.from(JSON.toJSONString(sending));
|
|
|
+
|
|
|
+ // 填充声部,目标群体
|
|
|
+ List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> records = Lists.newArrayList(record);
|
|
|
+
|
|
|
+ // 返回消息封闭
|
|
|
+ getBatchSendingPaddingData(records);
|
|
|
+
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ * @param page IPage<CustomerServiceBatchSending>
|
|
|
+ * @param query CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery
|
|
|
+ * @return IPage<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> selectPage(IPage<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> page,
|
|
|
+ CustomerServiceBatchSendingWrapper.CustomerServiceBatchSendingQuery query){
|
|
|
+
|
|
|
+ // 群发消息记录
|
|
|
+ List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> sendings = baseMapper.selectPage(page, query);
|
|
|
+
|
|
|
+ // 返回消息封闭
|
|
|
+ getBatchSendingPaddingData(sendings);
|
|
|
+
|
|
|
+ return page.setRecords(sendings);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 群发消息返回封装
|
|
|
+ * @param sendings List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending>
|
|
|
+ */
|
|
|
+ private void getBatchSendingPaddingData(List<CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending> sendings) {
|
|
|
+
|
|
|
+ // 声部信息
|
|
|
+ List<Long> subjectIds = sendings.stream()
|
|
|
+ .flatMap(x -> Arrays.stream(x.getSendSubject().split(",")))
|
|
|
+ .map(Long::parseLong).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, String> subjectNameMap = subjectService.findBySubjectByIdList(subjectIds).stream()
|
|
|
+ .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
|
|
|
+
|
|
|
+ // 发送群体,发送声部
|
|
|
+ for (CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending item : sendings) {
|
|
|
+
|
|
|
+ List<Long> collect = Arrays.stream(Optional.ofNullable(item.getSendSubject()).orElse("").split(","))
|
|
|
+ .map(Long::parseLong).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 发送声部
|
|
|
+ String subjectName = subjectNameMap.entrySet().stream()
|
|
|
+ .filter(x -> collect.contains(x.getKey()))
|
|
|
+ .map(Map.Entry::getValue).collect(Collectors.joining(","));
|
|
|
+ item.setSubjectName(subjectName);
|
|
|
+
|
|
|
+ // 发送群体
|
|
|
+ List<String> clientTypes = Arrays.stream(Optional.ofNullable(item.getTargetGroup()).orElse("").split(","))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ String targetGroup = Arrays.stream(ClientEnum.values())
|
|
|
+ .filter(x -> clientTypes.contains(x.getCode())).map(ClientEnum::getMsg)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ item.setTargetGroupName(targetGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @param info CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Boolean add(CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending info) {
|
|
|
+
|
|
|
+ // 推送消息
|
|
|
+ CustomerServiceBatchSending sending = JSON.parseObject(info.jsonString(),
|
|
|
+ CustomerServiceBatchSending.class);
|
|
|
+
|
|
|
+ // 保存推送群发消息
|
|
|
+ save(sending);
|
|
|
+
|
|
|
+ // 部分推送用户
|
|
|
+ if (CollectionUtils.isNotEmpty(info.getReceives())) {
|
|
|
+ for (CustomerServiceReceiveWrapper.CustomerServiceReceive item : info.getReceives()) {
|
|
|
+ item.setBatchSendingId(sending.getId());
|
|
|
+ }
|
|
|
+ customerServiceReceiveService.saveBatch(JSON.parseArray(JSON.toJSONString(info.getReceives()),
|
|
|
+ CustomerServiceReceive.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ * @param info CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Boolean update(CustomerServiceBatchSendingWrapper.CustomerServiceBatchSending info){
|
|
|
+
|
|
|
+ CustomerServiceBatchSending sending = JSON.parseObject(info.jsonString(),
|
|
|
+ CustomerServiceBatchSending.class);
|
|
|
+ // 更新群发消息
|
|
|
+ this.updateById(sending);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(info.getReceives())) {
|
|
|
+
|
|
|
+ // 先清除数据,后重新插入
|
|
|
+ customerServiceReceiveService.remove(Wrappers.<CustomerServiceReceive>lambdaQuery()
|
|
|
+ .eq(CustomerServiceReceive::getBatchSendingId, sending.getId()));
|
|
|
+
|
|
|
+ for (CustomerServiceReceiveWrapper.CustomerServiceReceive item : info.getReceives()) {
|
|
|
+ item.setBatchSendingId(sending.getId());
|
|
|
+ }
|
|
|
+ customerServiceReceiveService.saveBatch(JSON.parseArray(JSON.toJSONString(info.getReceives()),
|
|
|
+ CustomerServiceReceive.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|