xinjiang/SGGL/BLL/API/HSSE/APIGoodsManageService.cs

351 lines
15 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;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EmitMapper;
namespace BLL
{
/// <summary>
/// 物质出门服务类
/// </summary>
public static class APIGoodsManageService
{
#region
/// <summary>
/// 根据主键获取物质出门详细信息
/// </summary>
/// <param name="主键">物质出门ID</param>
/// <returns>物质出门详细</returns>
public static Model.GoodsManageItem getGoodsManageById(string id)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Model.GoodsManageItem getGoodsItem = new Model.GoodsManageItem();
var getData = db.CostGoods_GoodsManage.FirstOrDefault(x => x.GoodsManageId == id);
if (getData != null)
{
getGoodsItem.GoodsManageId = getData.GoodsManageId;
getGoodsItem.ProjectId = getData.ProjectId;
getGoodsItem.ApplyUnitId = getData.ApplyUnitId;
getGoodsItem.ApplyUnitName = UnitService.GetUnitNameByUnitId(getData.ApplyUnitId);
getGoodsItem.ApplyManId = getData.ApplyManId;
getGoodsItem.ApplyManName = UserService.GetUserNameByUserId(getData.ApplyManId);
getGoodsItem.ApplyTime = string.Format("{0:yyyy-MM-dd}", getData.ApplyTime);
getGoodsItem.OutReasons = getData.OutReasons;
getGoodsItem.CarNum = getData.CarNum;
getGoodsItem.BeBack = getData.BeBack ?? false;
getGoodsItem.BackTime = string.Format("{0:yyyy-MM-dd}", getData.BackTime);
getGoodsItem.States = getData.States;
getGoodsItem.AttachUrl = APIUpLoadFileService.getFileUrl(id, null);
getGoodsItem.GoodsManageItemItemList = getItemList(getData.GoodsManageId);
getGoodsItem.FlowOperateItemList= getFlowOperateItemList(getData.GoodsManageId);
var getNow = getFlowOperate(getData.GoodsManageId);
if (getNow != null)
{
getGoodsItem.OperateName = getNow.OperateName;
getGoodsItem.SortIndex = getNow.SortIndex ?? 0;
getGoodsItem.OperaterManId = getNow.OperaterId;
getGoodsItem.OperaterManName = UserService.GetUserNameByUserId(getNow.OperaterId);
getGoodsItem.IsAgree = getNow.IsAgree ?? true;
getGoodsItem.Opinion = getNow.Opinion;
var getNext= getNextFlowOperate(getData.GoodsManageId,getNow.SortIndex ?? 0);
if (getNext != null)
{
getGoodsItem.NextOperateName = getNext.OperateName;
getGoodsItem.NextSortIndex = getNext.SortIndex ?? 1;
getGoodsItem.NextOperaterManId = getNext.OperaterId;
getGoodsItem.NextUnitId = getNext.UnitIds;
}
}
}
return getGoodsItem;
}
}
#region
/// <summary>
/// 获取物资明细
/// </summary>
/// <returns></returns>
public static List<Model.GoodsManageItemItem> getItemList(string goodsManageId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
return (from x in db.CostGoods_GoodsManageItem
where x.GoodsManageId == goodsManageId
orderby x.GoodsName
select new Model.GoodsManageItemItem
{
GoodsManageItemId = x.GoodsManageItemId,
GoodsManageId = x.GoodsManageId,
GoodsName = x.GoodsName,
GoodsCounts = x.GoodsCounts,
CountingUnit = x.CountingUnit,
}).ToList();
}
}
#endregion
#region
/// <summary>
/// 获取物资明细
/// </summary>
/// <returns></returns>
public static List<Model.FlowOperateItem> getFlowOperateItemList(string goodsManageId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
return (from x in db.CostGoods_GoodsManageFlowOperate
where x.GoodsManageId == goodsManageId
orderby x.SortIndex
select new Model.FlowOperateItem
{
FlowOperateId = x.FlowOperateId,
DataId = x.GoodsManageId,
SortIndex = x.SortIndex ?? 0,
AuditFlowName = x.OperateName,
OperaterId = x.OperaterId,
OperaterName=UserService.GetUserNameByUserId(x.OperaterId),
OperaterTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.OperaterTime),
IsAgree=x.IsAgree,
Opinion=x.Opinion,
}).ToList();
}
}
#endregion
#region
/// <summary>
/// 获取当前办理步骤
/// </summary>
/// <param name="goodsManageId"></param>
/// <returns></returns>
public static Model.CostGoods_GoodsManageFlowOperate getFlowOperate(string goodsManageId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
return (from x in db.CostGoods_GoodsManageFlowOperate
where x.GoodsManageId == goodsManageId && !x.OperaterTime.HasValue
orderby x.SortIndex
select x).FirstOrDefault();
}
}
#endregion
#region
/// <summary>
/// 获取下一步办理步骤
/// </summary>
/// <param name="goodsManageId"></param>
/// <returns></returns>
public static Model.CostGoods_GoodsManageFlowOperate getNextFlowOperate(string goodsManageId,int sortIndex)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
return (from x in db.CostGoods_GoodsManageFlowOperate
where x.GoodsManageId == goodsManageId && x.SortIndex == sortIndex +1
orderby x.SortIndex
select x).FirstOrDefault();
}
}
#endregion
#endregion
#region projectId获取物质出门列表
/// <summary>
/// 记录数
/// </summary>
public static int getGoodsManageListCount
{
get;
set;
}
/// <summary>
/// 根据projectId获取物质出门列表
/// </summary>
/// <param name="projectId"></param>
/// <param name="states">状态0-待提交1-审核中2-审核完成;-1作废</param>
/// <returns></returns>
public static List<Model.GoodsManageItem> getGoodsManageByProjectIdStates(string projectId, string states, int pageIndex)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getData = from x in db.CostGoods_GoodsManage
where x.ProjectId == projectId
select x;
if (!string.IsNullOrEmpty(states))
{
getData = getData.Where(x => x.States == states);
}
getGoodsManageListCount = getData.Count();
if (getGoodsManageListCount == 0)
{
return null;
}
else
{
var getDataItem = from x in getData
orderby x.ApplyTime descending
select new Model.GoodsManageItem
{
GoodsManageId = x.GoodsManageId,
ProjectId = x.ProjectId,
ApplyUnitId = x.ApplyUnitId,
ApplyUnitName = db.Base_Unit.First(u => u.UnitId == x.ApplyUnitId).UnitName,
ApplyManId = x.ApplyManId,
ApplyManName = db.Sys_User.First(u => u.UserId == x.ApplyManId).UserName,
ApplyTime = string.Format("{0:yyyy-MM-dd}", x.ApplyTime),
OutReasons = x.OutReasons,
CarNum = x.CarNum,
BeBack = x.BeBack ?? false,
BackTime = string.Format("{0:yyyy-MM-dd}", x.BackTime),
};
if (pageIndex > 0)
{
return getDataItem.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
}
else
{
return getDataItem.ToList();
}
}
}
}
#endregion
#region GoodsManage
/// <summary>
/// 保存GoodsManage
/// </summary>
/// <param name="goodsManage">物质出门信息</param>
/// <returns></returns>
public static void SaveGoodsManage(Model.GoodsManageItem goodsManage)
{
Model.SGGLDB db = Funs.DB;
Model.CostGoods_GoodsManage newGoods = new Model.CostGoods_GoodsManage
{
GoodsManageId = goodsManage.GoodsManageId,
ProjectId = goodsManage.ProjectId,
ApplyUnitId = goodsManage.ApplyUnitId == "" ? null : goodsManage.ApplyUnitId,
ApplyManId = goodsManage.ApplyManId == "" ? null : goodsManage.ApplyManId,
ApplyTime = Funs.GetNewDateTime(goodsManage.ApplyTime),
OutReasons = goodsManage.OutReasons,
CarNum = goodsManage.CarNum,
BeBack = goodsManage.BeBack,
BackTime = Funs.GetNewDateTime(goodsManage.BackTime),
States = goodsManage.States,
NextManId = goodsManage.NextOperaterManId,
};
var updateDate = db.CostGoods_GoodsManage.FirstOrDefault(x => x.GoodsManageId == goodsManage.GoodsManageId);
if (updateDate == null)
{
newGoods.States = "1";
goodsManage.GoodsManageId = newGoods.GoodsManageId = SQLHelper.GetNewID();
db.CostGoods_GoodsManage.InsertOnSubmit(newGoods);
db.SubmitChanges();
var getSets = from x in db.CostGoods_GoodsManageFlowOperateSet select x;
foreach (var setItem in getSets)
{
Model.CostGoods_GoodsManageFlowOperate newFlowOperate = new Model.CostGoods_GoodsManageFlowOperate
{
FlowOperateId = SQLHelper.GetNewID(),
GoodsManageId = goodsManage.GoodsManageId,
SortIndex = setItem.SortIndex,
OperateName=setItem.OperateName,
};
if (setItem.UnitType == "1")
{
newFlowOperate.UnitIds = Const.UnitId_TCC;
}
else
{
newFlowOperate.UnitIds = newGoods.ApplyUnitId;
}
if (newFlowOperate.SortIndex == 0)
{
newFlowOperate.OperaterId = newGoods.ApplyManId;
newFlowOperate.OperaterTime = newGoods.ApplyTime;
newFlowOperate.IsAgree = true;
}
else if (newFlowOperate.SortIndex == 1)
{
newFlowOperate.OperaterId = newGoods.NextManId;
}
db.CostGoods_GoodsManageFlowOperate.InsertOnSubmit(newFlowOperate);
db.SubmitChanges();
}
}
else
{
if (goodsManage.IsAgree == false)
{
newGoods.States = "-1";
newGoods.NextManId = null;
}
else if (!goodsManage.NextSortIndex.HasValue)
{
newGoods.States = "2";
newGoods.NextManId = null;
}
GoodsManageService.UpdateGoodsManage(newGoods);
var getNow = db.CostGoods_GoodsManageFlowOperate.FirstOrDefault(x => x.GoodsManageId == newGoods.GoodsManageId && x.SortIndex ==goodsManage.SortIndex);
if (getNow != null)
{
getNow.OperaterTime = DateTime.Now;
getNow.IsAgree = goodsManage.IsAgree;
getNow.Opinion = goodsManage.Opinion;
db.SubmitChanges();
}
if (goodsManage.NextSortIndex.HasValue)
{
var getNext = db.CostGoods_GoodsManageFlowOperate.FirstOrDefault(x => x.GoodsManageId == newGoods.GoodsManageId && x.SortIndex ==goodsManage.NextSortIndex);
if (getNext != null)
{
getNext.OperaterId = goodsManage.NextOperaterManId;
db.SubmitChanges();
}
}
}
////删除明细
var gItems = from x in db.CostGoods_GoodsManageItem where x.GoodsManageId == goodsManage.GoodsManageId select x;
if (gItems.Count() > 0)
{
db.CostGoods_GoodsManageItem.DeleteAllOnSubmit(gItems);
db.SubmitChanges();
}
///// 新增明细
var getItemList = goodsManage.GoodsManageItemItemList;
if (goodsManage.GoodsManageItemItemList != null && getItemList.Count() > 0)
{
foreach (var item in getItemList)
{
Model.CostGoods_GoodsManageItem newGItem = new Model.CostGoods_GoodsManageItem
{
GoodsManageItemId = SQLHelper.GetNewID(),
GoodsManageId = goodsManage.GoodsManageId,
GoodsName = item.GoodsName,
GoodsCounts = item.GoodsCounts,
CountingUnit = item.CountingUnit,
};
db.CostGoods_GoodsManageItem.InsertOnSubmit(newGItem);
db.SubmitChanges();
}
}
if (!string.IsNullOrEmpty(goodsManage.AttachUrl))
{
APIUpLoadFileService.SaveAttachUrl(Const.GoodsManageMenuId, newGoods.GoodsManageId, goodsManage.AttachUrl, "0");
}
}
#endregion
}
}