Support front draft project preview
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.ruoyi.web.controller.front;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -8,6 +11,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
@@ -16,7 +20,9 @@ import com.ruoyi.generator.domain.front.dto.DatabaseDesignResponse;
|
||||
import com.ruoyi.generator.domain.front.dto.FrontProjectCreateRequest;
|
||||
import com.ruoyi.generator.domain.front.dto.FrontProjectUpdateRequest;
|
||||
import com.ruoyi.generator.domain.front.dto.GenerateDatabaseRequest;
|
||||
import com.ruoyi.generator.domain.front.dto.PreviewFileRequest;
|
||||
import com.ruoyi.generator.service.front.IAiGenerateService;
|
||||
import com.ruoyi.generator.service.front.IFrontProjectPreviewService;
|
||||
import com.ruoyi.generator.service.front.IFrontProjectService;
|
||||
|
||||
@RestController
|
||||
@@ -27,6 +33,8 @@ public class FrontProjectController extends BaseController
|
||||
private IFrontProjectService frontProjectService;
|
||||
@Autowired
|
||||
private IAiGenerateService aiGenerateService;
|
||||
@Autowired
|
||||
private IFrontProjectPreviewService frontProjectPreviewService;
|
||||
|
||||
@PostMapping("/create")
|
||||
public AjaxResult create(@RequestBody FrontProjectCreateRequest request)
|
||||
@@ -83,4 +91,40 @@ public class FrontProjectController extends BaseController
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return success(aiGenerateService.generateDatabase(userId, projectId, request));
|
||||
}
|
||||
|
||||
@PostMapping("/{projectId}/preview")
|
||||
public AjaxResult preview(@PathVariable Long projectId)
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
frontProjectPreviewService.getStructure(userId, projectId, "backend");
|
||||
frontProjectPreviewService.getStructure(userId, projectId, "frontend");
|
||||
frontProjectPreviewService.getStructure(userId, projectId, "admin_frontend");
|
||||
return toAjax(frontProjectPreviewService.markPreviewReady(userId, projectId));
|
||||
}
|
||||
|
||||
@GetMapping("/{projectId}/structure")
|
||||
public AjaxResult structure(@PathVariable Long projectId, @RequestParam String templateType)
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return success(frontProjectPreviewService.getStructure(userId, projectId, templateType));
|
||||
}
|
||||
|
||||
@GetMapping("/{projectId}/file-content")
|
||||
public AjaxResult fileContent(@PathVariable Long projectId, PreviewFileRequest request)
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return success(frontProjectPreviewService.getFileContent(userId, projectId, request));
|
||||
}
|
||||
|
||||
@GetMapping("/{projectId}/download")
|
||||
public void download(@PathVariable Long projectId, @RequestParam String templateType, HttpServletResponse response) throws IOException
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
byte[] data = frontProjectPreviewService.download(userId, projectId, templateType);
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"project.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user