feat(repository): CncRepository完整实现 - 20接口+16实现,编译通过
- Interface: 20个仓储接口(ISysConfig/IWorkshop/IBrand/IBrandFieldMapping/ICollectAddress/IMachine/IWorker/IWorkerMachine/IDailyProduction/IProductionSegment/IMachineDailyStatus/IWorkerDailySummary/IProductionAdjustment/IAlert/IScreenConfig/IScreenFilter/ICollectRaw/ISystemLog/ICollectorHeartbeat/IDashboard) - Impl: 16个仓储实现(BusinessRepository子类+LogRepository子类) - 包含: 基础CRUD/分页查询/多表JOIN/统计聚合/仪表盘查询 - 修复: AlertRepository继承修正(BusinessRepository)/dynamic替换为强类型main
parent
5ec37e6724
commit
fc7d350c3d
@ -1,15 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace CncModels.Dto.Alert
|
namespace CncModels.Dto.Alert
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 告警统计
|
/// 告警统计结果(未处理告警分类型统计)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AlertStatisticsResponse
|
public class AlertStatisticsResponse
|
||||||
{
|
{
|
||||||
public int Unresolved { get; set; }
|
/// <summary>未处理告警总数</summary>
|
||||||
public int CollectFail { get; set; }
|
public int UnresolvedCount { get; set; }
|
||||||
public int DeviceOffline { get; set; }
|
|
||||||
public int ProductionAnomaly { get; set; }
|
/// <summary>按告警类型统计的未处理数量</summary>
|
||||||
public int UnknownDevice { get; set; }
|
public Dictionary<string, int> UnresolvedByType { get; set; } = new Dictionary<string, int>();
|
||||||
public int ServiceError { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace CncModels.Dto.Dashboard
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 最新告警条目
|
||||||
|
/// </summary>
|
||||||
|
public class AlertListItem
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
|
public string Severity { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,19 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace CncModels.Dto.Production
|
namespace CncModels.Dto.Production
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日产量列表项
|
/// cnc_daily_production 日汇总表列表项
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DailyProductionListItem
|
public class DailyProductionListItem
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Date { get; set; }
|
public int MachineId { get; set; }
|
||||||
public string MachineName { get; set; }
|
public string MachineName { get; set; }
|
||||||
|
public DateTime ProductionDate { get; set; }
|
||||||
public string ProgramName { get; set; }
|
public string ProgramName { get; set; }
|
||||||
public int Quantity { get; set; }
|
public decimal TotalQuantity { get; set; }
|
||||||
public string RunTime { get; set; }
|
public int SegmentCount { get; set; }
|
||||||
public string CuttingTime { get; set; }
|
public decimal? TotalRunTime { get; set; }
|
||||||
public string DataStatus { get; set; }
|
public decimal? TotalCuttingTime { get; set; }
|
||||||
public int IsAdjusted { get; set; }
|
public decimal? TotalCycleTime { get; set; }
|
||||||
public int? AdjustedQuantity { get; set; }
|
public int? WorkerId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,111 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
using System.Data;
|
||||||
|
using CncModels.Dto;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 车间仓储实现
|
||||||
|
/// </summary>
|
||||||
|
public class WorkshopRepository : BusinessRepository, IWorkshopRepository
|
||||||
|
{
|
||||||
|
public WorkshopRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public Workshop GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, SortOrder as SortOrder, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_workshop WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<Workshop>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Workshop> GetAll()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, SortOrder as SortOrder, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_workshop ORDER BY SortOrder ASC";
|
||||||
|
return conn.Query<Workshop>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedResult<Workshop> GetList(string keyword)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var where = string.Empty;
|
||||||
|
var param = new DynamicParameters();
|
||||||
|
if (!string.IsNullOrWhiteSpace(keyword))
|
||||||
|
{
|
||||||
|
where = " WHERE Name LIKE @Keyword";
|
||||||
|
param.Add("Keyword", $"%{keyword}%");
|
||||||
|
}
|
||||||
|
var limit = 20;
|
||||||
|
var sql = $@"SELECT Id as Id, Name as Name, SortOrder as SortOrder, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt
|
||||||
|
FROM cnc_workshop {where} ORDER BY SortOrder ASC LIMIT {limit} OFFSET 0";
|
||||||
|
var totalSql = $@"SELECT COUNT(*) FROM cnc_workshop {where}";
|
||||||
|
var items = conn.Query<Workshop>(sql, param).ToList();
|
||||||
|
var total = conn.ExecuteScalar<int>(totalSql, param);
|
||||||
|
return new PagedResult<Workshop>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Total = total,
|
||||||
|
Page = 1,
|
||||||
|
PageSize = limit
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(Workshop entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_workshop (Name, SortOrder, IsEnabled, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@Name, @SortOrder, @IsEnabled, @CreatedAt, @UpdatedAt);
|
||||||
|
SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(Workshop entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_workshop SET Name = @Name, SortOrder = @SortOrder, IsEnabled = @IsEnabled, UpdatedAt = @UpdatedAt WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, entity) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_workshop WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ToggleEnabled(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_workshop SET IsEnabled = CASE WHEN IsEnabled = 1 THEN 0 ELSE 1 END, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetMachineCount(int workshopId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT COUNT(*) FROM cnc_machine WHERE WorkshopId = @WorkshopId";
|
||||||
|
return conn.ExecuteScalar<int>(sql, new { WorkshopId = workshopId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌字段映射实现
|
||||||
|
/// </summary>
|
||||||
|
public class BrandFieldMappingRepository : BusinessRepository, IBrandFieldMappingRepository
|
||||||
|
{
|
||||||
|
public BrandFieldMappingRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public List<BrandFieldMapping> GetByBrandId(int brandId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, BrandId as BrandId, StandardField as StandardField, FieldName as FieldName, MatchBy as MatchBy, DataType as DataType, IsRequired as IsRequired, CreatedAt as CreatedAt
|
||||||
|
FROM cnc_brand_field_mapping WHERE BrandId = @BrandId ORDER BY Id";
|
||||||
|
return conn.Query<BrandFieldMapping>(sql, new { BrandId = brandId }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BrandFieldMapping GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, BrandId as BrandId, StandardField as StandardField, FieldName as FieldName, MatchBy as MatchBy, DataType as DataType, IsRequired as IsRequired, CreatedAt as CreatedAt
|
||||||
|
FROM cnc_brand_field_mapping WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<BrandFieldMapping>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(BrandFieldMapping entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_brand_field_mapping (BrandId, StandardField, FieldName, MatchBy, DataType, IsRequired, CreatedAt)
|
||||||
|
VALUES (@BrandId, @StandardField, @FieldName, @MatchBy, @DataType, @IsRequired, @CreatedAt);
|
||||||
|
SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(BrandFieldMapping entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_brand_field_mapping SET BrandId = @BrandId, StandardField = @StandardField, FieldName = @FieldName, MatchBy = @MatchBy, DataType = @DataType, IsRequired = @IsRequired, CreatedAt = @CreatedAt WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, entity) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteByBrandId(int brandId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_brand_field_mapping WHERE BrandId = @BrandId";
|
||||||
|
return conn.Execute(sql, new { BrandId = brandId }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int BatchCreate(int brandId, List<BrandFieldMapping> mappings)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
using (var tran = conn.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
var sql = @"INSERT INTO cnc_brand_field_mapping (BrandId, StandardField, FieldName, MatchBy, DataType, IsRequired, CreatedAt)
|
||||||
|
VALUES (@BrandId, @StandardField, @FieldName, @MatchBy, @DataType, @IsRequired, @CreatedAt);
|
||||||
|
SELECT LAST_INSERT_ID();";
|
||||||
|
foreach (var m in mappings)
|
||||||
|
{
|
||||||
|
m.BrandId = brandId;
|
||||||
|
var id = conn.QuerySingle<int>(sql, m, tran);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
tran.Commit();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
tran.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌实现
|
||||||
|
/// </summary>
|
||||||
|
public class BrandRepository : BusinessRepository, IBrandRepository
|
||||||
|
{
|
||||||
|
public BrandRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public Brand GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, BrandName as BrandName, DeviceField as DeviceField, TagsPath as TagsPath, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt
|
||||||
|
FROM cnc_brand WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<Brand>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Brand> GetAll()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, BrandName as BrandName, DeviceField as DeviceField, TagsPath as TagsPath, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_brand ORDER BY Id";
|
||||||
|
return conn.Query<Brand>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(Brand entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_brand (BrandName, DeviceField, TagsPath, IsEnabled, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@BrandName, @DeviceField, @TagsPath, @IsEnabled, @CreatedAt, @UpdatedAt);
|
||||||
|
SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(Brand entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_brand SET BrandName = @BrandName, DeviceField = @DeviceField, TagsPath = @TagsPath, IsEnabled = @IsEnabled, UpdatedAt = @UpdatedAt WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, entity) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_brand WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ToggleEnabled(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_brand SET IsEnabled = CASE WHEN IsEnabled = 1 THEN 0 ELSE 1 END, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetFieldMappingCount(int brandId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT COUNT(*) FROM cnc_brand_field_mapping WHERE BrandId = @BrandId";
|
||||||
|
return conn.ExecuteScalar<int>(sql, new { BrandId = brandId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetCollectAddressCount(int brandId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT COUNT(*) FROM cnc_collect_address WHERE BrandId = @BrandId";
|
||||||
|
return conn.ExecuteScalar<int>(sql, new { BrandId = brandId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.CollectAddress;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 采集地址实现
|
||||||
|
/// </summary>
|
||||||
|
public class CollectAddressRepository : BusinessRepository, ICollectAddressRepository
|
||||||
|
{
|
||||||
|
public CollectAddressRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public CollectAddress GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, Url as Url, BrandId as BrandId, CollectInterval as CollectInterval, IsEnabled as IsEnabled, LastCollectTime as LastCollectTime, LastCollectStatus as LastCollectStatus, FailCount as FailCount, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_collect_address WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<CollectAddress>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedResult<CollectAddressListItem> GetList(CollectAddressQuery query)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var where = " WHERE 1=1";
|
||||||
|
var parameters = new DynamicParameters();
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.Keyword))
|
||||||
|
{
|
||||||
|
where += " AND (ca.Name LIKE @Keyword OR ca.Url LIKE @Keyword)";
|
||||||
|
parameters.Add("Keyword", $"%{query.Keyword}%");
|
||||||
|
}
|
||||||
|
if (query.BrandId.HasValue)
|
||||||
|
{
|
||||||
|
where += " AND ca.BrandId = @BrandId";
|
||||||
|
parameters.Add("BrandId", query.BrandId.Value);
|
||||||
|
}
|
||||||
|
if (query.IsEnabled.HasValue)
|
||||||
|
{
|
||||||
|
where += " AND ca.IsEnabled = @IsEnabled";
|
||||||
|
parameters.Add("IsEnabled", query.IsEnabled.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var limit = query.PageSize;
|
||||||
|
var offset = query.Offset;
|
||||||
|
var sql = @"SELECT ca.Id as Id, ca.Name as Name, ca.Url as Url, ca.BrandId as BrandId, b.BrandName as BrandName, ca.CollectInterval as CollectInterval, ca.IsEnabled as IsEnabled, ca.LastCollectTime as LastCollectTime,
|
||||||
|
(SELECT COUNT(*) FROM cnc_machine m WHERE m.CollectAddressId = ca.Id) as MachineCount
|
||||||
|
FROM cnc_collect_address ca LEFT JOIN cnc_brand b ON ca.BrandId = b.Id" + where + @" ORDER BY ca.Id DESC LIMIT @Limit OFFSET @Offset";
|
||||||
|
parameters.Add("Limit", limit);
|
||||||
|
parameters.Add("Offset", offset);
|
||||||
|
|
||||||
|
var totalSql = @"SELECT COUNT(*) FROM cnc_collect_address ca LEFT JOIN cnc_brand b ON ca.BrandId = b.Id" + where;
|
||||||
|
var total = conn.ExecuteScalar<int>(totalSql, parameters);
|
||||||
|
var items = conn.Query<CollectAddressListItem>(sql, parameters).ToList();
|
||||||
|
|
||||||
|
return new PagedResult<CollectAddressListItem>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Total = total,
|
||||||
|
Page = query.Page,
|
||||||
|
PageSize = limit
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(CollectAddress entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_collect_address (Name, Url, BrandId, CollectInterval, IsEnabled, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@Name, @Url, @BrandId, @CollectInterval, @IsEnabled, @CreatedAt, @UpdatedAt);
|
||||||
|
SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(CollectAddress entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_collect_address SET Name = @Name, Url = @Url, BrandId = @BrandId, CollectInterval = @CollectInterval, IsEnabled = @IsEnabled, UpdatedAt = @UpdatedAt WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, entity) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_collect_address WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ToggleEnabled(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_collect_address SET IsEnabled = CASE WHEN IsEnabled = 1 THEN 0 ELSE 1 END, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CollectAddress> GetEnabledList()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, Url as Url, BrandId as BrandId, CollectInterval as CollectInterval, IsEnabled as IsEnabled, LastCollectTime as LastCollectTime, LastCollectStatus as LastCollectStatus, FailCount as FailCount, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_collect_address WHERE IsEnabled = 1";
|
||||||
|
return conn.Query<CollectAddress>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetMachineCount(int collectAddressId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT COUNT(*) FROM cnc_machine WHERE CollectAddressId = @CollectAddressId";
|
||||||
|
return conn.ExecuteScalar<int>(sql, new { CollectAddressId = collectAddressId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,134 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto.Production;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Production;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_daily_production 产量仓储实现(业务库)
|
||||||
|
/// </summary>
|
||||||
|
public class DailyProductionRepository : BusinessRepository, IDailyProductionRepository
|
||||||
|
{
|
||||||
|
public DailyProductionRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public DailyProduction GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_daily_production WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<DailyProduction>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedResult<DailyProductionListItem> GetList(ProductionQuery query)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string baseSql = @"SELECT dp.Id, dp.MachineId, m.Name AS MachineName, dp.ProductionDate, dp.ProgramName, dp.TotalQuantity, dp.SegmentCount, dp.TotalRunTime, dp.TotalCuttingTime, dp.TotalCycleTime, dp.WorkerId AS WorkerId
|
||||||
|
FROM cnc_daily_production dp
|
||||||
|
LEFT JOIN cnc_machine m ON dp.MachineId = m.Id
|
||||||
|
WHERE 1=1";
|
||||||
|
string countSql = @"SELECT COUNT(*) FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.MachineId = m.Id WHERE 1=1";
|
||||||
|
|
||||||
|
var parameters = new DynamicParameters();
|
||||||
|
if (query?.Date.HasValue == true)
|
||||||
|
{
|
||||||
|
baseSql += " AND dp.ProductionDate = @Date";
|
||||||
|
countSql += " AND dp.ProductionDate = @Date";
|
||||||
|
parameters.Add("Date", query.Date);
|
||||||
|
}
|
||||||
|
int offset = (query.Page - 1) * query.PageSize;
|
||||||
|
string paging = " ORDER BY dp.ProductionDate DESC LIMIT @Limit OFFSET @Offset";
|
||||||
|
parameters.Add("Limit", query.PageSize);
|
||||||
|
parameters.Add("Offset", offset);
|
||||||
|
|
||||||
|
var items = conn.Query<DailyProductionListItem>(baseSql + paging, parameters).ToList();
|
||||||
|
int total = conn.ExecuteScalar<int>(countSql, parameters);
|
||||||
|
return new PagedResult<DailyProductionListItem>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Total = total,
|
||||||
|
Page = query.Page,
|
||||||
|
PageSize = query.PageSize
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DailyProduction> GetByMachineAndDate(int machineId, DateTime date)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_daily_production WHERE MachineId = @MachineId AND ProductionDate = @Date";
|
||||||
|
return conn.Query<DailyProduction>(sql, new { MachineId = machineId, Date = date }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DailyProduction> GetByDateRange(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"SELECT dp.* FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.MachineId = m.Id WHERE dp.ProductionDate BETWEEN @Start AND @End ORDER BY dp.ProductionDate DESC";
|
||||||
|
return conn.Query<DailyProduction>(sql, new { Start = startDate, End = endDate }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public decimal GetTotalByDateRange(DateTime startDate, DateTime endDate, int? workshopId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"SELECT SUM(dp.TotalQuantity) FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.MachineId = m.Id WHERE dp.ProductionDate BETWEEN @Start AND @End";
|
||||||
|
if (workshopId.HasValue)
|
||||||
|
{
|
||||||
|
sql += " AND m.WorkshopId = @WorkshopId";
|
||||||
|
return conn.ExecuteScalar<decimal>(sql, new { Start = startDate, End = endDate, WorkshopId = workshopId.Value });
|
||||||
|
}
|
||||||
|
return conn.ExecuteScalar<decimal>(sql, new { Start = startDate, End = endDate });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public decimal GetTotalByWorkerAndDateRange(int workerId, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"SELECT SUM(TotalQuantity) FROM cnc_daily_production WHERE WorkerId = @WorkerId AND ProductionDate BETWEEN @Start AND @End";
|
||||||
|
var res = conn.ExecuteScalar<decimal?>(sql, new { WorkerId = workerId, Start = startDate, End = endDate });
|
||||||
|
return res ?? 0m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DailyProduction> GetMachineRankByDateRange(DateTime startDate, DateTime endDate, int top)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"SELECT m.Id AS Id, m.Id AS MachineId, m.Name AS MachineName, SUM(dp.TotalQuantity) AS TotalQuantity, NULL AS ProgramName, NULL AS ProductionDate, NULL AS SegmentCount, NULL AS TotalRunTime, NULL AS TotalCuttingTime, NULL AS TotalCycleTime
|
||||||
|
FROM cnc_daily_production dp
|
||||||
|
JOIN cnc_machine m ON dp.MachineId = m.Id
|
||||||
|
WHERE dp.ProductionDate BETWEEN @Start AND @End
|
||||||
|
GROUP BY m.Id, m.Name
|
||||||
|
ORDER BY SUM(dp.TotalQuantity) DESC LIMIT @Top";
|
||||||
|
return conn.Query<DailyProduction>(sql, new { Start = startDate, End = endDate, Top = top }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DailyProduction> GetWorkerRankByDateRange(DateTime startDate, DateTime endDate, int top)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"SELECT 0 AS Id, NULL AS MachineId, NULL AS MachineName, SUM(TotalQuantity) AS TotalQuantity, WorkerId AS WorkerId, NULL AS ProductionDate, NULL AS ProgramName, NULL AS SegmentCount, NULL AS TotalRunTime, NULL AS TotalCuttingTime, NULL AS TotalCycleTime
|
||||||
|
FROM cnc_daily_production
|
||||||
|
WHERE ProductionDate BETWEEN @Start AND @End AND WorkerId IS NOT NULL
|
||||||
|
GROUP BY WorkerId
|
||||||
|
ORDER BY SUM(TotalQuantity) DESC LIMIT @Top";
|
||||||
|
return conn.Query<DailyProduction>(sql, new { Start = startDate, End = endDate, Top = top }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class MachineDailyStatusRepository : BusinessRepository, IMachineDailyStatusRepository
|
||||||
|
{
|
||||||
|
public MachineDailyStatusRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public MachineDailyStatus GetByMachineAndDate(int machineId, DateTime date)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_machine_daily_status WHERE MachineId = @MachineId AND ProductionDate = @Date";
|
||||||
|
return conn.QuerySingleOrDefault<MachineDailyStatus>(sql, new { MachineId = machineId, Date = date });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Upsert(MachineDailyStatus entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO cnc_machine_daily_status (MachineId, ProductionDate, DataStatus, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@MachineId, @ProductionDate, @DataStatus, @CreatedAt, @UpdatedAt)
|
||||||
|
ON DUPLICATE KEY UPDATE DataStatus = @DataStatus, UpdatedAt = @UpdatedAt";
|
||||||
|
return conn.Execute(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MachineDailyStatus> GetByDate(DateTime date)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_machine_daily_status WHERE ProductionDate = @Date";
|
||||||
|
return conn.Query<MachineDailyStatus>(sql, new { Date = date }).AsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CountByDateAndStatus(DateTime date, string dataStatus)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT COUNT(*) FROM cnc_machine_daily_status WHERE ProductionDate = @Date AND DataStatus = @Status";
|
||||||
|
return conn.ExecuteScalar<int>(sql, new { Date = date, Status = dataStatus });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,167 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Machine;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 机床实现
|
||||||
|
/// </summary>
|
||||||
|
public class MachineRepository : BusinessRepository, IMachineRepository
|
||||||
|
{
|
||||||
|
public MachineRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public Machine GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, DeviceCode as DeviceCode, Name as Name, WorkshopId as WorkshopId, CollectAddressId as CollectAddressId, IpAddress as IpAddress, BrandId as BrandId, IsEnabled as IsEnabled, IsOnline as IsOnline, LastPingTime as LastPingTime, LastCollectTime as LastCollectTime, LastDeviceStatus as LastDeviceStatus, LastRunStatus as LastRunStatus, LastProgramName as LastProgramName, LastPartCount as LastPartCount, LastOperateMode as LastOperateMode, LastMachiningStatus as LastMachiningStatus, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_machine WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<Machine>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedResult<MachineListItem> GetList(MachineQuery query)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var where = " WHERE 1=1";
|
||||||
|
var p = new DynamicParameters();
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.Keyword))
|
||||||
|
{
|
||||||
|
where += " AND (m.Name LIKE @Keyword OR m.DeviceCode LIKE @Keyword)";
|
||||||
|
p.Add("Keyword", $"%{query.Keyword}%");
|
||||||
|
}
|
||||||
|
if (query.WorkshopId.HasValue)
|
||||||
|
{
|
||||||
|
where += " AND m.WorkshopId = @WorkshopId";
|
||||||
|
p.Add("WorkshopId", query.WorkshopId.Value);
|
||||||
|
}
|
||||||
|
if (query.IsOnline.HasValue)
|
||||||
|
{
|
||||||
|
where += " AND m.IsOnline = @IsOnline";
|
||||||
|
p.Add("IsOnline", query.IsOnline.Value);
|
||||||
|
}
|
||||||
|
if (query.BrandId.HasValue)
|
||||||
|
{
|
||||||
|
where += " AND m.BrandId = @BrandId";
|
||||||
|
p.Add("BrandId", query.BrandId.Value);
|
||||||
|
}
|
||||||
|
var limit = query.PageSize;
|
||||||
|
var offset = query.Offset;
|
||||||
|
var sql = @"SELECT m.Id as Id, m.DeviceCode as DeviceCode, m.Name as Name, m.WorkshopId as WorkshopId, ws.Name as WorkshopName, m.CollectAddressId as CollectAddressId, m.BrandId as BrandId, b.BrandName as BrandName, m.IpAddress as IpAddress, m.IsEnabled as IsEnabled, m.IsOnline as IsOnline, m.LastProgramName as LastProgramName, m.LastCollectTime as LastCollectTime, w.Id as WorkerId, w.Name as WorkerName
|
||||||
|
FROM cnc_machine m
|
||||||
|
LEFT JOIN cnc_workshop ws ON m.WorkshopId = ws.Id
|
||||||
|
LEFT JOIN cnc_brand b ON m.BrandId = b.Id
|
||||||
|
LEFT JOIN cnc_worker_machine wm ON m.Id = wm.MachineId
|
||||||
|
LEFT JOIN cnc_worker w ON wm.WorkerId = w.Id" + where + @" ORDER BY m.Id DESC LIMIT @Limit OFFSET @Offset";
|
||||||
|
p.Add("Limit", limit);
|
||||||
|
p.Add("Offset", offset);
|
||||||
|
var totalSql = @"SELECT COUNT(*) FROM cnc_machine m" + where + @"";
|
||||||
|
var total = conn.ExecuteScalar<int>(totalSql, p);
|
||||||
|
var items = conn.Query<MachineListItem>(sql, p).ToList();
|
||||||
|
return new PagedResult<MachineListItem>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Total = total,
|
||||||
|
Page = query.Page,
|
||||||
|
PageSize = limit
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(Machine entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_machine (DeviceCode, Name, WorkshopId, CollectAddressId, IpAddress, BrandId, IsEnabled, IsOnline, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@DeviceCode, @Name, @WorkshopId, @CollectAddressId, @IpAddress, @BrandId, @IsEnabled, @IsOnline, @CreatedAt, @UpdatedAt);
|
||||||
|
SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(Machine entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_machine SET DeviceCode = @DeviceCode, Name = @Name, WorkshopId = @WorkshopId, CollectAddressId = @CollectAddressId, IpAddress = @IpAddress, BrandId = @BrandId, IsEnabled = @IsEnabled, IsOnline = @IsOnline, UpdatedAt = @UpdatedAt, LastProgramName = @LastProgramName, LastCollectTime = @LastCollectTime, LastDeviceStatus = @LastDeviceStatus, LastRunStatus = @LastRunStatus, LastMachiningStatus = @LastMachiningStatus WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, entity) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_machine WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ToggleEnabled(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_machine SET IsEnabled = CASE WHEN IsEnabled = 1 THEN 0 ELSE 1 END, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Machine GetByDeviceCode(string deviceCode)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, DeviceCode as DeviceCode, Name as Name, WorkshopId as WorkshopId, CollectAddressId as CollectAddressId, IpAddress as IpAddress, BrandId as BrandId, IsEnabled as IsEnabled, IsOnline as IsOnline, LastPingTime as LastPingTime, LastCollectTime as LastCollectTime, LastDeviceStatus as LastDeviceStatus, LastRunStatus as LastRunStatus, LastProgramName as LastProgramName, LastPartCount as LastPartCount, LastOperateMode as LastOperateMode, LastMachiningStatus as LastMachiningStatus, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_machine WHERE DeviceCode = @DeviceCode";
|
||||||
|
return conn.QuerySingleOrDefault<Machine>(sql, new { DeviceCode = deviceCode });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Machine> GetEnabledByAddressId(int collectAddressId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, DeviceCode as DeviceCode, Name as Name, WorkshopId as WorkshopId, CollectAddressId as CollectAddressId, IpAddress as IpAddress, BrandId as BrandId, IsEnabled as IsEnabled, IsOnline as IsOnline, LastPingTime as LastPingTime, LastCollectTime as LastCollectTime, LastDeviceStatus as LastDeviceStatus, LastRunStatus as LastRunStatus, LastProgramName as LastProgramName, LastPartCount as LastPartCount, LastOperateMode as LastOperateMode, LastMachiningStatus as LastMachiningStatus, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_machine WHERE CollectAddressId = @CollectAddressId AND IsEnabled = 1";
|
||||||
|
return conn.Query<Machine>(sql, new { CollectAddressId = collectAddressId }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Machine> GetEnabledOnline()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, DeviceCode as DeviceCode, Name as Name, WorkshopId as WorkshopId, CollectAddressId as CollectAddressId, IpAddress as IpAddress, BrandId as BrandId, IsEnabled as IsEnabled, IsOnline as IsOnline, LastPingTime as LastPingTime, LastCollectTime as LastCollectTime, LastDeviceStatus as LastDeviceStatus, LastRunStatus as LastRunStatus, LastProgramName as LastProgramName, LastPartCount as LastPartCount, LastOperateMode as LastOperateMode, LastMachiningStatus as LastMachiningStatus, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_machine WHERE IsEnabled = 1 AND IsOnline = 1";
|
||||||
|
return conn.Query<Machine>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateOnlineStatus(int id, bool isOnline)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_machine SET IsOnline = @IsOnline, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
conn.Execute(sql, new { Id = id, IsOnline = isOnline ? 1 : 0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLastCollect(int id, Machine entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_machine SET LastCollectTime = @LastCollectTime, LastProgramName = @LastProgramName, LastMachiningStatus = @LastMachiningStatus, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
var param = new
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
LastCollectTime = entity.LastCollectTime,
|
||||||
|
LastProgramName = entity.LastProgramName,
|
||||||
|
LastMachiningStatus = entity.LastMachiningStatus
|
||||||
|
};
|
||||||
|
conn.Execute(sql, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Dapper;
|
||||||
|
using System.Linq;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class ProductionAdjustmentRepository : BusinessRepository, IProductionAdjustmentRepository
|
||||||
|
{
|
||||||
|
public ProductionAdjustmentRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public int Create(ProductionAdjustment entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO cnc_production_adjustment (TargetTable, TargetId, FieldName, OldValue, NewValue, Reason, OperatorIp, CreatedAt)
|
||||||
|
VALUES (@TargetTable, @TargetId, @FieldName, @OldValue, @NewValue, @Reason, @OperatorIp, @CreatedAt);";
|
||||||
|
return conn.Execute(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedResult<ProductionAdjustment> GetList(string targetTable, DateTime? startDate, DateTime? endDate, string keyword, int page, int pageSize)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sqlBase = "SELECT * FROM cnc_production_adjustment WHERE 1=1";
|
||||||
|
if (!string.IsNullOrEmpty(targetTable)) sqlBase += " AND TargetTable = @TargetTable";
|
||||||
|
if (startDate.HasValue) sqlBase += " AND CreatedAt >= @StartDate";
|
||||||
|
if (endDate.HasValue) sqlBase += " AND CreatedAt <= @EndDate";
|
||||||
|
if (!string.IsNullOrEmpty(keyword)) sqlBase += " AND (CAST(TargetId AS CHAR) LIKE @Keyword OR FieldName LIKE @Keyword)";
|
||||||
|
int offset = (page - 1) * pageSize;
|
||||||
|
string sqlCount = "SELECT COUNT(*) FROM cnc_production_adjustment WHERE 1=1" +
|
||||||
|
(string.IsNullOrEmpty(targetTable) ? string.Empty : " AND TargetTable = @TargetTable") +
|
||||||
|
(startDate.HasValue ? " AND CreatedAt >= @StartDate" : "") +
|
||||||
|
(endDate.HasValue ? " AND CreatedAt <= @EndDate" : "") +
|
||||||
|
(!string.IsNullOrEmpty(keyword) ? " AND (CAST(TargetId AS CHAR) LIKE @Keyword OR FieldName LIKE @Keyword)" : "");
|
||||||
|
string sqlPage = sqlBase + " ORDER BY CreatedAt DESC LIMIT @Limit OFFSET @Offset";
|
||||||
|
var param = new { TargetTable = targetTable, StartDate = startDate, EndDate = endDate, Keyword = ("%" + keyword + "%"), Limit = pageSize, Offset = offset };
|
||||||
|
var items = conn.Query<ProductionAdjustment>(sqlPage, param).AsList();
|
||||||
|
int total = conn.ExecuteScalar<int>(sqlCount, param);
|
||||||
|
return new PagedResult<ProductionAdjustment> { Items = items, Total = total, Page = page, PageSize = pageSize };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class ProductionSegmentRepository : BusinessRepository, IProductionSegmentRepository
|
||||||
|
{
|
||||||
|
public ProductionSegmentRepository(string connectionString) : base(connectionString) { }
|
||||||
|
public ProductionSegment GetById(long id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_production_segment WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<ProductionSegment>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ProductionSegment GetActiveSegment(int machineId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_production_segment WHERE MachineId = @MachineId AND IsSettled = 0 AND EndTime IS NULL ORDER BY StartTime DESC LIMIT 1";
|
||||||
|
return conn.QuerySingleOrDefault<ProductionSegment>(sql, new { MachineId = machineId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<ProductionSegment> GetByMachineAndDate(int machineId, DateTime date)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_production_segment WHERE MachineId = @MachineId AND DATE(StartTime) = DATE(@Date)";
|
||||||
|
return conn.Query<ProductionSegment>(sql, new { MachineId = machineId, Date = date }).AsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Create(ProductionSegment entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO cnc_production_segment (MachineId, ProgramName, ProductionDate, StartTime, StartPartCount, EndPartCount, Quantity, IsSettled, CloseReason, EndTime, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@MachineId, @ProgramName, @ProductionDate, @StartTime, @StartPartCount, @EndPartCount, @Quantity, @IsSettled, @CloseReason, @EndTime, @CreatedAt, @UpdatedAt); SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.ExecuteScalar<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool CloseSegment(long id, decimal? endPartCount, decimal? quantity, string closeReason, DateTime endTime)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"UPDATE cnc_production_segment
|
||||||
|
SET EndPartCount = @EndPartCount, Quantity = @Quantity, CloseReason = @CloseReason, EndTime = @EndTime
|
||||||
|
WHERE Id = @Id";
|
||||||
|
int affected = conn.Execute(sql, new { Id = id, EndPartCount = endPartCount, Quantity = quantity, CloseReason = closeReason, EndTime = endTime });
|
||||||
|
return affected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool SettleByDate(DateTime date)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"UPDATE cnc_production_segment SET IsSettled = 1, CloseReason = 'end_of_day' WHERE DATE(StartTime) = DATE(@Date) AND IsSettled = 0";
|
||||||
|
int affected = conn.Execute(sql, new { Date = date });
|
||||||
|
return affected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class ScreenConfigRepository : BusinessRepository, IScreenConfigRepository
|
||||||
|
{
|
||||||
|
public ScreenConfigRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public List<ScreenConfig> GetAll()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
return conn.Query<ScreenConfig>("SELECT * FROM cnc_screen_config").AsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ScreenConfig> GetEnabled()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_screen_config WHERE IsEnabled = 1 ORDER BY SortOrder ASC";
|
||||||
|
return conn.Query<ScreenConfig>(sql).AsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScreenConfig GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_screen_config WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<ScreenConfig>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(ScreenConfig entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO cnc_screen_config (CardKey, CardType, Title, Metric, Dimension, SortOrder, IsEnabled, ChartConfig, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@CardKey, @CardType, @Title, @Metric, @Dimension, @SortOrder, @IsEnabled, @ChartConfig, @CreatedAt, @UpdatedAt); SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.ExecuteScalar<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ScreenConfig entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"UPDATE cnc_screen_config SET CardKey = @CardKey, CardType = @CardType, Title = @Title, Metric = @Metric, Dimension = @Dimension, SortOrder = @SortOrder, IsEnabled = @IsEnabled, ChartConfig = @ChartConfig, UpdatedAt = @UpdatedAt WHERE Id = @Id";
|
||||||
|
int affected = conn.Execute(sql, entity);
|
||||||
|
return affected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "DELETE FROM cnc_screen_config WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ToggleEnabled(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "UPDATE cnc_screen_config SET IsEnabled = CASE WHEN IsEnabled = 1 THEN 0 ELSE 1 END, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
int affected = conn.Execute(sql, new { Id = id });
|
||||||
|
return affected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class ScreenFilterRepository : BusinessRepository, IScreenFilterRepository
|
||||||
|
{
|
||||||
|
public ScreenFilterRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public List<ScreenFilter> GetByScreenKey(string screenKey)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_screen_filter WHERE ScreenKey = @ScreenKey ORDER BY SortOrder ASC";
|
||||||
|
return conn.Query<ScreenFilter>(sql, new { ScreenKey = screenKey }).AsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(ScreenFilter entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO cnc_screen_filter (ScreenKey, FilterType, FilterValue, IsDefault, SortOrder) VALUES (@ScreenKey, @FilterType, @FilterValue, @IsDefault, @SortOrder); SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.ExecuteScalar<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ScreenFilter entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"UPDATE cnc_screen_filter SET ScreenKey = @ScreenKey, FilterType = @FilterType, FilterValue = @FilterValue, IsDefault = @IsDefault, SortOrder = @SortOrder WHERE Id = @Id";
|
||||||
|
int affected = conn.Execute(sql, entity);
|
||||||
|
return affected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "DELETE FROM cnc_screen_filter WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 系统配置实现
|
||||||
|
/// </summary>
|
||||||
|
public class SysConfigRepository : BusinessRepository, ISysConfigRepository
|
||||||
|
{
|
||||||
|
public SysConfigRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public SysConfig GetByKey(string configKey)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, ConfigKey as ConfigKey, ConfigValue as ConfigValue, ValueType as ValueType, Description as Description, UpdatedAt as UpdatedAt
|
||||||
|
FROM cnc_sys_config WHERE ConfigKey = @ConfigKey LIMIT 1";
|
||||||
|
return conn.QuerySingleOrDefault<SysConfig>(sql, new { ConfigKey = configKey });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public List<SysConfig> GetAll()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, ConfigKey as ConfigKey, ConfigValue as ConfigValue, ValueType as ValueType, Description as Description, UpdatedAt as UpdatedAt FROM cnc_sys_config ORDER BY Id";
|
||||||
|
return conn.Query<SysConfig>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool UpdateValue(int id, string configValue)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_sys_config SET ConfigValue = @ConfigValue, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
var affected = conn.Execute(sql, new { Id = id, ConfigValue = configValue });
|
||||||
|
return affected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Log;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class SystemLogRepository : LogRepository, ISystemLogRepository
|
||||||
|
{
|
||||||
|
public SystemLogRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public PagedResult<SystemLogListItem> GetList(SystemLogQuery query)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"SELECT Id, CreatedAt, LogLevel, Source, Message, StackTrace, ExtraData
|
||||||
|
FROM log_system
|
||||||
|
WHERE 1=1";
|
||||||
|
string countSql = @"SELECT COUNT(*) FROM log_system WHERE 1=1";
|
||||||
|
if (!string.IsNullOrEmpty(query.LogLevel)) { sql += " AND LogLevel = @LogLevel"; countSql += " AND LogLevel = @LogLevel"; }
|
||||||
|
if (!string.IsNullOrEmpty(query.Source)) { sql += " AND Source = @Source"; countSql += " AND Source = @Source"; }
|
||||||
|
if (!string.IsNullOrEmpty(query.StartDate)) { sql += " AND CreatedAt >= @Start"; countSql += " AND CreatedAt >= @Start"; }
|
||||||
|
if (!string.IsNullOrEmpty(query.EndDate)) { sql += " AND CreatedAt <= @End"; countSql += " AND CreatedAt <= @End"; }
|
||||||
|
if (!string.IsNullOrEmpty(query.Keyword)) { sql += " AND Message LIKE @Keyword"; countSql += " AND Message LIKE @Keyword"; }
|
||||||
|
var p = new { LogLevel = query.LogLevel, Source = query.Source, Start = query.StartDate, End = query.EndDate, Keyword = ("%" + query.Keyword + "%") };
|
||||||
|
int offset = (query.Page - 1) * query.PageSize;
|
||||||
|
sql += " ORDER BY CreatedAt DESC LIMIT @Limit OFFSET @Offset";
|
||||||
|
var list = conn.Query<SystemLogListItem>(sql, p).AsList();
|
||||||
|
int total = conn.ExecuteScalar<int>(countSql, p);
|
||||||
|
return new PagedResult<SystemLogListItem> { Items = list, Total = total, Page = query.Page, PageSize = query.PageSize };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(SystemLog entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO log_system (LogLevel, Source, Message, StackTrace, ExtraData, CreatedAt)
|
||||||
|
VALUES (@LogLevel, @Source, @Message, @StackTrace, @ExtraData, @CreatedAt);";
|
||||||
|
return conn.Execute(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
public class WorkerDailySummaryRepository : BusinessRepository, IWorkerDailySummaryRepository
|
||||||
|
{
|
||||||
|
public WorkerDailySummaryRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public WorkerDailySummary GetByWorkerAndDate(int workerId, DateTime date)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_worker_daily_summary WHERE WorkerId = @WorkerId AND ProductionDate = @Date";
|
||||||
|
return conn.QuerySingleOrDefault<WorkerDailySummary>(sql, new { WorkerId = workerId, Date = date });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkerDailySummary> GetByDateRange(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM cnc_worker_daily_summary WHERE ProductionDate BETWEEN @Start AND @End";
|
||||||
|
return conn.Query<WorkerDailySummary>(sql, new { Start = startDate, End = endDate }).AsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Upsert(WorkerDailySummary entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = @"INSERT INTO cnc_worker_daily_summary (WorkerId, ProductionDate, TotalQuantity, MachineCount, ProgramCount, IsAdjusted, AdjustedQuantity, CreatedAt, UpdatedAt)
|
||||||
|
VALUES (@WorkerId, @ProductionDate, @TotalQuantity, @MachineCount, @ProgramCount, @IsAdjusted, @AdjustedQuantity, @CreatedAt, @UpdatedAt)
|
||||||
|
ON DUPLICATE KEY UPDATE TotalQuantity = @TotalQuantity, MachineCount = @MachineCount, ProgramCount = @ProgramCount, UpdatedAt = @UpdatedAt";
|
||||||
|
return conn.Execute(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工人-机床绑定实现
|
||||||
|
/// </summary>
|
||||||
|
public class WorkerMachineRepository : BusinessRepository, IWorkerMachineRepository
|
||||||
|
{
|
||||||
|
public WorkerMachineRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public WorkerMachine GetByMachineId(int machineId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, WorkerId as WorkerId, MachineId as MachineId, CreatedAt as CreatedAt FROM cnc_worker_machine WHERE MachineId = @MachineId";
|
||||||
|
return conn.QuerySingleOrDefault<WorkerMachine>(sql, new { MachineId = machineId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkerMachine> GetByWorkerId(int workerId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, WorkerId as WorkerId, MachineId as MachineId, CreatedAt as CreatedAt FROM cnc_worker_machine WHERE WorkerId = @WorkerId";
|
||||||
|
return conn.Query<WorkerMachine>(sql, new { WorkerId = workerId }).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(int workerId, int machineId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_worker_machine (WorkerId, MachineId, CreatedAt) VALUES (@WorkerId, @MachineId, NOW()); SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, new { WorkerId = workerId, MachineId = machineId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteByMachineId(int machineId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_worker_machine WHERE MachineId = @MachineId";
|
||||||
|
return conn.Execute(sql, new { MachineId = machineId }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteByWorkerId(int workerId)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_worker_machine WHERE WorkerId = @WorkerId";
|
||||||
|
return conn.Execute(sql, new { WorkerId = workerId }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,119 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto.Worker;
|
||||||
|
using CncRepository.Base;
|
||||||
|
using CncRepository.Interface;
|
||||||
|
|
||||||
|
namespace CncRepository.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工人实现
|
||||||
|
/// </summary>
|
||||||
|
public class WorkerRepository : BusinessRepository, IWorkerRepository
|
||||||
|
{
|
||||||
|
public WorkerRepository(string connectionString) : base(connectionString) { }
|
||||||
|
|
||||||
|
public Worker GetById(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, Code as Code, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_worker WHERE Id = @Id";
|
||||||
|
return conn.QuerySingleOrDefault<Worker>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedResult<WorkerListItem> GetList(WorkerQuery query)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var where = " WHERE 1=1";
|
||||||
|
var p = new DynamicParameters();
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.Keyword))
|
||||||
|
{
|
||||||
|
where += " AND (w.Name LIKE @Keyword OR w.Code LIKE @Keyword)";
|
||||||
|
p.Add("Keyword", $"%{query.Keyword}%");
|
||||||
|
}
|
||||||
|
if (query.IsEnabled.HasValue)
|
||||||
|
{
|
||||||
|
where += " AND w.IsEnabled = @IsEnabled";
|
||||||
|
p.Add("IsEnabled", query.IsEnabled.Value);
|
||||||
|
}
|
||||||
|
var limit = query.PageSize;
|
||||||
|
var offset = query.Offset;
|
||||||
|
var sql = @"SELECT w.Id as Id, w.Code as Code, w.Name as Name, w.IsEnabled as IsEnabled,
|
||||||
|
(SELECT COUNT(*) FROM cnc_worker_machine wm WHERE wm.WorkerId = w.Id) as MachineCount,
|
||||||
|
(SELECT GROUP_CONCAT(m.Name SEPARATOR ', ') FROM cnc_worker_machine wm JOIN cnc_machine m ON wm.MachineId = m.Id WHERE wm.WorkerId = w.Id) as MachineNames
|
||||||
|
FROM cnc_worker w" + where + @" ORDER BY w.Id DESC LIMIT @Limit OFFSET @Offset";
|
||||||
|
p.Add("Limit", limit);
|
||||||
|
p.Add("Offset", offset);
|
||||||
|
var totalSql = @"SELECT COUNT(*) FROM cnc_worker w" + where;
|
||||||
|
var total = conn.ExecuteScalar<int>(totalSql, p);
|
||||||
|
var items = conn.Query<WorkerListItem>(sql, p).ToList();
|
||||||
|
return new PagedResult<WorkerListItem>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Total = total,
|
||||||
|
Page = query.Page,
|
||||||
|
PageSize = limit
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(Worker entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO cnc_worker (Name, Code, IsEnabled, CreatedAt, UpdatedAt) VALUES (@Name, @Code, @IsEnabled, @CreatedAt, @UpdatedAt); SELECT LAST_INSERT_ID();";
|
||||||
|
return conn.QuerySingle<int>(sql, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(Worker entity)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_worker SET Name = @Name, Code = @Code, IsEnabled = @IsEnabled, UpdatedAt = @UpdatedAt WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, entity) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"DELETE FROM cnc_worker WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ToggleEnabled(int id)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"UPDATE cnc_worker SET IsEnabled = CASE WHEN IsEnabled = 1 THEN 0 ELSE 1 END, UpdatedAt = NOW() WHERE Id = @Id";
|
||||||
|
return conn.Execute(sql, new { Id = id }) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Worker GetByCode(string code)
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, Code as Code, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_worker WHERE Code = @Code";
|
||||||
|
return conn.QuerySingleOrDefault<Worker>(sql, new { Code = code });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Worker> GetAll()
|
||||||
|
{
|
||||||
|
using (var conn = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = @"SELECT Id as Id, Name as Name, Code as Code, IsEnabled as IsEnabled, CreatedAt as CreatedAt, UpdatedAt as UpdatedAt FROM cnc_worker ORDER BY Id";
|
||||||
|
return conn.Query<Worker>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Alert;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_alert 告警表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IAlertRepository
|
||||||
|
{
|
||||||
|
Alert GetById(long id);
|
||||||
|
PagedResult<AlertListItem> GetList(AlertQuery query);
|
||||||
|
long Create(Alert entity);
|
||||||
|
bool Resolve(long id);
|
||||||
|
int BatchResolve(List<long> ids);
|
||||||
|
AlertStatisticsResponse GetStatistics();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌字段映射仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IBrandFieldMappingRepository
|
||||||
|
{
|
||||||
|
List<BrandFieldMapping> GetByBrandId(int brandId);
|
||||||
|
BrandFieldMapping GetById(int id);
|
||||||
|
int Create(BrandFieldMapping entity);
|
||||||
|
bool Update(BrandFieldMapping entity);
|
||||||
|
bool DeleteByBrandId(int brandId);
|
||||||
|
int BatchCreate(int brandId, List<BrandFieldMapping> mappings);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IBrandRepository
|
||||||
|
{
|
||||||
|
Brand GetById(int id);
|
||||||
|
List<Brand> GetAll();
|
||||||
|
int Create(Brand entity);
|
||||||
|
bool Update(Brand entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
bool ToggleEnabled(int id);
|
||||||
|
int GetFieldMappingCount(int brandId);
|
||||||
|
int GetCollectAddressCount(int brandId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto.CollectAddress;
|
||||||
|
using CncModels.Dto;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 采集地址仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface ICollectAddressRepository
|
||||||
|
{
|
||||||
|
CollectAddress GetById(int id);
|
||||||
|
PagedResult<CollectAddressListItem> GetList(CollectAddressQuery query);
|
||||||
|
int Create(CollectAddress entity);
|
||||||
|
bool Update(CollectAddress entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
bool ToggleEnabled(int id);
|
||||||
|
List<CollectAddress> GetEnabledList();
|
||||||
|
int GetMachineCount(int collectAddressId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 日志库:原始采集记录仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface ICollectRawRepository
|
||||||
|
{
|
||||||
|
CollectRaw GetById(long id);
|
||||||
|
|
||||||
|
PagedResult<CollectRaw> GetByAddressId(int collectAddressId, int page, int pageSize);
|
||||||
|
|
||||||
|
CollectRaw GetLatestByAddressId(int collectAddressId);
|
||||||
|
|
||||||
|
long Create(CollectRaw entity);
|
||||||
|
|
||||||
|
int DeleteBeforeDate(DateTime date);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 日志库:心跳仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface ICollectorHeartbeatRepository
|
||||||
|
{
|
||||||
|
long Create(CollectorHeartbeat entity);
|
||||||
|
|
||||||
|
CollectorHeartbeat GetLatest(string serviceId);
|
||||||
|
|
||||||
|
int DeleteBeforeDate(DateTime date);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Production;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_daily_production 产量仓储接口(业务库)
|
||||||
|
/// </summary>
|
||||||
|
public interface IDailyProductionRepository
|
||||||
|
{
|
||||||
|
DailyProduction GetById(int id);
|
||||||
|
PagedResult<DailyProductionListItem> GetList(ProductionQuery query);
|
||||||
|
List<DailyProduction> GetByMachineAndDate(int machineId, DateTime date);
|
||||||
|
List<DailyProduction> GetByDateRange(DateTime startDate, DateTime endDate);
|
||||||
|
decimal GetTotalByDateRange(DateTime startDate, DateTime endDate, int? workshopId);
|
||||||
|
decimal GetTotalByWorkerAndDateRange(int workerId, DateTime startDate, DateTime endDate);
|
||||||
|
List<DailyProduction> GetMachineRankByDateRange(DateTime startDate, DateTime endDate, int top);
|
||||||
|
List<DailyProduction> GetWorkerRankByDateRange(DateTime startDate, DateTime endDate, int top);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Dto.Dashboard;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 仪表盘统计查询仓储接口(跨表聚合)
|
||||||
|
/// </summary>
|
||||||
|
public interface IDashboardRepository
|
||||||
|
{
|
||||||
|
DashboardSummaryResponse GetSummary();
|
||||||
|
|
||||||
|
List<WorkshopProductionResponse> GetWorkshopProduction(DateTime startDate, DateTime endDate);
|
||||||
|
|
||||||
|
List<MachineRankResponse> GetMachineRank(DateTime startDate, DateTime endDate, int top);
|
||||||
|
|
||||||
|
List<WorkerRankResponse> GetWorkerRank(DateTime startDate, DateTime endDate, int top);
|
||||||
|
|
||||||
|
List<dynamic> GetProductionTrend(int days);
|
||||||
|
|
||||||
|
List<dynamic> GetMachineStatusDistribution();
|
||||||
|
|
||||||
|
List<AlertListItem> GetRecentAlerts(int count);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_machine_daily_status 机床日状态表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IMachineDailyStatusRepository
|
||||||
|
{
|
||||||
|
MachineDailyStatus GetByMachineAndDate(int machineId, DateTime date);
|
||||||
|
int Upsert(MachineDailyStatus entity);
|
||||||
|
List<MachineDailyStatus> GetByDate(DateTime date);
|
||||||
|
int CountByDateAndStatus(DateTime date, string dataStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Machine;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 机床仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IMachineRepository
|
||||||
|
{
|
||||||
|
Machine GetById(int id);
|
||||||
|
PagedResult<MachineListItem> GetList(MachineQuery query);
|
||||||
|
int Create(Machine entity);
|
||||||
|
bool Update(Machine entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
bool ToggleEnabled(int id);
|
||||||
|
Machine GetByDeviceCode(string deviceCode);
|
||||||
|
List<Machine> GetEnabledByAddressId(int collectAddressId);
|
||||||
|
List<Machine> GetEnabledOnline();
|
||||||
|
void UpdateOnlineStatus(int id, bool isOnline);
|
||||||
|
void UpdateLastCollect(int id, Machine entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_production_adjustment 产量修正审计表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IProductionAdjustmentRepository
|
||||||
|
{
|
||||||
|
int Create(ProductionAdjustment entity);
|
||||||
|
PagedResult<ProductionAdjustment> GetList(string targetTable, DateTime? startDate, DateTime? endDate, string keyword, int page, int pageSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_production_segment 产量分段记录表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IProductionSegmentRepository
|
||||||
|
{
|
||||||
|
ProductionSegment GetById(long id);
|
||||||
|
ProductionSegment GetActiveSegment(int machineId);
|
||||||
|
List<ProductionSegment> GetByMachineAndDate(int machineId, DateTime date);
|
||||||
|
int Create(ProductionSegment entity);
|
||||||
|
bool CloseSegment(long id, decimal? endPartCount, decimal? quantity, string closeReason, DateTime endTime);
|
||||||
|
bool SettleByDate(DateTime date);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_screen_config 大屏卡片配置表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IScreenConfigRepository
|
||||||
|
{
|
||||||
|
List<ScreenConfig> GetAll();
|
||||||
|
List<ScreenConfig> GetEnabled();
|
||||||
|
ScreenConfig GetById(int id);
|
||||||
|
int Create(ScreenConfig entity);
|
||||||
|
bool Update(ScreenConfig entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
bool ToggleEnabled(int id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_screen_filter 大屏筛选配置表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IScreenFilterRepository
|
||||||
|
{
|
||||||
|
List<ScreenFilter> GetByScreenKey(string screenKey);
|
||||||
|
int Create(ScreenFilter entity);
|
||||||
|
bool Update(ScreenFilter entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 系统配置仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface ISysConfigRepository
|
||||||
|
{
|
||||||
|
/// <summary>按配置Key获取配置</summary>
|
||||||
|
SysConfig GetByKey(string configKey);
|
||||||
|
|
||||||
|
/// <summary>获取全部配置</summary>
|
||||||
|
List<SysConfig> GetAll();
|
||||||
|
|
||||||
|
/// <summary>更新配置值</summary>
|
||||||
|
/// <param name="id">配置项ID</param>
|
||||||
|
/// <param name="configValue">新值</param>
|
||||||
|
bool UpdateValue(int id, string configValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Log;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// log_system 系统日志 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface ISystemLogRepository
|
||||||
|
{
|
||||||
|
PagedResult<SystemLogListItem> GetList(SystemLogQuery query);
|
||||||
|
int Create(SystemLog entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// cnc_worker_daily_summary 工人日汇总表 仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IWorkerDailySummaryRepository
|
||||||
|
{
|
||||||
|
WorkerDailySummary GetByWorkerAndDate(int workerId, DateTime date);
|
||||||
|
List<WorkerDailySummary> GetByDateRange(DateTime startDate, DateTime endDate);
|
||||||
|
int Upsert(WorkerDailySummary entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工人-机床绑定仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IWorkerMachineRepository
|
||||||
|
{
|
||||||
|
WorkerMachine GetByMachineId(int machineId);
|
||||||
|
List<WorkerMachine> GetByWorkerId(int workerId);
|
||||||
|
int Create(int workerId, int machineId);
|
||||||
|
bool DeleteByMachineId(int machineId);
|
||||||
|
bool DeleteByWorkerId(int workerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
using CncModels.Dto.Worker;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工人仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IWorkerRepository
|
||||||
|
{
|
||||||
|
Worker GetById(int id);
|
||||||
|
PagedResult<WorkerListItem> GetList(WorkerQuery query);
|
||||||
|
int Create(Worker entity);
|
||||||
|
bool Update(Worker entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
bool ToggleEnabled(int id);
|
||||||
|
Worker GetByCode(string code);
|
||||||
|
List<Worker> GetAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CncModels.Entity;
|
||||||
|
using CncModels.Dto;
|
||||||
|
|
||||||
|
namespace CncRepository.Interface
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 车间仓储接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IWorkshopRepository
|
||||||
|
{
|
||||||
|
Workshop GetById(int id);
|
||||||
|
List<Workshop> GetAll();
|
||||||
|
PagedResult<Workshop> GetList(string keyword);
|
||||||
|
int Create(Workshop entity);
|
||||||
|
bool Update(Workshop entity);
|
||||||
|
bool Delete(int id);
|
||||||
|
bool ToggleEnabled(int id);
|
||||||
|
int GetMachineCount(int workshopId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue