Browse Source

重写商品导入,商品及分类验重20240709

ingredientmanage
gwbvipvip 5 months ago
parent
commit
5a8d97135f
10 changed files with 535 additions and 239 deletions
  1. +18
    -0
      BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsDto.cs
  2. +9
    -1
      BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportDto.cs
  3. +29
    -6
      BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs
  4. +18
    -4
      BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs
  5. +423
    -207
      BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs
  6. +22
    -19
      BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs
  7. +6
    -0
      BPA.SAAS.Manage.Application/System/AliyunOssServices.cs
  8. +1
    -0
      BPA.SAAS.Manage.Application/System/Interface/IAliyunOssService.cs
  9. +8
    -1
      BPA.SAAS.Manage.Application/System/Services/AliyunOssService.cs
  10. +1
    -1
      BPA.SAAS.Manage.Web.Entry/appsettings.json

+ 18
- 0
BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsDto.cs View File

@@ -1,4 +1,5 @@
using BPA.SAAS.Manage.Comm.Enum; using BPA.SAAS.Manage.Comm.Enum;
using Npoi.Mapper.Attributes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -24,4 +25,21 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods
public string GoodsTypeId { get; set; } public string GoodsTypeId { get; set; }
public string Status { get; set; } public string Status { get; set; }
} }
public class GoodsImportDto
{
[Column("商品名称")]
public string Name { get; set; }
[Column("商品分类")]
public string Type { get; set; }
[Column("商品单位")]
public string Uint { get; set; }
[Column("商品价格")]
public decimal Price { get; set; }
[Column("是否称重")]
public string IsWeigh { get; set; }
[Column("备注")]
public string Descritption { get; set; }
[Column("图片")]
public object ImgUrl { get; set; }
}
} }

+ 9
- 1
BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsTechnologyImportDto.cs View File

@@ -11,7 +11,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods
/// <summary> /// <summary>
/// 文件 /// 文件
/// </summary> /// </summary>
public IFormFile file { get; set; }
public IFormFile File { get; set; }
} }


public class GoodsTechnologyExportDto public class GoodsTechnologyExportDto
@@ -29,4 +29,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods
/// </summary> /// </summary>
public string FileName { get; set; } public string FileName { get; set; }
} }

public class GoodsInfoImportDto
{
/// <summary>
/// 文件
/// </summary>
public IFormFile File { get; set; }
}
} }

+ 29
- 6
BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs View File

@@ -14,12 +14,12 @@ using System.Threading.Tasks;
namespace BPA.SAAS.Manage.Application.DataBase namespace BPA.SAAS.Manage.Application.DataBase
{ {
[ApiDescriptionSettings("Goods", Tag = "商品管理")] [ApiDescriptionSettings("Goods", Tag = "商品管理")]
public class GoodsServices: IDynamicApiController, ITransient
public class GoodsServices : IDynamicApiController, ITransient
{ {
IGoodsService _goodsService; IGoodsService _goodsService;
public GoodsServices(IGoodsService goodsService) public GoodsServices(IGoodsService goodsService)
{ {
_goodsService=goodsService;
_goodsService = goodsService;
} }
/// <summary> /// <summary>
/// 分页查询 /// 分页查询
@@ -168,7 +168,7 @@ namespace BPA.SAAS.Manage.Application.DataBase
///// <returns></returns> ///// <returns></returns>
//Task<bool> SendGoodsInfo(GoodsDatadto goodsDatadto); //Task<bool> SendGoodsInfo(GoodsDatadto goodsDatadto);
[HttpPost("/api/goods/exportgood"), ApiDescriptionSettings(SplitCamelCase = false), NonUnify] [HttpPost("/api/goods/exportgood"), ApiDescriptionSettings(SplitCamelCase = false), NonUnify]
public async Task<bool> ExportGood(IFormFile file)
public async Task<bool> ExportGood(IFormFile file)
{ {
return await _goodsService.ExportGood(file); return await _goodsService.ExportGood(file);
} }
@@ -178,7 +178,7 @@ namespace BPA.SAAS.Manage.Application.DataBase
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost("/api/goods/technologytemplateexport"), NonUnify] [HttpPost("/api/goods/technologytemplateexport"), NonUnify]
public async Task<string> TechnologyTemplateExport(string deviceId)
public async Task<string> TechnologyTemplateExport(string deviceId)
{ {
return await _goodsService.TechnologyTemplateExport(deviceId); return await _goodsService.TechnologyTemplateExport(deviceId);
} }
@@ -199,19 +199,42 @@ namespace BPA.SAAS.Manage.Application.DataBase
/// <param name="importDto"></param> /// <param name="importDto"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("/api/goods/goodsTechnologyImport"), NonUnify] [HttpPost("/api/goods/goodsTechnologyImport"), NonUnify]
public async Task<bool> GoodsTechnologyImport([FromForm]GoodsTechnologyImportDto importDto)
public async Task<bool> GoodsTechnologyImport([FromForm] GoodsTechnologyImportDto importDto)
{ {
return await _goodsService.GoodsTechnologyImport(importDto); return await _goodsService.GoodsTechnologyImport(importDto);
} }


/// <summary> /// <summary>
/// 商品工艺导出
/// 商品工艺模版导出
/// </summary> /// </summary>
/// <param name="exportDto"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("/api/goods/goodsTechnologyExport"), NonUnify] [HttpPost("/api/goods/goodsTechnologyExport"), NonUnify]
public async Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto) public async Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto)
{ {
return await _goodsService.GoodsTechnologyExport(exportDto); return await _goodsService.GoodsTechnologyExport(exportDto);
} }

/// <summary>
/// 商品导入
/// </summary>
/// <param name="importDto"></param>
/// <returns></returns>
[HttpPost("/api/goods/goodsImport"), NonUnify]
public async Task<bool> GoodsImport([FromForm] GoodsInfoImportDto importDto)
{
return await _goodsService.GoodsImport(importDto);
}

/// <summary>
/// 商品工艺导出
/// </summary>
/// <param name="goodName"></param>
/// <returns></returns>
[HttpPost("/api/goods/goodsSimpleExport"), NonUnify]
public async Task<string> GoodsSimpleExport(string goodName)
{
return await _goodsService.GoodsSimpleExport(goodName);
}
} }
} }

+ 18
- 4
BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs View File

@@ -26,7 +26,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface
/// </summary> /// </summary>
/// <param name="GoodsIds"></param> /// <param name="GoodsIds"></param>
/// <returns></returns> /// <returns></returns>
Task<object> GetGoodsListByIds(List<string> GoodsIds);
Task<object> GetGoodsListByIds(List<string> GoodsIds);


/// <summary> /// <summary>
/// 添加商品 /// 添加商品
@@ -61,13 +61,13 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> AddGoodsUint(GoodsUintDto dto);
Task<bool> AddGoodsUint(GoodsUintDto dto);
/// <summary> /// <summary>
/// 商品配方 /// 商品配方
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <returns></returns> /// <returns></returns>
Task<PageUtil> GetGoodsBomPageAsync(GoodsBomQueryDto dto);
Task<PageUtil> GetGoodsBomPageAsync(GoodsBomQueryDto dto);
/// <summary> /// <summary>
/// 删除商品配方 /// 删除商品配方
/// </summary> /// </summary>
@@ -111,9 +111,23 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface
Task<bool> GoodsTechnologyImport([FromForm] GoodsTechnologyImportDto importDto); Task<bool> GoodsTechnologyImport([FromForm] GoodsTechnologyImportDto importDto);


/// <summary> /// <summary>
/// 商品工艺导出
/// 商品工艺模版导出
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto); Task<string> GoodsTechnologyExport(GoodsTechnologyExportDto exportDto);

/// <summary>
/// 商品导入
/// </summary>
/// <param name="importDto"></param>
/// <returns></returns>
Task<bool> GoodsImport([FromForm] GoodsInfoImportDto importDto);

