mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 09:35:29 +08:00
h5 动态表单,折腾中
This commit is contained in:
parent
723f2fd938
commit
6f08381705
@ -1,26 +1,48 @@
|
|||||||
### 提交表单数据
|
### 提交表单数据
|
||||||
POST {{host}}/h5/form/submit
|
POST http://localhost:8080/form/submit
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"projectId": 1,
|
"projectId": 1,
|
||||||
|
"formId": 461709,
|
||||||
|
"templateFormId": 450055,
|
||||||
"formData": {
|
"formData": {
|
||||||
"name": "张三",
|
"19fef684-b6ef-4bfb-8d68-603c99444ac5": "文本内容",
|
||||||
"age": 18,
|
"6cbf9138-a20d-428c-b635-291246da3926": "13255556645",
|
||||||
"email": "zhangsan@example.com"
|
"14154ccc-c2b3-4d27-8eb2-e3e422af294f": "1713322582323@qq.com"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
### 根据项目ID分页查询表单提交记录(带过滤条件)
|
### save表单版本+1
|
||||||
POST {{host}}/h5/form/page/project/1?pageNum=1&pageSize=10
|
POST http://localhost:8080/form/saveForm
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "张三1"
|
"projectId": 1,
|
||||||
|
"formId": 461709,
|
||||||
|
"templateFormId": 450055,
|
||||||
|
"formData": {
|
||||||
|
"19fef684-b6ef-4bfb-8d68-603c99444ac5": "测试版本+1",
|
||||||
|
"6cbf9138-a20d-428c-b635-291246da3926": "12345678901"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
### 根据项目ID分页查询表单提交记录
|
||||||
|
POST http://localhost:8080/form/page/project/1?pageNum=1&pageSize=10
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"field1": "value1"
|
||||||
}
|
}
|
||||||
|
|
||||||
### 根据提交记录ID获取表单数据详情
|
### 根据提交记录ID获取表单数据详情
|
||||||
GET {{host}}/h5/form/detail/1
|
GET http://localhost:8080/form/detail/1
|
||||||
|
|
||||||
### 根据项目ID获取所有表单数据
|
### 根据项目ID获取所有表单数据
|
||||||
GET {{host}}/h5/form/list/project/1
|
GET http://localhost:8080/form/list/project/1
|
||||||
|
|
||||||
|
### 获取所有表单信息
|
||||||
|
GET http://localhost:8080/form/editor/forms?templateId=450055&hasDeleted=true
|
||||||
|
|
||||||
|
### 获取所有表单相关字段
|
||||||
|
GET http://localhost:8080/form/editor/templateForms?templateFormId=450055
|
||||||
@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
* @author WeiHongBin
|
* @author WeiHongBin
|
||||||
*/
|
*/
|
||||||
@EnableDubbo
|
@EnableDubbo
|
||||||
@SpringBootApplication
|
@SpringBootApplication(scanBasePackages = {"com.luban","com.dromara.md.form"})
|
||||||
public class MallH5Application {
|
public class MallH5Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@ -1,126 +0,0 @@
|
|||||||
package com.luban.api.controller;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.luban.api.dto.H5FormSubmissionDTO;
|
|
||||||
import com.luban.api.entity.FormSubmission;
|
|
||||||
import com.luban.api.service.FormService;
|
|
||||||
import com.luban.api.util.JSON;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.dromara.common.core.utils.ServletUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 表单控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author your-name
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/form")
|
|
||||||
@Tag(name = "表单管理", description = "表单提交与查询")
|
|
||||||
@Slf4j
|
|
||||||
public class FormController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FormService formService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JSON json;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* save表单版本+1
|
|
||||||
*/
|
|
||||||
@Operation(summary = "save表单版本+1")
|
|
||||||
@PostMapping("/saveForm")
|
|
||||||
public Boolean saveForm(@RequestBody SubmitFormRequest request, HttpServletRequest httpRequest) {
|
|
||||||
//TODO待完成
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提交表单数据
|
|
||||||
*
|
|
||||||
* @param request 请求体包含表单数据
|
|
||||||
* @return 是否提交成功
|
|
||||||
*/
|
|
||||||
@Operation(summary = "提交表单数据")
|
|
||||||
@PostMapping("/submit")
|
|
||||||
public Boolean submitForm(@RequestBody SubmitFormRequest request, HttpServletRequest httpRequest) {
|
|
||||||
// 获取客户端IP地址
|
|
||||||
String ipAddress = ServletUtils.getClientIP();
|
|
||||||
// 获取User-Agent
|
|
||||||
String userAgent = httpRequest.getHeader("User-Agent");
|
|
||||||
|
|
||||||
H5FormSubmissionDTO dto = new H5FormSubmissionDTO();
|
|
||||||
dto.setProjectId(request.getProjectId());
|
|
||||||
//TODO TODO待完成 formId
|
|
||||||
dto.setFormId(null);
|
|
||||||
dto.setTempletFormId(null);
|
|
||||||
dto.setFormData(request.getFormData());
|
|
||||||
dto.setIpAddress(ipAddress);
|
|
||||||
dto.setUserAgent(userAgent);
|
|
||||||
return formService.submitFormData(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据项目ID分页查询表单提交记录
|
|
||||||
*
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param fieldFilters 字段过滤条件
|
|
||||||
* @param pageNum 页码
|
|
||||||
* @param pageSize 每页大小
|
|
||||||
* @return 表单提交记录分页数据
|
|
||||||
*/
|
|
||||||
@Operation(summary = "根据项目ID分页查询表单提交记录")
|
|
||||||
@PostMapping("/page/project/{projectId}")
|
|
||||||
public IPage<FormSubmission> pageByProjectId(
|
|
||||||
@PathVariable Long projectId,
|
|
||||||
@RequestBody(required = false) Map<String, Object> fieldFilters,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
return formService.pageFormSubmissionsByProjectId(projectId, fieldFilters, pageNum, pageSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据提交记录ID获取表单数据详情
|
|
||||||
*
|
|
||||||
* @param submissionId 提交记录ID
|
|
||||||
* @return 表单数据详情
|
|
||||||
*/
|
|
||||||
@Operation(summary = "根据提交记录ID获取表单数据详情")
|
|
||||||
@GetMapping("/detail/{submissionId}")
|
|
||||||
public H5FormSubmissionDTO getFormDataDetail(@PathVariable Long submissionId) {
|
|
||||||
return formService.getFormDataDetail(submissionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据项目ID获取所有表单数据
|
|
||||||
*
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @return 表单数据列表
|
|
||||||
*/
|
|
||||||
@Operation(summary = "根据项目ID获取所有表单数据")
|
|
||||||
@GetMapping("/list/project/{projectId}")
|
|
||||||
public List<H5FormSubmissionDTO> listByProjectId(@PathVariable Long projectId) {
|
|
||||||
return formService.listFormDataByProjectId(projectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class SubmitFormRequest {
|
|
||||||
private Long projectId;
|
|
||||||
private Map<String, Object> formData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,256 @@
|
|||||||
|
package com.luban.api.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.luban.api.dto.H5FormSubmissionDTO;
|
||||||
|
import com.luban.api.service.H5FormService;
|
||||||
|
import com.luban.api.util.JSON;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.core.utils.ServletUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 表单控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author your-name
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/form")
|
||||||
|
@Tag(name = "表单管理", description = "表单提交与查询")
|
||||||
|
@Slf4j
|
||||||
|
public class H5FormController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private H5FormService formService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JSON json;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save表单版本+1
|
||||||
|
*/
|
||||||
|
@Operation(summary = "save表单版本+1")
|
||||||
|
@PostMapping("/saveForm")
|
||||||
|
public Boolean saveForm(@RequestBody SubmitFormRequest request, HttpServletRequest httpRequest) {
|
||||||
|
// 获取客户端IP地址
|
||||||
|
String ipAddress = ServletUtils.getClientIP();
|
||||||
|
// 获取User-Agent
|
||||||
|
String userAgent = httpRequest.getHeader("User-Agent");
|
||||||
|
|
||||||
|
H5FormSubmissionDTO dto = new H5FormSubmissionDTO();
|
||||||
|
// 从请求中获取formId和templetFormId
|
||||||
|
dto.setFormId(request.getFormId());
|
||||||
|
dto.setTempletFormId(request.getTemplateFormId());
|
||||||
|
|
||||||
|
// 如果formData为空,初始化为Map
|
||||||
|
Map<String, Object> formData = request.getFormData();
|
||||||
|
if (formData == null) {
|
||||||
|
formData = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加版本信息到formData
|
||||||
|
// 版本号可以基于当前时间戳或自增计数器
|
||||||
|
long version = System.currentTimeMillis() / 1000; // 使用时间戳作为版本号
|
||||||
|
formData.put("version", version);
|
||||||
|
formData.put("saveTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
|
||||||
|
dto.setFormData(formData);
|
||||||
|
dto.setIpAddress(ipAddress);
|
||||||
|
dto.setUserAgent(userAgent);
|
||||||
|
|
||||||
|
return formService.submitFormData(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单数据
|
||||||
|
*
|
||||||
|
* @param request 请求体包含表单数据
|
||||||
|
* @return 是否提交成功
|
||||||
|
*/
|
||||||
|
@Operation(summary = "提交表单数据")
|
||||||
|
@PostMapping("/submit")
|
||||||
|
public Boolean submitForm(@RequestBody SubmitFormRequest request, HttpServletRequest httpRequest) {
|
||||||
|
// 获取客户端IP地址
|
||||||
|
String ipAddress = ServletUtils.getClientIP();
|
||||||
|
// 获取User-Agent
|
||||||
|
String userAgent = httpRequest.getHeader("User-Agent");
|
||||||
|
|
||||||
|
H5FormSubmissionDTO dto = new H5FormSubmissionDTO();
|
||||||
|
dto.setFormId(request.getFormId());
|
||||||
|
dto.setTempletFormId(request.getTemplateFormId());
|
||||||
|
dto.setFormData(request.getFormData());
|
||||||
|
dto.setIpAddress(ipAddress);
|
||||||
|
dto.setUserAgent(userAgent);
|
||||||
|
var 提交参数例子 = """
|
||||||
|
{
|
||||||
|
"templet_form_id": 450055,
|
||||||
|
"form_id": "461709",
|
||||||
|
"form_data": {
|
||||||
|
"19fef684-b6ef-4bfb-8d68-603c99444ac5": "文本内容",
|
||||||
|
"6cbf9138-a20d-428c-b635-291246da3926": "13255556645",
|
||||||
|
"14154ccc-c2b3-4d27-8eb2-e3e422af294f": "1713322582323@qq.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
""";
|
||||||
|
return formService.submitFormData(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据templateFormId获取所有表单数据
|
||||||
|
*
|
||||||
|
* @param templateFormId templateFormId
|
||||||
|
* @return 表单数据列表
|
||||||
|
*/
|
||||||
|
@Operation(summary = "分页查询提交数据")
|
||||||
|
@GetMapping("/list/detail/page")
|
||||||
|
public IPage<H5FormSubmissionDTO> listDetailPage(@RequestParam Long templateFormId,
|
||||||
|
@RequestParam String orderBy,
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||||
|
|
||||||
|
String getEditorTemplateFormResp返回结构 = """
|
||||||
|
{
|
||||||
|
"page": "1",
|
||||||
|
"page_size": "20",
|
||||||
|
"total": 2,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 26964584,
|
||||||
|
"form_id": 461709,
|
||||||
|
"data": "{\\"19fef684-b6ef-4bfb-8d68-603c99444ac5\\":\\"1\\",\\"14154ccc-c2b3-4d27-8eb2-e3e422af294f\\":\\"1212@134.com\\",\\"b8256478-4f71-4484-a859-f71628c6107a\\":\\"5656456456\\"}",
|
||||||
|
"ip": "27.17.43.218, 110.75.191.49",
|
||||||
|
"deleted_at": null,
|
||||||
|
"created_at": "2025-11-14 17:25:52",
|
||||||
|
"updated_at": "2025-11-14 17:25:52",
|
||||||
|
"platform_user_id": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 26963271,
|
||||||
|
"form_id": 461709,
|
||||||
|
"data": "{\\"19fef684-b6ef-4bfb-8d68-603c99444ac5\\":\\"文本内容\\",\\"6cbf9138-a20d-428c-b635-291246da3926\\":\\"13255556645\\",\\"14154ccc-c2b3-4d27-8eb2-e3e422af294f\\":\\"1713322582323@qq.com\\"}",
|
||||||
|
"ip": "27.17.43.218, 110.75.191.24",
|
||||||
|
"deleted_at": null,
|
||||||
|
"created_at": "2025-11-14 14:17:44",
|
||||||
|
"updated_at": "2025-11-14 14:17:44",
|
||||||
|
"platform_user_id": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
return formService.listDetailPage(templateFormId,
|
||||||
|
orderBy,
|
||||||
|
pageNum,
|
||||||
|
pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取所有表单")
|
||||||
|
@GetMapping("editor/forms")
|
||||||
|
public List<H5FormSubmissionDTO> editorForms(@RequestParam Long templateId,
|
||||||
|
@RequestParam(required = false, defaultValue = "true") Boolean hasDeleted) {
|
||||||
|
return formService.getEditorForms(templateId, hasDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getEditorForms返回结构 = """
|
||||||
|
{
|
||||||
|
"current_page": 1,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 450055,
|
||||||
|
"name": "表单1",
|
||||||
|
"templet_id": 7512497,
|
||||||
|
"content_form_id": "c8a6b97e-f5ab-48c8-8e29-ce1b139c3488",
|
||||||
|
"form_id": "461709",
|
||||||
|
"deleted_at": null,
|
||||||
|
"created_at": "2025-11-14 14:17:10",
|
||||||
|
"updated_at": "2025-11-14 14:17:10"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"first_page_url": "\\/?page=1",
|
||||||
|
"from": 1,
|
||||||
|
"next_page_url": null,
|
||||||
|
"path": "\\/",
|
||||||
|
"per_page": 1000,
|
||||||
|
"prev_page_url": null,
|
||||||
|
"to": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "获取所有表单相关字段")
|
||||||
|
@GetMapping("editor/templateForms")
|
||||||
|
public List<H5FormSubmissionDTO> editorTemplateForms(@RequestParam Long templateFormId) {
|
||||||
|
return formService.getEditorTemplateForms(templateFormId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String editorTemplateForms返回结构 = """
|
||||||
|
{
|
||||||
|
"id": 450055,
|
||||||
|
"name": "表单1",
|
||||||
|
"templet_id": 7512497,
|
||||||
|
"content_form_id": "c8a6b97e-f5ab-48c8-8e29-ce1b139c3488",
|
||||||
|
"form_id": "461709",
|
||||||
|
"deleted_at": null,
|
||||||
|
"created_at": "2025-11-14 14:17:10",
|
||||||
|
"updated_at": "2025-11-14 17:25:18",
|
||||||
|
"auth": {
|
||||||
|
"wechat": 0,
|
||||||
|
"max_count": "",
|
||||||
|
"wechat_limit": {
|
||||||
|
"type": "wechat",
|
||||||
|
"count": "",
|
||||||
|
"value": false,
|
||||||
|
"label": "微信限制",
|
||||||
|
"limit": "max"
|
||||||
|
},
|
||||||
|
"ip_limit": {
|
||||||
|
"type": "ip",
|
||||||
|
"count": "",
|
||||||
|
"value": false,
|
||||||
|
"label": "IP限制",
|
||||||
|
"limit": "max"
|
||||||
|
},
|
||||||
|
"equipment_limit": {
|
||||||
|
"type": "equipment",
|
||||||
|
"count": "",
|
||||||
|
"value": false,
|
||||||
|
"label": "设备限制",
|
||||||
|
"limit": "max"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extends": {
|
||||||
|
"questions": []
|
||||||
|
},
|
||||||
|
"fields": {
|
||||||
|
"19fef684-b6ef-4bfb-8d68-603c99444ac5": "您的姓名修改",
|
||||||
|
"14154ccc-c2b3-4d27-8eb2-e3e422af294f": "您的电子邮箱地址",
|
||||||
|
"b8256478-4f71-4484-a859-f71628c6107a": "测试新加文本"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class SubmitFormRequest {
|
||||||
|
private Long templateFormId;
|
||||||
|
private Long formId;
|
||||||
|
private Map<String, Object> formData;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.luban.api.dto.H5ProjectContentDTO;
|
import com.luban.api.dto.H5ProjectContentDTO;
|
||||||
import com.luban.api.dto.query.H5ProjectQueryDTO;
|
import com.luban.api.dto.query.H5ProjectQueryDTO;
|
||||||
import com.luban.api.entity.H5Project;
|
import com.luban.api.entity.H5Project;
|
||||||
|
import com.luban.api.service.H5FormService;
|
||||||
import com.luban.api.service.H5ProjectService;
|
import com.luban.api.service.H5ProjectService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -31,6 +32,8 @@ public class H5ProjectController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private H5ProjectService h5ProjectService;
|
private H5ProjectService h5ProjectService;
|
||||||
|
@Autowired
|
||||||
|
private H5FormService h5FormService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有H5项目
|
* 查询所有H5项目
|
||||||
@ -123,6 +126,38 @@ public class H5ProjectController {
|
|||||||
return h5ProjectService.updateH5ProjectWithContent(h5Project, request.getContent(), request.getGroupIds());
|
return h5ProjectService.updateH5ProjectWithContent(h5Project, request.getContent(), request.getGroupIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新H5项目
|
||||||
|
*
|
||||||
|
* @param id H5项目ID
|
||||||
|
* @param request 包含H5项目信息和内容的请求
|
||||||
|
* @return 是否更新成功
|
||||||
|
*/
|
||||||
|
@Operation(summary = "更新状态")
|
||||||
|
@PutMapping("updateStatus")
|
||||||
|
public Boolean 更新状态H5Project(@RequestParam Long id, @RequestBody CreateH5ProjectRequest request) {
|
||||||
|
H5Project h5Project = h5ProjectService.getById(id);
|
||||||
|
if (h5Project == null) {
|
||||||
|
throw new RuntimeException("项目不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
h5Project.setType(request.getType());
|
||||||
|
h5Project.setTitle(request.getTitle());
|
||||||
|
h5Project.setContentUpdatedAt(request.getContentUpdatedAt());
|
||||||
|
h5Project.setDescription(request.getDescription());
|
||||||
|
h5Project.setPreviewUrl(request.getPreviewUrl());
|
||||||
|
h5Project.setPreviewUrlWatermark(request.getPreviewUrlWatermark());
|
||||||
|
h5Project.setPreviewWidth(request.getPreviewWidth());
|
||||||
|
h5Project.setPreviewHeight(request.getPreviewHeight());
|
||||||
|
h5Project.setStatus(request.getStatus());//TODO 改成发布状态
|
||||||
|
|
||||||
|
//获取表单并保存
|
||||||
|
h5FormService.saveForm(request.getContent());
|
||||||
|
|
||||||
|
return h5ProjectService.updateH5ProjectWithContent(h5Project, request.getContent(), request.getGroupIds());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除H5项目
|
* 删除H5项目
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2,15 +2,17 @@ package com.luban.api.controller;
|
|||||||
|
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.dromara.md.form.api.constant.BaseConstant;
|
||||||
|
import com.dromara.md.form.utils.TenantHelper;
|
||||||
import com.luban.api.convert.WorkConvert;
|
import com.luban.api.convert.WorkConvert;
|
||||||
import com.luban.api.dto.WorkCreateDTO;
|
import com.luban.api.dto.WorkCreateDTO;
|
||||||
import com.luban.api.dto.WorkQueryDTO;
|
import com.luban.api.dto.WorkQueryDTO;
|
||||||
import com.luban.api.dto.WorkUpdateDTO;
|
import com.luban.api.dto.WorkUpdateDTO;
|
||||||
|
import com.luban.api.dto.query.H5ProjectQueryDTO;
|
||||||
|
import com.luban.api.entity.H5Project;
|
||||||
import com.luban.api.entity.Work;
|
import com.luban.api.entity.Work;
|
||||||
|
import com.luban.api.service.H5ProjectService;
|
||||||
import com.luban.api.service.WorkService;
|
import com.luban.api.service.WorkService;
|
||||||
import com.luban.api.vo.WorkVO;
|
import com.luban.api.vo.WorkVO;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@ -18,6 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -42,12 +45,11 @@ import java.util.stream.Collectors;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class WorkController {
|
public class WorkController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private H5ProjectService h5ProjectService;
|
||||||
|
|
||||||
private final WorkService workService;
|
@Autowired
|
||||||
|
private WorkService workService;
|
||||||
public WorkController(WorkService workService) {
|
|
||||||
this.workService = workService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "根据workId查询")
|
@Operation(summary = "根据workId查询")
|
||||||
@ -62,25 +64,14 @@ public class WorkController {
|
|||||||
return WorkConvert.toVO(workService.getById(id));
|
return WorkConvert.toVO(workService.getById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "查询所有work")
|
|
||||||
@GetMapping
|
|
||||||
public List<WorkVO> listAllWorks(@Valid WorkQueryDTO dto) {
|
|
||||||
WorkVO vo = new WorkVO();
|
|
||||||
vo.setTemplate(Boolean.parseBoolean(dto.getIs_template()));
|
|
||||||
BeanUtils.copyProperties(dto, vo);
|
|
||||||
return workService.list(new QueryWrapper<>(WorkConvert.toEntity(vo))).stream().map(WorkConvert::toVO).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "分页查询works")
|
@Operation(summary = "分页查询works")
|
||||||
@GetMapping("/pageable")
|
@GetMapping("/page")
|
||||||
public IPage<WorkVO> listWorks(@Valid WorkQueryDTO dto) {
|
public IPage<H5Project> listWorks(@Valid H5ProjectQueryDTO dto) {
|
||||||
WorkVO vo = new WorkVO();
|
if (dto.getIsTemplate()) {
|
||||||
vo.setTemplate(Boolean.parseBoolean(dto.getIs_template()));
|
return TenantHelper.dynamic(BaseConstant.TplTenantId, () -> h5ProjectService.pageH5Projects(dto));
|
||||||
BeanUtils.copyProperties(dto, vo);
|
} else {
|
||||||
IPage<Work> page = workService.page(new Page<>(dto.getCurrent(), dto.getSize()), new LambdaQueryWrapper<>(WorkConvert.toEntity(vo)).orderByDesc(Work::getCreateTime));
|
return h5ProjectService.pageH5Projects(dto);
|
||||||
List<WorkVO> voList = page.getRecords().stream().map(WorkConvert::toVO).collect(Collectors.toList());
|
}
|
||||||
return new Page<WorkVO>(page.getCurrent(), page.getSize(), page.getTotal()).setPages(page.getPages()).setRecords(voList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "创建work")
|
@Operation(summary = "创建work")
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.luban.api.convert;
|
package com.luban.api.convert;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.luban.api.dto.H5FormSubmissionDTO;
|
import com.luban.api.dto.H5FormSubmissionDTO;
|
||||||
import com.luban.api.entity.FormSubmission;
|
import com.luban.api.entity.FormSubmission;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
@ -55,6 +57,17 @@ public class FormSubmissionConvert {
|
|||||||
return dtoList;
|
return dtoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IPage<H5FormSubmissionDTO> toPageDTO(IPage<FormSubmission> page) {
|
||||||
|
IPage<H5FormSubmissionDTO> newPage = new Page<>();
|
||||||
|
newPage.setPages(page.getPages());
|
||||||
|
newPage.setRecords(toDTO(page.getRecords()));
|
||||||
|
newPage.setTotal(page.getTotal());
|
||||||
|
newPage.setSize(page.getSize());
|
||||||
|
newPage.setCurrent(page.getCurrent());
|
||||||
|
return newPage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将H5FormSubmissionDTO转换为FormSubmission实体
|
* 将H5FormSubmissionDTO转换为FormSubmission实体
|
||||||
*
|
*
|
||||||
@ -73,4 +86,4 @@ public class FormSubmissionConvert {
|
|||||||
}
|
}
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class H5FormSubmissionDTO {
|
|||||||
* 表单ID
|
* 表单ID
|
||||||
*/
|
*/
|
||||||
@Schema(title = "表单ID")
|
@Schema(title = "表单ID")
|
||||||
private String formId;
|
private Long formId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表单数据
|
* 表单数据
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class PageDtoBase {
|
|||||||
* 页码
|
* 页码
|
||||||
*/
|
*/
|
||||||
@Schema(title = "页码")
|
@Schema(title = "页码")
|
||||||
protected Integer current = 1;
|
protected Integer page = 1;
|
||||||
|
|
||||||
|
|
||||||
public void setSize(Integer size) {
|
public void setSize(Integer size) {
|
||||||
@ -31,9 +31,9 @@ public class PageDtoBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrent(Integer current) {
|
public void setPage(Integer page) {
|
||||||
if (current != null) {
|
if (page != null) {
|
||||||
this.current = current;
|
this.page = page;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,6 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author WeiHongBin
|
* @author WeiHongBin
|
||||||
*/
|
*/
|
||||||
@ -19,17 +16,7 @@ public class WorkQueryDTO extends PageDtoBase {
|
|||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private String description;
|
private Boolean isPublish;
|
||||||
|
|
||||||
private String coverImageUrl;
|
private Boolean isTemplate;
|
||||||
|
|
||||||
private List<Object> pages;
|
|
||||||
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
private String is_publish;
|
|
||||||
|
|
||||||
private String is_template;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,15 +17,16 @@ import java.util.List;
|
|||||||
@Schema(title = "H5项目查询对象")
|
@Schema(title = "H5项目查询对象")
|
||||||
public class H5ProjectQueryDTO extends PageDtoBase {
|
public class H5ProjectQueryDTO extends PageDtoBase {
|
||||||
|
|
||||||
/**
|
|
||||||
* 分组ID列表
|
|
||||||
*/
|
|
||||||
@Schema(description = "分组ID列表")
|
@Schema(description = "分组ID列表")
|
||||||
private List<Long> groupIds;
|
private List<Long> groupIds;
|
||||||
|
|
||||||
/**
|
|
||||||
* 项目标题
|
|
||||||
*/
|
|
||||||
@Schema(description = "项目标题")
|
@Schema(description = "项目标题")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
@Schema(description = "是否发布")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "是否模板")
|
||||||
|
private Boolean isTemplate = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ public class H5Project implements Serializable {
|
|||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览图URL
|
* 预览图URL TODO 后续合并成一个属性
|
||||||
*/
|
*/
|
||||||
private String previewUrl;
|
private String previewUrl;
|
||||||
|
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
package com.luban.api.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.luban.api.dto.H5FormSubmissionDTO;
|
|
||||||
import com.luban.api.entity.FormSubmission;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 表单服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author lizhw
|
|
||||||
*/
|
|
||||||
public interface FormService extends IService<FormSubmission> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提交表单数据
|
|
||||||
*
|
|
||||||
* @param dto 表单数据传输对象
|
|
||||||
* @return 是否提交成功
|
|
||||||
*/
|
|
||||||
boolean submitFormData(H5FormSubmissionDTO dto);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据项目ID分页查询表单提交记录,支持字段过滤
|
|
||||||
*
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param fieldFilters 字段过滤条件
|
|
||||||
* @param pageNum 页码
|
|
||||||
* @param pageSize 每页大小
|
|
||||||
* @return 表单提交记录分页数据
|
|
||||||
*/
|
|
||||||
IPage<FormSubmission> pageFormSubmissionsByProjectId(Long projectId, Map<String, Object> fieldFilters, Integer pageNum, Integer pageSize);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据提交记录ID获取表单数据详情
|
|
||||||
*
|
|
||||||
* @param submissionId 提交记录ID
|
|
||||||
* @return 表单数据详情
|
|
||||||
*/
|
|
||||||
H5FormSubmissionDTO getFormDataDetail(Long submissionId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据项目ID获取所有表单数据
|
|
||||||
*
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @return 表单数据列表
|
|
||||||
*/
|
|
||||||
List<H5FormSubmissionDTO> listFormDataByProjectId(Long projectId);
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package com.luban.api.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.luban.api.dto.H5FormSubmissionDTO;
|
||||||
|
import com.luban.api.dto.H5ProjectContentDTO;
|
||||||
|
import com.luban.api.entity.FormSubmission;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 表单服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author lizhw
|
||||||
|
*/
|
||||||
|
public interface H5FormService extends IService<FormSubmission> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单数据
|
||||||
|
*
|
||||||
|
* @param dto 表单数据传输对象
|
||||||
|
* @return 是否提交成功
|
||||||
|
*/
|
||||||
|
boolean submitFormData(H5FormSubmissionDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有表单信息
|
||||||
|
*
|
||||||
|
* @param templateId 模板ID
|
||||||
|
* @param hasDeleted 是否包含已删除的表单
|
||||||
|
* @return 表单信息列表
|
||||||
|
*/
|
||||||
|
List<H5FormSubmissionDTO> getEditorForms(Long templateId, Boolean hasDeleted);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有表单相关字段
|
||||||
|
*
|
||||||
|
* @param templateFormId 模板表单ID
|
||||||
|
* @return 表单相关字段列表
|
||||||
|
*/
|
||||||
|
List<H5FormSubmissionDTO> getEditorTemplateForms(Long templateFormId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询提交数据
|
||||||
|
*
|
||||||
|
* @param templateFormId 模板表单ID
|
||||||
|
* @param orderBy 排序字段
|
||||||
|
* @param pageNum 页码
|
||||||
|
* @param pageSize 每页大小
|
||||||
|
* @return 提交数据列表
|
||||||
|
*/
|
||||||
|
IPage<H5FormSubmissionDTO> listDetailPage(Long templateFormId, String orderBy, Integer pageNum, Integer pageSize);
|
||||||
|
|
||||||
|
long saveForm(H5ProjectContentDTO content);
|
||||||
|
}
|
||||||
@ -1,7 +1,10 @@
|
|||||||
package com.luban.api.service;
|
package com.luban.api.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.luban.api.dto.WorkQueryDTO;
|
||||||
import com.luban.api.entity.Work;
|
import com.luban.api.entity.Work;
|
||||||
|
import com.luban.api.vo.WorkVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -13,4 +16,12 @@ import com.luban.api.entity.Work;
|
|||||||
*/
|
*/
|
||||||
public interface WorkService extends IService<Work> {
|
public interface WorkService extends IService<Work> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询作品列表
|
||||||
|
*
|
||||||
|
* @param dto 查询条件
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
IPage<WorkVO> pageWorks(WorkQueryDTO dto);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
package com.luban.api.service.impl;
|
|
||||||
|
|
||||||
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.convert.FormSubmissionConvert;
|
|
||||||
import com.luban.api.dao.FormSubmissionDao;
|
|
||||||
import com.luban.api.dto.H5FormSubmissionDTO;
|
|
||||||
import com.luban.api.entity.FormSubmission;
|
|
||||||
import com.luban.api.service.FormService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 表单服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author lizhw
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class FormServiceImpl extends ServiceImpl<FormSubmissionDao, FormSubmission> implements FormService {
|
|
||||||
|
|
||||||
private final FormSubmissionDao formSubmissionDao;
|
|
||||||
|
|
||||||
public FormServiceImpl(FormSubmissionDao formSubmissionDao) {
|
|
||||||
this.formSubmissionDao = formSubmissionDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean submitFormData(H5FormSubmissionDTO dto) {
|
|
||||||
FormSubmission entity = FormSubmissionConvert.toEntity(dto);
|
|
||||||
entity.setId(null);
|
|
||||||
return this.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPage<FormSubmission> pageFormSubmissionsByProjectId(Long projectId, Map<String, Object> fieldFilters, Integer pageNum, Integer pageSize) {
|
|
||||||
IPage<FormSubmission> page = new Page<>(pageNum, pageSize);
|
|
||||||
return formSubmissionDao.selectByProjectIdWithFieldFilters(page, projectId, fieldFilters);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public H5FormSubmissionDTO getFormDataDetail(Long submissionId) {
|
|
||||||
FormSubmission formSubmission = this.getById(submissionId);
|
|
||||||
return FormSubmissionConvert.toDTO(formSubmission);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<H5FormSubmissionDTO> listFormDataByProjectId(Long projectId) {
|
|
||||||
List<FormSubmission> formSubmissions = this.lambdaQuery()
|
|
||||||
.eq(FormSubmission::getProjectId, projectId)
|
|
||||||
.list();
|
|
||||||
return FormSubmissionConvert.toDTO(formSubmissions);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,174 @@
|
|||||||
|
package com.luban.api.service.impl;
|
||||||
|
|
||||||
|
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.dromara.md.form.service.FormService;
|
||||||
|
import com.luban.api.convert.FormSubmissionConvert;
|
||||||
|
import com.luban.api.dao.FormSubmissionDao;
|
||||||
|
import com.luban.api.dto.H5FormSubmissionDTO;
|
||||||
|
import com.luban.api.dto.H5ProjectContentDTO;
|
||||||
|
import com.luban.api.entity.FormSubmission;
|
||||||
|
import com.luban.api.service.H5FormService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 表单服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author lizhw
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class H5FormServiceImpl extends ServiceImpl<FormSubmissionDao, FormSubmission> implements H5FormService {
|
||||||
|
|
||||||
|
private final FormSubmissionDao formSubmissionDao;
|
||||||
|
private final FormService formService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean submitFormData(H5FormSubmissionDTO dto) {
|
||||||
|
FormSubmission entity = FormSubmissionConvert.toEntity(dto);
|
||||||
|
entity.setId(null);
|
||||||
|
return this.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<H5FormSubmissionDTO> listDetailPage(Long templateFormId, String orderBy, Integer pageNum, Integer pageSize) {
|
||||||
|
Page<FormSubmission> page = this.lambdaQuery()
|
||||||
|
.eq(FormSubmission::getTempletFormId, templateFormId)
|
||||||
|
.orderByDesc(FormSubmission::getCreateTime)
|
||||||
|
.page(new Page<>(pageNum, pageSize));
|
||||||
|
return FormSubmissionConvert.toPageDTO(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long saveForm(H5ProjectContentDTO content) {
|
||||||
|
// 步骤1: 获取所有form组件
|
||||||
|
List<H5ProjectContentDTO.FormElement> formElements = extractFormElements(content);
|
||||||
|
|
||||||
|
// 步骤2: 保存所有form组件
|
||||||
|
saveFormElements(formElements);
|
||||||
|
|
||||||
|
return formElements.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 步骤1: 从H5项目内容中提取所有表单组件
|
||||||
|
*
|
||||||
|
* @param content H5项目内容
|
||||||
|
* @return 表单组件列表
|
||||||
|
*/
|
||||||
|
private List<H5ProjectContentDTO.FormElement> extractFormElements(H5ProjectContentDTO content) {
|
||||||
|
List<H5ProjectContentDTO.FormElement> formElements = new ArrayList<>();
|
||||||
|
|
||||||
|
if (content == null || content.getLayouts() == null) {
|
||||||
|
return formElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历所有布局,提取表单元素
|
||||||
|
for (H5ProjectContentDTO.Layout layout : content.getLayouts()) {
|
||||||
|
if (layout.getElements() != null) {
|
||||||
|
extractFormElementsFromList(layout.getElements(), formElements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从元素列表中递归提取表单组件
|
||||||
|
*
|
||||||
|
* @param elements 元素列表
|
||||||
|
* @param formElements 收集到的表单组件列表
|
||||||
|
*/
|
||||||
|
private void extractFormElementsFromList(List<H5ProjectContentDTO.Element> elements,
|
||||||
|
List<H5ProjectContentDTO.FormElement> formElements) {
|
||||||
|
if (elements == null || elements.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (H5ProjectContentDTO.Element element : elements) {
|
||||||
|
if (element == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是表单元素,添加到结果列表
|
||||||
|
if (H5ProjectContentDTO.ElementType.FORM.equals(element.getType())) {
|
||||||
|
formElements.add((H5ProjectContentDTO.FormElement) element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归处理组元素中的子元素
|
||||||
|
if (element instanceof H5ProjectContentDTO.GroupElement) {
|
||||||
|
H5ProjectContentDTO.GroupElement groupElement = (H5ProjectContentDTO.GroupElement) element;
|
||||||
|
if (groupElement.getElements() != null) {
|
||||||
|
extractFormElementsFromList(groupElement.getElements(), formElements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 步骤2: 保存表单组件列表
|
||||||
|
*
|
||||||
|
* @param formElements 表单组件列表
|
||||||
|
*/
|
||||||
|
private void saveFormElements(List<H5ProjectContentDTO.FormElement> formElements) {
|
||||||
|
if (formElements == null || formElements.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (H5ProjectContentDTO.FormElement formElement : formElements) {
|
||||||
|
saveSingleFormElement(formElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存单个表单组件
|
||||||
|
*
|
||||||
|
* @param formElement 表单组件
|
||||||
|
*/
|
||||||
|
private void saveSingleFormElement(H5ProjectContentDTO.FormElement formElement) {
|
||||||
|
if (formElement == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录表单组件信息到日志
|
||||||
|
log.info("发现表单组件: UUID={}, Title={}, FormSchema={}, FormData={}",
|
||||||
|
formElement.getUuid(),
|
||||||
|
formElement.getTitle(),
|
||||||
|
formElement.getFormSchema(),
|
||||||
|
formElement.getFormData());
|
||||||
|
|
||||||
|
// formService.create()
|
||||||
|
|
||||||
|
// TODO: 这里可以根据实际需求决定是否需要保存到数据库
|
||||||
|
// 如果需要保存到数据库,可以创建相应的实体类和服务
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<H5FormSubmissionDTO> getEditorForms(Long templateId, Boolean hasDeleted) {
|
||||||
|
// 由于当前模块没有表单定义表,返回空列表作为占位符
|
||||||
|
// 实际实现应查询 ruoyi-form 模块中的表单数据
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<H5FormSubmissionDTO> getEditorTemplateForms(Long templateFormId) {
|
||||||
|
// 由于当前模块没有表单定义表,返回空列表作为占位符
|
||||||
|
// 实际实现应查询 ruoyi-form 模块中的表单数据
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.luban.api.service.impl;
|
package com.luban.api.service.impl;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@ -65,7 +66,7 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
|
|||||||
|
|
||||||
// 更新项目与分组的关联关系
|
// 更新项目与分组的关联关系
|
||||||
if (updated && groupIds != null) {
|
if (updated && groupIds != null) {
|
||||||
h5ProjectGroupDao.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<H5ProjectGroup>()
|
h5ProjectGroupDao.delete(new LambdaQueryWrapper<H5ProjectGroup>()
|
||||||
.eq(H5ProjectGroup::getProjectId, h5Project.getId()));
|
.eq(H5ProjectGroup::getProjectId, h5Project.getId()));
|
||||||
|
|
||||||
if (!groupIds.isEmpty()) {
|
if (!groupIds.isEmpty()) {
|
||||||
@ -95,7 +96,7 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
|
|||||||
public boolean removeH5ProjectWithContent(Long id) {
|
public boolean removeH5ProjectWithContent(Long id) {
|
||||||
H5Project h5Project = this.getById(id);
|
H5Project h5Project = this.getById(id);
|
||||||
if (h5Project != null) {
|
if (h5Project != null) {
|
||||||
h5ProjectGroupDao.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<H5ProjectGroup>()
|
h5ProjectGroupDao.delete(new LambdaQueryWrapper<H5ProjectGroup>()
|
||||||
.eq(H5ProjectGroup::getProjectId, id));
|
.eq(H5ProjectGroup::getProjectId, id));
|
||||||
|
|
||||||
return this.removeById(id);
|
return this.removeById(id);
|
||||||
@ -120,7 +121,7 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getProjectGroupIds(Long projectId) {
|
public List<Long> getProjectGroupIds(Long projectId) {
|
||||||
return h5ProjectGroupDao.selectList(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<H5ProjectGroup>()
|
return h5ProjectGroupDao.selectList(new LambdaQueryWrapper<H5ProjectGroup>()
|
||||||
.eq(H5ProjectGroup::getProjectId, projectId))
|
.eq(H5ProjectGroup::getProjectId, projectId))
|
||||||
.stream()
|
.stream()
|
||||||
.map(H5ProjectGroup::getGroupId)
|
.map(H5ProjectGroup::getGroupId)
|
||||||
@ -130,7 +131,7 @@ public class H5ProjectServiceImpl extends ServiceImpl<H5ProjectDao, H5Project> i
|
|||||||
@Override
|
@Override
|
||||||
public IPage<H5Project> pageH5Projects(H5ProjectQueryDTO queryDTO) {
|
public IPage<H5Project> pageH5Projects(H5ProjectQueryDTO queryDTO) {
|
||||||
// 创建分页对象
|
// 创建分页对象
|
||||||
IPage<H5Project> page = new Page<>(queryDTO.getCurrent(), queryDTO.getSize());
|
IPage<H5Project> page = new Page<>(queryDTO.getPage(), queryDTO.getSize());
|
||||||
|
|
||||||
// 执行分页查询
|
// 执行分页查询
|
||||||
return baseMapper.selectH5ProjectPage(page, queryDTO);
|
return baseMapper.selectH5ProjectPage(page, queryDTO);
|
||||||
|
|||||||
@ -1,11 +1,21 @@
|
|||||||
package com.luban.api.service.impl;
|
package com.luban.api.service.impl;
|
||||||
|
|
||||||
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.luban.api.convert.WorkConvert;
|
||||||
import com.luban.api.dao.WorkDao;
|
import com.luban.api.dao.WorkDao;
|
||||||
|
import com.luban.api.dto.WorkQueryDTO;
|
||||||
import com.luban.api.entity.Work;
|
import com.luban.api.entity.Work;
|
||||||
import com.luban.api.service.WorkService;
|
import com.luban.api.service.WorkService;
|
||||||
|
import com.luban.api.vo.WorkVO;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 服务实现类
|
* 服务实现类
|
||||||
@ -17,5 +27,19 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class WorkServiceImpl extends ServiceImpl<WorkDao, Work> implements WorkService {
|
public class WorkServiceImpl extends ServiceImpl<WorkDao, Work> implements WorkService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<WorkVO> pageWorks(WorkQueryDTO dto) {
|
||||||
|
WorkVO vo = new WorkVO();
|
||||||
|
vo.setTemplate(dto.getIsTemplate());
|
||||||
|
BeanUtils.copyProperties(dto, vo);
|
||||||
|
IPage<Work> page = this.page(new Page<>(dto.getPage(), dto.getSize()),
|
||||||
|
new LambdaQueryWrapper<>(WorkConvert.toEntity(vo)).orderByDesc(Work::getCreateTime));
|
||||||
|
List<WorkVO> voList = page.getRecords().stream()
|
||||||
|
.map(WorkConvert::toVO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return new Page<WorkVO>(page.getCurrent(), page.getSize(), page.getTotal())
|
||||||
|
.setPages(page.getPages())
|
||||||
|
.setRecords(voList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,7 @@ tenant:
|
|||||||
# https://baomidou.com/config/
|
# https://baomidou.com/config/
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
# 多包名使用 例如 org.dromara.**.mapper,org.xxx.**.mapper
|
# 多包名使用 例如 org.dromara.**.mapper,org.xxx.**.mapper
|
||||||
mapperPackage: com.luban.api.dao
|
mapperPackage: com.luban.api.dao,com.dromara.**.mapper
|
||||||
# # 实体扫描,多个package用逗号或者分号分隔
|
# # 实体扫描,多个package用逗号或者分号分隔
|
||||||
# typeAliasesPackage: com.luban.api.entity
|
# typeAliasesPackage: com.luban.api.entity
|
||||||
global-config:
|
global-config:
|
||||||
@ -87,3 +87,5 @@ minioplus:
|
|||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
config: classpath:logback-plus.xml
|
config: classpath:logback-plus.xml
|
||||||
|
level:
|
||||||
|
com.baomidou.mybatisplus: debug
|
||||||
|
|||||||
@ -31,6 +31,9 @@
|
|||||||
<if test="queryDTO.title != null and queryDTO.title != ''">
|
<if test="queryDTO.title != null and queryDTO.title != ''">
|
||||||
AND MATCH(title) AGAINST(#{queryDTO.title} IN NATURAL LANGUAGE MODE)
|
AND MATCH(title) AGAINST(#{queryDTO.title} IN NATURAL LANGUAGE MODE)
|
||||||
</if>
|
</if>
|
||||||
|
<if test="queryDTO.status != null">
|
||||||
|
AND status = #{queryDTO.status}
|
||||||
|
</if>
|
||||||
<if test="queryDTO.groupIds != null and queryDTO.groupIds.size() > 0">
|
<if test="queryDTO.groupIds != null and queryDTO.groupIds.size() > 0">
|
||||||
AND EXISTS (
|
AND EXISTS (
|
||||||
SELECT 1
|
SELECT 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user