parent
4810d7f93a
commit
20e069a2a8
@ -0,0 +1,14 @@
|
||||
using Entity.DbModel.Station;
|
||||
using HybirdFrameworkCore.Autofac.Attribute;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Repository.Station;
|
||||
|
||||
[Scope("SingleInstance")]
|
||||
public class BatteryGroupRepository:BaseRepository<BatteryGroup>
|
||||
{
|
||||
|
||||
public BatteryGroupRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using Entity.DbModel.Station;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Repository.Station;
|
||||
using SqlSugar;
|
||||
|
||||
namespace WebStarter.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class GenController : ControllerBase
|
||||
{
|
||||
private readonly ISqlSugarClient _sqlSugarClient;
|
||||
private readonly BatteryGroupRepository _batteryGroupRepository;
|
||||
|
||||
public GenController(ISqlSugarClient sqlSugarClient, BatteryGroupRepository batteryGroupRepository)
|
||||
{
|
||||
_sqlSugarClient = sqlSugarClient;
|
||||
_batteryGroupRepository = batteryGroupRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("gen/t/{id}")]
|
||||
public void Get(int id)
|
||||
{
|
||||
Console.WriteLine();
|
||||
_sqlSugarClient.DbFirst
|
||||
.IsCreateAttribute() //创建sqlsugar自带特性
|
||||
.FormatFileName(it => ToPascalCase(it)) //格式化文件名(文件名和表名不一样情况)
|
||||
.FormatClassName(it => ToPascalCase(it)) //格式化类名 (类名和表名不一样的情况)
|
||||
.FormatPropertyName(it => ToPascalCase(it)) //格式化属性名 (属性名和字段名不一样情况)
|
||||
.CreateClassFile("D:\\lxw\\work\\pro\\c#\\hn_back_main\\Entity\\DbModel\\Station",
|
||||
"Entity.DbModel.Station");
|
||||
|
||||
|
||||
Console.WriteLine("生成完毕");
|
||||
}
|
||||
|
||||
[HttpGet("test115")]
|
||||
public void Test115()
|
||||
{
|
||||
_batteryGroupRepository.Insert(new List<BatteryGroup>()
|
||||
{
|
||||
new BatteryGroup()
|
||||
{
|
||||
BatteryNo = "1",
|
||||
Group = 1,
|
||||
},
|
||||
new BatteryGroup()
|
||||
{
|
||||
BatteryNo = "2",
|
||||
Group = 2,
|
||||
},
|
||||
});
|
||||
List<BatteryGroup> batteryGroups = _batteryGroupRepository.Query();
|
||||
BatteryGroup batteryGroup = batteryGroups[0];
|
||||
_batteryGroupRepository.Delete(batteryGroup);
|
||||
BatteryGroup batteryGroup1 = batteryGroups[1];
|
||||
batteryGroup1.Group = 3;
|
||||
_batteryGroupRepository.Update(batteryGroup1);
|
||||
|
||||
|
||||
Console.WriteLine("测试完毕");
|
||||
}
|
||||
|
||||
|
||||
static string ToPascalCase(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return input;
|
||||
string[] strings = input.Split("_");
|
||||
string res = "";
|
||||
foreach (var s in strings)
|
||||
{
|
||||
string first = s.First().ToString().ToUpper();
|
||||
string te = first + s.Substring(1);
|
||||
res += te;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in new issue