Exemplo n.º 1
0
        public async Task <ApiData> TakeOffline(int id, [FromBody] TakeOfflineArgs args)
        {
            Laneway laneway = await _session.GetAsync <Laneway>(id);

            if (laneway == null)
            {
                throw new InvalidOperationException("巷道不存在。");
            }

            if (laneway.Offline == true)
            {
                throw new InvalidOperationException($"巷道已处于脱机状态。【{laneway.LanewayCode}】");
            }

            laneway.Offline         = true;
            laneway.TakeOfflineTime = DateTime.Now;
            laneway.OfflineComment  = args.Comment;
            await _session.UpdateAsync(laneway);

            _ = await _opHelper.SaveOpAsync($"巷道【{laneway.LanewayCode}】,备注【{args.Comment}】");

            _logger.Information("已将巷道 {lanewayCode} 脱机", laneway.LanewayCode);

            return(this.Success());
        }
Exemplo n.º 2
0
        public async Task <ApiData> SimulateRequest(RequestInfo requestInfo)
        {
            _logger.Information("正在模拟请求 {requestInfo}", requestInfo);
            await _eventBus.FireEventAsync(EventTypes.PreRequest, requestInfo);

            await _eventBus.FireEventAsync(EventTypes.Request, requestInfo);

            var op = await _opHelper.SaveOpAsync("{0}", requestInfo);

            _logger.Information("模拟请求成功");
            return(this.Success());
        }
Exemplo n.º 3
0
        public async Task <ApiData> ChangeUnitloadLocation(string palletCode, ChangeLocationArgs args)
        {
            Unitload unitload = await _session.Query <Unitload>().Where(x => x.PalletCode == palletCode).SingleOrDefaultAsync();

            if (unitload == null)
            {
                throw new InvalidOperationException("托盘号不存在。");
            }

            Location dest = await _session.Query <Location>().Where(x => x.LocationCode == args.DestinationLocationCode).SingleOrDefaultAsync();

            if (dest == null)
            {
                throw new Exception("货位号不存在。");
            }

            var originalLocationCode = unitload.CurrentLocation?.LocationCode;

            if (originalLocationCode == null)
            {
                originalLocationCode = Cst.None;
            }

            var archived = await _taskHelper.ChangeUnitloadsLocationAsync(unitload, dest, args.Comment + string.Format("user: {0}", this.User?.Identity?.Name ?? "-"));

            _ = await _opHelper.SaveOpAsync("任务号 {0}", archived.TaskCode);

            _logger.Information("已将托盘 {palletCode} 的位置从 {originalLocationCode} 改为 {destinationLocationCode}", palletCode, originalLocationCode, args.DestinationLocationCode);

            return(this.Success());
        }
Exemplo n.º 4
0
        public async Task <ApiData> CreateOutboundOrder(CreateOutboundOrderArgs args)
        {
            OutboundOrder outboundOrder = new OutboundOrder();

            string prefix = $"OBO{DateTime.Now:yyMMdd}";
            int    next   = await _appSeqService.GetNextAsync(prefix);

            outboundOrder.OutboundOrderCode = $"{prefix}{next:00000}";
            outboundOrder.BizType           = args.BizType;
            outboundOrder.BizOrder          = args.BizOrder;
            outboundOrder.Comment           = args.Comment;

            if (args.Lines == null || args.Lines.Count == 0)
            {
                throw new InvalidOperationException("出库单应至少有一个出库行。");
            }

            foreach (var lineInfo in args.Lines)
            {
                OutboundLine line     = new OutboundLine();
                var          material = await _session.Query <Material>()
                                        .Where(x => x.MaterialCode == lineInfo.MaterialCode)
                                        .SingleOrDefaultAsync();

                if (material == null)
                {
                    throw new InvalidOperationException($"未找到编码为 {lineInfo.MaterialCode} 的物料。");
                }
                line.Material          = material;
                line.QuantityRequired  = lineInfo.QuantityRequired;
                line.QuantityDelivered = 0;
                line.Batch             = lineInfo.Batch;
                line.StockStatus       = lineInfo.StockStatus;
                line.Uom = lineInfo.Uom;

                outboundOrder.AddLine(line);
                _logger.Information("已添加出库单明细,物料 {materialCode},批号 {batch},需求数量 {quantity}", line.Material.MaterialCode, line.Batch, line.QuantityRequired);
            }

            await _session.SaveAsync(outboundOrder);

            _logger.Information("已创建出库单 {outboundOrder}", outboundOrder);
            _ = await _opHelper.SaveOpAsync(outboundOrder.OutboundOrderCode);

            return(this.Success());
        }
