提交 81c4d132 作者: 沈振路

人群包配置、接口

上级 5db358f7
......@@ -22,4 +22,8 @@ public class CrowdPackageCommonConstant {
public static final String GROUP_OR = "group_or";
public static final Integer STATIC_CONDITION = 1;
public static final Integer NUN_STATIC_CONDITION = 0;
}
......@@ -29,7 +29,7 @@ public class CrowdPackageController {
@ApiOperation("新增人群包")
@GetMapping("/insertPackage")
public GenericsResult<CrowdPackageCommonIdVO> insertCrowdPackage(@RequestParam Long id, @RequestParam String name) {
public GenericsResult<CrowdPackageCommonIdVO> insertCrowdPackage(@RequestParam(required = false) Long id, @RequestParam(required = false) String name) {
return crowdPackageService.insertCrowdPackage(id, name);
}
......
......@@ -15,6 +15,9 @@ import java.util.List;
@ApiModel("人群包条件保存实体")
public class CrowdPackageConditionDTO implements Serializable {
@ApiModelProperty("关联Id")
private Long matchId;
@ApiModelProperty("条件Id")
private Long conditionId;
......
package com.yaoyaozw.customer.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yaoyaozw.customer.entity.CrowdPackageCondition;
import org.springframework.stereotype.Repository;
......@@ -8,6 +9,7 @@ import org.springframework.stereotype.Repository;
* @author darker
* @date 2022/9/20 14:46
*/
@DS("material")
@Repository
public interface MaterialCrowdPackageConditionMapper extends BaseMapper<CrowdPackageCondition> {
}
package com.yaoyaozw.customer.schedules;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.dto.crowd.CrowdPackageQueryDTO;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CrowdPackageService;
import com.yaoyaozw.customer.vo.crowd.CrowdPackageListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author darker
* @date 2022/9/23 10:18
*/
@Component
public class CrowdPackageSchedule {
private final static Logger LOCAL_LOG = LoggerFactory.getLogger(CrowdPackageSchedule.class);
@Autowired
private CrowdPackageService crowdPackageService;
@Autowired
private CrowdPackageConditionMatchService matchService;
/**
* 计算人群包用户人数
*/
// @Scheduled(cron = "0 0 10 * * ?")
public void calCrowdPackageHumanNum() {
LOCAL_LOG.info("获取人群包列表");
CrowdPackageQueryDTO crowdPackageQuery = new CrowdPackageQueryDTO();
List<CrowdPackageListVO> crowdPackageList = crowdPackageService.pageList(crowdPackageQuery).getData();
// 没有人群包
if (CollectionUtil.isEmpty(crowdPackageList)) {
LOCAL_LOG.info("未找到符合条件的人群包");
return;
}
LOCAL_LOG.info("共获得人群包 {} 条", crowdPackageList.size());
// 遍历人群包,依次处理
for (CrowdPackageListVO crowdPackageVo : crowdPackageList) {
LOCAL_LOG.info("当前处理人群包: 【{}】", crowdPackageVo.getPackageName());
// 获取人群包下的条件
List<CrowdPackageConditionMatch> packageConditionList = matchService.list(new QueryWrapper<CrowdPackageConditionMatch>().eq("package_id", crowdPackageVo.getId()));
LOCAL_LOG.info("共获取人群包下条件 {} 条", packageConditionList.size());
}
}
}
......@@ -72,20 +72,11 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
public GenericsResult<CrowdPackageCommonIdVO> insertConditionIntoPackage(CrowdPackageConditionDTO conditionDto) {
CrowdPackageCommonIdVO crowdPackageCommonIdVo = new CrowdPackageCommonIdVO();
Long packageId = conditionDto.getPackageId();
if (ObjectUtil.isNull(packageId)) {
// 人群包内的第一个条件,先创建人群包,获取主键
GenericsResult<CrowdPackageCommonIdVO> insertResult = this.insertCrowdPackage(null, null);
if (!insertResult.getSuccess()) {
// 如果保存人群包失败
return insertResult;
}
crowdPackageCommonIdVo = insertResult.getData();
} else {
// 不是第一条条件,已经生成人群包
crowdPackageCommonIdVo.setPackageId(packageId);
}
// 构造关联表的相关数据
CrowdPackageConditionMatch match = new CrowdPackageConditionMatch();
match.setId(conditionDto.getMatchId());
match.setPackageId(crowdPackageCommonIdVo.getPackageId());
match.setConditionId(conditionDto.getConditionId());
// 构造条件数据
......@@ -97,7 +88,7 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
}
crowdPackageCommonIdVo.setConditionDescription(match.getOperatorDescription());
// 保存关联关系
boolean matchSaveResult = matchService.save(match);
boolean matchSaveResult = matchService.saveOrUpdate(match);
if (!matchSaveResult) {
return new GenericsResult<>(false, "向人群包保存条件失败!");
}
......@@ -143,14 +134,17 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
@Override
public GenericsResult<List<CrowdPackageConditionVO>> getAllConditions() {
LOCAL_LOG.info("获取条件列表");
List<CrowdPackageCondition> conditionList = conditionService.list();
// 将结果转换成返回结果
LOCAL_LOG.info("转换条件数据");
List<CrowdPackageConditionVO> conditionVoList = conditionList.stream().map(item -> {
CrowdPackageConditionVO vo = new CrowdPackageConditionVO();
BeanUtils.copyProperties(item, vo);
return vo;
}).collect(Collectors.toList());
// 封装返回结果
LOCAL_LOG.info("返回条件结果");
return new GenericsResult<>(conditionVoList);
}
......@@ -186,7 +180,7 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
* @param conditionDto 条件dto
*/
private void constructOperator(CrowdPackageConditionMatch match, CrowdPackageConditionDTO conditionDto){
// TODO: 2022/9/21 构造运算表达式
LOCAL_LOG.info("构造运算表达式");
CrowdPackageCondition conditionInfo = conditionService.getById(conditionDto.getConditionId());
if (ObjectUtil.isNull(conditionInfo)) {
throw new RuntimeException("无法获取条件");
......
package com.yaoyaozw.customer.vo.crowd;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -39,4 +40,10 @@ public class CrowdPackageConditionMatchVO implements Serializable {
@ApiModelProperty("条件描述")
private String operatorDescription;
public String getConditionId() {
if (ObjectUtil.isNull(this.conditionId)) {
return null;
}
return conditionId.toString();
}
}
......@@ -26,6 +26,9 @@ public class CrowdPackageListVO implements Serializable {
@ApiModelProperty("人群包中的人数")
private Integer numOfCrowdInPackage;
@ApiModelProperty("最后一次统计时间")
private Integer lastCountTime;
@ApiModelProperty("创建时间")
private String createTime;
......
......@@ -18,6 +18,7 @@
<select id="getPageList" resultType="com.yaoyaozw.customer.vo.crowd.CrowdPackageListVO">
select
cpm.id, cpm.package_name as packageName,
cpm.crowd_num as numOfCrowdInPackage, cpm.last_count_time as lastCountTime,
cpm.create_time as createTime, cpm.modified_time as modifiedTime,
cau.nick_name as createUser, mau.nick_name as modifiedUser
from crowd_package_main cpm
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论