添加 模版生成相关依赖

This commit is contained in:
2026-01-12 09:17:24 +08:00
parent f07fee186d
commit 2c2ac6d032
7 changed files with 264 additions and 6 deletions

View File

@@ -0,0 +1,42 @@
package com.cczsa.xinghe.codegen.controller;
import com.cczsa.xinghe.codegen.service.CodeGenService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author xia
* @date 2026/1/10
* @version 0.0.1
*/
@RestController
@RequestMapping("/codegen")
@RequiredArgsConstructor
public class CodeGenController {
private final CodeGenService codeGenService;
@PostMapping("/download")
public ResponseEntity<byte[]> downloadCode() {
try {
byte[] zipData = codeGenService.generateCodeZip();
return ResponseEntity.ok()
// 设置下载文件名
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"generated-code.zip\"")
// 设置为二进制流
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(zipData.length)
.body(zipData);
} catch (Exception e) {
return ResponseEntity.internalServerError().build();
}
}
}

View File

@@ -1,12 +1,22 @@
package com.cczsa.xinghe.codegen.controller;
import com.alibaba.fastjson2.JSONObject;
import com.cczsa.xinghe.codegen.util.XResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author xia
@@ -14,17 +24,49 @@ import org.springframework.web.bind.annotation.RestController;
* @version 0.0.1
*
*/
@Slf4j
@Tag(name = "登录")
@RequiredArgsConstructor
@RestController
@RequestMapping("/login")
public class LoginController {
@PostMapping("/")
public XResult<String> login(String username, String password) {
return null;
@Operation(summary = "登录", description = "登录")
@PostMapping("/login")
@Parameters({
@Parameter(name = "username", description = "用户名", required = true),
@Parameter(name = "password", description = "密码", required = true)
})
public XResult<Object> login(@RequestBody JSONObject login) {
if(!login.containsKey("username") || !login.containsKey("password")){
return XResult.failed("参数错误");
}
String username = login.getString("username");
String password = login.getString("password");
if ("admin".equals(username) && "9527".equals(password)) {
Map<String, Object> info = new HashMap<>();
info.put("token", "sk-"+System.currentTimeMillis());
info.put("roles", List.of("admin"));
info.put("username", "admin");
return XResult.ok(info);
}
return XResult.failed();
}
@Operation(summary = "用户信息", description = "用户信息")
@GetMapping("/users/info")
public XResult<Object> login() {
Map<String, Object> info = new HashMap<>();
info.put("roles", List.of("admin"));
info.put("username", "admin");
return XResult.ok(info);
}
}

View File

@@ -0,0 +1,10 @@
package com.cczsa.xinghe.codegen.service;
/**
* @author xia
* &#064;date 2026/1/10
* @version 0.0.1
*/
public interface CodeGenService {
byte[] generateCodeZip();
}

View File

@@ -0,0 +1,22 @@
package com.cczsa.xinghe.codegen.service.impl;
import com.cczsa.xinghe.codegen.service.CodeGenService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author xia
* &#064;date 2026/1/10
* @version 0.0.1
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class CodeGenServiceImpl implements CodeGenService {
@Override
public byte[] generateCodeZip() {
return null;
}
}