huangxiaoqiang
3 天以前 c3ed42924f19d383dd643814b754d60b392496d3
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Location/LocationInfoService.cs
@@ -3,7 +3,10 @@
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_DTO;
using WIDESEA_DTO.WMS;
using WIDESEA_IServices;
using WIDESEA_Model.Models;
namespace WIDESEA_StorageBasicService;
@@ -19,7 +22,9 @@
    private readonly IDt_WareAreaInfoRepository _wareAreaInfoRepository;
    private readonly IPointStackerRelationRepository _pointStackerRelationRepository;
    private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository;
    private readonly IDt_AreaInfoRepository _AreaInfoRepository;
    private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
    private readonly ISys_ConfigService _configService;
    private readonly IMapper _mapper;
    public LocationInfoService(ILocationInfoRepository BaseDal,
@@ -32,7 +37,9 @@
                                    ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository,
                                    IStockInfoDetailRepository stockInfoDetailRepository,
                                    IMapper mapper,
                                    IDt_TaskService taskService) : base(BaseDal)
                                    IDt_TaskService taskService,
                                    IDt_AreaInfoRepository AreaInfoRepository,
                                    ISys_ConfigService configService) : base(BaseDal)
    {
        _unitOfWorkManage = unitOfWorkManage;
        _taskRepository = taskRepository;
@@ -44,6 +51,8 @@
        _stockInfoDetailRepository = stockInfoDetailRepository;
        _mapper = mapper;
        _taskService = taskService;
        _AreaInfoRepository = AreaInfoRepository;
        _configService= configService;
    }
    /// <summary>
@@ -117,6 +126,94 @@
        return base.UpdateData(saveModel);
    }
    public WebResponseContent HandOutTask(int locationID)
    {
        LogFactory.GetLog("手动出库任务").InfoFormat(true, "手动出库任务", JsonConvert.SerializeObject(locationID), App.User.UserName);
        WebResponseContent content=new WebResponseContent();
        try
        {
            Dt_AreaInfo areaInfo = _AreaInfoRepository.QueryFirst(x => x.AreaCode == "CWSC1");
            DtLocationInfo location = BaseDal.QueryFirst(x => x.Id == locationID);
            DtStockInfo stock = _stockInfoRepository.QueryFirst(x => x.LocationId == location.Id && x.LocationCode == location.LocationCode);
            if (location.AreaId == areaInfo.AreaID)
            {
                Dt_Task task = new Dt_Task
                {
                    Grade = 1,
                    Roadway = location.RoadwayNo,
                    TargetAddress = "001-035-001",
                    Dispatchertime = DateTime.Now,
                    MaterialNo = "",
                    NextAddress = "001-035-001",
                    OrderNo = null,
                    PalletCode = stock == null ? "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000) : stock.PalletCode,
                    SourceAddress = location.LocationCode,
                    CurrentAddress = location.LocationCode,
                    TaskState = (int)TaskOutStatusEnum.OutNew,
                    TaskType = (int)TaskOutboundTypeEnum.InToOut,
                    TaskNum = _taskRepository.GetTaskNo().Result,
                    Creater = "System", // 修正拼写错误
                    CreateDate = DateTime.Now,
                    TaskId = 0,
                    ProductionLine = stock == null ? "" : stock.ProductionLine,
                    ProcessCode = stock == null ? "" : stock.ProcessCode,
                };
                var taskDTO = new WMSTaskDTO
                {
                    TaskNum = task.TaskNum.Value,
                    Grade = task.Grade.Value,
                    PalletCode = task.PalletCode,
                    RoadWay = task.Roadway,
                    SourceAddress = task.SourceAddress,
                    TargetAddress = task.TargetAddress,
                    TaskState = task.TaskState.Value,
                    Id = 0,
                    TaskType = task.TaskType,
                    ProductionLine = task.ProductionLine,
                };
                var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
                var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveByWMSTask)?.ConfigValue;
                if (ReceiveByWMSTask == null || ipAddress == null)
                {
                    throw new Exception("WMS IP 未配置");
                }
                var wmsIpAddrss = ipAddress + ReceiveByWMSTask;
                var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTO));   //http://localhost:9291/api/Task/ReceiveTask,
                if (respon != null)
                {
                    WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
                    if (respone.Status)
                    {
                        var taskId = _taskRepository.AddData(task);
                        location.LocationStatus = (int)LocationEnum.InStockDisable;
                        BaseDal.UpdateData(location);
                    }
                    else
                    {
                        throw new Exception("WCS处理失败:" + respone.Message);
                    }
                }
                else
                {
                    throw new Exception("WCS处理失败");
                }
                return content.OK("任务添加成功!");
            }
            else
            {
                return content.Error("不是常温货位,不允许出库!!");
            }
        }
        catch (Exception ex)
        {
            return content.Error(ex.Message);
        }
    }
    #region 初始化库位
    public async Task<WebResponseContent> initializeLocation(int locationID)
    {
@@ -132,7 +229,7 @@
            DtStockInfo stock = _stockInfoRepository.QueryFirst(x => x.LocationId == location.Id);
            if(stock == null)
            {
                location.LocationStatus= (int)LocationEnum.Lock;
                location.LocationStatus= (int)LocationEnum.Free;
                BaseDal.UpdateData(location);
            }
            else
@@ -144,11 +241,14 @@
                List<DtStockInfoDetail> detail = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id).ToList();
                if (detail != null && detail.Count() > 0)
                {
                    List<DtStockInfoDetail_Hty> details = detail.Adapt<List<DtStockInfoDetail_Hty>>();
                    await DeleteStockInfoDetailsAsync(detail);
                    AddStockInfoDetailHty(details);
                }
                await AddStockInfoHtyAsync(stockInfo_Hty);
                location.LocationStatus = (int)LocationEnum.Lock;
                location.LocationStatus = (int)LocationEnum.Free;
                BaseDal.UpdateData(location);
                _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, LastStatus, (int)StatusChangeTypeEnum.ManualOperation, 0);
