Files
SGGL_SHJ/SGGL/BLL/API/HJGL/APIPackagingManageService.cs
T

265 lines
13 KiB
C#
Raw Normal View History

using Model;
using System;
2022-10-08 23:50:15 +08:00
using System.Collections.Generic;
using System.Linq;
namespace BLL
{
public class APIPackagingManageService
2022-10-08 23:50:15 +08:00
{
public static List<Model.PackagingManageDetailItem> GetPackagingManageList(PackagingManageInput filter, int pageIndex, int pageSize, out int totalCount)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
// base join query to include project and receive person
var baseQuery = 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()
select new { x, n, t };
if (filter != null)
{
if (!string.IsNullOrEmpty(filter.PackagingManageId))
{
baseQuery = baseQuery.Where(z => z.x.PackagingManageId == filter.PackagingManageId);
}
if (!string.IsNullOrEmpty(filter.PackagingCode))
{
baseQuery = baseQuery.Where(z => z.x.PackagingCode.Contains(filter.PackagingCode));
}
if (!string.IsNullOrEmpty(filter.ProjectId))
{
baseQuery = baseQuery.Where(z => z.x.ProjectId == filter.ProjectId);
}
if (!string.IsNullOrEmpty(filter.ProjectName))
{
baseQuery = baseQuery.Where(z => z.n.ProjectName.Contains(filter.ProjectName));
}
if (!string.IsNullOrEmpty(filter.ContactName))
{
baseQuery = baseQuery.Where(z => z.x.ContactName.Contains(filter.ContactName));
}
if (!string.IsNullOrEmpty(filter.ContactPhone))
{
baseQuery = baseQuery.Where(z => z.x.ContactPhone.Contains(filter.ContactPhone));
}
if (!string.IsNullOrEmpty(filter.StackingPosition))
{
baseQuery = baseQuery.Where(z => z.x.StackingPosition.Contains(filter.StackingPosition));
}
if (filter.State != null)
{
baseQuery = baseQuery.Where(z => z.x.State == filter.State);
}
if (!string.IsNullOrEmpty(filter.ReceiveMan))
{
baseQuery = baseQuery.Where(z => z.x.ReceiveMan == filter.ReceiveMan || (z.t != null && z.t.PersonName.Contains(filter.ReceiveMan)));
}
if (!string.IsNullOrEmpty(filter.ReceiveDate))
{
DateTime dt;
if (DateTime.TryParse(filter.ReceiveDate, out dt))
{
var start = dt.Date;
var end = start.AddDays(1);
baseQuery = baseQuery.Where(z => z.x.ReceiveDate != null && z.x.ReceiveDate >= start && z.x.ReceiveDate < end);
}
}
if (!string.IsNullOrEmpty(filter.TrainNumberId))
{
baseQuery = baseQuery.Where(z => z.x.TrainNumber != null && z.x.TrainNumber.Contains(filter.TrainNumberId));
}
}
baseQuery = baseQuery.OrderByDescending(z => (z.x.ReceiveDate ?? DateTime.MinValue)).ThenBy(z => z.x.PackagingCode);
var q = (from z in baseQuery
select new PackagingManageDetailItem
{
PackagingManageId = z.x.PackagingManageId,
PackagingCode = z.x.PackagingCode,
ProjectName = z.n.ProjectName,
ContactName = z.x.ContactName,
ContactPhone = z.x.ContactPhone,
StackingPosition = z.x.StackingPosition,
State = z.x.State,
ReceiveMan = z.t.PersonName,
ReceiveDate = string.Format("{0:g}", z.x.ReceiveDate),
TrainNumber = z.x.TrainNumber,
}).Distinct();
totalCount = q.Count();
if (pageIndex <=0) pageIndex =1;
if (pageSize <=0) pageSize =20;
return q.Skip((pageIndex -1) * pageSize).Take(pageSize).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
2022-10-15 15:40:49 +08:00
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
from t in tt.DefaultIfEmpty()
2022-10-11 17:12:13 +08:00
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,
2022-10-15 15:40:49 +08:00
ReceiveMan = t.PersonName,
2024-09-28 16:59:44 +08:00
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();
}
2022-10-11 17:12:13 +08:00
bool isPower = Person_PersonsService.IsGeneralUnitByPersonId(personId, projectId);
2023-09-13 15:13:41 +08:00
if (!isPower)
{
var roleList = Person_PersonsService.GetRoleListByProjectIdPersonId(projectId, personId);
2023-09-13 15:13:41 +08:00
if (roleList.Contains(Const.CQEngineer))
{
isPower = true;
2023-09-13 15:13:41 +08:00
}
}
packagingManageItem.packagingManageDetailItem = q;
packagingManageItem.packagingPrepipeItems = packagingPrepipeItem;
2022-10-11 17:12:13 +08:00
packagingManageItem.isPower = isPower;
return packagingManageItem;
}
}
public static void GetPackingInfoConfirmArrival(string packagingManageId, string PersonId)
{
var q = BLL.HJGLPackagingmanageService.GetHJGL_PackagingManageById(packagingManageId);
if (q != null)
{
2025-09-24 17:31:28 +08:00
q.State = HJGLPackagingmanageService.state_2;
2022-10-15 15:40:49 +08:00
q.ReceiveMan = PersonId;
q.ReceiveDate = DateTime.Now;
2025-09-24 17:31:28 +08:00
HJGLPackagingmanageService.UpdateHJGL_PackagingManage(q);
}
}
2024-09-27 18:17:21 +08:00
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);
2025-06-04 22:46:21 +08:00
}
2024-09-27 18:17:21 +08:00
}
2025-09-24 17:31:28 +08:00
BLL.HJGLPackagingmanageService.UpdateHJGL_PackagingManage(table);
2025-06-04 22:46:21 +08:00
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,
2025-06-04 22:46:21 +08:00
};
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);
2024-09-27 18:17:21 +08:00
}
2022-10-08 23:50:15 +08:00
}
}