|
@@ -1,4 +1,6 @@
|
|
|
|
|
+using System.Text.Json;
|
|
|
using Admin.NET.Plugin.AiDOP.ProcurementExecution.Dto;
|
|
using Admin.NET.Plugin.AiDOP.ProcurementExecution.Dto;
|
|
|
|
|
+using Admin.NET.Plugin.AiDOP.ProcurementExecution.Entity;
|
|
|
|
|
|
|
|
namespace Admin.NET.Plugin.AiDOP.ProcurementExecution;
|
|
namespace Admin.NET.Plugin.AiDOP.ProcurementExecution;
|
|
|
|
|
|
|
@@ -142,5 +144,89 @@ public class SupplierShortageKanbanService : IDynamicApiController, ITransient
|
|
|
return new { ok = false, elapsedMs = sw.ElapsedMilliseconds, message = ex.Message };
|
|
return new { ok = false, elapsedMs = sw.ElapsedMilliseconds, message = ex.Message };
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 创建催料待办:快照当前 WorkOrdDetailTotalKB 数据,返回新记录 Id(前端再用此 Id 发起审批流)
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ [DisplayName("创建催料待办")]
|
|
|
|
|
+ [HttpPost("supplier-shortage-kanban/create-todo")]
|
|
|
|
|
+ public async Task<object> CreateTodo()
|
|
|
|
|
+ {
|
|
|
|
|
+ var tenantId = AidopTenantHelper.Resolve(App.HttpContext);
|
|
|
|
|
+ var userId = _userManager?.UserId ?? 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 查询当前全量欠料数据作为快照
|
|
|
|
|
+ var hasTenantColumn = await _db.Ado.GetIntAsync("""
|
|
|
|
|
+ SELECT COUNT(1) FROM information_schema.COLUMNS
|
|
|
|
|
+ WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'WorkOrdDetailTotalKB' AND COLUMN_NAME = 'tenant_id'
|
|
|
|
|
+ """) > 0;
|
|
|
|
|
+
|
|
|
|
|
+ var where = hasTenantColumn ? "WHERE tenant_id = @TenantId" : "";
|
|
|
|
|
+ var pars = hasTenantColumn ? new[] { new SugarParameter("@TenantId", tenantId) } : Array.Empty<SugarParameter>();
|
|
|
|
|
+
|
|
|
|
|
+ var snapshotSql = $"""
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ IFNULL(supplier_number, '') AS supplier_number,
|
|
|
|
|
+ IFNULL(supplier_name, '') AS supplier_name,
|
|
|
|
|
+ IFNULL(ItemNum, '') AS ItemNum,
|
|
|
|
|
+ IFNULL(Descr, '') AS Descr,
|
|
|
|
|
+ IFNULL(Descr1, '') AS Descr1,
|
|
|
|
|
+ IFNULL(D0, 0) AS D0, IFNULL(D1, 0) AS D1, IFNULL(D2, 0) AS D2,
|
|
|
|
|
+ IFNULL(D3, 0) AS D3, IFNULL(D4, 0) AS D4, IFNULL(D5, 0) AS D5,
|
|
|
|
|
+ IFNULL(D6, 0) AS D6, IFNULL(D7, 0) AS D7, IFNULL(D8, 0) AS D8,
|
|
|
|
|
+ IFNULL(D9, 0) AS D9, IFNULL(D10, 0) AS D10, IFNULL(D11, 0) AS D11,
|
|
|
|
|
+ IFNULL(D12, 0) AS D12, IFNULL(D13, 0) AS D13, IFNULL(D14, 0) AS D14
|
|
|
|
|
+ FROM WorkOrdDetailTotalKB {where}
|
|
|
|
|
+ ORDER BY IFNULL(D0, 0) DESC
|
|
|
|
|
+ """;
|
|
|
|
|
+
|
|
|
|
|
+ var rows = await _db.Ado.SqlQueryAsync<SupplierShortageKanbanListRow>(snapshotSql, pars);
|
|
|
|
|
+ var snapshotJson = JsonSerializer.Serialize(rows, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
|
|
|
+
|
|
|
|
|
+ var todo = new AdoMaterialShortageTodo
|
|
|
|
|
+ {
|
|
|
|
|
+ TenantId = tenantId,
|
|
|
|
|
+ SnapshotData = snapshotJson,
|
|
|
|
|
+ TotalCount = rows.Count,
|
|
|
|
|
+ FlowStatus = "PENDING",
|
|
|
|
|
+ CreateBy = userId,
|
|
|
|
|
+ CreateTime = DateTime.Now,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var id = await _db.Insertable(todo).ExecuteReturnIdentityAsync();
|
|
|
|
|
+ return new { id, totalCount = rows.Count };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 获取催料待办详情(含快照数据)
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ [DisplayName("催料待办详情")]
|
|
|
|
|
+ [HttpGet("supplier-shortage-kanban/todo-detail/{id:long}")]
|
|
|
|
|
+ public async Task<object> GetTodoDetail(long id)
|
|
|
|
|
+ {
|
|
|
|
|
+ var todo = await _db.Queryable<AdoMaterialShortageTodo>()
|
|
|
|
|
+ .Where(t => t.Id == id)
|
|
|
|
|
+ .FirstAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (todo == null) return new { code = 404, message = "待办不存在" };
|
|
|
|
|
+
|
|
|
|
|
+ var snapshotRows = new List<SupplierShortageKanbanListRow>();
|
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(todo.SnapshotData))
|
|
|
|
|
+ {
|
|
|
|
|
+ snapshotRows = JsonSerializer.Deserialize<List<SupplierShortageKanbanListRow>>(todo.SnapshotData,
|
|
|
|
|
+ new JsonSerializerOptions { PropertyNameCaseInsensitive = true }) ?? new List<SupplierShortageKanbanListRow>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return new
|
|
|
|
|
+ {
|
|
|
|
|
+ todo.Id,
|
|
|
|
|
+ todo.FlowStatus,
|
|
|
|
|
+ todo.FlowInstanceId,
|
|
|
|
|
+ todo.TotalCount,
|
|
|
|
|
+ todo.CreateBy,
|
|
|
|
|
+ todo.CreateTime,
|
|
|
|
|
+ snapshotRows,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|