处理挂单测试问题

This commit is contained in:
2025-09-16 17:53:38 +08:00
parent 40da17b414
commit c38dc55dff
8 changed files with 238 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
using Model;
using PagedList;
using System;
using System.Collections.Generic;
using System.Data.Entity;
@@ -15,12 +16,36 @@ using static regionController;
public class guadanOrderController : ApiController
{
private Model.ezEntities _db = new Model.ezEntities();
[HttpGet]
[HttpPost]
[Route("api/guadan/list")]
public async Task<IHttpActionResult> getGuadanList()
public async Task<IHttpActionResult> getGuadanList([FromBody] guadan_order_search_dto search)
{
var data = await _db.GuaDanOrder
var query = _db.GuaDanOrder
.Where(a => a.IsCancel == false)
.Where(a => a.IsDeleted == false);
if(search.guadanUser != null)
{
query = query.Where(order => order.BookerName == search.guadanUser);
}
if (search.startDate != null && search.endDate != null)
{
query = query.Where(order => order.StartDate >= search.startDate)
.Where(order => order.EndDate <= search.endDate);
}
else
{
if (search.startDate != null)
{
query = query.Where(order => order.StartDate == search.startDate);
}
else if (search.endDate != null)
{
query = query.Where(order => order.EndDate == search.endDate);
}
}
var total = query.Count();
var data = await query
.OrderByDescending(b => b.CreatedAt)
.Select(a => new
{
@@ -36,8 +61,15 @@ public class guadanOrderController : ApiController
.Where(c => c.GuaDanOrderNo == a.GuaDanOrderNo && c.IsDeleted == false)
.Where(c => c.RegionRoomBedStatus.Code != GuaDanOrderGuest.STATUS_CANCELLED)
.Count(),
}).ToListAsync();
return Ok(data);
})
.Skip((search.page - 1) * search.pageSize)
.Take(search.pageSize)
.ToListAsync();
return Ok(new
{
total,
data
});
}
[HttpGet]
[Route("api/guadan/getorderbyid")]
@@ -221,4 +253,13 @@ public class guadanOrderController : ApiController
public RegionRoomBed bed { get; set; } = null;
}
public class guadan_order_search_dto
{
public DateTime? startDate { get; set; }
public DateTime? endDate { get; set; }
public string guadanUser { get; set; }
public int page { get; set; } = 1;
public int pageSize { get; set; } = 10;
}
}

View File

@@ -39,8 +39,9 @@ public class regionController : ApiController
var startDate = filter.StartDate.Date;
var endDate = filter.EndDate.Date;
var query = _db.Region
var query = _db.Region//区域状态是否启用这里只设置了过滤了有客房的区域,是否要过滤所有
.Where(r => !r.IsDeleted)
.Where(r => r.IsActive)
.Where(r => r.Room.Any());
if (filter.Gender != null)
@@ -373,6 +374,10 @@ public class regionController : ApiController
var region = _db.Region.FirstOrDefault(r => r.Uuid == dto.Uuid);
if (region == null)
return NotFound();
if(dto.RoomCount < region.Room.Count())
{
return BadRequest("客房數量小於已存在的客房數量");
}
region.Name = dto.Name;
region.Description = dto.Description;
region.SortOrder = dto.SortOrder;

View File

@@ -379,6 +379,7 @@ public class regionRoomBedController : ApiController
RoomUuid = roomUuid,
CheckInAt = allocationStart,
CheckOutAt = allocationEnd,
StatusCode = "401",
};
_db.GuaDanOrderGuest.Add(guest);
@@ -396,7 +397,8 @@ public class regionRoomBedController : ApiController
IsDeleted = false,
CreatedBy = "系统自动分配",
CreatedAt = DateTime.Now,
GuaDanOrderNo = guest.GuaDanOrderNo
GuaDanOrderNo = guest.GuaDanOrderNo,
Title = "掛單"
};
_db.RegionAndRoomAndBedSchedule.Add(newSchedule);
}
@@ -413,7 +415,8 @@ public class regionRoomBedController : ApiController
IsDeleted = false,
CreatedBy = "系统自动分配",
CreatedAt = DateTime.Now,
GuaDanOrderNo = guest.GuaDanOrderNo
GuaDanOrderNo = guest.GuaDanOrderNo,
Title = "掛單"
};
_db.RegionAndRoomAndBedSchedule.Add(newSchedule);
}