Exemplo n.º 5
0
        public async Task <ApiData> UpdateAppSetting([Required] string?settingName, SetAppSettingArgs args)
        {
            settingName = settingName?.Trim();
            if (string.IsNullOrEmpty(settingName))
            {
                throw new InvalidOperationException("参数名不能为空。");
            }
            var setting = await _appSettingService.GetAsync(settingName);

            if (setting == null)
            {
                throw new InvalidOperationException("参数不存在");
            }

            var prevValue = setting.SettingValue;

            switch (setting.SettingType)
            {
            case AppSettingTypes.字符串:
                await _appSettingService.SetStringAsync(settingName, args.SettingValue);

                break;

            case AppSettingTypes.布尔:
                await _appSettingService.SetBooleanAsync(settingName, Convert.ToBoolean(args.SettingValue));

                break;

            case AppSettingTypes.数字:
                await _appSettingService.SetNumberAsync(settingName, Convert.ToDecimal(args.SettingValue));

                break;

            default:
                break;
            }

            _logger.Information("将参数 {settingName} 的值由 {prevValue} 改为 {value}", settingName, prevValue, args.SettingValue);
            await _opHelper.SaveOpAsync($"参数名 {settingName},前值 {prevValue},新值 {args.SettingValue}", settingName, prevValue, args.SettingValue);

            return(this.Success());
        }
Exemplo n.º 6
0
        public async Task <ApiData> ImportMaterials(IFormFile file)
        {
            string[] arr = new[] { ".xlsx", ".xls" };
            if (arr.Contains(Path.GetExtension(file.FileName)?.ToLower()) == false)
            {
                throw new InvalidOperationException("无效的文件扩展名。");
            }


            string filename = await WriteFileAsync(file);

            DataTable dt = ExcelUtil.ReadDataSet(filename).Tables[0];

            int imported = 0;
            int covered  = 0;
            int empty    = 0;

            foreach (DataRow row in dt.Rows)
            {
                string?mcode = Convert.ToString(row["编码"]);
                if (string.IsNullOrWhiteSpace(mcode))
                {
                    // 忽略空行
                    empty++;
                    continue;
                }
                Material material = await _session.Query <Material>().Where(x => x.MaterialCode == mcode).SingleOrDefaultAsync();

                if (material != null)
                {
                    covered++;
                    _logger.Warning("将覆盖已存在的物料 {material}", material.MaterialCode);
                }
                else
                {
                    material = _materialFactory.CreateMaterial();
                    material.MaterialCode = Convert.ToString(row["编码"]);
                }

                material.Description     = Convert.ToString(row["描述"]);
                material.BatchEnabled    = Convert.ToBoolean(row["批次管理"]);
                material.StandingTime    = 24;
                material.ValidDays       = Convert.ToInt32(row["有效天数"]);
                material.MaterialType    = Convert.ToString(row["物料类型"]);
                material.Uom             = Convert.ToString(row["计量单位"])?.ToUpper();
                material.DefaultQuantity = Convert.ToDecimal(row["每托数量"]);
                material.Specification   = Convert.ToString(row["规格型号"]);
                string pinyin = GetPinyin(material.Description);
                if (pinyin.Length > 20)
                {
                    pinyin = pinyin.Substring(0, 20);
                }
                material.MnemonicCode = pinyin;

                await _session.SaveOrUpdateAsync(material);

                _logger.Information("已导入物料 {material}", material.MaterialCode);
                imported++;
            }

            _ = await _opHelper.SaveOpAsync($"导入 {imported},覆盖 {covered}");

            return(this.Success($"导入 {imported},覆盖 {covered}"));