You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
6.2 KiB
C#
191 lines
6.2 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.HkOpenApi;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.CarModule.Dtos;
|
|
using DS.WMS.Core.CarModule.Entity;
|
|
using DS.WMS.Core.CarModule.Interface;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.CarModule.Method;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class TemporaryCarService:ITemporaryCarService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
private readonly string parkIndexCode;
|
|
private readonly IHttpRequestService _ihkHttpService;
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public TemporaryCarService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
parkIndexCode = AppSetting.app(new string[] { "HKOpenApi", "ParkIndexCode" }).ObjToString();
|
|
|
|
_ihkHttpService = _serviceProvider.GetRequiredService<IHttpRequestService>();
|
|
}
|
|
|
|
public DataResult<List<TemporaryCarListPageModel>> GetListByPage(PageRequest request)
|
|
{
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<tb_TemporaryCar>()
|
|
.Select<TemporaryCarListPageModel>()
|
|
.Where(whereList).ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
public DataResult<TemporaryCarViewModel> GetTemporaryCarInfo(string id)
|
|
{
|
|
var data = db.Queryable<tb_TemporaryCar>()
|
|
.Select<TemporaryCarViewModel>()
|
|
.Where(a => a.Id == id).First();
|
|
return DataResult<TemporaryCarViewModel>.Success(data);
|
|
}
|
|
|
|
public DataResult EditTemporaryCar(TemporaryCarInput model)
|
|
{
|
|
if (model.Id.IsNullOrEmpty())
|
|
{
|
|
// var isExist = db.Queryable<tb_TemporaryCar>().Where(x => x.PlateNo == model.PlateNo).First();
|
|
// if (isExist != null)
|
|
// {
|
|
// return DataResult.Failed("该车牌号信息已存在!");
|
|
// }
|
|
|
|
var data = model.Adapt<tb_TemporaryCar>();
|
|
|
|
db.Insertable(data).ExecuteCommand();
|
|
|
|
|
|
return DataResult.Successed("添加成功!",data.Id);
|
|
}
|
|
else
|
|
{
|
|
var info = db.Queryable<tb_TemporaryCar>().Where(x => x.Id == model.Id).First();
|
|
|
|
info = model.Adapt(info);
|
|
|
|
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
return DataResult.Successed("更新成功!");
|
|
}
|
|
}
|
|
|
|
public DataResult DelTemporaryCar(string id)
|
|
{
|
|
var info = db.Queryable<tb_TemporaryCar>().Where(x => x.Id == id).First();
|
|
|
|
if (info.IsNull())
|
|
{
|
|
return DataResult.Failed("该临时车辆不存在!");
|
|
}
|
|
if (info.Status == 1)
|
|
{
|
|
return DataResult.Failed("该临时车辆已预约海康!");
|
|
}
|
|
db.Deleteable(info).ExecuteCommand();
|
|
|
|
return DataResult.Successed("删除成功!");
|
|
}
|
|
|
|
public DataResult ReserveTemporaryCar(string id)
|
|
{
|
|
var info = db.Queryable<tb_TemporaryCar>().Where(x => x.Id == id).First();
|
|
|
|
if (info.IsNull())
|
|
{
|
|
return DataResult.Failed("该临时车辆不存在!");
|
|
}
|
|
if (info.Status == 1)
|
|
{
|
|
return DataResult.Failed("该临时车辆已预约海康!");
|
|
}
|
|
var now = DateTime.Now;
|
|
var end = DateTime.Now.AddYears(50);
|
|
var parm = new
|
|
{
|
|
parkSyscode = parkIndexCode,
|
|
phoneNo = info.PhoneNo,
|
|
owner = info.Owner,
|
|
plateNo = info.PlateNo,
|
|
allowTimes = info.AllowTimes,
|
|
isCharge = "1",
|
|
resvWay = "5",
|
|
startTime = string.Format("{0:s}",info.StartTime)+"+08:00",
|
|
endTime = string.Format("{0:s}",info.EndTime) +"+08:00",
|
|
};
|
|
var req = new HKPostData()
|
|
{
|
|
Url = "/artemis/api/pms/v2/parkingSpace/reservations/addition",
|
|
Data = JsonConvert.SerializeObject(parm),
|
|
};
|
|
var res= _ihkHttpService.HKHttpPost(req);
|
|
if (res.Code == "0")
|
|
{
|
|
info.Status = 1 ;
|
|
var data = JsonConvert.DeserializeObject<ReserveReturnData>(res.Data.ToString());
|
|
info.ReserveOrderNo = data.ReserveOrderNo;
|
|
info.ReserveTime = data.ReserveTime;
|
|
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
return DataResult.Successed("预约海康系统成功!");
|
|
}
|
|
else
|
|
{
|
|
// info.Note = res.Msg ;
|
|
// db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
return DataResult.Failed(res.Msg);
|
|
}
|
|
}
|
|
public DataResult CancelReserve(string id)
|
|
{
|
|
var info = db.Queryable<tb_TemporaryCar>().Where(x => x.Id == id).First();
|
|
|
|
if (info.IsNull())
|
|
{
|
|
return DataResult.Failed("该临时车辆不存在!");
|
|
}
|
|
if (info.Status == 0)
|
|
{
|
|
return DataResult.Failed("该临时车辆未预约海康!");
|
|
}
|
|
|
|
var parm = new
|
|
{
|
|
reserveOrderNo = info.ReserveOrderNo,
|
|
way = 1,
|
|
};
|
|
var req = new HKPostData()
|
|
{
|
|
Url = "/artemis/api/pms/v1/parkingSpace/reservations/deletion",
|
|
Data = JsonConvert.SerializeObject(parm),
|
|
};
|
|
var res= _ihkHttpService.HKHttpPost(req);
|
|
if (res.Code == "0")
|
|
{
|
|
info.Status = 0 ;
|
|
info.ReserveOrderNo = "";
|
|
info.ReserveTime = 0;
|
|
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
return DataResult.Successed("取消预约成功!");
|
|
}
|
|
else
|
|
{
|
|
// info.Note = res.Msg ;
|
|
// db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
return DataResult.Failed(res.Msg);
|
|
}
|
|
}
|
|
} |