1
hao
2025-05-20 8e24c6fea30d9b179375ee2893710cdec2443b13
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
package com.web.jhsop.websocket.service.internal;
 
 
import com.alibaba.fastjson.JSONObject;
import com.app.base.data.ApiResponseResult;
import com.app.base.service.FtpClientService;
import com.web.ftp.service.FileCheckService;
import com.web.jhsop.service.JhSopDataService;
 
import com.web.jhsop.websocket.dao.SopDeviceDao;
import com.web.jhsop.websocket.dao.SopFileDao;
import com.web.jhsop.websocket.entity.SopDevice;
import com.web.jhsop.websocket.entity.SopFile;
import com.web.jhsop.websocket.service.SopSendService;
import com.web.jhsop.websocket.util.WebSocketUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@Transactional(propagation = Propagation.REQUIRED)
public class SopSendServiceImpl implements SopSendService {
 
    @Autowired
    private WebSocketUtil webSocketUtil;
 
    @Autowired
    private FtpClientService ftpClientService;
 
    @Autowired
    private FileCheckService fileCheckService;
 
    @Autowired
    private SopDeviceDao sopDeviceDao;
 
    @Autowired
    private SopFileDao sopFileDao;
 
    @Autowired
    private JhSopDataService jhSopDataService;
 
    @Override
    public ApiResponseResult sendSop(String deviceCode, String url, String account, String password, String path, String root, String fileName, String workOrder, String processLine, Integer page) throws Exception {
        //接收设备id 文件ip地址 返回文件url地址和文件流
//        ApiResponseResult download = ftpClientService.download(url, 21, account, password, path, fileName, root);
//        Object data = download.getData();
        StringBuilder sb = new StringBuilder();
        sb.append("sop/getFtpFile?");
        sb.append("deviceCode="+(deviceCode==null?"":deviceCode));
        sb.append("&url="+(url==null?"":url));
        sb.append("&account="+(account==null?"":account));
        sb.append("&password="+(password==null?"":password));
        sb.append("&path="+(path==null?"":path));
        sb.append("&root="+(root==null?"":root));
        sb.append("&fileName="+(fileName==null?"":fileName));
        String ftpFilePath = sb.toString();
        Map<String,Object> resMap = new HashMap<>();
        String[] split = deviceCode.split(",");
 
//        ApiResponseResult result = jhSopDataService.getProcessLine(workOrder);
//        Object orderData = result.getData();
 
        resMap.put("ftpFilePath",ftpFilePath);
        resMap.put("workOrder",workOrder);
        resMap.put("processLine",processLine);
        resMap.put("fileName",fileName);
        resMap.put("page",page);
        String res = JSONObject.toJSONString(resMap);
        webSocketUtil.sendMoreMessage(split,res);
        return ApiResponseResult.success().data(resMap);
    }
 
    @Override
    public ApiResponseResult getFtpFile(String deviceCode, String url, String account, String password, String path, String root, String fileName, HttpServletResponse response) throws Exception {
        fileCheckService.onlineViewPdf(url,21,account,password,path,fileName,root,response);
        return null;
    }
 
    @Override
    public ApiResponseResult sendAllSop(String url, String account, String password, String path, String root, String fileName, String workOrder, String processLine, Integer page) {
        StringBuilder sb = new StringBuilder();
        sb.append("sop/getFtpFile?");
        sb.append("&url="+(url==null?"":url));
        sb.append("&account="+(account==null?"":account));
        sb.append("&password="+(password==null?"":password));
        sb.append("&path="+(path==null?"":path));
        sb.append("&root="+(root==null?"":root));
        sb.append("&fileName="+(fileName==null?"":fileName));
        String ftpFilePath = sb.toString();
//        webSocketUtil.sendAllMessage(ftpFilePath);
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("ftpFilePath",ftpFilePath);
        resMap.put("workOrder",workOrder);
        resMap.put("processLine",processLine);
        resMap.put("fileName",fileName);
        resMap.put("page",page);
        String res = JSONObject.toJSONString(resMap);
        webSocketUtil.sendAllMessage(res);
        return null;
    }
 
    @Override
    public ApiResponseResult toSheetByPage(String deviceId, String page) {
        webSocketUtil.sendOneMessage(deviceId,page);
        return ApiResponseResult.success();
    }
 
    @Override
    public ApiResponseResult getAllDevice() {
        List<SopDevice> list =  sopDeviceDao.findByIsDel(0);
        return  ApiResponseResult.success().data(list);
    }
 
    @Override
    public ApiResponseResult distributeFile(String deviceId, SopFile sopFile, String order) throws Exception {
        return sendSop(deviceId,sopFile.getBsUrl(),sopFile.getBsAccount(),sopFile.getBsPassword(),sopFile.getBsPath(),sopFile.getBsRoot(),sopFile.getBsName(),order,"",1);
    }
 
    @Override
    public ApiResponseResult getSopFile() {
        List<SopFile> list = sopFileDao.findByIsDel(0);
        return ApiResponseResult.success().data(list);
    }
}