View File

@@ -38,6 +38,15 @@ public class regionRoomController : ApiController
{
return BadRequest("請輸入床位數量");
}
var region = _db.Region.Find(room.RegionUuid);
if(region == null)
{
return BadRequest("未找到客房所屬的區域");
}
if(region.Room.Count() >= region.RoomCount)
{
return BadRequest("當前區域客房數量已經達到上限");
}
var newRoom = new Room();
newRoom.Name = room.Name;
newRoom.RegionUuid = room.RegionUuid;
@@ -102,6 +111,10 @@ public class regionRoomController : ApiController
[HttpPost]
[Route("api/region/room/delete")]
public async Task<IHttpActionResult> deleteRoom([FromBody] Room rm)
{
using (var transaction = _db.Database.BeginTransaction())
{
try
{
var room = await _db.Room.FindAsync(rm.Uuid);
if (room == null) return BadRequest("房間不存在");
@@ -110,8 +123,32 @@ public class regionRoomController : ApiController
_db.RegionRoomBed.RemoveRange(beds);
_db.Room.Remove(room);
await _db.SaveChangesAsync();
transaction.Commit();
return Ok(new { message = "刪除成功" });
}
catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
{
transaction.Rollback();
// 判断是否为外键约束错误
if (ex.InnerException?.InnerException is System.Data.SqlClient.SqlException sqlEx &&
sqlEx.Number == 547) // 547 = 外键冲突
{
return BadRequest("房間或床位正在被使用,不能刪除");
}
return InternalServerError(ex);
}
catch (Exception ex)
{
transaction.Rollback();
return InternalServerError(ex);
}
}
}
}

View File

@@ -1146,6 +1146,10 @@
.then(res => {
this.resetAutomaticBedAllocation();
this.getGuadanOrderGuestByOrderNo();
}).catch((error) => {
this.$refs.messageModal.open({
message: (error.response?.data?.message || error.message)
});
});
},

View File

