Browse Source

数据平台维护设备信息时同步到中间库

develop
lau572 9 months ago
parent
commit
47b8828730
  1. 5
      zc-business/src/main/java/com/zc/business/domain/DcDevice.java
  2. 311
      zc-business/src/main/java/com/zc/business/domain/MdDevice.java
  3. 30
      zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java
  4. 32
      zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java
  5. 30
      zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java
  6. 45
      zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java
  7. 81
      zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml

5
zc-business/src/main/java/com/zc/business/domain/DcDevice.java

@ -53,6 +53,8 @@ public class DcDevice {
private String otherConfig;
@ApiModelProperty("备注")
private String remark;
@ApiModelProperty("设施归属类型(0:默认1: 道路沿线2:桥梁3: 隧道4:收费广场5: 收费站6: 服务区等")
private String facilitiesType;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("修改时间")
@ -61,4 +63,7 @@ public class DcDevice {
private String longitude;
@TableField(exist = false)
private String latitude;
//设备厂商
@TableField(exist = false)
private String manufacturer;
}

311
zc-business/src/main/java/com/zc/business/domain/MdDevice.java

@ -0,0 +1,311 @@
package com.zc.business.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
import java.util.Date;
/**
* 中间库 设备对象 device
*
* @author ruoyi
* @date 2024-02-21
*/
public class MdDevice
{
/** 主键 */
private Long id;
/** 设备id */
@Excel(name = "设备id")
private String devNo;
/** 设备名称 */
@Excel(name = "设备名称")
private String devName;
/** 所在桩号 */
@Excel(name = "所在桩号")
private String stakeNum;
/** 方向1-上行,2-中,3-下行 */
@Excel(name = "方向1-上行,2-中,3-下行")
private String direction;
/** 设备类型
1 摄像机
2 可变信息标志
3 气象监测器
4 出口诱导灯
5 路段语音广播
6 护栏碰撞
7 毫米波雷达
8 合流区预警
9 智慧锥桶
10 激光疲劳唤醒
11 一类交通量调查站
12 行车诱导
13 智能设备箱
14 光线在线监测
*/
@Excel(name = "设备类型")
private String typeCode;
/** 设施归属类型(0:默认1: 道路沿线2:桥梁3: 隧道4:收费广场5: 收费站6: 服务区等 */
@Excel(name = "设施归属类型(0:默认1: 道路沿线2:桥梁3: 隧道4:收费广场5: 收费站6: 服务区等 ")
private String facilitiesType;
/** 设备状态:0-异常,1-正常 */
@Excel(name = "设备状态:0-异常,1-正常")
private String devStatus;
/** 所属机构id */
@Excel(name = "所属机构id")
private String opmaManagerId;
/** 所属机构名称 */
@Excel(name = "所属机构名称")
private String opmaManagerName;
/** 所属厂商 */
@Excel(name = "所属厂商")
private String supplierName;
/** 所属路段 */
@Excel(name = "所属路段")
private String sectionId;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date creationTime;
/** 创建人 */
@Excel(name = "创建人")
private Long creatorUserId;
/** 最后修改时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "最后修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date lastModificationTime;
/** 最后修改人 */
@Excel(name = "最后修改人")
private Long lastModifierUserId;
/** 是否删除 */
@Excel(name = "是否删除")
private Integer isDeleted;
/** 删除人 */
@Excel(name = "删除人")
private Long deleterUserId;
/** 删除时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "删除时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date deletionTime;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public String getDevNo() {
return devNo;
}
public void setDevNo(String devNo) {
this.devNo = devNo;
}
public String getDevName() {
return devName;
}
public void setDevName(String devName) {
this.devName = devName;
}
public String getStakeNum() {
return stakeNum;
}
public void setStakeNum(String stakeNum) {
this.stakeNum = stakeNum;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public String getTypeCode() {
return typeCode;
}
public void setTypeCode(String typeCode) {
this.typeCode = typeCode;
}
public String getFacilitiesType() {
return facilitiesType;
}
public void setFacilitiesType(String facilitiesType) {
this.facilitiesType = facilitiesType;
}
public String getDevStatus() {
return devStatus;
}
public void setDevStatus(String devStatus) {
this.devStatus = devStatus;
}
public String getOpmaManagerId() {
return opmaManagerId;
}
public void setOpmaManagerId(String opmaManagerId) {
this.opmaManagerId = opmaManagerId;
}
public String getOpmaManagerName() {
return opmaManagerName;
}
public void setOpmaManagerName(String opmaManagerName) {
this.opmaManagerName = opmaManagerName;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
public String getSectionId() {
return sectionId;
}
public void setSectionId(String sectionId) {
this.sectionId = sectionId;
}
public Date getCreationTime() {
return creationTime;
}
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}
public Long getCreatorUserId() {
return creatorUserId;
}
public void setCreatorUserId(Long creatorUserId) {
this.creatorUserId = creatorUserId;
}
public Date getLastModificationTime() {
return lastModificationTime;
}
public void setLastModificationTime(Date lastModificationTime) {
this.lastModificationTime = lastModificationTime;
}
public Long getLastModifierUserId() {
return lastModifierUserId;
}
public void setLastModifierUserId(Long lastModifierUserId) {
this.lastModifierUserId = lastModifierUserId;
}
public Integer getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Integer isDeleted) {
this.isDeleted = isDeleted;
}
public Long getDeleterUserId() {
return deleterUserId;
}
public void setDeleterUserId(Long deleterUserId) {
this.deleterUserId = deleterUserId;
}
public Date getDeletionTime() {
return deletionTime;
}
public void setDeletionTime(Date deletionTime) {
this.deletionTime = deletionTime;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", id)
.append("devNo", devNo)
.append("devName", devName)
.append("stakeNum", stakeNum)
.append("direction", direction)
.append("typeCode", typeCode)
.append("facilitiesType", facilitiesType)
.append("devStatus", devStatus)
.append("opmaManagerId", opmaManagerId)
.append("opmaManagerName", opmaManagerName)
.append("supplierName", supplierName)
.append("sectionId", sectionId)
.append("creationTime", creationTime)
.append("creatorUserId", creatorUserId)
.append("lastModificationTime", lastModificationTime)
.append("lastModifierUserId", lastModifierUserId)
.append("isDeleted", isDeleted)
.append("deleterUserId", deleterUserId)
.append("deletionTime", deletionTime)
.toString();
}
public MdDevice(){}
public MdDevice(DcDevice dcDevice){
this.id = dcDevice.getId();
this.devNo = dcDevice.getIotDeviceId();
this.devName = dcDevice.getDeviceName();
this.stakeNum = dcDevice.getStakeMark();
this.direction = dcDevice.getDirection();
this.typeCode = dcDevice.getDeviceType().toString();
if (StringUtils.isNotEmpty(dcDevice.getFacilitiesType())){
this.facilitiesType = dcDevice.getFacilitiesType();
}
this.devStatus = dcDevice.getDeviceState();
if (dcDevice.getGroupId() > 0){
this.opmaManagerId = dcDevice.getGroupId().toString();
}
this.supplierName = dcDevice.getManufacturer();
}
}

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

@ -3,10 +3,7 @@ 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;
import com.zc.business.domain.MdEvent;
import com.zc.business.domain.*;
import java.util.List;
@ -27,6 +24,31 @@ public interface MiddleDatabaseMapper
*/
Boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData);
/**
* 新增中间库设备
*
* @param mdDevice 设备
* @return 结果
*/
boolean insertMiddleDatabaseDeviceInfo(MdDevice mdDevice);
/**
* 修改中间库设备
*
* @param mdDevice 设备
* @return 结果
*/
boolean updateMiddleDatabaseDeviceInfo(MdDevice mdDevice);
/**
* 删除中间库设备
* 假删
*
* @param ids 设备ids
* @return 结果
*/
boolean deleteMiddleDatabaseDeviceInfoByIds(List<String> ids);
/**
* 更新中间库设备
*

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

@ -2,10 +2,7 @@ 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;
import com.zc.business.domain.MdDeviceData;
import com.zc.business.domain.MdEvent;
import com.zc.business.domain.*;
import java.util.List;
@ -35,7 +32,32 @@ public interface IMiddleDatabaseService
boolean updateMiddleDatabaseDeviceByList(List<DcDevice> listDevice);
/**
* 更新中间库设备
* 添加中间库设备
*
* @param mdDevice 设备
* @return 结果
*/
boolean insertMiddleDatabaseDeviceInfo(MdDevice mdDevice);
/**
* 修改中间库设备
*
* @param mdDevice 设备
* @return 结果
*/
boolean updateMiddleDatabaseDeviceInfo(MdDevice mdDevice);
/**
* 批量删除中间库设备
* 假删
*
* @param ids ids
* @return 结果
*/
boolean deleteMiddleDatabaseDeviceInfoByIds(List<String> ids);
/**
* 更新中间库设备状态
*
* @param device 设备
* @return 结果

30
zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java

@ -10,10 +10,12 @@ import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcProduct;
import com.zc.business.domain.DcStakeMark;
import com.zc.business.domain.MdDevice;
import com.zc.business.mapper.DcDeviceMapper;
import com.zc.business.service.IDcDeviceService;
import com.zc.business.service.IDcProductService;
import com.zc.business.service.IDcStakeMarkService;
import com.zc.business.service.IMiddleDatabaseService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@ -37,6 +39,8 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
private IDcStakeMarkService dcStakeMarkService;
@Resource
private DcDeviceMapper dcDeviceMapper;
@Resource
private IMiddleDatabaseService middleDataBaseService;
@Resource
private RedisCache redisCache;
@ -211,6 +215,8 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
if (Objects.isNull(dcProduct)) {
throw new ServiceException("所属产品[" + productId + "]不存在", HttpStatus.BAD_REQUEST);
}
//设备厂商
dcDevice.setManufacturer(dcProduct.getManufacturer());
}
dcDevice.setCreateTime(new Date());
@ -219,6 +225,11 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
if (save(dcDevice)) {
// 更新缓存
updateRedisCache();
//中间库添加设备
MdDevice mdDevice = new MdDevice(dcDevice);
middleDataBaseService.insertMiddleDatabaseDeviceInfo(mdDevice);
return true;
}
@ -243,11 +254,27 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
throw new ServiceException("设备ID[" + id + "]不存在", HttpStatus.BAD_REQUEST);
}
Long productId = dcDevice.getProductId();
if (Objects.nonNull(productId)) {
DcProduct dcProduct = dcProdurtService.getById(productId);
// 产品不存在
if (Objects.isNull(dcProduct)) {
throw new ServiceException("所属产品[" + productId + "]不存在", HttpStatus.BAD_REQUEST);
}
//设备厂商
dcDevice.setManufacturer(dcProduct.getManufacturer());
}
dcDevice.setUpdateTime(new Date());
if (updateById(dcDevice)) {
// 更新缓存
updateRedisCache();
//中间库修改设备
MdDevice mdDevice = new MdDevice(dcDevice);
middleDataBaseService.updateMiddleDatabaseDeviceInfo(mdDevice);
return true;
}
@ -275,6 +302,9 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
if (removeByIds(ids)) {
// 更新缓存
updateRedisCache();
//中间库 假删设备
middleDataBaseService.deleteMiddleDatabaseDeviceInfoByIds(ids);
return true;
}

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

@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.SecurityUtils;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.MdDevice;
import com.zc.business.domain.MdDeviceData;
import com.zc.business.domain.MdEvent;
import com.zc.business.mapper.MiddleDatabaseMapper;
@ -39,7 +40,6 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param mdDeviceData 气象检测器数据
* @return 结果
*/
// @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override
public boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData)
{
@ -53,7 +53,6 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param listDevice 设备列表
* @return 结果
*/
// @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override
public boolean updateMiddleDatabaseDeviceByList(List<DcDevice> listDevice)
{
@ -63,6 +62,42 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
return true;
}
/**
* 新增中间库设备
*
* @param mdDevice 设备
* @return 结果
*/
@Override
public boolean insertMiddleDatabaseDeviceInfo(MdDevice mdDevice)
{
return middleDatabaseMapper.insertMiddleDatabaseDeviceInfo(mdDevice);
}
/**
* 修改中间库设备
*
* @param mdDevice 设备
* @return 结果
*/
@Override
public boolean updateMiddleDatabaseDeviceInfo(MdDevice mdDevice)
{
return middleDatabaseMapper.updateMiddleDatabaseDeviceInfo(mdDevice);
}
/**
* 批量删除中间库设备
* 假删
*
* @param ids 设备ids
* @return 结果
*/
@Override
public boolean deleteMiddleDatabaseDeviceInfoByIds(List<String> ids)
{
return middleDatabaseMapper.deleteMiddleDatabaseDeviceInfoByIds(ids);
}
/**
* 更新中间库设备
@ -70,7 +105,6 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param device 设备
* @return 结果
*/
// @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override
public boolean updateMiddleDatabaseDevice(DcDevice device)
{
@ -85,10 +119,10 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
*/
@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);
}
@ -98,7 +132,6 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService {
* @param mdEvent 事件
* @return 结果
*/
// @DataSource(value = DataSourceType.SLAVE)//切换数据源
@Override
public boolean updateMiddleDatabaseEvent(MdEvent mdEvent){
LoginUser loginUser = SecurityUtils.getLoginUser();

81
zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml

@ -117,7 +117,84 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<update id="updateMiddleDatabaseDevice" parameterType="MdEvent">
<insert id="insertMiddleDatabaseDeviceInfo" parameterType="MdDevice">
insert into device
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="devNo != null">dev_no,</if>
<if test="devName != null">dev_name,</if>
<if test="stakeNum != null">stake_num,</if>
<if test="direction != null">direction,</if>
<if test="typeCode != null">type_code,</if>
<if test="facilitiesType != null">facilities_type,</if>
<if test="devStatus != null">dev_status,</if>
<if test="opmaManagerId != null">opma_manager_id,</if>
<if test="opmaManagerName != null">opma_manager_name,</if>
<if test="supplierName != null">supplier_name,</if>
<if test="sectionId != null">section_id,</if>
CreationTime,
<if test="creatorUserId != null">CreatorUserId,</if>
<if test="lastModificationTime != null">LastModificationTime,</if>
<if test="lastModifierUserId != null">LastModifierUserId,</if>
<if test="isDeleted != null">IsDeleted,</if>
<if test="deleterUserId != null">DeleterUserId,</if>
<if test="deletionTime != null">DeletionTime,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="devNo != null">#{devNo},</if>
<if test="devName != null">#{devName},</if>
<if test="stakeNum != null">#{stakeNum},</if>
<if test="direction != null">#{direction},</if>
<if test="typeCode != null">#{typeCode},</if>
<if test="facilitiesType != null">#{facilitiesType},</if>
<if test="devStatus != null">#{devStatus},</if>
<if test="opmaManagerId != null">#{opmaManagerId},</if>
<if test="opmaManagerName != null">#{opmaManagerName},</if>
<if test="supplierName != null">#{supplierName},</if>
<if test="sectionId != null">#{sectionId},</if>
now(),
<if test="creatorUserId != null">#{creatorUserId},</if>
<if test="lastModificationTime != null">#{lastModificationTime},</if>
<if test="lastModifierUserId != null">#{lastModifierUserId},</if>
<if test="isDeleted != null">#{isDeleted},</if>
<if test="deleterUserId != null">#{deleterUserId},</if>
<if test="deletionTime != null">#{deletionTime},</if>
</trim>
</insert>
<update id="updateMiddleDatabaseDeviceInfo" parameterType="MdDevice">
update device
<set>
<if test="devNo != null">dev_no = #{devNo}</if>
<if test="devName != null">dev_name = #{devName}</if>
<if test="stakeNum != null">stake_num = #{stakeNum}</if>
<if test="direction != null">direction = #{direction}</if>
<if test="typeCode != null">type_code = #{typeCode}</if>
<if test="facilitiesType != null">facilities_type = #{facilitiesType}</if>
<if test="devStatus != null">dev_status = #{devStatus}</if>
<if test="opmaManagerId != null">opma_manager_id = #{opmaManagerId}</if>
<if test="opmaManagerName != null">opma_manager_name = #{opmaManagerName}</if>
<if test="supplierName != null">supplier_name = #{supplierName}</if>
<if test="sectionId != null">section_id = #{sectionId}</if>
LastModificationTime = now(),
<if test="lastModifierUserId != null">LastModifierUserId = #{lastModifierUserId}</if>
<if test="isDeleted != null">IsDeleted = #{isDeleted}</if>
<if test="deleterUserId != null">DeleterUserId = #{deleterUserId}</if>
<if test="deletionTime != null">DeletionTime = #{deletionTime}</if>
</set>
where id = #{id}
</update>
<delete id="deleteMiddleDatabaseDeviceInfoByIds">
update device set IsDeleted = '1',DeletionTime = now()
where id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="updateMiddleDatabaseDevice" parameterType="DcDevice">
update device set dev_status = #{deviceState} where dev_no = #{iotDeviceId}
</update>
@ -164,4 +241,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
</mapper>

Loading…
Cancel
Save