/// <summary>
/// 商品工艺导出
/// </summary>
/// <param name="goodName"></param>
/// <returns></returns>
Task<string> GoodsSimpleExport(string goodName);
} }
} }

+ 423
- 207
BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs View File

@@ -1,5 +1,4 @@
using BPA.Franchisee.Application.FranchiseeCenter.GoodsServices;
using BPA.SAAS.Manage.Application.DataBase.Dtos;
using BPA.SAAS.Manage.Application.DataBase.Dtos;
using BPA.SAAS.Manage.Application.DataBase.Dtos.Batching; using BPA.SAAS.Manage.Application.DataBase.Dtos.Batching;
using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom;
using BPA.SAAS.Manage.Application.DataBase.Dtos.Goods; using BPA.SAAS.Manage.Application.DataBase.Dtos.Goods;
@@ -34,24 +33,21 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks;


namespace BPA.SAAS.Manage.Application.DataBase.Services namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
public class GoodsService: IGoodsService, ITransient
public class GoodsService : IGoodsService, ITransient
{ {
private readonly ISqlSugarClient _db; private readonly ISqlSugarClient _db;
IGoodsAttributeService _goodsAttributeService; IGoodsAttributeService _goodsAttributeService;
ISystemConfigService _SystemConfigService; ISystemConfigService _SystemConfigService;
IAliyunOssService _aliyunOssService; IAliyunOssService _aliyunOssService;
IWebHostEnvironment _hostingEnvironment;
public GoodsService(ISqlSugarClient db, IGoodsAttributeService goodsAttributeService, ISystemConfigService SystemConfigService, IAliyunOssService aliyunOssService, IWebHostEnvironment webHostEnvironment) public GoodsService(ISqlSugarClient db, IGoodsAttributeService goodsAttributeService, ISystemConfigService SystemConfigService, IAliyunOssService aliyunOssService, IWebHostEnvironment webHostEnvironment)
{ {
_db=db;
_goodsAttributeService=goodsAttributeService;
_db = db;
_goodsAttributeService = goodsAttributeService;
_SystemConfigService = SystemConfigService; _SystemConfigService = SystemConfigService;
_aliyunOssService = aliyunOssService; _aliyunOssService = aliyunOssService;
_hostingEnvironment = webHostEnvironment;
} }
/// <summary> /// <summary>
/// 分页查询 /// 分页查询
@@ -66,12 +62,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
conModels.Add(new ConditionalModel() { FieldName = "a.Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name }); conModels.Add(new ConditionalModel() { FieldName = "a.Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name });
} }
if (!string.IsNullOrEmpty(dto.GoodsTypeName)) if (!string.IsNullOrEmpty(dto.GoodsTypeName))
{ {
conModels.Add(new ConditionalModel() { FieldName = "a.GoodsTypeId", ConditionalType = ConditionalType.Equal, FieldValue = dto.GoodsTypeName }); conModels.Add(new ConditionalModel() { FieldName = "a.GoodsTypeId", ConditionalType = ConditionalType.Equal, FieldValue = dto.GoodsTypeName });
} }
if (!string.IsNullOrEmpty(dto.Status)) if (!string.IsNullOrEmpty(dto.Status))
{ {
conModels.Add(new ConditionalModel() { FieldName = "a.Status", ConditionalType = ConditionalType.Like, FieldValue = dto.Status }); conModels.Add(new ConditionalModel() { FieldName = "a.Status", ConditionalType = ConditionalType.Like, FieldValue = dto.Status });
@@ -83,12 +79,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
#endregion #endregion


RefAsync<int> total = 0; RefAsync<int> total = 0;
var res =await _db.Queryable<BPA_GoodsInfo, BPA_GoodsType>((a, b) => new JoinQueryInfos(
JoinType.Left, a.GoodsTypeId == b.Id
))
var res = await _db.Queryable<BPA_GoodsInfo, BPA_GoodsType>((a, b) => new JoinQueryInfos(
JoinType.Left, a.GoodsTypeId == b.Id
))
.WhereIF(!string.IsNullOrWhiteSpace(dto.Code), (a, b) => a.Code.Contains(dto.Code)) .WhereIF(!string.IsNullOrWhiteSpace(dto.Code), (a, b) => a.Code.Contains(dto.Code))
// .WhereIF(dto.CreateAt.HasValue, (a, b) => SqlFunc.DateIsSame(a.CreateAt, Convert.ToDateTime(dto.CreateAt), DateType.Day)) // .WhereIF(dto.CreateAt.HasValue, (a, b) => SqlFunc.DateIsSame(a.CreateAt, Convert.ToDateTime(dto.CreateAt), DateType.Day))
.Where(conModels) .Where(conModels)
.OrderBy(a => a.CreateAt, OrderByType.Desc) .OrderBy(a => a.CreateAt, OrderByType.Desc)
.Select((a, b) => new .Select((a, b) => new
@@ -103,7 +99,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
GoodsTypeName = b.IsDeleted == 0 ? b.Name : "", GoodsTypeName = b.IsDeleted == 0 ? b.Name : "",
Descritption = a.Descritption, Descritption = a.Descritption,
IsDeleted = a.IsDeleted, IsDeleted = a.IsDeleted,
// CreateAt = a.CreateAt, // CreateAt = a.CreateAt,
GoodsUintId = a.GoodsUintId, GoodsUintId = a.GoodsUintId,
ForeignKeyRe = a.ForeignKeyRe, ForeignKeyRe = a.ForeignKeyRe,
@@ -111,10 +107,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
IsWeigh = a.IsWeigh, IsWeigh = a.IsWeigh,
DefaultMate = a.DefaultMate, DefaultMate = a.DefaultMate,
IsAttrubute = a.IsAttrubute, IsAttrubute = a.IsAttrubute,
Goodstechnology = SqlFunc.Subqueryable<BPA_GoodsTechnologyAction>().Where(p => p.GoodsId == a.Id).WhereIF(!string.IsNullOrWhiteSpace(dto.DeviceId),p=>p.DeviceId== dto.DeviceId).ToList(),
Goodstechnology = SqlFunc.Subqueryable<BPA_GoodsTechnologyAction>().Where(p => p.GoodsId == a.Id).WhereIF(!string.IsNullOrWhiteSpace(dto.DeviceId), p => p.DeviceId == dto.DeviceId).ToList(),
}) })


