StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_FirstAid_CallDB.cs

387 lines
18 KiB
C#
Raw Normal View History

2024-03-11 09:47:34 +08:00
using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
namespace HL_FristAidPlatform_DataBase
{
//T_Service_FirstAid_Call
public class T_Service_FirstAid_CallDB : BaseDB, IT_Service_FirstAid_Call
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(T_Service_FirstAid_Call model)
{
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(T_Service_FirstAid_Call model)
{
return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).WhereColumns(it => new { it.GUID }).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(string GUID)
{
return db.Deleteable<T_Service_FirstAid_Call>().In(GUID).ExecuteCommand() == 1 ? true : false;
}
/// <summary>
/// 获取单个数据
/// </summary>
public TableModel<T_Service_FirstAid_Call> Get(string GUID)
{
TableModel<T_Service_FirstAid_Call> t = new TableModel<T_Service_FirstAid_Call>();
var listMode = db.Queryable<T_Service_FirstAid_Call>().Where(it => it.GUID == GUID && it.DeleteFlag == 0).ToList();
t.Code = 0;
t.PageCount = listMode.Count;
t.TotalNumber = listMode.Count;
t.Data = listMode;
t.Msg = "成功";
return t;
}
/// <summary>
/// 获取单个数据
/// </summary>
public T_Service_FirstAid_Call GetOfGUID(string GUID)
{
return db.Queryable<T_Service_FirstAid_Call>().Where(it => it.GUID == GUID && it.DeleteFlag == 0).First();
}
/// <summary>
/// 打印报表 获取单个数据
/// </summary>
public TableModel<DispatchModel> GetOfDispatch(string GUID)
{
var oneClass = db.Queryable<T_Service_FirstAid_Call, T_Base_Hospital, T_Base_WristStrap, T_Base_AccidentInfo, T_Base_AccidentLevel>
((a, b, d, e, f) => new JoinQueryInfos(
JoinType.Left, a.HospitalGuid == b.GUID,
JoinType.Left, a.WristStrapID == d.ID,
JoinType.Left, a.AccidentGUID == e.GUID,
JoinType.Left, a.AccidentLeveGUID == f.GUID
)).Where((a, b, d, e, f) => a.DeleteFlag == 0).Where((a, b, d, e, f) => a.GUID == GUID)
.Select((a, b, d, e, f) => new DispatchModel
{
GUID = a.GUID,
HospitalName = b.Name,
SchedulingTime = a.SchedulingTime,
DispatchNo = a.DispatchNo,
CallAddress = a.Attack_Address,
WaitingAddress = a.WaitingAddress,
ContactsPhone = a.ContactsPhone,
Contacts = a.Contacts,
Pathogeny = a.Pathogeny,
PatientNumber = a.PatientNumber,
AccompanyinPgersonnel = a.AccompanyinPerName,
Note = a.Note,
VehicleNumber = a.PlateNumber,
ECGNumber = a.ECGNumber,
LabelCard = d.Code,
DrivingTime = a.DrivingTime.ToString(),
Name = a.Name,
Age = a.Age,
Gender = a.Gender.ToString(),
ChiefComplaint = a.ChiefComplaint,
MedicalHistory = a.MedicalHistory,
AllergyHistory = a.AllergyHistory,
AccidentName = e.ParentName,
LeveName = f.LevelName
}).ToList();
TableModel<DispatchModel> t = new TableModel<DispatchModel>();
var listMode = oneClass;
t.Code = 0;
t.PageCount = 1;
t.TotalNumber = 1;
t.Data = listMode;
t.Msg = "成功";
return t;
}
/// <summary>
/// 获得数据列表 派车任务
/// </summary>
public TableModel<DispatchTaskModel> GetPageList(string hospitalGuid, string startTime, string endTime, int systmeModelId, int accidentType, string name, int gender, int pageIndex, int pageSize)
{
int total = 0;
var oneClass = db.Queryable<T_Service_FirstAid_Call, T_Base_Hospital, T_Base_WristStrap, T_Base_AccidentInfo, T_Base_AccidentLevel>
((a, b, d, e, f) => new JoinQueryInfos(
JoinType.Left, a.HospitalGuid == b.GUID,
JoinType.Left, a.WristStrapID == d.ID,
JoinType.Left, a.AccidentGUID == e.GUID,
JoinType.Left, a.AccidentLeveGUID == f.GUID
))
.Where((a, b, d, e, f) => a.CallHospitalGuid == hospitalGuid)
.WhereIF(!SqlFunc.IsNullOrEmpty(startTime), (a, b, d, e, f) => a.DrivingTime >= Convert.ToDateTime(startTime))
.WhereIF(!SqlFunc.IsNullOrEmpty(endTime), (a, b, d, e, f) => a.DrivingTime <= Convert.ToDateTime(endTime).AddDays(1))
//.WhereIF(systmeModelId != -1, (a, b, d, e, f) => i.SystemModuleID == systmeModelId)
.WhereIF(accidentType == 1, (a, b, d, e, f) => a.AccidentGUID == "")
.WhereIF(accidentType == 2, (a, b, d, e, f) => a.AccidentGUID != "")
.WhereIF(!SqlFunc.IsNullOrEmpty(name), (a, b, d, e, f) => a.Name.Contains(name))
.WhereIF(gender != -1, (a, b, d, e, f) => a.Gender == gender)
.OrderBy((a, b, d, e, f) => a.DrivingTime, OrderByType.Desc)
.Select((a, b, d, e, f) => new DispatchTaskModel
{
GUID = a.GUID,
Flag = a.Flag,
TaskState = a.TaskState,
Note = a.Note,
HospitalName = b.Name,
SchedulingTime = a.SchedulingTime,
DispatchNo = a.DispatchNo,
CallAddress = a.Attack_Address,
ContactsPhone = a.ContactsPhone,
Contacts = a.Contacts,
VehicleNumber = a.PlateNumber,
ECGNumber = a.ECGNumber,
LabelCard = d.Code,
ChiefComplaint = a.ChiefComplaint,
MedicalHistory = a.MedicalHistory,
AccidentGUID = a.AccidentGUID,
AllergyHistory = a.AllergyHistory,
AccidentName = e.ParentName,
AccidentLeveGUID = a.AccidentLeveGUID,
LeveName = f.LevelName,
ParentName = a.Name,
WaitingAddress = a.WaitingAddress,
Gender = a.Gender,
Pathogeny = a.Pathogeny,
Age = a.Age,
Name = a.Name,
CallType = a.CallType,
CallTime = a.CallTime,
PoliceCall = a.PoliceCall,
PoliceReceiver = a.PoliceReceiver,
AbnormalScheduling = a.AbnormalScheduling,
DrivingTime = a.DrivingTime.ToString("yyyy-MM-dd hh:ss:mm"),
ArrivalTime = a.ArrivalTime,
ReturnHospitalTime = a.ReturnHospitalTime,
BoardingTime = a.BoardingTime,
ArriveHospitalTime=a.ArriveHospitalTime,
ToAddress = a.ToAddress
}).ToPageList(pageIndex, pageSize, ref total);
List<DispatchTaskModel> data = oneClass;
TableModel<DispatchTaskModel> t = new TableModel<DispatchTaskModel>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = total;
t.Data = data;
t.Msg = "成功";
return t;
}
/// <summary>
/// 获取当天最大的事件编号
/// </summary>
/// <returns></returns>
public string GetMaxDispatchNo()
{
string str = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
return db.Queryable<T_Service_FirstAid_Call>().Where(it => it.DispatchNo.Substring(0, 7) == str).Max(it => it.DispatchNo);
}
/// <summary>
/// 查询是否存在该患者
/// </summary>
/// <param name="patientGUID"></param>
/// <returns></returns>
public T_Service_FirstAid_Call GetPatientInfo(string patientGUID)
{
return db.Queryable<T_Service_FirstAid_Call>().First(it => it.GUID == patientGUID);
}
/// <summary>
/// 更新派车任务时间
/// </summary>
/// <param name="guid"></param>
/// <param name="type"></param>
/// <returns></returns>
public string UpdateTime(string guid, int type)
{
string reuslt = "";
string dateTime = DateTime.Now.ToString();
int res = 0;
switch (type)
{
case 0:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { ArrivalTime = dateTime }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 1:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { BoardingTime = dateTime }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 2:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { ReturnHospitalTime = dateTime }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 3:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { ArriveHospitalTime = dateTime }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 4:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { TaskState = 0 }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 5:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { TaskState = 1 }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 6:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { TaskState = 2 }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 7:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { TaskState = 3 }).Where(it => it.GUID == guid).ExecuteCommand();
break;
case 8:
res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { TaskState = 4 }).Where(it => it.GUID == guid).ExecuteCommand();
break;
}
if (res > 0)
{
if (type <= 3)
{
reuslt = dateTime;
}
else
{
reuslt = type.ToString();
}
}
return reuslt;
}
/// <summary>
/// 更新异常原因
/// </summary>
/// <param name="model"></param>
public string UpadateAbnormalScheduling(AbnormalSchedulingModel model)
{
string result = "";
int res = db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call() { AbnormalScheduling = model.AbnormalScheduling }).Where(it => it.GUID == model.GUID).ExecuteCommand();
if (res == 1)
{
result = model.AbnormalScheduling;
}
else
{
result = "";
}
return result;
}
/// <summary>
/// 出车统计详情
/// </summary>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public TableModel<T_Service_FirstAid_Call> GetCensusDetailList(string hospitalGuid, string startTime, string endTime, int pageIndex, int pageSize)
{
int total = 0;
var expression = PredicateBuilder.True<T_Service_FirstAid_Call>().And(x => x.DeleteFlag == 0).And(x => x.HospitalGuid == hospitalGuid);
if (!string.IsNullOrEmpty(startTime))
{
var _startTime = DateTime.Parse(startTime);
expression = expression.And(x => Convert.ToDateTime(x.DrivingTime) >= _startTime);
}
if (!string.IsNullOrEmpty(endTime))
{
var _endTime = DateTime.Parse(endTime).AddDays(1);
expression = expression.And(x => Convert.ToDateTime(x.DrivingTime) <= _endTime);
}
List<T_Service_FirstAid_Call> data = db.Queryable<T_Service_FirstAid_Call>().Where(expression).ToPageList(pageIndex, pageSize, ref total);
TableModel<T_Service_FirstAid_Call> t = new TableModel<T_Service_FirstAid_Call>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = total;
t.Data = data;
t.Msg = "成功";
return t;
}
/// <summary>
/// 更新送往医院
/// </summary>
/// <param name="model"></param>
public void UpdateToAddress(UpdateToAddressModel model)
{
db.Updateable<T_Service_FirstAid_Call>().SetColumns(it => new T_Service_FirstAid_Call()
{
ToAddress = model.ToAddress
//HospitalGuid=model.HospitalGuid
}).Where(it => it.GUID == model.GUID).ExecuteCommand();
}
/// <summary>
/// 获取此派车单的急救车信息
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public string GetAmbulanceList(string guid)
{
//sql 写法
string sql = string.Format(@"select GUID, PlateNumber, State from dbo.T_Base_Ambulance where GUID in (select SUBSTRING(a.VehicleGUID, number, CHARINDEX(',', a.VehicleGUID + ',', number) - number)
from dbo.T_Service_FirstAid_Call a,master..spt_values
where GUID = '{0}'
and number >= 1 and number<len(a.VehicleGUID)
and type = 'p'
and SUBSTRING(',' + a.VehicleGUID,number,1)= ',')", guid);
//List<AmbulanceModel> list = new List<AmbulanceModel>();
//string[] ambulance = VehicleGUID.Split(new char[] { ',' });
//if (ambulance.Length > 0)
//{
// for (int i = 0; i < ambulance.Length; i++)
// {
// string guidStr = ambulance[i];
// var alist = db.Queryable<T_Base_Ambulance>().Where(i => i.GUID == guidStr && i.DeleteFlag == 0).First();
// AmbulanceModel model = new AmbulanceModel();
// model.GUID = alist.GUID;
// model.PlateNumber = alist.PlateNumber;
// model.State = alist.State;
// list.Add(model);
// }
//}
DataTable dt = db.Ado.GetDataTable(sql);
string JsonStr = Help.DataTableToJsonStr(dt);
return JsonStr;
}
/// <summary>
/// 获取此派车单的出车人员信息
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public string GetPerList(string guid)
{
string sql = string.Format(@" select GUID, Name, CurrentState,Role,Gender from dbo.T_Service_FirstAid_Personnel where GUID in
(select SUBSTRING(a.AccompanyinPersonnel, number, CHARINDEX(',', a.AccompanyinPersonnel + ',', number) - number)
from dbo.T_Service_FirstAid_Call a,master..spt_values
where GUID = '{0}'
and number >= 1 and number<len(a.AccompanyinPersonnel)
and type = 'p'
and SUBSTRING(',' + a.AccompanyinPersonnel,number,1)= ',')
", guid);
DataTable dt = db.Ado.GetDataTable(sql);
string JsonStr = Help.DataTableToJsonStr(dt);
return JsonStr;
}
}
}