HJGL_DS/HJGL_DS/BLL/API/APIWeldServices.cs

509 lines
23 KiB
C#

using Model;
using Model.APIItem;
using NPOI.SS.Formula.Eval;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using System.Web.UI;
namespace BLL.API
{
public class APIWeldServices
{
public static Model.ResponeData usingPlanList(string weldName, string userId, string useState, int page, int pageSize)
{
Model.ResponeData respone = new ResponeData();
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List<string> projectids = new List<string>();
var upids = db.Project_User.Where(x => x.UserId == userId).Select(x => x.ProjectId).ToList();
projectids.AddRange(upids);
var wpids = db.Project_Welder.Where(x => x.WED_ID == userId).Select(x => x.ProjectId).ToList();
projectids.AddRange(wpids);
if (userId == BLL.Const.GlyId)
{
projectids = (from x in db.Base_Project where x.ProjectSoft == "1" select x.ProjectId).ToList();
}
var q = from x in db.Weld_UsingPlan where projectids.Contains(x.ProjectId) && (x.UsingManOne == userId || x.InPutMan == userId) select x;
List<string> usingplanids = new List<string>();
if (!string.IsNullOrEmpty(useState))
{
switch (useState)
{
case "0"://未领用
q = q.Where(x => x.IsCancel.Value == false);
var ids1 = db.Weld_UsingMat.Where(x => projectids.Contains(x.ProjectId)).Select(x => x.UsingPlanId).ToList();
usingplanids.AddRange(ids1);
break;
case "1"://已领用
var ids2 = db.Weld_UsingMat.Where(x => projectids.Contains(x.ProjectId)).Select(x => x.UsingPlanId).ToList();
usingplanids.AddRange(ids2);
break;
case "2"://已作废
q = q.Where(x => x.IsCancel.Value == true);
break;
}
}
//if (!string.IsNullOrEmpty(userId))
//{
// q = q.Where(x => x.WeldId == userId);
//}
List<string> weldIds = new List<string>();
if (!string.IsNullOrEmpty(weldName))
{
weldIds = db.Weld_WeldInfo.Where(x => x.WeldName.Contains(weldName)).Select(x => x.WeldId).ToList();
q = q.Where(x => weldIds.Contains(x.WeldId));
}
//if (!string.IsNullOrEmpty(needConfirm))
//{
// q = q.Where(x => x.IsNeedConfirm.Value == true);
//}
List<UsingPlanItem> usingPlanItem = new List<UsingPlanItem>();
var list = q.OrderByDescending(x => x.OrderDate).ToList();
if (list.Count > 0)
{
foreach (var x in list)
{
if (!string.IsNullOrEmpty(weldName))
{
bool hasFind = false;
foreach (string wid in weldIds)
if (wid == x.WeldId)
{
hasFind = true;
}
if (!hasFind)
continue;
}
if (useState == "1")
{
bool hasFind = false;
foreach (string wid in usingplanids)
if (wid == x.UsingPlanId)
{
hasFind = true;
}
if (!hasFind)
continue;
}
if (useState == "0" && usingplanids.Count() > 0)
{
bool hasFind = false;
foreach (var wid in usingplanids)
if (wid == x.UsingPlanId)
{
hasFind = true;
}
if (hasFind)
continue;
}
UsingPlanItem planItem = new UsingPlanItem();
planItem.UsingPlanId = x.UsingPlanId;
planItem.WeldId = x.WeldId;
planItem.UnitStoreId= BLL.UnitStoreService.GetUnitStoreNameById(x.UnitStoreId);
planItem.ProjectId = x.ProjectId;
planItem.UsePosition = x.UsePosition;
planItem.Amount = x.Amount;
planItem.UsingManOne = x.UsingManOne;
planItem.UsingManTwo = x.UsingManTwo;
if (x.InPutDate != null)
{
planItem.InPutDate = string.Format("{0:yyyy-MM-dd}", x.InPutDate);
}
if (x.CancelDate != null)
{
planItem.CancelDate = string.Format("{0:yyyy-MM-dd}", x.CancelDate);
}
planItem.IsCancel = x.IsCancel;
planItem.FinishMan = x.FinishMan;
planItem.OrderTime = x.OrderTime;
if (x.OrderDate != null)
{
planItem.OrderDate = string.Format("{0:yyyy-MM-dd}", x.OrderDate);
}
planItem.CancelResult = x.CancelResult;
planItem.IsSubmit = x.IsSubmit;
planItem.UsingUnit = x.UsingUnit;
planItem.IsNeedConfirm = x.IsNeedConfirm;
planItem.InPutMan = x.InPutMan;
planItem.IsSteelStru = x.IsSteelStru;
planItem.TeamGroupId = x.TeamGroupId;
planItem.STE_ID = x.STE_ID;
planItem.IsFinish = x.IsFinish;
planItem.STE_Name = x.STE_Name;
usingPlanItem.Add(planItem);
}
}
usingPlanItem = usingPlanItem.Skip(page * pageSize).Take(pageSize).ToList();
foreach (var item in usingPlanItem)
{
if (!string.IsNullOrEmpty(item.ProjectId))
{
var project = db.Base_Project.Where(x => x.ProjectId == item.ProjectId).FirstOrDefault();
if (project != null)
{
item.ProjectName = project.ProjectName;
item.ProjectCode = project.ProjectCode;
}
}
if (!string.IsNullOrEmpty(item.WeldId))
{
var weldInfo = db.Weld_WeldInfo.Where(x => x.WeldId == item.WeldId).FirstOrDefault();
if (weldInfo != null)
{
item.WeldName = weldInfo.WeldName;
item.WeldSpec = weldInfo.WeldSpec;
}
if (weldInfo != null && !string.IsNullOrEmpty(weldInfo.WeldTypeId))
{
var weldType = db.Weld_WeldType.Where(x => x.WeldTypeId == weldInfo.WeldTypeId).FirstOrDefault();
if (weldType != null)
{
}
}
}
if (!string.IsNullOrEmpty(item.UsingManOne))
{
item.UsingManOneName = db.HJGL_BS_Welder.Where(x => x.WED_ID == item.UsingManOne).Select(x => x.WED_Name).FirstOrDefault();
}
if (!string.IsNullOrEmpty(item.UsingManTwo))
{
item.UsingManTwoName = db.HJGL_BS_Welder.Where(x => x.WED_ID == item.UsingManTwo).Select(x => x.WED_Name).FirstOrDefault();
}
if (!string.IsNullOrEmpty(item.UsingUnit))
{
item.UsingUnitName = db.Base_Unit.Where(x => x.UnitId == item.UsingUnit).Select(x => x.UnitName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(item.InPutMan))
{
item.InPutManName = db.Sys_User.Where(x => x.UserId == item.InPutMan).Select(x => x.UserName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(item.TeamGroupId))
{
item.TeamGroupName = db.Base_TeamGroup.Where(x => x.TeamGroupId == item.TeamGroupId).Select(x => x.TeamGroupName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(item.TeamGroupId))
{
item.TeamGroupName = db.Base_TeamGroup.Where(x => x.TeamGroupId == item.TeamGroupId).Select(x => x.TeamGroupName).FirstOrDefault();
}
}
respone.data = usingPlanItem;
}
return respone;
}
public static Model.ResponeData getUsingPlanById(string usingPlanId)
{
Model.ResponeData respone = new ResponeData();
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Weld_UsingPlan usingPlan = (from x in db.Weld_UsingPlan where x.UsingPlanId == usingPlanId select x).FirstOrDefault();
UsingPlanItem planItem = new UsingPlanItem();
planItem.UsingPlanId = usingPlan.UsingPlanId;
planItem.WeldId = usingPlan.WeldId;
planItem.ProjectId = usingPlan.ProjectId;
planItem.UsePosition = usingPlan.UsePosition;
planItem.Amount = usingPlan.Amount;
planItem.UsingManOne = usingPlan.UsingManOne;
planItem.UsingManTwo = usingPlan.UsingManTwo;
if (usingPlan.InPutDate != null)
{
planItem.InPutDate = string.Format("{0:yyyy-MM-dd}", usingPlan.InPutDate);
}
if (usingPlan.CancelDate != null)
{
planItem.CancelDate = string.Format("{0:yyyy-MM-dd}", usingPlan.CancelDate);
}
planItem.IsCancel = usingPlan.IsCancel;
planItem.FinishMan = usingPlan.FinishMan;
planItem.OrderTime = usingPlan.OrderTime;
if (usingPlan.OrderDate != null)
{
planItem.OrderDate = string.Format("{0:yyyy-MM-dd}", usingPlan.OrderDate);
}
planItem.CancelResult = usingPlan.CancelResult;
planItem.IsSubmit = usingPlan.IsSubmit;
planItem.UsingUnit = usingPlan.UsingUnit;
planItem.IsNeedConfirm = usingPlan.IsNeedConfirm;
planItem.InPutMan = usingPlan.InPutMan;
planItem.IsSteelStru = usingPlan.IsSteelStru;
planItem.TeamGroupId = usingPlan.TeamGroupId;
planItem.STE_ID = usingPlan.STE_ID;
planItem.IsFinish = usingPlan.IsFinish;
planItem.STE_Name = usingPlan.STE_Name;
planItem.UnitStoreId = BLL.UnitStoreService.GetUnitStoreNameById(usingPlan.UnitStoreId);
if (!string.IsNullOrEmpty(planItem.ProjectId))
{
var project = db.Base_Project.Where(x => x.ProjectId == planItem.ProjectId).FirstOrDefault();
if (project != null)
{
planItem.ProjectName = project.ProjectName;
planItem.ProjectCode = project.ProjectCode;
}
}
if (!string.IsNullOrEmpty(planItem.WeldId))
{
var weldInfo = db.Weld_WeldInfo.Where(x => x.WeldId == planItem.WeldId).FirstOrDefault();
if (weldInfo != null)
{
planItem.WeldName = weldInfo.WeldName;
planItem.WeldSpec = weldInfo.WeldSpec;
planItem.WeldCode = weldInfo.WeldCode;
}
if (weldInfo != null && !string.IsNullOrEmpty(weldInfo.WeldTypeId))
{
var weldType = db.Weld_WeldType.Where(x => x.WeldTypeId == weldInfo.WeldTypeId).FirstOrDefault();
if (weldType != null)
{
}
}
}
if (!string.IsNullOrEmpty(planItem.UsingManOne))
{
planItem.UsingManOneName = db.HJGL_BS_Welder.Where(x => x.WED_ID == planItem.UsingManOne).Select(x => x.WED_Name).FirstOrDefault();
}
if (!string.IsNullOrEmpty(planItem.UsingManTwo))
{
planItem.UsingManTwoName = db.HJGL_BS_Welder.Where(x => x.WED_ID == planItem.UsingManTwo).Select(x => x.WED_Name).FirstOrDefault();
}
if (!string.IsNullOrEmpty(planItem.UsingUnit))
{
planItem.UsingUnitName = db.Base_Unit.Where(x => x.UnitId == planItem.UsingUnit).Select(x => x.UnitName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(planItem.InPutMan))
{
planItem.InPutManName = db.Sys_User.Where(x => x.UserId == planItem.InPutMan).Select(x => x.UserName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(planItem.TeamGroupId))
{
planItem.TeamGroupName = db.Base_TeamGroup.Where(x => x.TeamGroupId == planItem.TeamGroupId).Select(x => x.TeamGroupName).FirstOrDefault();
}
respone.data = planItem;
}
return respone;
}
public static Model.ResponeData welderQueIsPass(string welderId, string steelType, bool isSteelStru)
{
Model.ResponeData respone = new ResponeData();
respone.data = false;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List<HJGL_BS_WelderQualifiedProject> list = new List<HJGL_BS_WelderQualifiedProject>();
if (isSteelStru == true)
{
list = db.HJGL_BS_WelderQualifiedProject.Where(x => x.WED_ID == welderId && x.LimitDate >= DateTime.Now && x.MaterialType != null).ToList();
}
else
{
list = db.HJGL_BS_WelderQualifiedProject.Where(x => x.WED_ID == welderId && x.LimitDate >= DateTime.Now && x.MaterialType != null && (!x.IsSteelStru.HasValue || x.IsSteelStru == null)).ToList();
}
foreach (HJGL_BS_WelderQualifiedProject item in list)
{
if (item.MaterialType.Contains(steelType))
{
respone.data = true;
break;
}
}
}
return respone;
}
public static Model.ResponeData addUsingPlan(UsingPlanItem usingPlan)
{
Model.ResponeData respone = new ResponeData();
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var teamGroups = from x in Funs.DB.Base_TeamGroup select x;
Weld_UsingPlan newUsingPlan = new Weld_UsingPlan();
if (string.IsNullOrEmpty(usingPlan.UsingPlanId))
{
newUsingPlan.UsingPlanId = Guid.NewGuid().ToString();
//newUsingPlan.OrderDate = DateTime.Now;
db.Weld_UsingPlan.InsertOnSubmit(newUsingPlan);
}
else
{
newUsingPlan = db.Weld_UsingPlan.FirstOrDefault(x => x.UsingPlanId == usingPlan.UsingPlanId);
}
newUsingPlan.WeldId = usingPlan.WeldId;
newUsingPlan.ProjectId = usingPlan.ProjectId;
newUsingPlan.UsePosition = usingPlan.UsePosition;
newUsingPlan.UnitStoreId = usingPlan.UnitStoreId;
newUsingPlan.Amount = usingPlan.Amount;
newUsingPlan.UsingManOne = usingPlan.UsingManOne;
newUsingPlan.UsingManTwo = usingPlan.UsingManTwo;
newUsingPlan.InPutDate = Funs.GetNewDateTime(usingPlan.InPutDate);
newUsingPlan.CancelDate = Funs.GetNewDateTime(usingPlan.CancelDate);
newUsingPlan.IsCancel = usingPlan.IsCancel;
newUsingPlan.FinishMan = usingPlan.FinishMan;
newUsingPlan.OrderTime = usingPlan.OrderTime;
newUsingPlan.OrderDate = Funs.GetNewDateTime(usingPlan.OrderDate);
newUsingPlan.CancelResult = usingPlan.CancelResult;
newUsingPlan.IsSubmit = usingPlan.IsSubmit;
newUsingPlan.UsingUnit = usingPlan.UsingUnit;
newUsingPlan.IsNeedConfirm = usingPlan.IsNeedConfirm;
newUsingPlan.InPutMan = usingPlan.InPutMan;
newUsingPlan.IsSteelStru = usingPlan.IsSteelStru;
var teamGroup = teamGroups.FirstOrDefault(x => x.TeamGroupId == usingPlan.TeamGroupId);
if (teamGroup != null)
{
newUsingPlan.TeamGroupId = teamGroup.TeamGroupName;
}
newUsingPlan.STE_ID = usingPlan.STE_ID;
newUsingPlan.IsFinish = usingPlan.IsFinish;
newUsingPlan.STE_Name = usingPlan.STE_Name;
db.SubmitChanges();
var old = db.Weld_UsingPlan.Where(x => x.UsingManOne == usingPlan.UsingManOne && x.OrderTime == usingPlan.OrderTime && x.OrderDate == Funs.GetNewDateTime(usingPlan.OrderDate)).ToList();
if (old.Count > 2)
{
foreach (var item in old)
{
item.IsNeedConfirm = true;
}
db.SubmitChanges();
}
}
return respone;
}
/// <summary>
/// 项目焊工
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
public static Model.ResponeData getProjectWelder(string projectId, string unitId, string date)
{
Model.ResponeData respone = new ResponeData();
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
DateTime dateTime =DateTime.Parse("1753-01-02");
if (!string.IsNullOrEmpty(date) && date != "null")
{
dateTime = DateTime.Parse(date);
}
var q = (from pw in db.Project_Welder
join w in db.HJGL_BS_Welder on pw.WED_ID equals w.WED_ID
where w.PhotoUrl !=null && pw.ExchangeTime > dateTime
select w).Distinct();
List<WelderItem> res = new List<WelderItem>();
foreach (var p in q)
{
WelderItem item = new WelderItem();
item.WED_ID = p.WED_ID;
item.WED_Unit = p.WED_Unit;
item.EDU_ID = p.EDU_ID;
item.SE_EquipmentID = p.SE_EquipmentID;
item.NP_NondestructivePersonID = p.NP_NondestructivePersonID;
item.WED_Code = p.WED_Code;
item.WED_Name = p.WED_Name;
item.WED_UserType = p.WED_UserType;
item.WED_Sex = p.WED_Sex;
item.WED_Birthday = p.WED_Birthday;
item.WED_WorkCode = p.WED_WorkCode;
item.WED_Class = p.WED_Class;
item.WED_TotalDin = p.WED_TotalDin;
item.WED_TotalJoint = p.WED_TotalJoint;
item.WED_ExtendDin = p.WED_ExtendDin;
item.WED_ExtendJoint = p.WED_ExtendJoint;
item.WED_RepairJoint = p.WED_RepairJoint;
item.WED_IfOnGuard = p.WED_IfOnGuard;
item.WED_Remark = p.WED_Remark;
item.WED_TotalFilm = p.WED_TotalFilm;
item.WED_PassFilm = p.WED_PassFilm;
item.WED_ExtendTotalFilm = p.WED_ExtendTotalFilm;
item.WED_ExtendPassFilm = p.WED_ExtendPassFilm;
item.ProjectId = p.ProjectId;
item.ThicknessMax = p.ThicknessMax;
item.ThicknessMin = p.ThicknessMin;
item.SizesMax = p.SizesMax;
item.SizesMin = p.SizesMin;
item.RecordDate = p.RecordDate;
item.MyFinger = p.MyFinger;
item.SignatureUrl = p.SignatureUrl;
item.Education = p.Education;
item.WED_States = p.WED_States;
item.IsOAM = p.IsOAM;
item.LimitDate = p.LimitDate;
item.IdentityCard = p.IdentityCard;
item.AttachUrl = p.AttachUrl;
item.PhotoUrl = p.PhotoUrl;
item.IsFaceTrain = p.IsFaceTrain;
item.ExchangeTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
res.Add(item);
}
respone.data = res;
}
return respone;
}
#region
/// <summary>
/// 更新人员数据交换时间
/// </summary>
/// <param name="personId">人员ID</param>
/// <param name="type">交换类型</param>
/// <returns></returns>
public static Model.ResponeData getUpdateWelderExchangeTime(string wedId, string projectId)
{
var responeData = new Model.ResponeData();
try
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getPerson = db.Project_Welder.FirstOrDefault(e => e.ProjectId == projectId && e.WED_ID == wedId);
getPerson.ExchangeTime = DateTime.Now;
db.SubmitChanges();
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
ErrLogInfo.WriteLog(ex, "更新人员数据交换时间", "PersonController.getUpdatePersonExchangeTime");
}
return responeData;
}
#endregion
}
}