Browse Source

数据迁移日志入库

lvxianyun 3 năm trước cách đây
mục cha
commit
7e08bf85c0

+ 77 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/migrate/controller/DigitalMigrateLogController.java

@@ -0,0 +1,77 @@
+package com.persagy.dmp.rwd.migrate.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.basic.utils.QueryCriteriaHelper;
+import com.persagy.dmp.common.constant.CommonConstant;
+import com.persagy.dmp.common.constant.ResponseCode;
+import com.persagy.dmp.common.exception.BusinessException;
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.common.utils.ParamCheckUtil;
+import com.persagy.dmp.common.utils.ResultHelper;
+import com.persagy.dmp.mybatis.utils.ConditionUtil;
+import com.persagy.dmp.rwd.migrate.entity.SyncData;
+import com.persagy.dmp.rwd.migrate.service.ISyncDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.util.List;
+
+/**
+ * @author lvxianyun
+ * @title: DigitalMigrateLogController
+ * @projectName digital-twin
+ * @description: adm 数据一键迁移到项目现场 日志记录
+ * @date 2021/12/20 16:35
+ */
+
+@Slf4j
+@RestController
+@RequestMapping("/log/migrate")
+public class DigitalMigrateLogController {
+    @Autowired
+    private ISyncDataService service;
+
+    @PostMapping("/query")
+    public CommonResult<List<SyncData>> query(@RequestBody QueryCriteria criteria) {
+        if(criteria == null) {
+            throw new BusinessException(ResponseCode.A0400.getCode(), ResponseCode.A0400.getDesc());
+        }
+        //基础参数校验
+        ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
+
+        QueryWrapper<SyncData> wrapper = new QueryWrapper<>();
+        // 添加所属项目条件
+        ConditionUtil.ensureProjectCriteriaDirectly(wrapper);
+        // 转换查询条件
+        QueryCriteriaHelper.toWrapper(wrapper, criteria, SyncData.class);
+        Page page = QueryCriteriaHelper.toPage(criteria);
+        if(criteria.isOnlyCount()) {
+            int total = service.count(wrapper);
+            page.setTotal(total);
+        } else {
+            page = service.page(QueryCriteriaHelper.toPage(criteria), wrapper);
+        }
+        return ResultHelper.multi(page.getRecords(), page.getTotal());
+    }
+
+    @PostMapping("/create")
+    public CommonResult<List<SyncData>> createBatch(@Valid @RequestBody List<SyncData> voList){
+        //基础参数校验
+        ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
+        //创建默认条件
+        try {
+            service.save(voList);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        //批量新增迁移日志
+        return ResultHelper.multi(voList);
+    }
+}

+ 23 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/migrate/dao/SyncDataMapper.java

@@ -0,0 +1,23 @@
+package com.persagy.dmp.rwd.migrate.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.persagy.dmp.rwd.migrate.entity.SyncData;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author lvxianyun
+ * @title: SyncData
+ * @projectName digital-twin
+ * @description: 记录数据迁移信息
+ * @date 2021/12/20 15:31
+ */
+public interface SyncDataMapper extends BaseMapper<SyncData> {
+    /**
+     * 保存
+     * @param vos
+     * @return
+     */
+    void save(@Param("vos") List<SyncData> vos);
+}

+ 38 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/migrate/service/ISyncDataService.java

@@ -0,0 +1,38 @@
+package com.persagy.dmp.rwd.migrate.service;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.persagy.dmp.rwd.migrate.entity.SyncData;
+
+import java.util.List;
+
+/**
+ * @author lvxianyun
+ * @title: ISyncDataService
+ * @projectName digital-twin
+ * @date 2021/12/20 15:41
+ */
+public interface ISyncDataService extends IService<SyncData> {
+    /**
+     * 新增
+     * @param voList 待新增数据
+     * @return 新增后数据
+     */
+    List<SyncData> save(List<SyncData> voList) throws Exception ;
+
+    /**
+     * 按条件查询
+     * @param queryWrapper 查询条件
+     * @return 返回结果
+     */
+    List<SyncData> queryByCondition(Wrapper<SyncData> queryWrapper);
+
+    /**
+     * 分页条件查询
+     * @param page 分页条件
+     * @param queryWrapper 查询条件
+     * @return 分页结果
+     */
+    Page queryByCondition(Page page, Wrapper<SyncData> queryWrapper);
+}

+ 66 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/migrate/service/impl/SyncDataServiceImpl.java

@@ -0,0 +1,66 @@
+package com.persagy.dmp.rwd.migrate.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.persagy.dmp.rwd.migrate.dao.SyncDataMapper;
+import com.persagy.dmp.rwd.migrate.entity.SyncData;
+import com.persagy.dmp.rwd.migrate.service.ISyncDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * @author lvxianyun
+ * @title: SyncDataServiceImpl
+ * @projectName digital-twin
+ * @description: 数据迁移日志入库
+ * @date 2021/12/20 15:42
+ */
+
+@Slf4j
+@Transactional(rollbackFor = Exception.class)
+@Service
+public class SyncDataServiceImpl extends ServiceImpl<SyncDataMapper, SyncData> implements ISyncDataService {
+    @Autowired
+    private SyncDataMapper syncDataMapper;
+
+
+    /**
+     * 添加迁移日志
+     * @param voList 待修改数据
+     * @return
+     */
+    @Override
+    public List<SyncData> save(List<SyncData> voList) throws Exception {
+        //修改采集信息点
+        syncDataMapper.save(voList);
+        return voList;
+    }
+
+    /**
+     * 按条件查询
+     *
+     * @param queryWrapper 查询条件
+     * @return 返回结果
+     */
+    @Override
+    public List<SyncData> queryByCondition(Wrapper<SyncData> queryWrapper) {
+        return syncDataMapper.selectList(queryWrapper);
+    }
+
+    /**
+     * 分页条件查询
+     *
+     * @param page         分页条件
+     * @param queryWrapper 查询条件
+     * @return 分页结果
+     */
+    @Override
+    public Page queryByCondition(Page page, Wrapper<SyncData> queryWrapper) {
+        return syncDataMapper.selectPage(page, queryWrapper);
+    }
+}

+ 30 - 1
dmp-business/dmp-rwd/src/main/resources/db/init/schema.sql

@@ -299,4 +299,33 @@ CREATE TABLE IF NOT EXISTS `dt_relation_his` (
     KEY `idx_4` (`graph_id`,`rel_code`,`obj_to`,`project_id`) USING BTREE,
     KEY `idx_5` (`obj_from`) USING BTREE,
     KEY `idx_6` (`obj_to`) USING BTREE
-    ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC COMMENT='关系实例表';
+    ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC COMMENT='关系实例表';
+
+CREATE TABLE IF NOT EXISTS `dt_sync_data` (
+   `id` varchar(200) NOT NULL COMMENT '消息id',
+   `table_name` varchar(32) NOT NULL COMMENT '同步表名称',
+   `target_id` varchar(100) DEFAULT NULL COMMENT '对象id,关系id,类型id,信息点id',
+   `obj_type` varchar(200) DEFAULT NULL COMMENT '对象类型',
+   `type` varchar(200) DEFAULT NULL COMMENT '操作类型',
+   `project_id` varchar(200) DEFAULT NULL COMMENT '项目id',
+   `sign` int DEFAULT NULL COMMENT '标记',
+   `ops` varchar(200) DEFAULT NULL COMMENT '操作符',
+   `ops_name` varchar(200) DEFAULT NULL COMMENT '操作符名称',
+   `from_id` varchar(100) DEFAULT NULL COMMENT '主id',
+   `to_id` varchar(100) DEFAULT NULL COMMENT '从id',
+   `error` longtext COMMENT '错误内容',
+   `class_code` varchar(100) DEFAULT NULL COMMENT '类型',
+   `local_name` varchar(200) DEFAULT NULL COMMENT '本地名称',
+   `local_id` varchar(200) DEFAULT NULL COMMENT '本地编码',
+   `name` varchar(200) DEFAULT NULL COMMENT '名称',
+   `code` varchar(200) DEFAULT NULL,
+   `obj_name` varchar(200) DEFAULT NULL,
+   `creator` varchar(32) NULL DEFAULT NULL COMMENT '创建人',
+   `creation_time` char(14) NULL DEFAULT NULL COMMENT '创建时间',
+   `modifier` varchar(32) NULL DEFAULT NULL COMMENT '最后修改人',
+   `modified_time` char(14) NULL DEFAULT NULL COMMENT '最后修改时间',
+   `valid` tinyint NULL DEFAULT NULL COMMENT '合法标识',
+   `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '乐观锁',
+   PRIMARY KEY (`id`),
+   UNIQUE KEY `idx_1`(`project_id`,`table_name`,`target_id`,`type`) USING BTREE
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC COMMENT='adm交付数据同步到项目现场';

+ 60 - 0
dmp-business/dmp-rwd/src/main/resources/mapper/SyncDatMapper.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.persagy.dmp.rwd.migrate.SyncDataMapper">
+  <resultMap id="BaseResultMap" type="com.persagy.dmp.rwd.migrate.entity.SyncData">
+    <id column="id" jdbcType="VARCHAR" property="id" />
+    <id column="table_name" jdbcType="VARCHAR" property="tableName" />
+    <result column="target_id" jdbcType="VARCHAR" property="targetId" />
+    <result column="obj_type" jdbcType="VARCHAR" property="objType" />
+    <result column="type" jdbcType="VARCHAR" property="type" />
+    <result column="project_id" jdbcType="VARCHAR" property="projectId" />
+    <result column="sign" jdbcType="INTEGER" property="sign" />
+    <result column="ops" jdbcType="VARCHAR" property="ops" />
+    <result column="ops_name" jdbcType="VARCHAR" property="opsName" />
+    <result column="from_id" jdbcType="VARCHAR" property="fromId" />
+    <result column="to_id" jdbcType="VARCHAR" property="toId" />
+    <result column="error" jdbcType="VARCHAR" property="error" />
+    <result column="class_code" jdbcType="VARCHAR" property="classCode" />
+    <result column="local_name" jdbcType="VARCHAR" property="localName" />
+    <result column="local_id" jdbcType="VARCHAR" property="localId" />
+    <result column="name" jdbcType="VARCHAR" property="name" />
+    <result column="code" jdbcType="VARCHAR" property="code" />
+    <result column="obj_name" jdbcType="VARCHAR" property="objName" />
+    <result column="creator" jdbcType="VARCHAR" property="creator" />
+    <result column="creation_time" jdbcType="CHAR" property="creationTime" />
+    <result column="modifier" jdbcType="VARCHAR" property="modifier" />
+    <result column="modified_time" jdbcType="CHAR" property="modifiedTime" />
+    <result column="valid" jdbcType="TINYINT" property="valid" />
+    <result column="ts" jdbcType="TIMESTAMP" property="ts" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    id, table_name, target_id, obj_type, `type`, project_id, sign, ops, ops_name, from_id, to_id,
+    error, class_code, local_name, local_id, `name`, code, obj_name, creator, creation_time,
+    modifier, modified_time, `valid`, ts
+  </sql>
+
+  <insert id="save">
+    insert into dt_sync_data (id,table_name,target_id, obj_type, `type`,
+      project_id, sign, ops, 
+      ops_name, from_id, to_id, 
+      error, class_code, local_name, 
+      local_id, `name`, code,
+      obj_name, creator, creation_time, 
+      modifier, modified_time, `valid`, 
+      ts)
+    <foreach collection="vos" item="vo" open="(" close=")" separator="),(">
+      #{vo.id},#{vo.tableName},#{vo.targetId},#{vo.objType},#{vo.type},#{vo.projectId},
+      #{vo.sign},#{vo.ops},#{vo.opsName},#{vo.fromId},#{vo.toId},
+      #{vo.error},#{vo.classCode},#{vo.localName},
+      #{vo.localId},#{vo.name},#{vo.code},
+      #{vo.creator},#{vo.creationTime},#{vo.modifier},#{vo.modifiedTime},#{vo.valid}
+    </foreach>
+    ON DUPLICATE KEY UPDATE
+    type = VALUES(type), ops = VALUES(ops), opsName = VALUES(opsName),
+    from_id = VALUES(from_id), to_id = VALUES(to_id), error = VALUES(error),
+    class_code = VALUES(class_code), local_name = VALUES(local_name), local_id = VALUES(local_id),
+    `name` = VALUES(name), code_name = VALUES(local_name), obj_name = VALUES(obj_name),code = VALUES(code),
+    modifier = VALUES(modifier), modified_time = VALUES(modified_time)
+  </insert>
+
+</mapper>

+ 55 - 0
dmp-comp/dmp-digital-starter/src/main/java/com/persagy/dmp/migrate/client/DigitalMigrateLogClient.java

@@ -0,0 +1,55 @@
+package com.persagy.dmp.migrate.client;
+
+import com.persagy.dmp.basic.config.DigitalFeignConfig;
+import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.rwd.migrate.entity.SyncData;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+/**
+ * @author lvxianyun
+ * @title: DigitalMigrateLogClient
+ * @projectName digital-twin
+ * @description:
+ * @date 2021/12/20 19:05
+ */
+@FeignClient(name = "dmp-rwd", configuration = DigitalFeignConfig.class,
+        url = "${persagy.bdtp.rwd.service:}",path = "/log/migrate/")
+public interface DigitalMigrateLogClient {
+
+    /**
+     * 查询数据迁移日志
+     * @param groupCode: 集团编码
+     * @param projectId: 项目ID
+     * @param appId: 应用ID
+     * @param userId: 用户ID
+     * @param criteria: 查询条件
+     * @return 对象数组
+     */
+    @PostMapping("query")
+    CommonResult<List<SyncData>> query(@RequestParam("groupCode") String groupCode,
+                                       @RequestParam("projectId") String projectId,
+                                       @RequestParam("appId") String appId,
+                                       @RequestParam("userId") String userId,
+                                       @RequestBody QueryCriteria criteria);
+    /**
+     * 新增数据迁移日志-批量新增
+     * @param groupCode: 集团编码
+     * @param projectId: 项目ID
+     * @param appId: 应用ID
+     * @param userId: 用户ID
+     * @param nodes: 新增对象集合
+     * @return 对象数组
+     */
+    @PostMapping("create")
+    CommonResult<List<SyncData>> create(@RequestParam("groupCode") String groupCode,
+                                             @RequestParam("projectId") String projectId,
+                                             @RequestParam("appId") String appId,
+                                             @RequestParam("userId") String userId,
+                                             @RequestBody List<SyncData> nodes);
+}

+ 52 - 0
dmp-comp/dmp-digital-starter/src/main/java/com/persagy/dmp/migrate/client/DigitalMigrateLogFacade.java

@@ -0,0 +1,52 @@
+package com.persagy.dmp.migrate.client;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.common.utils.ResultHelper;
+import com.persagy.dmp.rwd.migrate.entity.SyncData;
+
+import java.util.List;
+
+/**
+ * @author lvxianyun
+ * @title: DigitalMigrateLogFacade
+ * @projectName digital-twin
+ * @description: 数据迁移门面
+ * @date 2021/12/20 19:05
+ */
+public class DigitalMigrateLogFacade {
+
+    private static DigitalMigrateLogClient client = SpringUtil.getBean(DigitalMigrateLogClient.class);
+
+    /**
+     * 查询数据迁移日志
+     * @param groupCode: 集团编码
+     * @param projectId: 项目ID
+     * @param appId: 应用ID
+     * @param userId: 用户ID
+     * @param criteria: 请求参数
+     * @return 对象数组
+     */
+    public static CommonResult<List<SyncData>> query(String groupCode, String projectId, String appId,
+                                       String userId, QueryCriteria criteria) {
+        CommonResult<List<SyncData>> result = client.query(groupCode, projectId, appId, userId, criteria);
+        return result;
+    }
+
+
+    /**
+     * 新增数据迁移日志-批量新增
+     * @param groupCode: 集团编码
+     * @param projectId: 项目ID
+     * @param appId: 应用ID
+     * @param userId: 用户ID
+     * @param syncDataList: 新增对象集合
+     * @return 对象数组
+     */
+    public static List<SyncData> create(String groupCode, String projectId, String appId,
+                                             String userId, List<SyncData> syncDataList) {
+        CommonResult<List<SyncData>> result = client.create(groupCode, projectId, appId, userId, syncDataList);
+        return ResultHelper.getContent(result);
+    }
+}

+ 108 - 0
dmp-comp/dmp-digital-starter/src/main/java/com/persagy/dmp/rwd/migrate/entity/SyncData.java

@@ -0,0 +1,108 @@
+package com.persagy.dmp.rwd.migrate.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.persagy.dmp.common.model.entity.AuditableEntity;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author lvxianyun
+ * @title: SyncData
+ * @projectName digital-twin
+ * @description: 数据迁移记录
+ * @date 2021/12/20 15:34
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName(value = "sync_data",autoResultMap = true)
+@NoArgsConstructor
+@AllArgsConstructor
+public class SyncData extends AuditableEntity {
+
+    private static final long serialVersionUID = 1L;
+    /**
+     * 消息id
+     */
+    private String id;
+    /**
+     * 同步表名称
+     */
+    private String tableName;
+
+    /**
+     * 对象id,关系id,类型id,信息点id
+     */
+    private String targetId;
+
+    /**
+     * 对象类型
+     */
+    private String objType;
+
+    /**
+     * 操作类型
+     */
+    private String type;
+
+    /**
+     * 项目id
+     */
+    private String projectId;
+
+    /**
+     * 标记
+     */
+    private Integer sign;
+
+    /**
+     * 操作符
+     */
+    private String ops;
+
+    /**
+     * 操作符名称
+     */
+    private String opsName;
+
+    /**
+     * 主id
+     */
+    private String fromId;
+
+    /**
+     * 从id
+     */
+    private String toId;
+
+    /**
+     * 错误内容
+     */
+    private String error;
+
+    /**
+     * 类型
+     */
+    private String classCode;
+
+    /**
+     * 本地名称
+     */
+    private String localName;
+
+    /**
+     * 本地编码
+     */
+    private String localId;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    private String code;
+
+    private String objName;
+
+}