Просмотр исходного кода

撤回操作改为修改状态

qinchao 4 лет назад
Родитель
Сommit
f62a07acdf

+ 10 - 4
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/NoticeController.java

@@ -94,10 +94,16 @@ public class NoticeController extends ControllerSupport {
         noticeService.updateNotice(info);
     }
 
-    @ApiOperation(value = "发送、撤回信息")
-    @GetMapping("sendMsg/{status}/{id}")
-    public void backMsg(@PathVariable NoticeStatus status, @PathVariable Long id) {
-        noticeService.sendMsg(status, id);
+    @ApiOperation(value = "发送信息")
+    @GetMapping("sendMsg/{id}")
+    public void sendMsg(@PathVariable Long id) {
+        noticeService.sendMsg(id);
+    }
+
+    @ApiOperation(value = "撤回信息")
+    @GetMapping("recallMsg/{id}")
+    public void recallMsg(@PathVariable Long id) {
+        noticeService.recallMsg(id);
     }
 
     @ApiOperation(value = "删除通知信息")

+ 5 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/UserNoticeRepo.java

@@ -25,4 +25,9 @@ public interface UserNoticeRepo extends JpaRepository<UserNoticeEntity, Long>,
     @Transactional
     @Modifying
     void deleteByNoticeId(Long noticeId);
+
+    @Transactional
+    @Modifying
+    @Query(value = "update EC_E_USER_NOTICE set has_recalled = 1 where notice_id = ?1",nativeQuery = true)
+    int updateNoticeRecalledStatus(Long noticeId);
 }

+ 14 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/UserNoticeEntity.java

@@ -57,6 +57,12 @@ public class UserNoticeEntity extends WithIdJpaEntity {
 	@Column(nullable = false)
 	private Boolean hasRead;
 
+	/**
+	 * 是否已撤销
+	 */
+	@Column(nullable = false)
+	private Boolean hasRecalled;
+
 	public Long getRootOrgId() {
 		return rootOrgId;
 	}
@@ -96,4 +102,12 @@ public class UserNoticeEntity extends WithIdJpaEntity {
 	public void setHasRead(Boolean hasRead) {
 		this.hasRead = hasRead;
 	}
+
+	public Boolean getHasRecalled() {
+		return hasRecalled;
+	}
+
+	public void setHasRecalled(Boolean hasRecalled) {
+		this.hasRecalled = hasRecalled;
+	}
 }

+ 3 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/NoticeService.java

@@ -103,5 +103,7 @@ public interface NoticeService {
      */
     void updateNoticeStatus(Long noticeId, NoticeStatus noticeStatus);
 
-    void sendMsg(NoticeStatus status, Long id);
+    void sendMsg(Long id);
+
+    void recallMsg(Long id);
 }

+ 27 - 13
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/NoticeServiceImpl.java

@@ -301,24 +301,38 @@ public class NoticeServiceImpl implements NoticeService {
     }
 
     @Override
-    public void sendMsg(NoticeStatus status, Long id) {
+    public void sendMsg(Long id) {
         Optional<NoticeEntity> optional = noticeRepo.findById(id);
         if(optional.isPresent()){
             NoticeEntity entity = optional.get();
-            //根据noticeId删除用户通知记录
-            if(NoticeStatus.DRAFT.equals(status)){
-                if (entity.getNoticeStatus() != NoticeStatus.PUBLISHED) {
-                    throw new StatusException("501008", "只能撤回已经发送的消息");
-                } else {
-                    userNoticeRepo.deleteByNoticeId(id);
-                }
-            } else if (NoticeStatus.TO_BE_PUBLISHED.equals(status)){
-                if (entity.getNoticeStatus() != NoticeStatus.DRAFT) {
-                    throw new StatusException("501008", "只能发送未发布的消息");
-                }
+
+            if (entity.getNoticeStatus() != NoticeStatus.DRAFT) {
+                throw new StatusException("501008", "只能发送未发布的消息");
+            }
+
+            entity.setNoticeStatus(NoticeStatus.TO_BE_PUBLISHED);
+            entity.setUpdateTime(new Date());
+            noticeRepo.save(entity);
+        } else {
+            throw new StatusException("501006", "找不到通知id为:" + id + "的数据");
+        }
+    }
+
+    @Override
+    public void recallMsg(Long id) {
+        Optional<NoticeEntity> optional = noticeRepo.findById(id);
+        if(optional.isPresent()){
+            NoticeEntity entity = optional.get();
+
+            if (entity.getNoticeStatus() != NoticeStatus.PUBLISHED) {
+                throw new StatusException("501008", "只能撤回已经发送的消息");
+            } else {
+                //根据noticeId删除用户通知,改为更新是否已经撤回状态
+                //userNoticeRepo.deleteByNoticeId(id);
+                userNoticeRepo.updateNoticeRecalledStatus(id);
             }
 
-            entity.setNoticeStatus(status);
+            entity.setNoticeStatus(NoticeStatus.RECALLED);
             entity.setUpdateTime(new Date());
             noticeRepo.save(entity);
         } else {