@@ -20,13 +20,13 @@
</div>
<div class="form-item">
<label>入住日期区间:</label>
<label>入住日期區間:</label>
<input type="date" v-model="search.searchCheckInDateStart"> -
<input type="date" v-model="search.searchCheckInDateEnd">
</div>
<div class="form-item">
<label>退房日期区间:</label>
<label>退房日期區間:</label>
<input type="date" v-model="search.searchCheckOutDateStart"> -
<input type="date" v-model="search.searchCheckOutDateEnd">
</div>
@@ -142,10 +142,10 @@ button:hover {
loading: false,
search: {
searchName: null,
searchCheckInDateStart: null,//入住日期
searchCheckInDateEnd: null,//入住日期的
searchCheckOutDateStart: null,//退房日期的
searchCheckOutDateEnd: null,//退房日期的
searchCheckInDateStart: null,//入住日期
searchCheckInDateEnd: null,//入住日期的
searchCheckOutDateStart: null,//退房日期的
searchCheckOutDateEnd: null,//退房日期的
searchCheckInDate: null,
searchCheckOutDate: null,

View File

@@ -6,16 +6,29 @@
<nav>
<a href="create.aspx" class="btn btn-primary" >新建掛單</a>
</nav>
<div class="me-10">
<button class="btn btn-primary" type="button">查询</button>
<div class="d-flex align-items-center gap-3">
<label class="mb-0">掛單登記人</label>
<input class="form-control w-auto" style="width:150px;" v-model="search.guadanUser" />
<label class="mb-0">開始時間</label>
<input class="form-control w-auto" style="width:150px;" type="date" v-model="search.startDate" />
<label class="mb-0">結束時間</label>
<input class="form-control w-auto" style="width:150px;" type="date" v-model="search.endDate" />
<button class="btn btn-primary" type="button" @click="handleSearch">查詢</button>
<button class="btn btn-outline-primary" type="button" @click="clearSearch">清除條件</button>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="mx-5">
<v-data-table
:items="items"
:headers="headers">
:headers="headers"
hide-default-footer>
<template #item.actions="{item}">
<a :href="'create.aspx?orderId='+item.guaDanOrderNo" class="btn btn-secondary">編輯</a>
<a class="btn btn-outline-danger" @click="deleteGuadanOrder(item)">取消</a>
@@ -39,6 +52,41 @@
{{item.created_at | timeString('YYYY/MM/DD HH:mm')}}
</template>
</v-data-table>
<v-container>
<v-row class="align-baseline" wrap="false">
<v-col cols="12" md="8">
<v-pagination
v-model="options.page"
:length="pageCount">
</v-pagination>
</v-col>
<v-col class="text-truncate text-right" cols="12" md="2">
共 {{ total }} 筆, 頁數:
</v-col>
<v-col cols="6" md="1">
<v-text-field
v-model="options.page"
type="number"
hide-details
dense
min="1"
:max="pageCount"
@input="options.page = parseInt($event, 10)"
></v-text-field>
</v-col>
<!-- 每页条数选择 -->
<v-col cols="12" md="1">
<v-select
v-model="options.itemsPerPage"
:items="[5, 10, 20, 50]"
label="每頁條數"
dense
hide-details
style="width: 100px;"
></v-select>
</v-col>
</v-row>
</v-container>
</div>
<!-- 更新修改確認彈出視窗 -->
<message-modal ref="messageModal"></message-modal>
@@ -69,17 +117,74 @@
{ text: '備註', value: 'notes', align: 'center' },
{ text: '操作', value: 'actions', align: 'center' }
],
options: {
page: 1, // 當前頁
itemsPerPage: 10, // 每頁條數
sortBy: [],
sortDesc: []
},
search: {
startDate: null,
endDate: null,
guadanUser: null,
},
total: 0,
loading: false,
}
},
methods: {
resetTableOptions() {
this.options = {
page: 1,
itemsPerPage: 10,
sortBy: [],
sortDesc: []
};
},
handleSearch() {
const val = this.search.guadanUser;
// 驗證是否包含空格
if (val && /\s/.test(val)) {
this.$refs.messageModal.open({
message: '掛單登記人不能包含空格'
});
return;
}
// 驗證長度
if (val && val.length > 10) {
this.$refs.messageModal.open({
message: '掛單登記人不能超過 10 個字'
});
return;
}
this.resetTableOptions();
},
clearSearch() {
this.search.startDate = null;
this.search.endDate = null;
this.search.guadanUser = null;
this.resetTableOptions();
},
getGuadanOrder() {
axios.get('/api/guadan/list')
if (this.loading) return;
axios.post('/api/guadan/list', {
startDate: this.search.startDate,
endDate: this.search.endDate,
guadanUser: this.search.guadanUser,
page: this.options.page,
pageSize: this.options.itemsPerPage
})
.then((res) => {
this.items = res.data;
this.items = res.data.data;
this.total = res.data.total;
}).catch((err) => {
console.log(err);
})
}).finally(() => {
this.loading = false;
});
},
deleteGuadanOrder(order) {
this.$refs.confirmModal.open({
@@ -105,11 +210,21 @@
},
},
watch: {
options: {
handler() {
this.getGuadanOrder(); // 監聽分頁、排序變化,自動載入數據
},
deep: true,
}
},
mounted() {
this.getGuadanOrder();
},
computed: {
pageCount() {
return Math.ceil(this.total / this.options.itemsPerPage)
},
}
});
</script>
</asp:Content>

View File

@@ -907,6 +907,10 @@
this.currentSelectRoom = null;
this.room_bed.bed_items = [];
//清空 beds
}).catch((error) => {
this.$refs.messageModal.open({
message: (error.response?.data?.message || error.message)
});
});
},
confirmRoomDelete() {