odf_new/server/ZR.Admin.WebApi/Controllers/Business/OdfMarkerPolesController.cs
zpc 996e1abc24
Some checks reported errors
continuous-integration/drone/push Build encountered an error
21
2026-04-21 21:57:28 +08:00

207 lines
7.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using ZR.Model.Business.Dto;
using ZR.Service.Business.IBusinessService;
//创建时间2025-01-01
namespace ZR.Admin.WebApi.Controllers.Business
{
/// <summary>
/// 标石/杆号牌管理
/// </summary>
[Route("business/OdfMarkerPoles")]
public class OdfMarkerPolesController : BaseController
{
/// <summary>
/// 标石/杆号牌接口
/// </summary>
private readonly IOdfMarkerPolesService _OdfMarkerPolesService;
private readonly IOdfAuditLogsService _auditLogsService;
public OdfMarkerPolesController(
IOdfMarkerPolesService OdfMarkerPolesService,
IOdfAuditLogsService auditLogsService)
{
_OdfMarkerPolesService = OdfMarkerPolesService;
_auditLogsService = auditLogsService;
}
/// <summary>
/// 标石/杆号牌列表分页查询
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[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);
}
/// <summary>
/// 标石/杆号牌详情(含图片)
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
[ActionPermissionFilter(Permission = "odfmarkerpoles:query")]
public IActionResult GetDetail(int id)
{
var response = _OdfMarkerPolesService.GetDetail(id);
return SUCCESS(response);
}
/// <summary>
/// 新增标石/杆号牌图片已上传至COS提交COS URL
/// </summary>
/// <returns></returns>
[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<string, object>
{
["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);
}
/// <summary>
/// 编辑标石/杆号牌
/// </summary>
/// <returns></returns>
[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<string, object>
{
["名称"] = 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<string, object>
{
["名称"] = 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);
}
/// <summary>
/// 删除标石/杆号牌(支持单个/批量)
/// </summary>
/// <returns></returns>
[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<string, object>
{
["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);
}
}
}