mysql存储

This commit is contained in:
lizhengwei 2025-11-25 15:02:51 +08:00
parent bb9462f796
commit 2592f2d261
29 changed files with 219 additions and 343 deletions

View File

@ -21,22 +21,24 @@ SET FOREIGN_KEY_CHECKS = 0;
-- Table structure for h5_font
-- ----------------------------
DROP TABLE IF EXISTS `h5_font`;
CREATE TABLE `h5_font` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`source` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字体来源',
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '字体名称',
`font_family` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '字体族名称(唯一标识)',
`lang` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字体语言类型zh-中文en-英文',
`alias` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字体别名',
`authorization_id` bigint NULL DEFAULT NULL COMMENT '授权ID',
`user_over_role` int NULL DEFAULT NULL COMMENT '用户角色',
`sale_type` int NULL DEFAULT NULL COMMENT '销售类型',
`create_time` bigint NOT NULL COMMENT '创建时间戳',
`update_time` bigint NOT NULL COMMENT '更新时间戳',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_font_family`(`font_family`) USING BTREE COMMENT '字体族名称唯一索引',
INDEX `idx_lang`(`lang`) USING BTREE COMMENT '语言类型索引',
INDEX `idx_name`(`name`) USING BTREE COMMENT '字体名称索引'
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '字体表' ROW_FORMAT = Dynamic;
CREATE TABLE `h5_font`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`source_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '字体来源',
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '字体名称',
`preview` json NOT NULL COMMENT '预览JSON格式',
`lang` varchar(10) NOT NULL COMMENT '字体语言类型zh-中文en-英文',
`alias` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '字体别名',
`content` json NOT NULL COMMENT '字体内容JSON格式',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间戳',
`update_time` DATETIME ON UPDATE CURRENT_TIMESTAMP NULL COMMENT '更新时间戳',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_name` (`name`) USING BTREE COMMENT '字体族名称唯一索引',
INDEX `idx_lang` (`lang`) USING BTREE COMMENT '语言类型索引',
INDEX `idx_name` (`name`) USING BTREE COMMENT '字体名称索引'
) ENGINE = InnoDB
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '字体表'
ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -1,13 +1,13 @@
CREATE TABLE `h5_form_submission`
(
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
project_id bigint NOT NULL COMMENT 'H5Project的ID',
ip_address bigint UNSIGNED DEFAULT NULL COMMENT '提交者IP地址',
user_agent varchar(512) DEFAULT NULL COMMENT '用户代理信息',
form_data JSON NOT NULL COMMENT '表单数据JSON格式存储',
create_time bigint not null comment '创建时间戳',
update_time bigint not null comment '更新时间戳',
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
project_id bigint NOT NULL COMMENT 'H5Project的ID',
ip_address bigint UNSIGNED DEFAULT NULL COMMENT '提交者IP地址',
user_agent varchar(512) DEFAULT NULL COMMENT '用户代理信息',
form_data JSON NOT NULL COMMENT '表单数据JSON格式存储',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间戳',
`update_time` DATETIME ON UPDATE CURRENT_TIMESTAMP NULL COMMENT '更新时间戳',
PRIMARY KEY (id),
KEY `idx_project_id` (project_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT ='表单提交记录表';
DEFAULT CHARSET = utf8mb4 COMMENT ='表单提交记录表';

View File

@ -29,8 +29,8 @@ CREATE TABLE `h5_group`
`type` int NOT NULL COMMENT '分组类型1-物料 2-用途 3-行业',
`sort` int NOT NULL DEFAULT 0 COMMENT '排序',
`status` int NOT NULL DEFAULT 1 COMMENT '状态0-禁用 1-启用',
`create_time` bigint NOT NULL COMMENT '创建时间戳',
`update_time` bigint NULL DEFAULT NULL COMMENT '更新时间戳',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间戳',
`update_time` DATETIME ON UPDATE CURRENT_TIMESTAMP NULL COMMENT '更新时间戳',
INDEX `idx_parent_id` (`parent_id`) USING BTREE,
INDEX `idx_type` (`type`) USING BTREE
) ENGINE = InnoDB
@ -43,34 +43,34 @@ CREATE TABLE `h5_group`
-- 插入默认分组数据
-- ----------------------------
INSERT INTO `h5_group`
VALUES (1, '物料', 0, 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (1, '物料', 0, 1, 1, 1, CURRENT_TIMESTAMP(), null);
INSERT INTO `h5_group`
VALUES (2, '用途', 0, 2, 2, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (2, '用途', 0, 2, 2, 1, CURRENT_TIMESTAMP(), null);
INSERT INTO `h5_group`
VALUES (3, '行业', 0, 3, 3, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (3, '行业', 0, 3, 3, 1, CURRENT_TIMESTAMP(), null);
-- ----------------------------
-- 插入二级分组数据 - 物料
-- ----------------------------
INSERT INTO `h5_group`
VALUES (4, '长页', 1, 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (4, '长页', 1, 1, 1, 1, CURRENT_TIMESTAMP(), null);
INSERT INTO `h5_group`
VALUES (5, '翻页', 1, 1, 2, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (5, '翻页', 1, 1, 2, 1, CURRENT_TIMESTAMP(), null);
-- ----------------------------
-- 插入二级分组数据 - 用途
-- ----------------------------
INSERT INTO `h5_group`
VALUES (6, '通用', 2, 2, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (6, '通用', 2, 2, 1, 1, CURRENT_TIMESTAMP(), null);
INSERT INTO `h5_group`
VALUES (7, '祝福问候', 2, 2, 2, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (7, '祝福问候', 2, 2, 2, 1, CURRENT_TIMESTAMP(), null);
-- ----------------------------
-- 插入二级分组数据 - 行业
-- ----------------------------
INSERT INTO `h5_group`
VALUES (8, '金融', 3, 3, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (8, '金融', 3, 3, 1, 1, CURRENT_TIMESTAMP(), null);
INSERT INTO `h5_group`
VALUES (9, '医疗', 3, 3, 2, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES (9, '医疗', 3, 3, 2, 1, CURRENT_TIMESTAMP(), null);
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -26,15 +26,16 @@ CREATE TABLE `h5_project`
`id` bigint PRIMARY KEY NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`type` varchar(10) NOT NULL COMMENT '类型',
`title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '标题',
`content_updated_at` bigint NULL DEFAULT NULL COMMENT '内容更新时间戳',
`description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '描述',
`preview_url` varchar(500) NULL DEFAULT NULL COMMENT '预览图URL',
`preview_url_watermark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '水印预览图URL',
`content` json NOT NULL COMMENT '项目内容JSON格式',
`content_updated_at` bigint NULL COMMENT '内容更新时间戳',
`description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '描述',
`preview_url` varchar(500) NULL COMMENT '预览图URL',
`preview_url_watermark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '水印预览图URL',
`preview_width` int NOT NULL COMMENT '预览图宽度',
`preview_height` int NOT NULL COMMENT '预览图高度',
`status` tinyint NOT NULL COMMENT '状态',
`create_time` bigint NOT NULL COMMENT '创建时间戳',
`update_time` bigint NULL DEFAULT NULL COMMENT '更新时间戳'
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间戳',
`update_time` DATETIME ON UPDATE CURRENT_TIMESTAMP NULL COMMENT '更新时间戳'
) ENGINE = InnoDB
AUTO_INCREMENT = 1
CHARACTER SET = utf8mb4

