|
|
@@ -0,0 +1,134 @@ |
|
|
|
package com.taauav.admin.controller; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.taauav.admin.entity.TauvCategory; |
|
|
|
import com.taauav.admin.entity.TauvInspectImage; |
|
|
|
import com.taauav.admin.mapper.TauvCategoryMapper; |
|
|
|
import com.taauav.admin.mapper.TauvInspectImageMapper; |
|
|
|
import com.taauav.common.util.DateUtil; |
|
|
|
import org.apache.commons.lang3.time.DateUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileReader; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping("/demo") |
|
|
|
public class DemoController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TauvCategoryMapper categoryMapper; |
|
|
|
@Autowired |
|
|
|
private TauvInspectImageMapper inspectImageMapper; |
|
|
|
|
|
|
|
@GetMapping("/index") |
|
|
|
public void index() { |
|
|
|
List<String> stringList = getFiles("E:\\lable2"); |
|
|
|
for (String s : stringList) { |
|
|
|
File file = new File(s); |
|
|
|
String content = txt2String(file); |
|
|
|
Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
|
|
|
Matcher m = p.matcher(content); |
|
|
|
content = m.replaceAll(""); |
|
|
|
System.out.println(content); |
|
|
|
|
|
|
|
String[] strings = content.split(","); |
|
|
|
// 分类 |
|
|
|
String[] categoryArr = strings[0].split("_"); |
|
|
|
// 经纬度 |
|
|
|
String[] strings1 = strings[1].split("_"); |
|
|
|
// 地址 |
|
|
|
String address = strings[2]; |
|
|
|
// 获取文件名称 |
|
|
|
String[] fileName = file.getName().split("\\."); |
|
|
|
|
|
|
|
// 分类入库 |
|
|
|
List<String> categoryIds = new ArrayList<>(); |
|
|
|
for (String s1 : categoryArr) { |
|
|
|
QueryWrapper<TauvCategory> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("name", s1); |
|
|
|
queryWrapper.eq("mark", 1); |
|
|
|
queryWrapper.last("limit 1"); |
|
|
|
TauvCategory categoryInfo = categoryMapper.selectOne(queryWrapper); |
|
|
|
if (categoryInfo != null) { |
|
|
|
categoryIds.add(categoryInfo.getId().toString()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
TauvCategory category = new TauvCategory(); |
|
|
|
category.setName(s1); |
|
|
|
category.setSort(125); |
|
|
|
category.setStatus(1); |
|
|
|
category.setCreateUser(1); |
|
|
|
category.setCreateTime(DateUtil.now()); |
|
|
|
category.setUpdateUser(1); |
|
|
|
category.setUpdateTime(DateUtil.now()); |
|
|
|
categoryMapper.insert(category); |
|
|
|
|
|
|
|
// 分类ID |
|
|
|
categoryIds.add(category.getId().toString()); |
|
|
|
} |
|
|
|
|
|
|
|
TauvInspectImage inspectImage = new TauvInspectImage(); |
|
|
|
inspectImage.setPCategoryId(0); |
|
|
|
inspectImage.setCategoryId(String.join(",", categoryIds)); |
|
|
|
inspectImage.setName("公路"); |
|
|
|
inspectImage.setLongitude(strings1[1]); |
|
|
|
inspectImage.setLatitude(strings1[0]); |
|
|
|
inspectImage.setLocation(address); |
|
|
|
inspectImage.setGaodeLongitude(strings1[1]); |
|
|
|
inspectImage.setGaodeLatitude(strings1[0]); |
|
|
|
inspectImage.setGaodeAddress(address); |
|
|
|
inspectImage.setImage(String.format("/origin/%s.jpg", fileName[0])); |
|
|
|
inspectImage.setHandleImage(String.format("/sign/%s.jpg", fileName[0])); |
|
|
|
inspectImage.setStatus(1); |
|
|
|
inspectImage.setCreateUser(1); |
|
|
|
inspectImage.setCreateTime(DateUtil.now()); |
|
|
|
inspectImage.setUpdateUser(1); |
|
|
|
inspectImage.setUpdateTime(DateUtil.now()); |
|
|
|
inspectImageMapper.insert(inspectImage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static List<String> getFiles(String path) { |
|
|
|
List<String> files = new ArrayList<String>(); |
|
|
|
File file = new File(path); |
|
|
|
File[] tempList = file.listFiles(); |
|
|
|
|
|
|
|
for (int i = 0; i < tempList.length; i++) { |
|
|
|
if (tempList[i].isFile()) { |
|
|
|
files.add(tempList[i].toString()); |
|
|
|
//文件名,不包含路径 |
|
|
|
//String fileName = tempList[i].getName(); |
|
|
|
} |
|
|
|
if (tempList[i].isDirectory()) { |
|
|
|
//这里就不递归了, |
|
|
|
} |
|
|
|
} |
|
|
|
return files; |
|
|
|
} |
|
|
|
|
|
|
|
public static String txt2String(File file) { |
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
try { |
|
|
|
BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件 |
|
|
|
String s = null; |
|
|
|
while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 |
|
|
|
result.append(System.lineSeparator() + s); |
|
|
|
} |
|
|
|
br.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return result.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
} |