提交 30b95fe1 作者: 沈振路

客服-文本

上级 4e5006e1
......@@ -135,7 +135,36 @@ public class CustomerServiceCommonAsyncComponent {
}
@Async("myExecutor")
public void getAuthListLink(CustomerGraphics customerMain, ReferralEntity customerReferral) {
public void obtainLink(Long materialId, CustomerGraphics customerGraphics, List<ReferralEntity> referralEntityList) {
for (ReferralEntity referralEntity : referralEntityList) {
// 删除之前设置人群包的时候获取链接生成的数据
referralEntityService.ultimateDeleteReferrals(materialId, "and account_id is not null");
// 获取链接
if (CustomerCommonConstant.REPLACE_LINK_NEWS_TYPE_LIST.contains(referralEntity.getNewsType())) {
LOCAL_LOG.info("异步获取图文客服链接");
getAuthListLink(customerGraphics, referralEntity);
} else {
LOCAL_LOG.info("newsType: {}, 不需要获取链接", referralEntity.getNewsType());
}
}
// 处理完之后将状态改为待发送
customerGraphics.setSendStatus(2);
customerGraphicsMapper.updateById(customerGraphics);
}
private List<RegisterUserEntity> encapsulateUserEntity(List<CrowdPackageUserVO> userList) {
List<RegisterUserEntity> userEntityList = new ArrayList<>();
for (CrowdPackageUserVO crowdPackageUserVO : userList) {
RegisterUserEntity registerUserEntity = new RegisterUserEntity();
registerUserEntity.setId(crowdPackageUserVO.getId());
registerUserEntity.setInPackage(crowdPackageUserVO.getInPackage());
userEntityList.add(registerUserEntity);
}
return userEntityList;
}
private void getAuthListLink(CustomerGraphics customerMain, ReferralEntity customerReferral) {
Long packId = customerMain.getPackId();
LOCAL_LOG.info("开始异步处理客服链接, 客服标题: {}, 人群包主键: {}", customerMain.getName(), packId);
......@@ -158,21 +187,6 @@ public class CustomerServiceCommonAsyncComponent {
generateUsualLink(storeGroupMap, customerReferral);
}
// 处理完之后将状态改为待发送
customerMain.setSendStatus(2);
customerGraphicsMapper.updateById(customerMain);
}
private List<RegisterUserEntity> encapsulateUserEntity(List<CrowdPackageUserVO> userList) {
List<RegisterUserEntity> userEntityList = new ArrayList<>();
for (CrowdPackageUserVO crowdPackageUserVO : userList) {
RegisterUserEntity registerUserEntity = new RegisterUserEntity();
registerUserEntity.setId(crowdPackageUserVO.getId());
registerUserEntity.setInPackage(crowdPackageUserVO.getInPackage());
userEntityList.add(registerUserEntity);
}
return userEntityList;
}
private void generateExtendLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
......@@ -266,6 +280,7 @@ public class CustomerServiceCommonAsyncComponent {
getCopyReferral(dateStr, authInfoVo, referralEntity);
} catch (Exception e) {
LOCAL_LOG.warn("公众号: {} 获取链接异常: {}", authInfoVo.getAccountName(), e.getMessage());
referralEntity.setReferral("error");
}
referralEntityList.add(referralEntity);
......@@ -352,4 +367,5 @@ public class CustomerServiceCommonAsyncComponent {
}
}
package com.yaoyaozw.customer.configs;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.yaoyaozw.customer.components.TokenManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @author 10626
*/
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
@Autowired
private TokenManager tokenManager;
@Override
public void insertFill(MetaObject metaObject) {
Long userId = tokenManager.getUserIdFromToken();
if (ObjectUtil.isNull(userId)){
this.setFieldValByName("gmtModifiedUser", "0", metaObject);
this.setFieldValByName("gmtCreateUser", "0", metaObject);
}else {
String userIdStr = userId.toString();
this.setFieldValByName("gmtModifiedUser", userIdStr, metaObject);
this.setFieldValByName("gmtCreateUser", userIdStr, metaObject);
}
this.setFieldValByName("gmtCreate", new Date(), metaObject);
this.setFieldValByName("gmtModified", new Date(), metaObject);
this.setFieldValByName("isDeleted", 0, metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("gmtModified",new Date(),metaObject);
Long userId = tokenManager.getUserIdFromToken();
if (ObjectUtil.isNull(userId)){
this.setFieldValByName("gmtModifiedUser", "0", metaObject);
}else {
this.setFieldValByName("gmtModifiedUser", userId.toString(), metaObject);
}
}
}
......@@ -2,6 +2,10 @@ package com.yaoyaozw.customer.constants;
import cn.hutool.core.util.ObjectUtil;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author darker
* @date 2022/9/28 20:09
......@@ -14,6 +18,14 @@ public class CustomerCommonConstant {
public final static String STORE_NAME_ZHANG_ZHONG_YUN = "ZHANG_ZHONG_YUN";
public final static String STORE_NAME_YUE_WEN = "YUE_WEN";
public final static String ERROR_LABEL = "error";
public final static List<Integer> LINK_NEWS_TYPE_LIST = Arrays.asList(1, 2, 3, -1);
public final static List<Integer> REPLACE_LINK_NEWS_TYPE_LIST = Arrays.asList(1, 2, 3);
public final static List<Integer> COMMON_NEWS_TYPE_LIST = Collections.singletonList(4);
public final static Integer BOOK_NEWS_TYPE = 1;
public final static String BOOK_NEWS_TYPE_NAME = "推广";
......@@ -23,6 +35,11 @@ public class CustomerCommonConstant {
public final static String ACTIVITY_NEWS_TYPE_NAME = "活动";
public final static String ACTIVITY_NEWS_TYPE_NAME_MODEL = "系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-充{recharge}送{gift}";
public final static String CUSTOMER_TEXT_LINK_TEMPLATE = "<a href=\"{url}-\" style='color: blue'>{content}</a>";
public final static String CUSTOMER_TEXT_URL_PLACEHOLDER = "{url}-";
public final static String CUSTOMER_TEXT_CONTENT_PLACEHOLDER = "{content}";
public final static Integer USUAL_LINK_NEWS_TYPE = 3;
public final static String USUAL_LINK_NEWS_TYPE_NAME = "常用";
......
......@@ -21,10 +21,10 @@ import java.util.List;
* @author darker
* @date 2022/9/15 11:13
*/
@Api(tags = "客服消息接口")
@Api(tags = "客服消息接口-图文")
@RestController
@RequestMapping("/customer-service/message")
public class CustomerMessageController {
@RequestMapping("/customer-service/message/graphics")
public class CustomerMessageGraphicsController {
@Autowired
private CustomerGraphicsService customerGraphicsService;
......
package com.yaoyaozw.customer.controller;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.dto.customer.CustomerMessageTextSaveDTO;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.service.CustomerGraphicsTextService;
import com.yaoyaozw.customer.vo.customer.CustomerGraphicTextDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author darker
* @date 2022/9/15 11:13
*/
@Api(tags = "客服消息接口-文本")
@RestController
@RequestMapping("/customer-service/message/text")
public class CustomerMessageTextController {
@Autowired
private CustomerGraphicsTextService textService;
@ApiOperation("新增客服主体")
@PostMapping("/insertCustomerMessage")
public GenericsResult<String> insertCustomerMessage(@RequestBody CustomerMessageTextSaveDTO saveDto) {
return textService.insertCustomerMessage(saveDto);
}
@ApiOperation("新增客服内容")
@PostMapping("/insertCustomerContent")
public GenericsResult<CustomerGraphicTextDetailVO> insertCustomerContent(@RequestBody CustomerReferralDTO referralDto) {
return textService.insertCustomerContent(referralDto);
}
@ApiOperation("获取文本客服详情")
@GetMapping("/detail/{id}")
public GenericsResult<CustomerGraphicTextDetailVO> getCustomerTextDetail(@PathVariable("id") Long id) {
return textService.getCustomerTextDetail(id);
}
@ApiOperation("删除单条文本内容")
@GetMapping("/removeCustomerContent/{contentId}")
public GenericsResult<CustomerGraphicTextDetailVO> removeCustomerContent(@PathVariable("contentId") Long contentId) {
return textService.removeCustomerContent(contentId);
}
}
package com.yaoyaozw.customer.dto.customer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author darker
* @date 2022/10/12 16:33
*/
@Data
@ApiModel("文本类型客服保存实体")
public class CustomerMessageTextSaveDTO implements Serializable {
@ApiModelProperty("客服消息id")
private Long id;
@ApiModelProperty("标题")
private String name;
@ApiModelProperty("消息发送时间")
private String postTime;
@ApiModelProperty("客服消息类型(图文、文本)")
private String type;
}
......@@ -22,13 +22,23 @@ import java.util.List;
@Data
public class CustomerReferralDTO implements Serializable {
@ApiModelProperty("客服素材主体id")
@JsonSerialize(using = ToStringSerializer.class)
private Long materialGraphicsId;
@ApiModelProperty("主键id")
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
@ApiModelProperty("文本类型文本内容")
private String textContent;
@ApiModelProperty("链接类型")
private Integer newsType;
@ApiModelProperty(value="序号")
private Integer sort;
@ApiModelProperty("书城")
private String storeType;
......@@ -71,8 +81,6 @@ public class CustomerReferralDTO implements Serializable {
@ApiModelProperty(value = "赠送数量")
private Integer giftAmount;
private Integer isDeleted;
public Date getStartTime() {
if (ObjectUtil.isNull(this.startTime) && CollectionUtil.isNotEmpty(this.dateList)) {
return dateList.get(0);
......@@ -94,10 +102,4 @@ public class CustomerReferralDTO implements Serializable {
return dateList;
}
public Integer getIsDeleted() {
if (ObjectUtil.isNull(this.isDeleted)) {
return 0;
}
return isDeleted;
}
}
......@@ -59,6 +59,12 @@ public class CustomerGraphics implements Serializable {
private String content;
/**
* 可替换链接数量
*/
@TableField(value = "referral_size")
private Integer referralSize;
/**
* 发送时间
*/
@TableField(value = "post_time")
......@@ -99,7 +105,7 @@ public class CustomerGraphics implements Serializable {
*/
@TableField(value = "is_deleted")
@TableLogic
private Boolean isDeleted;
private Integer isDeleted;
private static final long serialVersionUID = 1L;
......
......@@ -107,6 +107,14 @@ public class ReferralEntity implements Serializable {
@ApiModelProperty(value="样式")
private Integer styleType;
@TableField(value = "sort")
@ApiModelProperty(value="序号")
private Integer sort;
@TableField(value = "text_content")
@ApiModelProperty(value="文本内容")
private String textContent;
@TableField(value = "gmt_create", fill = FieldFill.INSERT)
@ApiModelProperty(value="")
private Date gmtCreate;
......
......@@ -109,6 +109,17 @@ public class SchedulingTask {
item.setCrowdNum(num);
}).collect(Collectors.toList());
if (entries.size() != list.size()) {
localLog.info("删除redis在数据库中不存在的人群包");
List<String> idList = list.stream().map(item -> String.valueOf(item.getId())).collect(Collectors.toList());
for (String key : entries.keySet()) {
if (!idList.contains(key)) {
localLog.info("redis中人群包id: {} 在数据库中不存在, 删除", key);
redisTemplate.opsForHash().delete(CustomerCommonConstant.CROWD_HUMAN_NUN_REDIS_KEY, key);
}
}
}
localLog.info("要更新人群包: {} 条", resultList.size());
if (CollectionUtil.isNotEmpty(resultList)) {
crowdPackageService.updateBatchById(resultList);
......
package com.yaoyaozw.customer.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.dto.customer.CustomerMessageTextSaveDTO;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.vo.customer.CustomerGraphicTextDetailVO;
/**
* @author darker
* @date 2022/10/12 10:49
*/
public interface CustomerGraphicsTextService extends IService<CustomerGraphics> {
/**
* 存储客服消息
*
* @param saveDto 保存实体
* @return {@link GenericsResult}<{@link String}>
*/
GenericsResult<String> insertCustomerMessage(CustomerMessageTextSaveDTO saveDto);
/**
* 新增客户内容
*
* @param referralDto 推荐dto
* @return {@link GenericsResult}<{@link CustomerGraphicTextDetailVO}>
*/
GenericsResult<CustomerGraphicTextDetailVO> insertCustomerContent(CustomerReferralDTO referralDto);
/**
* 获取文本客服详情
*
* @param id 主键id
* @return {@link GenericsResult}<{@link CustomerGraphicTextDetailVO}>
*/
GenericsResult<CustomerGraphicTextDetailVO> getCustomerTextDetail(Long id);
/**
* 删除客户内容
*
* @param contentId 文本内容id
* @return {@link GenericsResult}<{@link CustomerGraphicTextDetailVO}>
*/
GenericsResult<CustomerGraphicTextDetailVO> removeCustomerContent(Long contentId);
}
......@@ -3,14 +3,21 @@ package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.components.CustomerServiceCommonAsyncComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO;
......@@ -19,10 +26,16 @@ import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.entity.CrowdPackageCondition;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.enums.CustomerStoreTemplateEnum;
import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCommonMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CrowdPackageConditionService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.vo.AuthInfoVO;
import com.yaoyaozw.customer.vo.CommonOptionResponseVO;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerMessageDetailVO;
import com.yaoyaozw.customer.vo.customer.CustomerMessageListVO;
import org.apache.commons.lang3.StringUtils;
......@@ -32,7 +45,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
......@@ -78,6 +93,10 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
long id = snowflakeComponent.snowflakeId();
customerGraphics.setId(id);
}
// 设置链接数
if (CustomerCommonConstant.REPLACE_LINK_NEWS_TYPE_LIST.contains(saveDto.getCustomerReferralDto().getNewsType())) {
customerGraphics.setReferralSize(1);
}
super.saveOrUpdate(customerGraphics);
// 处理活动数据
......@@ -133,11 +152,20 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
@Transactional(rollbackFor = Exception.class)
public BaseResult removeCustomerMessage(Long id) {
boolean result = super.removeById(id);
boolean referralResult = referralEntityService.remove(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id));
QueryWrapper<ReferralEntity> queryWrapper = new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id);
boolean referralResult = referralEntityService.remove(queryWrapper);
if (result && referralResult) {
// 删除成功
return new BaseResult().success();
}
if (!referralResult) {
int count = referralEntityService.count(queryWrapper);
if (count == 0) {
// 没找到链接数据
LOCAL_LOG.info("没找到链接数据, 删除完成");
return new BaseResult().success();
}
}
LOCAL_LOG.info("主体删除结果: {}, 链接删除结果: {}, 删除失败,回滚事务", result, referralResult);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new BaseResult().error("删除异常");
......@@ -150,17 +178,19 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
return new BaseResult().error("无法获取主体数据");
}
byId.setPackId(packId);
ReferralEntity referralEntity = referralEntityService.getOne(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id"));
LOCAL_LOG.info("获取书城条件主体");
CrowdPackageCondition storeCondition = conditionService.getOne(
new QueryWrapper<CrowdPackageCondition>().eq("condition_key", CrowdPackageCommonConstant.CONDITION_STORE_ID).eq("front_type", CrowdPackageCommonConstant.MULTIPLE_SELECT)
);
// TODO: 2022/10/8 校验人群包设置条件
// 校验人群包设置条件
LOCAL_LOG.info("获取人群包下的书城条件");
CrowdPackageConditionMatch storeConditionMatch = matchService.getOne(
new QueryWrapper<CrowdPackageConditionMatch>().eq("package_id", packId).eq("condition_id", storeCondition.getId())
);
List<ReferralEntity> referralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id"));
for (ReferralEntity referralEntity : referralEntityList) {
Integer newsType = referralEntity.getNewsType();
if (CustomerCommonConstant.BOOK_NEWS_TYPE.equals(newsType)) {
// 是推广链接
......@@ -169,16 +199,14 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
return checkResult;
}
}
}
byId.setPackId(packId);
// 设置状态为链接生成中
byId.setSendStatus(1);
boolean result = super.updateById(byId);
if (result) {
// 删除之前设置人群包的时候获取链接生成的数据
referralEntityService.ultimateDeleteReferrals(id, "and account_id is not null");
// 调用异步方法,获取链接
commonAsyncComponent.getAuthListLink(byId, referralEntity);
commonAsyncComponent.obtainLink(id, byId, referralEntityList);
return new BaseResult().success();
}
return new BaseResult().error("更新失败");
......
package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerMessageTextSaveDTO;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
import com.yaoyaozw.customer.service.CustomerGraphicsTextService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.vo.customer.CustomerContentVO;
import com.yaoyaozw.customer.vo.customer.CustomerGraphicTextDetailVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.ArrayList;
import java.util.List;
/**
* @author darker
* @date 2022/10/12 11:49
*/
@Service
public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphicsMapper, CustomerGraphics> implements CustomerGraphicsTextService {
private final static Logger LOCAL_LOG = LoggerFactory.getLogger(CustomerGraphicsTextServiceImpl.class);
@Autowired
private TokenManager tokenManager;
@Autowired
private SnowflakeComponent snowflakeComponent;
@Autowired
private ReferralEntityService referralEntityService;
@Override
public GenericsResult<String> insertCustomerMessage(CustomerMessageTextSaveDTO saveDto) {
// 主体数据
LOCAL_LOG.info("处理主体数据");
CustomerGraphics customerGraphics = new CustomerGraphics();
BeanUtil.copyProperties(saveDto, customerGraphics);
customerGraphics.initOperateInfo(tokenManager.getUserIdFromToken(), ObjectUtil.isNull(saveDto.getId()));
if (ObjectUtil.isNull(customerGraphics.getId())) {
long id = snowflakeComponent.snowflakeId();
customerGraphics.setId(id);
}
super.saveOrUpdate(customerGraphics);
return new GenericsResult<>(customerGraphics.getId().toString());
}
@Override
@Transactional(rollbackFor = Exception.class)
public GenericsResult<CustomerGraphicTextDetailVO> insertCustomerContent(CustomerReferralDTO referralDto) {
System.out.println(referralDto);
// 处理活动数据
ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(referralDto, referralEntity);
// 获取name模板
String nameModel = CustomerCommonConstant.getLinkNameModel(referralEntity.getNewsType());
LOCAL_LOG.info("获取name模板: {}", nameModel);
if (StringUtils.isNotBlank(nameModel)) {
referralEntity.setName(nameModel);
}
// 保存链接数据
referralEntityService.saveOrUpdate(referralEntity);
return getCustomerTextDetail(referralDto.getMaterialGraphicsId());
}
@Override
public GenericsResult<CustomerGraphicTextDetailVO> getCustomerTextDetail(Long id) {
// 查询主体数据
CustomerGraphics customerGraphics = super.getById(id);
if (ObjectUtil.isNull(customerGraphics)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new GenericsResult<>(false, "找不到主体数据");
}
// 赋值主体数据
CustomerGraphicTextDetailVO detailVO = new CustomerGraphicTextDetailVO();
BeanUtil.copyProperties(customerGraphics, detailVO);
detailVO.setPostTime(customerGraphics.getPostTimeStr());
// 合并链接中的h5代码
List<ReferralEntity> referralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id").orderByAsc("gmt_create"));
List<CustomerContentVO> contentList = new ArrayList<>();
// 位置计数器
StringBuilder mainH5Content = new StringBuilder();
LOCAL_LOG.info("根据链接重新生成H5");
int idx = 1;
int replaceLinkTypeNum = 0;
for (ReferralEntity item : referralEntityList) {
item.setSort(idx);
CustomerContentVO customerContentVO = new CustomerContentVO();
// 设置主键id和h5代码段
customerContentVO.setId(item.getId());
String context = null;
if (CustomerCommonConstant.LINK_NEWS_TYPE_LIST.contains(item.getNewsType())) {
context = CustomerCommonConstant.CUSTOMER_TEXT_LINK_TEMPLATE
.replace(CustomerCommonConstant.CUSTOMER_TEXT_CONTENT_PLACEHOLDER, item.getTextContent())
.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER, CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER + idx);
} else if (CustomerCommonConstant.COMMON_NEWS_TYPE_LIST.contains(item.getNewsType())){
context = item.getTextContent();
}
if (ObjectUtil.isNotNull(context)) {
mainH5Content.append(context);
if (idx != referralEntityList.size()) {
mainH5Content.append("\n").append("\n");
}
// 将链接中的占位符换成#
customerContentVO.setContent(context.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER+idx, "#"));
}
// 赋值链接信息
CustomerReferralDTO customerReferralDto = new CustomerReferralDTO();
BeanUtil.copyProperties(item, customerReferralDto);
customerContentVO.setCustomerReferralDto(customerReferralDto);
contentList.add(customerContentVO);
// 统计referralSize
if (CustomerCommonConstant.REPLACE_LINK_NEWS_TYPE_LIST.contains(item.getNewsType())) {
replaceLinkTypeNum += 1;
}
idx += 1;
}
customerGraphics.setContent(mainH5Content.toString());
customerGraphics.setReferralSize(replaceLinkTypeNum);
detailVO.setContentList(contentList);
// 更新连接表
LOCAL_LOG.info("更新连接表");
if (CollectionUtil.isNotEmpty(referralEntityList)) {
referralEntityService.updateBatchById(referralEntityList);
}
// 更新主表
LOCAL_LOG.info("更新主表");
customerGraphics.initOperateInfo(tokenManager.getUserIdFromToken(), false);
super.updateById(customerGraphics);
return new GenericsResult<>(detailVO);
}
@Override
public GenericsResult<CustomerGraphicTextDetailVO> removeCustomerContent(Long contentId) {
ReferralEntity referralEntity = referralEntityService.getById(contentId);
if (ObjectUtil.isNull(referralEntity)) {
return new GenericsResult<>(false, "找不到主体数据");
}
boolean result = referralEntityService.removeById(contentId);
if (result) {
return getCustomerTextDetail(referralEntity.getMaterialGraphicsId());
}
return new GenericsResult<>(false, "删除失败");
}
}
package com.yaoyaozw.customer.vo.customer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author darker
* @date 2022/10/12 11:31
*/
@Data
public class CustomerContentVO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty("子文本主键")
private Long id;
@ApiModelProperty("文本内容")
private String content;
@ApiModelProperty("链接相关内容")
private CustomerReferralDTO customerReferralDto;
}
package com.yaoyaozw.customer.vo.customer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author darker
* @date 2022/10/12 11:30
*/
@Data
@ApiModel("文本客服详情实体")
public class CustomerGraphicTextDetailVO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty("主键id")
private Long id;
@ApiModelProperty("标题")
private String name;
@ApiModelProperty("文本子内容")
private List<CustomerContentVO> contentList;
@ApiModelProperty("发文时间")
private String postTime;
@ApiModelProperty("发文时间")
private String type;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论