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

265 lines
13 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 Model;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BLL
{
public class APIPackagingManageService
{
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
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);
}
}
}