刘小明
2024-10-12 b76fd3fa68f6e64b40a101d7f688f748dd88d35c
添加网串中间件上传下载接口;修改文件上传大小限制
5个文件已添加
1个文件已修改
241 ■■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthNetSerialAdapterFileMapper.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthNetSerialAdapterFile.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/application-global.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/OthNetSerialAdapterFileMapper.xml 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterCtrl.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterSv.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthNetSerialAdapterFileMapper.java
New file
@@ -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();
}
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthNetSerialAdapterFile.java
New file
@@ -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;
}
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
pms-parent/pms-global/src/main/resources/mapper/OthNetSerialAdapterFileMapper.xml
New file
@@ -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>
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterCtrl.java
New file
@@ -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);
    }
}
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/adapter/AdapterSv.java
New file
@@ -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;
    }
}