物料新增路线增加视图导出功能

master
leo 3 years ago
parent b907e1224c
commit 4fc4ec11b9

@ -10,6 +10,9 @@ using System.Collections.Generic;
using System.Web.Http;
using FactorySystemModel.RequestModel;
using System.Reflection;
using System.Data;
using System.IO;
using System.Security.Cryptography;
namespace FactorySystemApi.Controllers
{
@ -579,5 +582,117 @@ namespace FactorySystemApi.Controllers
}
return result as T;
}
/// <summary>
/// 下载SAP视图
/// </summary>
[HttpPost]
public ApiResult DownMateialViewSAP(Dictionary<string, object> inParam)
{
ApiResult apiResult = new ApiResult();
return ExceptionHelper.TryReturnException(() =>
{
if (inParam.ContainsKey("teamId") && inParam.ContainsKey("teamWorkType"))
{
inParam.TryGetValue("teamId", out object teamworkId);
inParam.TryGetValue("teamWorkType", out object teamworkType);
inParam.TryGetValue("materialName", out object materialName);
string basePath = AppDomain.CurrentDomain.BaseDirectory.Trim('\\');
string savePath = basePath + string.Format("\\File\\Temp\\{0}_{1}\\", inParam["teamId"], "ViewSAP");
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
string tempPath = savePath.Replace("\\File\\Temp\\", "\\File\\View\\");
if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
savePath += ".xlsx";
bool hasFinish = inParam.ContainsKey("FFinish");
if (hasFinish) savePath = savePath.Replace("\\File\\Temp\\", "\\File\\View\\");
if (!File.Exists(savePath) || !hasFinish)
{
CreateExeclFileSAP(materialName.ToString(), savePath, teamworkId.ToString(), teamworkType.ToString());
}
string url = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "") + savePath.Replace(basePath, "").Replace("\\", "/").Replace(".xlsx", materialName.ToString() + ".xlsx");
apiResult.Data = url;
}
else
{
apiResult.Error("视图信息获取失败");
}
}, apiResult, Request);
}
/// <summary>
/// 下载视图
/// </summary>
[HttpPost]
public ApiResult DownMateialView(Dictionary<string, object> inParam)
{
ApiResult apiResult = new ApiResult();
return ExceptionHelper.TryReturnException(() =>
{
if (inParam.ContainsKey("teamId") && inParam.ContainsKey("teamWorkType") && inParam.ContainsKey("materialName"))
{
inParam.TryGetValue("teamId", out object teamworkId);
inParam.TryGetValue("teamWorkType", out object teamworkType);
inParam.TryGetValue("materialName", out object materialName);
string basePath = AppDomain.CurrentDomain.BaseDirectory.Trim('\\');
string savePath = basePath + string.Format("\\File\\Temp\\{0}_{1}\\", inParam["teamId"], "View");
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
string tempPath = savePath.Replace("\\File\\Temp\\", "\\File\\View\\");
if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
savePath += ".xlsx";
bool hasFinish = inParam.ContainsKey("FFinish");
if (hasFinish) savePath = savePath.Replace("\\File\\Temp\\", "\\File\\View\\");
if (!File.Exists(savePath) || !hasFinish)
{
CreateExeclFile(materialName.ToString(), savePath, teamworkId.ToString(), teamworkType.ToString());
}
string url = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "") + savePath.Replace(basePath, "").Replace("\\", "/").Replace(".xlsx", materialName.ToString() + ".xlsx");
apiResult.Data = url;
}
else
{
apiResult.Error("视图信息获取失败");
}
}, apiResult, Request);
}
private void CreateExeclFileSAP(string fType, string savePath, string teamworkId, string teamworkType)
{
DataTable dataList = new DataTable();
dataList = MaterialTeamworkBll.GetViewMaterialSAP(teamworkId, teamworkType);
NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", fType + ".xlsx"));
}
private void CreateExeclFile(string fType, string savePath, string teamworkId, string teamworkType)
{
DataTable dataList = null;
List<TFS_ViewMaterial> viewList = null;
int teamId;
int teamType;
int.TryParse(teamworkId, out teamId);
int.TryParse(teamworkType, out teamType);
viewList = MaterialTeamworkBll.GetViewMaterialByTeamId(teamId, teamType);
if (viewList != null && viewList.Count > 0)
{
int materialId = viewList[0].FMaterialID;
dataList = MaterialTeamworkBll.GetViewMaterial(materialId.ToString());
NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", fType + ".xlsx"));
}
}
}
}

