Yang 3 years ago
commit 0d42f66266

@ -8,14 +8,8 @@ using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Data;
using System.IO;
using Newtonsoft.Json.Linq;
using FactorySystemApi.Plm_Formula;
using System.Linq;
using SqlSugar;
using FactorySystemModel.RequestModel;
using System.Web.Http.Results;
using System.Reflection;
namespace FactorySystemApi.Controllers
{
@ -48,6 +42,7 @@ namespace FactorySystemApi.Controllers
{
}
#region 物料新增
/// <summary>
/// 新增物料路线
/// </summary>
@ -86,7 +81,7 @@ namespace FactorySystemApi.Controllers
}
else
{
inParam.Add("FEditDate", DateTime.Now);
inParam.Add("FAddDate", DateTime.Now);
}
if (inParam.ContainsKey("FEditUser"))
@ -147,7 +142,7 @@ namespace FactorySystemApi.Controllers
}
// 创建物料分类任务
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, user.FID, 0, factory.FID);
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, 1, user.FID, 0, factory.FID);
result.Add("TaskId", taskId);
}
}
@ -189,12 +184,13 @@ namespace FactorySystemApi.Controllers
if (Request.Properties["token"] is ApiAuthInfo user)
{
int teamId = int.Parse(inParam["teamId"].ToString());
int teamWorkType = int.Parse(inParam["teamWorkType"].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),
rows = MaterialTeamworkBll.GetMaterialViewsByTeamId(teamId, teamWorkType, teamType, user.FID, true, out List<int> materialId),
infos = MaterialTeamworkBll.GetMaterialInfoList(materialId, user.FID),
types = MaterialTeamworkBll.GetMaterialTypeList()
};
@ -222,50 +218,75 @@ namespace FactorySystemApi.Controllers
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());
int teamworkType = int.Parse(inParam["FTeamworkType"].ToString());
// 更新视图
MaterialTeamworkBll.UpdateMaterialViewById(viewList, user.FID, teamId);
MaterialTeamworkBll.UpdateMaterialViewById(viewList, user.FID, teamId, teamworkType);
// 更新物料
MaterialTeamworkBll.UpdateMaterialById(materialList, user.FID, teamId);
MaterialTeamworkBll.UpdateMaterialById(materialList, user.FID, teamId, teamworkType);
// 更新物料信息
MaterialTeamworkBll.UpdateMaterialInfoById(infoList, user.FID, teamId);
MaterialTeamworkBll.UpdateMaterialInfoById(infoList, user.FID, teamId, teamworkType);
List<TFS_FMaterialTask> tasks = MaterialTaskBll.GetMaterialTasks(teamId);
if (tasks != null && tasks.Count == 1)
{
TFS_FMaterialTask task = tasks[0];
if (task.FType == 0)
TFS_FMaterialTask task = null;
if ((task = tasks.FindLast(t => t.FType == 2)) != null)
{
// 结束物料分类任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 0);
// 创建物料编辑任务
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, user.FID, 1, task.FFactoryID);
}
// 结束物料确认任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 2);
// 结束物料路线
MaterialTeamworkBll.CloseMaterialTeamwork(teamId, user.FID);
}
else if (tasks.Count == 2)
{
TFS_FMaterialTask task = tasks.FindLast(t => t.FType == 1);
if (task != null)
else if((task = tasks.FindLast(t => t.FType == 1)) != null)
{
// 结束物料编辑任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 1);
// 创建物料确认任务
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, user.FID, 2, task.FFactoryID);
}
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, teamworkType, user.FID, 2, task.FFactoryID);
}
else if (tasks.Count == 3)
else if ((task = tasks.FindLast(t => t.FType == 0)) != null)
{
TFS_FMaterialTask task = tasks.FindLast(t => t.FType == 2);
if (task != null)
{
// 结束物料确认任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 2);
MaterialTeamworkBll.CloseMaterialTeamwork(teamId, user.FID);
}
}
// 结束物料分类任务
MaterialTaskBll.CloseMaterialTask(teamId, user.FID, 0);
// 创建物料编辑任务
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, teamworkType, user.FID, 1, task.FFactoryID);
}
//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;
@ -320,8 +341,145 @@ namespace FactorySystemApi.Controllers
return result;
}
#endregion
#region 物料修改
/// <summary>
/// 物料修改路线
/// </summary>
[HttpPost]
public ApiResult ModifyMaterial(Dictionary<string, object> inParam)
{
ApiResult apiResult = new ApiResult();
Dictionary<string, int> result = new Dictionary<string, int>();
Dictionary<string, object> teamworkParam = new Dictionary<string, object>();
return ExceptionHelper.TryReturnException(() =>
{
ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
TFS_Factory prodFactory = null;
int factoryId = int.Parse(inParam["FCreateFactoryID"].ToString());
int materialId = int.Parse(inParam["FMaterialId"].ToString());
// 根据FID获取工厂和物料
TFS_Factory factory = BaseBll.GetTempModel<TFS_Factory>(factoryId);
TFS_Material material = BaseBll.GetTempModel<TFS_Material>(materialId);
// 获取当前工厂视图
TFS_ViewMaterial view = MaterialTeamworkBll.GetMaterialViewsByFactoryAndMaterial(factoryId, materialId);
TFS_ViewMaterial prodView = null;
// 当前物料和模式没有对应视图,则创建视图
if (view == null)
{
view = new TFS_ViewMaterial();
view.FMaterialID = materialId; // 物料ID
view.FAddDate = DateTime.Now; // 创建日期
view.FTeamType = 1; // 路线类型
view.FFactoryID = factory.FID; // 工厂ID
view.FFactoryCode = factory.FCode; // 工厂Code
int vmId = MaterialTeamworkBll.InsertMaterialView(view);
view.FID = vmId;
result.Add("ViewId", vmId);
}
// 设置物料修改路线
teamworkParam.Add("FTeamworkType", 2); // 路线类型-修改
teamworkParam.Add("FState", 1); // 路线状态-进行中
teamworkParam.Add("FMaterialCode", material.FCode); // 物料编号
teamworkParam.Add("FMaterialName", material.FName); // 物料描述
teamworkParam.Add("FTestCode", material.FTestCode); // 试验号
teamworkParam.Add("FMaterialType", material.FType); // 物料类型产品分类TBasicCode.FType=32
teamworkParam.Add("FMaterialGroup", material.FMaterialGroup); // 物料组TDataCode.FType=2
teamworkParam.Add("FWeightUnit", material.FBaseUnit); // 计量单位
teamworkParam.Add("FAddUser", user.FID); // 创建用户
teamworkParam.Add("FAddDate", DateTime.Now); // 创建时间
teamworkParam.Add("FEditUser", user.FID); // 修改用户
teamworkParam.Add("FEditDate", DateTime.Now); // 修改时间
teamworkParam.Add("FCreateFactoryID", factory.FID); // 工厂ID
teamworkParam.Add("FCreateFactoryCode", factory.FCode); // 工厂Code
teamworkParam.Add("FCreateFactoryType", factory.FType); // 工厂类型
// 如果当前模式是委托,获取委托工厂
if (factory.FType == 1)
{
int prodFactoryId = factory.FFactoryID;
prodFactory = BaseBll.GetTempModel<TFS_Factory>(prodFactoryId);
teamworkParam.Add("FProdFactoryID", prodFactory.FID); // 委托工厂ID
teamworkParam.Add("FProdFactoryCode", prodFactory.FCode); // 委托工厂Code
prodView = MaterialTeamworkBll.GetMaterialViewsByFactoryAndMaterial(prodFactoryId, materialId);
// 新增委托工厂视图
if (prodView == null)
{
prodView = Clone(view);
prodView.FFactoryID = prodFactoryId;
prodView.FFactoryCode = prodFactory.FCode;
prodView.FAddDate = DateTime.Now;
// 插入视图
int prodVmId = MaterialTeamworkBll.InsertMaterialView(prodView);
prodView.FID = prodVmId;
result.Add("ProdViewId", prodVmId);
}
}
// 创建物料修改路线
int teamId = BaseBll.InsertDataModel(teamworkParam, "TFS_FMaterialTeamwork");
result.Add("TeamId", teamId);
// 更新视图
view.FMdfMaterialTeamID = teamId;
view.FTeamType = 1;
MaterialTeamworkBll.UpdateMaterialView(view);
if (prodView != null)
{
prodView.FMdfMaterialTeamID = teamId;
prodView.FTeamType = 1;
MaterialTeamworkBll.UpdateMaterialView(prodView);
}
// 创建物料修改事项
int taskId = MaterialTaskBll.CreateMaterialTask(teamId, 2, user.FID, 1, factory.FID);
result.Add("TaskId", taskId);
apiResult.Data = result;
}, apiResult, Request);
}
/// <summary>
/// 根据工厂和物料名查找物料
/// </summary>
[HttpPost]
public ApiResult SearchMaterialsByFactory(Dictionary<string, object> inParam)
{
ApiResult apiResult = new ApiResult();
return ExceptionHelper.TryReturnException(() =>
{
ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
Dictionary<string, object> result = new Dictionary<string, object>();
string searchName = inParam["FSearchName"].ToString();
int pageNumber = 0;
int pageSize = 0;
int.TryParse(inParam["FPageIndex"].ToString(), out pageNumber);
int.TryParse(inParam["FPageSize"].ToString(), out pageSize);
List<TFS_Material> materials = MaterialTeamworkBll.SearchMaterialsByFactory(searchName, pageNumber, pageSize, out var totalNumber);
result["List"] = materials;
result["Total"] = totalNumber;
apiResult.Data = result;
}, apiResult, Request);
}
private Dictionary<string, int> CreateProdMaterialData(TFS_ViewMaterial createViewMaterial, TFS_FMaterialTeamwork teamwork)
{
@ -337,5 +495,54 @@ namespace FactorySystemApi.Controllers
return result;
}
#endregion
public T Clone<T>(T obj) where T : class
{
// 如果对象是 null则返回 null
if (obj == null)
{
return null;
}
Type type = obj.GetType();
// 如果对象是字符串或值类型,则直接返回副本
if (type.IsPrimitive || type == typeof(string))
{
return obj;
}
// 如果对象是数组,则创建一个新的数组并复制元素
if (type.IsArray)
{
Array sourceArray = obj as Array;
Array destinationArray = sourceArray.Clone() as Array;
for (int i = 0; i < sourceArray.Length; i++)
{
destinationArray.SetValue(Clone(sourceArray.GetValue(i)), i);
}
return destinationArray as T;
}
// 否则,创建一个新对象并复制属性值
object result = Activator.CreateInstance(type);
foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
object fieldValue = field.GetValue(obj);
field.SetValue(result, Clone(fieldValue));
}
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
if (!property.CanWrite || !property.CanRead)
{
continue;
}
object propertyValue = property.GetValue(obj);
property.SetValue(result, Clone(propertyValue), null);
}
return result as T;
}
}
}

