| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- using Microsoft.AspNetCore.Mvc;
- using Snowflake.Core;
- using SqlSugar;
- using System.Diagnostics;
- using WebApplication1.Models;
- namespace WebApplication1.Controllers
- {
- public class HomeController : Controller
- {
- private readonly ILogger<HomeController> _logger;
- public HomeController(ILogger<HomeController> logger)
- {
- _logger = logger;
- }
- public IActionResult Index()
- {
- //for (int i = 0; i < 5; i++)
- //{
- // var id= IdFactory.NewId();
- //}
- //AutoGenerateLocation();
- //FJ1NorthAutoGenerateLocation();
- //FJSouthAutoGenerateLocation();
- return View();
- }
- public IActionResult Privacy()
- {
- return View();
- }
- [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
- public IActionResult Error()
- {
- return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
- }
- public void AutoGenerateLocation()
- {
- SqlSugarScope Db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
- {
- ConnectionString = "Data Source=10.30.44.50;User ID=bz;Password=Aa123456@;Initial Catalog=WMS_ZT_01HJ",//连接符字串
- DbType = DbType.SqlServer,//数据库类型
- IsAutoCloseConnection = true //不设成true要手动close
- },
- db =>
- {
- db.Aop.OnLogExecuting = (sql, pars) =>
- {
- Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
- //获取原生SQL推荐 5.1.4.63 性能OK
- //UtilMethods.GetNativeSql(sql,pars)
- //获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用
- //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
- };
- });
- var dbBaseWarecellLists = Db.Queryable<BaseWarecell>().ToList();
- var shelfcode = "";
- var list = new List<BaseWarecell>();
- var codes = new List<string>();
- for (int row = 1; row <= 12; row++) //行
- {
- shelfcode = "L";
- //1 2 是R, 3 4 是 L
- if (row == 1 || row == 2 || row == 5 || row == 6 || row == 9 || row == 10)
- {
- shelfcode = "R";
- }
-
- // 23 深度1 , 1 4 5 8 9 12深度2
- int depth = 1;
- if(row==1 || row == 4 || row == 5 || row == 8 || row == 9 || row == 12)
- {
- depth = 2;
- }
- int tunnel = 1;
- if (row > 4 && row <= 8)
- {
- tunnel = 2;
- }
- else if (row > 8)
- {
- tunnel = 3;
- }
- //12行 48列9层
- for (int layer = 1; layer <= 9; layer++) //层
- {
- for (int col = 0; col <=49; col++) //列
- {
- var code = row.ToString().PadLeft(2, '0') + "-" + col.ToString().PadLeft(2, '0') + "-" + layer.ToString().PadLeft(2, '0') + "-" + tunnel + shelfcode + "-" + depth.ToString().PadLeft(2, '0');
- codes.Add(code);
- var name = row.ToString() + "行" + col.ToString() + "列" + layer.ToString() + "层" + tunnel + shelfcode + "货架" + depth + "深度";
- list.Add(new BaseWarecell {
- Id = IdFactory.NewId(),
- WarehouseId = 1668442390064664576,
- WareAreaId = 1669154208777113600,
- IsStop = 0,
- Code =code ,
- Name =name ,
- StateNum = 1,
- TypeNum = 1,
- Size = 1,
- Shelf= tunnel.ToString() + shelfcode,
- WarehouseCode = "hjhouse",
- Row = row,
- Col = col,
- Layer = layer,
- Depth = depth,
- Tunnel = tunnel,
- SCRel = "SRM"+tunnel.ToString().PadLeft(2, '0'),
- ContGrpId = 0,
- ContGrpBarCode ="" ,
- Memo = "",
- AddWho = "admin",
- AddTime = DateTime.Now,
- EditWho = "admin",
- EditTime = DateTime.Now,
- });
- }
- }
- }
- Db.Insertable(list).ExecuteCommand();
- }
- public void FJ1NorthAutoGenerateLocation()
- {
- SqlSugarScope Db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
- {
- ConnectionString = "Data Source=10.30.44.50;User ID=bz;Password=Aa123456@;Initial Catalog=WMS_ZT_01FJ",//连接符字串
- DbType = DbType.SqlServer,//数据库类型
- IsAutoCloseConnection = true //不设成true要手动close
- },
- db =>
- {
- db.Aop.OnLogExecuting = (sql, pars) =>
- {
- Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
- //获取原生SQL推荐 5.1.4.63 性能OK
- //UtilMethods.GetNativeSql(sql,pars)
- //获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用
- //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
- };
- });
- BaseWarehouse BaseWarearea = new BaseWarehouse()
- {
- Id = IdFactory.NewId(),
- IsStop = 0,
- Code = "fj1northhouse",
- Name = "分拣库1北",
- AddTime = DateTime.Now
- ,
- AddWho = "admin",
- EditTime = DateTime.Now,
- EditWho = "admin",
- TypeNum = 1
- };
- var baseWareareaEntity = Db.Insertable(BaseWarearea).ExecuteReturnEntity();
- var dbBaseWarecellLists = Db.Queryable<BaseWarecell>().ToList();
- var shelfcode = "";
- var list = new List<BaseWarecell>();
- var codes = new List<string>();
- for (int row = 1; row <= 2; row++) //行
- {
- //shelfcode = "L";
- ////1 2 是R, 3 4 是 L
- //if (row == 1 || row == 2 || row == 5 || row == 6 || row == 9 || row == 10)
- //{
- // shelfcode = "R";
- //}
- //// 23 深度1 , 1 4 5 8 9 12深度2
- //int depth = 1;
- //if (row == 1 || row == 4 || row == 5 || row == 8 || row == 9 || row == 12)
- //{
- // depth = 2;
- //}
- int tunnel = 1;
- //12行 48列9层
- for (int layer = 1; layer <= 10; layer++) //层
- {
- for (int col = 1; col <= 10; col++) //列
- {
- var code = row.ToString().PadLeft(2, '0') + "-" + col.ToString().PadLeft(2, '0') + "-" + layer.ToString().PadLeft(2, '0') + "-" + tunnel ;
- codes.Add(code);
- var name = row.ToString() + "行" + col.ToString() + "列" + layer.ToString() + "层" ;
- list.Add(new BaseWarecell
- {
- Id = IdFactory.NewId(),
- WarehouseId = baseWareareaEntity.Id,
- WareAreaId = 1669154208777113600,
- IsStop = 0,
- Code = code,
- Name = name,
- StateNum = 1,
- TypeNum = 1,
- Size = 1,
- Shelf = tunnel.ToString() + shelfcode,
- WarehouseCode = "fj1northhouse",
- Row = row,
- Col = col,
- Layer = layer,
- Depth = 1,
- Tunnel = tunnel,
- SCRel = "SRM" + tunnel.ToString().PadLeft(2, '0'),
- ContGrpId = 0,
- ContGrpBarCode = "",
- Memo = "",
- AddWho = "admin",
- AddTime = DateTime.Now,
- EditWho = "admin",
- EditTime = DateTime.Now,
- });
- }
- }
- }
- Db.Insertable(list).ExecuteCommand();
- }
- public void FJSouthAutoGenerateLocation()
- {
- SqlSugarScope Db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
- {
- ConnectionString = "Data Source=10.30.44.50;User ID=bz;Password=Aa123456@;Initial Catalog=WMS_ZT_01FJ",//连接符字串
- DbType = DbType.SqlServer,//数据库类型
- IsAutoCloseConnection = true //不设成true要手动close
- },
- db =>
- {
- db.Aop.OnLogExecuting = (sql, pars) =>
- {
- Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
- //获取原生SQL推荐 5.1.4.63 性能OK
- //UtilMethods.GetNativeSql(sql,pars)
- //获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用
- //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
- };
- });
- BaseWarehouse BaseWarearea= new BaseWarehouse() {
- Id= IdFactory.NewId(),IsStop=0,Code= "fj1southhouse",
- Name="分拣库1南",AddTime=DateTime.Now
- ,AddWho="admin",EditTime=DateTime.Now,EditWho="admin",TypeNum=1 };
- var baseWareareaEntity = Db.Insertable(BaseWarearea).ExecuteReturnEntity();
- var dbBaseWarecellLists = Db.Queryable<BaseWarecell>().ToList();
- var shelfcode = "";
- var list = new List<BaseWarecell>();
- var codes = new List<string>();
- for (int row = 1; row <= 2; row++) //行
- {
- //shelfcode = "L";
- ////1 2 是R, 3 4 是 L
- //if (row == 1 || row == 2 || row == 5 || row == 6 || row == 9 || row == 10)
- //{
- // shelfcode = "R";
- //}
- //// 23 深度1 , 1 4 5 8 9 12深度2
- //int depth = 1;
- //if (row == 1 || row == 4 || row == 5 || row == 8 || row == 9 || row == 12)
- //{
- // depth = 2;
- //}
- int tunnel = 1;
-
- //12行 48列9层
- for (int layer = 1; layer <= 10; layer++) //层
- {
- for (int col = 11; col <= 20; col++) //列
- {
- var code = row.ToString().PadLeft(2, '0') + "-" + col.ToString().PadLeft(2, '0') + "-" + layer.ToString().PadLeft(2, '0') + "-" + tunnel ;
- codes.Add(code);
- var name = row.ToString() + "行" + col.ToString() + "列" + layer.ToString() + "层" ;
- list.Add(new BaseWarecell
- {
- Id = IdFactory.NewId(),
- WarehouseId = baseWareareaEntity.Id,
- WareAreaId = 1669154208777113600,
- IsStop = 0,
- Code = code,
- Name = name,
- StateNum = 1,
- TypeNum = 1,
- Size = 1,
- Shelf = tunnel.ToString() + shelfcode,
- WarehouseCode = "fj1southhouse",
- Row = row,
- Col = col,
- Layer = layer,
- Depth = 1,
- Tunnel = tunnel,
- SCRel = "SRM" + tunnel.ToString().PadLeft(2, '0'),
- ContGrpId = 0,
- ContGrpBarCode = "",
- Memo = "",
- AddWho = "admin",
- AddTime = DateTime.Now,
- EditWho = "admin",
- EditTime = DateTime.Now,
- });
- }
- }
- }
- Db.Insertable(list).ExecuteCommand();
- }
- }
- public static class IdFactory
- {
- private static readonly object locker = new object();
- private static IdWorker _idworker;
- public static IdWorker GetInstance()
- {
- if (_idworker == null)
- {
- lock (locker)
- {
- if (_idworker == null)
- {
- _idworker = new IdWorker(1, 1);
- }
- }
- }
- return _idworker;
- }
- public static long NewId()
- {
- return GetInstance().NextId();
- }
- }
- [SugarTable("Base_WareCell")]
- public partial class BaseWarecell
- {
- /// <summary>
- /// Id
- /// </summary>
- [SugarColumn(IsPrimaryKey = true, ColumnDataType = "bigint", IsNullable = false)]
- public long Id { get; set; }
- /// <summary>
- /// WarehouseId
- /// </summary>
- [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
- public long WarehouseId { get; set; }
- /// <summary>
- /// WarehouseCode
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string WarehouseCode { get; set; }
- /// <summary>
- /// WareAreaId
- /// </summary>
- [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
- public long WareAreaId { get; set; }
- /// <summary>
- /// IsStop
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int IsStop { get; set; }
- /// <summary>
- /// Code
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string Code { get; set; }
- /// <summary>
- /// Name
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = false)]
- public string Name { get; set; }
- /// <summary>
- /// StateNum
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int StateNum { get; set; }
- /// <summary>
- /// TypeNum
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int TypeNum { get; set; }
- /// <summary>
- /// Size
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int Size { get; set; }
- /// <summary>
- /// Row
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int Row { get; set; }
- /// <summary>
- /// Col
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int Col { get; set; }
- /// <summary>
- /// Layer
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int Layer { get; set; }
- /// <summary>
- /// Depth
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int Depth { get; set; }
- /// <summary>
- /// Tunnel
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int Tunnel { get; set; }
- /// <summary>
- /// SCRel
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string SCRel { get; set; }
- /// <summary>
- /// ContGrpId
- /// </summary>
- [SugarColumn(ColumnDataType = "bigint", IsNullable = true)]
- public long? ContGrpId { get; set; }
- /// <summary>
- /// ContGrpBarCode
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
- public string ContGrpBarCode { get; set; }
- /// <summary>
- /// Memo
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 500, IsNullable = false)]
- public string Memo { get; set; }
- /// <summary>
- /// AddWho
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string AddWho { get; set; }
- /// <summary>
- /// AddTime
- /// </summary>
- [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
- public DateTime AddTime { get; set; }
- /// <summary>
- /// EditWho
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string EditWho { get; set; }
- /// <summary>
- /// EditTime
- /// </summary>
- [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
- public DateTime EditTime { get; set; }
- /// <summary>
- /// Shelf
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
- public string Shelf { get; set; }
- }
- [SugarTable("Base_Warehouse")]
- public class BaseWarehouse
- {
- /// <summary>
- /// Id
- /// </summary>
- [SugarColumn(IsPrimaryKey = true, ColumnDataType = "bigint", IsNullable = false)]
- public long Id { get; set; }
- /// <summary>
- /// IsStop
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int IsStop { get; set; }
- /// <summary>
- /// Code
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string Code { get; set; }
- /// <summary>
- /// Name
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = false)]
- public string Name { get; set; }
- /// <summary>
- /// TypeNum
- /// </summary>
- [SugarColumn(ColumnDataType = "int", IsNullable = false)]
- public int TypeNum { get; set; }
- /// <summary>
- /// ConfigId
- /// </summary>
- [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
- public long ConfigId { get; set; }
- /// <summary>
- /// Memo
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 500, IsNullable = false)]
- public string Memo { get; set; }
- /// <summary>
- /// AddWho
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string AddWho { get; set; }
- /// <summary>
- /// AddTime
- /// </summary>
- [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
- public DateTime AddTime { get; set; }
- /// <summary>
- /// EditWho
- /// </summary>
- [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
- public string EditWho { get; set; }
- /// <summary>
- /// EditTime
- /// </summary>
- [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
- public DateTime EditTime { get; set; }
- }
- }
|