初步可用版本

This commit is contained in:
dd 2021-12-12 14:55:48 +08:00
parent 5a33104725
commit efdd134b09
659 changed files with 50070 additions and 0 deletions

25
.dockerignore Normal file
View File

@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

20
.gitignore vendored Normal file
View File

@ -0,0 +1,20 @@
# Build and Release Folders
bin-debug/
bin-release/
[Oo]bj/
[Bb]in/
# Other files and folders
.settings/
# Executables
*.swf
*.air
*.ipa
*.apk
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important
# information for Eclipse / Flash Builder.
/LK/appsettings.json
/LK/appsettings.json

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,41 @@
{
"Version": 1,
"ProjectMap": {
"61d79f77-09ef-4a98-a50b-043b1d72c111": {
"ProjectGuid": "61d79f77-09ef-4a98-a50b-043b1d72c111",
"DisplayName": "Plugin",
"ColorIndex": 0
},
"68abbdf2-1485-4756-9a94-6afa874d69a3": {
"ProjectGuid": "68abbdf2-1485-4756-9a94-6afa874d69a3",
"DisplayName": "IoTGateway",
"ColorIndex": 1
},
"00e91fc1-d5cf-416a-aaaf-61567e368dcd": {
"ProjectGuid": "00e91fc1-d5cf-416a-aaaf-61567e368dcd",
"DisplayName": "IoTGateway.ViewModel",
"ColorIndex": 2
},
"9e7c8c77-643f-45cf-8edc-5b032c51d563": {
"ProjectGuid": "9e7c8c77-643f-45cf-8edc-5b032c51d563",
"DisplayName": "IoTGateway.DataAccess",
"ColorIndex": 3
},
"c2978e5d-e71e-4882-8ef1-4014e8565a77": {
"ProjectGuid": "c2978e5d-e71e-4882-8ef1-4014e8565a77",
"DisplayName": "IoTGateway.Model",
"ColorIndex": 4
},
"7b432fc9-57e6-44bf-b8a7-2a1fb31d6add": {
"ProjectGuid": "7b432fc9-57e6-44bf-b8a7-2a1fb31d6add",
"DisplayName": "DriverModbusTCP",
"ColorIndex": 5
},
"16f2c5cc-d881-4fdf-82de-d6df3525d65d": {
"ProjectGuid": "16f2c5cc-d881-4fdf-82de-d6df3525d65d",
"DisplayName": "IoTGateway.Test",
"ColorIndex": 6
}
},
"NextColorIndex": 7
}

BIN
.vs/IoTGateway/v16/.suo Normal file

Binary file not shown.

Binary file not shown.

