Commit 7b31c066 authored by 黄奎's avatar 黄奎

api修改

parent 7acb0792
using EduSpider.Model.Entity; using EduSpider.Model.Entity;
using EduSpider.Model.Query;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -19,6 +20,23 @@ namespace EduSpider.Repository ...@@ -19,6 +20,23 @@ namespace EduSpider.Repository
/// </summary> /// </summary>
/// <param name="courses"></param> /// <param name="courses"></param>
/// <returns></returns> /// <returns></returns>
public bool BatchSetCourse(List<RB_Course> courses); public bool BatchSetCourseRepository(List<RB_Course> courses);
/// <summary>
/// 获取课程分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCoursePageRepository(int pageIndex, int pageSize, out long rowsCount, CourseQuery query);
/// <summary>
/// 获取课程列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCourseListRepository(CourseQuery query);
} }
} }
using System; using EduSpider.Model.Entity;
using EduSpider.Model.Query;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -12,6 +14,21 @@ namespace EduSpider.IServices ...@@ -12,6 +14,21 @@ namespace EduSpider.IServices
/// </summary> /// </summary>
public interface ICourseService : IDependency public interface ICourseService : IDependency
{ {
/// <summary>
/// 获取课程分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCoursePage(int pageIndex, int pageSize, out long rowsCount, CourseQuery query);
/// <summary>
/// 获取课程列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCourseList(CourseQuery query);
} }
} }
using EduSpider.Model.Entity; using EduSpider.Model.Entity;
using EduSpider.Model.Query;
using EduSpider.Repository.Base; using EduSpider.Repository.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using VTX.FW.DB.Dapper;
namespace EduSpider.Repository namespace EduSpider.Repository
{ {
...@@ -18,11 +20,72 @@ namespace EduSpider.Repository ...@@ -18,11 +20,72 @@ namespace EduSpider.Repository
/// </summary> /// </summary>
/// <param name="courses"></param> /// <param name="courses"></param>
/// <returns></returns> /// <returns></returns>
public bool BatchSetCourse(List<RB_Course> courses) public bool BatchSetCourseRepository(List<RB_Course> courses)
{ {
bool flag; bool flag;
flag = base.BatchInsert(courses, isReplace: true); flag = base.BatchInsert(courses, isReplace: true);
return flag; return flag;
} }
/// <summary>
/// 获取课程列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCourseListRepository(CourseQuery query)
{
var parameters = new DynamicParameters();
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*
FROM RB_Course AS A
WHERE 1=1
");
if (query != null)
{
if (!string.IsNullOrWhiteSpace(query.courseName))
{
builder.AppendFormat(" AND A.{0} LIKE @courseName ", nameof(RB_Course.courseName));
parameters.Add("courseName", "%" + query.courseName.Trim() + "%");
}
if (query.courseId > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Course.courseId), query.courseId);
}
}
return base.Get<RB_Course>(builder.ToString(), parameters).ToList();
}
/// <summary>
/// 获取课程分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCoursePageRepository(int pageIndex, int pageSize, out long rowsCount, CourseQuery query)
{
var parameters = new DynamicParameters();
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*
FROM RB_Course AS A
WHERE 1=1
");
if (query != null)
{
if (!string.IsNullOrWhiteSpace(query.courseName))
{
builder.AppendFormat(" AND A.{0} LIKE @courseName ", nameof(RB_Course.courseName));
parameters.Add("courseName", "%" + query.courseName.Trim() + "%");
}
if (query.courseId > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Course.courseId), query.courseId);
}
}
return base.GetPage<RB_Course>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
}
} }
} }
 