.ToPageListAsync(dto.Current, dto.PageSize, total);
.ToPageListAsync(dto.Current, dto.PageSize, total);
PageUtil util = new PageUtil() PageUtil util = new PageUtil()
{ {
Total = total, Total = total,
@@ -134,18 +130,18 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services


var result = new List<GoodsTypeResultDto>(); var result = new List<GoodsTypeResultDto>();
//商品信息 //商品信息
var goodsList=await _db.Queryable<BPA_GoodsInfo>().Where(x=> GoodsIds.Contains(x.Id)).ToListAsync();
var goodsList = await _db.Queryable<BPA_GoodsInfo>().Where(x => GoodsIds.Contains(x.Id)).ToListAsync();


var typeIds= goodsList.Select(x => x.GoodsTypeId).ToList();
var typeIds = goodsList.Select(x => x.GoodsTypeId).ToList();


//商品分类 //商品分类
var typeList =await _db.Queryable<BPA_GoodsType>().Where(x => typeIds.Contains(x.Id)).ToListAsync();
var typeList = await _db.Queryable<BPA_GoodsType>().Where(x => typeIds.Contains(x.Id)).ToListAsync();


//商品分类属性 //商品分类属性
var goodsAttribute = await _db.Queryable<BPA_GoodsAttribute>() var goodsAttribute = await _db.Queryable<BPA_GoodsAttribute>()
.Where(x=> typeIds.Contains(x.GoodsTypeId)).ToListAsync();
.Where(x => typeIds.Contains(x.GoodsTypeId)).ToListAsync();


var goodsAttributeIds= await _db.Queryable<BPA_GoodsAttribute>().Select(x=>x.Id).ToListAsync();
var goodsAttributeIds = await _db.Queryable<BPA_GoodsAttribute>().Select(x => x.Id).ToListAsync();




var goodsAttributeValue = await _db.Queryable<BPA_GoodsAttributeValue>() var goodsAttributeValue = await _db.Queryable<BPA_GoodsAttributeValue>()
@@ -153,9 +149,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
.Select(x => new GoodsAttributeValueResultDto() .Select(x => new GoodsAttributeValueResultDto()
{ {
GoodsAttributeValueId = x.Id, GoodsAttributeValueId = x.Id,
AttributeValue =x.AttributeValue,
GoodsAttributeId =x.GoodsAttributeId
AttributeValue = x.AttributeValue,
GoodsAttributeId = x.GoodsAttributeId
}) })
.ToListAsync(); .ToListAsync();


@@ -165,63 +161,63 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
var goodsTechnologyAction = await _db.Queryable<BPA_GoodsTechnologyAction>().ToListAsync(); var goodsTechnologyAction = await _db.Queryable<BPA_GoodsTechnologyAction>().ToListAsync();






foreach (var type in typeList) foreach (var type in typeList)
{ {


var value1 = goodsAttribute.Where(x => x.GoodsTypeId == type.Id) var value1 = goodsAttribute.Where(x => x.GoodsTypeId == type.Id)
.Select(x=>new BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttributeResultDto()
.Select(x => new BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttributeResultDto()
{ {
GoodsAttributeId=x.Id,
GoodsAttributeName=x.AttributeName
GoodsAttributeId = x.Id,
GoodsAttributeName = x.AttributeName


}).ToList(); }).ToList();


foreach (var item in value1) foreach (var item in value1)
{ {
var value2= goodsAttributeValue.Where(x=>x.GoodsAttributeId==item.GoodsAttributeId)
.Select(x=>new GoodsAttributeValueResultDto()
var value2 = goodsAttributeValue.Where(x => x.GoodsAttributeId == item.GoodsAttributeId)
.Select(x => new GoodsAttributeValueResultDto()
{ {
AttributeValue=x.AttributeValue,
GoodsAttributeId=x.GoodsAttributeId,
GoodsAttributeValueId=x.GoodsAttributeValueId,
AttributeValue = x.AttributeValue,
GoodsAttributeId = x.GoodsAttributeId,
GoodsAttributeValueId = x.GoodsAttributeValueId,
}) })
.ToList(); .ToList();


item.GoodsAttributeValueList= value2;
item.GoodsAttributeValueList = value2;
} }




var value3 = goodsInfos.Where(x => x.GoodsTypeId == type.Id) var value3 = goodsInfos.Where(x => x.GoodsTypeId == type.Id)
.Select(x => new GoodsInfoResultDto() .Select(x => new GoodsInfoResultDto()
{ {
GoodsId=x.Id,
GoodsName=x.Name,
ImgUrl=x.ImgUrl,
GoodsId = x.Id,
GoodsName = x.Name,
ImgUrl = x.ImgUrl,
}) })
.ToList(); .ToList();


foreach (var item in value3) foreach (var item in value3)
{ {
var value4= goodsTechnologyAction
.Where(x=>x.GoodsId==item.GoodsId)
.Select(x=>new GoodsTechnologyActionResultDto()
var value4 = goodsTechnologyAction
.Where(x => x.GoodsId == item.GoodsId)
.Select(x => new GoodsTechnologyActionResultDto()
{ {
GroupId=x.GroupId,
ActionJson=x.ActionJson,
ChnologyId=x.ChnologyId,
DeviceId=x.DeviceId,
GoodsAttributeId=x.GoodsAttributeId,
GoodsId=x.GoodsId,
IsBatch=x.IsBatch,
Sort=x.Sort,
StepName=x.StepName,
WarehousrTemplateId=x.WarehousrTemplateId,
GroupId = x.GroupId,
ActionJson = x.ActionJson,
ChnologyId = x.ChnologyId,
DeviceId = x.DeviceId,
GoodsAttributeId = x.GoodsAttributeId,
GoodsId = x.GoodsId,
IsBatch = x.IsBatch,
Sort = x.Sort,
StepName = x.StepName,
WarehousrTemplateId = x.WarehousrTemplateId,
}).ToList(); }).ToList();
item.GoodsTechnologyActionList= value4;
item.GoodsTechnologyActionList = value4;
} }






@@ -230,7 +226,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
GoodsTypeId = type.Id, GoodsTypeId = type.Id,
GoodsTypeName = type.Name, GoodsTypeName = type.Name,
GoodsAttributeList = value1, GoodsAttributeList = value1,
GoodsInfoList= value3
GoodsInfoList = value3


}); });


