AcsTaskAssignApp.cs 6.81 KB
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using WebRepository;

namespace WebApp
{
    /// <summary>
    /// 任务
    /// </summary>

    public partial class AcsTaskAssignApp
    {
        private IUnitWork _unitWork;

        public AcsTaskAssignApp(IUnitWork unitWork)
        {
            _unitWork = unitWork;
        }

        public TableData getStartZone()
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                var data = _unitWork.Find<AcsZone>(u => u.Isstart.Value).Select(u => new { u.Code, u.Name });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData getStartWs(string StartZone)
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                var data = _unitWork.Find<AcsWorkstation>(u => u.Zonename.Equals(StartZone)).Select(u => new { u.Code, u.Name });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData getEndZone(string StartZone)
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                if (string.IsNullOrEmpty(StartZone))
                {
                    var data = _unitWork.Find<AcsZone>(u => u.Isend.Value).Select(u => new { u.Name, u.Code });
                    tableData.data = data;
                    tableData.count = data.Count();
                }
                else
                {
                    List<string> zones = _unitWork.Find<AcsZoneRelevance>(u => u.Startzone.Equals(StartZone)).Select(u => u.Endzone).ToList();
                    var data = _unitWork.Find<AcsZone>(u => zones.Contains(u.Code)).Select(u => new { u.Code, u.Name });
                    tableData.data = data;
                    tableData.count = data.Count();
                }
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData getEndWs(string EndZone)
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                if (EndZone == "3楼暂存区" || EndZone == "3楼仓库")
                {
                    var data = _unitWork.Find<AcsWorkstation>(u => u.Zonename.Equals(EndZone)).Select(u => new { u.Code, u.Name });
                    tableData.data = data;
                    tableData.count = data.Count();
                }
                else
                {
                    var data = _unitWork.Find<AcsWorkstation>(u => u.Zonename.Equals(EndZone)).Select(u => new { u.Code, u.Name });
                    tableData.data = data;
                    tableData.count = data.Count();
                }
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData getZone()
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                var data = _unitWork.Find<AcsZone>(null).Select(u => new { u.Code, u.Name });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData getWs(string Zone)
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                var data = _unitWork.Find<AcsWorkstation>(u => u.Zonename.Equals(Zone)).Select(u => new { u.Code, u.Name });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData GetTaskType()
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                var data = _unitWork.Find<AcsTaskType>(null).Select(u => new { u.Code, u.Name, u.Remarks });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData GetStartStation(string tasktype)
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                List<string> zones = _unitWork.Find<AcsTaskFrom>(u => u.Taskcode.Equals(tasktype)).Select(u => u.Zonecode).ToList();
                var data = _unitWork.Find<AcsWorkstation>(u => zones.Contains(u.Zonename)).OrderBy("Zonename").ThenBy("Code").Select(u => new { u.Code, u.Name, u.Zonename });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }

        public TableData GetEndStation(string startzone)
        {
            TableData tableData = new TableData() { code = 200, msg = "", count = 0 };
            try
            {
                List<string> zones = _unitWork.Find<AcsZoneRelevance>(u => u.Startzone.Equals(startzone)).Select(u => u.Endzone).ToList();
                var data = _unitWork.Find<AcsWorkstation>(u => zones.Contains(u.Zonename)).OrderBy("Zonename").ThenBy("Code").Select(u => new { u.Code, u.Name, u.Zonename });
                tableData.data = data;
                tableData.count = data.Count();
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }
            return tableData;
        }
    }
}