提交 ef3aed86 作者: 沈振路

根据人群包名称批量查询人群包列表接口 & 批量设置客服消息人群包接口

上级 9cfb24a9
......@@ -95,4 +95,10 @@ public class CrowdPackageController {
return crowdPackageService.updateUserPackageBatch(openIdList);
}
@ApiOperation("根据人群包名称列表完全匹配查询")
@PostMapping("/getByPackageNames")
public GenericsResult<List<CrowdPackageListVO>> getByPackageNames(@RequestBody List<String> packageNames) {
return crowdPackageService.getByPackageNames(packageNames);
}
}
......@@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo;
import com.yaoyaozw.customer.annotations.OperateLog;
import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.dto.customer.CustomerBatchSetPackDTO;
import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO;
import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO;
import com.yaoyaozw.customer.service.CustomerGraphicsService;
......@@ -63,4 +64,14 @@ public class CustomerMessageGraphicsController {
return customerGraphicsService.setPack(id, packId);
}
@ApiOperation("批量设置人群包")
@PostMapping("/batchSetPack")
@OperateLog(module = "客服消息", desc = "批量设置人群包")
public BaseResult batchSetPack(@RequestBody List<CustomerBatchSetPackDTO> batchSetPackList) {
// 调用异步方法
customerGraphicsService.batchSetPack(batchSetPackList);
// 立即返回成功信息
return new BaseResult().success("批量生成中,请稍后查看");
}
}
package com.yaoyaozw.customer.dto.customer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 批量设置人群包DTO
* @author system
* @date 2024/01/01
*/
@Data
public class CustomerBatchSetPackDTO implements Serializable {
@ApiModelProperty("客服消息ID")
@JsonSerialize(using = ToStringSerializer.class)
private Long customerMessageId;
@ApiModelProperty("人群包ID")
@JsonSerialize(using = ToStringSerializer.class)
private Long packId;
@ApiModelProperty("人群包名称")
private String packName;
@ApiModelProperty("操作人ID")
@JsonSerialize(using = ToStringSerializer.class)
private Long operateUserId;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -51,4 +51,12 @@ public interface MaterialCrowdPackageMapper extends BaseMapper<CrowdPackage> {
* @param crowdPackage 人群中包
*/
void updatePackageFollowTime(@Param("crowdPackage") CrowdPackage crowdPackage);
/**
* 根据人群包名称列表完全匹配查询
*
* @param packageNames 人群包名称列表
* @return {@link List}<{@link CrowdPackageListVO}>
*/
List<CrowdPackageListVO> getByPackageNames(@Param("packageNames") List<String> packageNames);
}
......@@ -108,4 +108,12 @@ public interface CrowdPackageService extends IService<CrowdPackage> {
*/
void updateCrowdPackageNumFromRedis();
/**
* 根据人群包名称列表完全匹配查询
*
* @param packageNames 人群包名称列表
* @return {@link GenericsResult}<{@link List}<{@link CrowdPackageListVO}>>
*/
GenericsResult<List<CrowdPackageListVO>> getByPackageNames(List<String> packageNames);
}
......@@ -66,6 +66,13 @@ public interface CustomerGraphicsService extends IService<CustomerGraphics> {
*/
BaseResult setPack(Long id, Long packId);
/**
* 批量设置人群包
*
* @param batchSetPackList 批量设置参数列表
* @return {@link BaseResult}
*/
void batchSetPack(List<com.yaoyaozw.customer.dto.customer.CustomerBatchSetPackDTO> batchSetPackList);
/**
* 客服发送
......
......@@ -469,6 +469,16 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
}
@Override
public GenericsResult<List<CrowdPackageListVO>> getByPackageNames(List<String> packageNames) {
if (CollectionUtil.isEmpty(packageNames)) {
return new GenericsResult<>(true, "人群包名称列表为空");
}
List<CrowdPackageListVO> list = baseMapper.getByPackageNames(packageNames);
if (CollectionUtil.isEmpty(list)) {
return new GenericsResult<>(true, "暂无数据");
}
return new GenericsResult<>(list);
}
}
......@@ -3,6 +3,8 @@ package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -13,6 +15,7 @@ import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerBatchSetPackDTO;
import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO;
import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
......@@ -30,9 +33,11 @@ import com.yaoyaozw.customer.vo.referral.ReferralEntityVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.List;
......@@ -211,6 +216,65 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
return new BaseResult().error("更新失败");
}
@Override
@Async("myExecutor")
public void batchSetPack(List<CustomerBatchSetPackDTO> batchSetPackList) {
if (CollectionUtil.isEmpty(batchSetPackList)) {
LOCAL_LOG.error("批量设置参数不能为空");
return;
}
LOCAL_LOG.info("开始批量设置人群包,总数量: {}", batchSetPackList.size());
// 收集所有客服消息ID
List<Long> customerMessageIds = batchSetPackList.stream()
.map(CustomerBatchSetPackDTO::getCustomerMessageId)
.collect(Collectors.toList());
// 先将所有相关客服消息状态设置为批量生成中(状态值:11)
CustomerGraphics updateEntity = new CustomerGraphics();
updateEntity.setSendStatus(11);
this.update(updateEntity, new UpdateWrapper<CustomerGraphics>().in("id", customerMessageIds));
LOCAL_LOG.info("已将 {} 条客服消息状态设置为批量生成中", customerMessageIds.size());
// 收集执行完成的客服消息ID
List<Long> finishedIdList = new ArrayList<>();
try {
// 遍历执行setPack方法
for (CustomerBatchSetPackDTO dto : batchSetPackList) {
try {
LOCAL_LOG.info("正在处理客服消息ID: {}, 人群包ID: {}", dto.getCustomerMessageId(), dto.getPackId());
BaseResult result = setPack(dto.getCustomerMessageId(), dto.getPackId());
if (result.getSuccess()) {
LOCAL_LOG.info("客服消息ID: {} 设置人群包成功", dto.getCustomerMessageId());
} else {
LOCAL_LOG.error("客服消息ID: {} 设置人群包失败: {}", dto.getCustomerMessageId(), result.getMessage());
}
finishedIdList.add(dto.getCustomerMessageId());
TimeUnit.SECONDS.sleep(30);
} catch (Exception e) {
LOCAL_LOG.error("客服消息ID: {} 设置人群包异常", dto.getCustomerMessageId(), e);
}
}
} catch (Exception e) {
LOCAL_LOG.error("批量设置人群包整体异常", e);
// 计算未执行成功的客服消息ID
List<Long> failedIdList = customerMessageIds.stream()
.filter(id -> !finishedIdList.contains(id))
.collect(Collectors.toList());
if (!failedIdList.isEmpty()) {
// 将未执行成功的客服消息状态设置为3(链接生成异常)
updateEntity.setSendStatus(3);
this.update(updateEntity, new UpdateWrapper<CustomerGraphics>().in("id", failedIdList));
LOCAL_LOG.info("已将 {} 条客服消息状态设置为链接生成异常", failedIdList.size());
}
}
LOCAL_LOG.info("批量设置人群包完成,成功数量: {}, 总数量: {}", finishedIdList.size(), batchSetPackList.size());
}
/**
* 发送客服消息
* @param integrationRequestDTO 请求DTO
......
......@@ -54,4 +54,32 @@
follow_date_end = #{crowdPackage.followDateEnd}
where id = #{crowdPackage.id}
</update>
<select id="getByPackageNames" resultType="com.yaoyaozw.customer.vo.crowd.CrowdPackageListVO">
select
cpm.id, cpm.package_name as packageName,
ifnull(cpm.crowd_num, 0) as numOfCrowdInPackage,
cpm.last_count_time as lastCountTime,
cpm.create_time as createTime, cpm.modified_time as modifiedTime,
cau.nick_name as createUser, mau.nick_name as modifiedUser,
group_concat(concat('【', mat.operator_description, '】')) as packageLabel
from crowd_package_main cpm
left join acl_user cau
on cpm.create_user = cau.id
left join acl_user mau
on cpm.modified_user = mau.id
left join crowd_package_condition_match mat
on cpm.id = mat.package_id
where cpm.package_name is not null
and cpm.package_name in
<foreach collection="packageNames" item="packageName" open="(" separator="," close=")">
#{packageName}
</foreach>
group by cpm.id
order by cpm.create_time desc
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论