我们提供安全,免费的手游软件下载!
业务模型管理中所涉及的业务模型,业务模型的属性,业务模型的视图都是可以通过权限设置来实现数据的行(视图),列(属性)权限管控。业务模型是整个EDP平台的核心基础,数据的查询、新增、修改、删除、行列权限都是通过业务模型来实现的。
按分类管理系统内各个业务模型,对应系统中各个业务对象。
管理业务模型分类。
新增业务模型
编辑业务模型
业务模型代码生成
表设计文档模板,可以包含多个表结构设计
创建业务模型类,继承基类ModelPermissionBase。定义好的业务模型可以在上述的业务模型管理功能中进行管理,实现数据行、列权限的管控。
using System;
namespace School.Model
{
using EDP.Common.Model;
using EDP.Common.Help;
using EDP.Database;
using EDP.Framework;
using EDP.Authentication;
///
/// 学生业务对象
///
[ModelEnitity(TableName = "t_school_student", KeyName = "ID")]
public class StudentModel: ModelPermissionBase
{
///
/// 构造函数
///
public StudentModel() {
this.SetDefaultQuerySQL(@"select *
from (select a.ID
,a.Name
,a.Number
,a.GenderId
,a.Age
,a.Contact
,a.ContactMobile
,a.Hobby
,a.CampusId
,a.ClassId
,a.CreateUserId
,a.CreateUserName
,a.CreateDepartmentId
,a.CreateOrganizationId
,a.CreateTime
,a.ModifyUserId
,a.ModifyUserName
,a.ModifyTime
,a.Remarks
,b.Name CampusName
,c.Name ClassName
,d.Name SchoolName
,c.FullCode ClassFullCode
from t_school_student a
left join t_sys_organization_unit b on a.CampusId = b.ID
left join t_sys_organization_unit c on a.ClassId = c.ID
left join t_sys_organization_unit d on c.FullCode like d.FullCode + '%' and d.Levels = c.Levels - 3) tab");
}
#region **----实体属性---------------------------**
///
/// 主键ID
///
[ModelEnitity(ColumnName = "ID")]
public string ID { get; set; }
///
/// 姓名
///
[ModelEnitity(ColumnName = "Name", IsRequired = true, MaxLength = 50)]
public string Name { get; set; }
///
/// 编号
///
[ModelEnitity(ColumnName = "Number")]
public string Number { get; set; }
///
/// 性别ID
///
[ModelEnitity(ColumnName = "GenderId", IsRequired = true)]
public int? GenderId { get; set; }
///
/// 年龄
///
[ModelEnitity(ColumnName = "Age", IsRequired = true)]
public int? Age { get; set; }
///
/// 联系人
///
[ModelEnitity(ColumnName = "Contact", MaxLength = 50)]
public string Contact { get; set; }
///
/// 联系人手机
///
[ModelEnitity(ColumnName = "ContactMobile", Regex = @"^[1]([3-9])[0-9]{9}$")]
public string ContactMobile { get; set; }
///
/// 兴趣爱好
///
[ModelEnitity(ColumnName = "Hobby", MaxLength = 500)]
public string Hobby { get; set; }
///
/// 校区ID
///
[ModelEnitity(ColumnName = "CampusId")]
public string CampusId { get; set; }
///
/// 班级ID
///
[ModelEnitity(ColumnName = "ClassId", IsRequired = true)]
public string ClassId { get; set; }
///
/// 创建人ID
///
[ModelEnitity(ColumnName = "CreateUserId")]
public string CreateUserId { get; set; }
///
/// 创建人
///
[ModelEnitity(ColumnName = "CreateUserName")]
public string CreateUserName { get; set; }
///
/// 创建部门ID
///
[ModelEnitity(ColumnName = "CreateDepartmentId")]
public string CreateDepartmentId { get; set; }
///
/// 创建机构ID
///
[ModelEnitity(ColumnName = "CreateOrganizationId")]
public string CreateOrganizationId { get; set; }
///
/// 创建时间
///
[ModelEnitity(ColumnName = "CreateTime")]
public DateTime? CreateTime { get; set; }
///
/// 修改人ID
///
[ModelEnitity(ColumnName = "ModifyUserId")]
public string ModifyUserId { get; set; }
///
/// 修改人
///
[ModelEnitity(ColumnName = "ModifyUserName")]
public string ModifyUserName { get; set; }
///
/// 修改时间
///
[ModelEnitity(ColumnName = "ModifyTime")]
public DateTime? ModifyTime { get; set; }
///
/// 备注
///
[ModelEnitity(ColumnName = "Remarks", MaxLength = 1000)]
public string Remarks { get; set; }
#endregion
#region **----扩展属性---------------------------**
///
/// 校区名称
///
public string CampusName { get; set; }
///
/// 学校名称
///
public string SchoolName { get; set; }
///
/// 班级名称
///
public string ClassName { get; set; }
///
/// 性别@readonly
///
public GenderEnum Gender {
get {
GenderEnum ret = GenderEnum.None;
if (this.GenderId.HasValue) {
try { ret = (GenderEnum)this.GenderId; }
catch { }
}
return ret;
}
}
///
/// 性别显示@readonly
///
public string GenderDisplay {
get {
return EnumHelp.GetEnumDescription(this.Gender);
}
}
///
/// 班级全编码
///
public string ClassFullCode { get; set; }
///
/// 学校
///
public Organization.OrganizationModel School { get; set; } = new Organization.OrganizationModel();
#endregion
#region **----方法-------------------------------**
///
/// 创建当前实体对象
///
/// 数据库接口
public void Create(IDBInstance db = null) {
if (string.IsNullOrWhiteSpace(this.ID))
this.ID = Guid.NewGuid().ToString();
var loginUser = AuthenticationHelp.GetLoginUser(db);
if (loginUser != null && loginUser.IsLogin) {
this.CreateUserId = loginUser.UserInfo.ID;
this.CreateUserName = loginUser.UserInfo.Name;
this.CreateDepartmentId = loginUser.UserInfo.DepartmentId;
this.CreateOrganizationId = loginUser.UserInfo.OrganizationId;
}
this.CreateTime = DateTime.Now;
this.ModifyTime = null;
this.ModifyUserId = null;
this.ModifyUserName = null;
}
///
/// 修改当前实体对象
///
/// 数据库接口
public void Modify(IDBInstance db = null) {
this.ModifyTime = DateTime.Now;
var loginUser = AuthenticationHelp.GetLoginUser(db);
if (loginUser != null && loginUser.IsLogin) {
this.ModifyUserId = loginUser.UserInfo.ID;
this.ModifyUserName = loginUser.UserInfo.Name;
}
this.ModifyTime = DateTime.Now;
this.CreateDepartmentId = null;
this.CreateOrganizationId = null;
this.CreateTime = null;
this.CreateUserId = null;
this.CreateUserName = null;
}
///
/// 修改当前实体对象
///
/// 主键值
/// 数据库接口
public void Modify(string keyValue, IDBInstance db = null) {
this.ID = keyValue;
this.Modify(db);
}
#endregion
}
}
[ModelEnitity(TableName = "t_school_student", KeyName = "ID")]
TableName:表名
KeyName:主键对应的属性名
[ModelEnitity(ColumnName = "Name", IsRequired = true, MaxLength = 50)]
ColumnName:字段名称
IsRequired:是否必须,用于验证属性值是否必须有值
MaxLength:最大长度,属性值的最大长度
[ModelEnitity(ColumnName = "ContactMobile", Regex = @"^[1]([3-9])[0-9]{9}$")]
Regex:正则表达式,用于验证属性值格式
///
/// 构造函数
///
public StudentModel() {
this.SetDefaultQuerySQL(@"select *
from (select a.ID
,a.Name
,a.Number
,a.GenderId
,a.Age
,a.Contact
,a.ContactMobile
,a.Hobby
,a.CampusId
,a.ClassId
,a.CreateUserId
,a.CreateUserName
,a.CreateDepartmentId
,a.CreateOrganizationId
,a.CreateTime
,a.ModifyUserId
,a.ModifyUserName
,a.ModifyTime
,a.Remarks
,b.Name CampusName
,c.Name ClassName
,d.Name SchoolName
,c.FullCode ClassFullCode
from t_school_student a
left join t_sys_organization_unit b on a.CampusId = b.ID
left join t_sys_organization_unit c on a.ClassId = c.ID
left join t_sys_organization_unit d on c.FullCode like d.FullCode + '%' and d.Levels = c.Levels - 3) tab");
//引入命名空间 using EDP.Common;
//default:注册表配置中数据库连接配置所对应的"Key"值
//若没有设置连线字串,则取注册表配置中的默认数据库连接
//this.SetConnectionString(Config.Database["default"]); 示例项目使用默认数据库连接,不需要设置
}
public string CampusName { get; set; }
扩展属性是默认查询SQL中所查询的非业务模型映射的表中的字段。
///
/// 创建当前实体对象
///
/// 数据库接口
public void Create(IDBInstance db = null) {
if (string.IsNullOrWhiteSpace(this.ID))
this.ID = Guid.NewGuid().ToString();
var loginUser = AuthenticationHelp.GetLoginUser(db);
if (loginUser != null && loginUser.IsLogin) {
this.CreateUserId = loginUser.UserInfo.ID;
this.CreateUserName = loginUser.UserInfo.Name;
this.CreateDepartmentId = loginUser.UserInfo.DepartmentId;
this.CreateOrganizationId = loginUser.UserInfo.OrganizationId;
}
this.CreateTime = DateTime.Now;
this.ModifyTime = null;
this.ModifyUserId = null;
this.ModifyUserName = null;
}
///
/// 修改当前实体对象
///
/// 数据库接口
public void Modify(IDBInstance db = null) {
this.ModifyTime = DateTime.Now;
var loginUser = AuthenticationHelp.GetLoginUser(db);
if (loginUser != null && loginUser.IsLogin) {
this.ModifyUserId = loginUser.UserInfo.ID;
this.ModifyUserName = loginUser.UserInfo.Name;
}
this.ModifyTime = DateTime.Now;
this.CreateDepartmentId = null;
this.CreateOrganizationId = null;
this.CreateTime = null;
this.CreateUserId = null;
this.CreateUserName = null;
}
///
/// 修改当前实体对象
///
/// 主键值
/// 数据库接口
public void Modify(string keyValue, IDBInstance db = null) {
this.ID = keyValue;
this.Modify(db);
}
查询对象是用来实现业务对象的查询,通过属性来设置查询条件。需要继承QueryModelBase基类。
using System;
namespace School.Model
{
using EDP.Common;
using EDP.Common.Model;
///
/// 学生信息查询对象
///
[QueryModel] //标记类的查询对象特性
public class StudentQueryModel : QueryModelBase //继承QueryModelBase
{
///
/// 姓名
///
[QueryModel(Operator = QueryOperator.like, ColumnName = "Name")]
public string Name { get; set; }
///
/// 性别
///
[QueryModel(Operator = QueryOperator.eq, ColumnName = "GenderId")]
public int? GenderId { get; set; }
///
/// 校区
///
[QueryModel(Operator = QueryOperator.eq, ColumnName = "CampusId")]
public string CampusId { get; set; }
///
/// 班级
///
[QueryModel(Operator = QueryOperator.eq, ColumnName = "ClassId")]
public string ClassId { get; set; }
///
/// 班级全编码
///
/// ClassFullCode like '值%'
[QueryModel(Operator = QueryOperator.likeRight, ColumnName = "ClassFullCode")]
public string ClassFullCode { get; set; }
///
/// 编号姓名关键字
/// Number和Name都进行like查询
///
/// Number like '%关键字%' or Name like '%值%'
[QueryModel(Operator = QueryOperator.like, ColumnNameList = "Number;Name")]
public string NumberNameKeywrod { get; set; }
///
/// 分页对象
///
public PageModel Page { get; set; } = new PageModel();
}
}
[QueryModel(Operator = QueryOperator.like, ColumnName = "Name")]
Operator:查询操作符(=、>、<、>=、like等)
ColumnName:对应业务对象的属性(实体属性,扩展属性),只要是默认查询SQL中包含的字段都可以作为查询对象的属性(查询条件)
详见示例项目StudentBLL.cs
业务模型属性验证
var verify = item.Verify(keyValue);
此处通过Verify()方法验证业务模型各属性值,通过属性验证标记(IsRequired,MaxLength, Regex)进行验证。
业务模型新增
item.Create(db);
item.ValidateSQL = string.Format("where not exists (select 1 from t_school_student where Number = '{0}')", item.Number);
result = item.InsertModel(db);
通过业务模型Create()方法创建当前实体对象。
通过ValidateSQL属性值确保不会有重复的Number值插入到数据库。
调用InsertModel()方法新增业务模型数据。
item.Modify(keyValue, db);
item.Number = null; //编号不能修改
result = item.UpdateModel(db);
通过业务模型Modify()方法修改当前实体对象。
调用UpdateModel()方法修改业务模型数据。
ResultModel ret = new ResultModel();
ret.Content = new StudentModel();
ret.KeyValue = keyValue;
ret.Content.ID = keyValue;
ret.Content.Query(db);
使用统一的返回对象 ResultModel。
实例化ret.Content并设置操作的主键值ret.KeyValue = keyValue。
设置查询的主键值 ret.Content.ID = keyValue。
调用业务对象Query()方法 ret.Content.Query(db)。
执行Query()查询后,根据权限设置给ret.Content赋值。
ret.Content.AccessPropertyList中返回有权限的属性名称。
ResultModel> ret = new ResultModel>();
ret.Content = new List();
ret.Content.Query(queryModel.Page, queryModel, db);
ret.Page = queryModel.Page;
使用统一的返回对象 ResultModel>。
实例化 ret.Content = new List()。
调用业务对象Query()方法 ret.Content.Query(queryModel.Page, queryModel, db)。
queryModel为查询对象StudentQueryModel的实例。
执行Query()查询后,根据权限设置给ret.Content赋值(有权限的数据集合)。
ret.Content[0].AccessPropertyList中返回有权限的属性名称。
StudentModel item = new StudentModel();
item.Id = keyValue;
item.DeleteModel();
实例化StudentModel。
设置主键值 item.Id = keyValue。
调用业务对象DeleteModel()方法 item.DeleteModel()。
热门资讯