@@ -276,7 +272,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
var data = _db.Queryable<BPA_GoodsInfo>().Max(x => x.AutoKey); var data = _db.Queryable<BPA_GoodsInfo>().Max(x => x.AutoKey);
//if (data == 0) data = 1000; //if (data == 0) data = 1000;
//else data = data + 1; //else data = data + 1;
// resEntity.AutoKey = data;
// resEntity.AutoKey = data;
var res = await _db.Insertable(resEntity).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); var res = await _db.Insertable(resEntity).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
return res > 0; return res > 0;
} }
@@ -284,9 +280,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
return await UpdateGoods(dto); return await UpdateGoods(dto);
} }
} }
/// <summary> /// <summary>
/// 更新商品 /// 更新商品
/// </summary> /// </summary>
@@ -311,7 +307,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
resEntity.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), int.Parse(dto.Status)); resEntity.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), int.Parse(dto.Status));
} }
var res = await _db.Updateable(resEntity).ExecuteCommandAsync(); var res = await _db.Updateable(resEntity).ExecuteCommandAsync();
return res > 0; return res > 0;
} }
@@ -330,7 +326,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
foreach (var idItem in ids) foreach (var idItem in ids)
{ {
var good = _db.Queryable<BPA_GoodsInfo>().Where(x => x.Id == idItem).First(); var good = _db.Queryable<BPA_GoodsInfo>().Where(x => x.Id == idItem).First();
if (good == null)
if (good == null)
throw Oops.Oh("商品不存在"); throw Oops.Oh("商品不存在");
var goodsbom = _db.Queryable<BPA_GoodsBom>().Where(x => ids.Contains(x.Goods_Id)).ToList(); 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 goodsTechnology = _db.Queryable<BPA_GoodsTechnologyAction>().Where(x => ids.Contains(x.GoodsId)).ToList();
@@ -365,7 +361,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
var groupId = App.HttpContext.Request.Headers["groupId"].ToString(); var groupId = App.HttpContext.Request.Headers["groupId"].ToString();
if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空"); if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空");
var res = await _db.Queryable<BPA_GoodsUint>().Where(x=>x.GroupId== groupId).Select<dynamic>(x => new
var res = await _db.Queryable<BPA_GoodsUint>().Where(x => x.GroupId == groupId).Select<dynamic>(x => new


{ {
id = x.Id, id = x.Id,
@@ -380,10 +376,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
/// <returns></returns> /// <returns></returns>
public async Task<bool> AddGoodsUint(GoodsUintDto dto) public async Task<bool> AddGoodsUint(GoodsUintDto dto)
{ {
var productCode = _db.Queryable<BPA_GoodsUint>().Where(x =>x.Name == dto.Name).ToList();
var productCode = _db.Queryable<BPA_GoodsUint>().Where(x => x.Name == dto.Name).ToList();
if (productCode.Count() > 0) if (productCode.Count() > 0)
{ {
throw Oops.Oh("商品单位已存在");
throw Oops.Oh($"{dto.Name}已存在,添加失败!");
} }
try try
{ {
@@ -392,9 +388,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
var res = await _db.Insertable(bPA_Product).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); var res = await _db.Insertable(bPA_Product).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
return res > 0; return res > 0;
} }
catch (Exception ex)
catch (Exception e)
{ {
throw Oops.Oh("添加失败");
throw Oops.Oh(e.Message);
} }
} }
/// <summary> /// <summary>
@@ -402,25 +398,25 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <returns></returns> /// <returns></returns>
public async Task<PageUtil> GetGoodsBomPageAsync(GoodsBomQueryDto dto)
public async Task<PageUtil> GetGoodsBomPageAsync(GoodsBomQueryDto dto)
{ {
RefAsync<int> total = 0; RefAsync<int> total = 0;
var res =await _db.Queryable<BPA_Bom, BPA_BomAttributeValueRe>((a, b) => new JoinQueryInfos(
JoinType.Left, a.Id == b.BoomId
))
.WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsId), (a, b) => b.GoodsId==dto.GoodsId)
var res = await _db.Queryable<BPA_Bom, BPA_BomAttributeValueRe>((a, b) => new JoinQueryInfos(
JoinType.Left, a.Id == b.BoomId
))
.WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsId), (a, b) => b.GoodsId == dto.GoodsId)
.WhereIF(!string.IsNullOrWhiteSpace(dto.Name), (a, b) => a.Name.Contains(dto.Name)) .WhereIF(!string.IsNullOrWhiteSpace(dto.Name), (a, b) => a.Name.Contains(dto.Name))
.WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsAttributeValue), (a, b) => b.GoodsAttributeValue.Contains(dto.GoodsAttributeValue)) .WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsAttributeValue), (a, b) => b.GoodsAttributeValue.Contains(dto.GoodsAttributeValue))
.Select((a, b) => new GoodsBomPageView .Select((a, b) => new GoodsBomPageView
{ {
Id = b.Id, Id = b.Id,
Name = a.Name, Name = a.Name,
BomId= b.BoomId,
BomId = b.BoomId,
IsMain = a.IsMain, IsMain = a.IsMain,
GoodsAttributeValueId=b.GoodsAttributeValueId,
GoodsAttributeValue=b.GoodsAttributeValue,
GoodsAttributeValueId = b.GoodsAttributeValueId,
GoodsAttributeValue = b.GoodsAttributeValue,
}) })
.ToPageListAsync(dto.Current, dto.PageSize, total);
.ToPageListAsync(dto.Current, dto.PageSize, total);
PageUtil util = new PageUtil() PageUtil util = new PageUtil()
{ {
Total = total, Total = total,
@@ -436,9 +432,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
public async Task<bool> BatchDelGoodsBomAsync(string Ids) public async Task<bool> BatchDelGoodsBomAsync(string Ids)
{ {
// var GoodsBom=_db.Queryable<BPA_GoodsBom>().Where(x => x.Id == Ids).First(); // var GoodsBom=_db.Queryable<BPA_GoodsBom>().Where(x => x.Id == Ids).First();
var model=_db.Queryable<BPA_BomAttributeValueRe>().Where(x => x.Id == Ids).First();
if(model==null) throw Oops.Oh("配方不存在");
_db.Deleteable<BPA_GoodsBom>().Where(x => x.Goods_Id == model.GoodsId && x.BomId== model.BoomId).ExecuteCommand();
var model = _db.Queryable<BPA_BomAttributeValueRe>().Where(x => x.Id == Ids).First();
if (model == null) throw Oops.Oh("配方不存在");
_db.Deleteable<BPA_GoodsBom>().Where(x => x.Goods_Id == model.GoodsId && x.BomId == model.BoomId).ExecuteCommand();
// 查询数据库中是否存在未删除的商品 // 查询数据库中是否存在未删除的商品
var res = _db.Deleteable<BPA_BomAttributeValueRe>().In(Ids).ExecuteCommand(); var res = _db.Deleteable<BPA_BomAttributeValueRe>().In(Ids).ExecuteCommand();
return res > 0; return res > 0;
@@ -453,7 +449,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
_db.Ado.BeginTran(); _db.Ado.BeginTran();
try try
{ {
if(dto.Type== "add")
if (dto.Type == "add")
{ {
var sortMax = _db.Queryable<BPA_Bom>().Max(x => x.Sort); var sortMax = _db.Queryable<BPA_Bom>().Max(x => x.Sort);
BPA_Bom newbPA_BOM = new BPA_Bom BPA_Bom newbPA_BOM = new BPA_Bom
@@ -511,7 +507,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
if (string.IsNullOrWhiteSpace(dto.BomId)) throw Oops.Oh("请选择配方"); if (string.IsNullOrWhiteSpace(dto.BomId)) throw Oops.Oh("请选择配方");
if (!string.IsNullOrWhiteSpace(dto.BomId)) if (!string.IsNullOrWhiteSpace(dto.BomId))
{ {
var check=_db.Queryable<BPA_GoodsBom>().Where(x => x.Goods_Id == dto.GoodsId && x.BomId == dto.BomId).Any();
var check = _db.Queryable<BPA_GoodsBom>().Where(x => x.Goods_Id == dto.GoodsId && x.BomId == dto.BomId).Any();
if (!check) if (!check)
{ {
BPA_GoodsBom bom = new BPA_GoodsBom(); BPA_GoodsBom bom = new BPA_GoodsBom();
@@ -522,18 +518,18 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
_db.Insertable(bom).CallEntityMethod(m => m.Create()).ExecuteCommand(); _db.Insertable(bom).CallEntityMethod(m => m.Create()).ExecuteCommand();
} }
string vid = string.Join(",", dto.Shuxing); string vid = string.Join(",", dto.Shuxing);
var checkvid = _db.Queryable<BPA_BomAttributeValueRe>().Where(x => x.GoodsId == dto.GoodsId && x.BoomId == dto.BomId && x.GoodsAttributeValueId== vid).Any();
if(checkvid) throw Oops.Oh("该配方已经存在");
var checkvid = _db.Queryable<BPA_BomAttributeValueRe>().Where(x => x.GoodsId == dto.GoodsId && x.BoomId == dto.BomId && x.GoodsAttributeValueId == vid).Any();
if (checkvid) throw Oops.Oh("该配方已经存在");
//添加商品配方属性关系 //添加商品配方属性关系
BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new();
bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString();
bPA_BomAttributeValueRe.GoodsId = dto.GoodsId;
bPA_BomAttributeValueRe.BoomId = dto.BomId;
bPA_BomAttributeValueRe.GoodsAttributeValueId = vid;
bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString();
bPA_BomAttributeValueRe.GoodsId = dto.GoodsId;
bPA_BomAttributeValueRe.BoomId = dto.BomId;
bPA_BomAttributeValueRe.GoodsAttributeValueId = vid;
bPA_BomAttributeValueRe.GoodsAttributeValue = dto.GoodsAttributeValue; bPA_BomAttributeValueRe.GoodsAttributeValue = dto.GoodsAttributeValue;
_db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); _db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand();
}
}
} }
_db.Ado.CommitTran(); _db.Ado.CommitTran();
return true; return true;
@@ -554,14 +550,14 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
BPA_GoodsBom goodsBom = new(); BPA_GoodsBom goodsBom = new();
goodsBom.BomId = dto.BomId[i]; goodsBom.BomId = dto.BomId[i];
goodsBom.Goods_Id= dto.GoodsId;
goodsBom.Goods_Id = dto.GoodsId;
goodsBom.Status = CommonStatus.ENABLE; goodsBom.Status = CommonStatus.ENABLE;
list.Add(goodsBom); list.Add(goodsBom);
} }
} }
if (list.Count>0)
if (list.Count > 0)
{ {
res=await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync()>0;
res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync() > 0;
} }
return res; return res;
} }
@@ -592,7 +588,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
GoodsUintName = SqlFunc.Subqueryable<BPA_GoodsUint>().Where(s => s.Id == a.GoodsUintId && s.IsDeleted == 0).Select(s => s.Name), GoodsUintName = SqlFunc.Subqueryable<BPA_GoodsUint>().Where(s => s.Id == a.GoodsUintId && s.IsDeleted == 0).Select(s => s.Name),
//GoodsAttributeList = new List<GoodsAttributeList>() //GoodsAttributeList = new List<GoodsAttributeList>()
}).FirstAsync(); }).FirstAsync();
if (res!=null)
if (res != null)
{ {
if (!res.IsAttrubute) if (!res.IsAttrubute)
{ {
@@ -627,7 +623,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services


//1.查询并且添加类型 //1.查询并且添加类型
var nonLiquid = await _db.Queryable<BPA_BatchingType>() var nonLiquid = await _db.Queryable<BPA_BatchingType>()
.Where(x => x.Name == "非液体" ).FirstAsync();
.Where(x => x.Name == "非液体").FirstAsync();
if (nonLiquid == null) if (nonLiquid == null)
{ {
nonLiquid = new BPA_BatchingType() nonLiquid = new BPA_BatchingType()
@@ -730,15 +726,15 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
Remark = "", Remark = "",
Sort = 0, Sort = 0,
Status = 0, Status = 0,
Pid="0"
Pid = "0"
}; };


type=await _db.Insertable(parentType).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
type = await _db.Insertable(parentType).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
parentType = type; parentType = type;
} }
//属性 //属性
var goodsAttribute = await _db.Queryable<BPA_GoodsAttribute>() var goodsAttribute = await _db.Queryable<BPA_GoodsAttribute>()
.Where(x => x.AttributeName == "默认属性" ).FirstAsync();
.Where(x => x.AttributeName == "默认属性").FirstAsync();
if (goodsAttribute == null) if (goodsAttribute == null)
{ {
goodsAttribute = new BPA_GoodsAttribute() goodsAttribute = new BPA_GoodsAttribute()
@@ -798,8 +794,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
ForeignKeyRe = null, ForeignKeyRe = null,
GoodsUintId = goodsUint.Id, GoodsUintId = goodsUint.Id,
Descritption = "", Descritption = "",
ImgMode = 0,
ImgUrl = imagePath?.ImgesPath,
ImgMode = 0,
ImgUrl = imagePath?.ImgesPath,
Name = item.Name, Name = item.Name,
Sort = 0, Sort = 0,
GoodsTypeId = parentType.Id, GoodsTypeId = parentType.Id,
@@ -827,7 +823,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
item2.Id = thisitem.Id; item2.Id = thisitem.Id;
item2.AutoKey = thisitem.AutoKey; item2.AutoKey = thisitem.AutoKey;
item2.GroupId= thisitem.GroupId;
item2.GroupId = thisitem.GroupId;
_db.Updateable(item2).ExecuteCommand(); _db.Updateable(item2).ExecuteCommand();
} }
else else
@@ -937,7 +933,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
var thisName = goodTechnologyModel[i].Name == null ? cName : goodTechnologyModel[i].Name; var thisName = goodTechnologyModel[i].Name == null ? cName : goodTechnologyModel[i].Name;


var data = await _db.Queryable<BPA_Technology>() var data = await _db.Queryable<BPA_Technology>()
.Where(x => x.Name == thisName && x.DeviceVersionId == device.ProductVersionId).FirstAsync();
.Where(x => x.Name == thisName && x.DeviceVersionId == device.ProductVersionId).FirstAsync();
if (data == null) throw Oops.Oh("该设备还没有设置工艺基础信息"); if (data == null) throw Oops.Oh("该设备还没有设置工艺基础信息");
var data2 = await _db.Queryable<BPA_TechnologyAction>() var data2 = await _db.Queryable<BPA_TechnologyAction>()
.Where(x => x.ActionName == goodTechnologyModel[i].Configuration && x.TechnologyId == data.Id).FirstAsync(); .Where(x => x.ActionName == goodTechnologyModel[i].Configuration && x.TechnologyId == data.Id).FirstAsync();
@@ -1116,136 +1112,136 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services


//if (inputDto.IsAddGoodsTemplate) //if (inputDto.IsAddGoodsTemplate)
//{ //{
//} //}
//else //else
//{ //{
var source = file.OpenReadStream();
var mapper = new Mapper(source);
var deviceVersion = await _db.Queryable<BPA_ProductVesion>().FirstAsync(x => x.ProductId == inputDto.DeviceClientType && x.Vesion == inputDto.Version);
//添加 设备_烹饪工序模型
#region 添加 设备_烹饪工序模型
ReadExcel<GoodstechnologyModel> readGoodstechnologyExcel = new();
var GoodstechnologyModellist = readGoodstechnologyExcel.ExcelToList(source, mapper);
List<BPA_Technology> GoodsTechnologyList = new();
List<BPA_TechnologyAction> GoodsTechnologyActionList = new();
var GoodsTechnologyListDB = await _db.Queryable<BPA_Technology>()
.Where(x => x.DeviceVersionId == deviceVersion.Id).ToListAsync();
string currennaid = "";
string currennaname = "";
for (int i = 0; i < GoodstechnologyModellist.Count; i++)
{
var goodsTechnologyId = GoodsTechnologyListDB.FirstOrDefault(x => x.Name == GoodstechnologyModellist[i].Name);


if (!string.IsNullOrWhiteSpace(GoodstechnologyModellist[i].Name))
{
var source = file.OpenReadStream();
var mapper = new Mapper(source);
var deviceVersion = await _db.Queryable<BPA_ProductVesion>().FirstAsync(x => x.ProductId == inputDto.DeviceClientType && x.Vesion == inputDto.Version);
//添加 设备_烹饪工序模型
#region 添加 设备_烹饪工序模型
ReadExcel<GoodstechnologyModel> readGoodstechnologyExcel = new();
var GoodstechnologyModellist = readGoodstechnologyExcel.ExcelToList(source, mapper);
List<BPA_Technology> GoodsTechnologyList = new();
List<BPA_TechnologyAction> GoodsTechnologyActionList = new();
var GoodsTechnologyListDB = await _db.Queryable<BPA_Technology>()
.Where(x => x.DeviceVersionId == deviceVersion.Id).ToListAsync();
string currennaid = "";
string currennaname = "";
for (int i = 0; i < GoodstechnologyModellist.Count; i++)
{
var goodsTechnologyId = GoodsTechnologyListDB.FirstOrDefault(x => x.Name == GoodstechnologyModellist[i].Name);


BPA_Technology item = new BPA_Technology()
{
Id = goodsTechnologyId == null ? Guid.NewGuid().ToString() : goodsTechnologyId.Id,
Name = GoodstechnologyModellist[i].Name,
DeviceVersionId = deviceVersion.Id
};
GoodsTechnologyList.Add(item);
currennaid = item.Id;
currennaname = item.Name;
}
var actvalueary = GoodstechnologyModellist[i].ActionValue?.Split('、');
if (string.IsNullOrEmpty(GoodstechnologyModellist[i].ActionType) && currennaname != "液体料")
{
throw Oops.Oh($"类型错误");
}
BPA_TechnologyAction technologyAction = new()
if (!string.IsNullOrWhiteSpace(GoodstechnologyModellist[i].Name))
{

BPA_Technology item = new BPA_Technology()
{ {
Id = Guid.NewGuid().ToString(),
TechnologyId = currennaid,
ActionName = GoodstechnologyModellist[i].ActionName,
ActionType = CharacterConversion(GoodstechnologyModellist[i].ActionType),
Sort = i,
TechnologyType = GoodstechnologyModellist[i].TechnologyType == "物料" ? TechnologyEnums.Batch : TechnologyEnums.Other,
CreateAt = DateTime.Now,
//ActionValue = GoodstechnologyModellist[i].ActionValue,
Id = goodsTechnologyId == null ? Guid.NewGuid().ToString() : goodsTechnologyId.Id,
Name = GoodstechnologyModellist[i].Name,
DeviceVersionId = deviceVersion.Id
}; };
List<ActionValueModel> ActionValueModelList = new();
if (actvalueary != null)
{
foreach (var item in actvalueary)
{
ActionValueModelList.Add(new ActionValueModel() { actionValueName = item });
}
technologyAction.ActionValue = JsonConvert.SerializeObject(ActionValueModelList);
}
GoodsTechnologyActionList.Add(technologyAction);
GoodsTechnologyList.Add(item);
currennaid = item.Id;
currennaname = item.Name;
} }

//修改添加 主表
foreach (var item in GoodsTechnologyList)
var actvalueary = GoodstechnologyModellist[i].ActionValue?.Split('、');
if (string.IsNullOrEmpty(GoodstechnologyModellist[i].ActionType) && currennaname != "液体料")
{ {
var thisitem = GoodsTechnologyListDB.FirstOrDefault(x => x.Name == item.Name);

if (thisitem != null)
{
item.Id = thisitem.Id;
item.CreateAt = DateTime.Now;
_db.Updateable(item).ExecuteCommand();
}
else
throw Oops.Oh($"类型错误");
}
BPA_TechnologyAction technologyAction = new()
{
Id = Guid.NewGuid().ToString(),
TechnologyId = currennaid,
ActionName = GoodstechnologyModellist[i].ActionName,
ActionType = CharacterConversion(GoodstechnologyModellist[i].ActionType),
Sort = i,
TechnologyType = GoodstechnologyModellist[i].TechnologyType == "物料" ? TechnologyEnums.Batch : TechnologyEnums.Other,
CreateAt = DateTime.Now,
//ActionValue = GoodstechnologyModellist[i].ActionValue,
};
List<ActionValueModel> ActionValueModelList = new();
if (actvalueary != null)
{
foreach (var item in actvalueary)
{ {
//item.Id = Guid.NewGuid().ToString();
item.CreateAt = DateTime.Now;
await _db.Insertable(item).ExecuteCommandAsync();
ActionValueModelList.Add(new ActionValueModel() { actionValueName = item });
} }
technologyAction.ActionValue = JsonConvert.SerializeObject(ActionValueModelList);
} }
GoodsTechnologyActionList.Add(technologyAction);
}


//修改添从表
GoodsTechnologyActionList = GoodsTechnologyActionList.Where(x => !string.IsNullOrEmpty(x.ActionName)).ToList();
var goodstechnologyIds = GoodsTechnologyList.Select(x => x.Id).ToList();
var GoodsTechnologyActionListDb = await _db.Queryable<BPA_TechnologyAction>()
.Where(x => goodstechnologyIds.Contains(x.TechnologyId)).ToListAsync();
//修改添加 主表
foreach (var item in GoodsTechnologyList)
{
var thisitem = GoodsTechnologyListDB.FirstOrDefault(x => x.Name == item.Name);


foreach (var item in GoodsTechnologyActionList)
if (thisitem != null)
{ {
var thisitem = GoodsTechnologyActionListDb.FirstOrDefault(x => item.TechnologyId == x.TechnologyId && item.ActionName == x.ActionName);
if (thisitem != null)
{
item.Id = thisitem.Id;
item.CreateAt = DateTime.Now;
_db.Updateable(item).ExecuteCommand();
}
else
{
item.Id = Guid.NewGuid().ToString();
item.CreateAt= DateTime.Now;
await _db.Insertable(item).ExecuteCommandAsync();
}
item.Id = thisitem.Id;
item.CreateAt = DateTime.Now;
_db.Updateable(item).ExecuteCommand();
} }
#endregion
var path = inputDto.AliyunUrl;
var TechnologyExportRecode = _db.Queryable<BPA_TechnologyExportRecode>().Where(x=>x.DeviceVersionId == inputDto.Id).First();
if (TechnologyExportRecode != null)
else
{ {
TechnologyExportRecode.CreateAt= DateTime.Now;
TechnologyExportRecode.TemplatePath = path;
var vvv= await _db.Updateable(TechnologyExportRecode).ExecuteCommandAsync();
//item.Id = Guid.NewGuid().ToString();
item.CreateAt = DateTime.Now;
await _db.Insertable(item).ExecuteCommandAsync();
}
}

//修改添从表
GoodsTechnologyActionList = GoodsTechnologyActionList.Where(x => !string.IsNullOrEmpty(x.ActionName)).ToList();
var goodstechnologyIds = GoodsTechnologyList.Select(x => x.Id).ToList();
var GoodsTechnologyActionListDb = await _db.Queryable<BPA_TechnologyAction>()
.Where(x => goodstechnologyIds.Contains(x.TechnologyId)).ToListAsync();

foreach (var item in GoodsTechnologyActionList)
{
var thisitem = GoodsTechnologyActionListDb.FirstOrDefault(x => item.TechnologyId == x.TechnologyId && item.ActionName == x.ActionName);
if (thisitem != null)
{
item.Id = thisitem.Id;
item.CreateAt = DateTime.Now;
_db.Updateable(item).ExecuteCommand();
} }
else else
{ {
item.Id = Guid.NewGuid().ToString();
item.CreateAt = DateTime.Now;
await _db.Insertable(item).ExecuteCommandAsync();
}
}
#endregion
var path = inputDto.AliyunUrl;
var TechnologyExportRecode = _db.Queryable<BPA_TechnologyExportRecode>().Where(x => x.DeviceVersionId == inputDto.Id).First();
if (TechnologyExportRecode != null)
{
TechnologyExportRecode.CreateAt = DateTime.Now;
TechnologyExportRecode.TemplatePath = path;
var vvv = await _db.Updateable(TechnologyExportRecode).ExecuteCommandAsync();
}
else
{

BPA_TechnologyExportRecode _TechnologyExportRecode = new(); BPA_TechnologyExportRecode _TechnologyExportRecode = new();
_TechnologyExportRecode.Id = Guid.NewGuid().ToString();
_TechnologyExportRecode.CreateAt = DateTime.Now;
_TechnologyExportRecode.ProductId = inputDto.DeviceClientType;
_TechnologyExportRecode.DeviceVersionId = inputDto.Id;
_TechnologyExportRecode.TemplatePath= path;
await _db.Insertable(_TechnologyExportRecode).ExecuteCommandAsync();
_TechnologyExportRecode.Id = Guid.NewGuid().ToString();
_TechnologyExportRecode.CreateAt = DateTime.Now;
_TechnologyExportRecode.ProductId = inputDto.DeviceClientType;
_TechnologyExportRecode.DeviceVersionId = inputDto.Id;
_TechnologyExportRecode.TemplatePath = path;
await _db.Insertable(_TechnologyExportRecode).ExecuteCommandAsync();
//await _db.Updateable<BPA_TechnologyExportRecode>() //await _db.Updateable<BPA_TechnologyExportRecode>()
// .SetColumns(it => it.TemplatePath == path) // .SetColumns(it => it.TemplatePath == path)
// .Where(it => it.Id == inputDto.Id) // .Where(it => it.Id == inputDto.Id)
// .ExecuteCommandAsync(); // .ExecuteCommandAsync();
} }
//} //}
_db.Ado.CommitTran(); _db.Ado.CommitTran();
} }
@@ -1257,6 +1253,161 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
return true; return true;
} }


