From 9768e24380f2b18c469a3db2a125006b2e1aa852 Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Fri, 28 Jun 2024 10:43:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8E=A8=E4=BC=98=E5=8C=96=E5=AE=8C?= =?UTF-8?q?=E6=88=9020240628?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/BPA.SAAS.Manage/v17/.futdcache.v1 | Bin 0 -> 661 bytes .../DataBase/BomServices.cs | 2 +- .../DataBase/Dtos/Goods/BatchingModel.cs | 2 +- .../Dtos/Goods/GoodsTechnologyImportDto.cs | 32 ++ .../Dtos/Goods/GoodsTechnologyImportModel.cs | 31 ++ .../GoodsTechnology/GoodsTechnologDelete.cs | 1 + .../GoodsTechnologyActionListView.cs | 2 + .../GoodsTechnologyQueryDto.cs | 15 + .../DataBase/Dtos/GoodsType/GoodsTypeDto.cs | 17 +- .../DataBase/Dtos/GoodsType/GoodsTypeTree.cs | 4 +- .../DataBase/GoodsAttributeServices.cs | 11 +- .../DataBase/GoodsServices.cs | 21 + .../DataBase/GoodsTechnologyService.cs | 14 +- .../Interface/IGoodsAttributeService.cs | 6 + .../DataBase/Interface/IGoodsService.cs | 13 + .../Interface/IGoodsTechnologyService.cs | 1 + .../DataBase/Services/BomService.cs | 7 +- .../Services/GoodsAttributeService.cs | 28 +- .../DataBase/Services/GoodsService.cs | 395 +++++++++++++++++- .../Services/GoodsTechnologyService.cs | 78 +++- .../DataBase/Services/GoodsTypeService.cs | 190 +++++++-- .../Device/DeviceServices.cs | 14 +- .../Device/Dtos/Device/DeviceInfoBaseDto.cs | 4 + .../Device/Dtos/Device/DeviceInfoQueryDto.cs | 5 + .../Device/Interface/IDeviceService.cs | 2 +- .../Device/Services/DeviceService.cs | 40 +- .../Device/Services/DeviceVesionService.cs | 2 +- BPA.SAAS.Manage.Application/StoreServers.cs | 13 + .../DataBase/BPA_GoodsTechnologyAction.cs | 4 + BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs | 5 + 30 files changed, 876 insertions(+), 83 deletions(-) create mode 100644 .vs/BPA.SAAS.Manage/v17/.futdcache.v1 create mode 100644 BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportDto.cs create mode 100644 BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportModel.cs create mode 100644 BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyQueryDto.cs diff --git a/.vs/BPA.SAAS.Manage/v17/.futdcache.v1 b/.vs/BPA.SAAS.Manage/v17/.futdcache.v1 new file mode 100644 index 0000000000000000000000000000000000000000..d32a98e219ecf5ee08565a64ddffe5a51818f405 GIT binary patch literal 661 zcmZQ&U|p2z_mzJ4cS_Ia_>XMpNn$8iBlUS0LUzE${m{;i>5Xw_>B}VvRzDV?>I~)PT zIwd?cNzXaI2-A%)2@)NV!K*$C=w2}JAl4CB9RLy}(ef9k&4XZ;2N7#I$fK@#B}J7O rQ301B(HT}v*SW%^6&eGl-Qgf1403ZZT;QCan@ghQi6!;(U||3NHagPA literal 0 HcmV?d00001 diff --git a/BPA.SAAS.Manage.Application/DataBase/BomServices.cs b/BPA.SAAS.Manage.Application/DataBase/BomServices.cs index 8216827..1a15719 100644 --- a/BPA.SAAS.Manage.Application/DataBase/BomServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/BomServices.cs @@ -125,7 +125,7 @@ namespace BPA.SAAS.Manage.Application.DataBase /// /// 删除配方 /// - /// + /// /// [HttpPost("/api/bom/DelBom")] public async Task DelBom(string id) diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/BatchingModel.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/BatchingModel.cs index bb1e3fd..5e6972c 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/BatchingModel.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/BatchingModel.cs @@ -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; } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportDto.cs new file mode 100644 index 0000000..3c69d33 --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportDto.cs @@ -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 + { + /// + /// 文件 + /// + public IFormFile file { get; set; } + } + + public class GoodsTechnologyExportDto + { + /// + /// 商品Id + /// + public string GoodId { get; set; } + /// + /// 设备Id + /// + public string DeviceId { get; set; } + /// + /// 文档名 + /// + public string FileName { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportModel.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportModel.cs new file mode 100644 index 0000000..aab0f7d --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportModel.cs @@ -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 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;} + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologDelete.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologDelete.cs index f17ffbd..e93c95e 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologDelete.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologDelete.cs @@ -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; } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyActionListView.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyActionListView.cs index 25a2727..0d7cd63 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyActionListView.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyActionListView.cs @@ -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 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 diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyQueryDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyQueryDto.cs new file mode 100644 index 0000000..0fe8349 --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsTechnology/GoodsTechnologyQueryDto.cs @@ -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; } + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeDto.cs index 5d21114..e152948 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeDto.cs @@ -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 AttributeList { get; set; } + } + + public class AttributeDto + { + public string AttributeName { get; set; } + public int Sort { get; set; } + public List AttributeValueList { get; set; } + } + + public class AttributeValueDto + { + public string AttributeValue { get; set; } + public int Sort { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeTree.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeTree.cs index 8107a62..60734e5 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeTree.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsType/GoodsTypeTree.cs @@ -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 Children { get; set; } + public List GoodsAttributeViewList { get;set; } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/GoodsAttributeServices.cs b/BPA.SAAS.Manage.Application/DataBase/GoodsAttributeServices.cs index ad6d86a..ad6e77a 100644 --- a/BPA.SAAS.Manage.Application/DataBase/GoodsAttributeServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/GoodsAttributeServices.cs @@ -98,6 +98,15 @@ namespace BPA.SAAS.Manage.Application.DataBase { return await _goodsAttributeServices.GetByGoodsIdAttribute(id); } - + /// + /// 获取商品属性和属性值 + /// + /// + /// + [HttpPost("/api/goodsattribute/GetGoodsAttributeList")] + public async Task> GetGoodsAttributeViewList(string id) + { + return await _goodsAttributeServices.GetGoodsAttributeViewList(id); + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs b/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs index fe18661..c88368f 100644 --- a/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs @@ -192,5 +192,26 @@ namespace BPA.SAAS.Manage.Application.DataBase { return await _goodsService.DeviceVersionTemplateImport(inputDto); } + + /// + /// 商品工艺导入 + /// + /// + /// + [HttpPost("/api/goods/goodsTechnologyImport"), NonUnify] + public async Task GoodsTechnologyImport([FromForm]GoodsTechnologyImportDto importDto) + { + return await _goodsService.GoodsTechnologyImport(importDto); + } + + /// + /// 商品工艺导出 + /// + /// + [HttpPost("/api/goods/goodsTechnologyExport"), NonUnify] + public async Task GoodsTechnologyExport(GoodsTechnologyExportDto exportDto) + { + return await _goodsService.GoodsTechnologyExport(exportDto); + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/GoodsTechnologyService.cs b/BPA.SAAS.Manage.Application/DataBase/GoodsTechnologyService.cs index a9681fc..38b2b81 100644 --- a/BPA.SAAS.Manage.Application/DataBase/GoodsTechnologyService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/GoodsTechnologyService.cs @@ -113,9 +113,15 @@ namespace BPA.SAAS.Manage.Application.DataBase return await _goodsTechnologyService.CopyTechnologyAction(param); } - - - - + /// + /// 根据设备获取工艺(分页) + /// + /// + /// + [HttpPost("/api/goodstechnology/GetGoodsTechnologyPage")] + public async Task GetGoodsTechnologyPage(GoodsTechnologyQueryDto dto) + { + return await _goodsTechnologyService.GetGoodsTechnologyPage(dto); + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsAttributeService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsAttributeService.cs index 1ad1260..edc9b83 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsAttributeService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsAttributeService.cs @@ -59,5 +59,11 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// Task> GetByGoodsIdAttribute(string id); Task> GetByNameAttribute(string name); + /// + /// 获取商品属性和属性值 + /// + /// + /// + Task> GetGoodsAttributeViewList(string id); } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs index 920fa99..29f725a 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs @@ -102,5 +102,18 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// /// Task DeviceVersionTemplateImport(DeviceVersionTemplateImportInputDto inputDto); + + /// + /// 商品工艺导入 + /// + /// + /// + Task GoodsTechnologyImport([FromForm] GoodsTechnologyImportDto importDto); + + /// + /// 商品工艺导出 + /// + /// + Task GoodsTechnologyExport(GoodsTechnologyExportDto exportDto); } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsTechnologyService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsTechnologyService.cs index 7af6823..b979d9c 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsTechnologyService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsTechnologyService.cs @@ -25,5 +25,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface Task CopyTechnologyAction(IputParam param); + Task GetGoodsTechnologyPage(GoodsTechnologyQueryDto dto); } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs index 458aa6b..d24db15 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs @@ -337,7 +337,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// /// 删除配方 /// - /// + /// /// public async Task DelBom(string id) { @@ -345,8 +345,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services try { _db.Ado.BeginTran(); - await _db.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); - await _db.Deleteable().Where(x => x.BomId == id).ExecuteCommandAsync(); + var ids = id.Split(","); + await _db.Deleteable().Where(x =>ids.Contains(x.Id)).ExecuteCommandAsync(); + await _db.Deleteable().Where(x => ids.Contains(x.BomId)).ExecuteCommandAsync(); _db.Ado.CommitTran(); return true; } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsAttributeService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsAttributeService.cs index 4b7f230..5b59940 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsAttributeService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsAttributeService.cs @@ -361,6 +361,32 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices .ToListAsync(); return goodsAttributeList; } - + /// + /// 获取商品属性和属性值 + /// + /// + /// + public async Task> GetGoodsAttributeViewList(string id) + { + var goodType = await _db.Queryable().Where(x => x.Id == id).FirstAsync(); + if (goodType == null) throw Oops.Oh("商品分类不存在"); + var res = await _db.Queryable() + .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().Where(p => p.GoodsAttributeId == x.Id).OrderBy(x => x.Sort).ToList(); + x.AttributeValueList = list; + }).ToListAsync(); + return res; + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs index b1ad3db..259f0e1 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs @@ -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; } /// /// 分页查询 @@ -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 /// public async Task DeleteGoods(string id) { + var res = 0; try { _db.Ado.BeginTran(); - var ids = id.Split(","); - var goods = _db.Queryable().Where(x =>ids.Contains( x.Id)).First(); - if (goods == null) throw Oops.Oh("商品不存在"); - var goodsbom = _db.Queryable().Where(x => ids.Contains(x.Goods_Id)).ToList(); - var goodsTechnology = _db.Queryable().Where(x => ids.Contains(x.GoodsId)).ToList(); - //var FoodMenuGoods = _db.Queryable().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().Where(x => x.Id == idItem).First(); + if (good == null) + throw Oops.Oh("商品不存在"); + var goodsbom = _db.Queryable().Where(x => ids.Contains(x.Goods_Id)).ToList(); + var goodsTechnology = _db.Queryable().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("删除失败"); } - } /// /// 查询商品单位 @@ -1250,6 +1254,354 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services return true; } + /// + /// 商品工艺导入 + /// + /// + /// + public async Task GoodsTechnologyImport(GoodsTechnologyImportDto importDto) + { + string pattern = @"(?[^,(]+),(?\([^)]+\)),(?[^,]+)"; + var file = importDto.file; + var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + if (string.IsNullOrEmpty(userId)) + { + userId = ""; + } + var goodsInfoList = await _db.Queryable().ToListAsync(); + var deviceList = await _db.Queryable().ToListAsync(); + var technologyList = await _db.Queryable().ToListAsync(); + var technologyActionList = await _db.Queryable().ToListAsync(); + var wareHouseTemplateList = await _db.Queryable().OrderBy(a => a.Id).ToListAsync(); + var batchList = await _db.Queryable((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(); + 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().Where(x => x.GoodsId == goodId).ExecuteCommandAsync(); + var stepName = ""; + var actionName = ""; + var ids = ""; + var names = ""; + var dataModel = new GoodsTechnologyDataModel { Values = new List() }; + var dataList = new List(); + 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(); + 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 { 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 { 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(); + var newActionNameList = new List(); + 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>(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 UpdateObjectToModel(List objList) + { + var result = new List(); + foreach (var obj in objList) + { + var jsonObj = JsonConvert.SerializeObject(obj); + var model = JsonConvert.DeserializeObject(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 FillStepName(List list) + { + var stepName = ""; + foreach (var item in list) + { + if (item.StepName == null) + item.StepName = stepName; + else + stepName = item.StepName; + } + return list; + } + + /// + /// 商品工艺导出 + /// + /// + /// + public async Task GoodsTechnologyExport(GoodsTechnologyExportDto exportDto) + { + var goodsInfo = new List(); + goodsInfo = exportDto.GoodId != "" + ? await _db.Queryable().Where(t => t.Id == exportDto.GoodId).ToListAsync() + : await _db.Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.GoodsTypeId == b.Id)).ToListAsync(); + var deviceInfo = await _db.Queryable().FirstAsync(t => t.Id == exportDto.DeviceId); + var goodsAttributeList = await _db.Queryable().ToListAsync(); + var goodsAttributeValueList = await _db.Queryable().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>(); + var values = new Dictionary>(); + 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 GenerateCombinations(Dictionary> values, bool isId, BPA_GoodsInfo goodInfo, BPA_DeviceInfo deviceInfo) + { + var attributes = values.Keys.ToList(); + var results = new List>(); + var currentCombo = new List(); + 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> values, List attributes, List> results, List currentCombo, int index) + { + if (index >= attributes.Count) + { + results.Add(new List(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 GetSheetNameList(Stream stream) + { + var result = new List(); + 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; + } /// /// 将Excel单表转为Datatable /// diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTechnologyService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTechnologyService.cs index cbf4f1f..2ea31d1 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTechnologyService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTechnologyService.cs @@ -33,7 +33,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services try { var addlist = new List(); - var list = _db.Queryable().Where(x => x.DeviceId == inputDto[0].DeviceId && x.GoodsId == inputDto[0].GoodsId && x.GoodsAttributeId == inputDto[0].GoodsAttributeId).ToList(); + var oldOrder = _db.Queryable().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().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().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().Where(x => x.Id == inputDto[i].GoodsId).First(); - var maxsort = _db.Queryable().Where(x => x.GoodsId == inputDto[i].GoodsId && x.DeviceId == inputDto[i].DeviceId).Max(x => x.Sort); + var maxsort = _db.Queryable().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(); + var maxOrder = _db.Queryable().Where(t => t.GoodsId == inputDto[0].GoodsId).Max(a => a.Order); + var goodsTechnologyActionList = _db.Queryable().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().Where(x => x.Id == inputDto[i].GoodsId).First(); - var maxsort = _db.Queryable().Where(x => x.GoodsId == inputDto[i].GoodsId && x.DeviceId == inputDto[i].DeviceId).Max(x => x.Sort); + var maxsort = _db.Queryable().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().ToListAsync(); var goodlist= await _db.Queryable().ToListAsync(); var GoodsAttributeValue = await _db.Queryable().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 DeleteGoodsTechnologyAction(string id) @@ -178,7 +183,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services } public async Task DeleteGoodsTechnologyAction(GoodsTechnologDelete dto) { - var item = await _db.Queryable().Where(x => x.DeviceId == dto.devideId && x.GoodsId == dto.goodsId && x.GoodsAttributeId== dto.goodsAttributeId).ToListAsync(); + var item = await _db.Queryable().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().ToListAsync(); var Devicelist = await _db.Queryable().ToListAsync(); var GoodsAttributeValue = await _db.Queryable().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 GetGoodsTechnologyPage(GoodsTechnologyQueryDto dto) + { + var result = new List(); + var list = _db.Queryable().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().ToListAsync(); + var goodlist = await _db.Queryable().ToListAsync(); + var GoodsAttributeValue = await _db.Queryable().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; + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs index 5ec1579..44e08c6 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs @@ -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 GetGoodsTypePage(GoodsTypeQueryDto dto) { List conModels = new List(); - 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(); - var res =await _db.Queryable() + var res = await _db.Queryable() .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() + .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().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 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; } /// @@ -70,20 +91,106 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task 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().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 HandleGoodsAttribute(BPA_GoodsType typeEntity, List AttributeList) + { + try + { + var res = 0; + _db.Ado.BeginTran(); + var oldAttributeList = _db.Queryable().Where(it => it.GoodsTypeId == typeEntity.Id).ToList(); + if (oldAttributeList.Count > 0) + { + foreach (var oldAttribute in oldAttributeList) + { + var oldValueList = _db.Queryable().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(); + 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; } /// /// 更新商品类型 @@ -129,15 +236,42 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task DelGoodsType(string Id) { - // 查询数据库中是否存在未删除的商品类型 - var check = _db.Queryable().Any(it => it.GoodsTypeId == Id); - if (check) + try + { + _db.Ado.BeginTran(); + var res = 0; + var ids = Id.Split(","); + // 查询数据库中是否存在未删除的商品类型 + var check = _db.Queryable().Any(it => ids.Contains(it.GoodsTypeId)); + if (check) + { + throw Oops.Oh("该类已经使用无法删除"); + } + var resChildList = _db.Queryable().Where(t => ids.Contains(t.Pid)).ToList(); + var childIds = resChildList.Select(a => a.Id).ToList(); + var childCheck = _db.Queryable().Any(it => childIds.Contains(it.GoodsTypeId)); + if (childCheck) + { + throw Oops.Oh("该类已经使用无法删除"); + } + var resList = _db.Queryable().Where(it => ids.Contains(it.Id)).ToList(); + var attributeList = _db.Queryable().Where(it => ids.Contains(it.GoodsTypeId)).ToList(); + foreach (var attribute in attributeList) + { + var valueList = _db.Queryable().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().First(it => it.Id == Id); - var res =await _db.Deleteable(resEntity).ExecuteCommandAsync(); - return res > 0; } /// /// 查询商品类型树结构 diff --git a/BPA.SAAS.Manage.Application/Device/DeviceServices.cs b/BPA.SAAS.Manage.Application/Device/DeviceServices.cs index c73fa73..d8b65fa 100644 --- a/BPA.SAAS.Manage.Application/Device/DeviceServices.cs +++ b/BPA.SAAS.Manage.Application/Device/DeviceServices.cs @@ -95,10 +95,14 @@ namespace BPA.SAAS.Manage.Application.Device { return await _deviceService.GetDeviceTypeList(); } - - - - - + /// + /// 通过autoKey获取设备信息 + /// + /// + [HttpGet("/api/device/getDeviceInfoByDeviceId")] + public async Task GetDeviceInfoByDeviceId(string autoKey) + { + return await _deviceService.GetDeviceInfoByDeviceId(autoKey); + } } } diff --git a/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoBaseDto.cs b/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoBaseDto.cs index 603cfaa..44b281f 100644 --- a/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoBaseDto.cs +++ b/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoBaseDto.cs @@ -36,5 +36,9 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.Device /// public string ProductVersionId { get; set; } public CommonStatus Status { get; set; } + /// + /// 地址 + /// + public string Address { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoQueryDto.cs b/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoQueryDto.cs index fae9dce..7b63b7a 100644 --- a/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoQueryDto.cs +++ b/BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoQueryDto.cs @@ -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; } + /// + /// 地址 + /// + public string Address { get;set; } } } diff --git a/BPA.SAAS.Manage.Application/Device/Interface/IDeviceService.cs b/BPA.SAAS.Manage.Application/Device/Interface/IDeviceService.cs index 73e0a81..bc80fe3 100644 --- a/BPA.SAAS.Manage.Application/Device/Interface/IDeviceService.cs +++ b/BPA.SAAS.Manage.Application/Device/Interface/IDeviceService.cs @@ -21,6 +21,6 @@ namespace BPA.SAAS.Manage.Application.Device.Interface Task DelDeviceInfo(List inputList); Task AddDeviceTypeAsync(DeviceTypeBaseDto inputDto); Task> GetDeviceTypeList(); - + Task GetDeviceInfoByDeviceId(string autoKey); } } diff --git a/BPA.SAAS.Manage.Application/Device/Services/DeviceService.cs b/BPA.SAAS.Manage.Application/Device/Services/DeviceService.cs index 45871e0..24f7005 100644 --- a/BPA.SAAS.Manage.Application/Device/Services/DeviceService.cs +++ b/BPA.SAAS.Manage.Application/Device/Services/DeviceService.cs @@ -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; } - - - - - - + /// + /// 通过autoKey获取设备信息 + /// + /// + /// + public async Task GetDeviceInfoByDeviceId(string autoKey) + { + var data = await _db.Queryable((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; + } } } diff --git a/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs b/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs index 950bddb..fd3ba16 100644 --- a/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs +++ b/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs @@ -369,7 +369,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services /// /// 根据产品查询版本 /// - /// + /// /// public async Task> GetDeviceVesion(string ProductId) { diff --git a/BPA.SAAS.Manage.Application/StoreServers.cs b/BPA.SAAS.Manage.Application/StoreServers.cs index b30259c..e147fa9 100644 --- a/BPA.SAAS.Manage.Application/StoreServers.cs +++ b/BPA.SAAS.Manage.Application/StoreServers.cs @@ -32,5 +32,18 @@ namespace BPA.SAAS.Manage.Application var dataStore = JsonConvert.DeserializeObject>(resStore.data.ToString()); return dataStore; } + + public async Task> 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(responseGoodsAttribute); + if (resStore?.statusCode != "200") throw Oops.Oh("获取场景数据失败"); + var dataStore = JsonConvert.DeserializeObject>(resStore.data.ToString()); + return dataStore; + } } } diff --git a/BPA.SAAS.Manage.Core/DataBase/BPA_GoodsTechnologyAction.cs b/BPA.SAAS.Manage.Core/DataBase/BPA_GoodsTechnologyAction.cs index 1071467..5fd352c 100644 --- a/BPA.SAAS.Manage.Core/DataBase/BPA_GoodsTechnologyAction.cs +++ b/BPA.SAAS.Manage.Core/DataBase/BPA_GoodsTechnologyAction.cs @@ -39,5 +39,9 @@ namespace BPA.SAAS.Manage.Core.DataBase /// 仓位模板 /// public string WarehousrTemplateId { get; set; } + /// + /// 工艺序号 + /// + public int Order { get;set; } } } diff --git a/BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs b/BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs index d6f63b5..dbee1ec 100644 --- a/BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs +++ b/BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs @@ -55,5 +55,10 @@ namespace BPA.SAAS.Manage.Core.Device /// 支持工艺还是配方 0工艺 1配方 /// //public int TechnologyOrBom { get; set; } + + /// + /// 地址 + /// + public string Address { get; set; } } }