BIN
.vs/IoTGateway/v17/.suo Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,86 @@
using System.Linq;
using System.Threading.Tasks;
using IoTGateway.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.DataAccess
{
public class DataContext : FrameworkContext
{
public DbSet<FrameworkUser> FrameworkUsers { get; set; }
public DbSet<Device> Devices { get; set; }
public DbSet<DeviceConfig> DeviceConfigs { get; set; }
public DbSet<DeviceVariable> DeviceVariables { get; set; }
public DbSet<Driver> Drivers { get; set; }
public DbSet<SystemConfig> SystemConfig { get; set; }
public DataContext(CS cs)
: base(cs)
{
}
public DataContext(string cs, DBTypeEnum dbtype)
: base(cs, dbtype)
{
}
public DataContext(string cs, DBTypeEnum dbtype, string version = null)
: base(cs, dbtype, version)
{
}
public DataContext(DbContextOptions<DataContext> options) : base(options) { }
public override async Task<bool> DataInit(object allModules, bool IsSpa)
{
var state = await base.DataInit(allModules, IsSpa);
bool emptydb = false;
try
{
emptydb = Set<FrameworkUser>().Count() == 0 && Set<FrameworkUserRole>().Count() == 0;
}
catch { }
if (state == true || emptydb == true)
{
//when state is true, means it's the first time EF create database, do data init here
//当state是true的时候表示这是第一次创建数据库可以在这里进行数据初始化
var user = new FrameworkUser
{
ITCode = "admin",
Password = Utils.GetMD5String("000000"),
IsValid = true,
Name = "Admin"
};
var userrole = new FrameworkUserRole
{
UserCode = user.ITCode,
RoleCode = "001"
};
Set<FrameworkUser>().Add(user);
Set<FrameworkUserRole>().Add(userrole);
await SaveChangesAsync();
}
return state;
}
}
/// <summary>
/// DesignTimeFactory for EF Migration, use your full connection string,
/// EF will find this class and use the connection defined here to run Add-Migration and Update-Database
/// </summary>
public class DataContextFactory : IDesignTimeDbContextFactory<DataContext>
{
public DataContext CreateDbContext(string[] args)
{
return new DataContext("Data Source = ../IoTGateway/iotgateway.db", DBTypeEnum.SQLite);
}
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTGateway.Model\IoTGateway.Model.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,794 @@
// <auto-generated />
using System;
using IoTGateway.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IoTGateway.DataAccess.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20211209085327_ini")]
partial class ini
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.9");
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("AutoStart")
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceName")
.HasColumnType("TEXT");
b.Property<int>("DeviceTypeEnum")
.HasColumnType("INTEGER");
b.Property<Guid?>("DriverId")
.HasColumnType("TEXT");
b.Property<uint>("Index")
.HasColumnType("INTEGER");
b.Property<Guid?>("ParentId")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("DriverId");
b.HasIndex("ParentId");
b.ToTable("Devices");
});
modelBuilder.Entity("IoTGateway.Model.DeviceConfig", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceConfigName")
.HasColumnType("TEXT");
b.Property<Guid?>("DeviceId")
.HasColumnType("TEXT");
b.Property<string>("EnumInfo")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("DeviceId");
b.ToTable("DeviceConfigs");
});
modelBuilder.Entity("IoTGateway.Model.DeviceVariable", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("DataType")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceAddress")
.HasColumnType("TEXT");
b.Property<Guid?>("DeviceId")
.HasColumnType("TEXT");
b.Property<string>("Method")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int>("ProtectType")
.HasColumnType("INTEGER");
b.Property<double>("ValueFactor")
.HasColumnType("REAL");
b.HasKey("ID");
b.HasIndex("DeviceId");
b.ToTable("DeviceVariables");
});
modelBuilder.Entity("IoTGateway.Model.Driver", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AssembleName")
.HasColumnType("TEXT");
b.Property<int>("AuthorizesNum")
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("DriverName")
.HasColumnType("TEXT");
b.Property<string>("FileName")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("Drivers");
});
modelBuilder.Entity("IoTGateway.Model.SystemConfig", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GatewayName")
.HasColumnType("TEXT");
b.Property<string>("MqttIp")
.HasColumnType("TEXT");
b.Property<int>("MqttPort")
.HasColumnType("INTEGER");
b.Property<string>("MqttUName")
.HasColumnType("TEXT");
b.Property<string>("MqttUPwd")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("SystemConfig");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.ActionLog", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ActionName")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime>("ActionTime")
.HasColumnType("TEXT");
b.Property<string>("ActionUrl")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<double>("Duration")
.HasColumnType("REAL");
b.Property<string>("IP")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("ITCode")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("LogType")
.HasColumnType("INTEGER");
b.Property<string>("ModuleName")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Remark")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("ActionLogs");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.DataPrivilege", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Domain")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.HasColumnType("TEXT");
b.Property<string>("RelateId")
.HasColumnType("TEXT");
b.Property<string>("TableName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("DataPrivileges");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FileAttachment", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ExtraInfo")
.HasColumnType("TEXT");
b.Property<byte[]>("FileData")
.HasColumnType("BLOB");
b.Property<string>("FileExt")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HandlerInfo")
.HasColumnType("TEXT");
b.Property<long>("Length")
.HasColumnType("INTEGER");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<string>("SaveMode")
.HasColumnType("TEXT");
b.Property<DateTime>("UploadTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FileAttachments");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkGroup", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("GroupName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("GroupRemark")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkGroups");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ActionName")
.HasColumnType("TEXT");
b.Property<string>("ClassName")
.HasColumnType("TEXT");
b.Property<int?>("DisplayOrder")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<string>("Domain")
.HasColumnType("TEXT");
b.Property<bool>("FolderOnly")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("IsInherit")
.HasColumnType("INTEGER");
b.Property<bool?>("IsInside")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<bool>("IsPublic")
.HasColumnType("INTEGER");
b.Property<string>("MethodName")
.HasColumnType("TEXT");
b.Property<string>("ModuleName")
.HasColumnType("TEXT");
b.Property<string>("PageName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<Guid?>("ParentId")
.HasColumnType("TEXT");
b.Property<bool>("ShowOnMenu")
.HasColumnType("INTEGER");
b.Property<string>("Url")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("ParentId");
b.ToTable("FrameworkMenus");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkRole", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("RoleName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("RoleRemark")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkRoles");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUser", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Address")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("CellPhone")
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("Gender")
.HasColumnType("INTEGER");
b.Property<string>("HomePhone")
.HasMaxLength(30)
.HasColumnType("TEXT");
b.Property<string>("ITCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("IsValid")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<Guid?>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("ZipCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("PhotoId");
b.ToTable("FrameworkUsers");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUserGroup", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkUserGroups");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUserRole", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkUserRoles");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FunctionPrivilege", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool?>("Allowed")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<Guid>("MenuItemId")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("MenuItemId");
b.ToTable("FunctionPrivileges");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.PersistedGrant", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationTime")
.HasColumnType("TEXT");
b.Property<DateTime>("Expiration")
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Type")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("PersistedGrants");
});
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.HasOne("IoTGateway.Model.Driver", "Driver")
.WithMany()
.HasForeignKey("DriverId");
b.HasOne("IoTGateway.Model.Device", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId");
b.Navigation("Driver");
b.Navigation("Parent");
});
modelBuilder.Entity("IoTGateway.Model.DeviceConfig", b =>
{
b.HasOne("IoTGateway.Model.Device", "Device")
.WithMany("DeviceConfigs")
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("IoTGateway.Model.DeviceVariable", b =>
{
b.HasOne("IoTGateway.Model.Device", "Device")
.WithMany("DeviceVariables")
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FrameworkMenu", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId");
b.Navigation("Parent");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUser", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FileAttachment", "Photo")
.WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Photo");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FunctionPrivilege", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FrameworkMenu", "MenuItem")
.WithMany("Privileges")
.HasForeignKey("MenuItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("MenuItem");
});
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.Navigation("Children");
b.Navigation("DeviceConfigs");
b.Navigation("DeviceVariables");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.Navigation("Children");
b.Navigation("Privileges");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,462 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace IoTGateway.DataAccess.Migrations
{
public partial class ini : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ActionLogs",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
ModuleName = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
ActionName = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
ITCode = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
ActionUrl = table.Column<string>(type: "TEXT", maxLength: 250, nullable: true),
ActionTime = table.Column<DateTime>(type: "TEXT", nullable: false),
Duration = table.Column<double>(type: "REAL", nullable: false),
Remark = table.Column<string>(type: "TEXT", nullable: true),
IP = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
LogType = table.Column<int>(type: "INTEGER", nullable: false),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ActionLogs", x => x.ID);
});
migrationBuilder.CreateTable(
name: "DataPrivileges",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
UserCode = table.Column<string>(type: "TEXT", nullable: true),
GroupCode = table.Column<string>(type: "TEXT", nullable: true),
TableName = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
RelateId = table.Column<string>(type: "TEXT", nullable: true),
Domain = table.Column<string>(type: "TEXT", nullable: true),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DataPrivileges", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Drivers",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
DriverName = table.Column<string>(type: "TEXT", nullable: true),
FileName = table.Column<string>(type: "TEXT", nullable: true),
AssembleName = table.Column<string>(type: "TEXT", nullable: true),
AuthorizesNum = table.Column<int>(type: "INTEGER", nullable: false),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Drivers", x => x.ID);
});
migrationBuilder.CreateTable(
name: "FileAttachments",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
FileName = table.Column<string>(type: "TEXT", nullable: false),
FileExt = table.Column<string>(type: "TEXT", maxLength: 10, nullable: false),
Path = table.Column<string>(type: "TEXT", nullable: true),
Length = table.Column<long>(type: "INTEGER", nullable: false),
UploadTime = table.Column<DateTime>(type: "TEXT", nullable: false),
SaveMode = table.Column<string>(type: "TEXT", nullable: true),
FileData = table.Column<byte[]>(type: "BLOB", nullable: true),
ExtraInfo = table.Column<string>(type: "TEXT", nullable: true),
HandlerInfo = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FileAttachments", x => x.ID);
});
migrationBuilder.CreateTable(
name: "FrameworkGroups",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
GroupCode = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
GroupName = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
GroupRemark = table.Column<string>(type: "TEXT", nullable: true),
TenantCode = table.Column<string>(type: "TEXT", nullable: true),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FrameworkGroups", x => x.ID);
});
migrationBuilder.CreateTable(
name: "FrameworkMenus",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
PageName = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
ActionName = table.Column<string>(type: "TEXT", nullable: true),
ModuleName = table.Column<string>(type: "TEXT", nullable: true),
FolderOnly = table.Column<bool>(type: "INTEGER", nullable: false),
IsInherit = table.Column<bool>(type: "INTEGER", nullable: false),
ClassName = table.Column<string>(type: "TEXT", nullable: true),
MethodName = table.Column<string>(type: "TEXT", nullable: true),
Domain = table.Column<string>(type: "TEXT", nullable: true),
ShowOnMenu = table.Column<bool>(type: "INTEGER", nullable: false),
IsPublic = table.Column<bool>(type: "INTEGER", nullable: false),
DisplayOrder = table.Column<int>(type: "INTEGER", nullable: false),
IsInside = table.Column<bool>(type: "INTEGER", nullable: false),
Url = table.Column<string>(type: "TEXT", nullable: true),
Icon = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
ParentId = table.Column<Guid>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FrameworkMenus", x => x.ID);
table.ForeignKey(
name: "FK_FrameworkMenus_FrameworkMenus_ParentId",
column: x => x.ParentId,
principalTable: "FrameworkMenus",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "FrameworkRoles",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
RoleCode = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
RoleName = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
RoleRemark = table.Column<string>(type: "TEXT", nullable: true),
TenantCode = table.Column<string>(type: "TEXT", nullable: true),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FrameworkRoles", x => x.ID);
});
migrationBuilder.CreateTable(
name: "FrameworkUserGroups",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
UserCode = table.Column<string>(type: "TEXT", nullable: false),
GroupCode = table.Column<string>(type: "TEXT", nullable: false),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FrameworkUserGroups", x => x.ID);
});
migrationBuilder.CreateTable(
name: "FrameworkUserRoles",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
UserCode = table.Column<string>(type: "TEXT", nullable: false),
RoleCode = table.Column<string>(type: "TEXT", nullable: false),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FrameworkUserRoles", x => x.ID);
});
migrationBuilder.CreateTable(
name: "PersistedGrants",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
Type = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UserCode = table.Column<string>(type: "TEXT", nullable: true),
CreationTime = table.Column<DateTime>(type: "TEXT", nullable: false),
Expiration = table.Column<DateTime>(type: "TEXT", nullable: false),
RefreshToken = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PersistedGrants", x => x.ID);
});
migrationBuilder.CreateTable(
name: "SystemConfig",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
GatewayName = table.Column<string>(type: "TEXT", nullable: true),
MqttIp = table.Column<string>(type: "TEXT", nullable: true),
MqttPort = table.Column<int>(type: "INTEGER", nullable: false),
MqttUName = table.Column<string>(type: "TEXT", nullable: true),
MqttUPwd = table.Column<string>(type: "TEXT", nullable: true),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SystemConfig", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Devices",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
DeviceName = table.Column<string>(type: "TEXT", nullable: true),
Index = table.Column<uint>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: true),
DriverId = table.Column<Guid>(type: "TEXT", nullable: true),
AutoStart = table.Column<bool>(type: "INTEGER", nullable: false),
DeviceTypeEnum = table.Column<int>(type: "INTEGER", nullable: false),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", nullable: true),
ParentId = table.Column<Guid>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Devices", x => x.ID);
table.ForeignKey(
name: "FK_Devices_Devices_ParentId",
column: x => x.ParentId,
principalTable: "Devices",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Devices_Drivers_DriverId",
column: x => x.DriverId,
principalTable: "Drivers",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "FrameworkUsers",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Gender = table.Column<int>(type: "INTEGER", nullable: true),
CellPhone = table.Column<string>(type: "TEXT", nullable: true),
HomePhone = table.Column<string>(type: "TEXT", maxLength: 30, nullable: true),
Address = table.Column<string>(type: "TEXT", maxLength: 200, nullable: true),
ZipCode = table.Column<string>(type: "TEXT", nullable: true),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
ITCode = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Password = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
IsValid = table.Column<bool>(type: "INTEGER", nullable: false),
PhotoId = table.Column<Guid>(type: "TEXT", nullable: true),
TenantCode = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FrameworkUsers", x => x.ID);
table.ForeignKey(
name: "FK_FrameworkUsers_FileAttachments_PhotoId",
column: x => x.PhotoId,
principalTable: "FileAttachments",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "FunctionPrivileges",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
RoleCode = table.Column<string>(type: "TEXT", nullable: true),
MenuItemId = table.Column<Guid>(type: "TEXT", nullable: false),
Allowed = table.Column<bool>(type: "INTEGER", nullable: false),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FunctionPrivileges", x => x.ID);
table.ForeignKey(
name: "FK_FunctionPrivileges_FrameworkMenus_MenuItemId",
column: x => x.MenuItemId,
principalTable: "FrameworkMenus",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "DeviceConfigs",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
DeviceConfigName = table.Column<string>(type: "TEXT", nullable: true),
Description = table.Column<string>(type: "TEXT", nullable: true),
Value = table.Column<string>(type: "TEXT", nullable: true),
EnumInfo = table.Column<string>(type: "TEXT", nullable: true),
DeviceId = table.Column<Guid>(type: "TEXT", nullable: true),
CreateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CreateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdateBy = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceConfigs", x => x.ID);
table.ForeignKey(
name: "FK_DeviceConfigs_Devices_DeviceId",
column: x => x.DeviceId,
principalTable: "Devices",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "DeviceVariables",
columns: table => new
{
ID = table.Column<Guid>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: true),
Description = table.Column<string>(type: "TEXT", nullable: true),
Method = table.Column<string>(type: "TEXT", nullable: true),
DeviceAddress = table.Column<string>(type: "TEXT", nullable: true),
DataType = table.Column<int>(type: "INTEGER", nullable: false),
ValueFactor = table.Column<double>(type: "REAL", nullable: false),
ProtectType = table.Column<int>(type: "INTEGER", nullable: false),
DeviceId = table.Column<Guid>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceVariables", x => x.ID);
table.ForeignKey(
name: "FK_DeviceVariables_Devices_DeviceId",
column: x => x.DeviceId,
principalTable: "Devices",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_DeviceConfigs_DeviceId",
table: "DeviceConfigs",
column: "DeviceId");
migrationBuilder.CreateIndex(
name: "IX_Devices_DriverId",
table: "Devices",
column: "DriverId");
migrationBuilder.CreateIndex(
name: "IX_Devices_ParentId",
table: "Devices",
column: "ParentId");
migrationBuilder.CreateIndex(
name: "IX_DeviceVariables_DeviceId",
table: "DeviceVariables",
column: "DeviceId");
migrationBuilder.CreateIndex(
name: "IX_FrameworkMenus_ParentId",
table: "FrameworkMenus",
column: "ParentId");
migrationBuilder.CreateIndex(
name: "IX_FrameworkUsers_PhotoId",
table: "FrameworkUsers",
column: "PhotoId");
migrationBuilder.CreateIndex(
name: "IX_FunctionPrivileges_MenuItemId",
table: "FunctionPrivileges",
column: "MenuItemId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ActionLogs");
migrationBuilder.DropTable(
name: "DataPrivileges");
migrationBuilder.DropTable(
name: "DeviceConfigs");
migrationBuilder.DropTable(
name: "DeviceVariables");
migrationBuilder.DropTable(
name: "FrameworkGroups");
migrationBuilder.DropTable(
name: "FrameworkRoles");
migrationBuilder.DropTable(
name: "FrameworkUserGroups");
migrationBuilder.DropTable(
name: "FrameworkUserRoles");
migrationBuilder.DropTable(
name: "FrameworkUsers");
migrationBuilder.DropTable(
name: "FunctionPrivileges");
migrationBuilder.DropTable(
name: "PersistedGrants");
migrationBuilder.DropTable(
name: "SystemConfig");
migrationBuilder.DropTable(
name: "Devices");
migrationBuilder.DropTable(
name: "FileAttachments");
migrationBuilder.DropTable(
name: "FrameworkMenus");
migrationBuilder.DropTable(
name: "Drivers");
}
}
}

View File

@ -0,0 +1,792 @@
// <auto-generated />
using System;
using IoTGateway.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IoTGateway.DataAccess.Migrations
{
[DbContext(typeof(DataContext))]
partial class DataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.9");
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("AutoStart")
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceName")
.HasColumnType("TEXT");
b.Property<int>("DeviceTypeEnum")
.HasColumnType("INTEGER");
b.Property<Guid?>("DriverId")
.HasColumnType("TEXT");
b.Property<uint>("Index")
.HasColumnType("INTEGER");
b.Property<Guid?>("ParentId")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("DriverId");
b.HasIndex("ParentId");
b.ToTable("Devices");
});
modelBuilder.Entity("IoTGateway.Model.DeviceConfig", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceConfigName")
.HasColumnType("TEXT");
b.Property<Guid?>("DeviceId")
.HasColumnType("TEXT");
b.Property<string>("EnumInfo")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("DeviceId");
b.ToTable("DeviceConfigs");
});
modelBuilder.Entity("IoTGateway.Model.DeviceVariable", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("DataType")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceAddress")
.HasColumnType("TEXT");
b.Property<Guid?>("DeviceId")
.HasColumnType("TEXT");
b.Property<string>("Method")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int>("ProtectType")
.HasColumnType("INTEGER");
b.Property<double>("ValueFactor")
.HasColumnType("REAL");
b.HasKey("ID");
b.HasIndex("DeviceId");
b.ToTable("DeviceVariables");
});
modelBuilder.Entity("IoTGateway.Model.Driver", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AssembleName")
.HasColumnType("TEXT");
b.Property<int>("AuthorizesNum")
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("DriverName")
.HasColumnType("TEXT");
b.Property<string>("FileName")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("Drivers");
});
modelBuilder.Entity("IoTGateway.Model.SystemConfig", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GatewayName")
.HasColumnType("TEXT");
b.Property<string>("MqttIp")
.HasColumnType("TEXT");
b.Property<int>("MqttPort")
.HasColumnType("INTEGER");
b.Property<string>("MqttUName")
.HasColumnType("TEXT");
b.Property<string>("MqttUPwd")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("SystemConfig");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.ActionLog", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ActionName")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime>("ActionTime")
.HasColumnType("TEXT");
b.Property<string>("ActionUrl")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<double>("Duration")
.HasColumnType("REAL");
b.Property<string>("IP")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("ITCode")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("LogType")
.HasColumnType("INTEGER");
b.Property<string>("ModuleName")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Remark")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("ActionLogs");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.DataPrivilege", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Domain")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.HasColumnType("TEXT");
b.Property<string>("RelateId")
.HasColumnType("TEXT");
b.Property<string>("TableName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("DataPrivileges");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FileAttachment", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ExtraInfo")
.HasColumnType("TEXT");
b.Property<byte[]>("FileData")
.HasColumnType("BLOB");
b.Property<string>("FileExt")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HandlerInfo")
.HasColumnType("TEXT");
b.Property<long>("Length")
.HasColumnType("INTEGER");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<string>("SaveMode")
.HasColumnType("TEXT");
b.Property<DateTime>("UploadTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FileAttachments");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkGroup", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("GroupName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("GroupRemark")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkGroups");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ActionName")
.HasColumnType("TEXT");
b.Property<string>("ClassName")
.HasColumnType("TEXT");
b.Property<int?>("DisplayOrder")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<string>("Domain")
.HasColumnType("TEXT");
b.Property<bool>("FolderOnly")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("IsInherit")
.HasColumnType("INTEGER");
b.Property<bool?>("IsInside")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<bool>("IsPublic")
.HasColumnType("INTEGER");
b.Property<string>("MethodName")
.HasColumnType("TEXT");
b.Property<string>("ModuleName")
.HasColumnType("TEXT");
b.Property<string>("PageName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<Guid?>("ParentId")
.HasColumnType("TEXT");
b.Property<bool>("ShowOnMenu")
.HasColumnType("INTEGER");
b.Property<string>("Url")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("ParentId");
b.ToTable("FrameworkMenus");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkRole", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("RoleName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("RoleRemark")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkRoles");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUser", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Address")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("CellPhone")
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("Gender")
.HasColumnType("INTEGER");
b.Property<string>("HomePhone")
.HasMaxLength(30)
.HasColumnType("TEXT");
b.Property<string>("ITCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("IsValid")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<Guid?>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("ZipCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("PhotoId");
b.ToTable("FrameworkUsers");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUserGroup", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkUserGroups");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUserRole", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkUserRoles");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FunctionPrivilege", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool?>("Allowed")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<Guid>("MenuItemId")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("MenuItemId");
b.ToTable("FunctionPrivileges");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.PersistedGrant", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationTime")
.HasColumnType("TEXT");
b.Property<DateTime>("Expiration")
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Type")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("PersistedGrants");
});
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.HasOne("IoTGateway.Model.Driver", "Driver")
.WithMany()
.HasForeignKey("DriverId");
b.HasOne("IoTGateway.Model.Device", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId");
b.Navigation("Driver");
b.Navigation("Parent");
});
modelBuilder.Entity("IoTGateway.Model.DeviceConfig", b =>
{
b.HasOne("IoTGateway.Model.Device", "Device")
.WithMany("DeviceConfigs")
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("IoTGateway.Model.DeviceVariable", b =>
{
b.HasOne("IoTGateway.Model.Device", "Device")
.WithMany("DeviceVariables")
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FrameworkMenu", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId");
b.Navigation("Parent");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUser", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FileAttachment", "Photo")
.WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Photo");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FunctionPrivilege", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FrameworkMenu", "MenuItem")
.WithMany("Privileges")
.HasForeignKey("MenuItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("MenuItem");
});
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.Navigation("Children");
b.Navigation("DeviceConfigs");
b.Navigation("DeviceVariables");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.Navigation("Children");
b.Navigation("Privileges");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
namespace IoTGateway.Model
{
public enum DeviceTypeEnum
{
[Display(Name = "采集组")]
Group = 0,
[Display(Name = "采集点")]
Device = 1
}
public enum AccessEnum
{
[Display(Name = "只读")]
ReadOnly = 0,
[Display(Name = "读写")]
ReadAndWrite = 1
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.Model
{
public class Device : TreePoco<Device>, IBasePoco
{
[Display(Name = "名称")]
public string DeviceName { get; set; }
[Display(Name = "排序")]
public uint Index { get; set; }
[Display(Name = "描述")]
public string Description { get; set; }
public Driver Driver { get; set; }
[Display(Name = "驱动")]
public Guid? DriverId { get; set; }
[Display(Name = "自启动")]
public bool AutoStart { get; set; }
[Display(Name = "类型")]
public DeviceTypeEnum DeviceTypeEnum { get; set; }
[Display(Name = "创建时间")]
public DateTime? CreateTime { get; set; }
[Display(Name = "创建人")]
public string CreateBy { get; set; }
[Display(Name = "更新时间")]
public DateTime? UpdateTime { get; set; }
[Display(Name = "更新人")]
public string UpdateBy { get; set; }
public List<DeviceConfig> DeviceConfigs { get; set; }
public List<DeviceVariable> DeviceVariables { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.Model
{
public class DeviceConfig : BasePoco
{
[Display(Name = "名称")]
public string DeviceConfigName { get; set; }
[Display(Name = "描述")]
public string Description { get; set; }
[Display(Name = "值")]
public string Value { get; set; }
[Display(Name = "备注")]
public string EnumInfo { get; set; }
public Device Device { get; set; }
[Display(Name = "设备")]
public Guid? DeviceId { get; set; }
}
}

View File

@ -0,0 +1,35 @@
using PluginInterface;
using System;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.Model
{
public class DeviceVariable : TopBasePoco, IVariable
{
[Display(Name = "变量名")]
public string Name { get; set; }
[Display(Name = "描述")]
public string Description { get; set; }
[Display(Name = "方法")]
public string Method { get; set; }
[Display(Name = "地址")]
public string DeviceAddress { get; set; }
[Display(Name = "数据类型")]
public PluginInterface.DataTypeEnum DataType { get; set; }
[Display(Name = "倍率")]
public double ValueFactor { get; set; }
[Display(Name = "权限")]
public ProtectTypeEnum ProtectType { get; set; }
public Device Device { get; set; }
[Display(Name = "采集点")]
public Guid? DeviceId { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.Model
{
public class Driver : BasePoco
{
[Display(Name = "驱动名")]
public string DriverName { get; set; }
[Display(Name = "文件名")]
public string FileName { get; set; }
[Display(Name = "程序集名")]
public string AssembleName { get; set; }
[Display(Name = "剩余授权数量")]
public int AuthorizesNum { get; set; }
}
}

View File

@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WalkingTec.Mvvm.Core
{
/// <summary>
/// FrameworkUser
/// </summary>
[Table("FrameworkUsers")]
public class FrameworkUser : FrameworkUserBase
{
[Display(Name = "_Admin.Email")]
[RegularExpression("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", ErrorMessage = "Validate.{0}formaterror")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string Email { get; set; }
[Display(Name = "_Admin.Gender")]
public GenderEnum? Gender { get; set; }
[Display(Name = "_Admin.CellPhone")]
[RegularExpression("^[1][3-9]\\d{9}$", ErrorMessage = "Validate.{0}formaterror")]
public string CellPhone { get; set; }
[Display(Name = "_Admin.HomePhone")]
[StringLength(30, ErrorMessage = "Validate.{0}stringmax{1}")]
[RegularExpression("^[-0-9\\s]{8,30}$", ErrorMessage = "Validate.{0}formaterror")]
public string HomePhone { get; set; }
[Display(Name = "_Admin.Address")]
[StringLength(200, ErrorMessage = "Validate.{0}stringmax{1}")]
public string Address { get; set; }
[Display(Name = "_Admin.ZipCode")]
[RegularExpression("^[0-9]{6,6}$", ErrorMessage = "Validate.{0}formaterror")]
public string ZipCode { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using PluginInterface;
using System.ComponentModel.DataAnnotations;
namespace IoTGateway.Model
{
public interface IVariable
{
[Display(Name = "变量名")]
public string Name { get; set; }
[Display(Name = "描述")]
public string Description { get; set; }
[Display(Name = "地址")]
public string DeviceAddress { get; set; }
[Display(Name = "数据类型")]
public PluginInterface.DataTypeEnum DataType { get; set; }
[Display(Name = "倍率")]
public double ValueFactor { get; set; }
[Display(Name = "权限")]
public ProtectTypeEnum ProtectType { get; set; }
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WalkingTec.Mvvm.Core" Version="5.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Plugins\PluginInterface\PluginInterface.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.Model
{
public class SystemConfig : BasePoco
{
[Display(Name = "网关名称")]
public string GatewayName { get; set; }
[Display(Name = "Mqtt服务器")]
public string MqttIp { get; set; }
[Display(Name = "Mqtt端口")]
public int MqttPort { get; set; }
[Display(Name = "Mqtt用户名")]
public string MqttUName { get; set; }
[Display(Name = "Mqtt密码")]
public string MqttUPwd { get; set; }
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Plugin;
namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
{
public partial class DeviceConfigBatchVM : BaseBatchVM<DeviceConfig, DeviceConfig_BatchEdit>
{
public DeviceConfigBatchVM()
{
ListVM = new DeviceConfigListVM();
LinkedVM = new DeviceConfig_BatchEdit();
}
public override bool DoBatchDelete()
{
var ret = base.DoBatchDelete();
if (ret)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateConfig(DC, deviceService, FC);
}
return ret;
}
public override bool DoBatchEdit()
{
var ret = base.DoBatchEdit();
if (ret)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateConfig(DC, deviceService, FC);
}
return ret;
}
}
/// <summary>
/// Class to define batch edit fields
/// </summary>
public class DeviceConfig_BatchEdit : BaseVM
{
[Display(Name = "值")]
public String Value { get; set; }
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
{
public partial class DeviceConfigTemplateVM : BaseTemplateVM
{
[Display(Name = "名称")]
public ExcelPropety DeviceConfigName_Excel = ExcelPropety.CreateProperty<DeviceConfig>(x => x.DeviceConfigName);
[Display(Name = "描述")]
public ExcelPropety Description_Excel = ExcelPropety.CreateProperty<DeviceConfig>(x => x.Description);
[Display(Name = "值")]
public ExcelPropety Value_Excel = ExcelPropety.CreateProperty<DeviceConfig>(x => x.Value);
[Display(Name = "备注")]
public ExcelPropety EnumInfo_Excel = ExcelPropety.CreateProperty<DeviceConfig>(x => x.EnumInfo);
public ExcelPropety Device_Excel = ExcelPropety.CreateProperty<DeviceConfig>(x => x.DeviceId);
protected override void InitVM()
{
Device_Excel.DataType = ColumnDataType.ComboBox;
Device_Excel.ListItems = DC.Set<Device>().GetSelectListItems(Wtm, y => y.DeviceName);
}
}
public class DeviceConfigImportVM : BaseImportVM<DeviceConfigTemplateVM, DeviceConfig>
{
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
{
public partial class DeviceConfigListVM : BasePagedListVM<DeviceConfig_View, DeviceConfigSearcher>
{
public List<TreeSelectListItem> AllDevices { get; set; }
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "BasicData", dialogWidth: 800),
//this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "BasicData", dialogWidth: 800),
//this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "BasicData", dialogWidth: 800),
//this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "BasicData"),
};
}
protected override void InitListVM()
{
AllDevices = DC.Set<Device>().AsNoTracking()
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
.OrderBy(x => x.Index).ThenBy(x => x.DeviceName)
.GetTreeSelectListItems(Wtm, x => x.DeviceName);
foreach (var device in AllDevices)
{
foreach (var item in device.Children)
{
item.Text = item.Text;
item.Icon = "layui-icon layui-icon-link";
item.Expended = true;
}
}
base.InitListVM();
}
protected override IEnumerable<IGridColumn<DeviceConfig_View>> InitGridHeader()
{
return new List<GridColumn<DeviceConfig_View>>{
this.MakeGridHeader(x => x.DeviceConfigName),
this.MakeGridHeader(x => x.Description),
this.MakeGridHeader(x => x.Value),
this.MakeGridHeader(x => x.EnumInfo),
this.MakeGridHeader(x => x.DeviceName_view),
this.MakeGridHeaderAction(width: 200)
};
}
public override IOrderedQueryable<DeviceConfig_View> GetSearchQuery()
{
var query = DC.Set<DeviceConfig>()
.CheckContain(Searcher.DeviceConfigName, x=>x.DeviceConfigName)
.CheckContain(Searcher.Value, x=>x.Value)
.CheckEqual(Searcher.DeviceId, x=>x.DeviceId)
.Select(x => new DeviceConfig_View
{
ID = x.ID,
DeviceConfigName = x.DeviceConfigName,
Description = x.Description,
Value = x.Value,
EnumInfo = x.EnumInfo,
DeviceName_view = x.Device.DeviceName,
})
.OrderBy(x => x.ID);
return query;
}
}
public class DeviceConfig_View : DeviceConfig{
[Display(Name = "设备名")]
public String DeviceName_view { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Microsoft.EntityFrameworkCore;
namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
{
public partial class DeviceConfigSearcher : BaseSearcher
{
[Display(Name = "名称")]
public String DeviceConfigName { get; set; }
[Display(Name = "值")]
public String Value { get; set; }
public List<ComboSelectListItem> AllDevices { get; set; }
[Display(Name = "设备名")]
public Guid? DeviceId { get; set; }
protected override void InitVM()
{
AllDevices = DC.Set<Device>().AsNoTracking().Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Device)
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
.ThenBy(x => x.Index).ThenBy(x => x.Parent.DeviceName)
.GetSelectListItems(Wtm, y => y.DeviceName);
}
}
}

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Plugin;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Primitives;
namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
{
public partial class DeviceConfigVM : BaseCRUDVM<DeviceConfig>
{
public List<ComboSelectListItem> AllDevices { get; set; }
public List<ComboSelectListItem> AllTypes { get; set; }
public DeviceConfigVM()
{
SetInclude(x => x.Device);
}
protected override void InitVM()
{
AllDevices = DC.Set<Device>().AsNoTracking().Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Device)
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
.OrderBy(x => x.Index).ThenBy(x => x.DeviceName)
.GetSelectListItems(Wtm, y => y.DeviceName);
if (Entity.DeviceId != null)
{
if (Entity.EnumInfo != null)
{
AllTypes = new List<ComboSelectListItem>();
var EnumInfos = JsonSerializer.Deserialize<Dictionary<string, int>>(Entity.EnumInfo);
foreach (var EnumInfo in EnumInfos)
{
var item = new ComboSelectListItem
{
Text = EnumInfo.Key,
Value = EnumInfo.Key,
Selected = Entity.Value == EnumInfo.Key ? true : false
};
AllTypes.Add(item);
}
}
}
}
public override void DoAdd()
{
base.DoAdd();
UpdateConfig();
}
public override void DoEdit(bool updateAllFields = false)
{
base.DoEdit(updateAllFields);
UpdateConfig();
}
public override void DoDelete()
{
//先获取id
var id = UpdateDevices.FC2Guids(FC);
var deviceId = DC.Set<DeviceConfig>().Where(x => id.Contains(x.ID)).Select(x => x.DeviceId).FirstOrDefault();
FC["Entity.DeviceId"] = (StringValues)deviceId.ToString();
base.DoDelete();
UpdateConfig();
}
private void UpdateConfig()
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateConfig(DC, deviceService, FC);
}
}
}

View File

@ -0,0 +1,109 @@
using Microsoft.EntityFrameworkCore;
using Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public class CopyVM : BaseVM
{
public string { get; set; }
public uint { get; set; } = 20;
public string { get; set; }
public void Copy()
{
using (var transaction = DC.BeginTransaction())
{
try
{
var device = DC.Set<Device>().Where(x => x.ID == Guid.Parse(FC["id"].ToString())).Include(x => x.Driver).FirstOrDefault();
var devices = new List<Device>();
if (device == null)
= "复制失败,找不到采集点";
else if (device.DeviceTypeEnum == DeviceTypeEnum.Group)
= "复制失败,组不支持复制";
else
{
var deviceConfigs = DC.Set<DeviceConfig>().Where(x => x.DeviceId == device.ID).ToList();
var deviceVariables = DC.Set<DeviceVariable>().Where(x => x.DeviceId == device.ID).ToList();
for (int i = 1; i <= ; i++)
{
var newDevice = new Device
{
ID = Guid.NewGuid(),
DeviceName = $"{device.DeviceName}-Copy{i}",
AutoStart = false,
ParentId = device.ParentId,
CreateBy = this.Wtm.LoginUserInfo.Name,
CreateTime = DateTime.Now,
Driver = device.Driver,
DriverId = device.DriverId,
Description = device.Description,
DeviceTypeEnum = device.DeviceTypeEnum
};
DC.Set<Device>().Add(newDevice);
devices.Add(newDevice);
foreach (var deviceConfig in deviceConfigs)
{
var newDeviceConfig = new DeviceConfig
{
DeviceId = newDevice.ID,
DeviceConfigName = deviceConfig.DeviceConfigName,
Description = deviceConfig.Description,
EnumInfo = deviceConfig.EnumInfo,
Value = deviceConfig.Value,
UpdateBy = this.Wtm.LoginUserInfo.Name,
UpdateTime = DateTime.Now
};
DC.Set<DeviceConfig>().Add(newDeviceConfig);
}
foreach (var deviceVariable in deviceVariables)
{
var newDeviceVariable = new DeviceVariable
{
DeviceId = newDevice.ID,
Name = deviceVariable.Name,
Description = deviceVariable.Description,
DataType = deviceVariable.DataType,
Method = deviceVariable.Method,
ProtectType = deviceVariable.ProtectType,
ValueFactor = deviceVariable.ValueFactor,
DeviceAddress = deviceVariable.DeviceAddress
};
DC.Set<DeviceVariable>().Add(newDeviceVariable);
}
}
}
DC.SaveChanges();
transaction.Commit();
= "复制成功";
var pluginManager = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
pluginManager?.CreateDeviceThreads(devices);
}
catch (Exception ex)
{
transaction.Rollback();
= $"复制失败,{ex}";
}
}
}
protected override void InitVM()
{
var device = DC.Set<Device>().AsNoTracking().Include(x => x.Parent).Where(x => x.ID == Guid.Parse(FC["id"].ToString())).FirstOrDefault();
= $"{device?.Parent?.DeviceName}===>{device?.DeviceName}";
base.InitVM();
}
}
}

View File

@ -0,0 +1,68 @@
using Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
static class DeleteDevices
{
public static DeleteRet doDelete(DeviceService pluginManager,IDataContext DC,List<Guid> Ids)
{
DeleteRet deleteRet = new() { IsSuccess = false };
using (var transaction = DC.BeginTransaction())
{
try
{
var daps = DC.Set<Device>().Where(x => Ids.Contains(x.ID)).ToList();
foreach (var dap in daps)
{
if (dap == null)
{
deleteRet.Message = "采集点不存在,可能已经被删除了";
return deleteRet;
}
else if (dap.DeviceTypeEnum == DeviceTypeEnum.Group)
{
deleteRet.Message = "有风险,暂不支持组删除";
return deleteRet;
}
else
{
var dapConfigs = DC.Set<DeviceConfig>().Where(x => x.DeviceId == dap.ID).ToList();
var dapVariables = DC.Set<DeviceVariable>().Where(x => x.DeviceId == dap.ID).ToList();
DC.Set<DeviceConfig>().RemoveRange(dapConfigs);
DC.Set<DeviceVariable>().RemoveRange(dapVariables);
}
pluginManager.RemoveDeviceThread(dap);
}
DC.Set<Device>().RemoveRange(daps);
DC.SaveChanges();
transaction.Commit();
deleteRet.IsSuccess=true;
}
catch (Exception ex)
{
transaction.Rollback();
deleteRet.Message = $"其他错误,{ex}";
}
}
return deleteRet;
}
}
public class DeleteRet
{
public bool IsSuccess { get; set; }
public string Message { get; set; }
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Microsoft.Extensions.Primitives;
using Plugin;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public partial class DeviceBatchVM : BaseBatchVM<Device, Device_BatchEdit>
{
public DeviceBatchVM()
{
ListVM = new DeviceListVM();
LinkedVM = new Device_BatchEdit();
}
public override bool DoBatchDelete()
{
StringValues IdsStr = new();
if (FC.ContainsKey("Ids"))
IdsStr = (StringValues)FC["Ids"];
else if (FC.ContainsKey("Ids[]"))
IdsStr = (StringValues)FC["Ids[]"];
List<Guid> Ids = new();
foreach (var item in IdsStr)
{
Ids.Add(Guid.Parse(item));
}
var pluginManager = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
var ret = DeleteDevices.doDelete(pluginManager, DC, Ids);
if (!ret.IsSuccess)
{
MSD.AddModelError("", ret.Message);
return false;
}
return true;
}
protected override void InitVM()
{
base.InitVM();
}
public override bool DoBatchEdit()
{
var ret = base.DoBatchEdit();
if (ret)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateDevice(DC, deviceService, FC);
}
return ret;
}
}
/// <summary>
/// Class to define batch edit fields
/// </summary>
public class Device_BatchEdit : BaseVM
{
public List<ComboSelectListItem> AllDrivers { get; set; }
public Guid? DriverId { get; set; }
[Display(Name = "自启动")]
public Boolean? AutoStart { get; set; }
[Display(Name = "类型")]
public DeviceTypeEnum? DeviceTypeEnum { get; set; }
public List<ComboSelectListItem> AllParents { get; set; }
[Display(Name = "_Admin.Parent")]
public Guid? ParentId { get; set; }
protected override void InitVM()
{
AllDrivers = DC.Set<Driver>().GetSelectListItems(Wtm, y => y.DriverName);
AllParents = DC.Set<Device>().GetSelectListItems(Wtm, y => y.DeviceName);
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public partial class DeviceTemplateVM : BaseTemplateVM
{
[Display(Name = "名称")]
public ExcelPropety DeviceName_Excel = ExcelPropety.CreateProperty<Device>(x => x.DeviceName);
[Display(Name = "排序")]
public ExcelPropety Index_Excel = ExcelPropety.CreateProperty<Device>(x => x.Index);
[Display(Name = "描述")]
public ExcelPropety Description_Excel = ExcelPropety.CreateProperty<Device>(x => x.Description);
public ExcelPropety Driver_Excel = ExcelPropety.CreateProperty<Device>(x => x.DriverId);
[Display(Name = "自启动")]
public ExcelPropety AutoStart_Excel = ExcelPropety.CreateProperty<Device>(x => x.AutoStart);
[Display(Name = "类型")]
public ExcelPropety DeviceTypeEnum_Excel = ExcelPropety.CreateProperty<Device>(x => x.DeviceTypeEnum);
[Display(Name = "_Admin.Parent")]
public ExcelPropety Parent_Excel = ExcelPropety.CreateProperty<Device>(x => x.ParentId);
protected override void InitVM()
{
Driver_Excel.DataType = ColumnDataType.ComboBox;
Driver_Excel.ListItems = DC.Set<Driver>().GetSelectListItems(Wtm, y => y.DriverName);
Parent_Excel.DataType = ColumnDataType.ComboBox;
Parent_Excel.ListItems = DC.Set<Device>().GetSelectListItems(Wtm, y => y.DeviceName);
}
}
public class DeviceImportVM : BaseImportVM<DeviceTemplateVM, Device>
{
}
}

View File

@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using IoTGateway.Model;
using Microsoft.Extensions.Primitives;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public partial class DeviceListVM : BasePagedListVM<Device_View, DeviceSearcher>
{
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeAction("Device","Copy","设备复制","设备复制", GridActionParameterTypesEnum.SingleId,"BasicData",600).SetIconCls("layui-icon layui-icon-template-1").SetPromptMessage("你确定复制设备,包括配置参数和变量?").SetDialogTitle("复制设备确认").SetHideOnToolBar(true).SetShowInRow(true).SetBindVisiableColName("copy"),
this.MakeAction("Device","CreateGroup","创建组","创建组", GridActionParameterTypesEnum.NoId,"BasicData",600).SetIconCls("_wtmicon _wtmicon-zuzhiqunzu").SetDialogTitle("创建组").SetShowInRow(false),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.Create, "创建设备","BasicData", dialogWidth: 800,name:"创建设备").SetIconCls("layui-icon layui-icon-senior"),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "BasicData", dialogWidth: 800),
//this.MakeStandardAction("Device", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Device", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "BasicData"),
};
}
protected override IEnumerable<IGridColumn<Device_View>> InitGridHeader()
{
return new List<GridColumn<Device_View>>{
this.MakeGridHeader(x => x.DeviceName),
this.MakeGridHeader(x => x.Index),
this.MakeGridHeader(x => x.Description),
this.MakeGridHeader(x => x.DriverName_view),
this.MakeGridHeader(x => x.AutoStart),
this.MakeGridHeader(x => x.DeviceTypeEnum),
this.MakeGridHeader(x => x.DeviceName_view),
this.MakeGridHeader(x=>"copy").SetHide().SetFormat((a,b)=>{
if(a.DeviceTypeEnum== DeviceTypeEnum.Device)
return "true";
return "false";
}),
this.MakeGridHeaderAction(width: 280)
};
}
public override IOrderedQueryable<Device_View> GetSearchQuery()
{
var data = DC.Set<Device>().AsNoTracking().Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Group).OrderBy(x => x.Index).ThenBy(x => x.DeviceName).ToList();
var dataRet = new List<Device_View>();
int order = 0;
foreach (var x in data)
{
var itemF = new Device_View
{
ID = x.ID,
Index = x.Index,
DeviceName = x.DeviceName,
Description = x.Description,
DeviceTypeEnum = x.DeviceTypeEnum,
DriverName_view = x.Driver?.DriverName,
ExtraOrder = order
};
dataRet.Add(itemF);
order++;
StringValues Ids = new();
if (FC.ContainsKey("Ids[]"))
{
Ids = (StringValues)FC["Ids[]"];
}
var childrens = DC.Set<Device>().AsNoTracking().Where(y => y.ParentId == x.ID).Include(x => x.Driver).OrderBy(x => x.Index).ThenBy(x => x.DeviceName).ToList();
if (Ids.Count != 0)
childrens = childrens.Where(x => Ids.Contains(x.ID.ToString())).ToList();
foreach (var y in childrens)
{
var itemC = new Device_View
{
ID = y.ID,
Index = y.Index,
DeviceName = "&nbsp;&nbsp;&nbsp;&nbsp;" + y.DeviceName,
AutoStart = y.AutoStart,
Description = y.Description,
DeviceTypeEnum = y.DeviceTypeEnum,
DriverName_view = y.Driver?.DriverName,
DeviceName_view = itemF.DeviceName,
ExtraOrder = order
};
dataRet.Add(itemC);
}
order++;
}
return dataRet.AsQueryable<Device_View>().OrderBy(x => x.ExtraOrder);
}
}
public class Device_View : Device
{
[Display(Name = "驱动名")]
public String DriverName_view { get; set; }
[Display(Name = "父级名")]
public String DeviceName_view { get; set; }
public int ExtraOrder { get; set; }
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public partial class DeviceSearcher : BaseSearcher
{
[Display(Name = "名称")]
public String DeviceName { get; set; }
public List<ComboSelectListItem> AllDrivers { get; set; }
public Guid? DriverId { get; set; }
[Display(Name = "自启动")]
public Boolean? AutoStart { get; set; }
[Display(Name = "类型")]
public DeviceTypeEnum? DeviceTypeEnum { get; set; }
public List<ComboSelectListItem> AllParents { get; set; }
[Display(Name = "_Admin.Parent")]
public Guid? ParentId { get; set; }
protected override void InitVM()
{
AllDrivers = DC.Set<Driver>().GetSelectListItems(Wtm, y => y.DriverName);
AllParents = DC.Set<Device>().GetSelectListItems(Wtm, y => y.DeviceName);
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Plugin;
using Microsoft.EntityFrameworkCore;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public partial class DeviceVM : BaseCRUDVM<Device>
{
public List<ComboSelectListItem> AllDrivers { get; set; }
public List<ComboSelectListItem> AllParents { get; set; }
public DeviceVM()
{
SetInclude(x => x.Driver);
SetInclude(x => x.Parent);
}
protected override void InitVM()
{
AllDrivers = DC.Set<Driver>().GetSelectListItems(Wtm, y => y.DriverName);
AllParents = DC.Set<Device>().Where(x=>x.DeviceTypeEnum== DeviceTypeEnum.Group).GetSelectListItems(Wtm, y => y.DeviceName);
}
public override void DoAdd()
{
try
{
base.DoAdd();
//添加结束
if (this.Entity.DeviceTypeEnum == DeviceTypeEnum.Device)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
deviceService._DrvierManager.AddConfigs(this.Entity.ID, this.Entity.DriverId);
var dap = DC.Set<Device>().Where(x => x.ID == Entity.ID).Include(x => x.Driver).SingleOrDefault();
deviceService.CreateDeviceThread(dap);
}
}
catch (Exception ex)
{
MSD.AddModelError("", $"添加失败,{ex.Message}");
}
}
public override void DoEdit(bool updateAllFields = false)
{
base.DoEdit(updateAllFields);
//修改结束
var pluginManager = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateDevice(DC, pluginManager, FC);
}
public override void DoDelete()
{
List<Guid> Ids = new List<Guid>() { Guid.Parse(FC["id"].ToString()) };
var pluginManager = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
var ret = DeleteDevices.doDelete(pluginManager, DC, Ids);
if (!ret.IsSuccess)
MSD.AddModelError("", ret.Message);
}
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using PluginInterface;
using Plugin;
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
{
public partial class DeviceVariableBatchVM : BaseBatchVM<DeviceVariable, DeviceVariable_BatchEdit>
{
public DeviceVariableBatchVM()
{
ListVM = new DeviceVariableListVM();
LinkedVM = new DeviceVariable_BatchEdit();
}
public override bool DoBatchDelete()
{
var ret = base.DoBatchDelete();
if (ret)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateVaribale(DC, deviceService, FC);
}
return ret;
}
public override bool DoBatchEdit()
{
var ret = base.DoBatchEdit();
if (ret)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateVaribale(DC, deviceService, FC);
}
return ret;
}
}
/// <summary>
/// Class to define batch edit fields
/// </summary>
public class DeviceVariable_BatchEdit : BaseVM
{
[Display(Name = "变量名")]
public String Name { get; set; }
[Display(Name = "地址")]
public String DeviceAddress { get; set; }
[Display(Name = "数据类型")]
public DataTypeEnum? DataType { get; set; }
[Display(Name = "倍率")]
public Double? ValueFactor { get; set; }
[Display(Name = "权限")]
public ProtectTypeEnum? ProtectType { get; set; }
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using PluginInterface;
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
{
public partial class DeviceVariableTemplateVM : BaseTemplateVM
{
[Display(Name = "变量名")]
public ExcelPropety Name_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.Name);
[Display(Name = "描述")]
public ExcelPropety Description_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.Description);
[Display(Name = "方法")]
public ExcelPropety Method_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.Method);
[Display(Name = "地址")]
public ExcelPropety DeviceAddress_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.DeviceAddress);
[Display(Name = "数据类型")]
public ExcelPropety DataType_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.DataType);
[Display(Name = "倍率")]
public ExcelPropety ValueFactor_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.ValueFactor);
[Display(Name = "权限")]
public ExcelPropety ProtectType_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.ProtectType);
public ExcelPropety Device_Excel = ExcelPropety.CreateProperty<DeviceVariable>(x => x.DeviceId);
protected override void InitVM()
{
Device_Excel.DataType = ColumnDataType.ComboBox;
Device_Excel.ListItems = DC.Set<Device>().GetSelectListItems(Wtm, y => y.DeviceName);
}
}
public class DeviceVariableImportVM : BaseImportVM<DeviceVariableTemplateVM, DeviceVariable>
{
}
}

View File

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using IoTGateway.Model;
using PluginInterface;
using Plugin;
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
{
public partial class DeviceVariableListVM : BasePagedListVM<DeviceVariable_View, DeviceVariableSearcher>
{
public List<TreeSelectListItem> AllDevices { get; set; }
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "BasicData", dialogWidth: 800).SetBindVisiableColName("detail"),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "BasicData"),
};
}
protected override void InitListVM()
{
AllDevices = DC.Set<Device>().AsNoTracking()
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
.OrderBy(x => x.Index).ThenBy(x => x.DeviceName)
.GetTreeSelectListItems(Wtm, x => x.DeviceName);
foreach (var device in AllDevices)
{
foreach (var item in device.Children)
{
item.Text = item.Text;
item.Icon = "layui-icon layui-icon-link";
item.Expended = true;
}
}
base.InitListVM();
}
protected override IEnumerable<IGridColumn<DeviceVariable_View>> InitGridHeader()
{
return new List<GridColumn<DeviceVariable_View>>{
this.MakeGridHeader(x => x.Name).SetSort(true).SetWidth(120),
//this.MakeGridHeader(x => x.Description),
this.MakeGridHeader(x => x.Method).SetSort(true).SetWidth(160),
this.MakeGridHeader(x => x.DeviceAddress).SetSort(true).SetWidth(80),
this.MakeGridHeader(x => x.DataType).SetSort(true).SetWidth(110),
this.MakeGridHeader(x => x.Value).SetWidth(80),
this.MakeGridHeader(x => x.State).SetWidth(80),
this.MakeGridHeader(x => x.ValueFactor).SetSort(true).SetWidth(80),
//this.MakeGridHeader(x => x.ProtectType).SetSort(true),
this.MakeGridHeader(x => x.DeviceName_view).SetSort(true).SetWidth(90),
this.MakeGridHeader(x=> "detail").SetHide().SetFormat((a,b)=>{
return "false";
}),
this.MakeGridHeaderAction(width: 150)
};
}
public override void AfterDoSearcher()
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
foreach (var item in EntityList)
{
var DapThread = deviceService.DeviceThreads.Where(x => x.Device.ID == item.DeviceId).FirstOrDefault();
if (DapThread?.DeviceValues != null && DapThread.DeviceValues.ContainsKey(item.ID))
{
item.Value = DapThread.DeviceValues[item.ID].Value?.ToString();
item.State = DapThread.DeviceValues[item.ID].StatusType.ToString();
}
}
}
public override IOrderedQueryable<DeviceVariable_View> GetSearchQuery()
{
var query = DC.Set<DeviceVariable>()
.CheckContain(Searcher.Name, x => x.Name)
.CheckContain(Searcher.Method, x => x.Method)
.CheckContain(Searcher.DeviceAddress, x => x.DeviceAddress)
.CheckEqual(Searcher.DataType, x => x.DataType)
.CheckEqual(Searcher.DeviceId, x => x.DeviceId)
.Select(x => new DeviceVariable_View
{
ID = x.ID,
DeviceId = x.DeviceId,
Name = x.Name,
Description = x.Description,
Method = x.Method,
DeviceAddress = x.DeviceAddress,
DataType = x.DataType,
ValueFactor = x.ValueFactor,
ProtectType = x.ProtectType,
DeviceName_view = x.Device.DeviceName,
})
.OrderBy(x => x.ID);
return query;
}
}
public class DeviceVariable_View : DeviceVariable
{
[Display(Name = "设备名")]
public String DeviceName_view { get; set; }
[Display(Name = "值")]
public String Value { get; set; }
[Display(Name = "状态")]
public String State { get; set; }
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using PluginInterface;
using Microsoft.EntityFrameworkCore;
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
{
public partial class DeviceVariableSearcher : BaseSearcher
{
[Display(Name = "变量名")]
public String Name { get; set; }
[Display(Name = "方法")]
public String Method { get; set; }
[Display(Name = "地址")]
public String DeviceAddress { get; set; }
[Display(Name = "数据类型")]
public DataTypeEnum? DataType { get; set; }
public List<ComboSelectListItem> AllDevices { get; set; }
[Display(Name = "设备名")]
public Guid? DeviceId { get; set; }
protected override void InitVM()
{
AllDevices = DC.Set<Device>().AsNoTracking().Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Device)
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
.ThenBy(x => x.Index).ThenBy(x => x.Parent.DeviceName)
.GetSelectListItems(Wtm, y => y.DeviceName);
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Plugin;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Primitives;
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
{
public partial class DeviceVariableVM : BaseCRUDVM<DeviceVariable>
{
public List<ComboSelectListItem> AllDevices { get; set; }
public List<ComboSelectListItem> AllMethods { get; set; }
public DeviceVariableVM()
{
SetInclude(x => x.Device);
}
protected override void InitVM()
{
AllDevices = DC.Set<Device>().AsNoTracking().Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Device)
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
.OrderBy(x => x.Index).ThenBy(x => x.DeviceName)
.GetSelectListItems(Wtm, y => y.DeviceName);
if (Entity.DeviceId != null)
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
AllMethods = deviceService.GetDriverMethods(Entity.DeviceId);
var DapThread = deviceService.DeviceThreads.Where(x => x.Device.ID == Entity.DeviceId).FirstOrDefault();
}
}
public override void DoAdd()
{
base.DoAdd();
UpdateVaribale();
}
public override void DoEdit(bool updateAllFields = false)
{
base.DoEdit(updateAllFields);
UpdateVaribale();
}
public override void DoDelete()
{
//先获取id
var id= UpdateDevices.FC2Guids(FC);
var deviceId = DC.Set<DeviceVariable>().Where(x => id.Contains(x.ID)).Select(x=>x.DeviceId).FirstOrDefault();
FC["Entity.DeviceId"] =(StringValues)deviceId.ToString();
base.DoDelete();
UpdateVaribale();
}
private void UpdateVaribale()
{
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
UpdateDevices.UpdateVaribale(DC, deviceService, FC);
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DriverVMs
{
public partial class DriverBatchVM : BaseBatchVM<Driver, Driver_BatchEdit>
{
public DriverBatchVM()
{
ListVM = new DriverListVM();
LinkedVM = new Driver_BatchEdit();
}
}
/// <summary>
/// Class to define batch edit fields
/// </summary>
public class Driver_BatchEdit : BaseVM
{
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DriverVMs
{
public partial class DriverTemplateVM : BaseTemplateVM
{
[Display(Name = "驱动名")]
public ExcelPropety DriverName_Excel = ExcelPropety.CreateProperty<Driver>(x => x.DriverName);
[Display(Name = "文件名")]
public ExcelPropety FileName_Excel = ExcelPropety.CreateProperty<Driver>(x => x.FileName);
[Display(Name = "程序集名")]
public ExcelPropety AssembleName_Excel = ExcelPropety.CreateProperty<Driver>(x => x.AssembleName);
[Display(Name = "剩余授权数量")]
public ExcelPropety AuthorizesNum_Excel = ExcelPropety.CreateProperty<Driver>(x => x.AuthorizesNum);
protected override void InitVM()
{
}
}
public class DriverImportVM : BaseImportVM<DriverTemplateVM, Driver>
{
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DriverVMs
{
public partial class DriverListVM : BasePagedListVM<Driver_View, DriverSearcher>
{
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeStandardAction("Driver", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"BasicData", dialogWidth: 800),
this.MakeStandardAction("Driver", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Driver", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Driver", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Driver", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "BasicData", dialogWidth: 800),
this.MakeStandardAction("Driver", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "BasicData", dialogWidth: 800),
//this.MakeStandardAction("Driver", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "BasicData", dialogWidth: 800),
//this.MakeStandardAction("Driver", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "BasicData"),
};
}
protected override IEnumerable<IGridColumn<Driver_View>> InitGridHeader()
{
return new List<GridColumn<Driver_View>>{
this.MakeGridHeader(x => x.DriverName),
this.MakeGridHeader(x => x.FileName),
this.MakeGridHeader(x => x.AssembleName),
this.MakeGridHeader(x => x.AuthorizesNum),
this.MakeGridHeaderAction(width: 200)
};
}
public override IOrderedQueryable<Driver_View> GetSearchQuery()
{
var query = DC.Set<Driver>()
.CheckContain(Searcher.DriverName, x=>x.DriverName)
.Select(x => new Driver_View
{
ID = x.ID,
DriverName = x.DriverName,
FileName = x.FileName,
AssembleName = x.AssembleName,
AuthorizesNum = x.AuthorizesNum,
})
.OrderBy(x => x.ID);
return query;
}
}
public class Driver_View : Driver{
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DriverVMs
{
public partial class DriverSearcher : BaseSearcher
{
[Display(Name = "驱动名")]
public String DriverName { get; set; }
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Plugin;
namespace IoTGateway.ViewModel.BasicData.DriverVMs
{
public partial class DriverVM : BaseCRUDVM<Driver>
{
public DriverVM()
{
}
protected override void InitVM()
{
}
public override void DoAdd()
{
var drvierService = Wtm.ServiceProvider.GetService(typeof(DrvierService)) as DrvierService;
Entity.AssembleName = drvierService.GetAssembleNameByFileName(Entity.FileName);
if (string.IsNullOrEmpty(Entity.AssembleName))
{
MSD.AddModelError("", "程序集获取失败");
return;
}
base.DoAdd();
}
public override void DoEdit(bool updateAllFields = false)
{
base.DoEdit(updateAllFields);
}
public override void DoDelete()
{
base.DoDelete();
}
}
}

View File

@ -0,0 +1,111 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Primitives;
using Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData
{
internal static class UpdateDevices
{
internal enum FromVM
{
Variable,
Config,
Device
}
internal static void UpdateVaribale(IDataContext DC, DeviceService deviceService, Dictionary<String, Object> FC)
{
var devices = GetDevices(DC, deviceService, FromVM.Variable, FC);
deviceService.UpdateDevices(devices);
}
internal static void UpdateConfig(IDataContext DC, DeviceService deviceService, Dictionary<String, Object> FC)
{
var devices = GetDevices(DC,deviceService, FromVM.Config,FC);
deviceService.UpdateDevices(devices);
}
internal static void UpdateDevice(IDataContext DC, DeviceService deviceService, Dictionary<String, Object> FC)
{
var devices = GetDevices(DC, deviceService, FromVM.Device, FC);
deviceService.UpdateDevices(devices);
}
internal static List<Device> GetDevices(IDataContext DC, DeviceService deviceService, FromVM fromVM, Dictionary<String, Object> FC)
{
List<Device> devices = new();
List<Guid> Ids = FC2Guids(FC);
if (FC.ContainsKey("Entity.DeviceId"))
{
StringValues id = (StringValues)FC["Entity.DeviceId"];
var device = DC.Set<Device>().Where(x => x.ID == Guid.Parse(id)).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}
foreach (var varId in Ids)
{
switch (fromVM)
{
case FromVM.Variable:
var deviceVariable = DC.Set<DeviceVariable>().Where(x => x.ID == varId).SingleOrDefault();
if (deviceVariable != null)
{
var device = DC.Set<Device>().Where(x => x.ID == deviceVariable.DeviceId).Include(x=>x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}
break;
case FromVM.Config:
foreach (var deviceConfigId in Ids)
{
var deviceConfig = DC.Set<DeviceConfig>().Where(x => x.ID == deviceConfigId).SingleOrDefault();
if (deviceConfig != null)
{
var device = DC.Set<Device>().Where(x => x.ID == deviceConfig.DeviceId).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}
}
break;
case FromVM.Device:
foreach (var deviceId in Ids)
{
var device = DC.Set<Device>().Where(x => x.ID == deviceId).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}
break;
default:
break;
}
}
return devices;
}
internal static List<Guid> FC2Guids(Dictionary<String, Object> FC)
{
List<Guid> Ids = new();
StringValues IdsStr = new();
if (FC.ContainsKey("Ids"))
IdsStr = (StringValues)FC["Ids"];
else if (FC.ContainsKey("Ids[]"))
IdsStr = (StringValues)FC["Ids[]"];
else if (FC.ContainsKey("id"))
IdsStr = (StringValues)FC["id"];
foreach (var item in IdsStr)
{
Ids.Add(Guid.Parse(item));
}
return Ids;
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.Config.SystemConfigVMs
{
public partial class SystemConfigBatchVM : BaseBatchVM<SystemConfig, SystemConfig_BatchEdit>
{
public SystemConfigBatchVM()
{
ListVM = new SystemConfigListVM();
LinkedVM = new SystemConfig_BatchEdit();
}
}
/// <summary>
/// Class to define batch edit fields
/// </summary>
public class SystemConfig_BatchEdit : BaseVM
{
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.Config.SystemConfigVMs
{
public partial class SystemConfigTemplateVM : BaseTemplateVM
{
[Display(Name = "网关名称")]
public ExcelPropety GatewayName_Excel = ExcelPropety.CreateProperty<SystemConfig>(x => x.GatewayName);
[Display(Name = "Mqtt服务器")]
public ExcelPropety MqttIp_Excel = ExcelPropety.CreateProperty<SystemConfig>(x => x.MqttIp);
[Display(Name = "Mqtt端口")]
public ExcelPropety MqttPort_Excel = ExcelPropety.CreateProperty<SystemConfig>(x => x.MqttPort);
[Display(Name = "Mqtt用户名")]
public ExcelPropety MqttUName_Excel = ExcelPropety.CreateProperty<SystemConfig>(x => x.MqttUName);
[Display(Name = "Mqtt密码")]
public ExcelPropety MqttUPwd_Excel = ExcelPropety.CreateProperty<SystemConfig>(x => x.MqttUPwd);
protected override void InitVM()
{
}
}
public class SystemConfigImportVM : BaseImportVM<SystemConfigTemplateVM, SystemConfig>
{
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.Config.SystemConfigVMs
{
public partial class SystemConfigListVM : BasePagedListVM<SystemConfig_View, SystemConfigSearcher>
{
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
//this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"Config", dialogWidth: 800),
this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "Config", dialogWidth: 800),
//this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "Config", dialogWidth: 800),
this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "Config", dialogWidth: 800),
//this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "Config", dialogWidth: 800),
//this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "Config", dialogWidth: 800),
//this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "Config", dialogWidth: 800),
//this.MakeStandardAction("SystemConfig", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "Config"),
};
}
protected override IEnumerable<IGridColumn<SystemConfig_View>> InitGridHeader()
{
return new List<GridColumn<SystemConfig_View>>{
this.MakeGridHeader(x => x.GatewayName),
this.MakeGridHeader(x => x.MqttIp),
this.MakeGridHeader(x => x.MqttPort),
this.MakeGridHeader(x => x.MqttUName),
this.MakeGridHeader(x => x.MqttUPwd),
this.MakeGridHeaderAction(width: 200)
};
}
public override IOrderedQueryable<SystemConfig_View> GetSearchQuery()
{
var query = DC.Set<SystemConfig>()
.Select(x => new SystemConfig_View
{
ID = x.ID,
GatewayName = x.GatewayName,
MqttIp = x.MqttIp,
MqttPort = x.MqttPort,
MqttUName = x.MqttUName,
MqttUPwd = x.MqttUPwd,
})
.OrderBy(x => x.ID);
return query;
}
}
public class SystemConfig_View : SystemConfig{
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.Config.SystemConfigVMs
{
public partial class SystemConfigSearcher : BaseSearcher
{
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
using Plugin;
namespace IoTGateway.ViewModel.Config.SystemConfigVMs
{
public partial class SystemConfigVM : BaseCRUDVM<SystemConfig>
{
public SystemConfigVM()
{
}
protected override void InitVM()
{
}
public override void DoAdd()
{
base.DoAdd();
}
public override void DoEdit(bool updateAllFields = false)
{
base.DoEdit(updateAllFields);
var myMqttClient = Wtm.ServiceProvider.GetService(typeof(MyMqttClient)) as MyMqttClient;
myMqttClient.InitClient();
}
public override void DoDelete()
{
base.DoDelete();
}
}
}

View File

@ -0,0 +1,78 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.ViewModel.HomeVMs
{
public class LoginVM : BaseVM
{
[Display(Name = "_Admin.Account")]
[Required(ErrorMessage = "Validate.{0}required")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ITCode { get; set; }
[Display(Name = "_Admin.Password")]
[Required(ErrorMessage = "Validate.{0}required")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string Password { get; set; }
[Display(Name = "Login.RememberMe")]
public bool RememberLogin { get; set; }
private string _redirect;
public string Redirect
{
get
{
var rv = _redirect;
if (string.IsNullOrEmpty(rv) == false)
{
if (rv.StartsWith("/#") == false)
{
rv = "/#" + rv;
}
if(rv.Split("#/").Length > 2)
{
int index = rv.LastIndexOf("#/");
rv = rv.Substring(0, index);
}
}
return rv;
}
set { _redirect = value; }
}
[Display(Name = "Login.InputValidation")]
public string VerifyCode { get; set; }
/// <summary>
/// 进行登录
/// </summary>
/// <param name="ignorePris">外部传递的页面权限</param>
/// <returns>登录用户的信息</returns>
public async System.Threading.Tasks.Task<LoginUserInfo> DoLoginAsync(bool ignorePris = false)
{
//根据用户名和密码查询用户
var rv = await DC.Set<FrameworkUser>().Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid).Select(x => new { itcode = x.ITCode, id = x.GetID() }).SingleOrDefaultAsync();
//如果没有找到则输出错误
if (rv == null)
{
MSD.AddModelError("", Localizer["Sys.LoginFailed"]);
return null;
}
else
{
LoginUserInfo user = new LoginUserInfo
{
ITCode = rv.itcode,
UserId = rv.id.ToString()
};
//读取角色,用户组,页面权限,数据权限等框架配置信息
await user.LoadBasicInfoAsync(Wtm);
return user;
}
}
}
}

View File

@ -0,0 +1,76 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
namespace IoTGateway.ViewModel.HomeVMs
{
public class RegVM : BaseVM
{
[Display(Name = "_Admin.Account")]
[Required(ErrorMessage = "Validate.{0}required")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ITCode { get; set; }
[Display(Name = "_Admin.Name")]
[Required(ErrorMessage = "Validate.{0}required")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string Name { get; set; }
[Display(Name = "_Admin.Password")]
[Required(AllowEmptyStrings = false)]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string Password { get; set; }
[Display(Name = "_Admin.Password")]
[Required(AllowEmptyStrings = false)]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string NewPasswordComfirm { get; set; }
[Display(Name = "_Admin.Email")]
[RegularExpression("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", ErrorMessage = "Validate.{0}formaterror")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string Email { get; set; }
[Display(Name = "_Admin.CellPhone")]
[RegularExpression("^[1][3-9]\\d{9}$", ErrorMessage = "Validate.{0}formaterror")]
public string CellPhone { get; set; }
/// <summary>
/// 进行登录
/// </summary>
/// <returns>登录用户的信息</returns>
public bool DoReg()
{
//检查两次新密码是否输入一致,如不一致则输出错误
if (Password != NewPasswordComfirm)
{
MSD.AddModelError("NewPasswordComfirm", Localizer["Sys.PasswordNotSame"]);
return false;
}
//检查itcode是否重复
var exist = DC.Set<FrameworkUser>().Any(x => x.ITCode.ToLower() == ITCode.ToLower());
if (exist == true)
{
MSD.AddModelError("ITCode", Localizer["Login.ItcodeDuplicate"]);
return false;
}
FrameworkUser user = new FrameworkUser
{
ITCode = ITCode,
Name = Name,
Password = Utils.GetMD5String(Password),
IsValid = true,
CellPhone = CellPhone,
Email = Email
};
DC.Set<FrameworkUser>().Add(user);
DC.SaveChanges();
return true;
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\IoTGateway.Model\IoTGateway.Model.csproj" />
<ProjectReference Include="..\Plugins\Plugin\Plugin.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
// WTM默认页面 Wtm buidin page
using System;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs
{
public class ActionLogBatchVM : BaseBatchVM<ActionLog, ActionLog_BatchEdit>
{
public ActionLogBatchVM()
{
ListVM = new ActionLogListVM();
LinkedVM = new ActionLog_BatchEdit();
}
}
public class ActionLog_BatchEdit : BaseVM
{
protected override void InitVM()
{
}
}
}

View File

@ -0,0 +1,100 @@
// WTM默认页面 Wtm buidin page
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs
{
public class ActionLogListVM : BasePagedListVM<ActionLog, ActionLogSearcher>
{
protected override List<GridAction> InitGridAction()
{
var actions = new List<GridAction>
{
this.MakeStandardAction("ActionLog", GridActionStandardTypesEnum.BatchDelete, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("ActionLog", GridActionStandardTypesEnum.Details, "","_Admin", dialogWidth: 800).SetHideOnToolBar(true),
this.MakeStandardAction("ActionLog", GridActionStandardTypesEnum.ExportExcel, "","_Admin"),
};
return actions;
}
protected override IEnumerable<IGridColumn<ActionLog>> InitGridHeader()
{
var header = new List<GridColumn<ActionLog>>();
header.Add(this.MakeGridHeader(x => x.LogType, 100).SetForeGroundFunc((entity)=> {
if(entity.LogType == ActionLogTypesEnum.Exception)
{
return "FF0000";
}
else
{
return "";
}
}));
header.Add(this.MakeGridHeader(x => x.ModuleName, 120));
header.Add(this.MakeGridHeader(x => x.ActionName, 120));
header.Add(this.MakeGridHeader(x => x.ITCode, 120));
header.Add(this.MakeGridHeader(x => x.ActionUrl, 200));
header.Add(this.MakeGridHeader(x => x.ActionTime, 200).SetSort(true).SetFormat((a, b) => a.ActionTime.ToString("yyyy-MM-dd HH:mm:ss")));
header.Add(this.MakeGridHeader(x => x.Duration, 100).SetSort(true).SetForeGroundFunc((entity)=> {
if(entity.Duration <= 1)
{
return "008000";
}
else if(entity.Duration <= 3)
{
return "FFC90E";
}
else
{
return "FF0000";
}
}).SetFormat((entity,v)=> { return ((double)v).ToString("f2"); }));
header.Add(this.MakeGridHeader(x => x.IP, 120));
header.Add(this.MakeGridHeader(x => x.Remark).SetFormat((a,b)=> {
if (SearcherMode == ListVMSearchModeEnum.Search && a.Remark?.Length > 30)
{
a.Remark = a.Remark.Substring(0, 30) + "...";
}
return a.Remark;
}));
header.Add(this.MakeGridHeaderAction(width: 120));
return header;
}
public override IOrderedQueryable<ActionLog> GetSearchQuery()
{
var query = DC.Set<ActionLog>()
.CheckContain(Searcher.ITCode, x=>x.ITCode)
.CheckContain(Searcher.ActionUrl, x=>x.ActionUrl)
//.CheckEqual(Searcher.LogType, x=>x.LogType)
.CheckContain(Searcher.LogType, x=>x.LogType)
.CheckContain(Searcher.IP, x=>x.IP)
.CheckBetween(Searcher.ActionTime?.GetStartTime(), Searcher.ActionTime?.GetEndTime(), x=>x.ActionTime, includeMax:false)
.CheckWhere(Searcher.Duration,x=>x.Duration >= Searcher.Duration)
.Select(x=>new ActionLog()
{
ID = x.ID,
ModuleName = x.ModuleName,
ITCode = x.ITCode,
ActionTime = x.ActionTime,
ActionName = x.ActionName,
ActionUrl = x.ActionUrl,
Duration = x.Duration,
IP = x.IP,
LogType = x.LogType,
Remark = x.Remark,
CreateBy = x.CreateBy,
CreateTime = x.CreateTime,
UpdateBy = x.UpdateBy,
UpdateTime = x.UpdateTime
})
.OrderByDescending(x=>x.ActionTime);
return query;
}
}
}

View File

@ -0,0 +1,32 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs
{
public class ActionLogSearcher : BaseSearcher
{
[Display(Name = "_Admin.Account")]
public string ITCode { get; set; }
[Display(Name = "Url")]
public string ActionUrl { get; set; }
[Display(Name = "_Admin.LogType")]
public List<ActionLogTypesEnum> LogType { get; set; }
[Display(Name = "_Admin.ActionTime")]
public DateRange ActionTime { get; set; }
[Display(Name = "IP")]
public string IP { get; set; }
[Display(Name = "_Admin.Duration")]
public double? Duration { get; set; }
}
}

View File

@ -0,0 +1,9 @@
// WTM默认页面 Wtm buidin page
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs
{
public class ActionLogVM : BaseCRUDVM<ActionLog>
{
}
}

View File

@ -0,0 +1,23 @@
// WTM默认页面 Wtm buidin page
using System;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs
{
public class DataPrivilegeBatchVM : BaseBatchVM<DataPrivilege, DataPrivilege_BatchEdit>
{
public DataPrivilegeBatchVM()
{
ListVM = new DataPrivilegeListVM();
LinkedVM = new DataPrivilege_BatchEdit();
}
}
public class DataPrivilege_BatchEdit : BaseVM
{
}
}

View File

@ -0,0 +1,142 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs
{
public class DataPrivilegeListVM : BasePagedListVM<DataPrivilege_ListView, DataPrivilegeSearcher>
{
protected override List<GridAction> InitGridAction()
{
string tp = "";
if (Searcher.DpType == DpTypeEnum.User)
{
tp = "User";
}
if (Searcher.DpType == DpTypeEnum.UserGroup)
{
tp = "UserGroup";
}
return new List<GridAction>
{
this.MakeStandardAction("DataPrivilege", GridActionStandardTypesEnum.Create, "","_Admin", dialogWidth: 800).SetQueryString($"Type={tp}"),
this.MakeStandardAction("DataPrivilege", GridActionStandardTypesEnum.ExportExcel, "","_Admin"),
};
}
protected override IEnumerable<IGridColumn<DataPrivilege_ListView>> InitGridHeader()
{
return new List<GridColumn<DataPrivilege_ListView>>{
this.MakeGridHeader(x => x.Name, 200),
this.MakeGridHeader(x => x.TableName).SetFormat((entity,val)=>GetPrivilegeName(entity)),
this.MakeGridHeader(x => x.RelateIDs),
this.MakeGridHeader(x=>x.Edit,200).SetFormat((entity,val)=>GetOperation(entity)).SetHeader(Localizer["Sys.Operation"]).SetDisableExport(),
this.MakeGridHeader(x => x.DpType).SetHide(true),
this.MakeGridHeader(x => x.TargetId).SetHide(true)
};
}
public string GetPrivilegeName(DataPrivilege_ListView item)
{
var temp = Wtm.DataPrivilegeSettings.Where(x => x.ModelName == item.TableName).SingleOrDefault();
if (temp == null)
{
return "";
}
else
{
return temp.PrivillegeName;
}
}
public List<ColumnFormatInfo> GetOperation(DataPrivilege_ListView item)
{
string editurl = "";
string delurl = "";
if(Searcher.DpType == DpTypeEnum.User)
{
editurl = "/_Admin/DataPrivilege/Edit?ModelName=" + item.TableName + "&Type=User&Id=" + item.TargetId;
delurl = "/_Admin/DataPrivilege/Delete?ModelName=" + item.TableName + "&Type=User&Id=" + item.TargetId;
}
else
{
editurl = "/_Admin/DataPrivilege/Edit?ModelName=" + item.TableName + "&Type=UserGroup&Id=" + item.TargetId;
delurl = "/_Admin/DataPrivilege/Delete?ModelName=" + item.TableName + "&Type=UserGroup&Id=" + item.TargetId;
}
return new List<ColumnFormatInfo>
{
ColumnFormatInfo.MakeDialogButton(ButtonTypesEnum.Button,editurl,Localizer["Sys.Edit"],800,null,Localizer["Sys.Edit"]),
ColumnFormatInfo.MakeDialogButton(ButtonTypesEnum.Button,delurl,Localizer["Sys.Delete"],null,null,showDialog:false)
};
}
/// <summary>
/// 查询结果
/// </summary>
public override IOrderedQueryable<DataPrivilege_ListView> GetSearchQuery()
{
IOrderedQueryable<DataPrivilege_ListView> query = null;
if (Searcher.DpType == DpTypeEnum.User)
{
query = DC.Set<DataPrivilege>()
.Join(DC.Set<FrameworkUser>(), ok => ok.UserCode, ik => ik.ITCode, (dp, user) => new { dp = dp, user = user })
.CheckContain(Searcher.Name, x => x.user.Name)
.CheckContain(Searcher.TableName, x => x.dp.TableName)
.GroupBy(x => new { x.user.Name, x.user.ITCode, x.dp.TableName }, x => x.dp.RelateId)
.Select(x => new DataPrivilege_ListView
{
TargetId = x.Key.ITCode,
Name = x.Key.Name,
TableName = x.Key.TableName,
RelateIDs = x.Count(),
DpType = (int)Searcher.DpType
})
.OrderByDescending(x => x.Name).OrderByDescending(x => x.TableName);
}
else
{
query = DC.Set<DataPrivilege>()
.Join(DC.Set<FrameworkGroup>(), ok => ok.GroupCode, ik => ik.GroupCode, (dp, group) => new { dp = dp, group = group })
.CheckContain(Searcher.Name, x => x.group.GroupName)
.CheckContain(Searcher.TableName, x => x.dp.TableName)
.GroupBy(x => new { x.group.GroupName, x.group.GroupCode, x.dp.TableName }, x => x.dp.RelateId)
.Select(x => new DataPrivilege_ListView
{
TargetId = x.Key.GroupCode,
Name = x.Key.GroupName,
TableName = x.Key.TableName,
RelateIDs = x.Count(),
DpType = (int)Searcher.DpType
})
.OrderByDescending(x => x.Name).OrderByDescending(x => x.TableName);
}
return query;
}
}
public class DataPrivilege_ListView : BasePoco
{
[Display(Name = "_Admin.DpTargetName")]
public string Name { get; set; }
public string TargetId { get; set; }
[Display(Name = "_Admin.DataPrivilegeName")]
public string TableName { get; set; }
[Display(Name = "_Admin.DataPrivilegeCount")]
public int RelateIDs { get; set; }
public int DpType { get; set; }
public string DomainName { get; set; }
public Guid? DomainID { get; set; }
public string Edit { get; set; }
}
}

View File

@ -0,0 +1,34 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs
{
public enum DpTypeEnum
{
[Display(Name = "_Admin.GroupDp")]
UserGroup,
[Display(Name = "_Admin.UserDp")]
User
}
public class DataPrivilegeSearcher : BaseSearcher
{
[Display(Name = "_Admin.Account")]
public string Name { get; set; }
[Display(Name = "_Admin.Privileges")]
public string TableName { get; set; }
public List<ComboSelectListItem> TableNames { get; set; }
[Display(Name = "_Admin.DpType")]
public DpTypeEnum DpType { get; set; }
public Guid? DomainID { get; set; }
public List<ComboSelectListItem> AllDomains { get; set; }
protected override void InitVM()
{
TableNames = new List<ComboSelectListItem>();
}
}
}

View File

@ -0,0 +1,289 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs;
using WalkingTec.Mvvm.Core.Extensions;
using System.Threading.Tasks;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs
{
public class DataPrivilegeVM : BaseCRUDVM<DataPrivilege>
{
public List<ComboSelectListItem> TableNames { get; set; }
public List<ComboSelectListItem> AllItems { get; set; }
public List<ComboSelectListItem> AllGroups { get; set; }
[Display(Name = "_Admin.AllowedDp")]
public List<string> SelectedItemsID { get; set; }
[Display(Name = "_Admin.DpType")]
public DpTypeEnum DpType { get; set; }
public DpListVM DpList { get; set; }
[Display(Name = "_Admin.AllDp")]
public bool? IsAll { get; set; }
public DataPrivilegeVM()
{
DpList = new DpListVM();
IsAll = false;
}
protected override void InitVM()
{
TableNames = new List<ComboSelectListItem>();
if (ControllerName.Contains("/api") == false)
{
AllGroups = DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, x => x.GroupName, x=>x.GroupCode);
TableNames = Wtm.DataPrivilegeSettings.ToListItems(x => x.PrivillegeName, x => x.ModelName);
}
SelectedItemsID = new List<string>();
List<string> rids = null;
if (DpType == DpTypeEnum.User)
{
rids = DC.Set<DataPrivilege>().Where(x => x.TableName == Entity.TableName && x.UserCode == Entity.UserCode).Select(x => x.RelateId).ToList();
}
else
{
rids = DC.Set<DataPrivilege>().Where(x => x.TableName == Entity.TableName && x.GroupCode == Entity.GroupCode).Select(x => x.RelateId).ToList();
}
if (rids.Contains(null))
{
IsAll = true;
}
else
{
SelectedItemsID.AddRange(rids.Select(x => x));
}
}
protected override void ReInitVM()
{
TableNames = new List<ComboSelectListItem>();
AllItems = new List<ComboSelectListItem>();
TableNames = Wtm.DataPrivilegeSettings.ToListItems(x => x.PrivillegeName, x => x.ModelName);
if (ControllerName.Contains("/api") == false)
{
AllGroups = DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode);
}
}
public override void Validate()
{
if (DpType == DpTypeEnum.User)
{
if (string.IsNullOrEmpty(Entity.UserCode))
{
MSD.AddModelError("Entity.UserCode", Localizer["Validate.{0}required", Localizer["_Admin.Account"]]);
}
else
{
var user = DC.Set<FrameworkUser>().Where(x => x.ITCode == Entity.UserCode).FirstOrDefault();
if (user == null)
{
MSD.AddModelError("Entity.UserCode", Localizer["Sys.CannotFindUser", Entity.UserCode]);
}
}
}
else
{
if(string.IsNullOrEmpty(Entity.GroupCode))
{
MSD.AddModelError("Entity.GroupId", Localizer["Validate.{0}required", Localizer["_Admin.Group"]]);
}
}
base.Validate();
}
public override async Task DoAddAsync()
{
if (SelectedItemsID == null && IsAll == false)
{
return;
}
List<Guid> oldIDs = null;
if (DpType == DpTypeEnum.User)
{
oldIDs = DC.Set<DataPrivilege>().Where(x => x.UserCode == Entity.UserCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
}
else
{
oldIDs = DC.Set<DataPrivilege>().Where(x => x.GroupCode == Entity.GroupCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
}
foreach (var oldid in oldIDs)
{
DataPrivilege dp = new DataPrivilege { ID = oldid };
DC.Set<DataPrivilege>().Attach(dp);
DC.DeleteEntity(dp);
}
if (DpType == DpTypeEnum.User)
{
if (IsAll == true)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = null;
dp.UserCode = Entity.UserCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
else
{
foreach (var id in SelectedItemsID)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = id;
dp.UserCode = Entity.UserCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
}
}
else
{
if (IsAll == true)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = null;
dp.GroupCode = Entity.GroupCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
else
{
foreach (var id in SelectedItemsID)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = id;
dp.GroupCode = Entity.GroupCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
}
}
await DC.SaveChangesAsync();
if (DpType == DpTypeEnum.User)
{
await Wtm.RemoveUserCache(Entity.UserCode);
}
else
{
var userids = DC.Set<FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode).Select(x => x.UserCode).ToArray();
await Wtm.RemoveUserCache(userids);
}
}
public override async Task DoEditAsync(bool updateAllFields = false)
{
List<Guid> oldIDs = null;
if (DpType == DpTypeEnum.User)
{
oldIDs = DC.Set<DataPrivilege>().Where(x => x.UserCode == Entity.UserCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
}
else
{
oldIDs = DC.Set<DataPrivilege>().Where(x => x.GroupCode == Entity.GroupCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
}
foreach (var oldid in oldIDs)
{
DataPrivilege dp = new DataPrivilege { ID = oldid };
DC.Set<DataPrivilege>().Attach(dp);
DC.DeleteEntity(dp);
}
if(IsAll == true)
{
if (DpType == DpTypeEnum.User)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = null;
dp.UserCode = Entity.UserCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
else
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = null;
dp.GroupCode = Entity.GroupCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
}
else {
if (SelectedItemsID != null)
{
if (DpType == DpTypeEnum.User)
{
foreach (var id in SelectedItemsID)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = id;
dp.UserCode = Entity.UserCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
}
else
{
foreach (var id in SelectedItemsID)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = id;
dp.GroupCode = Entity.GroupCode;
dp.TableName = this.Entity.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
}
}
}
await DC.SaveChangesAsync();
if (DpType == DpTypeEnum.User)
{
await Wtm.RemoveUserCache(Entity.UserCode);
}
else
{
var userids = DC.Set<FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode).Select(x => x.UserCode).ToArray();
await Wtm.RemoveUserCache(userids);
}
}
public override async Task DoDeleteAsync()
{
List<Guid> oldIDs = null;
if (DpType == DpTypeEnum.User)
{
oldIDs = DC.Set<DataPrivilege>().Where(x => x.UserCode == Entity.UserCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
}
else
{
oldIDs = DC.Set<DataPrivilege>().Where(x => x.GroupCode == Entity.GroupCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
}
foreach (var oldid in oldIDs)
{
DataPrivilege dp = new DataPrivilege { ID = oldid };
DC.Set<DataPrivilege>().Attach(dp);
DC.DeleteEntity(dp);
}
await DC.SaveChangesAsync();
if (DpType == DpTypeEnum.User)
{
await Wtm.RemoveUserCache(Entity.UserCode.ToString());
}
else
{
var userids = DC.Set<FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode).Select(x => x.UserCode).ToArray();
await Wtm.RemoveUserCache(userids);
}
}
}
}

View File

@ -0,0 +1,68 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs
{
public class DpListVM : BasePagedListVM<DpView,DpSearcher>
{
public DpListVM()
{
NeedPage = false;
}
protected override IEnumerable<IGridColumn<DpView>> InitGridHeader()
{
return new List<GridColumn<DpView>>{
this.MakeGridHeader(x => x.Name),
};
}
public override IOrderedQueryable<DpView> GetSearchQuery()
{
var dps = Wtm.DataPrivilegeSettings.Where(x => x.ModelName == Searcher.TableName).SingleOrDefault();
if (dps != null)
{
return dps.GetItemList(Wtm, Searcher.Filter).Select(x => new DpView { ID = x.Value.ToString(), Name = x.Text }).AsQueryable().OrderBy(x => x.Name);
}
else
{
return new List<DpView>().AsQueryable().OrderBy(x => x.Name);
}
}
public override IOrderedQueryable<DpView> GetBatchQuery()
{
var dps = Wtm.DataPrivilegeSettings.Where(x => x.ModelName == Searcher.TableName).SingleOrDefault();
if (dps != null)
{
return dps.GetItemList(Wtm, null,Ids).Select(x => new DpView { ID = x.Value.ToString(), Name = x.Text }).AsQueryable().OrderBy(x => x.Name);
}
else
{
return new List<DpView>().AsQueryable().OrderBy(x => x.Name);
}
}
}
public class DpView : TopBasePoco
{
public new string ID { get; set; }
[Display(Name = "_Admin.DataPrivilegeName")]
public string Name { get; set; }
}
public class DpSearcher : BaseSearcher
{
public string TableName { get; set; }
[Display(Name = "_Admin.DataPrivilegeName")]
public string Filter { get; set; }
}
}

View File

@ -0,0 +1,20 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs
{
public class FrameworkGroupBatchVM : BaseBatchVM<FrameworkGroup, BaseVM>
{
public FrameworkGroupBatchVM()
{
ListVM = new FrameworkGroupListVM();
}
}
}

View File

@ -0,0 +1,17 @@
// WTM默认页面 Wtm buidin page
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs
{
public class FrameworkGroupTemplateVM : BaseTemplateVM
{
public ExcelPropety r1 = ExcelPropety.CreateProperty<FrameworkGroup>(x => x.GroupCode);
public ExcelPropety r2 = ExcelPropety.CreateProperty<FrameworkGroup>(x => x.GroupName);
public ExcelPropety r3 = ExcelPropety.CreateProperty<FrameworkGroup>(x => x.GroupRemark);
}
public class FrameworkGroupImportVM : BaseImportVM<FrameworkGroupTemplateVM, FrameworkGroup>
{
}
}

View File

@ -0,0 +1,45 @@
// WTM默认页面 Wtm buidin page
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs
{
public class FrameworkGroupListVM : BasePagedListVM<FrameworkGroup, FrameworkGroupSearcher>
{
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeStandardAction("FrameworkGroup", GridActionStandardTypesEnum.Create, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkGroup", GridActionStandardTypesEnum.Edit, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkGroup", GridActionStandardTypesEnum.Delete, "", "_Admin",dialogWidth: 800),
this.MakeStandardAction("FrameworkGroup", GridActionStandardTypesEnum.BatchDelete, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkGroup", GridActionStandardTypesEnum.Import, "","_Admin", dialogWidth: 800),
this.MakeAction("FrameworkGroup","DataFunction",Localizer["_Admin.DataPrivilege"],Localizer["_Admin.DataPrivilege"], GridActionParameterTypesEnum.SingleId,"_Admin",800,null,null,x=>x.GroupCode).SetShowInRow(),
this.MakeStandardAction("FrameworkGroup", GridActionStandardTypesEnum.ExportExcel, "","_Admin"),
};
}
protected override IEnumerable<IGridColumn<FrameworkGroup>> InitGridHeader()
{
return new List<GridColumn<FrameworkGroup>>{
this.MakeGridHeader(x => x.GroupCode, 120),
this.MakeGridHeader(x => x.GroupName, 120),
this.MakeGridHeader(x => x.GroupRemark),
this.MakeGridHeaderAction(width: 300)
};
}
public override IOrderedQueryable<FrameworkGroup> GetSearchQuery()
{
var query = DC.Set<FrameworkGroup>()
.CheckContain(Searcher.GroupCode, x=>x.GroupCode)
.CheckContain(Searcher.GroupName, x=>x.GroupName)
.OrderBy(x => x.GroupCode);
return query;
}
}
}

View File

@ -0,0 +1,100 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs
{
public class FrameworkGroupMDVM : BaseVM
{
public string GroupCode { get; set; }
public List<GroupDp> DpLists { get; set; }
public FrameworkGroupMDVM()
{
}
protected override void InitVM()
{
DpLists = new List<GroupDp>();
foreach (var item in Wtm.DataPrivilegeSettings)
{
DpListVM list = new DpListVM();
list.Searcher = new DpSearcher();
list.Searcher.TableName = item.ModelName;
DpLists.Add(new GroupDp { DpName = item.PrivillegeName, List = list, SelectedIds = new List<string>() });
}
var alldp = DC.Set<DataPrivilege>().Where(x => x.GroupCode == GroupCode).ToList();
foreach (var item in DpLists)
{
var select = alldp.Where(x => x.TableName == item.List.Searcher.TableName).Select(x => x.RelateId).ToList();
if(select.Count == 0)
{
item.IsAll = null;
}
else if (select.Contains(null))
{
item.IsAll = true;
}
else
{
item.IsAll = false;
item.SelectedIds = select;
}
}
}
public bool DoChange()
{
List<Guid> oldIDs = DC.Set<DataPrivilege>().Where(x => x.GroupCode == GroupCode).Select(x => x.ID).ToList();
foreach (var oldid in oldIDs)
{
DataPrivilege dp = new DataPrivilege { ID = oldid };
DC.Set<DataPrivilege>().Attach(dp);
DC.DeleteEntity(dp);
}
foreach (var item in DpLists)
{
if(item.IsAll == true)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = null;
dp.GroupCode = GroupCode;
dp.TableName = item.List.Searcher.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
if (item.IsAll == false && item.SelectedIds != null)
{
foreach (var id in item.SelectedIds)
{
DataPrivilege dp = new DataPrivilege();
dp.RelateId = id;
dp.GroupCode = GroupCode;
dp.TableName = item.List.Searcher.TableName;
DC.Set<DataPrivilege>().Add(dp);
}
}
}
DC.SaveChanges();
return true;
}
}
public class GroupDp
{
public DpListVM List { get; set; }
public string DpName { get; set; }
public List<string> SelectedIds { get; set; }
public bool? IsAll { get; set; }
}
}

View File

@ -0,0 +1,19 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs
{
public class FrameworkGroupSearcher : BaseSearcher
{
[Display(Name = "_Admin.GroupCode")]
public string GroupCode { get; set; }
[Display(Name = "_Admin.GroupName")]
public string GroupName { get; set; }
}
}

View File

@ -0,0 +1,51 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs
{
public class FrameworkGroupVM : BaseCRUDVM<FrameworkGroup>
{
public override DuplicatedInfo<FrameworkGroup> SetDuplicatedCheck()
{
var rv = CreateFieldsInfo(SimpleField(x => x.GroupName));
rv.AddGroup(SimpleField(x => x.GroupCode));
return rv;
}
public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.GroupCode"))
{
FC.Remove("Entity.GroupCode");
}
base.DoEdit(updateAllFields);
}
public override async Task DoDeleteAsync()
{
using (var tran = DC.BeginTransaction())
{
try
{
await base.DoDeleteAsync();
var ur = DC.Set<FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode);
DC.Set<FrameworkUserGroup>().RemoveRange(ur);
DC.SaveChanges();
tran.Commit();
await Wtm.RemoveUserCache(ur.Select(x => x.UserCode).ToArray());
}
catch
{
tran.Rollback();
}
}
}
}
}

View File

@ -0,0 +1,111 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public class FrameworkActionListVM : BasePagedListVM<FrameworkAction_ListView, BaseSearcher>
{
public FrameworkActionListVM()
{
NeedPage = false;
}
protected override List<GridAction> InitGridAction()
{
var actions = new List<GridAction>
{
};
return actions;
}
protected override IEnumerable<IGridColumn<FrameworkAction_ListView>> InitGridHeader()
{
var header = new List<GridColumn<FrameworkAction_ListView>>();
header.Add(this.MakeGridHeader(x => x.ModuleName, 150));
header.Add(this.MakeGridHeader(x => x.ActionName, 150));
header.Add(this.MakeGridHeader(x => x.ClassName, 150));
header.Add(this.MakeGridHeader(x => x.MethodName, 150));
return header;
}
/// <summary>
/// 查询结果
/// </summary>
public override IOrderedQueryable<FrameworkAction_ListView> GetSearchQuery()
{
var newdc = DC as FrameworkContext;
List<FrameworkAction_ListView> actions = new List<FrameworkAction_ListView>();
var urls = newdc.BaseFrameworkMenus.Where(y => y.IsInside == true && y.FolderOnly == false).Select(y => y.Url).Distinct().ToList();
if (ControllerName.Contains("/api") == false)
{
actions = Wtm.GlobaInfo.AllModule.SelectMany(x=>x.Actions)
.Where(x => urls.Contains(x.Url) == false)
.Select(x => new FrameworkAction_ListView
{
ID = x.ID,
ModuleID = x.ModuleId,
ModuleName = x.Module.ModuleName,
ActionName = x.ActionName,
ClassName = x.Module.ClassName,
MethodName = x.MethodName,
AreaName = x.Module.Area?.AreaName
}).ToList();
}
else
{
actions = Wtm.GlobaInfo.AllModule.SelectMany(x => x.Actions)
.Where(x => x.Module.IsApi == true && urls.Contains(x.Url) == false)
.Select(x => new FrameworkAction_ListView
{
ID = x.ID,
ModuleID = x.ModuleId,
ModuleName = x.Module.ModuleName,
ActionName = x.ActionName,
ClassName = x.Module.ClassName,
MethodName = x.MethodName,
AreaName = x.Module.Area?.AreaName
}).ToList();
}
var modules = Wtm.GlobaInfo.AllModule;
List<FrameworkAction_ListView> toremove = new List<FrameworkAction_ListView>();
foreach (var item in actions)
{
var m = modules.Where(x => x.ClassName == item.ClassName && x.Area?.AreaName == item.AreaName).FirstOrDefault();
var a = m?.Actions.Where(x => x.MethodName == item.MethodName).FirstOrDefault();
if(m?.IgnorePrivillege == true || a?.IgnorePrivillege == true)
{
toremove.Add(item);
}
}
toremove.ForEach(x => actions.Remove(x));
return actions.AsQueryable().OrderBy(x=>x.AreaName).ThenBy(x=>x.ModuleName).ThenBy(x=>x.MethodName);
}
}
public class FrameworkAction_ListView : BasePoco
{
public Guid? ModuleID { get; set; }
[Display(Name = "Codegen.ModuleName")]
public string ModuleName { get; set; }
[Display(Name = "_Admin.ActionName")]
public string ActionName { get; set; }
[Display(Name = "_Admin.ClassName")]
public string ClassName { get; set; }
[Display(Name = "_Admin.MethodName")]
public string MethodName { get; set; }
public string AreaName { get; set; }
}
}

View File

@ -0,0 +1,48 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public class FrameworkMenuBatchVM : BaseBatchVM<FrameworkMenu, FrameworkMenu_BatchEdit>
{
public FrameworkMenuBatchVM()
{
}
protected override void InitVM()
{
}
public override bool DoBatchDelete()
{
if (Ids != null)
{
foreach (var item in Ids)
{
FrameworkMenu f = new FrameworkMenu { ID = Guid.Parse(item) };
DC.CascadeDelete(f);
}
}
DC.SaveChanges();
return true;
}
}
public class FrameworkMenu_BatchEdit : BaseVM
{
public List<Guid> IDs { get; set; }
[Display(Name = "_Admin.ShowOnMenu")]
public bool ShowOnMenu { get; set; }
[Display(Name = "_Admin.ParentFolder")]
public Guid? ParentID { get; set; }
public List<ComboSelectListItem> AllParents { get; set; }
[Display(Name = "_Admin.Icon")]
public string Icon { get; set; }
}
}

View File

@ -0,0 +1,243 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public class FrameworkMenuListVM : BasePagedListVM<FrameworkMenu_ListView, FrameworkMenuSearcher>
{
public FrameworkMenuListVM()
{
this.NeedPage = false;
}
protected override IEnumerable<IGridColumn<FrameworkMenu_ListView>> InitGridHeader()
{
List<GridColumn<FrameworkMenu_ListView>> rv = new List<GridColumn<FrameworkMenu_ListView>>();
switch (SearcherMode)
{
case ListVMSearchModeEnum.Batch:
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
this.MakeGridHeader(x => x.PageName),
this.MakeGridHeader(x => x.ModuleName, 200),
this.MakeGridHeader(x => x.ActionName, 150),
});
break;
case ListVMSearchModeEnum.Custom1:
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
this.MakeGridHeader(x => x.PageName,300),
});
break;
case ListVMSearchModeEnum.Custom2:
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
this.MakeGridHeader(x => x.PageName,200),
this.MakeGridHeader(x => x.ParentID).SetHeader(Localizer["Sys.Operation"]).SetFormat((item, cell) => GenerateCheckBox(item)).SetAlign(GridColumnAlignEnum.Left),
});
break;
default:
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
this.MakeGridHeader(x => x.PageName,300),
this.MakeGridHeader(x => x.ModuleName, 150),
this.MakeGridHeader(x => x.ShowOnMenu),
this.MakeGridHeader(x => x.FolderOnly),
this.MakeGridHeader(x => x.IsPublic),
this.MakeGridHeader(x => x.DisplayOrder),
this.MakeGridHeader(x => x.Icon, 100).SetFormat(PhotoIdFormat),
this.MakeGridHeaderAction(width: 270)
});
break;
}
return rv;
}
private object GenerateCheckBox(FrameworkMenu_ListView item)
{
string rv = "";
if (item.FolderOnly == false)
{
if (item.IsInside == true)
{
var others = item.Children?.ToList();
rv += UIService.MakeCheckBox(item.Allowed, Localizer["Sys.MainPage"], "menu_" + item.ID, "1");
if (others != null)
{
foreach (var c in others)
{
string actionname = "";
if(c.ActionName != null)
{
actionname = Localizer[c.ActionName];
}
rv += UIService.MakeCheckBox(c.Allowed, actionname, "menu_" + c.ID, "1");
}
}
}
else
{
rv += UIService.MakeCheckBox(item.Allowed, Localizer["Sys.MainPage"], "menu_" + item.ID, "1");
}
}
return rv;
}
protected override List<GridAction> InitGridAction()
{
if (SearcherMode == ListVMSearchModeEnum.Search)
{
return new List<GridAction>{
this.MakeAction("FrameworkMenu", "Create",Localizer["Sys.Create"], Localizer["Sys.Create"], GridActionParameterTypesEnum.SingleIdWithNull,"_Admin").SetIconCls("layui-icon layui-icon-add-1"),
this.MakeStandardAction("FrameworkMenu", GridActionStandardTypesEnum.Edit, "", "_Admin"),
this.MakeStandardAction("FrameworkMenu", GridActionStandardTypesEnum.Delete, "", "_Admin"),
this.MakeStandardAction("FrameworkMenu", GridActionStandardTypesEnum.Details, "", "_Admin"),
this.MakeAction( "FrameworkMenu", "UnsetPages", Localizer["_Admin.CheckPage"], Localizer["_Admin.UnsetPages"],GridActionParameterTypesEnum.NoId, "_Admin").SetIconCls("layui-icon layui-icon-ok"),
this.MakeAction("FrameworkMenu", "RefreshMenu", Localizer["_Admin.RefreshMenu"], Localizer["_Admin.RefreshMenu"], GridActionParameterTypesEnum.NoId,"_Admin").SetShowDialog(false).SetIconCls("layui-icon layui-icon-refresh"),
};
}
else
{
return new List<GridAction>();
}
}
private string PhotoIdFormat(FrameworkMenu_ListView entity, object val)
{
if (entity.Icon != null)
{
return $"<i class='{entity.Icon}'></i>";
}
else
{
return "";
}
}
public override IOrderedQueryable<FrameworkMenu_ListView> GetSearchQuery()
{
var data = DC.Set<FrameworkMenu>().ToList();
var topdata = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder).Where(x => x.IsInside == false || x.FolderOnly == true || x.Url.EndsWith("/Index") || x.MethodName == null).ToList();
foreach (var item in topdata)
{
if (item.PageName?.StartsWith("MenuKey.") == true)
{
item.PageName =Localizer[item.PageName];
}
if (item.ModuleName?.StartsWith("MenuKey.") == true)
{
item.ModuleName = Localizer[item.ModuleName];
}
}
topdata.ForEach((x) => { int l = x.GetLevel(); for (int i = 0; i < l; i++) { x.PageName = "&nbsp;&nbsp;&nbsp;&nbsp;" + x.PageName; } });
if (SearcherMode == ListVMSearchModeEnum.Custom2)
{
var pris = DC.Set<FunctionPrivilege>()
.Where(x => x.RoleCode == DC.Set<FrameworkRole>().CheckID(Searcher.RoleID,null).Select(x=>x.RoleCode).FirstOrDefault()).ToList();
var allowed = pris.Where(x => x.Allowed == true).Select(x => x.MenuItemId).ToList();
var denied = pris.Where(x => x.Allowed == false).Select(x => x.MenuItemId).ToList();
int order = 0;
var data2 = topdata.Select(x => new FrameworkMenu_ListView
{
ID = x.ID,
PageName = x.PageName,
ModuleName = x.ModuleName,
ActionName = x.ActionName,
ShowOnMenu = x.ShowOnMenu,
FolderOnly = x.FolderOnly,
IsPublic = x.IsPublic,
DisplayOrder = x.DisplayOrder,
Children = x.Children?.Select(y => new FrameworkMenu_ListView
{
ID = y.ID,
Allowed = allowed.Contains(y.ID),
ActionName = y.ActionName
}),
ExtraOrder = order++,
ParentID = x.ParentId,
Parent = x.Parent,
IsInside = x.IsInside,
HasChild = (x.Children != null && x.Children.Count() > 0) ? true : false,
Allowed = allowed.Contains(x.ID),
Denied = denied.Contains(x.ID)
}).OrderBy(x => x.ExtraOrder);
return data2.AsQueryable() as IOrderedQueryable<FrameworkMenu_ListView>;
}
else
{
int order = 0;
var data2 = topdata.Select(x => new FrameworkMenu_ListView
{
ID = x.ID,
PageName = x.PageName,
ModuleName = x.ModuleName,
ActionName = x.ActionName,
ShowOnMenu = x.ShowOnMenu,
FolderOnly = x.FolderOnly,
IsPublic = x.IsPublic,
DisplayOrder = x.DisplayOrder,
ExtraOrder = order++,
ParentID = x.ParentId,
Icon = x.Icon,
HasChild = (x.Children != null && x.Children.Count() > 0) ? true : false
}).OrderBy(x => x.ExtraOrder);
return data2.AsQueryable() as IOrderedQueryable<FrameworkMenu_ListView>;
}
}
}
public class FrameworkMenu_ListView : BasePoco
{
[Display(Name = "_Admin.PageName")]
public string PageName { get; set; }
[Display(Name = "Codegen.ModuleName")]
public string ModuleName { get; set; }
[Display(Name = "_Admin.ActionName")]
public string ActionName { get; set; }
[Display(Name = "_Admin.ShowOnMenu")]
public bool? ShowOnMenu { get; set; }
[Display(Name = "_Admin.FolderOnly")]
public bool? FolderOnly { get; set; }
[Display(Name = "_Admin.IsPublic")]
public bool? IsPublic { get; set; }
[Display(Name = "_Admin.DisplayOrder")]
public int? DisplayOrder { get; set; }
[Display(Name = "_Admin.Icon")]
public string Icon { get; set; }
public bool Allowed { get; set; }
public bool Denied { get; set; }
public bool HasChild { get; set; }
public string IconClass { get; set; }
public IEnumerable<FrameworkMenu_ListView> Children { get; set; }
public FrameworkMenu Parent { get; set; }
public Guid? ParentID { get; set; }
public int ExtraOrder { get; set; }
public bool? IsInside { get; set; }
}
}

View File

@ -0,0 +1,73 @@
// WTM默认页面 Wtm buidin page
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public class FrameworkMenuListVM2 : BasePagedListVM<FrameworkMenu_ListView, BaseSearcher>
{
public FrameworkMenuListVM2()
{
this.NeedPage = false;
}
protected override IEnumerable<IGridColumn<FrameworkMenu_ListView>> InitGridHeader()
{
List<GridColumn<FrameworkMenu_ListView>> rv = new List<GridColumn<FrameworkMenu_ListView>>();
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
this.MakeGridHeader(x => x.PageName, 300),
this.MakeGridHeader(x => x.ModuleName, 150),
this.MakeGridHeader(x => x.ShowOnMenu, 60),
this.MakeGridHeader(x => x.FolderOnly, 60),
this.MakeGridHeader(x => x.IsPublic, 60),
this.MakeGridHeader(x => x.DisplayOrder, 60),
this.MakeGridHeader(x => x.Icon, 100),
this.MakeGridHeader(x => x.Children, 100),
this.MakeGridHeader(x=>x.ParentID).SetHide(),
this.MakeGridHeaderAction(width: 290)
});
return rv;
}
public override IOrderedQueryable<FrameworkMenu_ListView> GetSearchQuery()
{
var data = DC.Set<FrameworkMenu>().ToList();
var topdata = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder).Where(x => x.IsInside == false || x.FolderOnly == true || string.IsNullOrEmpty(x.MethodName)).ToList();
foreach (var item in topdata)
{
if (item.PageName?.StartsWith("MenuKey.") == true)
{
item.PageName = Localizer[item.PageName];
}
if (item.ModuleName?.StartsWith("MenuKey.") == true)
{
item.ModuleName = Localizer[item.ModuleName];
}
}
int order = 0;
var data2 = topdata.Select(x => new FrameworkMenu_ListView
{
ID = x.ID,
PageName = x.PageName,
ModuleName = x.ModuleName,
ActionName = x.ActionName,
ShowOnMenu = x.ShowOnMenu,
FolderOnly = x.FolderOnly,
IsPublic = x.IsPublic,
DisplayOrder = x.DisplayOrder,
ExtraOrder = order++,
ParentID = x.ParentId,
Icon = x.Icon,
HasChild = (x.Children != null && x.Children.Count() > 0) ? true : false
}).OrderBy(x => x.ExtraOrder).ToList();
return data2.AsQueryable() as IOrderedQueryable<FrameworkMenu_ListView>;
}
}
}

View File

@ -0,0 +1,29 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public enum FrameworkMenuMode { Normal = 0, RoleMode = 1, RoleSetMode = 2 }
public class FrameworkMenuSearcher : BaseSearcher
{
[Display(Name = "_Admin.PageName")]
public string PageName { get; set; }
[Display(Name = "Codegen.ModuleName")]
public string ModuleName { get; set; }
[Display(Name = "_Admin.ActionName")]
public string ActionName { get; set; }
[Display(Name = "_Admin.ShowOnMenu")]
public bool? ShowOnMenu { get; set; }
[Display(Name = "_Admin.IsPublic")]
public bool? IsPublic { get; set; }
[Display(Name = "_Admin.FolderOnly")]
public bool? FolderOnly { get; set; }
public Guid? RoleID { get; set; }
}
}

View File

@ -0,0 +1,380 @@
// WTM默认页面 Wtm buidin page
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json.Serialization;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using WalkingTec.Mvvm.Core.Support.Json;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public class FrameworkMenuVM : BaseCRUDVM<FrameworkMenu>
{
[Display(Name = "_Admin.IconFont")]
public string IconFont { get; set; }
[Display(Name = "_Admin.Icon")]
public string IconFontItem { get; set; }
[JsonIgnore]
public List<ComboSelectListItem> AllParents { get; set; }
[JsonIgnore]
public List<ComboSelectListItem> AllModules { get; set; }
[JsonIgnore]
public List<ComboSelectListItem> AllActions { get; set; }
[Display(Name = "_Admin.Action")]
public List<string> SelectedActionIDs { get; set; }
[Display(Name = "_Admin.Module")]
public string SelectedModule { get; set; }
[Display(Name = "_Admin.AllowedRole")]
public List<string> SelectedRolesIds { get; set; }
[JsonIgnore]
public FrameworkRoleListVM RoleListVM { get; set; }
public List<ComboSelectListItem> IconSelectItems { get; set; }
public FrameworkMenuVM()
{
RoleListVM = new FrameworkRoleListVM();
AllActions = new List<ComboSelectListItem>();
AllModules = new List<ComboSelectListItem>();
SelectedRolesIds = new List<string>();
}
protected override void InitVM()
{
if (!string.IsNullOrEmpty(Entity.Icon))
{
var res = Entity.Icon.Split(' ');
IconFont = res[0];
IconFontItem = res[1];
}
SelectedRolesIds.AddRange(DC.Set<FunctionPrivilege>().Where(x => x.MenuItemId == Entity.ID && x.RoleCode != null && x.Allowed == true).Select(x => x.RoleCode).ToList());
var data = DC.Set<FrameworkMenu>().AsNoTracking().ToList();
var topMenu = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder);
var pids = Entity.GetAllChildrenIDs(DC);
AllParents = data.Where(x => x.ID != Entity.ID && !pids.Contains(x.ID) && x.FolderOnly == true).ToList().ToListItems(y => y.PageName, x => x.ID);
foreach (var p in AllParents)
{
if (p.Text.StartsWith("MenuKey."))
{
p.Text = Localizer[p.Text];
}
}
var modules = Wtm.GlobaInfo.AllModule;
var toRemove = new List<SimpleModule>();
foreach (var item in modules)
{
if (item.IgnorePrivillege)
{
toRemove.Add(item);
}
}
var m = Utils.ResetModule(modules);
toRemove.ForEach(x => m.Remove(x));
AllModules = m.ToListItems(y => y.ModuleName, y => y.FullName);
if (string.IsNullOrEmpty(SelectedModule) == false || (string.IsNullOrEmpty(Entity.Url) == false && Entity.IsInside == true))
{
if (string.IsNullOrEmpty(SelectedModule))
{
SelectedModule = m.Where(x => (x.FullName == Entity.ClassName)).FirstOrDefault()?.FullName;
}
var mm = m.Where(x => x.FullName == SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != "Index" && x.IgnorePrivillege == false).ToList();
AllActions = mm.ToListItems(y => y.ActionName, y => y.Url);
if (SelectedActionIDs == null)
{
SelectedActionIDs = DC.Set<FrameworkMenu>().Where(x => AllActions.Select(y => y.Value).Contains(x.Url) && x.IsInside == true && x.FolderOnly == false).Select(x => x.Url).ToList();
}
}
}
public override void Validate()
{
if (Entity.IsInside == true && Entity.FolderOnly == false)
{
if (string.IsNullOrEmpty(SelectedModule) == true)
{
MSD.AddModelError("SelectedModule", Localizer["Validate.{0}required", Localizer["_Admin.Module"]]);
}
var modules = Wtm.GlobaInfo.AllModule;
var test = DC.Set<FrameworkMenu>().Where(x => x.ClassName == this.SelectedModule && (x.MethodName == null || x.MethodName == "Index") && x.ID != Entity.ID).FirstOrDefault();
if (test != null)
{
MSD.AddModelError(" error", Localizer["_Admin.ModuleHasSet"]);
}
}
base.Validate();
}
public override void DoEdit(bool updateAllFields = false)
{
Entity.Icon = $"{IconFont} {IconFontItem}";
FC.Add("Entity.Icon", " ");
if (Entity.IsInside == false)
{
if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
{
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
{
Entity.Url = "http://" + Entity.Url;
}
}
if(Entity.Url != null)
{
Entity.Url = Entity.Url.TrimEnd('/');
}
}
else
{
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
{
var modules = Wtm.GlobaInfo.AllModule;
var m = Utils.ResetModule(modules, false);
var actionPage = m.Where(x => x.FullName == this.SelectedModule)
.SelectMany(x => x.Actions).Where(x => x.MethodName == "Index" || x.ActionDes?.IsPage == true)
.FirstOrDefault();
if (actionPage == null && Entity.ShowOnMenu == true)
{
MSD.AddModelError("Entity.ModuleId", Localizer["_Admin.NoIndexInModule"]);
return;
}
List<SimpleAction> otherActions = null;
var mainModule = m.Where(x => x.FullName == this.SelectedModule).FirstOrDefault();
if (actionPage == null)
{
actionPage = new SimpleAction
{
Module = mainModule,
Url = "/" + mainModule.ClassName,
ActionName = mainModule.ModuleName
};
}
var mainAction = actionPage;
Entity.Url = mainAction.Url;
Entity.ModuleName = mainModule.ModuleName;
Entity.ActionName = mainAction.ActionDes?.Description ?? mainAction.ActionName;
Entity.ClassName = mainModule.FullName;
Entity.MethodName = null;
otherActions = m.Where(x => x.FullName == this.SelectedModule)
.SelectMany(x => x.Actions)
.Where(x => x.MethodName != mainAction.MethodName)
.ToList();
var actionsInDB = DC.Set<FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
int order = 1;
Entity.Children = new List<FrameworkMenu>();
foreach (var action in otherActions)
{
if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.Url))
{
Guid aid = action.ID;
var adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
if (adb != null)
{
aid = adb.ID;
}
var menu = new FrameworkMenu();
menu.FolderOnly = false;
menu.IsPublic = Entity.IsPublic;
menu.Parent = Entity;
menu.ShowOnMenu = false;
menu.DisplayOrder = order++;
menu.Privileges = new List<FunctionPrivilege>();
menu.IsInside = true;
menu.Domain = Entity.Domain;
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
menu.ModuleName = mainModule.ModuleName;
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
menu.ClassName = mainModule.FullName;
menu.MethodName = action.MethodName;
menu.Url = action.Url;
menu.ID = aid;
Entity.Children.Add(menu);
}
}
}
else
{
//Entity.Children = new List<FrameworkMenu>();
Entity.Url = null;
}
}
if (Entity.FolderOnly == false)
{
if (FC.ContainsKey("Entity.Children") == false)
{
FC.Add("Entity.Children", 0);
FC.Add("Entity.Children[0].IsPublic", 0);
FC.Add("Entity.Children[0].PageName", 0);
FC.Add("Entity.Children[0].ModuleName", 0);
FC.Add("Entity.Children[0].ActionName", 0);
FC.Add("Entity.Children[0].ClassName", 0);
FC.Add("Entity.Children[0].MethodName", 0);
FC.Add("Entity.Children[0].Url", 0);
}
}
FC.Add("Entity.ModuleName", 0);
base.DoEdit();
List<Guid> guids = new List<Guid>();
guids.Add(Entity.ID);
if (Entity.Children != null)
{
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
}
AddPrivilege(guids);
}
public override void DoAdd()
{
Entity.Icon = $"{IconFont} {IconFontItem}";
if (Entity.IsInside == false)
{
if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
{
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
{
Entity.Url = "http://" + Entity.Url;
}
}
if(Entity.Url != null)
{
Entity.Url = Entity.Url.TrimEnd('/');
}
}
else
{
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
{
var modules = Wtm.GlobaInfo.AllModule;
var m = Utils.ResetModule(modules, false);
var actionPage = m.Where(x => x.FullName == this.SelectedModule)
.SelectMany(x => x.Actions).Where(x => x.MethodName == "Index" || x.ActionDes?.IsPage == true)
.FirstOrDefault();
if (actionPage == null && Entity.ShowOnMenu == true)
{
MSD.AddModelError("Entity.ModuleId", Localizer["_Admin.NoIndexInModule"]);
return;
}
List<SimpleAction> otherActions = null;
var mainModule = m.Where(x => x.FullName == this.SelectedModule).FirstOrDefault();
if(actionPage == null)
{
actionPage = new SimpleAction
{
Module = mainModule,
Url = "/" + mainModule.ClassName,
ActionName = mainModule.ModuleName
};
}
var mainAction = actionPage;
Entity.Url = mainAction.Url;
Entity.ModuleName = mainModule.ModuleName;
Entity.ActionName = mainAction.ActionDes?.Description ?? mainAction.ActionName;
Entity.ClassName = mainModule.FullName;
Entity.MethodName = null;
Entity.Children = new List<FrameworkMenu>();
otherActions = m.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != mainAction.MethodName).ToList();
int order = 1;
foreach (var action in otherActions)
{
if (SelectedActionIDs?.Contains(action.Url) == true)
{
FrameworkMenu menu = new FrameworkMenu();
menu.FolderOnly = false;
menu.IsPublic = Entity.IsPublic;
menu.Parent = Entity;
menu.ShowOnMenu = false;
menu.DisplayOrder = order++;
menu.Privileges = new List<FunctionPrivilege>();
menu.IsInside = true;
menu.Domain = Entity.Domain;
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
menu.ModuleName = mainModule.ModuleName;
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
menu.ClassName = mainModule.FullName;
menu.MethodName = action.MethodName;
menu.Url = action.Url;
Entity.Children.Add(menu);
}
}
}
else
{
Entity.Children = null;
Entity.Url = null;
}
}
base.DoAdd();
List<Guid> guids = new List<Guid>();
guids.Add(Entity.ID);
if (Entity.Children != null)
{
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
}
AddPrivilege(guids);
}
public void AddPrivilege(List<Guid> menuids)
{
var admin = DC.Set<FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();
if (admin != null && SelectedRolesIds.Contains(admin.RoleCode) == false)
{
SelectedRolesIds.Add(admin.RoleCode);
}
foreach (var menuid in menuids)
{
if (SelectedRolesIds != null)
{
foreach (var code in SelectedRolesIds)
{
FunctionPrivilege fp = new FunctionPrivilege();
fp.MenuItemId = menuid;
fp.RoleCode = code;
fp.Allowed = true;
DC.Set<FunctionPrivilege>().Add(fp);
}
}
}
DC.SaveChanges();
}
public override void DoDelete()
{
try
{
DC.CascadeDelete(Entity);
DC.SaveChanges();
}
catch
{ }
}
}
}

View File

@ -0,0 +1,300 @@
// WTM默认页面 Wtm buidin page
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
public class FrameworkMenuVM2 : BaseCRUDVM<FrameworkMenu>
{
[Display(Name = "_Admin.Action")]
public List<string> SelectedActionIDs { get; set; }
[Display(Name = "_Admin.Module")]
public string SelectedModule { get; set; }
[Display(Name = "_Admin.AllowedRole")]
public List<string> SelectedRolesCodes { get; set; }
public FrameworkMenuVM2()
{
SelectedRolesCodes = new List<string>();
}
protected override void InitVM()
{
SelectedRolesCodes.AddRange(DC.Set<FunctionPrivilege>().Where(x => x.MenuItemId == Entity.ID && x.RoleCode != null && x.Allowed == true).Select(x => x.RoleCode).ToList());
var data = DC.Set<FrameworkMenu>().ToList();
var topMenu = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder);
var modules = Wtm.GlobaInfo.AllModule;
if (Entity.Url != null && Entity.IsInside == true)
{
SelectedModule = modules.Where(x => x.IsApi == true && (x.FullName == Entity.ClassName)).FirstOrDefault()?.FullName;
if (SelectedModule != null)
{
var urls = modules.Where(x => x.FullName == SelectedModule && x.IsApi == true).SelectMany(x => x.Actions).Where(x => x.IgnorePrivillege == false).Select(x => x.Url).ToList();
SelectedActionIDs = DC.Set<FrameworkMenu>().Where(x => urls.Contains(x.Url) && x.IsInside == true && x.FolderOnly == false).Select(x => x.MethodName).ToList();
}
else
{
SelectedModule = Entity.Url;
}
}
}
public override void Validate()
{
if (Entity.IsInside == true && Entity.FolderOnly == false)
{
if (string.IsNullOrEmpty(SelectedModule) == true)
{
MSD.AddModelError("SelectedModule", Localizer["Validate.{0}required", Localizer["_Admin.Module"]]);
}
else
{
var modules = Wtm.GlobaInfo.AllModule;
var test = DC.Set<FrameworkMenu>().Where(x => x.Url != null && x.Url.ToLower() == this.Entity.Url.ToLower() && x.ID != Entity.ID).FirstOrDefault();
if (test != null)
{
MSD.AddModelError(" error", Localizer["_Admin.ModuleHasSet"]);
}
}
}
base.Validate();
}
public override void DoEdit(bool updateAllFields = false)
{
if (Entity.IsInside == false)
{
if (Entity.Url != null && Entity.Url != "")
{
if (string.IsNullOrEmpty(Entity.Domain) == true)
{
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false && Entity.Url.StartsWith("@") == false)
{
Entity.Url = "http://" + Entity.Url;
}
}
else
{
if (Entity.Url.StartsWith("/") == false)
{
Entity.Url = "/" + Entity.Url;
}
}
Entity.Url = Entity.Url.TrimEnd('/');
}
}
else
{
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
{
var modules = Wtm.GlobaInfo.AllModule;
var ndc = DC.ReCreate();
var actionsInDB = DC.Set<FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
var mo = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
if (mo != null)
{
Entity.ModuleName = mo.ModuleName;
Entity.ClassName = mo.FullName;
Entity.MethodName = null;
var otherActions = mo.Actions;
int order = 1;
Entity.Children = new List<FrameworkMenu>();
foreach (var action in otherActions)
{
if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
{
Guid aid = action.ID;
var adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
if (adb != null)
{
aid = adb.ID;
}
FrameworkMenu menu = new FrameworkMenu();
menu.FolderOnly = false;
menu.IsPublic = Entity.IsPublic;
menu.Parent = Entity;
menu.ShowOnMenu = false;
menu.DisplayOrder = order++;
menu.Privileges = new List<FunctionPrivilege>();
menu.IsInside = true;
menu.Domain = Entity.Domain;
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
menu.ModuleName = action.Module.ModuleName;
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
menu.Url = action.Url;
menu.ClassName = action.Module.FullName;
menu.MethodName = action.MethodName;
menu.ID = aid;
Entity.Children.Add(menu);
}
}
}
else
{
Entity.ModuleName = "";
Entity.ClassName = "";
Entity.MethodName = "";
}
}
else
{
Entity.Children = null;
Entity.Url = null;
}
}
if (FC.ContainsKey("Entity.Children") == false)
{
FC.Add("Entity.Children", 0);
FC.Add("Entity.Children[0].IsPublic", 0);
FC.Add("Entity.Children[0].PageName", 0);
FC.Add("Entity.Children[0].ModuleName", 0);
FC.Add("Entity.Children[0].ActionName", 0);
FC.Add("Entity.Children[0].ClassName", 0);
FC.Add("Entity.Children[0].MethodName", 0);
FC.Add("Entity.Children[0].Url", 0);
}
base.DoEdit(updateAllFields);
List<Guid> guids = new List<Guid>();
guids.Add(Entity.ID);
if (Entity.Children != null)
{
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
}
AddPrivilege(guids);
}
public override void DoAdd()
{
if (Entity.IsInside == false)
{
if (Entity.Url != null && Entity.Url != "")
{
if (string.IsNullOrEmpty(Entity.Domain) == true)
{
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false && Entity.Url.StartsWith("@") == false)
{
Entity.Url = "http://" + Entity.Url;
}
}
else
{
if (Entity.Url.StartsWith("/") == false)
{
Entity.Url = "/" + Entity.Url;
}
}
Entity.Url = Entity.Url.TrimEnd('/');
}
}
else
{
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
{
var modules = Wtm.GlobaInfo.AllModule;
var mo = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
if (mo != null)
{
Entity.ModuleName = mo.ModuleName;
Entity.ClassName = mo.FullName;
Entity.MethodName = null;
var otherActions = mo.Actions;
int order = 1;
Entity.Children = new List<FrameworkMenu>();
foreach (var action in otherActions)
{
if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
{
FrameworkMenu menu = new FrameworkMenu();
menu.FolderOnly = false;
menu.IsPublic = Entity.IsPublic;
menu.Parent = Entity;
menu.ShowOnMenu = false;
menu.DisplayOrder = order++;
menu.Privileges = new List<FunctionPrivilege>();
menu.IsInside = true;
menu.Domain = Entity.Domain;
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
menu.ModuleName = action.Module.ModuleName;
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
menu.Url = action.Url;
menu.ClassName = action.Module.FullName;
menu.MethodName = action.MethodName;
Entity.Children.Add(menu);
}
}
}
}
else
{
Entity.Children = null;
Entity.Url = null;
}
}
base.DoAdd();
List<Guid> guids = new List<Guid>();
guids.Add(Entity.ID);
if (Entity.Children != null)
{
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
}
AddPrivilege(guids);
}
public void AddPrivilege(List<Guid> menuids)
{
var admin = DC.Set<FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();
if (admin != null && SelectedRolesCodes.Contains(admin.RoleCode) == false)
{
SelectedRolesCodes.Add(admin.RoleCode);
}
foreach (var menuid in menuids)
{
if (SelectedRolesCodes != null)
{
foreach (var code in SelectedRolesCodes)
{
FunctionPrivilege fp = new FunctionPrivilege();
fp.MenuItemId = menuid;
fp.RoleCode = code;
fp.Allowed = true;
DC.Set<FunctionPrivilege>().Add(fp);
}
}
}
DC.SaveChanges();
}
public override void DoDelete()
{
try
{
DC.CascadeDelete(Entity);
DC.SaveChanges();
}
catch
{ }
}
}
}

View File

@ -0,0 +1,20 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleBatchVM : BaseBatchVM<FrameworkRole, BaseVM>
{
public FrameworkRoleBatchVM()
{
ListVM = new FrameworkRoleListVM();
}
}
}

View File

@ -0,0 +1,17 @@
// WTM默认页面 Wtm buidin page
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleTemplateVM : BaseTemplateVM
{
public ExcelPropety r1 = ExcelPropety.CreateProperty<FrameworkRole>(x => x.RoleCode);
public ExcelPropety r2 = ExcelPropety.CreateProperty<FrameworkRole>(x => x.RoleName);
public ExcelPropety r3 = ExcelPropety.CreateProperty<FrameworkRole>(x => x.RoleRemark);
}
public class FrameworkRoleImportVM : BaseImportVM<FrameworkRoleTemplateVM, FrameworkRole>
{
}
}

