wlzboy
2025-12-26 4fdde57a837b47b0a04aa17a7627c21b7425eda2
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
package com.ruoyi.web.controller.task;
 
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTask;
import com.ruoyi.system.domain.SysTaskAttachment;
import com.ruoyi.system.service.ISysTaskService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.ITaskAttachmentSyncService;
import com.ruoyi.system.task.ITaskAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 任务附件同步Controller
 * 用于将任务附件同步到ImageData表
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/task/attachment/sync")
public class TaskAttachmentSyncController extends BaseController {
    
    @Autowired
    private ITaskAttachmentSyncService taskAttachmentSyncService;
 
    @Autowired
    private ITaskAttachmentService taskAttachmentService;
    
    @Autowired
    private ISysTaskService sysTaskService;
 
    @Autowired
    private ISysUserService sysUserService;
 
    /**
     * 手动同步单个任务的附件到ImageData
     * 
     * @param taskId 任务ID
     * @return 同步结果
     */
    @PreAuthorize("@ss.hasPermi('task:general:edit')")
    @Log(title = "任务附件同步", businessType = BusinessType.OTHER)
    @PostMapping("/task/{taskId}")
    public AjaxResult syncTaskAttachments(@PathVariable("taskId") Long taskId) {
        try {
            // 查询任务详情
            SysTask task = sysTaskService.getTaskDetail(taskId);
            SysUser user = sysUserService.selectUserById(task.getCreatorId());
            Integer oaUserId=user.getOaUserId();
            if (task == null) {
                return error("任务不存在");
            }
            
            // 获取serviceOrderId和dispatchOrdId
            Long serviceOrderId = null;
            Long dispatchOrdId = null;
            
            if (task.getEmergencyInfo() != null) {
                serviceOrderId = task.getEmergencyInfo().getLegacyServiceOrdId();
                dispatchOrdId = task.getEmergencyInfo().getLegacyDispatchOrdId();
            }
            
            if (serviceOrderId == null && dispatchOrdId == null) {
                return error("任务未关联服务单或调度单,无法同步");
            }
            List<SysTaskAttachment> attachmentList=sysTaskService.getAttachmentsByTaskId(taskId);
            // 执行同步
            List<SysTaskAttachment> attachments = taskAttachmentSyncService.syncTaskAttachmentsToImageData(
                    attachmentList, serviceOrderId, dispatchOrdId,oaUserId);
 
            for(SysTaskAttachment attachment:attachments){
 
                taskAttachmentService.updateAttachment(attachment);
            }
 
            return success("成功同步 " + attachments.stream().count() + " 个附件");
        } catch (Exception e) {
            logger.error("同步任务附件失败", e);
            return error("同步失败:" + e.getMessage());
        }
    }
 
    /**
     * 检查任务是否上传了知情同意书
     * 
     * @param taskId 任务ID
     * @return 检查结果
     */
    @PostMapping("/task/check/{taskId}")
    public AjaxResult checkTaskAttachment(@PathVariable("taskId") Long taskId) {
        try {
            logger.info("检查任务 {} 的知情同意书附件", taskId);
            
            Boolean ret = taskAttachmentSyncService.checkAttachment(taskId, "1");
            
            if (ret) {
                logger.info("任务 {} 已上传知情同意书", taskId);
                return AjaxResult.success("已上传知情同意书");
            } else {
                logger.warn("任务 {} 未上传知情同意书", taskId);
                return AjaxResult.error(-1, "未上传知情同意书");
            }
        } catch (Exception e) {
            logger.error("检查任务 {} 的附件失败", taskId, e);
            return AjaxResult.error("检查失败:" + e.getMessage());
        }
    }
 
    /**
     * 检查附件是否已同步
     * 
     * @param attachmentId 附件ID
     * @return 同步状态
     */
    @PreAuthorize("@ss.hasPermi('task:general:query')")
    @GetMapping("/check/{attachmentId}")
    public AjaxResult checkAttachmentSynced(@PathVariable("attachmentId") Long attachmentId) {
        try {
            boolean synced = taskAttachmentService.isAttachmentSynced(attachmentId);
            return AjaxResult.success(synced ? "已同步" : "未同步", synced);
        } catch (Exception e) {
            logger.error("检查附件同步状态失败", e);
            return error("检查失败:" + e.getMessage());
        }
    }
}