120 lines
4.4 KiB
C#
120 lines
4.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace BLL
|
||
{
|
||
public class APITrainNumberManagerService
|
||
{
|
||
/// <summary>
|
||
/// 车次发货验收
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="PersonId"></param>
|
||
public static void SaveTrainInfoConfirmArrival(string id, string PersonId)
|
||
{
|
||
var model = TrainNumberManageService.GetModelById(id);
|
||
if (model != null)
|
||
{
|
||
model.ReceiveDate = DateTime.Now;
|
||
model.State = ((int)TrainNumberManageService.StateInt.已验收);
|
||
TrainNumberManageService.Update(model);
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("车次信息有误,请检查!");
|
||
}
|
||
var packManagerList = HJGLPackagingmanageService.GetPackagingManage(id);
|
||
foreach (var item in packManagerList)
|
||
{
|
||
BLL.HJGLPackagingmanageService.GetPackingInfoConfirmArrival(item.PackagingManageId, PersonId);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取指定车次的包装明细(包装表)
|
||
/// </summary>
|
||
public static List<Model.HJGL_PackagingManage> GetPackagingByTrainId(string trainNumberId)
|
||
{
|
||
return HJGLPackagingmanageService.GetPackagingManage(trainNumberId);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将包装关联到车次(设置 HJGL_PackagingManage.TrainNumberId)
|
||
/// </summary>
|
||
public static void AddPackagingToTrain(string packagingManageId, string trainNumberId)
|
||
{
|
||
var packModel = HJGLPackagingmanageService.GetHJGL_PackagingManageById(packagingManageId);
|
||
if (packModel == null)
|
||
{
|
||
throw new Exception("未找到对应的包装信息");
|
||
}
|
||
// 仅允许状态为未出库(state_0)时修改车次号,保持与前端逻辑一致
|
||
if (packModel.State != HJGLPackagingmanageService.state_0)
|
||
{
|
||
throw new Exception("当前包装状态不可修改车次号");
|
||
}
|
||
packModel.TrainNumberId = trainNumberId;
|
||
HJGLPackagingmanageService.UpdateHJGL_PackagingManage(packModel);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取消包装与车次的关联(清空 HJGL_PackagingManage.TrainNumberId)
|
||
/// </summary>
|
||
public static void RemovePackagingFromTrain(string packagingManageId)
|
||
{
|
||
var packModel = HJGLPackagingmanageService.GetHJGL_PackagingManageById(packagingManageId);
|
||
if (packModel == null)
|
||
{
|
||
throw new Exception("未找到对应的包装信息");
|
||
}
|
||
/*if (packModel.State != HJGLPackagingmanageService.state_0)
|
||
{
|
||
throw new Exception("当前包装状态不可修改车次号");
|
||
}*/
|
||
packModel.TrainNumberId = null;
|
||
packModel.TrainNumber = null;
|
||
HJGLPackagingmanageService.UpdateHJGL_PackagingManage(packModel);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增或更新车次信息。若 model.Id 为空则新增,否则修改。返回创建或更新后的Id。
|
||
/// 新增时 State=0,ReceiveDate=null;修改时保持原有 State 和 ReceiveDate。
|
||
/// </summary>
|
||
public static string AddOrUpdateTrainNumber(Model.HJGL_TrainNumberManage model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
throw new ArgumentNullException(nameof(model));
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.Id))
|
||
{
|
||
// 新增
|
||
|
||
model.Id = SQLHelper.GetNewID(typeof(Model.HJGL_TrainNumberManage));
|
||
model.ReceiveDate = null;
|
||
TrainNumberManageService.Add(model);
|
||
return model.Id;
|
||
}
|
||
else
|
||
{
|
||
// 修改
|
||
var exist = TrainNumberManageService.GetModelById(model.Id);
|
||
if (exist == null)
|
||
{
|
||
model.ReceiveDate = null;
|
||
TrainNumberManageService.Add(model);
|
||
return model.Id;
|
||
}
|
||
else
|
||
{
|
||
// 保持原有ReceiveDate
|
||
model.ReceiveDate = exist.ReceiveDate;
|
||
TrainNumberManageService.Update(model);
|
||
return model.Id;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|