View File

@ -0,0 +1,46 @@
// WTM默认页面 Wtm buidin page
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleListVM : BasePagedListVM<FrameworkRole, FrameworkRoleSearcher>
{
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.Create, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.Edit, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.Delete, "", "_Admin",dialogWidth: 800),
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.Details, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.BatchDelete, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.Import, "","_Admin", dialogWidth: 800),
this.MakeAction("FrameworkRole","PageFunction",Localizer["_Admin.PageFunction"],Localizer["_Admin.PageFunction"], GridActionParameterTypesEnum.SingleId,"_Admin",800).SetShowInRow(),
this.MakeStandardAction("FrameworkRole", GridActionStandardTypesEnum.ExportExcel, "","_Admin"),
};
}
protected override IEnumerable<IGridColumn<FrameworkRole>> InitGridHeader()
{
return new List<GridColumn<FrameworkRole>>{
this.MakeGridHeader(x => x.RoleCode, 120),
this.MakeGridHeader(x => x.RoleName, 120),
this.MakeGridHeader(x => x.RoleRemark),
this.MakeGridHeaderAction(width: 300)
};
}
public override IOrderedQueryable<FrameworkRole> GetSearchQuery()
{
var query = DC.Set<FrameworkRole>()
.CheckContain(Searcher.RoleCode,x=>x.RoleCode)
.CheckContain(Searcher.RoleName,x=>x.RoleName)
.OrderBy(x => x.RoleCode);
return query;
}
}
}

