# Conflicts:
#	FactorySystemApi/Controllers/ViewController.cs
master
Yang 3 years ago
commit 2d515ed0c9

@ -18,7 +18,7 @@ namespace FactorySystemApi.Controllers
[UserLoginFilter]
public class MaterialTaskController : ApiController
{
private readonly MaterialTaskBll _taskBll = new MaterialTaskBll();
private readonly MaterialTaskBll MaterialTaskBll = new MaterialTaskBll();
/// <summary>
/// 根据当前用户获取任务列表
@ -35,7 +35,7 @@ namespace FactorySystemApi.Controllers
}
apiResult.Data = new
{
List = _taskBll.GetList(mtq, out var totalNumber),
List = MaterialTaskBll.GetList(mtq, out var totalNumber),
Total = totalNumber
};
}, apiResult, Request);

@ -15,6 +15,7 @@ using FactorySystemApi.Plm_Formula;
using System.Linq;
using SqlSugar;
using FactorySystemModel.RequestModel;
using System.Web.Http.Results;
namespace FactorySystemApi.Controllers
{
@ -29,17 +30,13 @@ namespace FactorySystemApi.Controllers
/// </summary>
public readonly BaseBll BaseBll = new BaseBll();
/// <summary>
/// 数据处理层-物料处理
/// </summary>
public readonly MaterialBll MaterialBll = new MaterialBll();
/// <summary>
/// 数据处理层-视图处理
/// 数据处理层-路线处理
/// </summary>
public readonly ViewBll ViewBll = new ViewBll();
private readonly MaterialTeamworkBll MaterialTeamworkBll = new MaterialTeamworkBll();
/// <summary>
/// 数据处理层-路线处理
/// 数据处理层-任务处理
/// </summary>
private readonly MaterialTeamworkBll _taskBll = new MaterialTeamworkBll();
private readonly MaterialTaskBll MaterialTaskBll = new MaterialTaskBll();
/// <summary>
/// 事项操作日志
/// </summary>
@ -55,7 +52,7 @@ namespace FactorySystemApi.Controllers
/// 新增物料路线
/// </summary>
[HttpPost]
public ApiResult InsertDataModel(Dictionary<string, object> inParam)
public ApiResult CreateMaterial(Dictionary<string, object> inParam)
{
ApiResult apiResult = new ApiResult();
return ExceptionHelper.TryReturnException(() =>
@ -64,7 +61,6 @@ namespace FactorySystemApi.Controllers
TFS_Factory factory = BaseBll.GetTempModel<TFS_Factory>(int.Parse(inParam["FCreateFactoryID"].ToString()));
Dictionary<string, int> result = new Dictionary<string, int>();
//inParam.Add("FMdmCode", GetMdmCode(inParam));
inParam.Remove("FID");
string materialName = inParam["FMaterialName"].ToString();
@ -144,14 +140,14 @@ namespace FactorySystemApi.Controllers
TFS_FMaterialTeamwork teamwork = BaseBll.GetTempModel<TFS_FMaterialTeamwork>(teamId);
// 创建物料和物料视图
Dictionary<string, int> materialInfo = CreateMaterial(inParam, factory, teamwork);
Dictionary<string, int> materialInfo = CreateMaterialData(inParam, factory, teamwork);
foreach(string key in materialInfo.Keys)
{
result.Add(key, materialInfo[key]);
}
// 创建物料分类任务
int taskId = BaseBll.CreateMaterialTask(teamId, user.FID, 15, factory.FID);
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, user.FID, 0, factory.FID);
result.Add("TaskId", taskId);
}
}
@ -175,13 +171,109 @@ namespace FactorySystemApi.Controllers
}
apiResult.Data = new
{
List = _taskBll.GetList(mtq, out var totalNumber),
List = MaterialTeamworkBll.GetList(mtq, out var totalNumber),
Total = totalNumber
};
}, apiResult, Request);
}
private Dictionary<string, int> CreateMaterial(Dictionary<string, object> inParam, TFS_Factory factory, TFS_FMaterialTeamwork teamwork)
/// <summary>
/// 根据物料路线ID获取物料视图
/// </summary>
[HttpPost]
public ApiResult GetMaterialViewsByTeamId(Dictionary<string, object> inParam)
{
var apiResult = new ApiResult();
return ExceptionHelper.TryReturnException(() =>
{
if (Request.Properties["token"] is ApiAuthInfo user)
{
int teamId = int.Parse(inParam["teamId"].ToString());
int teamType = int.Parse(inParam["teamType"].ToString());
apiResult.Data = new
{
columns = MaterialTeamworkBll.GetColumns(),
rows = MaterialTeamworkBll.GetMaterialViewsByTeamId(teamId, teamType, user.FID, out List<int> materialId, true),
infos = MaterialTeamworkBll.GetMaterialInfoList(materialId, user.FID),
types = MaterialTeamworkBll.GetMaterialTypeList()
};
}
}, apiResult, Request, inParam);
}
/// <summary>
/// 更新物料
/// </summary>
[HttpPost]
public ApiResult UpdateMaterial(Dictionary<string, object> inParam)
{
var apiResult = new ApiResult();
return ExceptionHelper.TryReturnException(() => {
if (Request.Properties["token"] is ApiAuthInfo user)
{
inParam.TryGetValue("TFS_ViewMaterial", out object viewObj);
inParam.TryGetValue("TFS_Material", out object materialObj);
inParam.TryGetValue("TFS_MaterialInfo", out object infoObj);
List<Dictionary<string, object>> viewList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(viewObj));
List<Dictionary<string, object>> materialList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(materialObj));
List<Dictionary<string, object>> infoList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(infoObj));
int teamId = int.Parse(inParam["FTeamID"].ToString());
// 更新视图
MaterialTeamworkBll.UpdateMaterialViewById(viewList, user.FID, teamId);
// 更新物料
MaterialTeamworkBll.UpdateMaterialById(materialList, user.FID, teamId);
// 更新物料信息
MaterialTeamworkBll.UpdateMaterialInfoById(infoList, user.FID, teamId);
List<TFS_FMaterialTask> tasks = MaterialTaskBll.GetMaterialTasks(teamId);
if (tasks != null && tasks.Count == 1)
{
TFS_FMaterialTask task = tasks[0];
if (task.FType == 0)
{
// 结束物料分类任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 0);
// 创建物料编辑任务
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, user.FID, 1, task.FFactoryID);
}
}
else if (tasks.Count == 2)
{
TFS_FMaterialTask task = tasks.FindLast(t => t.FType == 1);
if (task != null)
{
// 结束物料编辑任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 1);
// 创建物料确认任务
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, user.FID, 2, task.FFactoryID);
}
}
else if (tasks.Count == 3)
{
TFS_FMaterialTask task = tasks.FindLast(t => t.FType == 2);
if (task != null)
{
// 结束物料确认任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 2);
MaterialTeamworkBll.CloseMaterialTeamwork(teamId, user.FID);
}
}
apiResult.Data = teamId;
}
}, apiResult, Request, inParam);
}
private Dictionary<string, int> CreateMaterialData(Dictionary<string, object> inParam, TFS_Factory factory, TFS_FMaterialTeamwork teamwork)
{
Dictionary<string, int> result = new Dictionary<string, int>();
// 创建物料(物料表新增数据)
@ -194,7 +286,7 @@ namespace FactorySystemApi.Controllers
material.FFactoryCode = factory.FCode; // 工厂标识
material.FTestCode = inParam["FTestCode"].ToString(); // 试验号
int materialId = MaterialBll.InsertMaterial(material);
int materialId = MaterialTeamworkBll.InsertMaterial(material);
result.Add("MaterialId", materialId);
@ -207,7 +299,7 @@ namespace FactorySystemApi.Controllers
viewMaterial.FAddDate = DateTime.Now; // 创建日期
viewMaterial.FTeamType = 1; // 路线类型
int vmId = ViewBll.InsertMaterialView(viewMaterial);
int vmId = MaterialTeamworkBll.InsertMaterialView(viewMaterial);
result.Add("ViewId", vmId);
// 创建委托工厂视图
@ -221,7 +313,7 @@ namespace FactorySystemApi.Controllers
viewMaterial.FAddDate = DateTime.Now; // 创建日期
viewMaterial.FTeamType = 1; // 路线类型
int prodVmId = ViewBll.InsertMaterialView(viewMaterial);
int prodVmId = MaterialTeamworkBll.InsertMaterialView(viewMaterial);
result.Add("ProdViewId", prodVmId);
}

