提交 eabe9622 作者: 沈振路

Merge branch 'customer_service_SZlu'

<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="80" name="Java" />
</Languages>
</inspection_tool>
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
......
package com.yaoyaozw.customer.constants;
import java.util.regex.Pattern;
/**
* @author darker
* @date 2022/9/20 14:54
......@@ -22,4 +25,10 @@ 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;
public static final Pattern NUMBER_COMPILE = Pattern.compile("[\\d]");
}
......@@ -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;
......@@ -27,7 +30,7 @@ public class CrowdPackageConditionDTO implements Serializable {
@ApiModelProperty("设置的条件值")
private String conditionValue;
@ApiModelProperty("设置的条件值")
@ApiModelProperty("多选选项")
private List<String> multipleOptions;
}
package com.yaoyaozw.customer.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import org.springframework.stereotype.Repository;
......@@ -8,6 +9,7 @@ import org.springframework.stereotype.Repository;
* @author darker
* @date 2022/9/21 15:08
*/
@DS("material")
@Repository
public interface CrowdPackageConditionMatchMapper extends BaseMapper<CrowdPackageConditionMatch> {
public interface MaterialCrowdConditionMatchMapper extends BaseMapper<CrowdPackageConditionMatch> {
}
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());
}
}
}
......@@ -2,7 +2,7 @@ package com.yaoyaozw.customer.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.mapper.CrowdPackageConditionMatchMapper;
import com.yaoyaozw.customer.mapper.MaterialCrowdConditionMatchMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import org.springframework.stereotype.Service;
......@@ -11,5 +11,5 @@ import org.springframework.stereotype.Service;
* @date 2022/9/21 15:09
*/
@Service
public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<CrowdPackageConditionMatchMapper, CrowdPackageConditionMatch> implements CrowdPackageConditionMatchService {
public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialCrowdConditionMatchMapper, CrowdPackageConditionMatch> implements CrowdPackageConditionMatchService {
}
......@@ -3,6 +3,9 @@ package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult;
......@@ -49,8 +52,6 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
@Autowired
private TokenManager tokenManager;
@Autowired
private SnowflakeComponent snowflakeComponent;
@Autowired
private CrowdPackageConditionMatchService matchService;
......@@ -60,32 +61,35 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
boolean isCreate = ObjectUtil.isNull(id);
// 获取操作人
Long userId = tokenManager.getUserIdFromToken();
id = ObjectUtil.isNull(id) ? snowflakeComponent.snowflakeId() : id;
CrowdPackage crowdPackage = new CrowdPackage(id, name);
crowdPackage.handleInfo(new Date(), userId, isCreate);
if (ObjectUtil.isNotNull(name)) {
// 判断是否有重名
QueryWrapper<CrowdPackage> nameRepeatWrapper = new QueryWrapper<CrowdPackage>().eq("package_name", name).ne("id", id);
int count = super.count(nameRepeatWrapper);
if (count != 0) {
LOCAL_LOG.info("人群包名: '{}' 已存在", name);
return new GenericsResult<>(false, "人群包名已存在!");
}
}
// 执行保存
return super.saveOrUpdate(crowdPackage) ? new GenericsResult<>(new CrowdPackageCommonIdVO(id, null)) : new GenericsResult<>(false, "新增人群包失败!");
boolean result = super.saveOrUpdate(crowdPackage);
// TODO: 2022/9/26 添加人群包人群的更新
return result ? new GenericsResult<>(new CrowdPackageCommonIdVO(crowdPackage.getId(), null)) : new GenericsResult<>(false, "新增人群包失败!");
}
@Override
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);
}
crowdPackageCommonIdVo.setPackageId(packageId);
// 构造关联表的相关数据
CrowdPackageConditionMatch match = new CrowdPackageConditionMatch();
match.setPackageId(packageId);
match.setId(conditionDto.getMatchId());
match.setPackageId(crowdPackageCommonIdVo.getPackageId());
match.setConditionId(conditionDto.getConditionId());
// 构造条件数据
try {
......@@ -96,20 +100,29 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
}
crowdPackageCommonIdVo.setConditionDescription(match.getOperatorDescription());
// 保存关联关系
long matchId = snowflakeComponent.snowflakeId();
match.setId(matchId);
boolean matchSaveResult = matchService.save(match);
boolean matchSaveResult = matchService.saveOrUpdate(match);
if (!matchSaveResult) {
return new GenericsResult<>(false, "向人群包保存条件失败!");
}
// 构造返回数据
crowdPackageCommonIdVo.setLinkedId(matchId);
crowdPackageCommonIdVo.setLinkedId(match.getId());
return new GenericsResult<>(crowdPackageCommonIdVo);
}
@Override
public GenericsResult<CrowdPackageDetailVO> getPackageInfo(Long id) {
return null;
LOCAL_LOG.info("获取详情");
CrowdPackage byId = super.getById(id);
if (ObjectUtil.isNull(byId)) {
return new GenericsResult<>(false, "无法获取主体数据");
}
CrowdPackageDetailVO vo = new CrowdPackageDetailVO(id, byId.getPackageName());
// 获取条件数据
List<CrowdPackageConditionMatch> conditionMatchList = matchService.list(new QueryWrapper<CrowdPackageConditionMatch>().eq("package_id", id));
JSONArray jsonArray = JSONUtil.parseArray(conditionMatchList);
List<CrowdPackageConditionMatchVO> parseConditionList = jsonArray.toList(CrowdPackageConditionMatchVO.class);
vo.setConditionList(parseConditionList);
return new GenericsResult<>(vo);
}
@Override
......@@ -123,7 +136,7 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
@Override
public BaseResult removeCrowdPackage(Long id) {
return super.removeById(id) ? new BaseResult().error("删除异常!") : new BaseResult().success();
return super.removeById(id) ? new BaseResult().success() : new BaseResult().error("删除异常!");
}
@Override
......@@ -134,14 +147,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);
}
......@@ -177,7 +193,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("无法获取条件");
......@@ -211,16 +227,30 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
*/
private void handleCompareType(CrowdPackageConditionMatch match, CrowdPackageConditionDTO conditionDto, CrowdPackageCondition conditionInfo){
LOCAL_LOG.info("是需要比较的类型");
CrowdPackageConditionEnum operatorInfo = CrowdPackageConditionEnum.getInfoByOperator(conditionDto.getCompareOperator());
String compareOperator = conditionDto.getCompareOperator();
String conditionValue = conditionDto.getConditionValue();
LOCAL_LOG.info("比较符: {}; 条件值: {}", compareOperator, conditionValue);
match.setConditionOperator(compareOperator);
match.setOperatorValue(conditionValue);
CrowdPackageConditionEnum operatorInfo = CrowdPackageConditionEnum.getInfoByOperator(compareOperator);
if (ObjectUtil.isNull(operatorInfo)) {
throw new RuntimeException("无法获取比较类型");
}
String expression = conditionInfo.getConditionKey() + operatorInfo.getMeaning() + conditionDto.getConditionValue();
LOCAL_LOG.info("表达式拼接结果: {}", expression);
String description = conditionInfo.getConditionName() + operatorInfo.getDescription() + conditionDto.getConditionValue();
String description = conditionInfo.getConditionName() + operatorInfo.getDescription() + conditionValue;
LOCAL_LOG.info("条件描述: {}", description);
// 判断是不是数字
if (!CrowdPackageCommonConstant.NUMBER_COMPILE.matcher(conditionValue).matches()) {
// 不是数字,添加引号,否则sql报错
conditionValue = "'" + conditionValue + "'";
}
String expression = conditionInfo.getConditionKey() + " " + operatorInfo.getMeaning() + " " + conditionValue;
LOCAL_LOG.info("表达式拼接结果: {}", expression);
match.setOperatorExpression(expression);
match.setOperatorDescription(description);
}
......@@ -234,14 +264,21 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
private void handleRangeIn(CrowdPackageConditionMatch match, CrowdPackageConditionDTO conditionDto, CrowdPackageCondition conditionInfo) {
// 范围条件
LOCAL_LOG.info("是范围条件");
CrowdPackageConditionEnum operatorInfo = CrowdPackageConditionEnum.getInfoByOperator(conditionDto.getCompareOperator());
if (ObjectUtil.isNull(operatorInfo)) {
throw new RuntimeException("无法获取比较类型");
}
List<String> multipleOptions = conditionDto.getMultipleOptions();
StringBuilder expressionBuilder = new StringBuilder("in (");
if (CollectionUtil.isEmpty(multipleOptions)) {
return;
}
StringBuilder expressionBuilder = new StringBuilder(conditionInfo.getConditionKey() + " in (");
int location = 1;
for (String multipleOption : multipleOptions) {
boolean isLast = location == multipleOptions.size();
expressionBuilder.append("'").append(multipleOption).append("'");
if (!isLast) {
// 给非最后一个元素拼接逗号
expressionBuilder.append(", ");
}
location += 1;
}
expressionBuilder.append(")");
// 表达式
......@@ -253,9 +290,12 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
if (ObjectUtil.isNull(responseVo) || CollectionUtil.isEmpty(responseVo.getOptionList())) {
throw new RuntimeException("找不到条件的选项");
}
StringBuilder descriptionBuilder = new StringBuilder(conditionInfo.getConditionName() + " 范围: ");
StringBuilder descriptionBuilder = new StringBuilder(conditionInfo.getConditionName() + "范围: ");
for (CommonOptionResponseVO commonOptionResponseVo : responseVo.getOptionList()) {
descriptionBuilder.append(commonOptionResponseVo.getName()).append("/");
// 如果选中了这个选项,则拼接其name
if (multipleOptions.contains(commonOptionResponseVo.getKey())) {
descriptionBuilder.append(commonOptionResponseVo.getName()).append("/");
}
}
String description = descriptionBuilder.toString();
LOCAL_LOG.info("条件描述: {}", description);
......@@ -272,6 +312,46 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
*/
private void handleGroupOr(CrowdPackageConditionMatch match, CrowdPackageConditionDTO conditionDto, CrowdPackageCondition conditionInfo) {
// 分组求并条件
LOCAL_LOG.info("是分组求并条件");
List<String> multipleOptions = conditionDto.getMultipleOptions();
if (CollectionUtil.isEmpty(multipleOptions)) {
return;
}
// 获取该条件的所有的条件
ConditionOptionResponseVO responseVo = this.getOptions(conditionInfo.getId()).getData();
if (ObjectUtil.isNull(responseVo) || CollectionUtil.isEmpty(responseVo.getOptionList())) {
throw new RuntimeException("找不到条件的选项");
}
// 构造条件描述
StringBuilder descriptionBuilder = new StringBuilder(conditionInfo.getConditionName() + "取档: ");
for (CommonOptionResponseVO commonOptionResponseVo : responseVo.getOptionList()) {
// 如果选中了这个选项,则拼接其name
if (multipleOptions.contains(commonOptionResponseVo.getKey())) {
descriptionBuilder.append(commonOptionResponseVo.getName()).append("/");
}
}
String description = descriptionBuilder.toString();
LOCAL_LOG.info("条件描述: {}", description);
StringBuilder expressionBuilder = new StringBuilder("(");
LOCAL_LOG.info("拼接表达式");
int location = 1;
for (String option : multipleOptions) {
boolean isLast = location == multipleOptions.size();
expressionBuilder.append("(").append(option).append(")");
if (!isLast) {
// 给非最后一个元素后面拼接 or
expressionBuilder.append(" or ");
}
location += 1;
}
expressionBuilder.append(")");
String expression = expressionBuilder.toString();
LOCAL_LOG.info("表达式拼接结果: {}", expression);
match.setOperatorDescription(description);
match.setOperatorExpression(expression);
}
......
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;
import java.io.Serializable;
/**
* @author darker
* @date 2022/9/22 18:09
*/
@Data
@ApiModel("人群包条件匹配实体")
public class CrowdPackageConditionMatchVO implements Serializable {
/**
* 主键
*/
@ApiModelProperty("匹配主键")
private Long id;
/**
* 人群包ID
*/
@ApiModelProperty("人群包ID")
private Long packageId;
/**
* 条件表主键ID
*/
@ApiModelProperty("条件表主键ID")
private Long conditionId;
/**
* 条件描述
*/
@ApiModelProperty("条件描述")
private String operatorDescription;
public String getConditionId() {
if (ObjectUtil.isNull(this.conditionId)) {
return null;
}
return conditionId.toString();
}
}
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
......@@ -15,6 +16,7 @@ import java.util.List;
*/
@Data
@ApiModel("人群包详情页回显实体")
@NoArgsConstructor
public class CrowdPackageDetailVO implements Serializable {
@ApiModelProperty("人群包主键")
......@@ -25,6 +27,10 @@ public class CrowdPackageDetailVO implements Serializable {
private String packageName;
@ApiModelProperty("已配置的人群包条件")
private List<CrowdPackageConditionVO> conditionList;
private List<CrowdPackageConditionMatchVO> conditionList;
public CrowdPackageDetailVO(Long packageId, String packageName) {
this.packageId = packageId;
this.packageName = packageName;
}
}
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论