@@ -179,7 +279,7 @@
    {
        string[] chineseNumbers = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
        var locationList = new List<DtLocationInfo>();
        for (int line = 3; line <= x; line++)
        for (int line = 1; line <= x; line++)
        {
            for (int column = 1; column <= y; column++)
            {
@@ -195,10 +295,10 @@
                        LocationType = locType,
                        Remark = "",
                        Depth = locType > 1 ? (((line - 1) % 4) + 1) == 2 || (((line - 1) % 4) + 1) == 3 ? 1 : 2 : 1,
                        RoadwayNo = locType > 1 ? $"JZSC{((line - 1) / 4) + 1}" : $"JZSC{((line - 1) / 2) + 1}",
                        RoadwayNo = locType > 1 ? $"CHSC{((line - 1) / 4) + 1}" : $"CHSC{((line - 1) / 2) + 1}",
                        LocationStatus = LocationEnum.Free.ObjToInt(),
                        AreaId = areaId,
                        Creater = "systeam",
                        Creater = "System",
                        EnalbeStatus = 2,
                    });
                }
@@ -397,7 +497,7 @@
    private async Task AddStockInfoHtyAsync(DtStockInfo_Hty dtStock)
    {
        var isStockAdd = await SqlSugarHelper.Db.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommandAsync();
        var isStockAdd = await SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommandAsync();
        if (!isStockAdd)
        {
            throw new Exception("库存历史信息添加失败");
@@ -413,6 +513,16 @@
            throw new Exception("库存详情信息更新失败");
        }
    }
    private void AddStockInfoDetailHty(List<DtStockInfoDetail_Hty> details)
    {
        var isStockAdd = SqlSugarHelper.DbWMS.Insertable(details).ExecuteCommand();
        if (isStockAdd==0)
        {
            throw new Exception("库存明细历史信息添加失败");
        }
    }
    #endregion
    #endregion 内部方法