@ -9,6 +9,8 @@ using Microsoft.Ajax.Utilities;
using Newtonsoft.Json;
using FactorySystemModel.EnumModel;
using Aspose.Cells;
using System.Globalization;
using System.Linq;
namespace FactorySystemApi.Controllers
{
@ -203,14 +205,14 @@ namespace FactorySystemApi.Controllers
}, apiResult, Request);
}
/// <summary>
/// 保存视图编辑的内容
/// 保存视图编辑的内容(物料新增条线)
/// </summary>
[HttpPost]
public ApiResult UpdateBatchById3(Dictionary<string, object> inParam)
public ApiResult UpdateMaterialViewById(Dictionary<string, object> inParam)
{
var apiResult = new ApiResult();
BaseBll BaseBll = new BaseBll();
return ExceptionHelper.TryReturnException(() =>
{
if (Request.Properties["token"] is ApiAuthInfo user)
@ -223,13 +225,13 @@ namespace FactorySystemApi.Controllers
List<Dictionary<string, object>> infoList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(infoObj));
int teamId = int.Parse(inParam["FTeamID"].ToString());
int viewType = int.Parse(inParam["FViewType"].ToString());
apiResult.Data = _viewBll.UpdateBatchById3(viewList, materialList, infoList, teamId, viewType, user.FID);
apiResult.Data = _viewBll.UpdateMaterialViewById(viewList, materialList, infoList, teamId, viewType, user.FID);
if (viewType == 10)
{
// 创建物料视图事项
TFS_HalfMaterialFTeamwork teamwork = BaseBll.GetTempModel<TFS_HalfMaterialFTeamwork>(teamId);
List<Dictionary<string, object>> vml = _viewBll.GetListByTeamId(teamId, viewType, user.FID, out List<int> materialId, out string FGuaranteePeriod, out string FStorageConditions, true);
TFS_FTeamwork teamwork = BaseBll.GetTempModel<TFS_FTeamwork>(teamId);
List<Dictionary<string, object>> vml = _viewBll.GetMaterialViewsByTeamId(teamId, viewType, 1, user.FID, out List<int> materialId, out string FGuaranteePeriod, out string FStorageConditions, !inParam.ContainsKey("FAllView"));
Dictionary<int, string> hasNewView = new Dictionary<int, string>();
if (vml != null)
@ -239,8 +241,6 @@ namespace FactorySystemApi.Controllers
int materialType = (int)(long)row["FViewType"];
string factoryId = row["FFactoryID"].ToString();
if (materialType == 2 || materialType == 3 || materialType == 4 || materialType == 5)
{
if (hasNewView.ContainsKey(materialType))
{
hasNewView[materialType] = hasNewView[materialType] + factoryId + ",";
@ -250,14 +250,18 @@ namespace FactorySystemApi.Controllers
hasNewView.Add(materialType, factoryId + ",");
}
}
hasNewView.OrderBy(s => s.Key);
string facoryIds = "";
foreach (var item in hasNewView)
{
//创建视图事项
string factorys = item.Value.Trim(',');
BaseBll.CreateTaskData(teamId, user.FID, "0", factorys);
facoryIds += factorys;
}
HalfMaterialTeamworkBll TeamworkBll = new HalfMaterialTeamworkBll();
TeamworkBll.CreateMaterialTask(hasNewView, teamwork, user.FID);
}
BaseBll.CreateTaskData2(teamId, user.FID, "3");
BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.HalfMaterialProcessType., 3, 2);
BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.HalfMaterialProcessType., 2, 1);
}
}
}, apiResult, Request);

