Commit 09f51cc0 by chenxi

策略活动接口接口功能实现、sop营销策略接口功能实现

1 parent 5ddfc559
Showing 22 changed files with 876 additions and 0 deletions
package cn.com.glsx.dj.strategy.dto.marketing;
import lombok.Data;
import java.io.Serializable;
@Data
public class ActivityProductListReqDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer merchantId;
}
package cn.com.glsx.dj.strategy.dto.marketing;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class CarSeriesRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer carSeriesId;
private String carSeriesName;
private List<ProductRespDTO> productList;
}
package cn.com.glsx.dj.strategy.dto.marketing;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class MarketingStageGroupRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer marketingStage;
private List<CarSeriesRespDTO> carSeriesList;
}
package cn.com.glsx.dj.strategy.dto.marketing;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class ProductRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer productId;
private Integer productType;
private String tabName;
private String tabDescription;
private Integer isMainPush;
private BigDecimal currentPrice;
private BigDecimal discountPrice;
private String mainImageUrl;
private String thumbImageUrl;
private String detailImageUrl;
private Date startTime;
private Date endTime;
private Integer activityId;
private Integer carSeriesId;
}
package cn.com.glsx.dj.strategy.dto.sop;
import lombok.Data;
import java.io.Serializable;
@Data
public class CustomerSopTaskDetailReqDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer merchantId;
private Integer customerInstanceId;
}
package cn.com.glsx.dj.strategy.dto.sop;
import lombok.Data;
import java.io.Serializable;
@Data
public class CustomerSopTaskDetailRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer taskId;
private Integer strategyId;
private Integer actionType;
private Integer messageType;
/**
* 组装后的消息内容(Service层根据messageType从content/mediaIds/jumpUrl计算)
*/
private String messageContent;
/**
* 任务状态(Service层计算,1-已触达 2-不触达 3-推送失败,接口三固定为0)
*/
private Integer taskStatus;
private String confirmBy;
/**
* 推送结果(接口层定义: 2-成功 3-失败,接口三固定为null)
*/
private Integer pushResult;
// ==== 以下为Service层计算用辅助字段,由Mapper填充原始值 ====
private String content;
private String mediaIds;
private String jumpUrl;
private Integer confirmStatus;
private Integer executeStatus;
}
package cn.com.glsx.dj.strategy.dto.sop;
import lombok.Data;
import java.io.Serializable;
@Data
public class CustomerSopTaskPageReqDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer pageNum;
private Integer pageSize;
private Integer merchantId;
}
package cn.com.glsx.dj.strategy.dto.sop;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class CustomerSopTaskRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Long customerInstanceId;
private String customerName;
private String customerPhone;
private String customerStatus;
private String qwGroupName;
private String carSeriesName;
private Date orderHandleTime;
private String confirmBy;
private Date lastExecuteTime;
/**
* 跟进销售顾问(SQL返回原始值,Service层用于confirmBy为空时的回退)
*/
private String advanceUserName;
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailRespDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskPageReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskRespDTO;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
@ApiService(value = "SOP任务客户查询", owner = "chenx")
public interface CustomerSopRemote {
@ApiMethod("分页查询今日待执行触达客户")
@ApiParam(name = "pagination", notes = "分页查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("今日待执行触达客户分页列表")
RpcResponse<RpcPagination<CustomerSopTaskRespDTO>> pageTodayPendingCustomers(RpcPagination<CustomerSopTaskPageReqDTO> pagination);
@ApiMethod("分页查询近7天已触达客户")
@ApiParam(name = "pagination", notes = "分页查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("近7天已触达客户分页列表")
RpcResponse<RpcPagination<CustomerSopTaskRespDTO>> pageLastWeekReachedCustomers(RpcPagination<CustomerSopTaskPageReqDTO> pagination);
@ApiMethod("查询客户今日未触达任务列表")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("今日未触达任务列表")
RpcResponse<List<CustomerSopTaskDetailRespDTO>> listTodayPendingTaskDetails(CustomerSopTaskDetailReqDTO request);
@ApiMethod("查询客户近7天推送任务记录列表")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("近7天推送任务记录列表")
RpcResponse<List<CustomerSopTaskDetailRespDTO>> listLastWeekTaskRecords(CustomerSopTaskDetailReqDTO request);
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.marketing.ActivityProductListReqDTO;
import cn.com.glsx.dj.strategy.dto.marketing.MarketingStageGroupRespDTO;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
@ApiService(value = "营销活动商品查询", owner = "chenx")
public interface MarketingActivityProductRemote {
@ApiMethod("查询当前进行中的营销活动商品列表")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("营销活动商品嵌套列表")
RpcResponse<List<MarketingStageGroupRespDTO>> listActiveProducts(ActivityProductListReqDTO request);
}
...@@ -31,4 +31,9 @@ public interface MarketingActivityCarSeriesMapper extends OreMapper<MarketingAct ...@@ -31,4 +31,9 @@ public interface MarketingActivityCarSeriesMapper extends OreMapper<MarketingAct
* 按活动ID删除所有车系关联(逻辑删除) * 按活动ID删除所有车系关联(逻辑删除)
*/ */
int deleteByActivityId(@Param("activityId") Integer activityId); int deleteByActivityId(@Param("activityId") Integer activityId);
/**
* 按活动ID列表批量查询车系
*/
List<MarketingActivityCarSeries> selectByActivityIds(@Param("activityIds") List<Integer> activityIds);
} }
...@@ -38,4 +38,10 @@ public interface MarketingActivityMapper extends OreMapper<MarketingActivity> { ...@@ -38,4 +38,10 @@ public interface MarketingActivityMapper extends OreMapper<MarketingActivity> {
* 查询需要到期的活动(status IN (0,1,2) AND end_time < NOW()) * 查询需要到期的活动(status IN (0,1,2) AND end_time < NOW())
*/ */
List<Integer> selectExpiredActivityIds(); List<Integer> selectExpiredActivityIds();
/**
* 按商户查询当前进行中的活动
*/
List<MarketingActivity> selectActiveByMerchantId(@Param("merchantId") Integer merchantId,
@Param("now") java.util.Date now);
} }
...@@ -37,6 +37,11 @@ public interface MarketingActivityProductMapper extends OreMapper<MarketingActiv ...@@ -37,6 +37,11 @@ public interface MarketingActivityProductMapper extends OreMapper<MarketingActiv
@Param("carSeriesId") Integer carSeriesId); @Param("carSeriesId") Integer carSeriesId);
/** /**
* 按活动ID列表批量查询商品(含排序)
*/
List<MarketingActivityProduct> selectByActivityIds(@Param("activityIds") List<Integer> activityIds);
/**
* 按门店+商品编码查询有效活动商品 * 按门店+商品编码查询有效活动商品
*/ */
List<MarketingActivityProduct> selectActiveByMerchantIdAndGoodsCodes( List<MarketingActivityProduct> selectActiveByMerchantIdAndGoodsCodes(
......
package cn.com.glsx.dj.strategy.mapper.sop;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailRespDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskRespDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
@Mapper
public interface SopTaskCustomerMapper {
List<CustomerSopTaskRespDTO> selectTodayPendingCustomers(@Param("todayStart") Date todayStart,
@Param("tomorrowStart") Date tomorrowStart,
@Param("merchantId") Integer merchantId);
List<CustomerSopTaskRespDTO> selectLastWeekReachedCustomers(@Param("weekAgo") Date weekAgo,
@Param("tomorrowStart") Date tomorrowStart,
@Param("todayStart") Date todayStart,
@Param("merchantId") Integer merchantId);
List<CustomerSopTaskDetailRespDTO> selectTodayPendingTaskDetails(@Param("customerInstanceId") Integer customerInstanceId,
@Param("merchantId") Integer merchantId,
@Param("todayStart") Date todayStart,
@Param("tomorrowStart") Date tomorrowStart);
List<CustomerSopTaskDetailRespDTO> selectLastWeekTaskRecords(@Param("customerInstanceId") Integer customerInstanceId,
@Param("merchantId") Integer merchantId,
@Param("weekAgo") Date weekAgo,
@Param("tomorrowStart") Date tomorrowStart);
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailRespDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskPageReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskRespDTO;
import cn.com.glsx.dj.strategy.service.SopTaskCustomerService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
@Slf4j
@DubboService(version = "1.0.0")
@RequiredArgsConstructor
public class CustomerSopRemoteImpl implements CustomerSopRemote {
private final SopTaskCustomerService sopTaskCustomerService;
@Override
public RpcResponse<RpcPagination<CustomerSopTaskRespDTO>> pageTodayPendingCustomers(RpcPagination<CustomerSopTaskPageReqDTO> pagination) {
try {
return RpcResponse.success(sopTaskCustomerService.pageTodayPendingCustomers(pagination));
}catch (RpcServiceException e) {
log.error("CustomerSopRemote__pageTodayPendingCustomers__exception", e);
return RpcResponse.error(e);
}
catch (Exception e) {
log.error("CustomerSopRemote__pageTodayPendingCustomers__exception", e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<RpcPagination<CustomerSopTaskRespDTO>> pageLastWeekReachedCustomers(RpcPagination<CustomerSopTaskPageReqDTO> pagination) {
try {
return RpcResponse.success(sopTaskCustomerService.pageLastWeekReachedCustomers(pagination));
}catch (RpcServiceException e) {
log.error("CustomerSopRemote__pageLastWeekReachedCustomers__exception", e);
return RpcResponse.error(e);
}
catch (Exception e) {
log.error("CustomerSopRemote__pageLastWeekReachedCustomers__exception", e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<List<CustomerSopTaskDetailRespDTO>> listTodayPendingTaskDetails(CustomerSopTaskDetailReqDTO request) {
try {
return RpcResponse.success(sopTaskCustomerService.listTodayPendingTaskDetails(request));
}catch (RpcServiceException e) {
log.error("CustomerSopRemote__listTodayPendingTaskDetails__exception", e);
return RpcResponse.error(e);
}
catch (Exception e) {
log.error("CustomerSopRemote__listTodayPendingTaskDetails__exception", e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<List<CustomerSopTaskDetailRespDTO>> listLastWeekTaskRecords(CustomerSopTaskDetailReqDTO request) {
try {
return RpcResponse.success(sopTaskCustomerService.listLastWeekTaskRecords(request));
}catch (RpcServiceException e) {
log.error("CustomerSopRemote__listLastWeekTaskRecords__exception", e);
return RpcResponse.error(e);
}
catch (Exception e) {
log.error("CustomerSopRemote__listLastWeekTaskRecords__exception", e);
return RpcResponse.error(e);
}
}
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.marketing.ActivityProductListReqDTO;
import cn.com.glsx.dj.strategy.dto.marketing.MarketingStageGroupRespDTO;
import cn.com.glsx.dj.strategy.service.MarketingActivityProductQueryService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
@Slf4j
@DubboService(version = "1.0.0")
@RequiredArgsConstructor
public class MarketingActivityProductRemoteImpl implements MarketingActivityProductRemote {
private final MarketingActivityProductQueryService marketingActivityProductQueryService;
@Override
public RpcResponse<List<MarketingStageGroupRespDTO>> listActiveProducts(ActivityProductListReqDTO request) {
try {
return RpcResponse.success(marketingActivityProductQueryService.listActiveProducts(request));
} catch (RpcServiceException e) {
log.error("MarketingActivityProductRemote__listActiveProducts__exception", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("MarketingActivityProductRemote__listActiveProducts__exception", e);
return RpcResponse.error(e);
}
}
}
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.dto.marketing.ActivityProductListReqDTO;
import cn.com.glsx.dj.strategy.dto.marketing.CarSeriesRespDTO;
import cn.com.glsx.dj.strategy.dto.marketing.MarketingStageGroupRespDTO;
import cn.com.glsx.dj.strategy.dto.marketing.ProductRespDTO;
import cn.com.glsx.dj.strategy.mapper.MarketingActivityCarSeriesMapper;
import cn.com.glsx.dj.strategy.mapper.MarketingActivityMapper;
import cn.com.glsx.dj.strategy.mapper.MarketingActivityProductMapper;
import cn.com.glsx.dj.strategy.model.MarketingActivity;
import cn.com.glsx.dj.strategy.model.MarketingActivityCarSeries;
import cn.com.glsx.dj.strategy.model.MarketingActivityProduct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
@RequiredArgsConstructor
public class MarketingActivityProductQueryService {
private final MarketingActivityMapper marketingActivityMapper;
private final MarketingActivityCarSeriesMapper marketingActivityCarSeriesMapper;
private final MarketingActivityProductMapper marketingActivityProductMapper;
public List<MarketingStageGroupRespDTO> listActiveProducts(ActivityProductListReqDTO request) {
// 1. 查询有效活动
List<MarketingActivity> activities = marketingActivityMapper.selectActiveByMerchantId(request.getMerchantId(), new Date());
if (CollectionUtils.isEmpty(activities)) {
return Collections.emptyList();
}
Map<Integer, MarketingActivity> activityMap = activities.stream()
.collect(Collectors.toMap(MarketingActivity::getId, a -> a, (a1, a2) -> a1, LinkedHashMap::new));
List<Integer> activityIds = new ArrayList<>(activityMap.keySet());
// 2. 查询车系
List<MarketingActivityCarSeries> carSeriesList = marketingActivityCarSeriesMapper.selectByActivityIds(activityIds);
// 3. 查询商品(SQL已排序)
List<MarketingActivityProduct> products = marketingActivityProductMapper.selectByActivityIds(activityIds);
if (CollectionUtils.isEmpty(products)) {
return Collections.emptyList();
}
// 4. 构建车系名称映射(按car_series_id去重)
Map<Integer, String> carSeriesNameMap = new LinkedHashMap<>();
for (MarketingActivityCarSeries cs : carSeriesList) {
carSeriesNameMap.putIfAbsent(cs.getCarSeriesId(), cs.getCarSeriesName());
}
// 5. 转换商品模型 -> DTO,并分组
Map<Integer, Map<Integer, List<ProductRespDTO>>> stageMap = new LinkedHashMap<>();
for (MarketingActivityProduct p : products) {
MarketingActivity activity = activityMap.get(p.getActivityId());
if (activity == null) {
continue;
}
int stage = activity.getMarketingStage();
int targetCarSeriesId;
if (activity.getCarSeriesMode() == 0) {
targetCarSeriesId = -1;
} else {
targetCarSeriesId = p.getCarSeriesId() != null ? p.getCarSeriesId() : -1;
}
ProductRespDTO dto = new ProductRespDTO();
BeanUtils.copyProperties(p, dto);
dto.setProductId(p.getId());
dto.setStartTime(activity.getStartTime());
dto.setEndTime(activity.getEndTime());
stageMap.computeIfAbsent(stage, k -> new LinkedHashMap<>())
.computeIfAbsent(targetCarSeriesId, k -> new ArrayList<>())
.add(dto);
}
// 6. 构建响应
List<MarketingStageGroupRespDTO> result = new ArrayList<>();
for (int stage = 0; stage <= 1; stage++) {
Map<Integer, List<ProductRespDTO>> carSeriesProductMap = stageMap.get(stage);
if (carSeriesProductMap == null || carSeriesProductMap.isEmpty()) {
continue;
}
MarketingStageGroupRespDTO stageGroup = new MarketingStageGroupRespDTO();
stageGroup.setMarketingStage(stage);
List<CarSeriesRespDTO> carSeriesRespList = new ArrayList<>();
// 先放"通用"车系
List<ProductRespDTO> commonProducts = carSeriesProductMap.get(-1);
if (!CollectionUtils.isEmpty(commonProducts)) {
CarSeriesRespDTO commonCarSeries = new CarSeriesRespDTO();
commonCarSeries.setCarSeriesId(-1);
commonCarSeries.setCarSeriesName("通用");
commonCarSeries.setProductList(commonProducts);
carSeriesRespList.add(commonCarSeries);
}
// 再放实际车系(按carSeriesId升序)
for (Map.Entry<Integer, String> entry : carSeriesNameMap.entrySet()) {
Integer carSeriesId = entry.getKey();
List<ProductRespDTO> carSeriesProducts = carSeriesProductMap.get(carSeriesId);
if (!CollectionUtils.isEmpty(carSeriesProducts)) {
CarSeriesRespDTO carSeriesResp = new CarSeriesRespDTO();
carSeriesResp.setCarSeriesId(carSeriesId);
carSeriesResp.setCarSeriesName(entry.getValue());
carSeriesResp.setProductList(carSeriesProducts);
carSeriesRespList.add(carSeriesResp);
}
}
stageGroup.setCarSeriesList(carSeriesRespList);
result.add(stageGroup);
}
return result;
}
}
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailRespDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskPageReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskRespDTO;
import cn.com.glsx.dj.strategy.mapper.sop.SopTaskCustomerMapper;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
public class SopTaskCustomerService {
private final SopTaskCustomerMapper sopTaskCustomerMapper;
public RpcPagination<CustomerSopTaskRespDTO> pageTodayPendingCustomers(RpcPagination<CustomerSopTaskPageReqDTO> pagination) {
CustomerSopTaskPageReqDTO condition = pagination.getCondition();
Date todayStart = getTodayStart();
Date tomorrowStart = getTomorrowStart();
Page<CustomerSopTaskRespDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
List<CustomerSopTaskRespDTO> list = sopTaskCustomerMapper.selectTodayPendingCustomers(
todayStart, tomorrowStart, condition.getMerchantId());
// confirmBy fallback
for (CustomerSopTaskRespDTO dto : list) {
dto.setConfirmBy(StringUtils.isBlank(dto.getConfirmBy()) ? dto.getAdvanceUserName() : dto.getConfirmBy());
}
return RpcPagination.copyPage(page);
}
public RpcPagination<CustomerSopTaskRespDTO> pageLastWeekReachedCustomers(RpcPagination<CustomerSopTaskPageReqDTO> pagination) {
CustomerSopTaskPageReqDTO condition = pagination.getCondition();
Date weekAgo = getWeekAgoStart();
Date tomorrowStart = getTomorrowStart();
Date todayStart = getTodayStart();
Page<CustomerSopTaskRespDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
List<CustomerSopTaskRespDTO> list = sopTaskCustomerMapper.selectLastWeekReachedCustomers(
weekAgo, tomorrowStart, todayStart, condition.getMerchantId());
for (CustomerSopTaskRespDTO dto : list) {
dto.setConfirmBy(StringUtils.isBlank(dto.getConfirmBy()) ? dto.getAdvanceUserName() : dto.getConfirmBy());
}
return RpcPagination.copyPage(page);
}
public List<CustomerSopTaskDetailRespDTO> listTodayPendingTaskDetails(CustomerSopTaskDetailReqDTO request) {
Date todayStart = getTodayStart();
Date tomorrowStart = getTomorrowStart();
List<CustomerSopTaskDetailRespDTO> list = sopTaskCustomerMapper.selectTodayPendingTaskDetails(
request.getCustomerInstanceId(), request.getMerchantId(), todayStart, tomorrowStart);
for (CustomerSopTaskDetailRespDTO dto : list) {
dto.setMessageContent(buildMessageContent(dto));
dto.setTaskStatus(0);
dto.setPushResult(null);
}
return list;
}
public List<CustomerSopTaskDetailRespDTO> listLastWeekTaskRecords(CustomerSopTaskDetailReqDTO request) {
Date weekAgo = getWeekAgoStart();
Date tomorrowStart = getTomorrowStart();
List<CustomerSopTaskDetailRespDTO> list = sopTaskCustomerMapper.selectLastWeekTaskRecords(
request.getCustomerInstanceId(), request.getMerchantId(), weekAgo, tomorrowStart);
for (CustomerSopTaskDetailRespDTO dto : list) {
dto.setMessageContent(buildMessageContent(dto));
dto.setTaskStatus(computeTaskStatus(dto));
dto.setPushResult(dto.getExecuteStatus());
}
return list;
}
private String buildMessageContent(CustomerSopTaskDetailRespDTO dto) {
Integer messageType = dto.getMessageType();
if (messageType == null) {
return null;
}
switch (messageType) {
case 1:
return dto.getContent();
case 2:
case 3:
return dto.getMediaIds();
case 4:
return dto.getJumpUrl();
default:
return null;
}
}
private Integer computeTaskStatus(CustomerSopTaskDetailRespDTO dto) {
if (dto.getConfirmStatus() != null && dto.getConfirmStatus() == 2) {
return 2;
}
if (dto.getExecuteStatus() != null && dto.getExecuteStatus() == 3) {
return 3;
}
return 1;
}
private Date getTodayStart() {
return Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
}
private Date getTomorrowStart() {
return Date.from(LocalDate.now().plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
private Date getWeekAgoStart() {
return Date.from(LocalDate.now().minusDays(6).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}
...@@ -30,4 +30,19 @@ ...@@ -30,4 +30,19 @@
WHERE activity_id = #{activityId} WHERE activity_id = #{activityId}
</update> </update>
<select id="selectByActivityIds" resultType="cn.com.glsx.dj.strategy.model.MarketingActivityCarSeries">
SELECT id, activity_id activityId,
brand_id brandId, brand_name brandName,
child_id childId, child_name childName,
car_series_id carSeriesId, car_series_name carSeriesName,
created_by createdBy, created_date createdDate
FROM dj_marketing_activity_car_series
WHERE activity_id IN
<foreach collection="activityIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND deleted_flag = 'N'
ORDER BY car_series_id ASC
</select>
</mapper> </mapper>
...@@ -75,4 +75,20 @@ ...@@ -75,4 +75,20 @@
AND deleted_flag = 'N' AND deleted_flag = 'N'
</select> </select>
<select id="selectActiveByMerchantId" resultMap="BaseResultMap">
SELECT DISTINCT a.id, a.activity_name, a.start_time, a.end_time,
a.activity_tag, a.marketing_stage, a.status, a.car_series_mode,
a.created_by, a.created_date, a.updated_by, a.updated_date, a.deleted_flag
FROM dj_marketing_activity a
INNER JOIN dj_marketing_activity_store s
ON a.id = s.activity_id
AND s.merchant_id = #{merchantId}
AND s.deleted_flag = 'N'
WHERE a.status = 1
AND a.deleted_flag = 'N'
AND a.start_time &lt;= #{now}
AND a.end_time &gt;= #{now}
ORDER BY a.id DESC
</select>
</mapper> </mapper>
...@@ -80,6 +80,24 @@ ...@@ -80,6 +80,24 @@
</if> </if>
</update> </update>
<select id="selectByActivityIds" resultType="cn.com.glsx.dj.strategy.model.MarketingActivityProduct">
SELECT * FROM dj_marketing_activity_product
WHERE activity_id IN
<foreach collection="activityIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND deleted_flag = 'N'
ORDER BY
CASE
WHEN product_type = 0 AND is_main_push = 1 THEN 1
WHEN product_type = 1 AND is_main_push = 1 THEN 2
WHEN product_type = 0 AND is_main_push = 0 THEN 3
WHEN product_type = 1 AND is_main_push = 0 THEN 4
ELSE 5
END,
sort_order ASC
</select>
<select id="selectActiveByMerchantIdAndGoodsCodes" resultType="cn.com.glsx.dj.strategy.model.MarketingActivityProduct"> <select id="selectActiveByMerchantIdAndGoodsCodes" resultType="cn.com.glsx.dj.strategy.model.MarketingActivityProduct">
SELECT p.id, p.activity_id, p.goods_code, p.discount_price, p.sales_incentive SELECT p.id, p.activity_id, p.goods_code, p.discount_price, p.sales_incentive
FROM dj_marketing_activity_product p FROM dj_marketing_activity_product p
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.strategy.mapper.sop.SopTaskCustomerMapper">
<resultMap id="CustomerSopTaskRespMap" type="cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskRespDTO">
<result column="customer_instance_id" property="customerInstanceId"/>
<result column="confirm_by" property="confirmBy"/>
<result column="customer_name" property="customerName"/>
<result column="customer_phone" property="customerPhone"/>
<result column="customer_status" property="customerStatus"/>
<result column="qw_group_name" property="qwGroupName"/>
<result column="car_series_name" property="carSeriesName"/>
<result column="order_handle_time" property="orderHandleTime"/>
<result column="last_execute_time" property="lastExecuteTime"/>
<result column="advance_user_name" property="advanceUserName"/>
</resultMap>
<resultMap id="CustomerSopTaskDetailRespMap" type="cn.com.glsx.dj.strategy.dto.sop.CustomerSopTaskDetailRespDTO">
<result column="task_id" property="taskId"/>
<result column="strategy_id" property="strategyId"/>
<result column="action_type" property="actionType"/>
<result column="message_type" property="messageType"/>
<result column="content" property="content"/>
<result column="media_ids" property="mediaIds"/>
<result column="jump_url" property="jumpUrl"/>
<result column="confirm_by" property="confirmBy"/>
<result column="confirm_status" property="confirmStatus"/>
<result column="execute_status" property="executeStatus"/>
</resultMap>
<!-- 接口一:查询今日待执行触达客户 -->
<select id="selectTodayPendingCustomers" resultMap="CustomerSopTaskRespMap">
SELECT
t.customer_instance_id,
t.confirm_by,
ci.customer_phone,
ci.customer_name,
ci.customer_status,
ci.qw_group_name,
ci.car_series_name,
ci.order_handle_time,
ci.advance_user_name
FROM sop_strategy_task t
INNER JOIN dj_car_life_customer_info ci ON t.customer_instance_id = ci.id
WHERE t.trigger_time >= #{todayStart}
AND t.trigger_time &lt; #{tomorrowStart}
AND t.confirm_status = 0
AND t.execute_status = 0
AND t.deleted_flag = 'N'
AND ci.deleted_flag = 'N'
AND ci.merchant_id = #{merchantId}
GROUP BY t.customer_instance_id
ORDER BY ci.id DESC
</select>
<!-- 接口二:查询近7天已触达客户 -->
<select id="selectLastWeekReachedCustomers" resultMap="CustomerSopTaskRespMap">
SELECT
t1.customer_instance_id,
t1.confirm_by,
t1.execute_time AS last_execute_time,
ci.customer_phone,
ci.customer_name,
ci.customer_status,
ci.qw_group_name,
ci.car_series_name,
ci.order_handle_time,
ci.advance_user_name
FROM sop_strategy_task t1
LEFT JOIN sop_strategy_task t2
ON t1.customer_instance_id = t2.customer_instance_id
AND t1.execute_time &lt; t2.execute_time
AND t2.execute_time >= #{weekAgo}
AND t2.execute_time &lt; #{tomorrowStart}
AND t2.confirm_status IN (-1, 1, 2)
AND t2.execute_status IN (2, 3)
AND t2.deleted_flag = 'N'
LEFT JOIN sop_strategy_task t3
ON t1.customer_instance_id = t3.customer_instance_id
AND t3.trigger_time >= #{todayStart}
AND t3.trigger_time &lt; #{tomorrowStart}
AND t3.confirm_status = 0
AND t3.execute_status = 0
AND t3.deleted_flag = 'N'
INNER JOIN dj_car_life_customer_info ci ON t1.customer_instance_id = ci.id
WHERE t1.execute_time >= #{weekAgo}
AND t1.execute_time &lt; #{tomorrowStart}
AND t1.confirm_status IN (-1, 1, 2)
AND t1.execute_status IN (2, 3)
AND t1.deleted_flag = 'N'
AND t2.id IS NULL
AND t3.id IS NULL
AND ci.deleted_flag = 'N'
AND ci.merchant_id = #{merchantId}
ORDER BY ci.id DESC
</select>
<!-- 接口三:查询客户今日未触达任务明细 -->
<select id="selectTodayPendingTaskDetails" resultMap="CustomerSopTaskDetailRespMap">
SELECT
t.id AS task_id,
t.strategy_id,
t.confirm_by,
a.action_type,
a.message_type,
a.content,
a.media_ids,
a.jump_url
FROM dj_car_life_customer_info ci
INNER JOIN sop_strategy_task t ON ci.id = t.customer_instance_id
INNER JOIN sop_strategy_action a ON a.strategy_id = t.strategy_id AND a.branch_id = t.branch_id
WHERE ci.id = #{customerInstanceId}
AND ci.merchant_id = #{merchantId}
AND ci.deleted_flag = 'N'
AND t.trigger_time >= #{todayStart}
AND t.trigger_time &lt; #{tomorrowStart}
AND t.confirm_status = 0
AND t.execute_status = 0
AND t.deleted_flag = 'N'
AND a.deleted_flag = 'N'
ORDER BY t.execute_time DESC
</select>
<!-- 接口四:查询客户近7天推送任务记录 -->
<select id="selectLastWeekTaskRecords" resultMap="CustomerSopTaskDetailRespMap">
SELECT
t.id AS task_id,
t.strategy_id,
t.confirm_by,
t.confirm_status,
t.execute_status,
a.action_type,
a.message_type,
a.content,
a.media_ids,
a.jump_url
FROM dj_car_life_customer_info ci
INNER JOIN sop_strategy_task t ON ci.id = t.customer_instance_id
INNER JOIN sop_strategy_action a ON a.strategy_id = t.strategy_id AND a.branch_id = t.branch_id
WHERE ci.id = #{customerInstanceId}
AND ci.merchant_id = #{merchantId}
AND ci.deleted_flag = 'N'
AND t.execute_time >= #{weekAgo}
AND t.execute_time &lt; #{tomorrowStart}
AND t.confirm_status IN (-1, 1, 2)
AND t.execute_status IN (2, 3)
AND t.deleted_flag = 'N'
AND a.deleted_flag = 'N'
ORDER BY t.execute_time DESC
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!