wangliang 4 år sedan
förälder
incheckning
b5116802e7

+ 107 - 57
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/BasicAttachment.java

@@ -1,11 +1,17 @@
 package com.qmth.distributed.print.business.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.distributed.print.business.base.BaseEntity;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * <p>
@@ -16,42 +22,95 @@ import java.io.Serializable;
  * @since 2021-03-23
  */
 @TableName("basic_attachment")
-public class BasicAttachment extends BaseEntity implements Serializable {
+public class BasicAttachment implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    /**
-     * 文件名
-     */
+    @ApiModelProperty(value = "主键")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @TableId(value = "id")
+    private Long id;
+
+    @ApiModelProperty(value = "附件名称")
+    @TableField(value = "name")
     private String name;
-    /**
-     * 文件类型
-     */
+
+    @ApiModelProperty(value = "路径")
+    @TableField(value = "path")
+    private String path;
+
+    @ApiModelProperty(value = "类型")
+    @TableField(value = "type")
     private String type;
-    /**
-     * 单位(KB)
-     */
-    private Integer size;
-    /**
-     * 文件md5值
-     */
+
+    @ApiModelProperty(value = "大小")
+    @TableField(value = "size")
+    private BigDecimal size;
+
+    @ApiModelProperty(value = "MD5")
+    @TableField(value = "md5")
     private String md5;
-    /**
-     * H-高,M-中,L-低
-     */
-    private String level;
-    /**
-     * LOCAL-本地存储,OSS-阿里OSS
-     */
-    private String storage;
-    /**
-     * 存储路径
-     */
-    private String path;
-    /**
-     * 备注
-     */
-    private String remark;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(value = "create_time", fill = FieldFill.INSERT)//新增执行
+    private Long createTime;
+
+    @ApiModelProperty(value = "创建人id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @TableField("create_id")
+    private Long createId;
+
+    @ApiModelProperty(value = "关联业务id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @TableField("obj_id")
+    private Long objId;
+
+    public BasicAttachment() {
+
+    }
+
+    public BasicAttachment(String path, String name, String type, BigDecimal size, String md5, Long createId) {
+        this.id = SystemConstant.getDbUuid();
+        this.path = path;
+        this.name = name;
+        this.type = type;
+        this.size = size;
+        this.md5 = md5;
+        this.createTime = System.currentTimeMillis();
+        this.createId = createId;
+    }
+
+    public BasicAttachment(String path, String name, String type, BigDecimal size, String md5, Long createId, Long objId) {
+        this.id = SystemConstant.getDbUuid();
+        this.path = path;
+        this.name = name;
+        this.type = type;
+        this.size = size;
+        this.md5 = md5;
+        this.createTime = System.currentTimeMillis();
+        this.createId = createId;
+        this.objId = objId;
+    }
+
+    public Long getObjId() {
+        return objId;
+    }
+
+    public void setObjId(Long objId) {
+        this.objId = objId;
+    }
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
 
     public String getName() {
         return name;
@@ -61,6 +120,14 @@ public class BasicAttachment extends BaseEntity implements Serializable {
         this.name = name;
     }
 
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
     public String getType() {
         return type;
     }
@@ -69,11 +136,11 @@ public class BasicAttachment extends BaseEntity implements Serializable {
         this.type = type;
     }
 
-    public Integer getSize() {
+    public BigDecimal getSize() {
         return size;
     }
 
-    public void setSize(Integer size) {
+    public void setSize(BigDecimal size) {
         this.size = size;
     }
 
@@ -85,36 +152,19 @@ public class BasicAttachment extends BaseEntity implements Serializable {
         this.md5 = md5;
     }
 
-    public String getLevel() {
-        return level;
-    }
-
-    public void setLevel(String level) {
-        this.level = level;
-    }
-
-    public String getStorage() {
-        return storage;
-    }
-
-    public void setStorage(String storage) {
-        this.storage = storage;
+    public Long getCreateTime() {
+        return createTime;
     }
 
-    public String getPath() {
-        return path;
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
     }
 
-    public void setPath(String path) {
-        this.path = path;
+    public Long getCreateId() {
+        return createId;
     }
 
-    public String getRemark() {
-        return remark;
+    public void setCreateId(Long createId) {
+        this.createId = createId;
     }
-
-    public void setRemark(String remark) {
-        this.remark = remark;
-    }
-
 }

+ 22 - 16
distributed-print-business/src/main/resources/db/init-table.sql

@@ -21,23 +21,29 @@ SET FOREIGN_KEY_CHECKS = 0;
 -- Table structure for basic_attachment
 -- ----------------------------
 DROP TABLE IF EXISTS `basic_attachment`;
-CREATE TABLE `basic_attachment`  (
-  `id` bigint(10) NOT NULL AUTO_INCREMENT,
-  `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '文件名',
-  `type` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '文件类型',
-  `size` int(11) NOT NULL COMMENT '单位(KB)',
-  `md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '文件md5值',
-  `level` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'H-高,M-中,L-低',
-  `storage` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'LOCAL-本地存储,OSS-阿里OSS',
-  `path` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '存储路径',
-  `remark` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
-  `create_id` bigint(10) NULL DEFAULT NULL COMMENT '创建人',
-  `create_time` bigint(13) NULL DEFAULT NULL COMMENT '创建时间',
-  `update_id` bigint(10) NULL DEFAULT NULL,
-  `update_time` bigint(13) NULL DEFAULT NULL,
-  PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '所有附件记录表' ROW_FORMAT = Dynamic;
+CREATE TABLE basic_attachment
+(
+	id BIGINT AUTO_INCREMENT PRIMARY KEY NOT NULL,
+	name VARCHAR(100)
+		COMMENT '文件名' NOT NULL,
+	type VARCHAR(10)
+		COMMENT '文件类型' NOT NULL,
+	size INTEGER
+		COMMENT '单位(KB)' NOT NULL,
+	md5 VARCHAR(32)
+		COMMENT '文件md5值' NOT NULL,
+	path VARCHAR(2000)
+		COMMENT '存储路径' NOT NULL,
+	create_id BIGINT
+		COMMENT '创建人' NULL,
+	create_time BIGINT
+		COMMENT '创建时间' NULL,
+	obj_id BIGINT
+		COMMENT '关联业务id' NULL
+) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='所有附件记录表';
 
+/* Add Comments */
+ALTER TABLE basic_attachment COMMENT = '所有附件记录表';
 -- ----------------------------
 -- Table structure for basic_card_rule
 -- ----------------------------

+ 61 - 0
distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java

@@ -1,7 +1,12 @@
 package com.qmth.distributed.print.common.contant;
 
+import com.qmth.boot.core.uid.service.UidService;
+
+import java.io.File;
 import java.nio.charset.Charset;
 import java.util.Objects;
+import java.util.StringJoiner;
+import java.util.UUID;
 
 /**
  * @Description: 系统常量
@@ -21,6 +26,9 @@ public class SystemConstant {
     public static final String SUCCESS = "success";
     public static final String EXTEND_COLUMN = "extendColumn";
     public static final String METHOD = "post";
+    public static final String USER_DIR = "user.dir";
+    public static final String PDF_TEMP = "pdf-temp";
+    public static final String FILE_TEMP = "file-temp";
 
     /**
      * 鉴权
@@ -44,6 +52,31 @@ public class SystemConstant {
     public static final String AES_MODE_PKCS7 = "AES/CBC/PKCS7Padding";//用这个模式,规则必须为16位
     public static final String AES_RULE = "1234567890123456";//aes密钥
 
+
+    /**
+     * 变量
+     */
+    public static String TEMP_FILES_DIR;
+    public static String PDF_TEMP_FILES_DIR;
+
+    /**
+     * 初始化附件文件路径
+     */
+    public static void initTempFiles() {
+        StringJoiner localPath = new StringJoiner("").add(System.getProperty(USER_DIR));
+        String mkdir = localPath.toString().substring(0, localPath.toString().lastIndexOf(File.separator));
+        File fileTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(FILE_TEMP).toString());
+        if (!fileTempDir.exists()) {
+            fileTempDir.mkdirs();
+        }
+        File pdfTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(PDF_TEMP).toString());
+        if (!pdfTempDir.exists()) {
+            pdfTempDir.mkdirs();
+        }
+        TEMP_FILES_DIR = fileTempDir.getPath();
+        PDF_TEMP_FILES_DIR = pdfTempDir.getPath();
+    }
+
     /**
      * id转换为long
      *
@@ -52,4 +85,32 @@ public class SystemConstant {
     public static Long convertIdToLong(String id) {
         return Objects.nonNull(id) && id.length() > 0 ? Long.parseLong(id) : null;
     }
+
+    /**
+     * 获取全局uuid
+     *
+     * @return
+     */
+    public static String getUuid() {
+        return String.valueOf(UUID.randomUUID()).replaceAll("-", "");
+    }
+
+    /**
+     * 获取数据库uuid
+     *
+     * @return
+     */
+    public static Long getDbUuid() {
+        UidService uidservice = SpringContextHolder.getBean(UidService.class);
+        return uidservice.getId();
+    }
+
+    /**
+     * enable转换
+     *
+     * @return
+     */
+    public static Boolean convertEnable(Boolean enable) {
+        return Objects.nonNull(enable) ? enable : true;
+    }
 }