├── .gitignore ├── src ├── Controller │ ├── Auth │ │ ├── AuthController.cs │ │ └── DepartmentIpController.cs │ ├── DataImport │ │ └── DataImportController.cs │ ├── Version │ │ └── SystemVersionController.cs │ ├── Common │ │ ├── EmployeeImageController.cs │ │ ├── FunctionController.cs │ │ ├── SystemController.cs │ │ ├── MenuController.cs │ │ ├── DataImportEmployeesController.cs │ │ ├── RoleController.cs │ │ └── DepartmentController.cs │ ├── AutoRun │ │ └── TimerRecordController.cs │ ├── Area │ │ └── AreaController.cs │ └── Industries │ │ ├── IndustryCategoryController.cs │ │ └── IndustryController.cs ├── DAL │ ├── Area │ │ └── AreaDAL.cs │ ├── Common │ │ ├── RoleDAL.cs │ │ ├── MenuMainDAL.cs │ │ ├── FunctionDAL.cs │ │ ├── LoginHistoryDAL.cs │ │ ├── DepartmentIpDAL.cs │ │ ├── DataImport │ │ │ └── EmployeesImportDetailDAL.cs │ │ ├── DepartmentDAL.cs │ │ └── EmployeeDAL.cs │ ├── Industries │ │ ├── IndustryDAL.cs │ │ └── IndustryCategoryDAL.cs │ ├── AutoRun │ │ └── TimerRecordDAL.cs │ ├── DataImport │ │ ├── DataImportIndexDAL.cs │ │ └── DataImportDetailDAL.cs │ └── Version │ │ └── SystemVersionDAL.cs ├── Model │ ├── Common │ │ ├── Query │ │ │ ├── LoginHistoryQuery.cs │ │ │ ├── MenuQuery.cs │ │ │ ├── RoleQuery.cs │ │ │ ├── FunctionQuery.cs │ │ │ ├── DepartmentQuery.cs │ │ │ └── EmployeeQuery.cs │ │ ├── AuthSettingInfo.cs │ │ ├── ViewModel │ │ │ ├── LoginView.cs │ │ │ ├── SetPropertyView.cs │ │ │ ├── ParentDepartment.cs │ │ │ ├── EmployeeGroupByDepartment.cs │ │ │ ├── BaseEmployeeView.cs │ │ │ ├── RoleSimpleView.cs │ │ │ ├── FunctionView.cs │ │ │ ├── LogonPowerView.cs │ │ │ ├── FunctionModuleView.cs │ │ │ ├── MenuSubView.cs │ │ │ ├── FunctionGroupView.cs │ │ │ ├── UpdatePasswordView.cs │ │ │ ├── LoginHistoryView.cs │ │ │ ├── EmployeeSelectView.cs │ │ │ ├── MenuMainView.cs │ │ │ ├── RoleView.cs │ │ │ ├── DepartmentView.cs │ │ │ └── EmployeeView.cs │ │ ├── Enum │ │ │ ├── UserGender.cs │ │ │ ├── UserState.cs │ │ │ └── LoginVerifierType.cs │ │ ├── MenuType.cs │ │ ├── FunctionModuleConfig.cs │ │ ├── DepartmentIpInfo.cs │ │ ├── FunctionInfo.cs │ │ ├── MenuSubInfo.cs │ │ ├── FunctionModuleInfo.cs │ │ ├── LoginHistoryInfo.cs │ │ ├── FunctionGroupInfo.cs │ │ ├── RoleInfo.cs │ │ ├── MenuMainInfo.cs │ │ ├── DataImport │ │ │ └── EmployeesImportDetail.cs │ │ ├── DepartmentInfo.cs │ │ └── EmployeeInfo.cs │ ├── Area │ │ ├── AreaTree.cs │ │ ├── AreaType.cs │ │ ├── AreaQuery.cs │ │ ├── AreaView.cs │ │ ├── AreaInfo.cs │ │ └── AmapDistricts.cs │ ├── AutoRun │ │ ├── Query │ │ │ └── TimerRecordQuery.cs │ │ ├── TimerRecordInfo.cs │ │ └── View │ │ │ └── TimerRecordView.cs │ ├── Industries │ │ ├── IndustryCategoryQuery.cs │ │ ├── IndustryCategoryInfo.cs │ │ ├── IndustryQuery.cs │ │ ├── IndustryCategoryView.cs │ │ ├── IndustryInfo.cs │ │ └── IndustryView.cs │ ├── Version │ │ └── SystemVersion.cs │ ├── DataImport │ │ ├── ImportState.cs │ │ ├── Profile │ │ │ └── DataImportProfile.cs │ │ ├── DataImportDetailInfo.cs │ │ ├── DataImportDetailResult.cs │ │ ├── DataImportIndexInfo.cs │ │ └── DataImportIndexView.cs │ └── Profile │ │ └── SystemCommonModelProfile.cs ├── Services │ ├── Auth │ │ ├── LoginResult.cs │ │ ├── AuthServiceExt.cs │ │ ├── LoginView.cs │ │ ├── AuthServiceOption.cs │ │ ├── DepartmentIpService.cs │ │ ├── AuthVisitorService.cs │ │ └── AuthService.cs │ ├── Common │ │ ├── RoleServiceExt.cs │ │ ├── DepartmentServiceExt.cs │ │ ├── RoleServiceExtFun.cs │ │ ├── MenuServiceOption.cs │ │ ├── DataImport │ │ │ ├── FilePathServiceExt.cs │ │ │ └── ImportEmployeesService.cs │ │ ├── LoginHistoryService.cs │ │ └── RoleService.cs │ ├── CommonExt │ │ ├── TianChengCommonConfigureExt.cs │ │ └── TianChengCommonServicesExt.cs │ ├── Version │ │ └── SystemVersionService.cs │ ├── AutoRun │ │ └── TimerRecordService.cs │ └── Industries │ │ ├── IndustryCategoryService.cs │ │ └── IndustryService.cs └── TianCheng.SystemCommon.csproj ├── samples └── SamplesWebApi │ ├── SamplesWebApi.csproj │ ├── Properties │ ├── launchSettings.json │ └── PublishProfiles │ │ └── CustomProfile.pubxml │ ├── appsettings.json │ ├── Service │ ├── OnlineEmployeeService.cs │ ├── InitServiceExt.cs │ ├── DepartmentServiceTestExt.cs │ ├── DepartmentServiceOptionExt.cs │ ├── MenuServiceOptionExt.cs │ └── EmployeeServiceOptionExt.cs │ ├── Program.cs │ ├── appsettings.Development.json │ ├── Startup.cs │ └── Controllers │ └── ValuesController.cs ├── README.md └── TianCheng.SystemCommon.sln /.gitignore: -------------------------------------------------------------------------------- 1 | .git 2 | .vs 3 | .vscode 4 | [Bb]in/ 5 | [Oo]bj/ 6 | [Ll]ogs/ 7 | 8 | *.log 9 | *.user 10 | -------------------------------------------------------------------------------- /src/Controller/Auth/AuthController.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chengkkll/TianCheng.SystemCommon/HEAD/src/Controller/Auth/AuthController.cs -------------------------------------------------------------------------------- /src/DAL/Area/AreaDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 区域信息 [数据持久化] 8 | /// 9 | [DBMapping("system_area")] 10 | public class AreaDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Common/RoleDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 角色信息 [数据持久化] 8 | /// 9 | [DBMapping("system_role")] 10 | public class RoleDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Common/MenuMainDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 菜单信息 [数据持久化] 8 | /// 9 | [DBMapping("system_menu")] 10 | public class MenuMainDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Industries/IndustryDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 行业信息 数据持久化操作 8 | /// 9 | [DBMapping("system_industry")] 10 | public class IndustryDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/AutoRun/TimerRecordDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 定时运行记录 8 | /// 9 | [DBMapping("system_timer_record")] 10 | public class TimerRecordDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Common/FunctionDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 功能点信息 [数据持久化] 8 | /// 9 | [DBMapping("system_function")] 10 | public class FunctionDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Common/LoginHistoryDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 登录记录 [数据持久化] 8 | /// 9 | [DBMapping("System_RoleInfo")] 10 | public class LoginHistoryDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/DataImport/DataImportIndexDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 数据导入索引主表 8 | /// 9 | [DBMapping("import_index")] 10 | public class DataImportIndexDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Model/Common/Query/LoginHistoryQuery.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 登录历史查询条件 5 | /// 6 | public class LoginHistoryQuery : TianCheng.Model.QueryInfo 7 | { 8 | /// 9 | /// 查询关键字 10 | /// 11 | public string Key { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Common/DepartmentIpDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 部门可用IP范围 [数据持久化] 8 | /// 9 | [DBMapping("system_auth_department_ip")] 10 | public class DepartmentIpDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Model/Area/AreaTree.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 以树形结构显示区域信息 7 | /// 8 | public class AreaTree : AreaView 9 | { 10 | /// 11 | /// 下级行政机构 12 | /// 13 | public List Sub { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/DAL/DataImport/DataImportDetailDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 数据导入索引主表 8 | /// 9 | [DBMapping("import_detail")] 10 | public class DataImportDetailDAL : MongoOperation where T : DataImportDetailInfo 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DAL/Industries/IndustryCategoryDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 行业分类 数据持久化操作 8 | /// 9 | [DBMapping("system_industry_category")] 10 | public class IndustryCategoryDAL : MongoOperation 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Model/AutoRun/Query/TimerRecordQuery.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 按定时器查询 7 | /// 8 | public class TimerRecordQuery : QueryInfo 9 | { 10 | /// 11 | /// 按定时器名称模糊查询 12 | /// 13 | public string Name { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Model/Industries/IndustryCategoryQuery.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 行业分类查询 7 | /// 8 | public class IndustryCategoryQuery : QueryInfo 9 | { 10 | /// 11 | /// 按行业分类名称模糊查询 12 | /// 13 | public string Name { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Services/Auth/LoginResult.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Services 4 | { 5 | /// 6 | /// 登录返回结果 7 | /// 8 | public class LoginResult 9 | { 10 | /// 11 | /// Token 12 | /// 13 | [JsonProperty("token")] 14 | public string Token { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/DAL/Common/DataImport/EmployeesImportDetailDAL.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.DAL.MongoDB; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace TianCheng.SystemCommon.DAL 5 | { 6 | /// 7 | /// 数据导入索引主表 8 | /// 9 | [DBMapping("import_employees")] 10 | public class EmployeesImportDetailDAL : DataImportDetailDAL 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Model/Common/AuthSettingInfo.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 登录权限设置 7 | /// 8 | public class AuthSettingInfo : BusinessMongoModel 9 | { 10 | /// 11 | /// 登录时验证IP地址范围 12 | /// 13 | public string LoginVerifierIpAddress { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Model/Common/Query/MenuQuery.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 菜单的查询条件 7 | /// 8 | public class MenuQuery : TianCheng.Model.QueryInfo 9 | { 10 | /// 11 | /// 按名称模糊查询 12 | /// 13 | [JsonProperty("name")] 14 | public string Name { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Model/Common/Query/RoleQuery.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 角色的查询条件 7 | /// 8 | public class RoleQuery : TianCheng.Model.QueryInfo 9 | { 10 | /// 11 | /// 按名称模糊查询 12 | /// 13 | [JsonProperty("name")] 14 | public string Name { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Model/Common/Query/FunctionQuery.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 功能点的查询条件 7 | /// 8 | public class FunctionQuery : TianCheng.Model.QueryInfo 9 | { 10 | /// 11 | /// 按名称模糊查询 12 | /// 13 | [JsonProperty("name")] 14 | public string Name { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/LoginView.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 登录信息 5 | /// 6 | public class LoginView 7 | { 8 | /// 9 | /// 账号 10 | /// 11 | public string Account { get; set; } 12 | /// 13 | /// 密码 14 | /// 15 | public string Password { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Model/Common/Enum/UserGender.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 用户性别枚举 5 | /// 6 | public enum UserGender 7 | { 8 | /// 9 | /// 未定义 10 | /// 11 | None = 0, 12 | /// 13 | /// 男性 14 | /// 15 | Male = 1, 16 | /// 17 | /// 女性 18 | /// 19 | Female = 2 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Model/Common/Enum/UserState.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 用户状态 5 | /// 6 | public enum UserState 7 | { 8 | /// 9 | /// 正常可用状态 10 | /// 11 | Enable = 1, 12 | /// 13 | /// 登录锁住 14 | /// 15 | LogonLock = 3, 16 | /// 17 | /// 禁用 18 | /// 19 | Disable = 5 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Model/Common/MenuType.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 菜单类型 5 | /// 6 | public enum MenuType 7 | { 8 | /// 9 | /// 空值 10 | /// 11 | None = 0, 12 | /// 13 | /// 管理端多页面处理 14 | /// 15 | ManageMultiple = 1, 16 | /// 17 | /// 管理端单页面处理 18 | /// 19 | ManageSingle = 2, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Services/Auth/AuthServiceExt.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.BaseService; 2 | 3 | namespace TianCheng.SystemCommon.Services 4 | { 5 | /// 6 | /// 登录事件的扩展处理 7 | /// 8 | public class AuthServiceExt : IServiceExtOption 9 | { 10 | /// 11 | /// 设置扩展处理 12 | /// 13 | public void SetOption() 14 | { 15 | // 登录处理 16 | AuthService.OnLogin += LoginHistoryService.OnLogin; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Services/Common/RoleServiceExt.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.BaseService; 2 | 3 | namespace TianCheng.SystemCommon.Services 4 | { 5 | /// 6 | /// 角色的事件处理 7 | /// 8 | public class RoleServiceExt : IServiceExtOption 9 | { 10 | /// 11 | /// 设置扩展处理 12 | /// 13 | public void SetOption() 14 | { 15 | // 更新的后置处理 16 | RoleService.OnUpdated += EmployeeService.OnRoleUpdated; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Model/Common/Enum/LoginVerifierType.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 用户登录类型 5 | /// 6 | public enum LoginVerifierType 7 | { 8 | /// 9 | /// 无特殊验证 10 | /// 11 | None = 0, 12 | /// 13 | /// 验证IP地址区域 14 | /// 15 | IpAddress = 1, 16 | /// 17 | /// 短期不验证 18 | /// 19 | ShortRange = 2, 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Services/Common/DepartmentServiceExt.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.BaseService; 2 | 3 | namespace TianCheng.SystemCommon.Services 4 | { 5 | /// 6 | /// 部门服务扩展处理 7 | /// 8 | public class DepartmentServiceExt : IServiceExtOption 9 | { 10 | /// 11 | /// 设置扩展处理 12 | /// 13 | public void SetOption() 14 | { 15 | // 更新的后置处理 16 | DepartmentService.OnUpdated += EmployeeService.OnDepartmentUpdated; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Model/Common/FunctionModuleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 模块的配置信息,用于读取写在appsettings.json中的信息 7 | /// 8 | public class FunctionModuleConfig 9 | { 10 | /// 11 | /// 获取模块的命名空间及模块名称 12 | /// 13 | //public Dictionary ModuleDict { get; set; } = new Dictionary(); 14 | public List ModuleDict { get; set; } = new List(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/SetPropertyView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 按属性修改用户信息 7 | /// 8 | public class SetPropertyView 9 | { 10 | /// 11 | /// 属性名 12 | /// 13 | [JsonProperty("property")] 14 | public string PropertyName { get; set; } 15 | 16 | /// 17 | /// 属性值 18 | /// 19 | [JsonProperty("value")] 20 | public string PropertyValue { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Version/SystemVersion.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 系统的版本信息 7 | /// 8 | public class SystemVersion : BusinessMongoModel 9 | { 10 | /// 11 | /// 版本号 12 | /// 13 | public string Version { get; set; } 14 | /// 15 | /// 版本介绍 16 | /// 17 | public string Intro { get; set; } 18 | /// 19 | /// 是否为当前版本 20 | /// 21 | public bool IsCurrent { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/ParentDepartment.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 上级部门信息 7 | /// 8 | public class ParentDepartment 9 | { 10 | /// 11 | /// 上级部门ID 12 | /// 13 | public string Id { get; set; } 14 | /// 15 | /// 上级部门名称 16 | /// 17 | public string Name { get; set; } 18 | /// 19 | /// 本级与所有上级ID列表 20 | /// 21 | public List Ids { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Common/DepartmentIpInfo.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 部门的IP范围 7 | /// 8 | public class DepartmentIpInfo : BusinessMongoModel 9 | { 10 | /// 11 | /// 部门ID 12 | /// 13 | public string DepartmentId { get; set; } 14 | /// 15 | /// 部门名称 16 | /// 17 | public string DepartmentName { get; set; } 18 | /// 19 | /// 部门可用的IP 20 | /// 21 | public string IpRange { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Industries/IndustryCategoryInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 行业分类信息 7 | /// 8 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 9 | public class IndustryCategoryInfo : TianCheng.Model.BusinessMongoModel 10 | { 11 | /// 12 | /// 分类名称 13 | /// 14 | public string Name { get; set; } 15 | /// 16 | /// 分类中包含的行业信息 17 | /// 18 | public List Industries { get; set; } = new List(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Model/Industries/IndustryQuery.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 行业查询条件 9 | /// 10 | public class IndustryQuery : QueryInfo 11 | { 12 | /// 13 | /// 按编码、名称、说明模糊查询 14 | /// 15 | [JsonProperty("key")] 16 | public string Key { get; set; } 17 | 18 | /// 19 | /// 根据行业ID列表 20 | /// 21 | [JsonProperty("ids")] 22 | public List IndustryIdList { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Services/CommonExt/TianChengCommonConfigureExt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | 3 | namespace Microsoft.AspNetCore.Builder 4 | { 5 | /// 6 | /// 自动注册服务 7 | /// 8 | static public class TianChengBaseConfigureServices 9 | { 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | public static void TianChengCommonInit(this IApplicationBuilder app, IConfiguration configuration) 16 | { 17 | app.TianChengBaseServicesInit(configuration); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Model/Industries/IndustryCategoryView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 行业分类 查看对象 7 | /// 8 | public class IndustryCategoryView 9 | { 10 | /// 11 | /// 分类ID 12 | /// 13 | public string Id { get; set; } 14 | /// 15 | /// 分类名称 16 | /// 17 | public string Name { get; set; } 18 | /// 19 | /// 分类中包含的行业信息 20 | /// 21 | public List Industries { get; set; } = new List(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/DataImport/ImportState.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 导入状态 5 | /// 6 | public enum ImportState 7 | { 8 | /// 9 | /// 未定义 10 | /// 11 | None = 0, 12 | /// 13 | /// 已做数据转换 14 | /// 15 | Tran = 1, 16 | /// 17 | /// 检查数据 18 | /// 19 | Check = 2, 20 | /// 21 | /// 导入的数据有问题 22 | /// 23 | Fail = 4, 24 | /// 25 | /// 导入完成 26 | /// 27 | Complete = 8 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Services/Auth/LoginView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace TianCheng.SystemCommon.Services 5 | { 6 | /// 7 | /// 登录参数 8 | /// 9 | public class LoginView 10 | { 11 | /// 12 | /// 账号 13 | /// 14 | [JsonProperty("account")] 15 | [Required(ErrorMessage = "账号不能为空")] 16 | public string Account { get; set; } 17 | 18 | /// 19 | /// 密码 20 | /// 21 | [JsonProperty("password")] 22 | [Required(ErrorMessage = "密码不能为空")] 23 | public string Password { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/EmployeeGroupByDepartment.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 按部门分组的员工信息 8 | /// 9 | public class EmployeeGroupByDepartment 10 | { 11 | /// 12 | /// 部门ID 13 | /// 14 | public string Id { get; set; } 15 | /// 16 | /// 部门名称 17 | /// 18 | public string Name { get; set; } 19 | /// 20 | /// 员工列表 21 | /// 22 | public List Employees { get; set; } = new List(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/BaseEmployeeView.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 基础的员工信息 5 | /// 6 | public class BaseEmployeeView 7 | { 8 | /// 9 | /// Id 10 | /// 11 | public string Id { get; set; } 12 | /// 13 | /// 员工名称 14 | /// 15 | public string Name { get; set; } 16 | /// 17 | /// 所在部门名称 18 | /// 19 | public string DepartmentId { get; set; } 20 | /// 21 | /// 所在部门名称 22 | /// 23 | public string DepartmentName { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/RoleSimpleView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 简单的角色查看信息 7 | /// 8 | public class RoleSimpleView 9 | { 10 | /// 11 | /// ID 12 | /// 13 | [JsonProperty("id")] 14 | public string Id { get; set; } 15 | 16 | /// 17 | /// 显示的名称 18 | /// 19 | [JsonProperty("name")] 20 | public string Name { get; set; } 21 | /// 22 | /// 当前角色登录后的默认页面 23 | /// 24 | [JsonProperty("page")] 25 | public string DefaultPage { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Model/DataImport/Profile/DataImportProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 8 | /// 9 | public class DataImportProfile : Profile, IAutoProfile 10 | { 11 | /// 12 | /// 构造方法 13 | /// 14 | public DataImportProfile() 15 | { 16 | Register(); 17 | } 18 | 19 | /// 20 | /// 注册转换信息 21 | /// 22 | public void Register() 23 | { 24 | CreateMap(); 25 | CreateMap(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Model/Area/AreaType.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 区域类型 5 | /// 6 | public enum AreaType 7 | { 8 | /// 9 | /// 未定义 10 | /// 11 | None = 0, 12 | /// 13 | /// 国家 14 | /// 15 | Country = 1, 16 | /// 17 | /// 省 / 州 18 | /// 19 | Province = 2, 20 | /// 21 | /// 城市 22 | /// 23 | City = 4, 24 | /// 25 | /// 县 26 | /// 27 | District = 8, 28 | /// 29 | /// 街道 30 | /// 31 | Street = 16, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Model/Industries/IndustryInfo.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 行业信息 5 | /// 6 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 7 | public class IndustryInfo : TianCheng.Model.BusinessMongoModel 8 | { 9 | /// 10 | /// 编码 11 | /// 12 | public string Code { get; set; } 13 | /// 14 | /// 名称 15 | /// 16 | public string Name { get; set; } 17 | /// 18 | /// 行业说明 19 | /// 20 | public string Remarks { get; set; } 21 | /// 22 | /// 旧系统ID 23 | /// 24 | public int OldId { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/SamplesWebApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | SamplesWebApi 6 | 7 | 8 | 9 | bin\Debug\netcoreapp1.1\SamplesWebApi.xml 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:42717/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "SamplesWebApi": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "swagger", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:42718/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Services/CommonExt/TianChengCommonServicesExt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using TianCheng.SystemCommon.Model; 3 | 4 | namespace Microsoft.Extensions.DependencyInjection 5 | { 6 | /// 7 | /// 8 | /// 9 | static public class TianChengCommonServicesExt 10 | { 11 | /// 12 | /// 增加业务的Service 13 | /// 14 | /// 15 | /// 16 | public static void TianChengCommonInit(this IServiceCollection services, IConfiguration configuration) 17 | { 18 | services.TianChengBaseServicesInit(configuration); 19 | 20 | // 注册功能模块配置信息 21 | services.Configure(configuration.GetSection("FunctionModule")); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Model/AutoRun/TimerRecordInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 定时运行记录 8 | /// 9 | public class TimerRecordInfo : BusinessMongoModel 10 | { 11 | /// 12 | /// 定时器名称 13 | /// 14 | public string Name { get; set; } 15 | /// 16 | /// 备注 17 | /// 18 | public string Remark { get; set; } 19 | /// 20 | /// 运行时间 21 | /// 22 | public DateTime RunTime { get; set; } 23 | /// 24 | /// 运行结束时间 25 | /// 26 | public DateTime EndTime { get; set; } 27 | /// 28 | /// 耗时 秒 29 | /// 30 | public double TotalSeconds { get; set; } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/FunctionView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 功能点对象 查看对象 7 | /// 8 | public class FunctionView 9 | { 10 | /// 11 | /// 序号 12 | /// 13 | [JsonProperty("index")] 14 | public int Index { get; set; } 15 | ///// 16 | ///// 权限编码 17 | ///// 18 | //[JsonProperty("code")] 19 | //public string Code { get; set; } 20 | /// 21 | /// 功能点标识名 可以理解为唯一标识功能点的ID值 22 | /// 23 | [JsonProperty("policy")] 24 | public string Policy { get; set; } 25 | /// 26 | /// 权限名称 27 | /// 28 | [JsonProperty("name")] 29 | public string Name { get; set; } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AllowedHosts": "*", 3 | "SwaggerDoc": { 4 | "Version": "v1", 5 | "Title": "演示系统接口文档", 6 | "Description": "RESTful API for 演示", 7 | "TermsOfService": "https://github.com/chengkkll/TianCheng.BaseService", 8 | "ContactName": "cheng_kkll", 9 | "ContactEmail": "cheng_kkll@163.com", 10 | "ContactUrl": "", 11 | "EndpointUrl": "/swagger/v1/swagger.json", 12 | "EndpointDesc": "演示系统 API V1" 13 | }, 14 | "Token": { 15 | "Issuer": "TianCheng.WebApi.Demo", 16 | "Audience": "TianCheng", 17 | "SecretKey": "TianChengSecretKey", 18 | "Scheme": "Bearer" 19 | }, 20 | "FunctionModule": { 21 | "ModuleDict": [ 22 | { 23 | "Code": "TianCheng.SystemCommon", 24 | "Name": "系统管理" 25 | }, 26 | { 27 | "Code": "TianCheng.EmailSender", 28 | "Name": "系统管理" 29 | } 30 | ] 31 | } 32 | } -------------------------------------------------------------------------------- /samples/SamplesWebApi/Service/OnlineEmployeeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using TianCheng.BaseService; 6 | using TianCheng.SystemCommon.Model; 7 | 8 | namespace SamplesWebApi.Service 9 | { 10 | /// 11 | /// 在线用户控制 12 | /// 13 | public class OnlineEmployeeService 14 | { 15 | /// 16 | /// 17 | /// 18 | /// 19 | static public void OnLogin(EmployeeInfo employeeInfo) 20 | { 21 | // 处理登录用户信息 22 | 23 | } 24 | 25 | /// 26 | /// 27 | /// 28 | /// 29 | static public void OnLogout(TokenLogonInfo logonInfo) 30 | { 31 | // 处理登录用户信息 32 | 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Service/InitServiceExt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using TianCheng.BaseService; 6 | 7 | namespace SamplesWebApi.Service 8 | { 9 | /// 10 | /// 11 | /// 12 | public class InitServiceExt : IServiceExtOption 13 | { 14 | /// 15 | /// 16 | /// 17 | public void SetOption() 18 | { 19 | TianCheng.SystemCommon.Services.DepartmentService.OnSaveCheck += DepartmentServiceTestExt.Test; 20 | TianCheng.SystemCommon.Services.DepartmentService.OnSaveCheck += DepartmentServiceTestExt.Test2; 21 | 22 | TianCheng.SystemCommon.Services.AuthService.OnLogin += OnlineEmployeeService.OnLogin; 23 | TianCheng.SystemCommon.Services.AuthService.OnLogout += OnlineEmployeeService.OnLogout; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Model/Common/FunctionInfo.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 权限功能点信息 5 | /// 6 | public class FunctionInfo 7 | { 8 | /// 9 | /// 序号 10 | /// 11 | public int Index { get; set; } 12 | /// 13 | /// 权限编码 14 | /// 15 | public string Code { get; set; } 16 | /// 17 | /// 功能点标识名 18 | /// 19 | public string Policy { get; set; } 20 | /// 21 | /// 权限名称 22 | /// 23 | public string Name { get; set; } 24 | 25 | /// 26 | /// 所属模块编号 27 | /// 28 | public string ModeuleCode { get; set; } 29 | /// 30 | /// 所属功能组编号 31 | /// 32 | public string GroupCode { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Services/Version/SystemVersionService.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.BaseService; 2 | using TianCheng.SystemCommon.DAL; 3 | using TianCheng.SystemCommon.Model; 4 | 5 | namespace TianCheng.SystemCommon.Services 6 | { 7 | /// 8 | /// 9 | /// 10 | public class SystemVersionService : MongoBusinessService 11 | { 12 | #region 构造方法 13 | /// 14 | /// 构造方法 15 | /// 16 | /// 17 | public SystemVersionService(SystemVersionDAL dal) 18 | : base(dal) 19 | { 20 | } 21 | 22 | #endregion 23 | 24 | /// 25 | /// 更新数据库的结构支撑V2.0的版本 26 | /// 27 | /// 原1.0的数据结构与2.0的不同 28 | public void UpdateToV2() 29 | { 30 | ((SystemVersionDAL)_Dal).UpdateToV2(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Model/DataImport/DataImportDetailInfo.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Excel; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 数据导入 7 | /// 8 | public class DataImportDetailInfo : TianCheng.Model.BusinessMongoModel 9 | { 10 | /// 11 | /// 序号 12 | /// 13 | public int RowIndex { get; set; } 14 | /// 15 | /// 导入的批次 16 | /// 17 | public string Batch { get; set; } 18 | /// 19 | /// 导入状态 20 | /// 21 | public ImportState ImportState { get; set; } 22 | 23 | /// 24 | /// 导入失败原因 25 | /// 26 | [ExcelColumn("导入失败原因")] 27 | public string FailureReason { get; set; } 28 | /// 29 | /// 导入结果 30 | /// 31 | public string ImportResult { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Model/AutoRun/View/TimerRecordView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 定时运行记录 7 | /// 8 | public class TimerRecordView 9 | { 10 | /// 11 | /// Id 12 | /// 13 | public string Id { get; set; } 14 | /// 15 | /// 定时器名称 16 | /// 17 | public string Name { get; set; } 18 | /// 19 | /// 备注 20 | /// 21 | public string Remark { get; set; } 22 | /// 23 | /// 运行时间 24 | /// 25 | public DateTime RunTime { get; set; } 26 | /// 27 | /// 运行结束时间 28 | /// 29 | public DateTime EndTime { get; set; } 30 | /// 31 | /// 耗时 秒 32 | /// 33 | public double TotalSeconds { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Model/DataImport/DataImportDetailResult.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 数据导入的结果 5 | /// 6 | public class DataImportDetailResult 7 | { 8 | /// 9 | /// 10 | /// 11 | public string Id { get; set; } 12 | /// 13 | /// 序号 14 | /// 15 | public int RowIndex { get; set; } 16 | /// 17 | /// 导入的批次 18 | /// 19 | public string Batch { get; set; } 20 | /// 21 | /// 导入状态 22 | /// 23 | public ImportState ImportState { get; set; } 24 | 25 | /// 26 | /// 导入失败原因 27 | /// 28 | public string FailureReason { get; set; } 29 | /// 30 | /// 导入结果 31 | /// 32 | public string ImportResult { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/Common/MenuSubInfo.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 菜单信息 5 | /// 6 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 7 | public class MenuSubInfo 8 | { 9 | /// 10 | /// 菜单序号 11 | /// 12 | public int Index { get; set; } 13 | /// 14 | /// 菜单名称 15 | /// 16 | public string Name { get; set; } 17 | /// 18 | /// 菜单描述 19 | /// 20 | public string Title { get; set; } 21 | /// 22 | /// 图标 23 | /// 24 | public string Icon { get; set; } 25 | /// 26 | /// 菜单的定位 27 | /// 28 | public string Link { get; set; } 29 | /// 30 | /// 菜单类型 31 | /// 32 | public MenuType Type { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/Common/Query/DepartmentQuery.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 部门的查询条件 7 | /// 8 | public class DepartmentQuery : TianCheng.Model.QueryInfo 9 | { 10 | /// 11 | /// 按名称模糊查询 12 | /// 13 | public string Name { get; set; } 14 | /// 15 | /// 按上级部门ID查询 16 | /// 17 | public string ParentId { get; set; } 18 | 19 | /// 20 | /// 按部门主管ID查询 21 | /// 22 | public string ManageId { get; set; } 23 | 24 | /// 25 | /// 按部门主管的名称模糊查询 26 | /// 27 | public string ManageName { get; set; } 28 | 29 | /// 30 | /// 按所属行业id列表查询。不能传入一级行业。以数组的方式提交行业id,例如:[afd321,adfiop] 31 | /// 32 | public List Industries { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Services/Common/RoleServiceExtFun.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.BaseService; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Services 5 | { 6 | /// 7 | /// 角色操作的扩展方法 8 | /// 9 | static public class RoleServiceExtFun 10 | { 11 | /// 12 | /// 判断当前用户是否为管理员 13 | /// 14 | /// 15 | /// 16 | static public bool IsAdminRole(this TokenLogonInfo logonInfo) 17 | { 18 | RoleService roleService = ServiceLoader.GetService(); 19 | if (roleService == null) 20 | { 21 | return false; 22 | } 23 | var roleInfo = roleService._SearchById(logonInfo.RoleId); 24 | if (roleInfo != null && roleInfo.Name.Contains("管理员")) 25 | { 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/LogonPowerView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 登录后的用户权限信息 9 | /// 10 | public class LogonPowerView : BaseViewModel 11 | { 12 | /// 13 | /// 角色信息 14 | /// 15 | [JsonProperty("role")] 16 | public RoleSimpleView Role { get; set; } 17 | /// 18 | /// 部门信息 19 | /// 20 | [JsonProperty("department")] 21 | public BaseViewModel Department { get; set; } 22 | /// 23 | /// 菜单信息 24 | /// 25 | [JsonProperty("menu")] 26 | public List Menu { get; set; } 27 | /// 28 | /// 包含的功能点列表 29 | /// 30 | [JsonProperty("functions")] 31 | public List Functions { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Model/Common/FunctionModuleInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 功能模块 8 | /// 9 | public class FunctionModuleInfo : BusinessMongoModel 10 | { 11 | /// 12 | /// 模块序号 13 | /// 14 | public int Index { get; set; } 15 | /// 16 | /// 模块名称 17 | /// 18 | public string Name { get; set; } 19 | /// 20 | /// 模块编码 21 | /// 22 | public string Code { get; set; } 23 | 24 | private List _FunctionGroups = new List(); 25 | /// 26 | /// 功能点分组(Control) 27 | /// 28 | public List FunctionGroups 29 | { 30 | get { return _FunctionGroups; } 31 | set { _FunctionGroups = value; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/Common/LoginHistoryInfo.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 登录历史记录 7 | /// 8 | public class LoginHistoryInfo : BusinessMongoModel 9 | { 10 | /// 11 | /// 登录用户的ID 12 | /// 13 | public string LoginId { get; set; } 14 | /// 15 | /// 登录用户 16 | /// 17 | public string Name { get; set; } 18 | /// 19 | /// 所属部门ID 20 | /// 21 | public string DepartmentID { get; set; } 22 | /// 23 | /// 所属部门名称 24 | /// 25 | public string DepartmentName { get; set; } 26 | /// 27 | /// 请求IP地址 28 | /// 29 | public string IpAddress { get; set; } 30 | /// 31 | /// 请求IP地址推断城市 32 | /// 33 | public string IpAddressCityName { get; set; } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Services/Common/MenuServiceOption.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TianCheng.SystemCommon.Model; 4 | 5 | namespace TianCheng.SystemCommon.Services 6 | { 7 | /// 8 | /// 菜单管理服务的配置信息 9 | /// 10 | public class MenuServiceOption 11 | { 12 | #region 设置静态访问方式 13 | /// 14 | /// 15 | /// 16 | static private MenuServiceOption _Option = new MenuServiceOption(); 17 | /// 18 | /// 19 | /// 20 | static public MenuServiceOption Option 21 | { 22 | get { return _Option; } 23 | set { _Option = value; } 24 | } 25 | 26 | private MenuServiceOption() 27 | { 28 | 29 | } 30 | #endregion 31 | 32 | #region 扩展的事件处理 33 | /// 34 | /// 完善菜单数据的扩展处理 35 | /// 36 | public Action> InitMenuData; 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Service/DepartmentServiceTestExt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using TianCheng.BaseService; 6 | using TianCheng.SystemCommon.Model; 7 | 8 | namespace SamplesWebApi.Service 9 | { 10 | /// 11 | /// 12 | /// 13 | public class DepartmentServiceTestExt 14 | { 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | static public void Test(DepartmentInfo info , TokenLogonInfo logon) 21 | { 22 | //var a = "abc"; 23 | 24 | } 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | static public void Test2(DepartmentInfo info, TokenLogonInfo logon) 31 | { 32 | //var a = "abc"; 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/FunctionModuleView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 功能点模块 9 | /// 10 | public class FunctionModuleView : BaseViewModel 11 | { 12 | /// 13 | /// 模块序号 14 | /// 15 | [JsonProperty("index")] 16 | public int Index { get; set; } 17 | /// 18 | /// 模块编码 19 | /// 20 | [JsonProperty("code")] 21 | public string Code { get; set; } 22 | 23 | private List _FunctionGroups = new List(); 24 | /// 25 | /// 功能点分组(Control) 26 | /// 27 | [JsonProperty("group")] 28 | public List FunctionGroups 29 | { 30 | get { return _FunctionGroups; } 31 | set { _FunctionGroups = value; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/Common/FunctionGroupInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 功能点分组 7 | /// 8 | public class FunctionGroupInfo 9 | { 10 | /// 11 | /// 功能点分类序号 12 | /// 13 | public int Index { get; set; } 14 | /// 15 | /// 功能点分类名称 16 | /// 17 | public string Name { get; set; } 18 | /// 19 | /// 分类编码 20 | /// 21 | public string Code { get; set; } 22 | 23 | private List _FunctionList = new List(); 24 | /// 25 | /// 功能点列表 26 | /// 27 | public List FunctionList 28 | { 29 | get { return _FunctionList; } 30 | set { _FunctionList = value; } 31 | } 32 | /// 33 | /// 所属模块编号 34 | /// 35 | public string ModeuleCode { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.AspNetCore; 9 | 10 | namespace SamplesWebApi 11 | { 12 | /// 13 | /// 14 | /// 15 | public class Program 16 | { 17 | /// 18 | /// 19 | /// 20 | /// 21 | public static void Main(string[] args) 22 | { 23 | BuildWebHost(args).Run(); 24 | } 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | public static IWebHost BuildWebHost(string[] args) => 31 | WebHost.CreateDefaultBuilder(args) 32 | .UseStartup() 33 | .ConfigureAppConfiguration(TianCheng.Model.ServiceLoader.Appsettings) 34 | .Build(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/MenuSubView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 子菜单信息 7 | /// 8 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 9 | public class MenuSubView 10 | { 11 | /// 12 | /// 菜单名称 13 | /// 14 | [JsonProperty("name")] 15 | public string Name { get; set; } 16 | 17 | /// 18 | /// 菜单序号 19 | /// 20 | [JsonProperty("index")] 21 | public int Index { get; set; } 22 | /// 23 | /// 菜单描述 24 | /// 25 | [JsonProperty("title")] 26 | public string Title { get; set; } 27 | 28 | /// 29 | /// 菜单的定位 30 | /// 31 | [JsonProperty("link")] 32 | public string Link { get; set; } 33 | 34 | /// 35 | /// 图标 36 | /// 37 | [JsonProperty("icon")] 38 | public string Icon { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Model/Area/AreaQuery.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 区域信息查询条件 5 | /// 6 | public class AreaQuery : TianCheng.Model.QueryInfo 7 | { 8 | /// 9 | /// 查询关键字 10 | /// 11 | public string Key { get; set; } 12 | /// 13 | /// 按区域名称模糊查询 14 | /// 15 | public string Name { get; set; } 16 | /// 17 | /// 按区域编码查询 18 | /// 19 | public string Code { get; set; } 20 | /// 21 | /// 按上级区域ID查询 22 | /// 23 | public string SuperiorId { get; set; } 24 | /// 25 | /// 按上级区域Code查询 26 | /// 27 | public string SuperiorCode { get; set; } 28 | /// 29 | /// 按上级区域名称查询 30 | /// 31 | public string SuperiorName { get; set; } 32 | /// 33 | /// 按区域类型查询 34 | /// 35 | public AreaType AreaType { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/FunctionGroupView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 功能点分类 查看对象 8 | /// 9 | public class FunctionGroupView 10 | { 11 | /// 12 | /// 分组序号 13 | /// 14 | [JsonProperty("index")] 15 | public int Index { get; set; } 16 | /// 17 | /// 分组名称 18 | /// 19 | [JsonProperty("name")] 20 | public int Name { get; set; } 21 | /// 22 | /// 分组编码 23 | /// 24 | [JsonProperty("code")] 25 | public string Code { get; set; } 26 | 27 | private List _functions = new List(); 28 | /// 29 | /// 包含功能点列表 30 | /// 31 | [JsonProperty("functions")] 32 | public List FunctionList 33 | { 34 | get { return _functions; } 35 | set { _functions = value; } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Services/Auth/AuthServiceOption.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Services 2 | { 3 | /// 4 | /// 登录验证配制 5 | /// 6 | public class AuthServiceOption 7 | { 8 | #region 设置静态访问方式 9 | /// 10 | /// 11 | /// 12 | static private AuthServiceOption _Option = new AuthServiceOption(); 13 | /// 14 | /// 15 | /// 16 | static public AuthServiceOption Option 17 | { 18 | get { return _Option; } 19 | set { _Option = value; } 20 | } 21 | 22 | private AuthServiceOption() 23 | { 24 | 25 | } 26 | #endregion 27 | 28 | 29 | #region 扩展的配制信息 30 | private bool _IsLogonByTelephone = true; 31 | /// 32 | /// 是否可以用电话号码登录 33 | /// 34 | public bool IsLogonByTelephone { get { return _IsLogonByTelephone; } set { _IsLogonByTelephone = value; } } 35 | 36 | #endregion 37 | 38 | #region 扩展的事件处理 39 | 40 | #endregion 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/UpdatePasswordView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 更新密码时的对象信息 7 | /// 8 | public class UpdatePasswordView 9 | { 10 | /// 11 | /// 用户ID 12 | /// 13 | [JsonProperty("id")] 14 | public string Id { get; set; } 15 | /// 16 | /// 旧密码 17 | /// 18 | [JsonProperty("oldPwd")] 19 | public string OldPwd { get; set; } 20 | /// 21 | /// 新密码 22 | /// 23 | [JsonProperty("newPwd")] 24 | public string NewPwd { get; set; } 25 | } 26 | /// 27 | /// 修改当前用户密码 28 | /// 29 | public class UpdatePasswordMeView 30 | { 31 | /// 32 | /// 旧密码 33 | /// 34 | [JsonProperty("oldPwd")] 35 | public string OldPwd { get; set; } 36 | /// 37 | /// 新密码 38 | /// 39 | [JsonProperty("newPwd")] 40 | public string NewPwd { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Model/DataImport/DataImportIndexInfo.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Model; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 数据导入索引对象 7 | /// 8 | public class DataImportIndexInfo : TianCheng.Model.BusinessMongoModel 9 | { 10 | /// 11 | /// 导入文件 12 | /// 13 | public FileNameView ImportFile { get; set; } 14 | /// 15 | /// 导入失败文件 16 | /// 17 | public FileNameView FailImportFile { get; set; } 18 | /// 19 | /// 导入的批次 20 | /// 21 | public string Batch { get; set; } 22 | /// 23 | /// 数据类型 24 | /// 25 | public string DataType { get; set; } 26 | /// 27 | /// 导入数据总数量 28 | /// 29 | public int Count { get; set; } 30 | /// 31 | /// 已导入完成数量 32 | /// 33 | public int Current { get; set; } 34 | /// 35 | /// 是否导入完成 36 | /// 37 | public bool IsComplete { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Serilog": { 3 | "WriteTo": [ 4 | { 5 | "Name": "RollingFile", 6 | "Args": { 7 | "pathFormat": "Logs/common-{Date}.txt", 8 | "restrictedToMinimumLevel": "Information" 9 | } 10 | }, 11 | "Debug", 12 | { 13 | "Name": "Console", 14 | "Args": { 15 | "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", 16 | "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {NewLine}{Exception}", 17 | "restrictedToMinimumLevel": "Information" 18 | } 19 | }, 20 | { 21 | "Name": "MongoDB", 22 | "Args": { 23 | "databaseUrl": "mongodb://localhost:27017/samples", 24 | "collectionName": "system_log", 25 | "restrictedToMinimumLevel": "Information" 26 | } 27 | } 28 | ] 29 | }, 30 | "DBConnection": [ 31 | { 32 | "Name": "default", 33 | "ServerAddress": "mongodb://localhost:27017", 34 | "Database": "samples", 35 | "Type": "MongoDB" 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/LoginHistoryView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 8 | /// 9 | public class LoginHistoryView 10 | { 11 | /// 12 | /// ID 13 | /// 14 | public string Id { get; set; } 15 | /// 16 | /// 登录用户的ID 17 | /// 18 | public string LoginId { get; set; } 19 | /// 20 | /// 登录用户 21 | /// 22 | public string Name { get; set; } 23 | /// 24 | /// 所属部门ID 25 | /// 26 | public string DepartmentID { get; set; } 27 | /// 28 | /// 所属部门名称 29 | /// 30 | public string DepartmentName { get; set; } 31 | /// 32 | /// 请求IP地址 33 | /// 34 | public string IpAddress { get; set; } 35 | 36 | /// 37 | /// 创建时间 38 | /// 39 | [JsonProperty("loginDate")] 40 | public DateTime CreateDate { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Model/Common/RoleInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 角色信息 8 | /// 9 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 10 | public class RoleInfo : BusinessMongoModel 11 | { 12 | /// 13 | /// 角色名称 14 | /// 15 | public string Name { get; set; } 16 | /// 17 | /// 描述信息 18 | /// 19 | public string Desc { get; set; } 20 | /// 21 | /// 当前角色登录后的默认页面 22 | /// 23 | public string DefaultPage { get; set; } 24 | /// 25 | /// 包含菜单列表 26 | /// 27 | public List PagePower { get; set; } = new List(); 28 | /// 29 | /// 包含功能点列表 30 | /// 31 | public List FunctionPower { get; set; } = new List(); 32 | /// 33 | /// 是否为系统级别数据 34 | /// 35 | public bool IsSystem { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/EmployeeSelectView.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 下拉列表查看员工的数据 5 | /// 6 | public class EmployeeSelectView 7 | { 8 | /// 9 | /// 员工ID 10 | /// 11 | public string Id { get; set; } 12 | /// 13 | /// 员工编码 14 | /// 15 | public string Code { get; set; } 16 | /// 17 | /// 员工名称 18 | /// 19 | public string Name { get; set; } 20 | 21 | /// 22 | /// 部门Id 23 | /// 24 | public string DepartmentId { get; set; } 25 | /// 26 | /// 部门名称 27 | /// 28 | public string DepartmentName { get; set; } 29 | 30 | /// 31 | /// 角色Id 32 | /// 33 | public string RoleId { get; set; } 34 | /// 35 | /// 角色名称 36 | /// 37 | public string RoleName { get; set; } 38 | 39 | /// 40 | /// 是否在职 41 | /// 42 | public bool IsDelete { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/MenuMainView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 主菜单信息 9 | /// 10 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 11 | public class MenuMainView : BaseViewModel 12 | { 13 | /// 14 | /// 菜单序号 15 | /// 16 | [JsonProperty("index")] 17 | public int Index { get; set; } 18 | /// 19 | /// 菜单描述 20 | /// 21 | [JsonProperty("title")] 22 | public string Title { get; set; } 23 | 24 | /// 25 | /// 菜单的定位 26 | /// 27 | [JsonProperty("link")] 28 | public string Link { get; set; } 29 | 30 | /// 31 | /// 图标 32 | /// 33 | [JsonProperty("icon")] 34 | public string Icon { get; set; } 35 | 36 | /// 37 | /// 子菜单列表 38 | /// 39 | [JsonProperty("sub")] 40 | public List SubMenu { get; set; } = new List(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Model/Common/MenuMainInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 菜单信息 8 | /// 9 | [MongoDB.Bson.Serialization.Attributes.BsonIgnoreExtraElements] 10 | public class MenuMainInfo : BusinessMongoModel 11 | { 12 | /// 13 | /// 菜单序号 14 | /// 15 | public int Index { get; set; } 16 | /// 17 | /// 菜单名称 18 | /// 19 | public string Name { get; set; } 20 | /// 21 | /// 菜单描述 22 | /// 23 | public string Title { get; set; } 24 | /// 25 | /// 菜单类型 26 | /// 27 | public MenuType Type { get; set; } 28 | /// 29 | /// 图标 30 | /// 31 | public string Icon { get; set; } 32 | /// 33 | /// 菜单的定位 34 | /// 35 | public string Link { get; set; } 36 | /// 37 | /// 子菜单列表 38 | /// 39 | public List SubMenu { get; set; } = new List(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Controller/DataImport/DataImportController.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.BaseService; 2 | using TianCheng.BaseService.Services; 3 | using TianCheng.Model; 4 | using TianCheng.SystemCommon.DAL; 5 | using TianCheng.SystemCommon.Model; 6 | using TianCheng.SystemCommon.Services; 7 | 8 | namespace TianCheng.SystemCommon.Controller 9 | { 10 | /// 11 | /// 数据导入控制器 12 | /// 13 | public class DataImportController : DataController 14 | where T : DataImportDetailInfo, new() 15 | where TD : DataImportDetailDAL 16 | where TS : DataImportService 17 | where Info : BusinessMongoModel, new() 18 | { 19 | #region 构造方法 20 | /// 21 | /// 22 | /// 23 | protected readonly FilePathService filePath; 24 | /// 25 | /// 26 | /// 27 | protected readonly TS importService; 28 | /// 29 | /// 构造方法 30 | /// 31 | public DataImportController() 32 | { 33 | filePath = ServiceLoader.GetService(); 34 | importService = ServiceLoader.GetService(); 35 | } 36 | #endregion 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Properties/PublishProfiles/CustomProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | MSDeploy 9 | Release 10 | Any CPU 11 | http://118.89.221.56:99/swagger 12 | True 13 | False 14 | netcoreapp2.0 15 | 4cb7e964-a3ab-4ad7-b39c-78061d3cf890 16 | 118.89.221.56 17 | demo 18 | 19 | True 20 | WMSVC 21 | True 22 | deploy 23 | <_SavePWD>True 24 | 25 | -------------------------------------------------------------------------------- /src/Model/DataImport/DataImportIndexView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 8 | /// 9 | public class DataImportIndexView 10 | { 11 | /// 12 | /// Id 13 | /// 14 | public string Id { get; set; } 15 | /// 16 | /// 导入的批次 17 | /// 18 | public string Batch { get; set; } 19 | /// 20 | /// 数据类型 21 | /// 22 | public string DataType { get; set; } 23 | /// 24 | /// 导入数据总数量 25 | /// 26 | public int Count { get; set; } 27 | /// 28 | /// 已导入完成数量 29 | /// 30 | public int Current { get; set; } 31 | /// 32 | /// 是否导入完成 33 | /// 34 | public bool IsComplete { get; set; } 35 | 36 | /// 37 | /// 创建人名称 38 | /// 39 | [JsonProperty("creater")] 40 | public string CreaterName { get; set; } 41 | /// 42 | /// 创建时间 43 | /// 44 | [JsonProperty("date")] 45 | public DateTime CreateDate { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Controller/Version/SystemVersionController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Swashbuckle.AspNetCore.Annotations; 3 | using TianCheng.BaseService; 4 | using TianCheng.Model; 5 | using TianCheng.SystemCommon.Services; 6 | 7 | namespace TianCheng.SystemCommon.Controller 8 | { 9 | /// 10 | /// 版本控制 11 | /// 12 | [Route("api/Version")] 13 | public class SystemVersionController : DataController 14 | { 15 | #region 构造方法 16 | /// 17 | /// 版本操作服务 18 | /// 19 | private readonly SystemVersionService Service; 20 | /// 21 | /// 构造方法 22 | /// 23 | /// 24 | public SystemVersionController(SystemVersionService systemVersionService) 25 | { 26 | Service = systemVersionService; 27 | } 28 | #endregion 29 | 30 | /// 31 | /// 更新数据库的结构支撑V2.0的版本 32 | /// 33 | /// 原1.0的数据结构与2.0的不同 34 | [SwaggerOperation(Tags = new[] { "系统管理-版本控制" })] 35 | [HttpPost("UpdateToV2")] 36 | public ResultView UpdateToV2() 37 | { 38 | Service.UpdateToV2(); 39 | return ResultView.Success(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Controller/Common/EmployeeImageController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using Swashbuckle.AspNetCore.Annotations; 5 | using Swashbuckle.AspNetCore.SwaggerGen; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using TianCheng.BaseService; 10 | using TianCheng.BaseService.PlugIn.Swagger; 11 | using TianCheng.Model; 12 | using TianCheng.SystemCommon.DAL; 13 | using TianCheng.SystemCommon.Model; 14 | using TianCheng.SystemCommon.Services; 15 | 16 | namespace TianCheng.SystemCommon.Controller 17 | { 18 | /// 19 | /// 员工管理 20 | /// 21 | [Produces("application/json")] 22 | [Route("api/Employee")] 23 | public class EmployeeImageController : DataController 24 | { 25 | #region 构造方法 26 | private readonly EmployeeService _Service; 27 | private readonly ILogger _logger; 28 | 29 | /// 30 | /// 构造方法 31 | /// 32 | /// 33 | /// 34 | public EmployeeImageController(EmployeeService service, ILogger logger) 35 | { 36 | _Service = service; 37 | _logger = logger; 38 | } 39 | #endregion 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Model/Industries/IndustryView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 行业信息 [查看对象] 8 | /// 9 | public class IndustryView 10 | { 11 | /// 12 | /// ID 新增时不需要传值,修改的时候需要传递 13 | /// 14 | [JsonProperty("id")] 15 | public string Id { get; set; } 16 | /// 17 | /// 编码 18 | /// 19 | [JsonProperty("code")] 20 | public string Code { get; set; } 21 | /// 22 | /// 名称 23 | /// 24 | [JsonProperty("name")] 25 | public string Name { get; set; } 26 | /// 27 | /// 行业说明 28 | /// 29 | [JsonProperty("remarks")] 30 | public string Remarks { get; set; } 31 | /// 32 | /// 最后更新时间 33 | /// 34 | [JsonProperty("updateDate")] 35 | public string UpdateDate { get; set; } 36 | /// 37 | /// 最后更新人 38 | /// 39 | [JsonProperty("updateUser")] 40 | public string UpdaterName { get; set; } 41 | /// 42 | /// 子行业列表 43 | /// 44 | [JsonProperty("sub")] 45 | public List Sub { get; set; } = new List(); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Model/Common/Query/EmployeeQuery.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 员工的查询条件 7 | /// 8 | [JsonObject(MemberSerialization.OptIn)] 9 | public class EmployeeQuery : TianCheng.Model.QueryInfo 10 | { 11 | /// 12 | /// 按名称模糊查询 13 | /// 14 | [JsonProperty("name")] 15 | public string Name { get; set; } 16 | 17 | /// 18 | /// 查询关键字 19 | /// 20 | [JsonProperty("key")] 21 | public string Key { get; set; } 22 | 23 | /// 24 | /// 按部门ID查询 25 | /// 26 | [JsonProperty("departmentId")] 27 | public string DepartmentId { get; set; } 28 | 29 | /// 30 | /// 根节点部门 31 | /// 32 | public string RootDepartment { get; set; } 33 | /// 34 | /// 角色 35 | /// 36 | [JsonProperty("roleId")] 37 | public string RoleId { get; set; } 38 | /// 39 | /// 按状态查询 1-可用,3-锁住,5-禁用 40 | /// 41 | [JsonProperty("state")] 42 | public UserState State { get; set; } 43 | 44 | /// 45 | /// 是否查看被逻辑删除的数据 0/不传值-不显示逻辑删除的数据 1-显示所有数据,包含逻辑删除的 2-只显示逻辑删除的数据 46 | /// 47 | [JsonProperty("hasDelete")] 48 | public int HasDelete { get; set; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/RoleView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 角色查看信息 9 | /// 10 | public class RoleView : BaseViewModel 11 | { 12 | /// 13 | /// 描述信息 14 | /// 15 | [JsonProperty("desc")] 16 | public string Desc { get; set; } 17 | /// 18 | /// 当前角色登录后的默认页面 19 | /// 20 | [JsonProperty("page")] 21 | public string DefaultPage { get; set; } 22 | 23 | /// 24 | /// 包含菜单列表 25 | /// 26 | [JsonProperty("menu")] 27 | public List PagePower { get; set; } 28 | 29 | /// 30 | /// 包含功能点列表 31 | /// 32 | [JsonProperty("functions")] 33 | public List FunctionPower { get; set; } = new List(); 34 | 35 | /// 36 | /// 最后更新时间 37 | /// 38 | [JsonProperty("updateDate")] 39 | public string UpdateDate { get; set; } 40 | /// 41 | /// 最后更新人 42 | /// 43 | [JsonProperty("updateUser")] 44 | public string UpdaterName { get; set; } 45 | 46 | /// 47 | /// 是否为系统级别数据 48 | /// 49 | [JsonProperty("isSystem")] 50 | public bool IsSystem { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Model/Area/AreaView.cs: -------------------------------------------------------------------------------- 1 | namespace TianCheng.SystemCommon.Model 2 | { 3 | /// 4 | /// 区域信息 的查看对象 5 | /// 6 | public class AreaView 7 | { 8 | /// 9 | /// ID 10 | /// 11 | public string Id { get; set; } 12 | /// 13 | /// 区域名称 14 | /// 15 | public string Name { get; set; } 16 | /// 17 | /// 区域名称 英文 18 | /// 19 | public string NameEn { get; set; } 20 | /// 21 | /// 区域名称简写 22 | /// 23 | public string ShortName { get; set; } 24 | /// 25 | /// 区域代码 26 | /// 27 | public string Code { get; set; } 28 | /// 29 | /// 区域邮编 30 | /// 31 | public string Zip { get; set; } 32 | /// 33 | /// 电话区号 34 | /// 35 | public string TelephoneCode { get; set; } 36 | /// 37 | /// 上级区域ID 38 | /// 39 | public string SuperiorId { get; set; } 40 | /// 41 | /// 上级区域Code 42 | /// 43 | public string SuperiorCode { get; set; } 44 | /// 45 | /// 上级区域名称 46 | /// 47 | public string SuperiorName { get; set; } 48 | /// 49 | /// 区域类型 50 | /// 51 | public AreaType AreaType { get; set; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Model/Common/DataImport/EmployeesImportDetail.cs: -------------------------------------------------------------------------------- 1 | using TianCheng.Excel; 2 | 3 | namespace TianCheng.SystemCommon.Model 4 | { 5 | /// 6 | /// 员工信息导入明细信息 7 | /// 8 | [ExcelSheet("Employees")] 9 | public class EmployeesImportDetail : DataImportDetailInfo 10 | { 11 | /// 12 | /// 编号 13 | /// 14 | [ExcelColumn("编号", "A")] 15 | public string Code { get; set; } 16 | /// 17 | /// 名称 18 | /// 19 | [ExcelColumn("名称", "B")] 20 | public string Name { get; set; } 21 | /// 22 | /// 登陆账号 23 | /// 24 | [ExcelColumn("登陆账号", "C")] 25 | public string LogonAccount { get; set; } 26 | /// 27 | /// 登录密码 28 | /// 29 | [ExcelColumn("登录密码", "D")] 30 | public string LogonPassword { get; set; } 31 | /// 32 | /// 性别 33 | /// 34 | [ExcelColumn("性别", "E")] 35 | public string Gender { get; set; } 36 | /// 37 | /// 是否在职 38 | /// 39 | [ExcelColumn("是否在职", "F")] 40 | public string IsHoldJob { get; set; } 41 | 42 | /// 43 | /// 部门 44 | /// 45 | [ExcelColumn("部门", "G")] 46 | public string Department { get; set; } 47 | 48 | /// 49 | /// 角色 50 | /// 51 | [ExcelColumn("角色", "H")] 52 | public string Role { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TianCheng.SystemCommon 2 | 3 | 部门、用户、角色、功能点、菜单的通用处理 4 | 5 | 使用方式 6 | 7 | ----------- 8 | 9 | 在Startup.cs里面修改ConfigureServices 与 Configure 方法 10 | 11 | ```csharp 12 | public void ConfigureServices(IServiceCollection services) 13 | { 14 | //原代码不用,直接用下面代码代替 15 | services.TianChengCommonInit(Configuration); 16 | } 17 | 18 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 19 | { 20 | app.TianChengCommonInit(Configuration); 21 | } 22 | ``` 23 | 24 | 配置appsettings.json说明 25 | 26 | 1. 配置Swagger 27 | 2. 设置登录验证的Token信息 28 | 3. 配置MongoDB数据库连接 29 | 4. FunctionModule可配置,也可不配置,此配置主要用于权限中功能点的自动生成处理 30 | 31 | ```json 32 | { 33 | "Logging": { 34 | "LogLevel": { 35 | "Default": "Warning" 36 | } 37 | }, 38 | "AllowedHosts": "*", 39 | "SwaggerDoc": { 40 | "Version": "v1", 41 | "Title": "demo", 42 | "Description": "RESTful API for demo", 43 | "TermsOfService": "None", 44 | "ContactName": "cheng_kkll", 45 | "ContactEmail": "cheng_kkll@163.com", 46 | "ContactUrl": "", 47 | "EndpointUrl": "/swagger/v1/swagger.json", 48 | "EndpointDesc": "demo API V1" 49 | }, 50 | "Token": { 51 | "Issuer": "demo.issuer", 52 | "Audience": "demo.audi", 53 | "SecretKey": "DemoSecretKey", 54 | "Scheme": "Bearer", 55 | "Path": "/api/auth/login" 56 | }, 57 | "FunctionModule": { 58 | "ModuleDict": [ 59 | { 60 | "Code": "TianCheng.SystemCommon", 61 | "Name": "系统管理" 62 | } 63 | ] 64 | }, 65 | "DatabaseInfo": { 66 | "ServerAddress": "mongodb://demo:demo@loalhost", 67 | "Database": "demo" 68 | } 69 | } 70 | 71 | ``` 72 | -------------------------------------------------------------------------------- /TianCheng.SystemCommon.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TianCheng.SystemCommon", "src\TianCheng.SystemCommon.csproj", "{35D55B86-0F59-4BB9-813C-5088BE1C2F70}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesWebApi", "samples\SamplesWebApi\SamplesWebApi.csproj", "{3685B843-3BB8-4B8B-9FA7-A18A70115232}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {35D55B86-0F59-4BB9-813C-5088BE1C2F70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {35D55B86-0F59-4BB9-813C-5088BE1C2F70}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {35D55B86-0F59-4BB9-813C-5088BE1C2F70}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {35D55B86-0F59-4BB9-813C-5088BE1C2F70}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {3685B843-3BB8-4B8B-9FA7-A18A70115232}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {3685B843-3BB8-4B8B-9FA7-A18A70115232}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {3685B843-3BB8-4B8B-9FA7-A18A70115232}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {3685B843-3BB8-4B8B-9FA7-A18A70115232}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {A6C78DD6-AE7F-46A3-AEFD-06AC58A94063} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/Controller/AutoRun/TimerRecordController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.Model; 7 | using TianCheng.SystemCommon.Services; 8 | 9 | namespace TianCheng.SystemCommon.Controller 10 | { 11 | /// 12 | /// 系统控制 13 | /// 14 | [Produces("application/json")] 15 | [Route("api/Auotrun/Record")] 16 | public class TimerRecordController : DataController 17 | { 18 | #region 构造方法 19 | private readonly TimerRecordService _Service; 20 | private readonly ILogger _logger; 21 | 22 | /// 23 | /// 构造方法 24 | /// 25 | /// 26 | /// 27 | public TimerRecordController(TimerRecordService service, ILogger logger) 28 | { 29 | _Service = service; 30 | _logger = logger; 31 | } 32 | #endregion 33 | 34 | /// 35 | /// 查询 36 | /// 37 | /// 38 | /// 39 | /// 查询定时运行结果 40 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Auotrun.SearchPage")] 41 | [SwaggerOperation(Tags = new[] { "系统管理-定时运行" })] 42 | [Route("Search")] 43 | [HttpPost] 44 | public PagedResult SearchPage([FromBody]TimerRecordQuery queryInfo) 45 | { 46 | return _Service.FilterPage(queryInfo); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Model/Common/DepartmentInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 部门信息 8 | /// 9 | public class DepartmentInfo : BusinessMongoModel 10 | { 11 | #region 部门基本信息 12 | /// 13 | /// 部门编码 14 | /// 15 | public string Code { get; set; } 16 | /// 17 | /// 排序的序号 18 | /// 19 | public int Index { get; set; } 20 | /// 21 | /// 部门名称 22 | /// 23 | public string Name { get; set; } 24 | /// 25 | /// 部门描述 26 | /// 27 | public string Desc { get; set; } 28 | #endregion 29 | 30 | #region 上级信息 31 | /// 32 | /// 上级部门Id 33 | /// 34 | public string ParentId { get; set; } 35 | /// 36 | /// 上级部门名称 37 | /// 38 | public string ParentName { get; set; } 39 | /// 40 | /// 上级部门ID列表 41 | /// 42 | public List ParentsIds { get; set; } = new List(); 43 | #endregion 44 | 45 | #region 主管信息 46 | /// 47 | /// 部门主管ID 48 | /// 49 | public string ManageId { get; set; } 50 | /// 51 | /// 部门主管名称 52 | /// 53 | public string ManageName { get; set; } 54 | #endregion 55 | 56 | #region 扩展 57 | /// 58 | /// 扩展ID 用于部门信息的扩展 59 | /// 60 | public string ExtId { get; set; } 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Controller/Auth/DepartmentIpController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.Services; 7 | using TianCheng.SystemCommon.Services.Auth; 8 | 9 | namespace TianCheng.SystemCommon.Controller.Auth 10 | { 11 | /// 12 | /// 部门IP 13 | /// 14 | /// 系统控制 15 | [Produces("application/json")] 16 | [Route("api/auth/departmentIp")] 17 | public class DepartmentIpController : DataController 18 | { 19 | #region 构造方法 20 | private readonly DepartmentIpService _Service; 21 | private readonly ILogger _logger; 22 | 23 | /// 24 | /// 构造方法 25 | /// 26 | /// 27 | /// 28 | public DepartmentIpController(DepartmentIpService service, ILogger logger) 29 | { 30 | _Service = service; 31 | _logger = logger; 32 | } 33 | #endregion 34 | 35 | /// 36 | /// 新增部门IP 37 | /// 38 | /// 部门id 39 | /// 40 | [HttpPost("{id}")] 41 | [SwaggerOperation(Tags = new[] { "系统管理-登录验证" })] 42 | public ResultView Login(string id) 43 | { 44 | DepartmentService departmentService = ServiceLoader.GetService(); 45 | var dep = departmentService._SearchById(id); 46 | return ResultView.Success(); 47 | //return new LoginResult { Token = token }; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/DAL/Version/SystemVersionDAL.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using TianCheng.DAL.MongoDB; 5 | using TianCheng.SystemCommon.Model; 6 | 7 | namespace TianCheng.SystemCommon.DAL 8 | { 9 | /// 10 | /// 版本更新时的数据库处理 11 | /// 12 | [DBMapping("system_version")] 13 | public class SystemVersionDAL : MongoOperation 14 | { 15 | /// 16 | /// 更新数据库的结构支撑V2.0的版本 17 | /// 18 | /// 原1.0的数据结构与2.0的不同 19 | public void UpdateToV2() 20 | { 21 | // 修改集合名称 22 | IEnumerable names = this.Provider.Database.ListCollectionNames().Current.ToList(); 23 | if (names.Contains("System_DepartmentInfo")) 24 | { 25 | this.Provider.Database.RenameCollection("System_DepartmentInfo", "system_department"); 26 | } 27 | if (names.Contains("System_EmployeeInfo")) 28 | { 29 | this.Provider.Database.RenameCollection("System_EmployeeInfo", "system_employee"); 30 | } 31 | if (names.Contains("System_FunctionInfo")) 32 | { 33 | this.Provider.Database.RenameCollection("System_FunctionInfo", "system_function"); 34 | } 35 | if (names.Contains("System_MenuInfo")) 36 | { 37 | this.Provider.Database.RenameCollection("System_MenuInfo", "system_menu"); 38 | } 39 | if (names.Contains("System_RoleInfo")) 40 | { 41 | this.Provider.Database.RenameCollection("System_RoleInfo", "system_role"); 42 | } 43 | 44 | // 修改菜单数据结构 45 | 46 | // 修改功能点的数据结构 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Services/Auth/DepartmentIpService.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using TianCheng.BaseService; 3 | using TianCheng.Model; 4 | using TianCheng.SystemCommon.DAL; 5 | using TianCheng.SystemCommon.Model; 6 | 7 | namespace TianCheng.SystemCommon.Services.Auth 8 | { 9 | /// 10 | /// 部门IP服务 11 | /// 12 | public class DepartmentIpService : MongoBusinessService 13 | { 14 | /// 15 | /// 构造方法 16 | /// 17 | /// 18 | public DepartmentIpService(DepartmentIpDAL dal) : base(dal) 19 | { 20 | } 21 | 22 | #region 查询方法 23 | /// 24 | /// 按条件查询数据 25 | /// 26 | /// 27 | /// 28 | public override IQueryable _Filter(QueryInfo input) 29 | { 30 | var query = _Dal.Queryable(); 31 | 32 | #region 查询条件 33 | //不显示删除的数据 34 | query = query.Where(e => e.IsDelete == false); 35 | #endregion 36 | 37 | #region 设置排序规则 38 | 39 | //设置排序方式 40 | switch (input.Sort.Property) 41 | { 42 | case "name": { query = input.Sort.IsAsc ? query.OrderBy(e => e.DepartmentName) : query.OrderByDescending(e => e.DepartmentName); break; } 43 | case "date": { query = input.Sort.IsAsc ? query.OrderBy(e => e.UpdateDate) : query.OrderByDescending(e => e.UpdateDate); break; } 44 | default: { query = query.OrderByDescending(e => e.UpdateDate); break; } 45 | } 46 | #endregion 47 | 48 | //返回查询结果 49 | return query; 50 | } 51 | #endregion 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/DepartmentView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 部门信息 [查看对象] 9 | /// 10 | public class DepartmentView : BaseViewModel 11 | { 12 | /// 13 | /// 部门编码 14 | /// 15 | public string Code { get; set; } 16 | /// 17 | /// 排序的序号 18 | /// 19 | public int Index { get; set; } 20 | /// 21 | /// 部门描述 22 | /// 23 | public string Desc { get; set; } 24 | 25 | /// 26 | /// 上级部门ID 27 | /// 28 | public string ParentId { get; set; } 29 | /// 30 | /// 上级部门名称 31 | /// 32 | public string ParentName { get; set; } 33 | 34 | /// 35 | /// 部门主管ID 36 | /// 37 | public string ManageId { get; set; } 38 | /// 39 | /// 部门主管名称 40 | /// 41 | public string ManageName { get; set; } 42 | 43 | /// 44 | /// 包含的子部门 45 | /// 46 | [JsonProperty("sub")] 47 | public List SubList { get; set; } 48 | 49 | /// 50 | /// 最后更新时间 仅用于列表显示及排序,新增修改时不需要传递 51 | /// 52 | public string UpdateDate { get; set; } 53 | /// 54 | /// 最后更新人 仅用于列表显示及排序,新增修改时不需要传递 55 | /// 56 | public string UpdaterName { get; set; } 57 | 58 | /// 59 | /// 扩展ID 用于部门信息的扩展 60 | /// 61 | public string ExtId { get; set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/TianCheng.SystemCommon.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | true 6 | 2.0.0 7 | 成善斌 8 | 天成科技 9 | 天成科技通用业务类库 10 | 部门、用户、角色、功能点、菜单的通用处理 11 | 2.0 增加了区域、行业、IP登录、系统版本的处理 12 | https://raw.githubusercontent.com/chengkkll/resources/master/Logo64.ico 13 | github 14 | 设置目标架构为:.NET Standard 2.0 15 | tiancheng 16 | https://github.com/chengkkll/TianCheng.SystemCommon 17 | https://github.com/chengkkll/TianCheng.SystemCommon.git 18 | 19 | 20 | 21 | bin\Debug\netstandard2.0\TianCheng.SystemCommon.xml 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/Model/Area/AreaInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 区域信息 8 | /// 9 | public class AreaInfo : BusinessMongoModel 10 | { 11 | /// 12 | /// 区域名称 13 | /// 14 | public string Name { get; set; } 15 | /// 16 | /// 区域名称 英文 17 | /// 18 | public string NameEn { get; set; } 19 | /// 20 | /// 区域名称简写 21 | /// 22 | public string ShortName { get; set; } 23 | /// 24 | /// 区域代码 25 | /// 26 | public string Code { get; set; } 27 | /// 28 | /// 区域邮编 29 | /// 30 | public string Zip { get; set; } 31 | /// 32 | /// 电话区号 33 | /// 34 | public string TelephoneCode { get; set; } 35 | /// 36 | /// 上级区域Id 37 | /// 38 | public string SuperiorId { get; set; } 39 | /// 40 | /// 上级区域Code 41 | /// 42 | public string SuperiorCode { get; set; } 43 | /// 44 | /// 上级区域名称 45 | /// 46 | public string SuperiorName { get; set; } 47 | 48 | /// 49 | /// 上级区域Id列表 50 | /// 51 | public List SuperiorIds { get; set; } = new List(); 52 | /// 53 | /// 上级区域名称列表 54 | /// 55 | public List SuperiorNames { get; set; } = new List(); 56 | /// 57 | /// 区域类型 58 | /// 59 | public AreaType AreaType { get; set; } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.DependencyModel; 11 | using System.Reflection; 12 | using Microsoft.AspNetCore.Http; 13 | 14 | namespace SamplesWebApi 15 | { 16 | /// 17 | /// 18 | /// 19 | public class Startup 20 | { 21 | /// 22 | /// 23 | /// 24 | /// 25 | public Startup(IConfiguration configuration) 26 | { 27 | Configuration = configuration; 28 | } 29 | /// 30 | /// 31 | /// 32 | public IConfiguration Configuration { get; } 33 | 34 | /// 35 | /// 36 | /// 37 | /// 38 | public void ConfigureServices(IServiceCollection services) 39 | { 40 | services.TianChengCommonInit(Configuration); 41 | } 42 | 43 | /// 44 | /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 45 | /// 46 | /// 47 | /// 48 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 49 | { 50 | //if (env.IsDevelopment()) 51 | //{ 52 | // app.UseDeveloperExceptionPage(); 53 | //} 54 | 55 | app.TianChengCommonInit(Configuration); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Controller/Common/FunctionController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Swashbuckle.AspNetCore.Annotations; 3 | using System.Collections.Generic; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.Model; 7 | using TianCheng.SystemCommon.Services; 8 | 9 | namespace TianCheng.SystemCommon.Controller 10 | { 11 | /// 12 | /// 功能点管理 13 | /// 14 | [Produces("application/json")] 15 | [Route("api/Function")] 16 | public class FunctionController : DataController 17 | { 18 | #region 构造方法 19 | private readonly FunctionService _Service; 20 | /// 21 | /// 构造方法 22 | /// 23 | /// 24 | public FunctionController(FunctionService service) 25 | { 26 | _Service = service; 27 | } 28 | #endregion 29 | 30 | #region 数据查询 31 | /// 32 | /// 查询功能点 33 | /// 34 | /// 查询所有的功能点信息,以树形结构显示结果,无分页信息 35 | /// 查询 36 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Function.Search")] 37 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 38 | [HttpGet("")] 39 | public List Search() 40 | { 41 | return _Service.LoadTree(); 42 | } 43 | #endregion 44 | 45 | #region 初始化 46 | /// 47 | /// 初始化 48 | /// 49 | /// 初始化功能点。 清除已有功能点,分析引用项目的注释信息来重置功能点 50 | /// 初始化 51 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Function.Init")] 52 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 53 | [Route("Init")] 54 | [HttpPost] 55 | public ResultView Init() 56 | { 57 | _Service.Init(); 58 | 59 | return ResultView.Success(); 60 | } 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Model/Profile/SystemCommonModelProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using TianCheng.Model; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 系统基础信息的AutoMapper转换 8 | /// 9 | public class SystemCommonModelProfile : Profile, IAutoProfile 10 | { 11 | /// 12 | /// 构造方法 13 | /// 14 | public SystemCommonModelProfile() 15 | { 16 | Register(); 17 | } 18 | /// 19 | /// 20 | /// 21 | public void Register() 22 | { 23 | CreateMap(); 24 | CreateMap(); 25 | CreateMap(); 26 | 27 | CreateMap(); 28 | CreateMap(); 29 | CreateMap(); 30 | CreateMap(); 31 | CreateMap(); 32 | CreateMap(); 33 | 34 | CreateMap(); 35 | CreateMap(); 36 | CreateMap(); 37 | CreateMap(); 38 | 39 | CreateMap(); 40 | CreateMap(); 41 | CreateMap(); 42 | CreateMap(); 43 | 44 | CreateMap(); 45 | CreateMap(); 46 | CreateMap(); 47 | 48 | CreateMap(); 49 | CreateMap(); 50 | CreateMap(); 51 | 52 | CreateMap(); 53 | CreateMap(); 54 | CreateMap(); 55 | 56 | CreateMap(); 57 | CreateMap(); 58 | CreateMap(); 59 | 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/DAL/Common/DepartmentDAL.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Driver; 2 | using System; 3 | using TianCheng.DAL; 4 | using TianCheng.DAL.MongoDB; 5 | using TianCheng.SystemCommon.Model; 6 | 7 | namespace TianCheng.SystemCommon.DAL 8 | { 9 | /// 10 | /// 部门信息 [数据持久化] 11 | /// 12 | [DBMapping("system_department")] 13 | public class DepartmentDAL : MongoOperation 14 | { 15 | ///// 16 | ///// 获取指定部门及其下级部门 17 | ///// 18 | ///// 部门ID 19 | //public List GetSelfAndSub(string id) 20 | //{ 21 | // var builder = Builders.Filter; 22 | // FilterDefinition filter = builder.Eq("ParentsIds", id) | builder.Eq("_id", new ObjectId(id)); 23 | 24 | // try 25 | // { 26 | // return _mongoCollection.Find(filter).ToList(); 27 | // } 28 | // catch (System.TimeoutException te) 29 | // { 30 | // DBLog.Logger.LogWarning(te, "数据库链接超时。链接字符串:" + _options.ConnectionOptions.ConnectionString()); 31 | // throw; 32 | // } 33 | // catch (Exception ex) 34 | // { 35 | // DBLog.Logger.LogWarning(ex, "操作异常终止。"); 36 | // throw; 37 | // } 38 | //} 39 | 40 | /// 41 | /// 批量更新上级部门名称 42 | /// 43 | /// 44 | public void UpdateParentsDepartmentName(DepartmentInfo departmentInfo) 45 | { 46 | // 验证参数 47 | if (departmentInfo.IsEmpty) 48 | { 49 | return; 50 | } 51 | // 设置查询条件 52 | FilterDefinition filter = Builders.Filter.Eq("ParentId", departmentInfo.Id.ToString()); 53 | // 设置更新内容 54 | UpdateDefinition ud = Builders.Update.Set("ParentName", departmentInfo.Name); 55 | try 56 | { 57 | UpdateResult result = MongoCollection.UpdateMany(filter, ud); 58 | } 59 | catch (System.TimeoutException te) 60 | { 61 | DBLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString()); 62 | throw; 63 | } 64 | catch (Exception ex) 65 | { 66 | DBLog.Logger.Warning(ex, "操作异常终止。"); 67 | throw; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Service/DepartmentServiceOptionExt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using TianCheng.BaseService; 7 | using TianCheng.Model; 8 | using TianCheng.SystemCommon.Model; 9 | using TianCheng.SystemCommon.Services; 10 | 11 | namespace SamplesWebApi.Service 12 | { 13 | /// 14 | /// 部门服务的扩展处理 15 | /// 16 | public class DepartmentServiceOptionExt : IServiceExtOption 17 | { 18 | #region 构造方法 19 | /// 20 | /// 获取服务接口 21 | /// 22 | static private IServiceCollection _services; 23 | /// 24 | /// 构造方法 25 | /// 26 | /// 27 | public DepartmentServiceOptionExt(IServiceCollection services) 28 | { 29 | _services = services; 30 | } 31 | #endregion 32 | 33 | /// 34 | /// 设置扩展 35 | /// 36 | public void SetOption() 37 | { 38 | // 设置部门保存时的验证处理 39 | //DepartmentServiceOption.Option.SavingCheck = OnSavingCheck; 40 | 41 | //// 设置部门更新的后置处理 42 | //DepartmentServiceOption.Option.Updated = OnUpdated; 43 | 44 | } 45 | 46 | /// 47 | /// 部门信息的保存验证处理 48 | /// 49 | /// 50 | /// 51 | public void OnSavingCheck(DepartmentInfo entity, TokenLogonInfo logonInfo) 52 | { 53 | // 如果验证不通过,可以通过抛出异常的形式终止保存操作,系统会将异常信息按Json形式返回到调用端。 54 | // ApiException.ThrowBadRequest("部门信息自定义异常信息"); 55 | } 56 | 57 | /// 58 | /// 保存后置处理 59 | /// 60 | /// 61 | /// 62 | /// 63 | public void OnUpdated(DepartmentInfo newEntity, DepartmentInfo oldEntity, TokenLogonInfo logonInfo) 64 | { 65 | IServiceProvider _ServiceProvider = _services.BuildServiceProvider(); 66 | // 部门的主管修改后,需要修改企业的申请 67 | // CompanyApplyService companyApplyService = (CompanyApplyService)_ServiceProvider.GetService(typeof(CompanyApplyService)); 68 | // if (companyApplyService != null) 69 | // { 70 | // companyApplyService.OnDepartmentChange(newEntity, oldEntity, logonInfo); 71 | // } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using TianCheng.SystemCommon.Services; 8 | using Microsoft.AspNetCore.Hosting; 9 | using AutoMapper.Configuration; 10 | using Microsoft.Extensions.Configuration; 11 | 12 | namespace SamplesWebApi.Controllers 13 | { 14 | /// 15 | /// 16 | /// 17 | [Route("api/[controller]")] 18 | public class ValuesController : Controller 19 | { 20 | //private static ServiceCollection _service; 21 | private readonly MenuService MenuService; 22 | /// 23 | /// 24 | /// 25 | /// 26 | public ValuesController( MenuService menuService) 27 | { 28 | //_service = serviceCollection; 29 | MenuService = menuService; 30 | } 31 | 32 | /// 33 | /// GET api/values 34 | /// 35 | /// 36 | [HttpGet] 37 | public IEnumerable Get() 38 | { 39 | //var provider = _service.BuildServiceProvider(); 40 | //var depService = provider.GetService(); 41 | 42 | MenuService.SaveSubMenu("测试111s", 1, "test", "测试主菜单"); 43 | 44 | 45 | 46 | return new string[] { "value1", "value2" }; 47 | } 48 | 49 | /// 50 | /// GET api/values/5 51 | /// 52 | /// 53 | /// 54 | [HttpGet("{id}")] 55 | public string Get(int id) 56 | { 57 | return "value"; 58 | } 59 | 60 | /// 61 | /// POST api/values 62 | /// 63 | /// 64 | [HttpPost] 65 | public void Post([FromBody]string value) 66 | { 67 | } 68 | 69 | /// 70 | /// PUT api/values/5 71 | /// 72 | /// 73 | /// 74 | [HttpPut("{id}")] 75 | public void Put(int id, [FromBody]string value) 76 | { 77 | } 78 | 79 | /// 80 | /// DELETE api/values/5 81 | /// 82 | /// 83 | [HttpDelete("{id}")] 84 | public void Delete(int id) 85 | { 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Services/AutoRun/TimerRecordService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using TianCheng.BaseService; 4 | using TianCheng.SystemCommon.DAL; 5 | using TianCheng.SystemCommon.Model; 6 | 7 | namespace TianCheng.SystemCommon.Services 8 | { 9 | /// 10 | /// 定时运行记录 [ Service ] 11 | /// 12 | public class TimerRecordService : MongoBusinessService 13 | { 14 | #region 构造方法 15 | /// 16 | /// 构造方法 17 | /// 18 | /// 19 | public TimerRecordService(TimerRecordDAL dal) : base(dal) 20 | { 21 | 22 | } 23 | #endregion 24 | 25 | /// 26 | /// 新增 27 | /// 28 | /// 29 | public void Append(TimerRecordInfo info) 30 | { 31 | info.RunTime = DateTime.Now; 32 | info.CreateDate = DateTime.Now; 33 | info.UpdateDate = DateTime.Now; 34 | _Dal.InsertObject(info); 35 | } 36 | /// 37 | /// 更新 38 | /// 39 | /// 40 | public void Update(TimerRecordInfo info) 41 | { 42 | info.UpdateDate = DateTime.Now; 43 | info.EndTime = DateTime.Now; 44 | _Dal.UpdateObject(info); 45 | } 46 | /// 47 | /// 按条件查询数据 48 | /// 49 | /// 50 | /// 51 | public override IQueryable _Filter(TimerRecordQuery input) 52 | { 53 | var query = _Dal.Queryable(); 54 | 55 | #region 查询条件 56 | // 按定时器名称模糊查询 57 | if (!string.IsNullOrWhiteSpace(input.Name)) 58 | { 59 | query = query.Where(e => !string.IsNullOrEmpty(e.Name) && e.Name.Contains(input.Name)); 60 | } 61 | #endregion 62 | 63 | #region 设置排序规则 64 | 65 | //设置排序方式 66 | switch (input.Sort.Property) 67 | { 68 | case "name": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Name) : query.OrderByDescending(e => e.Name); break; } 69 | case "date": { query = input.Sort.IsAsc ? query.OrderBy(e => e.UpdateDate) : query.OrderByDescending(e => e.UpdateDate); break; } 70 | default: { query = query.OrderByDescending(e => e.UpdateDate); break; } 71 | } 72 | #endregion 73 | 74 | //返回查询结果 75 | return query; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Services/Common/DataImport/FilePathServiceExt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TianCheng.BaseService.Services; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.Company.Services 6 | { 7 | /// 8 | /// 文件路径服务,扩展处理 9 | /// 10 | static public class FilePathServiceExt 11 | { 12 | /// 13 | /// 转换路径 14 | /// 15 | /// 16 | /// 17 | static private string WebPath(string diskPath) 18 | { 19 | return diskPath.Replace('\\', '/'); 20 | } 21 | 22 | #region 导入员工信息文件 23 | /// 24 | /// 导入员工信息文件保存路径 25 | /// 26 | static private string DataImportEmployees { get; } = System.IO.Path.Combine(FilePathService.RootPath, "Files\\DataImport\\Employees"); 27 | 28 | /// 29 | /// 导入的员工信息文件名 30 | /// 31 | static public FileNameView DataImportEmployeesFileName(this FilePathService fpservice) 32 | { 33 | string file = $"{Guid.NewGuid().ToString("N")}.xlsx"; 34 | string webPath = WebPath(DataImportEmployees); 35 | return new FileNameView 36 | { 37 | DiskRoot = FilePathService.RootPath, 38 | WebRoot = "~", 39 | DiskPath = DataImportEmployees, 40 | WebPath = $"~/{webPath}", 41 | FileName = file, 42 | FileExtName = "xlsx", 43 | DiskFileFullName = $"{DataImportEmployees}\\{file}", 44 | WebFileFullName = $"~/{webPath}/{file}" 45 | }; 46 | } 47 | /// 48 | /// 导入失败时的导入失败报表文件名 49 | /// 50 | /// 51 | /// 52 | /// 53 | static public FileNameView DataImportEmployeesFailFileName(this FilePathService fpservice, string batch) 54 | { 55 | string file = $"fail-{batch}.xlsx"; 56 | string webPath = WebPath(DataImportEmployees); 57 | return new FileNameView 58 | { 59 | DiskRoot = FilePathService.RootPath, 60 | WebRoot = "~", 61 | DiskPath = DataImportEmployees, 62 | WebPath = $"~/{webPath}", 63 | FileName = file, 64 | FileExtName = "xlsx", 65 | DiskFileFullName = $"{DataImportEmployees}\\{file}", 66 | WebFileFullName = $"~/{webPath}/{file}" 67 | }; 68 | } 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Service/MenuServiceOptionExt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using TianCheng.BaseService; 7 | using TianCheng.SystemCommon.Model; 8 | using TianCheng.SystemCommon.Services; 9 | 10 | namespace SamplesWebApi.Service 11 | { 12 | /// 13 | /// 菜单服务的扩展处理 14 | /// 15 | public class MenuServiceOptionExt : IServiceExtOption 16 | { 17 | #region 构造方法 18 | /// 19 | /// 获取服务接口 20 | /// 21 | private IServiceCollection _Service; 22 | /// 23 | /// 构造方法 24 | /// 25 | /// 26 | public MenuServiceOptionExt(IServiceCollection service) 27 | { 28 | _Service = service; 29 | } 30 | #endregion 31 | 32 | /// 33 | /// 设置扩展 34 | /// 35 | public void SetOption() 36 | { 37 | //初始化菜单数据 38 | MenuServiceOption.Option.InitMenuData = InitMenuData; 39 | } 40 | 41 | /// 42 | /// 初始化菜单数据 43 | /// 44 | /// 已设置的菜单信息 45 | public void InitMenuData(List mainList) 46 | { 47 | 48 | 49 | MenuMainInfo mainSystem = new MenuMainInfo() { Name = "系统管理", Link = "System", Icon = "el-icon-setting", Type = MenuType.ManageSingle, Index = 6 }; 50 | mainSystem.SubMenu.Add(new MenuSubInfo() { Name = "部门管理", Link = "System.Departments", Type = MenuType.ManageSingle, Index = 1 }); 51 | mainSystem.SubMenu.Add(new MenuSubInfo() { Name = "菜单管理", Link = "System.Menus", Type = MenuType.ManageSingle, Index = 3 }); 52 | mainSystem.SubMenu.Add(new MenuSubInfo() { Name = "员工管理", Link = "System.Employees", Type = MenuType.ManageSingle, Index = 5 }); 53 | mainSystem.SubMenu.Add(new MenuSubInfo() { Name = "角色管理", Link = "System.Roles", Type = MenuType.ManageSingle, Index = 7 }); 54 | 55 | MenuMainInfo mainPersonal = new MenuMainInfo() { Name = "个人中心", Link = "PersonalCenter", Icon = "el-icon-setting", Type = MenuType.ManageSingle, Index = 5 }; 56 | mainPersonal.SubMenu.Add(new MenuSubInfo() { Name = "基本信息", Link = "PersonalCenter.Common", Type = MenuType.ManageSingle, Index = 2 }); 57 | mainPersonal.SubMenu.Add(new MenuSubInfo() { Name = "修改密码", Link = "PersonalCenter.ChangePwd", Type = MenuType.ManageSingle, Index = 4 }); 58 | 59 | mainList.Clear(); 60 | mainList.Add(mainSystem); 61 | mainList.Add(mainPersonal); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Controller/Common/SystemController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Swashbuckle.AspNetCore.Annotations; 3 | using System.Linq; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.Services; 7 | 8 | namespace TianCheng.SystemCommon.Controller 9 | { 10 | /// 11 | /// 系统控制 12 | /// 13 | [Route("api/System")] 14 | public class SystemController : DataController 15 | { 16 | #region 构造方法 17 | private readonly EmployeeService _EmployeeService; 18 | private readonly FunctionService _FunctionService; 19 | private readonly MenuService _MenuService; 20 | private readonly RoleService _RoleService; 21 | /// 22 | /// 构造方法 23 | /// 24 | /// 25 | /// 26 | /// 27 | /// 28 | public SystemController(EmployeeService employeeService, FunctionService functionService, MenuService menuService, RoleService roleService) 29 | { 30 | _EmployeeService = employeeService; 31 | _FunctionService = functionService; 32 | _MenuService = menuService; 33 | _RoleService = roleService; 34 | } 35 | #endregion 36 | 37 | /// 38 | /// 重置数据库 39 | /// 40 | /// 清除已有数据,初始成默认数据。/r/n初始化数据包括:菜单、功能点、角色、用户 41 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.System.Init")] 42 | [SwaggerOperation(Tags = new[] { "系统管理-系统设置" })] 43 | [HttpPost("InitDB")] 44 | public void Init() 45 | { 46 | //初始化系统菜单 47 | _MenuService.Init(); 48 | //初始化系统功能点列表 49 | _FunctionService.Init(); 50 | //初始化角色信息 51 | _RoleService.InitAdmin(); 52 | //初始化用户信息 53 | _EmployeeService.UpdateAdmin(); 54 | } 55 | 56 | /// 57 | /// 初始化数据库 58 | /// 59 | /// 无需登录的初始化数据库,必须系统中无用户信息时才可执行 60 | [SwaggerOperation(Tags = new[] { "系统管理-系统设置" })] 61 | [HttpPost("Init")] 62 | public void UpdateAdmin() 63 | { 64 | var employeeService = ServiceLoader.GetService(); 65 | if (employeeService.SearchQueryable().Count() > 0) 66 | { 67 | ApiException.ThrowBadRequest("系统中拥有用户信息,无密码初始化失败。您可以通过管理员账号登陆后再初始化"); 68 | } 69 | Init(); 70 | } 71 | 72 | ///// 73 | ///// 备份数据库 74 | ///// 75 | //[SwaggerOperation(Tags = new[] { "系统管理-系统设置" })] 76 | //[HttpPost("MongoDB/bak")] 77 | //public void MongoDBBak() 78 | //{ 79 | // var psi = new ProcessStartInfo("shell\\BakMongoDB.bat"); 80 | // //启动 81 | // var proc = Process.Start(psi); 82 | //} 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/DAL/Common/EmployeeDAL.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Driver; 2 | using System; 3 | using TianCheng.DAL; 4 | using TianCheng.DAL.MongoDB; 5 | using TianCheng.SystemCommon.Model; 6 | 7 | namespace TianCheng.SystemCommon.DAL 8 | { 9 | /// 10 | /// 员工信息 [数据持久化] 11 | /// 12 | [DBMapping("system_employee")] 13 | public class EmployeeDAL : MongoOperation 14 | { 15 | /// 16 | /// 批量更新部门名称 17 | /// 18 | /// 19 | public void UpdateDepartmentInfo(DepartmentInfo departmentInfo) 20 | { 21 | // 验证参数 22 | if (departmentInfo.IsEmpty) 23 | { 24 | return; 25 | } 26 | // 设置查询条件 27 | FilterDefinition filter = Builders.Filter.Eq("Department.Id", departmentInfo.Id.ToString()); 28 | // 设置更新内容 29 | UpdateDefinition ud = Builders.Update.Set("Department.Name", departmentInfo.Name) 30 | .Set("ParentDepartment.Id", departmentInfo.ParentId) 31 | .Set("ParentDepartment.Name", departmentInfo.ParentName) 32 | .Set("ParentDepartment.Ids", departmentInfo.ParentsIds); 33 | try 34 | { 35 | UpdateResult result = MongoCollection.UpdateMany(filter, ud); 36 | } 37 | catch (System.TimeoutException te) 38 | { 39 | DBLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString()); 40 | throw; 41 | } 42 | catch (Exception ex) 43 | { 44 | DBLog.Logger.Warning(ex, "操作异常终止。"); 45 | throw; 46 | } 47 | } 48 | /// 49 | /// 批量更新角色名称 50 | /// 51 | /// 52 | public void UpdateRoleInfo(RoleInfo roleInfo) 53 | { 54 | // 验证参数 55 | if (roleInfo.IsEmpty) 56 | { 57 | return; 58 | } 59 | // 设置查询条件 60 | FilterDefinition filter = Builders.Filter.Eq("Role.Id", roleInfo.Id.ToString()); 61 | // 设置更新内容 62 | UpdateDefinition ud = Builders.Update.Set("Role.Name", roleInfo.Name); 63 | try 64 | { 65 | UpdateResult result = MongoCollection.UpdateMany(filter, ud); 66 | } 67 | catch (System.TimeoutException te) 68 | { 69 | DBLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString()); 70 | throw; 71 | } 72 | catch (Exception ex) 73 | { 74 | DBLog.Logger.Warning(ex, "操作异常终止。"); 75 | throw; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /samples/SamplesWebApi/Service/EmployeeServiceOptionExt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using TianCheng.BaseService; 7 | using TianCheng.SystemCommon.Model; 8 | using TianCheng.SystemCommon.Services; 9 | 10 | namespace SamplesWebApi.Service 11 | { 12 | /// 13 | /// 员工服务的扩展处理 14 | /// 15 | public class EmployeeServiceOptionExt : IServiceExtOption 16 | { 17 | #region 构造方法 18 | /// 19 | /// 获取服务接口 20 | /// 21 | static private IServiceCollection _services; 22 | /// 23 | /// 构造方法 24 | /// 25 | /// 26 | public EmployeeServiceOptionExt(IServiceCollection services) 27 | { 28 | _services = services; 29 | } 30 | #endregion 31 | 32 | /// 33 | /// 设置扩展 34 | /// 35 | public void SetOption() 36 | { 37 | //设置角色是否必填 38 | //EmployeeServiceOption.Option.RequiredRole = true; 39 | ////设置部门信息是否必填 40 | //EmployeeServiceOption.Option.RequiredDepartment = true; 41 | //// 排列方式为执行顺序的方式 42 | //// 设置员工保存时的验证处理 43 | //EmployeeServiceOption.Option.SavingCheck = OnSavingCheck; 44 | //// 设置员工保存的前置处理 45 | //EmployeeServiceOption.Option.Saving = OnSaving; 46 | //// 设置员工更新的后置处理 47 | //EmployeeServiceOption.Option.Updated = OnUpdated; 48 | //// 设置员工保存的后置处理 49 | //EmployeeServiceOption.Option.Saved = OnSaved; 50 | } 51 | 52 | #region 事件处理 53 | /// 54 | /// 员工保存时的验证处理 55 | /// 56 | /// 57 | /// 58 | public void OnSavingCheck(EmployeeInfo entity, TokenLogonInfo logonInfo) 59 | { 60 | // 如果验证不通过,可以通过抛出异常的形式终止保存操作,系统会将异常信息按Json形式返回到调用端。 61 | // ApiException.ThrowBadRequest("员工信息自定义异常信息"); 62 | } 63 | /// 64 | /// 员工保存的前置处理 65 | /// 66 | /// 67 | /// 68 | public void OnSaving(EmployeeInfo entity, TokenLogonInfo logonInfo) 69 | { 70 | 71 | } 72 | 73 | /// 74 | /// 员工更新的后置处理 75 | /// 76 | /// 77 | /// 78 | /// 79 | public void OnUpdated(EmployeeInfo newEentity, EmployeeInfo oldEntity, TokenLogonInfo logonInfo) 80 | { 81 | 82 | } 83 | /// 84 | /// 员工保存的后置处理 85 | /// 86 | /// 87 | /// 88 | public void OnSaved(EmployeeInfo entity, TokenLogonInfo logonInfo) 89 | { 90 | 91 | } 92 | #endregion 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Model/Area/AmapDistricts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TianCheng.SystemCommon.Model 5 | { 6 | /// 7 | /// 高德返回行政区域信息 8 | /// 9 | public class AmapDistricts 10 | { 11 | /// 12 | /// 返回结果状态值 值为0或1,0表示失败;1表示成功 13 | /// 14 | public int Status { get; set; } 15 | /// 16 | /// 返回状态说明 返回状态说明,status为0时,info返回错误原因,否则返回“OK”。 17 | /// 18 | public string Info { get; set; } 19 | 20 | /// 21 | /// 状态码 返回状态说明,1000代表正确,详情参阅info状态表 22 | /// 23 | public string InfoCode { get; set; } 24 | 25 | /// 26 | /// 建议结果列表 27 | /// 28 | public SuggestionInfo Suggestion { get; set; } = new SuggestionInfo(); 29 | 30 | /// 31 | /// 行政区列表 32 | /// 33 | public List Districts { get; set; } = new List(); 34 | } 35 | /// 36 | /// 建议结果列表 37 | /// 38 | public class SuggestionInfo 39 | { 40 | /// 41 | /// 建议关键字列表 42 | /// 43 | public List keywords { get; set; } 44 | /// 45 | /// 建议城市列表 46 | /// 47 | public List cites { get; set; } 48 | } 49 | /// 50 | /// 行政区信息 51 | /// 52 | public class DistrictInfo 53 | { 54 | /// 55 | /// 城市编码 56 | /// 57 | public object CityCode { get; set; } 58 | /// 59 | /// 区域编码 60 | /// 61 | public string CityCodeString 62 | { 63 | get 64 | { 65 | if (CityCode is String) 66 | { 67 | return CityCode.ToString(); 68 | 69 | } 70 | return string.Empty; 71 | //if (Level == "country" || Level == "province") 72 | //{ 73 | // return string.Empty; 74 | //} 75 | } 76 | } 77 | /// 78 | /// 区域编码 省份时传递[] 城市时传递编码 79 | /// 80 | public string Adcode { get; set; } 81 | 82 | /// 83 | /// 行政区名称 84 | /// 85 | public string Name { get; set; } 86 | /// 87 | /// 行政区边界坐标点 88 | /// 89 | public string Polyline { get; set; } 90 | /// 91 | /// 城市中心点 92 | /// 93 | public string Center { get; set; } 94 | 95 | /// 96 | /// 行政区划级别 97 | /// 98 | /// 99 | /// country:国家 100 | /// province:省份(直辖市会在province和city显示) 101 | /// city:市(直辖市会在province和city显示) 102 | /// district:区县 103 | /// street:街道 104 | /// 105 | public string Level { get; set; } 106 | 107 | /// 108 | /// 下级行政区列表 109 | /// 110 | public List Districts { get; set; } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Services/Common/LoginHistoryService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using System.Linq; 3 | using TianCheng.BaseService; 4 | using TianCheng.Model; 5 | using TianCheng.SystemCommon.DAL; 6 | using TianCheng.SystemCommon.Model; 7 | 8 | namespace TianCheng.SystemCommon.Services 9 | { 10 | /// 11 | /// 登录记录管理 [ Service ] 12 | /// 13 | public class LoginHistoryService : MongoBusinessService 14 | { 15 | #region 构造方法 16 | /// 17 | /// 构造方法 18 | /// 19 | /// 20 | public LoginHistoryService(LoginHistoryDAL dal) : base(dal) 21 | { 22 | } 23 | #endregion 24 | 25 | 26 | /// 27 | /// 按条件查询数据 28 | /// 29 | /// 30 | /// 31 | public override IQueryable _Filter(LoginHistoryQuery input) 32 | { 33 | var query = _Dal.Queryable(); 34 | //_logger.LogInformation("this is a log test: input.code:{0}, input.key:{1}", input.Name, input.State); 35 | // var query = _Dal.Queryable(); 36 | 37 | #region 查询条件 38 | // 根据查询的关键字查询 39 | if (!string.IsNullOrWhiteSpace(input.Key)) 40 | { 41 | query = query.Where(e => (!string.IsNullOrEmpty(e.Name) && e.Name.Contains(input.Key)) || 42 | (!string.IsNullOrEmpty(e.DepartmentName) && e.DepartmentName.Contains(input.Key)) || 43 | (!string.IsNullOrEmpty(e.IpAddressCityName) && e.IpAddressCityName.Contains(input.Key)) || 44 | (!string.IsNullOrEmpty(e.IpAddress) && e.IpAddress.Contains(input.Key))); 45 | } 46 | #endregion 47 | 48 | #region 设置排序规则 49 | switch (input.Sort.Property) 50 | { 51 | case "name": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Name) : query.OrderByDescending(e => e.Name); break; } 52 | case "departmentName": { query = input.Sort.IsAsc ? query.OrderBy(e => e.DepartmentName) : query.OrderByDescending(e => e.DepartmentName); break; } 53 | case "ipAddress": { query = input.Sort.IsAsc ? query.OrderBy(e => e.IpAddress) : query.OrderByDescending(e => e.IpAddress); break; } 54 | case "date": { query = input.Sort.IsAsc ? query.OrderBy(e => e.CreateDate) : query.OrderByDescending(e => e.CreateDate); break; } 55 | default: { query = query.OrderByDescending(e => e.CreateDate); break; } 56 | } 57 | #endregion 58 | 59 | //返回查询结果 60 | return query; 61 | } 62 | 63 | /// 64 | /// 登录事件处理 65 | /// 66 | /// 67 | internal static void OnLogin(EmployeeInfo employee) 68 | { 69 | // 1、记录登录信息 70 | // 2、如果登录用户需要验证IP地址,验证 71 | if (employee.LoginType == LoginVerifierType.IpAddress) 72 | { 73 | // 获取用户所在部门的IP地址范围 74 | // 比较用户的IP地址 75 | IHttpContextAccessor accessor = ServiceLoader.GetService(); 76 | string userIp = accessor.HttpContext.Connection.RemoteIpAddress.ToString(); 77 | } 78 | if (employee.LoginType == LoginVerifierType.ShortRange) 79 | { 80 | 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Services/Industries/IndustryCategoryService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | using System.Linq; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.DAL; 7 | using TianCheng.SystemCommon.Model; 8 | 9 | namespace TianCheng.SystemCommon.Services 10 | { 11 | /// 12 | /// 行业分类 [ Service ] 13 | /// 14 | public class IndustryCategoryService : MongoBusinessService 15 | { 16 | #region 构造方法 17 | /// 18 | /// 构造方法 19 | /// 20 | /// 21 | /// 22 | /// 23 | public IndustryCategoryService(IndustryCategoryDAL dal, ILogger logger, IServiceProvider servicesProvider) 24 | : base(dal) 25 | { 26 | } 27 | #endregion 28 | 29 | #region 查询 30 | /// 31 | /// 按条件查询数据 32 | /// 33 | /// 34 | /// 35 | public override IQueryable _Filter(IndustryCategoryQuery input) 36 | { 37 | var query = _Dal.Queryable(); 38 | 39 | #region 查询条件 40 | //不显示删除的数据 41 | query = query.Where(e => e.IsDelete == false); 42 | 43 | // 按名称的模糊查询 44 | if (!string.IsNullOrWhiteSpace(input.Name)) 45 | { 46 | query = query.Where(e => !string.IsNullOrEmpty(e.Name) && e.Name.Contains(input.Name) || 47 | e.Industries != null && e.Industries.Any(i => e.Name.Contains(input.Name))); 48 | } 49 | #endregion 50 | 51 | #region 设置排序规则 52 | 53 | //设置排序方式 54 | switch (input.Sort.Property) 55 | { 56 | case "name": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Name) : query.OrderByDescending(e => e.Name); break; } 57 | case "date": { query = input.Sort.IsAsc ? query.OrderBy(e => e.UpdateDate) : query.OrderByDescending(e => e.UpdateDate); break; } 58 | default: { query = query.OrderByDescending(e => e.UpdateDate); break; } 59 | } 60 | #endregion 61 | 62 | //返回查询结果 63 | return query; 64 | } 65 | #endregion 66 | 67 | #region 新增 / 修改方法 68 | /// 69 | /// 保存的校验 70 | /// 71 | /// 72 | /// 73 | protected override void SavingCheck(IndustryCategoryInfo info, TokenLogonInfo logonInfo) 74 | { 75 | //数据验证 76 | if (string.IsNullOrWhiteSpace(info.Name)) 77 | { 78 | throw ApiException.BadRequest("行业分类名称不能为空"); 79 | } 80 | 81 | //检查行业名称不能重复 82 | var query = _Dal.Queryable().Where(e => !string.IsNullOrEmpty(e.Name) && e.Name.Equals(info.Name) && e.IsDelete == false); 83 | 84 | if (info.IsEmpty) 85 | { 86 | if (query.Count() > 0) 87 | { 88 | throw ApiException.BadRequest("行业分类不能重复"); 89 | } 90 | } 91 | else 92 | { 93 | string id = info.Id.ToString(); 94 | foreach (var item in query) 95 | { 96 | if (item.Id.ToString() != id) 97 | { 98 | throw ApiException.BadRequest("行业分类不能重复"); 99 | } 100 | } 101 | } 102 | } 103 | #endregion 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Services/Auth/AuthVisitorService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Claims; 4 | using System.Security.Principal; 5 | using TianCheng.BaseService; 6 | using TianCheng.BaseService.PlugIn; 7 | using TianCheng.Model; 8 | using TianCheng.SystemCommon.Model; 9 | 10 | namespace TianCheng.SystemCommon.Services 11 | { 12 | /// 13 | /// 游客权限设置 14 | /// 15 | public class AuthVisitorService : IAuthService 16 | { 17 | #region 构造方法 18 | private readonly TokenProviderOptions _tokenOptions; 19 | /// 20 | /// 构造方法 21 | /// 22 | /// 23 | public AuthVisitorService(Microsoft.Extensions.Configuration.IConfiguration configuration) 24 | { 25 | _tokenOptions = TokenProviderOptions.Load(configuration); 26 | } 27 | #endregion 28 | 29 | #region 访问接口时 完善用户权限 30 | /// 31 | /// 访问接口时 获取用户的角色信息 32 | /// 33 | static public Func OnLoadRole; 34 | 35 | /// 36 | /// 访问接口时 完善用户权限 37 | /// 38 | /// 39 | public void FillFunctionPolicy(ClaimsIdentity identity) 40 | { 41 | RoleView role = new RoleView(); 42 | // 如果有获取角色的委托方法,使用委托方法 43 | if (OnLoadRole != null) 44 | { 45 | role = OnLoadRole(identity); 46 | } 47 | else 48 | { 49 | // 暂不添加游客的角色获取逻辑 50 | } 51 | 52 | // 添加权限声明 53 | if (role == null) 54 | { 55 | throw ApiException.BadRequest("无法根据用户获取角色信息"); 56 | } 57 | if (role.FunctionPower.Count == 0) 58 | { 59 | throw ApiException.BadRequest("您没有任何权限,请与管理员联系"); 60 | } 61 | foreach (var function in role.FunctionPower) 62 | { 63 | identity.AddClaim(new Claim("function_policy", function.Policy)); 64 | } 65 | } 66 | #endregion 67 | 68 | #region 登录处理 69 | /// 70 | /// 登录时的事件处理 71 | /// 72 | static public Func> OnLogin; 73 | /// 74 | /// 登录 75 | /// 76 | /// 77 | /// 78 | /// 79 | public string Login(string account, string password) 80 | { 81 | account = account.Trim(); 82 | password = password.Trim(); 83 | List claims = new List(); 84 | // 如果有登录的委托方法,使用委托方法 85 | if (OnLogin != null) 86 | { 87 | claims = OnLogin(new LoginView { Account = account, Password = password }); 88 | } 89 | else 90 | { 91 | // 暂不添加游客的登录处理 92 | } 93 | 94 | claims.Add(new Claim("type", "AuthVisitorService")); 95 | 96 | var identity = new ClaimsIdentity(new GenericIdentity(account, "Token"), claims); 97 | string token = Jwt.GenerateJwtToken(account, identity, _tokenOptions); 98 | return token; 99 | } 100 | #endregion 101 | 102 | #region 退出处理 103 | /// 104 | /// 退出时的事件处理 105 | /// 106 | static public Action OnLogout; 107 | /// 108 | /// 109 | /// 110 | /// 111 | /// 112 | public void Logout(TokenLogonInfo logonInfo) 113 | { 114 | OnLogout?.Invoke(logonInfo); 115 | } 116 | #endregion 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/Controller/Area/AreaController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Swashbuckle.AspNetCore.Annotations; 3 | using System.Collections.Generic; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.Model; 7 | using TianCheng.SystemCommon.Services; 8 | 9 | namespace TianCheng.SystemCommon.Controller 10 | { 11 | /// 12 | /// 区域管理接口 13 | /// 14 | [Produces("application/json")] 15 | [Route("api/Area")] 16 | public class AreaController : DataController 17 | { 18 | #region 构造方法 19 | private readonly AreaService _Service; 20 | /// 21 | /// 构造方法 22 | /// 23 | /// 24 | public AreaController(AreaService service) 25 | { 26 | _Service = service; 27 | } 28 | #endregion 29 | 30 | #region 新增修改数据 31 | /// 32 | /// 初始化区域信息 33 | /// 34 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 35 | [HttpPost("InitArea")] 36 | public void InitArea() 37 | { 38 | _Service.DefaultInit(); 39 | } 40 | /// 41 | /// 新增 42 | /// 43 | /// 44 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 45 | [HttpPost("")] 46 | public ResultView Create([FromBody]AreaView view) 47 | { 48 | return _Service.Create(view, LogonInfo); 49 | } 50 | /// 51 | /// 修改 52 | /// 53 | /// 54 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 55 | [HttpPut("")] 56 | public ResultView Update([FromBody]AreaView view) 57 | { 58 | return _Service.Update(view, LogonInfo); 59 | } 60 | #endregion 61 | 62 | #region 查询 63 | /// 64 | /// 根据ID获取组织机构详情 65 | /// 66 | /// 详情 67 | /// 组织机构ID 68 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 69 | [HttpGet("{id}")] 70 | public AreaView SearchById(string id) 71 | { 72 | return _Service.SearchById(id); 73 | } 74 | /// 75 | /// 查询组织结构列表(分页 + 查询条件) 76 | /// 77 | /// 78 | /// 排序规则包含: 79 | /// 80 | /// name : 按名称排列 81 | /// code : 按编码排列 82 | /// date : 按最后更新时间排列 为默认排序 83 | /// 84 | /// 85 | /// 查询信息。(包含分页信息、查询条件、排序条件) 86 | /// 查询 87 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 88 | [HttpPost("Search")] 89 | public PagedResult SearchPage([FromBody]AreaQuery queryInfo) 90 | { 91 | return _Service.FilterPage(queryInfo); 92 | } 93 | 94 | /// 95 | /// 获取所有省份列表 96 | /// 97 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 98 | [HttpGet("Province")] 99 | public List Province() 100 | { 101 | return _Service.Select(new AreaQuery { AreaType = AreaType.Province }); 102 | } 103 | 104 | /// 105 | /// 获取指定省份下的城市列表 106 | /// 107 | /// 108 | /// 109 | [SwaggerOperation(Tags = new[] { "系统管理-区域管理" })] 110 | [HttpGet("{provinceId}/City")] 111 | public List City(string provinceId) 112 | { 113 | return _Service.Select(new AreaQuery { AreaType = AreaType.City, SuperiorId = provinceId }); 114 | } 115 | #endregion 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Controller/Industries/IndustryCategoryController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using TianCheng.BaseService; 7 | using TianCheng.Model; 8 | using TianCheng.SystemCommon.Model; 9 | using TianCheng.SystemCommon.Services; 10 | 11 | namespace TianCheng.SystemCommon.Controller 12 | { 13 | /// 14 | /// 行业管理 15 | /// 16 | [Produces("application/json")] 17 | [Route("api/Industry/Category")] 18 | public class IndustryCategoryController : DataController 19 | { 20 | #region 构造方法 21 | private readonly IndustryCategoryService _Service; 22 | private readonly ILogger _logger; 23 | /// 24 | /// 构造方法 25 | /// 26 | /// 27 | /// 28 | public IndustryCategoryController(IndustryCategoryService service, ILogger logger) 29 | { 30 | _Service = service; 31 | _logger = logger; 32 | } 33 | #endregion 34 | 35 | #region 新增修改数据 36 | /// 37 | /// 新增行业分类 38 | /// 39 | /// 请求体中放置新增对象的信息 40 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.IndustryCategory.Create")] 41 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 42 | [Route("")] 43 | [HttpPost] 44 | public ResultView Create([FromBody]IndustryCategoryView view) 45 | { 46 | return _Service.Create(view, LogonInfo); 47 | } 48 | 49 | /// 50 | /// 修改行业分类 51 | /// 52 | /// 请求体中带入修改对象的信息 53 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.IndustryCategory.Update")] 54 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 55 | [Route("")] 56 | [HttpPut] 57 | public ResultView Update([FromBody]IndustryCategoryView view) 58 | { 59 | return _Service.Update(view, LogonInfo); 60 | } 61 | #endregion 62 | 63 | #region 数据删除 64 | /// 65 | /// 删除行业分类 66 | /// 67 | /// 要删除的对象id 68 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.IndustryCategory.Delete")] 69 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 70 | [Route("{id}")] 71 | [HttpDelete] 72 | public ResultView Delete(string id) 73 | { 74 | return _Service.Delete(id, LogonInfo); 75 | } 76 | #endregion 77 | 78 | #region 数据查询 79 | /// 80 | /// 查看行业分类详情 81 | /// 82 | /// 组织机构ID 83 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.IndustryCategory.SearchById")] 84 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 85 | [Route("{id}")] 86 | [HttpGet] 87 | public IndustryCategoryView SearchById(string id) 88 | { 89 | return _Service.SearchById(id); 90 | } 91 | 92 | /// 93 | /// 查询行业分类分页列表 94 | /// 95 | /// 96 | /// 排序规则包含: 97 | /// 98 | /// name : 按名称排列 99 | /// date : 按最后更新时间排列 为默认排序 100 | /// 101 | /// 102 | /// 103 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.IndustryCategory.SearchPage")] 104 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 105 | [Route("Search")] 106 | [HttpPost] 107 | public PagedResult SearchPage([FromBody]IndustryCategoryQuery queryInfo) 108 | { 109 | return _Service.FilterPage(queryInfo); 110 | } 111 | 112 | /// 113 | /// 获取行业的下拉列表数据(按分类排列) 114 | /// 115 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 116 | [Route("Select")] 117 | [HttpGet] 118 | public List Select() 119 | { 120 | var list = _Service._Filter(new IndustryCategoryQuery()); 121 | return AutoMapper.Mapper.Map>(list.ToList()); 122 | } 123 | #endregion 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Controller/Common/MenuController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | using System.Collections.Generic; 5 | using TianCheng.BaseService; 6 | using TianCheng.Model; 7 | using TianCheng.SystemCommon.Model; 8 | using TianCheng.SystemCommon.Services; 9 | 10 | namespace TianCheng.SystemCommon.Controller 11 | { 12 | /// 13 | /// 菜单管理 14 | /// 15 | [Produces("application/json")] 16 | [Route("api/Menu")] 17 | public class MenuController : DataController 18 | { 19 | #region 构造方法 20 | private readonly MenuService _Service; 21 | private readonly ILogger _logger; 22 | /// 23 | /// 构造方法 24 | /// 25 | /// 26 | /// 27 | public MenuController(MenuService service, ILogger logger) 28 | { 29 | _Service = service; 30 | _logger = logger; 31 | } 32 | #endregion 33 | 34 | #region 数据查询 35 | /// 36 | /// 查询单页面的菜单信息,以树形结构显示,无分页信息 37 | /// 38 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Tree")] 39 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 40 | [HttpGet("")] 41 | public List Tree() 42 | { 43 | return _Service.SearchMainTree(); 44 | } 45 | ///// 46 | ///// 查询所有的菜单信息,以树形结构显示,无分页信息 47 | ///// 48 | //[Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Tree")] 49 | //[SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 50 | //[Route("All")] 51 | //[HttpGet] 52 | //public List ALL() 53 | //{ 54 | // return _Service.ManageMultipleTree(); 55 | //} 56 | 57 | /// 58 | /// 查询单页面的菜单信息,以树形结构显示,无分页信息 59 | /// 60 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Tree")] 61 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 62 | [HttpGet("Single")] 63 | public List ManageSingleTree() 64 | { 65 | return _Service.SearchMainTree(MenuType.ManageSingle); 66 | } 67 | 68 | /// 69 | /// 查询多页面菜单信息,以树形结构显示,无分页信息 70 | /// 71 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Tree")] 72 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 73 | [HttpGet("Multiple")] 74 | public List ManageMultipleTree() 75 | { 76 | return _Service.SearchMainTree(MenuType.ManageMultiple); 77 | } 78 | #endregion 79 | 80 | /// 81 | /// 初始化菜单 清除已有菜单,重新设置默认菜单 82 | /// 83 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Init")] 84 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 85 | [HttpPost("Init")] 86 | public void Init() 87 | { 88 | _Service.Init(); 89 | } 90 | 91 | #region 新增修改数据 92 | /// 93 | /// 新增一个主菜单 94 | /// 95 | /// 请求体中放置新增对象的信息 96 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Create")] 97 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 98 | [HttpPost("")] 99 | public ResultView Create([FromBody]MenuMainView view) 100 | { 101 | return _Service.Create(view, LogonInfo); 102 | } 103 | 104 | /// 105 | /// 修改一个主菜单 106 | /// 107 | /// 请求体中带入修改对象的信息 108 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Update")] 109 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 110 | [HttpPut("")] 111 | public ResultView Update([FromBody]MenuMainView view) 112 | { 113 | return _Service.Update(view, LogonInfo); 114 | } 115 | 116 | #endregion 117 | 118 | #region 数据删除 119 | /// 120 | /// 删除一个主菜单 121 | /// 122 | /// 要删除的对象id 123 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Menu.Remove")] 124 | [SwaggerOperation(Tags = new[] { "系统管理-权限管理" })] 125 | [HttpDelete("Remove/{id}")] 126 | public ResultView Remove(string id) 127 | { 128 | return _Service.Remove(id, LogonInfo); 129 | } 130 | #endregion 131 | } 132 | } 133 | 134 | -------------------------------------------------------------------------------- /src/Services/Industries/IndustryService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.DAL; 7 | using TianCheng.SystemCommon.Model; 8 | 9 | namespace TianCheng.SystemCommon.Services 10 | { 11 | /// 12 | /// 行业信息 13 | /// 14 | public class IndustryService : MongoBusinessService 15 | { 16 | #region 构造方法 17 | /// 18 | /// 构造方法 19 | /// 20 | /// 21 | /// 22 | public IndustryService(IndustryDAL dal, ILogger logger) : base(dal) 23 | { 24 | 25 | } 26 | #endregion 27 | 28 | #region 查询方法 29 | /// 30 | /// 根据编码列表查询行业 31 | /// 32 | /// 33 | /// 34 | public List SearchByCodeList(List codeList) 35 | { 36 | return _Dal.Queryable().Where(e => codeList.Contains(e.Code)).ToList(); 37 | } 38 | 39 | /// 40 | /// 按条件查询数据 41 | /// 42 | /// 43 | /// 44 | public override IQueryable _Filter(IndustryQuery input) 45 | { 46 | var query = _Dal.Queryable(); 47 | 48 | #region 查询条件 49 | 50 | // 按编码、名称、说明模糊查询 51 | if (!string.IsNullOrWhiteSpace(input.Key)) 52 | { 53 | query = query.Where(e => (!string.IsNullOrEmpty(e.Name) && e.Name.Contains(input.Key)) || 54 | (!string.IsNullOrEmpty(e.Code) && e.Code.Contains(input.Key)) || 55 | (!string.IsNullOrEmpty(e.Remarks) && e.Remarks.Contains(input.Key))); 56 | } 57 | 58 | // 根据行业ID列表 59 | if (input.IndustryIdList != null && input.IndustryIdList.Count > 0) 60 | { 61 | List IdList = new List(); 62 | foreach (string id in input.IndustryIdList) 63 | { 64 | if (MongoDB.Bson.ObjectId.TryParse(id, out MongoDB.Bson.ObjectId objId)) 65 | { 66 | IdList.Add(objId); 67 | } 68 | } 69 | 70 | query = query.Where(e => IdList.Contains(e.Id)); 71 | } 72 | 73 | #endregion 74 | 75 | #region 设置排序规则 76 | //设置排序方式 77 | switch (input.Sort.Property) 78 | { 79 | case "code": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Code) : query.OrderByDescending(e => e.Code); break; } 80 | case "name": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Name) : query.OrderByDescending(e => e.Name); break; } 81 | case "remarks": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Remarks) : query.OrderByDescending(e => e.Remarks); break; } 82 | case "date": { query = input.Sort.IsAsc ? query.OrderBy(e => e.UpdateDate) : query.OrderByDescending(e => e.UpdateDate); break; } 83 | default: { query = query.OrderByDescending(e => e.UpdateDate); break; } 84 | } 85 | #endregion 86 | 87 | //返回查询结果 88 | return query; 89 | } 90 | #endregion 91 | 92 | #region 新增 / 修改方法 93 | /// 94 | /// 保存验证处理 95 | /// 96 | /// 97 | /// 98 | protected override void SavingCheck(IndustryInfo info, TokenLogonInfo logonInfo) 99 | { 100 | //行业名称不能为空 101 | if (string.IsNullOrWhiteSpace(info.Name)) 102 | { 103 | throw ApiException.BadRequest("行业名称不能为空"); 104 | } 105 | //行业名称不能重复 106 | var query = _Dal.Queryable().Where(e => e.Name == info.Name).ToList(); 107 | if (!info.IsEmpty)//修改时过滤本身的ID 108 | { 109 | string id = info.Id.ToString(); 110 | for (int i = 0; i < query.Count; i++) 111 | { 112 | if (query[i].Id.ToString() == id) 113 | { 114 | query.RemoveAt(i); 115 | break; 116 | } 117 | } 118 | } 119 | if (query.Count() > 0) 120 | { 121 | throw ApiException.BadRequest("行业名称不能重复"); 122 | } 123 | } 124 | #endregion 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Controller/Industries/IndustryController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using TianCheng.BaseService; 7 | using TianCheng.Model; 8 | using TianCheng.SystemCommon.Model; 9 | using TianCheng.SystemCommon.Services; 10 | 11 | namespace TianCheng.SystemCommon.Controller 12 | { 13 | /// 14 | /// 行业管理 15 | /// 16 | [Produces("application/json")] 17 | [Route("api/Industry")] 18 | public class IndustryController : DataController 19 | { 20 | #region 构造方法 21 | private readonly IndustryService _Service; 22 | private readonly ILogger _logger; 23 | /// 24 | /// 构造方法 25 | /// 26 | /// 27 | /// 28 | public IndustryController(IndustryService service, ILogger logger) 29 | { 30 | _Service = service; 31 | _logger = logger; 32 | } 33 | #endregion 34 | 35 | #region 新增修改数据 36 | /// 37 | /// 新增行业 38 | /// 39 | /// 请求体中放置新增对象的信息 40 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Industry.Create")] 41 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 42 | [Route("")] 43 | [HttpPost] 44 | public ResultView Create([FromBody]IndustryView view) 45 | { 46 | return _Service.Create(view, LogonInfo); 47 | } 48 | 49 | /// 50 | /// 修改行业 51 | /// 52 | /// 请求体中带入修改对象的信息 53 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Industry.Update")] 54 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 55 | [Route("")] 56 | [HttpPut] 57 | public ResultView Update([FromBody]IndustryView view) 58 | { 59 | return _Service.Update(view, LogonInfo); 60 | } 61 | 62 | #endregion 63 | 64 | #region 数据删除 65 | /// 66 | /// 删除行业 67 | /// 68 | /// 要删除的对象id 69 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Industry.Delete")] 70 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 71 | [Route("{id}")] 72 | [HttpDelete] 73 | public ResultView Delete(string id) 74 | { 75 | return _Service.Delete(id, LogonInfo); 76 | } 77 | #endregion 78 | 79 | #region 数据查询 80 | /// 81 | /// 查看行业详情 82 | /// 83 | /// 组织机构ID 84 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Industry.SearchById")] 85 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 86 | [Route("{id}")] 87 | [HttpGet] 88 | public IndustryView SearchById(string id) 89 | { 90 | return _Service.SearchById(id); 91 | } 92 | 93 | /// 94 | /// 查询行业分页列表 95 | /// 96 | /// 97 | /// 排序规则包含: 98 | /// 99 | /// name : 按名称排列 100 | /// date : 按最后更新时间排列 为默认排序 101 | /// 102 | /// 103 | /// 104 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Industry.SearchPage")] 105 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 106 | [Route("Search")] 107 | [HttpPost] 108 | public PagedResult SearchPage([FromBody]IndustryQuery queryInfo) 109 | { 110 | return _Service.FilterPage(queryInfo); 111 | } 112 | 113 | /// 114 | /// 获取所有行业 115 | /// 116 | /// 117 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 118 | [HttpGet("SearchAll")] 119 | public List SearchAll() 120 | { 121 | var list = _Service._Filter(new IndustryQuery() { Sort = new QuerySort() { IsAsc = true, Property = "name" } }); 122 | return AutoMapper.Mapper.Map>(list.ToList()); 123 | } 124 | 125 | /// 126 | /// 获取可用行业列表 127 | /// 128 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Industry.Select")] 129 | [SwaggerOperation(Tags = new[] { "系统管理-行业管理" })] 130 | [HttpGet("Select")] 131 | public List Select() 132 | { 133 | IndustryQuery query = new IndustryQuery(); 134 | return _Service.Select(query); 135 | } 136 | #endregion 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Model/Common/ViewModel/EmployeeView.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 员工信息 [查看对象] 9 | /// 10 | public class EmployeeView : BaseViewModel 11 | { 12 | #region 基本信息 13 | /// 14 | /// 员工编码 15 | /// 16 | [JsonProperty("code")] 17 | public string Code { get; set; } 18 | 19 | /// 20 | /// 昵称 21 | /// 22 | [JsonProperty("nickname")] 23 | public string Nickname { get; set; } 24 | /// 25 | /// 头像 26 | /// 27 | [JsonProperty("headimg")] 28 | public string HeadImg { get; set; } 29 | #endregion 30 | 31 | #region 联系信息 32 | /// 33 | /// 手机电话 34 | /// 35 | [JsonProperty("mobile")] 36 | public string Mobile { get; set; } 37 | /// 38 | /// 座机电话 39 | /// 40 | [JsonProperty("telephone")] 41 | public string Telephone { get; set; } 42 | /// 43 | /// 联系邮箱 44 | /// 45 | [JsonProperty("email")] 46 | public string Email { get; set; } 47 | /// 48 | /// 联系地址 49 | /// 50 | [JsonProperty("address")] 51 | public string Address { get; set; } 52 | #endregion 53 | 54 | #region 登录信息 55 | /// 56 | /// 登录账号 57 | /// 58 | [JsonProperty("logonAccount")] 59 | public string LogonAccount { get; set; } 60 | /// 61 | /// 登录密码 62 | /// 63 | [JsonProperty("logonPassword")] 64 | public string LogonPassword { get; set; } 65 | #endregion 66 | 67 | #region 登录令牌信息 68 | /// 69 | /// 动态令牌Id 70 | /// 71 | [JsonProperty("secureId")] 72 | public string SecureKeyId { get; set; } 73 | /// 74 | /// 动态令牌号 75 | /// 76 | [JsonProperty("secureMark")] 77 | public string SecureKeyMark { get; set; } 78 | #endregion 79 | 80 | #region 部门信息 81 | 82 | /// 83 | /// 部门信息 84 | /// 85 | [JsonProperty("department")] 86 | public SelectView Department { get; set; } 87 | 88 | #endregion 89 | 90 | #region 角色信息 91 | 92 | /// 93 | /// 角色信息 94 | /// 95 | [JsonProperty("role")] 96 | public SelectView Role { get; set; } 97 | 98 | #endregion 99 | 100 | #region 扩展信息 101 | /// 102 | /// 性别 103 | /// 104 | [JsonProperty("gender")] 105 | public UserGender Gender { get; set; } 106 | 107 | /// 108 | /// 生日 109 | /// 110 | [JsonProperty("birthday")] 111 | public DateTime? Birthday { get; set; } 112 | 113 | /// 114 | /// 学历 115 | /// 116 | [JsonProperty("education")] 117 | public string Education { get; set; } 118 | 119 | /// 120 | /// 血型 121 | /// 122 | [JsonProperty("bloodType")] 123 | public string BloodType { get; set; } 124 | /// 125 | /// 职称 126 | /// 127 | [JsonProperty("title")] 128 | public string Title { get; set; } 129 | /// 130 | /// 职务 131 | /// 132 | [JsonProperty("position")] 133 | public string Position { get; set; } 134 | /// 135 | /// 籍贯 136 | /// 137 | [JsonProperty("nativePlace")] 138 | public string NativePlace { get; set; } 139 | /// 140 | /// 身份证号 141 | /// 142 | [JsonProperty("idnumber")] 143 | public string IdNumber { get; set; } 144 | #endregion 145 | 146 | #region 状态 147 | /// 148 | /// "状态(1-可用,3-锁住,5-禁用) 149 | /// 新增修改时,不用设置,列表时需要根据具体值判断如果现实数据。如果为1时显示‘禁用’按钮,为3时显示‘登录解锁’按钮,为5时显示‘取消禁用’按钮" 150 | /// 151 | [JsonProperty("state")] 152 | public UserState State { get; set; } 153 | 154 | /// 155 | /// 是否为系统级别数据 156 | /// 157 | [JsonProperty("isSystem")] 158 | public bool IsSystem { get; set; } 159 | #endregion 160 | 161 | /// 162 | /// 最后更新时间 163 | /// 164 | [JsonProperty("updateDate")] 165 | public string UpdateDate { get; set; } 166 | /// 167 | /// 最后更新人 168 | /// 169 | [JsonProperty("updaterName")] 170 | public string UpdaterName { get; set; } 171 | 172 | /// 173 | /// 扩展ID 用于员工信息的扩展 174 | /// 175 | [JsonProperty("extId")] 176 | public string ExtId { get; set; } 177 | 178 | /// 179 | /// 是否在职 180 | /// 181 | [JsonProperty("isDelete")] 182 | public bool IsDelete { get; set; } 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /src/Controller/Common/DataImportEmployeesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Swashbuckle.AspNetCore.Annotations; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using TianCheng.BaseService.PlugIn.Swagger; 8 | using TianCheng.BaseService.Services; 9 | using TianCheng.Company.Services; 10 | using TianCheng.DataImport.Controller; 11 | using TianCheng.DataImport.Model; 12 | using TianCheng.Model; 13 | using TianCheng.SystemCommon.DAL; 14 | using TianCheng.SystemCommon.Model; 15 | 16 | namespace TianCheng.SystemCommon.Controller 17 | { 18 | /// 19 | /// 员工数据导入 20 | /// 21 | [Produces("application/json")] 22 | [Route("api/Employees/Import")] 23 | public class DataImportEmployeesController 24 | : DataImportController 25 | { 26 | #region 构造方法 27 | /// 28 | /// 构造方法 29 | /// 30 | public DataImportEmployeesController() 31 | { 32 | 33 | } 34 | #endregion 35 | 36 | #region 查询导入列表 37 | /// 38 | /// 查询员工导入历史 39 | /// 40 | /// 41 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Employees.Import.Search")] 42 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 43 | [HttpGet("Search")] 44 | [SwaggerFileUpload] 45 | public List Search() 46 | { 47 | return importService.SearchMainByType(); 48 | } 49 | /// 50 | /// 查看导入详情 51 | /// 52 | /// 53 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 54 | [HttpGet("Single/{id}")] 55 | [SwaggerFileUpload] 56 | public DataImportIndexView Single(string id) 57 | { 58 | return importService.SearchMainById(id); 59 | } 60 | #endregion 61 | 62 | #region 保存上传文件并解析持久化 63 | /// 64 | /// 导入员工数据 上传导入企业文件,并返导入成功的文件信息 65 | /// 66 | /// 67 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Employees.Import.Upload")] 68 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 69 | [HttpPost("Upload")] 70 | [SwaggerFileUpload] 71 | public DataImportIndexView Upload() 72 | { 73 | // 获取存储导入企业的文件信息 74 | FileNameView fileName = filePath.DataImportEmployeesFileName(); 75 | // 将上传的文件保存至服务器磁盘 76 | SaveSingleFile(fileName.DiskFileFullName); 77 | // 解析上传的文件,并创建导入文件索引对象 78 | return importService.AnalyzFile(fileName, LogonInfo); 79 | } 80 | #endregion 81 | 82 | #region 获取需要导入的数据 83 | /// 84 | /// 获取需要导入的数据 一次最多获取20个 85 | /// 86 | /// 87 | /// 88 | /// 89 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 90 | [HttpGet("Step/{batch}-{start}")] 91 | public List Step(string batch, int start) 92 | { 93 | return importService.Step(batch, start); 94 | } 95 | #endregion 96 | 97 | #region 导入数据 98 | /// 99 | /// 导入一条数据 100 | /// 101 | /// 102 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 103 | [HttpPost("{importId}")] 104 | public DataImportDetailResult ImportSingle(string importId) 105 | { 106 | return importService.ImportSingle(importId, LogonInfo); 107 | } 108 | #endregion 109 | 110 | #region 完成数据导入 111 | /// 112 | /// 完成数据导入 113 | /// 114 | /// 115 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 116 | [HttpPatch("{batch}")] 117 | public void SetComplete(string batch) 118 | { 119 | FileNameView failFileName = filePath.DataImportEmployeesFailFileName(batch); 120 | importService.SetComplete(batch, failFileName, LogonInfo); 121 | } 122 | #endregion 123 | 124 | #region 删除导入数据 125 | /// 126 | /// 删除员工导入数据 127 | /// 128 | /// 129 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Employees.Import.Remove")] 130 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 131 | [HttpDelete("{batch}")] 132 | public ResultView Remove(string batch) 133 | { 134 | return importService.Remove(batch); 135 | } 136 | #endregion 137 | 138 | #region 下载导入失败结果 139 | /// 140 | /// 下载导入失败报表 141 | /// 142 | /// 143 | [SwaggerOperation(Tags = new[] { "企业管理-数据导入" })] 144 | [HttpGet("Download/Fail/{batch}")] 145 | public IActionResult DownloadFailFile(string batch) 146 | { 147 | ImportEmployeesService importService = ServiceLoader.GetService(); 148 | var main = importService.SearchMainByBatch(batch); 149 | if (!System.IO.File.Exists(main.FailImportFile.DiskFileFullName)) 150 | { 151 | importService.GenerateFailFile(main); 152 | } 153 | return PhysicalFile(main.FailImportFile.DiskFileFullName, "application/x-xls", $"{batch}.{main.FailImportFile.FileExtName}"); 154 | } 155 | #endregion 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/Controller/Common/RoleController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | using System.Collections.Generic; 5 | using TianCheng.BaseService; 6 | using TianCheng.Model; 7 | using TianCheng.SystemCommon.Model; 8 | using TianCheng.SystemCommon.Services; 9 | 10 | namespace TianCheng.SystemCommon.Controller 11 | { 12 | /// 13 | /// 角色管理 14 | /// 15 | [Produces("application/json")] 16 | [Route("api/Role")] 17 | public class RoleController : DataController 18 | { 19 | #region 构造方法 20 | private readonly RoleService _Service; 21 | private readonly ILogger _logger; 22 | /// 23 | /// 构造方法 24 | /// 25 | /// 26 | /// 27 | public RoleController(RoleService service, ILogger logger) 28 | { 29 | _Service = service; 30 | _logger = logger; 31 | } 32 | #endregion 33 | 34 | #region 新增修改数据 35 | /// 36 | /// 新增 37 | /// 38 | /// 请求体中放置新增角色的信息,新增时无需传递ID值 39 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Create")] 40 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 41 | [HttpPost("")] 42 | public ResultView Create([FromBody]RoleView view) 43 | { 44 | return _Service.Create(view, LogonInfo); 45 | } 46 | 47 | /// 48 | /// 修改 49 | /// 50 | /// 请求体中带入修改角色的信息,修改时请指定ID值 51 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Update")] 52 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 53 | [HttpPut("")] 54 | public ResultView Update([FromBody]RoleView view) 55 | { 56 | return _Service.Update(view, LogonInfo); 57 | } 58 | 59 | #endregion 60 | 61 | #region 数据删除 62 | /// 63 | /// 逻辑删除数据 64 | /// 65 | /// 要删除的角色id 66 | /// 删除 67 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Delete")] 68 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 69 | [HttpDelete("Delete/{id}")] 70 | public ResultView Delete(string id) 71 | { 72 | return _Service.Delete(id, LogonInfo); 73 | } 74 | /// 75 | /// 物理删除数据 76 | /// 77 | /// 要删除的角色id 78 | /// 粉碎数据 79 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Remove")] 80 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 81 | [HttpDelete("Remove/{id}")] 82 | public ResultView Remove(string id) 83 | { 84 | return _Service.Remove(id, LogonInfo); 85 | } 86 | #endregion 87 | 88 | #region 数据查询 89 | /// 90 | /// 根据ID获取一个角色信息 91 | /// 92 | /// 要获取的对象ID 93 | /// 详情 94 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Single")] 95 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 96 | [HttpGet("{id}")] 97 | public RoleView SearchById(string id) 98 | { 99 | return _Service.SearchById(id); 100 | } 101 | 102 | /// 103 | /// 查询角色列表(分页 + 查询条件) 104 | /// 105 | /// 106 | /// 107 | /// 排序规则包含: 108 | /// 109 | /// name : 按名称排列 110 | /// date : 按最后更新时间排列 为默认排序 111 | /// 112 | /// 113 | /// 查询信息。(包含分页信息、查询条件、排序条件) 114 | /// 115 | /// 查询 116 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Search")] 117 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 118 | [HttpPost("Search")] 119 | public PagedResult SearchPage([FromBody]RoleQuery queryInfo) 120 | { 121 | return _Service.FilterPage(queryInfo); 122 | } 123 | 124 | /// 125 | /// 获取所有的角色列表 - 主要为下拉列表提供数据 126 | /// 127 | /// 128 | /// 操作成功。 返回的结果中SelectView对象code属性均为空 129 | /// 130 | /// 列表选择 131 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Select")] 132 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 133 | [HttpGet("Select")] 134 | public List Select() 135 | { 136 | RoleQuery queryInfo = new RoleQuery(); 137 | return _Service.Select(queryInfo); 138 | } 139 | #endregion 140 | 141 | #region 初始化角色 142 | /// 143 | /// 初始化角色 清除已有角色,重置管理员角色信息 144 | /// 145 | /// 重置管理员角色 146 | /// 147 | /// 重置管理员角色信息,重置信息包含菜单、功能点 148 | /// 注:只要系统中有叫“管理员”字样的角色均被重置。如果不存在则添加名为“系统管理员”的角色。 149 | /// 150 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Role.Init")] 151 | [SwaggerOperation(Tags = new[] { "系统管理-角色管理" })] 152 | [HttpPost("InitAdmin")] 153 | public void Init() 154 | { 155 | _Service.InitAdmin(); 156 | } 157 | #endregion 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/Services/Common/RoleService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using TianCheng.BaseService; 5 | using TianCheng.Model; 6 | using TianCheng.SystemCommon.DAL; 7 | using TianCheng.SystemCommon.Model; 8 | 9 | namespace TianCheng.SystemCommon.Services 10 | { 11 | /// 12 | /// 角色管理 [ Service ] 13 | /// 14 | public class RoleService : MongoBusinessService 15 | { 16 | #region 构造方法 17 | private readonly MenuService _MenuService; 18 | private readonly FunctionService _FunctionService; 19 | /// 20 | /// 构造方法 21 | /// 22 | /// 23 | public RoleService(RoleDAL dal) 24 | : base(dal) 25 | { 26 | _MenuService = ServiceLoader.GetService(); 27 | _FunctionService = ServiceLoader.GetService(); 28 | } 29 | 30 | #endregion 31 | 32 | #region 查询方法 33 | /// 34 | /// 按条件查询数据 35 | /// 36 | /// 37 | /// 38 | public override IQueryable _Filter(RoleQuery input) 39 | { 40 | var query = _Dal.Queryable(); 41 | 42 | #region 查询条件 43 | //不显示删除的数据 44 | query = query.Where(e => e.IsDelete == false); 45 | 46 | // 按名称的模糊查询 47 | if (!string.IsNullOrWhiteSpace(input.Name)) 48 | { 49 | query = query.Where(e => !string.IsNullOrEmpty(e.Name) && e.Name.Contains(input.Name)); 50 | } 51 | 52 | #endregion 53 | 54 | #region 设置排序规则 55 | //设置排序方式 56 | switch (input.Sort.Property) 57 | { 58 | case "name": { query = input.Sort.IsAsc ? query.OrderBy(e => e.Name) : query.OrderByDescending(e => e.Name); break; } 59 | case "date": { query = input.Sort.IsAsc ? query.OrderBy(e => e.UpdateDate) : query.OrderByDescending(e => e.UpdateDate); break; } 60 | default: { query = query.OrderByDescending(e => e.UpdateDate); break; } 61 | } 62 | #endregion 63 | 64 | //返回查询结果 65 | return query; 66 | } 67 | 68 | /// 69 | /// 获取一个以角色名称为key的字典信息 70 | /// 71 | /// 72 | public Dictionary GetNameDict() 73 | { 74 | Dictionary dict = new Dictionary(); 75 | foreach (RoleInfo info in _Dal.Queryable().Where(e => e.IsDelete == false)) 76 | { 77 | if (!dict.ContainsKey(info.Name)) 78 | { 79 | dict.Add(info.Name, info); 80 | } 81 | } 82 | return dict; 83 | } 84 | #endregion 85 | 86 | #region 删除方法 87 | /// 88 | /// 删除时的检查 89 | /// 90 | /// 91 | protected override void DeleteRemoveCheck(RoleInfo info) 92 | { 93 | //如果角色下有员工信息,不允许删除 94 | EmployeeService employeeService = ServiceLoader.GetService(); 95 | if (employeeService.CountByRoleId(info.Id.ToString()) > 0) 96 | { 97 | throw ApiException.BadRequest("角色下有员工信息,不允许删除"); 98 | } 99 | } 100 | #endregion 101 | 102 | #region 初始化 103 | /// 104 | /// 初始化管理员角色信息 105 | /// 106 | public void InitAdmin() 107 | { 108 | //获取已有的角色信息 109 | List roleList = _Dal.Queryable().Where(e => !string.IsNullOrEmpty(e.Name) && e.Name.Contains("管理员")).ToList(); 110 | if (roleList == null || roleList.Count == 0) 111 | { 112 | roleList = new List 113 | { 114 | new RoleInfo() { Name = "系统管理员", Desc = "系统默认系统管理员" } 115 | }; 116 | } 117 | //添加管理员角色 118 | foreach (RoleInfo admin in roleList) 119 | { 120 | admin.PagePower = _MenuService.SearchMainTree(); 121 | admin.FunctionPower = _FunctionService.SearchFunction(); 122 | admin.CreateDate = DateTime.Now; 123 | admin.CreaterId = ""; 124 | admin.CreaterName = "系统初始化"; 125 | _Dal.Save(admin); 126 | } 127 | } 128 | /// 129 | /// 更新管理员的角色信息 130 | /// 131 | public void UpdateAdminRole() 132 | { 133 | RoleInfo admin = _Dal.Queryable().Where(e => e.Name == "系统管理员").FirstOrDefault(); 134 | if (admin == null) 135 | { 136 | admin = new RoleInfo() 137 | { 138 | Name = "系统管理员", 139 | Desc = "系统默认系统管理员", 140 | CreateDate = DateTime.Now, 141 | CreaterId = "", 142 | CreaterName = "系统初始化", 143 | ProcessState = ProcessState.Edit 144 | }; 145 | } 146 | admin.PagePower = _MenuService.SearchMainTree(); 147 | admin.FunctionPower = _FunctionService.SearchFunction(); 148 | admin.UpdateDate = DateTime.Now; 149 | admin.UpdaterId = ""; 150 | admin.UpdaterName = "系统初始化"; 151 | admin.IsDelete = false; 152 | 153 | //保存管理员角色信息 154 | if (admin.IsEmpty) 155 | { 156 | _Dal.InsertObject(admin); 157 | } 158 | else 159 | { 160 | _Dal.UpdateObject(admin); 161 | } 162 | } 163 | #endregion 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/Model/Common/EmployeeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using TianCheng.Model; 4 | 5 | namespace TianCheng.SystemCommon.Model 6 | { 7 | /// 8 | /// 员工信息 9 | /// 10 | public class EmployeeInfo : BusinessMongoModel 11 | { 12 | /// 13 | /// 旧系统ID 主要用于数据导入时 14 | /// 15 | public string OldId { get; set; } 16 | 17 | #region 基本信息 18 | /// 19 | /// 员工编码 20 | /// 21 | public string Code { get; set; } 22 | /// 23 | /// 名称 24 | /// 25 | [Required(ErrorMessage = "请填写员工名称")] 26 | public string Name { get; set; } 27 | /// 28 | /// 昵称 29 | /// 30 | public string Nickname { get; set; } 31 | /// 32 | /// 头像 33 | /// 34 | public string HeadImg { get; set; } 35 | #endregion 36 | 37 | #region 联系信息 38 | /// 39 | /// 手机电话 40 | /// 41 | public string Mobile { get; set; } 42 | /// 43 | /// 座机电话 44 | /// 45 | public string Telephone { get; set; } 46 | /// 47 | /// 联系邮箱 48 | /// 49 | public string Email { get; set; } 50 | /// 51 | /// 联系地址 52 | /// 53 | public string Address { get; set; } 54 | /// 55 | /// 传真 56 | /// 57 | public string Fax { get; set; } 58 | #endregion 59 | 60 | #region 登录信息 61 | /// 62 | /// 登录账号 63 | /// 64 | [Required(ErrorMessage = "请填写登录账号")] 65 | public string LogonAccount { get; set; } 66 | /// 67 | /// 登录密码 68 | /// 69 | [Required(ErrorMessage = "请填写登录密码")] 70 | public string LogonPassword { get; set; } 71 | /// 72 | /// 登录错误的次数 73 | /// 74 | public int LogonWrongNum { get; set; } 75 | /// 76 | /// 锁定账号不允许登录 77 | /// 78 | public bool LogonLock { get; set; } 79 | /// 80 | /// 登录类型 81 | /// 82 | public LoginVerifierType LoginType { get; set; } 83 | #endregion 84 | 85 | #region 登录令牌信息 86 | /// 87 | /// 动态令牌Id 88 | /// 89 | public string SecureKeyId { get; set; } 90 | /// 91 | /// 动态令牌号 92 | /// 93 | public string SecureKeyMark { get; set; } 94 | #endregion 95 | 96 | #region 部门信息 97 | 98 | private SelectView _Department = new SelectView(); 99 | /// 100 | /// 部门信息 101 | /// 102 | public SelectView Department 103 | { 104 | get { return _Department; } 105 | set 106 | { 107 | if (value == null) 108 | { 109 | value = new SelectView(); 110 | } 111 | _Department = value; 112 | } 113 | } 114 | private ParentDepartment _ParentDep = new ParentDepartment(); 115 | /// 116 | /// 上级部门信息 117 | /// 118 | public ParentDepartment ParentDepartment 119 | { 120 | get { return _ParentDep; } 121 | set 122 | { 123 | if (value == null) 124 | { 125 | value = new ParentDepartment(); 126 | } 127 | _ParentDep = value; 128 | } 129 | } 130 | #endregion 131 | 132 | #region 角色信息 133 | /// 134 | /// 角色信息 135 | /// 136 | /// 137 | /// 角色信息 138 | /// 139 | public SelectView Role { get; set; } = new SelectView(); 140 | 141 | #endregion 142 | 143 | #region 扩展信息 144 | /// 145 | /// 性别 146 | /// 147 | public UserGender Gender { get; set; } 148 | 149 | /// 150 | /// 出生日期 151 | /// 152 | public DateTime? Birthday { get; set; } 153 | 154 | /// 155 | /// 学历 156 | /// 157 | public string Education { get; set; } 158 | 159 | /// 160 | /// 血型 161 | /// 162 | public string BloodType { get; set; } 163 | /// 164 | /// 职称 165 | /// 166 | public string Title { get; set; } 167 | /// 168 | /// 职务 169 | /// 170 | public string Position { get; set; } 171 | /// 172 | /// 籍贯 173 | /// 174 | public string NativePlace { get; set; } 175 | /// 176 | /// 身份证号 177 | /// 178 | public string IdNumber { get; set; } 179 | #endregion 180 | 181 | #region 状态 182 | /// 183 | /// 状态 184 | /// 185 | public UserState State { get; set; } 186 | /// 187 | /// 状态文本 188 | /// 189 | public string StateText 190 | { 191 | get 192 | { 193 | if (this == null) 194 | { 195 | return string.Empty; 196 | } 197 | 198 | switch (State) 199 | { 200 | case UserState.Disable: return "禁用"; 201 | case UserState.Enable: return "正常"; 202 | case UserState.LogonLock: return "登录已锁"; 203 | default: return string.Empty; 204 | } 205 | } 206 | } 207 | 208 | /// 209 | /// 是否为系统级别数据 210 | /// 211 | public bool IsSystem { get; set; } 212 | #endregion 213 | 214 | /// 215 | /// 扩展ID 用于员工信息的扩展 216 | /// 217 | public string ExtId { get; set; } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/Services/Common/DataImport/ImportEmployeesService.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using TianCheng.BaseService; 3 | using TianCheng.Model; 4 | using TianCheng.SystemCommon.DAL; 5 | using TianCheng.SystemCommon.Model; 6 | using TianCheng.SystemCommon.Services; 7 | 8 | namespace TianCheng.Company.Services 9 | { 10 | /// 11 | /// 导入员工数据 服务处理 12 | /// 13 | public class ImportEmployeesService : DataImportService 14 | { 15 | #region 属性设置 16 | /// 17 | /// 操作的数据类型标识 18 | /// 19 | protected override string DataType 20 | { 21 | get 22 | { 23 | return "Employees"; 24 | } 25 | } 26 | #endregion 27 | 28 | /// 29 | /// 数据转换 30 | /// 31 | /// 32 | /// 33 | protected override EmployeeInfo Tran(EmployeesImportDetail import) 34 | { 35 | // 转换对象基本信息 36 | // 性别 37 | UserGender gender = UserGender.None; 38 | import.Gender = import.Gender.Trim(); 39 | if (import.Gender.Contains("女") || import.Gender == "0" || import.Gender == "false") 40 | { 41 | gender = UserGender.Female; 42 | } 43 | if (import.Gender.Contains("男") || import.Gender == "1" || import.Gender == "true") 44 | { 45 | gender = UserGender.Male; 46 | } 47 | // 是否在职 48 | bool isDelete = false; 49 | import.IsHoldJob = import.IsHoldJob.Trim(); 50 | if (import.IsHoldJob.Contains("是") || import.IsHoldJob == "1" || import.IsHoldJob == "true") 51 | { 52 | isDelete = false; 53 | } 54 | if (import.Gender.Contains("否") || import.Gender == "0" || import.Gender == "false") 55 | { 56 | isDelete = true; 57 | } 58 | EmployeeInfo info = new EmployeeInfo 59 | { 60 | OldId = import.Code, 61 | Code = import.Code, 62 | Name = import.Name, 63 | LogonAccount = import.LogonAccount, 64 | LogonPassword = import.LogonPassword, 65 | Gender = gender, 66 | IsDelete = isDelete, 67 | State = isDelete ? UserState.Disable : UserState.Enable 68 | }; 69 | // 获取部门 70 | if (!string.IsNullOrWhiteSpace(import.Department)) 71 | { 72 | DepartmentService depService = ServiceLoader.GetService(); 73 | DepartmentInfo depInfo = depService.SearchQueryable().Where(e => e.Name == import.Department).FirstOrDefault(); 74 | if (depInfo != null) 75 | { 76 | info.Department = new SelectView { Id = depInfo.Id.ToString(), Name = depInfo.Name, Code = depInfo.Code }; 77 | info.ParentDepartment = new ParentDepartment { Id = depInfo.ParentId, Name = depInfo.ParentName, Ids = depInfo.ParentsIds }; 78 | } 79 | } 80 | // 获取角色 81 | if (!string.IsNullOrWhiteSpace(import.Role)) 82 | { 83 | RoleService roleService = ServiceLoader.GetService(); 84 | RoleInfo roleInfo = roleService.SearchQueryable().Where(e => e.Name == import.Role).FirstOrDefault(); 85 | if (roleInfo != null) 86 | { 87 | info.Role = new SelectView { Id = roleInfo.Id.ToString(), Name = roleInfo.Name, Code = string.Empty }; 88 | } 89 | } 90 | // 返回信息 91 | return info; 92 | } 93 | 94 | #region 导入数据 95 | /// 96 | /// 检查导入的数据 97 | /// 98 | /// 99 | /// 100 | /// 101 | protected override void ImportCheck(EmployeesImportDetail import, EmployeeInfo info) 102 | { 103 | string fail = string.Empty; 104 | if (string.IsNullOrEmpty(import.Code)) 105 | { 106 | fail += "编号不能为空、"; 107 | } 108 | if (string.IsNullOrEmpty(import.Name)) 109 | { 110 | fail += "名称不能为空、"; 111 | } 112 | if (string.IsNullOrEmpty(import.LogonAccount)) 113 | { 114 | fail += "登陆账号不能为空、"; 115 | } 116 | if (string.IsNullOrEmpty(import.LogonPassword)) 117 | { 118 | fail += "登陆密码不能为空、"; 119 | } 120 | 121 | if (!string.IsNullOrWhiteSpace(fail) || import.ImportState == SystemCommon.Model.ImportState.Fail) 122 | { 123 | import.ImportState = ImportState.Fail; 124 | import.FailureReason = fail; 125 | return; 126 | } 127 | else 128 | { 129 | import.ImportState = ImportState.Check; 130 | import.FailureReason = string.Empty; 131 | } 132 | } 133 | 134 | /// 135 | /// 排重的检查 136 | /// 137 | /// 138 | /// 139 | protected override void RepeatCheck(EmployeesImportDetail import, EmployeeInfo info) 140 | { 141 | string fail = string.Empty; 142 | // 判断是否已经导入过 143 | EmployeeService employeeService = ServiceLoader.GetService(); 144 | if (!string.IsNullOrEmpty(import.Code) && employeeService.SearchQueryable().Where(e => e.Code == import.Code).Count() > 0) 145 | { 146 | fail += $"编码为{import.Code}的员工已经导入过,终止再次导入"; 147 | } 148 | if (!string.IsNullOrEmpty(import.LogonAccount) && employeeService.SearchQueryable().Where(e => e.LogonAccount == import.LogonAccount).Count() > 0) 149 | { 150 | fail += $"编码为{import.Code}的{import.Name}员工登陆账号({import.LogonAccount})已存在,终止再次导入"; 151 | } 152 | if (!string.IsNullOrEmpty(fail)) 153 | { 154 | import.ImportState = ImportState.Fail; 155 | import.FailureReason = fail; 156 | return; 157 | } 158 | else 159 | { 160 | import.ImportState = ImportState.Check; 161 | import.FailureReason = string.Empty; 162 | } 163 | } 164 | 165 | /// 166 | /// 导入数据的具体操作 167 | /// 168 | /// 169 | /// 170 | /// 171 | protected override void Import(EmployeesImportDetail import, EmployeeInfo info, TokenLogonInfo logonInfo) 172 | { 173 | EmployeeService employeeService = ServiceLoader.GetService(); 174 | // 新增导入的数据 175 | employeeService.Create(info, logonInfo); 176 | } 177 | #endregion 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/Services/Auth/AuthService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Security.Principal; 7 | using TianCheng.BaseService; 8 | using TianCheng.BaseService.PlugIn; 9 | using TianCheng.Model; 10 | using TianCheng.SystemCommon.DAL; 11 | using TianCheng.SystemCommon.Model; 12 | 13 | namespace TianCheng.SystemCommon.Services 14 | { 15 | /// 16 | /// 登录处理 17 | /// 18 | public class AuthService : IAuthService 19 | { 20 | #region 构造方法 21 | private readonly EmployeeDAL _employeeDal; 22 | private readonly ILogger _logger; 23 | private readonly TokenProviderOptions _tokenOptions; 24 | EmployeeService _EmployeeService; 25 | RoleService _RoleService; 26 | MenuService _MenuService; 27 | FunctionService _FunctionService; 28 | /// 29 | /// 构造方法 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | /// 36 | /// 37 | /// 38 | public AuthService(EmployeeDAL employeeDal, ILogger logger, 39 | Microsoft.Extensions.Configuration.IConfiguration configuration, 40 | EmployeeService employeeService, RoleService roleService, MenuService menuService, FunctionService functionService) 41 | { 42 | _employeeDal = employeeDal; 43 | _logger = logger; 44 | _EmployeeService = employeeService; 45 | _RoleService = roleService; 46 | _MenuService = menuService; 47 | _FunctionService = functionService; 48 | _tokenOptions = TokenProviderOptions.Load(configuration); 49 | } 50 | #endregion 51 | 52 | /// 53 | /// 每次请求接口时,加载用户的权限信息 54 | /// 55 | /// 56 | public void FillFunctionPolicy(ClaimsIdentity identity) 57 | { 58 | string userId = ""; 59 | foreach (var item in identity.Claims) 60 | { 61 | if (item.Type == "id") 62 | { 63 | userId = item.Value; 64 | break; 65 | } 66 | } 67 | 68 | 69 | EmployeeView employee = _EmployeeService.SearchById(userId); 70 | 71 | // 添加角色声明 72 | //Claim claimRole = new Claim(ClaimTypes.Role, employee.Role.name); 73 | //identity.AddClaim(claimRole); 74 | if (employee == null) 75 | { 76 | throw ApiException.BadRequest("无法根据Token信息获取用户"); 77 | } 78 | // 添加权限声明 79 | RoleView role = _RoleService.SearchById(employee.Role.Id); 80 | if (role == null) 81 | { 82 | throw ApiException.BadRequest("无法根据用户获取角色信息"); 83 | } 84 | if (role.FunctionPower == null) 85 | { 86 | //如果功能点为空,初始化功能点 87 | if (_FunctionService.SearchQueryable().Count() == 0) 88 | { 89 | //初始化系统菜单 90 | _MenuService.Init(); 91 | //初始化系统功能点列表 92 | _FunctionService.Init(); 93 | //初始化角色信息 94 | _RoleService.InitAdmin(); 95 | //初始化用户信息 96 | _EmployeeService.UpdateAdmin(); 97 | } 98 | } 99 | if (role.FunctionPower.Count == 0) 100 | { 101 | _logger.LogInformation($"{employee.Name}用户无任何功能点权限。所属角色为:{role.Name}({role.Id.ToString()})"); 102 | } 103 | foreach (var function in role.FunctionPower) 104 | { 105 | identity.AddClaim(new Claim("function_policy", function.Policy)); 106 | } 107 | } 108 | 109 | /// 110 | /// 登录时的事件处理 111 | /// 112 | static public Action OnLogin; 113 | /// 114 | /// 退出时的事件处理 115 | /// 116 | static public Action OnLogout; 117 | 118 | /// 119 | /// 登录 120 | /// 121 | /// 122 | /// 123 | /// 124 | public string Login(string account, string password) 125 | { 126 | account = account.Trim(); 127 | password = password.Trim(); 128 | //查询密码正确的可用用户列表 129 | var pwdQuery = _employeeDal.Queryable().Where(e => e.LogonPassword == password && e.IsDelete == false).ToList(); 130 | 131 | // 通过账号和密码验证登录 132 | var employeeList = pwdQuery.Where(e => e.LogonAccount == account); 133 | if (employeeList.Count() > 1) 134 | { 135 | throw ApiException.BadRequest("有多个满足条件的用户,无法登陆。"); 136 | } 137 | 138 | // 如果查找不到用户信息,并且允许用电话登录,尝试电话号码+登录密码登录 139 | if (employeeList.Count() == 0 && AuthServiceOption.Option.IsLogonByTelephone) 140 | { 141 | employeeList = pwdQuery.Where(e => e.Telephone == account || e.Mobile == account); 142 | if (employeeList.Count() > 1) 143 | { 144 | throw ApiException.BadRequest("有多个满足条件的用户,无法通过电话登陆。"); 145 | } 146 | } 147 | 148 | var employee = employeeList.FirstOrDefault(); 149 | 150 | if (employee == null) 151 | { 152 | throw ApiException.BadRequest("您的登陆账号或密码错误。"); 153 | } 154 | 155 | if (employee.State == UserState.Disable) 156 | { 157 | throw ApiException.BadRequest("您的登陆功能已被禁用,请与管理员联系。"); 158 | } 159 | if (employee.State == UserState.LogonLock) 160 | { 161 | throw ApiException.BadRequest("多次登陆失败,登陆已被锁住,请与管理员联系。"); 162 | } 163 | 164 | // 执行扩展的登录事件 165 | OnLogin?.Invoke(employee); 166 | 167 | List claims = new List 168 | { 169 | new Claim("id",employee.Id.ToString()), 170 | new Claim("name", employee.Name ?? ""), 171 | new Claim("roleId",employee.Role?.Id ?? ""), 172 | new Claim("depId",employee.Department?.Id ?? ""), 173 | new Claim("depName",employee.Department?.Name ?? ""), 174 | new Claim("type","AuthService") 175 | }; 176 | 177 | 178 | var identity = new ClaimsIdentity(new GenericIdentity(account, "Token"), claims); 179 | string token = Jwt.GenerateJwtToken(account, identity, _tokenOptions); 180 | return token; 181 | } 182 | 183 | 184 | /// 185 | /// 186 | /// 187 | /// 188 | /// 189 | public void Logout(TokenLogonInfo logonInfo) 190 | { 191 | OnLogout?.Invoke(logonInfo); 192 | } 193 | } 194 | 195 | } 196 | -------------------------------------------------------------------------------- /src/Controller/Common/DepartmentController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Swashbuckle.AspNetCore.Annotations; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using TianCheng.BaseService; 6 | using TianCheng.Model; 7 | using TianCheng.SystemCommon.Model; 8 | using TianCheng.SystemCommon.Services; 9 | 10 | namespace TianCheng.SystemCommon.Controller 11 | { 12 | /// 13 | /// 组织机构管理 14 | /// 15 | [Produces("application/json")] 16 | [Route("api/Department")] 17 | public class DepartmentController : DataController 18 | { 19 | #region 构造方法 20 | private readonly DepartmentService _Service; 21 | /// 22 | /// 构造方法 23 | /// 24 | /// 25 | public DepartmentController(DepartmentService service) 26 | { 27 | _Service = service; 28 | } 29 | #endregion 30 | 31 | #region 新增修改数据 32 | /// 33 | /// 新增 34 | /// 35 | /// 请求体中放置新增部门的信息 36 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Create")] 37 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 38 | [HttpPost("")] 39 | public ResultView Create([FromBody]DepartmentView view) 40 | { 41 | return _Service.Create(view, LogonInfo); 42 | } 43 | 44 | /// 45 | /// 修改 46 | /// 47 | /// 请求体中带入修改部门的信息 48 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Update")] 49 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 50 | [HttpPut("")] 51 | public ResultView Update([FromBody]DepartmentView view) 52 | { 53 | return _Service.Update(view, LogonInfo); 54 | } 55 | 56 | #endregion 57 | 58 | #region 数据删除 59 | /// 60 | /// 逻辑删除数据 61 | /// 62 | /// 要删除的部门id 63 | /// 删除 64 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Delete")] 65 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 66 | [HttpDelete("Delete/{id}")] 67 | public ResultView Delete(string id) 68 | { 69 | return _Service.Delete(id, LogonInfo); 70 | } 71 | /// 72 | /// 物理删除数据 73 | /// 74 | /// 要删除的部门id 75 | /// 粉碎数据 76 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Remove")] 77 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 78 | [HttpDelete("Remove/{id}")] 79 | public ResultView Remove(string id) 80 | { 81 | return _Service.Remove(id, LogonInfo); 82 | } 83 | #endregion 84 | 85 | #region 数据查询 86 | /// 87 | /// 根据ID获取组织机构详情 88 | /// 89 | /// 详情 90 | /// 组织机构ID 91 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Single")] 92 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 93 | [HttpGet("{id}")] 94 | public DepartmentView SearchById(string id) 95 | { 96 | return _Service.SearchById(id); 97 | } 98 | 99 | /// 100 | /// 查询组织结构列表(分页 + 查询条件) 101 | /// 102 | /// 103 | /// 排序规则包含: 104 | /// 105 | /// name : 按名称排列 106 | /// code : 按编码排列 107 | /// parent : 按上级部门名称排列 108 | /// index : 按部门序号排列 109 | /// date : 按最后更新时间排列 为默认排序 110 | /// 111 | /// 112 | /// 查询信息。(包含分页信息、查询条件、排序条件) 113 | /// 查询 114 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Search")] 115 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 116 | [HttpPost("Search")] 117 | public PagedResult SearchPage([FromBody]DepartmentQuery queryInfo) 118 | { 119 | return _Service.FilterPage(queryInfo); 120 | } 121 | 122 | /// 123 | /// 查询组织结构列表(无分页 + 查询条件) 124 | /// 125 | /// 126 | /// 排序规则包含: 127 | /// 128 | /// name : 按名称排列 129 | /// code : 按编码排列 130 | /// parent : 按上级部门名称排列 131 | /// index : 按部门序号排列 132 | /// date : 按最后更新时间排列 为默认排序 133 | /// 134 | /// 135 | /// 查询信息。(包含查询条件、排序条件) 136 | /// 查询 137 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Search")] 138 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 139 | [HttpPost("SearchALL")] 140 | public List SearchFilter([FromBody]DepartmentQuery queryInfo) 141 | { 142 | return _Service.Filter(queryInfo); 143 | } 144 | 145 | /// 146 | /// 获取所有的组织机构列表 147 | /// 148 | /// 返回的下级对象结构为SelectView,适合用作下拉列表中的显示 149 | /// 列表选择 150 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Select")] 151 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 152 | [HttpGet("Select")] 153 | public List Select() 154 | { 155 | DepartmentQuery query = new DepartmentQuery(); 156 | return _Service.Select(query); 157 | } 158 | /// 159 | /// 获取根部门 160 | /// 161 | /// 列表选择 162 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Select")] 163 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 164 | [HttpGet("Root")] 165 | public DepartmentView Root() 166 | { 167 | var info = _Service.SearchQueryable().Where(e => string.IsNullOrEmpty(e.ParentId)).FirstOrDefault(); 168 | return AutoMapper.Mapper.Map(info); 169 | } 170 | 171 | ///// 172 | ///// 获取根部门 173 | ///// 174 | ///// 175 | ///// 列表选择 176 | //[Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Select")] 177 | //[SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 178 | //[HttpGet("Root/Multiple")] 179 | //public List GetMultipleRoot() 180 | //{ 181 | // return AutoMapper.Mapper.Map>(_Service.GetRoot()); 182 | //} 183 | 184 | /// 185 | /// 查询指定机构下的子机构 186 | /// 187 | /// 机构管理id 188 | /// 返回的下级对象结构为SelectView,适合用作下拉列表中的显示 189 | /// 列表选择 190 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Select")] 191 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 192 | [HttpGet("{id}/Sub")] 193 | public List Sub(string id) 194 | { 195 | DepartmentQuery query = new DepartmentQuery() { ParentId = id }; 196 | return _Service.Select(query); 197 | } 198 | 199 | /// 200 | /// 查询当前用户的所有下级部门 201 | /// 202 | /// 返回的下级对象结构为SelectView,适合用作下拉列表中的显示 203 | /// 列表选择 204 | [Microsoft.AspNetCore.Authorization.Authorize(Policy = "SystemManage.Department.Select")] 205 | [SwaggerOperation(Tags = new[] { "系统管理-组织机构管理" })] 206 | [HttpGet("My/Sub")] 207 | public List MySub() 208 | { 209 | if (string.IsNullOrWhiteSpace(LogonInfo.DepartmentId)) 210 | { 211 | ApiException.ThrowBadRequest("您需要先有所属部门才可执行此操作"); 212 | } 213 | 214 | DepartmentQuery query = new DepartmentQuery() { ParentId = LogonInfo.DepartmentId }; 215 | List subList = _Service.Select(query); 216 | return subList; 217 | } 218 | #endregion 219 | 220 | } 221 | } 222 | --------------------------------------------------------------------------------