Skip to content

Commit

Permalink
t4自己自动生成仓储及仓储接口
Browse files Browse the repository at this point in the history
  • Loading branch information
liningit committed Jun 14, 2019
1 parent 0022c21 commit 74e7982
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 34 deletions.
17 changes: 9 additions & 8 deletions src/LnskyDB.Demo/Controllers/ProductSaleByDayController.cs
Expand Up @@ -5,6 +5,7 @@
using Common.Tool;
using LnskyDB.Demo.Entity.Purify;
using LnskyDB.Demo.Repository;
using LnskyDB.Demo.Repository.Purify;
using Microsoft.AspNetCore.Mvc;

namespace LnskyDB.Demo.Controllers
Expand All @@ -28,7 +29,7 @@ private static IRepository<ProductSaleByDayEntity> GetRepository()
return new ProductSaleByDayRepository();
}
}
// GET http://localhost:53277/ProductSaleByDay/Get?sysNo=2d0c6662-9670-4c52-a4e1-02c37681e7e9
// GET http://localhost:53277/ProductSaleByDay/Get

[HttpGet]
public ActionResult<ProductSaleByDayEntity> Get(Guid sysNo)
Expand All @@ -47,7 +48,7 @@ public ActionResult<ProductSaleByDayEntity> Get(Guid sysNo)
return entity;
}

// GET http://localhost:53277/ProductSaleByDay/GetList?shopName=1&stTime=2019-01-01&endTime=2019-09-05
// GET http://localhost:53277/ProductSaleByDay/GetList
[HttpGet]
public ActionResult<List<ProductSaleByDayEntity>> GetList()
{
Expand All @@ -67,7 +68,7 @@ public ActionResult<List<ProductSaleByDayEntity>> GetList()

return lst;
}
//GET http://localhost:53277/ProductSaleByDay/GetPaging?shopName=1&stTime=2019-01-01&endTime=2019-03-11&page=2&pageSize=3
//GET http://localhost:53277/ProductSaleByDay/GetPaging
[HttpGet]
public ActionResult<Paging<ProductSaleByDayEntity>> GetPaging()
{
Expand All @@ -88,7 +89,7 @@ public ActionResult<Paging<ProductSaleByDayEntity>> GetPaging()
return paging;
}

// Get http://localhost:53277/ProductSaleByDay/Add?shopName=增加2&StatisticalDate=2019-01-01&dataSource=测试用
// Get http://localhost:53277/ProductSaleByDay/Add
[HttpGet]
public void Add()
{
Expand All @@ -108,7 +109,7 @@ public void Add()
//如果新增主键是自增列会自动赋值自增列值到主键
repository.Add(addEntity);
}
//http://localhost:53277/ProductSaleByDay/Update?sysNo=650BC09C-2B9C-467B-A457-8B4853CC1F0F&shopName=修改&statisticalDate=2019-01-01&dataSource=修改测试用
//http://localhost:53277/ProductSaleByDay/Update
[HttpGet]
public bool Update()
{
Expand All @@ -125,7 +126,7 @@ public bool Update()
//根据主键更新其他字段
return repository.Update(updateEntity);
}
//http://localhost:53277/ProductSaleByDay/UpdateWhere?shopName=批量修改&shuffledTempDate=2019-02-02&dataSource=更新
//http://localhost:53277/ProductSaleByDay/UpdateWhere
[HttpGet]
public int UpdateWhere()
{
Expand All @@ -141,7 +142,7 @@ public int UpdateWhere()
//注意如果是更新用的是实体类的DBModel_ShuffledTempDate Query中的无效
return repository.Update(updateEntity, where);
}
// http://localhost:53277/ProductSaleByDay/Delete?sysNo=5119AC4F-FA2F-470F-8144-0069B45E15CF&statisticalDate=2019-01-01
// http://localhost:53277/ProductSaleByDay/Delete
[HttpGet]
public bool Delete()
{
Expand All @@ -155,7 +156,7 @@ public bool Delete()
return repository.Delete(deleteEntity);
}

//http://localhost:53277/ProductSaleByDay/DleteWhere?shopName=批量修改&shuffledTempDate=2019-02-02&dataSource=新+更
//http://localhost:53277/ProductSaleByDay/DleteWhere
[HttpGet]
public int DleteWhere(string shopName, DateTime shuffledTempDate, string dataSource)
{
Expand Down
5 changes: 5 additions & 0 deletions src/LnskyDB.Demo/LnskyDB.Demo.csproj
Expand Up @@ -33,4 +33,9 @@
</Compile>
</ItemGroup>

<ItemGroup>
<Folder Include="RepositoryInterface\" />
<Folder Include="Repository\" />
</ItemGroup>

</Project>
13 changes: 0 additions & 13 deletions src/LnskyDB.Demo/Repository/IProductSaleByDayRepository.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/LnskyDB.Demo/Repository/ProductSaleByDayRepository.cs

This file was deleted.

11 changes: 11 additions & 0 deletions src/LnskyDB.Demo/Repository/Purify/ProductSaleByDayRepository.cs
@@ -0,0 +1,11 @@
using LnskyDB;
using LnskyDB.Demo.Entity.Purify;
using LnskyDB.Demo.RepositoryInterface.Purify;

namespace LnskyDB.Demo.Repository.Purify
{
public class ProductSaleByDayRepository : Repository<ProductSaleByDayEntity>, IProductSaleByDayRepository
{
}
}

@@ -0,0 +1,9 @@
using LnskyDB;
using LnskyDB.Demo.Entity.Purify;

namespace LnskyDB.Demo.RepositoryInterface.Purify
{
public interface IProductSaleByDayRepository : IRepository<ProductSaleByDayEntity>
{
}
}
30 changes: 29 additions & 1 deletion src/LnskyDB.Demo/T4/Entity.tt
Expand Up @@ -85,7 +85,35 @@ namespace LnskyDB.Demo.Entity.<#=tableInfo.TablePre #>
}
}
<#
manager.EndBlock();
manager.EndBlock();
manager.StartBlock("LnskyDB.Demo\\RepositoryInterface\\"+tableInfo.TablePre+"\\I"+tableInfo.TableName+"Repository.cs",false);
#>
using LnskyDB;
using LnskyDB.Demo.Entity.<#=tableInfo.TablePre #>;

namespace LnskyDB.Demo.RepositoryInterface.<#=tableInfo.TablePre #>
{
public interface I<#=tableInfo.TableName #>Repository : IRepository<<#=tableInfo.TableName #>Entity>
{
}
}
<#
manager.EndBlock();
manager.StartBlock("LnskyDB.Demo\\Repository\\"+tableInfo.TablePre+"\\"+tableInfo.TableName+"Repository.cs",false);
#>
using LnskyDB;
using LnskyDB.Demo.Entity.<#=tableInfo.TablePre #>;
using LnskyDB.Demo.RepositoryInterface.<#=tableInfo.TablePre #>;

namespace LnskyDB.Demo.Repository.<#=tableInfo.TablePre #>
{
public class <#=tableInfo.TableName #>Repository : Repository<<#=tableInfo.TableName #>Entity>, I<#=tableInfo.TableName #>Repository
{
}
}

<#
manager.EndBlock();
#>
<# }
manager.Process();
Expand Down

0 comments on commit 74e7982

Please sign in to comment.