Expand EasyCode front workbench features
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.generator.domain.front.dto.DatabaseDesignResponse;
|
||||
import com.ruoyi.generator.domain.front.dto.FrontProjectCreateRequest;
|
||||
import com.ruoyi.generator.domain.front.dto.FrontProjectUpdateRequest;
|
||||
@@ -117,10 +118,12 @@ public class FrontProjectController extends BaseController
|
||||
}
|
||||
|
||||
@GetMapping("/{projectId}/download")
|
||||
public void download(@PathVariable Long projectId, @RequestParam String templateType, HttpServletResponse response) throws IOException
|
||||
public void download(@PathVariable Long projectId, @RequestParam(required = false) String templateType, HttpServletResponse response) throws IOException
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
byte[] data = frontProjectPreviewService.download(userId, projectId, templateType);
|
||||
byte[] data = StringUtils.isNotEmpty(templateType)
|
||||
? frontProjectPreviewService.download(userId, projectId, templateType)
|
||||
: frontProjectPreviewService.downloadAll(userId, projectId);
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"project.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.ruoyi.web.controller.front;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.generator.domain.SourceProject;
|
||||
import com.ruoyi.generator.service.ISourceProjectService;
|
||||
import com.ruoyi.system.service.ISysDictTypeService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/front/source")
|
||||
public class FrontSourceController extends BaseController
|
||||
{
|
||||
private static final String SOURCE_PROJECT_CATEGORY_DICT_TYPE = "source_project_category";
|
||||
|
||||
@Autowired
|
||||
private ISourceProjectService sourceProjectService;
|
||||
|
||||
@Autowired
|
||||
private ISysDictTypeService dictTypeService;
|
||||
|
||||
@GetMapping("/categories")
|
||||
public AjaxResult categories()
|
||||
{
|
||||
List<SysDictData> data = dictTypeService.selectDictDataByType(SOURCE_PROJECT_CATEGORY_DICT_TYPE);
|
||||
if (data == null)
|
||||
{
|
||||
data = new ArrayList<SysDictData>();
|
||||
}
|
||||
return success(data);
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public AjaxResult projects(SourceProject query)
|
||||
{
|
||||
return success(sourceProjectService.listPublicProjects(optionalUserId(), query));
|
||||
}
|
||||
|
||||
@GetMapping("/projects/{slug}")
|
||||
public AjaxResult detail(@PathVariable String slug)
|
||||
{
|
||||
return success(sourceProjectService.getPublicProject(optionalUserId(), slug, true));
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{projectId}/purchase")
|
||||
public AjaxResult purchase(@PathVariable Long projectId)
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return success(sourceProjectService.purchase(userId, projectId));
|
||||
}
|
||||
|
||||
@GetMapping("/purchases")
|
||||
public AjaxResult purchases()
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return success(sourceProjectService.listPurchases(userId));
|
||||
}
|
||||
|
||||
@GetMapping("/projects/{projectId}/download")
|
||||
public AjaxResult download(@PathVariable Long projectId)
|
||||
{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return success(sourceProjectService.getDownloadInfo(userId, projectId));
|
||||
}
|
||||
|
||||
private Long optionalUserId()
|
||||
{
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null || authentication.getPrincipal() == null
|
||||
|| "anonymousUser".equals(authentication.getPrincipal()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (authentication.getPrincipal() instanceof LoginUser)
|
||||
{
|
||||
return ((LoginUser) authentication.getPrincipal()).getUserId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,13 @@ ruoyi:
|
||||
captchaType: math
|
||||
|
||||
deepseek:
|
||||
apiKey: ${DEEPSEEK_API_KEY:}
|
||||
apiKey: sk-2aef3231d45048a9a0ba6f0367a072ca
|
||||
baseUrl: https://api.deepseek.com
|
||||
model: deepseek-chat
|
||||
timeout: 60000
|
||||
model: deepseek-v4-flash
|
||||
timeout: ${DEEPSEEK_TIMEOUT:180000}
|
||||
maxTables: 12
|
||||
maxColumnsPerTable: 30
|
||||
skipSslVerify: true
|
||||
|
||||
# 开发环境配置
|
||||
server:
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ruoyi.web.controller.front;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
import com.ruoyi.system.service.ISysDictTypeService;
|
||||
|
||||
public class FrontSourceControllerTest
|
||||
{
|
||||
private FrontSourceController controller;
|
||||
|
||||
@Mock
|
||||
private ISysDictTypeService dictTypeService;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
controller = new FrontSourceController();
|
||||
setField("dictTypeService", dictTypeService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void categoriesReturnsSourceProjectCategoryDictData()
|
||||
{
|
||||
SysDictData data = new SysDictData();
|
||||
data.setDictLabel("Enterprise Systems");
|
||||
data.setDictValue("enterprise");
|
||||
data.setDictType("source_project_category");
|
||||
when(dictTypeService.selectDictDataByType("source_project_category")).thenReturn(Collections.singletonList(data));
|
||||
|
||||
AjaxResult result = controller.categories();
|
||||
|
||||
List<?> categories = (List<?>) result.get(AjaxResult.DATA_TAG);
|
||||
SysDictData category = (SysDictData) categories.get(0);
|
||||
assertEquals("enterprise", category.getDictValue());
|
||||
assertEquals("Enterprise Systems", category.getDictLabel());
|
||||
}
|
||||
|
||||
private void setField(String name, Object value) throws Exception
|
||||
{
|
||||
Field field = FrontSourceController.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(controller, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user