You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

125 lines
5.2 KiB

using NFine.Code;
using NFine.Data.Extensions;
using NFine.Domain.Entity.SystemManage;
using NFine.Domain.IRepository.SystemManage;
using NFine.Repository.SystemManage;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace NFine.Application.SystemManage
{
public class RoleApp
{
private IRoleRepository service = new RoleRepository();
private ModuleApp moduleApp = new ModuleApp();
private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
public List<RoleEntity> GetList(string keyword = "")
{
var expression = ExtLinq.True<RoleEntity>();
if (!string.IsNullOrEmpty(keyword))
{
expression = expression.And(t => t.F_FullName.Contains(keyword));
expression = expression.Or(t => t.F_EnCode.Contains(keyword));
}
expression = expression.And(t => t.F_Category == 1);
return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList();
}
public RoleEntity GetForm(string keyValue)
{
return service.FindEntity(keyValue);
}
public void DeleteForm(string keyValue)
{
service.DeleteForm(keyValue);
}
public void SubmitForm(RoleEntity roleEntity, string[] permissionIds, string keyValue)
{
if (!string.IsNullOrEmpty(keyValue))
{
roleEntity.F_Id = keyValue;
}
else
{
roleEntity.F_Id = Common.GuId();
}
var moduledata = moduleApp.GetListAll();
var buttondata = moduleButtonApp.GetList();
List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
foreach (var itemId in permissionIds)
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Common.GuId();
roleAuthorizeEntity.F_ObjectType = 1;
roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (moduledata.Find(t => t.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 1;
}
if (buttondata.Find(t => t.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 2;
}
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
}
service.SubmitForm(roleEntity, roleAuthorizeEntitys, keyValue);
}
public DataTable GetRole()
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @"
select '' as ID,'' as F_FullName
union all
SELECT F_Id as ID ,F_FullName as F_FullName FROM dbo.Sys_SRM_Role ";
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public int SubmitFormCloneRole(string keyValue)
{
string sql = string.Empty;
var queryParam = keyValue.ToJObject();
string RoleID = queryParam["RoleID"].ToString();
string F_FullName = queryParam["F_FullName"].ToString();
string F_EnCode = queryParam["F_EnCode"].ToString();
string F_SortCode = queryParam["F_SortCode"].ToString();
string F_Description = queryParam["F_Description"].ToString();
var NewRoleID = Guid.NewGuid();
sql += @"INSERT INTO dbo.Sys_SRM_Role
(F_Id,F_OrganizeId,F_Category,F_EnCode,F_FullName,F_Type,F_AllowEdit,F_AllowDelete,F_SortCode,F_DeleteMark,F_EnabledMark,F_Description,F_CreatorTime,F_CreatorUserId,F_LastModifyTime,F_LastModifyUserId,F_DeleteTime,F_DeleteUserId )
select '{0}',F_OrganizeId,F_Category,'{1}','{2}',F_Type,F_AllowEdit,F_AllowDelete,'{3}',F_DeleteMark,F_EnabledMark,'{4}',getdate(),F_CreatorUserId,F_LastModifyTime,F_LastModifyUserId,F_DeleteTime,F_DeleteUserId
from Sys_SRM_Role where F_Id='{5}'";
sql += "\r\n";
sql += @" INSERT INTO dbo.Sys_SRM_RoleAuthorize
(F_Id,F_ItemType,F_ItemId,F_ObjectType,F_ObjectId,F_SortCode,F_CreatorTime,F_CreatorUserId)
select newid(),F_ItemType,F_ItemId,F_ObjectType,'{0}',F_SortCode,F_CreatorTime,F_CreatorUserId
from Sys_SRM_RoleAuthorize where F_ObjectId='{5}'";
sql += "\r\n";
sql += @" INSERT INTO dbo.Sys_RoleDataPower
(ID,RoleId,DataActionId)
select newid(),'{0}',DataActionId
from Sys_RoleDataPower where RoleId='{5}'";
sql += "\r\n";
sql += @" INSERT INTO dbo.Sys_FormColsVisible
(ID,MenuId,RoleId,FieldName,VisibleFlag,WorkPoint)
select newid(),MenuId,'{0}',FieldName,VisibleFlag,WorkPoint
from Sys_FormColsVisible where RoleId='{5}'";
sql = string.Format(sql, NewRoleID, F_EnCode, F_FullName, F_SortCode, F_Description, RoleID);
int count = SqlHelper.CmdExecuteNonQueryLi(sql);
return count;
}
}
}