View File

@ -0,0 +1,55 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleMDVM : BaseCRUDVM<FrameworkRole>
{
public FrameworkMenuListVM ListVM { get; set; }
public FrameworkRoleMDVM()
{
ListVM = new FrameworkMenuListVM();
}
protected override void InitVM()
{
ListVM.CopyContext(this);
ListVM.Searcher.RoleID = Entity.ID;
}
public async Task<bool> DoChangeAsync()
{
var all = FC.Where(x => x.Key.StartsWith("menu_")).ToList();
List<Guid> AllowedMenuIds = all.Where(x => x.Value.ToString() == "1").Select(x=> Guid.Parse(x.Key.Replace("menu_",""))).ToList();
var torem = AllowedMenuIds.Distinct();
var oldIDs = DC.Set<FunctionPrivilege>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.ID).ToList();
foreach (var oldid in oldIDs)
{
FunctionPrivilege fp = new FunctionPrivilege { ID = oldid };
DC.Set<FunctionPrivilege>().Attach(fp);
DC.DeleteEntity(fp);
}
foreach (var menuid in AllowedMenuIds)
{
FunctionPrivilege fp = new FunctionPrivilege();
fp.MenuItemId = menuid;
fp.RoleCode = Entity.RoleCode;
fp.Allowed = true;
DC.Set<FunctionPrivilege>().Add(fp);
}
await DC.SaveChangesAsync();
var userids = DC.Set<FrameworkUserRole>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.UserCode).ToArray();
await Wtm.RemoveUserCache(userids);
return true;
}
}
}

