提交 4ee24f6a 作者: 沈振路

Merge branch 'customer_service_SZlu'

# Conflicts:
#	src/main/java/com/yaoyaozw/customer/mapper/ReferralEntityMapper.java
#	src/main/java/com/yaoyaozw/customer/scheduling/SchedulingTask.java
#	src/main/java/com/yaoyaozw/customer/service/impl/CustomerGraphicsServiceImpl.java
...@@ -3,6 +3,8 @@ package com.yaoyaozw.customer.components; ...@@ -3,6 +3,8 @@ package com.yaoyaozw.customer.components;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; 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.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
...@@ -14,12 +16,16 @@ import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO; ...@@ -14,12 +16,16 @@ import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO;
import com.yaoyaozw.customer.entity.CustomerGraphics; import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.entity.ReferralEntity; import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.entity.RegisterUserEntity; import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.enums.CustomerStoreTemplateEnum;
import com.yaoyaozw.customer.feigns.ReferralFeignClient; import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCommonMapper; import com.yaoyaozw.customer.mapper.MaterialCommonMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService; import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.service.RegisterUserEntityService; import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.vo.AuthInfoVO; 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.CrowdPackageUserVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -29,6 +35,7 @@ import org.springframework.data.redis.core.RedisTemplate; ...@@ -29,6 +35,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.RoundingMode;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -58,6 +65,10 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -58,6 +65,10 @@ public class CustomerServiceCommonAsyncComponent {
private ReferralFeignClient referralFeignClient; private ReferralFeignClient referralFeignClient;
@Autowired @Autowired
private MaterialCommonMapper materialCommonMapper; private MaterialCommonMapper materialCommonMapper;
@Autowired
private CustomerGraphicsMapper customerGraphicsMapper;
@Autowired
private KanbanCommonMapper kanbanCommonMapper;
@Async("myExecutor") @Async("myExecutor")
...@@ -124,7 +135,36 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -124,7 +135,36 @@ public class CustomerServiceCommonAsyncComponent {
} }
@Async("myExecutor") @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(); Long packId = customerMain.getPackId();
LOCAL_LOG.info("开始异步处理客服链接, 客服标题: {}, 人群包主键: {}", customerMain.getName(), packId); LOCAL_LOG.info("开始异步处理客服链接, 客服标题: {}, 人群包主键: {}", customerMain.getName(), packId);
...@@ -147,23 +187,13 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -147,23 +187,13 @@ public class CustomerServiceCommonAsyncComponent {
generateUsualLink(storeGroupMap, customerReferral); generateUsualLink(storeGroupMap, customerReferral);
} }
}
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) { private void generateExtendLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = dateFormat.format(new Date());
Map<String, String> storeEntityMap = getStoreEntityMap(storeGroupMap.keySet());
storeGroupMap.forEach((storeType, userVoList) -> { storeGroupMap.forEach((storeType, userVoList) -> {
LOCAL_LOG.info("当前处理书城: {}", storeType); LOCAL_LOG.info("当前处理书城: {}", storeType);
...@@ -178,8 +208,13 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -178,8 +208,13 @@ public class CustomerServiceCommonAsyncComponent {
BeanUtil.copyProperties(customerReferral, referralEntity); BeanUtil.copyProperties(customerReferral, referralEntity);
// 重新生成链接主键id // 重新生成链接主键id
referralEntity.setId(snowflakeComponent.snowflakeId()); referralEntity.setId(snowflakeComponent.snowflakeId());
// TODO: 2022/10/9 获取原文链接 referralEntity.setAccountId(authInfoVo.getAccountId());
getCopyReferral(null, authInfoVo, referralEntity); referralEntity.setStoreTypeName(storeEntityMap.get(storeType));
try {
getCopyReferral(dateStr, authInfoVo, referralEntity);
} catch (Exception e) {
LOCAL_LOG.warn("公众号: {} 获取链接异常: {}", authInfoVo.getAccountName(), e.getMessage());
}
referralEntityList.add(referralEntity); referralEntityList.add(referralEntity);
} }
...@@ -191,90 +226,146 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -191,90 +226,146 @@ public class CustomerServiceCommonAsyncComponent {
private void generateActivityLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) { private void generateActivityLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = dateFormat.format(new Date());
String activityContent = customerReferral.getRechargeAmount().stripTrailingZeros().toPlainString() + "送" + customerReferral.getGiftAmount();
LOCAL_LOG.info("活动内容: {}", activityContent);
Map<String, String> storeEntityMap = getStoreEntityMap(storeGroupMap.keySet());
storeGroupMap.forEach((storeType, userVoList) -> { storeGroupMap.forEach((storeType, userVoList) -> {
LOCAL_LOG.info("当前处理书城: {}", storeType); LOCAL_LOG.info("当前处理书城: {}", storeType);
// 去重提取公众号 boolean isLegal = true;
Set<String> accountSet = userVoList.stream().map(CrowdPackageUserVO::getAccountId).collect(Collectors.toSet()); // 阳光、掌中云 需要获取configId
if (storeType.equals(CustomerCommonConstant.STORE_NAME_YANG_GUANG) || storeType.equals(CustomerCommonConstant.STORE_NAME_ZHANG_ZHONG_YUN)) {
// 定义 R activityConfig = referralFeignClient.getActivityConfig(customerReferral.getRechargeAmount().stripTrailingZeros().toPlainString(), storeType, null);
List<ReferralEntity> referralEntityList = new ArrayList<>(accountSet.size()); // 获取资源配置列表
ReferralEntity referralEntity = new ReferralEntity(); Map<String, Object> data = activityConfig.getData();
BeanUtil.copyProperties(customerReferral, referralEntity); JSONArray configList = JSONUtil.parseArray(data.get("configList"));
// 重新生成链接主键id List<CommonOptionResponseVO> activityConfigList = JSONUtil.toList(configList, CommonOptionResponseVO.class);
referralEntity.setId(snowflakeComponent.snowflakeId());
// TODO: 2022/10/9 获取原文链接 if (!CollectionUtil.isEmpty(activityConfigList)) {
// 转换config
Map<String, String> configMap = activityConfigList.stream().collect(Collectors.toMap(key -> key.getLabel().replaceAll("[^(0-9.送)]", ""), CommonOptionResponseVO::getValue, (o1, o2) -> o2));
String configId = configMap.get(activityContent);
LOCAL_LOG.info("活动内容: {} 获取到configId: {}", activityContent, configId);
customerReferral.setConfigId(configId);
if (ObjectUtil.isNull(configId)) {
isLegal = false;
}
} else {
isLegal = false;
LOCAL_LOG.info("无法获取资源配置, 中断当前循环");
}
}
String tempId = CustomerStoreTemplateEnum.getTempId(storeType);
customerReferral.setTemplateId(tempId);
if (isLegal) {
// 去重提取公众号
Set<String> accountSet = userVoList.stream().map(CrowdPackageUserVO::getAccountId).collect(Collectors.toSet());
List<AuthInfoVO> authInfoList = materialCommonMapper.getAuthInfoList(accountSet);
// 定义
List<ReferralEntity> referralEntityList = new ArrayList<>(accountSet.size());
for (AuthInfoVO authInfoVo : authInfoList) {
ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(customerReferral, referralEntity);
// 重新生成链接主键id
referralEntity.setId(snowflakeComponent.snowflakeId());
referralEntity.setAccountId(authInfoVo.getAccountId());
referralEntity.setStoreTypeName(storeEntityMap.get(storeType));
try {
getCopyReferral(dateStr, authInfoVo, referralEntity);
} catch (Exception e) {
LOCAL_LOG.warn("公众号: {} 获取链接异常: {}", authInfoVo.getAccountName(), e.getMessage());
referralEntity.setReferral("error");
}
referralEntityList.add(referralEntity); referralEntityList.add(referralEntity);
}
// 批量新增 // 批量新增
referralEntityService.saveBatch(referralEntityList); referralEntityService.saveBatch(referralEntityList);
}
}); });
} }
private void generateUsualLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) { private void generateUsualLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
Map<String, String> storeEntityMap = getStoreEntityMap(storeGroupMap.keySet());
storeGroupMap.forEach((storeType, userVoList) -> { storeGroupMap.forEach((storeType, userVoList) -> {
LOCAL_LOG.info("当前处理书城: {}", storeType); LOCAL_LOG.info("当前处理书城: {}", storeType);
// 去重提取公众号 // 去重提取公众号
Set<String> accountSet = userVoList.stream().map(CrowdPackageUserVO::getAccountId).collect(Collectors.toSet()); Set<String> accountSet = userVoList.stream().map(CrowdPackageUserVO::getAccountId).collect(Collectors.toSet());
List<AuthInfoVO> authInfoList = materialCommonMapper.getAuthInfoList(accountSet);
// 定义 // 定义
List<ReferralEntity> referralEntityList = new ArrayList<>(accountSet.size()); List<ReferralEntity> referralEntityList = new ArrayList<>(accountSet.size());
ReferralEntity referralEntity = new ReferralEntity(); for (AuthInfoVO authInfoVo : authInfoList) {
ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(customerReferral, referralEntity);
// 重新生成链接主键id
referralEntity.setId(snowflakeComponent.snowflakeId());
referralEntity.setAccountId(authInfoVo.getAccountId());
referralEntity.setStoreTypeName(storeEntityMap.get(storeType));
BeanUtil.copyProperties(customerReferral, referralEntity); getCopyReferral(null, authInfoVo, referralEntity);
// 重新生成链接主键id
referralEntity.setId(snowflakeComponent.snowflakeId());
// TODO: 2022/10/9 获取原文链接
referralEntityList.add(referralEntity); referralEntityList.add(referralEntity);
}
// 批量新增 // 批量新增
referralEntityService.saveBatch(referralEntityList); referralEntityService.saveBatch(referralEntityList);
}); });
} }
private void getCopyReferral(String dateStr, AuthInfoVO authInfoVo, ReferralEntity referralEntity) {
private void getCopyReferral(String dateStr,
AuthInfoVO authInfoVo,
ReferralEntity referralEntity) {
referralEntity.setStoreType(authInfoVo.getStoreType()); referralEntity.setStoreType(authInfoVo.getStoreType());
referralEntity.setStoreTypeName(authInfoVo.getStoreTypeName());
// 非常用链接类型的name需要处理 // 非常用链接类型的name需要处理
if (!CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) { String name = referralEntity.getName();
referralEntity.setName(replaceName(referralEntity.getName(), dateStr)); Integer newsType = referralEntity.getNewsType();
if (!CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(newsType) && !StringUtils.isBlank(name)) {
String newsTypeName = CustomerCommonConstant.getNewsTypeName(newsType);
if (ObjectUtil.isNull(newsTypeName)) {
throw new RuntimeException("无法获取链接类型");
}
// 替换共用字段
name = name.replace("{newsType}", newsTypeName).replace("{accountNickName}", authInfoVo.getAccountName())
.replace("{storeType}", referralEntity.getStoreTypeName()).replace("{currentDate}", dateStr);
if (newsType.equals(CustomerCommonConstant.BOOK_NEWS_TYPE)) {
// 系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-{bookName}
name = name.replace("{bookName}", referralEntity.getBookName());
} else if (newsType.equals(CustomerCommonConstant.ACTIVITY_NEWS_TYPE)) {
// 系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-充{recharge}送{gift}
name = name.replace("{recharge}", referralEntity.getRechargeAmount().stripTrailingZeros().toPlainString()).replace("{gift}", referralEntity.getGiftAmount().toString());
}
referralEntity.setName(name);
} }
referralEntity.setAccountId(null);
referralEntity.setInfoId(authInfoVo.getId()); referralEntity.setInfoId(authInfoVo.getId());
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());
} else {
LOCAL_LOG.info("公众号: {} 获取链接成功", authInfoVo.getAccountName());
} }
String res = r.getData("storeReferral", new TypeReference<String>() {}); String res = r.getData("storeReferral", new TypeReference<String>() {});
JSONObject jsonObject1 = JSON.parseObject(res); JSONObject jsonObject1 = JSON.parseObject(res);
String referral = jsonObject1.getString("referral"); String referral = jsonObject1.getString("referral");
referralEntity.setPromoteId(jsonObject1.getString("promoteId")); referralEntity.setPromoteId(jsonObject1.getString("promoteId"));
referralEntity.setReferral(referral); referralEntity.setReferral(referral);
// 系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-{bookName}
// 系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-充{recharge}送{gift}
} }
private Map<String, String> getStoreEntityMap(Set<String> storeKeySet) {
private String replaceName(String materialName, String appNickName) { if (CollectionUtil.isEmpty(storeKeySet)) {
if (StringUtils.isBlank(materialName)) { return new HashMap<>(4);
return null;
}
if (materialName.contains("-")) {
String[] split = materialName.split("-");
String format = new SimpleDateFormat("yyyy/MM/dd").format(new Date());
split[5] = format;
split[3] = appNickName;
return String.join("-", split);
} }
return materialName; List<CommonOptionResponseVO> storeTypeEntity = kanbanCommonMapper.getStoreTypeEntity(storeKeySet);
return storeTypeEntity.stream().collect(Collectors.toMap(CommonOptionResponseVO::getKey, CommonOptionResponseVO::getName));
} }
} }
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; ...@@ -2,6 +2,10 @@ package com.yaoyaozw.customer.constants;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/** /**
* @author darker * @author darker
* @date 2022/9/28 20:09 * @date 2022/9/28 20:09
...@@ -10,11 +14,34 @@ public class CustomerCommonConstant { ...@@ -10,11 +14,34 @@ public class CustomerCommonConstant {
public final static String CROWD_HUMAN_NUN_REDIS_KEY = "crowdHumanNum"; public final static String CROWD_HUMAN_NUN_REDIS_KEY = "crowdHumanNum";
public final static Integer ACTIVITY_NEWS_TYPE = 8; public final static String STORE_NAME_YANG_GUANG = "YANG_GUANG";
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 = 7; public final static Integer BOOK_NEWS_TYPE = 1;
public final static String BOOK_NEWS_TYPE_NAME = "推广";
public final static String BOOK_NEWS_TYPE_NAME_MODEL = "系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-{bookName}";
public final static Integer USUAL_LINK_NEWS_TYPE = 9; public final static Integer ACTIVITY_NEWS_TYPE = 2;
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 = "常用";
public final static String CUSTOMER_TYPE_VALUE_GRAPHICS = "news"; public final static String CUSTOMER_TYPE_VALUE_GRAPHICS = "news";
...@@ -37,4 +64,34 @@ public class CustomerCommonConstant { ...@@ -37,4 +64,34 @@ public class CustomerCommonConstant {
return type; return type;
} }
public static String getNewsTypeName(Integer code) {
if (ObjectUtil.isNull(code)) {
return null;
}
if (code.equals(BOOK_NEWS_TYPE)) {
return BOOK_NEWS_TYPE_NAME;
}
if (code.equals(ACTIVITY_NEWS_TYPE)) {
return ACTIVITY_NEWS_TYPE_NAME;
}
if (code.equals(USUAL_LINK_NEWS_TYPE)) {
return USUAL_LINK_NEWS_TYPE_NAME;
}
return null;
}
public static String getLinkNameModel(Integer code) {
if (ObjectUtil.isNull(code)) {
return null;
}
if (code.equals(BOOK_NEWS_TYPE)) {
return BOOK_NEWS_TYPE_NAME_MODEL;
}
if (code.equals(ACTIVITY_NEWS_TYPE)) {
return ACTIVITY_NEWS_TYPE_NAME_MODEL;
}
return null;
}
} }
...@@ -21,10 +21,10 @@ import java.util.List; ...@@ -21,10 +21,10 @@ import java.util.List;
* @author darker * @author darker
* @date 2022/9/15 11:13 * @date 2022/9/15 11:13
*/ */
@Api(tags = "客服消息接口") @Api(tags = "客服消息接口-图文")
@RestController @RestController
@RequestMapping("/customer-service/message") @RequestMapping("/customer-service/message/graphics")
public class CustomerMessageController { public class CustomerMessageGraphicsController {
@Autowired @Autowired
private CustomerGraphicsService customerGraphicsService; 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,19 +22,35 @@ import java.util.List; ...@@ -22,19 +22,35 @@ import java.util.List;
@Data @Data
public class CustomerReferralDTO implements Serializable { public class CustomerReferralDTO implements Serializable {
@ApiModelProperty("客服素材主体id")
@JsonSerialize(using = ToStringSerializer.class)
private Long materialGraphicsId;
@ApiModelProperty("主键id") @ApiModelProperty("主键id")
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long id; private Long id;
@ApiModelProperty("文本类型文本内容")
private String textContent;
@ApiModelProperty("链接类型") @ApiModelProperty("链接类型")
private Integer newsType; private Integer newsType;
@ApiModelProperty(value="序号")
private Integer sort;
@ApiModelProperty("书城") @ApiModelProperty("书城")
private String storeType; private String storeType;
@ApiModelProperty("书城名")
private String storeTypeName;
@ApiModelProperty("书") @ApiModelProperty("书")
private String bookId; private String bookId;
@ApiModelProperty("书名")
private String bookName;
@ApiModelProperty("章节") @ApiModelProperty("章节")
private Integer chapterIdx; private Integer chapterIdx;
...@@ -65,8 +81,6 @@ public class CustomerReferralDTO implements Serializable { ...@@ -65,8 +81,6 @@ public class CustomerReferralDTO implements Serializable {
@ApiModelProperty(value = "赠送数量") @ApiModelProperty(value = "赠送数量")
private Integer giftAmount; private Integer giftAmount;
private Integer isDeleted;
public Date getStartTime() { public Date getStartTime() {
if (ObjectUtil.isNull(this.startTime) && CollectionUtil.isNotEmpty(this.dateList)) { if (ObjectUtil.isNull(this.startTime) && CollectionUtil.isNotEmpty(this.dateList)) {
return dateList.get(0); return dateList.get(0);
...@@ -76,7 +90,7 @@ public class CustomerReferralDTO implements Serializable { ...@@ -76,7 +90,7 @@ public class CustomerReferralDTO implements Serializable {
public Date getEndTime() { public Date getEndTime() {
if (ObjectUtil.isNull(this.endTime) && CollectionUtil.isNotEmpty(this.dateList)) { if (ObjectUtil.isNull(this.endTime) && CollectionUtil.isNotEmpty(this.dateList)) {
return dateList.get(0); return dateList.get(1);
} }
return endTime; return endTime;
} }
...@@ -88,10 +102,4 @@ public class CustomerReferralDTO implements Serializable { ...@@ -88,10 +102,4 @@ public class CustomerReferralDTO implements Serializable {
return dateList; return dateList;
} }
public Integer getIsDeleted() {
if (ObjectUtil.isNull(this.isDeleted)) {
return 0;
}
return isDeleted;
}
} }
package com.yaoyaozw.customer.entity; package com.yaoyaozw.customer.entity;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable; import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
...@@ -57,12 +59,24 @@ public class CustomerGraphics implements Serializable { ...@@ -57,12 +59,24 @@ public class CustomerGraphics implements Serializable {
private String content; private String content;
/** /**
* 可替换链接数量
*/
@TableField(value = "referral_size")
private Integer referralSize;
/**
* 发送时间 * 发送时间
*/ */
@TableField(value = "post_time") @TableField(value = "post_time")
private Date postTime; private Date postTime;
/** /**
* 发送状态
*/
@TableField(value = "send_status")
private Integer sendStatus;
/**
* 创建人 * 创建人
*/ */
@TableField(value = "create_user") @TableField(value = "create_user")
...@@ -94,7 +108,7 @@ public class CustomerGraphics implements Serializable { ...@@ -94,7 +108,7 @@ public class CustomerGraphics implements Serializable {
*/ */
@TableField(value = "is_deleted") @TableField(value = "is_deleted")
@TableLogic @TableLogic
private Boolean isDeleted; private Integer isDeleted;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -123,4 +137,12 @@ public class CustomerGraphics implements Serializable { ...@@ -123,4 +137,12 @@ public class CustomerGraphics implements Serializable {
this.gmtModified = now; this.gmtModified = now;
this.modifiedUser = userId; this.modifiedUser = userId;
} }
public String getPostTimeStr() {
if (ObjectUtil.isNull(this.postTime)) {
return null;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(this.postTime);
}
} }
\ No newline at end of file
...@@ -107,6 +107,14 @@ public class ReferralEntity implements Serializable { ...@@ -107,6 +107,14 @@ public class ReferralEntity implements Serializable {
@ApiModelProperty(value="样式") @ApiModelProperty(value="样式")
private Integer styleType; 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) @TableField(value = "gmt_create", fill = FieldFill.INSERT)
@ApiModelProperty(value="") @ApiModelProperty(value="")
private Date gmtCreate; private Date gmtCreate;
......
package com.yaoyaozw.customer.enums;
import org.apache.commons.lang3.StringUtils;
/**
* @author darker
* @date 2022/10/11 20:23
*/
public enum CustomerStoreTemplateEnum {
/**
* 客服消息书城活动模板
*/
YANG_GUANG("YANG_GUANG", "5"),
YUE_WEN("YUE_WEN", "1"),
ZHANG_ZHONG_YUN("ZHANG_ZHONG_YUN", "1"),
ZHANG_DU("ZHANG_DU", "1")
;
private final String storeType;
private final String templateId;
CustomerStoreTemplateEnum(String storeType, String templateId) {
this.storeType = storeType;
this.templateId = templateId;
}
public String getStoreType() {
return storeType;
}
public String getTemplateId() {
return templateId;
}
public static String getTempId(String storeType) {
if (StringUtils.isBlank(storeType)) {
return null;
}
for (CustomerStoreTemplateEnum value : CustomerStoreTemplateEnum.values()) {
if (storeType.contains(value.getStoreType())) {
return value.getTemplateId();
}
}
return null;
}
}
...@@ -3,8 +3,10 @@ package com.yaoyaozw.customer.feigns; ...@@ -3,8 +3,10 @@ package com.yaoyaozw.customer.feigns;
import com.yaoyaozw.customer.common.R; import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.entity.ReferralEntity; import com.yaoyaozw.customer.entity.ReferralEntity;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/** /**
...@@ -25,4 +27,16 @@ public interface ReferralFeignClient { ...@@ -25,4 +27,16 @@ public interface ReferralFeignClient {
@PostMapping("/getReferral") @PostMapping("/getReferral")
R productReferral(@RequestBody ReferralEntity referralEntity); R productReferral(@RequestBody ReferralEntity referralEntity);
/**
* 获取活动config
*
* @param Key 关键
* @param storeType 存储类型
* @param infoId 信息标识
* @return {@link R}
*/
@GetMapping("/getActivityConfig")
R getActivityConfig(@RequestParam String Key, @RequestParam String storeType, @RequestParam(required = false) Long infoId);
} }
...@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param; ...@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author darker * @author darker
...@@ -41,5 +42,13 @@ public interface KanbanCommonMapper { ...@@ -41,5 +42,13 @@ public interface KanbanCommonMapper {
*/ */
String getStoreTypeByExpression(@Param("expression") String expression); String getStoreTypeByExpression(@Param("expression") String expression);
/**
* 获取书城
*
* @param storeKeySet 存储键设置
* @return {@link List}<{@link CommonOptionResponseVO}>
*/
List<CommonOptionResponseVO> getStoreTypeEntity(@Param("storeKeySet") Set<String> storeKeySet);
} }
...@@ -22,8 +22,9 @@ public interface ReferralEntityMapper extends BaseMapper<ReferralEntity> { ...@@ -22,8 +22,9 @@ public interface ReferralEntityMapper extends BaseMapper<ReferralEntity> {
* 物理删除素材元素 * 物理删除素材元素
* *
* @param sourceId 素材主体ID * @param sourceId 素材主体ID
* @param extraCondition 特殊条件表达式
*/ */
void ultimateDeleteReferrals(@Param("sourceId") Long sourceId); void ultimateDeleteReferrals(@Param("sourceId") Long sourceId, @Param("extraCondition") String extraCondition);
List<ReferralEntityVo> findByMaterialGraphicsId(@Param("graphicsId")Long graphicsId); List<ReferralEntityVo> findByMaterialGraphicsId(@Param("graphicsId")Long graphicsId);
......
package com.yaoyaozw.customer.scheduling; package com.yaoyaozw.customer.scheduling;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO; import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.entity.CustomerGraphics; import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.service.*; import com.yaoyaozw.customer.service.*;
import com.yaoyaozw.customer.entity.CrowdPackage;
import com.yaoyaozw.customer.service.AccountOrderService;
import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.service.impl.CrowdPackageServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class SchedulingTask { public class SchedulingTask {
private final static Logger localLog = LoggerFactory.getLogger(SchedulingTask.class);
@Autowired @Autowired
private AccountOrderService accountOrderService; private AccountOrderService accountOrderService;
...@@ -20,6 +36,11 @@ public class SchedulingTask { ...@@ -20,6 +36,11 @@ public class SchedulingTask {
@Autowired @Autowired
private CustomerDelayPublishService customerDelayPublishService; private CustomerDelayPublishService customerDelayPublishService;
private RegisterUserEntityService registerUserEntityService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private CrowdPackageServiceImpl crowdPackageService;
/** /**
...@@ -90,4 +111,45 @@ public class SchedulingTask { ...@@ -90,4 +111,45 @@ public class SchedulingTask {
customerDelayPublishService.sendCustomerDelayMessage(integrationRequestDTO); customerDelayPublishService.sendCustomerDelayMessage(integrationRequestDTO);
} }
/**
* 从redis中更新人群包人数
*/
@Scheduled(cron = "0 0/15 * * * ?")
public void updateCrowdPackageNumFromRedis() {
localLog.info("开始同步redis中人群包人数至数据库");
HashMap<String, Integer> entries = (HashMap<String, Integer>) redisTemplate.boundHashOps(CustomerCommonConstant.CROWD_HUMAN_NUN_REDIS_KEY).entries();
if (CollectionUtil.isEmpty(entries)) {
return;
}
localLog.info("redis中获取到人群包人数数据: {}对", entries.size());
Date now = new Date();
List<CrowdPackage> list = crowdPackageService.list();
localLog.info("数据库中获取人群包: {}条", list.size());
List<CrowdPackage> resultList = list.stream().filter(item -> entries.containsKey(item.getId().toString()))
.peek(item -> {
item.setLastCountTime(now);
Integer num = entries.get(item.getId().toString());
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);
}
localLog.info("删除创建时的临时数据");
crowdPackageService.remove(new QueryWrapper<CrowdPackage>().isNull("package_name"));
}
} }
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);
}
...@@ -17,8 +17,9 @@ public interface ReferralEntityService extends IService<ReferralEntity> { ...@@ -17,8 +17,9 @@ public interface ReferralEntityService extends IService<ReferralEntity> {
* 物理删除素材元素 * 物理删除素材元素
* *
* @param sourceId 素材主体ID * @param sourceId 素材主体ID
* @param extraCondition 特殊条件表达式
*/ */
void ultimateDeleteReferrals(Long sourceId); void ultimateDeleteReferrals(Long sourceId, String extraCondition);
/** /**
* 根据客服id找链接 * 根据客服id找链接
......
...@@ -147,10 +147,6 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap ...@@ -147,10 +147,6 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
if (CollectionUtil.isEmpty(pageList)) { if (CollectionUtil.isEmpty(pageList)) {
return new GenericsResult<>(false, "暂无数据"); return new GenericsResult<>(false, "暂无数据");
} }
HashMap<String, Integer> entries = (HashMap<String, Integer>) redisTemplate.boundHashOps(CustomerCommonConstant.CROWD_HUMAN_NUN_REDIS_KEY).entries();
if (CollectionUtil.isNotEmpty(entries)) {
pageList.forEach(item -> item.setNumOfCrowdInPackage(entries.get(item.getId().toString())));
}
return new GenericsResult<>(pageList); return new GenericsResult<>(pageList);
} }
......
...@@ -4,15 +4,22 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -4,15 +4,22 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; 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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.sun.xml.internal.bind.v2.TODO; import com.sun.xml.internal.bind.v2.TODO;
import com.yaoyaozw.customer.common.BaseResult; import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult; import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.components.CustomerServiceCommonAsyncComponent; import com.yaoyaozw.customer.components.CustomerServiceCommonAsyncComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent; import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager; import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant; import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant; import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO; import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO;
...@@ -23,15 +30,22 @@ import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO; ...@@ -23,15 +30,22 @@ import com.yaoyaozw.customer.dto.customer.CustomerReferralDTO;
import com.yaoyaozw.customer.entity.CrowdPackageCondition; import com.yaoyaozw.customer.entity.CrowdPackageCondition;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch; import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.entity.ReferralEntity; 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.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCommonMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService; import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CrowdPackageConditionService; import com.yaoyaozw.customer.service.CrowdPackageConditionService;
import com.yaoyaozw.customer.service.ReferralEntityService; 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.CustomerMessageDetailVO;
import com.yaoyaozw.customer.service.*; import com.yaoyaozw.customer.service.*;
import com.yaoyaozw.customer.service.wechat.service.WeChatService; import com.yaoyaozw.customer.service.wechat.service.WeChatService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO; import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerMessageListVO; import com.yaoyaozw.customer.vo.customer.CustomerMessageListVO;
import org.apache.commons.lang3.StringUtils;
import com.yaoyaozw.customer.vo.referral.ReferralEntityVo; import com.yaoyaozw.customer.vo.referral.ReferralEntityVo;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -42,6 +56,10 @@ import java.util.*; ...@@ -42,6 +56,10 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.List; import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.entity.CustomerGraphics; import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper; import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
...@@ -94,13 +112,22 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -94,13 +112,22 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
long id = snowflakeComponent.snowflakeId(); long id = snowflakeComponent.snowflakeId();
customerGraphics.setId(id); customerGraphics.setId(id);
} }
// 设置链接数
if (CustomerCommonConstant.REPLACE_LINK_NEWS_TYPE_LIST.contains(saveDto.getCustomerReferralDto().getNewsType())) {
customerGraphics.setReferralSize(1);
}
super.saveOrUpdate(customerGraphics); super.saveOrUpdate(customerGraphics);
// 处理活动数据 // 处理活动数据
ReferralEntity referralEntity = new ReferralEntity(); ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(saveDto.getCustomerReferralDto(), referralEntity); BeanUtil.copyProperties(saveDto.getCustomerReferralDto(), referralEntity);
referralEntity.setMaterialGraphicsId(customerGraphics.getId()); referralEntity.setMaterialGraphicsId(customerGraphics.getId());
// 获取name模板
String nameModel = CustomerCommonConstant.getLinkNameModel(referralEntity.getNewsType());
LOCAL_LOG.info("获取name模板: {}", nameModel);
if (StringUtils.isNotBlank(nameModel)) {
referralEntity.setName(nameModel);
}
// 保存链接数据 // 保存链接数据
referralEntityService.saveOrUpdate(referralEntity); referralEntityService.saveOrUpdate(referralEntity);
...@@ -117,6 +144,7 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -117,6 +144,7 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
} }
CustomerMessageDetailVO customerMessageDetailVO = new CustomerMessageDetailVO(); CustomerMessageDetailVO customerMessageDetailVO = new CustomerMessageDetailVO();
BeanUtil.copyProperties(customerGraphics, customerMessageDetailVO); BeanUtil.copyProperties(customerGraphics, customerMessageDetailVO);
customerMessageDetailVO.setPostTime(customerGraphics.getPostTimeStr());
// 获取链接数据 // 获取链接数据
ReferralEntity referralEntity = referralEntityService.getOne(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id")); ReferralEntity referralEntity = referralEntityService.getOne(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id"));
...@@ -143,11 +171,20 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -143,11 +171,20 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public BaseResult removeCustomerMessage(Long id) { public BaseResult removeCustomerMessage(Long id) {
boolean result = super.removeById(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) { if (result && referralResult) {
// 删除成功 // 删除成功
return new BaseResult().success(); 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); LOCAL_LOG.info("主体删除结果: {}, 链接删除结果: {}, 删除失败,回滚事务", result, referralResult);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new BaseResult().error("删除异常"); return new BaseResult().error("删除异常");
...@@ -160,31 +197,35 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -160,31 +197,35 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
return new BaseResult().error("无法获取主体数据"); return new BaseResult().error("无法获取主体数据");
} }
byId.setPackId(packId); byId.setPackId(packId);
ReferralEntity referralEntity = referralEntityService.getOne(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id"));
LOCAL_LOG.info("获取书城条件主体"); LOCAL_LOG.info("获取书城条件主体");
CrowdPackageCondition storeCondition = conditionService.getOne( CrowdPackageCondition storeCondition = conditionService.getOne(
new QueryWrapper<CrowdPackageCondition>().eq("condition_key", CrowdPackageCommonConstant.CONDITION_STORE_ID).eq("front_type", CrowdPackageCommonConstant.MULTIPLE_SELECT) new QueryWrapper<CrowdPackageCondition>().eq("condition_key", CrowdPackageCommonConstant.CONDITION_STORE_ID).eq("front_type", CrowdPackageCommonConstant.MULTIPLE_SELECT)
); );
// TODO: 2022/10/8 校验人群包设置条件 // 校验人群包设置条件
LOCAL_LOG.info("获取人群包下的书城条件"); LOCAL_LOG.info("获取人群包下的书城条件");
CrowdPackageConditionMatch storeConditionMatch = matchService.getOne( CrowdPackageConditionMatch storeConditionMatch = matchService.getOne(
new QueryWrapper<CrowdPackageConditionMatch>().eq("package_id", packId).eq("condition_id", storeCondition.getId()) new QueryWrapper<CrowdPackageConditionMatch>().eq("package_id", packId).eq("condition_id", storeCondition.getId())
); );
Integer newsType = referralEntity.getNewsType(); List<ReferralEntity> referralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id"));
if (CustomerCommonConstant.BOOK_NEWS_TYPE.equals(newsType)) {
// 是推广链接 for (ReferralEntity referralEntity : referralEntityList) {
BaseResult checkResult = this.checkExtendBook(referralEntity.getStoreType(), storeConditionMatch); Integer newsType = referralEntity.getNewsType();
if (!checkResult.getSuccess()) { if (CustomerCommonConstant.BOOK_NEWS_TYPE.equals(newsType)) {
return checkResult; // 是推广链接
BaseResult checkResult = this.checkExtendBook(referralEntity.getStoreType(), storeConditionMatch);
if (!checkResult.getSuccess()) {
return checkResult;
}
} }
} }
// TODO: 2022/10/8 根据人群包条件获取用户公众号,生成链接
byId.setPackId(packId); byId.setPackId(packId);
// 设置状态为链接生成中
byId.setSendStatus(1);
boolean result = super.updateById(byId); boolean result = super.updateById(byId);
if (result) { if (result) {
commonAsyncComponent.obtainLink(id, byId, referralEntityList);
return new BaseResult().success(); return new BaseResult().success();
} }
return new BaseResult().error("更新失败"); 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, "删除失败");
}
}
...@@ -17,8 +17,8 @@ import java.util.List; ...@@ -17,8 +17,8 @@ import java.util.List;
public class ReferralEntityServiceImpl extends ServiceImpl<ReferralEntityMapper, ReferralEntity> implements ReferralEntityService { public class ReferralEntityServiceImpl extends ServiceImpl<ReferralEntityMapper, ReferralEntity> implements ReferralEntityService {
@Override @Override
public void ultimateDeleteReferrals(Long materialId) { public void ultimateDeleteReferrals(Long materialId, String extraCondition) {
super.baseMapper.ultimateDeleteReferrals(materialId); super.baseMapper.ultimateDeleteReferrals(materialId, extraCondition);
} }
@Override @Override
......
...@@ -20,4 +20,10 @@ public class CommonOptionResponseVO implements Serializable { ...@@ -20,4 +20,10 @@ public class CommonOptionResponseVO implements Serializable {
@ApiModelProperty("选项名称") @ApiModelProperty("选项名称")
private String name; private String name;
@ApiModelProperty("key值")
private String value;
@ApiModelProperty("选项名称")
private String label;
} }
...@@ -31,7 +31,7 @@ public class CrowdPackageListVO implements Serializable { ...@@ -31,7 +31,7 @@ public class CrowdPackageListVO implements Serializable {
private Integer numOfCrowdInPackage; private Integer numOfCrowdInPackage;
@ApiModelProperty("最后一次统计时间") @ApiModelProperty("最后一次统计时间")
private Integer lastCountTime; private String lastCountTime;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
private String createTime; private String createTime;
......
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;
}
...@@ -33,4 +33,15 @@ ...@@ -33,4 +33,15 @@
limit 1 limit 1
</select> </select>
<select id="getStoreTypeEntity" resultType="com.yaoyaozw.customer.vo.CommonOptionResponseVO">
select
store_type as `key`,
store_name as `name`
from store_entity
where store_type in
<foreach collection="storeKeySet" item="storeKey" open="(" close=")" separator=",">
#{storeKey}
</foreach>
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -12,15 +12,12 @@ ...@@ -12,15 +12,12 @@
<select id="getAuthInfoList" resultType="com.yaoyaozw.customer.vo.AuthInfoVO"> <select id="getAuthInfoList" resultType="com.yaoyaozw.customer.vo.AuthInfoVO">
select select
ai.id, ai.account_id as accountId, id, account_id as accountId,
ai.nick_name as accountName, nick_name as accountName,
ai.store_type as storeType, store_type as storeType
se.store_name as storeTypeName from authorizer_info
from authorizer_info ai
left join store_entity se
on ai.store_type = se.store_type
where ai.account_id in where account_id in
<foreach collection="accountSet" item="accountId" separator="," open="(" close=")"> <foreach collection="accountSet" item="accountId" separator="," open="(" close=")">
#{accountId} #{accountId}
</foreach> </foreach>
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
<select id="getPageList" resultType="com.yaoyaozw.customer.vo.crowd.CrowdPackageListVO"> <select id="getPageList" resultType="com.yaoyaozw.customer.vo.crowd.CrowdPackageListVO">
select select
cpm.id, cpm.package_name as packageName, cpm.id, cpm.package_name as packageName,
cpm.crowd_num as numOfCrowdInPackage, cpm.last_count_time as lastCountTime, ifnull(cpm.crowd_num, 0) as numOfCrowdInPackage,
cpm.last_count_time as lastCountTime,
cpm.create_time as createTime, cpm.modified_time as modifiedTime, cpm.create_time as createTime, cpm.modified_time as modifiedTime,
cau.nick_name as createUser, mau.nick_name as modifiedUser, cau.nick_name as createUser, mau.nick_name as modifiedUser,
group_concat(concat('【', mat.operator_description, '】')) as packageLabel group_concat(concat('【', mat.operator_description, '】')) as packageLabel
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
<delete id="ultimateDeleteReferrals"> <delete id="ultimateDeleteReferrals">
delete from referral_entity where material_graphics_id = #{sourceId} delete from referral_entity where material_graphics_id = #{sourceId}
<if test="extraCondition != null and extraCondition != ''">
${extraCondition}
</if>
</delete> </delete>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论