|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|