Browse Source

评价提醒推送消息

wucl 2 years ago
parent
commit
d0b8d4a9d0

+ 5 - 17
biz-base/src/main/java/com/dayou/controller/MessageController.java

@@ -1,27 +1,15 @@
 package com.dayou.controller;
 
-import com.dayou.message.bo.SystemMessageBO;
+import com.dayou.message.MessageServerCenter;
 import com.dayou.message.handler.SystemMessageHandler;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.web.bind.annotation.RestController;
-import com.dayou.controller.BaseController;
-import com.dayou.service.IMessageService;
 import com.dayou.entity.Message;
 import com.dayou.common.RestResponse;
 import org.springframework.web.bind.annotation.*;
-import com.dayou.utils.ConvertUtil;
-import com.dayou.utils.HttpKit;
-import com.dayou.exception.ErrorCode;
-import java.util.Date;
 import java.util.List;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import org.springframework.http.MediaType;
-import org.springframework.web.multipart.MultipartFile;
 /**
  * 消息
  *
@@ -31,14 +19,14 @@ import org.springframework.web.multipart.MultipartFile;
 @RestController
 @RequestMapping("message")
 @Slf4j
-public class MessageController extends BaseController {
+public class MessageController {
 
     @Autowired
-    private IMessageService messageService;
+    private SystemMessageHandler systemMessageHandler;
 
     @GetMapping("/notRead")
     public RestResponse<List<Message>> messageRedPoint(){
-        List<Message> list = messageService.messageRedPoint();
+        List<Message> list = systemMessageHandler.messageRedPoint();
         return RestResponse.data(list);
     }
 
@@ -49,7 +37,7 @@ public class MessageController extends BaseController {
      */
     @GetMapping("/updateRead/{id}")
     public RestResponse<Boolean> updateRead(@PathVariable("id") Long id){
-        Boolean result = messageService.updateRead(id);
+        Boolean result = systemMessageHandler.readMessage(id);
         return RestResponse.data(result);
     }
 }

+ 3 - 1
common/src/main/java/com/dayou/configuration/AsyncManager.java

@@ -299,7 +299,9 @@ public class AsyncManager {
      * 异步业务类型
      */
     public enum AsyncBiz implements CodeMsgEnumInterface<String, String> {
-        BROKERAGE_SETTLE("BROKERAGE_SETTLE","提成结算")
+        BROKERAGE_SETTLE("BROKERAGE_SETTLE","提成结算"),
+
+        PACKAGING_EVALUATE_REMAIN("PACKAGING_EVALUATE_REMAIN","打包评价提醒消息")
         ;
 
         private String key;

+ 2 - 0
dao/src/main/java/com/dayou/mapper/ItemMapper.java

@@ -47,4 +47,6 @@ public interface ItemMapper extends CustomBaseMapper<Item> {
     ItemDTO  getItemByBrokerageGeneralId(@Param("generalId") Long generalId);
 
     Set<ItemBrokerageGeneralDTO> getLastMonthTeamItems(@Param("lastMonth23")LocalDate lastMonth23, @Param("juniorUserIds") Set<Long> juniorUserIds);
+
+    List<ItemVO> getCompletedNotEvaluateItem();
 }

+ 54 - 0
dao/src/main/resources/mapper/ItemMapper.xml

@@ -404,4 +404,58 @@
             )
           and ibg.marketer_status != 'CLOSED'
     </select>
+
+    <select id="getCompletedNotEvaluateItem" resultType="com.dayou.vo.ItemVO">
+        SELECT
+        i.id,
+        i.user_id,
+        i.name,
+        (	CASE when  ((SELECT count(*) FROM item_stage s
+                          WHERE
+                              s.item_id = i.id
+                            AND curDate() &gt;= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
+                            AND curDate() &lt;= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id )
+                         )=0
+
+            AND
+
+                         ( SELECT count(*) FROM item_stage s WHERE s.item_id = i.id ) !=0 )
+
+            THEN
+        '已完成'
+
+        WHEN
+        (SELECT
+        count(*)
+        FROM
+        item_stage s
+        WHERE
+        s.item_id = i.id
+        AND curDate() &gt;= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
+        AND curDate() &lt;= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id ) )
+        !=0
+        THEN
+        '进行中'
+        WHEN
+        (SELECT
+        count(*)
+        FROM
+        item_stage s
+        WHERE
+        s.item_id = i.id)= 0
+        THEN
+        '未开始'
+        ELSE ''
+        END
+        ) AS itemStatus
+        FROM
+        item i
+        WHERE
+        i.deleted = 0
+        GROUP BY
+        i.id
+        HAVING
+        itemStatus = '已完成'
+        AND NOT EXISTS ( SELECT id FROM item_evaluate WHERE item_id = i.id AND deleted = 0 )
+    </select>
 </mapper>

