SGGL_SHJ/SGGL/BLL/API/HJGL/APITrainNumberManagerServic...

118 lines
4.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
TrainNumberManageService.Update(model);
}
else
{
throw new Exception("车次信息有误,请检查!");
}
var packManagerList = HJGLPackagingmanageService.GetPackagingManage(id);
foreach (var item in packManagerList)
{
BLL.APIPackagingManageService.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=0ReceiveDate=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;
}
}
}
}
}