@ -1,10 +1,12 @@
using FactorySystemCommon;
using FactorySystemModel.EnumModel;
using FactorySystemModel.RequestModel;
using FactorySystemModel.ResponseModel;
using FactorySystemModel.SqlSugarModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FactorySystemBll
{
@ -17,7 +19,7 @@ namespace FactorySystemBll
{
totalNumber = 0;
var db = AppSettingsHelper.GetSqlSugar();
return db.Queryable<TFS_FMaterialTask, TFS_FMaterialTeamwork>((a, b) => new JoinQueryInfos(JoinType.Inner, a.FMaterialTeamID == b.FID))
return db.Queryable<TFS_FMaterialTask, TFS_FMaterialTeamwork, TUser>((a, b, c) => new JoinQueryInfos(JoinType.Inner, a.FMaterialTeamID == b.FID, JoinType.Left, a.FAddUser == c.FID))
// 事项状态
.WhereIF(mtq.FState > 0 && mtq.FState != 99, (a, b) => a.FState == mtq.FState)
// 物料号
@ -31,8 +33,97 @@ namespace FactorySystemBll
//.WhereIF(mtq.FUserID != null, (a, b) => (',' + a.FUserID + ',').Contains(',' + mtq.FUserID + ',') || a.FAddUser.Equals(mtq.FUserID))
//// 协同
//.WhereIF(mtq.FMaterialTeamID > 0, (a, b) => a.FMaterialTeamID == mtq.FMaterialTeamID).OrderBy((a, b) => a.FID, OrderByType.Desc)
.Select<MaterialTaskRow>("a.*,b.FMaterialName,b.FMaterialCode,b.FTestCode,b.FMaterialType")
.Select<MaterialTaskRow>("a.*,b.FMaterialName,b.FMaterialCode,b.FTestCode,b.FMaterialType, c.FName as FAddUserName").OrderBy((a) => a.FID, OrderByType.Desc)
.ToPageList(mtq.FPageIndex, mtq.FPageSize, ref totalNumber);
}
public List<TFS_FMaterialTask> GetMaterialTasks(int teamId)
{
var db = AppSettingsHelper.GetSqlSugar();
List<TFS_FMaterialTask> tasks = db.Queryable<TFS_FMaterialTask>().Where(t => t.FMaterialTeamID == teamId).ToList();
return tasks;
}
/// <summary>
/// 创建物料新增事项
/// </summary>
public int CreateMaterialTask(int teamId, int userId, int type, int factoryId)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
int funcType = (int)Constant.RoleType.;
string tType = type == 0 ? "10" : "11";
int taskId = -1;
try
{
List<string> funcVal = db.Queryable<TBasicCode>().Where(s => s.FType == (int)Constant.BasicCode. && s.F1 == tType && s.FState == 1).Select(s => s.FValue).ToList();
List<TUser> users = db.Queryable<TUser, TRole_Right>((a, b) => new JoinQueryInfos(JoinType.Left, a.FRoleID == b.FRoleID))
.Where((a, b) => a.FState == 1 && a.FDeleted != 1 && b.FType == funcType && funcVal.Contains(b.FFunctionID.ToString()))
.Where(string.Format("a.FFactoryID in({0})", factoryId))
.GroupBy("a.FID,a.FFactoryID,a.FName,a.FUser").Select<TUser>("a.FID,a.FFactoryID,a.FName,a.FUser").ToList();
if (users.Count > 0)
{
TFS_FMaterialTask materialTask = new TFS_FMaterialTask();
materialTask.FMaterialTeamID = teamId;
materialTask.FType = type;
materialTask.FFactoryID = factoryId;
materialTask.FCanEdit = 1;
materialTask.FAddUser = userId;
materialTask.FAddDate = DateTime.Now;
materialTask.FState = 1;
if (type == 0)
{
materialTask.FName = "物料分类";
materialTask.FDesc = "物料分类选择";
}
else if (type == 1)
{
materialTask.FName = "物料视图";
materialTask.FDesc = "物料视图编辑";
}
else
{
materialTask.FName = "确认视图";
materialTask.FDesc = "物料视图确认";
}
materialTask.FUserID = string.Join(",", users.GroupBy(ss => ss.FID).Select(sss => sss.Key));
materialTask.FUserName = string.Join("、", users.GroupBy(ss => ss.FName).Select(sss => sss.Key));
taskId = db.Insertable(materialTask).IgnoreColumns(true).ExecuteReturnIdentity();
}
}
catch (Exception ex)
{
taskId = -1;
}
return taskId;
}
public int CloseMaterialTask(int teamId, int userId, int type)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_FMaterialTask> taskList = db.Queryable<TFS_FMaterialTask>().Where(s => s.FType == type && s.FMaterialTeamID == teamId && s.FState == 1).ToList();
int result = 0;
if (taskList != null && taskList.Count > 0)
{
TFS_FMaterialTask fmt = taskList[0];
fmt.FCanEdit = 2;
fmt.FState = 2;
fmt.FEditUser = userId;
fmt.FEditDate = DateTime.Now;
result = db.Updateable(fmt).IgnoreColumns(true).WhereColumns("FID").ExecuteCommand();
}
return result;
}
}
}

