wzp
2025-05-03 ff76ba9c9c56aa2dd1c6a96d5d6365fbb3db1fad
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
package com.ruoyi.web.controller.system;
 
import java.util.List;
import java.util.Objects;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.math.BigDecimal;
 
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.constant.HttpStatus;
 
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.IDispatchOrdService;
import com.ruoyi.system.service.IPayInfoService;
import com.ruoyi.system.service.ITbOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IServiceOrderService;
 
 
import javax.servlet.http.HttpServletResponse;
 
/**
 * 服务订单 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/order")
//@DataSource(DataSourceType.SQLSERVER)
public class ServiceOrderController extends BaseController {
    @Autowired
    private IServiceOrderService serviceOrderService;
 
    @Autowired
    private ITbOrdersService tbOrdersService;
 
    @Autowired
    private IDispatchOrdService dispatchOrdService;
 
    @Autowired
    private IPayInfoService payInfoService;
 
    /**
     * 获取服务订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceOrder serviceOrder) {
        // 获取总数
        int total = serviceOrderService.selectServiceOrderCount(serviceOrder);
        // 获取分页数据
        List<ServiceOrder> list = serviceOrderService.selectServiceOrderList(serviceOrder);
        // 设置总数
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(total);
        return rspData;
    }
 
    @Log(title = "服务订单", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceOrder serviceOrder) {
        List<ServiceOrder> list = serviceOrderService.selectServiceOrderList(serviceOrder);
        ExcelUtil<ServiceOrder> util = new ExcelUtil<ServiceOrder>(ServiceOrder.class);
        util.exportExcel(response, list, "服务订单数据");
    }
 
    /**
     * 根据服务订单编号获取详细信息
     */
 
    @Anonymous
    @GetMapping(value = "/{serviceOrdId}")
    public AjaxResult getInfo(@PathVariable Long serviceOrdId) {
        TbOrders orderDetail = tbOrdersService.selectTbOrdersByOrderID(serviceOrdId);
 
        //查询服务单
        ServiceOrder mingServiceOrder = serviceOrderService.selectServiceOrderById(Long.valueOf(orderDetail.getServiceOrdID()));
 
        DispatchOrd dispatchOrd = dispatchOrdService.selectDispatchOrdByServiceOrdIDDt(mingServiceOrder.getServiceOrdId().toString());
 
        Map<String, Object> data = new HashMap<>();
        
        // 构建订单基本信息
        Map<String, Object> orderInfo = new HashMap<>();
        orderInfo.put("OrderID", orderDetail.getOrderID());
        
        // 格式化时间
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
        // 格式化创建时间
        String formattedCreateTime = orderDetail.getCreateTime() != null ? 
            dateFormat.format(orderDetail.getCreateTime()) : "";
        orderInfo.put("orderTime", formattedCreateTime);
        
        // 格式化预约时间
        String formattedBookingTime = orderDetail.getBookingDate() != null ? 
            dateFormat.format(orderDetail.getBookingDate()) : "";
        orderInfo.put("appointmentTime", formattedBookingTime);
 
 
 
 
        if(dispatchOrd!=null) {
            //要查询调度单
            // 格式化调度时间
            String formattedDispatchTime = dispatchOrd.getDispatchOrdStartDate() != null ?
                    dateFormat.format(dispatchOrd.getDispatchOrdStartDate()) : "";
            orderInfo.put("dispatchTime", formattedDispatchTime);
        }
        
        // 订单状态转换逻辑
        String orderStatus;
        if (mingServiceOrder.getServiceOrdState() == 4) {
            orderStatus = "已取消";
        } else if (mingServiceOrder.getServiceOrdState() == 3) {
            orderStatus = "已调度";
        } else if (mingServiceOrder.getServiceOrdTraTxnPrice().compareTo(BigDecimal.ZERO) > 0 
                && mingServiceOrder.getServiceOrdState() <= 1) {
            orderStatus = "咨询单";
        } else if (mingServiceOrder.getServiceOrdTraTxnPrice().compareTo(BigDecimal.ZERO) > 0 
                && mingServiceOrder.getServiceOrdState() != 4) {
            orderStatus = "已报价";
        } else {
            orderStatus = "咨询单";
        }
        
        orderInfo.put("orderStatus", orderStatus);
        orderInfo.put("orderSource","广交集团");
        orderInfo.put("externalNo",orderDetail.getServiceOrdNo());
 
        if(orderStatus.contains("调度")){
            orderInfo.put("documentStatus", "调度单");
        }
        else{
            orderInfo.put("documentStatus", "咨询单");
        }
 
        orderInfo.put("price",mingServiceOrder.getServiceOrdTraTxnPrice());//价格
        
        // 构建患者信息
        Map<String, Object> patientInfo = new HashMap<>();
        patientInfo.put("contactName", orderDetail.getLinkPerson());
        patientInfo.put("contactPhone", orderDetail.getLinkTel());
        patientInfo.put("patientName", orderDetail.getPatientName());
        patientInfo.put("patientAge", orderDetail.getAge());
        // 性别转换:1是男,其他是女
        patientInfo.put("patientGender", "1".equals(orderDetail.getSex()) ? "男" : "女");
        patientInfo.put("patientWeight", orderDetail.getKg());
        
        // 构建服务信息
        Map<String, Object> serviceInfo = new HashMap<>();
        serviceInfo.put("startAddress", orderDetail.getLocalAddress());
        serviceInfo.put("startLocation", orderDetail.getLocalLongitude() + "," + orderDetail.getLocalLatitude());
        serviceInfo.put("endAddress", orderDetail.getSendAddress());
        serviceInfo.put("endLocation", orderDetail.getSendLongitude() + "," + orderDetail.getSendLatitude());
        serviceInfo.put("distance", orderDetail.getBookingKM());
        serviceInfo.put("liftService", orderDetail.getLiftingCode());
        serviceInfo.put("liftFloor", orderDetail.getLiftingFloor());
 
 
        //构建调度信息
        Map<String, Object> dispatchInfo = new HashMap<>();
        if(dispatchOrd!=null){
            String dispatchOAEntourage = dispatchOrd.getDispatchOrd_OAEntourage();
            String dispatchOAName = dispatchOrd.getDispatchOrd_OAName();
            
            if (dispatchOAEntourage != null && dispatchOAName != null) {
                String[] entourages = dispatchOAEntourage.split(",");
                String[] names = dispatchOAName.split(",");
                
                // 用于存储不同角色的人员
                Map<String, StringBuilder> roleMap = new HashMap<>();
                roleMap.put("driver", new StringBuilder());
                roleMap.put("doctor", new StringBuilder());
                roleMap.put("nurse", new StringBuilder());
                
                // 遍历找出对应角色的人员
                for (int i = 0; i < Math.min(entourages.length, names.length); i++) {
                    String role = entourages[i].trim();
                    String name = names[i].trim();
                    
                    switch(role) {
                        case "司机":
                            appendName(roleMap.get("driver"), name);
                            break;
                        case "医生":
                            appendName(roleMap.get("doctor"), name);
                            break;
                        case "护士":
                            appendName(roleMap.get("nurse"), name);
                            break;
                    }
                }
                
                // 将收集到的人员信息放入dispatchInfo
                dispatchInfo.put("driver", roleMap.get("driver").toString());
                dispatchInfo.put("doctor", roleMap.get("doctor").toString());
                dispatchInfo.put("nurse", roleMap.get("nurse").toString());
 
                //调度时间
                String formattedDispatchTime = dispatchOrd.getDispatchOrdStartDate() != null ?
                    dateFormat.format(dispatchOrd.getDispatchOrdStartDate()) : "";
                dispatchInfo.put("dispatchTime", formattedDispatchTime);
 
                dispatchInfo.put("dispatchStatus","已调度");
            }
 
 
            //车牌号
            String carLicense = dispatchOrdService.selectCarLicenseByCarId(Integer.valueOf(dispatchOrd.getDispatchOrdCarID()));
            dispatchInfo.put("carLicense", carLicense);
        }
 
        //病人情况
        Map<String, Object> medicalInfo = new HashMap<>();
        medicalInfo.put("hasConsciousness", orderDetail.getSense());
        medicalInfo.put("complaint",orderDetail.getComplaint());
        
        //条件
        List<DictionaryCondition> conditions = dispatchOrdService.selectDictionaryConditions();
        List<Integer> conditionIds = dispatchOrdService.selectConditionIdsByServiceOrdCoId(Long.valueOf(orderDetail.getServiceOrdID()));
 
        String patientCondition = "";//病人情况
        String useVentilator = "";//使用呼吸机
        for(DictionaryCondition condition : conditions){
 
            if(conditionIds.contains(condition.getVID())){
                patientCondition += condition.getVOrder2() + ": " + condition.getVtext() + ";   ";
            }
 
            if(condition.getVOrder2().contains("呼吸机")){
                useVentilator = condition.getVtext();
            }
        }
 
        medicalInfo.put("patientCondition", patientCondition);
        medicalInfo.put("useVentilator", useVentilator);
 
 
        //支付信息
//        List<PayInfo> payInfoList = payInfoService.selectPayInfoByServiceOrdIDDt(orderDetail.getServiceOrdID()); //1016302788
        List<PayInfo> payInfoList = payInfoService.selectPayInfoByServiceOrdIDDt("1016302788");
 
        data.put("orderInfo", orderInfo);
        data.put("patientInfo", patientInfo);
        data.put("serviceInfo", serviceInfo);
        data.put("medicalInfo", medicalInfo); // 暂时为空
        data.put("dispatchInfo", dispatchInfo);  // 更新为包含人员信息的dispatchInfo
        data.put("paymentInfo", payInfoList); // 暂时为空
        data.put("operationInfo", new ArrayList<>()); // 暂时为空
        
        return AjaxResult.success(data);
    }
 
    // 添加辅助方法来处理名字的拼接
    private void appendName(StringBuilder sb, String name) {
        if (sb.length() > 0) {
            sb.append(",");
        }
        sb.append(name);
    }
 
    /*
    新增订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "服务订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceOrder serviceOrder) {
        return toAjax(serviceOrderService.insertServiceOrder(serviceOrder));
    }
 
    /**
     * 修改服务订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "服务订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceOrder serviceOrder) {
        return toAjax(serviceOrderService.updateServiceOrder(serviceOrder));
    }
 
    /**
     * 删除服务订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "服务订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceOrdIds}")
    public AjaxResult remove(@PathVariable Long[] serviceOrdIds) {
        return toAjax(serviceOrderService.deleteServiceOrderByIds(serviceOrdIds));
    }