USE [master]
GO
/****** Object:  Database [Miidy_Cloud_Train]    Script Date: 2019/7/4 10:56:54 ******/

ALTER DATABASE [Miidy_Cloud_Train] SET COMPATIBILITY_LEVEL = 120
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [Miidy_Cloud_Train].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [Miidy_Cloud_Train] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET ARITHABORT OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET  DISABLE_BROKER 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET RECOVERY FULL 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET  MULTI_USER 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [Miidy_Cloud_Train] SET DB_CHAINING OFF 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
ALTER DATABASE [Miidy_Cloud_Train] SET DELAYED_DURABILITY = DISABLED 
GO
EXEC sys.sp_db_vardecimal_storage_format N'Miidy_Cloud_Train', N'ON'
GO
USE [Miidy_Cloud_Train]
GO
/****** Object:  Table [dbo].[MC_Category]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_Category](
	[CategoryId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[OrganizaId] [uniqueidentifier] NOT NULL,
	[CreateUserId] [uniqueidentifier] NOT NULL,
	[FatherId] [uniqueidentifier] NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Type] [int] NOT NULL,
	[Sort] [int] NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MCS_ExamCategory] PRIMARY KEY CLUSTERED 
(
	[CategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_Chapter]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_Chapter](
	[ChapterId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](150) NOT NULL,
	[Sort] [int] NOT NULL,
	[Comment] [nvarchar](300) NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MCS_CourseChapter] PRIMARY KEY CLUSTERED 
(
	[ChapterId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_Chapter_Ware]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_Chapter_Ware](
	[ChapterWareId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[ChapterId] [uniqueidentifier] NOT NULL,
	[WareId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](150) NOT NULL,
	[Duration] [int] NOT NULL,
	[Sort] [int] NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MCS_Chapter_Ware] PRIMARY KEY CLUSTERED 
(
	[ChapterWareId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_Course]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_Course](
	[CourseId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[OrganizaId] [uniqueidentifier] NOT NULL,
	[CategoryId] [uniqueidentifier] NOT NULL,
	[CreateUserId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](150) NOT NULL,
	[Pic] [nvarchar](150) NOT NULL,
	[Duration] [int] NOT NULL,
	[State] [int] NOT NULL,
	[StudyType] [int] NOT NULL,
	[Credit] [int] NOT NULL,
	[Password] [int] NOT NULL,
	[Complete] [int] NOT NULL,
	[LimitType] [int] NOT NULL,
	[EndTime] [datetime] NULL,
	[EndNum] [int] NOT NULL,
	[Introduce] [nvarchar](3000) NULL,
	[Notice] [nvarchar](600) NULL,
	[Target] [nvarchar](3000) NULL,
	[IsSequence] [bit] NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MCS_Course] PRIMARY KEY CLUSTERED 
(
	[CourseId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[MC_CourseComment]    Script Date: 2019/8/26 19:26:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[MC_CourseComment](
	[CourseCommentId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Context] [nvarchar](3000) NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MC_CourseComment] PRIMARY KEY CLUSTERED 
(
	[CourseCommentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO


/****** Object:  Table [dbo].[MC_CourseCommentReply]    Script Date: 2019/8/27 15:01:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[MC_CourseCommentReply](
	[CourseCommentReplyId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[CourseCommentId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Context] [nvarchar](3000) NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MC_CourseCommentReply] PRIMARY KEY CLUSTERED 
(
	[CourseCommentReplyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[MC_CourseEmpower]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_CourseEmpower](
	[CourseEmpowerId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[ObjectId] [uniqueidentifier] NOT NULL,
	[Type] [int] NOT NULL,
	[IsDistribution] [bit] NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_CourseLimit] PRIMARY KEY CLUSTERED 
(
	[CourseEmpowerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_CourseRecord]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_CourseRecord](
	[CourseRecordId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[LastChapterWareId] [uniqueidentifier] NULL,
	[Duration] [int] NOT NULL,
	[Count] [int] NOT NULL,
	[State] [int] NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MC_CourseRecord] PRIMARY KEY CLUSTERED 
(
	[CourseRecordId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_Note]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_Note](
	[NoteId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseId] [uniqueidentifier] NOT NULL,
	[ChapterId] [uniqueidentifier] NOT NULL,
	[ChapterWareId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Context] [nvarchar](3000) NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MC_Note] PRIMARY KEY CLUSTERED 
(
	[NoteId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_Ware]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_Ware](
	[WareId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[OrganizaId] [uniqueidentifier] NOT NULL,
	[CategoryId] [uniqueidentifier] NOT NULL,
	[CreateUserId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](150) NOT NULL,
	[Type] [int] NOT NULL,
	[Duration] [int] NOT NULL,
	[Url] [nvarchar](800) NULL,
	[Context] [nvarchar](max) NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_MCS_Ware] PRIMARY KEY CLUSTERED 
(
	[WareId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MC_WareRecord]    Script Date: 2019/7/4 10:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MC_WareRecord](
	[WareRecordId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CourseRecordId] [uniqueidentifier] NOT NULL,
	[ChapterId] [uniqueidentifier] NOT NULL,
	[ChapterWareId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Duration] [int] NOT NULL,
	[Count] [int] NOT NULL,
	[State] [int] NOT NULL,
	[IsDelete] [bit] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_WareRecord] PRIMARY KEY CLUSTERED 
(
	[WareRecordId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'57bf9f39-3bc9-42e4-a31e-1042b78c7e09', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'be36d946-5c65-41bf-b469-add06977e7fd', N'课件分类2-1', 1, 0, 0, CAST(N'2019-06-16T22:15:27.160' AS DateTime), CAST(N'2019-06-16T22:15:27.160' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'f89bb03b-9a9d-4bb1-8625-77526d8c1b71', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'3b7f2b25-6ca8-4300-89d0-fd8e0f52041e', N'课件分类1-1-1', 1, 1, 0, CAST(N'2019-05-09T17:14:23.000' AS DateTime), CAST(N'2019-05-09T17:14:23.000' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'53092b5b-96a5-49d8-a7d3-7f105908c99e', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', NULL, N'课程分类', 2, 5, 0, CAST(N'2019-05-18T20:17:22.087' AS DateTime), CAST(N'2019-05-19T10:12:53.747' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'6eb259b2-e8d2-4273-bbc2-8882d37809fd', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', NULL, N'测试', 2, 3, 0, CAST(N'2019-05-19T10:12:41.607' AS DateTime), CAST(N'2019-05-19T10:12:41.607' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'eb87b2fe-79e1-4c7d-a981-999dc5766f59', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', NULL, N'课件分类23', 1, 5, 1, CAST(N'2019-05-09T17:14:23.000' AS DateTime), CAST(N'2019-05-18T14:06:17.830' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'be36d946-5c65-41bf-b469-add06977e7fd', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', NULL, N'课件分类2', 1, 2, 0, CAST(N'2019-06-16T22:15:15.110' AS DateTime), CAST(N'2019-06-16T22:15:15.110' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'899e4640-1735-4888-a071-c81ae44233ac', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', NULL, N'课件分类1', 1, 1, 0, CAST(N'2019-05-09T17:14:23.000' AS DateTime), CAST(N'2019-05-09T17:14:23.000' AS DateTime))
INSERT [dbo].[MC_Category] ([CategoryId], [CompanyId], [OrganizaId], [CreateUserId], [FatherId], [Name], [Type], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'3b7f2b25-6ca8-4300-89d0-fd8e0f52041e', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'899e4640-1735-4888-a071-c81ae44233ac', N'课件分类1-1', 1, 1, 0, CAST(N'2019-05-09T17:14:23.000' AS DateTime), CAST(N'2019-05-09T17:14:23.000' AS DateTime))
INSERT [dbo].[MC_Chapter] ([ChapterId], [CompanyId], [CourseId], [Name], [Sort], [Comment], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'7eccea54-1453-4674-bd25-38213f3f716a', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'第二章', 2, NULL, 0, CAST(N'2019-05-18T20:50:32.777' AS DateTime), CAST(N'2019-05-18T20:50:32.777' AS DateTime))
INSERT [dbo].[MC_Chapter] ([ChapterId], [CompanyId], [CourseId], [Name], [Sort], [Comment], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'bf00ef2c-69c8-483d-926a-4444b9346360', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'第三章', 3, N'大规模4545', 0, CAST(N'2019-05-19T11:12:00.240' AS DateTime), CAST(N'2019-05-19T12:29:33.800' AS DateTime))
INSERT [dbo].[MC_Chapter] ([ChapterId], [CompanyId], [CourseId], [Name], [Sort], [Comment], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'31bb8e45-aaa7-45b4-a0f5-99f22aa12e86', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'第一章', 1, NULL, 0, CAST(N'2019-05-18T20:54:54.860' AS DateTime), CAST(N'2019-05-18T20:54:54.860' AS DateTime))
INSERT [dbo].[MC_Chapter] ([ChapterId], [CompanyId], [CourseId], [Name], [Sort], [Comment], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'6754fe05-6748-4a38-941f-c7f2824c1e71', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'第四章', 4, N'夺', 1, CAST(N'2019-05-19T12:03:05.030' AS DateTime), CAST(N'2019-05-19T12:09:27.580' AS DateTime))
INSERT [dbo].[MC_Chapter] ([ChapterId], [CompanyId], [CourseId], [Name], [Sort], [Comment], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'0b040fa4-9bbb-4819-9a7c-e5f10f8c4e87', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'45', 0, N'fgfg', 1, CAST(N'2019-05-19T12:29:47.797' AS DateTime), CAST(N'2019-05-19T12:29:54.957' AS DateTime))
INSERT [dbo].[MC_Chapter_Ware] ([ChapterWareId], [CompanyId], [CourseId], [ChapterId], [WareId], [Name], [Duration], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'48ca2445-e971-44b4-a721-4a543c397db5', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'bf00ef2c-69c8-483d-926a-4444b9346360', N'1911ec6d-f356-4e28-a685-fcffcb202b28', N'图文课件演示2', 4, 0, 0, CAST(N'2019-05-30T09:33:02.153' AS DateTime), CAST(N'2019-05-30T09:33:02.153' AS DateTime))
INSERT [dbo].[MC_Chapter_Ware] ([ChapterWareId], [CompanyId], [CourseId], [ChapterId], [WareId], [Name], [Duration], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'1e6d60ee-bc0e-4099-8cee-4c94d5bedc15', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'31bb8e45-aaa7-45b4-a0f5-99f22aa12e86', N'55a630a7-e6c8-4c05-a92b-a99bc7464b7a', N'图文课件演示', 8, 0, 0, CAST(N'2019-05-21T17:57:57.927' AS DateTime), CAST(N'2019-05-21T17:57:57.927' AS DateTime))
INSERT [dbo].[MC_Chapter_Ware] ([ChapterWareId], [CompanyId], [CourseId], [ChapterId], [WareId], [Name], [Duration], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'2970811f-1521-4e3d-90f5-b991dff8c96e', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'7eccea54-1453-4674-bd25-38213f3f716a', N'9afb7033-8b40-43eb-b38a-441f96eeea5e', N'音频课件演示', 3, 0, 0, CAST(N'2019-05-30T09:32:44.963' AS DateTime), CAST(N'2019-06-16T12:36:25.313' AS DateTime))
INSERT [dbo].[MC_Chapter_Ware] ([ChapterWareId], [CompanyId], [CourseId], [ChapterId], [WareId], [Name], [Duration], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'48261477-c55e-468a-9e48-ba09df8ff6e1', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'31bb8e45-aaa7-45b4-a0f5-99f22aa12e86', N'92f30f47-dd66-486a-8d10-9e50c68965b3', N'视频课件演示', 23, 1, 0, CAST(N'2019-05-19T14:23:02.050' AS DateTime), CAST(N'2019-05-19T15:05:11.190' AS DateTime))
INSERT [dbo].[MC_Chapter_Ware] ([ChapterWareId], [CompanyId], [CourseId], [ChapterId], [WareId], [Name], [Duration], [Sort], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'4e75e2bb-4378-4fec-a171-f8d89600c2ed', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'7eccea54-1453-4674-bd25-38213f3f716a', N'd5534c34-7242-4861-ad75-75ba965b5c47', N'PDF课件演示', 4, 0, 0, CAST(N'2019-05-30T09:32:44.863' AS DateTime), CAST(N'2019-05-30T09:32:44.863' AS DateTime))
INSERT [dbo].[MC_Course] ([CourseId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Pic], [Duration], [State], [StudyType], [Credit], [Password], [Complete], [LimitType], [EndTime], [EndNum], [Introduce], [Notice], [Target], [IsSequence], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'53092b5b-96a5-49d8-a7d3-7f105908c99e', N'78d7b156-369f-4541-b847-bf85abd6438c', N'利用MassTransit集成RabbitMQ', N'', 42, 2, 2, 4, 219619, 0, 1, NULL, 0, N'在ASP.NET Core上利用MassTransit来集成使用RabbitMQ真的很简单，代码也很简洁。近期因为项目需要，我便在这基础上再次进行了封装，抽成了公共方法，使得使用RabbitMQ的调用变得更方便简洁。那么，就让咱们来瞧瞧其魅力所在吧。基于MassTransit库使得我们使用RabbitMQ变得更简洁、方便。而基于再次封装后，生产者与消费者将不需要关注具体的业务，也跟业务代码解耦了，更能适应项目的需要。', N'必需按顺学完每个章节', N'帮助学员认识RabbitMQ与MassTransit技术。', 1, 0, CAST(N'2019-05-18T20:54:54.860' AS DateTime), CAST(N'2019-06-16T12:36:25.827' AS DateTime))
INSERT [dbo].[MC_Course] ([CourseId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Pic], [Duration], [State], [StudyType], [Credit], [Password], [Complete], [LimitType], [EndTime], [EndNum], [Introduce], [Notice], [Target], [IsSequence], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'e145da82-42d7-47e6-84c2-ed469767eed3', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'53092b5b-96a5-49d8-a7d3-7f105908c99e', N'78d7b156-369f-4541-b847-bf85abd6438c', N'微软Powerbi从入门到精通', N'', 0, 2, 1, 1, 219618, 0, 1, NULL, 0, N'大规模、课程简介', N'大规模、课程须知', N'大规模、学习目标', 0, 0, CAST(N'2019-05-18T20:50:32.777' AS DateTime), CAST(N'2019-06-16T22:23:37.807' AS DateTime))
INSERT [dbo].[MC_CourseEmpower] ([CourseEmpowerId], [CompanyId], [CourseId], [ObjectId], [Type], [IsDistribution], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'340799ad-e23f-4b53-8b3e-06041f9c12cc', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'6c215a66-6009-4c4e-a8f5-b5f7c9ad553b', 2, 1, 1, CAST(N'2019-05-21T17:42:40.707' AS DateTime), CAST(N'2019-05-21T17:55:29.577' AS DateTime))
INSERT [dbo].[MC_CourseEmpower] ([CourseEmpowerId], [CompanyId], [CourseId], [ObjectId], [Type], [IsDistribution], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'e823c18e-69d1-4e8b-81ac-4eb12475ad42', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'e145da82-42d7-47e6-84c2-ed469767eed3', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', 1, 0, 0, CAST(N'2019-05-29T13:47:47.177' AS DateTime), CAST(N'2019-05-29T15:15:17.650' AS DateTime))
INSERT [dbo].[MC_CourseEmpower] ([CourseEmpowerId], [CompanyId], [CourseId], [ObjectId], [Type], [IsDistribution], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'bfa41006-e943-401a-888a-9b8210ecb701', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', 1, 1, 1, CAST(N'2019-05-21T17:52:06.970' AS DateTime), CAST(N'2019-05-29T13:05:19.207' AS DateTime))
INSERT [dbo].[MC_CourseEmpower] ([CourseEmpowerId], [CompanyId], [CourseId], [ObjectId], [Type], [IsDistribution], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'5f363281-89d3-4d7c-99bb-f57e6f7d5e20', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', 2, 1, 0, CAST(N'2019-05-21T17:42:40.647' AS DateTime), CAST(N'2019-05-29T13:05:22.623' AS DateTime))
INSERT [dbo].[MC_CourseRecord] ([CourseRecordId], [CompanyId], [CourseId], [UserId], [LastChapterWareId], [Duration], [Count], [State], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'7788fe0b-d5ec-4677-bd7e-8ba84c49abb9', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'2970811f-1521-4e3d-90f5-b991dff8c96e', 1, 1, 1, 0, CAST(N'2019-05-31T08:39:38.207' AS DateTime), CAST(N'2019-06-16T13:09:26.757' AS DateTime))
INSERT [dbo].[MC_Note] ([NoteId], [CompanyId], [CourseId], [ChapterId], [ChapterWareId], [UserId], [Context], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'a9eb453d-c7f7-45ad-9e70-4c35af36b063', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'f4df2b0a-cee9-4feb-8a14-1e68ddf969bf', N'31bb8e45-aaa7-45b4-a0f5-99f22aa12e86', N'1e6d60ee-bc0e-4099-8cee-4c94d5bedc15', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'是一个让RabbitMQ支持stomp协议的插件，必需安装后才能通过RabbitMQ实现前端通讯，所以基于WebSocket技术实现的通讯方案正越来越受大家喜爱，于是在ASP.NET中就有了鼎鼎大名的Signalr。但Signalr不是咱们这里的主角，这里将给大家介绍另一套基于WebSocket的前后端通讯方案，可以给大家在应用中多一个选择。', 0, CAST(N'2019-05-31T17:06:17.170' AS DateTime), CAST(N'2019-05-31T17:06:17.170' AS DateTime))
INSERT [dbo].[MC_Ware] ([WareId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Type], [Duration], [Url], [Context], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'9afb7033-8b40-43eb-b38a-441f96eeea5e', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'3b7f2b25-6ca8-4300-89d0-fd8e0f52041e', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'音频课件演示', 3, 6, N'http://www.lezhima.com/Down/63gpu33a73a-ffgc-2rtd0-4v0-afe5-2bm926473c0179.mp3', N'<p></p>', 0, CAST(N'2019-05-18T13:26:12.577' AS DateTime), CAST(N'2019-06-23T11:10:22.600' AS DateTime))
INSERT [dbo].[MC_Ware] ([WareId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Type], [Duration], [Url], [Context], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'd5534c34-7242-4861-ad75-75ba965b5c47', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'899e4640-1735-4888-a071-c81ae44233ac', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'PDF课件演示', 4, 4, N'http://www.lezhima.com/Down/96cb0b6d-4dbf-4046-a187-e78955bdf970.pdf', N'<p></p>', 0, CAST(N'2019-05-18T13:01:23.767' AS DateTime), CAST(N'2019-05-30T09:14:07.717' AS DateTime))
INSERT [dbo].[MC_Ware] ([WareId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Type], [Duration], [Url], [Context], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'92f30f47-dd66-486a-8d10-9e50c68965b3', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'899e4640-1735-4888-a071-c81ae44233ac', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'视频课件演示', 2, 23, N'http://vjs.zencdn.net/v/oceans.mp4', N'<p></p>', 0, CAST(N'2019-05-18T13:52:45.327' AS DateTime), CAST(N'2019-05-30T09:08:39.110' AS DateTime))
INSERT [dbo].[MC_Ware] ([WareId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Type], [Duration], [Url], [Context], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'55a630a7-e6c8-4c05-a92b-a99bc7464b7a', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'899e4640-1735-4888-a071-c81ae44233ac', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'图文课件演示', 1, 8, NULL, N'<p>
</p><h1>
			<a id="cb_post_title_url" href="https://www.cnblogs.com/Andre/p/10012329.html">ASP.NET Core2基于RabbitMQ对Web前端实现推送功能</a>
		</h1>
		
		<div>
			<div id="cnblogs_post_body"><p>在我们很多的Web应用中会遇到需要从后端将指定的数据或消息实时推送到前端，通常的做法是前端写个脚本定时到后端获取，或者借助WebSocket技术实现前后端实时通讯。因定时刷新的方法弊端很多（已不再采用），所以基于WebSocket技术实现的通讯方案正越来越受大家喜爱，于是在ASP.NET中就有了鼎鼎大名的Signalr。但Signalr不是咱们这里的主角，这里将给大家介绍另一套基于WebSocket的前后端通讯方案，可以给大家在应用中多一个选择。</p>
<p>&nbsp;</p>
<p><strong><span>准备</span></strong></p>
<p>在开始动手前，咱们先简单介绍下方案的组成部分，如下：</p>
<p><strong>RabbitMQ：</strong>是一个成熟的MQ队列服务，由 Erlang 语言开发的 AMQP 的开源实现。这里用来接收后端的指令并广播到前端（基于topic模式）。关于更多RabbitMQ的实现可以查看我另一篇文章，<a href="https://www.cnblogs.com/Andre/p/9579764.html" target="_blank">传送门</a></p>
<p><strong>RabbitMQ插件stomp：</strong>是一个让RabbitMQ支持stomp协议的插件，必需安装后才能通过RabbitMQ实现前端通讯。安装说明在此：<a title="http://www.rabbitmq.com/stomp.html" href="http://www.rabbitmq.com/stomp.html" target="_blank">http://www.rabbitmq.com/stomp.html</a></p>
<p><strong>stomp.js：</strong>是一个基于stomp协议的客户端实现，底层基于WebSocket通讯协议。这里用于前端实现WebSocket通讯。官网地址：<a title="https://github.com/jmesnil/stomp-websocket" href="https://github.com/jmesnil/stomp-websocket" target="_blank">https://github.com/jmesnil/stomp-websocket</a></p>
<p><strong>Lezhima.Rest：</strong>是一个基于ASP.NET Core2的Web Api后端程序，用来模拟向前端发送指令。</p>
<p><strong>Lezhima.Site：</strong>是一个纯前端技术的前端程序，用来模拟前端实时接收后台的指令。</p>
<p>&nbsp;</p>
<p><strong><span>实现</span></strong></p>
<p>如上面所述，我们已经清楚了整个实现思路，那么下面就来看看具体的代码实现吧。</p>
<p>1、首先来看看Lezhima.Rest的MQ生产者代码，如下：</p>
<div><div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div>
<pre><span>  1</span> <span>/// &lt;summary&gt;</span>
<span>  2</span> <span>/// MQ生产者，采用topic模式推送指定内容</span>
<span>  3</span> <span>/// &lt;/summary&gt;</span>
<span>  4</span> <span>/// &lt;param name="objText"&gt;&lt;/param&gt;</span>
<span>  5</span> <span>public</span> <span>static</span> <span>void</span> PushMessage(<span>string</span> objText)
<span>  6</span> {
<span>  7</span>     <span>//创建MQ连接工厂</span>
<span>  8</span>     var factory = <span>new</span> ConnectionFactory()
<span>  9</span>     {
<span> 10</span>         HostName = "<span>localhost</span>",
<span> 11</span>         Port = 5672,
<span> 12</span>         UserName = "<span>fans</span>",
<span> 13</span>         Password = "<span>123456</span>"
<span> 14</span>     };
<span> 15</span>     <span>//创建MQ连接</span>
<span> 16</span>     <span>using</span> (var connection = factory.CreateConnection())
<span> 17</span>     <span>using</span> (var channel = connection.CreateModel())
<span> 18</span>     {
<span> 19</span>         <span>//绑定交换器</span>
<span> 20</span>         channel.ExchangeDeclare(exchange: "<span>topic/test</span>", type: "<span>topic</span>");
<span> 21</span>         var body = Encoding.UTF8.GetBytes(objText);
<span> 22</span>         <span>//对指定routingkey发送内容</span>
<span> 23</span>         channel.BasicPublish(exchange: "<span>amq.topic</span>",
<span> 24</span>                             routingKey: "<span>test</span>",
<span> 25</span>                             basicProperties: <span>null</span>,
<span> 26</span>                             body: body);
<span> 27</span>     }
<span> 28</span> }</pre>
<div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div></div>
<p>&nbsp;</p>
<p>2、Lezhima.Site的前端代码，如下：</p>
<div><div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div>
<pre><span>  1</span> &lt;!DOCTYPE html&gt;
<span>  2</span> &lt;html&gt;
<span>  3</span> &lt;head&gt;
<span>  4</span>     &lt;meta charset="<span>utf-8</span>"&gt;
<span>  5</span>     &lt;link href="<span>main.css</span>" rel="<span>stylesheet</span>" type="<span>text/css</span>" /&gt;
<span>  6</span>     &lt;script src="<span>Script/jquery.js</span>"&gt;&lt;/script&gt;
<span>  7</span>     &lt;script src="<span>stomp.js</span>"&gt;&lt;/script&gt;
<span>  8</span>     &lt;style&gt;
<span>  9</span> 
<span> 10</span>         .box {
<span> 11</span>             width: 440px;
<span> 12</span>             <span>float</span>: left;
<span> 13</span>             margin: 0 20px 0 20px;
<span> 14</span>         }
<span> 15</span>         .box div, .box input {
<span> 16</span>             border: 1px solid;
<span> 17</span>             -moz-border-radius: 4px;
<span> 18</span>             border-radius: 4px;
<span> 19</span>             width: 100%;
<span> 20</span>             padding: 5px;
<span> 21</span>             margin: 3px 0 10px 0;
<span> 22</span>         }
<span> 23</span> 
<span> 24</span>         .box div {
<span> 25</span>             border-color: grey;
<span> 26</span>             height: 300px;
<span> 27</span>             overflow: auto;
<span> 28</span>         }
<span> 29</span> 
<span> 30</span>         div code {
<span> 31</span>             display: block;
<span> 32</span>         }
<span> 33</span> 
<span> 34</span>         #first div code {
<span> 35</span>             -moz-border-radius: 2px;
<span> 36</span>             border-radius: 2px;
<span> 37</span>             border: 1px solid #eee;
<span> 38</span>             margin-bottom: 5px;
<span> 39</span>         }
<span> 40</span>     &lt;/style&gt;
<span> 41</span> &lt;/head&gt;
<span> 42</span> &lt;body lang="<span>en</span>"&gt;
<span> 43</span>     &lt;div id="<span>first</span>" <span>class</span>="<span>box</span>"&gt;
<span> 44</span>         &lt;h2&gt;接收来自后端的消息&lt;/h2&gt;
<span> 45</span>         &lt;div&gt;&lt;/div&gt;
<span> 46</span>     &lt;/div&gt;
<span> 47</span>     &lt;script&gt;
<span> 48</span>         <span>var</span> has_had_focus = <span>false</span>;
<span> 49</span>         <span>//封装个接收呈现方法</span>
<span> 50</span>         <span>var</span> pipe = <span>function</span> (el_name) {
<span> 51</span>             <span>var</span> div = $(el_name + '' div'');
<span> 52</span>             <span>var</span> <span>print</span> = <span>function</span> (m) {
<span> 53</span>                 div.append($("<span>&lt;code&gt;</span>").text(''后端的指令：''+ m));
<span> 54</span>                 div.scrollTop(div.scrollTop() + 10000);
<span> 55</span>             };
<span> 56</span>             <span>return</span> <span>print</span>;
<span> 57</span>         };
<span> 58</span> 
<span> 59</span>         <span>//RabbitMQ的服务地址</span>
<span> 60</span>         <span>var</span> mqUrl = "<span>ws://localhost:15674/ws</span>";
<span> 61</span>         <span>//声明个Stompjs客户端</span>
<span> 62</span>         <span>var</span> client = Stomp.client(mqUrl);
<span> 63</span> 
<span> 64</span>         <span>var</span> print_first = pipe(''#first'', <span>function</span> (data) {
<span> 65</span>             client.send(''/topic/test'', { "<span>content-type</span>": "<span>text/plain</span>" }, data);
<span> 66</span>         });
<span> 67</span> 
<span> 68</span>         <span>//监听连接事件</span>
<span> 69</span>         <span>var</span> on_connect = <span>function</span> (x) {
<span> 70</span>             id = client.subscribe("<span>/topic/test</span>", <span>function</span> (d) {
<span> 71</span>                 print_first(d.body);
<span> 72</span>             });
<span> 73</span>         };
<span> 74</span>         <span>var</span> on_error = <span>function</span> () {
<span> 75</span>             console.log(''error'');
<span> 76</span>         };
<span> 77</span>         <span>//连接MQ</span>
<span> 78</span>         client.connect(''fans'', ''123456'', on_connect, on_error, ''/'');
<span> 79</span> 
<span> 80</span>     &lt;/script&gt;
<span> 81</span> &lt;/body&gt;
<span> 82</span> &lt;/html&gt;
<span> 83</span> </pre>
<div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div></div>
<p>&nbsp;</p>
<p>3、分别运行“Lezhima.Rest”与“Lezhima.Site”程序后，效果是这个样子的，如下：</p>
<p><a href="https://img2018.cnblogs.com/blog/135036/201811/135036-20181124154203326-1357622539.jpg"><img title="1543044548(1)" src="https://img2018.cnblogs.com/blog/135036/201811/135036-20181124154203749-1920630252.jpg" alt="1543044548(1)" width="572" height="236" border="0"></a></p>
<p>&nbsp;</p>
<p><strong><span>总结</span></strong></p>
<p>1、借助RabbitMQ实现前后端通讯功能时，必需先安装RabbitMQ插件stomp，通过该插件可使RabbitMQ支持WebSocket通讯能力。而我们的后端开发人员只需通过“生产者”方法按需向MQ发送数据即可，MQ将根据routingKey广播给所有客户端（消费者）。</p>
<p>2、前端借助stomp.js可以简便的实现与RabbitMQ通讯，并绑定相应的routingKey后承担MQ消费者的能力，以达到前后端即时推送的效果。</p>
<p>&nbsp;</p>
<p><strong><span>声明</span></strong></p>
<p>本文为作者原创，转载请备注出处与保留原文地址，谢谢。如文章能给您带来帮助，请点下推荐或关注，感谢您的支持！</p></div></div>

', 0, CAST(N'2019-05-18T13:19:31.377' AS DateTime), CAST(N'2019-05-30T09:08:58.140' AS DateTime))
INSERT [dbo].[MC_Ware] ([WareId], [CompanyId], [OrganizaId], [CategoryId], [CreateUserId], [Name], [Type], [Duration], [Url], [Context], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'1911ec6d-f356-4e28-a685-fcffcb202b28', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'2d70bcc6-10eb-465f-b4d2-81f24e245c52', N'899e4640-1735-4888-a071-c81ae44233ac', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', N'图文课件演示2', 1, 4, NULL, N'<p>
</p><h1>
			<a id="cb_post_title_url" href="https://www.cnblogs.com/Andre/p/9884051.html">ASP.NET Core2读写InfluxDB时序数据库</a>
		</h1>
		
		<div>
			<div id="cnblogs_post_body"><p>在我们很多应用中会遇到有一种基于一系列时间的数据需要处理，通过时间的顺序可以将这些数据点连成线，再通过数据统计后可以做成多纬度的报表，也可通过机器学习来实现数据的预测告警。而时序数据库就是用于存放管理这种有着时间顺序数据的，时序数据库一般都支持时序数据的快速写入、持久化、多纬度的聚合查询等基本功能。</p>
<p>&nbsp;</p>
<p><strong><span>InfluxDB简介</span></strong></p>
<p>InfluxDB是一个基于时间序列数据而开发的高性能数据存储平台，它可以对时序数据进行高吞吐量的摄取、压缩和实时查询。InfluxDB是用Go语言编写的，它会编译成一个没有外部依赖的二进制文件来运行，支持Java、JavaScript、c#等语言。InfluxDB支持类似SQL的查询语言，同时还支持正则表达式、算术表达式和时间序列特定函数以加速数据的处理效率。如下是跟InfluxDB相关的网址：</p>
<p>InfluxDB官网：<a title="https://www.influxdata.com/" href="https://www.influxdata.com/" target="_blank">https://www.influxdata.com/</a></p>
<p>InfluxDB官方文档：<a href="https://docs.influxdata.com/influxdb/" target="_blank">https://docs.influxdata.com/influxdb/</a></p>
<p>InfluxDB官方下载：<a title="https://portal.influxdata.com/downloads" href="https://portal.influxdata.com/downloads" target="_blank">https://portal.influxdata.com/downloads</a></p>
<p>InfluxDB客户端工具下载：<a title="https://docs.influxdata.com/influxdb/v1.6/tools/api_client_libraries/" href="https://docs.influxdata.com/influxdb/v1.6/tools/api_client_libraries/" target="_blank">https://docs.influxdata.com/influxdb/v1.6/tools/api_client_libraries/</a></p>
<p>&nbsp;</p>
<p><strong><span>InfluxDB操作</span></strong></p>
<p>这里将会简单的介绍下如何操作InfluxDB，通过这些操作基本也能满足工作上的需要了。操作InfluxDB可以通过命令行工具，也可借助开源的客户端工具，我这里使用的是一款名叫“InfluxDBStudio”基于C#编写的开源工具。常用操作的代码如下：</p>
<div><div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div>
<pre><span>  1</span> #显示用户
<span>  2</span> show users
<span>  3</span> 
<span>  4</span> #创建用户
<span>  5</span> create <span>user</span> "<span>username</span>" with password ''password''
<span>  6</span> 
<span>  7</span> #创建管理员权限用户
<span>  8</span> create <span>user</span> "<span>username</span>" with password ''password'' with all privileges
<span>  9</span> 
<span> 10</span> #删除用户
<span> 11</span> drop <span>user</span> "<span>username</span>"
<span> 12</span> 
<span> 13</span> #创建数据库
<span> 14</span> create database "<span>db_name</span>"
<span> 15</span> 
<span> 16</span> #显示所有的数据库
<span> 17</span> show databases
<span> 18</span> 
<span> 19</span> #删除数据库
<span> 20</span> drop database "<span>db_name</span>"
<span> 21</span> 
<span> 22</span> #使用数据库
<span> 23</span> use db_name
<span> 24</span> 
<span> 25</span> #显示该数据库中所有的表
<span> 26</span> show measurements
<span> 27</span> 
<span> 28</span> #创建表，直接在插入数据的时候指定表名，其中test为表名
<span> 29</span> insert test,host=127.0.0.1,monitor_name=test <span>count</span>=1
<span> 30</span> 
<span> 31</span> #删除表
<span> 32</span> drop measurement "<span>measurement_name</span>"
<span> 33</span> 
<span> 34</span> #查询数据
<span> 35</span> select * from test order by <span>time</span> desc
<span> 36</span> 
<span> 37</span> #查看当前数据库的数据保存策略（Retention Policies）
<span> 38</span> show retention policies on "<span>db_name</span>"
<span> 39</span> 
<span> 40</span> #创建新的数据保存策略
<span> 41</span> #rp_name：策略名
<span> 42</span> #db_name：具体的数据库名；
<span> 43</span> #3w：保存3周，3周之前的数据将被删除，influxdb具有各种事件参数，比如：h（小时），d（天），w（星期）
<span> 44</span> #replication 1：副本个数，一般为1就可以了
<span> 45</span> #default：设置为默认策略
<span> 46</span> create retention policy "<span>rp_name</span>" on "<span>db_name</span>" duration 3w replication 1 default
<span> 47</span> 
<span> 48</span> #修改数据保存策略
<span> 49</span> alter retention policy "<span>rp_name</span>" on "<span>db_name</span>" duration 30d default
<span> 50</span> 
<span> 51</span> #删除数据保存策略
<span> 52</span> drop retention policy "<span>rp_name</span>"
<span> 53</span> 
<span> 54</span> #查看数据库的连续查询（Continous Queries）
<span> 55</span> show continuous queries
<span> 56</span> 
<span> 57</span> #创建新的连续查询（Continous Queries）
<span> 58</span> #cq_name：连续查询名字
<span> 59</span> #db_name：数据库名字
<span> 60</span> #sum(<span>count</span>)：计算总和
<span> 61</span> #table_name：当前表名
<span> 62</span> #new_table_name：存新的数据的表名
<span> 63</span> #30m：时间间隔为30分钟
<span> 64</span> create continous query cq_name on db_name begin select sum(<span>count</span>) into new_table_name from table_name <span>group</span> by <span>time</span>(30m) <span>end</span>
<span> 65</span> 
<span> 66</span> #删除连续查询
<span> 67</span> drop continous query cp_name on db_name
<span> 68</span> </pre>
<div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div></div>
<p>&nbsp;</p>
<p><strong><span>实现</span></strong></p>
<p>通过上述的介绍与操作我们已基本熟悉了InfluxDB数据库，那么接下来咱们就一起来看看在ASP.NET 
Core2程序中如何来读写操作InfluxDB数据库吧。而这里我们借助一个名为“InfluxData.Net”的第三方库来与InfluxDB交互通讯，基于“InfluxData.Net”库可以使得我们很简单的完成数据库的读写操作。在ASP.NET
 Core2项目中通过Nuget管理器引用“InfluxData.Net”类库后，敲入实现代码如下：</p>
<div><div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div>
<pre><span>  1</span> <span>using</span> System;
<span>  2</span> <span>using</span> System.Collections.Generic;
<span>  3</span> <span>using</span> System.Linq;
<span>  4</span> <span>using</span> System.Threading.Tasks;
<span>  5</span> <span>using</span> InfluxData.Net.Common.Enums;
<span>  6</span> <span>using</span> InfluxData.Net.InfluxDb;
<span>  7</span> <span>using</span> InfluxData.Net.InfluxDb.Models;
<span>  8</span> <span>using</span> Microsoft.AspNetCore.Mvc;
<span>  9</span> 
<span> 10</span> <span>namespace</span> WebApplication1.Controllers
<span> 11</span> {
<span> 12</span>     <span>public</span> <span>class</span> InfoController : Controller
<span> 13</span>     {
<span> 14</span>         <span>//声明InfluxDbClient</span>
<span> 15</span>         <span>private</span> InfluxDbClient clientDb;
<span> 16</span> 
<span> 17</span>         <span>public</span> InfoController()
<span> 18</span>         {
<span> 19</span>             <span>//连接InfluxDb的API地址、账号、密码</span>
<span> 20</span>             var infuxUrl = "<span>http://localhost:8086/</span>";
<span> 21</span>             var infuxUser = "<span>admin</span>";
<span> 22</span>             var infuxPwd = "<span>admin</span>";
<span> 23</span> 
<span> 24</span>             <span>//创建InfluxDbClient实例</span>
<span> 25</span>             clientDb = <span>new</span> InfluxDbClient(infuxUrl, infuxUser, infuxPwd, InfluxDbVersion.Latest);
<span> 26</span>         }
<span> 27</span> 
<span> 28</span> 
<span> 29</span>         <span>/// &lt;summary&gt;</span>
<span> 30</span>         <span>/// 从InfluxDB中读取数据</span>
<span> 31</span>         <span>/// &lt;/summary&gt;</span>
<span> 32</span>         <span>public</span> async <span>void</span> GetData()
<span> 33</span>         {
<span> 34</span>             <span>//传入查询命令，支持多条</span>
<span> 35</span>             var queries = <span>new</span>[]
<span> 36</span>             {
<span> 37</span>                 "<span> SELECT * FROM Reading WHERE time&gt; now() -  24h </span>"
<span> 38</span>             };
<span> 39</span>             var dbName = "<span>code-hub</span>";
<span> 40</span> 
<span> 41</span>             <span>//从指定库中查询数据</span>
<span> 42</span>             var response = await clientDb.Client.QueryAsync(queries, dbName);
<span> 43</span>             <span>//得到Serie集合对象（返回执行多个查询的结果）</span>
<span> 44</span>             var series = response.ToList();
<span> 45</span>             <span>//取出第一条命令的查询结果，是一个集合</span>
<span> 46</span>             var list = series[0].Values;
<span> 47</span>             <span>//从集合中取出第一条数据</span>
<span> 48</span>             var info_model = list.FirstOrDefault();
<span> 49</span>         }
<span> 50</span> 
<span> 51</span> 
<span> 52</span> 
<span> 53</span>         <span>/// &lt;summary&gt;</span>
<span> 54</span>         <span>/// 往InfluxDB中写入数据</span>
<span> 55</span>         <span>/// &lt;/summary&gt;</span>
<span> 56</span>         <span>public</span> async <span>void</span> AddData()
<span> 57</span>         {
<span> 58</span>             <span>//基于InfluxData.Net.InfluxDb.Models.Point实体准备数据</span>
<span> 59</span>             var point_model = <span>new</span> Point()
<span> 60</span>             {
<span> 61</span>                 Name = "<span>Reading</span>",<span>//表名</span>
<span> 62</span>                 Tags = <span>new</span> Dictionary&lt;<span>string</span>, <span>object</span>&gt;()
<span> 63</span>                 {
<span> 64</span>                     { "<span>Id</span>",  158}
<span> 65</span>                 },
<span> 66</span>                 Fields = <span>new</span> Dictionary&lt;<span>string</span>, <span>object</span>&gt;()
<span> 67</span>                 {
<span> 68</span>                     { "<span>Val</span>", "<span>webInfo</span>" }
<span> 69</span>                 },
<span> 70</span>                 Timestamp = DateTime.UtcNow
<span> 71</span>             };
<span> 72</span>             var dbName = "<span>code-hub</span>";
<span> 73</span> 
<span> 74</span>             <span>//从指定库中写入数据，支持传入多个对象的集合</span>
<span> 75</span>             var response = await clientDb.Client.WriteAsync(point_model, dbName);
<span> 76</span>         }
<span> 77</span>     }
<span> 78</span> }</pre>
<div><span><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div></div>
<p>&nbsp;</p>
<p><strong><span>总结</span></strong></p>
<p>1、InfluxDB是个专业的时序数据库，通过时序库可帮助我们更高效的处理应用中的时序数据。</p>
<p>2、使用InfluxDB库时需先了解该库的一些特色功能，如数据保存策略、连续查询等。</p>
<p>3、通过“InfluxData.Net”类库可快速简便的帮助我们在ASP.NET Core2程序中实现对InfluxDB的读写操作。</p>
<p>&nbsp;</p>
<p><strong><span>声明</span></strong></p>
<p>本文为作者原创，转载请备注出处与保留原文地址，谢谢。如文章能给您带来帮助，请点下推荐或关注，感谢您的支持！</p></div></div>

', 0, CAST(N'2019-05-18T16:45:51.253' AS DateTime), CAST(N'2019-05-30T09:13:49.337' AS DateTime))
INSERT [dbo].[MC_WareRecord] ([WareRecordId], [CompanyId], [CourseRecordId], [ChapterId], [ChapterWareId], [UserId], [Duration], [Count], [State], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'6407f27d-a490-4604-a1ed-965538651bd2', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'7788fe0b-d5ec-4677-bd7e-8ba84c49abb9', N'7eccea54-1453-4674-bd25-38213f3f716a', N'2970811f-1521-4e3d-90f5-b991dff8c96e', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', 1, 0, 0, 0, CAST(N'2019-06-16T13:09:26.580' AS DateTime), CAST(N'2019-06-16T13:09:26.580' AS DateTime))
INSERT [dbo].[MC_WareRecord] ([WareRecordId], [CompanyId], [CourseRecordId], [ChapterId], [ChapterWareId], [UserId], [Duration], [Count], [State], [IsDelete], [CreateTime], [UpdateTime]) VALUES (N'787d3a91-db77-446b-80cc-e3ceacf23641', N'2013a73a-2ed0-4440-afe5-2b264d8e3c79', N'7788fe0b-d5ec-4677-bd7e-8ba84c49abb9', N'31bb8e45-aaa7-45b4-a0f5-99f22aa12e86', N'1e6d60ee-bc0e-4099-8cee-4c94d5bedc15', N'57cb0b6d-4dbf-4046-a187-e78955bdf979', 8, 0, 0, 0, CAST(N'2019-05-31T09:31:50.410' AS DateTime), CAST(N'2019-05-31T13:03:44.500' AS DateTime))

USE [master]
GO
ALTER DATABASE [Miidy_Cloud_Train] SET  READ_WRITE 
GO
