神祖牌位管理模組,掛單模組前端URL添加HTTP_HOST
This commit is contained in:
180
web/App_Code/api/AncestralTabletAreaController.cs
Normal file
180
web/App_Code/api/AncestralTabletAreaController.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using Model;
|
||||
using PagedList;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using static AncestralTabletPositionController;
|
||||
using static regionController;
|
||||
|
||||
/// <summary>
|
||||
/// AncestralTabletController 的摘要描述
|
||||
/// </summary>
|
||||
public class AncestralTabletAreaController: ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
public class AreaViewModel
|
||||
{
|
||||
public int? AreaId { get; set; }
|
||||
public string AreaName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "區域編號為必填")]
|
||||
public string AreaCode { get; set; }
|
||||
public int? ParentAreaId { get; set; }
|
||||
public string AreaType { get; set; }
|
||||
public int? Price { get; set; }
|
||||
public int? SortOrder { get; set; }
|
||||
public bool IsDisabled { get; set; } = false;
|
||||
public string Description { get; set; }
|
||||
}
|
||||
public class RegionDto
|
||||
{
|
||||
public int AreaId { get; set; }
|
||||
public string AreaName { get; set; }
|
||||
public string AreaCode { get; set; }
|
||||
public int? SortOrder { get; set; }
|
||||
public int? ParentAreaId { get; set; }
|
||||
public string AreaType { get; set; }
|
||||
public bool IsDisabled { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int? Price { set; get; }
|
||||
|
||||
public List<RegionDto> Children { get; set; } = new List<RegionDto>();
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/area/getlist")]
|
||||
public IHttpActionResult GetList()
|
||||
{
|
||||
var allArea = _db.AncestralTabletArea.ToList();
|
||||
|
||||
var rootRegions = allArea
|
||||
.Where(r => r.ParentAreaId == null)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.ToList();
|
||||
|
||||
var tree = rootRegions
|
||||
.Select(r => BuildRegionDto(r, allArea))
|
||||
.ToList();
|
||||
return Ok(tree);
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/area/getereawithposition")]
|
||||
public IHttpActionResult GetEreaWithPosition()
|
||||
{
|
||||
//获取有神位位置的区域
|
||||
var allArea = _db.AncestralTabletArea
|
||||
.Where(a => a.AncestralTabletPosition.Count()>0)
|
||||
.Select(a => new
|
||||
{
|
||||
a.AreaId,
|
||||
a.AreaName,
|
||||
})
|
||||
.ToList();
|
||||
return Ok(allArea);
|
||||
|
||||
}
|
||||
private RegionDto BuildRegionDto(AncestralTabletArea area, List<AncestralTabletArea> allArea)
|
||||
{
|
||||
return new RegionDto
|
||||
{
|
||||
AreaId = area.AreaId,
|
||||
AreaName = area.AreaName,
|
||||
AreaCode = area.AreaCode,
|
||||
SortOrder = area.SortOrder,
|
||||
ParentAreaId = area.ParentAreaId,
|
||||
AreaType = area.AreaType,
|
||||
IsDisabled = area.IsDisabled,
|
||||
Description = area.Description,
|
||||
Price = area.Price,
|
||||
Children = allArea
|
||||
.Where(r => r.ParentAreaId == area.AreaId)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.Select(child => BuildRegionDto(child, allArea))
|
||||
.ToList(),
|
||||
};
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/area/create")]
|
||||
public async Task<IHttpActionResult> CreateArea([FromBody] AreaViewModel tabletArea)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
try
|
||||
{
|
||||
var area = new AncestralTabletArea
|
||||
{
|
||||
AreaName = tabletArea.AreaName,
|
||||
AreaCode = tabletArea.AreaCode,
|
||||
ParentAreaId = tabletArea.ParentAreaId,
|
||||
AreaType = tabletArea.AreaType,
|
||||
Price = tabletArea.Price,
|
||||
SortOrder = tabletArea.SortOrder,
|
||||
IsDisabled = tabletArea.IsDisabled,
|
||||
Description = tabletArea.Description
|
||||
};
|
||||
_db.AncestralTabletArea.Add(area);
|
||||
await _db.SaveChangesAsync();
|
||||
tabletArea.AreaId = area.AreaId;
|
||||
return Ok(new { message = "區域建立成功", area = tabletArea });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/area/edit")]
|
||||
public async Task<IHttpActionResult> EditArea([FromBody] AreaViewModel tabletArea)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
try
|
||||
{
|
||||
var oldArea = _db.AncestralTabletArea.Find(tabletArea.AreaId);
|
||||
if (oldArea == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
oldArea.AreaName = tabletArea.AreaName;
|
||||
oldArea.AreaCode = tabletArea.AreaCode;
|
||||
oldArea.ParentAreaId = tabletArea.ParentAreaId;
|
||||
oldArea.Price = tabletArea.Price;
|
||||
oldArea.SortOrder = tabletArea.SortOrder;
|
||||
oldArea.Description = tabletArea.Description;
|
||||
oldArea.IsDisabled = tabletArea.IsDisabled;
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { message = "區域修改成功", area = tabletArea });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/area/position/getlist")]
|
||||
public IHttpActionResult GetPositionList([FromUri] int areaId)
|
||||
{
|
||||
var positions = _db.AncestralTabletPosition
|
||||
.Where(p => p.AreaId == areaId)
|
||||
.Select(p => new AncestralTabletPositionDto
|
||||
{
|
||||
PositionId = p.PositionId,
|
||||
AreaId = p.AreaId,
|
||||
PositionCode = p.PositionCode,
|
||||
PositionName = p.PositionName,
|
||||
Price = p.Price,
|
||||
StatusCode = p.StatusCode,
|
||||
Description = p.Description,
|
||||
RowNo = p.RowNo,
|
||||
ColumnNo = p.ColumnNo
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Ok(positions);
|
||||
}
|
||||
}
|
||||
184
web/App_Code/api/AncestralTabletPositionController.cs
Normal file
184
web/App_Code/api/AncestralTabletPositionController.cs
Normal file
@@ -0,0 +1,184 @@
|
||||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
/// <summary>
|
||||
/// AncestralTabletPositionController 的摘要描述
|
||||
/// </summary>
|
||||
public class AncestralTabletPositionController: ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/position/getlist")]
|
||||
public IHttpActionResult GetList([FromUri] int areaId)
|
||||
{
|
||||
var positions = _db.AncestralTabletPosition
|
||||
.Where(p => p.AreaId == areaId)
|
||||
.Select(p => new
|
||||
{
|
||||
PositionId = p.PositionId,
|
||||
AreaId = p.AreaId,
|
||||
PositionCode = p.PositionCode,
|
||||
PositionName = p.PositionName,
|
||||
Price = p.Price,
|
||||
StatusCode = p.StatusCode,
|
||||
Description = p.Description,
|
||||
RowNo = p.RowNo,
|
||||
ColumnNo = p.ColumnNo,
|
||||
AncestralTabletRegistrant = _db.AncestralTabletRegistrant
|
||||
.Where(r => r.PositionId == p.PositionId && r.IsActive == true)
|
||||
.Select(r => new
|
||||
{
|
||||
r.RegistrantCode,
|
||||
r.Name,
|
||||
r.Phone,
|
||||
r.Address,
|
||||
r.RegisterDate,
|
||||
r.Price,
|
||||
r.StartDate,
|
||||
r.EndDate,
|
||||
r.IsLongTerm,
|
||||
r.IsActive,
|
||||
|
||||
// 嵌套查询牌位记录(PositionRecord)
|
||||
TabletRecord = r.AncestralTabletPositionRecord
|
||||
.Select(pr => new
|
||||
{
|
||||
pr.RecordId,
|
||||
pr.RegistrantCode,
|
||||
pr.NPTitle,
|
||||
pr.NPStandDate,
|
||||
pr.NPYangShang,
|
||||
pr.WPContent
|
||||
})
|
||||
.FirstOrDefault()
|
||||
})
|
||||
.FirstOrDefault()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Ok(positions);
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/position/shortlist")]
|
||||
public IHttpActionResult GetListWithShort([FromUri] int areaId)
|
||||
{
|
||||
//获取位置列表,简单信息
|
||||
var positions = _db.AncestralTabletPosition
|
||||
.Where(p => p.AreaId == areaId)
|
||||
.Select(p => new
|
||||
{
|
||||
PositionId = p.PositionId,
|
||||
AreaId = p.AreaId,
|
||||
PositionCode = p.PositionCode,
|
||||
PositionName = p.PositionName,
|
||||
Price = p.Price,
|
||||
StatusCode = p.StatusCode,
|
||||
Description = p.Description,
|
||||
RowNo = p.RowNo,
|
||||
ColumnNo = p.ColumnNo,
|
||||
isCanUse = p.StatusCode == "available" ? true : false,
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Ok(positions);
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/position/batchcreate")]
|
||||
public IHttpActionResult BatchCreatePosition([FromBody] List<AncestralTabletPositionDto> positions)
|
||||
{
|
||||
if (positions == null || positions.Count == 0)
|
||||
return BadRequest("未接收到任何位置数据");
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var dto in positions)
|
||||
{
|
||||
var entity = new AncestralTabletPosition
|
||||
{
|
||||
AreaId = dto.AreaId,
|
||||
PositionCode = dto.PositionCode,
|
||||
PositionName = dto.PositionName,
|
||||
Price = dto.Price,
|
||||
StatusCode = dto.StatusCode,
|
||||
Description = dto.Description,
|
||||
RowNo = dto.RowNo,
|
||||
ColumnNo = dto.ColumnNo
|
||||
};
|
||||
|
||||
_db.AncestralTabletPosition.Add(entity);
|
||||
}
|
||||
|
||||
_db.SaveChanges();
|
||||
|
||||
return Ok(new { message = "批量新增成功", count = positions.Count });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string message = ex.InnerException?.InnerException?.Message ?? ex.Message;
|
||||
|
||||
return Content(HttpStatusCode.InternalServerError, new
|
||||
{
|
||||
message = "批量新增失败",
|
||||
exceptionMessage = message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/position/edit")]
|
||||
public IHttpActionResult EditPosition([FromBody] AncestralTabletPositionDto pos)
|
||||
{
|
||||
var oldPos = _db.AncestralTabletPosition
|
||||
.FirstOrDefault(p => p.AreaId == pos.AreaId && p.PositionCode == pos.PositionCode);
|
||||
if(oldPos == null) return NotFound();
|
||||
try
|
||||
{
|
||||
oldPos.PositionName = pos.PositionName;
|
||||
oldPos.Price = pos.Price;
|
||||
oldPos.StatusCode = pos.StatusCode;
|
||||
|
||||
// 保存到数据库
|
||||
_db.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
return Ok(new { message="更新成功", code=200});
|
||||
}
|
||||
[HttpDelete]
|
||||
[Route("api/ancestraltablet/position/delete/{positionId}")]
|
||||
public IHttpActionResult DeletePosition(int positionId)
|
||||
{
|
||||
var pos = _db.AncestralTabletPosition.FirstOrDefault(p => p.PositionId == positionId);
|
||||
|
||||
if (pos == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_db.AncestralTabletPosition.Remove(pos);
|
||||
_db.SaveChanges();
|
||||
|
||||
return Ok("删除成功");
|
||||
}
|
||||
public class AncestralTabletPositionDto
|
||||
{
|
||||
public int PositionId { get; set; }
|
||||
public int AreaId { get; set; }
|
||||
public string PositionCode { get; set; }
|
||||
public string PositionName { get; set; }
|
||||
public int? Price { get; set; }
|
||||
public string StatusCode { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int? RowNo { get; set; }
|
||||
public int? ColumnNo { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
361
web/App_Code/api/AncestralTabletRecordController.cs
Normal file
361
web/App_Code/api/AncestralTabletRecordController.cs
Normal file
@@ -0,0 +1,361 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
/// <summary>
|
||||
/// AncestralTabletRecordController 的摘要描述
|
||||
/// </summary>
|
||||
public class AncestralTabletRecordController: ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/registrant/getlist")]
|
||||
public IHttpActionResult GetRegistrantList()
|
||||
{
|
||||
//获取登记人列表
|
||||
var data = _db.AncestralTabletRegistrant.Select(x => new
|
||||
{
|
||||
x.RegistrantCode,
|
||||
x.Name,
|
||||
x.Phone,
|
||||
x.Address,
|
||||
x.RegisterDate,
|
||||
x.Price,
|
||||
x.PositionId,
|
||||
x.StartDate,
|
||||
x.EndDate,
|
||||
x.IsLongTerm,
|
||||
x.IsActive,
|
||||
x.CreatedAt,
|
||||
x.UpdatedAt
|
||||
})
|
||||
.Take(1000) // 取前1000条
|
||||
.ToList(); ;
|
||||
return Ok(data);
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/registrant/getlistbypage")]
|
||||
public IHttpActionResult GetRegistrantListByPage([FromBody] RegistrantSearchDto searchDto)
|
||||
{
|
||||
//获取登记人列表
|
||||
var query = _db.AncestralTabletRegistrant.AsQueryable();
|
||||
if( !string.IsNullOrEmpty(searchDto.searchName))
|
||||
{
|
||||
query = query.Where(r => r.Name == searchDto.searchName);
|
||||
}
|
||||
var tatol = query.Count();
|
||||
var data = query.Select(x => new
|
||||
{
|
||||
x.RegistrantCode,
|
||||
x.Name,
|
||||
x.Phone,
|
||||
x.Address,
|
||||
x.RegisterDate,
|
||||
x.Price,
|
||||
x.PositionId,
|
||||
x.StartDate,
|
||||
x.EndDate,
|
||||
x.IsLongTerm,
|
||||
x.IsActive,
|
||||
x.CreatedAt,
|
||||
x.UpdatedAt
|
||||
})
|
||||
.OrderByDescending(a => a.CreatedAt)
|
||||
.Skip((searchDto.page - 1) * searchDto.pageSize)
|
||||
.Take(searchDto.pageSize) // 取前1000条
|
||||
.ToList();
|
||||
return Ok(new
|
||||
{
|
||||
data = data,
|
||||
total = tatol
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/registrant/getbycode")]
|
||||
public IHttpActionResult GetRegistrantByCode([FromUri] string registrantCode)
|
||||
{
|
||||
var r = _db.AncestralTabletRegistrant.Find(registrantCode);
|
||||
if (r == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
var rDto = new
|
||||
{
|
||||
r.RegistrantCode,
|
||||
r.Name,
|
||||
r.Phone,
|
||||
r.Address,
|
||||
r.RegisterDate,
|
||||
r.Price,
|
||||
r.StartDate,
|
||||
r.EndDate,
|
||||
r.IsLongTerm,
|
||||
r.IsActive,
|
||||
r.PositionId,
|
||||
positionName = r.AncestralTabletPosition?.PositionName,
|
||||
|
||||
|
||||
// 嵌套查询牌位记录(PositionRecord)
|
||||
TabletRecord = r.AncestralTabletPositionRecord
|
||||
.Select(pr => new
|
||||
{
|
||||
pr.RecordId,
|
||||
pr.RegistrantCode,
|
||||
pr.NPTitle,
|
||||
pr.NPStandDate,
|
||||
pr.NPYangShang,
|
||||
pr.WPContent,
|
||||
})
|
||||
.FirstOrDefault()
|
||||
};
|
||||
return Ok(rDto);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/registrant/create")]
|
||||
public IHttpActionResult CreateRegistrant([FromBody] AncestralTabletRegistrantDto dto)
|
||||
{
|
||||
//新增登记人api
|
||||
if (dto == null)
|
||||
{
|
||||
return BadRequest("请求体不能为空");
|
||||
}
|
||||
if(!string.IsNullOrEmpty(dto.RegistrantCode))
|
||||
{
|
||||
return BadRequest("RegistrantCode 应传递空");
|
||||
}
|
||||
try
|
||||
{
|
||||
dto.RegistrantCode = GenerateRegistrantCode();
|
||||
|
||||
// 设置默认创建时间
|
||||
dto.CreatedAt = DateTime.Now;
|
||||
var entity = new Model.AncestralTabletRegistrant
|
||||
{
|
||||
RegistrantCode = dto.RegistrantCode,
|
||||
Name = dto.Name,
|
||||
Phone = dto.Phone,
|
||||
Address = dto.Address,
|
||||
RegisterDate = dto.RegisterDate,
|
||||
Price = dto.Price,
|
||||
PositionId = dto.PositionId,
|
||||
StartDate = dto.startDate,
|
||||
EndDate = dto.endDate,
|
||||
IsLongTerm = dto.isLongTerm,
|
||||
IsActive = dto.isActive,
|
||||
CreatedAt = dto.CreatedAt,
|
||||
UpdatedAt = dto.UpdatedAt
|
||||
};
|
||||
|
||||
// 假设你有一个 EF DbContext(如 _db)
|
||||
_db.AncestralTabletRegistrant.Add(entity);
|
||||
if (dto.PositionId != null)
|
||||
{
|
||||
var position = _db.AncestralTabletPosition
|
||||
.FirstOrDefault(p => p.PositionId == dto.PositionId);
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
position.StatusCode = "used"; // 或者根据你的枚举/字段设置
|
||||
}
|
||||
}
|
||||
|
||||
_db.SaveChanges();
|
||||
|
||||
return Ok(new { message = "登记成功", registrantCode = entity.RegistrantCode });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/registrant/update")]
|
||||
public IHttpActionResult UpdateRegistrant([FromBody] AncestralTabletRegistrantDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
{
|
||||
return BadRequest("请求体不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dto.RegistrantCode))
|
||||
{
|
||||
return BadRequest("缺少 RegistrantCode,无法进行更新操作");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 查找原始资料
|
||||
var entity = _db.AncestralTabletRegistrant
|
||||
.FirstOrDefault(r => r.RegistrantCode == dto.RegistrantCode);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return NotFound(); // 没有对应记录
|
||||
}
|
||||
|
||||
// ===== 处理安位状态 =====
|
||||
if (entity.PositionId != dto.PositionId)
|
||||
{
|
||||
// 1. 原来的安位设置为可用
|
||||
if (entity.PositionId != null)
|
||||
{
|
||||
var oldPosition = _db.AncestralTabletPosition
|
||||
.FirstOrDefault(p => p.PositionId == entity.PositionId);
|
||||
|
||||
if (oldPosition != null)
|
||||
{
|
||||
oldPosition.StatusCode = "available"; // 可用
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 新的安位设置为已使用
|
||||
if (dto.PositionId != null)
|
||||
{
|
||||
var newPosition = _db.AncestralTabletPosition
|
||||
.FirstOrDefault(p => p.PositionId == dto.PositionId);
|
||||
|
||||
if (newPosition != null)
|
||||
{
|
||||
newPosition.StatusCode = "used"; // 已使用
|
||||
}
|
||||
}
|
||||
|
||||
// 更新登记人安位
|
||||
entity.PositionId = dto.PositionId;
|
||||
}
|
||||
|
||||
// 更新其它字段
|
||||
entity.Name = dto.Name;
|
||||
entity.Phone = dto.Phone;
|
||||
entity.Address = dto.Address;
|
||||
entity.RegisterDate = dto.RegisterDate;
|
||||
entity.Price = dto.Price;
|
||||
entity.StartDate = dto.startDate;
|
||||
entity.EndDate = dto.endDate;
|
||||
entity.IsLongTerm = dto.isLongTerm;
|
||||
entity.IsActive = dto.isActive;
|
||||
entity.UpdatedAt = DateTime.Now;
|
||||
|
||||
_db.SaveChanges();
|
||||
|
||||
return Ok(new { message = "登记人更新成功", registrantCode = entity.RegistrantCode });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/pw/create")]
|
||||
public IHttpActionResult CreatePW([FromBody] AncestralTabletPositionRecordDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
return BadRequest("请求体不能为空");
|
||||
|
||||
if (string.IsNullOrEmpty(dto.RegistrantCode))
|
||||
return BadRequest("登记人编号(RegistrantCode)不能为空");
|
||||
|
||||
try
|
||||
{
|
||||
// 映射到数据库实体
|
||||
var entity = new Model.AncestralTabletPositionRecord
|
||||
{
|
||||
RegistrantCode = dto.RegistrantCode,
|
||||
NPTitle = dto.NPTitle,
|
||||
NPStandDate = dto.NPStandDate,
|
||||
NPYangShang = dto.NPYangShang,
|
||||
WPContent = dto.WPContent,
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = null
|
||||
};
|
||||
|
||||
_db.AncestralTabletPositionRecord.Add(entity);
|
||||
_db.SaveChanges();
|
||||
|
||||
return Ok(new { message = "牌位登记成功", recordId = entity.RecordId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/pw/update")]
|
||||
public IHttpActionResult UpdatePW([FromBody] AncestralTabletPositionRecordDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
return BadRequest("请求体不能为空");
|
||||
try
|
||||
{
|
||||
var entity = _db.AncestralTabletPositionRecord.Find(dto.RecordId);
|
||||
// 映射到数据库实体
|
||||
if (entity == null)
|
||||
return BadRequest("牌位不存在,更新失败");
|
||||
entity.RegistrantCode = dto.RegistrantCode;
|
||||
entity.NPTitle = dto.NPTitle;
|
||||
entity.NPStandDate = dto.NPStandDate;
|
||||
entity.NPYangShang = dto.NPYangShang;
|
||||
entity.WPContent = dto.WPContent;
|
||||
entity.UpdatedAt = DateTime.Now;
|
||||
_db.SaveChanges();
|
||||
|
||||
return Ok(new { message = "牌位更新成功", recordId = entity.RecordId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public string GenerateRegistrantCode(string prefix = "REG", int randomLength = 6)
|
||||
{
|
||||
string datePart = DateTime.Now.ToString("yyyyMMdd");
|
||||
|
||||
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
var random = new Random();
|
||||
var suffix = new string(Enumerable.Repeat(chars, randomLength)
|
||||
.Select(s => s[random.Next(s.Length)]).ToArray());
|
||||
|
||||
return $"{prefix}{datePart}{suffix}";
|
||||
}
|
||||
public class AncestralTabletRegistrantDto
|
||||
{
|
||||
public string RegistrantCode { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Phone { get; set; }
|
||||
public string Address { get; set; }
|
||||
public DateTime RegisterDate { get; set; }
|
||||
public int? Price { get; set; }
|
||||
public int? PositionId { get; set; }
|
||||
public DateTime startDate { get; set; }
|
||||
public DateTime? endDate { get; set; }
|
||||
public bool isLongTerm { get; set; } = false;
|
||||
public bool isActive { get; set; } = true;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
public class AncestralTabletPositionRecordDto
|
||||
{
|
||||
public int? RecordId { get; set; }
|
||||
public string RegistrantCode { get; set; }
|
||||
public string NPTitle { get; set; }
|
||||
public DateTime NPStandDate { get; set; }
|
||||
public string NPYangShang { get; set; }
|
||||
public string WPContent { get; set; }
|
||||
}
|
||||
public class RegistrantSearchDto
|
||||
{
|
||||
public int page { get; set; } = 1;
|
||||
public int pageSize { get; set; } = 10;
|
||||
public string searchName { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
38
web/App_Code/api/AncestralTabletStatisticsController.cs
Normal file
38
web/App_Code/api/AncestralTabletStatisticsController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
/// <summary>
|
||||
/// AncestralTabletStatisticsController 的摘要描述
|
||||
/// </summary>
|
||||
public class AncestralTabletStatisticsController:ApiController
|
||||
{
|
||||
private Model.ezEntities db = new Model.ezEntities();
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/statistics/positions/availablepositions")]
|
||||
public IHttpActionResult GetAvailablePositions()
|
||||
{
|
||||
var query =
|
||||
from a in db.AncestralTabletArea // 区域表
|
||||
join p in db.AncestralTabletPosition
|
||||
on a.AreaId equals p.AreaId into ap
|
||||
from p in ap.DefaultIfEmpty()
|
||||
join r in db.AncestralTabletRegistrant
|
||||
on p.PositionId equals r.PositionId into pr
|
||||
from r in pr.DefaultIfEmpty()
|
||||
group new { a, p, r } by new { a.AreaId, a.AreaName } into g
|
||||
select new
|
||||
{
|
||||
AreaId = g.Key.AreaId,
|
||||
AreaName = g.Key.AreaName,
|
||||
TotalPositions = g.Count(x => x.p != null), // 总位置数
|
||||
AvailableCount = g.Count(x => x.p != null && x.r == null) // 可用位置数(未登记)
|
||||
};
|
||||
|
||||
var result = query.ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
29
web/App_Code/api/AncestralTabletStatusController.cs
Normal file
29
web/App_Code/api/AncestralTabletStatusController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
/// <summary>
|
||||
/// AncestralTabletStatusController 的摘要描述
|
||||
/// </summary>
|
||||
public class AncestralTabletStatusController:ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/status/list")]
|
||||
public IHttpActionResult GetStatusList()
|
||||
{
|
||||
var statusList = _db.AncestralTabletStatus
|
||||
.Select(s => new
|
||||
{
|
||||
s.StatusCode,
|
||||
s.StatusName,
|
||||
s.StatusType
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Ok(statusList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,6 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using static regionController;
|
||||
|
||||
/// <summary>
|
||||
/// guadanOderController 的摘要描述
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user