添加 模版生成相关依赖
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.cczsa.xinghe.codegen.service;
|
||||
|
||||
/**
|
||||
* @author xia
|
||||
* @date 2026/1/10
|
||||
* @version 0.0.1
|
||||
*/
|
||||
public interface CodeGenService {
|
||||
byte[] generateCodeZip();
|
||||
}
|
||||
@@ -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
|
||||
* @date 2026/1/10
|
||||
* @version 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CodeGenServiceImpl implements CodeGenService {
|
||||
|
||||
@Override
|
||||
public byte[] generateCodeZip() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ server:
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://192.168.1.40:5432/xinghe-codegen
|
||||
url: jdbc:postgresql://192.168.1.26:5432/xinghe-codegen
|
||||
username: postgres
|
||||
password: root
|
||||
driver-class-name: org.postgresql.Driver
|
||||
|
||||
Reference in New Issue
Block a user