更新参数类型

This commit is contained in:
liuchengqian 2022-03-01 14:39:41 +08:00
parent b0afd5f4aa
commit 266c46fe16
5 changed files with 29 additions and 26 deletions

View File

@ -59,7 +59,7 @@ public class FileController {
@Transactional(rollbackOn = Exception.class)
public String updateFileUploadPath(@RequestBody FileUpdateQo fileUpdateQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException {
Locale locale = LocaleContextHolder.getLocale();
String file = ExcelUploadUtil.memoryFile(fileExcel);
String file = ExcelUploadUtil.memoryFile(fileExcel,1);
fileDao.updateFileUploadPath(fileUpdateQo.getLotNo(), fileUpdateQo.getMachineNo(), fileUpdateQo.getMaterialNo(), fileUpdateQo.getModelNo(), fileUpdateQo.getPartNo(), file);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
}

View File

@ -7,7 +7,6 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
/**
@ -41,6 +40,6 @@ public interface PictureDao extends JpaRepository<PictureEntity, Long>, JpaSpeci
* @param picturePath 图片路径
*/
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE qc_inspection_picture SET picture_path = ?6 where lot_no = ?1 and machine_no = ?2 and material_no = ?3 and model_no = ?4 and part_no = ?5",nativeQuery = true)
@Query(value = "UPDATE qc_inspection_picture SET picture_path = ?6 where lot_no = ?1 and machine_no = ?2 and material_no = ?3 and model_no = ?4 and part_no = ?5", nativeQuery = true)
void updatePicturePath(String lotNo, String machineNo, String materialNo, String modelNo, String partNo, String picturePath);
}

View File

@ -54,7 +54,7 @@ public class FileServiceImpl implements FileService {
if (fileExcel == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale);
}
String file = ExcelUploadUtil.memoryFile(fileExcel);
String file = ExcelUploadUtil.memoryFile(fileExcel,1);
FileEntity fileEntity1 = new FileEntity();
fileEntity1.setLotNo(fileQo.getLotNo());
fileEntity1.setMachineNo(fileQo.getMachineNo());

View File

@ -35,7 +35,7 @@ public class PictureServiceImpl implements PictureService {
if (pictureEntity2.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "请勿重复添加!", locale);
}
String file = ExcelUploadUtil.memoryFile(pictureFile);
String file = ExcelUploadUtil.memoryFile(pictureFile, 2);
PictureEntity pictureEntity1 = new PictureEntity();
pictureEntity1.setLotNo(lotNo);
pictureEntity1.setMachineNo(machineNo);

View File

@ -23,16 +23,18 @@ public class ExcelUploadUtil {
/**
* 上传单张图片
* @param fileExcel
*
* @param fileInput
* @return
* @throws IOException
*/
public static String memoryFile(MultipartFile fileExcel) throws IOException {
public static String memoryFile(MultipartFile fileInput, int subDirType) throws IOException {
String subDir = subDirType == 1 ? "excel/" : "picture/";
//String uploadPath = "http://139.199.98.175:2088/wfTaskImage/";
// String uploadPath = "http://192.168.2.9:2088/";
String uploadPath = "http://118.24.27.47:4096/";
//获取原始文件名
String originalFilename = fileExcel.getOriginalFilename();
String originalFilename = fileInput.getOriginalFilename();
if (originalFilename != null && !"".equals(originalFilename)) {
//找到 . 的位置
int index = originalFilename.lastIndexOf(".");
@ -42,16 +44,16 @@ public class ExcelUploadUtil {
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/");
// File file = new File("/Users/liuchengqian/Desktop/DaJiang/");
File file = new File("/home/sxy/server/industrial_measurement/" + subDir);
if (!file.exists()) {
file.mkdirs();
}
//String path = "E:/shoptest/" + newName;
String path = "/home/sxy/server/industrial_measurement/excel/" + newName;
// String path = "/Users/liuchengqian/Desktop/DaJiang/"+newName;
String path = "/home/sxy/server/industrial_measurement/" + subDir + newName;
String uploadsImage = uploadPath + newName;
//实现上传
fileExcel.transferTo(new File(path));
fileInput.transferTo(new File(path));
return path;
}
return null;
@ -99,27 +101,27 @@ public class ExcelUploadUtil {
}*/
/**
* 删除本地或服务器储存的图片
*
* @param path
* @return
*/
public static String delFile(String path){
public static String delFile(String path) {
String resultInfo = null;
int lastIndexOf = path.lastIndexOf("/");
String imgPath = path.substring(lastIndexOf + 1,path.length());
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()){
if (file.exists()) {
if (file.delete()) {
resultInfo = "删除成功!";
}else {
} else {
resultInfo = "删除失败!";
}
}else {
} else {
resultInfo = "文件不存在";
}
return resultInfo;
@ -127,6 +129,7 @@ public class ExcelUploadUtil {
/**
* 通过图片路径解析 上传保存
*
* @param listImgSrc
* @return
*/
@ -171,17 +174,18 @@ public class ExcelUploadUtil {
/**
* 删除本地文件夹图片
*
* @param url
*/
public static void deleteImage(String url){
File file=new File(url);
public static void deleteImage(String url) {
File file = new File(url);
//判断file是否是文件目录 若是返回TRUE
if (file.isDirectory()){
if (file.isDirectory()) {
//name存储file文件夹中的文件名
String[] name =file.list();
for (int i=0; i<name.length; i++){
String[] name = file.list();
for (int i = 0; i < name.length; i++) {
//此时就可得到文件夹中的文件
File f=new File(url, name[i]);
File f = new File(url, name[i]);
//删除文件
f.delete();
}