using Autofac.Core;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseRepository;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_IBasicInfoService;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_BasicInfoService
|
{
|
public class BoxingService : ServiceBase<Dt_Boxing, IRepository<Dt_Boxing>>, IBoxingService
|
{
|
private readonly IProcessInfoService _processInfoService;
|
// 直接注入 BoxingDetail 的仓储,替代注入 BoxingDetailService
|
private readonly IRepository<Dt_BoxingDetail> _boxingDetailRepo;
|
|
public BoxingService(
|
IRepository<Dt_Boxing> BaseDal,
|
IProcessInfoService processInfoService,
|
// 新增注入 BoxingDetail 仓储
|
IRepository<Dt_BoxingDetail> boxingDetailRepo
|
) : base(BaseDal)
|
{
|
_processInfoService = processInfoService;
|
_boxingDetailRepo = boxingDetailRepo; // 赋值
|
}
|
|
public IRepository<Dt_Boxing> Repository => BaseDal;
|
|
//删除当前托盘
|
public WebResponseContent DeleteCurrentTray()
|
{
|
try
|
{
|
var PalletCode = TcpClientExample.Start("192.168.2.120", 2001);
|
if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
|
{
|
return WebResponseContent.Instance.Error("托盘码未扫到,请重试");
|
}
|
Db.Ado.BeginTran();
|
|
// 1. 删除 Boxing 主表数据
|
Dt_Boxing dt_Boxing = BaseDal.QueryFirst(x => x.PalletCode == PalletCode);
|
if (dt_Boxing != null)
|
{
|
BaseDal.DeleteData(dt_Boxing);
|
|
// 2. 直接通过仓储删除 BoxingDetail 数据(核心修改)
|
Dt_BoxingDetail dt_BoxingDetail = _boxingDetailRepo.QueryFirst(x => x.BoxingId == dt_Boxing.Id);
|
if (dt_BoxingDetail != null)
|
{
|
_boxingDetailRepo.DeleteData(dt_BoxingDetail);
|
}
|
}
|
|
// 3. 删除 ProcessInfo 数据
|
Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
|
if (dt_ProcessInfo != null)
|
{
|
_processInfoService.Repository.DeleteData(dt_ProcessInfo);
|
}
|
|
Db.Ado.CommitTran();
|
return WebResponseContent.Instance.OK("删除成功");
|
}
|
catch (Exception ex)
|
{
|
Db.Ado.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
|
}
|
}
|