6040-003分支:更新WCS库代码

This commit is contained in:
zhusenlin
2026-03-02 10:56:30 +08:00
parent b83624f0c3
commit 91ded5ac61
113 changed files with 3012 additions and 15964 deletions

View File

@@ -11,7 +11,7 @@ namespace Plugin.Cowain.Wcs.Services;
public class StationService : BaseService, IStationService
{
public StationService(SqlDbContext dbContext) : base(dbContext)
public StationService(IDbContextFactory<SqlDbContext> dbContextFactory) : base(dbContextFactory)
{
}
@@ -30,9 +30,8 @@ public class StationService : BaseService, IStationService
{
return ResultModel.Error("工站编码不能为空");
}
var dbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var dbSet = dbContext.GetDbSet<StationDto>();
// 检查StationName是否重复
var nameExists = await dbSet.AnyAsync(x => x.StationName == station.StationName);
if (nameExists)
@@ -63,7 +62,7 @@ public class StationService : BaseService, IStationService
Enable = true,
};
await dbSet.AddAsync(entity);
var count = await _dBContext.SaveChangesAsync();
var count = await dbContext.SaveChangesAsync();
return count > 0 ? ResultModel.Success("工站添加成功") : ResultModel.Error("工站添加失败");
}
@@ -73,14 +72,15 @@ public class StationService : BaseService, IStationService
{
return ResultModel.Error("id不能小于0");
}
var DbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var DbSet = dbContext.GetDbSet<StationDto>();
var existingModel = await DbSet.FirstOrDefaultAsync(x => x.Id == id);
if (existingModel == null)
{
return ResultModel.Error("工站id不存在");
}
DbSet.Remove(existingModel);
int count = await _dBContext.SaveChangesAsync();
int count = await dbContext.SaveChangesAsync();
return count > 0 ? ResultModel.Success("工站删除成功") : ResultModel.Error("工站删除失败");
}
@@ -90,14 +90,15 @@ public class StationService : BaseService, IStationService
{
return ResultModel.Error("id不能小于0");
}
var DbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var DbSet = dbContext.GetDbSet<StationDto>();
var existingModel = await DbSet.FirstOrDefaultAsync(x => x.Id == id);
if (existingModel == null)
{
return ResultModel.Error("工站id不存在");
}
existingModel.Enable = false;
await _dBContext.SaveChangesAsync();
await dbContext.SaveChangesAsync();
return ResultModel.Success("工站禁用成功");
}
@@ -107,20 +108,22 @@ public class StationService : BaseService, IStationService
{
return ResultModel.Error("id不能小于0");
}
var DbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var DbSet = dbContext.GetDbSet<StationDto>();
var existingModel = await DbSet.FirstOrDefaultAsync(x => x.Id == id);
if (existingModel == null)
{
return ResultModel.Error("工站id不存在");
}
existingModel.Enable = true;
await _dBContext.SaveChangesAsync();
await dbContext.SaveChangesAsync();
return ResultModel.Success("工站启用成功");
}
public async Task<List<StationViewModel>> GetAllAsync()
{
var DbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var DbSet = dbContext.GetDbSet<StationDto>();
var data = await DbSet.ToListAsync();
return new List<StationViewModel>(data.Select(x => new StationViewModel
{
@@ -145,8 +148,8 @@ public class StationService : BaseService, IStationService
public async Task<(List<StationViewModel>, int totals)> GetAllAsync(int pageIndex, int pageSize)
{
var dbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var dbSet = dbContext.GetDbSet<StationDto>();
var query = dbSet.AsQueryable();
int totals = await query.CountAsync();
@@ -197,7 +200,8 @@ public class StationService : BaseService, IStationService
{
return ResultModel.Error("工站编码不能为空");
}
var DbSet = _dBContext.GetDbSet<StationDto>();
using var dbContext = _dbContextFactory.CreateDbContext();
var DbSet = dbContext.GetDbSet<StationDto>();
var existingModel = await DbSet.FirstOrDefaultAsync(x => x.Id == satation.Id);
if (existingModel == null)
{
@@ -240,7 +244,7 @@ public class StationService : BaseService, IStationService
existingModel.Enable = satation.Enable;
existingModel.UpdateTime = DateTime.Now;
var count = await _dBContext.SaveChangesAsync();
var count = await dbContext.SaveChangesAsync();
return count > 0 ? ResultModel.Success("工站更新成功") : ResultModel.Error("工站更新失败");
}
}