@ -6,7 +6,9 @@ using FactorySystemModel.SqlSugarModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using static FactorySystemModel.EnumModel.Constant;
namespace FactorySystemBll
@ -162,8 +164,6 @@ namespace FactorySystemBll
.OrderBy("FDepth,FID").Select<dynamic>("FID,FName,FID FValue,FDepth,FParentID").ToList();
}
public int InsertMaterialView(TFS_ViewMaterial view)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
@ -368,5 +368,330 @@ namespace FactorySystemBll
return materialList;
}
public List<TFS_ViewMaterial> GetViewMaterialByTeamId(int teamworkId, int teamworkType)
{
List<TFS_ViewMaterial> viewList = null;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
if (teamworkType == 1)
{
viewList = db.Queryable<TFS_ViewMaterial>().Where(s => s.FTeamID == teamworkId && s.FTeamType == 1).ToList();
}
else
{
viewList = db.Queryable<TFS_ViewMaterial>().Where(s => s.FMdfMaterialTeamID == teamworkId && s.FTeamType == 1).ToList();
}
return viewList;
}
public DataTable GetViewMaterialSAP(string teamworkId, string teamworkType)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string strSql = @"
SELECT
isnull(FMaterialId, '') AS 'ID',
isnull(FOrganizeIndustryField, '') AS '.',
isnull(FOrganizeMaterialType, '') AS '.',
isnull(FOrganizeFactory, '') AS '.',
isnull(FOrganizeInventoryLocation, '') AS '.',
isnull(FOrganizeSalesOrganize, '') AS '.',
isnull(FOrganizeDistributionChannel, '') AS '.',
isnull(FBaseMaterialCode, '') AS '.',
isnull(FBaseTestCode, '') AS '.',
isnull(FBaseBasicMeter, '') AS '.',
isnull(FBaseMaterialDesc, '') AS '.',
isnull(FBaseMaterialGroup, '') AS '.',
isnull(FBaseSpecification, '') AS './()',
isnull(FBaseMaterialText, '') AS '.',
isnull(FBaseIdentifier, '') AS '.:/',
isnull(FBaseVolumeUnit, '') AS '.',
isnull(FBaseGrossWeight, '') AS '.',
isnull(FBaseNetWeight, '') AS '.',
isnull(FBaseWeightUnit, '') AS '.',
isnull(FBaseBusinessVolume, '') AS '.',
isnull(FBaseFameCode, '') AS '.fame',
isnull(FPurchaseGroup, '') AS '.',
isnull(FPurchaseCompany, '') AS '.',
isnull(FPurchaseCompanyCount, '') AS '.',
isnull(FPurchaseBaseCompanyCount, '') AS '.',
isnull(FPurchaseValueCode, '') AS '.',
isnull(FPurchaseFactorySpecificStatus, '') AS '.',
isnull(FPurchaseAutoOrder, '') AS '.',
isnull(FPurchaseGoodsSource, '') AS '.',
isnull(FTypeCategoryType, '') AS '.',
isnull(FTypeType, '') AS '.',
isnull(FSaleDeliveryFactory, '') AS '.',
isnull(FSaleTaxType, '') AS '.',
isnull(FSaleMaterialStatisticsGroup, '') AS '.',
isnull(FSaleSalesCompany, '') AS '.',
isnull(FSaleBaseCompanyCount, '') AS '.',
isnull(FSaleSalesCompanyCount, '') AS '.',
isnull(FSaleAccountSettingGroup, '') AS '.',
isnull(FSaleGeneralProjectCategoryGroup, '') AS '.',
isnull(FSaleProjectCategoryGroup, '') AS '.',
isnull(FSaleAvailabilityCheck, '') AS '.',
isnull(FSaleOutfitGroup, '') AS '.',
isnull(FSaleOldMaterialCode, '') AS '.',
isnull(FStorageConditions, '') AS '.',
isnull(FStorageBatchManage, '') AS '.',
isnull(FStorageMaxStoragePeriod, '') AS '.',
isnull(FStorageTimeUnit, '') AS '.',
isnull(FStorageMinSurplusShelfLife, '') AS '.寿',
isnull(FStorageTotalShelfLife, '') AS '.寿',
isnull(FStorageSLEDCode, '') AS '.SLED',
isnull(FMRP1Type, '') AS 'MRP1.MRP',
isnull(FMRP1Controller, '') AS 'MRP1.MRP',
isnull(FMRP1BatchSize, '') AS 'MRP1.',
isnull(FMRP1MinBatchSize, '') AS 'MRP1.',
isnull(FMRP1MaxBatchSize, '') AS 'MRP1.',
isnull(FMRP1Group, '') AS 'MRP1.MRP',
isnull(FMRP1RoundValue, '') AS 'MRP1. ',
isnull(FMRP1ProductType, '') AS 'MRP1.',
isnull(FMRP1CustomerCode, '') AS 'MRP1.',
isnull(FMRP1SizeMaterial, '') AS 'MRP1.',
isnull(FMRP1SmallMaterialStandard, '') AS 'MRP1. ()',
isnull(FMRP2PurchaseType, '') AS 'MRP2.',
isnull(FMRP2PlanMarginalCode, '') AS 'MRP2.',
isnull(FMRP2SpecialProcurement, '') AS 'MRP2.',
isnull(FMRP2Recoil, '') AS 'MRP2.',
isnull(FMRP2SelfProductTime, '') AS 'MRP2.',
isnull(FMRP2PlannDeliveryTime, '') AS 'MRP2.',
isnull(FMRP2ReceiveProcessTime, '') AS 'MRP2.',
isnull(FMRP2SafeStock, '') AS 'MRP2.',
isnull(FMRP2DeliveryInventoryPlace, '') AS 'MRP2.',
isnull(FMRP2ExternalStoragePlace, '') AS 'MRP2.',
isnull(FMRP3PolicyGroup, '') AS 'MRP3.',
isnull(FMRP3ConsumePattern, '') AS 'MRP3.',
isnull(FMRP3ForwardConsumePeriod, '') AS 'MRP3.',
isnull(FMRP3ReverseConsumePeriod, '') AS 'MRP3.',
isnull(FMRP3BlendMRP, '') AS 'MRP3.MRP',
isnull(FMRP3AvailabilityCheck, '') AS 'MRP3.',
isnull(FMRP4AloneOrFocus, '') AS 'MRP4.',
isnull(FPlanProductPlanParam, '') AS '.',
isnull(FPlanUnlimitedOverDelivery, '') AS '.',
isnull(FPlanUnderDeliveryTolerance, '') AS '.',
isnull(FPlanOverDeliveryTolerance, '') AS '.',
isnull(FPlanDeliverCompany, '') AS '.',
isnull(FPlanDeliverCompanyCount, '') AS '.',
isnull(FPlanBaseCompanyCount, '') AS '.',
isnull(FQualityType1, '') AS '.1',
isnull(FQualityType2, '') AS '.2',
isnull(FQualityType3, '') AS '.3',
isnull(FQualityType4, '') AS '.4',
isnull(FQualityType5, '') AS '.5',
isnull(FQualityType6, '') AS '.6',
isnull(FAccountPriceControl, '') AS '.',
isnull(FAccountPriceDetermine, '') AS '.',
isnull(FAccountPriceUnit, '') AS '.',
isnull(FAccountAccessType, '') AS '.',
isnull(FAccountSaleOrderInventory, '') AS '.VC: ',
isnull(FAccountStandardPrice, '') AS '.',
isnull(FAccountProfitCenter, '') AS '.',
isnull(FAccountCostAccountBatch, '') AS '.',
isnull(FExtraQuantity, '') AS 'bomPLMBOM',
isnull(FMRP1ReorderLocation, '') AS 'MRP1.',
isnull(FMRP1RegularBatchSize, '') AS 'MRP1.',
isnull(FMRP1MaxInventorySize, '') AS 'MRP1.',
isnull(FMRP1IgnoreLack, '') AS 'MRP1.',
isnull(FMRP1laminated, '') AS 'MRP1.',
isnull(FMRP1SafeStock, '') AS 'MRP1.',
isnull(FMRP1RequireCount, '') AS 'MRP1.',
isnull(FMRP4DiscontinuousIidentifier, '') AS 'MRP4.',
isnull(FMRP4EffectivePeriod, '') AS 'MRP4.',
isnull(FMRP4FollowMaterial, '') AS 'MRP4.'
FROM TFS_ViewMaterial";
if ("2".Equals(teamworkType))
{
string whereSql = string.Format(" Where FTeamType=1 And FMdfMaterialTeamID={0}", teamworkId);
strSql = strSql + whereSql;
}
else
{
string whereSql = string.Format(" Where FTeamType=1 And FTeamID={0}", teamworkId);
strSql = strSql + whereSql;
}
DataTable data = db.Ado.GetDataTable(strSql);
return data;
}
public DataTable GetViewMaterial(string FID)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string strSql = string.Format(@"
SELECT
isnull( FTypeName1, '' ) AS '',
isnull( FTypeName2, '' ) AS '',
isnull( FK3Code, '' ) AS 'K3',
isnull( FK3Name, '' ) AS 'K3',
isnull( FK3ShortCode, '' ) AS 'K3',
isnull( FTestCode, '' ) AS '',
isnull( FCode, '' ) AS 'SAP',
isnull( FName, '' ) AS 'SAP',
isnull( FMaterialGroup, '' ) AS '',
isnull( FMaterialType, '' ) AS '',
isnull( FCustomerCode, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FBomEntry, '' ) AS 'BOM',
isnull( FLineHouse, '' ) AS '线',
isnull( FProductDesc, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FIidentifier, '' ) AS '',
isnull( FGuaranteePeriod, '' ) AS '',
isnull( FStorageConditions, '' ) AS '',
isnull( FSafetyStock, '' ) AS '',
isnull( FTriggerRatio, '' ) AS '',
isnull( FMinAmount, '' ) AS '',
isnull( FMaxAmount, '' ) AS '',
isnull( FYield, '' ) AS '',
isnull( FFixedLoss, '' ) AS '',
isnull( FTheoryYield, '' ) AS '',
isnull( FQualityTest1, '' ) AS '1',
isnull( FQualityTest2, '' ) AS '2',
isnull( FName, '' ) AS '',
isnull( FDesc, '' ) AS '',
isnull( FType, '' ) AS '',
isnull( FCode, '' ) AS '',
isnull( FTestCode, '' ) AS '',
isnull( FVersionCode, '' ) AS '',
isnull( FFactoryCode, '' ) AS '',
isnull( FSupplyCode, '' ) AS '',
isnull( FGroupCode, '' ) AS '',
isnull( FBaseUnit, '' ) AS '',
isnull( FMaterialGroup, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftDesc, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FLineHouse, '' ) AS '线',
isnull( FFixedLoss, '' ) AS '',
isnull( FOrganizeIndustryField, '' ) AS '.',
isnull( FOrganizeMaterialType, '' ) AS '.',
isnull( FOrganizeFactory, '' ) AS '.',
isnull( FOrganizeInventoryLocation, '' ) AS '.',
isnull( FOrganizeSalesOrganize, '' ) AS '.',
isnull( FOrganizeDistributionChannel, '' ) AS '.',
isnull( FBaseMaterialCode, '' ) AS '.',
isnull( FBaseTestCode, '' ) AS '.',
isnull( FBaseBasicMeter, '' ) AS '.',
isnull( FBaseMaterialDesc, '' ) AS '.',
isnull( FBaseMaterialGroup, '' ) AS '.',
isnull( FBaseSpecification, '' ) AS './()',
isnull( FBaseMaterialText, '' ) AS '.',
isnull( FBaseIdentifier, '' ) AS '.:/',
isnull( FBaseVolumeUnit, '' ) AS '.',
isnull( FBaseGrossWeight, '' ) AS '.',
isnull( FBaseNetWeight, '' ) AS '.',
isnull( FBaseWeightUnit, '' ) AS '.',
isnull( FBaseBusinessVolume, '' ) AS '.',
isnull( FBaseFameCode, '' ) AS '.fame',
isnull( FPurchaseGroup, '' ) AS '.',
isnull( FPurchaseCompany, '' ) AS '.',
isnull( FPurchaseCompanyCount, '' ) AS '.',
isnull( FPurchaseBaseCompanyCount, '' ) AS '.',
isnull( FPurchaseValueCode, '' ) AS '.',
isnull( FPurchaseFactorySpecificStatus, '' ) AS '.',
isnull( FPurchaseAutoOrder, '' ) AS '.',
isnull( FPurchaseGoodsSource, '' ) AS '.',
isnull( FTypeCategoryType, '' ) AS '.',
isnull( FTypeType, '' ) AS '.',
isnull( FSaleDeliveryFactory, '' ) AS '.',
isnull( FSaleTaxType, '' ) AS '.',
isnull( FSaleMaterialStatisticsGroup, '' ) AS '.',
isnull( FSaleSalesCompany, '' ) AS '.',
isnull( FSaleBaseCompanyCount, '' ) AS '.',
isnull( FSaleSalesCompanyCount, '' ) AS '.',
isnull( FSaleAccountSettingGroup, '' ) AS '.',
isnull( FSaleGeneralProjectCategoryGroup, '' ) AS '.',
isnull( FSaleProjectCategoryGroup, '' ) AS '.',
isnull( FSaleAvailabilityCheck, '' ) AS '.',
isnull( FSaleOutfitGroup, '' ) AS '.',
isnull( FSaleOldMaterialCode, '' ) AS '.',
isnull( FStorageConditions, '' ) AS '.',
isnull( FStorageBatchManage, '' ) AS '.',
isnull( FStorageMaxStoragePeriod, '' ) AS '.',
isnull( FStorageTimeUnit, '' ) AS '.',
isnull( FStorageMinSurplusShelfLife, '' ) AS '.寿',
isnull( FStorageTotalShelfLife, '' ) AS '.寿',
isnull( FStorageSLEDCode, '' ) AS '.SLED',
isnull( FMRP1Type, '' ) AS 'MRP1.MRP',
isnull( FMRP1Controller, '' ) AS 'MRP1.MRP',
isnull( FMRP1BatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MinBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MaxBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1Group, '' ) AS 'MRP1.MRP',
isnull( FMRP1RoundValue, '' ) AS 'MRP1.',
isnull( FMRP1ProductType, '' ) AS 'MRP1.',
isnull( FMRP1CustomerCode, '' ) AS 'MRP1.',
isnull( FMRP1SizeMaterial, '' ) AS 'MRP1.',
isnull( FMRP1SmallMaterialStandard, '' ) AS 'MRP1.',
isnull( FMRP2PurchaseType, '' ) AS 'MRP2.',
isnull( FMRP2PlanMarginalCode, '' ) AS 'MRP2.',
isnull( FMRP2SpecialProcurement, '' ) AS 'MRP2.',
isnull( FMRP2Recoil, '' ) AS 'MRP2.',
isnull( FMRP2SelfProductTime, '' ) AS 'MRP2.',
isnull( FMRP2PlannDeliveryTime, '' ) AS 'MRP2.',
isnull( FMRP2ReceiveProcessTime, '' ) AS 'MRP2.',
isnull( FMRP2SafeStock, '' ) AS 'MRP2.',
isnull( FMRP2DeliveryInventoryPlace, '' ) AS 'MRP2.',
isnull( FMRP2ExternalStoragePlace, '' ) AS 'MRP2.',
isnull( FMRP3PolicyGroup, '' ) AS 'MRP3.',
isnull( FMRP3ConsumePattern, '' ) AS 'MRP3.',
isnull( FMRP3ForwardConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3ReverseConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3BlendMRP, '' ) AS 'MRP3.MRP',
isnull( FMRP3AvailabilityCheck, '' ) AS 'MRP3.',
isnull( FMRP4AloneOrFocus, '' ) AS 'MRP3.',
isnull( FPlanProductPlanParam, '' ) AS '.',
isnull( FPlanUnlimitedOverDelivery, '' ) AS '.',
isnull( FPlanUnderDeliveryTolerance, '' ) AS '.',
isnull( FPlanOverDeliveryTolerance, '' ) AS '.',
isnull( FPlanDeliverCompany, '' ) AS '.',
isnull( FPlanDeliverCompanyCount, '' ) AS '.',
isnull( FPlanBaseCompanyCount, '' ) AS '.',
isnull( FQualityType1, '' ) AS '.1',
isnull( FQualityType2, '' ) AS '.2',
isnull( FQualityType3, '' ) AS '.3',
isnull( FQualityType4, '' ) AS '.4',
isnull( FQualityType5, '' ) AS '.5',
isnull( FQualityType6, '' ) AS '.6',
isnull( FAccountPriceControl, '' ) AS '.',
isnull( FAccountPriceDetermine, '' ) AS '.',
isnull( FAccountPriceUnit, '' ) AS '.',
isnull( FAccountAccessType, '' ) AS '.',
isnull( FAccountSaleOrderInventory, '' ) AS '.VC: ',
isnull( FAccountStandardPrice, '' ) AS '.',
isnull( FAccountProfitCenter, '' ) AS '.',
isnull( FAccountCostAccountBatch, '' ) AS '.'
FROM(
SELECT
isnull( b.FName, '' ) AS 'FTypeName1',
isnull( c.FName, '' ) AS 'FTypeName2',
isnull( FSAPCode, '' ) AS 'FCode',
isnull( FSAPDescription, '' ) AS 'FName',
isnull( FBaseMaterialDesc, '' ) AS 'FDesc',
isnull( FBaseMaterialDesc, '' ) AS 'FVersionCode',
isnull( FBaseMaterialDesc, '' ) AS 'FFactoryCode',
isnull( FBaseMaterialDesc, '' ) AS 'FSupplyCode',
isnull( FBaseMaterialGroup, '' ) AS 'FGroupCode',
isnull( FBaseWeightUnit, '' ) AS 'FBaseUnit',
isnull( FCraftExplain, '' ) AS 'FCraftDesc',
d.FName AS 'FtypeName',
a.*
FROM
TFS_MaterialInfo AS a
LEFT JOIN TFS_MaterialType AS d ON a.FType=d.FID
LEFT JOIN TFS_MaterialType AS b ON a.FTypeID1= b.FID
LEFT JOIN TFS_MaterialType AS C ON a.FTypeID2= b.FID
WHERE
FDataId = {0})a;", FID);
DataTable data = db.Ado.GetDataTable(strSql);
return data;
}
}
}

Loading…
Cancel
Save