public async Task <IActionResult> ChangeICon([FromBody] IconEdtiModel model)
        {
            var fileMicroServer = new FileMicroService(_AppConfig.APIGatewayServer, Token);
            var file            = await fileMicroServer.GetById(model.AssetId);

            var entity = await _Context.Set <T>().FirstOrDefaultAsync(x => x.Id == model.ObjId);

            if (file == null)
            {
                ModelState.AddModelError("message", $"找不到文件Id为{model.AssetId}的记录信息");
                return(BadRequest(ModelState));
            }
            if (entity == null)
            {
                ModelState.AddModelError("message", $"找不到对象Id为{model.ObjId}的记录信息");
                return(BadRequest(ModelState));
            }

            entity.Icon = file.Id;
            _Context.Set <T>().Update(entity);
            await _Context.SaveChangesAsync();

            return(Ok());
        }
예제 #2
0
        public override async Task <IActionResult> Get(string id)
        {
            var accountMicroService     = new AccountMicroService(_AppConfig.APIGatewayServer);
            var productSpecMicroService = new ProductSpecMicroService(_AppConfig.APIGatewayServer);
            var productMicroService     = new ProductMicroService(_AppConfig.APIGatewayServer);
            var fileMicroServer         = new FileMicroService(_AppConfig.APIGatewayServer);

            var toDTO = new Func <Order, Task <OrderDTO> >(async(entity) =>
            {
                var dto  = new OrderDTO();
                dto.Id   = entity.Id;
                dto.Name = entity.Name;

                dto.Description    = entity.Description;
                dto.Creator        = entity.Creator;
                dto.Modifier       = entity.Modifier;
                dto.CreatedTime    = entity.CreatedTime;
                dto.ModifiedTime   = entity.ModifiedTime;
                dto.OrganizationId = entity.OrganizationId;
                dto.TotalNum       = entity.TotalNum;
                //dto.TotalPrice = entity.TotalPrice;
                dto.OrderNo         = entity.OrderNo;
                dto.CustomerName    = entity.CustomerName;
                dto.CustomerPhone   = entity.CustomerPhone;
                dto.CustomerAddress = entity.CustomerAddress;
                dto.Data            = entity.Data;
                dto.SolutionId      = entity.SolutionId;
                dto.Url             = $"{_AppConfig.Plugins.OrderViewer}?order={entity.Id}";

                #region 订单状态
                if (string.IsNullOrWhiteSpace(entity.WorkFlowItemId))
                {
                    var refRule = await _Context.WorkFlowRuleDetails.FirstOrDefaultAsync(x => x.OrganizationId == CurrentAccountOrganizationId && x.WorkFlowRuleId == WorkFlowRuleConst.OrderWorkFlow);
                    if (refRule != null)
                    {
                        var dfItem           = await _Context.WorkFlowItems.FirstOrDefaultAsync(x => x.WorkFlowId == refRule.WorkFlowId && x.FlowGrade == 0);
                        dto.WorkFlowItemId   = dfItem.Id;
                        dto.WorkFlowItemName = dfItem.Name;
                    }
                }
                else
                {
                    dto.WorkFlowItemId = entity.WorkFlowItemId;
                    var dfitem         = await _Context.WorkFlowItems.FirstOrDefaultAsync(x => x.Id == entity.WorkFlowItemId);
                    if (dfitem != null)
                    {
                        dto.WorkFlowItemName = dfitem.Name;
                    }
                }
                #endregion

                #region OrderDetails
                var details = new List <OrderDetailDTO>();
                if (entity.OrderDetails != null && entity.OrderDetails.Count > 0)
                {
                    decimal totalPrice = 0;
                    foreach (var it in entity.OrderDetails)
                    {
                        var ditem           = new OrderDetailDTO();
                        ditem.Id            = it.Id;
                        ditem.Remark        = it.Remark;
                        ditem.Num           = it.Num;
                        ditem.UnitPrice     = Math.Round(it.UnitPrice, 2, MidpointRounding.AwayFromZero);
                        ditem.TotalPrice    = Math.Round(it.UnitPrice * it.Num, 2, MidpointRounding.AwayFromZero);
                        ditem.AttachmentIds = it.AttachmentIds;
                        ditem.Room          = it.Room;
                        ditem.Owner         = it.Owner;
                        totalPrice         += ditem.TotalPrice;
                        var pckDtos         = new List <OrderDetailPackageDTO>();
                        var pcks            = await _Context.OrderDetailPackages.Where(x => x.OrderDetailId == it.Id).OrderByDescending(x => x.Num).ToListAsync();
                        foreach (var pck in pcks)
                        {
                            var pckDto     = new OrderDetailPackageDTO();
                            var refPackage = await _Context.ProductPackages.FirstOrDefaultAsync(x => x.Id == pck.ProductPackageId);
                            if (refPackage != null)
                            {
                                pckDto.Id          = pck.Id;
                                pckDto.PackageName = refPackage.Name;
                                pckDto.PackingUnit = refPackage.Num;
                                pckDto.Num         = pck.Num;
                                pckDtos.Add(pckDto);
                            }
                        }
                        ditem.Packages = pckDtos;

                        await productSpecMicroService.GetBriefById(it.ProductSpecId, (spec) =>
                        {
                            ditem.ProductSpecId   = spec.Id;
                            ditem.ProductSpecName = spec.Name;
                            ditem.ProductId       = spec.ProductId;
                            ditem.Icon            = spec.Icon;
                            ditem.TPID            = spec.TPID;
                        });

                        await productMicroService.GetBriefById(ditem.ProductId, (prod) =>
                        {
                            ditem.ProductName         = prod.Name;
                            ditem.ProductCategoryId   = prod.CategoryId;
                            ditem.ProductCategoryName = prod.CategoryName;
                            ditem.ProductUnit         = prod.Unit;
                            ditem.ProductBrand        = prod.Brand;
                            ditem.ProductDescription  = prod.Description;
                        });

                        if (!string.IsNullOrWhiteSpace(ditem.AttachmentIds))
                        {
                            var fsIdArr = ditem.AttachmentIds.Split(",", StringSplitOptions.RemoveEmptyEntries);
                            var fsList  = new List <OrderDetailAttachmentDTO>();
                            foreach (var fid in fsIdArr)
                            {
                                await fileMicroServer.GetById(fid, (fs) =>
                                {
                                    var fdto  = new OrderDetailAttachmentDTO();
                                    fdto.Id   = fs.Id;
                                    fdto.Name = fs.Name;
                                    fdto.Url  = fs.Url;
                                    fsList.Add(fdto);
                                });
                            }
                            ditem.Attachments = fsList;
                        }

                        details.Add(ditem);
                    }
                    dto.TotalPrice = totalPrice;
                }
                dto.OrderDetails = details;
                #endregion

                #region CustomizedProduct
                var customizedProducts = new List <OrderDetailCustomizedProductDTO>();
                if (entity.CustomizedProducts != null & entity.CustomizedProducts.Count > 0)
                {
                    foreach (var it in entity.CustomizedProducts)
                    {
                        var ditem  = new OrderDetailCustomizedProductDTO();
                        ditem.Id   = it.Id;
                        ditem.Name = it.Name;
                        ditem.Icon = it.Icon;
                        customizedProducts.Add(ditem);
                    }
                }
                dto.CustomizedProducts = customizedProducts;
                #endregion

                #region OrderFlowLogs
                var logs = new List <OrderFlowLogDTO>();
                if (entity.OrderFlowLogs != null && entity.OrderFlowLogs.Count > 0)
                {
                    foreach (var log in entity.OrderFlowLogs)
                    {
                        var logDto              = new OrderFlowLogDTO();
                        logDto.Id               = log.Id;
                        logDto.Approve          = log.Approve;
                        logDto.Remark           = log.Remark;
                        logDto.WorkFlowItemId   = log.WorkFlowItemId;
                        logDto.WorkFlowItemName = await _Context.WorkFlowItems.Where(x => x.Id == log.WorkFlowItemId).Select(x => x.Name).FirstOrDefaultAsync();
                        logDto.Creator          = log.Creator;
                        logDto.CreatedTime      = log.CreatedTime;
                        await accountMicroService.GetNameByIds(entity.Creator, (creatorName) =>
                        {
                            logDto.CreatorName = creatorName;
                        });
                        logs.Add(logDto);
                    }
                }
                dto.OrderFlowLogs = logs;
                #endregion

                await accountMicroService.GetNameByIds(entity.Creator, entity.Modifier, (creatorName, modifierName) =>
                {
                    dto.CreatorName  = creatorName;
                    dto.ModifierName = modifierName;
                });
                return(await Task.FromResult(dto));
            });

            return(await _GetByIdRequest(id, toDTO));
        }