/// <summary>
/// 商品导入
/// </summary>
/// <param name="importDto"></param>
/// <returns></returns>
public async Task<bool> GoodsImport(GoodsInfoImportDto importDto)
{
var file = importDto.File;
var aliyunHost = "https://bpa.oss-cn-chengdu.aliyuncs.com/";
var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
if (string.IsNullOrEmpty(userId))
{
userId = "";
}
var goodsInfo = await _db.Queryable<BPA_GoodsInfo>().ToListAsync();
var goodsType = await _db.Queryable<BPA_GoodsType>().ToListAsync();
var goodsUint = await _db.Queryable<BPA_GoodsUint>().ToListAsync();
try
{
_db.Ado.BeginTran();
var source = file.OpenReadStream();
var mapper = new Mapper(source);
var excelDto = new ReadExcel<GoodsImportDto>();
var dataList = excelDto.ExcelToList(source, mapper);
dataList.RemoveAll(t => t.Name == null);
UpdateGoodsImportDto(dataList);
var imageList = await GetImagesWithExcel(file.OpenReadStream(), Path.GetExtension(file.FileName));
var newUnitList = new List<BPA_GoodsUint>();
var i = 0;
foreach (var data in dataList)
{
if (data.Type == null)
throw Oops.Oh($"商品分类不能为空!");
if (data.Name == null)
throw Oops.Oh($"商品名称不能为空!");
if (data.Uint == null)
throw Oops.Oh($"商品单位不能为空!");
var type = goodsType.FirstOrDefault(t => t.Name == data.Type);
if (type == null)
throw Oops.Oh($"{data.Name} 不存在分类:{data.Type}!");
var old = goodsInfo.FirstOrDefault(t => t.Name == data.Name && t.GoodsTypeId == type.Id);
if (old != null)
throw Oops.Oh($"{data.Name} 已存在该商品!");
var uintId = "";
var uintData = goodsUint.FirstOrDefault(t => t.Name == data.Uint);
var newUnitData = newUnitList.FirstOrDefault(t => t.Name == data.Uint);
if (uintData != null || newUnitData != null)
uintId = uintData != null ? uintData.Id : newUnitData.Id;
else
{
uintId = Guid.NewGuid().ToString();
var newUint = new BPA_GoodsUint
{
Id = uintId,
Name = data.Uint,
CreateBy = userId
};
newUnitList.Add(newUint);
await _db.Insertable(newUint).ExecuteCommandAsync();
}
var imgUrl = data.ImgUrl != null ? data.ImgUrl.ToString() : "";
if (!imgUrl.Contains("=DISPIMG"))
imgUrl = null;
else
{
imgUrl = aliyunHost + imageList[i];
i++;
}
var newValue = new BPA_GoodsInfo
{
Id = Guid.NewGuid().ToString(),
Name = data.Name,
GoodsTypeId = type.Id,
Descritption = data.Descritption,
ImgUrl = imgUrl,
Code = GetNumber2(8),
Price = data.Price,
CreateBy = userId,
GoodsUintId = uintId,
IsWeigh = data.IsWeigh == "是",
IsAttrubute = true
};
await _db.Insertable(newValue).ExecuteCommandAsync();
}
_db.Ado.CommitTran();
}
catch (Exception e)
{
_db.Ado.RollbackTran();
throw Oops.Oh($"Excel导入错误," + e.Message);
}
return true;
}