@ -1,10 +1,13 @@
using FactorySystemCommon;
using FactorySystemModel.EnumModel;
using FactorySystemModel.RequestModel;
using FactorySystemModel.ResponseModel;
using FactorySystemModel.SqlSugarModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using static FactorySystemModel.EnumModel.Constant;
namespace FactorySystemBll
{
@ -13,11 +16,11 @@ namespace FactorySystemBll
/// <summary>
/// 获取路线列表
/// </summary>
public List<TFS_FMaterialTeamwork> GetList(MaterialTeamworkQuery mtq, out int totalNumber)
public List<MaterialTeamworkRow> GetList(MaterialTeamworkQuery mtq, out int totalNumber)
{
totalNumber = 0;
var db = AppSettingsHelper.GetSqlSugar();
return db.Queryable<TFS_FMaterialTeamwork>()
return db.Queryable<TFS_FMaterialTeamwork, TUser>((a, b) => new JoinQueryInfos(JoinType.Left, a.FAddUser == b.FID))
// 事项状态
.WhereIF(mtq.FState > 0 && mtq.FState != 99, a => a.FState == mtq.FState)
// 物料号
@ -31,8 +34,270 @@ namespace FactorySystemBll
//.WhereIF(mtq.FUserID != null, (a, b) => (',' + a.FUserID + ',').Contains(',' + mtq.FUserID + ',') || a.FAddUser.Equals(mtq.FUserID))
//// 协同
//.WhereIF(mtq.FMaterialTeamID > 0, (a, b) => a.FMaterialTeamID == mtq.FMaterialTeamID).OrderBy((a, b) => a.FID, OrderByType.Desc)
.Select<TFS_FMaterialTeamwork>()
.Select<MaterialTeamworkRow>("a.* ,b.FName as FAddUserName").OrderBy((a) => a.FID, OrderByType.Desc)
.ToPageList(mtq.FPageIndex, mtq.FPageSize, ref totalNumber);
}
/// <summary>
/// 获取视图编辑列
/// </summary>
public List<Dictionary<string, object>> GetColumns()
{
List<TFS_ViewFieldInfo> fieldList = AppSettingsHelper.GetSqlSugar().Queryable<TFS_ViewFieldInfo>()
.Where(it => it.FType == (int)Constant.ViewType. || it.FType == (int)Constant.ViewType.)
.OrderBy(it => it.FType, OrderByType.Desc)
.OrderBy(it => it.FOrder)
.ToList();
List<Dictionary<string, object>> dicList = new List<Dictionary<string, object>>();
foreach (var field in fieldList)
{
Dictionary<string, object> dic = new Dictionary<string, object> { { "id", field.FID } };
string[] fArr = field.FField.Split('.');
dic.Add("key", fArr.Last());
dic.Add("table", fArr.First());
string[] nArr = field.FName.Split('.');
dic.Add("title", nArr.Last());
dic.Add("category", nArr.First());
dic.Add("width", field.FWidth);
dic.Add("align", field.FAlign);
dic.Add("dataType", field.FDataType);
if (field.FName.Equals("基本视图.大小/量纲(规格)") || field.FName.Equals("基本视图.毛重") || field.FName.Equals("基本视图.净重"))
{
dic.Add("fieldType", 7);
}
else
{
dic.Add("fieldType", field.FType);
}
dicList.Add(dic);
}
return dicList;
}
/// <summary>
/// 获取视图
/// </summary>
public List<Dictionary<string, object>> GetMaterialViewsByTeamId(int teamId, int teamType, int currUserId, out List<int> materialId, bool byFactory = true)
{
TUser currUser = null;
if (byFactory == true) currUser = BaseBll.GetTempModel<TUser>(currUserId, "FFactoryID");
var db = AppSettingsHelper.GetSqlSugar();
List<Dictionary<string, object>> viewList = new List<Dictionary<string, object>>();
viewList = db.Queryable<TFS_ViewMaterial, TFS_Material>((a, b) =>
new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID))
.Where((a, b) => a.FTeamID == teamId)
.Where((a, b) => a.FTeamType == teamType)
//.WhereIF(currUser != null, (a, b) => a.FFactoryID == currUser.FFactoryID)
.Select<object>("distinct a.*,b.FTypeID1,b.FTypeID2,b.FK3Code,b.FK3Name,b.FK3ShortCode,b.FTestCode,b.FRelationCode,b.FRelationName,b.FSAPCode,b.FSAPDescription,b.FMaterialGroup,b.FMaterialType,b.FCustomerCode,b.FStoreHouse," +
"b.FBomEntry,b.FLineHouse,b.FProductDesc,b.FWorkCenter,b.FCraftExplain,b.FIidentifier,b.FGuaranteePeriod,b.FBStorageConditions,b.FSafetyStock,b.FTriggerRatio,b.FMinAmount,b.FMaxAmount,b.FYield,b.FFixedLoss,b.FTheoryYield," +
"b.FQualityTest1,b.FQualityTest2").ToDictionaryList();
materialId = viewList.GroupBy(s => s["FMaterialID"]).Select(s => int.Parse(s.Key.ToString())).ToList();
return viewList;
}
/// <summary>
/// 根据物料获取基本信息
/// </summary>
public List<TFS_MaterialInfo> GetMaterialInfoList(List<int> materialIds, int userId)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_MaterialInfo> infoList = db.Queryable<TFS_MaterialInfo>().Where(s => materialIds.Contains(s.FDataID) && s.FType == 2).ToList();
if (infoList.Count != materialIds.Count)
{
materialIds = materialIds.Where(s => infoList.Find(f => f.FDataID == s) == null).ToList();
foreach (int materialId in materialIds)
{
TFS_Material temp = db.Queryable<TFS_Material>().Where(s => s.FID == materialId).First();
TFS_MaterialInfo info = new TFS_MaterialInfo()
{
FType = 2,
FDataID = materialId,
FAddUser = userId,
FMaterialGroup = temp.FMaterialGroup,
FMaterialType = temp.FMaterialType
};
db.Insertable(info).IgnoreColumns(true).ExecuteCommand();
infoList.Add(info);
}
}
return infoList;
}
/// <summary>
/// 根据物料分类集合信息
/// </summary>
public object GetMaterialTypeList()
{
return AppSettingsHelper.GetSqlSugar().Queryable<TFS_MaterialType>().Where(s => s.FDeleted != 1 && s.FState == 1)
.OrderBy("FDepth,FID").Select<dynamic>("FID,FName,FID FValue,FDepth,FParentID").ToList();
}
public int InsertMaterialView(TFS_ViewMaterial view)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Insertable(view).IgnoreColumns(true).ExecuteReturnIdentity();
}
public int InsertMaterial(TFS_Material material)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Insertable(material).IgnoreColumns(true).ExecuteReturnIdentity();
}
public int UpdateMaterial(TFS_Material material)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Updateable(material).IgnoreColumns(true).Where("FID").ExecuteCommand();
}
public int UpdateMaterialViewById(List<Dictionary<string, object>> viewList, int userId, int teamId)
{
int result = 0;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
if (viewList != null && viewList.Count > 0)
{
for(int i = 0; i < viewList.Count; i++)
{
viewList[i]["FEditUser"] = userId;
viewList[i]["FEditDate"] = DateTime.Now;
}
// 更新视图
string sqlWhere = string.Format("FViewType={0} and FTeamID={1} and FTeamType={2}", 0, teamId, 1);
result += db.Updateable(viewList).AS("TFS_ViewMaterial").WhereColumns("FMaterialID").Where(sqlWhere).ExecuteCommand();
result += UnionModifyData(viewList, "TFS_ViewMaterial", teamId, db, "FMaterialID");
}
return result;
}
public int UpdateMaterialById(List<Dictionary<string, object>> materialList, int userId, int teamId)
{
int result = 0;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
if (materialList != null && materialList.Count > 0)
{
for (int i = 0; i < materialList.Count; i++)
{
materialList[i]["FID"] = materialList[i]["FMaterialID"];
materialList[i]["FEditUser"] = userId;
materialList[i]["FEditDate"] = DateTime.Now;
materialList[i].Remove("FMaterialID");
if (materialList[i].TryGetValue("FK3Code", out object k3Code))
{
if (materialList[i].ContainsKey("FK3ShortCode"))
{
materialList[i]["FK3ShortCode"] = k3Code.ToString().Split('.').Last();
}
else
{
materialList[i].Add("FK3ShortCode", k3Code.ToString().Split('.').Last());
}
}
}
result += db.Updateable(materialList).AS("TFS_Material").WhereColumns("FID").ExecuteCommand();
result += UnionModifyData(materialList, "TFS_Material", teamId, db);
}
return result;
}
public int UpdateMaterialInfoById(List<Dictionary<string, object>> infoList, int userId, int teamId)
{
int result = 0;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
if (infoList != null && infoList.Count > 0)
{
for (int i = 0; i < infoList.Count; i++)
{
infoList[i]["FDataID"] = infoList[i]["FMaterialID"];
infoList[i]["FEditUser"] = userId;
infoList[i]["FEditDate"] = DateTime.Now;
infoList[i].Remove("FMaterialID");
infoList[i].Add("FType", 2);
}
result += db.Updateable(infoList).AS("TFS_MaterialInfo").WhereColumns("FType", "FDataID").ExecuteCommand();
result += UnionModifyData(infoList, "TFS_MaterialInfo", teamId, db, "FDataID");
}
return result;
}
public int UpdateMaterialView(TFS_ViewMaterial view)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Updateable(view).IgnoreColumns(true).Where("FID").ExecuteCommand();
}
private int UnionModifyData(List<Dictionary<string, object>> dataList, string srcTable, int teamId, SqlSugarClient db = null, string colName = "FID")
{
int result = 0;
if (dataList != null && dataList.Count > 0)
{
if (db == null) db = AppSettingsHelper.GetSqlSugar();
List<TFS_UnionModify> unionList = db.Queryable<TFS_UnionModify>().Where(s => s.FDeleted != 1 && s.FTableOriginal == srcTable).ToList();
if (unionList.Count > 0)
{
List<string> sqlList = new List<string>() { "update {0} set {0}.{1}={2}.{3} from {0} left join {2} on {4} where {2}.{5}='{6}' {7}" };
foreach (Dictionary<string, object> data in dataList)
{
foreach (TFS_UnionModify union in unionList)
{
if (data.TryGetValue(union.FColumnOriginal, out object srcVal))
{
string sqlWhere = "";
if (union.FTableTarget == "TFS_ViewMaterial" || union.FTableOriginal == "TFS_ViewMaterial")
{
sqlWhere = " and TFS_ViewMaterial.FTeamID=" + teamId;
}
sqlList.Add(string.Format(sqlList[0], union.FTableTarget, union.FColumnTarget,
union.FTableOriginal, union.FColumnOriginal, union.FUnionCondition, colName,
data[colName], sqlWhere));
}
}
}
sqlList.RemoveAt(0);
if (sqlList.Count > 0)
{
string updateSql = string.Join(";", sqlList);
try { result = db.Ado.ExecuteCommand(updateSql); }
catch (Exception) { }
}
}
}
return result;
}
public int CloseMaterialTeamwork(int teamId, int userId)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_FMaterialTeamwork> teamworkList = db.Queryable<TFS_FMaterialTeamwork>().Where(s => s.FID == teamId && s.FState == 1).ToList();
int result = 0;
if (teamworkList != null && teamworkList.Count > 0)
{
TFS_FMaterialTeamwork fmt = teamworkList[0];
fmt.FState = 2;
fmt.FEditUser = userId;
fmt.FEditDate = DateTime.Now;
result = db.Updateable(fmt).IgnoreColumns(true).WhereColumns("FID").ExecuteCommand();
}
return result;
}
}
}

