PLC
yanjinhui
2025-04-24 461ccbda1d9d3fef42f250771c2fd30702755c16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_ISerialPortRepository;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class ArticleInfomServer : ServiceBase<Dt_ArticleInfom, IArticleInfomRepository>, IArticleInfomServer
    {
        private readonly IProcessRepository _processRepository;
        private readonly IPutakeRepository _ptakeRepository;
        public ArticleInfomServer(IArticleInfomRepository BaseDal, IProcessRepository processRepository, IPutakeRepository ptakeRepository) : base(BaseDal)
        {
            _processRepository = processRepository;
            _ptakeRepository = ptakeRepository;
        }
        public override PageGridData<Dt_ArticleInfom> GetPageData(PageDataOptions options)
        {
            OrderByParameters = new Dictionary<string, SqlSugar.OrderByType> {
                { nameof(Dt_ArticleInfom.ID),SqlSugar.OrderByType.Asc  },
            };
            return base.GetPageData(options);
        }
 
 
 
        //public WebResponseContent PutPossorArticl()
        //{
        //    try
        //    {
        //        var articl = BaseDal.QueryData();
        //        var process = _processRepository.QueryData();
        //        var putake = _ptakeRepository.QueryData();
 
        //        // 先获取基础查询结果
        //        var query = from a in articl
        //                    from p in process
        //                    from t in putake
        //                    where (a.ID == p.ArticleTowid || a.ID == p.ArticleOneid)
        //                      && (t.Pustatus == 0 || t.Pustatus == 2)
        //                    orderby p.CraftType
        //                    select new
        //                    {
        //                        t.Njtakeid,
        //                        t.Pustatus,
        //                        t.Grouptype,
        //                        a.ArticleName,
        //                        a.ArticleType
        //                    };
 
        //        // 按 ArticleType 和 Pustatus 组合去重
        //        var result = query
        //            .GroupBy(x => new { x.ArticleType, x.Pustatus }) // 按类型和状态分组
        //            .Select(g => g.First()) // 每组取第一条
        //            .OrderBy(x => x.Grouptype) // 可以保持原有排序
        //            .ToList();
        //        return new WebResponseContent { Status = true, Data = result };
        //    }
        //    catch (Exception ex)
        //    {
 
        //        return new WebResponseContent { Status = false, Message = "错误:" + ex.Message };
        //    }
 
        //}
        public WebResponseContent PutPossorArticl()
        {
            try
            {
                var articl = BaseDal.QueryData();
                var process = _processRepository.QueryData();
                var putake = _ptakeRepository.QueryData();
 
                // 先获取基础查询结果
                var query = (
                 from t in putake
                 join p in process on t.Grouptype equals p.CraftType
                 join a in articl on p.ArticleOneid equals a.ID
                 where t.Pustatus == 0 || t.Pustatus == 2
                 select new
                 {
                     t.Njtakeid,
                     t.Pustatus,
                     t.Grouptype,
                     a.ArticleName,
                     a.ArticleType
                 })
                 .Union(
                 from t in putake
                 join p in process on t.Grouptype equals p.CraftType
                 join a in articl on p.ArticleTowid equals a.ID
                 where t.Pustatus == 0 || t.Pustatus == 2
                 select new
                 {
                     t.Njtakeid,
                     t.Pustatus,
                     t.Grouptype,
                     a.ArticleName,
                     a.ArticleType
                 });
 
                var result = query
                    .GroupBy(x => new { x.ArticleType, x.Pustatus, x.Grouptype,x.Njtakeid }) // 根据套筒类型和任务状态,以及组别分组
                    .Select(g => g.First()) // 每组取第一条
                    .OrderBy(x => x.Grouptype)
                    .ToList();
 
                return new WebResponseContent { Status = true, Data = result };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = "错误:" + ex.Message };
            }
 
        }
    }
}