glj-代码提交

This commit is contained in:
glj 2023-05-13 18:04:22 +08:00
parent 58395829b7
commit 3199b3b5d4
9 changed files with 248 additions and 21 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -98,6 +98,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -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));
}
}

View File

@ -15,12 +15,13 @@
<result property="status" column="status" jdbcType="SMALLINT"/>
<result property="managerId" column="manager_id" jdbcType="BIGINT"/>
<result property="reviewTime" column="review_time" jdbcType="TIMESTAMP"/>
<result property="Time" column="time" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,title,content,
link,type,disaster_id,
create_time,status,manager_id,
review_time
review_time,time
</sql>
</mapper>

View File

@ -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<News> {
* @param type
*/
void export(Long disasterId,Integer type, HttpServletRequest request, HttpServletResponse response);
R importTemplate(MultipartFile file, Integer type, Long disasterId);
}

View File

@ -1,22 +1,34 @@
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;
/**
@ -32,8 +44,11 @@ implements NewsService {
private HotspotService hotspotService;
private SocialMediaMapper socialMediaMapper;
/**
* 新闻热点导出功能
*
* @param disasterId
* @param request
* @param response
@ -65,8 +80,131 @@ implements NewsService {
}
}
@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<Object> row = (List) content.get(i);
if (i != 0) {
if (CollUtil.isNotEmpty(row)) {
String title = ExcelCellUtil.strHandle(row.get(0));
String contentNew = ExcelCellUtil.strHandle(row.get(1));
String link = ExcelCellUtil.strHandle(row.get(2));
String time = ExcelCellUtil.strHandle(row.get(3));
News news = new News();
news.setTitle(title);
news.setContent(contentNew);
news.setLink(link);
news.setTime(time);
news.setCreateTime(new Date());
news.setDisasterId(disasterId);
news.setType(typeData);
news.setStatus(1);
this.baseMapper.insert(news);
}
}
}
} else {
for (int i = 0; i < content.size(); ++i) {
List<Object> row = (List) content.get(i);
if (i != 0) {
if (CollUtil.isNotEmpty(row)) {
String link = ExcelCellUtil.strHandle(row.get(0));
String time = ExcelCellUtil.strHandle(row.get(1));
String contentNew = ExcelCellUtil.strHandle(row.get(2));
String userName = ExcelCellUtil.strHandle(row.get(3));
String favorite_count = ExcelCellUtil.strHandle(row.get(4));
String reply_count = ExcelCellUtil.strHandle(row.get(5));
String visit_count = ExcelCellUtil.strHandle(row.get(6));
String retweet_count = ExcelCellUtil.strHandle(row.get(7));
String geo = ExcelCellUtil.strHandle(row.get(7));
String coordinates = ExcelCellUtil.strHandle(row.get(7));
String place = ExcelCellUtil.strHandle(row.get(7));
String contributors = ExcelCellUtil.strHandle(row.get(7));
String topic = ExcelCellUtil.strHandle(row.get(7));
SocialMedia socialMedia = new SocialMedia();
socialMedia.setCreateTime(new Date());
socialMedia.setDisasterId(disasterId);
if (typeData == 2) {
socialMedia.setType(0);
} else if (typeData == 3) {
socialMedia.setType(1);
}
socialMedia.setLink(link);
if (time != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateStr = null;
try {
dateStr = sdf.parse(time);
} catch (ParseException e) {
return R.fail("时间格式错误");
}
socialMedia.setTime(dateStr);
}
socialMedia.setContent(contentNew);
if (userName != null) {
socialMedia.setUserId(userName);
}
if (favorite_count != null) {
socialMedia.setFavoriteCount(Integer.parseInt(favorite_count));
}
if (reply_count != null) {
socialMedia.setReplyCount(Integer.parseInt(reply_count));
}
if (visit_count != null) {
socialMedia.setVisitCount(Integer.parseInt(visit_count));
}
if (retweet_count != null) {
socialMedia.setRetweetCount(Integer.parseInt(retweet_count));
}
if (geo != null) {
socialMedia.setGeo(geo);
}
if (coordinates != null) {
socialMedia.setCoordinates(coordinates);
}
if (place != null) {
socialMedia.setPlace(place);
}
if (contributors != null) {
socialMedia.setContributors(contributors);
}
if (topic != null) {
}
socialMedia.setTopic(topic);
socialMedia.setStatus(1);
socialMediaMapper.insert(socialMedia);
}
}
}
}
return R.data("上传成功!");
}
/**
* 导出设置
*
* @param response
* @param fileName
* @throws IOException

View File

@ -14,4 +14,4 @@ swagger:
mail:
home:
link: http://192.168.31.77:8888
link: http://39.98.35.99:6400

View File

@ -26,7 +26,7 @@
<docker.password>Harbor12345</docker.password>
<docker.namespace>iot</docker.namespace>
<docker.plugin.version>1.4.13</docker.plugin.version>
<hutool.version>5.8.16</hutool.version>
<hutool.version>5.0.0</hutool.version>
<easyexcel.version>3.2.1</easyexcel.version>
</properties>