DefaultDataCreator.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Linq;
  2. using IwbZero.ToolCommon.StringModel;
  3. using WeOnlineApp.Basic;
  4. using WeOnlineApp.Configuration;
  5. using WeOnlineApp.EF;
  6. namespace WeOnlineApp.SeedData
  7. {
  8. public class DefaultDataCreator
  9. {
  10. private readonly WeOnlineAppDbContext _context;
  11. public DefaultDataCreator(WeOnlineAppDbContext context)
  12. {
  13. _context = context;
  14. }
  15. public void Create()
  16. {
  17. SubjectCategory();
  18. }
  19. private int Index { get; set; }
  20. private string GetNo(DataLibType type, bool flag = false, bool flag2 = false)
  21. {
  22. if (flag)
  23. {
  24. while (Index % 10 != 0)
  25. {
  26. Index++;
  27. }
  28. }
  29. if (flag2)
  30. {
  31. while (Index % 50 != 0)
  32. {
  33. Index++;
  34. }
  35. }
  36. Index++;
  37. var no = $"JY{type.ToInt().LeftPad(3)}{Index.LeftPad(9)}";
  38. return no;
  39. }
  40. #region SCENECATEGORY
  41. private string scYl { get; set; }
  42. private string scHz { get; set; }
  43. private string scTd { get; set; }
  44. private string scGj { get; set; }
  45. private string scFx { get; set; }
  46. private string scPj { get; set; }
  47. private string scWhp { get; set; }
  48. public void SubjectCategory()
  49. {
  50. _context.Sql("DELETE FROM [dbo].[Base_SubjectCategories]");
  51. scYl = GetNo(DataLibType.SubjectCategoryInfo);
  52. scHz = GetNo(DataLibType.SubjectCategoryInfo);
  53. scTd = GetNo(DataLibType.SubjectCategoryInfo);
  54. scGj = GetNo(DataLibType.SubjectCategoryInfo);
  55. scFx = GetNo(DataLibType.SubjectCategoryInfo);
  56. scPj = GetNo(DataLibType.SubjectCategoryInfo);
  57. scWhp = GetNo(DataLibType.SubjectCategoryInfo);//index=107
  58. var path = $"{IwbConsts.SubjectCategoryRootNo},{scYl}";
  59. SubjectCategoryCreate(IwbConsts.SubjectCategoryRootNo, IwbConsts.TreeRootParentNo, "根节点", null);
  60. SubjectCategoryCreate(scYl, IwbConsts.SubjectCategoryRootNo, "综合演练", path);
  61. SubjectCategoryCreate(scHz, scYl, "高层火灾", $"{path},{scHz}");
  62. SubjectCategoryCreate(scTd, scYl, "大面积停电", $"{path},{scTd}");
  63. SubjectCategoryCreate(scGj, scYl, "轨交大客流", $"{path},{scGj}");
  64. SubjectCategoryCreate(scFx, scYl, "防台防汛", $"{path},{scFx}");
  65. SubjectCategoryCreate(scPj, scYl, "飞机迫降", $"{path},{scPj}");
  66. SubjectCategoryCreate(scWhp, scYl, "危化品事故", $"{path},{scWhp}");
  67. }
  68. /// <summary>
  69. /// 场景类别
  70. /// </summary>
  71. private void SubjectCategoryCreate(string id, string pId, string name, string pPath)
  72. {
  73. if (_context.SubjectCategoryInfos.Any(s => s.Id == id))
  74. {
  75. return;
  76. }
  77. _context.SubjectCategoryInfos.Add(new SubjectCategoryInfo()
  78. {
  79. Id = id,
  80. ParentNo = pId,
  81. CategoryName = name,
  82. CategoryPath = $"{(pPath.IsNotEmpty() ? $"{pPath}," : "")}{id}",
  83. Sort = 0,
  84. Description = name
  85. });
  86. _context.SaveChanges();
  87. }
  88. #endregion
  89. }
  90. }