Commit 0b663726 by Jbb

代码健壮性的考虑

parent e4a43ce2
......@@ -22,11 +22,11 @@ public class TbStLayer extends PageInfo {
private Double threshold;
private String lrr;
private String lrdwdm;
private String lrdwdc;
private String lrdwmc;
private Date lrsj;
private String gxr;
private String gxdwdm;
private String gxdwdc;
private String gxdwmc;
private Date gxsj;
private List<TbStLayerData> stLayerDataList;
private String startTime;
......
......@@ -48,14 +48,14 @@ public class TbStLayerDataController {
* @param threshold
* @param lrr
* @param lrdwdm
* @param lrdwdc
* @param lrdwmc
* @return
*/
@RequestMapping("/uploadExcel")
public MapRestResult uploadDown(@RequestParam("excelFile") MultipartFile excelFile,@RequestParam(required = false) String xxzjbh,
@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) {
@RequestParam(required = false) String lrdwmc) {
TbStLayer tbStLayer = new TbStLayer();
List<TbStLayerData> pointLists = null;
String layerId = xxzjbh;
......@@ -71,7 +71,7 @@ public class TbStLayerDataController {
tbStLayer.setThreshold(threshold);
tbStLayer.setLrr(lrr);
tbStLayer.setLrdwdm(lrdwdm);
tbStLayer.setLrdwdc(lrdwdc);
tbStLayer.setLrdwmc(lrdwmc);
tbStLayer.setLrsj(new Date());
tbStLayerService.save(tbStLayer);
is = excelFile.getInputStream();
......@@ -84,7 +84,7 @@ public class TbStLayerDataController {
}
return MapRestResult.build(200,"数据上传成功!",pointLists);
} catch (Exception e) {
e.printStackTrace();
//e.printStackTrace();
//如果保存数据、poi生成excel失败了就将之前的数据删除....
tbStLayerService.removeById(layerId);
accidentPointService.deleteByGlId(layerId);
......@@ -123,29 +123,32 @@ public class TbStLayerDataController {
dateStr = row.getCell(3).getStringCellValue();
System.out.println(jd + "====" + wd + "====" + titleStr + "====" + dateStr);
}*/
//经纬度不能为空 否则报错 每一行都判断单元格是否为空 设置单元格格式 是因为不知道哪一个会为空
if (row.getCell(0) != null && row.getCell(1) != null) {
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 {
//验证经纬度是否是八位小数以内
boolean isTrue = LngLonUtil.verifyLongAndLat(Double.parseDouble(row.getCell(0).getStringCellValue()), Double.parseDouble(row.getCell(1).getStringCellValue()));
if (isTrue) {//这里可以不用for循环 因为excel列数比较少
for (int j = 0; j < lastCellNum; j++) {
if (j == 0) {
if (j == 0 && row.getCell(0) != null) {
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
double x = Double.parseDouble(row.getCell(0).getStringCellValue());
point.setX(x);
}
if (j == 1) {
if (j == 1 && row.getCell(1) != null) {
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
double y = Double.parseDouble(row.getCell(1).getStringCellValue());
point.setY(y);
}
if (j == 2) {
if (j == 2 && row.getCell(2) != null) {
row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
String title = row.getCell(2).getStringCellValue();
point.setTitle(title);
}
if (j == 3) {
if (j == 3 && row.getCell(3) != null) {
row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
String dateTimeStr = row.getCell(3).getStringCellValue();
if(dateTimeStr != ""){
Date dateTime = df.parse(dateTimeStr);
......@@ -172,19 +175,21 @@ public class TbStLayerDataController {
y = Double.parseDouble(row.getCell(1).getStringCellValue());
}
for (int j = 0; j < lastCellNum; j++) {
if (j == 0) {
if (j == 0 && row.getCell(0) != null) {
//x = row.getCell(0).getNumericCellValue();
point.setX(x);
}
if (j == 1) {
if (j == 1 && row.getCell(1) != null) {
//y = row.getCell(1).getNumericCellValue();
point.setY(y);
}
if (j == 2) {
if (j == 2 && row.getCell(2) != null) {
row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
String title = row.getCell(2).getStringCellValue();
point.setTitle(title);
}
if (j == 3) {
if (j == 3 && row.getCell(3) != null) {
row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
String dateTimeStr = row.getCell(3).getStringCellValue();
if(dateTimeStr != ""){
Date dateTime = df.parse(dateTimeStr);
......
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