+ 2 - 1
dao/src/main/resources/mapper/MessageMapper.xml

@@ -10,6 +10,7 @@
         <result column="modified" property="modified" />
         <result column="title" property="title" />
         <result column="message" property="message" />
+        <result column="params" property="params" />
         <result column="sender" property="sender" />
         <result column="receiver" property="receiver" />
         <result column="type" property="type" />
@@ -22,7 +23,7 @@
         deleted,
         created,
         modified,
-        title, message, sender, receiver, type, is_read
+        title, message,params, sender, receiver, type, is_read
     </sql>
 
 </mapper>

+ 5 - 0
domain/src/main/java/com/dayou/entity/Message.java

@@ -35,6 +35,11 @@ public class Message extends BaseEntity {
     private String message;
 
     /**
+     * 业务参数
+     */
+    private String params;
+
+    /**
      * 消息发送人id(userId)
      */
     private Long sender;

+ 17 - 5
service/src/main/java/com/dayou/message/MessageServerCenter.java

@@ -1,7 +1,12 @@
 package com.dayou.message;
 
+import com.dayou.entity.Message;
+import com.dayou.service.IMessageService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 类说明:
  *
@@ -12,6 +17,9 @@ import org.springframework.stereotype.Service;
 @Service
 public abstract class MessageServerCenter<T> {
 
+    @Autowired
+    private IMessageService messageService;
+
     /**
      * 发送消息
      * @param t
@@ -20,20 +28,24 @@ public abstract class MessageServerCenter<T> {
     public abstract Boolean sendMessage(T t);
 
     /**
-     * 销毁消息
+     * 读取消息
      * @param id
      * @return
      */
-    protected Boolean destroyMessage(Long id){
-        return Boolean.TRUE;
+    public Boolean readMessage(Long id){
+        return messageService.updateRead(id);
+    }
+
+    public List<Message> messageRedPoint(){
+        return messageService.messageRedPoint();
     }
 
     /**
-     * 读取消息
+     * 销毁消息
      * @param id
      * @return
      */
-    protected Boolean readMessage(Long id){
+    public Boolean destroyMessage(Long id){
         return Boolean.TRUE;
     }
 

+ 3 - 2
service/src/main/java/com/dayou/message/MessageTitle.java

@@ -13,7 +13,8 @@ public interface MessageTitle
 
     public static final String SYSTEM_MESSAGE_TITLE = "系统消息[x]";
 
-    public static final String SETTLE_MESSAGE_TITLE = "提成结算";
-
     public static final String SETTLE_MESSAGE_CONTENT = "您好。您的上月项目提成已结算,请在[项目提成]菜单下查看明细,若有疑问请联系相关领导。";
+
+    public static final String EVALUATE_REMIND_CONTENT = "您好。[x]项目已完成,请及时评价。";
+
 }

+ 31 - 0
service/src/main/java/com/dayou/message/MessageTypeEnum.java

@@ -0,0 +1,31 @@
+package com.dayou.message;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2023/7/6
+ * created with IntelliJ IDEA.
+ */
+public enum MessageTypeEnum {
+
+    SETTLE("SETTLE","提成结算"),
+
+    EVALUATE_REMIND("EVALUATE_REMIND","评价提醒"),
+
+    BUSINESS("BUSINESS","业务消息")
+    ;
+
+    private String code;
+
+    private String name;
+
+    MessageTypeEnum(String code, String name) {
+        this.name = name;
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

+ 0 - 1
service/src/main/java/com/dayou/message/bo/BusinessMessageBO.java

@@ -25,5 +25,4 @@ public class BusinessMessageBO extends MessageBO{
      */
     private Long receiver;
 
-    private final String type = "BUSINESS";
 }

+ 10 - 0
service/src/main/java/com/dayou/message/bo/MessageBO.java

@@ -26,4 +26,14 @@ public class MessageBO {
      */
     private String message;
 
+    /**
+     * 业务参数
+     */
+    private String params;
+
+    /**
+     * 消息类型
+     */
+    private String type;
+
 }

+ 1 - 1
service/src/main/java/com/dayou/message/bo/SystemMessageBO.java

@@ -14,7 +14,7 @@ import java.util.List;
 @Data
 public class SystemMessageBO extends MessageBO{
 
-    private final String type = "SETTLE";
+
 
     private Long receiver;
 

+ 53 - 0
service/src/main/java/com/dayou/message/schedule/ItemStatusSchedule.java

@@ -0,0 +1,53 @@
+package com.dayou.message.schedule;
+
+import com.dayou.configuration.AsyncManager;
+import com.dayou.entity.Item;
+import com.dayou.enums.ItemStateEnum;
+import com.dayou.message.handler.SystemMessageHandler;
+import com.dayou.service.IItemService;
+import com.dayou.service.IMessageService;
+import com.dayou.vo.ItemVO;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 类说明:项目状态监听定时器
+ *
+ * @author: wucl
+ * @since: 2023/7/6
+ * created with IntelliJ IDEA.
+ */
+@Slf4j
+@Component
+public class ItemStatusSchedule {
+
+    @Autowired
+    private IItemService itemService;
+
+    @Autowired
+    private IMessageService messageService;
+
+    @Scheduled(cron = "0 0 1 * * ?")
+    public void sendMessage2Manager()
+    {
+        AsyncManager.me().execute(new AsyncManager.BizHandler() {
+            List<ItemVO> completedNotEvaluateItem = itemService.getCompletedNotEvaluateItem();
+            @Override
+            public Boolean validBefore() {
+                return CollectionUtils.isNotEmpty(completedNotEvaluateItem);
+            }
+
+            @Override
+            public Object doCustom() {
+                messageService.packagingEvaluateRemind(completedNotEvaluateItem);
+                return null;
+            }
+        }, AsyncManager.AsyncLockStrategy.LOCK_BIZ, AsyncManager.AsyncBiz.PACKAGING_EVALUATE_REMAIN);
+
+    }
+}

+ 2 - 0
service/src/main/java/com/dayou/service/IItemService.java

@@ -40,4 +40,6 @@ public interface IItemService extends IService<Item> {
 
 
     Boolean changManager(ItemDTO itemDTO);
+
+    List<ItemVO> getCompletedNotEvaluateItem();
 }

+ 3 - 0
service/src/main/java/com/dayou/service/IMessageService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.dayou.message.bo.BusinessMessageBO;
+import com.dayou.vo.ItemVO;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -29,4 +30,6 @@ public interface IMessageService extends IService<Message> {
     List<Message> messageRedPoint();
 
     Boolean updateRead(Long id);
+
+    void packagingEvaluateRemind(List<ItemVO> completedNotEvaluateItem);
 }

+ 5 - 0
service/src/main/java/com/dayou/service/impl/ItemServiceImpl.java

@@ -156,6 +156,11 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
         return this.update(new LambdaUpdateWrapper<Item>().set(Item::getUserId,itemDTO.getUserId()).eq(BaseEntity::getId,itemDTO.getId()));
     }
 
+    @Override
+    public List<ItemVO> getCompletedNotEvaluateItem() {
+        return itemMapper.getCompletedNotEvaluateItem();
+    }
+
 
     /**
      * 获取项目状态

+ 22 - 2
service/src/main/java/com/dayou/service/impl/MessageServiceImpl.java

@@ -5,6 +5,7 @@ import com.dayou.common.BaseEntity;
 import com.dayou.entity.BusinessReply;
 import com.dayou.entity.Message;
 import com.dayou.mapper.MessageMapper;
+import com.dayou.message.MessageTypeEnum;
 import com.dayou.message.bo.BusinessMessageBO;
 import com.dayou.message.bo.SystemMessageBO;
 import com.dayou.message.handler.BusinessMessageHandler;
@@ -12,6 +13,7 @@ import com.dayou.message.handler.SystemMessageHandler;
 import com.dayou.service.IMessageService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dayou.utils.LoginContext;
+import com.dayou.vo.ItemVO;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -40,6 +42,7 @@ import com.dayou.enums.BatchTaskTypeEnum;
 import static com.dayou.enums.BusinessReplyEnum.MARKET_LOG_REPLY;
 import static com.dayou.enums.BusinessReplyEnum.MARKET_VISIT_REPLY;
 import static com.dayou.message.MessageTitle.*;
+import static com.dayou.message.MessageTypeEnum.*;
 
 /**
  * <p>
@@ -64,8 +67,10 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
         messageBO.setReceiver(originalBO.getReceiverId());
         String bizType = originalBO.getBizType().equals(MARKET_VISIT_REPLY.name())?MARKET_VISIT_REPLY.getName(): MARKET_LOG_REPLY.getName();
         messageBO.setTitle(BUSINESS_MESSAGE_TITLE.replace("x", bizType));
-        messageBO.setMessage(JSON.toJSONString(originalBO));
+        messageBO.setMessage(originalBO.getContent());
+        messageBO.setParams(JSON.toJSONString(originalBO));
         messageBO.setSender(originalBO.getReplierId());
+        messageBO.setType(BUSINESS.name());
         return businessMessageHandler.sendMessage(messageBO);
     }
 
@@ -73,9 +78,10 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
     public Boolean packagingSettleMessage(Set<Long> userIds) {
         Set<SystemMessageBO> settleMessages = userIds.stream().map(x -> {
             SystemMessageBO systemMessageBO = new SystemMessageBO();
-            systemMessageBO.setTitle(SYSTEM_MESSAGE_TITLE.replace("x", SETTLE_MESSAGE_TITLE));
+            systemMessageBO.setTitle(SYSTEM_MESSAGE_TITLE.replace("x", SETTLE.getName()));
             systemMessageBO.setMessage(SETTLE_MESSAGE_CONTENT);
             systemMessageBO.setReceiver(x);
+            systemMessageBO.setType(SETTLE.name());
             return systemMessageBO;
         }).collect(Collectors.toSet());
         if (CollectionUtils.isNotEmpty(settleMessages)){
@@ -96,4 +102,18 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
     public Boolean updateRead(Long id) {
         return this.update(new LambdaUpdateWrapper<Message>().eq(BaseEntity::getId,id).set(Message::getIsRead,Boolean.TRUE));
     }
+
+    @Override
+    public void packagingEvaluateRemind(List<ItemVO> completedNotEvaluateItem) {
+        Set<SystemMessageBO> collect = completedNotEvaluateItem.stream().map(x -> {
+            SystemMessageBO systemMessageBO = new SystemMessageBO();
+            systemMessageBO.setType(EVALUATE_REMIND.name());
+            systemMessageBO.setTitle(SYSTEM_MESSAGE_TITLE.replace("x", EVALUATE_REMIND.getName()));
+            systemMessageBO.setMessage(EVALUATE_REMIND_CONTENT.replace("x", x.getName()));
+            systemMessageBO.setParams(JSON.toJSONString(x));
+            systemMessageBO.setReceiver(x.getUserId());
+            return systemMessageBO;
+        }).collect(Collectors.toSet());
+        systemMessageHandler.sendMessage(collect);
+    }
 }