Some checks are pending
continuous-integration/drone/push Build is running
- Add inline editing UI for mileage correction field in fault detail page - Implement save/cancel buttons for mileage correction updates - Add updateMileageCorrection API endpoint and service method - Update App.vue global styles with page background color - Enhance pages.json with backgroundColorTop and backgroundColorBottom - Add MileageCorrectionDto for request validation - Implement batch fault times retrieval for export functionality - Add fault frequency time concatenation in export data - Improve export data structure with complete fault history information
211 lines
8.4 KiB
C#
211 lines
8.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using MiniExcelLibs;
|
||
using ZR.Model.Business.Dto;
|
||
using ZR.Service.Business.IBusinessService;
|
||
|
||
//创建时间:2025-09-21
|
||
namespace ZR.Admin.WebApi.Controllers.Business
|
||
{
|
||
/// <summary>
|
||
/// 干线故障管理
|
||
/// </summary>
|
||
[Route("business/OdfCableFaults")]
|
||
public class OdfCableFaultsController : BaseController
|
||
{
|
||
/// <summary>
|
||
/// 干线故障接口
|
||
/// </summary>
|
||
private readonly IOdfCableFaultsService _OdfCableFaultsService;
|
||
|
||
public OdfCableFaultsController(IOdfCableFaultsService OdfCableFaultsService)
|
||
{
|
||
_OdfCableFaultsService = OdfCableFaultsService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 故障列表分页查询
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("list")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:list")]
|
||
public IActionResult GetList([FromQuery] OdfCableFaultsQueryDto parm)
|
||
{
|
||
var response = _OdfCableFaultsService.GetList(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 故障详情(含图片)
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("{id}")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:query")]
|
||
public IActionResult GetDetail(int id)
|
||
{
|
||
var response = _OdfCableFaultsService.GetDetail(id);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增故障(含图片上传,APP端调用)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("add")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:list")]
|
||
[Log(Title = "干线故障", BusinessType = BusinessType.INSERT)]
|
||
public async Task<IActionResult> Add([FromForm] OdfCableFaultAddDto dto)
|
||
{
|
||
dto.UserId = HttpContext.GetUId();
|
||
var response = await _OdfCableFaultsService.AddFault(dto);
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 增加故障频次
|
||
/// </summary>
|
||
[HttpPost("incrementFaultCount/{id}")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:list")]
|
||
[Log(Title = "干线故障", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult IncrementFaultCount(int id)
|
||
{
|
||
var response = _OdfCableFaultsService.IncrementFaultCount(id);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新表显里程矫正
|
||
/// </summary>
|
||
[HttpPost("updateMileageCorrection/{id}")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:list")]
|
||
[Log(Title = "干线故障", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult UpdateMileageCorrection(int id, [FromBody] MileageCorrectionDto dto)
|
||
{
|
||
var response = _OdfCableFaultsService.UpdateMileageCorrection(id, dto.MileageCorrection);
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除故障并级联删除图片
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("delete/{id}")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:delete")]
|
||
[Log(Title = "干线故障", BusinessType = BusinessType.DELETE)]
|
||
public IActionResult Delete(int id)
|
||
{
|
||
var response = _OdfCableFaultsService.Delete(id);
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导出故障列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Log(Title = "干线故障", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||
[HttpGet("export")]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:export")]
|
||
public IActionResult Export([FromQuery] OdfCableFaultsQueryDto parm)
|
||
{
|
||
var list = _OdfCableFaultsService.ExportList(parm);
|
||
if (list == null || list.Result == null || list.Result.Count <= 0)
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
|
||
}
|
||
|
||
// 收集所有故障ID,批量查询频次时间记录
|
||
var faultIds = list.Result.Select(item => (int)((dynamic)item).Id).ToList();
|
||
var allFaultTimes = _OdfCableFaultsService.GetFaultTimesByFaultIds(faultIds);
|
||
|
||
// 将英文属性名转换为中文列头
|
||
var exportList = new List<Dictionary<string, object>>();
|
||
foreach (var item in list.Result)
|
||
{
|
||
var obj = (object)item;
|
||
var props = obj.GetType().GetProperties();
|
||
var dict = props.ToDictionary(p => p.Name, p => p.GetValue(obj));
|
||
var faultId = (int)dict.GetValueOrDefault("Id");
|
||
var faultCount = dict.ContainsKey("FaultCount") ? dict["FaultCount"] : 1;
|
||
|
||
// 拼接所有故障时间(首次 + 增加的频次时间)
|
||
var times = new List<string>();
|
||
var firstTime = dict.GetValueOrDefault("FaultTime");
|
||
if (firstTime != null) times.Add(firstTime.ToString());
|
||
if (allFaultTimes.ContainsKey(faultId))
|
||
{
|
||
times.AddRange(allFaultTimes[faultId].Select(t => t.ToString()));
|
||
}
|
||
times.Sort();
|
||
|
||
var row = new Dictionary<string, object>
|
||
{
|
||
["编号"] = dict.GetValueOrDefault("Id"),
|
||
["光缆编号"] = dict.GetValueOrDefault("CableId"),
|
||
["故障时间"] = string.Join("\n", times),
|
||
["故障发生频次"] = faultCount,
|
||
["人员"] = dict.GetValueOrDefault("Personnel"),
|
||
["故障原因"] = dict.GetValueOrDefault("FaultReason"),
|
||
["表显故障里程"] = dict.GetValueOrDefault("Mileage"),
|
||
["表显里程矫正"] = dict.GetValueOrDefault("MileageCorrection"),
|
||
["地点"] = dict.GetValueOrDefault("Location"),
|
||
["纬度"] = dict.GetValueOrDefault("Latitude"),
|
||
["经度"] = dict.GetValueOrDefault("Longitude"),
|
||
["备注"] = dict.GetValueOrDefault("Remark"),
|
||
["创建时间"] = dict.GetValueOrDefault("CreatedAt"),
|
||
["所属光缆"] = dict.GetValueOrDefault("CableName")
|
||
};
|
||
exportList.Add(row);
|
||
}
|
||
|
||
var result = ExportExcelMini(exportList, "故障列表", "故障列表");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量导入故障
|
||
/// </summary>
|
||
[HttpPost("importData")]
|
||
[Log(Title = "干线故障导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false)]
|
||
[ActionPermissionFilter(Permission = "odfcablefaults:import")]
|
||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||
{
|
||
if (formFile == null || formFile.Length <= 0)
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "请选择要导入的文件");
|
||
}
|
||
|
||
List<OdfCableFaultImportDto> list = new();
|
||
using (var stream = formFile.OpenReadStream())
|
||
{
|
||
list = stream.Query<OdfCableFaultImportDto>(startCell: "A1").ToList();
|
||
}
|
||
|
||
if (list.Count <= 0)
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "导入数据为空");
|
||
}
|
||
|
||
var (successCount, errorCount, errorMsg) = _OdfCableFaultsService.ImportFaults(list);
|
||
var msg = $"导入成功{successCount}条,失败{errorCount}条";
|
||
if (!string.IsNullOrEmpty(errorMsg))
|
||
{
|
||
msg += $"。{errorMsg}";
|
||
}
|
||
return SUCCESS(msg);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 干线故障导入模板下载
|
||
/// </summary>
|
||
[HttpGet("importTemplate")]
|
||
[Log(Title = "干线故障模板", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||
[AllowAnonymous]
|
||
public IActionResult ImportTemplateExcel()
|
||
{
|
||
var result = DownloadImportTemplate(new List<OdfCableFaultImportDto>() { }, "OdfCableFaults");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
}
|
||
}
|