diff --git a/kn-common/src/main/java/org/springblade/common/utils/ExcelCellUtil.java b/kn-common/src/main/java/org/springblade/common/utils/ExcelCellUtil.java
new file mode 100644
index 0000000..3edf91d
--- /dev/null
+++ b/kn-common/src/main/java/org/springblade/common/utils/ExcelCellUtil.java
@@ -0,0 +1,52 @@
+
+package org.springblade.common.utils;
+
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.RegionUtil;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+public class ExcelCellUtil {
+ public ExcelCellUtil() {
+ }
+
+ public static String strHandle(Object obj) {
+ return obj == null ? "" : obj.toString().trim();
+ }
+
+ public static XSSFCellStyle cellBorder(XSSFWorkbook workbook) {
+ XSSFCellStyle borderStyle = workbook.createCellStyle();
+ borderStyle.setBorderBottom(BorderStyle.THIN);
+ borderStyle.setBorderLeft(BorderStyle.THIN);
+ borderStyle.setBorderTop(BorderStyle.THIN);
+ borderStyle.setBorderRight(BorderStyle.THIN);
+ return borderStyle;
+ }
+
+ public static XSSFCellStyle cellFontAndBorder(XSSFWorkbook wb, String fontName, short fontSize) {
+ XSSFCellStyle fontAndBorderStyle = wb.createCellStyle();
+ XSSFFont font = wb.createFont();
+ font.setFontName(fontName);
+ font.setFontHeightInPoints(fontSize);
+ fontAndBorderStyle.setFont(font);
+ fontAndBorderStyle.setBorderBottom(BorderStyle.THIN);
+ fontAndBorderStyle.setBorderLeft(BorderStyle.THIN);
+ fontAndBorderStyle.setBorderTop(BorderStyle.THIN);
+ fontAndBorderStyle.setBorderRight(BorderStyle.THIN);
+ fontAndBorderStyle.setAlignment(HorizontalAlignment.CENTER);
+ fontAndBorderStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+ return fontAndBorderStyle;
+ }
+
+ public static void setRegionBorder(CellRangeAddress region, XSSFSheet sheet) {
+ RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);
+ RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);
+ RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);
+ RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);
+ }
+}
diff --git a/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/News.java b/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/News.java
index 9b71af2..63b5e29 100644
--- a/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/News.java
+++ b/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/News.java
@@ -83,6 +83,11 @@ public class News implements Serializable {
@ExcelIgnore
private Date reviewTime;
+ /**
+ * 审核时间
+ */
+ private String Time;
+
@ExcelIgnore
@TableField(exist = false)
private static final long serialVersionUID = 1L;
diff --git a/kn-service/biz-vordm/pom.xml b/kn-service/biz-vordm/pom.xml
index e41a563..4533b47 100644
--- a/kn-service/biz-vordm/pom.xml
+++ b/kn-service/biz-vordm/pom.xml
@@ -98,6 +98,21 @@
org.springframework.boot
spring-boot-starter-thymeleaf
+
+ org.apache.poi
+ poi
+ 4.0.0
+
+
+ org.apache.poi
+ poi-ooxml
+ 4.0.0
+
+
+ org.apache.poi
+ poi-ooxml-schemas
+ 4.0.0
+
diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/NewsController.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/NewsController.java
index 8f4fcd2..4b63263 100644
--- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/NewsController.java
+++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/NewsController.java
@@ -16,6 +16,7 @@ import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -87,4 +88,14 @@ public class NewsController {
Boolean flag=newsService.update(updateWrapper);
return R.data(flag);
}
+
+ /**
+ * 导入供应商模板
+ * @param file
+ * @return
+ */
+ @PostMapping({"/importTemplate"})
+ public R fileExcelUpload(@RequestParam("fileData") MultipartFile file,@RequestParam("type") Integer type,@RequestParam("disasterId") Long disasterId) {
+ return R.data(newsService.importTemplate(file,type,disasterId));
+ }
}
diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/NewsMapper.xml b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/NewsMapper.xml
index 273c67d..c1da9ff 100644
--- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/NewsMapper.xml
+++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/NewsMapper.xml
@@ -15,12 +15,13 @@
+
id,title,content,
link,type,disaster_id,
create_time,status,manager_id,
- review_time
+ review_time,time
diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/NewsService.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/NewsService.java
index 6055b45..b3298f0 100644
--- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/NewsService.java
+++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/NewsService.java
@@ -3,6 +3,8 @@ package com.kening.vordm.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kening.vordm.entity.News;
+import org.springblade.core.tool.api.R;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -22,4 +24,7 @@ public interface NewsService extends IService {
* @param type
*/
void export(Long disasterId,Integer type, HttpServletRequest request, HttpServletResponse response);
+
+ R importTemplate(MultipartFile file, Integer type, Long disasterId);
+
}
diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/NewsServiceImpl.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/NewsServiceImpl.java
index c8ab79b..aab7d56 100644
--- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/NewsServiceImpl.java
+++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/NewsServiceImpl.java
@@ -1,72 +1,210 @@
package com.kening.vordm.service.impl;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kening.vordm.entity.Hotspot;
import com.kening.vordm.entity.News;
+import com.kening.vordm.entity.SocialMedia;
import com.kening.vordm.mapper.NewsMapper;
+import com.kening.vordm.mapper.SocialMediaMapper;
import com.kening.vordm.service.HotspotService;
import com.kening.vordm.service.NewsService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springblade.common.utils.ExcelCellUtil;
+import org.springblade.core.tool.api.R;
import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
/**
-* @author G1393
-* @description 针对表【news(新闻咨询数据表)】的数据库操作Service实现
-* @createDate 2023-04-04 15:54:31
-*/
+ * @author G1393
+ * @description 针对表【news(新闻咨询数据表)】的数据库操作Service实现
+ * @createDate 2023-04-04 15:54:31
+ */
@Slf4j
@Service
@AllArgsConstructor
public class NewsServiceImpl extends ServiceImpl
-implements NewsService {
+ implements NewsService {
private HotspotService hotspotService;
+ private SocialMediaMapper socialMediaMapper;
+
/**
* 新闻、热点导出功能
+ *
* @param disasterId
* @param request
* @param response
* @param type
*/
@Override
- public void export(Long disasterId,Integer type, HttpServletRequest request, HttpServletResponse response) {
- try{
+ public void export(Long disasterId, Integer type, HttpServletRequest request, HttpServletResponse response) {
+ try {
String fileName = "";
- if(type.equals(1) || type.equals(0)){
+ if (type.equals(1) || type.equals(0)) {
fileName = type.equals(1) ? "English News" : "Chinese News";
//英文的新闻 或 中文的新闻
- List newsList = list(Wrappers.lambdaQuery().eq(News::getDisasterId,disasterId).eq(News::getStatus,1).eq(News::getType,type));
+ List newsList = list(Wrappers.lambdaQuery().eq(News::getDisasterId, disasterId).eq(News::getStatus, 1).eq(News::getType, type));
extracted(response, fileName);
- EasyExcel.write(response.getOutputStream(),News.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("news").doWrite(newsList);
- }else if(type.equals(2)){
+ EasyExcel.write(response.getOutputStream(), News.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("news").doWrite(newsList);
+ } else if (type.equals(2)) {
//热点数据
fileName = "Hotspot Area";
- List hotspotList = hotspotService.list(Wrappers.lambdaQuery().eq(Hotspot::getDisasterId,disasterId).eq(Hotspot::getStatus,1));
+ List hotspotList = hotspotService.list(Wrappers.lambdaQuery().eq(Hotspot::getDisasterId, disasterId).eq(Hotspot::getStatus, 1));
extracted(response, fileName);
- EasyExcel.write(response.getOutputStream(),Hotspot.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("hotspot").doWrite(hotspotList);
+ EasyExcel.write(response.getOutputStream(), Hotspot.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("hotspot").doWrite(hotspotList);
}
- }catch (IOException e){
- log.error("导出IO异常:{}",e.getMessage());
+ } catch (IOException e) {
+ log.error("导出IO异常:{}", e.getMessage());
ExceptionUtil.stacktraceToString(e);
- }catch (Exception e){
- log.error("导出发生异常:{}",e.getMessage());
+ } catch (Exception e) {
+ log.error("导出发生异常:{}", e.getMessage());
ExceptionUtil.stacktraceToString(e);
}
}
+ @Override
+ public R importTemplate(MultipartFile file, Integer typeData, Long disasterId) {
+ List content;
+ try {
+ ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
+ content = reader.read();
+ } catch (Exception var30) {
+ return R.fail("上传文件格式解析错误");
+ }
+ if (CollectionUtil.isEmpty(content)) {
+ return R.fail("文件内容为空!");
+ }
+ if (typeData < 1) {
+ for (int i = 0; i < content.size(); ++i) {
+ List