public List<GoodsImportDto> UpdateGoodsImportDto(List<GoodsImportDto> list)
{
foreach (var item in list)
{
item.Name = item.Name?.Trim();
item.Type = item.Type?.Trim();
item.Uint = item.Uint?.Trim();
item.IsWeigh = item.IsWeigh?.Trim();
item.Descritption = item.Descritption?.Trim();
}
return list;
}

public async Task<List<string>> GetImagesWithExcel(Stream stream, string fileType)
{
try
{
var result = new List<string>();
IWorkbook workbook;
if (fileType == ".xlsx")
{
workbook = new XSSFWorkbook(stream);
var pictures = workbook.GetAllPictures();
foreach (XSSFPictureData pic in pictures)
{
using (var ms = new MemoryStream(pic.Data))
{
var suffix = pic.SuggestFileExtension();
var fileName = Guid.NewGuid().ToString();
IFormFile formFile = new FormFile(ms, 0, ms.Length, "name", $"{fileName}.{suffix}");
result.Add(await _aliyunOssService.UpFileAsync(formFile));
}
}
}
else if (fileType == ".xls")
{
workbook = new HSSFWorkbook(stream);
var pictures = workbook.GetAllPictures();
foreach (HSSFPictureData pic in pictures)
{
using (var ms = new MemoryStream(pic.Data))
{
var suffix = pic.SuggestFileExtension();
var fileName = Guid.NewGuid().ToString();
IFormFile formFile = new FormFile(ms, 0, ms.Length, "name", $"{fileName}.{suffix}");
result.Add(await _aliyunOssService.UpFileAsync(formFile));
}
}
}
else
{
throw new Exception("传入的不是Excel文件!");
}
return result;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

/// <summary> /// <summary>
/// 商品工艺导入 /// 商品工艺导入
/// </summary> /// </summary>
@@ -1265,7 +1416,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
public async Task<bool> GoodsTechnologyImport(GoodsTechnologyImportDto importDto) public async Task<bool> GoodsTechnologyImport(GoodsTechnologyImportDto importDto)
{ {
string pattern = @"(?<part1>[^,(]+),(?<part2>\([^)]+\)),(?<part3>[^,]+)"; string pattern = @"(?<part1>[^,(]+),(?<part2>\([^)]+\)),(?<part3>[^,]+)";
var file = importDto.file;
var file = importDto.File;
var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
if (string.IsNullOrEmpty(userId)) if (string.IsNullOrEmpty(userId))
{ {
@@ -1480,7 +1631,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
} }


/// <summary> /// <summary>
/// 商品工艺导出
/// 商品工艺模版导出
/// </summary> /// </summary>
/// <param name="exportDto"></param> /// <param name="exportDto"></param>
/// <returns></returns> /// <returns></returns>
@@ -1576,7 +1727,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
sheet.AddMergedRegion(new CellRangeAddress(1, 2, 4, 4)); sheet.AddMergedRegion(new CellRangeAddress(1, 2, 4, 4));
#endregion #endregion
} }
var tempFolder = Path.Combine(_hostingEnvironment.ContentRootPath, "TechnologyTemplate");
var tempFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TechnologyTemplate");
if (!Directory.Exists(tempFolder)) if (!Directory.Exists(tempFolder))
Directory.CreateDirectory(tempFolder); Directory.CreateDirectory(tempFolder);
var time = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒"); var time = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒");
@@ -1589,6 +1740,70 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
return fileBase64; return fileBase64;
} }


