|
@@ -0,0 +1,131 @@
|
|
|
+package com.simuwang.manage.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.simuwang.base.common.support.MybatisPage;
|
|
|
+import com.simuwang.base.mapper.daq.ChannelEmailMapper;
|
|
|
+import com.simuwang.base.mapper.daq.ChannelMapper;
|
|
|
+import com.simuwang.base.pojo.dos.ChannelEmailInfoDO;
|
|
|
+import com.simuwang.base.pojo.dos.ChannelInfoDO;
|
|
|
+import com.simuwang.base.pojo.dos.ChannelPageInfoDO;
|
|
|
+import com.simuwang.base.pojo.dos.CompanyEmailSendHistoryDO;
|
|
|
+import com.simuwang.base.pojo.dto.GetByIdQuery;
|
|
|
+import com.simuwang.base.pojo.dto.query.ChannelIdPageQuery;
|
|
|
+import com.simuwang.base.pojo.dto.query.ChannelPageQuery;
|
|
|
+import com.simuwang.base.pojo.vo.ChannelEmailInfoVO;
|
|
|
+import com.simuwang.base.pojo.vo.ChannelInfoVO;
|
|
|
+import com.simuwang.base.pojo.vo.ChannelPageInfoVO;
|
|
|
+import com.simuwang.base.pojo.vo.CompanyEmailSendHistoryVO;
|
|
|
+import com.simuwang.manage.service.ChannelService;
|
|
|
+import com.simuwang.shiro.utils.UserUtils;
|
|
|
+import com.smppw.common.pojo.ResultVo;
|
|
|
+import com.smppw.common.pojo.enums.status.ResultCode;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ChannelServiceImpl implements ChannelService {
|
|
|
+ @Autowired
|
|
|
+ private ChannelMapper channelMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChannelEmailMapper channelEmailMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultVo saveChannel(ChannelInfoVO channel) {
|
|
|
+ ResultVo vo = new ResultVo(ResultCode.SAVE_SUCCESS.getCode());
|
|
|
+ Integer userId = UserUtils.getLoginUser().getUserId();
|
|
|
+ ChannelInfoDO channelInfoDO = BeanUtil.copyProperties(channel,ChannelInfoDO.class);
|
|
|
+ channelInfoDO.setUpdateTime(new Date());
|
|
|
+ channelInfoDO.setUpdaterId(userId);
|
|
|
+ channelInfoDO.setIsvalid(1);
|
|
|
+ if(channelInfoDO.getId() == null){
|
|
|
+ //判断渠道是否已经存在
|
|
|
+ ChannelInfoDO channelInfo = channelMapper.selectByChannelName(channelInfoDO.getChannelName());
|
|
|
+ if(channelInfo != null){
|
|
|
+ vo.setCode(ResultCode.SAVE_FAILED.getCode());
|
|
|
+ vo.setMsg("渠道已经存在无需添加");
|
|
|
+ vo.setData(false);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ channelInfoDO.setCreatorId(userId);
|
|
|
+ channelInfoDO.setCreateTime(new Date());
|
|
|
+ channelMapper.insert(channelInfoDO);
|
|
|
+ }else{
|
|
|
+ channelMapper.updateById(channelInfoDO);
|
|
|
+ }
|
|
|
+ vo.setData(true);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultVo deleteChannel(List<Integer> idList) {
|
|
|
+ ResultVo vo = new ResultVo(ResultCode.DELETE_SUCCESS.getCode());
|
|
|
+ for (Integer id : idList) {
|
|
|
+ Integer userId = UserUtils.getLoginUser().getUserId();
|
|
|
+ channelMapper.deleteChannelById(id,userId);
|
|
|
+ //删除渠道关联的邮箱
|
|
|
+ channelEmailMapper.deleteByChannelId(id,userId);
|
|
|
+ }
|
|
|
+ vo.setData(true);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultVo saveChannelEmail(List<ChannelEmailInfoVO> channelEmailInfoVOList) {
|
|
|
+ ResultVo vo = new ResultVo(ResultCode.SAVE_SUCCESS.getCode());
|
|
|
+ Integer userId = UserUtils.getLoginUser().getUserId();
|
|
|
+ List<ChannelEmailInfoDO> channelEmailInfoDOList = new ArrayList<>();
|
|
|
+ for (ChannelEmailInfoVO channelEmailInfoVO : channelEmailInfoVOList) {
|
|
|
+ ChannelEmailInfoDO emailInfoDO = channelEmailMapper.selectByEmail(channelEmailInfoVO.getEmail());
|
|
|
+ if(emailInfoDO != null && !emailInfoDO.getChannelId().equals(channelEmailInfoVO.getChannelId())){
|
|
|
+ vo.setCode(ResultCode.SAVE_FAILED.getCode());
|
|
|
+ vo.setData(false);
|
|
|
+ vo.setMsg(channelEmailInfoVO.getEmail()+"已经被其他渠道绑定,无法添加");
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ ChannelEmailInfoDO channelEmailInfoDO = BeanUtil.copyProperties(channelEmailInfoVO,ChannelEmailInfoDO.class);
|
|
|
+ channelEmailInfoDO.setIsvalid(1);
|
|
|
+ channelEmailInfoDO.setUpdaterId(userId);
|
|
|
+ channelEmailInfoDO.setUpdateTime(new Date());
|
|
|
+ if(channelEmailInfoDO.getId() == null){
|
|
|
+ channelEmailInfoDO.setCreatorId(userId);
|
|
|
+ channelEmailInfoDO.setCreateTime(new Date());
|
|
|
+ }
|
|
|
+ channelEmailInfoDOList.add(channelEmailInfoDO);
|
|
|
+ }
|
|
|
+ channelEmailMapper.insertOrUpdate(channelEmailInfoDOList);
|
|
|
+ vo.setData(true);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MybatisPage<ChannelPageInfoVO> searchChannelList(ChannelPageQuery channelPageQuery) {
|
|
|
+ List<ChannelPageInfoDO> dataList = channelMapper.searchChannelList(channelPageQuery);
|
|
|
+ List<ChannelPageInfoVO> voList = dataList.stream().filter(Objects::nonNull).map(ChannelPageInfoDO::toVo).collect(Collectors.toList());
|
|
|
+ long total = channelMapper.countChannelInfo(channelPageQuery);
|
|
|
+ return MybatisPage.of(total, voList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultVo deleteChannelEmail(Integer id) {
|
|
|
+ ResultVo vo = new ResultVo(ResultCode.DELETE_SUCCESS.getCode());
|
|
|
+ Integer userId = UserUtils.getLoginUser().getUserId();
|
|
|
+ channelEmailMapper.deleteByIdAndUserId(id,userId);
|
|
|
+ vo.setData(true);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MybatisPage<ChannelEmailInfoVO> searchChannelEmailList(ChannelIdPageQuery channelIdPageQuery) {
|
|
|
+ List<ChannelEmailInfoDO> dataList = channelEmailMapper.searchChannelEmailList(channelIdPageQuery);
|
|
|
+ List<ChannelEmailInfoVO> voList = dataList.stream().filter(Objects::nonNull).map(ChannelEmailInfoDO::toVo).collect(Collectors.toList());
|
|
|
+ long total = channelEmailMapper.countChannelEmail(channelIdPageQuery);
|
|
|
+ return MybatisPage.of(total, voList);
|
|
|
+ }
|
|
|
+}
|