2024-08-15 14:56:34 +08:00
|
|
|
|
using Model;
|
2025-06-04 22:46:21 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2023-06-06 17:01:34 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-06-04 22:46:21 +08:00
|
|
|
|
using System.IO;
|
2022-09-05 16:36:31 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BLL
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 安全费用管理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class CostManageService
|
|
|
|
|
|
{
|
2025-06-04 22:46:21 +08:00
|
|
|
|
|
2022-09-05 16:36:31 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据主键获取安全费用管理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManageId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static Model.CostGoods_CostManage GetCostManageById(string costManageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Funs.DB.CostGoods_CostManage.FirstOrDefault(e => e.CostManageId == costManageId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-06-06 17:01:34 +08:00
|
|
|
|
/// 获取 已支付的HSE费用
|
2022-09-05 16:36:31 +08:00
|
|
|
|
/// </summary>
|
2023-06-06 17:01:34 +08:00
|
|
|
|
/// <param name="ProjectId"></param>
|
|
|
|
|
|
/// <param name="UnitId"></param>
|
2022-09-05 16:36:31 +08:00
|
|
|
|
/// <returns></returns>
|
2025-06-04 22:46:21 +08:00
|
|
|
|
public static decimal GetSumHSECost(string ProjectId, string UnitId, string costManageId)
|
2022-09-05 16:36:31 +08:00
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal sumCost = 0;
|
2025-06-04 22:46:21 +08:00
|
|
|
|
var getData = from x in db.CostGoods_CostManage
|
2023-06-06 17:01:34 +08:00
|
|
|
|
where x.ProjectId == ProjectId && x.UnitId == UnitId && x.States == Const.State_2 && x.CostManageId != costManageId
|
|
|
|
|
|
select x;
|
|
|
|
|
|
if (getData.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
sumCost = getData.Sum(x => x.SumMoney ?? 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sumCost;
|
|
|
|
|
|
}
|
2022-09-05 16:36:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加安全费用管理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManage"></param>
|
|
|
|
|
|
public static void AddCostManage(Model.CostGoods_CostManage costManage)
|
|
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
2022-09-05 16:36:31 +08:00
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
Model.CostGoods_CostManage newCostManage = new Model.CostGoods_CostManage
|
|
|
|
|
|
{
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
ProjectId = costManage.ProjectId,
|
|
|
|
|
|
CostManageCode = costManage.CostManageCode,
|
|
|
|
|
|
CostManageName = costManage.CostManageName,
|
|
|
|
|
|
UnitId = costManage.UnitId,
|
|
|
|
|
|
ContractNum = costManage.ContractNum,
|
|
|
|
|
|
CostManageDate = costManage.CostManageDate,
|
|
|
|
|
|
Opinion = costManage.Opinion,
|
|
|
|
|
|
SubCN = costManage.SubCN,
|
|
|
|
|
|
SubHSE = costManage.SubHSE,
|
|
|
|
|
|
SubProject = costManage.SubProject,
|
|
|
|
|
|
States = costManage.States,
|
|
|
|
|
|
CompileMan = costManage.CompileMan,
|
2023-06-13 16:30:08 +08:00
|
|
|
|
CompileDate = costManage.CompileDate,
|
2025-06-04 22:46:21 +08:00
|
|
|
|
NextManId = costManage.NextManId,
|
2023-06-06 17:01:34 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
db.CostGoods_CostManage.InsertOnSubmit(newCostManage);
|
|
|
|
|
|
db.SubmitChanges();
|
2025-06-04 22:46:21 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
AddCostManageFlowOperate(newCostManage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-05 16:36:31 +08:00
|
|
|
|
CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectCostManageMenuId, costManage.ProjectId, null, costManage.CostManageId, costManage.CompileDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改费用管理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManage"></param>
|
|
|
|
|
|
public static void UpdateCostManage(Model.CostGoods_CostManage costManage)
|
|
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
2022-09-05 16:36:31 +08:00
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
Model.CostGoods_CostManage newCostManage = db.CostGoods_CostManage.FirstOrDefault(e => e.CostManageId == costManage.CostManageId);
|
|
|
|
|
|
if (newCostManage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//newCostManage.ProjectId = costManage.ProjectId;
|
|
|
|
|
|
newCostManage.CostManageName = costManage.CostManageName;
|
|
|
|
|
|
newCostManage.UnitId = costManage.UnitId;
|
|
|
|
|
|
newCostManage.ContractNum = costManage.ContractNum;
|
|
|
|
|
|
newCostManage.CostManageDate = costManage.CostManageDate;
|
|
|
|
|
|
newCostManage.Opinion = costManage.Opinion;
|
|
|
|
|
|
newCostManage.SubCN = costManage.SubCN;
|
|
|
|
|
|
newCostManage.SubHSE = costManage.SubHSE;
|
|
|
|
|
|
newCostManage.SubProject = costManage.SubProject;
|
|
|
|
|
|
newCostManage.States = costManage.States;
|
|
|
|
|
|
newCostManage.CompileMan = costManage.CompileMan;
|
|
|
|
|
|
newCostManage.CompileDate = costManage.CompileDate;
|
2023-06-13 16:30:08 +08:00
|
|
|
|
newCostManage.NextManId = costManage.NextManId;
|
2023-06-06 17:01:34 +08:00
|
|
|
|
db.SubmitChanges();
|
2025-11-17 20:31:53 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
}
|
2022-09-05 16:36:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据主键删除费用管理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManageId"></param>
|
|
|
|
|
|
public static void DeleteCostManageById(string costManageId)
|
|
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
2022-09-05 16:36:31 +08:00
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
var costManage = db.CostGoods_CostManage.FirstOrDefault(e => e.CostManageId == costManageId);
|
|
|
|
|
|
if (costManage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deleteCostManageFlowOperate(costManageId);
|
|
|
|
|
|
CommonService.DeleteAttachFileById(costManageId);//删除附件
|
|
|
|
|
|
db.CostGoods_CostManage.DeleteOnSubmit(costManage);
|
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 按照明细取当前单据总费用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManageId"></param>
|
|
|
|
|
|
public static void UpdateSumMoney(string costManageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var costManage = db.CostGoods_CostManage.FirstOrDefault(e => e.CostManageId == costManageId);
|
|
|
|
|
|
if (costManage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal sumC = 0;
|
|
|
|
|
|
var getItems = db.CostGoods_CostManageItem.Where(x => x.CostManageId == costManageId);
|
|
|
|
|
|
if (getItems.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
sumC = getItems.Sum(x => x.PriceMoney ?? 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
costManage.SumMoney = sumC;
|
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据主表ID获取审核列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManageId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static List<Model.CostGoods_CostManageFlowOperate> getCostManageFlowOperateList(string costManageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (from x in Funs.DB.CostGoods_CostManageFlowOperate
|
|
|
|
|
|
where x.CostManageId == costManageId
|
|
|
|
|
|
orderby x.SortIndex
|
|
|
|
|
|
select x).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前步骤审核人
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManageId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static Model.CostGoods_CostManageFlowOperate getNowCostManageFlowOperateList(string costManageId)
|
2025-06-04 22:46:21 +08:00
|
|
|
|
{
|
2023-06-06 17:01:34 +08:00
|
|
|
|
var getAllNoClose = Funs.DB.CostGoods_CostManageFlowOperate.Where(x => x.CostManageId == costManageId && (x.IsClosed == null || x.IsClosed == false));
|
|
|
|
|
|
if (getAllNoClose.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var minSortIndex = getAllNoClose.Min(x => x.SortIndex) ?? 0;
|
|
|
|
|
|
return getAllNoClose.FirstOrDefault(x => x.SortIndex == minSortIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取下一步审核人
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costManageId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-06-04 22:46:21 +08:00
|
|
|
|
public static Model.CostGoods_CostManageFlowOperate getNextCostManageFlowOperateList(string costManageId, string operaterId)
|
2023-06-06 17:01:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
int minSortIndex = 1;
|
2025-06-04 22:46:21 +08:00
|
|
|
|
var getAllNoClose = Funs.DB.CostGoods_CostManageFlowOperate.Where(x => x.CostManageId == costManageId && (x.IsClosed == null || x.IsClosed == false));
|
2023-06-06 17:01:34 +08:00
|
|
|
|
if (getAllNoClose.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var getFlowOperate = getAllNoClose.Where(x => x.OperaterId == operaterId);
|
|
|
|
|
|
if (getFlowOperate.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
minSortIndex = (getFlowOperate.Min(x => x.SortIndex) ?? 0) + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
minSortIndex = getAllNoClose.Min(x => x.SortIndex) ?? 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return getAllNoClose.FirstOrDefault(x => x.SortIndex == minSortIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-06-04 22:46:21 +08:00
|
|
|
|
return null;
|
2023-06-06 17:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据新增费用申请表 自动生成审核流程表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void AddCostManageFlowOperate(Model.CostGoods_CostManage costManage)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
|
|
|
|
|
List<Model.CostGoods_CostManageFlowOperate> flowList = new List<CostGoods_CostManageFlowOperate>();
|
|
|
|
|
|
/// 施工单位
|
|
|
|
|
|
if (ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(costManage.ProjectId, costManage.UnitId))
|
|
|
|
|
|
{
|
|
|
|
|
|
string cUnitId = Const.UnitId_SEDIN;
|
|
|
|
|
|
var getUnit = db.Project_ProjectUnit.FirstOrDefault(x => x.ProjectId == costManage.ProjectId && x.UnitType == Const.ProjectUnitType_1);
|
|
|
|
|
|
if (getUnit != null && !string.IsNullOrEmpty(getUnit.UnitId))
|
|
|
|
|
|
{
|
|
|
|
|
|
cUnitId = getUnit.UnitId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//// 分包单位项目经理审批、总包单位HSE经理审核、总包单位项目控制经理审核、总包单位项目经理审批
|
|
|
|
|
|
var Flow1 = new CostGoods_CostManageFlowOperate()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowOperateId = SQLHelper.GetNewID(),
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
AuditFlowName = "分包单位项目经理审批",
|
|
|
|
|
|
SortIndex = 1,
|
|
|
|
|
|
UnitId = costManage.UnitId,
|
|
|
|
|
|
IsClosed = false,
|
|
|
|
|
|
};
|
|
|
|
|
|
flowList.Add(Flow1);
|
|
|
|
|
|
|
|
|
|
|
|
var Flow2 = new CostGoods_CostManageFlowOperate()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowOperateId = SQLHelper.GetNewID(),
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
AuditFlowName = "总包单位HSE经理审核",
|
|
|
|
|
|
SortIndex = 2,
|
|
|
|
|
|
UnitId = cUnitId,
|
|
|
|
|
|
IsClosed = false,
|
|
|
|
|
|
};
|
|
|
|
|
|
flowList.Add(Flow2);
|
|
|
|
|
|
|
|
|
|
|
|
var Flow3 = new CostGoods_CostManageFlowOperate()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowOperateId = SQLHelper.GetNewID(),
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
AuditFlowName = "总包单位项目控制经理审核",
|
|
|
|
|
|
SortIndex = 3,
|
|
|
|
|
|
UnitId = cUnitId,
|
|
|
|
|
|
IsClosed = false,
|
|
|
|
|
|
};
|
|
|
|
|
|
flowList.Add(Flow3);
|
|
|
|
|
|
|
|
|
|
|
|
var Flow4 = new CostGoods_CostManageFlowOperate()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowOperateId = SQLHelper.GetNewID(),
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
AuditFlowName = "总包单位项目经理审批",
|
|
|
|
|
|
SortIndex = 4,
|
|
|
|
|
|
UnitId = cUnitId,
|
|
|
|
|
|
IsClosed = false,
|
|
|
|
|
|
};
|
|
|
|
|
|
flowList.Add(Flow4);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else ///非施工单位
|
|
|
|
|
|
{
|
|
|
|
|
|
////安全工程师发起、安全经理审核、项目经理批准
|
|
|
|
|
|
var Flow1 = new CostGoods_CostManageFlowOperate()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowOperateId = SQLHelper.GetNewID(),
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
AuditFlowName = "安全经理审核",
|
|
|
|
|
|
SortIndex = 1,
|
|
|
|
|
|
UnitId = costManage.UnitId,
|
|
|
|
|
|
IsClosed = false,
|
|
|
|
|
|
};
|
|
|
|
|
|
flowList.Add(Flow1);
|
|
|
|
|
|
|
|
|
|
|
|
var Flow2 = new CostGoods_CostManageFlowOperate()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowOperateId = SQLHelper.GetNewID(),
|
|
|
|
|
|
CostManageId = costManage.CostManageId,
|
|
|
|
|
|
AuditFlowName = "项目经理批准",
|
|
|
|
|
|
SortIndex = 2,
|
|
|
|
|
|
UnitId = costManage.UnitId,
|
|
|
|
|
|
IsClosed = false,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
flowList.Add(Flow2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (flowList.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CostGoods_CostManageFlowOperate.InsertAllOnSubmit(flowList);
|
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 审核意见更新
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="flow"></param>
|
|
|
|
|
|
public static void updateCostManageFlowOperate(Model.CostGoods_CostManageFlowOperate flow)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var getData = db.CostGoods_CostManageFlowOperate.FirstOrDefault(x => x.FlowOperateId == flow.FlowOperateId);
|
|
|
|
|
|
if (getData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
getData.OperaterId = flow.OperaterId;
|
|
|
|
|
|
getData.OperaterTime = flow.OperaterTime;
|
|
|
|
|
|
getData.IsAgree = flow.IsAgree;
|
|
|
|
|
|
getData.Opinion = flow.Opinion;
|
|
|
|
|
|
getData.IsClosed = flow.IsClosed;
|
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所以关闭步骤 打开
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="flow"></param>
|
|
|
|
|
|
public static void updateOpenCostManageFlowOperate(string costManageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
2025-06-04 22:46:21 +08:00
|
|
|
|
var getDatas = db.CostGoods_CostManageFlowOperate.Where(x => x.CostManageId == costManageId && x.IsClosed == true);
|
|
|
|
|
|
foreach (var item in getDatas)
|
2023-06-06 17:01:34 +08:00
|
|
|
|
{
|
2025-06-04 22:46:21 +08:00
|
|
|
|
item.IsClosed = false;
|
2023-06-06 17:01:34 +08:00
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="costMangeId"></param>
|
|
|
|
|
|
public static void deleteCostManageFlowOperate(string costManageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var getData = db.CostGoods_CostManageFlowOperate.Where(x => x.CostManageId == costManageId);
|
|
|
|
|
|
if (getData.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CostGoods_CostManageFlowOperate.DeleteAllOnSubmit(getData);
|
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
2022-09-05 16:36:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-04 22:46:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-10-10 14:33:21 +08:00
|
|
|
|
public static string PushDataToHSE(string projectId, string contractNum, string costManageId)
|
2025-06-04 22:46:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string message = "";
|
|
|
|
|
|
// 查询当前合同所有审核通过的数据
|
|
|
|
|
|
var costData = from x in Funs.DB.CostGoods_CostManage
|
2025-06-18 10:38:46 +08:00
|
|
|
|
where x.ProjectId == projectId && x.ContractNum == contractNum && x.States == Const.State_2
|
|
|
|
|
|
orderby x.CostManageDate descending
|
|
|
|
|
|
select x;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
var projectModel = ProjectService.GetProjectByProjectId(projectId);
|
2025-06-18 10:38:46 +08:00
|
|
|
|
var contractModel = CostManageService.GetCostManageById(costManageId);
|
2025-07-03 18:42:35 +08:00
|
|
|
|
//decimal totalAmount = costData.Sum(x => x.SumMoney ?? 0);
|
2025-06-18 10:38:46 +08:00
|
|
|
|
var files = new List<object>();
|
2025-10-10 14:33:21 +08:00
|
|
|
|
if (contractModel != null)
|
|
|
|
|
|
{
|
2025-07-03 18:42:35 +08:00
|
|
|
|
var url = ConstValue.GetConstByConstText("PU_PUSH_URL")?.ConstValue;
|
|
|
|
|
|
if (string.IsNullOrEmpty(url))
|
2025-06-04 22:46:21 +08:00
|
|
|
|
{
|
2025-07-03 18:42:35 +08:00
|
|
|
|
message = "未配置推送接口地址";
|
|
|
|
|
|
return message;
|
2025-06-18 10:38:46 +08:00
|
|
|
|
|
2025-07-03 18:42:35 +08:00
|
|
|
|
}
|
2025-06-18 10:38:46 +08:00
|
|
|
|
var requestGetTokenUrl = url + "/auth/getToken";
|
|
|
|
|
|
string requestGetTokenBody = "{\"username\": \"coadmin\",\"password\": \"coadminPu@2025\"}";
|
2025-06-04 22:46:21 +08:00
|
|
|
|
var response = Funs.RequestPost(requestGetTokenUrl, "", requestGetTokenBody);
|
|
|
|
|
|
var responseStr = JsonConvert.DeserializeObject<JObject>(response);
|
2025-06-18 10:38:46 +08:00
|
|
|
|
APICommonService.SaveSysHttpLog("PU_Token", requestGetTokenUrl, response);
|
|
|
|
|
|
|
|
|
|
|
|
if (responseStr == null || responseStr["code"]?.ToString() != "200" || responseStr["data"] == null)
|
2025-06-04 22:46:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
message = "获取Pu系统Token失败";
|
2025-06-18 10:38:46 +08:00
|
|
|
|
return message;
|
|
|
|
|
|
}
|
2025-06-04 22:46:21 +08:00
|
|
|
|
|
2025-06-18 10:38:46 +08:00
|
|
|
|
string accessToken = responseStr["data"]["token"]?.ToString();
|
|
|
|
|
|
if (string.IsNullOrEmpty(accessToken))
|
|
|
|
|
|
{
|
|
|
|
|
|
message = "获取Pu系统Token失败,Token为空";
|
|
|
|
|
|
return message;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
}
|
2025-06-18 10:38:46 +08:00
|
|
|
|
Dictionary<string, string> headers = new Dictionary<string, string>();
|
|
|
|
|
|
headers.Add("Authorization", "Bearer " + accessToken);
|
2025-07-03 18:42:35 +08:00
|
|
|
|
#region 先获取当前费用是否已经推送过
|
|
|
|
|
|
var getRequestUrl = url + "/pu_api/payCraftAmountToHSE/get";
|
2025-11-17 20:31:53 +08:00
|
|
|
|
var getRequestbody = $"{{\"projectNumber\":\"{projectModel.ContractNo}\",\"contractNo\":\"{contractNum}\"}}";
|
2025-10-10 14:33:21 +08:00
|
|
|
|
APICommonService.SaveSysHttpLog("PU_GetPuPayCraftAmount", getRequestUrl, getRequestbody, "Requset");
|
2025-07-03 18:42:35 +08:00
|
|
|
|
var getResponse = Funs.RequestPost(getRequestUrl, headers, getRequestbody);
|
2025-10-10 14:33:21 +08:00
|
|
|
|
APICommonService.SaveSysHttpLog("PU_GetPuPayCraftAmount", getRequestUrl, getResponse, "Response");
|
|
|
|
|
|
var getResponseStr = JsonConvert.DeserializeObject<JObject>(getResponse);
|
2025-07-03 18:42:35 +08:00
|
|
|
|
if (getResponseStr == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
message = "推送数据到HSE系统失败";
|
|
|
|
|
|
return message;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (getResponseStr["code"]?.ToString() != "200")
|
|
|
|
|
|
{
|
|
|
|
|
|
message = getResponseStr["message"]?.ToString();
|
|
|
|
|
|
return message;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
var getResponseOutput = JsonConvert.DeserializeObject<List<PuGetApiOutput>>(getResponseStr["data"]?.ToString());
|
|
|
|
|
|
if (getResponseOutput.Any() && getResponseOutput.Count(x => x.itemNo == costManageId) > 0)
|
2025-07-03 18:42:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
message = "当前费用已推送,无需重复推送!";
|
|
|
|
|
|
return message;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 推送数据至Pu
|
2025-06-18 10:38:46 +08:00
|
|
|
|
var requestUrl = url + "/pu_api/payCraftAmountToHSE/add";
|
2025-07-03 18:42:35 +08:00
|
|
|
|
// 构建请求体
|
|
|
|
|
|
var fileDetails = GetBase64FilesWithDetails(contractModel.CostManageId);
|
|
|
|
|
|
if (fileDetails != null && fileDetails.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
files.AddRange(fileDetails);
|
|
|
|
|
|
}
|
|
|
|
|
|
List<PuAddApiInput> puAddApiInputs = new List<PuAddApiInput>()
|
|
|
|
|
|
{
|
|
|
|
|
|
new PuAddApiInput()
|
|
|
|
|
|
{
|
2025-11-17 20:31:53 +08:00
|
|
|
|
projectNumber = projectModel.ContractNo,
|
2025-07-03 18:42:35 +08:00
|
|
|
|
itemId= costManageId,
|
|
|
|
|
|
contractNo = contractNum,
|
|
|
|
|
|
amountHSE = contractModel.SumMoney.ToString(),
|
2025-10-10 14:33:21 +08:00
|
|
|
|
files = files
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-07-03 18:42:35 +08:00
|
|
|
|
var jsonBody = JsonConvert.SerializeObject(puAddApiInputs);
|
2025-06-18 10:38:46 +08:00
|
|
|
|
APICommonService.SaveSysHttpLog("PU_AddPuPayCraftAmount", requestUrl, jsonBody, "Requset");
|
|
|
|
|
|
var responseHSE = Funs.RequestPost(requestUrl, headers, jsonBody);
|
2025-06-04 22:46:21 +08:00
|
|
|
|
var responseHSEStr = JsonConvert.DeserializeObject<JObject>(responseHSE);
|
2025-06-18 10:38:46 +08:00
|
|
|
|
APICommonService.SaveSysHttpLog("PU_AddPuPayCraftAmount", requestUrl, responseHSE, "Response");
|
|
|
|
|
|
if (responseHSEStr == null)
|
2025-06-04 22:46:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
message = "推送数据到HSE系统失败";
|
2025-06-18 10:38:46 +08:00
|
|
|
|
return message;
|
|
|
|
|
|
}
|
2025-10-10 14:33:21 +08:00
|
|
|
|
else if (string.IsNullOrEmpty(responseHSEStr["code"]?.ToString()))
|
2025-07-03 18:42:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
message = responseHSE;
|
|
|
|
|
|
return message;
|
|
|
|
|
|
}
|
2025-06-18 10:38:46 +08:00
|
|
|
|
else if (responseHSEStr["code"]?.ToString() != "200")
|
|
|
|
|
|
{
|
|
|
|
|
|
message = responseHSEStr["message"]?.ToString();
|
|
|
|
|
|
return message;
|
|
|
|
|
|
}
|
2025-10-10 14:33:21 +08:00
|
|
|
|
else
|
2025-06-18 10:38:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
message = "";
|
|
|
|
|
|
return message;
|
2025-06-04 22:46:21 +08:00
|
|
|
|
}
|
2025-07-03 18:42:35 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-06-04 22:46:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-18 10:38:46 +08:00
|
|
|
|
return message;
|
2025-06-04 22:46:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 记录错误日志
|
|
|
|
|
|
ErrLogInfo.WriteLog(ex.Message, ex.StackTrace);
|
2025-06-18 10:38:46 +08:00
|
|
|
|
return "推送数据失败";
|
2025-06-04 22:46:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取Base64编码的附件文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static List<object> GetBase64FilesWithDetails(string costManageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = new List<object>();
|
|
|
|
|
|
// 获取费用管理信息
|
|
|
|
|
|
var costManage = GetCostManageById(costManageId);
|
2025-07-03 18:42:35 +08:00
|
|
|
|
var costItem = BLL.CostManageItemService.GetCostManageItemByCostManageId(costManageId);
|
|
|
|
|
|
foreach (var item in costItem)
|
|
|
|
|
|
{ // 获取附件文件
|
|
|
|
|
|
var attachments = AttachFileService.getFileUrl(item.CostManageItemId);
|
2025-06-04 22:46:21 +08:00
|
|
|
|
|
2025-07-03 18:42:35 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(attachments))
|
2025-06-04 22:46:21 +08:00
|
|
|
|
{
|
2025-07-03 18:42:35 +08:00
|
|
|
|
string[] filePaths = attachments.Split(',');
|
|
|
|
|
|
foreach (var filePath in filePaths)
|
2025-06-18 10:38:46 +08:00
|
|
|
|
{
|
2025-07-03 18:42:35 +08:00
|
|
|
|
string fullPath = Funs.RootPath + filePath;
|
|
|
|
|
|
if (File.Exists(fullPath))
|
2025-06-18 10:38:46 +08:00
|
|
|
|
{
|
2025-07-03 18:42:35 +08:00
|
|
|
|
FileInfo file = new FileInfo(fullPath);
|
|
|
|
|
|
byte[] fileBytes = File.ReadAllBytes(fullPath);
|
|
|
|
|
|
string base64Content = Convert.ToBase64String(fileBytes);
|
|
|
|
|
|
|
|
|
|
|
|
result.Add(new Model.PuPayCraftAmountFileInput
|
|
|
|
|
|
{
|
|
|
|
|
|
name = file.Name,
|
|
|
|
|
|
content = base64Content,
|
|
|
|
|
|
thisamount = item?.PriceMoney?.ToString() ?? "0",
|
|
|
|
|
|
date = costManage?.CompileDate?.ToString("yyyy-MM-dd") ?? DateTime.Now.ToString("yyyy-MM-dd")
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
continue;//只取第一个文件
|
2025-10-10 14:33:21 +08:00
|
|
|
|
}
|
2025-06-18 10:38:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-04 22:46:21 +08:00
|
|
|
|
}
|
2025-06-18 10:38:46 +08:00
|
|
|
|
|
2025-10-10 14:33:21 +08:00
|
|
|
|
|
2025-07-03 18:42:35 +08:00
|
|
|
|
|
2025-06-04 22:46:21 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2025-06-18 10:38:46 +08:00
|
|
|
|
|
2022-09-05 16:36:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|