StableVersion4.3/HL_FristAidPlatform_DataBase/TranService/AlarmInfoService.cs

112 lines
4.3 KiB
C#

using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace HL_FristAidPlatform_DataBase
{
/// <summary>
/// 接警信息
/// </summary>
public class AlarmInfoService : BaseDB, IAlarmInfoService
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 保存接警信息事务
/// </summary>
/// <param name="info"></param>
/// <param name="ambulance"></param>
/// <param name="task"></param>
/// <param name="dringCensus"></param>
/// <param name="perList"></param>
/// <returns></returns>
public int SaveAlarmInfoTran(T_Service_FirstAid_AlarmInfo info, List<T_Base_Ambulance> ambulanceList, List<T_Service_FirstAid_AlarmTaskInfo> taskList, List<T_SYS_User> perList)
{
int id = 0;
try
{
db.Ado.BeginTran();
id = db.Insertable(info).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity();
if (!SqlFunc.IsNullOrEmpty(ambulanceList) && ambulanceList.Count > 0)
for (int i = 0; i < ambulanceList.Count; i++)
{
db.Updateable<T_Base_Ambulance>().SetColumns(it => new T_Base_Ambulance()
{ State = 2 }).Where(it => it.GUID == ambulanceList[i].GUID).ExecuteCommand();
}
if (!SqlFunc.IsNullOrEmpty(taskList) && taskList.Count > 0) db.Insertable(taskList).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
if (!SqlFunc.IsNullOrEmpty(perList) && perList.Count > 0)
{
for (int j = 0; j < perList.Count; j++)
{
db.Updateable<T_SYS_User>().SetColumns(it => new T_SYS_User() { State = 2, VehicleGUID = perList[j].VehicleGUID }).Where(i => i.GUID == perList[j].GUID).ExecuteCommand();
}
}
if (!SqlFunc.IsNullOrEmpty(info.AccidentGUID))
{
var accident = db.Queryable<T_Base_AccidentInfo>().First(i => i.GUID == info.AccidentGUID);
for (int i = 0; i < info.PatientsNumber; i++)
{
T_Service_Patient patient = new T_Service_Patient();
patient.GUID = Guid.NewGuid().ToString();
patient.Name = accident.ParentName + "_" + i + "号患者";
patient.CreationDate = DateTime.Now;
patient.RegisterTime = patient.CreationDate;
db.Insertable(patient).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
}
db.Ado.CommitTran();
return id;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("院前:保存接警信息(SaveAlarmInfoTran)", ex.ToString());
return 0;
}
}
/// <summary>
/// 更改出车人员
/// </summary>
/// <param name="info"></param>
/// <param name="user"></param>
/// <returns></returns>
public bool UpdateDrvingpPersonnel(T_Service_FirstAid_AlarmTaskInfo info, T_SYS_User user, T_SYS_User user1)
{
try
{
db.Ado.BeginTran();
if (!string.IsNullOrEmpty(info.GUID))
{
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
}
if (user != null)
{
db.Updateable(user).UpdateColumns(it => new { it.State, it.VehicleGUID }).ExecuteCommand();
}
if (user1 != null)
{
db.Updateable(user1).UpdateColumns(it => new { it.State, it.VehicleGUID }).ExecuteCommand();
}
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("院前:更改出车人员(UpdateDrvingpPersonnel)", ex.ToString());
return false;
}
}
}
}