后端 - 新增实体 ChejianBanci(表 ChejianBancis:车间 / 班次 / 日工作小时数) - 新增 ChejianBanciService 与 ChejianBanciController(api/prod/chejianbanci) 分页列表、编辑回显、新增、修改、删除、前缫车间下拉;含必填校验与同车间同班次重复校验 - 菜单种子:基础数据 → 车间班次(Timer 图标,权限 base:chejianbanci:list) - 修正历史数据:名称以「前缫」开头的部门职责类型改为「前缫」(25)。 迁移时 duty_type 被统一写成「其他」,导致按职责类型筛选车间取不到数据 前端 - 新增 web/src/views/base/chejianbanci/index.vue(列表 / 搜索 / 分页 / 新增 / 编辑 / 删除) - 注册组件映射 base/chejianbanci/index
139 lines
4.9 KiB
C#
139 lines
4.9 KiB
C#
using F9WebAiTest.Application.Common;
|
|
using F9WebAiTest.Application.Dtos.Prod;
|
|
using F9WebAiTest.Domain.Common;
|
|
using F9WebAiTest.Domain.Entities;
|
|
using F9WebAiTest.Domain.Entities.Base;
|
|
using F9WebAiTest.Domain.Entities.Prod;
|
|
using F9WebAiTest.Domain.Enums.SYS.Departments;
|
|
using SysDept = F9WebAiTest.Domain.Entities.SYS.Departments;
|
|
|
|
namespace F9WebAiTest.Application.Services.Prod;
|
|
|
|
public interface IChejianBanciService
|
|
{
|
|
Task<PageResult<ChejianbanciReadDto_View>> GetPagedAsync(int pageIndex, int pageSize, string keyword);
|
|
Task<ChejianbanciReadDto_Edit> GetByIdForEditAsync(long id);
|
|
Task CreateAsync(ChejianbanciReadDto_Edit dto);
|
|
Task UpdateAsync(long id, ChejianbanciReadDto_Edit dto);
|
|
Task DeleteAsync(long id);
|
|
|
|
/// <summary>车间下拉:只取职责类型为「前缫」的部门</summary>
|
|
Task<List<ChejianbanciDepOptionDto>> GetQianxianDepsAsync();
|
|
}
|
|
|
|
public class ChejianBanciService : IChejianBanciService
|
|
{
|
|
private readonly IRepository<ChejianBanci> _repo;
|
|
private readonly IRepository<SysDept.Department> _deptRepo;
|
|
|
|
public ChejianBanciService(IRepository<ChejianBanci> repo, IRepository<SysDept.Department> deptRepo)
|
|
{
|
|
_repo = repo;
|
|
_deptRepo = deptRepo;
|
|
}
|
|
|
|
public async Task<PageResult<ChejianbanciReadDto_View>> GetPagedAsync(int pageIndex, int pageSize, string keyword)
|
|
{
|
|
if (pageIndex <= 0) pageIndex = 1;
|
|
if (pageSize <= 0) pageSize = 20;
|
|
|
|
var depts = await _deptRepo.GetAllAsync();
|
|
var deptDict = depts.ToDictionary(d => d.Id, d => d.Name);
|
|
|
|
var all = await _repo.GetAllAsync();
|
|
var q = all.AsQueryable();
|
|
|
|
if (!string.IsNullOrWhiteSpace(keyword))
|
|
{
|
|
var kw = keyword.Trim();
|
|
var kwDeptIds = depts.Where(d => d.Name.Contains(kw)).Select(d => d.Id).ToHashSet();
|
|
q = q.Where(x => kwDeptIds.Contains(x.DeptId) || x.Banci.ToString().Contains(kw));
|
|
}
|
|
|
|
var total = q.LongCount();
|
|
var items = q.OrderBy(x => x.DeptId).ThenBy(x => x.Banci)
|
|
.Skip((pageIndex - 1) * pageSize).Take(pageSize)
|
|
.Select(x => new ChejianbanciReadDto_View
|
|
{
|
|
Id = x.Id,
|
|
DepId = x.DeptId,
|
|
Deptname = deptDict.GetValueOrDefault(x.DeptId, ""),
|
|
Banci = x.Banci,
|
|
BanciName = x.Banci.ToString(),
|
|
KaoqinDayhours = x.KaoqinDayhours
|
|
}).ToList();
|
|
|
|
return new PageResult<ChejianbanciReadDto_View>
|
|
{
|
|
Items = items,
|
|
Total = total,
|
|
PageIndex = pageIndex,
|
|
PageSize = pageSize
|
|
};
|
|
}
|
|
|
|
public async Task<ChejianbanciReadDto_Edit> GetByIdForEditAsync(long id)
|
|
{
|
|
var e = await _repo.GetByIdAsync(id) ?? throw new ServiceException("记录不存在", 404);
|
|
return new ChejianbanciReadDto_Edit
|
|
{
|
|
Id = e.Id,
|
|
DepId = e.DeptId,
|
|
Banci = e.Banci,
|
|
KaoqinDayhours = e.KaoqinDayhours
|
|
};
|
|
}
|
|
|
|
public async Task CreateAsync(ChejianbanciReadDto_Edit dto)
|
|
{
|
|
await ValidateAsync(dto, 0);
|
|
await _repo.AddAsync(new ChejianBanci
|
|
{
|
|
DeptId = dto.DepId,
|
|
Banci = dto.Banci,
|
|
KaoqinDayhours = dto.KaoqinDayhours
|
|
});
|
|
await _repo.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task UpdateAsync(long id, ChejianbanciReadDto_Edit dto)
|
|
{
|
|
var e = await _repo.GetByIdAsync(id) ?? throw new ServiceException("记录不存在", 404);
|
|
await ValidateAsync(dto, id);
|
|
|
|
e.DeptId = dto.DepId;
|
|
e.Banci = dto.Banci;
|
|
e.KaoqinDayhours = dto.KaoqinDayhours;
|
|
await _repo.UpdateAsync(e);
|
|
await _repo.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(long id)
|
|
{
|
|
var e = await _repo.GetByIdAsync(id) ?? throw new ServiceException("记录不存在", 404);
|
|
await _repo.DeleteAsync(e);
|
|
await _repo.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<List<ChejianbanciDepOptionDto>> GetQianxianDepsAsync()
|
|
{
|
|
var depts = await _deptRepo.GetAllAsync();
|
|
return depts
|
|
.Where(d => d.DutyType == Department_DutyType_Enum.前缫)
|
|
.OrderBy(d => d.SortOrder).ThenBy(d => d.Id)
|
|
.Select(d => new ChejianbanciDepOptionDto { Id = d.Id, Name = d.Name })
|
|
.ToList();
|
|
}
|
|
|
|
/// <summary>校验:车间、班次、工时必填,且同一车间的同一班次不可重复</summary>
|
|
private async Task ValidateAsync(ChejianbanciReadDto_Edit dto, long excludeId)
|
|
{
|
|
if (dto.DepId <= 0) throw new ServiceException("请选择车间");
|
|
if (dto.KaoqinDayhours <= 0) throw new ServiceException("日工作小时数必须大于 0");
|
|
|
|
var all = await _repo.GetAllAsync();
|
|
if (all.Any(x => x.Id != excludeId && x.DeptId == dto.DepId && x.Banci == dto.Banci))
|
|
throw new ServiceException("该车间的此班次已存在,请勿重复配置");
|
|
}
|
|
}
|