【调度系统】广东民航医疗快线调度系统源代码
克樊道人
2024-12-02 61ce8cc6883e5f94e6470141df3484167caf31ed
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
<?php
$UnitNameID=empty($_REQUEST['UnitNameID'])!=false ? "" : addslashes($_REQUEST['UnitNameID']);
 
//分页信息
$page=empty($_REQUEST['page'])!=false ? 1 : $_REQUEST['page'];
$QuantityInt = 20;    //每页显示数量
$acc1=$page;        //当前页数
$acc2=0;            //总页数
$acc3=0;            //总记录数
 
//区域列表
$ArrayOrdAreaType=array();
$sql = "select vID,vtext from dictionary where vtitle='ServiceOrdAreaType' order by vOrder" ;
$data = sqlsrv_query($conn,$sql);
if($data == true){
    $i=0;
    while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) {
        $ArrayOrdAreaType[$rs['vID']]=$rs['vtext'];
        $i++;
    }
}
 
//类型列表
$ArrayOrdType=array();
$sql = "select vID,vtext from dictionary where vtitle='ServiceOrderType' order by vOrder" ;
$data = sqlsrv_query($conn,$sql);
if($data == true){
    $i=0;
    while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) {
        $ArrayOrdType[$rs['vID']]=$rs['vtext'];
        $i++;
    }
}
 
//查看各分公司报表权限
if (isDepartment("070109")==1) {
  $OrdClassListSql="";
  //$UnitNameID="1";
  If ($UnitNameID!="" and $UnitNameID!="0") {
      $sql="select vOrder2 from dictionary where vtitle='UnitName' and vID=".$UnitNameID;
        $data = sqlsrv_query($conn,$sql);
        if($data == true){
            if (sqlsrv_rows_affected($data)!=0) {
                while($rs = sqlsrv_fetch_array($data) ) {
                    $UnitTypeID        = $rs[0];
                    $sql="select vID,vtext,vOrder2 from dictionary where vID in (".$UnitTypeID.") and vtitle='OrderClass' order by vOrder";
                    $data1 = sqlsrv_query($conn,$sql);
                    if($data1 == true){
                        while($rs1 = sqlsrv_fetch_array($data1) ) {
                            $OrderClassID        = $rs1['vOrder2'];
                            $OrdClassListSql    .= ",".$OrderClassID;
                        }
                    }
                    $OrdClassListSql=substr($OrdClassListSql,1);
                    $OrdClassListSql=str_replace(",","','",$OrdClassListSql);
                }
            }
        }
    }else{
        $sql="select vID,vtext,vOrder2 from dictionary where vType in (1,2) and vtitle='OrderClass' order by vOrder";
        $data1 = sqlsrv_query($conn,$sql);
        if($data1 == true){
            while($rs1 = sqlsrv_fetch_array($data1) ) {
                $OrderClassID        = $rs1['vOrder2'];
                $OrdClassListSql    .= ",".$OrderClassID;
            }
        }
        $OrdClassListSql=substr($OrdClassListSql,1);
        $OrdClassListSql=str_replace(",","','",$OrdClassListSql);
    }
}
 
//查询条件
$searchSql="";
$searchTXT=empty($searchTXT)!=false ? "" : $searchTXT;
if ($searchTXT!=""){
    $searchSql=" and (OA_Name like '%$searchTXT%') ";
}else{
    $searchSql="";
}
if (empty($_REQUEST['CarID'])==false){
    $searchSql=$searchSql." and DispatchOrdCarID=".$_REQUEST['CarID']." ";
}
 
$orderby=empty($orderby)!=false ? "" : $orderby;
If (strrpos($orderby," desc")>1){
    $orderbydesc="";
    $descTXT="↓";
}else{
    $orderbydesc=" desc";
    $descTXT="↑";
}
 
If ($orderby=="") {
  $orderby="OA_DepartmentID,OA_User_ID";
  $descTXT="↓";
}
 
if ($OrdDateType=="0" and $OrdDateStart=="" and $OrdDateEnd=="") {$OrdDateType=4;}
 
