|
@@ -1,15 +1,26 @@
|
|
package com.persagy.dmp.message.service.impl;
|
|
package com.persagy.dmp.message.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.text.StrFormatter;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.persagy.dmp.common.constant.ValidEnum;
|
|
import com.persagy.dmp.common.constant.ValidEnum;
|
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
import com.persagy.dmp.message.dao.SenderRegisterMapper;
|
|
import com.persagy.dmp.message.dao.SenderRegisterMapper;
|
|
|
|
+import com.persagy.dmp.message.dao.SenderRegisterMapper;
|
|
|
|
+import com.persagy.dmp.message.model.SenderRegister;
|
|
import com.persagy.dmp.message.model.SenderRegister;
|
|
import com.persagy.dmp.message.model.SenderRegister;
|
|
import com.persagy.dmp.message.service.ISenderRegisterService;
|
|
import com.persagy.dmp.message.service.ISenderRegisterService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 消息渠道注册 服务实现
|
|
* 消息渠道注册 服务实现
|
|
@@ -20,10 +31,129 @@ import java.util.List;
|
|
@Transactional
|
|
@Transactional
|
|
public class SenderRegisterServiceImpl extends ServiceImpl<SenderRegisterMapper, SenderRegister> implements ISenderRegisterService {
|
|
public class SenderRegisterServiceImpl extends ServiceImpl<SenderRegisterMapper, SenderRegister> implements ISenderRegisterService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SenderRegisterMapper dao;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询所有消息渠道注册
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@Override
|
|
@Override
|
|
public List<SenderRegister> queryAll() {
|
|
public List<SenderRegister> queryAll() {
|
|
LambdaQueryWrapper<SenderRegister> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<SenderRegister> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(SenderRegister::getValid, ValidEnum.TRUE.getType());
|
|
queryWrapper.eq(SenderRegister::getValid, ValidEnum.TRUE.getType());
|
|
return list(queryWrapper);
|
|
return list(queryWrapper);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分页查询消息类型
|
|
|
|
+ * @param page 分页条件
|
|
|
|
+ * @param queryWrapper 查询条件
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Page queryByCondition(Page page, Wrapper<SenderRegister> queryWrapper) {
|
|
|
|
+ return dao.selectPage(page, queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增消息渠道注册信息
|
|
|
|
+ * @param voList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<SenderRegister> insertType(List<SenderRegister> voList) {
|
|
|
|
+ //发送渠道编码校验
|
|
|
|
+ validateOnSave(voList,false);
|
|
|
|
+ //批量保存消息类型
|
|
|
|
+ saveBatch(voList);
|
|
|
|
+ return voList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改消息渠道注册信息
|
|
|
|
+ * @param voList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<SenderRegister> updateType(List<SenderRegister> voList) {
|
|
|
|
+ //消息类型编码校验
|
|
|
|
+ validateOnSave(voList,true);
|
|
|
|
+ //批量保存消息类型
|
|
|
|
+ saveOrUpdateBatch(voList);
|
|
|
|
+ return voList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除消息渠道注册信息
|
|
|
|
+ * @param ids
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void deleteType(List<String> ids) {
|
|
|
|
+ List<SenderRegister> voList = load(ids);
|
|
|
|
+ if(CollUtil.isEmpty(voList)){
|
|
|
|
+ throw new BusinessException("消息类型不存在");
|
|
|
|
+ }
|
|
|
|
+ //数据置为无效状态
|
|
|
|
+ voList.forEach(item->item.setValid(ValidEnum.FALSE.getType()));
|
|
|
|
+ saveOrUpdateBatch(voList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据id查询消消息渠道
|
|
|
|
+ * * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public SenderRegister load(String id) {
|
|
|
|
+ return getById(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据id批量查询消息渠道
|
|
|
|
+ * @param ids
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<SenderRegister> load(List<String> ids) {
|
|
|
|
+ return dao.selectBatchIds(ids);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存校验
|
|
|
|
+ * 编码全局唯一
|
|
|
|
+ * @param voList
|
|
|
|
+ * @param isUpdate
|
|
|
|
+ */
|
|
|
|
+ private void validateOnSave(List<SenderRegister> voList, Boolean isUpdate) {
|
|
|
|
+ Set<String> codeSet = new HashSet<>();
|
|
|
|
+ List<String> idList = new ArrayList<>();
|
|
|
|
+ for(SenderRegister vo:voList) {
|
|
|
|
+ // 编码重复
|
|
|
|
+ if(!codeSet.add(vo.getCode())) {
|
|
|
|
+ throw new BusinessException(StrFormatter.format("存在重复编码{},不允许保存!", vo.getCode()));
|
|
|
|
+ }
|
|
|
|
+ if(isUpdate) {
|
|
|
|
+ idList.add(vo.getId());
|
|
|
|
+ }
|
|
|
|
+ // 补充valid值
|
|
|
|
+ if (null==vo.getValid()){
|
|
|
|
+ vo.setValid(ValidEnum.TRUE.getType());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查询条件
|
|
|
|
+ LambdaQueryWrapper<SenderRegister> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.select(SenderRegister::getCode);
|
|
|
|
+ queryWrapper.in(SenderRegister::getValid, ValidEnum.TRUE.getType());
|
|
|
|
+ queryWrapper.in(SenderRegister::getCode, codeSet);
|
|
|
|
+ if(isUpdate) {
|
|
|
|
+ queryWrapper.notIn(SenderRegister::getId, idList);
|
|
|
|
+ }
|
|
|
|
+ // 查询重复的编码
|
|
|
|
+ List<SenderRegister> dbList = dao.selectList(queryWrapper);
|
|
|
|
+ if(CollUtil.isEmpty(dbList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<String> codes = CollUtil.getFieldValues(voList, "typeCode", String.class);
|
|
|
|
+ throw new BusinessException(StrFormatter.format("存在重复编码{},不允许保存!", codes));
|
|
|
|
+ }
|
|
}
|
|
}
|