wzp
2025-05-21 e6d10b40cf08fb35a73552aa4f0d2e9ac0b227df
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ServiceOrderController.java
@@ -1,10 +1,22 @@
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;
@@ -22,7 +34,6 @@
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ServiceOrder;
import com.ruoyi.system.service.IServiceOrderService;
@@ -30,15 +41,23 @@
/**
 * 服务订单 信息操作处理
 *
 *
 * @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;
    /**
     * 获取服务订单列表
@@ -71,14 +90,266 @@
    /**
     * 根据服务订单编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @Anonymous(needSign = true)
    @GetMapping(value = "/{serviceOrdId}")
    public AjaxResult getInfo(@PathVariable Long serviceOrdId) {
        return success(serviceOrderService.selectServiceOrderById(serviceOrdId));
        TbOrders orderDetail = tbOrdersService.selectTbOrdersByOrderID(serviceOrdId);
        if(orderDetail==null){
            return AjaxResult.error("订单不存在");
        }
        //查询服务单
        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 = new ArrayList<>();
        if(serviceOrdId==88801)
        {
            //测试数据
            payInfoList = payInfoService.selectPayInfoByServiceOrdIDDt("1016302788");//测试使用
        }
        else{
            payInfoList = payInfoService.selectPayInfoByServiceOrdIDDt(orderDetail.getServiceOrdID()); //正式使用
        }
        //其他信息
        Map<String, Object> otherInfo = new HashMap<>();
        //评价
        otherInfo.put("serviceOrdVisit", Objects.toString(mingServiceOrder.getServiceOrdVisit(), "-"));
        //知情同意书
        List<String> imageUrls = new ArrayList<>();//测试使用
        if(serviceOrdId==88801)
        {
            //测试数据
            imageUrls.add("https://sys.966120.com.cn/upload/202505/3016127678_3VhEv_VVql2K6eM9tS9uXgKv8fm7vaKtrSFCiP0SraTgz2qe1isgvIuUrqSNv-XgEvdC5kFUxeyrn_wz8Mfc2Sg.jpg");
            imageUrls.add("https://sys.966120.com.cn/upload/202505/3016127678_3cDOPpqc_fzEJ-dHz8lq5aIx3tsnmEtossC6F5VCi2vj6sBwkuzOx4g1RcsWnQ3XNua7COADksYI1rHnbizccOw.jpg");
            otherInfo.put("imageUrls", imageUrls);
        }
        else{
            imageUrls = dispatchOrdService.selectImageUrlsByDOrdIDDt(orderDetail.getServiceOrdID());  //正式使用
            otherInfo.put("imageUrls", imageUrls);
        }
        //发票获取
        Map<String, Object> invoiceInfo = new HashMap<>();
        if(serviceOrdId==88801)
        {
            //测试数据
            invoiceInfo = payInfoService.selectLatestInvoiceInfo("1016302788");
        }
        else{
            invoiceInfo = payInfoService.selectLatestInvoiceInfo(orderDetail.getServiceOrdID()); //正式使用
        }
        String invoiceStatus = "";
        if (invoiceInfo != null && invoiceInfo.get("AuditStatus") != null) {
            switch (String.valueOf(invoiceInfo.get("AuditStatus"))) {
                case "0":
                    invoiceStatus = "未处理";
                    break;
                case "1":
                    invoiceStatus = "延后处理";
                    break;
                case "3":
                    invoiceStatus = "已开票";
                    break;
                case "4":
                    invoiceStatus = "取消申请";
                    break;
            }
            otherInfo.put("invoiceStatus",invoiceInfo.get("InvoiceMakeout")+"-"+invoiceStatus);
        }
        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("otherInfo", otherInfo);
        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)
@@ -106,4 +377,8 @@
    public AjaxResult remove(@PathVariable Long[] serviceOrdIds) {
        return toAjax(serviceOrderService.deleteServiceOrderByIds(serviceOrdIds));
    }