|  |  | using FactorySystemBll;
 | 
						
						
						
							|  |  | using FactorySystemCommon;
 | 
						
						
						
							|  |  | using FactorySystemModel.BusinessModel;
 | 
						
						
						
							|  |  | using FactorySystemModel.ResponseModel;
 | 
						
						
						
							|  |  | using FactorySystemModel.SqlSugarModel;
 | 
						
						
						
							|  |  | using System;
 | 
						
						
						
							|  |  | using System.Collections.Generic;
 | 
						
						
						
							|  |  | using System.Data;
 | 
						
						
						
							|  |  | using System.Linq;
 | 
						
						
						
							|  |  | using System.Reflection;
 | 
						
						
						
							|  |  | using System.Web.Http;
 | 
						
						
						
							|  |  | using FactorySystemModel.EnumModel;
 | 
						
						
						
							|  |  | using FactorySystemModel.RequestModel;
 | 
						
						
						
							|  |  | using FactorySystemApi.Plm_Formula;
 | 
						
						
						
							|  |  | using System.Web.UI.WebControls;
 | 
						
						
						
							|  |  | using Newtonsoft.Json;
 | 
						
						
						
							|  |  | using Aspose.Cells;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | namespace FactorySystemApi.Controllers
 | 
						
						
						
							|  |  | {
 | 
						
						
						
							|  |  |     /// <summary>
 | 
						
						
						
							|  |  |     /// 配方接口
 | 
						
						
						
							|  |  |     /// </summary>
 | 
						
						
						
							|  |  |     [UserLoginFilter]
 | 
						
						
						
							|  |  |     public class FormulaController : BaseController<TFS_Formula>
 | 
						
						
						
							|  |  |     {
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 数据处理层
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         public readonly FormulaBll FormulaBll = new FormulaBll();
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 初始化
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         public FormulaController()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             //设置可修改字段
 | 
						
						
						
							|  |  |             UpdateField = "";
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 更具试验号获取配方视图
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="data"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetFormulaByFTestCode(Dictionary<string,object> data) 
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 apiResult.Data = FormulaBll.GetFormulaByFTestCode(data["code"].ToString());
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取配方集合
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetFormulaList()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 apiResult.Data = FormulaBll.GetFormulaList();
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取修改配方集合
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetUpdateFormulaList() 
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 apiResult.Data = FormulaBll.GetUpdateFormulaList();
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 分业请求
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetFormulaPageList(FormulaQuery fq)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 apiResult.Data = new
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     List = FormulaBll.GetList(fq, out var totalNumber),
 | 
						
						
						
							|  |  |                     Total = totalNumber
 | 
						
						
						
							|  |  |                 };
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取配方变更列表
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="fq"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public ApiResult GetUpdateFormulaPageList(FormulaQuery fq)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 apiResult.Data = new
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     List = FormulaBll.GetUpdateFormulaList(fq, out var totalNumber),
 | 
						
						
						
							|  |  |                     Total = totalNumber
 | 
						
						
						
							|  |  |                 };
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 更新修改配方的描述及状态
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult EditUpdateFormula(Dictionary<string, object> inParam) 
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             apiResult.Data = 0;
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 if (inParam == null)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Error("未接收到参数");
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 if (!inParam.ContainsKey("FID")) 
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Error("未接收到参数FID");
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 if (!inParam.ContainsKey("Remark"))
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Error("未填写备注说明");
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 else 
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     int userId = -1;
 | 
						
						
						
							|  |  |                     userId = Request.Properties["token"] is ApiAuthInfo user ? user.FID : userId;
 | 
						
						
						
							|  |  |                     int fid = int.Parse(inParam["FID"].ToString());
 | 
						
						
						
							|  |  |                     TFS_UpdateFormula model = FormulaBll.GetUpdateFormulaByFID(fid);
 | 
						
						
						
							|  |  |                     model.Update_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
 | 
						
						
						
							|  |  |                     model.Remark = inParam["Remark"].ToString();
 | 
						
						
						
							|  |  |                     model.Status = "已处理";
 | 
						
						
						
							|  |  |                     model.Update_User = userId.ToString();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     apiResult.Data= FormulaBll.EditUpdateFormula(model);
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }, apiResult, Request, inParam);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 对接配方数据(对方写入)
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult DockingRecipeData(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             apiResult.Data = 0;
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 if (inParam == null)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Error("未接收到参数");
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 else
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (inParam.ContainsKey("SP")&&!inParam.ContainsKey("FPlmCode")) 
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         inParam.Add("FPlmCode", inParam["SP"].ToString());
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                   
 | 
						
						
						
							|  |  |                     if (inParam.ContainsKey("SP_VERSION")&& !inParam.ContainsKey("FVersionCode")) 
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         //inParam.Add("FVersionCode", inParam["SP_VERSION"].ToString());
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         // 20230530 格式化传入的版本号
 | 
						
						
						
							|  |  |                         string sVersion = inParam["SP_VERSION"].ToString();
 | 
						
						
						
							|  |  |                         double dVersion;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         bool isVersionNum = double.TryParse(sVersion, out dVersion);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         if (isVersionNum)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             sVersion = string.Format("{0:F4}", dVersion);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         inParam.Add("FVersionCode", sVersion);
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                    
 | 
						
						
						
							|  |  |                     if (inParam.ContainsKey("SP_VALUE")&&!inParam.ContainsKey("FTestCode")) 
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         inParam.Add("FTestCode", inParam["SP_VALUE"].ToString());
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     List<TFS_FieldInfo> fieldList = BaseBll.GetFileInfoList((int)Constant.FieldInfoType.配方模板导入);
 | 
						
						
						
							|  |  |                     TFS_Formula formula = new TFS_Formula();
 | 
						
						
						
							|  |  |                     List<PropertyInfo> propertys = formula.GetType().GetProperties().ToList();
 | 
						
						
						
							|  |  |                     foreach (var field in fieldList)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         PropertyInfo temp = propertys.Find(s => s.Name == field.FColumnFIeld);
 | 
						
						
						
							|  |  |                         if (temp != null) temp.SetValue(formula, GetValueByName(inParam, field.FFieldName, field.FDefault));
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (inParam.ContainsKey("SP_AUTHOR")) 
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         formula.FConversionPersonnel = inParam["SP_AUTHOR"].ToString();
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     if (string.IsNullOrEmpty(formula.FPlmCode))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("FPlmCode不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (string.IsNullOrEmpty(formula.FVersionCode))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("FVersionCode不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (string.IsNullOrEmpty(formula.FName))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("FName不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (string.IsNullOrEmpty(formula.FType))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("FType不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     /**
 | 
						
						
						
							|  |  |                      * 20230401 新增
 | 
						
						
						
							|  |  |                      * 接口新增:
 | 
						
						
						
							|  |  |                      * 转规格人员 FConversionPersonnel
 | 
						
						
						
							|  |  |                      * BOM版本号 FBomVersionCode
 | 
						
						
						
							|  |  |                      * **/
 | 
						
						
						
							|  |  |                     else if (string.IsNullOrEmpty(formula.FConversionPersonnel))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("FConversionPersonnel不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         int userId = -1;
 | 
						
						
						
							|  |  |                         if (Request.Properties.ContainsKey("token"))
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                          
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             userId = Request.Properties["token"] is ApiAuthInfo user ? user.FID : userId;
 | 
						
						
						
							|  |  |                             apiResult.Data = FormulaBll.DockingRecipeData(new List<TFS_Formula>() { formula }, userId);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                         else
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             apiResult.Error("token信息不存在");
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }, apiResult, Request, inParam);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult DockingChangeData(Dictionary<string, object> inParam) 
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             apiResult.Data = 0;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 if (inParam == null)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Error("未接收到参数");
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 else
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (!inParam.ContainsKey("SP"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("PLM规格内码不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (!inParam.ContainsKey("SP_VERSION"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("版本号不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (!inParam.ContainsKey("Name"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("配方中文名称不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (!inParam.ContainsKey("Type"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("配方类型不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (!inParam.ContainsKey("SP_AUTHOR"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Error("修改人不能为空");
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         //int userId = -1;
 | 
						
						
						
							|  |  |                         if (Request.Properties.ContainsKey("token"))
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             string sVersion = inParam["SP_VERSION"].ToString();
 | 
						
						
						
							|  |  |                             double dVersion;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             bool isVersionNum = double.TryParse(sVersion, out dVersion);
 | 
						
						
						
							|  |  |                             int task = -1;
 | 
						
						
						
							|  |  |                             if (isVersionNum)
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 sVersion = string.Format("{0:F4}", dVersion);
 | 
						
						
						
							|  |  |                             }
 | 
						
						
						
							|  |  |                             if (inParam.ContainsKey("Change_List") && inParam["Change_List"] != null && inParam["Change_List"].ToString() != "")
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 List<TFS_UpdateFormula> jsonList = JsonConvert.DeserializeObject<List<TFS_UpdateFormula>>(inParam["Change_List"].ToString());
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                                 if (jsonList.Count > 0)
 | 
						
						
						
							|  |  |                                 {
 | 
						
						
						
							|  |  |                                     foreach (var item in jsonList)
 | 
						
						
						
							|  |  |                                     {
 | 
						
						
						
							|  |  |                                         TFS_UpdateFormula tFS_UpdateFormula = new TFS_UpdateFormula()
 | 
						
						
						
							|  |  |                                         {
 | 
						
						
						
							|  |  |                                             SP = inParam["SP"].ToString(),
 | 
						
						
						
							|  |  |                                             SP_VERSION = sVersion,
 | 
						
						
						
							|  |  |                                             SP_VALUE = inParam["SP_VALUE"].ToString(),
 | 
						
						
						
							|  |  |                                             Name = inParam["Name"].ToString(),
 | 
						
						
						
							|  |  |                                             Type = inParam["Type"].ToString(),
 | 
						
						
						
							|  |  |                                             SP_AUTHOR = inParam["SP_AUTHOR"].ToString(),
 | 
						
						
						
							|  |  |                                             //Change_Content = inParam["Change_Content"].ToString(),
 | 
						
						
						
							|  |  |                                             Change_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm"),
 | 
						
						
						
							|  |  |                                             Change_Content = JsonConvert.SerializeObject(item),
 | 
						
						
						
							|  |  |                                         };
 | 
						
						
						
							|  |  |                                         task = FormulaBll.SevaTFS_UpdateFormula(tFS_UpdateFormula);
 | 
						
						
						
							|  |  |                                     }
 | 
						
						
						
							|  |  |                                 }
 | 
						
						
						
							|  |  |                                 else 
 | 
						
						
						
							|  |  |                                 {
 | 
						
						
						
							|  |  |                                     apiResult.Error("Change_List不能为空!");
 | 
						
						
						
							|  |  |                                 }
 | 
						
						
						
							|  |  |                                
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             }
 | 
						
						
						
							|  |  |                             else 
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 apiResult.Error("Change_List不能为空!");
 | 
						
						
						
							|  |  |                             }
 | 
						
						
						
							|  |  |                            
 | 
						
						
						
							|  |  |                             apiResult.Data = task;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //userId = Request.Properties["token"] is ApiAuthInfo user ? user.FID : userId;
 | 
						
						
						
							|  |  |                             //apiResult.Data = FormulaBll.DockingRecipeData(new List<TFS_Formula>() { formula }, userId);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                         else
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             apiResult.Error("token信息不存在");
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }, apiResult, Request, inParam);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// (对接)SAP配方同步
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult DockSapFormula()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 Data = 0
 | 
						
						
						
							|  |  |             };
 | 
						
						
						
							|  |  |             int result = 0;
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 Sap_Formula.dt_pp062_reqDATA[] reqDatas = new Sap_Formula.dt_pp062_reqDATA[1] {
 | 
						
						
						
							|  |  |                     new Sap_Formula.dt_pp062_reqDATA()
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         SOURCESYS = "MCS",
 | 
						
						
						
							|  |  |                         TARGETSYS = "SAP"
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 };
 | 
						
						
						
							|  |  |                 List<TFS_Factory> factoryList = FactoryBll.GetFactoryList();
 | 
						
						
						
							|  |  |                 if (factoryList.Count > 0)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
 | 
						
						
						
							|  |  |                     Sap_Formula.si_pp062_bc_senderService sapService = new Sap_Formula.si_pp062_bc_senderService()
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         Credentials = new System.Net.NetworkCredential()
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             UserName = AppSettingsHelper.GetAppSettingVal("Sap_UserName"),
 | 
						
						
						
							|  |  |                             Password = AppSettingsHelper.GetAppSettingVal("Sap_Password")
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     };
 | 
						
						
						
							|  |  |                     foreach (TFS_Factory factory in factoryList)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         reqDatas[0].UPDATETIME = DateTime.Now.ToString("yyyyMMddHHmmss");
 | 
						
						
						
							|  |  |                         reqDatas[0].WERKS = factory.FCode;
 | 
						
						
						
							|  |  |                         try
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             Sap_Formula.dt_pp062_res resData = sapService.si_pp062_bc_sender(reqDatas);
 | 
						
						
						
							|  |  |                             ExceptionHelper.AddSystemJournal(Request, reqDatas, resData);
 | 
						
						
						
							|  |  |                             List<TFS_Formula> formulaList = new List<TFS_Formula>();
 | 
						
						
						
							|  |  |                             if (resData != null && resData.DATA != null && resData.DATA.Length > 0)
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 foreach (var item in resData.DATA)
 | 
						
						
						
							|  |  |                                 {
 | 
						
						
						
							|  |  |                                     formulaList.Add(new TFS_Formula()
 | 
						
						
						
							|  |  |                                     {
 | 
						
						
						
							|  |  |                                         FFactoryID = factory.FID,
 | 
						
						
						
							|  |  |                                         FFactoryCode = factory.FCode,
 | 
						
						
						
							|  |  |                                         FName = string.IsNullOrEmpty(item.MAKTX) ? "" : item.MAKTX,
 | 
						
						
						
							|  |  |                                         FTestCode = string.IsNullOrEmpty(item.MATNR) ? "" : item.MATNR,
 | 
						
						
						
							|  |  |                                         FAddDate = DateTime.Now,
 | 
						
						
						
							|  |  |                                         FEditUser = user.FID
 | 
						
						
						
							|  |  |                                     });
 | 
						
						
						
							|  |  |                                 }
 | 
						
						
						
							|  |  |                             }
 | 
						
						
						
							|  |  |                             if (formulaList.Count > 0) result += FormulaBll.DockSapFormula(formulaList);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                         catch (Exception ex)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             ExceptionHelper.AddSystemJournal(Request, reqDatas, ex.Message);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 apiResult.Data = result;
 | 
						
						
						
							|  |  |             }, apiResult, Request, null);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取用户是否具备申请查询配方权限
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetApplyBomPower()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 bool hasPower = false;
 | 
						
						
						
							|  |  |                 ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 List<object> powerList = FormulaBll.GetTaskPower(user.FID);
 | 
						
						
						
							|  |  |                 List<object> applyBomPowers = powerList.FindAll(p => ((IDictionary<string, object>)p)["FFunctionID"].ToString().Equals("12")).ToList();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 if (applyBomPowers.Count > 0)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     hasPower = true;
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 apiResult.Data = hasPower;
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取用户是否导出配方和查看工艺指导书的权限
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetBomPower()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 bool bomDownloadPower = false;
 | 
						
						
						
							|  |  |                 bool plmWebsitePower = false;
 | 
						
						
						
							|  |  |                 ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 List<object> powerList = FormulaBll.GetTaskPower(user.FID);
 | 
						
						
						
							|  |  |                 List<object> BomDownloadPowers = powerList.FindAll(p => ((IDictionary<string, object>)p)["FFunctionID"].ToString().Equals("13")).ToList();
 | 
						
						
						
							|  |  |                 List<object> plmWebsitedPowers = powerList.FindAll(p => ((IDictionary<string, object>)p)["FFunctionID"].ToString().Equals("14")).ToList();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 if (BomDownloadPowers.Count > 0)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     bomDownloadPower = true;
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 if (plmWebsitedPowers.Count > 0)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     plmWebsitePower = true;
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 Dictionary<string, bool> bomPowers = new Dictionary<string, bool>();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 bomPowers.Add("bomDownloadPower", bomDownloadPower);
 | 
						
						
						
							|  |  |                 bomPowers.Add("plmWebsitePower", plmWebsitePower);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 apiResult.Data = bomPowers;
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取用户是否具备申请查询配方权限
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetFormulaByTestCode(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 SearchFormulaQuery searchFormulaQuery = new SearchFormulaQuery();
 | 
						
						
						
							|  |  |                 string testCode = inParam["FTestCode"] == null ? "" : inParam["FTestCode"].ToString();
 | 
						
						
						
							|  |  |                 string pageIndex = inParam["FPageIndex"] == null ? "0" : inParam["FPageIndex"].ToString();
 | 
						
						
						
							|  |  |                 string pageSize = inParam["FPageSize"] == null ? "5" : inParam["FPageSize"].ToString();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 int nPageIndex = 0;
 | 
						
						
						
							|  |  |                 int nPageSize = 0;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 int.TryParse(pageIndex, out nPageIndex);
 | 
						
						
						
							|  |  |                 int.TryParse(pageSize, out nPageSize);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 searchFormulaQuery.FTestCode = testCode;
 | 
						
						
						
							|  |  |                 searchFormulaQuery.FPageIndex = nPageIndex;
 | 
						
						
						
							|  |  |                 searchFormulaQuery.FPageSize = nPageSize;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 apiResult.Data = new
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     List = FormulaBll.GetListByTestCode(searchFormulaQuery, out var totalNumber),
 | 
						
						
						
							|  |  |                     Total = totalNumber
 | 
						
						
						
							|  |  |                 };
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 获取配方清单
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetBomList(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
 | 
						
						
						
							|  |  |             Dictionary<string, object> resultObj = new Dictionary<string, object>();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 string fid = inParam["FID"] == null ? "" : inParam["FID"].ToString();
 | 
						
						
						
							|  |  |                 int nFid = 0;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 int.TryParse(fid, out nFid);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 List<TFS_Formula> formulas = FormulaBll.GetFormulaListById(nFid);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 if (formulas != null && formulas.Count > 0)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     TFS_Formula formula = formulas[0];
 | 
						
						
						
							|  |  |                     OAService oAService = new OAService();
 | 
						
						
						
							|  |  |                     string bomListStr = "";
 | 
						
						
						
							|  |  |                     Dictionary<string, object> bomResult = null;
 | 
						
						
						
							|  |  |                     List<Specifications> specifList = new List<Specifications>() { new Specifications() };
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     specifList[0].SP = formula.FPlmCode;
 | 
						
						
						
							|  |  |                     specifList[0].SP_Version = formula.FVersionCode;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     InputSpecifications oaParam = new InputSpecifications();
 | 
						
						
						
							|  |  |                     oaParam.USERNAME = AppSettingsHelper.GetAppSettingVal("Plm_Formula_Username");
 | 
						
						
						
							|  |  |                     oaParam.PASSWORD = AppSettingsHelper.GetAppSettingVal("Plm_Formula_Password");
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     oaParam.Specifications = specifList.ToArray();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     RestResult restResult = oAService.GetSpecificationsList(oaParam);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     ExceptionHelper.AddSystemJournal(Request, inParam, restResult);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (restResult != null && restResult.data != null)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         ExceptionHelper.AddSystemJournal(Request, inParam, restResult);
 | 
						
						
						
							|  |  |                         List<BomModel> bomList = JsonConvert.DeserializeObject<List<BomModel>>(restResult.data.ToString());
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                       
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         //string materialCodes = ",";
 | 
						
						
						
							|  |  |                         //string testCodes = ",";
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         if (bomList != null && bomList.Count > 0)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             bomResult = CheckBomMaterial(bomList, 0, new Random());
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //List<BomModel> subBomList = bomList[0].Specifications;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //if (subBomList != null && subBomList.Count > 0)
 | 
						
						
						
							|  |  |                             //{
 | 
						
						
						
							|  |  |                             //    foreach(BomModel bom in subBomList)
 | 
						
						
						
							|  |  |                             //    {
 | 
						
						
						
							|  |  |                             //        string bomType = bom.Type.ToLower(); // 转小写
 | 
						
						
						
							|  |  |                             //        if (bomType == "a" || bomType == "f")
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            bom.ABomType = "20";
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  |                             //        else if (bomType == "b" || bomType == "bb" || bomType == "i" || bomType == "iz")
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            bom.ABomType = "30";
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  |                             //        else
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            bom.ABomType = "40";
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //        if ("40".Equals(bom.ABomType))
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            bom.ASapCode = bom.SP_VALUE;
 | 
						
						
						
							|  |  |                             //            materialCodes = materialCodes + bom.ASapCode + ",";
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  |                             //        else
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            bom.ATestCode = bom.SP_VALUE;
 | 
						
						
						
							|  |  |                             //            testCodes = testCodes + bom.ATestCode + ",";
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  |                             //    }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //    List<TFS_ViewMaterial> viewsByMaterialCodes = FormulaBll.GetViewByMaterialCodes(materialCodes);
 | 
						
						
						
							|  |  |                             //    List<TFS_ViewMaterial> viewsByTestCodes = FormulaBll.GetViewByTestCodes(testCodes);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //    foreach (BomModel bom in subBomList)
 | 
						
						
						
							|  |  |                             //    {
 | 
						
						
						
							|  |  |                             //        if ("40".Equals(bom.ABomType))
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            if (viewsByMaterialCodes != null && viewsByMaterialCodes.Count > 0)
 | 
						
						
						
							|  |  |                             //            {
 | 
						
						
						
							|  |  |                             //                TFS_ViewMaterial view = viewsByMaterialCodes.Find(v => v.FBaseMaterialCode.Equals(bom.ASapCode));
 | 
						
						
						
							|  |  |                             //                if (view != null)
 | 
						
						
						
							|  |  |                             //                {
 | 
						
						
						
							|  |  |                             //                    bom.AMaterialCode = view.FSaleOldMaterialCode;
 | 
						
						
						
							|  |  |                             //                }
 | 
						
						
						
							|  |  |                             //            }
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  |                             //        else
 | 
						
						
						
							|  |  |                             //        {
 | 
						
						
						
							|  |  |                             //            if (viewsByTestCodes != null && viewsByTestCodes.Count > 0)
 | 
						
						
						
							|  |  |                             //            {
 | 
						
						
						
							|  |  |                             //                TFS_ViewMaterial view = viewsByTestCodes.Find(v => v.FBaseTestCode.Equals(bom.ATestCode));
 | 
						
						
						
							|  |  |                             //                if (view != null)
 | 
						
						
						
							|  |  |                             //                {
 | 
						
						
						
							|  |  |                             //                    bom.AMaterialCode = view.FSaleOldMaterialCode;
 | 
						
						
						
							|  |  |                             //                    bom.ASapCode = view.FBaseMaterialCode;
 | 
						
						
						
							|  |  |                             //                }
 | 
						
						
						
							|  |  |                             //            }
 | 
						
						
						
							|  |  |                             //        }
 | 
						
						
						
							|  |  |                             //    }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //    int formulaApplyHistoryId = FormulaBll.AddFormulaApplyHistroy(formula, user.FName, user.FID);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //    resultObj.Add("applyHistoryId", formulaApplyHistoryId);
 | 
						
						
						
							|  |  |                             //    resultObj.Add("bomList", bomList);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             //    bomListStr = JsonConvert.SerializeObject(resultObj);
 | 
						
						
						
							|  |  |                             //}
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     apiResult.Data = bomResult;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 递归梳理BOM
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="dataList">需要解析的集合</param>
 | 
						
						
						
							|  |  |         /// <param name="materLevel">层级</param>
 | 
						
						
						
							|  |  |         /// <param name="random">内部定义会有问题,需要外部传入</param>
 | 
						
						
						
							|  |  |         /// <param name="parentId">父子级关系ID</param>
 | 
						
						
						
							|  |  |         private Dictionary<string, object> CheckBomMaterial(List<BomModel> dataList, int materLevel, Random random, int parentId = -1)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             List<TFS_Material> mateList = new List<TFS_Material>();
 | 
						
						
						
							|  |  |             List<TFS_ViewMaterial> viewList = new List<TFS_ViewMaterial>();
 | 
						
						
						
							|  |  |             List<TFS_Formula> formulaList = new List<TFS_Formula>();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             string ids1 = "", ids2 = "";//需求变更ids2弃用
 | 
						
						
						
							|  |  |             string materialCodes = ",";
 | 
						
						
						
							|  |  |             string testCodes = ",";
 | 
						
						
						
							|  |  |             if (dataList != null && dataList.Count > 0)
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 foreach (BomModel item in dataList)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     if (!string.IsNullOrWhiteSpace(item.SP))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.Code = item.SP;
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     if (!string.IsNullOrWhiteSpace(item.SP_Version))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.Version = item.SP_Version;
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     if (!string.IsNullOrWhiteSpace(item.SP_VALUE))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.TestNO = item.SP_VALUE;
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     int dataId = random.Next(1, 99) * random.Next(1, 99);
 | 
						
						
						
							|  |  |                     dataId += random.Next(10, 99) * random.Next(10, 99) * 2;
 | 
						
						
						
							|  |  |                     dataId += random.Next(1, 99) * random.Next(1, 99) * 10;
 | 
						
						
						
							|  |  |                     TFS_Material material = new TFS_Material()
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         FID = DateTime.Now.DayOfYear * 10 + dataId,
 | 
						
						
						
							|  |  |                         FPlmCode = item.Code,
 | 
						
						
						
							|  |  |                         FName = item.Name,
 | 
						
						
						
							|  |  |                         //FCode = item.Code,
 | 
						
						
						
							|  |  |                         FType = item.Type!=null? item.Type.ToLower():"",
 | 
						
						
						
							|  |  |                         //FTestCode = item.TestNO,
 | 
						
						
						
							|  |  |                         FVersionCode = item.Version,
 | 
						
						
						
							|  |  |                         FParentID = parentId
 | 
						
						
						
							|  |  |                     };
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     TFS_ViewMaterial view = new TFS_ViewMaterial()
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         //FBaseFameCode = "",
 | 
						
						
						
							|  |  |                         //FBaseMaterialCode = material.FCode,
 | 
						
						
						
							|  |  |                         //FBaseTestCode = material.FTestCode,
 | 
						
						
						
							|  |  |                         FExtraQuantity = item.Quantity,
 | 
						
						
						
							|  |  |                         FBaseMaterialDesc = material.FName,
 | 
						
						
						
							|  |  |                         FLevel = materLevel,
 | 
						
						
						
							|  |  |                         FBomMaterialID = material.FID
 | 
						
						
						
							|  |  |                     };
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     
 | 
						
						
						
							|  |  |                     if (material.FType == "a" || material.FType == "f")
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         material.FType = "20";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (material.FType == "b" || material.FType == "bb" || material.FType == "i" || material.FType == "iz")
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         material.FType = "30";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         material.FType = "40";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if ("40".Equals(material.FType))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.ASapCode = item.SP_VALUE;
 | 
						
						
						
							|  |  |                         materialCodes = materialCodes + item.ASapCode + ",";
 | 
						
						
						
							|  |  |                         item.ATestCode = "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.ATestCode = item.SP_VALUE;
 | 
						
						
						
							|  |  |                         testCodes = testCodes + item.ATestCode + ",";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     List<TFS_ViewMaterial> viewsByMaterialCodes = FormulaBll.GetViewByMaterialCodes(materialCodes);
 | 
						
						
						
							|  |  |                     List<TFS_ViewMaterial> viewsByTestCodes = FormulaBll.GetViewByTestCodes(testCodes);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     MaterialBll materialBll = new MaterialBll();
 | 
						
						
						
							|  |  |                     TFS_Material tFS_Material = materialBll.GetMaterialListByFCode(item.SP_VALUE).FirstOrDefault();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (tFS_Material != null&& !string.IsNullOrWhiteSpace(tFS_Material.OldCode))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.ASapCode = tFS_Material.OldCode;
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else 
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.ASapCode = "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if ("40".Equals(material.FType))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.AMaterialCode = item.SP_VALUE;
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         if (viewsByTestCodes != null && viewsByTestCodes.Count > 0)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                            //TFS_ViewMaterial view2 = viewsByTestCodes.Find(v => v.FBaseTestCode.Equals(item.ATestCode));
 | 
						
						
						
							|  |  |                           
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             if (tFS_Material != null)
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 item.AMaterialCode = tFS_Material.FCode;
 | 
						
						
						
							|  |  |                                
 | 
						
						
						
							|  |  |                                 //item.AMaterialCode = view2.FSaleOldMaterialCode;
 | 
						
						
						
							|  |  |                                 //item.ASapCode = view2.FBaseMaterialCode;
 | 
						
						
						
							|  |  |                             }
 | 
						
						
						
							|  |  |                           
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     if (string.IsNullOrWhiteSpace(item.AMaterialCode)) 
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.AMaterialCode = "空";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     item.ABomType = "kg";
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (item.Name!=null&&item.Name.Contains("@"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.EnName = "甜味";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else if (item.Name != null && item.Name.Contains("□"))
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         item.EnName = "咸味";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else {
 | 
						
						
						
							|  |  |                         item.EnName = "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (materLevel == 0)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         material.FType = "20";
 | 
						
						
						
							|  |  |                         ids2 = material.FID + "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     if (material.FType == "40")
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         material.FCode = item.TestNO;
 | 
						
						
						
							|  |  |                         //material.FPlmCode = "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     
 | 
						
						
						
							|  |  |                     int.TryParse(material.FType, out int mType);
 | 
						
						
						
							|  |  |                     if (materLevel == 1) ids1 += material.FID + ",";
 | 
						
						
						
							|  |  |                     
 | 
						
						
						
							|  |  |                     mateList.Add(material);
 | 
						
						
						
							|  |  |                     viewList.Add(view);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (item.Specifications != null && item.Specifications.Count > 0)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         Dictionary<string, object> childData = CheckBomMaterial(item.Specifications, materLevel + 1, random, material.FID);
 | 
						
						
						
							|  |  |                         if (materLevel >= 1)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             formulaList.Add(new TFS_Formula()
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 FID = -1,
 | 
						
						
						
							|  |  |                                 FName = material.FName,
 | 
						
						
						
							|  |  |                                 FType = material.FType,
 | 
						
						
						
							|  |  |                                 FTestCode = material.FTestCode,
 | 
						
						
						
							|  |  |                                 FVersionCode = material.FVersionCode,
 | 
						
						
						
							|  |  |                                 FPlmCode = string.IsNullOrEmpty(material.FPlmCode) ? material.FCode : material.FPlmCode
 | 
						
						
						
							|  |  |                             });
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                         mateList.AddRange((List<TFS_Material>)childData["mateList"]);
 | 
						
						
						
							|  |  |                         viewList.AddRange((List<TFS_ViewMaterial>)childData["viewList"]);
 | 
						
						
						
							|  |  |                         formulaList.AddRange((List<TFS_Formula>)childData["formulaList"]);
 | 
						
						
						
							|  |  |                         ids1 = ids1.Trim(',') + "," + childData["formulaIds"] + ",";
 | 
						
						
						
							|  |  |                         ids2 = ids2.Trim(',') + "," + childData["halfIds"] + ",";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }
 | 
						
						
						
							|  |  |             return new Dictionary<string, object>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 { "mateList", mateList },
 | 
						
						
						
							|  |  |                 { "viewList", viewList },
 | 
						
						
						
							|  |  |                 { "formulaList", formulaList },
 | 
						
						
						
							|  |  |                 { "formulaIds", ids1.Trim(',') },
 | 
						
						
						
							|  |  |                 { "halfIds", ids2.Trim(',') },
 | 
						
						
						
							|  |  |                 { "bomList", dataList }
 | 
						
						
						
							|  |  |             };
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 根据物料号列表获取物料列表
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetMaterialList(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 string materialCodes = inParam["materialCodes"] == null ? "" : inParam["materialCodes"].ToString();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 List<object> materialList = FormulaBll.GetMaterialList(materialCodes);
 | 
						
						
						
							|  |  |                 apiResult.Data = materialList;
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 根据配方号获取配方申请历史
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult GetFormulaApplyHistory(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 string formulaId = inParam["formulaId"] == null ? "-1" : inParam["formulaId"].ToString();
 | 
						
						
						
							|  |  |                 string pageIndex = inParam["pageIndex"] == null ? "-1" : inParam["pageIndex"].ToString();
 | 
						
						
						
							|  |  |                 string pageSize = inParam["pageSize"] == null ? "-1" : inParam["pageSize"].ToString();
 | 
						
						
						
							|  |  |                 int nFormulaId = 0;
 | 
						
						
						
							|  |  |                 int nPageIndex = 0;
 | 
						
						
						
							|  |  |                 int nPageSize = 0;
 | 
						
						
						
							|  |  |                 int.TryParse(formulaId, out nFormulaId);
 | 
						
						
						
							|  |  |                 int.TryParse(pageIndex, out nPageIndex);
 | 
						
						
						
							|  |  |                 int.TryParse(pageSize, out nPageSize);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                 List<object> formulaApplyHistory = FormulaBll.GetFormulaApplyHistory(nFormulaId, nPageIndex, nPageSize);
 | 
						
						
						
							|  |  |                 apiResult.Data = formulaApplyHistory;
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 导出申请配方列表
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult ExportFormulaApplyInfo(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
 | 
						
						
						
							|  |  |             string rootPath = System.Web.Hosting.HostingEnvironment.MapPath("/");
 | 
						
						
						
							|  |  |             string savePath = "/File/Temp/配方清单/工艺样品生产记录表_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 if (inParam != null && inParam.ContainsKey("bomList"))
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     inParam.TryGetValue("bomList", out object bomObj);
 | 
						
						
						
							|  |  |                     List<Dictionary<string, object>> bomList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(bomObj));
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     inParam.TryGetValue("FID", out object oFid);
 | 
						
						
						
							|  |  |                     inParam.TryGetValue("ApplyHisId", out object oApplyHisId);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     string sFid = oFid != null ? oFid.ToString() : "-1";
 | 
						
						
						
							|  |  |                     int nFid = -1;
 | 
						
						
						
							|  |  |                     int.TryParse(sFid, out nFid);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     string sApplyHisId = oApplyHisId != null ? oApplyHisId.ToString() : "-1";
 | 
						
						
						
							|  |  |                     int nApplyHisId = -1;
 | 
						
						
						
							|  |  |                     int.TryParse(sApplyHisId, out nApplyHisId);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     string testCode = "";
 | 
						
						
						
							|  |  |                     string userName = user.FName;
 | 
						
						
						
							|  |  |                     string productNumber = "";
 | 
						
						
						
							|  |  |                     string productName = "";
 | 
						
						
						
							|  |  |                     string applyTime = DateTime.Now.ToString("yyyy-MM-dd");
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     List<TFS_Formula> formulaList = FormulaBll.GetFormulaListById(nFid);
 | 
						
						
						
							|  |  |                     if (formulaList != null && formulaList.Count > 0)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         TFS_Formula formula = formulaList[0];
 | 
						
						
						
							|  |  |                         testCode = formula.FTestCode;
 | 
						
						
						
							|  |  |                         productName = formula.FName;
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     bool exportResult = NPOIHelper.ExportBomlist(rootPath + "/File/Formula/配方申请模板.xlsx", rootPath + savePath, testCode, userName, productNumber, productName, applyTime, bomList);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (exportResult)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Data = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "").Trim('/') + savePath;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         TFS_FormulaApplyHistory formulaApplyHistory = FormulaBll.GetFormulaApplyHistory(nApplyHisId);
 | 
						
						
						
							|  |  |                         if (formulaApplyHistory != null)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             formulaApplyHistory.FExportTimes = formulaApplyHistory.FExportTimes + 1;
 | 
						
						
						
							|  |  |                             formulaApplyHistory.FLastExportTime = DateTime.Now;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             FormulaBll.UpdateFormulaApplyHistory(formulaApplyHistory);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Data = "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 else
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Data = "";
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 导出申请配方记录
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         /// <param name="inParam"></param>
 | 
						
						
						
							|  |  |         /// <returns></returns>
 | 
						
						
						
							|  |  |         [HttpPost]
 | 
						
						
						
							|  |  |         public ApiResult ExportFormulaApplyHistory(Dictionary<string, object> inParam)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             ApiResult apiResult = new ApiResult();
 | 
						
						
						
							|  |  |             string rootPath = System.Web.Hosting.HostingEnvironment.MapPath("/");
 | 
						
						
						
							|  |  |             string savePath = "/File/Temp/配方清单/查询记录_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |             return ExceptionHelper.TryReturnException(() =>
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 if (inParam != null && inParam.ContainsKey("applyHistory"))
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     inParam.TryGetValue("applyHistory", out object applyHistory);
 | 
						
						
						
							|  |  |                     List<Dictionary<string, object>> hisList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(applyHistory));
 | 
						
						
						
							|  |  |                     DataTable dataList = new DataTable();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                     if (hisList != null && hisList.Count > 0)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("申请日期");
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("申请人");
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("试验号");
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("产品名称");
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("导出次数");
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("最后导出时间");
 | 
						
						
						
							|  |  |                         dataList.Columns.Add("备注");
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         foreach (Dictionary<string, object> his in hisList)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             DataRow row = dataList.NewRow();
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             string applyTime = his["FApplyTime"] != null ? his["FApplyTime"].ToString() : "";
 | 
						
						
						
							|  |  |                             string userName = his["FUserName"] != null ? his["FUserName"].ToString() : "";
 | 
						
						
						
							|  |  |                             string testCode = his["FTestCode"] != null ? his["FTestCode"].ToString() : "";
 | 
						
						
						
							|  |  |                             string formulaName = his["FFormulaName"] != null ? his["FFormulaName"].ToString() : "";
 | 
						
						
						
							|  |  |                             string applyNumber = his["FApplyNumber"] != null ? his["FApplyNumber"].ToString() : "0";
 | 
						
						
						
							|  |  |                             string exportTimes = his["FExportTimes"] != null ? his["FExportTimes"].ToString() : "0";
 | 
						
						
						
							|  |  |                             string lastExportTime = string.Compare(exportTimes, "0") > 0 && his["FLastExportTime"] != null ? his["FLastExportTime"].ToString() : "";
 | 
						
						
						
							|  |  |                             string remark = his["FRemark"] != null ? his["FRemark"].ToString() : "";
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             row["申请日期"] = applyTime;
 | 
						
						
						
							|  |  |                             row["申请人"] = userName;
 | 
						
						
						
							|  |  |                             row["试验号"] = testCode;
 | 
						
						
						
							|  |  |                             row["产品名称"] = formulaName;
 | 
						
						
						
							|  |  |                             row["导出次数"] = exportTimes;
 | 
						
						
						
							|  |  |                             row["最后导出时间"] = lastExportTime;
 | 
						
						
						
							|  |  |                             row["备注"] = remark;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                             dataList.Rows.Add(row);
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |                         if (dataList != null && dataList.Rows.Count > 0)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             NPOIHelper.ExportDTtoExcel(dataList, "sheet1", rootPath + savePath);
 | 
						
						
						
							|  |  |                             apiResult.Data = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "").Trim('/') + savePath;
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                         else
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             apiResult.Data = "";
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     else
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         apiResult.Data = "";
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 else
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     apiResult.Data = "";
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |             }, apiResult, Request);
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         #region 内部方法
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         /// <summary>
 | 
						
						
						
							|  |  |         /// 模板上传处理(重构父方法)
 | 
						
						
						
							|  |  |         /// </summary>
 | 
						
						
						
							|  |  |         protected override object CheckUploadFile(List<string> fileList, int funcType, int userId)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             if (funcType <= 1)
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 List<TFS_Formula> formulas = new List<TFS_Formula>();
 | 
						
						
						
							|  |  |                 List<TFS_FieldInfo> fieldList = BaseBll.GetFileInfoList((int)Constant.FieldInfoType.配方模板导入);
 | 
						
						
						
							|  |  |                 List<PropertyInfo> formulaProp = typeof(TFS_Formula).GetTypeInfo().GetProperties().ToList();
 | 
						
						
						
							|  |  |                 PropertyInfo temp = null;
 | 
						
						
						
							|  |  |                 foreach (string filePath in fileList)
 | 
						
						
						
							|  |  |                 {
 | 
						
						
						
							|  |  |                     DataTable dt = NPOIHelper.ImportExceltoDt(filePath);
 | 
						
						
						
							|  |  |                     List<string> items = new List<string>();
 | 
						
						
						
							|  |  |                     for (int i = 0; i < dt.Columns.Count; i++)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         items.Add(dt.Columns[i].ColumnName);
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                     foreach (DataRow dr in dt.Rows)
 | 
						
						
						
							|  |  |                     {
 | 
						
						
						
							|  |  |                         TFS_Formula formula = new TFS_Formula();
 | 
						
						
						
							|  |  |                         foreach (var field in fieldList)
 | 
						
						
						
							|  |  |                         {
 | 
						
						
						
							|  |  |                             if ((temp = formulaProp.Find(s => s.Name.Equals(field.FColumnFIeld))) != null)
 | 
						
						
						
							|  |  |                             {
 | 
						
						
						
							|  |  |                                 temp.SetValue(formula, GetValueByName(dr, items, field.FFieldName, field.FDefault));
 | 
						
						
						
							|  |  |                             }
 | 
						
						
						
							|  |  |                         }
 | 
						
						
						
							|  |  |                         formulas.Add(formula);
 | 
						
						
						
							|  |  |                     }
 | 
						
						
						
							|  |  |                 }
 | 
						
						
						
							|  |  |                 return FormulaBll.DockingRecipeData(formulas, userId);
 | 
						
						
						
							|  |  |             }
 | 
						
						
						
							|  |  |             return fileList;
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         #endregion
 | 
						
						
						
							|  |  |     }
 | 
						
						
						
							|  |  | }
 |