From b76fd3fa68f6e64b40a101d7f688f748dd88d35c Mon Sep 17 00:00:00 2001
From: 刘小明 <liuxm_a@163.com>
Date: 星期六, 12 十月 2024 11:18:39 +0800
Subject: [PATCH] 添加网串中间件上传下载接口;修改文件上传大小限制

---
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterCtrl.java                |   34 ++++++
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthNetSerialAdapterFileMapper.java |   21 ++++
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthNetSerialAdapterFile.java      |   47 +++++++++
 pms-parent/pms-global/src/main/resources/application-global.yml                                |    4 
 pms-parent/pms-global/src/main/resources/mapper/OthNetSerialAdapterFileMapper.xml              |   76 +++++++++++++++
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterSv.java                  |   59 +++++++++++
 6 files changed, 239 insertions(+), 2 deletions(-)

diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthNetSerialAdapterFileMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthNetSerialAdapterFileMapper.java
new file mode 100644
index 0000000..74ae36d
--- /dev/null
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthNetSerialAdapterFileMapper.java
@@ -0,0 +1,21 @@
+package com.dy.pmsGlobal.daoOth;
+
+import com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface OthNetSerialAdapterFileMapper {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(OthNetSerialAdapterFile record);
+
+    int insertSelective(OthNetSerialAdapterFile record);
+
+    OthNetSerialAdapterFile selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(OthNetSerialAdapterFile record);
+
+    int updateByPrimaryKey(OthNetSerialAdapterFile record);
+
+    OthNetSerialAdapterFile getAdapter();
+}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthNetSerialAdapterFile.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthNetSerialAdapterFile.java
new file mode 100644
index 0000000..b1abc14
--- /dev/null
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthNetSerialAdapterFile.java
@@ -0,0 +1,47 @@
+package com.dy.pmsGlobal.pojoOth;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.dy.common.po.BaseEntity;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import jakarta.validation.constraints.NotNull;
+import lombok.*;
+
+import java.util.Date;
+
+/**
+ * 缃戜覆涓棿浠朵笅杞借〃
+ */
+@TableName(value="oth_net_serial_adapter_file", autoResultMap = true)
+@Data
+@Builder
+@ToString
+@NoArgsConstructor
+@AllArgsConstructor
+public class OthNetSerialAdapterFile implements BaseEntity {
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    public Long id;
+
+    /**
+    * 鏂囦欢缂栧彿
+    */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    @NotNull
+    public Long fileId;
+
+    /**
+    * 涓婁紶鏃堕棿
+    */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    public Date dt;
+
+    @TableField(exist = false)
+    public String webUrl;
+
+    @TableField(exist = false)
+    public String orgName;
+    @TableField(exist = false)
+    public String extName;
+}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/resources/application-global.yml b/pms-parent/pms-global/src/main/resources/application-global.yml
index 79deadf..745cfc0 100644
--- a/pms-parent/pms-global/src/main/resources/application-global.yml
+++ b/pms-parent/pms-global/src/main/resources/application-global.yml
@@ -2,8 +2,8 @@
     servlet:
         multipart:
             # 鍓嶇涓婁紶鏂囦欢锛岄檺鍒跺崟涓枃浠剁殑澶у皬鍜岄檺鍒舵墍鏈夋枃浠剁殑澶у皬
-            max-file-size: 1MB
-            max-request-size: 10MB
+            max-file-size: 20MB
+            max-request-size: 25MB
 logging:
     charset:
         console: UTF-8
