Browse Source

feature: 同步服务完善
1.全量教职双向同步

luoyb 1 năm trước cách đây
mục cha
commit
49047c9983

+ 2 - 0
.gitignore

@@ -45,3 +45,5 @@ nbdist/
 !*/build/*.xml
 
 .flattened-pom.xml
+/jrebel-classpath-27688.jar
+/ruoyi-server/ruoyi-server-consume/Dockerfile

+ 9 - 0
ruoyi-api/ruoyi-api-backstage/src/main/java/org/dromara/backstage/api/RemoteCardService.java

@@ -1,5 +1,6 @@
 package org.dromara.backstage.api;
 
+import org.dromara.backstage.api.domain.bo.RemoteCardBo;
 import org.dromara.backstage.api.domain.vo.RemoteCardVo;
 
 import java.math.BigDecimal;
@@ -72,4 +73,12 @@ public interface RemoteCardService {
      * @return 更新结果
      */
     Boolean updateCardDayData(Long cardNo, Long mealType, BigDecimal consumeValue, Date consumeDate);
+
+    /**
+     * 保存楼增加卡片信息
+     * @param bo 卡片业务对象
+     * @return 卡片视图对象
+     */
+    RemoteCardVo saveOrUpdate(RemoteCardBo bo);
+
 }

+ 7 - 0
ruoyi-api/ruoyi-api-backstage/src/main/java/org/dromara/backstage/api/domain/bo/RemoteCardBo.java

@@ -40,7 +40,14 @@ public class RemoteCardBo implements Serializable {
      * 卡片类型
      */
     private Long cardType;
+    /**
+     * 卡片操作类型
+     */
     private CardOperateEnum operateType;
+
+    /**
+     * 工作站编号
+     */
     private Long stationNumb;
     /**
      * 租户Id

+ 1 - 1
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CloudMqEventConstants.java

@@ -13,7 +13,7 @@ public interface CloudMqEventConstants {
     /**
      * 队列topic
      */
-    String TOPIC = "TO_CLOUD_EVENT";
+    String TOPIC = "CLOUD_PUSH_EVENT";
     /**
      * 业务系统编号
      */

+ 1 - 1
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/business/accouunt/UserAccountBusiness.java

@@ -118,7 +118,7 @@ public class UserAccountBusiness {
             message.setHeader(header);
             message.setBody(vo);
 
-            kafkaNormalProducer.sendKafkaMessage(CloudMqEventConstants.ACCOUNT, message);
+            kafkaNormalProducer.sendKafkaMessage(CloudMqEventConstants.TOPIC, message);
         }
     }
 }

+ 13 - 1
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/cardCenter/dubbo/RemoteCardServiceImpl.java

@@ -1,9 +1,12 @@
 package org.dromara.backstage.cardCenter.dubbo;
 
+import cn.hutool.core.bean.BeanUtil;
 import lombok.RequiredArgsConstructor;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.dromara.backstage.api.RemoteCardService;
+import org.dromara.backstage.api.domain.bo.RemoteCardBo;
 import org.dromara.backstage.api.domain.vo.RemoteCardVo;
+import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
 import org.dromara.backstage.domain.vo.card.PtCardVo;
 import org.dromara.backstage.cardCenter.service.IPtCardService;
 import org.dromara.common.core.utils.MapstructUtils;
@@ -97,6 +100,15 @@ public class RemoteCardServiceImpl implements RemoteCardService {
     public Boolean updateCardDayData(Long cardNo, Long mealType, BigDecimal consumeValue, Date consumeDate) {
         return cardService.updateCardDayData(cardNo, mealType, consumeValue, consumeDate);
     }
-
+    /**
+     * 保存楼增加卡片信息
+     * @param bo 卡片业务对象
+     * @return 卡片视图对象
+     */
+    @Override
+    public RemoteCardVo saveOrUpdate(RemoteCardBo bo) {
+        PtCardVo vo = cardService.saveOrUpdate(BeanUtil.copyProperties(bo, PtCardBo.class));
+        return MapstructUtils.convert(vo, RemoteCardVo.class);
+    }
 }
 

+ 1 - 1
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/cardCenter/service/impl/PtCardServiceImpl.java

@@ -551,7 +551,7 @@ public class PtCardServiceImpl implements IPtCardService {
             message.setHeader(header);
             message.setBody(vo);
 
-            kafkaNormalProducer.sendKafkaMessage(CloudMqEventConstants.CARD, message);
+            kafkaNormalProducer.sendKafkaMessage(CloudMqEventConstants.TOPIC, message);
         }
     }
 }

+ 40 - 0
ruoyi-server/ruoyi-server-mqdata/src/main/java/org/dromara/server/mq/event/kafka/impl/cloud/PushCardEventStrategyImpl.java

