|
@@ -5,20 +5,20 @@ import cn.cslg.pas.common.model.PersonnelVO;
|
|
|
import cn.cslg.pas.common.model.dto.EventAddNewDTO;
|
|
|
import cn.cslg.pas.common.model.dto.EventQueryPageDTO;
|
|
|
import cn.cslg.pas.common.model.dto.EventUpdateDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.ProjectEventAddNewDTO;
|
|
|
import cn.cslg.pas.common.model.vo.EventListItemVO;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
-import cn.cslg.pas.common.utils.Response;
|
|
|
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
|
import cn.cslg.pas.common.utils.ThrowException;
|
|
|
import cn.cslg.pas.domain.Event;
|
|
|
import cn.cslg.pas.domain.Project;
|
|
|
import cn.cslg.pas.domain.asso.AssoEventProject;
|
|
|
-import cn.cslg.pas.mapper.AssoEventProjectMapper;
|
|
|
import cn.cslg.pas.mapper.EventMapper;
|
|
|
+import cn.cslg.pas.mapper.asso.AssoEventProjectMapper;
|
|
|
+import cn.cslg.pas.service.IAssoEventProjectService;
|
|
|
import cn.cslg.pas.service.IEventService;
|
|
|
import cn.cslg.pas.service.ProjectService;
|
|
|
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.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -30,7 +30,6 @@ import org.springframework.stereotype.Service;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
-import java.util.StringJoiner;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -48,65 +47,95 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
|
|
|
private final ProjectService projectService;
|
|
|
private final EventMapper eventMapper;
|
|
|
private final AssoEventProjectMapper assoEventProjectMapper;
|
|
|
+ private final IAssoEventProjectService assoEventProjectService;
|
|
|
private final CacheUtils cacheUtils;
|
|
|
private final LoginUtils loginUtils;
|
|
|
|
|
|
/**
|
|
|
* 新增事件
|
|
|
*
|
|
|
- * @param eventAddNewDTO 新增事件的DTO类对象
|
|
|
+ * @param eventAddNewDTOs 新增事件的DTO类对象集合
|
|
|
+ * @return 返回事件eventIds
|
|
|
*/
|
|
|
@Override
|
|
|
- public void addNew(EventAddNewDTO eventAddNewDTO) {
|
|
|
- log.info("开始处理【新增事件】的业务,参数为:{}", eventAddNewDTO);
|
|
|
+ public List<Integer> addNew(List<EventAddNewDTO> eventAddNewDTOs) {
|
|
|
+ log.info("开始处理【批量新增事件】的业务,参数为:{}", eventAddNewDTOs);
|
|
|
|
|
|
- //检查名称是否被占用(同一租户下不能有同名事件名称)
|
|
|
- String questionName = eventAddNewDTO.getQuestionName();
|
|
|
- Integer projectId = eventAddNewDTO.getProjectId();
|
|
|
- Project project = projectService.getById(projectId);
|
|
|
- Integer tenantId = project.getTenantId();
|
|
|
+ //获取当前登陆人信息取出登陆人id、登陆人名称、租户id
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ Integer tenantId = personnelVO.getTenantId();
|
|
|
+ Integer createPersonId = personnelVO.getId();
|
|
|
+ String createPersonName = personnelVO.getName();
|
|
|
|
|
|
- log.info("检查事件名称是否被占用(同一租户下不能有同名事件)");
|
|
|
- int count = eventMapper.countByNameAndTenantId(questionName, tenantId);
|
|
|
- if (count > 0) {
|
|
|
- ThrowException.throwXiaoShiException("新增事件失败,当前租户下事件名称【" + questionName + "】已存在,请尝试更换名称");
|
|
|
+ //取出DTOs中的事件名称questionNames,根据事件名称questionNames和租户id查询出重名的已有事件
|
|
|
+ List<String> questionNames = eventAddNewDTOs.stream().map(EventAddNewDTO::getQuestionName).collect(Collectors.toList());
|
|
|
+ LambdaQueryWrapper<Event> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(Event::getQuestionName, questionNames).in(Event::getTenantId, tenantId);
|
|
|
+ List<Event> existNamesEvents = this.list(wrapper);
|
|
|
+ if (existNamesEvents != null && existNamesEvents.size() > 0) {
|
|
|
+ ThrowException.throwXiaoShiException("新增失败,本租户下事件名称【" + existNamesEvents.get(0).getQuestionName() + "已存在,请尝试更换名称】");
|
|
|
}
|
|
|
|
|
|
- //新增事件DTO数据赋值给事件表实体类
|
|
|
- Event event = new Event();
|
|
|
- BeanUtils.copyProperties(eventAddNewDTO, event);
|
|
|
- event.setTenantId(tenantId);
|
|
|
- List<Integer> applicationScenarios = eventAddNewDTO.getApplicationScenarios();
|
|
|
- //若有应用场景,则将应用场景集合转换成以逗号拼接的字符串,并赋值给实体类对应参数
|
|
|
- if (applicationScenarios != null && applicationScenarios.size() > 0) {
|
|
|
- String applicationScenario = applicationScenarios.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
- event.setApplicationScenario(applicationScenario);
|
|
|
- }
|
|
|
-
|
|
|
- //获取当前登陆人id及姓名
|
|
|
- PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
- event
|
|
|
- .setCreatePersonId(personnelVO.getId())
|
|
|
- .setCreatePersonName(personnelVO.getName());
|
|
|
-
|
|
|
- log.info("数据入事件表");
|
|
|
- int rows = eventMapper.insert(event);
|
|
|
- if (rows != 1) {
|
|
|
- ThrowException.throwXiaoShiException("新增事件失败,服务器忙请稍后再次尝试");
|
|
|
+ //新增事件
|
|
|
+ ArrayList<Event> events = new ArrayList<>();
|
|
|
+ for (EventAddNewDTO eventAddNewDTO : eventAddNewDTOs) {
|
|
|
+ String questionName = eventAddNewDTO.getQuestionName();
|
|
|
+ if (questionName == null || questionName.equals("")) {
|
|
|
+ ThrowException.throwXiaoShiException("新增失败,事件名称不能为空");
|
|
|
+ }
|
|
|
+ Event event = new Event();
|
|
|
+ BeanUtils.copyProperties(eventAddNewDTO, event);
|
|
|
+ event
|
|
|
+ .setTenantId(tenantId)
|
|
|
+ .setCreatePersonId(createPersonId)
|
|
|
+ .setCreatePersonName(createPersonName);
|
|
|
+ List<Integer> applicationScenarios = eventAddNewDTO.getApplicationScenarios();
|
|
|
+ //若有应用场景,则将应用场景集合转换成以逗号拼接的字符串,并赋值给实体类对应参数
|
|
|
+ if (applicationScenarios != null && applicationScenarios.size() > 0) {
|
|
|
+ String applicationScenario = applicationScenarios.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
+ event.setApplicationScenario(applicationScenario);
|
|
|
+ }
|
|
|
+ events.add(event);
|
|
|
}
|
|
|
+ //数据入事件表
|
|
|
+ this.saveBatch(events);
|
|
|
|
|
|
- //数据入事件和专题库关联表
|
|
|
- Integer eventId = event.getId();
|
|
|
- AssoEventProject assoEventProject = new AssoEventProject()
|
|
|
- .setEventId(eventId)
|
|
|
- .setProjectId(projectId);
|
|
|
- log.info("数据入事件和专题库关联表");
|
|
|
- rows = assoEventProjectMapper.insert(assoEventProject);
|
|
|
- if (rows != 1) {
|
|
|
- ThrowException.throwXiaoShiException("新增事件失败,数据入事件和专题库关联表失败,服务器忙请稍后再次尝试");
|
|
|
+ ArrayList<Integer> eventIds = new ArrayList<>();
|
|
|
+ for (Event event : events) {
|
|
|
+ eventIds.add(event.getId());
|
|
|
}
|
|
|
|
|
|
log.info("新增事件完成");
|
|
|
+ return eventIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 专题库中新增事件
|
|
|
+ *
|
|
|
+ * @param projectEventAddNewDTO 专题库新增事件的DTO类对象集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addNewEvent(ProjectEventAddNewDTO projectEventAddNewDTO) {
|
|
|
+ log.info("开始处理【专题库中新增事件】的业务,参数为:{}", projectEventAddNewDTO);
|
|
|
+
|
|
|
+ //新增事件
|
|
|
+ List<EventAddNewDTO> eventAddNewDTOs = projectEventAddNewDTO.getEventAddNewDTOs();
|
|
|
+ Integer projectId = projectEventAddNewDTO.getProjectId();
|
|
|
+ List<Integer> eventIds = new ArrayList<>();
|
|
|
+ //过滤去除已有事件↓(根据是否有id来过滤,有id则为已有事件无需新增,只做关联)
|
|
|
+ List<EventAddNewDTO> oldEventAddNewDTOs = eventAddNewDTOs.stream().filter(item -> item.getId() != null).collect(Collectors.toList());
|
|
|
+ eventAddNewDTOs.removeAll(oldEventAddNewDTOs);
|
|
|
+
|
|
|
+ //过滤后为新事件↓,新事件需要先去新增事件,拿到事件ids后再做关联
|
|
|
+ if (eventAddNewDTOs.size() > 0) {
|
|
|
+ List<Integer> newEventIds = this.addNew(eventAddNewDTOs);
|
|
|
+ eventIds.addAll(newEventIds);
|
|
|
+ }
|
|
|
+ for (EventAddNewDTO oldEventAddNewDTO : oldEventAddNewDTOs) {
|
|
|
+ eventIds.add(oldEventAddNewDTO.getId());
|
|
|
+ }
|
|
|
+ //新增事件和专题库关联
|
|
|
+ assoEventProjectService.addNew(eventIds, projectId);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -209,7 +238,9 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
|
|
|
}
|
|
|
|
|
|
//删除事件和专题库关联表数据
|
|
|
- assoEventProjectMapper.deleteByEventIdAndProjectId(eventId, projectId);
|
|
|
+ ArrayList<Integer> eventIds = new ArrayList<>();
|
|
|
+ eventIds.add(eventId);
|
|
|
+ assoEventProjectMapper.deleteByEventIdsAndProjectId(eventIds, projectId);
|
|
|
|
|
|
//删除事件表数据
|
|
|
// int rows = eventMapper.deleteById(eventId);
|