Browse Source

收到添加事件时同步添加到中间库

develop
lau572 9 months ago
parent
commit
32ff4b3256
  1. 3
      zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java
  2. 1
      zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java
  3. 13
      zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java
  4. 18
      zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java

3
zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java

@ -1,5 +1,8 @@
package com.zc.business.mapper; 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.DcBoardReleaseLog;
import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDevice;
import com.zc.business.domain.MdDeviceData; import com.zc.business.domain.MdDeviceData;

1
zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java

@ -1,5 +1,6 @@
package com.zc.business.service; package com.zc.business.service;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcBoardPublish; import com.zc.business.domain.DcBoardPublish;
import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDevice;

13
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.domain.*;
import com.zc.business.mapper.*; import com.zc.business.mapper.*;
import com.zc.business.service.IDcEventService; import com.zc.business.service.IDcEventService;
import com.zc.business.service.IMiddleDatabaseService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -58,6 +59,8 @@ private DcEventAbnormalWeatherMapper dcEventAbnormalWeatherMapper;
//部门信息 //部门信息
@Autowired @Autowired
private ISysDeptService deptService; private ISysDeptService deptService;
@Autowired
private IMiddleDatabaseService middleDatabaseService;
@ -131,6 +134,11 @@ dcEvent.setUserId(SecurityUtils.getUserId());
int i7 = dcEventMapper.insertDcEvent(dcEvent); int i7 = dcEventMapper.insertDcEvent(dcEvent);
if (i7>0){ if (i7>0){
//中间库
// MdEvent mdEvent = new MdEvent(dcEvent);
// middleDatabaseService.insertMiddleDatabaseEvent(mdEvent);
//获取事件类型 //获取事件类型
int eventType = Math.toIntExact(dcEvent.getEventType()); int eventType = Math.toIntExact(dcEvent.getEventType());
switch (eventType){ switch (eventType){
@ -205,6 +213,11 @@ dcEvent.setUserId(SecurityUtils.getUserId());
dcEvent.setUpdateTime(DateUtils.getNowDate()); dcEvent.setUpdateTime(DateUtils.getNowDate());
int i7 = dcEventMapper.updateDcEvent(dcEvent); int i7 = dcEventMapper.updateDcEvent(dcEvent);
if (i7>0) { if (i7>0) {
//中间库
// MdEvent mdEvent = new MdEvent(dcEvent);
// middleDatabaseService.updateMiddleDatabaseEvent(mdEvent);
int eventType = Math.toIntExact(dcEvent.getEventType()); int eventType = Math.toIntExact(dcEvent.getEventType());
switch (eventType){ switch (eventType){
//交通事故 //交通事故

18
zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java

@ -1,5 +1,6 @@
package com.zc.business.service.impl; package com.zc.business.service.impl;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.enums.DataSourceType;
@ -11,6 +12,8 @@ import com.zc.business.mapper.MiddleDatabaseMapper;
import com.zc.business.service.IMiddleDatabaseService; import com.zc.business.service.IMiddleDatabaseService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -21,6 +24,8 @@ import java.util.List;
* @date 2024-01-03 * @date 2024-01-03
*/ */
@Service @Service
@DataSource(value = DataSourceType.SLAVE)//切换数据源
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
@ -34,7 +39,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param mdDeviceData 气象检测器数据 * @param mdDeviceData 气象检测器数据
* @return 结果 * @return 结果
*/ */
@DataSource(value = DataSourceType.SLAVE)//切换数据源 // @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override @Override
public boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData) public boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData)
{ {
@ -48,7 +53,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param listDevice 设备列表 * @param listDevice 设备列表
* @return 结果 * @return 结果
*/ */
@DataSource(value = DataSourceType.SLAVE)//切换数据源 // @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override @Override
public boolean updateMiddleDatabaseDeviceByList(List<DcDevice> listDevice) public boolean updateMiddleDatabaseDeviceByList(List<DcDevice> listDevice)
{ {
@ -65,7 +70,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param device 设备 * @param device 设备
* @return 结果 * @return 结果
*/ */
@DataSource(value = DataSourceType.SLAVE)//切换数据源 // @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override @Override
public boolean updateMiddleDatabaseDevice(DcDevice device) public boolean updateMiddleDatabaseDevice(DcDevice device)
{ {
@ -78,13 +83,12 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param mdEvent 事件 * @param mdEvent 事件
* @return 结果 * @return 结果
*/ */
@DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override @Override
public boolean insertMiddleDatabaseEvent(MdEvent mdEvent){ public boolean insertMiddleDatabaseEvent(MdEvent mdEvent){
LoginUser loginUser = SecurityUtils.getLoginUser(); /* LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null) { if (loginUser != null) {
mdEvent.setCreatorUserId(loginUser.getUserId()); mdEvent.setCreatorUserId(loginUser.getUserId());
} }*/
return middleDatabaseMapper.insertMiddleDatabaseEvent(mdEvent); return middleDatabaseMapper.insertMiddleDatabaseEvent(mdEvent);
} }
@ -94,7 +98,7 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param mdEvent 事件 * @param mdEvent 事件
* @return 结果 * @return 结果
*/ */
@DataSource(value = DataSourceType.SLAVE)//切换数据源 // @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override @Override
public boolean updateMiddleDatabaseEvent(MdEvent mdEvent){ public boolean updateMiddleDatabaseEvent(MdEvent mdEvent){
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();

Loading…
Cancel
Save