提交 b09ed005 作者: 沈振路

延时客服-文本-finish

上级 ee47fc32
...@@ -351,8 +351,13 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -351,8 +351,13 @@ public class CustomerServiceCommonAsyncComponent {
targetCustomerGraphics.setAppId(targetAuthInfo.getAppid()); targetCustomerGraphics.setAppId(targetAuthInfo.getAppid());
List<ReferralEntity> sourceReferralList = sourceGraphics.getBelongReferralList(); List<ReferralEntity> sourceReferralList = sourceGraphics.getBelongReferralList();
String type = sourceGraphics.getType();
// 构造h5
StringBuilder h5Context = new StringBuilder();
Integer postSort = sourceGraphics.getPostSort(); Integer postSort = sourceGraphics.getPostSort();
// 遍历处理客服链接 // 遍历处理客服链接
int idx = 1;
for (ReferralEntity sourceReferralEntity : sourceReferralList) { for (ReferralEntity sourceReferralEntity : sourceReferralList) {
// 生成新的链接数据 // 生成新的链接数据
ReferralEntity targetReferralEntity = new ReferralEntity(); ReferralEntity targetReferralEntity = new ReferralEntity();
...@@ -388,10 +393,32 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -388,10 +393,32 @@ public class CustomerServiceCommonAsyncComponent {
targetReferralEntityList.add(targetReferralEntity); targetReferralEntityList.add(targetReferralEntity);
// 图文主表只有一个素材链接,文本主表不需要存素材链接 // 图文主表只有一个素材链接,文本主表不需要存素材链接
targetCustomerGraphics.setSourceUrl(targetReferralEntity.getReferral()); String referral = targetReferralEntity.getReferral();
targetCustomerGraphics.setSourceUrl(referral);
if (type.equals(CustomerCommonConstant.CUSTOMER_TYPE_VALUE_TEXT)) {
// 文本类型替换h5链接
String context = null;
if (CustomerCommonConstant.LINK_NEWS_TYPE_LIST.contains(newsType)) {
context = CustomerCommonConstant.CUSTOMER_TEXT_LINK_TEMPLATE.replace(CustomerCommonConstant.CUSTOMER_TEXT_CONTENT_PLACEHOLDER, targetReferralEntity.getTextContent());
} else if (CustomerCommonConstant.COMMON_NEWS_TYPE_LIST.contains(newsType)){
context = targetReferralEntity.getTextContent();
}
if (ObjectUtil.isNotNull(context)) {
// 拼接的要替换链接
h5Context.append(context.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER, referral));
if (idx != sourceReferralList.size()) {
h5Context.append("\n").append("\n");
}
}
idx += 1;
}
} }
targetCustomerGraphics.setSendStatus(CustomerCommonConstant.SEND_STATUS_LINK_FINISH); targetCustomerGraphics.setSendStatus(CustomerCommonConstant.SEND_STATUS_LINK_FINISH);
if (StringUtils.isNotBlank(h5Context)) {
targetCustomerGraphics.setContent(h5Context.toString());
}
LOCAL_LOG.info("保存主体数据, 主体id: {}", mainId); LOCAL_LOG.info("保存主体数据, 主体id: {}", mainId);
customerGraphicsDelayMapper.insert(targetCustomerGraphics); customerGraphicsDelayMapper.insert(targetCustomerGraphics);
...@@ -493,6 +520,7 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -493,6 +520,7 @@ public class CustomerServiceCommonAsyncComponent {
referralEntity.setName(name); referralEntity.setName(name);
} }
referralEntity.setInfoId(authInfoVo.getId()); referralEntity.setInfoId(authInfoVo.getId());
LOCAL_LOG.info("获取链接, 参数: {}", referralEntity);
R r = referralFeignClient.productReferral(referralEntity); R r = referralFeignClient.productReferral(referralEntity);
if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) { if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) {
throw new RuntimeException(r.getMessage()); throw new RuntimeException(r.getMessage());
......
package com.yaoyaozw.customer.controller;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.dto.customer.CustomerDelayTextSaveDTO;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.service.CustomerDelayTextService;
import com.yaoyaozw.customer.vo.customer.CustomerDelayTextDetailVO;
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/delay/text")
public class CustomerDelayTextController {
@Autowired
private CustomerDelayTextService textService;
@ApiOperation("新增客服主体")
@PostMapping("/insertCustomerDelay")
public GenericsResult<String> insertCustomerDelay(@RequestBody CustomerDelayTextSaveDTO saveDto) {
return textService.insertCustomerDelay(saveDto);
}
@ApiOperation("新增客服内容")
@PostMapping("/insertCustomerContent")
public GenericsResult<CustomerDelayTextDetailVO> insertCustomerContent(@RequestBody CustomerReferralDTO referralDto) {
return textService.insertCustomerContent(referralDto);
}
@ApiOperation("获取文本客服详情")
@GetMapping("/detail/{id}")
public GenericsResult<CustomerDelayTextDetailVO> getCustomerTextDetail(@PathVariable("id") Long id) {
return textService.getCustomerTextDetail(id);
}
@ApiOperation("删除单条文本内容")
@GetMapping("/removeCustomerContent/{contentId}")
public GenericsResult<CustomerDelayTextDetailVO> 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 CustomerDelayTextSaveDTO implements Serializable {
@ApiModelProperty("客服消息id")
private Long id;
@ApiModelProperty("公众号AppId")
private String appId;
@ApiModelProperty("标题")
private String name;
@ApiModelProperty("发文序号")
private Integer postSort;
@ApiModelProperty("发文间隔时间")
private Long timeInterval;
@ApiModelProperty("已支付、未支付")
private Integer isPay;
@ApiModelProperty("客服消息类型(图文、文本)")
private String type;
}
...@@ -33,6 +33,9 @@ public class CustomerReferralDTO implements Serializable { ...@@ -33,6 +33,9 @@ public class CustomerReferralDTO implements Serializable {
@ApiModelProperty("文本类型文本内容") @ApiModelProperty("文本类型文本内容")
private String textContent; private String textContent;
@ApiModelProperty("appId")
private String appId;
@ApiModelProperty("链接类型") @ApiModelProperty("链接类型")
private Integer newsType; private Integer newsType;
......
...@@ -34,7 +34,7 @@ public interface CustomerGraphicsDelayMapper extends BaseMapper<CustomerGraphics ...@@ -34,7 +34,7 @@ public interface CustomerGraphicsDelayMapper extends BaseMapper<CustomerGraphics
* @param queryDto 查询dto * @param queryDto 查询dto
* @return {@link List}<{@link CustomerDelayListVO}> * @return {@link List}<{@link CustomerDelayListVO}>
*/ */
List<CustomerDelayListVO> pageList(CustomerDelayQueryDTO queryDto); List<CustomerDelayListVO> pageList(@Param("queryDto") CustomerDelayQueryDTO queryDto);
/** /**
* 得到客户账户存在 * 得到客户账户存在
......
...@@ -50,5 +50,11 @@ public interface KanbanCommonMapper { ...@@ -50,5 +50,11 @@ public interface KanbanCommonMapper {
*/ */
List<CommonOptionResponseVO> getStoreTypeEntity(@Param("storeKeySet") Set<String> storeKeySet); List<CommonOptionResponseVO> getStoreTypeEntity(@Param("storeKeySet") Set<String> storeKeySet);
/**
* @param appId 应用程序id
* @return {@link String}
*/
String getStoreTypeNameByAppId(@Param("appId") String appId);
} }
package com.yaoyaozw.customer.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.dto.customer.CustomerDelayTextSaveDTO;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.entity.CustomerGraphicsDelay;
import com.yaoyaozw.customer.vo.customer.CustomerDelayTextDetailVO;
/**
* @author darker
* @date 2022/10/17 16:38
*/
public interface CustomerDelayTextService extends IService<CustomerGraphicsDelay> {
/**
* 插入客户延迟
*
* @param saveDto 保存dto
* @return {@link GenericsResult}<{@link String}>
*/
GenericsResult<String> insertCustomerDelay(CustomerDelayTextSaveDTO saveDto);
/**
* 插入客户内容
*
* @param referralDto 推荐dto
* @return {@link GenericsResult}<{@link CustomerDelayTextDetailVO}>
*/
GenericsResult<CustomerDelayTextDetailVO> insertCustomerContent(CustomerReferralDTO referralDto);
/**
* 得到客户文本细节
*
* @param id id
* @return {@link GenericsResult}<{@link CustomerDelayTextDetailVO}>
*/
GenericsResult<CustomerDelayTextDetailVO> getCustomerTextDetail(Long id);
/**
* 删除客户内容
*
* @param contentId 内容识别
* @return {@link GenericsResult}<{@link CustomerDelayTextDetailVO}>
*/
GenericsResult<CustomerDelayTextDetailVO> removeCustomerContent(Long contentId);
}
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.CustomerServiceCommonAsyncComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerDelayTextSaveDTO;
import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerGraphicsDelay;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.mapper.CustomerGraphicsDelayMapper;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.service.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CustomerDelayTextService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.vo.AuthInfoVO;
import com.yaoyaozw.customer.vo.customer.CustomerContentVO;
import com.yaoyaozw.customer.vo.customer.CustomerDelayTextDetailVO;
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.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author darker
* @date 2022/10/17 16:39
*/
@Service
public class CustomerDelayTextServiceImpl extends ServiceImpl<CustomerGraphicsDelayMapper, CustomerGraphicsDelay> implements CustomerDelayTextService {
private final static Logger localLog = LoggerFactory.getLogger(CustomerDelayTextServiceImpl.class);
@Autowired
private TokenManager tokenManager;
@Autowired
private SnowflakeComponent snowflakeComponent;
@Autowired
private ReferralEntityService referralEntityService;
@Autowired
private CustomerServiceCommonAsyncComponent commonAsyncComponent;
@Autowired
private AuthorizerInfoService authorizerInfoService;
@Autowired
private KanbanCommonMapper kanbanCommonMapper;
@Override
public GenericsResult<String> insertCustomerDelay(CustomerDelayTextSaveDTO saveDto) {
// 主体数据
localLog.info("处理主体数据");
CustomerGraphicsDelay customerGraphicsDelay = new CustomerGraphicsDelay();
BeanUtil.copyProperties(saveDto, customerGraphicsDelay);
customerGraphicsDelay.initOperateInfo(tokenManager.getUserIdFromToken(), ObjectUtil.isNull(saveDto.getId()));
if (ObjectUtil.isNull(customerGraphicsDelay.getId())) {
long id = snowflakeComponent.snowflakeId();
customerGraphicsDelay.setId(id);
}
super.saveOrUpdate(customerGraphicsDelay);
return new GenericsResult<>(customerGraphicsDelay.getId().toString());
}
@Override
public GenericsResult<CustomerDelayTextDetailVO> insertCustomerContent(CustomerReferralDTO referralDto) {
// 处理活动数据
ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(referralDto, referralEntity);
// 获取name模板
String nameModel = CustomerCommonConstant.getLinkNameModel(referralEntity.getNewsType());
localLog.info("获取name模板: {}", nameModel);
if (StringUtils.isNotBlank(nameModel)) {
referralEntity.setName(nameModel);
}
String storeTypeName = kanbanCommonMapper.getStoreTypeNameByAppId(referralDto.getAppId());
referralEntity.setStoreTypeName(storeTypeName);
// 保存链接数据
referralEntityService.saveOrUpdate(referralEntity);
return getCustomerTextDetail(referralDto.getMaterialGraphicsId());
}
@Override
public GenericsResult<CustomerDelayTextDetailVO> getCustomerTextDetail(Long id) {
// 查询主体数据
CustomerGraphicsDelay customerGraphicsDelay = super.getById(id);
if (ObjectUtil.isNull(customerGraphicsDelay)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new GenericsResult<>(false, "找不到主体数据");
}
// 赋值主体数据
CustomerDelayTextDetailVO detailVO = new CustomerDelayTextDetailVO();
BeanUtil.copyProperties(customerGraphicsDelay, detailVO);
// 合并链接中的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();
// 日期
String format = new SimpleDateFormat("yyyy/MM/dd").format(new Date());
// 公众号
AuthorizerInfo authorizerInfo = authorizerInfoService.getOne(new QueryWrapper<AuthorizerInfo>().eq("appid", customerGraphicsDelay.getAppId()));
AuthInfoVO authInfoVO = new AuthInfoVO();
authInfoVO.putPropertyValue(authorizerInfo);
localLog.info("根据链接重新生成H5");
int idx = 1;
for (ReferralEntity item : referralEntityList) {
item.setSort(idx);
CustomerContentVO customerContentVO = new CustomerContentVO();
// 设置主键id和h5代码段
customerContentVO.setId(item.getId());
// 获取链接
commonAsyncComponent.getCopyReferral(format, authInfoVO, item);
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());
} else if (CustomerCommonConstant.COMMON_NEWS_TYPE_LIST.contains(item.getNewsType())){
context = item.getTextContent();
}
if (ObjectUtil.isNotNull(context)) {
// 拼接的要替换链接
mainH5Content.append(context.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER, item.getReferral()));
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);
idx += 1;
}
customerGraphicsDelay.setContent(mainH5Content.toString().replace(CustomerCommonConstant.H5_STYLE_CODE, ""));
detailVO.setContentList(contentList);
// 更新连接表
localLog.info("更新连接表");
if (CollectionUtil.isNotEmpty(referralEntityList)) {
referralEntityService.updateBatchById(referralEntityList);
}
// 更新主表
localLog.info("更新主表");
customerGraphicsDelay.initOperateInfo(tokenManager.getUserIdFromToken(), false);
super.updateById(customerGraphicsDelay);
return new GenericsResult<>(detailVO);
}
@Override
public GenericsResult<CustomerDelayTextDetailVO> 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, "删除失败");
}
}
...@@ -117,7 +117,7 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi ...@@ -117,7 +117,7 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
localLog.info("链接获取完成"); localLog.info("链接获取完成");
} catch (Exception e) { } catch (Exception e) {
localLog.info("获取链接异常"); localLog.info("获取链接异常");
return new BaseResult().error("获取链接异常"); return new BaseResult().error("获取链接异常" + e.getMessage());
} }
} }
customerGraphicsDelay.setSourceUrl(referralEntity.getReferral()); customerGraphicsDelay.setSourceUrl(referralEntity.getReferral());
......
...@@ -65,8 +65,6 @@ public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphic ...@@ -65,8 +65,6 @@ public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphic
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public GenericsResult<CustomerMessageTextDetailVO> insertCustomerContent(CustomerReferralDTO referralDto) { public GenericsResult<CustomerMessageTextDetailVO> insertCustomerContent(CustomerReferralDTO referralDto) {
System.out.println(referralDto);
// 处理活动数据 // 处理活动数据
ReferralEntity referralEntity = new ReferralEntity(); ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(referralDto, referralEntity); BeanUtil.copyProperties(referralDto, referralEntity);
......
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 CustomerDelayTextDetailVO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty("主键id")
private Long id;
@ApiModelProperty("标题")
private String name;
@ApiModelProperty("文本子内容")
private List<CustomerContentVO> contentList;
@ApiModelProperty("类型")
private String type;
@ApiModelProperty("发文序号")
private Integer postSort;
@ApiModelProperty("发文间隔时间")
@JsonSerialize(using = ToStringSerializer.class)
private Long timeInterval;
@ApiModelProperty("已支付、未支付")
private Integer isPay;
@ApiModelProperty("appId")
private String appId;
}
...@@ -18,7 +18,7 @@ spring: ...@@ -18,7 +18,7 @@ spring:
namespace: 062507b6-b1d7-4aac-8ed8-0da1cd9451e1 namespace: 062507b6-b1d7-4aac-8ed8-0da1cd9451e1
file-extension: yml file-extension: yml
ext-config: ext-config:
- data-id: customer-service-test.yml - data-id: customer-service-dev.yml
group: DEFAULT_GROUP group: DEFAULT_GROUP
refresh: true refresh: true
--- ---
......
...@@ -57,6 +57,13 @@ ...@@ -57,6 +57,13 @@
on s_dic.group_id = 'CUSTOMER_SEND_STATUS' on s_dic.group_id = 'CUSTOMER_SEND_STATUS'
and s_dic.dic_key = cgd.send_status and s_dic.dic_key = cgd.send_status
where cgd.is_deleted = 0
<if test="queryDto.appId != null and queryDto.appId != ''">
and cgd.app_id = #{queryDto.appId}
</if>
order by cgd.app_id, cgd.post_sort
</select> </select>
<select id="getExistCustomerAccount" resultType="com.yaoyaozw.customer.vo.AuthInfoVO"> <select id="getExistCustomerAccount" resultType="com.yaoyaozw.customer.vo.AuthInfoVO">
......
...@@ -44,4 +44,15 @@ ...@@ -44,4 +44,15 @@
#{storeKey} #{storeKey}
</foreach> </foreach>
</select> </select>
<select id="getStoreTypeNameByAppId" resultType="java.lang.String">
select
se.store_name
from account_entity ae
left join store_entity se
on ae.store_id = se.id
where ae.app_id = #{appId}
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论