201 lines
9.3 KiB
C#
201 lines
9.3 KiB
C#
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace BLL
|
||
{
|
||
public class APIPackagingManageService
|
||
{
|
||
public static List<Model.PackagingManageDetailItem> GetPackagingManageList(string projectId)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
var q = (from x in db.HJGL_PackagingManage
|
||
join n in db.Base_Project on x.ProjectId equals n.ProjectId
|
||
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
|
||
from t in tt.DefaultIfEmpty()
|
||
where x.ProjectId == projectId
|
||
select new PackagingManageDetailItem
|
||
{
|
||
PackagingManageId = x.PackagingManageId,
|
||
PackagingCode = x.PackagingCode,
|
||
ProjectName = n.ProjectName,
|
||
ContactName = x.ContactName,
|
||
ContactPhone = x.ContactPhone,
|
||
StackingPosition = x.StackingPosition,
|
||
State = x.State,
|
||
ReceiveMan = t.PersonName,
|
||
ReceiveDate = string.Format("{0:g}", x.ReceiveDate),
|
||
TrainNumber = x.TrainNumber,
|
||
}).Distinct();
|
||
return q.ToList();
|
||
|
||
}
|
||
}
|
||
|
||
public static Model.PackagingManageItem GetPackagingInformationById(string projectId, string personId, string packagingManageId)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
PackagingManageItem packagingManageItem = new PackagingManageItem();
|
||
List<PackagingPrepipeItem> packagingPrepipeItem = new List<PackagingPrepipeItem>();
|
||
|
||
var q = (from x in db.HJGL_PackagingManage
|
||
join n in db.Base_Project on x.ProjectId equals n.ProjectId
|
||
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
|
||
from t in tt.DefaultIfEmpty()
|
||
where x.PackagingManageId == packagingManageId
|
||
select new PackagingManageDetailItem
|
||
{
|
||
PackagingManageId = x.PackagingManageId,
|
||
PackagingCode = x.PackagingCode,
|
||
ProjectName = n.ProjectName,
|
||
ProjectId = x.ProjectId,
|
||
ContactName = x.ContactName,
|
||
ContactPhone = x.ContactPhone,
|
||
StackingPosition = x.StackingPosition,
|
||
State = x.State,
|
||
ReceiveMan = t.PersonName,
|
||
ReceiveDate = string.Format("{0:g}", x.ReceiveDate),
|
||
TrainNumber = x.TrainNumber,
|
||
}).FirstOrDefault();
|
||
var tb_packing = (from x in db.HJGL_PackagingManage where x.PackagingManageId == packagingManageId select x).FirstOrDefault();
|
||
var PipelineComponentIdList = tb_packing?.PipelineComponentId?.Split(',');
|
||
if (PipelineComponentIdList != null && PipelineComponentIdList.Count() > 0)
|
||
{
|
||
packagingPrepipeItem = (from x in db.HJGL_Pipeline_Component
|
||
join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId
|
||
join z in db.WBS_UnitWork on y.UnitWorkId equals z.UnitWorkId
|
||
where PipelineComponentIdList.Contains(x.PipelineComponentId)
|
||
select new PackagingPrepipeItem
|
||
{
|
||
PipelineComponentId = x.PipelineComponentId,
|
||
PipelineComponentCode = x.PipelineComponentCode,
|
||
PreUnit = "1/个",
|
||
UnitWorkName = z.UnitWorkName,
|
||
PlanStartDate = string.Format("{0:g}", y.PlanStartDate),
|
||
|
||
}).ToList();
|
||
}
|
||
|
||
bool isPower = Person_PersonsService.IsGeneralUnitByPersonId(personId, projectId);
|
||
if (!isPower)
|
||
{
|
||
var roleList = Person_PersonsService.GetRoleListByProjectIdPersonId(projectId, personId);
|
||
if (roleList.Contains(Const.CQEngineer))
|
||
{
|
||
isPower = true;
|
||
}
|
||
}
|
||
packagingManageItem.packagingManageDetailItem = q;
|
||
packagingManageItem.packagingPrepipeItems = packagingPrepipeItem;
|
||
packagingManageItem.isPower = isPower;
|
||
return packagingManageItem;
|
||
|
||
}
|
||
|
||
}
|
||
public static void GetPackingInfoConfirmArrival(string packagingManageId, string PersonId)
|
||
{
|
||
var q = BLL.HJGLPackagingmanageService.GetHJGL_PackagingManageById(packagingManageId);
|
||
if (q != null)
|
||
{
|
||
q.State = HJGLPackagingmanageService.state_2;
|
||
q.ReceiveMan = PersonId;
|
||
q.ReceiveDate = DateTime.Now;
|
||
HJGLPackagingmanageService.UpdateHJGL_PackagingManage(q);
|
||
}
|
||
}
|
||
public static void getSavePackagingInformationById(string packagingManageId, string PipelineComponentIds)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
var table = db.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == packagingManageId);
|
||
if (table != null)
|
||
{
|
||
if (string.IsNullOrEmpty(table.PipelineComponentId))
|
||
{
|
||
table.PipelineComponentId = PipelineComponentIds;
|
||
}
|
||
else
|
||
{
|
||
HashSet<string> set = new HashSet<string>();
|
||
string[] oldIds = table.PipelineComponentId.Split(',');
|
||
foreach (var id in oldIds)
|
||
{
|
||
set.Add(id);
|
||
}
|
||
string[] newIds = PipelineComponentIds.Split(',');
|
||
foreach (var id in newIds)
|
||
{
|
||
set.Add(id);
|
||
}
|
||
table.PipelineComponentId = string.Join(",", set);
|
||
|
||
|
||
}
|
||
}
|
||
BLL.HJGLPackagingmanageService.UpdateHJGL_PackagingManage(table);
|
||
var newDetailList = new List<Model.HJGL_PackagingManageDetail>();
|
||
foreach (var item in table.PipelineComponentId.Split(','))
|
||
{
|
||
var ComponentModel = BLL.HJGL_PipelineComponentService.GetPipelineComponentById(item);
|
||
if (ComponentModel != null)
|
||
{
|
||
var model = new Model.HJGL_PackagingManageDetail()
|
||
{
|
||
Id = SQLHelper.GetNewID(),
|
||
PackagingManageId = table.PackagingManageId,
|
||
PipelineId = ComponentModel.PipelineId,
|
||
PipelineComponentId = item,
|
||
CreateTime = DateTime.Now,
|
||
};
|
||
newDetailList.Add(model);
|
||
}
|
||
}
|
||
HJGLPackagingmanagedetailService.DeleteByPackagingManageId(table.PackagingManageId);
|
||
HJGLPackagingmanagedetailService.AddBulk(newDetailList);
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 新增或更新包装信息(Id为空则新增,否则更新),返回创建或更新后的Id。
|
||
/// </summary>
|
||
public static string AddOrUpdatePackaging(Model.HJGL_PackagingManage model)
|
||
{
|
||
if (model == null)
|
||
throw new ArgumentNullException(nameof(model));
|
||
|
||
if (string.IsNullOrEmpty(model.PackagingManageId))
|
||
{
|
||
// 新增
|
||
model.PackagingManageId = SQLHelper.GetNewID(typeof(Model.HJGL_PackagingManage));
|
||
HJGLPackagingmanageService.AddHJGL_PackagingManage(model);
|
||
return model.PackagingManageId;
|
||
}
|
||
else
|
||
{
|
||
// 修改
|
||
var exist = HJGLPackagingmanageService.GetHJGL_PackagingManageById(model.PackagingManageId);
|
||
if (exist == null)
|
||
{
|
||
HJGLPackagingmanageService.AddHJGL_PackagingManage(model);
|
||
return model.PackagingManageId;
|
||
}
|
||
else
|
||
{
|
||
HJGLPackagingmanageService.UpdateHJGL_PackagingManage(model);
|
||
return model.PackagingManageId;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public static string GetNewPackagingCode(string projectId)
|
||
{
|
||
return HJGLPackagingmanageService.GetNewPackagingCode(projectId);
|
||
}
|
||
}
|
||
}
|