View File

@ -0,0 +1,128 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleMDVM2 : BaseCRUDVM<FrameworkRole>
{
public List<Page_View> Pages { get; set; }
public FrameworkRoleMDVM2()
{
}
protected override void InitVM()
{
var allowedids = DC.Set<FunctionPrivilege>()
.Where(x => x.RoleCode == Entity.RoleCode && x.Allowed == true).Select(x => x.MenuItemId)
.ToList();
var data = DC.Set<FrameworkMenu>().ToList();
var topdata = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder).Where(x => x.IsInside == false || x.FolderOnly == true || x.MethodName == null).ToList();
int order = 0;
var data2 = topdata.Select(x => new Page_View
{
ID = x.ID,
Name = x.PageName,
AllActions = x.FolderOnly == true ? null : x.Children.ToListItems(y => y.ActionName, y => y.ID, null),
ParentID = x.ParentId,
Level = x.GetLevel(),
IsFolder = x.FolderOnly,
ExtraOrder = order++
}).OrderBy(x => x.ExtraOrder).ToList();
foreach (var item in data2)
{
if (item.Name?.StartsWith("MenuKey.") == true)
{
item.Name = Localizer[item.Name];
}
if (item.AllActions == null)
{
item.AllActions = new List<ComboSelectListItem>();
}
foreach (var act in item.AllActions)
{
act.Text = Localizer[act.Text];
}
item.AllActions.Insert(0, new ComboSelectListItem { Text = Localizer["Sys.MainPage"], Value = item.ID.ToString() });
var ids = item.AllActions.Select(x => Guid.Parse(x.Value.ToString()));
item.Actions = ids.Where(x => allowedids.Contains(x)).ToList();
}
Pages = data2;
}
public async Task<bool> DoChangeAsync()
{
List<Guid> AllowedMenuIds = new List<Guid>();
var torem = AllowedMenuIds.Distinct();
foreach (var page in Pages)
{
if (page.Actions != null)
{
foreach (var action in page.Actions)
{
if (AllowedMenuIds.Contains(action) == false)
{
AllowedMenuIds.Add(action);
}
}
}
}
var oldIDs = DC.Set<FunctionPrivilege>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.ID).ToList();
foreach (var oldid in oldIDs)
{
FunctionPrivilege fp = new FunctionPrivilege { ID = oldid };
DC.Set<FunctionPrivilege>().Attach(fp);
DC.DeleteEntity(fp);
}
foreach (var menuid in AllowedMenuIds)
{
FunctionPrivilege fp = new FunctionPrivilege();
fp.MenuItemId = menuid;
fp.RoleCode = Entity.RoleCode;
fp.Allowed = true;
DC.Set<FunctionPrivilege>().Add(fp);
}
await DC.SaveChangesAsync();
var userids = DC.Set<FrameworkUserRole>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.UserCode).ToArray();
await Wtm.RemoveUserCache(userids);
return true;
}
}
public class Page_View : TopBasePoco
{
[Display(Name = "_Admin.PageName")]
public string Name { get; set; }
[Display(Name = "_Admin.PageFunction")]
public List<Guid> Actions { get; set; }
[Display(Name = "_Admin.PageFunction")]
public List<ComboSelectListItem> AllActions { get; set; }
public List<Page_View> Children { get; set; }
public bool IsFolder { get; set; }
[JsonIgnore]
public int ExtraOrder { get; set; }
public Guid? ParentID { get; set; }
[JsonIgnore]
public Page_View Parent { get; set; }
public int Level { get; set; }
}
}

