wlzboy
7 天以前 09e6dc3fb7266620fafb5e341808a8eb36e080a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
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";
    }
 
 
 
}