using Microsoft.AspNetCore.Mvc;
using ZR.Model.Business.Dto;
using ZR.Service.Business.IBusinessService;
//创建时间:2025-01-01
namespace ZR.Admin.WebApi.Controllers.Business
{
///
/// 标石/杆号牌管理
///
[Route("business/OdfMarkerPoles")]
public class OdfMarkerPolesController : BaseController
{
///
/// 标石/杆号牌接口
///
private readonly IOdfMarkerPolesService _OdfMarkerPolesService;
private readonly IOdfAuditLogsService _auditLogsService;
public OdfMarkerPolesController(
IOdfMarkerPolesService OdfMarkerPolesService,
IOdfAuditLogsService auditLogsService)
{
_OdfMarkerPolesService = OdfMarkerPolesService;
_auditLogsService = auditLogsService;
}
///
/// 标石/杆号牌列表分页查询
///
///
///
[HttpGet("list")]
[ActionPermissionFilter(Permission = "odfmarkerpoles:list")]
public IActionResult GetList([FromQuery] OdfMarkerPolesQueryDto parm)
{
var deptId = HttpContext.GetDeptId();
var response = _OdfMarkerPolesService.GetList(parm, deptId);
return SUCCESS(response);
}
///
/// 标石/杆号牌详情(含图片)
///
///
///
[HttpGet("{id}")]
[ActionPermissionFilter(Permission = "odfmarkerpoles:query")]
public IActionResult GetDetail(int id)
{
var response = _OdfMarkerPolesService.GetDetail(id);
return SUCCESS(response);
}
///
/// 新增标石/杆号牌(图片已上传至COS,提交COS URL)
///
///
[HttpPost("add")]
[ActionPermissionFilter(Permission = "odfmarkerpoles:add")]
[Log(Title = "标石/杆号牌", BusinessType = BusinessType.INSERT)]
public IActionResult Add([FromBody] OdfMarkerPoleAddDto dto)
{
dto.UserId = HttpContext.GetUId();
var deptId = HttpContext.GetDeptId();
var response = _OdfMarkerPolesService.Add(dto, deptId);
// 手动记录 INSERT 审计日志
try
{
var newRecord = _OdfMarkerPolesService.GetFirst(f => f.Id == response);
string newData = BuildAuditJson(new Dictionary
{
["Id"] = newRecord.Id,
["关联光缆ID"] = newRecord.CableId,
["名称"] = newRecord.Name,
["记录时间"] = newRecord.RecordTime,
["责任人"] = newRecord.Personnel,
["纬度"] = newRecord.Latitude,
["经度"] = newRecord.Longitude,
["实际里程"] = newRecord.ActualMileage,
["部门ID"] = newRecord.DeptId,
["部门名称"] = newRecord.DeptName,
["提交人用户ID"] = newRecord.UserId,
["创建时间"] = newRecord.CreatedAt,
["更新时间"] = newRecord.UpdatedAt,
});
_auditLogsService.AddLog(BuildAuditLog("odf_marker_poles", response, "INSERT", null, newData));
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Error(ex, "审计日志写入失败");
}
return SUCCESS(response);
}
///
/// 编辑标石/杆号牌
///
///
[HttpPut("edit")]
[ActionPermissionFilter(Permission = "odfmarkerpoles:edit")]
[Log(Title = "标石/杆号牌", BusinessType = BusinessType.UPDATE)]
public IActionResult Update([FromBody] OdfMarkerPoleEditDto dto)
{
// 查旧数据
var oldRecord = _OdfMarkerPolesService.GetFirst(f => f.Id == dto.Id);
string oldData = BuildAuditJson(new Dictionary
{
["名称"] = oldRecord.Name,
["记录时间"] = oldRecord.RecordTime,
["责任人"] = oldRecord.Personnel,
["纬度"] = oldRecord.Latitude,
["经度"] = oldRecord.Longitude,
["实际里程"] = oldRecord.ActualMileage,
["更新时间"] = oldRecord.UpdatedAt,
});
// 执行更新
var response = _OdfMarkerPolesService.Update(dto);
// 查新数据
var newRecord = _OdfMarkerPolesService.GetFirst(f => f.Id == dto.Id);
string newData = BuildAuditJson(new Dictionary
{
["名称"] = newRecord.Name,
["记录时间"] = newRecord.RecordTime,
["责任人"] = newRecord.Personnel,
["纬度"] = newRecord.Latitude,
["经度"] = newRecord.Longitude,
["实际里程"] = newRecord.ActualMileage,
["更新时间"] = newRecord.UpdatedAt,
});
// 写入审计日志
try
{
_auditLogsService.AddLog(BuildAuditLog("odf_marker_poles", dto.Id, "UPDATE", oldData, newData));
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Error(ex, "审计日志写入失败");
}
return ToResponse(response);
}
///
/// 删除标石/杆号牌(支持单个/批量)
///
///
[HttpDelete("delete/{ids}")]
[ActionPermissionFilter(Permission = "odfmarkerpoles:delete")]
[Log(Title = "标石/杆号牌", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(string ids)
{
var idList = ids.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(s => int.TryParse(s.Trim(), out var v) ? v : 0)
.Where(v => v > 0)
.ToList();
if (idList.Count == 0)
{
return ToResponse(ResultCode.FAIL, "请选择要删除的数据");
}
// 循环每条记录分别记录 DELETE 审计日志
foreach (var id in idList)
{
var oldRecord = _OdfMarkerPolesService.GetFirst(f => f.Id == id);
string oldData = BuildAuditJson(new Dictionary
{
["Id"] = oldRecord.Id,
["关联光缆ID"] = oldRecord.CableId,
["名称"] = oldRecord.Name,
["记录时间"] = oldRecord.RecordTime,
["责任人"] = oldRecord.Personnel,
["纬度"] = oldRecord.Latitude,
["经度"] = oldRecord.Longitude,
["实际里程"] = oldRecord.ActualMileage,
["部门ID"] = oldRecord.DeptId,
["部门名称"] = oldRecord.DeptName,
["提交人用户ID"] = oldRecord.UserId,
["创建时间"] = oldRecord.CreatedAt,
["更新时间"] = oldRecord.UpdatedAt,
});
try
{
_auditLogsService.AddLog(BuildAuditLog("odf_marker_poles", id, "DELETE", oldData, null));
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Error(ex, "审计日志写入失败");
}
}
int total = 0;
foreach (var id in idList)
{
total += _OdfMarkerPolesService.Delete(id);
}
return ToResponse(total);
}
}
}