refactor: 消息通知

This commit is contained in:
Captain.B 2021-08-18 12:39:53 +08:00 committed by 刘瑞斌
parent e8c3f23fdf
commit 720e52f911
5 changed files with 110 additions and 36 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.Organization;
import io.metersphere.base.domain.Project;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.dto.ProjectDTO;
@ -27,4 +28,6 @@ public interface ExtProjectMapper {
@MapKey("id")
Map<String, Project> queryNameByIds(@Param("ids") List<String> ids);
Organization getOrganizationByProjectId(@Param("projectId")String projectId);
}

View File

@ -151,4 +151,11 @@
where organization_id = #{orgId})) as a)
</update>
<select id="getOrganizationByProjectId">
SELECT organization.*
FROM organization
JOIN workspace ON organization.id = organization_id
JOIN project ON workspace.id = workspace_id
WHERE project.id = #{projectId, jdbcType=VARCHAR}
</select>
</mapper>

View File

@ -0,0 +1,59 @@
package io.metersphere.notice.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.Notification;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.notice.service.NotificationService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping(value = "notification")
public class NotificationController {
@Resource
private NotificationService notificationService;
@PostMapping(value = "/list/all/{goPage}/{pageSize}")
public Pager<List<Notification>> listNotification(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody Notification notification) {
Page page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, notificationService.listNotification(notification));
}
@PostMapping(value = "/list/read/{goPage}/{pageSize}")
public Pager<List<Notification>> listReadNotification(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody Notification notification) {
Page page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, notificationService.listReadNotification(notification));
}
@PostMapping(value = "/list/unread/{goPage}/{pageSize}")
public Pager<List<Notification>> listUnreadNotification(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody Notification notification) {
Page page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, notificationService.listUnreadNotification(notification));
}
@GetMapping(value = "/get/{id}")
public Notification getNotification(@PathVariable int id) {
return notificationService.getNotification(id);
}
@GetMapping(value = "/read/{id}")
public Integer read(@PathVariable int id) {
return notificationService.read(id);
}
@GetMapping(value = "/read/all")
public Integer readAll() {
return notificationService.readAll();
}
@PostMapping(value = "/count")
public Integer countNotification(@RequestBody Notification notification) {
return notificationService.countNotification(notification);
}
}

View File

@ -3,11 +3,11 @@ package io.metersphere.notice.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.MessageTask;
import io.metersphere.base.domain.MessageTaskExample;
import io.metersphere.base.domain.Organization;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.MessageTaskMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.i18n.Translator;
@ -17,6 +17,7 @@ import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.StatusReference;
import io.metersphere.log.vo.system.SystemReference;
import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.service.ProjectService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -34,7 +35,7 @@ public class NoticeService {
@Resource
private LoadTestReportMapper loadTestReportMapper;
@Resource
private UserMapper userMapper;
private ExtProjectMapper extProjectMapper;
public void saveMessageTask(MessageDetail messageDetail) {
MessageTaskExample example = new MessageTaskExample();
@ -43,8 +44,7 @@ public class NoticeService {
if (messageTaskLists.size() > 0) {
delMessage(messageDetail.getIdentification());
}
SessionUser user = SessionUtils.getUser();
String orgId = user.getLastOrganizationId();
String orgId = SessionUtils.getCurrentOrganizationId();
long time = System.currentTimeMillis();
String identification = messageDetail.getIdentification();
if (StringUtils.isBlank(identification)) {
@ -117,8 +117,7 @@ public class NoticeService {
public List<MessageDetail> searchMessageByType(String type) {
try {
SessionUser user = SessionUtils.getUser();
String orgId = user.getLastOrganizationId();
String orgId = SessionUtils.getCurrentOrganizationId();
List<MessageDetail> messageDetails = new ArrayList<>();
MessageTaskExample example = new MessageTaskExample();
@ -150,11 +149,11 @@ public class NoticeService {
try {
String orgId = "";
if (null == SessionUtils.getUser()) {
String userId = loadTestReportMapper.selectByPrimaryKey(id).getUserId();
orgId = userMapper.selectByPrimaryKey(userId).getLastOrganizationId();
String projectId = loadTestReportMapper.selectByPrimaryKey(id).getProjectId();
Organization organization = extProjectMapper.getOrganizationByProjectId(projectId);
orgId = organization.getId();
} else {
SessionUser user = SessionUtils.getUser();
orgId = user.getLastOrganizationId();
orgId = SessionUtils.getCurrentOrganizationId();
}
List<MessageDetail> messageDetails = new ArrayList<>();
MessageTaskExample example = new MessageTaskExample();

View File

@ -532,6 +532,7 @@ public class ProjectService {
}
}
}
public void reloadMockTcp(Project project, int oldPort) {
this.closeMockTcp(oldPort);
this.openMockTcp(project);
@ -541,6 +542,7 @@ public class ProjectService {
Project project = projectMapper.selectByPrimaryKey(projectId);
this.closeMockTcp(project);
}
public void closeMockTcp(Project project) {
if (project == null) {
MSException.throwException("Project not found!");
@ -570,4 +572,8 @@ public class ProjectService {
this.openMockTcp(p);
}
}
public Organization getOrganizationByProjectId(String projectId) {
return extProjectMapper.getOrganizationByProjectId(projectId);
}
}