using EduSpider.IServices; using EduSpider.IServices;
using EduSpider.Model.Entity;
using EduSpider.Model.Query;
using EduSpider.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using VTX.FW.Attr;
namespace EduSpider.Services namespace EduSpider.Services
{ {
...@@ -13,6 +17,33 @@ namespace EduSpider.Services ...@@ -13,6 +17,33 @@ namespace EduSpider.Services
/// </summary> /// </summary>
public class CourseService : ICourseService public class CourseService : ICourseService
{ {
/// <summary>
/// 课程仓储接口
/// </summary>
[Autowired]
public ICourseRepository CourseRepository { get; set; }
/// <summary>
/// 获取课程列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCourseList(CourseQuery query)
{
return CourseRepository.GetCourseListRepository(query);
}
/// <summary>
/// 获取课程分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Course> GetCoursePage(int pageIndex, int pageSize, out long rowsCount, CourseQuery query)
{
return CourseRepository.GetCoursePageRepository(pageIndex, pageSize, out rowsCount, query);
}
} }
} }
...@@ -13,6 +13,11 @@ namespace EduSpider.WebApi.Controllers ...@@ -13,6 +13,11 @@ namespace EduSpider.WebApi.Controllers
public class CourseController : BaseController public class CourseController : BaseController
{ {
/// <summary>
/// 课程仓储接口
/// </summary>
[Autowired]
public ICourseService CourseService { get; set; }
/// <summary> /// <summary>
/// 获取课程列表 /// 获取课程列表
...@@ -23,8 +28,8 @@ namespace EduSpider.WebApi.Controllers ...@@ -23,8 +28,8 @@ namespace EduSpider.WebApi.Controllers
public ApiResult GetCoursePage() public ApiResult GetCoursePage()
{ {
var list = CourseService.GetCoursePage(1, 1000, out _, new Model.Query.CourseQuery());
return ApiResult.Success(data: "", message: "成功!"); return ApiResult.Success(data: list, message: "成功!");
} }
} }
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SqlSugarCore" Version="5.0.8.3" /> <PackageReference Include="SqlSugarCore" Version="5.0.8.3" />
<PackageReference Include="StackExchange.Redis" Version="2.0.601" /> <PackageReference Include="StackExchange.Redis" Version="2.0.601" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="VTX.FW" Version="1.0.0" /> <PackageReference Include="VTX.FW" Version="1.0.0" />
</ItemGroup> </ItemGroup>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
], ],
//ַ //ַ
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "server=192.168.10.214;user id=reborn;password=Reborn@2018;database=reborn_user;CharSet=utf8mb4; Convert Zero Datetime=true; ", "DefaultConnection": "server=192.168.10.214;user id=reborn;password=Reborn@2018;database=reborn_think;CharSet=utf8mb4; Convert Zero Datetime=true; ",
"DefaultConnectionPName": "MySql.Data.MySqlClient" "DefaultConnectionPName": "MySql.Data.MySqlClient"
} }
} }
...@@ -45,7 +45,7 @@ namespace EduSpider.Spiders.ClassInRule ...@@ -45,7 +45,7 @@ namespace EduSpider.Spiders.ClassInRule
var tempList = ParseJson(dataObj.GetString("courseList")); var tempList = ParseJson(dataObj.GetString("courseList"));
if (tempList != null && tempList.Count > 0) if (tempList != null && tempList.Count > 0)
{ {
courseRepository.BatchSetCourse(tempList); courseRepository.BatchSetCourseRepository(tempList);
totalCount += tempList.Count(); totalCount += tempList.Count();
Console.WriteLine(string.Format("第{0}次,导入完成{1}条.", pageCount,totalCount)); Console.WriteLine(string.Format("第{0}次,导入完成{1}条.", pageCount,totalCount));
} }
...@@ -78,7 +78,7 @@ namespace EduSpider.Spiders.ClassInRule ...@@ -78,7 +78,7 @@ namespace EduSpider.Spiders.ClassInRule
var subtempList = ParseJson(sub_dataObj.GetString("courseList")); var subtempList = ParseJson(sub_dataObj.GetString("courseList"));
if (subtempList != null && subtempList.Count > 0) if (subtempList != null && subtempList.Count > 0)
{ {
courseRepository.BatchSetCourse(subtempList); courseRepository.BatchSetCourseRepository(subtempList);
totalCount += subtempList.Count(); totalCount += subtempList.Count();
Console.WriteLine(string.Format("第{0}次,导入完成{1}条.", i, totalCount)); Console.WriteLine(string.Format("第{0}次,导入完成{1}条.", i, totalCount));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment