package com.ruoyi.web.controller.imagedata;
|
|
import com.ruoyi.common.annotation.Anonymous;
|
import com.ruoyi.common.annotation.DataSource;
|
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.config.LegacySystemConfig;
|
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.DataSourceType;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.InputStreamBase64Converter;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.system.file.FileUploadResponse;
|
import com.ruoyi.system.file.IFileUploadService;
|
import com.ruoyi.system.imagedata.IImageDataService;
|
import com.ruoyi.system.domain.ImageData;
|
import com.ruoyi.system.domain.enums.ImageTypeEnum;
|
import com.ruoyi.system.imagedata.WxImageUploadRequest;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.InputStream;
|
import java.util.*;
|
import java.util.List;
|
|
/**
|
* 图片数据控制器
|
*
|
* @author mhyl
|
* @date 2024-01-01
|
*/
|
@RestController
|
@DataSource(DataSourceType.SQLSERVER)
|
@RequestMapping("/hospital/imagedata")
|
public class ImageDataController extends BaseController {
|
|
private static final Logger log = LoggerFactory.getLogger(ImageDataController.class);
|
@Autowired
|
private IImageDataService imageDataService;
|
|
@Autowired
|
private IFileUploadService fileUploadService;
|
|
|
@Autowired
|
private LegacySystemConfig legacyConfig;
|
/**
|
* 查询图片数据列表
|
*/
|
// @PreAuthorize("@ss.hasPermi('hospital:imagedata:list')")
|
@GetMapping("/list")
|
public TableDataInfo list(ImageData imageData) {
|
// startPage();
|
List<ImageData> list = imageDataService.selectImageDataList(imageData);
|
return getDataTable(list);
|
}
|
|
/**
|
* 导出图片数据列表
|
*/
|
|
@Log(title = "图片数据", businessType = BusinessType.EXPORT)
|
@PostMapping("/export")
|
public void export(HttpServletResponse response, ImageData imageData) {
|
List<ImageData> list = imageDataService.selectImageDataList(imageData);
|
ExcelUtil<ImageData> util = new ExcelUtil<ImageData>(ImageData.class);
|
util.exportExcel(response, list, "图片数据数据");
|
}
|
|
/**
|
* 获取图片数据详细信息
|
*/
|
|
@GetMapping(value = "/{id}")
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
return AjaxResult.success(imageDataService.selectImageDataById(id));
|
}
|
|
/**
|
* 新增图片数据
|
*/
|
|
@Log(title = "图片数据", businessType = BusinessType.INSERT)
|
@PostMapping
|
public AjaxResult add(@RequestBody ImageData imageData) {
|
return toAjax(imageDataService.insertImageData(imageData));
|
}
|
|
/**
|
* 修改图片数据
|
*/
|
@Log(title = "图片数据", businessType = BusinessType.UPDATE)
|
@PutMapping
|
public AjaxResult edit(@RequestBody ImageData imageData) {
|
return toAjax(imageDataService.updateImageData(imageData));
|
}
|
|
/**
|
* 删除图片数据
|
*/
|
@Log(title = "图片数据", businessType = BusinessType.DELETE)
|
@DeleteMapping("/{ids}")
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
return toAjax(imageDataService.deleteImageDataByIds(ids));
|
}
|
|
/**
|
* 根据调度单ID查询图片数据
|
*/
|
@GetMapping("/byDispatchOrder/{dispatchOrdID}")
|
public AjaxResult getByDispatchOrder(@PathVariable("dispatchOrdID") Long dispatchOrdID) {
|
List<ImageData> list = imageDataService.selectImageDataByDOrdIDDt(dispatchOrdID);
|
return AjaxResult.success(list);
|
}
|
|
/**
|
* 根据调度单ID和图片类型获取有效图片(包含完整链接)
|
*
|
* @param dispatchOrdID 调度单ID
|
* @param imageType 图片类型
|
* @return 图片数据(包含完整链接)
|
*/
|
// @PreAuthorize("@ss.hasPermi('hospital:imagedata:query')")
|
@Anonymous()
|
@GetMapping("/byDispatchOrderAndType/{dispatchOrdID}/{imageType}")
|
public AjaxResult getByDispatchOrderAndType(@PathVariable("dispatchOrdID") Long dispatchOrdID,
|
@PathVariable("imageType") Integer imageType) {
|
try {
|
// 查询指定调度单和类型的有效图片
|
List<ImageData> imageDataList = imageDataService.selectImageDataByDOrdIDDtAndType(dispatchOrdID, imageType);
|
|
// 过滤有效图片(未删除的)
|
List<ImageData> validImages = imageDataList.stream()
|
.filter(img -> img.getImageDel() == null || img.getImageDel() == 0)
|
.collect(java.util.stream.Collectors.toList());
|
|
// 为每个图片添加完整链接
|
for (ImageData imageData : validImages) {
|
// 添加原始图片完整链接
|
if (StringUtils.hasText(imageData.getImageUrl())) {
|
String fullImageUrl = buildFullImageUrl(imageData.getImageUrl());
|
imageData.setImageUrl(fullImageUrl);
|
}
|
|
// 添加缩略图完整链接
|
if (StringUtils.hasText(imageData.getImageUrls())) {
|
String fullThumbnailUrl = buildFullImageUrl(imageData.getImageUrls());
|
imageData.setImageUrls(fullThumbnailUrl);
|
}
|
}
|
|
return AjaxResult.success("获取图片成功", validImages);
|
} catch (Exception e) {
|
return AjaxResult.error("获取图片失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 根据调度单ID和图片类型获取有效图片(简化版,只返回图片链接)
|
*
|
* @param dispatchOrdID 调度单ID
|
* @param imageType 图片类型
|
* @return 图片链接列表
|
*/
|
// @PreAuthorize("@ss.hasPermi('hospital:imagedata:query')")
|
@Anonymous()
|
@GetMapping("/links/byDispatchOrderAndType/{dispatchOrdID}/{imageType}")
|
public AjaxResult getImageLinksByDispatchOrderAndType(@PathVariable("dispatchOrdID") Long dispatchOrdID,
|
@PathVariable("imageType") Integer imageType) {
|
try {
|
// 查询指定调度单和类型的有效图片
|
List<ImageData> imageDataList = imageDataService.selectImageDataByDOrdIDDtAndType(dispatchOrdID, imageType);
|
|
// 构建图片链接列表
|
List<java.util.Map<String, String>> imageLinks = new java.util.ArrayList<>();
|
|
for (ImageData imageData : imageDataList) {
|
// 只处理未删除的图片
|
if (imageData.getImageDel() == null || imageData.getImageDel() == 0) {
|
java.util.Map<String, String> linkMap = new java.util.HashMap<>();
|
|
// 原始图片链接
|
if (StringUtils.hasText(imageData.getImageUrl())) {
|
linkMap.put("originalUrl", buildFullImageUrl(imageData.getImageUrl()));
|
}
|
|
// 缩略图链接
|
if (StringUtils.hasText(imageData.getImageUrls())) {
|
linkMap.put("thumbnailUrl", buildFullImageUrl(imageData.getImageUrls()));
|
}
|
|
// 图片ID
|
linkMap.put("imageId", String.valueOf(imageData.getId()));
|
|
// 图片类型
|
linkMap.put("imageType", String.valueOf(imageData.getImageType()));
|
|
// 上传时间
|
if (imageData.getUpImageTime() != null) {
|
linkMap.put("uploadTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, imageData.getUpImageTime()));
|
}
|
|
imageLinks.add(linkMap);
|
}
|
}
|
|
return AjaxResult.success("获取图片链接成功", imageLinks);
|
} catch (Exception e) {
|
return AjaxResult.error("获取图片链接失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 构建完整的图片URL
|
*
|
* @param imagePath 图片路径
|
* @return 完整的图片URL
|
*/
|
private String buildFullImageUrl(String imagePath) {
|
if (!StringUtils.hasText(imagePath)) {
|
return "";
|
}
|
|
// 如果已经是完整URL,直接返回
|
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
return imagePath;
|
}
|
|
// 从配置中读取文件服务器URL
|
String fileServerUrl = legacyConfig.getFileServerUrl();
|
|
// 如果配置中没有设置,使用默认值
|
if (!StringUtils.hasText(fileServerUrl)) {
|
// 记录警告日志
|
System.err.println("警告:配置文件中未设置 legacy.system.fileServerUrl,使用默认值");
|
fileServerUrl = "https://sync.966120.com.cn";
|
}
|
|
// 确保文件服务器URL不以/结尾
|
if (fileServerUrl.endsWith("/")) {
|
fileServerUrl = fileServerUrl.substring(0, fileServerUrl.length() - 1);
|
}
|
|
// 处理图片路径:移除开头和结尾的空白字符
|
imagePath = imagePath.trim();
|
|
// 移除开头和结尾的斜杠
|
while (imagePath.startsWith("/")) {
|
imagePath = imagePath.substring(1);
|
}
|
while (imagePath.endsWith("/")) {
|
imagePath = imagePath.substring(0, imagePath.length() - 1);
|
}
|
|
// 处理反斜杠:将反斜杠替换为正斜杠
|
imagePath = imagePath.replace("\\", "/");
|
|
// 移除路径中可能的重复斜杠
|
imagePath = imagePath.replaceAll("/+", "/");
|
|
// 确保图片路径以/开头
|
if (!imagePath.startsWith("/")) {
|
imagePath = "/" + imagePath;
|
}
|
|
// 构建完整URL
|
String fullUrl = fileServerUrl + imagePath;
|
|
// 记录调试信息
|
System.out.println("构建图片URL - 配置URL: " + fileServerUrl + ", 图片路径: " + imagePath + ", 完整URL: " + fullUrl);
|
|
return fullUrl;
|
}
|
|
/**
|
* 根据服务单ID查询图片数据
|
*/
|
@PreAuthorize("@ss.hasPermi('hospital:imagedata:query')")
|
@GetMapping("/byServiceOrder/{serviceOrdID}")
|
public AjaxResult getByServiceOrder(@PathVariable("serviceOrdID") Long serviceOrdID) {
|
List<ImageData> list = imageDataService.selectImageDataBySOrdIDDt(serviceOrdID);
|
return AjaxResult.success(list);
|
}
|
|
/**
|
* 根据图片类型查询图片数据
|
*/
|
@PreAuthorize("@ss.hasPermi('hospital:imagedata:query')")
|
@GetMapping("/byType/{imageType}")
|
public AjaxResult getByType(@PathVariable("imageType") Integer imageType) {
|
List<ImageData> list = imageDataService.selectImageDataByType(imageType);
|
return AjaxResult.success(list);
|
}
|
|
/**
|
* 标记图片为删除状态
|
*/
|
@PreAuthorize("@ss.hasPermi('hospital:imagedata:remove')")
|
@Log(title = "标记图片删除", businessType = BusinessType.DELETE)
|
@PutMapping("/markDelete/{id}")
|
public AjaxResult markDelete(@PathVariable("id") Long id) {
|
return toAjax(imageDataService.markImageDataAsDeleted(id));
|
}
|
|
/**
|
* 微信图片上传处理(原ASP代码转换)
|
*/
|
@Log(title = "微信图片上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadWxImage")
|
public AjaxResult uploadWxImage(@RequestBody WxImageUploadRequest request) {
|
|
// 获取当前登录用户ID
|
Integer adminId = getUserId().intValue();
|
|
String result = imageDataService.uploadWxImage(
|
request.getDispatchOrdID(),
|
request.getServiceOrdID(),
|
request.getOaid(),
|
request.getMediaId(),
|
request.getImageType(),
|
adminId
|
);
|
|
if (result.contains("成功")) {
|
return success(result);
|
} else {
|
return error(result);
|
}
|
}
|
|
/**
|
* 微信图片上传处理(兼容原有参数格式)
|
*/
|
@Log(title = "微信图片上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadWxImageForm")
|
public AjaxResult uploadWxImageForm(
|
@RequestParam(value = "DispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "ServiceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "OAID", required = false) Integer oaid,
|
@RequestParam(value = "media_id", required = true) String mediaId,
|
@RequestParam(value = "ImageType", required = false) Integer imageType) {
|
|
// 获取当前登录用户ID
|
Integer adminId = getUserId().intValue();
|
|
String result = imageDataService.uploadWxImage(dispatchOrdID, serviceOrdID, oaid, mediaId, imageType, adminId);
|
|
if (result.contains("成功")) {
|
return success(result);
|
} else {
|
return error(result);
|
}
|
}
|
|
/**
|
* 微信图片上传处理(完整版本,包含文件下载和缩略图生成)
|
*/
|
@Log(title = "微信图片上传完整版", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadWxImageWithDownload")
|
public AjaxResult uploadWxImageWithDownload(@RequestBody WxImageUploadRequest request) {
|
|
// 获取当前登录用户ID
|
Integer adminId = getUserId().intValue();
|
|
// 这里需要从配置或请求中获取access_token
|
// 实际使用时应该从微信配置或缓存中获取
|
String accessToken = request.getAccessToken(); // 需要在WxImageUploadRequest中添加此字段
|
|
if (accessToken == null || accessToken.isEmpty()) {
|
return error("缺少微信访问令牌");
|
}
|
|
String result = imageDataService.uploadWxImageWithDownload(
|
accessToken,
|
request.getMediaId(),
|
request.getDispatchOrdID(),
|
request.getOaid(),
|
request.getImageType(),
|
adminId
|
);
|
|
if (result.contains("成功")) {
|
return success(result);
|
} else {
|
return error(result);
|
}
|
}
|
|
/**
|
* 微信图片上传处理(完整版本,兼容原有参数格式)
|
*/
|
@Log(title = "微信图片上传完整版", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadWxImageWithDownloadForm")
|
public AjaxResult uploadWxImageWithDownloadForm(
|
@RequestParam(value = "access_token", required = true) String accessToken,
|
@RequestParam(value = "media_id", required = true) String mediaId,
|
@RequestParam(value = "DispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "ServiceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "OAID", required = false) Integer oaid,
|
@RequestParam(value = "ImageType", required = false) Integer imageType) {
|
|
// 获取当前登录用户ID
|
Integer adminId = getUserId().intValue();
|
|
String result = imageDataService.uploadWxImageWithDownload(
|
accessToken, mediaId, dispatchOrdID, oaid, imageType, adminId);
|
|
if (result.contains("成功")) {
|
return success(result);
|
} else {
|
return error(result);
|
}
|
}
|
|
|
|
/**
|
* 生成缩略图
|
*/
|
@Log(title = "生成缩略图", businessType = BusinessType.OTHER)
|
@PostMapping("/createThumbnail")
|
public AjaxResult createThumbnail(
|
@RequestParam(value = "bigImgPath", required = true) String bigImgPath,
|
@RequestParam(value = "width", required = true) int width,
|
@RequestParam(value = "height", required = false, defaultValue = "0") int height,
|
@RequestParam(value = "smallImgPath", required = true) String smallImgPath) {
|
|
boolean result = imageDataService.createThumbnail(bigImgPath, width, height, smallImgPath);
|
|
if (result) {
|
return success("缩略图生成成功");
|
} else {
|
return error("缩略图生成失败");
|
}
|
}
|
|
/**
|
* 检查文件兼容性
|
*/
|
|
@GetMapping("/checkCompatibility")
|
public AjaxResult checkFileCompatibility(@RequestParam("filePath") String filePath) {
|
try {
|
String result = imageDataService.checkFileCompatibility(filePath);
|
return AjaxResult.success("兼容性检查完成", result);
|
} catch (Exception e) {
|
return AjaxResult.error("兼容性检查失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 验证URL格式是否与旧系统兼容
|
*/
|
@GetMapping("/checkUrlCompatibility")
|
public AjaxResult checkUrlCompatibility(@RequestParam("url") String url) {
|
try {
|
boolean isCompatible = imageDataService.isUrlCompatible(url);
|
return AjaxResult.success("URL兼容性检查完成", isCompatible);
|
} catch (Exception e) {
|
return AjaxResult.error("URL兼容性检查失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 生成与旧系统兼容的文件路径
|
*/
|
|
@GetMapping("/generateCompatibleFilePath")
|
public AjaxResult generateCompatibleFilePath(@RequestParam("dispatchOrdID") Long dispatchOrdID,
|
@RequestParam("mediaId") String mediaId,
|
@RequestParam(value = "isThumbnail", defaultValue = "false") boolean isThumbnail) {
|
try {
|
String filePath = imageDataService.generateCompatibleFilePath(dispatchOrdID, mediaId, isThumbnail);
|
return AjaxResult.success("生成兼容文件路径成功", filePath);
|
} catch (Exception e) {
|
return AjaxResult.error("生成兼容文件路径失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 生成与旧系统兼容的访问URL
|
*/
|
|
@GetMapping("/generateCompatibleUrl")
|
public AjaxResult generateCompatibleUrl(@RequestParam("dispatchOrdID") Long dispatchOrdID,
|
@RequestParam("mediaId") String mediaId,
|
@RequestParam(value = "isThumbnail", defaultValue = "false") boolean isThumbnail) {
|
try {
|
String url = imageDataService.generateCompatibleUrl(dispatchOrdID, mediaId, isThumbnail);
|
return AjaxResult.success("生成兼容URL成功", url);
|
} catch (Exception e) {
|
return AjaxResult.error("生成兼容URL失败:" + e.getMessage());
|
}
|
}
|
|
|
/**
|
* 通过图片URL上传处理(完整版本)
|
*
|
* @param dispatchOrdID 调度单ID
|
* @param serviceOrdID 服务单ID
|
* @param oaid OA用户ID
|
* @param imageUrl 图片URL
|
* @param thumbnailUrl 缩略图URL
|
* @param imageType 图片类型
|
* @return 处理结果
|
*/
|
@PreAuthorize("@ss.hasPermi('hospital:imagedata:add')")
|
@Log(title = "图片URL上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadByUrl")
|
public AjaxResult uploadImageByUrl(@RequestParam(value = "dispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "serviceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "oaid", required = false) Integer oaid,
|
@RequestParam("imageUrl") String imageUrl,
|
@RequestParam(value = "thumbnailUrl", required = false) String thumbnailUrl,
|
@RequestParam(value = "imageType", defaultValue = "0") Integer imageType) {
|
try {
|
// 获取当前管理员ID
|
Integer adminId = getUserId().intValue();
|
|
// 调用图片数据服务处理上传
|
String result = imageDataService.uploadImageByUrl(dispatchOrdID, serviceOrdID, oaid,
|
imageUrl, thumbnailUrl, imageType, adminId);
|
|
if (result.contains("成功")) {
|
return AjaxResult.success("图片URL上传成功", result);
|
} else {
|
return AjaxResult.error(result);
|
}
|
} catch (Exception e) {
|
return AjaxResult.error("图片URL上传失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 通过图片URL上传处理(简化版本)
|
*
|
* @param dispatchOrdID 调度单ID
|
* @param serviceOrdID 服务单ID
|
* @param oaid OA用户ID
|
* @param imageUrl 图片URL
|
* @param imageType 图片类型
|
* @return 处理结果
|
*/
|
@Log(title = "图片URL上传简化版", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadByUrlSimple")
|
public AjaxResult uploadImageByUrlSimple(@RequestParam(value = "dispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "serviceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "oaid", required = false) Integer oaid,
|
@RequestParam("imageUrl") String imageUrl,
|
@RequestParam(value = "imageType", defaultValue = "0") Integer imageType) {
|
try {
|
// 获取当前管理员ID
|
Integer adminId = getUserId().intValue();
|
|
// 调用图片数据服务处理上传(简化版)
|
String result = imageDataService.uploadImageByUrlSimple(dispatchOrdID, serviceOrdID, oaid,
|
imageUrl, imageType, adminId);
|
|
if (result.contains("成功")) {
|
return AjaxResult.success("图片URL上传成功", result);
|
} else {
|
return AjaxResult.error(result);
|
}
|
} catch (Exception e) {
|
return AjaxResult.error("图片URL上传失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 通过图片URL上传处理(JSON格式)
|
*
|
* @param requestBody 请求体
|
* @return 处理结果
|
*/
|
@PreAuthorize("@ss.hasPermi('hospital:imagedata:add')")
|
@Log(title = "图片URL上传JSON", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadByUrlJson")
|
public AjaxResult uploadImageByUrlJson(@RequestBody ImageUrlUploadRequest requestBody) {
|
try {
|
// 获取当前管理员ID
|
Integer adminId = getUserId().intValue();
|
|
// 调用图片数据服务处理上传
|
String result = imageDataService.uploadImageByUrl(requestBody.getDispatchOrdID(),
|
requestBody.getServiceOrdID(), requestBody.getOaid(), requestBody.getImageUrl(),
|
requestBody.getThumbnailUrl(), requestBody.getImageType(), adminId);
|
|
if (result.contains("成功")) {
|
return AjaxResult.success("图片URL上传成功", result);
|
} else {
|
return AjaxResult.error(result);
|
}
|
} catch (Exception e) {
|
return AjaxResult.error("图片URL上传失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 图片URL上传请求对象
|
*/
|
public static class ImageUrlUploadRequest {
|
|
private Long dispatchOrdID;
|
private Long serviceOrdID;
|
private Integer oaid;
|
private String imageUrl;
|
private String thumbnailUrl;
|
private Integer imageType;
|
|
// getter和setter方法
|
public Long getDispatchOrdID() {
|
return dispatchOrdID;
|
}
|
|
public void setDispatchOrdID(Long dispatchOrdID) {
|
this.dispatchOrdID = dispatchOrdID;
|
}
|
|
public Long getServiceOrdID() {
|
return serviceOrdID;
|
}
|
|
public void setServiceOrdID(Long serviceOrdID) {
|
this.serviceOrdID = serviceOrdID;
|
}
|
|
public Integer getOaid() {
|
return oaid;
|
}
|
|
public void setOaid(Integer oaid) {
|
this.oaid = oaid;
|
}
|
|
public String getImageUrl() {
|
return imageUrl;
|
}
|
|
public void setImageUrl(String imageUrl) {
|
this.imageUrl = imageUrl;
|
}
|
|
public String getThumbnailUrl() {
|
return thumbnailUrl;
|
}
|
|
public void setThumbnailUrl(String thumbnailUrl) {
|
this.thumbnailUrl = thumbnailUrl;
|
}
|
|
public Integer getImageType() {
|
return imageType;
|
}
|
|
public void setImageType(Integer imageType) {
|
this.imageType = imageType;
|
}
|
}
|
|
/**
|
* 图片文件上传接口
|
*
|
* @param file 上传的图片文件
|
* @param dispatchOrdID 调度单ID
|
* @param serviceOrdID 服务单ID
|
* @param imageType 图片类型
|
* @return 处理结果
|
*/
|
// @PreAuthorize("@ss.hasPermi('hospital:imagedata:add')")
|
@Anonymous()
|
@Log(title = "图片文件上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadFile")
|
public AjaxResult uploadImageFile(@RequestParam("file") MultipartFile file,
|
@RequestParam(value = "dispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "serviceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "imageType", defaultValue = "0", required = true) Integer imageType,
|
@RequestParam(value = "adminId", defaultValue = "0", required = false) Integer adminId) {
|
try {
|
|
adminId = getUserId().intValue();
|
|
// 验证文件
|
if (file.isEmpty()) {
|
return AjaxResult.error("请选择要上传的图片文件");
|
}
|
|
// 验证文件类型
|
String originalFilename = file.getOriginalFilename();
|
if (originalFilename == null || !isValidImageFile(originalFilename)) {
|
return AjaxResult.error("只支持上传图片文件(jpg、jpeg、png、gif、bmp)");
|
}
|
|
// 生成目标路径(使用年月目录结构)
|
String yearMonth = DateUtils.datePath();
|
String targetPath = dispatchOrdID.toString();
|
//在结果另返回 fileUrl,thumbnailUrl,及mediaid
|
// 使用文件上传服务保存到文件服务器(包含缩略图生成)
|
FileUploadResponse uploadResponse = fileUploadService.uploadMultipartFileWithThumbnail(file, targetPath);
|
|
// 添加调试信息
|
System.out.println("文件上传响应 - 成功: " + uploadResponse.isSuccess());
|
System.out.println("文件上传响应 - 消息: " + uploadResponse.getMessage());
|
System.out.println("文件上传响应 - 文件路径: " + uploadResponse.getFilePath());
|
System.out.println("文件上传响应 - 缩略图路径: " + uploadResponse.getThumbnailPath());
|
|
if (!uploadResponse.isSuccess()) {
|
return AjaxResult.error("文件上传失败:" + uploadResponse.getMessage());
|
}
|
|
// 创建图片数据对象
|
ImageData imageData = new ImageData();
|
imageData.setDOrdIDDt(dispatchOrdID);
|
imageData.setSOrdIDDt(serviceOrdID);
|
imageData.setImageType(imageType);
|
imageData.setImageUrl(uploadResponse.getFilePath());
|
imageData.setImageUrls(uploadResponse.getThumbnailPath()); // 缩略图路径
|
imageData.setUpImageTime(new Date());
|
imageData.setUpImageOAid(adminId);
|
imageData.setImageDel(0);
|
|
// 插入数据库
|
int result = imageDataService.insertImageData(imageData);
|
|
if (result > 0) {
|
// 根据图片类型进行特殊处理
|
ImageTypeEnum imageTypeEnum = ImageTypeEnum.getByCode(imageType);
|
|
|
//返回全路径
|
//在结果另返回 fileUrl,thumbnailUrl,及id
|
HashMap<String, String> map = new HashMap<>();
|
//加上fileServerUrl
|
map.put("fileUrl", buildFullImageUrl(uploadResponse.getFilePath()));
|
map.put("thumbnailUrl", buildFullImageUrl(uploadResponse.getThumbnailPath()));
|
map.put("id", imageData.getId().toString());
|
|
return AjaxResult.success("图片上传成功", map);
|
} else {
|
return AjaxResult.error("图片数据保存失败");
|
}
|
|
} catch (Exception e) {
|
return AjaxResult.error("图片上传失败:" + e.getMessage());
|
}
|
}
|
@Anonymous()
|
@Log(title = "图片文件上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadFileBase64")
|
public AjaxResult uploadFileBase64(@RequestParam("fileContent") String fileContent,@RequestParam("filename") String filename,
|
@RequestParam(value = "dispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "serviceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "imageType", defaultValue = "0", required = true) Integer imageType,
|
@RequestParam(value = "adminId", defaultValue = "0", required = false) Integer adminId) {
|
try {
|
|
if( adminId == 0)
|
adminId = getUserId().intValue();
|
|
InputStream stream= InputStreamBase64Converter.base64ToInputStream(fileContent);
|
|
// 生成目标路径(使用年月目录结构)
|
String yearMonth = DateUtils.datePath();
|
String targetPath = dispatchOrdID.toString();
|
//在结果另返回 fileUrl,thumbnailUrl,及mediaid
|
// 使用文件上传服务保存到文件服务器(包含缩略图生成)
|
FileUploadResponse uploadResponse = fileUploadService.uploadInputStream(stream,filename, targetPath);
|
|
// 添加调试信息
|
System.out.println("文件上传响应 - 成功: " + uploadResponse.isSuccess());
|
System.out.println("文件上传响应 - 消息: " + uploadResponse.getMessage());
|
System.out.println("文件上传响应 - 文件路径: " + uploadResponse.getFilePath());
|
System.out.println("文件上传响应 - 缩略图路径: " + uploadResponse.getThumbnailPath());
|
|
if (!uploadResponse.isSuccess()) {
|
return AjaxResult.error("文件上传失败:" + uploadResponse.getMessage());
|
}
|
|
// 创建图片数据对象
|
ImageData imageData = new ImageData();
|
imageData.setDOrdIDDt(dispatchOrdID);
|
imageData.setSOrdIDDt(serviceOrdID);
|
imageData.setImageType(imageType);
|
imageData.setImageUrl(uploadResponse.getFilePath());
|
imageData.setImageUrls(uploadResponse.getThumbnailPath()); // 缩略图路径
|
imageData.setUpImageTime(new Date());
|
imageData.setUpImageOAid(adminId);
|
imageData.setImageDel(0);
|
|
// 插入数据库
|
int result = imageDataService.insertImageData(imageData);
|
|
if (result > 0) {
|
// 根据图片类型进行特殊处理
|
ImageTypeEnum imageTypeEnum = ImageTypeEnum.getByCode(imageType);
|
|
|
//返回全路径
|
//在结果另返回 fileUrl,thumbnailUrl,及id
|
HashMap<String, String> map = new HashMap<>();
|
//加上fileServerUrl
|
map.put("fileUrl", buildFullImageUrl(uploadResponse.getFilePath()));
|
map.put("thumbnailUrl", buildFullImageUrl(uploadResponse.getThumbnailPath()));
|
map.put("id", imageData.getId().toString());
|
|
return AjaxResult.success("图片上传成功", map);
|
} else {
|
return AjaxResult.error("图片数据保存失败");
|
}
|
|
} catch (Exception e) {
|
return AjaxResult.error("图片上传失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 微信小程序专用图片文件上传接口
|
* 支持微信小程序的 wx.uploadFile API
|
*
|
* @param request HttpServletRequest 请求对象
|
* @param dispatchOrdID 调度单ID
|
* @param serviceOrdID 服务单ID
|
* @param imageType 图片类型
|
* @param adminId 管理员ID
|
* @return 处理结果
|
*/
|
@Anonymous()
|
@Log(title = "微信小程序图片上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadWxFile")
|
public AjaxResult uploadWxFile(HttpServletRequest request,
|
@RequestParam(value = "dispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "serviceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "imageType", defaultValue = "0", required = true) Integer imageType,
|
@RequestParam(value = "adminId", defaultValue = "0", required = false) Integer adminId) {
|
try {
|
adminId = getUserId().intValue();
|
|
// 获取文件参数 - 微信小程序专用
|
MultipartFile file = null;
|
|
// 检查是否为 multipart 请求
|
if (request instanceof MultipartHttpServletRequest) {
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
// 微信小程序通常使用 "file" 作为文件参数名
|
file = multipartRequest.getFile("file");
|
|
// 如果没找到,尝试其他可能的参数名
|
if (file == null || file.isEmpty()) {
|
String[] possibleFileParams = {"image", "photo", "upload"};
|
for (String paramName : possibleFileParams) {
|
file = multipartRequest.getFile(paramName);
|
if (file != null && !file.isEmpty()) {
|
break;
|
}
|
}
|
}
|
|
// 如果还是没找到文件,获取第一个文件
|
if (file == null || file.isEmpty()) {
|
Iterator<String> fileNames = multipartRequest.getFileNames();
|
if (fileNames.hasNext()) {
|
file = multipartRequest.getFile(fileNames.next());
|
}
|
}
|
}
|
|
// 验证文件
|
if (file == null || file.isEmpty()) {
|
return AjaxResult.error("请选择要上传的图片文件");
|
}
|
|
// 验证文件类型
|
String originalFilename = file.getOriginalFilename();
|
if (originalFilename == null || !isValidImageFile(originalFilename)) {
|
return AjaxResult.error("只支持上传图片文件(jpg、jpeg、png、gif、bmp)");
|
}
|
|
// 生成目标路径
|
String targetPath = dispatchOrdID != null ? dispatchOrdID.toString() : "default";
|
|
// 使用文件上传服务保存到文件服务器(包含缩略图生成)
|
FileUploadResponse uploadResponse = fileUploadService.uploadMultipartFileWithThumbnail(file, targetPath);
|
|
// 添加调试信息
|
System.out.println("微信小程序文件上传响应 - 成功: " + uploadResponse.isSuccess());
|
System.out.println("微信小程序文件上传响应 - 消息: " + uploadResponse.getMessage());
|
System.out.println("微信小程序文件上传响应 - 文件路径: " + uploadResponse.getFilePath());
|
System.out.println("微信小程序文件上传响应 - 缩略图路径: " + uploadResponse.getThumbnailPath());
|
|
if (!uploadResponse.isSuccess()) {
|
return AjaxResult.error("文件上传失败:" + uploadResponse.getMessage());
|
}
|
|
// 创建图片数据对象
|
ImageData imageData = new ImageData();
|
imageData.setDOrdIDDt(dispatchOrdID);
|
imageData.setSOrdIDDt(serviceOrdID);
|
imageData.setImageType(imageType);
|
imageData.setImageUrl(uploadResponse.getFilePath());
|
imageData.setImageUrls(uploadResponse.getThumbnailPath()); // 缩略图路径
|
imageData.setUpImageTime(new Date());
|
imageData.setUpImageOAid(adminId);
|
imageData.setImageDel(0);
|
|
// 插入数据库
|
int result = imageDataService.insertImageData(imageData);
|
|
if (result > 0) {
|
// 根据图片类型进行特殊处理
|
ImageTypeEnum imageTypeEnum = ImageTypeEnum.getByCode(imageType);
|
|
|
|
// 返回微信小程序需要的格式
|
HashMap<String, Object> map = new HashMap<>();
|
map.put("fileUrl", buildFullImageUrl(uploadResponse.getFilePath()));
|
map.put("thumbnailUrl", buildFullImageUrl(uploadResponse.getThumbnailPath()));
|
map.put("id", imageData.getId());
|
map.put("success", true);
|
map.put("message", "图片上传成功");
|
|
return AjaxResult.success("图片上传成功", map);
|
} else {
|
return AjaxResult.error("图片数据保存失败");
|
}
|
|
} catch (Exception e) {
|
log.error("微信小程序图片上传失败", e);
|
return AjaxResult.error("图片上传失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 微信小程序Base64图片上传接口
|
* 支持微信小程序将图片转换为Base64后上传
|
*
|
* @param fileContent Base64编码的图片内容
|
* @param filename 文件名
|
* @param dispatchOrdID 调度单ID
|
* @param serviceOrdID 服务单ID
|
* @param imageType 图片类型
|
* @param adminId 管理员ID
|
* @return 处理结果
|
*/
|
@Anonymous()
|
@Log(title = "微信小程序Base64图片上传", businessType = BusinessType.INSERT)
|
@PostMapping("/uploadWxBase64")
|
public AjaxResult uploadWxBase64(@RequestParam("fileContent") String fileContent,
|
@RequestParam("filename") String filename,
|
@RequestParam(value = "dispatchOrdID", required = false) Long dispatchOrdID,
|
@RequestParam(value = "serviceOrdID", required = false) Long serviceOrdID,
|
@RequestParam(value = "imageType", defaultValue = "0", required = true) Integer imageType,
|
@RequestParam(value = "adminId", defaultValue = "0", required = false) Integer adminId) {
|
try {
|
if (adminId == 0) {
|
adminId = getUserId().intValue();
|
}
|
|
// 验证Base64内容
|
if (fileContent == null || fileContent.trim().isEmpty()) {
|
return AjaxResult.error("图片内容不能为空");
|
}
|
|
// 验证文件类型
|
if (filename == null || !isValidImageFile(filename)) {
|
return AjaxResult.error("只支持上传图片文件(jpg、jpeg、png、gif、bmp)");
|
}
|
|
// 将Base64转换为InputStream
|
InputStream stream = InputStreamBase64Converter.base64ToInputStream(fileContent);
|
|
// 生成目标路径
|
String targetPath = dispatchOrdID != null ? dispatchOrdID.toString() : "default";
|
|
// 使用文件上传服务保存到文件服务器
|
FileUploadResponse uploadResponse = fileUploadService.uploadInputStream(stream, filename, targetPath);
|
|
// 添加调试信息
|
System.out.println("微信小程序Base64上传响应 - 成功: " + uploadResponse.isSuccess());
|
System.out.println("微信小程序Base64上传响应 - 消息: " + uploadResponse.getMessage());
|
System.out.println("微信小程序Base64上传响应 - 文件路径: " + uploadResponse.getFilePath());
|
System.out.println("微信小程序Base64上传响应 - 缩略图路径: " + uploadResponse.getThumbnailPath());
|
|
if (!uploadResponse.isSuccess()) {
|
return AjaxResult.error("文件上传失败:" + uploadResponse.getMessage());
|
}
|
|
// 创建图片数据对象
|
ImageData imageData = new ImageData();
|
imageData.setDOrdIDDt(dispatchOrdID);
|
imageData.setSOrdIDDt(serviceOrdID);
|
imageData.setImageType(imageType);
|
imageData.setImageUrl(uploadResponse.getFilePath());
|
imageData.setImageUrls(uploadResponse.getThumbnailPath()); // 缩略图路径
|
imageData.setUpImageTime(new Date());
|
imageData.setUpImageOAid(adminId);
|
imageData.setImageDel(0);
|
|
// 插入数据库
|
int result = imageDataService.insertImageData(imageData);
|
|
if (result > 0) {
|
// 根据图片类型进行特殊处理
|
ImageTypeEnum imageTypeEnum = ImageTypeEnum.getByCode(imageType);
|
|
|
|
// 返回微信小程序需要的格式
|
HashMap<String, Object> map = new HashMap<>();
|
map.put("fileUrl", buildFullImageUrl(uploadResponse.getFilePath()));
|
map.put("thumbnailUrl", buildFullImageUrl(uploadResponse.getThumbnailPath()));
|
map.put("id", imageData.getId());
|
map.put("success", true);
|
map.put("message", "图片上传成功");
|
|
return AjaxResult.success("图片上传成功", map);
|
} else {
|
return AjaxResult.error("图片数据保存失败");
|
}
|
|
} catch (Exception e) {
|
log.error("微信小程序Base64图片上传失败", e);
|
return AjaxResult.error("图片上传失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 验证是否为有效的图片文件
|
*/
|
private boolean isValidImageFile(String filename) {
|
String[] allowedExtensions = {".jpg", ".jpeg", ".png", ".gif", ".bmp"};
|
String lowerFilename = filename.toLowerCase();
|
for (String ext : allowedExtensions) {
|
if (lowerFilename.endsWith(ext)) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/**
|
* 获取文件扩展名
|
*/
|
private String getFileExtension(String filename) {
|
int lastDotIndex = filename.lastIndexOf('.');
|
if (lastDotIndex > 0) {
|
return filename.substring(lastDotIndex + 1);
|
}
|
return "jpg"; // 默认扩展名
|
}
|
|
/**
|
* 获取上传路径
|
*/
|
private String getUploadPath() {
|
// 这里可以根据实际配置返回上传路径
|
// 可以从配置文件中读取或使用默认路径
|
return System.getProperty("user.dir") + "/upload";
|
}
|
|
|
|
}
|