|
|
|
@ -79,7 +79,19 @@ namespace CncService.Impl
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
UpdatedAt = DateTime.Now
|
|
|
|
UpdatedAt = DateTime.Now
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return _workerRepository.Create(entity);
|
|
|
|
var workerId = _workerRepository.Create(entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 绑定机床
|
|
|
|
|
|
|
|
if (request.MachineIds != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var mid in request.MachineIds)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var binding = _workerMachineRepository.GetByMachineId(mid);
|
|
|
|
|
|
|
|
if (binding != null) throw new BusinessException(ErrorCode.Conflict, $"机床(ID={mid})已绑定其他工人");
|
|
|
|
|
|
|
|
_workerMachineRepository.Create(workerId, mid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return workerId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
@ -91,8 +103,27 @@ namespace CncService.Impl
|
|
|
|
if (entity == null) throw new BusinessException(ErrorCode.NotFound, "员工未找到");
|
|
|
|
if (entity == null) throw new BusinessException(ErrorCode.NotFound, "员工未找到");
|
|
|
|
|
|
|
|
|
|
|
|
entity.Name = request.Name ?? entity.Name;
|
|
|
|
entity.Name = request.Name ?? entity.Name;
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.Code) && request.Code != entity.Code)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dup = _workerRepository.GetByCode(request.Code);
|
|
|
|
|
|
|
|
if (dup != null) throw new BusinessException(ErrorCode.Conflict, "工号已存在");
|
|
|
|
|
|
|
|
entity.Code = request.Code;
|
|
|
|
|
|
|
|
}
|
|
|
|
entity.UpdatedAt = DateTime.Now;
|
|
|
|
entity.UpdatedAt = DateTime.Now;
|
|
|
|
return _workerRepository.Update(entity);
|
|
|
|
_workerRepository.Update(entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 全量替换机床绑定
|
|
|
|
|
|
|
|
if (request.MachineIds != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_workerMachineRepository.DeleteByWorkerId(id);
|
|
|
|
|
|
|
|
foreach (var mid in request.MachineIds)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var binding = _workerMachineRepository.GetByMachineId(mid);
|
|
|
|
|
|
|
|
if (binding != null) throw new BusinessException(ErrorCode.Conflict, $"机床(ID={mid})已绑定其他工人");
|
|
|
|
|
|
|
|
_workerMachineRepository.Create(id, mid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|