工业测量

This commit is contained in:
2022-02-12 08:48:57 +08:00
commit 92b683a7a4
48 changed files with 3291 additions and 0 deletions

View File

@ -0,0 +1,191 @@
package com.xkrs.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @author XinYi Song
*/
public class ExcelUploadUtil {
public static Logger log = LoggerFactory.getLogger(ExcelUploadUtil.class);
/**
* 上传单张图片
* @param fileExcel
* @return
* @throws IOException
*/
public static String memoryFile(MultipartFile fileExcel) throws IOException {
//String uploadPath = "http://139.199.98.175:2088/wfTaskImage/";
String uploadPath = "http://192.168.2.9:2088/";
//获取原始文件名
String originalFilename = fileExcel.getOriginalFilename();
if (originalFilename != null && !"".equals(originalFilename)) {
//找到 . 的位置
int index = originalFilename.lastIndexOf(".");
//根据 . 的位置进行分割,拿到文件后缀名
String suffix = originalFilename.substring(index);
//uuid生成新的文件名
String newName = UUID.randomUUID().toString() + suffix;
//将图片保存到本地/usr/etc/images/Folder
//File file = new File("E:/shoptest/");
File file = new File("/home/sxy/server/industrial_measurement/excel/");
if (!file.exists()) {
file.mkdirs();
}
//String path = "E:/shoptest/" + newName;
String path = "/home/sxy/server/industrial_measurement/excel/" + newName;
String uploadsImage = uploadPath + newName;
//实现上传
fileExcel.transferTo(new File(path));
return path;
}
return null;
}
/**
* 以文件形式,批量上传图片
* @param files
* @return
* @throws IOException
*/
/*public static List<FireTaskPhoto> uploadImage(MultipartFile[] files, String fireCode) throws IOException {
//String uploadPath = "http://139.199.98.175:2099/forestTaskImage/";
String uploadPath = "http://118.24.27.47:2088/";
String newName = "";
String oldName = "";
List<FireTaskPhoto> fireTaskPhotos = new ArrayList<>();
for(MultipartFile file : files){
//获取file图片名称
oldName = file.getOriginalFilename();
//找到 . 的位置
int index = oldName.lastIndexOf(".");
//根据 . 的位置进行分割,拿到文件后缀名
String suffix = oldName.substring(index);
//uuid生成新的文件名
newName = UUID.randomUUID().toString() + suffix;
//将图片保存到本地/usr/etc/images/Folder
File file1 = new File("/home/sxy/server/fire_point/firePointImage/");
//File file1 = new File("E:/file/work/image/");
if (!file1.exists()) {
file1.mkdirs();
}
String path = "/home/sxy/server/fire_point/firePointImage/" + newName;
//String path = "E:/file/work/image/" + newName;
String uploadPaths = "/firePointImage/" + newName;
//实现上传
file.transferTo(new File(path));
FireTaskPhoto fireTaskPhoto = new FireTaskPhoto();
fireTaskPhoto.setPhotoFireCode(fireCode);
fireTaskPhoto.setTaskPhoto(uploadPaths);
fireTaskPhotos.add(fireTaskPhoto);
}
return fireTaskPhotos;
}*/
/**
* 删除本地或服务器储存的图片
* @param path
* @return
*/
public static String delFile(String path){
String resultInfo = null;
int lastIndexOf = path.lastIndexOf("/");
String imgPath = path.substring(lastIndexOf + 1,path.length());
System.out.println(imgPath);
imgPath = "/usr/local/etc/images/" + imgPath;
// img_path = "/usr/etc/images/Folder/" + img_path;
File file = new File(imgPath);
if(file.exists()){
if(file.delete()){
resultInfo = "删除成功!";
}else {
resultInfo = "删除失败!";
}
}else {
resultInfo = "文件不存在";
}
return resultInfo;
}
/**
* 通过图片路径解析 ,上传保存
* @param listImgSrc
* @return
*/
public static List downloadImage(List<String> listImgSrc) {
try {
List list = new ArrayList();
//开始时间
Date beginDate = new Date();
for (String url : listImgSrc) {
//开始时间
Date beginDate2 = new Date();
String imageName = url.substring(url.lastIndexOf("/") + 1, url.length());
URL uri = new URL(url);
InputStream in = uri.openStream();
//String pathUpload = "E:/img/" + imageName;
String pathUpload = "/home/web/wf-fire-service/wfimage/" + imageName;
FileOutputStream fo = new FileOutputStream(new File(pathUpload));
byte[] buf = new byte[1024];
int length = 0;
log.info("-------开始下载:" + url);
while ((length = in.read(buf, 0, buf.length)) != -1) {
fo.write(buf, 0, length);
}
in.close();
fo.close();
list.add(imageName);
log.info(imageName + "------下载完成");
//结束时间
Date overDate2 = new Date();
double time = overDate2.getTime() - beginDate2.getTime();
log.info("-----耗时:" + time / 1000 + "s");
}
Date overDate = new Date();
double time = overDate.getTime() - beginDate.getTime();
log.info("======总耗时:" + time / 1000 + "s");
return list;
} catch (Exception e) {
log.info("++++++下载失败");
}
return null;
}
/**
* 删除本地文件夹图片
* @param url
*/
public static void deleteImage(String url){
File file=new File(url);
//判断file是否是文件目录 若是返回TRUE
if (file.isDirectory()){
//name存储file文件夹中的文件名
String[] name =file.list();
for (int i=0; i<name.length; i++){
//此时就可得到文件夹中的文件
File f=new File(url, name[i]);
//删除文件
f.delete();
}
}
}
}

