diff --git a/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java index 9b72f0a6..864a86cd 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java @@ -1,5 +1,8 @@ package com.zc.business.mapper; +import com.ruoyi.common.annotation.DataScope; +import com.ruoyi.common.annotation.DataSource; +import com.ruoyi.common.enums.DataSourceType; import com.zc.business.domain.DcBoardReleaseLog; import com.zc.business.domain.DcDevice; import com.zc.business.domain.MdDeviceData; @@ -13,7 +16,7 @@ import java.util.List; * @author ruoyi * @date 2024-01-05 */ -public interface MiddleDatabaseMapper +public interface MiddleDatabaseMapper { /** diff --git a/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java index 9ebaf619..1d669667 100644 --- a/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java +++ b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java @@ -1,5 +1,6 @@ package com.zc.business.service; +import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcBoardPublish; import com.zc.business.domain.DcDevice; diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java index a0c2b780..b922c48d 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java @@ -12,6 +12,7 @@ import com.ruoyi.system.service.ISysDeptService; import com.zc.business.domain.*; import com.zc.business.mapper.*; import com.zc.business.service.IDcEventService; +import com.zc.business.service.IMiddleDatabaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -58,6 +59,8 @@ private DcEventAbnormalWeatherMapper dcEventAbnormalWeatherMapper; //部门信息 @Autowired private ISysDeptService deptService; + @Autowired + private IMiddleDatabaseService middleDatabaseService; @@ -131,6 +134,11 @@ dcEvent.setUserId(SecurityUtils.getUserId()); int i7 = dcEventMapper.insertDcEvent(dcEvent); if (i7>0){ + + //中间库 +// MdEvent mdEvent = new MdEvent(dcEvent); +// middleDatabaseService.insertMiddleDatabaseEvent(mdEvent); + //获取事件类型 int eventType = Math.toIntExact(dcEvent.getEventType()); switch (eventType){ @@ -205,6 +213,11 @@ dcEvent.setUserId(SecurityUtils.getUserId()); dcEvent.setUpdateTime(DateUtils.getNowDate()); int i7 = dcEventMapper.updateDcEvent(dcEvent); if (i7>0) { + + //中间库 +// MdEvent mdEvent = new MdEvent(dcEvent); +// middleDatabaseService.updateMiddleDatabaseEvent(mdEvent); + int eventType = Math.toIntExact(dcEvent.getEventType()); switch (eventType){ //交通事故 diff --git a/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java index be315357..0ea93378 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java @@ -1,5 +1,6 @@ package com.zc.business.service.impl; +import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.enums.DataSourceType; @@ -11,6 +12,8 @@ import com.zc.business.mapper.MiddleDatabaseMapper; import com.zc.business.service.IMiddleDatabaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -21,6 +24,8 @@ import java.util.List; * @date 2024-01-03 */ @Service +@DataSource(value = DataSourceType.SLAVE)//切换数据源 +@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { @@ -34,7 +39,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { * @param mdDeviceData 气象检测器数据 * @return 结果 */ - @DataSource(value = DataSourceType.SLAVE)//切换数据源 +// @DataSource(value = DataSourceType.SLAVE)//切换数据源 @Override public boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData) { @@ -48,7 +53,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { * @param listDevice 设备列表 * @return 结果 */ - @DataSource(value = DataSourceType.SLAVE)//切换数据源 +// @DataSource(value = DataSourceType.SLAVE)//切换数据源 @Override public boolean updateMiddleDatabaseDeviceByList(List listDevice) { @@ -65,7 +70,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { * @param device 设备 * @return 结果 */ - @DataSource(value = DataSourceType.SLAVE)//切换数据源 +// @DataSource(value = DataSourceType.SLAVE)//切换数据源 @Override public boolean updateMiddleDatabaseDevice(DcDevice device) { @@ -78,13 +83,12 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { * @param mdEvent 事件 * @return 结果 */ - @DataSource(value = DataSourceType.SLAVE)//切换数据源 @Override public boolean insertMiddleDatabaseEvent(MdEvent mdEvent){ - LoginUser loginUser = SecurityUtils.getLoginUser(); + /* LoginUser loginUser = SecurityUtils.getLoginUser(); if (loginUser != null) { mdEvent.setCreatorUserId(loginUser.getUserId()); - } + }*/ return middleDatabaseMapper.insertMiddleDatabaseEvent(mdEvent); } @@ -94,7 +98,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { * @param mdEvent 事件 * @return 结果 */ - @DataSource(value = DataSourceType.SLAVE)//切换数据源 +// @DataSource(value = DataSourceType.SLAVE)//切换数据源 @Override public boolean updateMiddleDatabaseEvent(MdEvent mdEvent){ LoginUser loginUser = SecurityUtils.getLoginUser();