zhaowc
2024-09-06 1b108e8d7335d5a5a59dfcf2f4eeef034a53b9b8
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Model.ModelDto.SysDto;
using Model.ModelVm;
using WMS.Entity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using SqlSugar;
using Model.ModelVm.SysVm;
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments;
using Utility.Tools;
using WMS.IBLL.ILogServer;
using WMS.Entity.LogEntity;
using System.Security.Cryptography;
using System.Data;
using Model.ModelDto.LogDto;
using Utility;
using Model.ModelVm.LogVm;
using System.Diagnostics;
 
namespace Wms.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    [ServiceFilter(typeof(ApiResponseActionFilter))]
    public class BasisController : ControllerBase
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        private readonly ICustomerServer _customerSvc;//客户Svc
        private readonly ILogisticsInfoServer _logisticsSvc;//物流Svc
        private readonly IUnitServer _unitSvc;//单位Svc
        private readonly IPackagServer _packagSvc; // 包装
        private readonly IMaterialsServer _mate; // 包装
        private readonly IUserInforServer _userInforServer; //用户
        private readonly IRolesServer _rolesServer; //角色
        private readonly IRoleRightServer _roleRightServer; //角色权限
        private readonly IRBACServer _rBACServer; //RBAC
        private readonly IDepartmentServer _department; //部门
        private readonly IFunSettingServer _setting; //功能设定
        private readonly IInterfaceServer _interface;//接口管理
        private readonly IOperationSysServer _operation; //操作日志
        private readonly UserManager _userManager;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="customerSvc">客户</param>
        /// <param name="logisticsSvc">物流</param>
        /// <param name="userInforServer">用户</param>
        /// <param name="rolesServer">角色</param>
        /// <param name="roleRightServer">角色权限</param>
        /// <param name="rBACServer">RBAC</param>
        /// <param name="unitSvc">单位</param>
        /// <param name="mate">物料</param>
        /// <param name="department">部门</param>
        /// <param name="setting">功能设定</param>
        /// <param name="operation">操作日志</param>
        public BasisController(ICustomerServer customerSvc, ILogisticsInfoServer logisticsSvc, IUserInforServer userInforServer, 
            IRolesServer rolesServer, IRoleRightServer roleRightServer, IRBACServer rBACServer, IUnitServer unitSvc, 
            IPackagServer packagServer, IMaterialsServer mate, IDepartmentServer department, IFunSettingServer setting, 
            IInterfaceServer interfaceS, IOperationSysServer operation, UserManager userManager)
        {
            _customerSvc = customerSvc;//客户Svc
            _logisticsSvc = logisticsSvc;//物流Svc
            _userInforServer = userInforServer;//用户
            _rolesServer = rolesServer;//角色
            _roleRightServer = roleRightServer;//角色权限
            _rBACServer = rBACServer;//RBAC
            _unitSvc = unitSvc;//单位
            _packagSvc = packagServer;     // 包装
            _mate = mate; //物料
            _department = department;//部门
            _setting = setting; //功能设定
            _interface = interfaceS;//接口管理
            _operation = operation; //操作日志
            _userManager = userManager;
        }
        //基本信息管理
 
        #region 用户管理
 
        #region 用户管理
 
        /// <summary>
        /// 获取用户角色信息
        /// </summary>
        /// <param name="UserName">登录名称</param>
        /// <param name="DepartmentNo">部门号</param>
        /// <param name="RoleNo">角色号</param>
        /// <param name="Status">状态</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<UserInfoDto>> GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status)
        {
            return await _userInforServer.GetUserRoleList(UserName, DepartmentNo, RoleNo, Status);
        }
 
        /// <summary>
        /// 根据id获取用户信息列表
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysUserInfor> GetUserinfoListById(int id)
        {
            return await _userInforServer.GetUserInfoById(id);
        }
 
 
        /// <summary>
        /// 新增用户信息
        /// </summary>
        /// <param name="UserInfoDto">用户dto模型</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task InsertUserinfo(UserInfoDto UserInfoDto)
        {
            await _userInforServer.InsertUserInfo(UserInfoDto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "用户管理",
                FkNo = UserInfoDto.UserNo,
                TypeName = "添加",
                Msg = "添加用户信息 用户号:" + UserInfoDto.UserNo
            });
        }
 
 
        /// <summary>
        /// 删除\批删用户信息
        /// </summary>
        /// <param name="userids">用户id</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">异常</exception>
        [HttpGet]
        [UnitOfWork]
        public async Task DeleteUserInfo(int userids)
        {
            //获取用户信息
            SysUserInfor user = await _userInforServer.GetUserInfoById(userids);
            await _userInforServer.DeleteUserinfo(user);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "用户管理",
                FkNo = user.UserNo,
                TypeName = "删除",
                Msg = "删除用户信息 用户号:" + user.UserNo
            });
        }
 
 
        /// <summary>
        /// 编辑用户信息
        /// </summary>
        /// <param name="userdto">用户dto模型</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task UpdateUserinfo(UserInfoDto userdto)
        {
            await _userInforServer.UpdateUserinfo(userdto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "用户管理",
                FkNo = userdto.UserNo,
                TypeName = "编辑",
                Msg = "修改用户信息 用户号:" + userdto.UserNo
            });
        }
 
 
        #endregion
 
        #region 修改密码
 
        ///// <param name="userId">用户id</param>
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="pwdOld">原密码</param>
        /// <param name="pwdNew">新密码</param>
        /// <param name="pwdNewTwo">确认密码</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpGet]
        public async Task UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo/*, int userId*/)
        {
            pwdOld = Md5Tools.CalcMd5(pwdOld);
            pwdNew = Md5Tools.CalcMd5(pwdNew);
            //pwdNewTwo = Md5Tools.CalcMd5(pwdNewTwo);
            //获取当前操作用户id
            SysUserInfor user = await _userInforServer.GetUserInfoById(_userManager.UserId);
            if (user == null)
                throw Oops.Bah("找不到用户信息");
            if (user.PassWord != pwdOld)
                throw Oops.Bah("原密码不正确");
            //修改密码
            int i = await _userInforServer.UptUserPassWord(pwdNew, pwdNewTwo, _userManager.UserId);
            if (i <= 0)
                throw Oops.Bah("修改密码失败");
        }
        /// <summary>
        /// x天后提醒用户修改密码
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> IsPassWordTime()
        {
            return await _userInforServer.IsPassWordTime(_userManager.UserId);
        }
        #endregion
 
        #endregion
 
        #region 角色管理
 
        /// <summary>
        /// 查询角色信息列表
        /// </summary>
        /// <param name="RoleNo">角色号</param>
        /// <param name="RoleName">角色名称</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<RoleDto>> GetRolesList(string RoleNo, string RoleName)
        {
            return await _rolesServer.GetRoleList(RoleNo, RoleName);
        }
 
        /// <summary>
        /// 根据id获取角色信息列表
        /// </summary>
        /// <param name="roleid">角色id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysRoles> GetRolesListById(int roleid)
        {
            return await _rolesServer.GetRoleInfoById(roleid);
        }
 
        /// <summary>
        /// 新增角色信息
        /// </summary>
        /// <param name="roledto">角色dto</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task InsertRoleInfo(RoleDto roledto)
        {
            await _rolesServer.InsertRoleInfo(roledto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "角色权限",
                FkNo = roledto.RoleNo,
                TypeName = "添加",
                Msg = "添加角色信息 角色号:" + roledto.RoleNo
            });
        }
 
        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="roleids">角色id</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        [HttpGet]
        [UnitOfWork]
        public async Task DeleteRoleInfo(int roleids)
        {
            //根据角色id获取角色信息
            SysRoles role = await _rolesServer.GetRoleInfoById(roleids);
            await _rolesServer.DeleteRoleInfo(role);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "角色权限",
                FkNo = role.RoleNo,
                TypeName = "删除",
                Msg = "删除角色信息 角色号:" + role.RoleNo
            });
        }
 
        /// <summary>
        /// 编辑角色信息
        /// </summary>
        /// <param name="role">角色实体模型</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task UpdateRolesInfo(SysRoles role)
        {
            await _rolesServer.UpdateRoleInfo(role);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "角色权限",
                FkNo = role.RoleNo,
                TypeName = "编辑",
                Msg = "修改角色信息 角色号:" + role.RoleNo
            });
        }
 
        #endregion
 
        #region 角色权限管理
 
        /// <summary>
        /// 根据角色id获取当前所拥有权限
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<FunctionMenuDto>> GetRBACLists(int id)
        {
            return await _rBACServer.GetMenuByroleIdNew(id);
        }
 
 
        /// <summary>
        /// 根据角色id获取当前所拥有权限
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<FunctionMenuDto>> GetRoleRightRBAC(int id, string MenuNo)
        {
            return await _rBACServer.GetRoleRightRBAC(MenuNo, _userManager.UserId.ToString());
        }
 
        /// <summary>
        /// 根据角色id获取当前所拥有权限
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<RoleRightDto>> GetRoleRightLists(int id)
        {
            return await _rBACServer.GetRoleRightList(id);
        }
 
        /// <summary>
        /// 获取角色权限信息列表
        /// 多表:角色权限、角色、菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<RoleRightDto>> GetRoleRightList()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            var model =  await _roleRightServer.GetRoleMenuList();
            stopwatch.Stop();
 
            var time = stopwatch.ElapsedMilliseconds;
            return model;
        }
 
        /// <summary>
        /// 获取角色权限信息列表(单表)
        /// </summary>
        /// <param name="id">角色权限id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysRoleRight>> GetRoleRightOneListById(int id)
        {
            return await _roleRightServer.GetRoleRightOneListById(id);
        }
 
        /// <summary>
        /// 分配角色权限信息
        /// </summary>
        /// <param name="MenuNo">菜单号</param>
        /// <param name="id">角色id</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task InsertRoleRight(string MenuNo, int id)
        {
            //根据Id获取角色号
            SysRoles roles = await _rolesServer.GetRoleInfoById(id);
            //保存角色权限信息
            await _roleRightServer.InsertRoleRight(MenuNo, roles.RoleNo);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "角色权限",
                FkNo = roles.RoleNo,
                TypeName = "编辑",
                Msg = "分配角色权限 角色号:" + roles.RoleNo
            });
        }
 
        #endregion
 
        #region 部门管理
 
        /// <summary>
        /// 获取部门信息列表
        /// </summary>
        /// <param name="DepartmentName">部门名称</param>
        /// <param name="DepartmentNo">部门号</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<DepartmentDto>> GetDepartmentList(string DepartmentName, string DepartmentNo)
        {
            return await _department.GetDepartmentList(DepartmentName, DepartmentNo);
        }
 
        /// <summary>
        /// 根据id获取部门信息
        /// </summary>
        /// <param name="id">部门id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysDepartment> GetDepartmentById(int id)
        {
            return await _department.GetDepartmentById(id);
        }
 
        /// <summary>
        /// 新增部门信息
        /// </summary>
        /// <param name="departmentdto">部门dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task AddDepartment(DepartmentDto departmentdto)
        {
            await _department.AddDepartment(departmentdto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "基础信息",
                MenuName = "部门管理",
                FkNo = departmentdto.DepartmentNo,
                TypeName = "添加",
                Msg = "添加部门信息 部门号:" + departmentdto.DepartmentNo
            });
        }
 
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="Id">部门id</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpGet]
        [UnitOfWork]
        public async Task DelDepartment(int Id)
        {
            SysDepartment department = await _department.GetDepartmentById(Id);
            await _department.DelDepartment(department);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "基础信息",
                MenuName = "部门管理",
                FkNo = department.DepartmentNo,
                TypeName = "删除",
                Msg = "删除部门信息 部门号:" + department.DepartmentNo
            });
        }
 
        /// <summary>
        /// 编辑部门信息
        /// </summary>
        /// <param name="departmentdto">部门dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task ExitDepartment(DepartmentDto departmentdto)
        {
            await _department.ExitDepartment(departmentdto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "基础信息",
                MenuName = "部门管理",
                FkNo = departmentdto.DepartmentNo,
                TypeName = "编辑",
                Msg = "编辑部门信息 部门号:" + departmentdto.DepartmentNo
            });
        }
 
        #endregion
 
        #region 功能设定
 
        /// <summary>
        /// 获取功能设定信息列表
        /// </summary>
        /// <param name="FunSetName">功能名称</param>
        /// <param name="IsEnable">开启状态</param>
        /// <param name="GroupNo">组号</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<FunSettingDto>> GetFunSettingList(string FunSetName, string IsEnable, string GroupNo)
        {
            return await _setting.GetFunSettingList(FunSetName, IsEnable, GroupNo);
        }
 
        /// <summary>
        /// 根据id查询功能设定信息
        /// </summary>
        /// <param name="id">功能id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysFunSetting> GetFunSettingById(int id)
        {
            return await _setting.GetFunSettingById(id);
        }
 
        /// <summary>
        /// 根据编号查询功能设定消息
        /// </summary>
        /// <param name="funSetNo">功能编号</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysFunSetting> GetFunSettingByNo(string funSetNo)
        {
            return await _setting.GetFunSettingByNo(funSetNo);
        }
        /// <summary>
        /// 新增功能信息
        /// </summary>
        /// <param name="settingdto">功能设定dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task AddFunSettings(FunSettingDto settingdto)
        {
            await _setting.AddFunSettings(settingdto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "功能设定",
                FkNo = settingdto.FunSetNo,
                TypeName = "添加",
                Msg = "添加功能设定 功能号:" + settingdto.FunSetNo
            });
        }
 
        /// <summary>
        /// 删除功能信息
        /// </summary>
        /// <param name="id">功能id</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpGet]
        [UnitOfWork]
        public async Task DelFunSettings(int id)
        {
            SysFunSetting funSetting = await _setting.GetFunSettingById(id);
            await _setting.DelFunSettings(funSetting);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "功能设定",
                FkNo = funSetting.FunSetNo,
                TypeName = "删除",
                Msg = "删除功能设定 功能号:" + funSetting.FunSetNo
            });
        }
 
        /// <summary>
        /// 编辑功能信息
        /// </summary>
        /// <param name="settingdto">功能设定dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        [UnitOfWork]
        public async Task ExitFunSettings(FunSettingDto settingdto)
        {
            await _setting.ExitFunSettings(settingdto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "功能设定",
                FkNo = settingdto.FunSetNo,
                TypeName = "编辑",
                Msg = "修改功能设定 功能号:" + settingdto.FunSetNo
            });
        }
 
        #endregion
 
        #region 物料管理
 
        #region yyk
 
        #region wms
 
        /// <summary>
        /// 获取物料信息列表
        /// </summary>
        /// <param name="skuNo">物料编码</param>
        /// <param name="skuName">物料名称</param>
        /// <param name="auditStatusNo">审核状态</param>
        /// <param name="type">类型</param>
        /// <param name="isControlled">是否受控</param>
        /// <param name="isInspect">是否免检</param>
        /// <param name="environment">存储环境</param>
        /// <param name="categoryNo">类别编码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<MaterialsDto>> GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment, string categoryNo)
        {
            return await _mate.GetMateList(skuNo, skuName, auditStatusNo, type, isControlled, isInspect, environment, categoryNo);
        }
 
        /// <summary>
        /// 根据id查询物料信息
        /// </summary>
        /// <param name="id">物料id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysMaterials> GetMateById(int id)
        {
            return await _mate.GetMateById(id);
        }
 
        /// <summary>
        /// 新增物料信息
        /// </summary>
        /// <param name="matedto">物料dto</param>
        /// <returns></returns>
        [HttpPost]
        public async Task AddMate(MaterialsDto matedto)
        {
            await _mate.AddMate(matedto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "基础信息",
                MenuName = "物料管理",
                FkNo = matedto.SkuNo,
                TypeName = "添加",
                Msg = "添加物料信息 物料号:" + matedto.SkuNo
            });
        }
 
        /// <summary>
        /// 删除物料信息
        /// </summary>
        /// <param name="id">物料id</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpGet]
        public async Task DelMate(int id)
        {
            SysMaterials mate = await _mate.GetMateById(id);
            await _mate.DelMate(mate);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "基础信息",
                MenuName = "物料管理",
                FkNo = mate.SkuNo,
                TypeName = "删除",
                Msg = "删除物料信息 物料号:" + mate.SkuNo
            });
        }
 
        /// <summary>
        /// 编辑物料信息
        /// </summary>
        /// <param name="matedto">物料dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        public async Task ExitMate(MaterialsDto matedto)
        {
            await _mate.ExitMate(matedto);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "基础信息",
                MenuName = "物料管理",
                FkNo = matedto.SkuNo,
                TypeName = "编辑",
                Msg = "编辑物料信息 物料号:" + matedto.SkuNo
            });
        }
 
        #region 包装 单位
 
        /// <summary>
        /// 获取计量单位信息列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysUnit>> GetUnitList()
        {
            return await _mate.GetUnitList();
        }
 
        /// <summary>
        /// 获取包装信息列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysPackag>> GetPackagList()
        {
            return await _mate.GetPackagList();
        }
 
        #endregion
 
        #endregion
 
        #region erp
 
        /// <summary>
        /// 获取erp数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetERPList()
        {
            List<ERPTestDto> list = _mate.GetERPList();
            return Ok(new
            {
                data = list,
                msg = "成功",
                code = 0
            });
        }
 
        /// <summary>
        /// 根据id获取erp数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetERPListById(int id)
        {
            SysERPTest erp = _mate.GetERPListById(id);
            return Ok(new
            {
                data = erp,
                msg = "成功",
                code = 0
            });
        }
 
        /// <summary>
        /// 新增erp数据
        /// </summary>
        /// <param name="erpdto">erp测试dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        public async Task<IActionResult> AddERP(ERPTestDto erpdto)
        {
            //捕获异常
            try
            {
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                //创建人
                erpdto.CreateUser = uid;
                //新增
                int i = await _mate.AddERP(erpdto);
                //判断是否新增成功
                if (i == 0)
                {
                    return Ok(new
                    {
                        data = i,
                        code = 1,
                        msg = "失败"
                    });
                }
                else if (i == 3)
                {
                    return Ok(new
                    {
                        data = i,
                        code = 3,
                        msg = "物料号必须唯一"
                    });
                }
                else
                {
                    return Ok(new
                    {
                        data = i,
                        code = 0,
                        msg = "成功"
                    });
                }
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("新增erp异常", ex);
            }
        }
 
        /// <summary>
        /// 删除erp信息
        /// </summary>
        /// <param name="erpdto">erp测试dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        public async Task<int> DelERP(ERPTestDto erpdto)
        {
            //捕获异常
            try
            {
                //根据id获取数据
                SysERPTest erp = _mate.GetERPListById(erpdto.Id);
                // 获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                erp.UpdateUser = uid;
                //删除
                int i = await _mate.DelERP(erp);
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("删除erp异常", ex);
            }
        }
 
        /// <summary>
        /// 编辑erp数据
        /// </summary>
        /// <param name="erpdto">erp测试dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpPost]
        public async Task<IActionResult> EditERP(ERPTestDto erpdto)
        {
            //捕获异常
            try
            {
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                //创建人
                erpdto.UpdateUser = uid;
                //新增
                int i = await _mate.EditERP(erpdto);
                //判断是否编辑成功
                if (i == 0)
                {
                    return Ok(new
                    {
                        data = i,
                        code = 1,
                        msg = "失败"
                    });
                }
                else
                {
                    return Ok(new
                    {
                        data = i,
                        code = 0,
                        msg = "成功"
                    });
                }
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("编辑erp异常", ex);
            }
        }
 
        #endregion
 
        #endregion
 
 
        #endregion
 
        #region 客户管理
        /// <summary>
        /// 查询客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetCustomerList(GetCustomerVm model)
        {
            RefAsync<int> count = new RefAsync<int>();
            var bolls = await _customerSvc.GetCustomerList(model.CustomerNo, model.CustomerName, model.Type, model.LinkMan, model.Phone, model.Page, model.Limit, count);
            return new SqlSugarPagedList() { Items = bolls, Total = count };
        }
        /// <summary>
        /// 查询单条客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SysCustomer> GetCustomer(IdVm model)
        {
            return await _customerSvc.GetCustomer(model.Id);
        }
        /// <summary>
        /// 查询全部客户信息
        /// </summary> 
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysCustomer>> GetCustomerSelect()
        {
            return await _customerSvc.GetCustomerSelect();
        }
        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task AddCustomer(AddCustomerVm model)
        {
            await _customerSvc.AddCustomer(model.CustomerNo, model.CustomerName, model.Type, model.Address, model.LinkMan, model.Phone, model.BankAccount, model.CreditRating, model.Demo, _userManager.UserId);
            await _operation.InsertOperation("基础信息", "客户管理", model.CustomerNo, "添加", "添加客户信息 客户号:" + model.CustomerNo, _userManager.UserId);
        }
        /// <summary>
        /// 编辑客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task EditCustomer(EditCustomerVm model)
        {
            await _customerSvc.EditCustomer(model.Id, model.CustomerNo, model.CustomerName, model.Type, model.Address, model.LinkMan, model.Phone, model.BankAccount, model.CreditRating, model.Demo, _userManager.UserId);
            await _operation.InsertOperation("基础信息", "客户管理", model.CustomerNo, "编辑", "编辑客户信息 客户号:" + model.CustomerNo, _userManager.UserId);
        }
        /// <summary>
        /// 删除客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelCustomer(IdVm model)
        {
            SysCustomer customer = await _customerSvc.GetCustomer(model.Id);
            var bolls = await _customerSvc.DelCustomer(model.Id, _userManager.UserId);
            await _operation.InsertOperation("基础信息", "客户管理", customer.CustomerNo, "删除", "删除客户信息 客户号:" + customer.CustomerNo, _userManager.UserId);
        }
        /// <summary>
        /// 删除客户信息(多删除)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelsCustomer(IdVm model)
        {
            await _customerSvc.DelsCustomer(model.Ids, _userManager.UserId);
        }
        #endregion
 
        #region 物流信息管理
        /// <summary>
        /// 查询物流信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetLogisticsInfoList(GetLogisticsInfoVm model)
        {
            RefAsync<int> count = new RefAsync<int>();
            var list = await _logisticsSvc.GetLogisticsInfoList(model.CarrierName, model.LinkMan, model.Phone, model.LicensePlate, model.Type, model.Page, model.Limit, count);
            return new SqlSugarPagedList() { Items = list, Total = count };
        }
        /// <summary>
        /// 查询单条物流信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SysLogisticsInfo> GetLogisticsInfo(IdVm model)
        {
            return await _logisticsSvc.GetLogisticsInfo(model.Id);
        }
        /// <summary>
        /// 查询全部物流信息
        /// </summary> 
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysLogisticsInfo>> GetLogisticsInfoSelect()
        {
            return await _logisticsSvc.GetLogisticsInfoSelect();
        }
 
        /// <summary>
        /// 添加物流信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task AddLogisticsInfo(AddLogisticsInfoVm model)
        {
            await _logisticsSvc.AddLogisticsInfo(model, _userManager.UserId);
            await _operation.InsertOperation("基础信息", "物流管理", model.CarrierName, "添加", "添加物流信息 公司名称:" + model.CarrierName, _userManager.UserId);
        }
        /// <summary>
        /// 编辑物流信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task EditLogisticsInfo(EditLogisticsInfoVm model)
        {
            await _logisticsSvc.EditLogisticsInfo(model, _userManager.UserId);
            await _operation.InsertOperation("基础信息", "物流管理", model.CarrierName, "编辑", "编辑物流信息 公司名称:" + model.CarrierName, _userManager.UserId);
        }
        /// <summary>
        /// 删除物流信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelLogisticsInfo(IdVm model)
        {
            await _logisticsSvc.DelLogisticsInfo(model.Id, _userManager.UserId);
            SysLogisticsInfo logisit = await _logisticsSvc.GetLogisticsDelInfo(model.Id);
            await _operation.InsertOperation("基础信息", "物流管理", logisit.CarrierName, "删除", "删除物流信息 公司名称:" + logisit.CarrierName, _userManager.UserId);
        }
        /// <summary>
        /// 删除物流信息(多条信息)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelsLogisticsInfo(IdVm model)
        {
            await _logisticsSvc.DelsLogisticsInfo(model.Ids, _userManager.UserId);
        }
        #endregion
 
        #region 计量单位管理
 
        /// <summary>
        /// 查询计量单位信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetUnitList(GetUnitVm model)
        {
            RefAsync<int> count = new RefAsync<int>();
            var list = await _unitSvc.GetUnitList(model.UnitNo, model.UnitName, model.Page, model.Limit, count);
            return new SqlSugarPagedList() { Items = list, Total = count };
        }
        /// <summary>
        /// 查询单条单位信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SysUnit> GetUnit(IdVm model)
        {
            return await _unitSvc.GetUnit(model.Id);
        }
        /// <summary>
        /// 添加计量信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task AddUnit(AddEditUnitVm model)
        {
            if (ModelState.IsValid)
            {
                await _unitSvc.AddUnit(model.UnitName, model.Abbrev, _userManager.UserId);
            }
            else
            {
                throw Oops.Bah("数据格式错误");
            }
 
        }
        /// <summary>
        /// 编辑计量单位信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task EditUnit(AddEditUnitVm model)
        {
            if (ModelState.IsValid)
            {
                await _unitSvc.EditUnit(model.Id, model.UnitName, model.Abbrev, _userManager.UserId);
                SysUnit unit = await _unitSvc.GetUnit(model.Id);
                await _operation.InsertOperation("基础信息", "计量单位", unit.UnitNo, "编辑", "编辑计量单位 单位名称:" + unit.UnitNo, _userManager.UserId);
            }
            else
            {
                throw Oops.Bah("数据格式错误");
            }
 
        }
        /// <summary>
        /// 删除计量单位信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelUnit(IdVm model)
        {
            await _unitSvc.DelUnit(model.Id, _userManager.UserId);
        }
        /// <summary>
        /// 删除计量单位信息(多删除)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelsUnit(IdVm model)
        {
            var bolls = await _unitSvc.DelsUnit(model.Ids, _userManager.UserId);
        }
        #endregion
 
        #region 包装管理
 
        /// <summary>
        /// 查询包装信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetPackagList(GetPackagVm model)
        {
            RefAsync<int> count = new RefAsync<int>();
            var list = await _packagSvc.GetPackagList(model.PackagNo, model.PackagName, model.Level, model.Page, model.Limit, count);
            return new SqlSugarPagedList { Items = list, Total = count };
        }
 
        /// <summary>
        /// 根据id获取包装信息
        /// </summary>
        /// <param name="id">包装id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysPackag> GetPackagById(int id)
        {
            return await _packagSvc.GetPackagById(id);
        }
 
        /// <summary>
        /// 添加包装信息
        /// </summary>
        /// <param name="model">包装信息</param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task AddPackag(AddEditPackagVm model)
        {
            await _packagSvc.AddPackag(model);
            await _operation.InsertOperation("基础信息", "包装管理", model.PackagNo, "添加", "添加包装信息 包装编号:" + model.PackagNo, _userManager.UserId);
        }
 
        /// <summary>
        /// 编辑包装信息
        /// </summary>
        /// <param name="model">包装信息</param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task EditPackag(AddEditPackagVm model)
        {
            await _packagSvc.EditPackag(model);
            await _operation.InsertOperation("基础信息", "包装管理", model.PackagNo, "编辑", "编辑包装信息 包装编号:" + model.PackagNo, _userManager.UserId);
        }
 
        /// <summary>
        /// 逻辑删除包装信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelPackag(AddEditPackagVm model)
        {
            await _packagSvc.DelPackag(model.Id, _userManager.UserId);
            await _operation.InsertOperation("基础信息", "包装管理", model.PackagNo, "删除", "删除包装信息 包装编号:" + model.PackagNo, _userManager.UserId);
        }
        #endregion
 
        #region 系统操作日志
 
        /// <summary>
        /// 获取操作日志信息列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetSysOperationList(GetOperationVm model)
        {
            return await _operation.GetSysOperationList(model);
        }
 
        /// <summary>
        /// 获取类型菜单
        /// </summary>
        /// <param name="dicName">字典名称</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysDictionary>> GetDicTypeList(string dicName)
        {
            return await _operation.GetDicTypeList(dicName);
        }
 
        #endregion
 
        #region 接口管理
        /// <summary>
        /// 获取接口列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetInterfaceList(InterfaceVm model)
        {
            return await _interface.GetInterfaceList(model);
        }
 
        /// <summary>
        /// 获取接口明细列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SqlSugarPagedList> GetInterfaceDetailList(InterfaceDetailVm model)
        {
            return await _interface.GetInterfaceDetailList(model);
        }
 
        /// <summary>
        /// 添加接口信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task AddInterface(InterfaceVm model)
        {
            await _interface.AddInterface(model);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "接口管理",
                FkNo = model.InterfaceNo,
                TypeName = "添加",
                Msg = $"添加了接口编号为{model.InterfaceNo}的接口信息"
            });
        }
 
        /// <summary>
        /// 编辑接口信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task EditInterface(InterfaceVm model)
        {
            await _interface.EditInterface(model);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "接口管理",
                FkNo = model.InterfaceNo,
                TypeName = "编辑",
                Msg = $"编辑了接口编号为{model.InterfaceNo}的接口信息"
            });
        }
 
        /// <summary>
        /// 删除接口信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelInterface(InterfaceVm model)
        {
            await _interface.DelInterface(model);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "接口管理",
                FkNo = model.InterfaceNo,
                TypeName = "编辑",
                Msg = $"删除了接口编号为{model.InterfaceNo}的接口信息"
            });
        }
 
        /// <summary>
        /// 删除接口明细信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task DelInterfaceDetail(InterfaceDetailVm model)
        {
            await _interface.DelInterfaceDetail(model);
            await _operation.InsertOperation(new OperationInputVm()
            {
                ParentName = "系统设置",
                MenuName = "接口管理",
                FkNo = model.InterfaceNo,
                TypeName = "编辑",
                Msg = $"删除了接口编号为{model.InterfaceNo}的接口信息,本系统字段为{model.Field}的接口信息"
            });
        }
        #endregion
    }
}