渠道链接业务修改(未测)
parent
55d1d8459e
commit
4cafa95965
@ -0,0 +1,20 @@
|
||||
package com.baiye.modules.distribute.converter;
|
||||
|
||||
import com.baiye.modules.distribute.dto.PushLinkDTO;
|
||||
import com.baiye.modules.distribute.entity.PushLinkEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface PushLinkConverter {
|
||||
|
||||
PushLinkConverter INSTANCE = Mappers.getMapper(PushLinkConverter.class);
|
||||
|
||||
/**
|
||||
* 修改DTO 转 PO
|
||||
* @param dto 修改DTO
|
||||
* @return ClueEntity PO
|
||||
*/
|
||||
PushLinkEntity dtoToPo(PushLinkDTO dto);
|
||||
|
||||
}
|
@ -1,13 +1,40 @@
|
||||
package com.baiye.modules.distribute.mapper;
|
||||
|
||||
import com.baiye.domain.PageParam;
|
||||
import com.baiye.domain.PageResult;
|
||||
import com.baiye.extend.mybatis.plus.conditions.query.LambdaAliasQueryWrapperX;
|
||||
import com.baiye.extend.mybatis.plus.mapper.ExtendMapper;
|
||||
import com.baiye.extend.mybatis.plus.toolkit.WrappersX;
|
||||
import com.baiye.modules.distribute.entity.PushLinkEntity;
|
||||
import com.baiye.modules.distribute.qo.PushLinkQo;
|
||||
import com.baiye.modules.distribute.vo.PushLinkVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface PushLinkMapper extends ExtendMapper<PushLinkEntity> {
|
||||
|
||||
default PageResult<PushLinkVO> queryPage(PageParam pageParam, PushLinkQo qo) {
|
||||
IPage<PushLinkVO> page = this.prodPage(pageParam);
|
||||
|
||||
LambdaAliasQueryWrapperX<PushLinkEntity> wrapperX = WrappersX.lambdaAliasQueryX(PushLinkEntity.class);
|
||||
wrapperX.likeIfPresent(PushLinkEntity::getName, qo.getName())
|
||||
.eqIfPresent(PushLinkEntity::getCreateBy, qo.getCreateBy())
|
||||
.eqIfPresent(PushLinkEntity::getChannelType, qo.getChannelType());
|
||||
|
||||
if (StringUtils.isNotBlank(qo.getStartTime()) && StringUtils.isNotBlank(qo.getEndTime())) {
|
||||
wrapperX.between(PushLinkEntity::getCreateTime, qo.getStartTime(), qo.getEndTime());
|
||||
}
|
||||
this.selectByPage(page, wrapperX);
|
||||
return new PageResult<>(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
IPage<PushLinkVO> selectByPage(IPage<PushLinkVO> page, @Param(Constants.WRAPPER) Wrapper<PushLinkEntity> wrapper);
|
||||
|
||||
default PushLinkEntity selectByAppKey(String appKey) {
|
||||
return this.selectOne(Wrappers.<PushLinkEntity>lambdaQuery().eq(PushLinkEntity::getAppKey, appKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,73 +1,102 @@
|
||||
package com.baiye.modules.distribute.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baiye.domain.PageParam;
|
||||
import com.baiye.domain.PageResult;
|
||||
import com.baiye.exception.BadRequestException;
|
||||
import com.baiye.extend.mybatis.plus.service.impl.ExtendServiceImpl;
|
||||
import com.baiye.modules.distribute.converter.PushLinkConverter;
|
||||
import com.baiye.modules.distribute.dto.PushLinkDTO;
|
||||
import com.baiye.modules.distribute.entity.ClueRecordEntity;
|
||||
import com.baiye.modules.distribute.entity.PushLinkEntity;
|
||||
import com.baiye.modules.distribute.mapper.PushLinkMapper;
|
||||
import com.baiye.modules.distribute.service.ClueRecordService;
|
||||
import com.baiye.modules.distribute.service.DistributeTaskService;
|
||||
import com.baiye.modules.distribute.qo.PushLinkQo;
|
||||
import com.baiye.modules.distribute.service.PushLinkService;
|
||||
import com.baiye.modules.distribute.vo.PushLinkVO;
|
||||
import com.baiye.properties.UrlsProperties;
|
||||
import com.baiye.security.util.SecurityUtils;
|
||||
import com.baiye.util.AppUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PushLinkServiceImpl extends ExtendServiceImpl<PushLinkMapper, PushLinkEntity> implements PushLinkService {
|
||||
|
||||
private final ClueRecordService clueRecordService;
|
||||
|
||||
private final UrlsProperties urlsProperties;
|
||||
|
||||
private final DistributeTaskService distributeTaskService;
|
||||
@Override
|
||||
public PageResult<PushLinkVO> queryPage(PageParam pageParam, PushLinkQo qo) {
|
||||
PageResult<PushLinkVO> pushLinkVOPageResult = baseMapper.queryPage(pageParam, qo);
|
||||
|
||||
List<PushLinkVO> records = pushLinkVOPageResult.getRecords();
|
||||
if (CollUtil.isNotEmpty(records)){
|
||||
for (PushLinkVO record : records) {
|
||||
if (StringUtils.isNotBlank(record.getChannelIdentifying())){
|
||||
record.setChannelIdentifyingList(JSONUtil.parseArray(record.getChannelIdentifying()));
|
||||
record.setChannelIdentifying("");
|
||||
}
|
||||
}
|
||||
}
|
||||
return pushLinkVOPageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String add(PushLinkDTO pushLinkDTO) {
|
||||
String dtoName = pushLinkDTO.getName();
|
||||
Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String name = pushLinkDTO.getName();
|
||||
Integer channelType = pushLinkDTO.getChannelType();
|
||||
String dbPushUrl = urlsProperties.getDbPushUrl();
|
||||
Long userId = pushLinkDTO.getUserId();
|
||||
PushLinkEntity pushLinkEntity = PushLinkConverter.INSTANCE.dtoToPo(pushLinkDTO);
|
||||
|
||||
PushLinkEntity linkEntity = baseMapper.selectOne(new LambdaQueryWrapper<PushLinkEntity>()
|
||||
.eq(PushLinkEntity::getName, name)
|
||||
.eq(PushLinkEntity::getCreateBy, currentUserId));
|
||||
if (ObjectUtil.isNotNull(linkEntity)) throw new BadRequestException("渠道名称重复,请重新输入");
|
||||
|
||||
PushLinkEntity pushLinkEntity = baseMapper.selectOne(new LambdaQueryWrapper<PushLinkEntity>().eq(PushLinkEntity::getUserId, userId));
|
||||
if (pushLinkEntity != null) {
|
||||
dbPushUrl = dbPushUrl.concat(pushLinkEntity.getAppKey()).concat("?dataType=detail&encrypt=1");
|
||||
}
|
||||
else {
|
||||
// 生成的appKey标识重复,重新生成
|
||||
String appKey = AppUtils.getAppId();
|
||||
while (true) {
|
||||
PushLinkEntity entity = baseMapper.selectOne(new LambdaQueryWrapper<PushLinkEntity>().eq(PushLinkEntity::getAppKey, appKey));
|
||||
if (entity == null) break;
|
||||
if (ObjectUtil.isNull(entity)) break;
|
||||
appKey = AppUtils.getAppId();
|
||||
}
|
||||
|
||||
// 大坝推送接口参数拼接
|
||||
if (channelType == 0){
|
||||
dbPushUrl = dbPushUrl.concat(appKey).concat("?dataType=detail&encrypt=1");
|
||||
// 创建记录(任务)
|
||||
ClueRecordEntity clueRecordEntity = clueRecordService.addDefaultRecordService(SecurityUtils.getCurrentUserId(), dtoName, dtoName);
|
||||
}else if (channelType == 1){
|
||||
// 飞鱼推送接口 TODO
|
||||
}
|
||||
|
||||
Long recordId = clueRecordEntity.getClueRecordId();
|
||||
PushLinkEntity saveEntity = new PushLinkEntity();
|
||||
saveEntity.setUserId(userId);
|
||||
saveEntity.setAppKey(appKey);
|
||||
saveEntity.setName(dtoName);
|
||||
saveEntity.setClueRecordId(recordId);
|
||||
baseMapper.insert(saveEntity);
|
||||
// 检验数据--创建默认的执行任务
|
||||
distributeTaskService.inspectUserTask(Collections.singletonList(userId));
|
||||
distributeTaskService.addDefaultTask(dtoName, dbPushUrl, recordId.toString(), SecurityUtils.getCurrentUserId(), userId);
|
||||
pushLinkEntity.setAppKey(appKey);
|
||||
pushLinkEntity.setChannelUrl(dbPushUrl);
|
||||
if (CollUtil.isNotEmpty(pushLinkDTO.getChannelIdentifyingList())){
|
||||
pushLinkEntity.setChannelIdentifying(JSONUtil.toJsonStr(pushLinkDTO.getChannelIdentifyingList()));
|
||||
}
|
||||
baseMapper.insert(pushLinkEntity);
|
||||
return dbPushUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(PushLinkDTO pushLinkDTO) {
|
||||
PushLinkEntity pushLinkEntity = PushLinkConverter.INSTANCE.dtoToPo(pushLinkDTO);
|
||||
if (CollUtil.isNotEmpty(pushLinkDTO.getChannelIdentifyingList())){
|
||||
pushLinkEntity.setChannelIdentifying(JSONUtil.toJsonStr(pushLinkDTO.getChannelIdentifyingList()));
|
||||
}
|
||||
return SqlHelper.retBool(baseMapper.updateById(pushLinkEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushLinkEntity getByAppKey(String appKey) {
|
||||
return baseMapper.selectByAppKey(appKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
<?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="com.baiye.modules.distribute.mapper.PushLinkMapper">
|
||||
<sql id="Base_Alias_Column_List">
|
||||
pl.id,
|
||||
pl.name,
|
||||
pl.app_key,
|
||||
pl.channel_identifying,
|
||||
pl.channel_url,
|
||||
pl.channel_type,
|
||||
pl.status,
|
||||
pl.create_time,
|
||||
pl.create_by
|
||||
</sql>
|
||||
|
||||
<select id="selectByPage" resultType="com.baiye.modules.distribute.vo.PushLinkVO">
|
||||
SELECT
|
||||
<include refid="Base_Alias_Column_List"/>
|
||||
FROM
|
||||
tb_push_link pl
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue