zhoupeng 1 year ago
parent
commit
a4f21fb585

+ 21 - 0
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/TextEditor.java

@@ -0,0 +1,21 @@
+package com.example.opc_common.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class TextEditor implements Serializable {
+
+    private static final long serialVersionUID = -96536212774977561L;
+
+    //主键
+    private Integer id;
+    //用户id
+    private String userId;
+    //用户名称
+    private String content;
+    //创建时间
+    private Date createTime;
+}

+ 73 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/TextEditorController.java

@@ -0,0 +1,73 @@
+package com.example.opc_da.controller;
+
+import com.example.opc_common.entity.TextEditor;
+import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.util.Blank;
+import com.example.opc_common.util.Result;
+import com.example.opc_da.service.TextEditorService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("textEditor")
+@Slf4j
+public class TextEditorController {
+
+    @Autowired
+    private TextEditorService textEditorService;
+
+    /**
+     * 新增富文本编辑器
+     *
+     * @param textEditor
+     * @return
+     */
+    @PostMapping("/addTextEditor")
+    public Result addTextEditor(@RequestBody TextEditor textEditor) {
+        if (Blank.isEmpty(textEditor, textEditor.getContent())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表、定时任务都不能为空");
+        }
+        return textEditorService.addTextEditor(textEditor);
+    }
+
+    /**
+     * 获取所有富文本编辑器
+     *
+     * @param page
+     * @param limit
+     * @return
+     */
+    @GetMapping("/getAllTextEditor")
+    public Result getAllTextEditor(Integer page, Integer limit) {
+        if (Blank.isEmpty(page, limit)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return textEditorService.getAllTextEditor(page, limit);
+    }
+
+    /**
+     * 通过id获取富文本编辑器
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/getTextEditorById")
+    public Result getTextEditorById(Integer id) {
+        if (Blank.isEmpty(id)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return textEditorService.getTextEditorById(id);
+    }
+
+    /**
+     * 获取最新一条富文本编辑器
+     *
+     * @return
+     */
+    @GetMapping("/getTextEditorNew")
+    public Result getTextEditorNew() {
+        return textEditorService.getTextEditorNew();
+    }
+
+}

+ 20 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/TextEditorDao.java

@@ -0,0 +1,20 @@
+package com.example.opc_da.dao;
+
+import com.example.opc_common.entity.TextEditor;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface TextEditorDao {
+
+    Integer addTextEditor(TextEditor textEditor);
+
+    TextEditor getTextEditorById(Integer id);
+
+    Long getTextEditorCount(String userId);
+
+    List<TextEditor> getAllTextEditor(Long startNum, Long limitNum, String userId);
+
+    TextEditor getTextEditorNew();
+}

+ 15 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/TextEditorService.java

@@ -0,0 +1,15 @@
+package com.example.opc_da.service;
+
+import com.example.opc_common.entity.TextEditor;
+import com.example.opc_common.util.Result;
+
+public interface TextEditorService {
+    Result addTextEditor(TextEditor textEditor);
+
+    Result getTextEditorById(Integer id);
+
+    Result getAllTextEditor(Integer page, Integer limit);
+
+    Result getTextEditorNew();
+
+}

+ 59 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/TextEditorServiceImpl.java

@@ -0,0 +1,59 @@
+package com.example.opc_da.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.example.opc_common.entity.Log;
+import com.example.opc_common.entity.TextEditor;
+import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.util.Result;
+import com.example.opc_da.dao.TextEditorDao;
+import com.example.opc_da.service.TextEditorService;
+import com.example.opc_da.util.UserUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+@Transactional
+public class TextEditorServiceImpl implements TextEditorService {
+
+    @Autowired
+    private TextEditorDao textEditorDao;
+
+    @Autowired
+    private UserUtil userUtil;
+
+    @Override
+    public Result addTextEditor(TextEditor textEditor) {
+        textEditor.setUserId(userUtil.getCurrentUserId());
+        if (textEditorDao.addTextEditor(textEditor) <= 0) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "新增失败");
+        }
+        return Result.ok("新增成功");
+    }
+
+    @Override
+    public Result getAllTextEditor(Integer page, Integer limit) {
+        String userId = userUtil.getCurrentUserId();
+        JSONObject jsonObject = new JSONObject();
+        Long count = textEditorDao.getTextEditorCount(userId);
+        Long startNum = Long.valueOf((page - 1) * limit);
+        List<TextEditor> textEditorList = textEditorDao.getAllTextEditor(startNum, Long.valueOf(limit), userId);
+        jsonObject.put("count", count);
+        jsonObject.put("textEditorList", textEditorList);
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public Result getTextEditorNew() {
+        return Result.ok(textEditorDao.getTextEditorNew());
+    }
+
+    @Override
+    public Result getTextEditorById(Integer id) {
+        return Result.ok(textEditorDao.getTextEditorById(id));
+    }
+
+
+}

