소스 검색

外网定时同步代码

wukai 2 년 전
부모
커밋
625bde7737

+ 81 - 0
sync-admin/src/main/resources/templates/out/sync/add.html

@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('新增数据同步')" />
+    <th:block th:include="include :: datetimepicker-css" />
+</head>
+<body class="white-bg">
+    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
+        <form class="form-horizontal m" id="form-sync-add">
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件名:</label>
+                <div class="col-sm-8">
+                    <input name="syncFileName" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件MD5值:</label>
+                <div class="col-sm-8">
+                    <input name="syncFileMd5" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件大小:</label>
+                <div class="col-sm-8">
+                    <input name="syncFileSize" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件本次序号:</label>
+                <div class="col-sm-8">
+                    <input name="syncSort" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件上传花费时间:</label>
+                <div class="col-sm-8">
+                    <input name="costTime" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件上传至FTP时间:</label>
+                <div class="col-sm-8">
+                    <div class="input-group date">
+                        <input name="uploadTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
+                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
+                    </div>
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件上传状态:</label>
+                <div class="col-sm-8">
+                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
+                        <input type="radio" th:id="${'uploadStatus_' + dict.dictCode}" name="uploadStatus" th:value="${dict.dictValue}" th:checked="${dict.default}">
+                        <label th:for="${'uploadStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
+                    </div>
+                </div>
+            </div>
+        </form>
+    </div>
+    <th:block th:include="include :: footer" />
+    <th:block th:include="include :: datetimepicker-js" />
+    <script th:inline="javascript">
+        var prefix = ctx + "out/sync"
+        $("#form-sync-add").validate({
+            focusCleanup: true
+        });
+
+        function submitHandler() {
+            if ($.validate.form()) {
+                $.operate.save(prefix + "/add", $('#form-sync-add').serialize());
+            }
+        }
+
+        $("input[name='uploadTime']").datetimepicker({
+            format: "yyyy-mm-dd",
+            minView: "month",
+            autoclose: true
+        });
+    </script>
+</body>
+</html>

+ 82 - 0
sync-admin/src/main/resources/templates/out/sync/edit.html

@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('修改数据同步')" />
+    <th:block th:include="include :: datetimepicker-css" />
+</head>
+<body class="white-bg">
+    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
+        <form class="form-horizontal m" id="form-sync-edit" th:object="${outSyncInfo}">
+            <input name="infoId" th:field="*{infoId}" type="hidden">
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件名:</label>
+                <div class="col-sm-8">
+                    <input name="syncFileName" th:field="*{syncFileName}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件MD5值:</label>
+                <div class="col-sm-8">
+                    <input name="syncFileMd5" th:field="*{syncFileMd5}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件大小:</label>
+                <div class="col-sm-8">
+                    <input name="syncFileSize" th:field="*{syncFileSize}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">同步文件本次序号:</label>
+                <div class="col-sm-8">
+                    <input name="syncSort" th:field="*{syncSort}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件上传花费时间:</label>
+                <div class="col-sm-8">
+                    <input name="costTime" th:field="*{costTime}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件上传至FTP时间:</label>
+                <div class="col-sm-8">
+                    <div class="input-group date">
+                        <input name="uploadTime" th:value="${#dates.format(outSyncInfo.uploadTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
+                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
+                    </div>
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件上传状态:</label>
+                <div class="col-sm-8">
+                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
+                        <input type="radio" th:id="${'uploadStatus_' + dict.dictCode}" name="uploadStatus" th:value="${dict.dictValue}" th:field="*{uploadStatus}">
+                        <label th:for="${'uploadStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
+                    </div>
+                </div>
+            </div>
+        </form>
+    </div>
+    <th:block th:include="include :: footer" />
+    <th:block th:include="include :: datetimepicker-js" />
+    <script th:inline="javascript">
+        var prefix = ctx + "out/sync";
+        $("#form-sync-edit").validate({
+            focusCleanup: true
+        });
+
+        function submitHandler() {
+            if ($.validate.form()) {
+                $.operate.save(prefix + "/edit", $('#form-sync-edit').serialize());
+            }
+        }
+
+        $("input[name='uploadTime']").datetimepicker({
+            format: "yyyy-mm-dd",
+            minView: "month",
+            autoclose: true
+        });
+    </script>
+</body>
+</html>

+ 124 - 0
sync-admin/src/main/resources/templates/out/sync/sync.html

