Commit e1d15369 by Jbb

pom中缺少mybatis中xml的配置

parent ee86a608
package com.founder.commonutils.viewEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("TB_ST_LAYER_DATA")
@ApiModel(value="图层数据对象", description="图层数据")
public class TbStLayerData implements Serializable {
private String xxzjbh;
private String gl_xxzjbh;
private double x; //经度
private double y; //纬度
private String title; //事故提示
private Date time; //事故时间
public String getXxzjbh() {
return xxzjbh;
}
public void setXxzjbh(String xxzjbh) {
this.xxzjbh = xxzjbh;
}
public String getGl_xxzjbh() {
return gl_xxzjbh;
}
public void setGl_xxzjbh(String gl_xxzjbh) {
this.gl_xxzjbh = gl_xxzjbh;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
}
......@@ -14,4 +14,6 @@
<finalName>view</finalName>
</build>
</project>
\ No newline at end of file
package com.founder.view.controller;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.util.KeyUtil;
import com.founder.commonutils.util.LngLonUtil;
import com.founder.commonutils.viewEntity.TbStLayerData;
import com.founder.view.service.TbStLayerDataService;
import io.swagger.annotations.Api;
import org.apache.poi.hssf.usermodel.HSSFRow;
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.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Api(description = "经纬度上传")
@RestController
@RequestMapping("/xy")
public class TbStLayerDataController {
@Resource
TbStLayerDataService accidentPointService;
@RequestMapping("/uploadExcel")
public MapRestResult uploadDown(@RequestParam("excelFile") MultipartFile excelFile, HttpServletResponse response) {
try {
InputStream is = excelFile.getInputStream();
XSSFWorkbook sheets = new XSSFWorkbook(is);
XSSFSheet sheetAt = sheets.getSheetAt(0);
//获取excel有多少行
int lastRowNum = sheetAt.getLastRowNum();
List<TbStLayerData> pointList = new ArrayList<>();
for (int i = 1; i <= lastRowNum; i++) {
TbStLayerData point = new TbStLayerData();
String id = KeyUtil.getUUIDKey("xy");
point.setXxzjbh(id);
point.setGl_xxzjbh(id);
XSSFRow row = sheetAt.getRow(i);
//获取excel有多少列
short lastCellNum = row.getLastCellNum();
//判断经纬度是否符合要求
//检车一下数据是否能正常读取.....
double jd = 0.0;
double wd = 0.0;
String titleStr = "";
String dateStr = "";
if(row.getCell(0) != null && row.getCell(1) != null){
jd = row.getCell(0).getNumericCellValue();
wd = row.getCell(1).getNumericCellValue();
titleStr = row.getCell(2).getStringCellValue();
dateStr = row.getCell(3).getStringCellValue();
System.out.println(jd + "==========" + wd + "=========" + titleStr + "=========" + dateStr);
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
//验证经纬度是否是八位小数以内
boolean isTrue = LngLonUtil.verifyLongAndLat(row.getCell(0).getNumericCellValue(), row.getCell(1).getNumericCellValue());
if(isTrue){//这里可以不用for循环 因为excel列数比较少
for (int j = 0; j < lastCellNum; j++) {
if(j == 0){
double x = row.getCell(0).getNumericCellValue();
point.setX(x);
}
if(j == 1){
double y = row.getCell(1).getNumericCellValue();
point.setY(y);
}
if(j == 2){
String title = row.getCell(2).getStringCellValue();
point.setTitle(title);
}
if(j == 3){
String dateTimeStr = row.getCell(3).getStringCellValue();
Date dateTime = df.parse(dateTimeStr);
point.setTime(dateTime);
}
}
accidentPointService.save(point);
}else {
//经度小数点后超过了八位
double x = 0;
double y = 0;
if(row.getCell(0).getNumericCellValue() + "" .length() > 12){
String xStr = row.getCell(0).getNumericCellValue() + "".substring(0, 12);
x = Double.parseDouble(xStr);
}
if(row.getCell(1).getNumericCellValue() + "" .length() > 11){
String yStr = row.getCell(0).getNumericCellValue() + "".substring(0, 11);
y = Double.parseDouble(yStr);
}
for (int j = 0; j < lastCellNum; j++) {
if(j == 0){
//x = row.getCell(0).getNumericCellValue();
point.setX(x);
}
if(j == 1){
//y = row.getCell(1).getNumericCellValue();
point.setY(y);
}
if(j == 2){
String title = row.getCell(2).getStringCellValue();
point.setTitle(title);
}
if(j == 3){
String dateTimeStr = row.getCell(3).getStringCellValue();
Date dateTime = df.parse(dateTimeStr);
point.setTime(dateTime);
}
}
accidentPointService.save(point);
}
} catch (Exception e) {
//具体的错误数据保存到这里
//e.printStackTrace();
pointList.add(point);
}
}
//输出流写入到excel中
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
//给个标题头
HSSFRow rowTitle = sheet.createRow(0);
rowTitle.createCell(0).setCellValue("经度");
rowTitle.createCell(1).setCellValue("纬度");
rowTitle.createCell(2).setCellValue("标题");
rowTitle.createCell(3).setCellValue("时间");
for (int i = 0; i < pointList.size(); i++) {
TbStLayerData accidentPoint = pointList.get(i);
double lon = accidentPoint.getX();
double lat = accidentPoint.getY();
String title = accidentPoint.getTitle();
Date time = accidentPoint.getTime();
HSSFRow rowData = sheet.createRow(i + 1);
rowData.createCell(0).setCellValue(lon);
rowData.createCell(1).setCellValue(lat);
rowData.createCell(2).setCellValue(title);
rowData.createCell(3).setCellValue(time);
}
//通过输出流下载
ServletOutputStream outputStream = response.getOutputStream();
//设置文件响应输出格式
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=error.xls");
wb.write(outputStream);
outputStream.flush();
outputStream.close();
wb.close();
} catch (Exception e) {
e.printStackTrace();
}
return MapRestResult.build(200,"数据上传成功!",null);
}
}
package com.founder.view.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.founder.commonutils.viewEntity.TbStLayerData;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 用户登录 Mapper 接口
* </p>
*
* @author yy
* @since 2021-03-11
*/
@Mapper
public interface TbStLayerDataMapper extends BaseMapper<TbStLayerData> {
}
<?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.TbStLayerDataMapper">
</mapper>
package com.founder.view.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.founder.commonutils.viewEntity.TbStLayerData;
public interface TbStLayerDataService extends IService<TbStLayerData> {
}
package com.founder.view.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.commonutils.viewEntity.TbStLayerData;
import com.founder.view.mapper.TbStLayerDataMapper;
import com.founder.view.service.TbStLayerDataService;
import org.springframework.stereotype.Service;
@Service
public class TbStLayerDataServiceImpl extends ServiceImpl<TbStLayerDataMapper, TbStLayerData> implements TbStLayerDataService {
}
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