瀏覽代碼

统计界面接口和全部已读后修改发文状态为已完成

zh 3 年之前
父節點
當前提交
f0ab53f9c8

+ 7 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/MessageController.java

@@ -3,6 +3,7 @@ package com.boman.web.core.controller;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.QueryBySqlDto;
+import com.boman.web.core.domain.MessageDto;
 import com.boman.web.core.service.message.MessageService;
 import org.springframework.web.bind.annotation.*;
 
@@ -71,4 +72,10 @@ public class MessageController {
     public AjaxResult toDoMessage(@RequestBody FormDataDto dto) {
         return service.toDoMessage(dto);
     }
+
+    @PostMapping("/receiveMessage")
+    public AjaxResult receiveMessage(@RequestBody MessageDto dto) {
+        return service.receiveMessage(dto);
+    }
+
 }

+ 41 - 0
boman-web-core/src/main/java/com/boman/web/core/domain/MessageDto.java

@@ -0,0 +1,41 @@
+package com.boman.web.core.domain;
+
+import com.alibaba.fastjson.annotation.JSONField;
+
+import java.io.Serializable;
+
+public class MessageDto implements Serializable {
+
+    @JSONField(name = "objId")
+    private Long objId;
+
+    @JSONField(name = "messageId")
+    private Long messageId;
+
+    @JSONField(name = "receiveTime")
+    private String receiveTime;
+
+    public Long getObjId() {
+        return objId;
+    }
+
+    public void setObjId(Long objId) {
+        this.objId = objId;
+    }
+
+    public Long getMessageId() {
+        return messageId;
+    }
+
+    public void setMessageId(Long messageId) {
+        this.messageId = messageId;
+    }
+
+    public String getReceiveTime() {
+        return receiveTime;
+    }
+
+    public void setReceiveTime(String receiveTime) {
+        this.receiveTime = receiveTime;
+    }
+}

+ 73 - 6
boman-web-core/src/main/java/com/boman/web/core/mapper/MessageMapper.java

@@ -3,11 +3,9 @@ package com.boman.web.core.mapper;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.SqlProviderUtils;
 import com.boman.domain.jflow.ProcessNodeCandidator;
+import io.swagger.models.auth.In;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.SelectProvider;
+import org.apache.ibatis.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -26,7 +24,7 @@ public interface MessageMapper {
 
     /**
      * 功能描述: 自定义查询,需要查询的字段和value都在condition中
-     * {@link StandardMapper.SqlProvider#countByCondition(Map)}
+     * {@link MessageMapper.SqlProvider#countByCondition(Map)}
      *
      * @param username username
      * @return int
@@ -34,12 +32,58 @@ public interface MessageMapper {
     @SelectProvider(type = MessageMapper.SqlProvider.class, method = "countByCondition")
     int countByCondition(@Param("username") String username);
 
-
+    /**
+     * 功能描述: 查询
+     * {@link MessageMapper.SqlProvider#selectByCondition(Map)}
+     *
+     * @param username username
+     * @return int
+     */
     @SelectProvider(type = MessageMapper.SqlProvider.class, method = "selectByCondition")
     List<JSONObject> toDoMessage(@Param("username") String username
             , @Param("limit") int limit
             , @Param("offset") int offset);
 
+    /**
+     * 功能描述: 查询
+     * {@link MessageMapper.SqlProvider#getIndexCountInfo(Map)}
+     *
+     * @param userId userId
+     * @return int
+     */
+    @SelectProvider(type = MessageMapper.SqlProvider.class, method = "getIndexCountInfo")
+    Long getIndexCountInfo(@Param("userId") Long userId, @Param("dateStr") String dateStr);
+
+    /**
+     * 功能描述: 统计是否完成全部已读
+     *
+     * {@link MessageMapper.SqlProvider#countReceive(Map)}
+     *
+     * @param messageId userId
+     * @return int
+     */
+    @SelectProvider(type = MessageMapper.SqlProvider.class, method = "countReceive")
+    Integer countReceive(@Param("messageId") Long messageId);
+
+    /**
+     * {@link MessageMapper.SqlProvider#updateReceive(Map)}
+     *
+     * @param dataId
+     * @param receiveTime
+     * @return
+     */
+    @UpdateProvider(type = MessageMapper.SqlProvider.class, method = "updateReceive")
+    int updateReceive(@Param("dataId") Long dataId, @Param("receiveTime") String receiveTime);
+
+    /**
+     * {@link MessageMapper.SqlProvider#updateMessageSituationStatus(Map)}
+     *
+     * @param dataId
+     * @return
+     */
+    @UpdateProvider(type = MessageMapper.SqlProvider.class, method = "updateMessageSituationStatus")
+    int updateMessageSituationStatus(@Param("dataId") Long dataId);
+
     class SqlProvider {
 
         public String countByCondition(Map<String, Object> para) {
@@ -59,5 +103,28 @@ public interface MessageMapper {
             LOGGER.info("查询拼出的sql语句为:{} \r\n", result);
             return result;
         }
+
+        public String getIndexCountInfo(Map<String, Object> para) {
+            String result = "SELECT count(1)  FROM boman_message  WHERE send_user_id = " + para.get("userId") + "  " +
+                    " AND DATE_FORMAT(create_time, '%Y-%m-%d') = '" + para.get("dateStr") + "'  AND message_situation <> '3'";
+
+            LOGGER.info("查询拼出的sql语句为:{} \r\n", result);
+            return result;
+        }
+
+        public String countReceive(Map<String, Object> para) {
+            String result = "select count(1) from boman_message_receive t where t.visible  = 'Y' and status = 'N' and t.message_id = " + para.get("messageId");
+            return result;
+        }
+
+        public String updateReceive(Map<String, Object> para) {
+            String sql = "update boman_message_receive set status = 'Y', receive_time = str_to_date('" + para.get("receiveTime") + "', '%Y-%m-%d %H:%i:%s') where id = " + para.get("dataId");
+            return sql;
+        }
+
+        public String updateMessageSituationStatus(Map<String, Object> para) {
+            String sql = "update boman_message set message_situation = '2' where id = " + para.get("dataId");
+            return sql;
+        }
     }
 }

+ 7 - 12
boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/BomanMessageReceiveServiceImpl.java

@@ -6,6 +6,7 @@ import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.StringUtils;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.mapper.MessageMapper;
 import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import com.sun.org.apache.regexp.internal.RE;
@@ -37,6 +38,8 @@ public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveServi
 
     @Autowired
     private IBaseSelectService selectService;
+    @Autowired
+    private MessageMapper messageMapper;
     @Resource
     private ICommonService commonService;
 
@@ -73,17 +76,9 @@ public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveServi
      */
     @Override
     public AjaxResult getIndexInfo(String userId) {
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("send_user_id",userId);
-        //备注,boman_message表中create_time需要在gen_table_column中设置like
-        jsonObject.put("create_time", DateUtils.getDate());
-        jsonObject.put("message_situation","1");
         //查询今日发文
-        List<JSONObject> bomanMessage = selectService.getByMap("boman_message", jsonObject);
-        long toDaySend = 0;
-        if (bomanMessage != null && bomanMessage.size() > 0){
-            toDaySend = bomanMessage.size();
-        }
+        Long toDaySend = messageMapper.getIndexCountInfo(Long.valueOf(userId), DateUtils.getDate());
+
         JSONObject jsonObjectTwo = new JSONObject();
         jsonObjectTwo.put("receive_user_id",userId);
         jsonObjectTwo.put("visible","Y");
@@ -93,9 +88,9 @@ public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveServi
         long todayReceipt = 0L;
         if (bomanMessageReceive != null && bomanMessageReceive.size() > 0){
             //未读
-             unread = bomanMessageReceive.stream().filter(e -> e.get("status") == "N").count();
+            unread = bomanMessageReceive.stream().filter(e -> e.get("status").equals("N")).count();
             //已读
-             read = bomanMessageReceive.stream().filter(e -> e.get("status") == "Y").count();
+            read = bomanMessageReceive.stream().filter(e -> e.get("status").equals("Y")).count();
             //今日收文
              todayReceipt = bomanMessageReceive.stream().filter(e -> DateUtils.formatDate(e.get("send_message_time").toString(), DateUtils.YYYY_MM_DD).equals(DateUtils.getDate())).count();
         }

+ 9 - 0
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageService.java

@@ -3,6 +3,7 @@ package com.boman.web.core.service.message;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.QueryBySqlDto;
+import com.boman.web.core.domain.MessageDto;
 
 /**
  * @author shiqian
@@ -41,4 +42,12 @@ public interface MessageService {
      * @return List<JSONObject>
      */
     AjaxResult toDoMessage(FormDataDto dto);
+
+    /**
+     * 修改收文情况
+     *
+     * @param dto
+     * @return
+     */
+    AjaxResult receiveMessage(MessageDto dto);
 }

+ 15 - 0
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageServiceImpl.java

@@ -6,6 +6,7 @@ import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.domain.MessageDto;
 import com.boman.web.core.mapper.MessageMapper;
 import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.service.bomanMessageReceive.IBomanMessageReceiveService;
@@ -141,4 +142,18 @@ public class MessageServiceImpl implements MessageService {
         rows.put(PAGE_ROWS, result);
         return AjaxResult.success(rows);
     }
+
+    @Override
+    @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
+    public AjaxResult receiveMessage(MessageDto dto) {
+        // 第一步修改收文时间和状态
+        Integer updates = messageMapper.updateReceive(dto.getObjId(), dto.getReceiveTime());
+        // 统计是否还有未读
+        Integer unRead = messageMapper.countReceive(dto.getMessageId());
+        LOGGER.info("已读人数还有{}人。", unRead);
+        if(unRead == 0) {
+            messageMapper.updateMessageSituationStatus(dto.getMessageId());
+        }
+        return AjaxResult.success(updates);
+    }
 }