View File

@ -0,0 +1,19 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleSearcher : BaseSearcher
{
[Display(Name = "_Admin.RoleCode")]
public string RoleCode { get; set; }
[Display(Name = "_Admin.RoleName")]
public string RoleName { get; set; }
}
}

View File

@ -0,0 +1,49 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs
{
public class FrameworkRoleVM : BaseCRUDVM<FrameworkRole>
{
public override DuplicatedInfo<FrameworkRole> SetDuplicatedCheck()
{
var rv = CreateFieldsInfo(SimpleField(x => x.RoleName));
rv.AddGroup(SimpleField(x => x.RoleCode));
return rv;
}
public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.RoleCode"))
{
FC.Remove("Entity.RoleCode");
}
base.DoEdit(updateAllFields);
}
public override async Task DoDeleteAsync()
{
using (var tran = DC.BeginTransaction())
{
try
{
await base.DoDeleteAsync();
var ur = DC.Set<FrameworkUserRole>().Where(x => x.RoleCode == Entity.RoleCode);
DC.Set<FrameworkUserRole>().RemoveRange(ur);
DC.SaveChanges();
tran.Commit();
await Wtm.RemoveUserCache(ur.Select(x=>x.UserCode).ToArray());
}
catch
{
tran.Rollback();
}
}
}
}
}