@@ -0,0 +1,40 @@
+package org.dromara.server.mq.event.kafka.impl.cloud;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.dromara.backstage.api.RemoteCardService;
+import org.dromara.backstage.api.RemoteUserAccountService;
+import org.dromara.backstage.api.domain.bo.RemoteCardBo;
+import org.dromara.backstage.api.domain.bo.RemoteUserAccountBo;
+import org.dromara.backstage.api.domain.vo.RemoteCardVo;
+import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
+import org.dromara.common.core.constant.CloudMqEventConstants;
+import org.dromara.server.mq.event.kafka.IEventStrategy;
+import org.springframework.stereotype.Service;
+
+/**
+ * @ClassName PushCardEventStrategyImpl
+ * @Description 处理卡片消息队列
+ * @Author luoyibo
+ * @Date 2024-11-12 11:52
+ * @Version 1.0
+ * @since jdk17
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service(CloudMqEventConstants.CARD)
+public class PushCardEventStrategyImpl implements IEventStrategy {
+    @DubboReference
+    private final RemoteCardService remoteCardService;
+
+    @Override
+    public void doMsgHandle(JSONObject data) {
+        RemoteCardBo remoteBo = JSONUtil.toBean(data, RemoteCardBo.class);
+        log.info("[处理云端卡片同步请求]-[卡片信息:{}]", JSONUtil.toJsonStr(remoteBo));
+        remoteCardService.saveOrUpdate(remoteBo);
+    }
+}

+ 2 - 2
ruoyi-server/ruoyi-server-mqdata/src/main/java/org/dromara/server/mq/event/kafka/impl/cloud/PushDeptEventStrategyImpl.java

@@ -40,7 +40,7 @@ public class PushDeptEventStrategyImpl implements IEventStrategy {
     @Override
     public void doMsgHandle(JSONObject data) {
         RemoteDeptBo remoteDeptBo = JSONUtil.toBean(data, RemoteDeptBo.class);
-        log.info("[云端处理部门同步请求]-[部门信息:{}]", JSONUtil.toJsonStr(remoteDeptBo));
+        log.info("[处理云端部门同步请求]-[部门信息:{}]", JSONUtil.toJsonStr(remoteDeptBo));
         RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(remoteDeptBo.getDeptId());
         if (ObjectUtil.isEmpty(remoteDeptVo)) {
             remoteDeptService.insertDept(remoteDeptBo);
@@ -59,7 +59,7 @@ public class PushDeptEventStrategyImpl implements IEventStrategy {
             remoteTeamBo.setOtherId(remoteDeptBo.getOtherId());
             remoteTeamBo.setTenantId(remoteDeptBo.getTenantId());
             remoteTeamBo.setOperatorId(ObjectUtil.isEmpty(remoteDeptBo.getCreateBy()) ? remoteDeptBo.getUpdateBy() : remoteDeptBo.getCreateBy());
-            log.info("[云端处理部门至团客]-[团客信息:{}]", JSONUtil.toJsonStr(remoteTeamBo));
+            log.info("[处理云端部门至团客]-[团客信息:{}]", JSONUtil.toJsonStr(remoteTeamBo));
             R<RemoteTeamVo> remoteTeamVo = remoteTeamService.selectTeamByBo(remoteTeamBo);
             if(R.isSuccess(remoteTeamVo)){
                 remoteTeamService.updateTeamByBo(remoteTeamBo);

+ 45 - 0
ruoyi-server/ruoyi-server-mqdata/src/main/java/org/dromara/server/mq/event/kafka/impl/cloud/PushUserAccountEventStrategyImpl.java

@@ -0,0 +1,45 @@
+package org.dromara.server.mq.event.kafka.impl.cloud;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.dromara.backstage.api.RemoteUserAccountService;
+import org.dromara.backstage.api.domain.bo.RemoteUserAccountBo;
+import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
+import org.dromara.common.core.constant.CloudMqEventConstants;
+import org.dromara.server.mq.event.kafka.IEventStrategy;
+import org.dromara.system.api.RemoteUserService;
+import org.dromara.system.api.domain.bo.RemoteUserBo;
+import org.dromara.system.api.domain.vo.RemoteUserVo;
+import org.springframework.stereotype.Service;
+
+/**
+ * @ClassName PushUserAccountEventStrategyImpl
+ * @Description 处理一卡通账户消息队列
+ * @Author luoyibo
+ * @Date 2024-11-12 11:52
+ * @Version 1.0
+ * @since jdk17
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service(CloudMqEventConstants.ACCOUNT)
+public class PushUserAccountEventStrategyImpl implements IEventStrategy {
+    @DubboReference
+    private final RemoteUserAccountService remoteAccountService;
+
+    @Override
+    public void doMsgHandle(JSONObject data) {
+        RemoteUserAccountBo remoteBo = JSONUtil.toBean(data, RemoteUserAccountBo.class);
+        log.info("[处理云端一卡通账户同步请求]-[账户信息:{}]", JSONUtil.toJsonStr(remoteBo));
+        RemoteUserAccountVo remoteVo = remoteAccountService.getUserAccountVoById(remoteBo.getUserId());
+        if(ObjectUtil.isEmpty(remoteVo)){
+            remoteAccountService.insertByBo(remoteBo);
+        } else {
+            remoteAccountService.updateByBo(remoteBo);
+        }
+    }
+}