|
@@ -0,0 +1,225 @@
|
|
|
+package cn.cslg.pas.service.impl;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.JsonPage;
|
|
|
+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.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.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;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 事件的Service层接口实现类
|
|
|
+ *
|
|
|
+ * @Author chenyu
|
|
|
+ * @Date 2023/4/2
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements IEventService {
|
|
|
+ private final ProjectService projectService;
|
|
|
+ private final EventMapper eventMapper;
|
|
|
+ private final AssoEventProjectMapper assoEventProjectMapper;
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增事件
|
|
|
+ *
|
|
|
+ * @param eventAddNewDTO 新增事件的DTO类对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addNew(EventAddNewDTO eventAddNewDTO) {
|
|
|
+ log.info("开始处理【新增事件】的业务,参数为:{}", eventAddNewDTO);
|
|
|
+
|
|
|
+ //检查名称是否被占用(同一租户下不能有同名事件名称)
|
|
|
+ String questionName = eventAddNewDTO.getQuestionName();
|
|
|
+ Integer projectId = eventAddNewDTO.getProjectId();
|
|
|
+ Project project = projectService.getById(projectId);
|
|
|
+ Integer tenantId = project.getTenantId();
|
|
|
+
|
|
|
+ log.info("检查事件名称是否被占用(同一租户下不能有同名事件)");
|
|
|
+ int count = eventMapper.countByNameAndTenantId(questionName, tenantId);
|
|
|
+ if (count > 0) {
|
|
|
+ ThrowException.throwXiaoShiException("新增事件失败,当前租户下事件名称【" + questionName + "】已存在,请尝试更换名称");
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增事件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("新增事件失败,服务器忙请稍后再次尝试");
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据入事件和专题库关联表
|
|
|
+ Integer eventId = event.getId();
|
|
|
+ AssoEventProject assoEventProject = new AssoEventProject()
|
|
|
+ .setEventId(eventId)
|
|
|
+ .setProjectId(projectId);
|
|
|
+ log.info("数据入事件和专题库关联表");
|
|
|
+ rows = assoEventProjectMapper.insert(assoEventProject);
|
|
|
+ if (rows != 1) {
|
|
|
+ ThrowException.throwXiaoShiException("新增事件失败,数据入事件和专题库关联表失败,服务器忙请稍后再次尝试");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("新增事件完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询事件
|
|
|
+ *
|
|
|
+ * @param eventQueryPageDTO 事件的分页查询DTO类对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JsonPage query(EventQueryPageDTO eventQueryPageDTO) {
|
|
|
+ log.info("开始处理【分页查询事件】的业务,参数为:{}", eventQueryPageDTO);
|
|
|
+
|
|
|
+ Integer current = eventQueryPageDTO.getCurrent();
|
|
|
+ Integer size = eventQueryPageDTO.getSize();
|
|
|
+ String orderBy = eventQueryPageDTO.getOrderBy();
|
|
|
+ if (orderBy != null && !orderBy.equals("")) {
|
|
|
+ String regex = "[A-Z]+";
|
|
|
+ Pattern compile = Pattern.compile(regex);
|
|
|
+ Matcher matcher = compile.matcher(orderBy);
|
|
|
+ while (matcher.find()) {
|
|
|
+ orderBy = orderBy.replaceFirst(matcher.group(), "_" + matcher.group().toLowerCase());
|
|
|
+ }
|
|
|
+ eventQueryPageDTO.setOrderBy(orderBy);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (current != null && size != null) {
|
|
|
+ PageHelper.startPage(current, size);
|
|
|
+ }
|
|
|
+ List<EventListItemVO> queryResults = eventMapper.queryList(eventQueryPageDTO);
|
|
|
+ for (EventListItemVO queryResult : queryResults) {
|
|
|
+ String applicationScenario = queryResult.getApplicationScenario();
|
|
|
+ if (applicationScenario != null && !applicationScenario.equals("")) {
|
|
|
+ List<Integer> applicationScenarioIds = Arrays.stream(applicationScenario.split(",")).map(Integer::parseInt).collect(Collectors.toList());
|
|
|
+ queryResult.setApplicationScenarios(applicationScenarioIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return JsonPage.restPage(new PageInfo<>(queryResults));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改事件
|
|
|
+ *
|
|
|
+ * @param eventUpdateDTO 修改事件的DTO类对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void update(EventUpdateDTO eventUpdateDTO) {
|
|
|
+ log.info("开始处理【修改事件】的业务,参数为:{}", eventUpdateDTO);
|
|
|
+
|
|
|
+ //检查尝试修改的数据是否存在
|
|
|
+ Event queryResult = eventMapper.selectById(eventUpdateDTO.getId());
|
|
|
+ if (queryResult == null) {
|
|
|
+ ThrowException.throwXiaoShiException("修改失败,访问的数据不存在,请尝试刷新页面");
|
|
|
+ }
|
|
|
+
|
|
|
+ //若修改了名称,则检查名称是否被占用(同一租户下专题库不能有同名事件名称)
|
|
|
+ String newQuestionName = eventUpdateDTO.getQuestionName();
|
|
|
+ String oldQuestionName = queryResult.getQuestionName();
|
|
|
+ Project project = projectService.getById(eventUpdateDTO.getProjectId());
|
|
|
+ Integer tenantId = project.getTenantId();
|
|
|
+ if (!newQuestionName.equals(oldQuestionName)) {
|
|
|
+ log.info("检查事件名称是否被占用(同一租户下专题库不能有同名事件)");
|
|
|
+ int count = eventMapper.countByNameAndTenantId(newQuestionName, tenantId);
|
|
|
+ if (count > 0) {
|
|
|
+ ThrowException.throwXiaoShiException("修改失败,当前租户下事件名称【" + newQuestionName + "】已存在,请尝试更换名称");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改事件
|
|
|
+ Event event = new Event();
|
|
|
+ BeanUtils.copyProperties(eventUpdateDTO, event);
|
|
|
+ event.setTenantId(tenantId);
|
|
|
+ List<Integer> applicationScenarios = eventUpdateDTO.getApplicationScenarios();
|
|
|
+ if (applicationScenarios != null && applicationScenarios.size() > 0) {
|
|
|
+ String applicationScenario = applicationScenarios.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
+ event.setApplicationScenario(applicationScenario);
|
|
|
+ }
|
|
|
+ int rows = eventMapper.updateById(event);
|
|
|
+ if (rows != 1) {
|
|
|
+ ThrowException.throwXiaoShiException("修改失败,服务器忙请稍后再次尝试");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("修改完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id删除事件
|
|
|
+ *
|
|
|
+ * @param eventId 事件id
|
|
|
+ * @param projectId 专题库id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void delete(Integer eventId, Integer projectId) {
|
|
|
+ log.info("开始处理【删除事件】的业务,参数为:{}, {}", eventId, projectId);
|
|
|
+
|
|
|
+ //检查尝试删除的数据是否存在
|
|
|
+ Event queryResult = eventMapper.selectById(eventId);
|
|
|
+ if (queryResult == null) {
|
|
|
+ ThrowException.throwXiaoShiException("删除失败,访问的数据不存在,请尝试刷新页面");
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除事件和专题库关联表数据
|
|
|
+ assoEventProjectMapper.deleteByEventIdAndProjectId(eventId, projectId);
|
|
|
+
|
|
|
+ //删除事件表数据
|
|
|
+// int rows = eventMapper.deleteById(eventId);
|
|
|
+// if (rows != 1) {
|
|
|
+// ThrowException.throwXiaoShiException("删除失败,服务器忙请稍后再次尝试");
|
|
|
+// }
|
|
|
+
|
|
|
+ log.info("删除完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|