diff --git a/pms-parent/pms-global/src/main/resources/mapper/OthNetSerialAdapterFileMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/OthNetSerialAdapterFileMapper.xml
new file mode 100644
index 0000000..6ef0b9d
--- /dev/null
+++ b/pms-parent/pms-global/src/main/resources/mapper/OthNetSerialAdapterFileMapper.xml
@@ -0,0 +1,76 @@
+<?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.dy.pmsGlobal.daoOth.OthNetSerialAdapterFileMapper">
+  <resultMap id="BaseResultMap" type="com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile">
+    <!--@mbg.generated-->
+    <!--@Table oth_net_serial_adapter_file-->
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="file_id" jdbcType="BIGINT" property="fileId" />
+    <result column="dt" jdbcType="TIMESTAMP" property="dt" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, file_id, dt
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    <!--@mbg.generated-->
+    select 
+    <include refid="Base_Column_List" />
+    from oth_net_serial_adapter_file
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    <!--@mbg.generated-->
+    delete from oth_net_serial_adapter_file
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile" useGeneratedKeys="true">
+    <!--@mbg.generated-->
+    insert into oth_net_serial_adapter_file (file_id, dt)
+    values (#{fileId,jdbcType=BIGINT}, #{dt,jdbcType=TIMESTAMP})
+  </insert>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile" useGeneratedKeys="true">
+    <!--@mbg.generated-->
+    insert into oth_net_serial_adapter_file
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="fileId != null">
+        file_id,
+      </if>
+      <if test="dt != null">
+        dt,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="fileId != null">
+        #{fileId,jdbcType=BIGINT},
+      </if>
+      <if test="dt != null">
+        #{dt,jdbcType=TIMESTAMP},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile">
+    <!--@mbg.generated-->
+    update oth_net_serial_adapter_file
+    <set>
+      <if test="fileId != null">
+        file_id = #{fileId,jdbcType=BIGINT},
+      </if>
+      <if test="dt != null">
+        dt = #{dt,jdbcType=TIMESTAMP},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile">
+    <!--@mbg.generated-->
+    update oth_net_serial_adapter_file
+    set file_id = #{fileId,jdbcType=BIGINT},
+      dt = #{dt,jdbcType=TIMESTAMP}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+
+  <select id="getAdapter" resultMap="BaseResultMap">
+    select * from oth_net_serial_adapter_file limit 1
+  </select>
+</mapper>
\ No newline at end of file
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterCtrl.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterCtrl.java
new file mode 100644
index 0000000..1ebe4ff
--- /dev/null
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterCtrl.java
@@ -0,0 +1,34 @@
+package com.dy.pmsOther.adapter;
+
+import com.alibaba.fastjson2.JSON;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile;
+import jakarta.validation.Valid;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping(value = "adapter")
+public class AdapterCtrl {
+    private AdapterSv sv;
+
+    public AdapterCtrl(AdapterSv sv) {
+        this.sv = sv;
+    }
+
+    @GetMapping(value = "/getAdapter")
+    public BaseResponse<OthNetSerialAdapterFile> getAdapter() {
+        OthNetSerialAdapterFile adapter = sv.getAdapter();
+        return BaseResponseUtils.buildSuccess(JSON.toJSON(adapter));
+    }
+
+    @PostMapping(value="saveOrUpdate")
+    public BaseResponse<OthNetSerialAdapterFile> saveOrUpdateAdapter(@RequestBody @Valid OthNetSerialAdapterFile adapter) {
+        int count =sv.saveOrUpdateAdapter(adapter);
+        if (count <= 0) {
+            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+}
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterSv.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterSv.java
new file mode 100644
index 0000000..ea22970
--- /dev/null
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterSv.java
@@ -0,0 +1,59 @@
+package com.dy.pmsOther.adapter;
+
+import com.dy.pmsGlobal.daoOth.OthFileMapper;
+import com.dy.pmsGlobal.daoOth.OthNetSerialAdapterFileMapper;
+import com.dy.pmsGlobal.dyFile.FileOperate;
+import com.dy.pmsGlobal.dyFile.FileRestVo;
+import com.dy.pmsGlobal.pojoOth.OthFile;
+import com.dy.pmsGlobal.pojoOth.OthNetSerialAdapterFile;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class AdapterSv {
+    private OthNetSerialAdapterFileMapper dao;
+    private FileOperate fileOperate;
+    private OthFileMapper othFileMapper;
+    @Value("${dy.webFile.fmUrl}")
+    private String fmUrl ;
+    @Autowired
+    public void setDao(OthNetSerialAdapterFileMapper dao) {
+        this.dao = dao;
+    }
+    @Autowired
+    public void setFileOperate(FileOperate fileOperate) {
+        this.fileOperate = fileOperate;
+    }
+    @Autowired
+    public void setOthFileMapper(OthFileMapper othFileMapper) {
+        this.othFileMapper = othFileMapper;
+    }
+
+
+    public OthNetSerialAdapterFile getAdapter() {
+        OthNetSerialAdapterFile adapter =dao.getAdapter();
+        if(adapter != null){
+            OthFile file = othFileMapper.selectByPrimaryKey(adapter.fileId);
+            if (file != null) {
+                FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
+                adapter.webUrl = fileRestVo.fileWebDownloadPath + adapter.fileId;
+                adapter.orgName = file.orgName;
+                adapter.extName = file.extName;
+            }
+        }
+        return adapter;
+    }
+
+    public int saveOrUpdateAdapter(OthNetSerialAdapterFile adapter) {
+        int count=0;
+        if(adapter.getId()==null){
+            count = dao.insertSelective(adapter);
+        }else{
+            count = dao.updateByPrimaryKeySelective(adapter);
+        }
+        return count;
+    }
+}

--
Gitblit v1.8.0