View File

@ -0,0 +1,52 @@
// WTM默认页面 Wtm buidin page
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms
{
public class ChangePasswordVM : BaseVM
{
[Display(Name = "_Admin.Account")]
public string ITCode { get; set; }
[Display(Name = "Login.OldPassword")]
[Required(AllowEmptyStrings = false)]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string OldPassword { get; set; }
[Display(Name = "Login.NewPassword")]
[Required(AllowEmptyStrings = false)]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string NewPassword { get; set; }
[Display(Name = "Login.NewPasswordComfirm")]
[Required(AllowEmptyStrings = false)]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string NewPasswordComfirm { get; set; }
public override void Validate()
{
List<ValidationResult> rv = new List<ValidationResult>();
if (DC.Set<FrameworkUser>().Where(x => x.ITCode == LoginUserInfo.ITCode && x.Password == Utils.GetMD5String(OldPassword)).SingleOrDefault() == null)
{
MSD.AddModelError("OldPassword", Localizer["Login.OldPasswrodWrong"]);
}
if (NewPassword != NewPasswordComfirm)
{
MSD.AddModelError("NewPasswordComfirm", Localizer["Login.PasswordNotSame"]);
}
}
public void DoChange()
{
var user = DC.Set<FrameworkUser>().Where(x => x.ITCode == LoginUserInfo.ITCode).SingleOrDefault();
if (user != null)
{
user.Password = Utils.GetMD5String(NewPassword);
}
DC.SaveChanges();
}
}
}

View File

@ -0,0 +1,61 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms
{
public class FrameworkUserBatchVM : BaseBatchVM<FrameworkUser, FrameworkUser_BatchEdit>
{
public FrameworkUserBatchVM()
{
ListVM = new FrameworkUserListVM();
LinkedVM = new FrameworkUser_BatchEdit();
}
public override bool DoBatchEdit()
{
var entityList = DC.Set<FrameworkUser>().AsNoTracking().CheckIDs(Ids.ToList()).ToList();
foreach (var entity in entityList)
{
List<Guid> todelete = new List<Guid>();
todelete.AddRange(DC.Set<FrameworkUserRole>().AsNoTracking().Where(x => x.UserCode == entity.ITCode).Select(x => x.ID));
foreach (var item in todelete)
{
DC.DeleteEntity(new FrameworkUserRole { ID = item });
}
if (LinkedVM.SelectedRolesCodes != null)
{
foreach (var rolecode in LinkedVM.SelectedRolesCodes)
{
FrameworkUserRole r = new FrameworkUserRole
{
RoleCode = rolecode,
UserCode = entity.ITCode
};
DC.AddEntity(r);
}
}
}
return base.DoBatchEdit();
}
}
public class FrameworkUser_BatchEdit : BaseVM
{
[Display(Name = "_Admin.Role")]
public List<string> SelectedRolesCodes { get; set; }
public List<ComboSelectListItem> AllRoles { get; set; }
protected override void InitVM()
{
AllRoles = DC.Set<FrameworkRole>().GetSelectListItems(Wtm, y => y.RoleName, y => y.RoleCode);
}
}
}

View File

@ -0,0 +1,38 @@
// WTM默认页面 Wtm buidin page
using System.Collections.Generic;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms
{
public class FrameworkUserTemplateVM : BaseTemplateVM
{
public ExcelPropety c1 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.ITCode);
public ExcelPropety c2 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.Password);
public ExcelPropety c3 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.Name);
public ExcelPropety c5 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.Gender);
public ExcelPropety c6 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.CellPhone);
public ExcelPropety c7 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.HomePhone);
public ExcelPropety c8 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.Address);
public ExcelPropety c9 = ExcelPropety.CreateProperty<FrameworkUser>(x => x.ZipCode);
protected override void InitVM()
{
}
}
public class FrameworkUserImportVM : BaseImportVM<FrameworkUserTemplateVM, FrameworkUser>
{
public override bool BatchSaveData()
{
SetEntityList();
foreach (var item in EntityList)
{
item.IsValid = true;
item.Password = Utils.GetMD5String(item.Password);
}
return base.BatchSaveData();
}
}
}

View File

@ -0,0 +1,88 @@
// WTM默认页面 Wtm buidin page
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms
{
public class FrameworkUserListVM : BasePagedListVM<FrameworkUser_View, FrameworkUserSearcher>
{
protected override List<GridAction> InitGridAction()
{
return new List<GridAction>
{
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.Create, "", "_Admin",dialogWidth: 800),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.Edit, "", "_Admin",dialogWidth: 800),
this.MakeAction("FrameworkUser","Password",Localizer?["Login.ChangePassword"],Localizer?["Login.ChangePassword"], GridActionParameterTypesEnum.SingleId,"_Admin",400).SetShowInRow(true),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.Delete, "","_Admin",dialogWidth: 800),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.Details, "", "_Admin",dialogWidth: 600),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.BatchEdit, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.BatchDelete, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.Import, "","_Admin", dialogWidth: 800),
this.MakeStandardAction("FrameworkUser", GridActionStandardTypesEnum.ExportExcel, "","_Admin"),
};
}
protected override IEnumerable<IGridColumn<FrameworkUser_View>> InitGridHeader()
{
return new List<GridColumn<FrameworkUser_View>>{
this.MakeGridHeader(x => x.ITCode),
this.MakeGridHeader(x => x.Name),
this.MakeGridHeader(x => x.Gender,80),
this.MakeGridHeader(x => x.CellPhone,120),
this.MakeGridHeader(x => x.RoleName_view),
this.MakeGridHeader(x => x.GroupName_view),
this.MakeGridHeader(x=> x.PhotoId,170).SetFormat(PhotoIdFormat),
this.MakeGridHeader(x => x.IsValid).SetHeader(Localizer["Sys.Enable"]).SetWidth(80),
this.MakeGridHeaderAction(width: 280)
};
}
private List<ColumnFormatInfo> PhotoIdFormat(FrameworkUser_View entity, object val)
{
return new List<ColumnFormatInfo>
{
ColumnFormatInfo.MakeDownloadButton(ButtonTypesEnum.Button,entity.PhotoId),
ColumnFormatInfo.MakeViewButton(ButtonTypesEnum.Button,entity.PhotoId),
};
}
public override IOrderedQueryable<FrameworkUser_View> GetSearchQuery()
{
var query = DC.Set<FrameworkUser>()
.CheckContain(Searcher.ITCode,x=>x.ITCode)
.CheckContain(Searcher.Name, x=>x.Name)
.CheckEqual(Searcher.IsValid, x=>x.IsValid)
.Select(x => new FrameworkUser_View
{
ID = x.ID,
ITCode = x.ITCode,
Name = x.Name,
PhotoId = x.PhotoId,
CellPhone = x.CellPhone,
IsValid = x.IsValid,
RoleName_view = DC.Set<FrameworkUserRole>().Where(y => y.UserCode == x.ITCode)
.Join(DC.Set<FrameworkRole>(), ur => ur.RoleCode, role => role.RoleCode, (ur, role) => role.RoleName).ToSepratedString(null, ","),
GroupName_view = DC.Set<FrameworkUserGroup>().Where(y => y.UserCode == x.ITCode)
.Join(DC.Set<FrameworkGroup>(), ug => ug.GroupCode, group => group.GroupCode, (ug, group) => group.GroupName).ToSepratedString(null, ","),
Gender = x.Gender
})
.OrderBy(x => x.ITCode);
return query;
}
}
public class FrameworkUser_View : FrameworkUser
{
[Display(Name = "_Admin.Role")]
public string RoleName_view { get; set; }
[Display(Name = "_Admin.Group")]
public string GroupName_view { get; set; }
}
}

View File

@ -0,0 +1,19 @@
// WTM默认页面 Wtm buidin page
using System;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms
{
public class FrameworkUserSearcher : BaseSearcher
{
[Display(Name = "_Admin.Account")]
public string ITCode { get; set; }
[Display(Name = "_Admin.Name")]
public string Name { get; set; }
[Display(Name = "_Admin.IsValid")]
public bool? IsValid { get; set; }
}
}

View File

