移动系统liao
8 小时以前 757e9a10418043eb1a5c5e41975d3eb39db66a80
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using cylsg.Model.ECTEModel;
using ECTESTOA;
using EzCoreNet.Redis;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ProductOfflineGetSameCityTemplateResponse.Types.Template.Types;
 
namespace cylsg.Application.CyOS
{
    /// <summary>
    /// 川印通用信息获取
    /// </summary>
    [Authorize]
    [ApiDescriptionSettings("CYOA")]
    public class CYOSSettingController : IDynamicApiController
    {
 
        private readonly ISqlSugarClient _client;
        private readonly IOAServices _oAServices;
        private readonly IEzCoreNetRedisService _eZCoreNetRedisService;
 
        public CYOSSettingController(ISqlSugarClient client, IOAServices oAServices, IEzCoreNetRedisService netRedisService)
        {
            _client = client.AsTenant().GetConnection("ECTESTOADB");
            _oAServices = oAServices;
            _eZCoreNetRedisService = netRedisService;
        }
 
        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<OaDepartment>> GetDepartLstt()
        {
            return await _client.Queryable<OaDepartment>().Where(x => x.Status == "启用" && x.FirmId == _oAServices.firmId).Select(x => new OaDepartment
            {
                Name = x.Name,
                Keyid = x.Keyid,
                Remark = x.Remark,
            }).WithCache(60).ToListAsync();
        }
        /// <summary>
        /// 获取科目列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<List<OaSubjectSet>> getKeMuList()
        {
            return await _client.Queryable<OaSubjectSet>().Where(x => x.Status == true && x.FirmId == _oAServices.firmId && x.SubjectType == "贷").Select(x => new OaSubjectSet
            {
                SubjectName = x.SubjectName,
                Keyid = x.Keyid,
                Remark = x.Remark,
            }).WithCache(60).ToListAsync();
        }
        /// <summary>
        /// 获取流水号
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public string GetShowID()
        {
            return _eZCoreNetRedisService.GetYYYMMddAnd4sn();
        }
        /// <summary>
        /// 获取客户列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[AllowAnonymous]
        public async Task<object> GeCorporateClients()
        {
             return  await _client.Queryable<OA_CorporateClients>()
                .LeftJoin<OA_CustomerCommunications>((Co,Cu)=>Co.Keyid==Cu.Keyid)
                .Where((Co, Cu) => Co.Shifouwanjie != 1 && Co.FirmId == _oAServices.firmId).Select((Co, Cu) => new 
            {
                 Co.Keyid,
                    Co.CompanyName,
                  adder=Cu.Province+Cu.City+Cu.County+Cu.DetailedAddress,
                  Cu.CompanyPhone,
                  Cu.BusinessManagers,     
 
 
            }).MergeTable().OrderBy(Co => Co.CompanyName).WithCache(1800).ToListAsync();
        }
        /// <summary>
        /// 获取司机列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        
        public async Task<List<OaStaff>> Getdrivers()
        {
            return await _client.Queryable<OaStaff>().Includes(x=>x.Car).Where(x => x.Status == "在职" && x.FirmId == _oAServices.firmId && x.BF_IsDriver).Select(x => new OaStaff
            {
                Name = x.Name,
                MemberId = x.MemberId,
                Keyid = x.Keyid,
                Car=x.Car
 
            }).ToListAsync();
        }
 
 
        /// <summary>
        /// 获取车辆列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]       
        public async Task<List<OA_CarManage>> GetCarList()
        {
            var listdata= await _client.Queryable<OA_CarManage>().Includes(x => x.Staff).Where(x =>  x.MemberID == _oAServices.firmId ).Select(x=>new OA_CarManage
            {
                 Keyid = x.Keyid,
                 CarNumber = x.CarNumber,
                 Staff=x.Staff
            })
           .ToListAsync();
 
            foreach (var item in listdata)
            {
                if(item.Staff!=null)
                {
                    if (item.Staff.Status != "在职")
                    {
                        item.Mark = "该员工不属于在职状态,派车后可能无法完成后续流程";
                    }
                    if (item.Staff.BF_IsDriver )
                    {
                        item.Mark+= "该员工不是专职司机";
                    }
                    item.CarNumber = item.CarNumber + "(" + item.Staff.Name + ")";
                    item.Staff = null;
                }
                item.StaffID = 0;
               
                
            }
           
            return listdata;
        }
        /// <summary>
        /// 获取7天内司机列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<List<OaStaff>> GetDriversOfWithin7days()
        {
           
            var list = await _client.Queryable<OA_DeliverPlanPaiche>().Where(x =>( x.DeliverTime.Value.Date < DateTime.Now.AddDays(8).Date) && (x.DeliverTime.Value.Date >= DateTime.Now.Date)).Select(x => x.DriverId).ToListAsync();
            return await _client.Queryable<OaStaff>().Includes(x=>x.Car).Where(x=>list.Contains(x.Keyid)).Where(x => x.Status == "在职" && x.FirmId == _oAServices.firmId && x.BF_IsDriver).Select(x => new OaStaff
            {
                Name = x.Name,
                MemberId = x.MemberId,
                Keyid = x.Keyid,
                Car=x.Car
 
            })/*.WithCache(30)*/.ToListAsync(); //Includes(x => x.Car)加缓存会报错
            ////      return await _client.Queryable<OA_DeliverPlan>()
            ////.LeftJoin<OaStaff>((dp, os) => dp.DriverId == os.Keyid)
            ////.Where((dp, os) => SqlFunc.ToDate(dp.DeliverTime) < DateTime.Now.AddDays(8).Date
            ////    && SqlFunc.ToDate(dp.DeliverTime) >= DateTime.Now.Date
            ////    && os.Status == "在职"
            ////    && os.FirmId == _oAServices.firmId
            ////    )
            ////.GroupBy((dp, os) => dp.DriverId)
            ////.Select((dp, os) => new OaStaff
            ////{
            ////    Name = SqlFunc.AggregateMax(os.Name),
            ////    MemberId = SqlFunc.AggregateMax(os.MemberId),
            ////    Keyid = SqlFunc.AggregateMax(os.Keyid),
            ////})
            ////.WithCache(1800)
            ////.ToListAsync();
             }
 
        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<OaStaff>>GetStaffList()
        {
            return await _client.Queryable<OaStaff>().Where(x => x.Status == "在职" && x.FirmId == _oAServices.firmId && x.BF_IsDriver).Select(x => new OaStaff
            {
                Name = x.Name,
                MemberId = x.MemberId,
                Keyid = x.Keyid,
             
 
            }).WithCache(30).ToListAsync();
        }
 
        }
 
 
  
}