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");
|
|
//其他信息
|
Map<String, Object> otherInfo = new HashMap<>();
|
//评价
|
otherInfo.put("serviceOrdVisit", Objects.toString(mingServiceOrder.getServiceOrdVisit(), "无"));
|
|
//发票获取
|
Map<String, Object> invoiceInfo = payInfoService.selectLatestInvoiceInfo("1016302788");
|
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)
|
@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));
|
}
|
|
|
|
|
}
|