/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2025/12/7 0:55:50
* Description: 暂无
***********************************************************************/
using CoreCms.Net.Configuration;
using CoreCms.Net.Filter;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Model.ViewModels.SQ;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.Web.Admin.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using NLog;
using AutoMapper;
namespace CoreCms.Net.Web.Admin.Controllers
{
///
///
///
[Description("")]
[Route("api/[controller]/[action]")]
[ApiController]
[RequiredErrorForAdmin]
[Authorize]
public class SQRoomPricingController : ControllerBase
{
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly ISQRoomPricingServices _SQRoomPricingServices;
private readonly ISQRoomsServices _SQRoomsServices;
private readonly ISQReservationsServices _SQReservationsServices;
private readonly ISQReservationParticipantsServices _SQReservationParticipantsServices;
private readonly ISQRoomUnavailableTimesServices _SQRoomUnavailableTimesServices;
private readonly ICoreCmsUserServices _userServices;
private readonly IMapper _mapper;
///
/// 构造函数
///
public SQRoomPricingController(IWebHostEnvironment webHostEnvironment
, ISQRoomPricingServices SQRoomPricingServices
, ISQRoomsServices SQRoomsServices
, ISQReservationsServices SQReservationsServices
, ISQReservationParticipantsServices SQReservationParticipantsServices
, ISQRoomUnavailableTimesServices SQRoomUnavailableTimesServices
, ICoreCmsUserServices userServices
, IMapper mapper
)
{
_webHostEnvironment = webHostEnvironment;
_SQRoomPricingServices = SQRoomPricingServices;
_SQRoomsServices = SQRoomsServices;
_SQReservationsServices = SQReservationsServices;
_SQReservationParticipantsServices = SQReservationParticipantsServices;
_SQRoomUnavailableTimesServices = SQRoomUnavailableTimesServices;
_userServices = userServices;
_mapper = mapper;
}
#region 获取列表============================================================
// POST: Api/SQRoomPricing/GetPageList
///
/// 获取列表
///
///
[HttpPost]
[Description("获取列表")]
public async Task GetPageList()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
//获取排序字段
var orderField = Request.Form["orderField"].FirstOrDefault();
Expression> orderEx = orderField switch
{
"id" => p => p.id,
"room_id" => p => p.room_id,
"time_slot_type" => p => p.time_slot_type,
"standard_price" => p => p.standard_price,
"member_price" => p => p.member_price,
"price_desc_standard" => p => p.price_desc_standard,
"price_desc_member" => p => p.price_desc_member,
"effective_date_start" => p => p.effective_date_start,
"effective_date_end" => p => p.effective_date_end,
"is_active" => p => p.is_active,
"created_at" => p => p.created_at,
"updated_at" => p => p.updated_at,
_ => p => p.id
};
//设置排序方式
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
var orderBy = orderDirection switch
{
"asc" => OrderByType.Asc,
"desc" => OrderByType.Desc,
_ => OrderByType.Desc
};
//查询筛选
// int
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
if (id > 0)
{
where = where.And(p => p.id == id);
}
// int
var room_id = Request.Form["room_id"].FirstOrDefault().ObjectToInt(0);
if (room_id > 0)
{
where = where.And(p => p.room_id == room_id);
}
// int
var time_slot_type = Request.Form["time_slot_type"].FirstOrDefault().ObjectToInt(0);
if (time_slot_type > 0)
{
where = where.And(p => p.time_slot_type == time_slot_type);
}
// decimal
var standard_price = Request.Form["standard_price"].FirstOrDefault().ObjectToDecimal(0);
if (standard_price > 0)
{
where = where.And(p => p.standard_price == standard_price);
}
// decimal
var member_price = Request.Form["member_price"].FirstOrDefault().ObjectToDecimal(0);
if (member_price > 0)
{
where = where.And(p => p.member_price == member_price);
}
// nvarchar
var price_desc_standard = Request.Form["price_desc_standard"].FirstOrDefault();
if (!string.IsNullOrEmpty(price_desc_standard))
{
where = where.And(p => p.price_desc_standard.Contains(price_desc_standard));
}
// nvarchar
var price_desc_member = Request.Form["price_desc_member"].FirstOrDefault();
if (!string.IsNullOrEmpty(price_desc_member))
{
where = where.And(p => p.price_desc_member.Contains(price_desc_member));
}
// bit
var is_active = Request.Form["is_active"].FirstOrDefault();
if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "true")
{
where = where.And(p => p.is_active == true);
}
else if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "false")
{
where = where.And(p => p.is_active == false);
}
// datetime
var created_at = Request.Form["created_at"].FirstOrDefault();
if (!string.IsNullOrEmpty(created_at))
{
if (created_at.Contains("到"))
{
var dts = created_at.Split("到");
var dtStart = dts[0].Trim().ObjectToDate();
where = where.And(p => p.created_at > dtStart);
var dtEnd = dts[1].Trim().ObjectToDate();
where = where.And(p => p.created_at < dtEnd);
}
else
{
var dt = created_at.ObjectToDate();
where = where.And(p => p.created_at > dt);
}
}
// datetime
var updated_at = Request.Form["updated_at"].FirstOrDefault();
if (!string.IsNullOrEmpty(updated_at))
{
if (updated_at.Contains("到"))
{
var dts = updated_at.Split("到");
var dtStart = dts[0].Trim().ObjectToDate();
where = where.And(p => p.updated_at > dtStart);
var dtEnd = dts[1].Trim().ObjectToDate();
where = where.And(p => p.updated_at < dtEnd);
}
else
{
var dt = updated_at.ObjectToDate();
where = where.And(p => p.updated_at > dt);
}
}
//获取数据
var list = await _SQRoomPricingServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 首页数据============================================================
// POST: Api/SQRoomPricing/GetIndex
///
/// 首页数据
///
///
[HttpPost]
[Description("首页数据")]
public AdminUiCallBack GetIndex()
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
return jm;
}
#endregion
#region 创建数据============================================================
// POST: Api/SQRoomPricing/GetCreate
///
/// 创建数据
///
///
[HttpPost]
[Description("创建数据")]
public AdminUiCallBack GetCreate()
{
//返回数据
var jm = new AdminUiCallBack { code = 0, data = new SQRoomPricing() };
return jm;
}
#endregion
#region 创建提交============================================================
// POST: Api/SQRoomPricing/DoCreate
///
/// 创建提交
///
///
///
[HttpPost]
[Description("创建提交")]
public async Task DoCreate([FromBody] SQRoomPricing entity)
{
entity.created_at = DateTime.Now;
entity.updated_at = DateTime.Now;
entity.member_price = 0;
entity.standard_price = 0;
var jm = await _SQRoomPricingServices.InsertAsync(entity);
return new AdminUiCallBack() { code = 0, msg = "删除成功" }; ;
}
#endregion
#region 编辑数据============================================================
// POST: Api/SQRoomPricing/GetEdit
///
/// 编辑数据
///
///
///
[HttpPost]
[Description("编辑数据")]
public async Task GetEdit([FromBody] FMIntId entity)
{
var jm = new AdminUiCallBack();
var model = await _SQRoomPricingServices.QueryByIdAsync(entity.id, false);
if (model == null)
{
jm.msg = "不存在此信息";
return jm;
}
jm.code = 0;
jm.data = model;
return jm;
}
#endregion
#region 编辑提交============================================================
// POST: Api/SQRoomPricing/Edit
///
/// 编辑提交
///
///
///
[HttpPost]
[Description("编辑提交")]
public async Task DoEdit([FromBody] SQRoomPricing entity)
{
entity.updated_at = DateTime.Now;
entity.member_price = 0;
entity.standard_price = 0;
var jm = await _SQRoomPricingServices.UpdateAsync(entity);
return new AdminUiCallBack() { code = 0, msg = "删除成功" }; ;
}
#endregion
#region 删除数据============================================================
// POST: Api/SQRoomPricing/DoDelete/10
///
/// 单选删除
///
///
///
[HttpPost]
[Description("单选删除")]
public async Task DoDelete([FromBody] FMIntId entity)
{
var jm = new AdminUiCallBack();
var model = await _SQRoomPricingServices.ExistsAsync(p => p.id == entity.id, true);
if (!model)
{
jm.msg = GlobalConstVars.DataisNo;
return jm;
}
await _SQRoomPricingServices.DeleteByIdAsync(entity.id);
return jm;
}
#endregion
#region 批量删除============================================================
// POST: Api/SQRoomPricing/DoBatchDelete/10,11,20
///
/// 批量删除
///
///
///
[HttpPost]
[Description("批量删除")]
public async Task DoBatchDelete([FromBody] FMArrayIntIds entity)
{
await _SQRoomPricingServices.DeleteByIdsAsync(entity.id);
return new AdminUiCallBack() { code = 0, msg = "删除成功" };
}
#endregion
#region 预览数据============================================================
// POST: Api/SQRoomPricing/GetDetails/10
///
/// 预览数据
///
///
///
[HttpPost]
[Description("预览数据")]
public async Task GetDetails([FromBody] FMIntId entity)
{
var jm = new AdminUiCallBack();
var model = await _SQRoomPricingServices.QueryByIdAsync(entity.id, false);
if (model == null)
{
jm.msg = "不存在此信息";
return jm;
}
jm.code = 0;
jm.data = model;
return jm;
}
#endregion
#region 选择导出============================================================
// POST: Api/SQRoomPricing/SelectExportExcel/10
///
/// 选择导出
///
///
///
[HttpPost]
[Description("选择导出")]
public async Task SelectExportExcel([FromBody] FMArrayIntIds entity)
{
var jm = new AdminUiCallBack();
//创建Excel文件的对象
var book = new HSSFWorkbook();
//添加一个sheet
var mySheet = book.CreateSheet("Sheet1");
//获取list数据
var listModel = await _SQRoomPricingServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc, true);
//给sheet1添加第一行的头部标题
var headerRow = mySheet.CreateRow(0);
var headerStyle = ExcelHelper.GetHeaderStyle(book);
var cell0 = headerRow.CreateCell(0);
cell0.SetCellValue("");
cell0.CellStyle = headerStyle;
mySheet.SetColumnWidth(0, 10 * 256);
var cell1 = headerRow.CreateCell(1);
cell1.SetCellValue("");
cell1.CellStyle = headerStyle;
mySheet.SetColumnWidth(1, 10 * 256);
var cell2 = headerRow.CreateCell(2);
cell2.SetCellValue("");
cell2.CellStyle = headerStyle;
mySheet.SetColumnWidth(2, 10 * 256);
var cell3 = headerRow.CreateCell(3);
cell3.SetCellValue("");
cell3.CellStyle = headerStyle;
mySheet.SetColumnWidth(3, 10 * 256);
var cell4 = headerRow.CreateCell(4);
cell4.SetCellValue("");
cell4.CellStyle = headerStyle;
mySheet.SetColumnWidth(4, 10 * 256);
var cell5 = headerRow.CreateCell(5);
cell5.SetCellValue("");
cell5.CellStyle = headerStyle;
mySheet.SetColumnWidth(5, 10 * 256);
var cell6 = headerRow.CreateCell(6);
cell6.SetCellValue("");
cell6.CellStyle = headerStyle;
mySheet.SetColumnWidth(6, 10 * 256);
var cell7 = headerRow.CreateCell(7);
cell7.SetCellValue("");
cell7.CellStyle = headerStyle;
mySheet.SetColumnWidth(7, 10 * 256);
var cell8 = headerRow.CreateCell(8);
cell8.SetCellValue("");
cell8.CellStyle = headerStyle;
mySheet.SetColumnWidth(8, 10 * 256);
var cell9 = headerRow.CreateCell(9);
cell9.SetCellValue("");
cell9.CellStyle = headerStyle;
mySheet.SetColumnWidth(9, 10 * 256);
var cell10 = headerRow.CreateCell(10);
cell10.SetCellValue("");
cell10.CellStyle = headerStyle;
mySheet.SetColumnWidth(10, 10 * 256);
var cell11 = headerRow.CreateCell(11);
cell11.SetCellValue("");
cell11.CellStyle = headerStyle;
mySheet.SetColumnWidth(11, 10 * 256);
headerRow.Height = 30 * 20;
var commonCellStyle = ExcelHelper.GetCommonStyle(book);
//将数据逐步写入sheet1各个行
for (var i = 0; i < listModel.Count; i++)
{
var rowTemp = mySheet.CreateRow(i + 1);
var rowTemp0 = rowTemp.CreateCell(0);
rowTemp0.SetCellValue(listModel[i].id.ToString());
rowTemp0.CellStyle = commonCellStyle;
var rowTemp1 = rowTemp.CreateCell(1);
rowTemp1.SetCellValue(listModel[i].room_id.ToString());
rowTemp1.CellStyle = commonCellStyle;
var rowTemp2 = rowTemp.CreateCell(2);
rowTemp2.SetCellValue(listModel[i].time_slot_type.ToString());
rowTemp2.CellStyle = commonCellStyle;
var rowTemp3 = rowTemp.CreateCell(3);
rowTemp3.SetCellValue(listModel[i].standard_price.ToString());
rowTemp3.CellStyle = commonCellStyle;
var rowTemp4 = rowTemp.CreateCell(4);
rowTemp4.SetCellValue(listModel[i].member_price.ToString());
rowTemp4.CellStyle = commonCellStyle;
var rowTemp5 = rowTemp.CreateCell(5);
rowTemp5.SetCellValue(listModel[i].price_desc_standard.ToString());
rowTemp5.CellStyle = commonCellStyle;
var rowTemp6 = rowTemp.CreateCell(6);
rowTemp6.SetCellValue(listModel[i].price_desc_member.ToString());
rowTemp6.CellStyle = commonCellStyle;
var rowTemp7 = rowTemp.CreateCell(7);
rowTemp7.SetCellValue(listModel[i].effective_date_start.ToString());
rowTemp7.CellStyle = commonCellStyle;
var rowTemp8 = rowTemp.CreateCell(8);
rowTemp8.SetCellValue(listModel[i].effective_date_end.ToString());
rowTemp8.CellStyle = commonCellStyle;
var rowTemp9 = rowTemp.CreateCell(9);
rowTemp9.SetCellValue(listModel[i].is_active.ToString());
rowTemp9.CellStyle = commonCellStyle;
var rowTemp10 = rowTemp.CreateCell(10);
rowTemp10.SetCellValue(listModel[i].created_at.ToString());
rowTemp10.CellStyle = commonCellStyle;
var rowTemp11 = rowTemp.CreateCell(11);
rowTemp11.SetCellValue(listModel[i].updated_at.ToString());
rowTemp11.CellStyle = commonCellStyle;
}
// 导出excel
string webRootPath = _webHostEnvironment.WebRootPath;
string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-SQRoomPricing导出(选择结果).xls";
string filePath = webRootPath + tpath;
DirectoryInfo di = new DirectoryInfo(filePath);
if (!di.Exists)
{
di.Create();
}
FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create);
book.Write(fileHssf);
fileHssf.Close();
jm.code = 0;
jm.msg = GlobalConstVars.ExcelExportSuccess;
jm.data = tpath + fileName;
return jm;
}
#endregion
#region 查询导出============================================================
// POST: Api/SQRoomPricing/QueryExportExcel/10
///
/// 查询导出
///
///
[HttpPost]
[Description("查询导出")]
public async Task QueryExportExcel()
{
var jm = new AdminUiCallBack();
var where = PredicateBuilder.True();
//查询筛选
// int
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
if (id > 0)
{
where = where.And(p => p.id == id);
}
// int
var room_id = Request.Form["room_id"].FirstOrDefault().ObjectToInt(0);
if (room_id > 0)
{
where = where.And(p => p.room_id == room_id);
}
// int
var time_slot_type = Request.Form["time_slot_type"].FirstOrDefault().ObjectToInt(0);
if (time_slot_type > 0)
{
where = where.And(p => p.time_slot_type == time_slot_type);
}
// decimal
var standard_price = Request.Form["standard_price"].FirstOrDefault().ObjectToDecimal(0);
if (standard_price > 0)
{
where = where.And(p => p.standard_price == standard_price);
}
// decimal
var member_price = Request.Form["member_price"].FirstOrDefault().ObjectToDecimal(0);
if (member_price > 0)
{
where = where.And(p => p.member_price == member_price);
}
// nvarchar
var price_desc_standard = Request.Form["price_desc_standard"].FirstOrDefault();
if (!string.IsNullOrEmpty(price_desc_standard))
{
where = where.And(p => p.price_desc_standard.Contains(price_desc_standard));
}
// nvarchar
var price_desc_member = Request.Form["price_desc_member"].FirstOrDefault();
if (!string.IsNullOrEmpty(price_desc_member))
{
where = where.And(p => p.price_desc_member.Contains(price_desc_member));
}
// bit
var is_active = Request.Form["is_active"].FirstOrDefault();
if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "true")
{
where = where.And(p => p.is_active == true);
}
else if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "false")
{
where = where.And(p => p.is_active == false);
}
// datetime
var created_at = Request.Form["created_at"].FirstOrDefault();
if (!string.IsNullOrEmpty(created_at))
{
var dt = created_at.ObjectToDate();
where = where.And(p => p.created_at > dt);
}
// datetime
var updated_at = Request.Form["updated_at"].FirstOrDefault();
if (!string.IsNullOrEmpty(updated_at))
{
var dt = updated_at.ObjectToDate();
where = where.And(p => p.updated_at > dt);
}
//获取数据
//创建Excel文件的对象
var book = new HSSFWorkbook();
//添加一个sheet
var mySheet = book.CreateSheet("Sheet1");
//获取list数据
var listModel = await _SQRoomPricingServices.QueryListByClauseAsync(where, p => p.id, OrderByType.Asc, true);
//给sheet1添加第一行的头部标题
var headerRow = mySheet.CreateRow(0);
var headerStyle = ExcelHelper.GetHeaderStyle(book);
var cell0 = headerRow.CreateCell(0);
cell0.SetCellValue("");
cell0.CellStyle = headerStyle;
mySheet.SetColumnWidth(0, 10 * 256);
var cell1 = headerRow.CreateCell(1);
cell1.SetCellValue("");
cell1.CellStyle = headerStyle;
mySheet.SetColumnWidth(1, 10 * 256);
var cell2 = headerRow.CreateCell(2);
cell2.SetCellValue("");
cell2.CellStyle = headerStyle;
mySheet.SetColumnWidth(2, 10 * 256);
var cell3 = headerRow.CreateCell(3);
cell3.SetCellValue("");
cell3.CellStyle = headerStyle;
mySheet.SetColumnWidth(3, 10 * 256);
var cell4 = headerRow.CreateCell(4);
cell4.SetCellValue("");
cell4.CellStyle = headerStyle;
mySheet.SetColumnWidth(4, 10 * 256);
var cell5 = headerRow.CreateCell(5);
cell5.SetCellValue("");
cell5.CellStyle = headerStyle;
mySheet.SetColumnWidth(5, 10 * 256);
var cell6 = headerRow.CreateCell(6);
cell6.SetCellValue("");
cell6.CellStyle = headerStyle;
mySheet.SetColumnWidth(6, 10 * 256);
var cell7 = headerRow.CreateCell(7);
cell7.SetCellValue("");
cell7.CellStyle = headerStyle;
mySheet.SetColumnWidth(7, 10 * 256);
var cell8 = headerRow.CreateCell(8);
cell8.SetCellValue("");
cell8.CellStyle = headerStyle;
mySheet.SetColumnWidth(8, 10 * 256);
var cell9 = headerRow.CreateCell(9);
cell9.SetCellValue("");
cell9.CellStyle = headerStyle;
mySheet.SetColumnWidth(9, 10 * 256);
var cell10 = headerRow.CreateCell(10);
cell10.SetCellValue("");
cell10.CellStyle = headerStyle;
mySheet.SetColumnWidth(10, 10 * 256);
var cell11 = headerRow.CreateCell(11);
cell11.SetCellValue("");
cell11.CellStyle = headerStyle;
mySheet.SetColumnWidth(11, 10 * 256);
headerRow.Height = 30 * 20;
var commonCellStyle = ExcelHelper.GetCommonStyle(book);
//将数据逐步写入sheet1各个行
for (var i = 0; i < listModel.Count; i++)
{
var rowTemp = mySheet.CreateRow(i + 1);
var rowTemp0 = rowTemp.CreateCell(0);
rowTemp0.SetCellValue(listModel[i].id.ToString());
rowTemp0.CellStyle = commonCellStyle;
var rowTemp1 = rowTemp.CreateCell(1);
rowTemp1.SetCellValue(listModel[i].room_id.ToString());
rowTemp1.CellStyle = commonCellStyle;
var rowTemp2 = rowTemp.CreateCell(2);
rowTemp2.SetCellValue(listModel[i].time_slot_type.ToString());
rowTemp2.CellStyle = commonCellStyle;
var rowTemp3 = rowTemp.CreateCell(3);
rowTemp3.SetCellValue(listModel[i].standard_price.ToString());
rowTemp3.CellStyle = commonCellStyle;
var rowTemp4 = rowTemp.CreateCell(4);
rowTemp4.SetCellValue(listModel[i].member_price.ToString());
rowTemp4.CellStyle = commonCellStyle;
var rowTemp5 = rowTemp.CreateCell(5);
rowTemp5.SetCellValue(listModel[i].price_desc_standard.ToString());
rowTemp5.CellStyle = commonCellStyle;
var rowTemp6 = rowTemp.CreateCell(6);
rowTemp6.SetCellValue(listModel[i].price_desc_member.ToString());
rowTemp6.CellStyle = commonCellStyle;
var rowTemp7 = rowTemp.CreateCell(7);
rowTemp7.SetCellValue(listModel[i].effective_date_start.ToString());
rowTemp7.CellStyle = commonCellStyle;
var rowTemp8 = rowTemp.CreateCell(8);
rowTemp8.SetCellValue(listModel[i].effective_date_end.ToString());
rowTemp8.CellStyle = commonCellStyle;
var rowTemp9 = rowTemp.CreateCell(9);
rowTemp9.SetCellValue(listModel[i].is_active.ToString());
rowTemp9.CellStyle = commonCellStyle;
var rowTemp10 = rowTemp.CreateCell(10);
rowTemp10.SetCellValue(listModel[i].created_at.ToString());
rowTemp10.CellStyle = commonCellStyle;
var rowTemp11 = rowTemp.CreateCell(11);
rowTemp11.SetCellValue(listModel[i].updated_at.ToString());
rowTemp11.CellStyle = commonCellStyle;
}
// 写入到excel
string webRootPath = _webHostEnvironment.WebRootPath;
string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-SQRoomPricing导出(查询结果).xls";
string filePath = webRootPath + tpath;
DirectoryInfo di = new DirectoryInfo(filePath);
if (!di.Exists)
{
di.Create();
}
FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create);
book.Write(fileHssf);
fileHssf.Close();
jm.code = 0;
jm.msg = GlobalConstVars.ExcelExportSuccess;
jm.data = tpath + fileName;
return jm;
}
#endregion
#region 设置============================================================
// POST: Api/SQRoomPricing/DoSetis_active/10
///
/// 设置
///
///
///
[HttpPost]
[Description("设置")]
public async Task DoSetis_active([FromBody] FMUpdateBoolDataByIntId entity)
{
var jm = new AdminUiCallBack();
var oldModel = await _SQRoomPricingServices.QueryByIdAsync(entity.id, false);
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
oldModel.is_active = (bool)entity.data;
var bl = await _SQRoomPricingServices.UpdateAsync(p => new SQRoomPricing() { is_active = oldModel.is_active }, p => p.id == oldModel.id);
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
#endregion
#region 获取房间时段状态============================================================
// GET: Api/SQRoomPricing/GetRoomListWithSlots
///
/// 获取房间列表及时段状态(用于日历视图)
///
/// 日期
/// 是否只显示可用房间
/// 当前时段
///
[HttpGet]
[AllowAnonymous]
[Description("获取房间列表及时段状态")]
public async Task GetRoomListWithSlots([FromQuery] string date, [FromQuery] bool showOnlyAvailable = false, [FromQuery] int? currentTimeSlot = null)
{
var jm = new AdminUiCallBack();
// 验证日期参数
if (string.IsNullOrEmpty(date))
{
jm.msg = "请提供日期参数";
return jm;
}
if (!DateTime.TryParse(date, out DateTime dateValue))
{
jm.msg = "日期格式不正确";
return jm;
}
// 调用服务获取数据
var result = await _SQRoomsServices.GetRoomListWithSlotsAsync(dateValue, showOnlyAvailable, currentTimeSlot);
jm.code = 0;
jm.msg = "获取成功";
jm.data = result;
return jm;
}
#endregion
#region 获取日期详情============================================================
// GET: Api/SQRoomPricing/GetDateDetails
///
/// 获取指定日期和房间的详细信息(用于日历视图点击日期)
///
/// 日期
/// 房间ID
///
[HttpGet]
[AllowAnonymous]
[Description("获取日期详情")]
public async Task GetDateDetails([FromQuery] string date, [FromQuery] int roomId)
{
var jm = new AdminUiCallBack();
try
{
// 验证参数
if (string.IsNullOrEmpty(date))
{
jm.msg = "请提供日期参数";
return jm;
}
if (roomId <= 0)
{
jm.msg = "请提供房间ID";
return jm;
}
if (!DateTime.TryParse(date, out DateTime dateValue))
{
jm.msg = "日期格式不正确";
return jm;
}
// 获取房间信息
var room = await _SQRoomsServices.QueryByIdAsync(roomId);
if (room == null)
{
jm.msg = "房间不存在";
return jm;
}
// 获取该日期该房间的时段状态
var roomListWithSlots = await _SQRoomsServices.GetRoomListWithSlotsAsync(dateValue, false, null);
var roomData = roomListWithSlots?.FirstOrDefault(r => r.id == roomId);
// 获取该日期该房间的预约列表
var startTime = dateValue.Date;
var endTime = dateValue.Date.AddDays(1);
var reservations = await _SQReservationsServices.QueryListByClauseAsync(
p => p.room_id == roomId &&
p.start_time >= startTime &&
p.start_time < endTime &&
p.status != 4, // 排除已取消的预约
p => p.start_time,
OrderByType.Asc
);
// 查询所有预约的参与者
var reservationIds = reservations.Select(r => r.id).ToList();
List allParticipants = new List();
List userList = new List();
if (reservationIds.Any())
{
allParticipants = await _SQReservationParticipantsServices.QueryListByClauseAsync(
p => reservationIds.Contains(p.reservation_id),
p => p.role,
OrderByType.Desc,
true
);
// 查询所有参与者的用户信息
var userIds = allParticipants.Select(p => p.user_id).Distinct().ToList();
if (userIds.Any())
{
userList = await _userServices.QueryListByClauseAsync(
u => userIds.Contains(u.id),
u => u.id,
OrderByType.Asc,
true
);
}
}
// 处理时段数据,添加参与者头像和数量
var enhancedTimeSlots = new List