Bläddra i källkod

更新

master
麒麟 4 år sedan
förälder
incheckning
4962023e1b
3 ändrade filer med 136 tillägg och 1 borttagningar
  1. +134
    -0
      src/main/java/com/taauav/admin/controller/DemoController.java
  2. +1
    -1
      src/main/java/com/taauav/admin/mapper/TauvInspectImageMapper.xml
  3. +1
    -0
      src/main/java/com/taauav/common/config/ShiroConfig.java

+ 134
- 0
src/main/java/com/taauav/admin/controller/DemoController.java Visa fil

@@ -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();
}

}

+ 1
- 1
src/main/java/com/taauav/admin/mapper/TauvInspectImageMapper.xml Visa fil

@@ -14,7 +14,7 @@
</if>
<!-- 二级分类筛选 -->
<if test="param.categoryId != null and param.categoryId != '' and param.categoryId>0">
and find_in_set(category_id,#{param.categoryId})
and find_in_set(#{param.categoryId},category_id)
</if>
order by id desc
</select>

+ 1
- 0
src/main/java/com/taauav/common/config/ShiroConfig.java Visa fil

@@ -74,6 +74,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/doc.html", "anon");
//前台接口权限 开放
filterChainDefinitionMap.put("/front/**", "anon");
filterChainDefinitionMap.put("/demo/**", "anon");
//APP接口权限 开放
filterChainDefinitionMap.put("/app/login/**", "anon");
// 所有url都必须认证通过才可以访问

Laddar…
Avbryt
Spara