@@ -125,7 +125,7 @@ namespace BPA.SAAS.Manage.Application.DataBase | |||
/// <summary> | |||
/// 删除配方 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/bom/DelBom")] | |||
public async Task<bool> DelBom(string id) | |||
@@ -9,7 +9,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods | |||
{ | |||
public class BatchingModel | |||
{ | |||
[Column("仓位号")] | |||
[Column("仓位")] | |||
public string Index { get; set; } | |||
[Column("物料名称")] | |||
public string BatchingName { get; set; } | |||
@@ -0,0 +1,32 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods | |||
{ | |||
public class GoodsTechnologyImportDto | |||
{ | |||
/// <summary> | |||
/// 文件 | |||
/// </summary> | |||
public IFormFile file { get; set; } | |||
} | |||
public class GoodsTechnologyExportDto | |||
{ | |||
/// <summary> | |||
/// 商品Id | |||
/// </summary> | |||
public string GoodId { get; set; } | |||
/// <summary> | |||
/// 设备Id | |||
/// </summary> | |||
public string DeviceId { get; set; } | |||
/// <summary> | |||
/// 文档名 | |||
/// </summary> | |||
public string FileName { get; set; } | |||
} | |||
} |
@@ -0,0 +1,31 @@ | |||
using Npoi.Mapper.Attributes; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods | |||
{ | |||
public class GoodsTechnologyDataModel | |||
{ | |||
public string Ids { get; set; } | |||
public string Names { get; set; } | |||
public List<GoodsTechnologyValueModel> Values { get; set; } | |||
} | |||
public class GoodsTechnologyValueModel | |||
{ | |||
public string StepName { get;set; } | |||
public string ActionName { get;set; } | |||
public string ActionValue { get;set; } | |||
public string Index { get;set; } | |||
} | |||
public class ActionJsonModel | |||
{ | |||
public string actionName { get;set; } | |||
public string actionValue { get;set; } | |||
public string technologyactionId { get;set; } | |||
public string index { get;set;} | |||
} | |||
} |
@@ -11,5 +11,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology | |||
public string devideId { get; set; } | |||
public string goodsId { get; set; } | |||
public string goodsAttributeId { get; set; } | |||
public string warehousrTemplateId { get; set; } | |||
} | |||
} |
@@ -12,6 +12,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology | |||
public string WarehousrTemplateId { get; set; } | |||
public string GoodsAttributeId { get; set; } | |||
public string DeviceName { get; set; } | |||
public int Order { get; set; } | |||
public List<GoodsTechnologyActionView> Data { get; set; } | |||
} | |||
public class GoodsTechnologyActionView | |||
@@ -44,6 +45,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology | |||
public string GoodsId { get; set; } | |||
public string DeviceId { get; set; } | |||
public string WarehousrTemplateId { get; set; } | |||
public int Order { get; set; } | |||
} | |||
public class DeviceTechnologyActionListView | |||
@@ -0,0 +1,15 @@ | |||
using BPA.SAAS.Manage.Core.Base; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology | |||
{ | |||
public class GoodsTechnologyQueryDto : PageInputBase | |||
{ | |||
public string GoodsId { get; set; } | |||
public string DeviceName { get; set; } | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
using System; | |||
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -14,5 +15,19 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsType | |||
public int Sort { get; set; } | |||
public int Status { get; set; } | |||
public string Remark { get; set; } | |||
public List<AttributeDto> AttributeList { get; set; } | |||
} | |||
public class AttributeDto | |||
{ | |||
public string AttributeName { get; set; } | |||
public int Sort { get; set; } | |||
public List<AttributeValueDto> AttributeValueList { get; set; } | |||
} | |||
public class AttributeValueDto | |||
{ | |||
public string AttributeValue { get; set; } | |||
public int Sort { get; set; } | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
using BPA.SAAS.Manage.Comm.Enum; | |||
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; | |||
using BPA.SAAS.Manage.Comm.Enum; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
@@ -17,5 +18,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsType | |||
public CommonStatus Status { get; set; } | |||
public string Pid { get; set; }//父级字段 | |||
public List<GoodsTypeTree> Children { get; set; } | |||
public List<GoodsAttributeView> GoodsAttributeViewList { get;set; } | |||
} | |||
} |
@@ -98,6 +98,15 @@ namespace BPA.SAAS.Manage.Application.DataBase | |||
{ | |||
return await _goodsAttributeServices.GetByGoodsIdAttribute(id); | |||
} | |||
/// <summary> | |||
/// 获取商品属性和属性值 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/goodsattribute/GetGoodsAttributeList")] | |||
public async Task<List<GoodsAttributeView>> GetGoodsAttributeViewList(string id) | |||
{ | |||
return await _goodsAttributeServices.GetGoodsAttributeViewList(id); | |||
} | |||
} | |||
} |
@@ -192,5 +192,26 @@ namespace BPA.SAAS.Manage.Application.DataBase | |||
{ | |||
return await _goodsService.DeviceVersionTemplateImport(inputDto); | |||
} | |||
/// <summary> | |||
/// 商品工艺导入 | |||
/// </summary> | |||
/// <param name="importDto"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/goods/goodsTechnologyImport"), NonUnify] | |||
public async Task<bool> GoodsTechnologyImport([FromForm]GoodsTechnologyImportDto importDto) | |||
{ | |||
return await _goodsService.GoodsTechnologyImport(importDto); | |||
} | |||
/// <summary> | |||
/// 商品工艺导出 | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpPost("/api/goods/goodsTechnologyExport"), NonUnify] | |||
public async Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto) | |||
{ | |||
return await _goodsService.GoodsTechnologyExport(exportDto); | |||
} | |||
} | |||
} |
@@ -113,9 +113,15 @@ namespace BPA.SAAS.Manage.Application.DataBase | |||
return await _goodsTechnologyService.CopyTechnologyAction(param); | |||
} | |||
/// <summary> | |||
/// 根据设备获取工艺(分页) | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/goodstechnology/GetGoodsTechnologyPage")] | |||
public async Task<PageUtil> GetGoodsTechnologyPage(GoodsTechnologyQueryDto dto) | |||
{ | |||
return await _goodsTechnologyService.GetGoodsTechnologyPage(dto); | |||
} | |||
} | |||
} |
@@ -59,5 +59,11 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface | |||
/// <returns></returns> | |||
Task<List<GoodsAttributeList>> GetByGoodsIdAttribute(string id); | |||
Task<List<GoodsAttributeList>> GetByNameAttribute(string name); | |||
/// <summary> | |||
/// 获取商品属性和属性值 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
Task<List<GoodsAttributeView>> GetGoodsAttributeViewList(string id); | |||
} | |||
} |
@@ -102,5 +102,18 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface | |||
/// </summary> | |||
/// <returns></returns> | |||
Task<bool> DeviceVersionTemplateImport(DeviceVersionTemplateImportInputDto inputDto); | |||
/// <summary> | |||
/// 商品工艺导入 | |||
/// </summary> | |||
/// <param name="importDto"></param> | |||
/// <returns></returns> | |||
Task<bool> GoodsTechnologyImport([FromForm] GoodsTechnologyImportDto importDto); | |||
/// <summary> | |||
/// 商品工艺导出 | |||
/// </summary> | |||
/// <returns></returns> | |||
Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto); | |||
} | |||
} |
@@ -25,5 +25,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface | |||
Task<bool> CopyTechnologyAction(IputParam param); | |||
Task<PageUtil> GetGoodsTechnologyPage(GoodsTechnologyQueryDto dto); | |||
} | |||
} |
@@ -337,7 +337,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
/// <summary> | |||
/// 删除配方 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public async Task<bool> DelBom(string id) | |||
{ | |||
@@ -345,8 +345,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
try | |||
{ | |||
_db.Ado.BeginTran(); | |||
await _db.Deleteable<BPA_Bom>().Where(x => x.Id == id).ExecuteCommandAsync(); | |||
await _db.Deleteable<BPA_BomEntry>().Where(x => x.BomId == id).ExecuteCommandAsync(); | |||
var ids = id.Split(","); | |||
await _db.Deleteable<BPA_Bom>().Where(x =>ids.Contains(x.Id)).ExecuteCommandAsync(); | |||
await _db.Deleteable<BPA_BomEntry>().Where(x => ids.Contains(x.BomId)).ExecuteCommandAsync(); | |||
_db.Ado.CommitTran(); | |||
return true; | |||
} | |||
@@ -361,6 +361,32 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices | |||
.ToListAsync(); | |||
return goodsAttributeList; | |||
} | |||
/// <summary> | |||
/// 获取商品属性和属性值 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public async Task<List<GoodsAttributeView>> GetGoodsAttributeViewList(string id) | |||
{ | |||
var goodType = await _db.Queryable<BPA_GoodsType>().Where(x => x.Id == id).FirstAsync(); | |||
if (goodType == null) throw Oops.Oh("商品分类不存在"); | |||
var res = await _db.Queryable<BPA_GoodsAttribute>() | |||
.Where(a => a.IsDeleted == 0) | |||
.WhereIF(!id.IsNullOrWhiteSpace(), x => x.GoodsTypeId.Contains(id)) | |||
.OrderBy(a => a.CreateAt, OrderByType.Desc) | |||
.Select(a => new GoodsAttributeView | |||
{ | |||
Id = a.Id, | |||
AttributeName = a.AttributeName, | |||
GoodsTypeId = a.GoodsTypeId, | |||
Sort = a.Sort, | |||
}) | |||
.Mapper(x => | |||
{ | |||
var list = _db.Queryable<BPA_GoodsAttributeValue>().Where(p => p.GoodsAttributeId == x.Id).OrderBy(x => x.Sort).ToList(); | |||
x.AttributeValueList = list; | |||
}).ToListAsync(); | |||
return res; | |||
} | |||
} | |||
} |
@@ -16,6 +16,7 @@ using BPA.SAAS.Manage.Core.DataBase; | |||
using BPA.SAAS.Manage.Core.Device; | |||
using BPA.SAAS.Manage.Core.Product; | |||
using Furion.ClayObject.Extensions; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Newtonsoft.Json; | |||
using Npoi.Mapper; | |||
using NPOI.HSSF.UserModel; | |||
@@ -32,6 +33,7 @@ using System.Drawing.Imaging; | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Text; | |||
using System.Text.RegularExpressions; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
@@ -42,12 +44,14 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
IGoodsAttributeService _goodsAttributeService; | |||
ISystemConfigService _SystemConfigService; | |||
IAliyunOssService _aliyunOssService; | |||
public GoodsService(ISqlSugarClient db, IGoodsAttributeService goodsAttributeService, ISystemConfigService SystemConfigService, IAliyunOssService aliyunOssService) | |||
IWebHostEnvironment _hostingEnvironment; | |||
public GoodsService(ISqlSugarClient db, IGoodsAttributeService goodsAttributeService, ISystemConfigService SystemConfigService, IAliyunOssService aliyunOssService, IWebHostEnvironment webHostEnvironment) | |||
{ | |||
_db=db; | |||
_goodsAttributeService=goodsAttributeService; | |||
_SystemConfigService = SystemConfigService; | |||
_aliyunOssService = aliyunOssService; | |||
_hostingEnvironment = webHostEnvironment; | |||
} | |||
/// <summary> | |||
/// 分页查询 | |||
@@ -300,7 +304,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
resEntity.Price = dto.Price; | |||
resEntity.IsWeigh = dto.IsWeigh; | |||
resEntity.GoodsUintId = dto.GoodsUintId; | |||
resEntity.IsAttrubute = Convert.ToBoolean(dto.IsAttrubute); | |||
if (!string.IsNullOrWhiteSpace(dto.Status)) | |||
{ | |||
resEntity.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), int.Parse(dto.Status)); | |||
@@ -316,20 +319,22 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
/// <returns></returns> | |||
public async Task<bool> DeleteGoods(string id) | |||
{ | |||
var res = 0; | |||
try | |||
{ | |||
_db.Ado.BeginTran(); | |||
var ids = id.Split(","); | |||
var goods = _db.Queryable<BPA_GoodsInfo>().Where(x =>ids.Contains( x.Id)).First(); | |||
if (goods == null) throw Oops.Oh("商品不存在"); | |||
var goodsbom = _db.Queryable<BPA_GoodsBom>().Where(x => ids.Contains(x.Goods_Id)).ToList(); | |||
var goodsTechnology = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => ids.Contains(x.GoodsId)).ToList(); | |||
//var FoodMenuGoods = _db.Queryable<BPA_FoodMenuGoods>().Where(x => x.GoodsId == id).ToList(); | |||
await _db.Deleteable(goodsbom).ExecuteCommandAsync(); | |||
await _db.Deleteable(goodsTechnology).ExecuteCommandAsync(); | |||
//await _db.Deleteable(FoodMenuGoods).ExecuteCommandAsync(); | |||
var res = await _db.Deleteable(goods).ExecuteCommandAsync(); | |||
foreach (var idItem in ids) | |||
{ | |||
var good = _db.Queryable<BPA_GoodsInfo>().Where(x => x.Id == idItem).First(); | |||
if (good == null) | |||
throw Oops.Oh("商品不存在"); | |||
var goodsbom = _db.Queryable<BPA_GoodsBom>().Where(x => ids.Contains(x.Goods_Id)).ToList(); | |||
var goodsTechnology = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => ids.Contains(x.GoodsId)).ToList(); | |||
await _db.Deleteable(goodsbom).ExecuteCommandAsync(); | |||
await _db.Deleteable(goodsTechnology).ExecuteCommandAsync(); | |||
res += await _db.Deleteable(good).ExecuteCommandAsync(); | |||
} | |||
_db.Ado.CommitTran(); | |||
return res > 0; | |||
} | |||
@@ -338,7 +343,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
_db.Ado.RollbackTran(); | |||
throw Oops.Oh("删除失败"); | |||
} | |||
} | |||
/// <summary> | |||
/// 查询商品单位 | |||
@@ -1250,6 +1254,354 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
return true; | |||
} | |||
/// <summary> | |||
/// 商品工艺导入 | |||
/// </summary> | |||
/// <param name="importDto"></param> | |||
/// <returns></returns> | |||
public async Task<bool> GoodsTechnologyImport(GoodsTechnologyImportDto importDto) | |||
{ | |||
string pattern = @"(?<part1>[^,(]+),(?<part2>\([^)]+\)),(?<part3>[^,]+)"; | |||
var file = importDto.file; | |||
var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; | |||
if (string.IsNullOrEmpty(userId)) | |||
{ | |||
userId = ""; | |||
} | |||
var goodsInfoList = await _db.Queryable<BPA_GoodsInfo>().ToListAsync(); | |||
var deviceList = await _db.Queryable<BPA_DeviceInfo>().ToListAsync(); | |||
var technologyList = await _db.Queryable<BPA_Technology>().ToListAsync(); | |||
var technologyActionList = await _db.Queryable<BPA_TechnologyAction>().ToListAsync(); | |||
var wareHouseTemplateList = await _db.Queryable<BPA_WarehouseTemplate>().OrderBy(a => a.Id).ToListAsync(); | |||
var batchList = await _db.Queryable<BPA_Batching, BPA_BatchingType>((a, b) => new JoinQueryInfos(JoinType.Left, a.TypeID == b.Id)).Select((a, b) => new BatchingView() { Id = a.Id, Name = a.Batching_Name, TypeName = b.Name }).ToListAsync(); | |||
try | |||
{ | |||
_db.Ado.BeginTran(); | |||
var sheetNameList = GetSheetNameList(file.OpenReadStream()); | |||
foreach (var sheetName in sheetNameList) | |||
{ | |||
var source = file.OpenReadStream(); | |||
var mapper = new Mapper(source); | |||
var objModel = new ReadExcel<object>(); | |||
var objList = objModel.ExcelToList(source, mapper, sheetName); | |||
var modelList = UpdateObjectToModel(objList); | |||
modelList.RemoveAll(t => t.StepName == "主料(例)" && t.ActionName == "主料名称(例)" && t.ActionValue == "水(例)" && t.Index == "1(例)"); | |||
modelList.RemoveAll(t => t.StepName == "主料(例)" && t.ActionName == "主料位置(例)" && t.ActionValue == "1号位(例)" && t.Index == "2(例)"); | |||
modelList.RemoveAll(t => t.StepName == null && t.ActionName == null && t.ActionValue == null && t.Index == null); | |||
modelList.RemoveAll(t => t.StepName == "工序" && t.ActionName == "工序参数" && t.ActionValue == "工序参数值" && t.Index == "值序号"); | |||
var modelMatch = Regex.Match(modelList[0].StepName, pattern); | |||
var deviceId = modelMatch.Groups["part3"].Value.Trim(); | |||
var deviceInfo = deviceList.FirstOrDefault(t => t.Id == deviceId); | |||
wareHouseTemplateList = wareHouseTemplateList.Where(t => t.DeviceId == deviceId).ToList(); | |||
if (!wareHouseTemplateList.Any()) | |||
throw Oops.Oh($"{deviceInfo.DeviceName}不存在仓位模版,请先添加仓位模版!"); | |||
var goodId = modelMatch.Groups["part1"].Value.Trim(); | |||
await _db.Deleteable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == goodId).ExecuteCommandAsync(); | |||
var stepName = ""; | |||
var actionName = ""; | |||
var ids = ""; | |||
var names = ""; | |||
var dataModel = new GoodsTechnologyDataModel { Values = new List<GoodsTechnologyValueModel>() }; | |||
var dataList = new List<GoodsTechnologyDataModel>(); | |||
foreach (var model in modelList) | |||
{ | |||
if (model.ActionName.Contains(sheetName)) | |||
{ | |||
if (model.ActionValue == null && dataModel.Values.Count > 0) | |||
{ | |||
dataList.Add(dataModel); | |||
dataModel = new GoodsTechnologyDataModel(); | |||
} | |||
dataModel.Ids = model.StepName; | |||
dataModel.Names = model.ActionName; | |||
dataModel.Values = new List<GoodsTechnologyValueModel>(); | |||
ids = model.StepName; | |||
names = model.ActionName; | |||
stepName = ""; | |||
actionName = ""; | |||
} | |||
else | |||
{ | |||
if (stepName == "" || stepName == model.StepName) | |||
{ | |||
if(actionName == model.ActionName) | |||
{ | |||
dataList.Add(dataModel); | |||
dataModel = new GoodsTechnologyDataModel | |||
{ | |||
Ids = ids, | |||
Names = names, | |||
Values = new List<GoodsTechnologyValueModel> { model } | |||
}; | |||
} | |||
else | |||
{ | |||
dataModel.Values.Add(model); | |||
if (actionName == "") | |||
actionName = model.ActionName; | |||
} | |||
} | |||
else | |||
{ | |||
dataList.Add(dataModel); | |||
dataModel = new GoodsTechnologyDataModel | |||
{ | |||
Ids = ids, | |||
Names = names, | |||
Values = new List<GoodsTechnologyValueModel> { model } | |||
}; | |||
actionName = model.ActionName; | |||
} | |||
stepName = model.StepName; | |||
} | |||
} | |||
var oldAtteibuteId = ""; | |||
var sort = 1; | |||
var order = 0; | |||
foreach (var data in dataList) | |||
{ | |||
var attributeId = ""; | |||
Match idsMatch = Regex.Match(data.Ids, pattern); | |||
if (idsMatch.Success) | |||
attributeId = idsMatch.Groups["part2"].Value.Trim()[1..^1]; | |||
if (oldAtteibuteId == attributeId) | |||
sort++; | |||
else | |||
{ | |||
order++; | |||
sort = 1; | |||
} | |||
FillStepName(data.Values); | |||
var groupList = data.Values.GroupBy(t => t.StepName).ToList(); | |||
foreach (var groupItem in groupList) | |||
{ | |||
technologyList = technologyList.Where(t => t.DeviceVersionId == deviceList.FirstOrDefault(a => a.Id == deviceId)?.ProductVersionId).ToList(); | |||
technologyActionList = technologyActionList.Where(t => technologyList.Select(a => a.Id).Contains(t.TechnologyId)).ToList(); | |||
var technology = technologyList.FirstOrDefault(t => t.Name == groupItem.Key); | |||
if (technology == null) | |||
throw Oops.Oh($"{data.Names}的工序:{groupItem.Key} 不存在!"); | |||
var warehousrTemplateId = wareHouseTemplateList[0]?.Id; | |||
var jsonList = new List<ActionJsonModel>(); | |||
var newActionNameList = new List<string>(); | |||
foreach (var item in groupItem) | |||
{ | |||
newActionNameList.Add(item.ActionName); | |||
var action = technologyActionList.FirstOrDefault(t => t.ActionName == item.ActionName); | |||
if (action == null) | |||
throw Oops.Oh($"{data.Names}的工序参数:{item.ActionName} 不存在!"); | |||
if (action.ActionValue != null) | |||
{ | |||
var actionValueList = JsonConvert.DeserializeObject<List<ActionValueModel>>(action.ActionValue); | |||
var actionValues = actionValueList.Select(t => t.actionValueName).ToList(); | |||
if (!actionValues.Contains(item.ActionValue)) | |||
throw Oops.Oh($"{data.Names}的工序参数值:{item.ActionValue} 不存在!"); | |||
} | |||
else if (action.TechnologyType == TechnologyEnums.Batch) | |||
{ | |||
var batchNameList = batchList.Select(t => t.Name).ToList(); | |||
if (!batchNameList.Contains(item.ActionValue)) | |||
throw Oops.Oh($"{data.Names}的物料名称:{item.ActionValue} 不存在!"); | |||
} | |||
jsonList.Add(new ActionJsonModel | |||
{ | |||
actionName = item.ActionName, | |||
actionValue = item.ActionValue, | |||
technologyactionId = action.Id, | |||
index = item.Index | |||
}); | |||
} | |||
var oldActionNameList = technologyActionList.Where(t => t.TechnologyId == technology.Id).Select(t => t.ActionName).ToList(); | |||
var listsEqual = !newActionNameList.Except(oldActionNameList).Any() && newActionNameList.Count == oldActionNameList.Count; | |||
if (!listsEqual) | |||
throw Oops.Oh($"{data.Names}的{groupItem.Key}的工序参数值数量不一致!"); | |||
var actionJson = JsonConvert.SerializeObject(jsonList); | |||
var newValue = new BPA_GoodsTechnologyAction | |||
{ | |||
Id = Guid.NewGuid().ToString(), | |||
StepName = groupItem.Key, | |||
ChnologyId = technology.Id, | |||
GoodsAttributeId = attributeId, | |||
Sort = sort, | |||
ActionJson = actionJson, | |||
GoodsId = goodId, | |||
DeviceId = deviceId, | |||
CreateBy = userId, | |||
WarehousrTemplateId = warehousrTemplateId, | |||
Order = order | |||
}; | |||
await _db.Insertable(newValue).ExecuteCommandAsync(); | |||
oldAtteibuteId = attributeId; | |||
} | |||
} | |||
} | |||
_db.Ado.CommitTran(); | |||
} | |||
catch (Exception e) | |||
{ | |||
_db.Ado.RollbackTran(); | |||
throw Oops.Oh($"Excel导入错误," + e.Message); | |||
} | |||
return true; | |||
} | |||
public List<GoodsTechnologyValueModel> UpdateObjectToModel(List<object> objList) | |||
{ | |||
var result = new List<GoodsTechnologyValueModel>(); | |||
foreach (var obj in objList) | |||
{ | |||
var jsonObj = JsonConvert.SerializeObject(obj); | |||
var model = JsonConvert.DeserializeObject<GoodsTechnologyValueModel>(jsonObj); | |||
model.StepName = model.StepName?.Trim(); | |||
model.ActionName = model.ActionName?.Trim(); | |||
model.ActionValue = model.ActionValue?.Trim(); | |||
model.Index = model.Index?.Trim(); | |||
result.Add(model); | |||
} | |||
return result; | |||
} | |||
public List<GoodsTechnologyValueModel> FillStepName(List<GoodsTechnologyValueModel> list) | |||
{ | |||
var stepName = ""; | |||
foreach (var item in list) | |||
{ | |||
if (item.StepName == null) | |||
item.StepName = stepName; | |||
else | |||
stepName = item.StepName; | |||
} | |||
return list; | |||
} | |||
/// <summary> | |||
/// 商品工艺导出 | |||
/// </summary> | |||
/// <param name="exportDto"></param> | |||
/// <returns></returns> | |||
public async Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto) | |||
{ | |||
var goodsInfo = new List<BPA_GoodsInfo>(); | |||
goodsInfo = exportDto.GoodId != "" | |||
? await _db.Queryable<BPA_GoodsInfo>().Where(t => t.Id == exportDto.GoodId).ToListAsync() | |||
: await _db.Queryable<BPA_GoodsInfo, BPA_GoodsType>((a, b) => new JoinQueryInfos(JoinType.Left, a.GoodsTypeId == b.Id)).ToListAsync(); | |||
var deviceInfo = await _db.Queryable<BPA_DeviceInfo>().FirstAsync(t => t.Id == exportDto.DeviceId); | |||
var goodsAttributeList = await _db.Queryable<BPA_GoodsAttribute>().ToListAsync(); | |||
var goodsAttributeValueList = await _db.Queryable<BPA_GoodsAttributeValue>().Where(t => goodsAttributeList.Select(a => a.Id).Contains(t.GoodsAttributeId)).OrderBy(a => a.Sort).ToListAsync(); | |||
IWorkbook workbook = new XSSFWorkbook(); | |||
foreach (var good in goodsInfo) | |||
{ | |||
ISheet sheet = workbook.CreateSheet(good.Name); | |||
ICellStyle style = workbook.CreateCellStyle(); | |||
IFont font = workbook.CreateFont(); | |||
font.Boldweight = (short)FontBoldWeight.Bold; | |||
style.SetFont(font); | |||
style.FillForegroundColor = IndexedColors.Grey25Percent.Index; | |||
style.FillPattern = FillPattern.SolidForeground; | |||
style.VerticalAlignment = VerticalAlignment.Center; | |||
style.BorderBottom = BorderStyle.Thin; | |||
style.BottomBorderColor = IndexedColors.Black.Index; | |||
style.BorderLeft = BorderStyle.Thin; | |||
style.LeftBorderColor = IndexedColors.Black.Index; | |||
style.BorderRight = BorderStyle.Thin; | |||
style.RightBorderColor = IndexedColors.Black.Index; | |||
style.BorderTop = BorderStyle.Thin; | |||
style.TopBorderColor = IndexedColors.Black.Index; | |||
sheet.SetColumnWidth(0, 20 * 256); | |||
sheet.SetColumnWidth(1, 20 * 256); | |||
sheet.SetColumnWidth(2, 20 * 256); | |||
sheet.SetColumnWidth(3, 20 * 256); | |||
sheet.SetColumnWidth(4, 150 * 256); | |||
sheet.DefaultColumnWidth = 100 * 256; | |||
sheet.DefaultRowHeight = 30 * 20; | |||
IRow headerRow = sheet.CreateRow(0); | |||
headerRow.RowStyle = style; | |||
headerRow.CreateCell(0).SetCellValue("StepName"); | |||
headerRow.CreateCell(1).SetCellValue("ActionName"); | |||
headerRow.CreateCell(2).SetCellValue("ActionValue"); | |||
headerRow.CreateCell(3).SetCellValue("Index"); | |||
var ids = new Dictionary<string, List<string>>(); | |||
var values = new Dictionary<string, List<string>>(); | |||
var attrList = goodsAttributeList.Where(t => t.GoodsTypeId == good.GoodsTypeId).OrderBy(a => a.Sort).ToList(); | |||
foreach (var attr in attrList) | |||
{ | |||
var attributeValueList = goodsAttributeValueList.Where(t => t.GoodsAttributeId == attr.Id).OrderBy(a => a.Sort).ToList(); | |||
ids.Add(attr.Id, attributeValueList.Select(t => t.Id).ToList()); | |||
values.Add(attr.AttributeName, attributeValueList.Select(a => a.AttributeValue).ToList()); | |||
} | |||
var valueList = GenerateCombinations(values, false, good, deviceInfo); | |||
var idList = GenerateCombinations(ids, true, good, deviceInfo); | |||
var j = 0; | |||
for (int i = 0; i < int.MaxValue; i += 4) | |||
{ | |||
IRow dataRow = sheet.CreateRow(i + 1); | |||
dataRow.RowStyle = style; | |||
IRow dataRowTitle = sheet.CreateRow(i + 2); | |||
dataRowTitle.RowStyle = style; | |||
dataRow.CreateCell(0).SetCellValue(idList[j]); | |||
dataRow.CreateCell(1).SetCellValue(valueList[j]); | |||
dataRowTitle.CreateCell(0).SetCellValue("工序"); | |||
dataRowTitle.CreateCell(1).SetCellValue("工序参数"); | |||
dataRowTitle.CreateCell(2).SetCellValue("工序参数值"); | |||
dataRowTitle.CreateCell(3).SetCellValue("值序号"); | |||
j++; | |||
if (idList.Count <= j) | |||
break; | |||
} | |||
#region 填充两行示例数据和注意事项 | |||
var dataRow1 = sheet.CreateRow(3); | |||
dataRow1.CreateCell(0).SetCellValue("主料(例)"); | |||
dataRow1.CreateCell(1).SetCellValue("主料名称(例)"); | |||
dataRow1.CreateCell(2).SetCellValue("水(例)"); | |||
dataRow1.CreateCell(3).SetCellValue("1(例)"); | |||
var dataRow2 = sheet.CreateRow(4); | |||
dataRow2.CreateCell(0).SetCellValue("主料(例)"); | |||
dataRow2.CreateCell(1).SetCellValue("主料位置(例)"); | |||
dataRow2.CreateCell(2).SetCellValue("1号位(例)"); | |||
dataRow2.CreateCell(3).SetCellValue("2(例)"); | |||
sheet.GetRow(1).CreateCell(4).SetCellValue($"!!!注意事项!!!\n(1)表格黑色背景部分请勿修改或删除;\n(2)导入商品工艺时请删除示例;\n(3)“工序(模型名称)”、“工序参数(模型配置)”、“工序参数值(输入值)”请查看设备工艺模版“{exportDto.FileName}”;"); | |||
sheet.AddMergedRegion(new CellRangeAddress(1, 2, 4, 4)); | |||
#endregion | |||
} | |||
var tempFolder = Path.Combine(_hostingEnvironment.ContentRootPath, "TechnologyTemplate"); | |||
if (!Directory.Exists(tempFolder)) | |||
Directory.CreateDirectory(tempFolder); | |||
var time = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒"); | |||
var filePath = Path.Combine(tempFolder, $"{deviceInfo.DeviceName}工艺模版-{time}.xlsx"); | |||
using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) | |||
{ | |||
workbook.Write(stream); | |||
} | |||
var fileBase64 = Convert.ToBase64String(File.ReadAllBytes(filePath)); | |||
return fileBase64; | |||
} | |||
public static List<string> GenerateCombinations(Dictionary<string, List<string>> values, bool isId, BPA_GoodsInfo goodInfo, BPA_DeviceInfo deviceInfo) | |||
{ | |||
var attributes = values.Keys.ToList(); | |||
var results = new List<List<string>>(); | |||
var currentCombo = new List<string>(); | |||
Generate(values, attributes, results, currentCombo, 0); | |||
return (from item in results | |||
let a = isId ? goodInfo.Id + ",(" + string.Join(",", item) + ")," + deviceInfo.Id : goodInfo.Name + "-(" + string.Join("-", item) + ")-" + deviceInfo.DeviceName | |||
select a).ToList(); | |||
} | |||
private static void Generate(Dictionary<string, List<string>> values, List<string> attributes, List<List<string>> results, List<string> currentCombo, int index) | |||
{ | |||
if (index >= attributes.Count) | |||
{ | |||
results.Add(new List<string>(currentCombo)); | |||
return; | |||
} | |||
var attribute = attributes[index]; | |||
foreach (var value in values[attribute]) | |||
{ | |||
currentCombo.Add(value); | |||
Generate(values, attributes, results, currentCombo, index + 1); | |||
currentCombo.RemoveAt(currentCombo.Count - 1); | |||
} | |||
} | |||
public string GetValueStr(string str) | |||
{ | |||
try | |||
@@ -1381,6 +1733,23 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
} | |||
return result; | |||
} | |||
private List<string> GetSheetNameList(Stream stream) | |||
{ | |||
var result = new List<string>(); | |||
try | |||
{ | |||
IWorkbook workbook = new XSSFWorkbook(stream); | |||
for (int i = 0; i < ((XSSFWorkbook)workbook).Count; i++) | |||
{ | |||
result.Add(workbook.GetSheetAt(i).SheetName); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
throw Oops.Oh($"Excel读取错误" + ex.Message); | |||
} | |||
return result; | |||
} | |||
/// <summary> | |||
/// 将Excel单表转为Datatable | |||
/// </summary> | |||
@@ -33,7 +33,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
try | |||
{ | |||
var addlist = new List<BPA_GoodsTechnologyAction>(); | |||
var list = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.DeviceId == inputDto[0].DeviceId && x.GoodsId == inputDto[0].GoodsId && x.GoodsAttributeId == inputDto[0].GoodsAttributeId).ToList(); | |||
var oldOrder = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.DeviceId == inputDto[0].DeviceId && x.GoodsId == inputDto[0].GoodsId && x.GoodsAttributeId == inputDto[0].GoodsAttributeId && x.WarehousrTemplateId == inputDto[0].WarehousrTemplateId).First()?.Order; | |||
var list = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.DeviceId == inputDto[0].DeviceId && x.GoodsId == inputDto[0].GoodsId && x.GoodsAttributeId == inputDto[0].GoodsAttributeId && x.WarehousrTemplateId == inputDto[0].WarehousrTemplateId).ToList(); | |||
_db.Ado.BeginTran(); | |||
_db.Deleteable(list).ExecuteCommand(); | |||
//var list = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GroupId == groupId && x.IsDeleted == 0).ToList(); | |||
@@ -41,7 +42,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
for (int i = 0; i < inputDto.Count; i++) | |||
{ | |||
var goodsinfo = _db.Queryable<BPA_GoodsInfo>().Where(x => x.Id == inputDto[i].GoodsId).First(); | |||
var maxsort = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == inputDto[i].GoodsId && x.DeviceId == inputDto[i].DeviceId).Max(x => x.Sort); | |||
var maxsort = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == inputDto[i].GoodsId && x.DeviceId == inputDto[i].DeviceId && x.GoodsAttributeId == inputDto[i].GoodsAttributeId && x.WarehousrTemplateId == inputDto[i].WarehousrTemplateId).Max(x => x.Sort); | |||
var data = new BPA_GoodsTechnologyAction() | |||
{ | |||
Id = string.IsNullOrEmpty(inputDto[i].Id) ? Guid.NewGuid().ToString() : inputDto[i].Id, | |||
@@ -56,6 +57,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
Sort = string.IsNullOrWhiteSpace(inputDto[i].Sort.ToString()) ? maxsort + (i + 1) : Convert.ToInt32(inputDto[i].Sort.ToString()), | |||
IsBatch = inputDto[i].IsBatch, | |||
DeviceId = inputDto[i].DeviceId, | |||
Order = (int)oldOrder | |||
}; | |||
if (!goodsinfo.IsAttrubute) | |||
{ | |||
@@ -81,10 +83,13 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
try | |||
{ | |||
var addlist = new List<BPA_GoodsTechnologyAction>(); | |||
var maxOrder = _db.Queryable<BPA_GoodsTechnologyAction>().Where(t => t.GoodsId == inputDto[0].GoodsId).Max(a => a.Order); | |||
var goodsTechnologyActionList = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == inputDto[0].GoodsId && x.DeviceId == inputDto[0].DeviceId && x.WarehousrTemplateId == inputDto[0].WarehousrTemplateId && x.GoodsAttributeId == inputDto[0].GoodsAttributeId).ToList(); | |||
_db.Deleteable(goodsTechnologyActionList).ExecuteCommand(); | |||
for (int i = 0; i < inputDto.Count; i++) | |||
{ | |||
var goodsinfo = _db.Queryable<BPA_GoodsInfo>().Where(x => x.Id == inputDto[i].GoodsId).First(); | |||
var maxsort = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == inputDto[i].GoodsId && x.DeviceId == inputDto[i].DeviceId).Max(x => x.Sort); | |||
var maxsort = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == inputDto[i].GoodsId && x.DeviceId == inputDto[i].DeviceId && x.WarehousrTemplateId == inputDto[i].WarehousrTemplateId && x.GoodsAttributeId == inputDto[0].GoodsAttributeId).Max(x => x.Sort); | |||
var data = new BPA_GoodsTechnologyAction() | |||
{ | |||
Id = string.IsNullOrEmpty(inputDto[i].Id) ? Guid.NewGuid().ToString() : inputDto[i].Id, | |||
@@ -99,6 +104,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
Sort = string.IsNullOrWhiteSpace(inputDto[i].Sort.ToString()) ? maxsort + (i + 1) : Convert.ToInt32(inputDto[i].Sort.ToString()), | |||
IsBatch = inputDto[i].IsBatch, | |||
DeviceId = inputDto[i].DeviceId, | |||
Order = maxOrder + 1 | |||
}; | |||
if (!goodsinfo.IsAttrubute) | |||
{ | |||
@@ -128,28 +134,27 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
var Devicelist = await _db.Queryable<BPA_DeviceInfo>().ToListAsync(); | |||
var goodlist= await _db.Queryable<BPA_GoodsInfo>().ToListAsync(); | |||
var GoodsAttributeValue = await _db.Queryable<BPA_GoodsAttributeValue>().ToListAsync(); | |||
var sf = list.GroupBy(x => x.GoodsAttributeId).ToList(); | |||
var sf1 = list.GroupBy(x => x.WarehousrTemplateId).ToList(); | |||
var sf = list.GroupBy(x => (x.GoodsAttributeId, x.WarehousrTemplateId)).ToList(); | |||
for (int i = 0; i < sf.Count; i++) | |||
{ | |||
var sd = GoodsAttributeValue?.Where(x => sf[i].Key.Contains(x.Id)).Select(x => x.AttributeValue).ToArray(); | |||
var sdw = GoodsAttributeValue?.Where(x => sf[i].Key.Contains(x.Id)).Select(x => x.Id).ToArray(); | |||
var sd = GoodsAttributeValue?.Where(x => sf[i].Key.GoodsAttributeId.Contains(x.Id)).OrderBy(x => sf[i].Key.GoodsAttributeId.IndexOf(x.Id)).Select(x => x.AttributeValue).ToArray(); | |||
var sdw = GoodsAttributeValue?.Where(x => sf[i].Key.GoodsAttributeId.Contains(x.Id)).OrderBy(x => sf[i].Key.GoodsAttributeId.IndexOf(x.Id)).Select(x => x.Id).ToArray(); | |||
var nane =string.Join('-', sd); | |||
var s = sf[i].AsQueryable().ToList().GroupBy(x => x.DeviceId).ToList(); | |||
for (int t = 0; t < s.Count; t++) | |||
{ | |||
var ss = s[t]; | |||
GoodsTechnologyActionListView item = new() | |||
{ | |||
DeviceId = s[t].Key, | |||
WarehousrTemplateId = sf1[t].Key, | |||
WarehousrTemplateId = sf[i].Key.WarehousrTemplateId, | |||
GoodsAttributeId = string.Join(',', sdw), | |||
DeviceName = Devicelist?.FirstOrDefault(x => x.Id == s[t].Key).DeviceName+ goodlist?.FirstOrDefault(x=>x.Id==goodsId).Name + "【"+ nane+"】", | |||
DeviceName = Devicelist?.FirstOrDefault(x => x.Id == s[t].Key)?.DeviceName +"-"+ goodlist?.FirstOrDefault(x=>x.Id==goodsId)?.Name + "【"+ nane+"】", | |||
Data = s[t].AsQueryable().ToList(), | |||
}; | |||
goodsTechnologyActionListViews.Add(item); | |||
} | |||
} | |||
return goodsTechnologyActionListViews; | |||
} | |||
public async Task<bool> DeleteGoodsTechnologyAction(string id) | |||
@@ -178,7 +183,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
} | |||
public async Task<bool> DeleteGoodsTechnologyAction(GoodsTechnologDelete dto) | |||
{ | |||
var item = await _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.DeviceId == dto.devideId && x.GoodsId == dto.goodsId && x.GoodsAttributeId== dto.goodsAttributeId).ToListAsync(); | |||
var item = await _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.DeviceId == dto.devideId && x.GoodsId == dto.goodsId && x.GoodsAttributeId== dto.goodsAttributeId && x.WarehousrTemplateId==dto.warehousrTemplateId).ToListAsync(); | |||
if (item.Count > 0) | |||
{ | |||
return await _db.Deleteable(item).ExecuteCommandAsync() > 0; | |||
@@ -420,11 +425,11 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
var Goodlist = await _db.Queryable<BPA_GoodsInfo>().ToListAsync(); | |||
var Devicelist = await _db.Queryable<BPA_DeviceInfo>().ToListAsync(); | |||
var GoodsAttributeValue = await _db.Queryable<BPA_GoodsAttributeValue>().ToListAsync(); | |||
var sf = list.GroupBy(x => x.GoodsAttributeId).ToList(); | |||
var sf = list.GroupBy(x => (x.GoodsAttributeId, x.WarehousrTemplateId)).ToList(); | |||
for (int i = 0; i < sf.Count; i++) | |||
{ | |||
var sd = GoodsAttributeValue?.Where(x => sf[i].Key.Contains(x.Id)).Select(x => x.AttributeValue).ToArray(); | |||
var sdw = GoodsAttributeValue?.Where(x => sf[i].Key.Contains(x.Id)).Select(x => x.Id).ToArray(); | |||
var sd = GoodsAttributeValue?.Where(x => sf[i].Key.GoodsAttributeId.Contains(x.Id)).OrderBy(x => sf[i].Key.GoodsAttributeId.IndexOf(x.Id)).Select(x => x.AttributeValue).ToArray(); | |||
var sdw = GoodsAttributeValue?.Where(x => sf[i].Key.GoodsAttributeId.Contains(x.Id)).OrderBy(x => sf[i].Key.GoodsAttributeId.IndexOf(x.Id)).Select(x => x.Id).ToArray(); | |||
var name = string.Join('-', sd); | |||
var s = sf[i].AsQueryable().ToList().GroupBy(x => x.GoodsId).ToList(); | |||
for (int t = 0; t < s.Count; t++) | |||
@@ -447,6 +452,51 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
} | |||
return goodsTechnologyActionListViews; | |||
} | |||
public async Task<PageUtil> GetGoodsTechnologyPage(GoodsTechnologyQueryDto dto) | |||
{ | |||
var result = new List<GoodsTechnologyActionListView>(); | |||
var list = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => x.GoodsId == dto.GoodsId) | |||
.Select(x => new GoodsTechnologyActionView() | |||
{ | |||
Id = x.Id.SelectAll(), | |||
}).OrderBy(x => x.GoodsAttributeId, OrderByType.Asc).ToList(); | |||
var Devicelist = await _db.Queryable<BPA_DeviceInfo>().ToListAsync(); | |||
var goodlist = await _db.Queryable<BPA_GoodsInfo>().ToListAsync(); | |||
var GoodsAttributeValue = await _db.Queryable<BPA_GoodsAttributeValue>().ToListAsync(); | |||
var sf = list.GroupBy(x => (x.GoodsAttributeId, x.WarehousrTemplateId)).ToList(); | |||
for (int i = 0; i < sf.Count; i++) | |||
{ | |||
var sd = GoodsAttributeValue?.Where(x => sf[i].Key.GoodsAttributeId.Contains(x.Id)).OrderBy(x => sf[i].Key.GoodsAttributeId.IndexOf(x.Id)).Select(x => x.AttributeValue).ToArray(); | |||
var sdw = GoodsAttributeValue?.Where(x => sf[i].Key.GoodsAttributeId.Contains(x.Id)).OrderBy(x => sf[i].Key.GoodsAttributeId.IndexOf(x.Id)).Select(x => x.Id).ToArray(); | |||
var nane = string.Join('-', sd); | |||
var s = sf[i].AsQueryable().ToList().GroupBy(x => x.DeviceId).ToList(); | |||
for (int t = 0; t < s.Count; t++) | |||
{ | |||
GoodsTechnologyActionListView item = new() | |||
{ | |||
DeviceId = s[t].Key, | |||
WarehousrTemplateId = sf[i].Key.WarehousrTemplateId, | |||
GoodsAttributeId = string.Join(',', sdw), | |||
DeviceName = Devicelist?.FirstOrDefault(x => x.Id == s[t].Key)?.DeviceName + "-" + goodlist?.FirstOrDefault(x => x.Id == dto.GoodsId)?.Name + "【" + nane + "】", | |||
Order = s[t].AsQueryable().First().Order, | |||
Data = s[t].AsQueryable().OrderBy(t=>t.Sort).ToList(), | |||
}; | |||
result.Add(item); | |||
} | |||
} | |||
if (!string.IsNullOrWhiteSpace(dto.DeviceName)) | |||
{ | |||
result = result.Where(x => x.DeviceName.Contains(dto.DeviceName)).ToList(); | |||
} | |||
result = result.OrderBy(t => t.Order).ToList(); | |||
PageUtil util = new PageUtil() | |||
{ | |||
Total = result.Count, | |||
Data = result | |||
}; | |||
return util; | |||
} | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsType; | |||
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; | |||
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsType; | |||
using BPA.SAAS.Manage.Application.DataBase.Interface; | |||
using BPA.SAAS.Manage.Application.Org.Dtos.Organize; | |||
using BPA.SAAS.Manage.Application.Org.Interface; | |||
@@ -9,6 +10,7 @@ using BPA.SAAS.Manage.Core.Base; | |||
using BPA.SAAS.Manage.Core.DataBase; | |||
using BPA.SAAS.Manage.Core.Org; | |||
using Furion.LinqBuilder; | |||
using StackExchange.Profiling.Internal; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
@@ -34,7 +36,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
public async Task<PageUtil> GetGoodsTypePage(GoodsTypeQueryDto dto) | |||
{ | |||
List<IConditionalModel> conModels = new List<IConditionalModel>(); | |||
string groupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; | |||
//string groupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; | |||
if (!string.IsNullOrEmpty(dto.Name)) | |||
{ | |||
conModels.Add(new ConditionalModel() { FieldName = "Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name }); | |||
@@ -43,24 +45,43 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
{ | |||
conModels.Add(new ConditionalModel() { FieldName = "Status", ConditionalType = ConditionalType.Equal, FieldValue = dto.Status }); | |||
} | |||
int total = new RefAsync<int>(); | |||
var res =await _db.Queryable<BPA_GoodsType>() | |||
var res = await _db.Queryable<BPA_GoodsType>() | |||
.Where(conModels) | |||
.OrderBy(a => a.CreateAt, OrderByType.Desc) | |||
.Select(it => new GoodsTypeTree() { Id = it.Id, Name = it.Name, Pid = it.Pid,Sort=it.Sort,Remark=it.Remark,Status=it.Status }).ToTreeAsync(it => it.Children, it => it.Pid, 0); | |||
.OrderBy(a => a.Sort, OrderByType.Asc) | |||
.Select(it => new GoodsTypeTree() { Id = it.Id, Name = it.Name, Pid = it.Pid, Sort = it.Sort, Remark = it.Remark, Status = it.Status }) | |||
.Mapper(x => | |||
{ | |||
var attrViewList = _db.Queryable<BPA_GoodsAttribute>() | |||
.Where(a => a.IsDeleted == 0) | |||
.WhereIF(!x.Id.IsNullOrWhiteSpace(), a => a.GoodsTypeId.Contains(x.Id)) | |||
.OrderBy(a => a.Sort, OrderByType.Asc) | |||
.Select(a => new GoodsAttributeView | |||
{ | |||
Id = a.Id, | |||
AttributeName = a.AttributeName, | |||
GoodsTypeId = a.GoodsTypeId, | |||
Sort = a.Sort, | |||
}) | |||
.Mapper(x => | |||
{ | |||
var list = _db.Queryable<BPA_GoodsAttributeValue>().Where(p => p.GoodsAttributeId == x.Id).OrderBy(x => x.Sort).ToList(); | |||
x.AttributeValueList = list; | |||
}).ToList(); | |||
x.GoodsAttributeViewList = attrViewList; | |||
}) | |||
.ToTreeAsync(it => it.Children, it => it.Pid, 0); | |||
//.ToPageList(dto.Current, dto.PageSize, ref total); | |||
List<GoodsTypeTree> list = new(); | |||
if (res != null) | |||
{ | |||
list = res.Skip((dto.Current - 1) * dto.PageSize).Take(dto.PageSize).ToList(); | |||
} | |||
PageUtil util = new PageUtil() | |||
PageUtil util = new PageUtil() | |||
{ | |||
Total = res==null?0:res.Count, | |||
Total = res == null ? 0 : res.Count, | |||
Data = list | |||
}; | |||
}; | |||
return util; | |||
} | |||
/// <summary> | |||
@@ -70,20 +91,106 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
/// <returns></returns> | |||
public async Task<bool> AddGoodsType(GoodsTypeDto dto) | |||
{ | |||
var newType = new BPA_GoodsType | |||
try | |||
{ | |||
Pid = dto.Pid, | |||
Name = dto.Name, | |||
Remark = dto.Remark, | |||
Sort = dto.Sort, | |||
Status = CommonStatus.ENABLE, | |||
}; | |||
if (string.IsNullOrWhiteSpace(dto.Pid)) | |||
var res = 0; | |||
if (string.IsNullOrWhiteSpace(dto.Id)) | |||
{ | |||
_db.Ado.BeginTran(); | |||
var newType = new BPA_GoodsType | |||
{ | |||
Pid = dto.Pid ?? "0", | |||
Name = dto.Name, | |||
Remark = dto.Remark, | |||
Sort = dto.Sort, | |||
Status = CommonStatus.ENABLE, | |||
}; | |||
var typeEntity = await _db.Insertable(newType).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); | |||
res++; | |||
if (dto.AttributeList != null) | |||
res += await HandleGoodsAttribute(typeEntity, dto.AttributeList); | |||
_db.Ado.CommitTran(); | |||
return res > 0; | |||
} | |||
else | |||
{ | |||
var typeEntity = _db.Queryable<BPA_GoodsType>().First(it => it.Id == dto.Id); | |||
if (null == typeEntity) | |||
{ | |||
return false; | |||
} | |||
typeEntity.Name = dto.Name; | |||
typeEntity.Pid = dto.Pid ?? "0"; | |||
typeEntity.Sort = dto.Sort; | |||
typeEntity.Remark = dto.Remark; | |||
typeEntity.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), dto.Status); | |||
await _db.Updateable(typeEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); | |||
res++; | |||
if (dto.AttributeList != null) | |||
res += await HandleGoodsAttribute(typeEntity, dto.AttributeList); | |||
_db.Ado.CommitTran(); | |||
return res > 0; | |||
} | |||
} | |||
catch (Exception) | |||
{ | |||
newType.Pid = "0"; | |||
_db.Ado.RollbackTran(); | |||
throw Oops.Oh("添加失败!"); | |||
} | |||
} | |||
public async Task<int> HandleGoodsAttribute(BPA_GoodsType typeEntity, List<AttributeDto> AttributeList) | |||
{ | |||
try | |||
{ | |||
var res = 0; | |||
_db.Ado.BeginTran(); | |||
var oldAttributeList = _db.Queryable<BPA_GoodsAttribute>().Where(it => it.GoodsTypeId == typeEntity.Id).ToList(); | |||
if (oldAttributeList.Count > 0) | |||
{ | |||
foreach (var oldAttribute in oldAttributeList) | |||
{ | |||
var oldValueList = _db.Queryable<BPA_GoodsAttributeValue>().Where(it => it.GoodsAttributeId == oldAttribute.Id).ToList(); | |||
if (oldValueList.Count > 0) | |||
res += await _db.Deleteable(oldValueList).ExecuteCommandAsync(); | |||
} | |||
res += await _db.Deleteable(oldAttributeList).ExecuteCommandAsync(); | |||
} | |||
if (AttributeList != null) | |||
{ | |||
foreach (var i in AttributeList) | |||
{ | |||
var attribute = new BPA_GoodsAttribute | |||
{ | |||
GoodsTypeId = typeEntity.Id, | |||
AttributeName = i.AttributeName, | |||
Sort = i.Sort | |||
}; | |||
var attributeEntity = await _db.Insertable(attribute).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); | |||
var valueList = new List<BPA_GoodsAttributeValue>(); | |||
if (i.AttributeValueList != null) | |||
{ | |||
foreach (var j in i.AttributeValueList) | |||
{ | |||
var value = new BPA_GoodsAttributeValue | |||
{ | |||
GoodsAttributeId = attributeEntity.Id, | |||
AttributeValue = j.AttributeValue, | |||
Sort = j.Sort | |||
}; | |||
valueList.Add(value); | |||
} | |||
} | |||
res += await _db.Insertable(valueList).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); | |||
} | |||
} | |||
_db.Ado.CommitTran(); | |||
return res; | |||
} | |||
catch (Exception) | |||
{ | |||
_db.Ado.RollbackTran(); | |||
throw Oops.Oh("添加失败!"); | |||
} | |||
var res =await _db.Insertable(newType).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); | |||
return res > 0; | |||
} | |||
/// <summary> | |||
/// 更新商品类型 | |||
@@ -129,15 +236,42 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services | |||
/// <returns></returns> | |||
public async Task<bool> DelGoodsType(string Id) | |||
{ | |||
// 查询数据库中是否存在未删除的商品类型 | |||
var check = _db.Queryable<BPA_GoodsInfo>().Any(it => it.GoodsTypeId == Id); | |||
if (check) | |||
try | |||
{ | |||
_db.Ado.BeginTran(); | |||
var res = 0; | |||
var ids = Id.Split(","); | |||
// 查询数据库中是否存在未删除的商品类型 | |||
var check = _db.Queryable<BPA_GoodsInfo>().Any(it => ids.Contains(it.GoodsTypeId)); | |||
if (check) | |||
{ | |||
throw Oops.Oh("该类已经使用无法删除"); | |||
} | |||
var resChildList = _db.Queryable<BPA_GoodsType>().Where(t => ids.Contains(t.Pid)).ToList(); | |||
var childIds = resChildList.Select(a => a.Id).ToList(); | |||
var childCheck = _db.Queryable<BPA_GoodsInfo>().Any(it => childIds.Contains(it.GoodsTypeId)); | |||
if (childCheck) | |||
{ | |||
throw Oops.Oh("该类已经使用无法删除"); | |||
} | |||
var resList = _db.Queryable<BPA_GoodsType>().Where(it => ids.Contains(it.Id)).ToList(); | |||
var attributeList = _db.Queryable<BPA_GoodsAttribute>().Where(it => ids.Contains(it.GoodsTypeId)).ToList(); | |||
foreach (var attribute in attributeList) | |||
{ | |||
var valueList = _db.Queryable<BPA_GoodsAttributeValue>().Where(it => it.GoodsAttributeId == attribute.Id).ToList(); | |||
res += await _db.Deleteable(valueList).ExecuteCommandAsync(); | |||
} | |||
res += await _db.Deleteable(attributeList).ExecuteCommandAsync(); | |||
res += await _db.Deleteable(resChildList).ExecuteCommandAsync(); | |||
res += await _db.Deleteable(resList).ExecuteCommandAsync(); | |||
_db.Ado.CommitTran(); | |||
return res > 0; | |||
} | |||
catch (Exception) | |||
{ | |||
throw Oops.Oh("该类已经使用无法删除"); | |||
_db.Ado.RollbackTran(); | |||
throw Oops.Oh("删除失败!"); | |||
} | |||
var resEntity = _db.Queryable<BPA_GoodsType>().First(it => it.Id == Id); | |||
var res =await _db.Deleteable(resEntity).ExecuteCommandAsync(); | |||
return res > 0; | |||
} | |||
/// <summary> | |||
/// 查询商品类型树结构 | |||
@@ -95,10 +95,14 @@ namespace BPA.SAAS.Manage.Application.Device | |||
{ | |||
return await _deviceService.GetDeviceTypeList(); | |||
} | |||
/// <summary> | |||
/// 通过autoKey获取设备信息 | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpGet("/api/device/getDeviceInfoByDeviceId")] | |||
public async Task<DeviceInfoQueryDto> GetDeviceInfoByDeviceId(string autoKey) | |||
{ | |||
return await _deviceService.GetDeviceInfoByDeviceId(autoKey); | |||
} | |||
} | |||
} |
@@ -36,5 +36,9 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.Device | |||
/// </summary> | |||
public string ProductVersionId { get; set; } | |||
public CommonStatus Status { get; set; } | |||
/// <summary> | |||
/// 地址 | |||
/// </summary> | |||
public string Address { get; set; } | |||
} | |||
} |
@@ -48,7 +48,12 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.Device | |||
public string OrgKey { get; set; } | |||
public string ProductVersionName { get; set; } | |||
public int TechnologyOrBom { get; set; } | |||
public string GroupId { get; set; } | |||
public string StopId { get; set; } | |||
public string StopName { get; set; } | |||
/// <summary> | |||
/// 地址 | |||
/// </summary> | |||
public string Address { get;set; } | |||
} | |||
} |
@@ -21,6 +21,6 @@ namespace BPA.SAAS.Manage.Application.Device.Interface | |||
Task<bool> DelDeviceInfo(List<string> inputList); | |||
Task<bool> AddDeviceTypeAsync(DeviceTypeBaseDto inputDto); | |||
Task<List<ListSelectQuery>> GetDeviceTypeList(); | |||
Task<DeviceInfoQueryDto> GetDeviceInfoByDeviceId(string autoKey); | |||
} | |||
} |
@@ -54,7 +54,8 @@ namespace BPA.SAAS.Manage.Application.Device.Services | |||
ProductName=b.Name, | |||
ProductCode=b.Code, | |||
StopId=a.StopId, | |||
ProductVersionName = "" | |||
ProductVersionName = "", | |||
Address=a.Address | |||
}) | |||
.Mapper(x => | |||
{ | |||
@@ -85,7 +86,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services | |||
AutoKey=a.AutoKey.ToString(), | |||
ProductVersionId=a.ProductVersionId, | |||
ProductId=a.ProductId, | |||
}) .ToListAsync(); | |||
data.ForEach(x => | |||
{ | |||
@@ -164,6 +165,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services | |||
x.Status, | |||
x.ProductVersionId, | |||
// x.TechnologyOrBom | |||
x.Address | |||
}) | |||
.Where(x => x.Id == inputDto.Id).ExecuteCommandAsync(); | |||
@@ -240,11 +242,33 @@ namespace BPA.SAAS.Manage.Application.Device.Services | |||
// BPALog.WriteLog($"调用订单服务:{url},调用成功"); | |||
return true; | |||
} | |||
/// <summary> | |||
/// 通过autoKey获取设备信息 | |||
/// </summary> | |||
/// <param name="autoKey"></param> | |||
/// <returns></returns> | |||
public async Task<DeviceInfoQueryDto> GetDeviceInfoByDeviceId(string autoKey) | |||
{ | |||
var data = await _db.Queryable<BPA_DeviceInfo, BPA_Product, BPA_ProductVesion>((a, b, c) => | |||
new JoinQueryInfos(JoinType.Left, a.ProductId == b.Id, JoinType.Left, a.ProductVersionId == c.Id)) | |||
.Where(a => a.AutoKey.ToString() == autoKey) | |||
.Select((a, b, c) => new DeviceInfoQueryDto | |||
{ | |||
Id = a.Id.SelectAll(), | |||
DeviceName = a.DeviceName, | |||
DeviceTypeId = a.DeviceTypeId, | |||
ProductId = a.ProductId, | |||
ProductName = b.Name, | |||
ProductCode = b.Code, | |||
ProductVersionId = a.ProductVersionId, | |||
ProductVersionName = c.Vesion, | |||
StopId = a.StopId, | |||
GroupId = a.GroupId, | |||
Address = a.Address | |||
}).FirstAsync(); | |||
var stopInfo = await storeServer.GetStopWithGroupId(data?.GroupId); | |||
data.StopName = stopInfo.FirstOrDefault(a => a.Id == data.StopId)?.Name; | |||
return data; | |||
} | |||
} | |||
} |
@@ -369,7 +369,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services | |||
/// <summary> | |||
/// 根据产品查询版本 | |||
/// </summary> | |||
/// <param name="Code"></param> | |||
/// <param name="ProductId"></param> | |||
/// <returns></returns> | |||
public async Task<List<BPA_ProductVesion>> GetDeviceVesion(string ProductId) | |||
{ | |||
@@ -32,5 +32,18 @@ namespace BPA.SAAS.Manage.Application | |||
var dataStore = JsonConvert.DeserializeObject<List<StoreDto>>(resStore.data.ToString()); | |||
return dataStore; | |||
} | |||
public async Task<List<StoreDto>> GetStopWithGroupId(string groupId) | |||
{ | |||
var getStoreurl = BaseServerUrl + "api/store/getstorelist_alm";//获取商品属性 | |||
var responseGoodsAttribute = await getStoreurl.SetHeaders(new | |||
{ | |||
groupId | |||
}).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); | |||
var resStore = JsonConvert.DeserializeObject<ResponDataBase>(responseGoodsAttribute); | |||
if (resStore?.statusCode != "200") throw Oops.Oh("获取场景数据失败"); | |||
var dataStore = JsonConvert.DeserializeObject<List<StoreDto>>(resStore.data.ToString()); | |||
return dataStore; | |||
} | |||
} | |||
} |
@@ -39,5 +39,9 @@ namespace BPA.SAAS.Manage.Core.DataBase | |||
/// 仓位模板 | |||
/// </summary> | |||
public string WarehousrTemplateId { get; set; } | |||
/// <summary> | |||
/// 工艺序号 | |||
/// </summary> | |||
public int Order { get;set; } | |||
} | |||
} |
@@ -55,5 +55,10 @@ namespace BPA.SAAS.Manage.Core.Device | |||
/// 支持工艺还是配方 0工艺 1配方 | |||
/// </summary> | |||
//public int TechnologyOrBom { get; set; } | |||
/// <summary> | |||
/// 地址 | |||
/// </summary> | |||
public string Address { get; set; } | |||
} | |||
} |