Skip to content

Commit

Permalink
add reach api
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnerliu committed Jun 14, 2022
1 parent 94c2fd1 commit d9307d3
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import org.apache.ibatis.annotations.Param;

import cn.archliu.horus.infr.domain.reach.entity.HorusReachChannel;

/**
Expand All @@ -14,4 +16,21 @@
*/
public interface HorusReachChannelMapper extends BaseMapper<HorusReachChannel> {

/**
* 触达通道添加接收人
*
* @param channelId
* @param receiverId
*/
void addChannelReceiver(@Param("channelId") Long channelId, @Param("receiverId") Long receiverId);

/**
* 检查该触达通道是否存在该接收人
*
* @param channelId
* @param receiverId
* @return
*/
boolean channelReceiverExists(@Param("channelId") Long channelId, @Param("receiverId") Long receiverId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import org.apache.ibatis.annotations.Param;

import cn.archliu.horus.infr.domain.reach.entity.HorusReachReceiver;

Expand All @@ -22,6 +25,15 @@ public interface HorusReachReceiverMapper extends BaseMapper<HorusReachReceiver>
* @param channelId
* @return
*/
List<HorusReachReceiver> loadByChannel(Long channelId);
List<HorusReachReceiver> loadByChannel(@Param("channelId") Long channelId);

/**
* 分页查询达通道的接收人
*
* @param page
* @param channelId
* @return
*/
IPage<HorusReachReceiver> pageChannelReceivers(IPage<HorusReachReceiver> page, @Param("channelId") Long channelId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.archliu.horus.infr.domain.reach.mapper.HorusReachChannelMapper">

</mapper>
<insert id="addChannelReceiver">
insert into horus_channel_receiver(channel_id, receiver_id) values(#{channelId}, #{receiverId})
</insert>

<select id="channelReceiverExists" resultType="java.lang.Boolean">
SELECT
count(1)
FROM
horus_channel_receiver
WHERE
channel_id = #{channelId};
and receiver_id = #{receiverId}
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
select rec.* from horus_channel_receiver cr left join horus_reach_receiver rec on cr.channel_id = #{channelId} and cr.receiver_id = rec.id
</select>

<select id="pageChannelReceivers" resultType="cn.archliu.horus.infr.domain.reach.entity.HorusReachReceiver">
select rec.* from horus_channel_receiver cr left join horus_reach_receiver rec on cr.channel_id = #{channelId} and cr.receiver_id = rec.id
</select>


</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.archliu.horus.infr.domain.reach.entity.HorusReachChannel;
import cn.archliu.horus.infr.domain.reach.entity.HorusReachReceiver;
import cn.archliu.horus.server.domain.reach.entity.HorusMessage;
import cn.archliu.horus.server.domain.reach.entity.ReachChannel;
import cn.archliu.horus.server.domain.reach.web.dto.ChannelReceiverDTO;

/**
* @Author: Arch
Expand All @@ -20,4 +26,42 @@ public interface ChannelService {
*/
List<ReachChannel> pickChannel(HorusMessage message);

/**
* 添加触达通道
*
* @param reachChannel
*/
void addReachChannel(HorusReachChannel reachChannel);

/**
* reachReceiver
*
* @param convert
*/
void addReceiver(HorusReachReceiver reachReceiver);

/**
* 添加触达通道的接收人
*
* @param channelReceiverDTO
*/
void addChannelReceiver(ChannelReceiverDTO channelReceiverDTO);

/**
* 分页查询所有的触达通道
*
* @param page
* @return
*/
Page<HorusReachChannel> pageChannels(Page<HorusReachChannel> page);

/**
* 查询通道下的接收人
*
* @param channelId
* @param page
* @return
*/
IPage<HorusReachReceiver> pageChannelReceivers(Long channelId, Page<HorusReachReceiver> page);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;

import cn.archliu.common.exception.sub.ParamErrorException;
import cn.archliu.horus.infr.domain.reach.entity.HorusReachChannel;
import cn.archliu.horus.infr.domain.reach.entity.HorusReachReceiver;
import cn.archliu.horus.infr.domain.reach.mapper.HorusReachChannelMapper;
Expand All @@ -22,6 +25,7 @@
import cn.archliu.horus.server.domain.reach.entity.ReceiverInfo;
import cn.archliu.horus.server.domain.reach.enums.ReacherType;
import cn.archliu.horus.server.domain.reach.service.ChannelService;
import cn.archliu.horus.server.domain.reach.web.dto.ChannelReceiverDTO;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
Expand Down Expand Up @@ -72,6 +76,49 @@ public List<ReachChannel> pickChannel(HorusMessage message) {
return channelList;
}

@Override
public void addReachChannel(HorusReachChannel reachChannel) {
boolean exists = new LambdaQueryChainWrapper<>(channelMapper)
.eq(HorusReachChannel::getChannelCode, reachChannel.getChannelCode()).exists();
if (exists) {
throw ParamErrorException.throwE("该触达通道已经存在!");
}
// 数据落地
channelMapper.insert(reachChannel);
}

@Override
public void addReceiver(HorusReachReceiver reachReceiver) {
receiverMapper.insert(reachReceiver);
}

@Override
public void addChannelReceiver(ChannelReceiverDTO channelReceiverDTO) {
boolean channelExists = new LambdaQueryChainWrapper<>(channelMapper)
.eq(HorusReachChannel::getId, channelReceiverDTO.getChannelId()).exists();
boolean receiverExists = new LambdaQueryChainWrapper<>(receiverMapper)
.eq(HorusReachReceiver::getId, channelReceiverDTO.getReceiverId()).exists();
if (!channelExists || !receiverExists) {
throw ParamErrorException.throwE("触达通道或者接收人不存在!");
}
if (channelMapper.channelReceiverExists(channelReceiverDTO.getChannelId(),
channelReceiverDTO.getReceiverId())) {
throw ParamErrorException.throwE("该触达通道已经存在该接收人!");
}
// 数据落地
channelMapper.addChannelReceiver(channelReceiverDTO.getChannelId(), channelReceiverDTO.getReceiverId());
}

@Override
public Page<HorusReachChannel> pageChannels(Page<HorusReachChannel> page) {
return channelMapper.selectPage(page, null);
}

@Override
public IPage<HorusReachReceiver> pageChannelReceivers(Long channelId, Page<HorusReachReceiver> page) {
return receiverMapper.pageChannelReceivers(page, channelId);
}

@Override
public void run(ApplicationArguments args) throws Exception {
// 组织默认的触达通道
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
package cn.archliu.horus.server.domain.reach.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.archliu.common.response.ComRes;
import cn.archliu.common.response.sub.CRUDData;
import cn.archliu.common.response.sub.ResData;
import cn.archliu.horus.infr.domain.reach.entity.HorusReachChannel;
import cn.archliu.horus.infr.domain.reach.entity.HorusReachReceiver;
import cn.archliu.horus.server.domain.reach.service.ChannelService;
import cn.archliu.horus.server.domain.reach.service.MessageReach;
import cn.archliu.horus.server.domain.reach.web.convert.ChannelConvert;
import cn.archliu.horus.server.domain.reach.web.convert.MessageConvert;
import cn.archliu.horus.server.domain.reach.web.dto.ChannelReceiverDTO;
import cn.archliu.horus.server.domain.reach.web.dto.HorusMessageDTO;
import cn.archliu.horus.server.domain.reach.web.dto.ReachChannelDTO;
import cn.archliu.horus.server.domain.reach.web.dto.ReachReceiverDTO;
import cn.archliu.horus.server.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

Expand All @@ -24,11 +38,55 @@ public class ReachWeb {
@Autowired
private MessageReach messageReach;

@Autowired
private ChannelService channelService;

@ApiOperation("发送消息")
@PutMapping("/sendMessage")
public ComRes<ResData<Void>> sendMessage(@RequestBody HorusMessageDTO message) {
messageReach.sendMessage(MessageConvert.INSTANCE.trans(message));
return ComRes.success();
}

@ApiOperation("添加触达通道")
@PutMapping("/addReachChannel")
public ComRes<ResData<Void>> addReachChannel(@RequestBody ReachChannelDTO reachChannelDTO) {
channelService.addReachChannel(ChannelConvert.INSTANCE.convert(reachChannelDTO));
return ComRes.success();
}

@ApiOperation("添加消息接收人")
@PutMapping("/addReceiver")
public ComRes<ResData<Void>> addReceiver(@RequestBody ReachReceiverDTO reachReceiverDTO) {
channelService.addReceiver(ChannelConvert.INSTANCE.convert(reachReceiverDTO));
return ComRes.success();
}

@ApiOperation("添加触达通道的接收人")
@PutMapping("/addChannelReceiver")
public ComRes<ResData<Void>> addChannelReceiver(@RequestBody ChannelReceiverDTO channelReceiverDTO) {
channelService.addChannelReceiver(channelReceiverDTO);
return ComRes.success();
}

@ApiOperation("分页查询所有的触达通道")
@GetMapping("/pageChannels")
public ComRes<CRUDData<HorusReachChannel>> pageChannels(@RequestParam("pageIndex") Integer pageIndex,
@RequestParam("pageSize") Integer pageSize) {
Page<HorusReachChannel> page = PageUtil.build(pageIndex, pageSize);
Page<HorusReachChannel> data = channelService.pageChannels(page);
return ComRes.success(new CRUDData<HorusReachChannel>().setItems(data.getRecords()).setTotal(data.getTotal()));
}

@ApiOperation("查询通道下的接收人")
@GetMapping("/pageChannelReceivers")
public ComRes<CRUDData<HorusReachReceiver>> pageChannelReceivers(@RequestParam("channelId") Long channelId,
@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
Page<HorusReachReceiver> page = PageUtil.build(pageIndex, pageSize);
IPage<HorusReachReceiver> data = channelService.pageChannelReceivers(channelId, page);
return ComRes.success(new CRUDData<HorusReachReceiver>().setItems(data.getRecords()).setTotal(data.getTotal()));
}

// TODO 编辑

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cn.archliu.horus.server.domain.reach.web.convert;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import cn.archliu.horus.infr.domain.reach.entity.HorusReachChannel;
import cn.archliu.horus.infr.domain.reach.entity.HorusReachReceiver;
import cn.archliu.horus.server.domain.reach.web.dto.ReachChannelDTO;
import cn.archliu.horus.server.domain.reach.web.dto.ReachReceiverDTO;

@Mapper
public interface ChannelConvert {

ChannelConvert INSTANCE = Mappers.getMapper(ChannelConvert.class);

HorusReachChannel convert(ReachChannelDTO dto);

HorusReachReceiver convert(ReachReceiverDTO dto);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.archliu.horus.server.domain.reach.web.dto;

import javax.validation.constraints.NotNull;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

@ApiModel("通道添加接收人")
@Data
@Accessors(chain = true)
public class ChannelReceiverDTO {

@ApiModelProperty("通道ID")
@NotNull(message = "通达ID不允许为空")
private Long channelId;

@ApiModelProperty("消息接收人ID")
@NotNull(message = "消息接收人ID不允许为空")
private Long receiverId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cn.archliu.horus.server.domain.reach.web.dto;

import javax.validation.constraints.NotBlank;

import cn.archliu.horus.common.enums.ComState;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

@ApiModel("触达通道")
@Data
@Accessors(chain = true)
public class ReachChannelDTO {

@ApiModelProperty("通道编码")
@NotBlank(message = "通道编码不允许为空!")
private String channelCode;

@ApiModelProperty("通道名称")
@NotBlank(message = "通道名称不允许为空!")
private String channelName;

@ApiModelProperty("匹配类别编码")
@NotBlank(message = "匹配类别编码不允许为空!")
private String categoryCode;

@ApiModelProperty("启用状态")
private ComState enableState = ComState.ENABLED;

}
Loading

0 comments on commit d9307d3

Please sign in to comment.