using Entity.DbModel.System.App; using Entity.Dto.Req; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using Repository.Station; using SqlSugar; namespace Service.Station; [Scope] public class CarTeamService : BaseServices { private readonly CarTeamRepository _carTeamRepository; public CarTeamService( CarTeamRepository carTeamRepository ) { _carTeamRepository = carTeamRepository; } /// /// 获取车队分页 /// /// /// public async Task> Page(PageCarTeamReq input) { RefAsync total = 0; var items = await _carTeamRepository.QueryPageAsync( entity => true, !string.IsNullOrWhiteSpace(input.TeamCode), u => u.TeamCode.Equals(input.TeamCode.Trim()), !string.IsNullOrWhiteSpace(input.TeamName), u => u.TeamName.Equals(input.TeamName.Trim()), !string.IsNullOrWhiteSpace(input.Principal), u => u.Principal.Equals(input.Principal.Trim()), u => u.CreatedTime, OrderByType.Desc, input.PageNum, input.PageSize, total); return new PageResult() { PageNum = input.PageNum, PageSize = input.PageSize, ToTal = total, Rows = items, }; } /// /// 获取所有车队 /// /// public async Task> GetTeamList() { return await _carTeamRepository.QueryAsync(); } /// /// 新增车队 /// /// /// public virtual async Task AddCarTeamReq(AddCarTeamReq input) { var existingUser = await _carTeamRepository.QueryByClauseAsync(u => u.TeamCode == input.TeamCode || u.TeamName == input.TeamName); if (existingUser?.TeamCode == input.TeamCode) { return "车队编码已存在"; } if (existingUser?.TeamName == input.TeamName) { return "车队名称已存在"; } // 插入新用户 await _carTeamRepository.InsertAsync(input); // 查询新ID CarTeam carTeam = await _carTeamRepository.QueryByClauseAsync(u => u.TeamCode == input.TeamCode); return "新增车队:" + carTeam.TeamName; } /// /// 车队修改 /// /// /// public virtual async Task> UpdateTeam(UpdateCarTeamReq team) { var existingTeam = await _carTeamRepository.QueryByClauseAsync(u => u.TeamCode == team.TeamCode || u.TeamName == team.TeamName && u.Id != team.Id); if (existingTeam?.TeamCode == team.TeamCode) { return Result.Fail("修改失败,车队编码已存在"); } if (existingTeam?.TeamName == team.TeamName) { return Result.Fail("修改失败,车队名称已存在"); } var updateAsync = await _carTeamRepository.UpdateAsync(team); if (updateAsync) { return Result.Success("修改成功"); } return Result.Fail("修改失败"); } /// /// 车队删除 /// /// /// /// public virtual async Task DeleteTeam(DeleteCarTeamReq input) { var user = await _carTeamRepository.QueryByClauseAsync(u => u.Id == input.Id); if (user == null) throw new ArgumentException($"车队不存在"); return await _carTeamRepository.DeleteAsync(user); } }