View File

@ -24,9 +24,9 @@ DROP TABLE IF EXISTS `h5_project_group`;
CREATE TABLE `h5_project_group`
(
`id` bigint PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
`project_id` bigint NOT NULL COMMENT '项目ID',
`group_id` bigint NOT NULL COMMENT '分组ID',
`create_time` bigint NOT NULL COMMENT '创建时间戳',
`project_id` bigint NOT NULL COMMENT '项目ID',
`group_id` bigint NOT NULL COMMENT '分组ID',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间戳',
INDEX `idx_project_id` (`project_id`) USING BTREE,
INDEX `idx_group_id` (`group_id`) USING BTREE
) ENGINE = InnoDB

View File

@ -11,13 +11,11 @@ Content-Type: application/json
"url": "https://st0.dancf.com/csc/49/fonts/0/20200809-105104-c105.svg",
"width": 490,
"height": 80,
"partial_video": "",
"partialVideo": "",
"video": "",
"hex": "",
"duration": 0
},
"price": null,
"items": [],
"content": {
"family": "Open Sans",
"alias": "Open Sans Bold",
@ -26,13 +24,13 @@ Content-Type: application/json
"woff": "https://gd-filems.dancf.com/gaoding/editor/20240116-211715-jaeea.woff",
"ttf": "https://gd-filems.dancf.com/gaoding/editor/20240116-211715-kiige.ttf",
"lang": "en",
"origin_file": {
"originFile": {
"size": 104120,
"url": "https://st0.dancf.com/csc/49/fonts/0/20200809-105059-cc06.ttf"
},
"woff_size": 56092,
"ttf_size": 92500,
"meta_data": {
"woffSize": 56092,
"ttfSize": 92500,
"metaData": {
"ascent": 2189,
"descent": -600,
"emSize": 2048,
@ -51,13 +49,11 @@ Content-Type: application/json
"xheight": 1118
}
},
"content_id": null,
"content_url": "https://gd-filems.dancf.com/xi19e5/xi19e5/0/32d51454-451e-4b80-a8b2-138fa5d185e750.json?auth_key=1763092800-10a7b6d1071b4787b7225660db3f71a1-0-8c6b2cbd6b9aae7a0943fd4190e16094",
"lang": "en",
"alias": "Open Sans Bold",
"authorization_id": 26,
"user_over_role": 0,
"sale_type": 0,
"authorizationId": 26,
"userOverRole": 0,
"saleType": 0,
"createTime": 1602230400,
"updateTime": 1602230400
}
@ -77,4 +73,4 @@ Content-Type: application/json
### 根据ID获取字体详情
GET http://localhost:19200/h5/font/1
Accept: application/json
Accept: application/json

View File

@ -83,12 +83,6 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
</dependency>
<!--mongodb 支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -2,7 +2,7 @@ package com.luban.api.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.luban.api.entity.Font;
import com.luban.api.mongo.entity.FontContent;
import com.luban.api.dto.FontDTO;
import com.luban.api.service.FontService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -24,8 +24,8 @@ public class FontController {
@Operation(summary = "批量上传字体")
@PostMapping("create")
public Boolean create(@RequestBody List<FontContent> fontContents) {
return fontService.batchSaveFonts(fontContents);
public Boolean create(@RequestBody List<FontDTO> fontDTOS) {
return fontService.batchSaveFonts(fontDTOS);
}
@Operation(summary = "分页查询字体")
@ -39,8 +39,8 @@ public class FontController {
@Operation(summary = "根据字体族名称列表查询字体")
@PostMapping("list")
public List<FontContent> list(@RequestBody List<String> fontFamilyNames) {
List<FontContent> fontContents = fontService.listFontsByFamilyNames(fontFamilyNames);
public List<String> list(@RequestBody List<String> names) {
List<String> fontContents = fontService.listFontsByNames(names);
if (fontContents == null) {
return new ArrayList<>();
}
@ -49,7 +49,7 @@ public class FontController {
@Operation(summary = "根据ID获取字体详情")
@GetMapping("/{id}")
public FontContent getFontById(@PathVariable Long id) {
public String getFontById(@PathVariable Long id) {
return fontService.getFontDetail(id);
}
}
}

View File

@ -90,9 +90,6 @@ public class H5GroupController {
@Operation(summary = "创建H5分组")
@PostMapping
public boolean createH5Group(@RequestBody H5Group h5Group) {
long currentTime = System.currentTimeMillis();
h5Group.setCreateTime(currentTime);
h5Group.setUpdateTime(currentTime);
return h5GroupService.save(h5Group);
}
@ -107,7 +104,6 @@ public class H5GroupController {
@PutMapping("/{id}")
public boolean updateH5Group(@PathVariable Long id, @RequestBody H5Group h5Group) {
h5Group.setId(id);
h5Group.setUpdateTime(System.currentTimeMillis());
return h5GroupService.updateById(h5Group);
}

View File

@ -3,7 +3,7 @@ package com.luban.api.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luban.api.entity.H5Project;
import com.luban.api.mongo.entity.H5ProjectContent;
import com.luban.api.dto.H5ProjectContentDTO;
import com.luban.api.service.H5ProjectService;
import com.luban.api.vo.H5ProjectDetailVO;
import io.swagger.v3.oas.annotations.Operation;
@ -72,16 +72,9 @@ public class H5ProjectController {
H5ProjectDetailVO detailVO = new H5ProjectDetailVO();
detailVO.setProject(h5Project);
// 获取项目内容
if (h5Project != null) {
H5ProjectContent content = h5ProjectService.getProjectContent(h5Project.getId());
detailVO.setContent(content);
}
// 获取项目关联的分组ID列表
List<Long> groupIds = h5ProjectService.getProjectGroupIds(id);
detailVO.setGroupIds(groupIds);
return detailVO;
}
@ -161,7 +154,7 @@ public class H5ProjectController {
public static class CreateH5ProjectRequest {
private String type;
private String title;
private H5ProjectContent content;
private H5ProjectContentDTO content;
private Long contentUpdatedAt;
private String description;
private String previewUrl;
@ -171,4 +164,4 @@ public class H5ProjectController {
private Integer status;
private List<Long> groupIds;
}
}
}

View File

@ -1,11 +1,10 @@
package com.luban.api.mongo.entity;
package com.luban.api.dto;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.luban.api.util.TimestampToLocalDateTimeDeserializer;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
import java.util.Map;
import java.time.LocalDateTime;
/**
* 字体内容实体类 (存储在MongoDB中)
@ -13,17 +12,14 @@ import java.util.Map;
* @author your-name
*/
@Data
@Document(collection = "h5_font_content")
public class FontContent {
public class FontDTO {
/**
* 主键ID与MySQL中Font的ID对应
* 主键ID
*/
@Id
private Long id;
/**
* 字体来源ID
* 字体来源
*/
private String sourceId;
@ -33,69 +29,36 @@ public class FontContent {
private String name;
/**
* 预览信息
* 预览JSON格式
*/
private Preview preview;
/**
* 价格
*/
private Object price;
/**
* 项目列表
*/
private List<Object> items;
/**
* 字体内容详情
*/
private Content content;
/**
* 内容ID
*/
private Object contentId;
/**
* 内容URL
*/
private String contentUrl;
/**
* 语言
* 字体语言类型zh-中文en-英文
*/
private String lang;
/**
* 别名
* 字体别名
*/
private String alias;
/**
* 授权ID
* 字体内容JSON格式
*/
private Long authorizationId;
/**
* 用户角色
*/
private Integer userOverRole;
/**
* 销售类型
*/
private Integer saleType;
private Content content;
/**
* 创建时间戳
*/
private Long createTime;
@JsonDeserialize(using = TimestampToLocalDateTimeDeserializer.class)
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
@JsonDeserialize(using = TimestampToLocalDateTimeDeserializer.class)
private LocalDateTime updateTime;
/**
* 预览信息类
@ -160,4 +123,4 @@ public class FontContent {
private Integer hheadLineGap;
private Integer xheight;
}
}
}

View File

@ -2,6 +2,8 @@ package com.luban.api.dto;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 表单数据传输对象
*
@ -34,14 +36,14 @@ public class H5FormSubmissionDTO {
* 表单数据JSON格式存储
*/
private String formData;
/**
* 创建时间戳
*/
private Long createTime;
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
}
private LocalDateTime updateTime;
}

View File

@ -1,14 +1,15 @@
package com.luban.api.mongo.entity;
package com.luban.api.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.luban.api.util.TimestampToLocalDateTimeDeserializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@ -18,13 +19,11 @@ import java.util.Map;
* @author your-name
*/
@Data
@Document(collection = "h5_project_content")
public class H5ProjectContent {
public class H5ProjectContentDTO {
/**
* 主键ID与MySQL中H5Project的ID对应
*/
@Id
private Long id;
/**
@ -50,12 +49,14 @@ public class H5ProjectContent {
/**
* 创建时间戳
*/
private Long createTime;
@JsonDeserialize(using = TimestampToLocalDateTimeDeserializer.class)
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
@JsonDeserialize(using = TimestampToLocalDateTimeDeserializer.class)
private LocalDateTime updateTime;
/**
* 全局配置类

View File

@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 字体实体类
@ -31,7 +32,7 @@ public class Font implements Serializable {
/**
* 字体来源
*/
private String source;
private String sourceId;
/**
* 字体名称
@ -39,9 +40,9 @@ public class Font implements Serializable {
private String name;
/**
* 字体族名称唯一标识
* 预览JSON格式
*/
private String fontFamily;
private String preview;
/**
* 字体语言类型zh-中文en-英文
@ -54,27 +55,17 @@ public class Font implements Serializable {
private String alias;
/**
* 授权ID
* 字体内容JSON格式
*/
private Long authorizationId;
/**
* 用户角色
*/
private Integer userOverRole;
/**
* 销售类型
*/
private Integer saleType;
private String content;
/**
* 创建时间戳
*/
private Long createTime;
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
}
private LocalDateTime updateTime;
}

View File

@ -8,6 +8,7 @@ import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 表单提交记录实体类
@ -53,16 +54,16 @@ public class FormSubmission implements Serializable {
*/
@TableField("form_data")
private String formData;
/**
* 创建时间戳
*/
@TableField("create_time")
private Long createTime;
private LocalDateTime createTime;
/**
* 更新时间戳
*/
@TableField("update_time")
private Long updateTime;
}
private LocalDateTime updateTime;
}

View File

@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* H5分组实体类
@ -56,11 +57,11 @@ public class H5Group implements Serializable {
/**
* 创建时间戳
*/
private Long createTime;
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
private LocalDateTime updateTime;
}

View File

@ -9,6 +9,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* H5项目实体类
@ -40,6 +41,10 @@ public class H5Project implements Serializable {
*/
private String title;
/**
* 项目内容JSON格式
*/
private String content;
/**
* 内容更新时间戳
@ -79,11 +84,11 @@ public class H5Project implements Serializable {
/**
* 创建时间戳
*/
private Long createTime;
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
private LocalDateTime updateTime;
}

View File

@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* H5项目与分组关联实体类
@ -41,6 +42,6 @@ public class H5ProjectGroup implements Serializable {
/**
* 创建时间戳
*/
private Long createTime;
private LocalDateTime createTime;
}

View File

@ -1,12 +0,0 @@
package com.luban.api.mongo.dao;
import com.luban.api.mongo.entity.FontContent;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* 字体内容 Repository
*
* @author your-name
*/
public interface FontContentRepository extends MongoRepository<FontContent, Long> {
}

View File

@ -1,12 +0,0 @@
package com.luban.api.mongo.dao;
import com.luban.api.mongo.entity.H5ProjectContent;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* H5项目内容 Repository
*
* @author your-name
*/
public interface H5ProjectContentRepository extends MongoRepository<H5ProjectContent, Long> {
}

View File

@ -3,7 +3,8 @@ package com.luban.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.luban.api.entity.Font;
import com.luban.api.mongo.entity.FontContent;
import com.luban.api.dto.FontDTO;
// Removed MongoDB import
import java.util.List;
@ -19,10 +20,10 @@ public interface FontService extends IService<Font> {
/**
* 批量上传字体
*
* @param fontContents 字体内容列表
* @param fontJsonList 字体内容列表JSON字符串
* @return 是否保存成功
*/
boolean batchSaveFonts(List<FontContent> fontContents);
boolean batchSaveFonts(List<FontDTO> fontJsonList);
/**
* 分页查询字体
@ -38,10 +39,10 @@ public interface FontService extends IService<Font> {
/**
* 根据字体族名称批量查询字体
*
* @param fontFamilyList 字体族名称列表
* @param fontNameList 字体族名称列表
* @return 字体列表
*/
List<FontContent> listFontsByFamilyNames(List<String> fontFamilyList);
List<String> listFontsByNames(List<String> fontNameList);
/**
* 根据ID获取字体详情
@ -49,5 +50,5 @@ public interface FontService extends IService<Font> {
* @param id 字体ID
* @return 字体详情
*/
FontContent getFontDetail(Long id);
}
String getFontDetail(Long id);
}

View File

@ -2,7 +2,7 @@ package com.luban.api.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.luban.api.entity.H5Project;
import com.luban.api.mongo.entity.H5ProjectContent;
import com.luban.api.dto.H5ProjectContentDTO;
import java.util.List;
@ -23,7 +23,7 @@ public interface H5ProjectService extends IService<H5Project> {
* @param groupIds 分组ID列表
* @return 是否保存成功
*/
boolean saveH5ProjectWithContent(H5Project h5Project, H5ProjectContent content, List<Long> groupIds);
boolean saveH5ProjectWithContent(H5Project h5Project, H5ProjectContentDTO content, List<Long> groupIds);
/**
* 更新H5项目及其内容
@ -33,7 +33,7 @@ public interface H5ProjectService extends IService<H5Project> {
* @param groupIds 分组ID列表
* @return 是否更新成功
*/
boolean updateH5ProjectWithContent(H5Project h5Project, H5ProjectContent content, List<Long> groupIds);
boolean updateH5ProjectWithContent(H5Project h5Project, H5ProjectContentDTO content, List<Long> groupIds);
/**
* 根据ID获取H5项目及其内容
@ -62,8 +62,8 @@ public interface H5ProjectService extends IService<H5Project> {
/**
* 获取项目内容
*
* @param contentId 内容ID
* @param projectId 项目ID
* @return 项目内容
*/
H5ProjectContent getProjectContent(Long contentId);
}
String getProjectContent(Long projectId);
}

View File

@ -1,21 +1,21 @@
package com.luban.api.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luban.api.dao.FontDao;
import com.luban.api.entity.Font;
import com.luban.api.mongo.dao.FontContentRepository;
import com.luban.api.mongo.entity.FontContent;
// Removed MongoDB imports
import com.luban.api.dto.FontDTO;
import com.luban.api.service.FontService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -29,43 +29,25 @@ import java.util.stream.Collectors;
@Service
public class FontServiceImpl extends ServiceImpl<FontDao, Font> implements FontService {
@Autowired
private FontContentRepository fontContentRepository;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean batchSaveFonts(List<FontContent> fontContents) {
if (CollectionUtils.isEmpty(fontContents)) {
public boolean batchSaveFonts(List<FontDTO> fontDTOS) {
if (CollectionUtils.isEmpty(fontDTOS)) {
return false;
}
// 获取当前时间戳
long currentTime = System.currentTimeMillis();
for (FontContent fontContent : fontContents) {
// 保存到MongoDB
fontContent.setCreateTime(currentTime);
fontContent.setUpdateTime(currentTime);
fontContentRepository.save(fontContent);
// 保存基本信息到MySQL
List<Font> fonts = fontDTOS.stream().map(dto -> {
Font font = new Font();
font.setId(fontContent.getId());
font.setSource(fontContent.getSourceId());
font.setName(fontContent.getName());
font.setFontFamily(fontContent.getContent().getFamily());
font.setLang(fontContent.getContent().getLang());
font.setAlias(fontContent.getContent().getAlias());
font.setAuthorizationId(fontContent.getAuthorizationId());
font.setUserOverRole(fontContent.getUserOverRole());
font.setSaleType(fontContent.getSaleType());
font.setCreateTime(currentTime);
font.setUpdateTime(currentTime);
BeanUtil.copyProperties(dto, font);
// 使用insertOrUpdate避免重复插入
this.saveOrUpdate(font);
}
return true;
if (dto.getPreview() != null) {
font.setPreview(JSONUtil.toJsonStr(dto.getPreview()));
}
if (dto.getContent() != null ) {
font.setContent(JSONUtil.toJsonStr(dto.getContent()));
}
return font;
}).collect(Collectors.toList());
return this.saveOrUpdateBatch(fonts);
}
@Override
@ -89,33 +71,29 @@ public class FontServiceImpl extends ServiceImpl<FontDao, Font> implements FontS
}
@Override
public List<FontContent> listFontsByFamilyNames(List<String> fontFamilyList) {
if (CollectionUtils.isEmpty(fontFamilyList)) {
public List<String> listFontsByNames(List<String> fontNameList) {
if (CollectionUtils.isEmpty(fontNameList)) {
return null;
}
// 先从MySQL查询ID列表
// 从MySQL查询字体内容
List<Font> fonts = this.list(new LambdaQueryWrapper<Font>()
.in(Font::getFontFamily, fontFamilyList));
.in(Font::getName, fontNameList)
.isNotNull(Font::getContent));
if (CollectionUtils.isEmpty(fonts)) {
return null;
}
// 根据ID列表从MongoDB查询详细信息
List<FontContent> fontContents = new ArrayList<>();
for (Font font : fonts) {
FontContent fontContent = fontContentRepository.findById(font.getId()).orElse(null);
if (fontContent != null) {
fontContents.add(fontContent);
}
}
return fontContents;
// 提取JSON内容
return fonts.stream()
.map(Font::getContent)
.collect(Collectors.toList());
}
@Override
public FontContent getFontDetail(Long id) {
return fontContentRepository.findById(id).orElse(null);
public String getFontDetail(Long id) {
Font font = this.getById(id);
return font != null ? font.getContent() : null;
}
}

View File

@ -33,13 +33,8 @@ public class FormServiceImpl extends ServiceImpl<FormSubmissionDao, FormSubmissi
@Override
@Transactional(rollbackFor = Exception.class)
public boolean submitFormData(H5FormSubmissionDTO dto) {
// 转换DTO为实体并保存到MySQL
FormSubmission entity = FormSubmissionConvert.toEntity(dto);
// 设置创建和更新时间
long currentTime = System.currentTimeMillis();
entity.setId(null);
entity.setCreateTime(currentTime);
entity.setUpdateTime(currentTime);
return this.save(entity);
}

View File

@ -1,12 +1,12 @@
package com.luban.api.service.impl;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luban.api.dao.H5ProjectDao;
import com.luban.api.dao.H5ProjectGroupDao;
import com.luban.api.entity.H5Project;
import com.luban.api.entity.H5ProjectGroup;
import com.luban.api.mongo.dao.H5ProjectContentRepository;
import com.luban.api.mongo.entity.H5ProjectContent;
import com.luban.api.dto.H5ProjectContentDTO;
import com.luban.api.service.H5ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -25,35 +25,21 @@ import java.util.stream.Collectors;
@Service
public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> implements H5ProjectService {
@Autowired
private H5ProjectContentRepository h5ProjectContentRepository;
@Autowired
private H5ProjectGroupDao h5ProjectGroupDao;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveH5ProjectWithContent(H5Project h5Project, H5ProjectContent content, List<Long> groupIds) {
public boolean saveH5ProjectWithContent(H5Project h5Project, H5ProjectContentDTO content, List<Long> groupIds) {
// 设置创建和更新时间戳
long currentTime = System.currentTimeMillis();
h5Project.setCreateTime(currentTime);
h5Project.setUpdateTime(currentTime);
h5Project.setContent(JSONUtil.toJsonStr(content));
// 保存H5Project基本信息到MySQL
// 保存H5Project基本信息到MySQL
boolean saved = this.save(h5Project);
if (saved && content != null) {
// 保存H5ProjectContent到MongoDB
content.setId(h5Project.getId());
content.setCreateTime(currentTime);
content.setUpdateTime(currentTime);
h5ProjectContentRepository.save(content);
}
// 保存项目与分组的关联关系
if (saved && groupIds != null && !groupIds.isEmpty()) {
saveProjectGroups(h5Project.getId(), groupIds, currentTime);
saveProjectGroups(h5Project.getId(), groupIds);
}
return saved;
@ -61,29 +47,20 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateH5ProjectWithContent(H5Project h5Project, H5ProjectContent content, List<Long> groupIds) {
public boolean updateH5ProjectWithContent(H5Project h5Project, H5ProjectContentDTO content, List<Long> groupIds) {
// 设置更新时间戳
long currentTime = System.currentTimeMillis();
h5Project.setUpdateTime(currentTime);
h5Project.setContent(JSONUtil.toJsonStr(content));
// 更新H5Project基本信息到MySQL
boolean updated = this.updateById(h5Project);
if (updated && content != null) {
// 更新或创建H5ProjectContent到MongoDB
content.setId(h5Project.getId());
content.setUpdateTime(currentTime);
h5ProjectContentRepository.save(content);
}
// 更新项目与分组的关联关系
if (updated && groupIds != null) {
h5ProjectGroupDao.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<H5ProjectGroup>()
.eq(H5ProjectGroup::getProjectId, h5Project.getId()));
if (!groupIds.isEmpty()) {
saveProjectGroups(h5Project.getId(), groupIds, currentTime);
saveProjectGroups(h5Project.getId(), groupIds);
}
}
@ -92,22 +69,14 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
@Override
public H5Project getH5ProjectWithContent(Long id) {
// 获取MySQL中的H5Project基本信息
H5Project h5Project = this.getById(id);
if (h5Project != null) {
// 获取MongoDB中的内容
H5ProjectContent h5ProjectContent = h5ProjectContentRepository.findById(id).orElse(null);
// 可以在这里将content设置到h5Project的某个属性中如果需要的话
}
return h5Project;
return this.getById(id);
}
@Override
public H5ProjectContent getProjectContent(Long contentId) {
if (contentId != null) {
return h5ProjectContentRepository.findById(contentId).orElse(null);
public String getProjectContent(Long projectId) {
if (projectId != null) {
H5Project project = this.getById(projectId);
return project != null ? project.getContent() : null;
}
return null;
}
@ -117,14 +86,9 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
public boolean removeH5ProjectWithContent(Long id) {
H5Project h5Project = this.getById(id);
if (h5Project != null) {
// 先删除MongoDB中的内容
h5ProjectContentRepository.deleteById(id);
// 删除项目与分组的关联关系
h5ProjectGroupDao.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<H5ProjectGroup>()
.eq(H5ProjectGroup::getProjectId, id));
// 再删除MySQL中的记录
return this.removeById(id);
}
return false;
@ -135,14 +99,12 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
*
* @param projectId 项目ID
* @param groupIds 分组ID列表
* @param currentTime 当前时间戳
*/
private void saveProjectGroups(Long projectId, List<Long> groupIds, long currentTime) {
private void saveProjectGroups(Long projectId, List<Long> groupIds) {
for (Long groupId : groupIds) {
H5ProjectGroup projectGroup = new H5ProjectGroup();
projectGroup.setProjectId(projectId);
projectGroup.setGroupId(groupId);
projectGroup.setCreateTime(currentTime);
h5ProjectGroupDao.insert(projectGroup);
}
}
@ -155,4 +117,4 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
.map(H5ProjectGroup::getGroupId)
.collect(Collectors.toList());
}
}
}

View File

@ -0,0 +1,26 @@
package com.luban.api.util;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
public class TimestampToLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext deserializationContext) throws IOException, JacksonException {
long timestamp = p.getValueAsLong();
// 处理秒级时间戳
if (timestamp < 10000000000L) {
return LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneId.systemDefault());
} else {
// 处理毫秒级时间戳
return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
}
}
}

View File

@ -1,7 +1,6 @@
package com.luban.api.vo;
import com.luban.api.entity.H5Project;
import com.luban.api.mongo.entity.H5ProjectContent;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -24,15 +23,9 @@ public class H5ProjectDetailVO {
@Schema(title = "项目基本信息")
private H5Project project;
/**
* 项目内容
*/
@Schema(title = "项目内容")
private H5ProjectContent content;
/**
* 项目关联的分组ID列表
*/
@Schema(title = "项目关联的分组ID列表")
private List<Long> groupIds;
}
}

View File

@ -5,6 +5,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
/**
* H5项目视图对象
*
@ -84,11 +86,11 @@ public class H5ProjectVO {
/**
* 创建时间戳
*/
private Long createTime;
private LocalDateTime createTime;
/**
* 更新时间戳
*/
private Long updateTime;
private LocalDateTime updateTime;
}
}

View File

@ -73,10 +73,6 @@ spring:
max-idle: 10
# 连接池中的最小空闲连接
min-idle: 0
mongodb:
database: h5
host: 127.0.0.1
port: 27017
springdoc:
api-docs: