Input.cs.vm 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
  2. //
  3. // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
  4. //
  5. // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
  6. using Admin.NET.Core;
  7. using System.ComponentModel.DataAnnotations;
  8. using Magicodes.ExporterAndImporter.Core;
  9. using Magicodes.ExporterAndImporter.Excel;
  10. namespace @(Model.NameSpace);
  11. /// <summary>
  12. /// @(Model.BusName)基础输入参数
  13. /// </summary>
  14. public class @(Model.ClassName)BaseInput
  15. {
  16. @foreach (var column in Model.PrimaryKeyFieldList.Concat(Model.AddUpdateFieldList)){
  17. @:/// <summary>
  18. @:/// @column.ColumnComment
  19. @:/// </summary>
  20. if (column.EffectType is "EnumSelector" or "DictSelector") {
  21. @:[Dict(@(column.EffectType == "EnumSelector" ? $"nameof({column.DictTypeCode})" : $"\"{column.DictTypeCode}\""), AllowNullValue=true)]
  22. }
  23. if (column.WhetherRequired == "Y") {
  24. @:[Required(ErrorMessage = "@(column.ColumnComment)不能为空")]
  25. }
  26. @:public virtual @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  27. @:
  28. }
  29. }
  30. /// <summary>
  31. /// @(Model.BusName)分页查询输入参数
  32. /// </summary>
  33. public class Page@(Model.ClassName)Input : BasePageInput
  34. {
  35. @foreach (var column in Model.TableField.Where(u => u.WhetherQuery == "Y")){
  36. if(column.NetType?.TrimEnd('?') == "DateTime" && column.QueryType == "~"){
  37. @:/// <summary>
  38. @:/// @(column.ColumnComment)范围
  39. @:/// </summary>
  40. @: public DateTime?[] @(column.PropertyName)Range { get; set; }
  41. } else {
  42. @:/// <summary>
  43. @:/// @column.ColumnComment
  44. @:/// </summary>
  45. if (column.EffectType is "EnumSelector" or "DictSelector") {
  46. @:[Dict(@(column.EffectType == "EnumSelector" ? $"nameof({column.DictTypeCode})" : $"\"{column.DictTypeCode}\""), AllowNullValue=true)]
  47. }
  48. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  49. }
  50. @:
  51. }
  52. @if (Model.ImportFieldList.Count > 0){
  53. var primaryKey = Model.PrimaryKeyFieldList.First();
  54. @:/// <summary>
  55. @:/// 选中主键列表
  56. @:/// </summary>
  57. @: public List<@(primaryKey.NetType)> SelectKeyList { get; set; }
  58. }
  59. }
  60. /// <summary>
  61. /// @(Model.BusName)增加输入参数
  62. /// </summary>
  63. public class Add@(Model.ClassName)Input
  64. {
  65. @foreach (var column in Model.AddUpdateFieldList){
  66. @:/// <summary>
  67. @:/// @column.ColumnComment
  68. @:/// </summary>
  69. if (column.EffectType is "EnumSelector" or "DictSelector") {
  70. @:[Dict(@(column.EffectType == "EnumSelector" ? $"nameof({column.DictTypeCode})" : $"\"{column.DictTypeCode}\""), AllowNullValue=true)]
  71. }
  72. if (column.WhetherRequired == "Y") {
  73. @:[Required(ErrorMessage = "@(column.ColumnComment)不能为空")]
  74. }
  75. if (column.NetType.TrimEnd('?').EndsWith("string") && column.ColumnLength > 0){
  76. @:[MaxLength(@column.ColumnLength, ErrorMessage = "@(column.ColumnComment)字符长度不能超过@(column.ColumnLength)")]
  77. }
  78. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  79. @:
  80. }
  81. }
  82. /// <summary>
  83. /// @(Model.BusName)删除输入参数
  84. /// </summary>
  85. public class Delete@(Model.ClassName)Input
  86. {
  87. @foreach (var column in Model.PrimaryKeyFieldList) {
  88. @:/// <summary>
  89. @:/// @column.ColumnComment
  90. @:/// </summary>
  91. @:[Required(ErrorMessage = "@(column.ColumnComment)不能为空")]
  92. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  93. @:
  94. }
  95. }
  96. /// <summary>
  97. /// @(Model.BusName)更新输入参数
  98. /// </summary>
  99. public class Update@(Model.ClassName)Input
  100. {
  101. @foreach (var column in Model.PrimaryKeyFieldList.Concat(Model.AddUpdateFieldList)){
  102. @:/// <summary>
  103. @:/// @column.ColumnComment
  104. @:/// </summary>
  105. if (column.EffectType is "EnumSelector" or "DictSelector") {
  106. @:[Dict(@(column.EffectType == "EnumSelector" ? $"nameof({column.DictTypeCode})" : $"\"{column.DictTypeCode}\""), AllowNullValue=true)]
  107. }
  108. if (column.WhetherRequired == "Y" || column.ColumnKey == "True") {
  109. @:[Required(ErrorMessage = "@(column.ColumnComment)不能为空")]
  110. }
  111. if (column.NetType.TrimEnd('?').EndsWith("string") && column.ColumnLength > 0){
  112. @:[MaxLength(@column.ColumnLength, ErrorMessage = "@(column.ColumnComment)字符长度不能超过@(column.ColumnLength)")]
  113. }
  114. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  115. @:
  116. }
  117. }
  118. /// <summary>
  119. /// @(Model.BusName)主键查询输入参数
  120. /// </summary>
  121. public class QueryById@(Model.ClassName)Input : Delete@(Model.ClassName)Input
  122. {
  123. }
  124. @if (Model.DropdownFieldList.Count > 0) {
  125. @:/// <summary>
  126. @:/// 下拉数据输入参数
  127. @:/// </summary>
  128. @:public class DropdownData@(Model.ClassName)Input
  129. @:{
  130. @:/// <summary>
  131. @:/// 是否用于分页查询
  132. @:/// </summary>
  133. @:public bool FromPage { get; set; }
  134. @:}
  135. @:
  136. }
  137. @if (Model.HasSetStatus) {
  138. @:/// <summary>
  139. @:/// 设置状态输入参数
  140. @:/// </summary>
  141. @:public class Set@(Model.ClassName)StatusInput : BaseStatusInput
  142. @:{
  143. @foreach (var column in Model.PrimaryKeyFieldList.Where(u => u.PropertyName != "Id")) {
  144. @:/// <summary>
  145. @:/// @column.ColumnComment
  146. @:/// </summary>
  147. @:[Required(ErrorMessage = "@(column.ColumnComment)不能为空")]
  148. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  149. @:
  150. }
  151. @:}
  152. @:
  153. }
  154. @if (Model.ImportFieldList.Count > 0){
  155. @:/// <summary>
  156. @:/// @(Model.BusName)数据导入实体
  157. @:/// </summary>
  158. @:[ExcelImporter(SheetIndex = 1, IsOnlyErrorRows = true)]
  159. @:public class Import@(Model.ClassName)Input : BaseImportInput
  160. @:{
  161. foreach (var column in Model.ImportFieldList){
  162. var headerName = (column.WhetherRequired == "Y" ? "*" : "") + column.ColumnComment;
  163. if(column.EffectType == "ForeignKey" || column.EffectType == "ApiTreeSelector" || column.EffectType == "DictSelector") {
  164. @:/// <summary>
  165. @:/// @column.ColumnComment 关联值
  166. @:/// </summary>
  167. @:[ImporterHeader(IsIgnore = true)]
  168. @:[ExporterHeader(IsIgnore = true)]
  169. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  170. @:
  171. @:/// <summary>
  172. @:/// @column.ColumnComment 文本
  173. @:/// </summary>
  174. if (column.EffectType == "DictSelector") {
  175. @:[Dict(@($"\"{column.DictTypeCode}\""))]
  176. }
  177. @:[ImporterHeader(Name = "@(headerName)")]
  178. @:[ExporterHeader("@(headerName)", Format = "@", Width = 25, IsBold = true)]
  179. @:public string @column.ExtendedPropertyName { get; set; }
  180. } else {
  181. @:/// <summary>
  182. @:/// @column.ColumnComment
  183. @:/// </summary>
  184. @:[ImporterHeader(Name = "@(headerName)")]
  185. @:[ExporterHeader("@(headerName)", Format = "@", Width = 25, IsBold = true)]
  186. @:public @Model.GetNullableNetType(column.NetType) @column.PropertyName { get; set; }
  187. }
  188. @:
  189. }
  190. @:}
  191. }