@ -0,0 +1,185 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms
{
public class FrameworkUserVM : BaseCRUDVM<FrameworkUser>
{
[JsonIgnore]
public List<ComboSelectListItem> AllRoles { get; set; }
[JsonIgnore]
public List<ComboSelectListItem> AllGroups { get; set; }
[Display(Name = "_Admin.Role")]
public List<string> SelectedRolesCodes { get; set; }
[Display(Name = "_Admin.Group")]
public List<string> SelectedGroupCodes { get; set; }
public FrameworkUserVM()
{
}
public override DuplicatedInfo<FrameworkUser> SetDuplicatedCheck()
{
var rv = CreateFieldsInfo(SimpleField(x => x.ITCode));
return rv;
}
protected override void InitVM()
{
AllRoles = DC.Set<FrameworkRole>().GetSelectListItems(Wtm, y => y.RoleName, y => y.RoleCode);
AllGroups = DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, y => y.GroupName, y => y.GroupCode);
SelectedRolesCodes = DC.Set<FrameworkUserRole>().Where(x => x.UserCode == Entity.ITCode).Select(x => x.RoleCode).ToList();
SelectedGroupCodes = DC.Set<FrameworkUserGroup>().Where(x => x.UserCode == Entity.ITCode).Select(x => x.GroupCode).ToList();
}
protected override void ReInitVM()
{
AllRoles = DC.Set<FrameworkRole>().GetSelectListItems(Wtm, y => y.RoleName, y => y.RoleCode);
AllGroups = DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, y => y.GroupName, y => y.GroupCode);
}
public override async Task DoAddAsync()
{
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
{
foreach (var rolecode in SelectedRolesCodes)
{
FrameworkUserRole r = new FrameworkUserRole
{
RoleCode = rolecode,
UserCode = Entity.ITCode
};
DC.AddEntity(r);
}
}
if (SelectedGroupCodes != null)
{
foreach (var groupcode in SelectedGroupCodes)
{
FrameworkUserGroup g = new FrameworkUserGroup
{
GroupCode = groupcode,
UserCode = Entity.ITCode
};
DC.AddEntity(g);
}
}
Entity.IsValid = true;
Entity.Password = Utils.GetMD5String(Entity.Password);
await base.DoAddAsync();
if (MSD.IsValid)
{
trans.Commit();
}
else
{
trans.Rollback();
}
}
}
public override async Task DoEditAsync(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.ITCode"))
{
FC.Remove("Entity.ITCode");
}
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
{
List<Guid> todelete = new List<Guid>();
todelete.AddRange(DC.Set<FrameworkUserRole>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID));
foreach (var item in todelete)
{
DC.DeleteEntity(new FrameworkUserRole { ID = item });
}
}
if (SelectedGroupCodes != null)
{
List<Guid> todelete = new List<Guid>();
todelete.AddRange(DC.Set<FrameworkUserGroup>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID));
foreach (var item in todelete)
{
DC.DeleteEntity(new FrameworkUserGroup { ID = item });
}
}
if (SelectedRolesCodes != null)
{
foreach (var rolecode in SelectedRolesCodes)
{
FrameworkUserRole r = new FrameworkUserRole
{
RoleCode = rolecode,
UserCode = Entity.ITCode
};
DC.AddEntity(r);
}
}
if (SelectedGroupCodes != null)
{
foreach (var groupcode in SelectedGroupCodes)
{
FrameworkUserGroup g = new FrameworkUserGroup
{
GroupCode = groupcode,
UserCode = Entity.ITCode
};
DC.AddEntity(g);
}
}
await base.DoEditAsync(updateAllFields);
if (MSD.IsValid)
{
trans.Commit();
await Wtm.RemoveUserCache(Entity.ITCode.ToString());
}
else
{
trans.Rollback();
}
}
}
public override async Task DoDeleteAsync()
{
using (var tran = DC.BeginTransaction())
{
try
{
await base.DoDeleteAsync();
var ur = DC.Set<FrameworkUserRole>().Where(x => x.UserCode == Entity.ITCode);
DC.Set<FrameworkUserRole>().RemoveRange(ur);
var ug = DC.Set<FrameworkUserGroup>().Where(x => x.UserCode == Entity.ITCode);
DC.Set<FrameworkUserGroup>().RemoveRange(ug);
DC.SaveChanges();
tran.Commit();
}
catch
{
tran.Rollback();
}
}
await Wtm.RemoveUserCache(Entity.ITCode.ToString());
}
public void ChangePassword()
{
Entity.Password = Utils.GetMD5String(Entity.Password);
DC.UpdateProperty(Entity, x => x.Password);
DC.SaveChanges();
}
}
}

71
IoTGateway.sln Normal file
View File

@ -0,0 +1,71 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTGateway", "IoTGateway\IoTGateway.csproj", "{68ABBDF2-1485-4756-9A94-6AFA874D69A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTGateway.Model", "IoTGateway.Model\IoTGateway.Model.csproj", "{C2978E5D-E71E-4882-8EF1-4014E8565A77}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTGateway.DataAccess", "IoTGateway.DataAccess\IoTGateway.DataAccess.csproj", "{9E7C8C77-643F-45CF-8EDC-5B032C51D563}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTGateway.ViewModel", "IoTGateway.ViewModel\IoTGateway.ViewModel.csproj", "{00E91FC1-D5CF-416A-AAAF-61567E368DCD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{FBED048F-7AB9-4348-AD56-F9BF4D9E3A55}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin", "Plugins\Plugin\Plugin.csproj", "{61D79F77-09EF-4A98-A50B-043B1D72C111}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginInterface", "Plugins\PluginInterface\PluginInterface.csproj", "{E5F79995-AB61-41F4-820D-BA39967B406B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Drivers", "Drivers", "{52D96C24-2F2F-49B5-9F29-00414DEA41D8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DriverModbusTCP", "Plugins\Drivers\DriverModbusTCP\DriverModbusTCP.csproj", "{7B432FC9-57E6-44BF-B8A7-2A1FB31D6ADD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68ABBDF2-1485-4756-9A94-6AFA874D69A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68ABBDF2-1485-4756-9A94-6AFA874D69A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68ABBDF2-1485-4756-9A94-6AFA874D69A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68ABBDF2-1485-4756-9A94-6AFA874D69A3}.Release|Any CPU.Build.0 = Release|Any CPU
{C2978E5D-E71E-4882-8EF1-4014E8565A77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2978E5D-E71E-4882-8EF1-4014E8565A77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2978E5D-E71E-4882-8EF1-4014E8565A77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2978E5D-E71E-4882-8EF1-4014E8565A77}.Release|Any CPU.Build.0 = Release|Any CPU
{9E7C8C77-643F-45CF-8EDC-5B032C51D563}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E7C8C77-643F-45CF-8EDC-5B032C51D563}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E7C8C77-643F-45CF-8EDC-5B032C51D563}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E7C8C77-643F-45CF-8EDC-5B032C51D563}.Release|Any CPU.Build.0 = Release|Any CPU
{00E91FC1-D5CF-416A-AAAF-61567E368DCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00E91FC1-D5CF-416A-AAAF-61567E368DCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00E91FC1-D5CF-416A-AAAF-61567E368DCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00E91FC1-D5CF-416A-AAAF-61567E368DCD}.Release|Any CPU.Build.0 = Release|Any CPU
{61D79F77-09EF-4A98-A50B-043B1D72C111}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61D79F77-09EF-4A98-A50B-043B1D72C111}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61D79F77-09EF-4A98-A50B-043B1D72C111}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61D79F77-09EF-4A98-A50B-043B1D72C111}.Release|Any CPU.Build.0 = Release|Any CPU
{E5F79995-AB61-41F4-820D-BA39967B406B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5F79995-AB61-41F4-820D-BA39967B406B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5F79995-AB61-41F4-820D-BA39967B406B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5F79995-AB61-41F4-820D-BA39967B406B}.Release|Any CPU.Build.0 = Release|Any CPU
{7B432FC9-57E6-44BF-B8A7-2A1FB31D6ADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B432FC9-57E6-44BF-B8A7-2A1FB31D6ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B432FC9-57E6-44BF-B8A7-2A1FB31D6ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B432FC9-57E6-44BF-B8A7-2A1FB31D6ADD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{61D79F77-09EF-4A98-A50B-043B1D72C111} = {FBED048F-7AB9-4348-AD56-F9BF4D9E3A55}
{E5F79995-AB61-41F4-820D-BA39967B406B} = {FBED048F-7AB9-4348-AD56-F9BF4D9E3A55}
{52D96C24-2F2F-49B5-9F29-00414DEA41D8} = {FBED048F-7AB9-4348-AD56-F9BF4D9E3A55}
{7B432FC9-57E6-44BF-B8A7-2A1FB31D6ADD} = {52D96C24-2F2F-49B5-9F29-00414DEA41D8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1F219808-E6E8-4C1D-B846-41F2F7CF20FA}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "6.0.0",
"commands": [
"dotnet-ef"
]
}
}
}

View File

@ -0,0 +1,219 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.ViewModel.BasicData.DeviceConfigVMs;
namespace IoTGateway.Controllers
{
[Area("BasicData")]
[ActionDescription("设备参数配置")]
public partial class DeviceConfigController : BaseController
{
#region Search
[ActionDescription("Sys.Search")]
public ActionResult Index()
{
var vm = Wtm.CreateVM<DeviceConfigListVM>();
return PartialView(vm);
}
[ActionDescription("Sys.Search")]
[HttpPost]
public string Search(DeviceConfigSearcher searcher)
{
var vm = Wtm.CreateVM<DeviceConfigListVM>(passInit: true);
if (ModelState.IsValid)
{
vm.Searcher = searcher;
return vm.GetJson(false);
}
else
{
return vm.GetError();
}
}
#endregion
#region Create
[ActionDescription("Sys.Create")]
public ActionResult Create()
{
var vm = Wtm.CreateVM<DeviceConfigVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Create")]
public ActionResult Create(DeviceConfigVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoAdd();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
}
#endregion
#region Edit
[ActionDescription("Sys.Edit")]
public ActionResult Edit(string id)
{
var vm = Wtm.CreateVM<DeviceConfigVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Edit")]
[HttpPost]
[ValidateFormItemOnly]
public ActionResult Edit(DeviceConfigVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoEdit();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
}
}
}
#endregion
#region Delete
[ActionDescription("Sys.Delete")]
public ActionResult Delete(string id)
{
var vm = Wtm.CreateVM<DeviceConfigVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Delete")]
[HttpPost]
public ActionResult Delete(string id, IFormCollection nouse)
{
var vm = Wtm.CreateVM<DeviceConfigVM>(id);
vm.DoDelete();
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
#endregion
#region Details
[ActionDescription("Sys.Details")]
public ActionResult Details(string id)
{
var vm = Wtm.CreateVM<DeviceConfigVM>(id);
return PartialView(vm);
}
#endregion
#region BatchEdit
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult BatchEdit(string[] IDs)
{
var vm = Wtm.CreateVM<DeviceConfigBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult DoBatchEdit(DeviceConfigBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchEdit())
{
return PartialView("BatchEdit",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
}
}
#endregion
#region BatchDelete
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult BatchDelete(string[] IDs)
{
var vm = Wtm.CreateVM<DeviceConfigBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult DoBatchDelete(DeviceConfigBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchDelete())
{
return PartialView("BatchDelete",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
}
}
#endregion
#region Import
[ActionDescription("Sys.Import")]
public ActionResult Import()
{
var vm = Wtm.CreateVM<DeviceConfigImportVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Import")]
public ActionResult Import(DeviceConfigImportVM vm, IFormCollection nouse)
{
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
}
}
#endregion
[ActionDescription("Sys.Export")]
[HttpPost]
public IActionResult ExportExcel(DeviceConfigListVM vm)
{
return vm.GetExportData();
}
}
}

View File

@ -0,0 +1,289 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.ViewModel.BasicData.DeviceVMs;
using Plugin;
namespace IoTGateway.Controllers
{
[Area("BasicData")]
[ActionDescription("设备维护")]
public partial class DeviceController : BaseController
{
private DeviceService _DeviceService;
public DeviceController(DeviceService deviceService)
{
_DeviceService = deviceService;
}
#region Search
[ActionDescription("Sys.Search")]
public ActionResult Index()
{
var vm = Wtm.CreateVM<DeviceListVM>();
return PartialView(vm);
}
[ActionDescription("Sys.Search")]
[HttpPost]
public string Search(DeviceSearcher searcher)
{
var vm = Wtm.CreateVM<DeviceListVM>(passInit: true);
if (ModelState.IsValid)
{
vm.Searcher = searcher;
return vm.GetJson(false);
}
else
{
return vm.GetError();
}
}
#endregion
#region Create
[ActionDescription("创建设备")]
public ActionResult Create()
{
var vm = Wtm.CreateVM<DeviceVM>();
vm.Entity.DeviceTypeEnum = Model.DeviceTypeEnum.Device;
return PartialView(vm);
}
[HttpPost]
[ActionDescription("创建设备")]
public ActionResult Create(DeviceVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.Entity.DeviceTypeEnum = Model.DeviceTypeEnum.Device;
vm.DoAdd();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
}
#endregion
#region Create
[ActionDescription("Sys.Create")]
public ActionResult CreateGroup()
{
var vm = Wtm.CreateVM<DeviceVM>();
vm.Entity.DeviceTypeEnum = Model.DeviceTypeEnum.Group;
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Create")]
public ActionResult CreateGroup(DeviceVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.Entity.DeviceTypeEnum = Model.DeviceTypeEnum.Group;
vm.DoAdd();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
}
#endregion
#region Edit
[ActionDescription("Sys.Edit")]
public ActionResult Edit(string id)
{
var vm = Wtm.CreateVM<DeviceVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Edit")]
[HttpPost]
[ValidateFormItemOnly]
public ActionResult Edit(DeviceVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoEdit();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
}
}
}
#endregion
#region Delete
[ActionDescription("Sys.Delete")]
public ActionResult Delete(string id)
{
var vm = Wtm.CreateVM<DeviceVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Delete")]
[HttpPost]
public ActionResult Delete(string id, IFormCollection nouse)
{
var vm = Wtm.CreateVM<DeviceVM>(id);
vm.DoDelete();
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
#endregion
#region Details
[ActionDescription("Sys.Details")]
public ActionResult Details(string id)
{
var vm = Wtm.CreateVM<DeviceVM>(id);
return PartialView(vm);
}
#endregion
#region BatchEdit
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult BatchEdit(string[] IDs)
{
var vm = Wtm.CreateVM<DeviceBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult DoBatchEdit(DeviceBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchEdit())
{
return PartialView("BatchEdit",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
}
}
#endregion
#region BatchDelete
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult BatchDelete(string[] IDs)
{
var vm = Wtm.CreateVM<DeviceBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult DoBatchDelete(DeviceBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchDelete())
{
return PartialView("BatchDelete",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
}
}
#endregion
#region Import
[ActionDescription("Sys.Import")]
public ActionResult Import()
{
var vm = Wtm.CreateVM<DeviceImportVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Import")]
public ActionResult Import(DeviceImportVM vm, IFormCollection nouse)
{
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
}
}
#endregion
[ActionDescription("Sys.Export")]
[HttpPost]
public IActionResult ExportExcel(DeviceListVM vm)
{
return vm.GetExportData();
}
#region
[ActionDescription("设备复制")]
public ActionResult Copy()
{
var vm = Wtm.CreateVM<CopyVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("设备复制")]
public ActionResult Copy(CopyVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.Copy();
return FFResult().CloseDialog().RefreshGrid().Alert($"{vm.复制结果}");
}
}
#endregion
public IActionResult GetMethods(Guid? ID)
{
return JsonMore(_DeviceService.GetDriverMethods(ID));
}
}
}

View File

@ -0,0 +1,220 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.ViewModel.BasicData.DeviceVariableVMs;
namespace IoTGateway.Controllers
{
[Area("BasicData")]
[ActionDescription("设备变量配置")]
public partial class DeviceVariableController : BaseController
{
#region Search
[ActionDescription("Sys.Search")]
public ActionResult Index()
{
var vm = Wtm.CreateVM<DeviceVariableListVM>();
return PartialView(vm);
}
[ActionDescription("Sys.Search")]
[HttpPost]
public string Search(DeviceVariableSearcher searcher)
{
var vm = Wtm.CreateVM<DeviceVariableListVM>(passInit: true);
if (ModelState.IsValid)
{
vm.Searcher = searcher;
return vm.GetJson(false);
}
else
{
return vm.GetError();
}
}
#endregion
#region Create
[ActionDescription("Sys.Create")]
public ActionResult Create()
{
var vm = Wtm.CreateVM<DeviceVariableVM>();
vm.Entity.ValueFactor = 1;
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Create")]
public ActionResult Create(DeviceVariableVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoAdd();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
}
#endregion
#region Edit
[ActionDescription("Sys.Edit")]
public ActionResult Edit(string id)
{
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Edit")]
[HttpPost]
[ValidateFormItemOnly]
public ActionResult Edit(DeviceVariableVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoEdit();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
}
}
}
#endregion
#region Delete
[ActionDescription("Sys.Delete")]
public ActionResult Delete(string id)
{
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Delete")]
[HttpPost]
public ActionResult Delete(string id, IFormCollection nouse)
{
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
vm.DoDelete();
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
#endregion
#region Details
[ActionDescription("Sys.Details")]
public ActionResult Details(string id)
{
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
return PartialView(vm);
}
#endregion
#region BatchEdit
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult BatchEdit(string[] IDs)
{
var vm = Wtm.CreateVM<DeviceVariableBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult DoBatchEdit(DeviceVariableBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchEdit())
{
return PartialView("BatchEdit",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
}
}
#endregion
#region BatchDelete
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult BatchDelete(string[] IDs)
{
var vm = Wtm.CreateVM<DeviceVariableBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult DoBatchDelete(DeviceVariableBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchDelete())
{
return PartialView("BatchDelete",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
}
}
#endregion
#region Import
[ActionDescription("Sys.Import")]
public ActionResult Import()
{
var vm = Wtm.CreateVM<DeviceVariableImportVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Import")]
public ActionResult Import(DeviceVariableImportVM vm, IFormCollection nouse)
{
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
}
}
#endregion
[ActionDescription("Sys.Export")]
[HttpPost]
public IActionResult ExportExcel(DeviceVariableListVM vm)
{
return vm.GetExportData();
}
}
}

View File

@ -0,0 +1,219 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.ViewModel.BasicData.DriverVMs;
namespace IoTGateway.Controllers
{
[Area("BasicData")]
[ActionDescription("驱动管理")]
public partial class DriverController : BaseController
{
#region Search
[ActionDescription("Sys.Search")]
public ActionResult Index()
{
var vm = Wtm.CreateVM<DriverListVM>();
return PartialView(vm);
}
[ActionDescription("Sys.Search")]
[HttpPost]
public string Search(DriverSearcher searcher)
{
var vm = Wtm.CreateVM<DriverListVM>(passInit: true);
if (ModelState.IsValid)
{
vm.Searcher = searcher;
return vm.GetJson(false);
}
else
{
return vm.GetError();
}
}
#endregion
#region Create
[ActionDescription("Sys.Create")]
public ActionResult Create()
{
var vm = Wtm.CreateVM<DriverVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Create")]
public ActionResult Create(DriverVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoAdd();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
}
#endregion
#region Edit
[ActionDescription("Sys.Edit")]
public ActionResult Edit(string id)
{
var vm = Wtm.CreateVM<DriverVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Edit")]
[HttpPost]
[ValidateFormItemOnly]
public ActionResult Edit(DriverVM vm)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
vm.DoEdit();
if (!ModelState.IsValid)
{
vm.DoReInit();
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
}
}
}
#endregion
#region Delete
[ActionDescription("Sys.Delete")]
public ActionResult Delete(string id)
{
var vm = Wtm.CreateVM<DriverVM>(id);
return PartialView(vm);
}
[ActionDescription("Sys.Delete")]
[HttpPost]
public ActionResult Delete(string id, IFormCollection nouse)
{
var vm = Wtm.CreateVM<DriverVM>(id);
vm.DoDelete();
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid();
}
}
#endregion
#region Details
[ActionDescription("Sys.Details")]
public ActionResult Details(string id)
{
var vm = Wtm.CreateVM<DriverVM>(id);
return PartialView(vm);
}
#endregion
#region BatchEdit
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult BatchEdit(string[] IDs)
{
var vm = Wtm.CreateVM<DriverBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchEdit")]
public ActionResult DoBatchEdit(DriverBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchEdit())
{
return PartialView("BatchEdit",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
}
}
#endregion
#region BatchDelete
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult BatchDelete(string[] IDs)
{
var vm = Wtm.CreateVM<DriverBatchVM>(Ids: IDs);
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.BatchDelete")]
public ActionResult DoBatchDelete(DriverBatchVM vm, IFormCollection nouse)
{
if (!ModelState.IsValid || !vm.DoBatchDelete())
{
return PartialView("BatchDelete",vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
}
}
#endregion
#region Import
[ActionDescription("Sys.Import")]
public ActionResult Import()
{
var vm = Wtm.CreateVM<DriverImportVM>();
return PartialView(vm);
}
[HttpPost]
[ActionDescription("Sys.Import")]
public ActionResult Import(DriverImportVM vm, IFormCollection nouse)
{
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
{
return PartialView(vm);
}
else
{
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
}
}
#endregion
[ActionDescription("Sys.Export")]
[HttpPost]
public IActionResult ExportExcel(DriverListVM vm)
{
return vm.GetExportData();
}
}
}

View File

@ -0,0 +1,12 @@
@model IoTGateway.ViewModel.BasicData.DeviceVMs.DeviceBatchVM
@inject IStringLocalizer<Program> Localizer;
<wt:form vm="@Model">
<wt:quote>@Localizer["Sys.BatchDeleteConfirm"]</wt:quote>
<wt:hidden field="Ids" />
<wt:grid vm="ListVM" use-local-data="true" height="300" hidden-checkbox="true" hidden-panel="true"/>
<wt:row align="AlignEnum.Right">
<wt:submitbutton theme=" ButtonThemeEnum.Warm" text="@Localizer["Sys.Delete"]"/>
<wt:closebutton />
</wt:row>
</wt:form>

View File

@ -0,0 +1,18 @@
@model IoTGateway.ViewModel.BasicData.DeviceVMs.DeviceBatchVM
@inject IStringLocalizer<Program> Localizer;
<wt:form vm="@Model">
<div style="margin-bottom:10px">@Localizer["Sys.BatchEditConfirm"] </div>
<wt:row items-per-row="ItemsPerRowEnum.Two">
<wt:combobox field="LinkedVM.DriverId" items="LinkedVM.AllDrivers"/>
<wt:switch field="LinkedVM.AutoStart" />
<wt:combobox field="LinkedVM.DeviceTypeEnum" />
<wt:combobox field="LinkedVM.ParentId" items="LinkedVM.AllParents"/>
</wt:row>
<wt:hidden field="Ids" />
<wt:grid vm="ListVM" use-local-data="true" height="300" hidden-checkbox="true" hidden-panel="true"/>
<wt:row align="AlignEnum.Right">
<wt:submitbutton />
<wt:closebutton />
</wt:row>
</wt:form>

View File

@ -0,0 +1,15 @@
@model IoTGateway.ViewModel.BasicData.DeviceVMs.CopyVM
@inject IStringLocalizer<Program> Localizer;
<wt:form vm="@Model" >
<wt:row items-per-row="ItemsPerRowEnum.One">
<wt:quote>@Model.设备名称</wt:quote>
<wt:textbox field=复制数量/>
</wt:row>
<wt:row align="AlignEnum.Right">
<wt:submitbutton text="复制" />
<wt:closebutton text="取消" />
</wt:row>
</wt:form>

Some files were not shown because too many files have changed in this diff Show More