@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
+<head>
+    <th:block th:include="include :: header('数据同步列表')"/>
+</head>
+<body class="gray-bg">
+<div class="container-div">
+    <div class="row">
+        <div class="col-sm-12 search-collapse">
+            <form id="formId">
+                <div class="select-list">
+                    <ul>
+                        <li>
+                            <label>文件名:</label>
+                            <input type="text" name="syncFileName"/>
+                        </li>
+                        <li>
+                            <label>是否成功:</label>
+                            <select name="uploadStatus" th:with="type=${@dict.getType('sys_yes_no')}">
+                                <option value=""></option>
+                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
+                                        th:value="${dict.dictValue}"></option>
+                            </select>
+                        </li>
+                        <li>
+                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
+                                    class="fa fa-search"></i>&nbsp;搜索</a>
+                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
+                                    class="fa fa-refresh"></i>&nbsp;重置</a>
+                        </li>
+                    </ul>
+                </div>
+            </form>
+        </div>
+
+        <div class="btn-group-sm" id="toolbar" role="group">
+            <!--            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="out:sync:add">-->
+            <!--                <i class="fa fa-plus"></i> 添加-->
+            <!--            </a>-->
+            <!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="out:sync:edit">-->
+            <!--                <i class="fa fa-edit"></i> 修改-->
+            <!--            </a>-->
+            <!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
+            <!--               shiro:hasPermission="out:sync:remove">-->
+            <!--                <i class="fa fa-remove"></i> 删除-->
+            <!--            </a>-->
+            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="out:sync:export">
+                <i class="fa fa-download"></i> 导出
+            </a>
+        </div>
+        <div class="col-sm-12 select-table table-striped">
+            <table id="bootstrap-table"></table>
+        </div>
+    </div>
+</div>
+<th:block th:include="include :: footer"/>
+<script th:inline="javascript">
+    var editFlag = [[${@permission.hasPermi('out:sync:edit')}]];
+    var removeFlag = [[${@permission.hasPermi('out:sync:remove')}]];
+    var uploadStatusDatas = [[${@dict.getType('sys_yes_no')}]];
+    var prefix = ctx + "out/sync";
+
+    $(function () {
+        var options = {
+            url: prefix + "/list",
+            createUrl: prefix + "/add",
+            updateUrl: prefix + "/edit/{id}",
+            removeUrl: prefix + "/remove",
+            exportUrl: prefix + "/export",
+            modalName: "数据同步",
+            columns: [{
+                checkbox: true
+            },
+                {
+                    field: 'infoId',
+                    title: '数据ID',
+                    visible: false
+                },
+                {
+                    field: 'syncType',
+                    title: '同步类型'
+                },
+                {
+                    field: 'syncFileName',
+                    title: '同步文件名'
+                },
+                {
+                    field: 'syncFileMd5',
+                    title: '同步文件MD5值'
+                },
+                {
+                    field: 'syncFileSize',
+                    title: '同步文件大小'
+                },
+                {
+                    field: 'syncSort',
+                    title: '同步文件本次序号'
+                },
+                {
+                    field: 'costTime',
+                    title: '文件上传花费时间(s)',
+                    formatter: function (value, row, index) {
+                        return value / 1000;
+                    }
+                },
+                {
+                    field: 'uploadTime',
+                    title: '文件上传至FTP时间'
+                },
+                {
+                    field: 'uploadStatus',
+                    title: '是否成功',
+                    formatter: function (value, row, index) {
+                        return $.table.selectDictLabel(uploadStatusDatas, value);
+                    }
+                }
+            ]
+        };
+        $.table.init(options);
+    })
+    ;
+</script>
+</body>
+</html>

+ 24 - 2
sync-common/src/main/java/com/jjt/common/utils/FtpUtil.java