/// <summary>
/// 商品工艺导出
/// </summary>
/// <param name="goodName"></param>
/// <returns></returns>
public async Task<string> GoodsSimpleExport(string goodName)
{
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();
var goodsType = await _db.Queryable<BPA_GoodsType>().ToListAsync();
var goodsInfo = await _db.Queryable<BPA_GoodsInfo>().FirstAsync(t => t.Name == goodName);
if (goodsInfo == null)
throw Oops.Oh("商品不存在!");
var actionList = await _db.Queryable<BPA_GoodsTechnologyAction>().Where(t => t.GoodsId == goodsInfo.Id).OrderBy(a => a.GoodsAttributeId).OrderBy(a => a.Order).ToListAsync();
IWorkbook workbook = new XSSFWorkbook();
string[] charsToReplace = new string[] { "\\", "/", "?", "*", "[", "]" };
foreach (string c in charsToReplace)
{
goodName = goodName.Replace(c, " ");
}
ISheet sheet = workbook.CreateSheet(goodName);
IRow headerRow = sheet.CreateRow(0);
headerRow.CreateCell(0).SetCellValue("商品名称");
headerRow.CreateCell(1).SetCellValue("属性组合");
headerRow.CreateCell(2).SetCellValue("工序");
headerRow.CreateCell(3).SetCellValue("工序参数");
headerRow.CreateCell(4).SetCellValue("参数值");
var k = 1;
for (int i = 0; i < actionList.Count; i++)
{
var stepName = actionList[i].StepName;
var attributeNames = "";
var attributeNameList = new List<string>();
var goodsAttributeIdList = actionList[i].GoodsAttributeId.Split(',');
foreach (var goodsAttributeId in goodsAttributeIdList)
{
attributeNameList.Add(goodsAttributeValueList.FirstOrDefault(t => t.Id == goodsAttributeId)?.AttributeValue);
}
attributeNames = string.Join("-", attributeNameList);
var actionJsonList = JsonConvert.DeserializeObject<List<ActionJsonModel>>(actionList[i].ActionJson);
for (int j = 0; j < actionJsonList.Count; j++)
{
IRow dataRow = sheet.CreateRow(k);
dataRow.CreateCell(0).SetCellValue(goodName);
dataRow.CreateCell(1).SetCellValue(attributeNames);
dataRow.CreateCell(2).SetCellValue(stepName);
dataRow.CreateCell(3).SetCellValue(actionJsonList[j].actionName);
dataRow.CreateCell(4).SetCellValue(actionJsonList[j].actionValue);
k++;
}
}
var tempFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GoodsTechnologyData");
if (!Directory.Exists(tempFolder))
Directory.CreateDirectory(tempFolder);
var time = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒");
var filePath = Path.Combine(tempFolder, $"{goodName}导出-{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) public static List<string> GenerateCombinations(Dictionary<string, List<string>> values, bool isId, BPA_GoodsInfo goodInfo, BPA_DeviceInfo deviceInfo)
{ {
var attributes = values.Keys.ToList(); var attributes = values.Keys.ToList();
@@ -1850,13 +2065,14 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
}, data); }, data);
return result; return result;
} }
private string GetNumber2(int Length = 10)
private string GetNumber2(int Length = 10)
{ {
byte[] buffer = Guid.NewGuid().ToByteArray(); byte[] buffer = Guid.NewGuid().ToByteArray();
var ram = BitConverter.ToInt64(buffer, 0); var ram = BitConverter.ToInt64(buffer, 0);
var str = string.Format("{0}", ram.ToString().Substring(0, Length)); var str = string.Format("{0}", ram.ToString().Substring(0, Length));
return str; return str;
} }

} }
} }