+ 5 - 6
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ScheduledTask.java

@@ -5,10 +5,8 @@ import com.example.opc_common.entity.AttachRawData;
 import com.example.opc_common.entity.DataSource;
 import com.example.opc_common.entity.Item;
 import com.example.opc_common.entity.ItemGroup;
-import com.example.opc_common.util.Blank;
-import com.example.opc_common.util.ConstantStr;
-import com.example.opc_common.util.DateUtil;
-import com.example.opc_common.util.OpcUtil;
+import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.util.*;
 import com.example.opc_da.dao.DataSourceDao;
 import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.util.OpcDaUtil;
@@ -50,6 +48,9 @@ public class ScheduledTask {
         List<DataSource> dataSourceList = dataSourceDao.getAllDataSource(null);
         if (Blank.isNotEmpty(dataSourceList)) {
             for (DataSource dataSource : dataSourceList) {
+                if (Blank.isNotEmpty(dataSource.getIpPassword())) {
+                    dataSource = DataSource.convertPassword(dataSource);
+                }
                 String dataSourceTypeKey = dataSource.getDataSourceTypeKey();
                 Integer dataSourceId = dataSource.getId();
                 if (OpcUtil.isOpcDa(dataSourceTypeKey)) {
@@ -105,8 +106,6 @@ public class ScheduledTask {
                                                 opcAsyncTask.addAttachRawData(attachRawData);
                                             }
                                         }
-                                        AttachRawData attachRawData = new AttachRawData();
-                                        opcAsyncTask.addAttachRawData(attachRawData);
                                     }
                                 }
                             } catch (Exception e) {

+ 43 - 0
chaunyi_opc/opc_da/src/main/resources/mapper/TextEditorDao.xml

@@ -0,0 +1,43 @@
+<?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.example.opc_da.dao.TextEditorDao">
+
+    <sql id="textEditor">
+        id
+        , user_id, content, create_time
+    </sql>
+
+    <insert id="addTextEditor">
+        insert into t_text_editor(user_id, content, create_time)
+            value (#{userId},#{content},now())
+    </insert>
+
+    <select id="getTextEditorById" resultType="com.example.opc_common.entity.TextEditor">
+        select
+        <include refid="textEditor"/>
+        from t_text_editor
+        where id = #{id}
+    </select>
+
+    <select id="getTextEditorCount" resultType="java.lang.Long">
+        select count(*)
+        from t_text_editor
+        where user_id = #{userId}
+    </select>
+
+    <select id="getAllTextEditor" resultType="com.example.opc_common.entity.TextEditor">
+        select
+        <include refid="textEditor"/>
+        from t_text_editor
+        where user_id = #{userId}
+        order by create_time DESC
+        limit #{startNum},#{limitNum}
+    </select>
+
+    <select id="getTextEditorNew" resultType="com.example.opc_common.entity.TextEditor">
+        select
+        <include refid="textEditor"/>
+        from t_text_editor
+        order by create_time DESC limit 1
+    </select>
+</mapper>