|
@@ -1,13 +1,23 @@
|
|
|
package com.example.nngkxxdp.controller;
|
|
|
|
|
|
import com.example.nngkxxdp.entity.SortArticleHeadlinesDO;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.converters.string.StringNumberConverter;
|
|
|
+import com.example.nngkxxdp.base.SortArticleHeadlinesExcelListeners;
|
|
|
+import com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO;
|
|
|
import com.example.nngkxxdp.service.SortArticleHeadlinesService;
|
|
|
import com.example.nngkxxdp.util.Blank;
|
|
|
import com.example.nngkxxdp.util.ConstStr;
|
|
|
import com.example.nngkxxdp.util.SendUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+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.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -86,4 +96,19 @@ public class SortArticleHeadlinesController {
|
|
|
return sortArticleHeadlinesService.deleteArticleById(id);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/add/batch")
|
|
|
+ public Map<String,Object> page(MultipartFile file) {
|
|
|
+ if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
|
|
|
+ return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ EasyExcel.read(file.getInputStream(), SortArticleHeadlinesExcelDTO.class, new SortArticleHeadlinesExcelListeners(sortArticleHeadlinesService))
|
|
|
+ .registerConverter(new StringNumberConverter()).sheet().doRead();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return SendUtil.send(true, ConstStr.RESULT_SUCCESS);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|