@ -349,6 +349,52 @@ namespace FactorySystemBll
return result;
}
public int UpdateMaterialViewById(List<Dictionary<string, object>> viewList, List<Dictionary<string, object>> materialList,
List<Dictionary<string, object>> infoList, int teamId, int viewType, int userId)
{
int result = 0;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
if (viewList != null && viewList.Count > 0)
{
string sqlWhere = string.Format("FViewType={0} and FTeamID={1}", viewType, teamId);
result += db.Updateable(viewList).AS("TFS_ViewMaterial").WhereColumns("FMaterialID").Where(sqlWhere).ExecuteCommand();
result += UnionModifyData(viewList, "TFS_ViewMaterial", teamId, db, "FMaterialID");
}
if (materialList != null && materialList.Count > 0)
{
for (int i = 0; i < materialList.Count; i++)
{
materialList[i]["FID"] = materialList[i]["FMaterialID"];
materialList[i].Remove("FMaterialID");
if (materialList[i].TryGetValue("FK3Code", out object k3Code))
{
if (materialList[i].ContainsKey("FK3ShortCode"))
{
materialList[i]["FK3ShortCode"] = k3Code.ToString().Split('.').Last();
}
else
{
materialList[i].Add("FK3ShortCode", k3Code.ToString().Split('.').Last());
}
}
}
result += db.Updateable(materialList).AS("TFS_Material").WhereColumns("FID").ExecuteCommand();
result += UnionModifyData(materialList, "TFS_Material", teamId, db);
}
if (infoList != null && infoList.Count > 0)
{
for (int i = 0; i < infoList.Count; i++)
{
infoList[i]["FDataID"] = infoList[i]["FMaterialID"];
infoList[i].Remove("FMaterialID");
infoList[i].Add("FType", 2);
}
result += db.Updateable(infoList).AS("TFS_MaterialInfo").WhereColumns("FType", "FDataID").ExecuteCommand();
result += UnionModifyData(infoList, "TFS_MaterialInfo", teamId, db, "FDataID");
}
return result;
}
private int CheckTaskComplete(SqlSugarClient db, int teamId, int taskType, int userId)
{
int result = 0;

@ -31,5 +31,12 @@ namespace FactorySystemModel.ResponseModel
/// Nullable:False
/// </summary>
public string FMaterialType { get; set; }
/// <summary>
/// Desc:发起人
/// Default:
/// Nullable:False
/// </summary>
public string FAddUserName { get; set; }
}
}

@ -1,13 +1,14 @@
using FactorySystemModel.SqlSugarModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactorySystemModel.ResponseModel
{
public class MaterialTeamworkRow : TFS_FMaterialTeamwork
{
/// <summary>
/// Desc:发起人
/// Default:
/// Nullable:False
/// </summary>
public string FAddUserName { get; set; }
}
}

Loading…
Cancel
Save