|
@@ -1,15 +1,21 @@
|
|
|
package com.molin.study_class.controller;
|
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.molin.study_class.model.dto.ResponseCode;
|
|
|
import com.molin.study_class.model.dto.ResponseObject;
|
|
|
import com.molin.study_class.model.param.MeetAllParam;
|
|
|
+import com.molin.study_class.model.param.MeetParam;
|
|
|
import com.molin.study_class.service.FileMakeService;
|
|
|
import com.molin.study_class.utils.ExcelUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @author David
|
|
|
* @date 2025年06月07日
|
|
@@ -17,16 +23,48 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("fileMake")
|
|
|
+@Slf4j
|
|
|
public class FileMakeController {
|
|
|
|
|
|
@Autowired
|
|
|
private FileMakeService fileMakeService;
|
|
|
|
|
|
|
|
|
- @PostMapping("/createExcel")
|
|
|
- public ResponseObject createExcel(@RequestBody MeetAllParam meetAllParam) {
|
|
|
+// @PostMapping("/createExcel")
|
|
|
+// public ResponseObject createExcel(@RequestBody MeetAllParam meetAllParam) {
|
|
|
+//
|
|
|
+// ResponseObject url = fileMakeService.createExcel(meetAllParam);
|
|
|
+// if (url.getCode().equals(ResponseCode.FAILURE)) {
|
|
|
+// return ResponseObject.fail("表格文件失败!");
|
|
|
+// }
|
|
|
+// return url;
|
|
|
+// }
|
|
|
|
|
|
- ResponseObject url = fileMakeService.createExcel(meetAllParam);
|
|
|
+ @PostMapping("/createExcel")
|
|
|
+ public ResponseObject createExcel(@RequestBody MeetAllParam param) {
|
|
|
+ String ss = param.getValue();
|
|
|
+// String ss = "{\"code\":1,\"msg\":\"成功\",\"data\":[{\"id\":\"\",\"className\":\"\",\"courseName\":\"\",\"startTime\":\"\",\"endTime\":\"\",\"teacherName\":\"\",\"weekDay\":\"\",\"roomName\":\"\",\"peoples\":\"\"}]}";
|
|
|
+ if (StringUtils.isEmpty(ss)){
|
|
|
+ ResponseObject.fail("解析表格数据为空");
|
|
|
+ }
|
|
|
+ log.info("处理前:"+ss);
|
|
|
+ // 步骤2:处理转义字符
|
|
|
+ String str = ss
|
|
|
+ .replace("\\\"", "\"") // 处理转义双引号
|
|
|
+ .trim();
|
|
|
+ log.info("处理后:"+ss);
|
|
|
+ // 去除首尾空格
|
|
|
+ List<MeetParam> meets = null;
|
|
|
+ try {
|
|
|
+ meets = JSONObject.parseArray(str, MeetParam.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("解析表格数据失败:" + e.toString());
|
|
|
+ return ResponseObject.fail("解析表格数据失败");
|
|
|
+ }
|
|
|
+ param.setData(meets);
|
|
|
+ param.setCode(1);
|
|
|
+ param.setMsg("成功");
|
|
|
+ ResponseObject url = fileMakeService.createExcel(param);
|
|
|
if (url.getCode().equals(ResponseCode.FAILURE)) {
|
|
|
return ResponseObject.fail("表格文件失败!");
|
|
|
}
|