+ 22
- 19
BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs View File

@@ -21,12 +21,12 @@ using System.Threading.Tasks;


namespace BPA.SAAS.Manage.Application.DataBase.Services namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
public class GoodsTypeService: IGoodsTypeService, ITransient
public class GoodsTypeService : IGoodsTypeService, ITransient
{ {
private readonly ISqlSugarClient _db; private readonly ISqlSugarClient _db;
public GoodsTypeService(ISqlSugarClient db) public GoodsTypeService(ISqlSugarClient db)
{ {
_db= db;
_db = db;
} }
/// <summary> /// <summary>
/// 分页查询 /// 分页查询
@@ -93,6 +93,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
try try
{ {
var old = await _db.Queryable<BPA_GoodsType>().FirstAsync(t => t.Name == dto.Name);
if (old != null)
throw Oops.Oh($"已存在{dto.Name},添加失败!");
var res = 0; var res = 0;
if (string.IsNullOrWhiteSpace(dto.Id)) if (string.IsNullOrWhiteSpace(dto.Id))
{ {
@@ -132,10 +135,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
return res > 0; return res > 0;
} }
} }
catch (Exception)
catch (Exception e)
{ {
_db.Ado.RollbackTran(); _db.Ado.RollbackTran();
throw Oops.Oh("添加失败!");
throw Oops.Oh(e.Message);
} }
} }
public async Task<int> HandleGoodsAttribute(BPA_GoodsType typeEntity, List<AttributeDto> AttributeList) public async Task<int> HandleGoodsAttribute(BPA_GoodsType typeEntity, List<AttributeDto> AttributeList)
@@ -200,20 +203,20 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
public async Task<bool> UpdateGoodsType(GoodsTypeDto dto) public async Task<bool> UpdateGoodsType(GoodsTypeDto dto)
{ {
// 查询数据库中是否存在未删除的商品类型 // 查询数据库中是否存在未删除的商品类型
var resEntity = _db.Queryable<BPA_GoodsType>().First(it => it.Id == dto.Id);
if (null == resEntity)
{
return false;
}
var resEntity = _db.Queryable<BPA_GoodsType>().First(it => it.Id == dto.Id);
if (null == resEntity)
{
return false;
}

resEntity.Name = dto.Name;
resEntity.Pid = dto.Pid;
resEntity.Sort = dto.Sort;
resEntity.Remark = dto.Remark;

resEntity.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), dto.Status);


resEntity.Name = dto.Name;
resEntity.Pid = dto.Pid;
resEntity.Sort = dto.Sort;
resEntity.Remark = dto.Remark;
resEntity.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), dto.Status);
var res =await _db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
var res = await _db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
return res > 0; return res > 0;
} }
public async Task<List<dynamic>> GetGoodsTypeList_alm() public async Task<List<dynamic>> GetGoodsTypeList_alm()
@@ -225,7 +228,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
{ {
id = x.Id, id = x.Id,
name = x.Name, name = x.Name,
pid= x.Pid,
pid = x.Pid,
}).ToListAsync(); }).ToListAsync();
return res; return res;
} }
@@ -282,7 +285,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
var dataScopeList = new List<string>(); var dataScopeList = new List<string>();
var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value; var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value;
var orgs = await _db.Queryable<BPA_GoodsType>().WhereIF(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id)) var orgs = await _db.Queryable<BPA_GoodsType>().WhereIF(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id))
.Where(u => u.Status == CommonStatus.ENABLE && u.IsDeleted==0 && u.GroupId == groupId).OrderBy(u => u.Sort)
.Where(u => u.Status == CommonStatus.ENABLE && u.IsDeleted == 0 && u.GroupId == groupId).OrderBy(u => u.Sort)
.Select(u => new OrgTreeNode .Select(u => new OrgTreeNode
{ {
key = u.Id, key = u.Id,


+ 6
- 0
BPA.SAAS.Manage.Application/System/AliyunOssServices.cs View File

@@ -23,5 +23,11 @@ namespace BPA.SAAS.Manage.Application.System
{ {
return await _aliyunOssService.GeneratePostPolicyAsync(request); return await _aliyunOssService.GeneratePostPolicyAsync(request);
} }

[HttpPost("/api/systemconfig/UpFileAsync"), ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify]
public async Task<string> UpFileAsync(IFormFile formFile)
{
return await _aliyunOssService.UpFileAsync(formFile);
}
} }
} }

+ 1
- 0
BPA.SAAS.Manage.Application/System/Interface/IAliyunOssService.cs View File

@@ -11,5 +11,6 @@ namespace BPA.SAAS.Manage.Application.System.Interface
public interface IAliyunOssService public interface IAliyunOssService
{ {
Task<AliyunOssPostPolicyResponse> GeneratePostPolicyAsync(Aliyun0ssGeneratePostPolicyRequest request); Task<AliyunOssPostPolicyResponse> GeneratePostPolicyAsync(Aliyun0ssGeneratePostPolicyRequest request);
Task<string> UpFileAsync(IFormFile formFile);
} }
} }

+ 8
- 1
BPA.SAAS.Manage.Application/System/Services/AliyunOssService.cs View File

@@ -1,4 +1,5 @@
using BPA.Aliyun.OSS;
using Aliyun.OSS.Util;
using BPA.Aliyun.OSS;
using BPA.Aliyun.OSS.Options; using BPA.Aliyun.OSS.Options;
using BPA.SAAS.Manage.Application.System.Dtos; using BPA.SAAS.Manage.Application.System.Dtos;
using BPA.SAAS.Manage.Application.System.Interface; using BPA.SAAS.Manage.Application.System.Interface;
@@ -27,5 +28,11 @@ namespace BPA.SAAS.Manage.Application.System.Services
var data = await _aliyunOssClient.GeneratePostPolicyAsync(dir); var data = await _aliyunOssClient.GeneratePostPolicyAsync(dir);
return data; return data;
} }

public async Task<string> UpFileAsync(IFormFile formFile)
{
var data = await _aliyunOssClient.UpFileAsync(formFile);
return data;
}
} }
} }

+ 1
- 1
BPA.SAAS.Manage.Web.Entry/appsettings.json View File

@@ -41,7 +41,7 @@
"PresignedUriExpirationMinutes": 1440, "PresignedUriExpirationMinutes": 1440,
"PolicyExpirationMinutes": 1440, "PolicyExpirationMinutes": 1440,
"ProjectName": "hkerp", "ProjectName": "hkerp",
"ServiceName": "test"
"ServiceName": "test/goods"
} }
} }
}, },


Loading…
Cancel
Save