//查询开始
$SqlOrdDateType=empty($SqlOrdDateType)!=false ? "" : $SqlOrdDateType;
$sql="select DispatchOrdID,ServiceOrdID,CarStItm_Time=convert(char,CarStItm_Time,120)
,DispatchOrdNo=DispatchOrdClass+convert(nvarchar(10),year(DispatchOrd_NS_Time))+right('0'+convert(nvarchar(10),month(DispatchOrd_NS_Time)),2)+right('0'+convert(nvarchar(10),day(DispatchOrd_NS_Time)),2)+'-'+right('00'+convert(nvarchar(10),DispatchOrdNo),3)
,OrdDistance=convert(money,Replace(Replace(ServiceOrdTraDistance,'公里',''),'km','')),ServiceOrdAreaType,ServiceOrdType,DispatchOrd_NS_Time=convert(char,DispatchOrd_NS_Time,23)
,TraStreet=(case when DispatchOrdTraVia<>'' then DispatchOrdTraVia else DispatchOrdTraStreet end)
,TraEnd=DispatchOrdTraEnd
,ServiceOrdPtOutHosp=(select vtext from dictionary where vType=1 and vtitle='HospName' and vID=ServiceOrdPtOutHosp)
,ServiceOrdPtInHosp=(select vtext from dictionary where vType=1 and vtitle='HospName' and vID=ServiceOrdPtInHosp)
,RunningTimeJson=(select '['+ stuff((select ',{\"State\": \"' + convert(varchar(2),DispatchOrdState) + '\",\"StateDate\": \"' + convert(varchar(20),DispatchOrdStartDate,120) + '\"}' from DispatchOrd_Running where DispatchOrdIDDt=DispatchOrdID order by id for xml path('')),1,1,'') +']') from DispatchOrd,ServiceOrder where ServiceOrdID=ServiceOrdIDDt and DispatchOrdState in (8,9) and DispatchOrd_NS_Time ".$SqlOrdDateType.$searchSql." and ServiceOrdClass in ('".$OrdClassListSql."') order by DispatchOrd_NS_Time desc";
//echo $sql;exit;
$data = sqlsrv_query($conn,$sql);
if($data == true){
    $FormArray=array();
    //表头
    $FormArray[0]=array("序号","日期","单号","类型","转出医院","转出地址","转入医院","转入地址","实际公里数","出车检查时间","出车时间","收车时间","转运时间");
 
    $FormArrayX=count($FormArray[0]);
    if (sqlsrv_rows_affected($data)==0) {
        $SystemMessageType=2;
        $SystemMessageTXT="数据库中相关无数据!";
        $y=0;
    } else {
        $i=1;
        while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) {
            //读取数据
            $DispatchOrdID        = $rs['DispatchOrdID'];
            $ServiceOrdID        = $rs['ServiceOrdID'];
            $DispatchOrdNo        = $rs['DispatchOrdNo'];
            $ServiceOrdAreaType    = $rs['ServiceOrdAreaType'];
            $ServiceOrdType        = $rs['ServiceOrdType'];
            $OrdDistance        = $rs['OrdDistance'];
            $DispatchOrd_NS_Time= $rs['DispatchOrd_NS_Time'];
            $ServiceOrdPtOutHosp= $rs['ServiceOrdPtOutHosp'];
            $ServiceOrdPtInHosp    = $rs['ServiceOrdPtInHosp'];
            $TraStreet            = $rs['TraStreet'];
            $TraEnd                = $rs['TraEnd'];
            $CarStItm_Time        = $rs['CarStItm_Time'];
            $RunningTimeJson    = $rs['RunningTimeJson'];
            $RunningTimeArr        = json_decode($RunningTimeJson,true);
            $RunningTime_start=0;
            $RunningTime_wait_sa=0;
            $RunningTime_wait_ba=0;
            $RunningTime_end=0;
            $RunningTime_wait=0;
            $RunningTime_wait=0;
            $RunningTime_wait="";
            $RunningTime_diff="";
            if (!empty($RunningTimeArr)){
                foreach($RunningTimeArr as $x=>$RunningTimeArr_value) {
                    switch ($RunningTimeArr_value["State"])
                    {
                        case "4":
                            if (empty($RunningTime_start)) {$RunningTime_start=$RunningTimeArr_value["StateDate"];}break;
                        case "5":
                            if (empty($RunningTime_wait_sa)) {$RunningTime_wait_sa=$RunningTimeArr_value["StateDate"];}break;
                        case "6":
                            if (empty($RunningTime_wait_ba)) {$RunningTime_wait_ba=$RunningTimeArr_value["StateDate"];}break;
                        case "7":
                            $RunningTime7=$RunningTimeArr_value["StateDate"];break;
                        case "8":
                            if (empty($RunningTime_end)) {$RunningTime_end=$RunningTimeArr_value["StateDate"];}break;
                        case "9":
                            if (empty($RunningTime_end)) {$RunningTime_end=$RunningTimeArr_value["StateDate"];}break;
                    }
                }
            }else{
                $RunningTime_start="--";
                $RunningTime_end="--";
            }
            if (!empty($RunningTime_wait_sa) and !empty($RunningTime_wait_ba)) {
                $RunningTime_wait_date=floor((strtotime($RunningTime_wait_ba)-strtotime($RunningTime_wait_sa))/86400);
                $RunningTime_wait_hour=floor((strtotime($RunningTime_wait_ba)-strtotime($RunningTime_wait_sa))%86400/3600);
                $RunningTime_wait_minute=floor((strtotime($RunningTime_wait_ba)-strtotime($RunningTime_wait_sa))%86400%3600/60);
                if (!empty($RunningTime_wait_date)) {$RunningTime_wait=$RunningTime_wait.$RunningTime_wait_date."天 ";}
                if (!empty($RunningTime_wait_hour)) {$RunningTime_wait=$RunningTime_wait.$RunningTime_wait_hour."小时 ";}
                if (!empty($RunningTime_wait_minute)) {$RunningTime_wait=$RunningTime_wait.$RunningTime_wait_minute."分钟";}
                if (empty($RunningTime_wait)) {$RunningTime_wait="小于1分钟";}
            }
            if (empty($RunningTime_start) and !empty($RunningTime_end)) {$RunningTime_start=$RunningTime_end;}
            if (!empty($RunningTime_start) and !empty($RunningTime_end)) {
                $RunningTime_diff_date=floor((strtotime($RunningTime_end)-strtotime($RunningTime_start))/86400);
                $RunningTime_diff_hour=floor((strtotime($RunningTime_end)-strtotime($RunningTime_start))%86400/3600);
                $RunningTime_diff_minute=floor((strtotime($RunningTime_end)-strtotime($RunningTime_start))%86400%3600/60);
                if (!empty($RunningTime_diff_date)) {$RunningTime_diff=$RunningTime_diff.$RunningTime_diff_date."天 ";}
                if (!empty($RunningTime_diff_hour)) {$RunningTime_diff=$RunningTime_diff.$RunningTime_diff_hour."小时 ";}
                if (!empty($RunningTime_diff_minute)) {$RunningTime_diff=$RunningTime_diff.$RunningTime_diff_minute."分钟";}
                if (empty($RunningTime_diff)) {$RunningTime_diff="小于1分钟";}
            }
            if (empty($CarStItm_Time)) {$CarStItm_Time=$RunningTime_start;}
            //读取数据--End
 
            //写入数组
            $FormArray[$i][0]=$i;
            $FormArray[$i][1]=$DispatchOrd_NS_Time;
            $FormArray[$i][2]="<a href=DispatchOrder.gds?DispatchOrdID=".$DispatchOrdID."&OrdDateType=4&OrdClassList=&h_menu1_1=1 target=_blank>".$DispatchOrdNo."</a>";
            $FormArray[$i][3]=$ArrayOrdAreaType[$ServiceOrdAreaType];
            $FormArray[$i][4]=$ArrayOrdType[$ServiceOrdType];
            $FormArray[$i][5]=$ServiceOrdPtOutHosp;
            $FormArray[$i][6]=$TraStreet;
            $FormArray[$i][7]=$ServiceOrdPtInHosp;
            $FormArray[$i][8]=$TraEnd;
            $FormArray[$i][9]=floatval(number_format($OrdDistance,2,".",""));
            $FormArray[$i][10]=$CarStItm_Time;
            $FormArray[$i][11]=$RunningTime_start;
            $FormArray[$i][12]=$RunningTime_end;
            $FormArray[$i][13]=$RunningTime_diff;
            //$FormArray[$i][14]=$RunningTime_wait;
            $i++;
            
        }
            
 
    }
}
 
if ($is_CSV==2) {
    echo json_encode($FormArray);
}
//echo print_r($FormArray);
//exit;
?>