Commit ee86a608 by Jbb

删除多余的代码 config包下的代码没有删除

parent 037b5fc4
package com.founder.commonutils.viewEntity;
import java.io.Serializable;
import java.util.Date;
public class AccidentPoint implements Serializable {
private String xxzjbh;
private double lat; //纬度
private double lon; //经度
private String title; //事故提示
private Date time; //事故时间
public String getXxzjbh() {
return xxzjbh;
}
public void setXxzjbh(String xxzjbh) {
this.xxzjbh = xxzjbh;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
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;
}
}
package com.founder.view;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableSwagger2
@MapperScan(basePackages = "com.founder.view.mapper")
public class ViewApplication {
public static void main(String[] args) {
......
......@@ -15,7 +15,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
@Configuration
@MapperScan(basePackages = {"com.founder.asj.qgxzMapper"},
@MapperScan(basePackages = {"com.founder.view.qgxzMapper"},
sqlSessionTemplateRef = "qgSqlTemplate")
public class MybatisQgDbConfig {
......
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.AccidentPoint;
import com.founder.view.service.AccidentPointService;
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 AccidentPointController {
@Resource
AccidentPointService 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<AccidentPoint> pointList = new ArrayList<>();
for (int i = 1; i <= lastRowNum; i++) {
AccidentPoint point = new AccidentPoint();
String id = KeyUtil.getUUIDKey("xy");
point.setXxzjbh(id);
XSSFRow row = sheetAt.getRow(i);
//获取excel有多少列
short lastCellNum = row.getLastCellNum();
//判断经纬度是否符合要求
//检车一下数据是否能正常读取.....
/*double x = 0.0;
double y = 0.0;
String title = "";
String dateTime = "";
if(row.getCell(0) != null && row.getCell(1) != null){
x = row.getCell(0).getNumericCellValue();
y = row.getCell(1).getNumericCellValue();
title = row.getCell(2).getStringCellValue();
dateTime = row.getCell(3).getStringCellValue();
System.out.println(x + "==========" + y + "=========" + title + "=========" + dateTime);
}*/
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.setLon(x);
}
if(j == 1){
double y = row.getCell(1).getNumericCellValue();
point.setLat(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);
}
}
}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.setLon(x);
}
if(j == 1){
//y = row.getCell(1).getNumericCellValue();
point.setLat(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++) {
AccidentPoint accidentPoint = pointList.get(i);
double lon = accidentPoint.getLon();
double lat = accidentPoint.getLat();
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.ok();
}
}
......@@ -3,6 +3,7 @@ package com.founder.view.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.founder.commonutils.publicEntity.SysUser;
import com.founder.commonutils.viewEntity.AccidentPoint;
import org.apache.ibatis.annotations.Mapper;
/**
......@@ -14,6 +15,6 @@ import org.apache.ibatis.annotations.Mapper;
* @since 2021-03-11
*/
@Mapper
public interface SysUsersMapper extends BaseMapper<SysUser> {
public interface AccidentPointMapper extends BaseMapper<AccidentPoint> {
}
<?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.SysUsersMapper">
<mapper namespace="com.founder.view.mapper.AccidentPointMapper">
</mapper>
package com.founder.view.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.founder.commonutils.viewEntity.AccidentPoint;
public interface AccidentPointService extends IService<AccidentPoint> {
}
package com.founder.view.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.commonutils.viewEntity.AccidentPoint;
import com.founder.view.mapper.AccidentPointMapper;
import com.founder.view.service.AccidentPointService;
import org.springframework.stereotype.Service;
@Service
public class AccidentPointServiceImpl extends ServiceImpl<AccidentPointMapper, AccidentPoint> implements AccidentPointService {
}
......@@ -9,12 +9,12 @@ spring.profiles.active=dev
# 该配置影响统一配置中心中的dataId
spring.application.name=view
spring.cloud.nacos.config.namespace=dev
spring.cloud.nacos.config.namespace=f1160b5f-cef5-4e86-bddc-c55e28c2d8b0
#spring.cloud.nacos.config.ext-config[0].data-id=image.properties
# 开启动态刷新配置,否则配置文件修改,工程无法感知
#spring.cloud.nacos.config.ext-config[0].refresh=true
spring.cloud.nacos.config.shared-dataids=view-dev.yml
spring.cloud.nacos.config.refreshable-dataids=view-dev.yml
spring.cloud.nacos.config.shared-dataids=view-dev.properties
spring.cloud.nacos.config.refreshable-dataids=view-dev.properties
management.health.elasticsearch.enabled: false
\ No newline at end of file
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