View File

@ -0,0 +1,68 @@
package com.xkrs.util;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import java.io.*;
import java.util.Map;
/**
* @Author: XinYi Song
* @Date: 2022/1/17 8:56
*/
public class ExportExcel {
/**
* 最简单的填充
*
* @since 2.1.1
*/
/*public static String simpleFill(Map<String, String> map,String templateFileName) {
String s = System.currentTimeMillis() + ".xlsx";
// 方案2 根据Map填充
String fileName = "/usr/local/excel/" + s;
//String fileName = "E:\\shoptest\\" + s;
// 这里 会填充到第一个sheet 然后文件流会自动关闭
ExcelWriterBuilder write = EasyExcel.write(fileName);
ExcelWriterBuilder excelWriterBuilder = write.withTemplate(templateFileName);
ExcelWriter build = excelWriterBuilder.build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
build.fill(map,writeSheet);
build.finish();
//EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(map);
return "http://118.24.27.47:2088/excel/"+s;
//return "http://192.168.2.139/"+s;
}*/
public static String exportToProveExcel(Map<String, String> dataMap, String srcFilePath) throws IOException, InvalidFormatException {
String s = System.currentTimeMillis() + ".xlsx";
//String path = "E:/shop/"+s;
String path = "/home/sxy/server/industrial_measurement/excel/" + s;
// 开始转换。利用 transformer 转到Excel
XLSTransformer transformer = new XLSTransformer();
// 参数srcFilePath模板源文件 cMap需要导出的数据 destFile.getAbsolutePath():下载的目标文件
transformer.transformXLS(srcFilePath, dataMap, path);
//return "http://192.168.2.139/"+s;
return "http://118.24.27.47:2088/excel/"+s;
}
/*public static void main(String[] args) throws IOException, InvalidFormatException {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
String templateFileName = TestFileUtil.getPath() + "templates" + File.separator + "test.xlsx";
Map<String, String> map = new HashMap<String, String>();
map.put("name", "张三");
map.put("sex", "男");
//simpleFill(map,templateFileName);
HttpServletResponse response = null;
String s = exportToProveExcel(map);
System.out.println(s);
}*/
}

View File

@ -0,0 +1,48 @@
package com.xkrs.util;
import com.xkrs.dao.DataDictDao;
import com.xkrs.model.entity.DataDict;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: XinYi Song
* @Date: 2022/1/19 13:56
*/
@Component
public class Query {
@Resource
private DataDictDao dataDictDao;
/**
* 动态多条件查询字典信息
* @return
*/
public List<DataDict> selectDataDict(String dictChineseName,String dictEnglishName) {
Specification<DataDict> specification = new Specification<DataDict>() {
@Override
public Predicate toPredicate(Root<DataDict> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<>();
if(dictChineseName != null && !"".equals(dictChineseName)){
list.add(criteriaBuilder.equal(root.get("dictChineseName").as(String.class), dictChineseName));
}
if(dictEnglishName != null && !"".equals(dictEnglishName)){
list.add(criteriaBuilder.equal(root.get("dictEnglishName").as(String.class), dictEnglishName));
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return dataDictDao.findAll(specification);
}
}

View File

@ -0,0 +1,38 @@
package com.xkrs.util;
import java.io.File;
import java.io.InputStream;
/**
* @Author: XinYi Song
* @Date: 2022/1/17 9:29
*/
public class TestFileUtil {
public static InputStream getResourcesFileInputStream(String fileName) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
}
public static String getPath() {
return TestFileUtil.class.getResource("/").getPath();
}
public static File createNewFile(String pathName) {
File file = new File(getPath() + pathName);
if (file.exists()) {
file.delete();
} else {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
}
return file;
}
public static File readFile(String pathName) {
return new File(getPath() + pathName);
}
public static File readUserHomeFile(String pathName) {
return new File(System.getProperty("user.home") + File.separator + pathName);
}
}