@ -48,7 +48,7 @@ namespace FactorySystemBll
/// <summary>
/// 创建物料新增事项
/// </summary>
public int CreateMaterialTask(int teamId, int userId, int type, int factoryId)
public int CreateMaterialTask(int teamId, int teamworkType, int userId, int type, int factoryId)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
int funcType = (int)Constant.RoleType.;
@ -74,6 +74,7 @@ namespace FactorySystemBll
materialTask.FAddUser = userId;
materialTask.FAddDate = DateTime.Now;
materialTask.FState = 1;
materialTask.FTeamworkType = teamworkType;
if (type == 0)
{

@ -77,7 +77,7 @@ namespace FactorySystemBll
/// <summary>
/// 获取视图
/// </summary>
public List<Dictionary<string, object>> GetMaterialViewsByTeamId(int teamId, int teamType, int currUserId, out List<int> materialId, bool byFactory = true)
public List<Dictionary<string, object>> GetMaterialViewsByTeamId(int teamId, int teamworkType, int teamType, int currUserId, bool byFactory, out List<int> materialId)
{
TUser currUser = null;
if (byFactory == true) currUser = BaseBll.GetTempModel<TUser>(currUserId, "FFactoryID");
@ -85,6 +85,19 @@ namespace FactorySystemBll
List<Dictionary<string, object>> viewList = new List<Dictionary<string, object>>();
if (teamworkType == 2)
{
viewList = db.Queryable<TFS_ViewMaterial, TFS_Material>((a, b) =>
new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID))
.Where((a, b) => a.FMdfMaterialTeamID == 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();
}
else
{
viewList = db.Queryable<TFS_ViewMaterial, TFS_Material>((a, b) =>
new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID))
.Where((a, b) => a.FTeamID == teamId)
@ -93,12 +106,24 @@ namespace FactorySystemBll
.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 TFS_ViewMaterial GetMaterialViewsByFactoryAndMaterial(int factoryId, int materialId)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
TFS_ViewMaterial view = db.Queryable<TFS_ViewMaterial>().Where(s => s.FMaterialID == materialId && s.FFactoryID == factoryId).First();
return view;
}
/// <summary>
/// 根据物料获取基本信息
/// </summary>
@ -157,7 +182,7 @@ namespace FactorySystemBll
return db.Updateable(material).IgnoreColumns(true).Where("FID").ExecuteCommand();
}
public int UpdateMaterialViewById(List<Dictionary<string, object>> viewList, int userId, int teamId)
public int UpdateMaterialViewById(List<Dictionary<string, object>> viewList, int userId, int teamId, int teamworkType)
{
int result = 0;
@ -170,16 +195,26 @@ namespace FactorySystemBll
viewList[i]["FEditUser"] = userId;
viewList[i]["FEditDate"] = DateTime.Now;
}
string sqlWhere = "";
if (teamworkType == 2)
{
sqlWhere = string.Format("FViewType={0} and FMdfMaterialTeamId={1} and FTeamType={2}", 0, teamId, 1);
}
else
{
sqlWhere = string.Format("FViewType={0} and FTeamID={1} and FTeamType={2}", 0, teamId, 1);
}
// 更新视图
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");
result += UnionModifyData(viewList, "TFS_ViewMaterial", teamId, teamworkType, db, "FMaterialID");
}
return result;
}
public int UpdateMaterialById(List<Dictionary<string, object>> materialList, int userId, int teamId)
public int UpdateMaterialById(List<Dictionary<string, object>> materialList, int userId, int teamId, int teamworkType)
{
int result = 0;
@ -207,13 +242,13 @@ namespace FactorySystemBll
result += db.Updateable(materialList[i]).AS("TFS_Material").WhereColumns("FID").ExecuteCommand();
}
result += UnionModifyData(materialList, "TFS_Material", teamId, db);
result += UnionModifyData(materialList, "TFS_Material", teamId, teamworkType, db);
}
return result;
}
public int UpdateMaterialInfoById(List<Dictionary<string, object>> infoList, int userId, int teamId)
public int UpdateMaterialInfoById(List<Dictionary<string, object>> infoList, int userId, int teamId, int teamworkType)
{
int result = 0;
@ -232,7 +267,7 @@ namespace FactorySystemBll
result += db.Updateable(infoList[i]).AS("TFS_MaterialInfo").WhereColumns("FDataID", "FType").ExecuteCommand();
}
//result += db.Updateable(infoList).AS("TFS_MaterialInfo").WhereColumns("FDataID", "FType").ExecuteCommand();
result += UnionModifyData(infoList, "TFS_MaterialInfo", teamId, db, "FDataID");
result += UnionModifyData(infoList, "TFS_MaterialInfo", teamId, teamworkType, db, "FDataID");
}
return result;
@ -241,10 +276,10 @@ namespace FactorySystemBll
public int UpdateMaterialView(TFS_ViewMaterial view)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Updateable(view).IgnoreColumns(true).Where("FID").ExecuteCommand();
return db.Updateable(view).IgnoreColumns(true).WhereColumns("FID").ExecuteCommand();
}
private int UnionModifyData(List<Dictionary<string, object>> dataList, string srcTable, int teamId, SqlSugarClient db = null, string colName = "FID")
private int UnionModifyData(List<Dictionary<string, object>> dataList, string srcTable, int teamId, int teamworkType, SqlSugarClient db = null, string colName = "FID")
{
int result = 0;
if (dataList != null && dataList.Count > 0)
@ -262,9 +297,16 @@ namespace FactorySystemBll
{
string sqlWhere = "";
if (union.FTableTarget == "TFS_ViewMaterial" || union.FTableOriginal == "TFS_ViewMaterial")
{
if (teamworkType == 2)
{
sqlWhere = " and TFS_ViewMaterial.FMdfMaterialTeamID=" + teamId;
}
else
{
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));
@ -305,5 +347,17 @@ namespace FactorySystemBll
return result;
}
public List<TFS_Material> SearchMaterialsByFactory(string materialName, int pageNumber, int pageSize, out int totalNumber)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
totalNumber = 0;
List<TFS_Material> materialList = db.Queryable<TFS_Material>()
.WhereIF(!string.IsNullOrEmpty(materialName.Trim()), a => a.FName.Contains(materialName))
.ToPageList(pageNumber, pageSize, ref totalNumber);
return materialList;
}
}
}

@ -116,5 +116,12 @@ namespace FactorySystemModel.SqlSugarModel
/// Nullable:False
/// </summary>
public DateTime FEditDate { get; set; }
/// <summary>
/// Desc:路线类型1新增物料2修改物料
/// Default:-1
/// Nullable:False
/// </summary>
public int FTeamworkType { get; set; }
}
}

Loading…
Cancel
Save