|  |  |  | 
|---|
|  |  |  | public class PalletCodeInfoService : ServiceBase<Dt_PalletCodeInfo, IPalletCodeInfoRepository>, IPalletCodeInfoService | 
|---|
|  |  |  | { | 
|---|
|  |  |  | private readonly IWarehouseRepository _warehouseRepository; | 
|---|
|  |  |  | public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal, IWarehouseRepository warehouseRepository) : base(BaseDal) | 
|---|
|  |  |  | private readonly IPalletTypeInfoRepository _palletTypeInfoRepository; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal, IWarehouseRepository warehouseRepository, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _warehouseRepository = warehouseRepository; | 
|---|
|  |  |  | _palletTypeInfoRepository = palletTypeInfoRepository; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | static object locker = new object(); | 
|---|
|  |  |  | public override WebResponseContent AddData(SaveModel saveModel) | 
|---|
|  |  |  | //public override WebResponseContent AddData(SaveModel saveModel) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    int warehouseId = 0; | 
|---|
|  |  |  | //    int count = 0; | 
|---|
|  |  |  | //    if (saveModel.MainData.TryGetValue("warehouseId", out object? warehouse) && warehouse != null) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        warehouseId = warehouse.ObjToInt(); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    if (saveModel.MainData.TryGetValue("count", out object? countValue) && countValue != null) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        count = countValue.ObjToInt(); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    lock (locker) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        List<Dt_PalletCodeInfo> palletCodeInfos = new List<Dt_PalletCodeInfo>(); | 
|---|
|  |  |  | //        int serialNo = 0; | 
|---|
|  |  |  | //        DateTime now = DateTime.Now; | 
|---|
|  |  |  | //        Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.WarehouseId == warehouseId, new Dictionary<string, OrderByType> { { nameof(Dt_PalletCodeInfo.SerialNo), OrderByType.Desc } }); | 
|---|
|  |  |  | //        if (palletCodeInfo != null && palletCodeInfo.CreateDate.Year == now.Year && palletCodeInfo.CreateDate.Month == now.Month && palletCodeInfo.CreateDate.Day == now.Day) | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            serialNo = palletCodeInfo.SerialNo + 1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        else | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            serialNo = 1; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        Dt_Warehouse _Warehouse = _warehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId); | 
|---|
|  |  |  | //        string uplen = ""; | 
|---|
|  |  |  | //        uplen = _Warehouse.WarehouseCode switch | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            "HA57" => "B", | 
|---|
|  |  |  | //            "HA58" => "P", | 
|---|
|  |  |  | //            "HA152" => "G", | 
|---|
|  |  |  | //            "HA64" => "S", | 
|---|
|  |  |  | //            "é»çä»" => "Z", | 
|---|
|  |  |  | //            "HA153" => "Y", | 
|---|
|  |  |  | //            "HA71" => "C", | 
|---|
|  |  |  | //            "HA60" => "F", | 
|---|
|  |  |  | //            _ => "N" | 
|---|
|  |  |  | //        }; | 
|---|
|  |  |  | //        for (int i = 0; i < count; i++) | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //            palletCodeInfos.Add(new Dt_PalletCodeInfo | 
|---|
|  |  |  | //            { | 
|---|
|  |  |  | //                SerialNo = serialNo, | 
|---|
|  |  |  | //                PalletCode = uplen + now.ToString("yyyyMMdd") + serialNo.ToString().PadLeft(3, '0'), | 
|---|
|  |  |  | //                PalletType = 1, | 
|---|
|  |  |  | //                PalletTypeId = 0, | 
|---|
|  |  |  | //                WarehouseId = warehouseId, | 
|---|
|  |  |  | //                Status = 0, | 
|---|
|  |  |  | //                Size = 0 | 
|---|
|  |  |  | //            }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //            serialNo = serialNo + 1; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return base.AddData(palletCodeInfos); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public WebResponseContent AddData(int warehouseId, int count, int palletTypeId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | int warehouseId = 0; | 
|---|
|  |  |  | int count = 0; | 
|---|
|  |  |  | if (saveModel.MainData.TryGetValue("warehouseId", out object? warehouse) && warehouse != null) | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | warehouseId = warehouse.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (saveModel.MainData.TryGetValue("count", out object? countValue) && countValue != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | count = countValue.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | lock (locker) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_PalletCodeInfo> palletCodeInfos = new List<Dt_PalletCodeInfo>(); | 
|---|
|  |  |  | int serialNo = 0; | 
|---|
|  |  |  | DateTime now = DateTime.Now; | 
|---|
|  |  |  | Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.WarehouseId == warehouseId, new Dictionary<string, OrderByType> { { nameof(Dt_PalletCodeInfo.SerialNo), OrderByType.Desc } }); | 
|---|
|  |  |  | if (palletCodeInfo != null && palletCodeInfo.CreateDate.Year == now.Year && palletCodeInfo.CreateDate.Month == now.Month && palletCodeInfo.CreateDate.Day == now.Day) | 
|---|
|  |  |  | Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.Id == palletTypeId && x.WarehouseId == warehouseId); | 
|---|
|  |  |  | if (palletTypeInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | serialNo = palletCodeInfo.SerialNo + 1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°æçç±»åé
置信æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | lock (locker) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | serialNo = 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Warehouse _Warehouse = _warehouseRepository.QueryFirst(x=>x.WarehouseId== warehouseId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string uplen = _Warehouse.WarehouseCode switch | 
|---|
|  |  |  | { | 
|---|
|  |  |  | "HA57" => "B", | 
|---|
|  |  |  | "HA58" => "P", | 
|---|
|  |  |  | "HA152" => "G", | 
|---|
|  |  |  | "HA64" => "S", | 
|---|
|  |  |  | "é»çä»" => "Z", | 
|---|
|  |  |  | "HA153" => "Y", | 
|---|
|  |  |  | "HA71" => "C", | 
|---|
|  |  |  | "HA60" => "F", | 
|---|
|  |  |  | _ => "N" | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | for (int i = 0; i < count; i++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | palletCodeInfos.Add(new Dt_PalletCodeInfo | 
|---|
|  |  |  | List<Dt_PalletCodeInfo> palletCodeInfos = new List<Dt_PalletCodeInfo>(); | 
|---|
|  |  |  | int serialNo = 0; | 
|---|
|  |  |  | DateTime now = DateTime.Now; | 
|---|
|  |  |  | Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.WarehouseId == warehouseId && x.PalletTypeId==palletTypeId && x.CreateDate.Year == now.Year && x.CreateDate.Month == now.Month && x.CreateDate.Day == now.Day, new Dictionary<string, OrderByType> { { nameof(Dt_PalletCodeInfo.SerialNo), OrderByType.Desc } }); | 
|---|
|  |  |  | if (palletCodeInfo != null && palletCodeInfo.CreateDate.Year == now.Year && palletCodeInfo.CreateDate.Month == now.Month && palletCodeInfo.CreateDate.Day == now.Day) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SerialNo = serialNo, | 
|---|
|  |  |  | PalletCode = uplen+now.ToString("yyyyMMdd") + serialNo.ToString().PadLeft(3, '0'), | 
|---|
|  |  |  | PalletType = 1, | 
|---|
|  |  |  | PalletTypeId = 0, | 
|---|
|  |  |  | WarehouseId = warehouseId, | 
|---|
|  |  |  | Status = 0, | 
|---|
|  |  |  | Size = 0 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | serialNo = palletCodeInfo.SerialNo + 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | serialNo = 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | serialNo = serialNo + 1; | 
|---|
|  |  |  | for (int i = 0; i < count; i++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | palletCodeInfos.Add(new Dt_PalletCodeInfo | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SerialNo = serialNo, | 
|---|
|  |  |  | PalletCode = palletTypeInfo.CodeStartStr + now.ToString("yyyyMMdd") + serialNo.ToString().PadLeft(3, '0'), | 
|---|
|  |  |  | PalletType = 1, | 
|---|
|  |  |  | PalletTypeId = palletTypeId, | 
|---|
|  |  |  | WarehouseId = warehouseId, | 
|---|
|  |  |  | Status = 0, | 
|---|
|  |  |  | Size = 0 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | serialNo = serialNo + 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BaseDal.AddData(palletCodeInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return base.AddData(palletCodeInfos); | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public WebResponseContent PrintStatusUp(string printCode) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x=>x.PalletCode==printCode); | 
|---|
|  |  |  | if (palletCodeInfo==null) | 
|---|
|  |  |  | Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.PalletCode == printCode); | 
|---|
|  |  |  | if (palletCodeInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error("æå°çæçç ä¸åå¨"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content.Error("é误:"+ex.Message); | 
|---|
|  |  |  | content.Error("é误:" + ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|