qinchao 4 éve
szülő
commit
eff1967eee

+ 11 - 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 = "删除通知信息")
@@ -208,6 +214,7 @@ public class NoticeController extends ControllerSupport {
             domain.setPublisher(info.getPublisher());
             domain.setPublishTime(info.getPublishTime());
             domain.setHasRead(info.getHasRead());
+            domain.setHasRecalled(info.getHasRecalled());
             domain.setTitle(info.getTitle());
             resultList.add(domain);
         }

+ 13 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/bean/UserNoticeDomain.java

@@ -51,6 +51,11 @@ public class UserNoticeDomain implements JsonSerializable {
      */
     @ApiModelProperty("读取状态")
     private Boolean hasRead;
+    /**
+     * 撤回状态
+     */
+    @ApiModelProperty("撤回状态")
+    private Boolean hasRecalled;
 
     public Long getId() {
         return id;
@@ -99,4 +104,12 @@ public class UserNoticeDomain implements JsonSerializable {
     public void setHasRead(Boolean hasRead) {
         this.hasRead = hasRead;
     }
+
+    public Boolean getHasRecalled() {
+        return hasRecalled;
+    }
+
+    public void setHasRecalled(Boolean hasRecalled) {
+        this.hasRecalled = hasRecalled;
+    }
 }

+ 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);
 }

+ 14 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/bean/UserNoticeInfo.java

@@ -55,6 +55,12 @@ public class UserNoticeInfo implements JsonSerializable {
     @ApiModelProperty("读取状态")
     private Boolean hasRead;
 
+    /**
+     * 撤回状态
+     */
+    @ApiModelProperty("撤回状态")
+    private Boolean hasRecalled;
+
     public Long getId() {
         return id;
     }
@@ -102,4 +108,12 @@ public class UserNoticeInfo implements JsonSerializable {
     public void setHasRead(Boolean hasRead) {
         this.hasRead = hasRead;
     }
+
+    public Boolean getHasRecalled() {
+        return hasRecalled;
+    }
+
+    public void setHasRecalled(Boolean hasRecalled) {
+        this.hasRecalled = hasRecalled;
+    }
 }

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

@@ -100,6 +100,7 @@ public class NoticeServiceImpl implements NoticeService {
                 info.setPublisher(noticeEntity.getPublisher());
                 info.setPublishTime(noticeEntity.getPublishTime());
                 info.setHasRead(un.getHasRead());
+                info.setHasRecalled(un.getHasRecalled());
                 resultList.add(info);
             }
         }
@@ -301,24 +302,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 {