-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
747eda9
commit 65ef6bf
Showing
6 changed files
with
64 additions
and
132 deletions.
There are no files selected for viewing
32 changes: 10 additions & 22 deletions
32
src/main/java/com/aiassistant/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
package com.aiassistant.controller; | ||
|
||
import com.aiassistant.model.Demo; | ||
import com.aiassistant.service.DemoService; | ||
import com.aiassistant.utils.ResultModel; | ||
import com.aiassistant.utils.ResultPageModel; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
/** | ||
* 控制器层--DemoController | ||
*/ | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Api(tags = "DemoController") | ||
public class DemoController { | ||
|
||
private final DemoService demoService; | ||
|
||
@PostMapping("/addDemo") | ||
@ApiOperation(value = "Demo add") | ||
public ResultModel addDemo(@RequestBody Demo demo) { | ||
return demoService.addDemo(demo); | ||
@Autowired | ||
public DemoController(DemoService demoService) { | ||
this.demoService = demoService; | ||
} | ||
|
||
@GetMapping("/getDemoList") | ||
@ApiOperation(value = "Get Demo list") | ||
public ResultPageModel<Demo> getDemoList() { | ||
return demoService.getDemoList(); | ||
@PostMapping("/upload") | ||
public ResultModel<String> uploadZipFile(@RequestParam("file") MultipartFile file) { | ||
return demoService.uploadZipFile(file); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,11 @@ | ||
package com.aiassistant.mapper; | ||
|
||
import com.aiassistant.model.Demo; | ||
import org.apache.ibatis.annotations.Insert; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 持久化层--DemoMapper | ||
*/ | ||
@Mapper | ||
public interface DemoMapper { | ||
|
||
/** | ||
* 插入一条目录记录 | ||
* | ||
* @param demo | ||
*/ | ||
Demo insertDemo(Demo demo); | ||
|
||
/** | ||
* 查询所有目录记录 | ||
* | ||
* @return | ||
*/ | ||
List<Demo> getDemoList(); | ||
|
||
/** | ||
* 根据Id查询 | ||
* | ||
* @param id | ||
* @return | ||
*/ | ||
Demo selectById(@Param("id") Integer id); | ||
} | ||
@Insert("INSERT INTO demo (file_path) VALUES (#{filePath})") | ||
void uploadZipFile(@Param("filePath") String filePath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package com.aiassistant.model; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* 实体类--Demo | ||
*/ | ||
@Data | ||
public class Demo { | ||
private int id; | ||
private String demoType; | ||
private String demoName; | ||
private String filePath; | ||
|
||
public void uploadZipFile(String filePath) { | ||
this.filePath = filePath; | ||
} | ||
|
||
public String getFilePath() { | ||
return filePath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
package com.aiassistant.service; | ||
|
||
import com.aiassistant.model.Demo; | ||
import com.aiassistant.mapper.DemoMapper; | ||
import com.aiassistant.utils.ResultModel; | ||
import com.aiassistant.utils.ResultPageModel; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
/** | ||
* 业务逻辑层--demo Service | ||
*/ | ||
public interface DemoService { | ||
@Service | ||
public class DemoService { | ||
private final DemoMapper demoMapper; | ||
|
||
/** | ||
* 添加一条Demo | ||
* | ||
* @param demo | ||
*/ | ||
ResultModel<Demo> addDemo(Demo demo); | ||
@Autowired | ||
public DemoService(DemoMapper demoMapper) { | ||
this.demoMapper = demoMapper; | ||
} | ||
|
||
/** | ||
* 获取所有 | ||
* | ||
* @return | ||
*/ | ||
ResultPageModel<Demo> getDemoList(); | ||
public ResultModel<String> uploadZipFile(MultipartFile file) { | ||
String filePath = saveFile(file); | ||
demoMapper.uploadZipFile(filePath); | ||
return ResultModel.ofSuccess(filePath); | ||
} | ||
|
||
/** | ||
* 根据Id查询 | ||
* | ||
* @param id | ||
* @return | ||
*/ | ||
Demo getById(Integer id); | ||
} | ||
private String saveFile(MultipartFile file) { | ||
// Save the file to the server and return the file path | ||
return "path/to/zip/file"; | ||
} | ||
} |
45 changes: 17 additions & 28 deletions
45
src/main/java/com/aiassistant/service/impl/DemoServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
package com.aiassistant.service.impl; | ||
|
||
import com.aiassistant.mapper.DemoMapper; | ||
import com.aiassistant.model.Demo; | ||
import com.aiassistant.service.DemoService; | ||
import com.aiassistant.utils.ResultModel; | ||
import com.aiassistant.utils.ResultPageModel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.List; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* 业务逻辑层--DemoService接口实现 | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class DemoServiceImpl implements DemoService { | ||
|
||
private final DemoMapper demoMapper; | ||
|
||
@Override | ||
public ResultModel<Demo> addDemo(Demo demo) { | ||
Demo result = demoMapper.insertDemo(demo); | ||
return ResultModel.ofSuccess(result); | ||
} | ||
|
||
@Override | ||
public ResultPageModel<Demo> getDemoList() { | ||
List<Demo> list = demoMapper.getDemoList(); | ||
|
||
return ResultPageModel.of(list); | ||
} | ||
|
||
|
||
@Override | ||
public Demo getById(Integer id) { | ||
return demoMapper.selectById(id); | ||
public ResultModel<String> uploadZipFile(MultipartFile file) { | ||
try { | ||
// 获取当前目录 | ||
String currentPath = System.getProperty("user.dir"); | ||
// 保存文件的路径 | ||
String savePath = currentPath + File.separator + file.getOriginalFilename(); | ||
// 将上传的zip文件保存到服务器的当前目录中 | ||
file.transferTo(new File(savePath)); | ||
return ResultModel.ofSuccess(savePath); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return ResultModel.ofError("Failed to upload zip file", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="com.aiassistant.mapper.DemoMapper"> | ||
|
||
<insert id="insertDemo" useGeneratedKeys="true" keyProperty="id"> | ||
INSERT INTO guanshui_demo (demo_type, demo_name) | ||
VALUES (#{demoType}, #{demoName}) | ||
</insert> | ||
|
||
<select id="getDemoList" resultType="com.aiassistant.model.Demo"> | ||
SELECT * FROM guanshui_demo | ||
</select> | ||
|
||
<select id="selectById" resultType="com.aiassistant.model.Demo"> | ||
select * from guanshui_demo where id = #{id} | ||
</select> | ||
|
||
</mapper> | ||
<insert id="uploadZipFile" parameterType="String"> | ||
INSERT INTO demo (demo_type, demo_name) VALUES ('zip', #{filePath}) | ||
</insert> |