@@ -84,7 +84,9 @@ public class FtpUtil {
     }
 
     /**
-     * @param localDir 保存到ftp服务器上的名称
+     * 目录上传至FTP
+     *
+     * @param localDir 本地目录
      * @return 成功则返回 true
      */
     public Boolean upload(String localDir) {
@@ -104,7 +106,6 @@ public class FtpUtil {
 
                 //获取目录下所有文件
                 for (File file : files) {
-                    System.err.println(file.getAbsolutePath());
                     ftp.upload(dir, file);
                 }
 
@@ -117,6 +118,27 @@ public class FtpUtil {
     }
 
     /**
+     * 单个文件上传至FTP
+     *
+     * @param file 要上传的文件
+     * @return 成功则返回 true
+     */
+    public Boolean upload(File file) {
+        if (!dir.endsWith(Constants.DIR_END)) {
+            dir += "/";
+        }
+        try (Ftp ftp = new Ftp(ip, port == null ? 21 : port, user, pass)) {
+            // 设置传输模式为被动模式(可根据需要修改)
+            ftp.setMode(FtpMode.Passive);
+
+            return ftp.upload(dir, file);
+        } catch (Exception e) {
+            log.error("上传出错啦", e.getMessage());
+            return false;
+        }
+    }
+
+    /**
      * 删除远程服务器上的文件
      *
      * @return 成功则返回 true

+ 2 - 0
sync-in/src/main/java/com/jjt/in/service/impl/InEsServiceImpl.java

@@ -99,7 +99,9 @@ public class InEsServiceImpl implements IInEsService {
                         File baseFile = new File(dir + name);
                         ObjectMapper mapper = new ObjectMapper();
                         IndexDO ido = mapper.readValue(baseFile, IndexDO.class);
+
                         boolean flag = createIndex(ido);
+
                         if (flag) {
                             String uri = scheme + "://" + hostname + ":" + port + "/" + ido.getIndexName();
 

+ 127 - 0
sync-out/src/main/java/com/jjt/out/controller/OutSyncInfoController.java

@@ -0,0 +1,127 @@
+package com.jjt.out.controller;
+
+import java.util.List;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import com.jjt.common.annotation.Log;
+import com.jjt.common.enums.BusinessType;
+import com.jjt.out.domain.OutSyncInfo;
+import com.jjt.out.service.IOutSyncInfoService;
+import com.jjt.common.core.controller.BaseController;
+import com.jjt.common.core.domain.AjaxResult;
+import com.jjt.common.utils.poi.ExcelUtil;
+import com.jjt.common.core.page.TableDataInfo;
+
+/**
+ * 数据同步Controller
+ * 
+ * @author ruoyi
+ * @date 2023-06-14
+ */
+@Controller
+@RequestMapping("/out/sync")
+public class OutSyncInfoController extends BaseController
+{
+    private String prefix = "out/sync";
+
+    @Autowired
+    private IOutSyncInfoService outSyncInfoService;
+
+    @RequiresPermissions("out:sync:view")
+    @GetMapping()
+    public String sync()
+    {
+        return prefix + "/sync";
+    }
+
+    /**
+     * 查询数据同步列表
+     */
+    @RequiresPermissions("out:sync:list")
+    @PostMapping("/list")
+    @ResponseBody
+    public TableDataInfo list(OutSyncInfo outSyncInfo)
+    {
+        startPage();
+        List<OutSyncInfo> list = outSyncInfoService.selectOutSyncInfoList(outSyncInfo);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出数据同步列表
+     */
+    @RequiresPermissions("out:sync:export")
+    @Log(title = "数据同步", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    @ResponseBody
+    public AjaxResult export(OutSyncInfo outSyncInfo)
+    {
+        List<OutSyncInfo> list = outSyncInfoService.selectOutSyncInfoList(outSyncInfo);
+        ExcelUtil<OutSyncInfo> util = new ExcelUtil<OutSyncInfo>(OutSyncInfo.class);
+        return util.exportExcel(list, "数据同步数据");
+    }
+
+    /**
+     * 新增数据同步
+     */
+    @GetMapping("/add")
+    public String add()
+    {
+        return prefix + "/add";
+    }
+
+    /**
+     * 新增保存数据同步
+     */
+    @RequiresPermissions("out:sync:add")
+    @Log(title = "数据同步", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    @ResponseBody
+    public AjaxResult addSave(OutSyncInfo outSyncInfo)
+    {
+        return toAjax(outSyncInfoService.insertOutSyncInfo(outSyncInfo));
+    }
+
+    /**
+     * 修改数据同步
+     */
+    @RequiresPermissions("out:sync:edit")
+    @GetMapping("/edit/{infoId}")
+    public String edit(@PathVariable("infoId") Long infoId, ModelMap mmap)
+    {
+        OutSyncInfo outSyncInfo = outSyncInfoService.selectOutSyncInfoByInfoId(infoId);
+        mmap.put("outSyncInfo", outSyncInfo);
+        return prefix + "/edit";
+    }
+
+    /**
+     * 修改保存数据同步
+     */
+    @RequiresPermissions("out:sync:edit")
+    @Log(title = "数据同步", businessType = BusinessType.UPDATE)
+    @PostMapping("/edit")
+    @ResponseBody
+    public AjaxResult editSave(OutSyncInfo outSyncInfo)
+    {
+        return toAjax(outSyncInfoService.updateOutSyncInfo(outSyncInfo));
+    }
+
+    /**
+     * 删除数据同步
+     */
+    @RequiresPermissions("out:sync:remove")
+    @Log(title = "数据同步", businessType = BusinessType.DELETE)
+    @PostMapping( "/remove")
+    @ResponseBody
+    public AjaxResult remove(String ids)
+    {
+        return toAjax(outSyncInfoService.deleteOutSyncInfoByInfoIds(ids));
+    }
+}

+ 160 - 0
sync-out/src/main/java/com/jjt/out/domain/OutSyncInfo.java

@@ -0,0 +1,160 @@
+package com.jjt.out.domain;
+
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.jjt.common.annotation.Excel;
+import com.jjt.common.core.domain.BaseEntity;
+
+/**
+ * 数据同步对象 out_sync_info
+ *
+ * @author ruoyi
+ * @date 2023-06-14
+ */
+public class OutSyncInfo extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 数据ID
+     */
+    private Long infoId;
+
+    /**
+     * 同步类型
+     */
+    @Excel(name = "同步类型")
+    private String syncType;
+
+    /**
+     * 同步文件名
+     */
+    @Excel(name = "同步文件名")
+    private String syncFileName;
+
+    /**
+     * 同步文件MD5值
+     */
+    @Excel(name = "同步文件MD5值")
+    private String syncFileMd5;
+
+    /**
+     * 同步文件大小
+     */
+    @Excel(name = "同步文件大小")
+    private Long syncFileSize;
+
+    /**
+     * 同步文件本次序号
+     */
+    @Excel(name = "同步文件本次序号")
+    private Long syncSort;
+
+    /**
+     * 文件上传花费时间
+     */
+    @Excel(name = "文件上传花费时间")
+    private Long costTime;
+
+    /**
+     * 文件上传至FTP时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "文件上传至FTP时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date uploadTime;
+
+    /**
+     * 文件上传状态
+     */
+    @Excel(name = "文件上传状态")
+    private String uploadStatus;
+
+    public void setInfoId(Long infoId) {
+        this.infoId = infoId;
+    }
+
+    public Long getInfoId() {
+        return infoId;
+    }
+
+    public void setSyncType(String syncType) {
+        this.syncType = syncType;
+    }
+
+    public String getSyncType() {
+        return syncType;
+    }
+
+    public void setSyncFileName(String syncFileName) {
+        this.syncFileName = syncFileName;
+    }
+
+    public String getSyncFileName() {
+        return syncFileName;
+    }
+
+    public void setSyncFileMd5(String syncFileMd5) {
+        this.syncFileMd5 = syncFileMd5;
+    }
+
+    public String getSyncFileMd5() {
+        return syncFileMd5;
+    }
+
+    public void setSyncFileSize(Long syncFileSize) {
+        this.syncFileSize = syncFileSize;
+    }
+
+    public Long getSyncFileSize() {
+        return syncFileSize;
+    }
+
+    public void setSyncSort(Long syncSort) {
+        this.syncSort = syncSort;
+    }
+
+    public Long getSyncSort() {
+        return syncSort;
+    }
+
+    public void setCostTime(Long costTime) {
+        this.costTime = costTime;
+    }
+
+    public Long getCostTime() {
+        return costTime;
+    }
+
+    public void setUploadTime(Date uploadTime) {
+        this.uploadTime = uploadTime;
+    }
+
+    public Date getUploadTime() {
+        return uploadTime;
+    }
+
+    public void setUploadStatus(String uploadStatus) {
+        this.uploadStatus = uploadStatus;
+    }
+
+    public String getUploadStatus() {
+        return uploadStatus;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("infoId", getInfoId())
+                .append("syncType", getSyncType())
+                .append("syncFileName", getSyncFileName())
+                .append("syncFileMd5", getSyncFileMd5())
+                .append("syncFileSize", getSyncFileSize())
+                .append("syncSort", getSyncSort())
+                .append("costTime", getCostTime())
+                .append("uploadTime", getUploadTime())
+                .append("uploadStatus", getUploadStatus())
+                .toString();
+    }
+}

+ 61 - 0
sync-out/src/main/java/com/jjt/out/mapper/OutSyncInfoMapper.java

@@ -0,0 +1,61 @@
+package com.jjt.out.mapper;
+
+import java.util.List;
+import com.jjt.out.domain.OutSyncInfo;
+
+/**
+ * 数据同步Mapper接口
+ * 
+ * @author ruoyi
+ * @date 2023-06-14
+ */
+public interface OutSyncInfoMapper 
+{
+    /**
+     * 查询数据同步
+     * 
+     * @param infoId 数据同步主键
+     * @return 数据同步
+     */
+    public OutSyncInfo selectOutSyncInfoByInfoId(Long infoId);
+
+    /**
+     * 查询数据同步列表
+     * 
+     * @param outSyncInfo 数据同步
+     * @return 数据同步集合
+     */
+    public List<OutSyncInfo> selectOutSyncInfoList(OutSyncInfo outSyncInfo);
+
+    /**
+     * 新增数据同步
+     * 
+     * @param outSyncInfo 数据同步
+     * @return 结果
+     */
+    public int insertOutSyncInfo(OutSyncInfo outSyncInfo);
+
+    /**
+     * 修改数据同步
+     * 
+     * @param outSyncInfo 数据同步
+     * @return 结果
+     */
+    public int updateOutSyncInfo(OutSyncInfo outSyncInfo);
+
+    /**
+     * 删除数据同步
+     * 
+     * @param infoId 数据同步主键
+     * @return 结果
+     */
+    public int deleteOutSyncInfoByInfoId(Long infoId);
+
+    /**
+     * 批量删除数据同步
+     * 
+     * @param infoIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteOutSyncInfoByInfoIds(String[] infoIds);
+}

+ 5 - 0
sync-out/src/main/java/com/jjt/out/service/IOutProcessService.java

@@ -8,6 +8,11 @@ package com.jjt.out.service;
  */
 public interface IOutProcessService {
     /**
+     * 同步文件
+     */
+    public void sync();
+
+    /**
      * 上传文件到光闸FTP
      */
     public void uploadFile();

+ 61 - 0
sync-out/src/main/java/com/jjt/out/service/IOutSyncInfoService.java

@@ -0,0 +1,61 @@
+package com.jjt.out.service;
+
+import java.util.List;
+import com.jjt.out.domain.OutSyncInfo;
+
+/**
+ * 数据同步Service接口
+ * 
+ * @author ruoyi
+ * @date 2023-06-14
+ */
+public interface IOutSyncInfoService 
+{
+    /**
+     * 查询数据同步
+     * 
+     * @param infoId 数据同步主键
+     * @return 数据同步
+     */
+    public OutSyncInfo selectOutSyncInfoByInfoId(Long infoId);
+
+    /**
+     * 查询数据同步列表
+     * 
+     * @param outSyncInfo 数据同步
+     * @return 数据同步集合
+     */
+    public List<OutSyncInfo> selectOutSyncInfoList(OutSyncInfo outSyncInfo);
+
+    /**
+     * 新增数据同步
+     * 
+     * @param outSyncInfo 数据同步
+     * @return 结果
+     */
+    public int insertOutSyncInfo(OutSyncInfo outSyncInfo);
+
+    /**
+     * 修改数据同步
+     * 
+     * @param outSyncInfo 数据同步
+     * @return 结果
+     */
+    public int updateOutSyncInfo(OutSyncInfo outSyncInfo);
+
+    /**
+     * 批量删除数据同步
+     * 
+     * @param infoIds 需要删除的数据同步主键集合
+     * @return 结果
+     */
+    public int deleteOutSyncInfoByInfoIds(String infoIds);
+
+    /**
+     * 删除数据同步信息
+     * 
+     * @param infoId 数据同步主键
+     * @return 结果
+     */
+    public int deleteOutSyncInfoByInfoId(Long infoId);
+}

+ 6 - 6
sync-out/src/main/java/com/jjt/out/service/impl/OutEsServiceImpl.java

@@ -140,12 +140,12 @@ public class OutEsServiceImpl implements IOutEsService {
             } catch (IOException ignored) {
             }
 
-//            //导出mapping命令
-//            String mappingCmd = "/usr/bin/elasticdump --input " + uri + " --output " + tmpDir + mappingName + " --type=mapping";
-//            LinuxCommand.exec(mappingCmd);
-//            //导出data命令
-//            String dataCmd = "/usr/bin/elasticdump --input " + uri + " --output " + tmpDir + dataName + " --type=data";
-//            LinuxCommand.exec(dataCmd);
+            //导出mapping命令
+            String mappingCmd = "/usr/bin/elasticdump --input " + uri + " --output " + tmpDir + mappingName + " --type=mapping";
+            LinuxCommand.exec(mappingCmd);
+            //导出data命令
+            String dataCmd = "/usr/bin/elasticdump --input " + uri + " --output " + tmpDir + dataName + " --type=data";
+            LinuxCommand.exec(dataCmd);
         }
 
         //获取外网同步正式目录

+ 89 - 0
sync-out/src/main/java/com/jjt/out/service/impl/OutProcessServiceImpl.java

@@ -1,14 +1,29 @@
 package com.jjt.out.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jjt.common.constant.Constants;
+import com.jjt.common.domain.FileDesc;
+import com.jjt.common.utils.CompressZip;
 import com.jjt.common.utils.FtpUtil;
+import com.jjt.out.domain.OutSyncInfo;
 import com.jjt.out.service.IOutProcessService;
+import com.jjt.out.service.IOutSyncInfoService;
 import com.jjt.system.service.ISysConfigService;
+import org.apache.commons.codec.digest.DigestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
 
 /**
  * 数据同步Service业务层处理
@@ -21,6 +36,80 @@ public class OutProcessServiceImpl implements IOutProcessService {
     private static final Logger log = LoggerFactory.getLogger(OutProcessServiceImpl.class);
     @Resource
     private ISysConfigService sysConfigService;
+    @Resource
+    private IOutSyncInfoService syncInfoService;
+
+
+    /**
+     * 同步文件
+     */
+    @Override
+    public void sync() {
+        //获取外网同步正式目录
+        String syncDir = sysConfigService.selectConfigByKey("out.dir.sync");
+        if (!syncDir.endsWith(Constants.DIR_END)) {
+            syncDir += "/";
+        }
+        String fgapInfo = sysConfigService.selectConfigByKey("out.fgap.info");
+        FtpUtil ftpUtil = JSONObject.parseObject(fgapInfo, FtpUtil.class);
+        try {
+            // 创建File对象
+            File dirFile = new File(syncDir);
+            if (dirFile.isDirectory()) {
+                //先获取目录下所有json格式文件
+                File[] files = dirFile.listFiles(((dir, name) -> name.endsWith(".json")));
+                if (files != null && files.length > 0) {
+                    Arrays.sort(files, Comparator.comparing(File::getName));
+                }
+
+                for (File file : files) {
+                    //获取文件同步顺序,如果报错,则不同步
+                    try {
+                        //校验JSON文件名格式
+                        if (!file.getName().startsWith("sync-")) {
+                            continue;
+                        }
+                        long sort = Long.parseLong(file.getName().split("-")[1]);
+                        ObjectMapper mapper = new ObjectMapper();
+                        FileDesc desc = mapper.readValue(file, FileDesc.class);
+
+                        File zipFile = new File(syncDir + desc.getName());
+                        String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
+                        if (md5.equals(desc.getMd5())) {
+                            Date start = new Date();
+                            //上传json文件
+                            boolean flag = ftpUtil.upload(file);
+                            //上传zip文件
+                            boolean flag1 = ftpUtil.upload(zipFile);
+                            Date end = new Date();
+
+                            String status = "N";
+                            if (flag && flag1) {
+                                status = "Y";
+                            }
+
+                            OutSyncInfo info = new OutSyncInfo();
+                            info.setSyncType(desc.getType().toString());
+                            info.setCostTime(end.getTime() - start.getTime());
+                            info.setSyncFileMd5(desc.getMd5());
+                            info.setSyncFileName(desc.getName());
+                            info.setSyncSort(sort);
+                            info.setSyncFileSize(file.length());
+                            info.setUploadTime(start);
+                            info.setUploadStatus(status);
+                            syncInfoService.insertOutSyncInfo(info);
+                        } else {
+                            System.err.println("这个是错误滴" + desc.toString());
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
     /**
      * 上传文件到光闸FTP

+ 90 - 0
sync-out/src/main/java/com/jjt/out/service/impl/OutSyncInfoServiceImpl.java

@@ -0,0 +1,90 @@
+package com.jjt.out.service.impl;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.jjt.out.mapper.OutSyncInfoMapper;
+import com.jjt.out.domain.OutSyncInfo;
+import com.jjt.out.service.IOutSyncInfoService;
+import com.jjt.common.core.text.Convert;
+
+import javax.annotation.Resource;
+
+/**
+ * 数据同步Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2023-06-14
+ */
+@Service
+public class OutSyncInfoServiceImpl implements IOutSyncInfoService {
+    @Resource
+    private OutSyncInfoMapper outSyncInfoMapper;
+
+    /**
+     * 查询数据同步
+     *
+     * @param infoId 数据同步主键
+     * @return 数据同步
+     */
+    @Override
+    public OutSyncInfo selectOutSyncInfoByInfoId(Long infoId) {
+        return outSyncInfoMapper.selectOutSyncInfoByInfoId(infoId);
+    }
+
+    /**
+     * 查询数据同步列表
+     *
+     * @param outSyncInfo 数据同步
+     * @return 数据同步
+     */
+    @Override
+    public List<OutSyncInfo> selectOutSyncInfoList(OutSyncInfo outSyncInfo) {
+        return outSyncInfoMapper.selectOutSyncInfoList(outSyncInfo);
+    }
+
+    /**
+     * 新增数据同步
+     *
+     * @param outSyncInfo 数据同步
+     * @return 结果
+     */
+    @Override
+    public int insertOutSyncInfo(OutSyncInfo outSyncInfo) {
+        return outSyncInfoMapper.insertOutSyncInfo(outSyncInfo);
+    }
+
+    /**
+     * 修改数据同步
+     *
+     * @param outSyncInfo 数据同步
+     * @return 结果
+     */
+    @Override
+    public int updateOutSyncInfo(OutSyncInfo outSyncInfo) {
+        return outSyncInfoMapper.updateOutSyncInfo(outSyncInfo);
+    }
+
+    /**
+     * 批量删除数据同步
+     *
+     * @param infoIds 需要删除的数据同步主键
+     * @return 结果
+     */
+    @Override
+    public int deleteOutSyncInfoByInfoIds(String infoIds) {
+        return outSyncInfoMapper.deleteOutSyncInfoByInfoIds(Convert.toStrArray(infoIds));
+    }
+
+    /**
+     * 删除数据同步信息
+     *
+     * @param infoId 数据同步主键
+     * @return 结果
+     */
+    @Override
+    public int deleteOutSyncInfoByInfoId(Long infoId) {
+        return outSyncInfoMapper.deleteOutSyncInfoByInfoId(infoId);
+    }
+}

+ 22 - 0
sync-out/src/main/java/com/jjt/out/task/OutProcessTask.java

@@ -0,0 +1,22 @@
+package com.jjt.out.task;
+
+import com.jjt.out.service.IOutEsService;
+import com.jjt.out.service.IOutProcessService;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * Es定时任务
+ *
+ * @author ruoyi
+ */
+@Component("outProcessTask")
+public class OutProcessTask {
+    @Resource
+    private IOutProcessService processService;
+
+    public void sync() {
+        processService.sync();
+    }
+}

+ 92 - 0
sync-out/src/main/resources/mapper/out/OutSyncInfoMapper.xml

@@ -0,0 +1,92 @@
+<?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.jjt.out.mapper.OutSyncInfoMapper">
+    
+    <resultMap type="OutSyncInfo" id="OutSyncInfoResult">
+        <result property="infoId"    column="INFO_ID"    />
+        <result property="syncType"    column="SYNC_TYPE"    />
+        <result property="syncFileName"    column="SYNC_FILE_NAME"    />
+        <result property="syncFileMd5"    column="SYNC_FILE_MD5"    />
+        <result property="syncFileSize"    column="SYNC_FILE_SIZE"    />
+        <result property="syncSort"    column="SYNC_SORT"    />
+        <result property="costTime"    column="COST_TIME"    />
+        <result property="uploadTime"    column="UPLOAD_TIME"    />
+        <result property="uploadStatus"    column="UPLOAD_STATUS"    />
+    </resultMap>
+
+    <sql id="selectOutSyncInfoVo">
+        select INFO_ID, SYNC_TYPE, SYNC_FILE_NAME, SYNC_FILE_MD5, SYNC_FILE_SIZE, SYNC_SORT, COST_TIME, UPLOAD_TIME, UPLOAD_STATUS from out_sync_info
+    </sql>
+
+    <select id="selectOutSyncInfoList" parameterType="OutSyncInfo" resultMap="OutSyncInfoResult">
+        <include refid="selectOutSyncInfoVo"/>
+        <where>  
+            <if test="syncType != null  and syncType != ''"> and SYNC_TYPE = #{syncType}</if>
+            <if test="syncFileName != null  and syncFileName != ''"> and SYNC_FILE_NAME like concat('%', #{syncFileName}, '%')</if>
+            <if test="syncFileMd5 != null  and syncFileMd5 != ''"> and SYNC_FILE_MD5 = #{syncFileMd5}</if>
+            <if test="syncFileSize != null "> and SYNC_FILE_SIZE = #{syncFileSize}</if>
+            <if test="syncSort != null "> and SYNC_SORT = #{syncSort}</if>
+            <if test="costTime != null "> and COST_TIME = #{costTime}</if>
+            <if test="uploadTime != null "> and UPLOAD_TIME = #{uploadTime}</if>
+            <if test="uploadStatus != null  and uploadStatus != ''"> and UPLOAD_STATUS = #{uploadStatus}</if>
+        </where>
+    </select>
+    
+    <select id="selectOutSyncInfoByInfoId" parameterType="Long" resultMap="OutSyncInfoResult">
+        <include refid="selectOutSyncInfoVo"/>
+        where INFO_ID = #{infoId}
+    </select>
+        
+    <insert id="insertOutSyncInfo" parameterType="OutSyncInfo" useGeneratedKeys="true" keyProperty="infoId">
+        insert into out_sync_info
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="syncType != null">SYNC_TYPE,</if>
+            <if test="syncFileName != null">SYNC_FILE_NAME,</if>
+            <if test="syncFileMd5 != null">SYNC_FILE_MD5,</if>
+            <if test="syncFileSize != null">SYNC_FILE_SIZE,</if>
+            <if test="syncSort != null">SYNC_SORT,</if>
+            <if test="costTime != null">COST_TIME,</if>
+            <if test="uploadTime != null">UPLOAD_TIME,</if>
+            <if test="uploadStatus != null">UPLOAD_STATUS,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="syncType != null">#{syncType},</if>
+            <if test="syncFileName != null">#{syncFileName},</if>
+            <if test="syncFileMd5 != null">#{syncFileMd5},</if>
+            <if test="syncFileSize != null">#{syncFileSize},</if>
+            <if test="syncSort != null">#{syncSort},</if>
+            <if test="costTime != null">#{costTime},</if>
+            <if test="uploadTime != null">#{uploadTime},</if>
+            <if test="uploadStatus != null">#{uploadStatus},</if>
+         </trim>
+    </insert>
+
+    <update id="updateOutSyncInfo" parameterType="OutSyncInfo">
+        update out_sync_info
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="syncType != null">SYNC_TYPE = #{syncType},</if>
+            <if test="syncFileName != null">SYNC_FILE_NAME = #{syncFileName},</if>
+            <if test="syncFileMd5 != null">SYNC_FILE_MD5 = #{syncFileMd5},</if>
+            <if test="syncFileSize != null">SYNC_FILE_SIZE = #{syncFileSize},</if>
+            <if test="syncSort != null">SYNC_SORT = #{syncSort},</if>
+            <if test="costTime != null">COST_TIME = #{costTime},</if>
+            <if test="uploadTime != null">UPLOAD_TIME = #{uploadTime},</if>
+            <if test="uploadStatus != null">UPLOAD_STATUS = #{uploadStatus},</if>
+        </trim>
+        where INFO_ID = #{infoId}
+    </update>
+
+    <delete id="deleteOutSyncInfoByInfoId" parameterType="Long">
+        delete from out_sync_info where INFO_ID = #{infoId}
+    </delete>
+
+    <delete id="deleteOutSyncInfoByInfoIds" parameterType="String">
+        delete from out_sync_info where INFO_ID in 
+        <foreach item="infoId" collection="array" open="(" separator="," close=")">
+            #{infoId}
+        </foreach>
+    </delete>
+
+</mapper>