Commit 4a683c28 by Jbb

图层数据上传功能完善

parent d0cffb90
package com.founder.commonutils.viewEntity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_st_layer")
@ApiModel(value="图层对象", description="图层信息数据")
public class TbStLayer {
@TableId(value = "xxzjbh")
private String xxzjbh;
private String name;
private Double threshold;
private String lrr;
private String lrdwdm;
private String lrdwdc;
private Date lrsj;
private String gxr;
private String gxdwdm;
private String gxdwdc;
private Date gxsj;
}
...@@ -10,13 +10,15 @@ import java.util.Date; ...@@ -10,13 +10,15 @@ import java.util.Date;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) @Accessors(chain = true)
@TableName("TB_ST_LAYER_DATA") @TableName("tb_st_layer_data")
@ApiModel(value="图层数据对象", description="图层数据") @ApiModel(value="图层数据对象", description="图层数据")
public class TbStLayerData implements Serializable { public class TbStLayerData implements Serializable {
private String xxzjbh; private String xxzjbh;
private String gl_xxzjbh; private String gl_xxzjbh;
private double x; //经度 private double x; //经度
private double y; //纬度 private double y; //纬度
private String xStr; //保存错误的经度
private String yStr; //保存错误的纬度
private String title; //事故提示 private String title; //事故提示
private Date time; //事故时间 private Date time; //事故时间
...@@ -52,6 +54,22 @@ public class TbStLayerData implements Serializable { ...@@ -52,6 +54,22 @@ public class TbStLayerData implements Serializable {
this.y = y; this.y = y;
} }
public String getxStr() {
return xStr;
}
public void setxStr(String xStr) {
this.xStr = xStr;
}
public String getyStr() {
return yStr;
}
public void setyStr(String yStr) {
this.yStr = yStr;
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
......
...@@ -16,12 +16,12 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; ...@@ -16,12 +16,12 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver;
@Configuration @Configuration
@MapperScan(basePackages = {"com.founder.view.mapper"}, /*@MapperScan(basePackages = {"com.founder.view.mapper"},
sqlSessionTemplateRef = "xzxtSqlTemplate") sqlSessionTemplateRef = "xzxtSqlTemplate")*/
public class MybatisBaseDbConfig { public class MybatisBaseDbConfig {
@Bean(name = "xzxtdbDatasource") /*@Bean(name = "xzxtdbDatasource")
@ConfigurationProperties(prefix = "spring.datasource.xzxtdb") @ConfigurationProperties(prefix = "spring.datasource.xzxtdb")
public DruidDataSource druidXzxtdbDatasource() public DruidDataSource druidXzxtdbDatasource()
{ {
...@@ -51,5 +51,5 @@ public class MybatisBaseDbConfig { ...@@ -51,5 +51,5 @@ public class MybatisBaseDbConfig {
SqlSessionFactory sqlSessionFactory) SqlSessionFactory sqlSessionFactory)
{ {
return new SqlSessionTemplate(sqlSessionFactory); return new SqlSessionTemplate(sqlSessionFactory);
} }*/
} }
...@@ -15,11 +15,11 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; ...@@ -15,11 +15,11 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver;
@Configuration @Configuration
@MapperScan(basePackages = {"com.founder.view.qgxzMapper"}, /*@MapperScan(basePackages = {"com.founder.view.qgxzMapper"},
sqlSessionTemplateRef = "qgSqlTemplate") sqlSessionTemplateRef = "qgSqlTemplate")*/
public class MybatisQgDbConfig { public class MybatisQgDbConfig {
@Bean(name = "qgdbDatasource") /* @Bean(name = "qgdbDatasource")
@ConfigurationProperties(prefix = "spring.datasource.qgdb") @ConfigurationProperties(prefix = "spring.datasource.qgdb")
public DruidDataSource druidQgdbDatasource() public DruidDataSource druidQgdbDatasource()
{ {
...@@ -43,5 +43,5 @@ public class MybatisQgDbConfig { ...@@ -43,5 +43,5 @@ public class MybatisQgDbConfig {
SqlSessionFactory sqlSessionFactory) SqlSessionFactory sqlSessionFactory)
{ {
return new SqlSessionTemplate(sqlSessionFactory); return new SqlSessionTemplate(sqlSessionFactory);
} }*/
} }
...@@ -3,12 +3,12 @@ package com.founder.view.controller; ...@@ -3,12 +3,12 @@ package com.founder.view.controller;
import com.founder.commonutils.publicEntity.MapRestResult; import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.util.KeyUtil; import com.founder.commonutils.util.KeyUtil;
import com.founder.commonutils.util.LngLonUtil; import com.founder.commonutils.util.LngLonUtil;
import com.founder.commonutils.viewEntity.TbStLayer;
import com.founder.commonutils.viewEntity.TbStLayerData; import com.founder.commonutils.viewEntity.TbStLayerData;
import com.founder.view.service.TbStLayerDataService; import com.founder.view.service.TbStLayerDataService;
import com.founder.view.service.TbStLayerService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
...@@ -20,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -20,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -27,55 +28,76 @@ import java.util.ArrayList; ...@@ -27,55 +28,76 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@Api(description = "经纬度上传") @Api(description = "图层数据上传")
@RestController @RestController
@RequestMapping("/xy") @RequestMapping("/tbStLayerData")
public class TbStLayerDataController { public class TbStLayerDataController {
@Resource @Resource
TbStLayerDataService accidentPointService; TbStLayerDataService accidentPointService;
@Resource
TbStLayerService tbStLayerService;
@RequestMapping("/uploadExcel") @RequestMapping("/uploadExcel")
public MapRestResult uploadDown(@RequestParam("excelFile") MultipartFile excelFile, HttpServletResponse response) { public MapRestResult uploadDown(@RequestParam("excelFile") MultipartFile excelFile,
@RequestParam(required = false) String name,@RequestParam(required = false) Double threshold,
@RequestParam(required = false) String lrr,@RequestParam(required = false) String lrdwdm,
@RequestParam(required = false) String lrdwdc, HttpServletResponse response) {
TbStLayer tbStLayer = new TbStLayer();
String layerId = KeyUtil.getUUIDKey("L");
try { try {
tbStLayer.setXxzjbh(layerId);
tbStLayer.setName(name);
tbStLayer.setThreshold(threshold);
tbStLayer.setLrr(lrr);
tbStLayer.setLrdwdm(lrdwdm);
tbStLayer.setLrdwdc(lrdwdc);
tbStLayer.setLrsj(new Date());
tbStLayerService.save(tbStLayer);
InputStream is = excelFile.getInputStream(); InputStream is = excelFile.getInputStream();
//InputStream is = new FileInputStream("C:\\Users\\JBB\\Desktop\\工作目录\\excel\\error (5).xlsx");
XSSFWorkbook sheets = new XSSFWorkbook(is); XSSFWorkbook sheets = new XSSFWorkbook(is);
XSSFSheet sheetAt = sheets.getSheetAt(0); XSSFSheet sheetAt = sheets.getSheetAt(0);
//获取excel有多少行 //获取excel有多少行
int lastRowNum = sheetAt.getLastRowNum(); int lastRowNum = sheetAt.getLastRowNum();
List<TbStLayerData> pointList = new ArrayList<>(); List<TbStLayerData> pointList = new ArrayList<>();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String id = "";
for (int i = 1; i <= lastRowNum; i++) { for (int i = 1; i <= lastRowNum; i++) {
TbStLayerData point = new TbStLayerData(); TbStLayerData point = new TbStLayerData();
String id = KeyUtil.getUUIDKey("xy"); id = KeyUtil.getUUIDKey("D");
point.setXxzjbh(id); point.setXxzjbh(id);
point.setGl_xxzjbh(id); point.setGl_xxzjbh(layerId);
XSSFRow row = sheetAt.getRow(i); XSSFRow row = sheetAt.getRow(i);
//获取excel有多少列 //获取excel有多少列
short lastCellNum = row.getLastCellNum(); short lastCellNum = row.getLastCellNum();
//判断经纬度是否符合要求 //判断经纬度是否符合要求
//检车一下数据是否能正常读取..... //检车一下数据是否能正常读取..... 这里忘记了 设置单元格格式了
/*double jd = 0.0; /*double jd = 0.0;
double wd = 0.0; double wd = 0.0;
String titleStr = ""; String titleStr = "";
String dateStr = ""; String dateStr = "";
if(row.getCell(0) != null && row.getCell(1) != null){ if(row.getCell(0) != null && row.getCell(1) != null){
jd = row.getCell(0).getNumericCellValue(); jd = Double.parseDouble(row.getCell(0).getStringCellValue());
wd = row.getCell(1).getNumericCellValue(); wd = Double.parseDouble(row.getCell(1).getStringCellValue());
titleStr = row.getCell(2).getStringCellValue(); titleStr = row.getCell(2).getStringCellValue();
dateStr = row.getCell(3).getStringCellValue(); dateStr = row.getCell(3).getStringCellValue();
System.out.println(jd + "==========" + wd + "=========" + titleStr + "=========" + dateStr); System.out.println(jd + "====" + wd + "====" + titleStr + "====" + dateStr);
}*/ }*/
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
try { try {
//验证经纬度是否是八位小数以内 //验证经纬度是否是八位小数以内
boolean isTrue = LngLonUtil.verifyLongAndLat(row.getCell(0).getNumericCellValue(), row.getCell(1).getNumericCellValue()); boolean isTrue = LngLonUtil.verifyLongAndLat(Double.parseDouble(row.getCell(0).getStringCellValue()), Double.parseDouble(row.getCell(1).getStringCellValue()));
if(isTrue){//这里可以不用for循环 因为excel列数比较少 if(isTrue){//这里可以不用for循环 因为excel列数比较少
for (int j = 0; j < lastCellNum; j++) { for (int j = 0; j < lastCellNum; j++) {
if(j == 0){ if(j == 0){
double x = row.getCell(0).getNumericCellValue(); double x = Double.parseDouble(row.getCell(0).getStringCellValue());
point.setX(x); point.setX(x);
} }
if(j == 1){ if(j == 1){
double y = row.getCell(1).getNumericCellValue(); double y = Double.parseDouble(row.getCell(1).getStringCellValue());
point.setY(y); point.setY(y);
} }
if(j == 2){ if(j == 2){
...@@ -93,13 +115,17 @@ public class TbStLayerDataController { ...@@ -93,13 +115,17 @@ public class TbStLayerDataController {
//经度小数点后超过了八位 //经度小数点后超过了八位
double x = 0; double x = 0;
double y = 0; double y = 0;
if(row.getCell(0).getNumericCellValue() + "" .length() > 12){ if(row.getCell(0).getStringCellValue().length() > 12){
String xStr = row.getCell(0).getNumericCellValue() + "".substring(0, 12); String xStr = row.getCell(0).getStringCellValue().substring(0,12);
x = Double.parseDouble(xStr); x = Double.parseDouble(xStr);
}else{
x = Double.parseDouble(row.getCell(0).getStringCellValue());
} }
if(row.getCell(1).getNumericCellValue() + "" .length() > 11){ if(row.getCell(1).getStringCellValue().length() > 11){
String yStr = row.getCell(0).getNumericCellValue() + "".substring(0, 11); String yStr = row.getCell(1).getStringCellValue().substring(0, 11);
y = Double.parseDouble(yStr); y = Double.parseDouble(yStr);
}else{
y = Double.parseDouble(row.getCell(1).getStringCellValue());
} }
for (int j = 0; j < lastCellNum; j++) { for (int j = 0; j < lastCellNum; j++) {
if(j == 0){ if(j == 0){
...@@ -123,30 +149,34 @@ public class TbStLayerDataController { ...@@ -123,30 +149,34 @@ public class TbStLayerDataController {
accidentPointService.save(point); accidentPointService.save(point);
} }
} catch (Exception e) { } catch (Exception e) {
//具体的错误数据保存到这里 //具体的错误数据保存到这里 这里就不输出错误信息了
//e.printStackTrace(); //e.printStackTrace();
pointList.add(point); TbStLayerData errorData = new TbStLayerData();
errorData.setxStr(row.getCell(0).getStringCellValue());
errorData.setyStr(row.getCell(1).getStringCellValue());
errorData.setTitle(row.getCell(2).getStringCellValue());
errorData.setTime(df.parse(row.getCell(3).getStringCellValue()));
pointList.add(errorData);
} }
} }
if(pointList != null && pointList.size() > 0){
//输出流写入到excel中 //输出流写入到excel中
HSSFWorkbook wb = new HSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
HSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
//给个标题头 //给个标题头
HSSFRow rowTitle = sheet.createRow(0); XSSFRow rowTitle = sheet.createRow(0);
rowTitle.createCell(0).setCellValue("经度"); rowTitle.createCell(0).setCellValue("经度");
rowTitle.createCell(1).setCellValue("纬度"); rowTitle.createCell(1).setCellValue("纬度");
rowTitle.createCell(2).setCellValue("标题"); rowTitle.createCell(2).setCellValue("标题");
rowTitle.createCell(3).setCellValue("时间"); rowTitle.createCell(3).setCellValue("时间");
for (int i = 0; i < pointList.size(); i++) { for (int i = 0; i < pointList.size(); i++) {
TbStLayerData accidentPoint = pointList.get(i); TbStLayerData accidentPoint = pointList.get(i);
double lon = accidentPoint.getX();
double lat = accidentPoint.getY();
String title = accidentPoint.getTitle(); String title = accidentPoint.getTitle();
Date time = accidentPoint.getTime(); Date time = accidentPoint.getTime();
String timeFormat = df.format(time); String timeFormat = df.format(time);
HSSFRow rowData = sheet.createRow(i + 1); XSSFRow rowData = sheet.createRow(i + 1);
rowData.createCell(0).setCellValue(lon); rowData.createCell(0).setCellValue(accidentPoint.getxStr());
rowData.createCell(1).setCellValue(lat); rowData.createCell(1).setCellValue(accidentPoint.getyStr());
rowData.createCell(2).setCellValue(title); rowData.createCell(2).setCellValue(title);
rowData.createCell(3).setCellValue(timeFormat); rowData.createCell(3).setCellValue(timeFormat);
} }
...@@ -154,14 +184,18 @@ public class TbStLayerDataController { ...@@ -154,14 +184,18 @@ public class TbStLayerDataController {
ServletOutputStream outputStream = response.getOutputStream(); ServletOutputStream outputStream = response.getOutputStream();
//设置文件响应输出格式 //设置文件响应输出格式
response.setContentType("application/vnd.ms-excel"); response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=error.xls"); response.setHeader("Content-Disposition", "attachment;filename=error.xlsx");
wb.write(outputStream); wb.write(outputStream);
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
wb.close(); }
return MapRestResult.build(200,"数据上传成功!",null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
//如果失败了就将之前的数据删除....
tbStLayerService.removeById(layerId);
accidentPointService.deleteByGlId(layerId);
return MapRestResult.build(500,"数据上传失败!",null);
} }
return MapRestResult.build(200,"数据上传成功!",null);
} }
} }
...@@ -16,4 +16,6 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -16,4 +16,6 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface TbStLayerDataMapper extends BaseMapper<TbStLayerData> { public interface TbStLayerDataMapper extends BaseMapper<TbStLayerData> {
void deleteByGlId(String layerId);
} }
...@@ -2,8 +2,8 @@ package com.founder.view.mapper; ...@@ -2,8 +2,8 @@ package com.founder.view.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.founder.commonutils.publicEntity.SysUser; import com.founder.commonutils.viewEntity.TbStLayer;
import com.founder.commonutils.viewEntity.AccidentPoint; import com.founder.commonutils.viewEntity.TbStLayerData;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
...@@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
* @since 2021-03-11 * @since 2021-03-11
*/ */
@Mapper @Mapper
public interface AccidentPointMapper extends BaseMapper<AccidentPoint> { public interface TbStLayerMapper extends BaseMapper<TbStLayer> {
} }
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.founder.view.mapper.TbStLayerDataMapper"> <mapper namespace="com.founder.view.mapper.TbStLayerDataMapper">
<delete id="deleteByGlId" parameterType="String">
delete from tb_st_layer_data where gl_xxzjbh = #{layerId}
</delete>
</mapper> </mapper>
<?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.founder.view.mapper.TbStLayerMapper">
</mapper>
...@@ -4,4 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,4 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.founder.commonutils.viewEntity.TbStLayerData; import com.founder.commonutils.viewEntity.TbStLayerData;
public interface TbStLayerDataService extends IService<TbStLayerData> { public interface TbStLayerDataService extends IService<TbStLayerData> {
void deleteByGlId(String layerId);
} }
package com.founder.view.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.founder.commonutils.viewEntity.TbStLayer;
import com.founder.commonutils.viewEntity.TbStLayerData;
public interface TbStLayerService extends IService<TbStLayer> {
}
...@@ -6,7 +6,15 @@ import com.founder.view.mapper.TbStLayerDataMapper; ...@@ -6,7 +6,15 @@ import com.founder.view.mapper.TbStLayerDataMapper;
import com.founder.view.service.TbStLayerDataService; import com.founder.view.service.TbStLayerDataService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service @Service
public class TbStLayerDataServiceImpl extends ServiceImpl<TbStLayerDataMapper, TbStLayerData> implements TbStLayerDataService { public class TbStLayerDataServiceImpl extends ServiceImpl<TbStLayerDataMapper, TbStLayerData> implements TbStLayerDataService {
@Resource
TbStLayerDataMapper tbStLayerDataMapper;
@Override
public void deleteByGlId(String layerId) {
tbStLayerDataMapper.deleteByGlId(layerId);
}
} }
package com.founder.view.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.commonutils.viewEntity.TbStLayer;
import com.founder.commonutils.viewEntity.TbStLayerData;
import com.founder.view.mapper.TbStLayerDataMapper;
import com.founder.view.mapper.TbStLayerMapper;
import com.founder.view.service.TbStLayerDataService;
import com.founder.view.service.TbStLayerService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class TbStLayerServiceImpl extends ServiceImpl<TbStLayerMapper, TbStLayer> implements TbStLayerService {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment