PackageModel.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. using IwbZero.Expr;
  2. using IwbZero.IwbBase;
  3. using IwbZero.ToolCommon.StringModel;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text.RegularExpressions;
  10. using WeEngine.CommonDto.WeInfo;
  11. using WeEngine.ComponentInfo;
  12. using WeEngine.Enum;
  13. using WeEngine.Packages;
  14. namespace WeEngine.ModelInfo
  15. {
  16. public class PackageModel : ModelBase
  17. {
  18. public PackageModel()
  19. {
  20. Children = new List<RoundModel>();
  21. }
  22. public int RoundCount { get; set; }
  23. public string EngineType { get; set; }
  24. /// <summary>
  25. /// 定性评估表达式
  26. /// </summary>
  27. public string EvalQualitativeExpression { get; set; }
  28. public string AssessRoles { get; set; }
  29. public string AssessRoleNos { get; set; }
  30. public bool AssessAuto { get; set; }
  31. public bool AutoNextRound { get; set; }
  32. public decimal RoundScore { get; set; }
  33. public List<EngineComponent> Components { get; set; }
  34. public List<RoundModel> _children;
  35. public new List<RoundModel> Children
  36. {
  37. get
  38. {
  39. if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
  40. {
  41. _children = new List<RoundModel>();
  42. foreach (var child in PackageNode.Children)
  43. {
  44. var modal = new RoundModel();
  45. modal.ModelFrom(child);
  46. _children.Add(modal);
  47. }
  48. }
  49. return _children;
  50. }
  51. set => _children = value;
  52. }
  53. private PackageNode _package;
  54. [JsonIgnore]
  55. public PackageNode Package { get => _package ?? PackageNodeFrom(); set => _package = value; }
  56. #region ALL MODEL INFO
  57. [JsonIgnore]
  58. public List<RoundModel> AllRoundModels => Children ?? new List<RoundModel>();
  59. [JsonIgnore]
  60. public List<BlockModel> AllBlockModels
  61. {
  62. get
  63. {
  64. var list = new List<BlockModel>();
  65. foreach (var model in AllRoundModels)
  66. {
  67. list.AddRange(model.AllBlockModels);
  68. }
  69. return list;
  70. }
  71. }
  72. [JsonIgnore]
  73. public List<SceneFlowModel> AllFlowModels
  74. {
  75. get
  76. {
  77. var list = new List<SceneFlowModel>();
  78. foreach (var model in AllRoundModels)
  79. {
  80. list.AddRange(model.AllFlowModels);
  81. }
  82. return list;
  83. }
  84. }
  85. [JsonIgnore]
  86. public List<FlowModel> AllFlowNodeModels
  87. {
  88. get
  89. {
  90. var list = new List<FlowModel>();
  91. foreach (var model in AllRoundModels)
  92. {
  93. list.AddRange(model.AllFlowNodeModels);
  94. }
  95. return list;
  96. }
  97. }
  98. [JsonIgnore]
  99. public List<SceneModel> AllSceneModels
  100. {
  101. get
  102. {
  103. var list = new List<SceneModel>();
  104. foreach (var model in AllRoundModels)
  105. {
  106. list.AddRange(model.AllSceneModels);
  107. }
  108. return list;
  109. }
  110. }
  111. [JsonIgnore]
  112. public List<BehaviorModel> AllBehaviorModels
  113. {
  114. get
  115. {
  116. var list = new List<BehaviorModel>();
  117. foreach (var model in AllRoundModels)
  118. {
  119. list.AddRange(model.AllBehaviorModels);
  120. }
  121. return list;
  122. }
  123. }
  124. [JsonIgnore]
  125. public List<GuideModel> AllGuideModels
  126. {
  127. get
  128. {
  129. var list = new List<GuideModel>();
  130. list.AddRange(GuideInfos ?? new List<GuideModel>());
  131. foreach (var model in AllRoundModels)
  132. {
  133. list.AddRange(model.AllGuideModels);
  134. }
  135. return list;
  136. }
  137. }
  138. [JsonIgnore]
  139. public List<EnvironResourceModel> AllEnvironResourceModels
  140. {
  141. get
  142. {
  143. var list = new List<EnvironResourceModel>();
  144. foreach (var model in AllRoundModels)
  145. {
  146. list.AddRange(model.AllEnvironResourceModels);
  147. }
  148. return list;
  149. }
  150. }
  151. #endregion ALL MODEL INFO
  152. public List<RoleModel> RoleInfos => Package?.AllRoleInfos
  153. .Select(a => new RoleModel(a.RoleNo, a.RoleName, a.RoleWeight, a.TotalWeight)).ToList();
  154. //public string AllRoleNames => RoleInfos?.Count > 0
  155. // ? string.Join(",", RoleInfos.Select(a => a.ToString()).ToArray())
  156. // : "";
  157. /// <summary>
  158. /// 构建方案包Node
  159. /// </summary>
  160. /// <param name="xmlInfo"></param>
  161. /// <returns></returns>
  162. public PackageNode BuildPackageNodeByXml(WePackageXmlDto xmlInfo)
  163. {
  164. var package = new PackageNode
  165. {
  166. AssessAuto = AssessAuto,
  167. AssessRoles = AssessRoles?.Split(',').ToList(),
  168. EngineType = EngineType,
  169. AutoNextRound = AutoNextRound,
  170. RoundScore = RoundScore,
  171. Parent = null,
  172. QueryFlowXmlFunc = id => PackageHelper.GetSceneFlowXmlFromXml(xmlInfo.FlowXml, id),
  173. QuerySceneXmlFunc = id => PackageHelper.GetSceneXmlFromXml(xmlInfo.SceneXml, id),
  174. QueryBehaviorXmlFunc = id => PackageHelper.GetBehaviorXmlFromXml(xmlInfo.BehaviorXml, id),
  175. QueryGuidesXmlFunc = ids => PackageHelper.GetGuidesXmlFromXml(xmlInfo.GuideXml, string.Join(",", ids)),
  176. QueryEnvironmentXmlFunc = id => PackageHelper.GetEnvironResourceXmlFromXml(xmlInfo.EnvironResourceXml, id),
  177. };
  178. var packageXmlNode = IwbXmlNode.ParseGenericXml(xmlInfo.PackageXml);
  179. package = (PackageNode)package.BuildNodeByXmlNode(packageXmlNode);
  180. Package = package;
  181. return package;
  182. }
  183. /// <summary>
  184. /// 构建方案包Model
  185. /// </summary>
  186. /// <param name="xmlInfo"></param>
  187. /// <returns></returns>
  188. public PackageModel BuildPackageModelByXml(WePackageXmlDto xmlInfo)
  189. {
  190. var packageNode = BuildPackageNodeByXml(xmlInfo);
  191. var packageModel = new PackageModel();
  192. packageModel.ModelFrom(packageNode);
  193. return packageModel;
  194. }
  195. /// <summary>
  196. /// Model转换为Node
  197. /// </summary>
  198. /// <returns></returns>
  199. public PackageNode PackageNodeFrom()
  200. {
  201. var package = new PackageNode
  202. {
  203. AssessAuto = AssessAuto,
  204. AssessRoles = AssessRoles?.Split(',').ToList(),
  205. EngineType = EngineType,
  206. AutoNextRound = AutoNextRound,
  207. RoundScore = RoundScore,
  208. EvalQualitativeExpression = EvalQualitativeExpression,
  209. Parent = null,
  210. };
  211. package = (PackageNode)NodeFrom(package);
  212. return package;
  213. }
  214. /// <summary>
  215. /// 方案包转换成 XML Dto
  216. /// </summary>
  217. /// <returns></returns>
  218. public WePackageXmlDto Package2Xml()
  219. {
  220. var packageNode = Package;
  221. var dto = new WePackageXmlDto
  222. {
  223. PackageXml = packageNode.ToXmlString(),
  224. FlowXml = packageNode.Flows2Xml(),
  225. SceneXml = packageNode.Scenes2Xml(),
  226. BehaviorXml = packageNode.Behaviors2Xml(),
  227. GuideXml = packageNode.Guide2Xml(),
  228. EnvironResourceXml = packageNode.EnvironmentRender2Xml(),
  229. ComponentXml = new EngineComponent().ConvertComponents2Xml(Components),
  230. AllRoles = RoleInfos?.Count > 0
  231. ? string.Join(",", RoleInfos.Select(a => a.ToString()).ToArray())
  232. : ""
  233. };
  234. return dto;
  235. }
  236. /// <summary>
  237. /// 转换Node
  238. /// </summary>
  239. /// <param name="node">空Node</param>
  240. /// <returns></returns>
  241. internal override NodeBase NodeFrom(NodeBase node)
  242. {
  243. var node2 = (PackageNode)base.NodeFrom(node);
  244. node2.Parent = null;
  245. var children = new List<SceneRoundNode>();
  246. if (Children?.Count > 0)
  247. {
  248. foreach (var child in Children)
  249. {
  250. var childNode = new SceneRoundNode(node2);
  251. children.Add((SceneRoundNode)child.NodeFrom(childNode));
  252. }
  253. }
  254. node2.Children = children;
  255. return node2;
  256. }
  257. /// <summary>
  258. /// 转换为Model
  259. /// </summary>
  260. /// <param name="node"></param>
  261. /// <returns></returns>
  262. internal override void ModelFrom(NodeBase node)
  263. {
  264. base.ModelFrom(node);
  265. var node2 = (PackageNode)node;
  266. AssessAuto = node2.AssessAuto;
  267. AssessRoles = string.Join(",", node2.AssessRoles);
  268. EngineType = node2.EngineType;
  269. AutoNextRound = node2.AutoNextRound;
  270. RoundScore = node2.RoundScore;
  271. EvalQualitativeExpression = node2.EvalQualitativeExpression;
  272. PackageNode = node2;
  273. //if (node.HasChild)
  274. //{
  275. // Children= new List<RoundModel>();
  276. // foreach (var child in node.Children)
  277. // {
  278. // var modal = new RoundModel() ;
  279. // modal.ModelFrom(child);
  280. // Children.Add(modal);
  281. // }
  282. //}
  283. }
  284. }
  285. public class RoundModel : ModelBase
  286. {
  287. public int RoundIndex { get; set; }
  288. public int BlockIndex { get; set; }
  289. public decimal RoundFullScore { get; set; }
  290. public int ControlRate { get; set; }
  291. public int SceneCount { get; set; }
  292. public List<BlockModel> _children;
  293. public new List<BlockModel> Children
  294. {
  295. get
  296. {
  297. if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
  298. {
  299. _children = new List<BlockModel>();
  300. foreach (var child in PackageNode.Children)
  301. {
  302. var modal = new BlockModel();
  303. modal.ModelFrom(child);
  304. _children.Add(modal);
  305. }
  306. }
  307. return _children;
  308. }
  309. set => _children = value;
  310. }
  311. #region ALL MODEL INFO
  312. [JsonIgnore]
  313. public List<BlockModel> AllBlockModels => Children ?? new List<BlockModel>();
  314. [JsonIgnore]
  315. public List<SceneFlowModel> AllFlowModels
  316. {
  317. get
  318. {
  319. var list = new List<SceneFlowModel>();
  320. foreach (var model in AllBlockModels)
  321. {
  322. list.AddRange(model.AllFlowModels);
  323. }
  324. return list;
  325. }
  326. }
  327. [JsonIgnore]
  328. public List<FlowModel> AllFlowNodeModels
  329. {
  330. get
  331. {
  332. var list = new List<FlowModel>();
  333. foreach (var model in AllBlockModels)
  334. {
  335. list.AddRange(model.AllFlowNodeModels);
  336. }
  337. return list;
  338. }
  339. }
  340. [JsonIgnore]
  341. public List<SceneModel> AllSceneModels
  342. {
  343. get
  344. {
  345. var list = new List<SceneModel>();
  346. foreach (var model in AllBlockModels)
  347. {
  348. list.AddRange(model.AllSceneModels);
  349. }
  350. return list;
  351. }
  352. }
  353. [JsonIgnore]
  354. public List<BehaviorModel> AllBehaviorModels
  355. {
  356. get
  357. {
  358. var list = new List<BehaviorModel>();
  359. foreach (var model in AllBlockModels)
  360. {
  361. list.AddRange(model.AllBehaviorModels);
  362. }
  363. return list;
  364. }
  365. }
  366. [JsonIgnore]
  367. public List<GuideModel> AllGuideModels
  368. {
  369. get
  370. {
  371. var list = new List<GuideModel>();
  372. list.AddRange(GuideInfos ?? new List<GuideModel>());
  373. foreach (var model in AllBlockModels)
  374. {
  375. list.AddRange(model.AllGuideModels);
  376. }
  377. return list;
  378. }
  379. }
  380. [JsonIgnore]
  381. public List<EnvironResourceModel> AllEnvironResourceModels
  382. {
  383. get
  384. {
  385. var list = new List<EnvironResourceModel>();
  386. foreach (var model in AllBlockModels)
  387. {
  388. list.AddRange(model.AllEnvironResourceModels);
  389. }
  390. return list;
  391. }
  392. }
  393. #endregion ALL MODEL INFO
  394. /// <summary>
  395. /// 转换Node
  396. /// </summary>
  397. /// <param name="node">空Node</param>
  398. /// <returns></returns>
  399. internal override NodeBase NodeFrom(NodeBase node)
  400. {
  401. var newNode = (SceneRoundNode)base.NodeFrom(node);
  402. newNode.RoundIndex = RoundIndex;
  403. newNode.RoundFullScore = RoundFullScore;
  404. newNode.ControlRate = ControlRate;
  405. newNode.SceneCount = SceneCount;
  406. if (Children?.Count > 0)
  407. {
  408. var list = new List<SceneFlowBlockNode>();
  409. foreach (var child in Children)
  410. {
  411. var childNode = new SceneFlowBlockNode(newNode);
  412. list.Add((SceneFlowBlockNode)child.NodeFrom(childNode));
  413. }
  414. newNode.Children = list;
  415. }
  416. return newNode;
  417. }
  418. /// <summary>
  419. /// 转换Model
  420. /// </summary>
  421. /// <param name="node"></param>
  422. /// <returns></returns>
  423. internal override void ModelFrom(NodeBase node)
  424. {
  425. base.ModelFrom(node);
  426. var node2 = (SceneRoundNode)node;
  427. RoundIndex = node2.RoundIndex;
  428. RoundFullScore = node2.RoundFullScore;
  429. ControlRate = node2.ControlRate;
  430. SceneCount = node2.SceneCount;
  431. PackageNode = node2;
  432. //if (node.HasChild)
  433. //{
  434. // Children = new List<BlockModel>();
  435. // foreach (var child in node.Children)
  436. // {
  437. // var modal = new BlockModel();
  438. // modal.ModelFrom(child);
  439. // Children.Add(modal);
  440. // }
  441. //}
  442. }
  443. }
  444. public class BlockModel : ModelBase
  445. {
  446. public int BlockType { get; set; }
  447. public string FlowNos { get; set; }
  448. public string FlowNames { get; set; }
  449. public List<SceneFlowModel> _children;
  450. public new List<SceneFlowModel> Children
  451. {
  452. get
  453. {
  454. if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
  455. {
  456. _children = new List<SceneFlowModel>();
  457. foreach (var child in PackageNode.Children)
  458. {
  459. var modal = new SceneFlowModel();
  460. modal.ModelFrom(child);
  461. _children.Add(modal);
  462. }
  463. }
  464. return _children;
  465. }
  466. set => _children = value;
  467. }
  468. #region ALL MODEL INFO
  469. [JsonIgnore]
  470. public List<SceneFlowModel> AllFlowModels => Children ?? new List<SceneFlowModel>();
  471. [JsonIgnore]
  472. public List<FlowModel> AllFlowNodeModels
  473. {
  474. get
  475. {
  476. var list = new List<FlowModel>();
  477. foreach (var model in AllFlowModels)
  478. {
  479. list.AddRange(model.AllFlowNodeModels);
  480. }
  481. return list;
  482. }
  483. }
  484. [JsonIgnore]
  485. public List<SceneModel> AllSceneModels
  486. {
  487. get
  488. {
  489. var list = new List<SceneModel>();
  490. foreach (var model in AllFlowModels)
  491. {
  492. list.AddRange(model.AllSceneModels);
  493. }
  494. return list;
  495. }
  496. }
  497. [JsonIgnore]
  498. public List<BehaviorModel> AllBehaviorModels
  499. {
  500. get
  501. {
  502. var list = new List<BehaviorModel>();
  503. foreach (var model in AllFlowModels)
  504. {
  505. list.AddRange(model.AllBehaviorModels);
  506. }
  507. return list;
  508. }
  509. }
  510. [JsonIgnore]
  511. public List<GuideModel> AllGuideModels
  512. {
  513. get
  514. {
  515. var list = new List<GuideModel>();
  516. list.AddRange(GuideInfos ?? new List<GuideModel>());
  517. foreach (var model in AllFlowModels)
  518. {
  519. list.AddRange(model.AllGuideModels);
  520. }
  521. return list;
  522. }
  523. }
  524. [JsonIgnore]
  525. public List<EnvironResourceModel> AllEnvironResourceModels
  526. {
  527. get
  528. {
  529. var list = new List<EnvironResourceModel>();
  530. foreach (var model in AllFlowModels)
  531. {
  532. list.AddRange(model.AllEnvironResourceModels);
  533. }
  534. return list;
  535. }
  536. }
  537. #endregion ALL MODEL INFO
  538. /// <summary>
  539. /// 转换Node
  540. /// </summary>
  541. /// <param name="node">空Node</param>
  542. /// <returns></returns>
  543. internal override NodeBase NodeFrom(NodeBase node)
  544. {
  545. var newNode = (SceneFlowBlockNode)base.NodeFrom(node);
  546. newNode.BlockType = (SceneFlowBlockType)BlockType;
  547. if (Children?.Count > 0)
  548. {
  549. var list = new List<SceneFlowNode>();
  550. foreach (var child in Children)
  551. {
  552. var childNode = new SceneFlowNode(newNode);
  553. list.Add((SceneFlowNode)child.NodeFrom(childNode));
  554. }
  555. newNode.Children = list;
  556. }
  557. return newNode;
  558. }
  559. /// <summary>
  560. /// 转换为Model
  561. /// </summary>
  562. /// <param name="node"></param>
  563. /// <returns></returns>
  564. internal override void ModelFrom(NodeBase node)
  565. {
  566. base.ModelFrom(node);
  567. var node2 = (SceneFlowBlockNode)node;
  568. BlockType = (int)node2.BlockType;
  569. PackageNode = node2;
  570. //if (node.HasChild)
  571. //{
  572. // Children = new List<SceneFlowModel>();
  573. // foreach (var child in node.Children)
  574. // {
  575. // var modal = new SceneFlowModel();
  576. // modal.ModelFrom(child);
  577. // Children.Add(modal);
  578. // }
  579. //}
  580. }
  581. }
  582. public class SceneFlowModel : ModelBase
  583. {
  584. public FlowModel ContentInfo { get; set; }
  585. public List<FlowModel> _children;
  586. public new List<FlowModel> Children
  587. {
  588. get
  589. {
  590. if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
  591. {
  592. _children = new List<FlowModel>();
  593. foreach (var child in PackageNode.Children)
  594. {
  595. var modal = new FlowModel();
  596. modal.ModelFrom(child);
  597. _children.Add(modal);
  598. }
  599. }
  600. return _children;
  601. }
  602. set => _children = value;
  603. }
  604. #region ALL MODEL INFO
  605. [JsonIgnore]
  606. public List<FlowModel> AllFlowNodeModels
  607. {
  608. get
  609. {
  610. var list = new List<FlowModel>();
  611. foreach (var child in Children)
  612. {
  613. list.AddRange(GetFlowModels(child));
  614. }
  615. return list;
  616. }
  617. }
  618. [JsonIgnore]
  619. public List<SceneModel> AllSceneModels
  620. {
  621. get
  622. {
  623. var list = new List<SceneModel>();
  624. foreach (var model in AllFlowNodeModels)
  625. {
  626. list.AddRange(model.AllSceneModels);
  627. }
  628. return list;
  629. }
  630. }
  631. [JsonIgnore]
  632. public List<BehaviorModel> AllBehaviorModels
  633. {
  634. get
  635. {
  636. var list = new List<BehaviorModel>();
  637. foreach (var model in AllFlowNodeModels)
  638. {
  639. list.AddRange(model.AllBehaviorModels);
  640. }
  641. return list;
  642. }
  643. }
  644. [JsonIgnore]
  645. public List<GuideModel> AllGuideModels
  646. {
  647. get
  648. {
  649. var list = new List<GuideModel>();
  650. list.AddRange(GuideInfos ?? new List<GuideModel>());
  651. foreach (var model in AllFlowNodeModels)
  652. {
  653. list.AddRange(model.AllGuideModels);
  654. }
  655. return list;
  656. }
  657. }
  658. [JsonIgnore]
  659. public List<EnvironResourceModel> AllEnvironResourceModels
  660. {
  661. get
  662. {
  663. var list = new List<EnvironResourceModel>();
  664. foreach (var model in AllFlowNodeModels)
  665. {
  666. list.AddRange(model.AllEnvironResourceModels);
  667. }
  668. return list;
  669. }
  670. }
  671. #endregion ALL MODEL INFO
  672. /// <summary>
  673. /// 转换Node
  674. /// </summary>
  675. /// <param name="node">空Node</param>
  676. /// <returns></returns>
  677. internal override NodeBase NodeFrom(NodeBase node)
  678. {
  679. var newNode = (SceneFlowNode)base.NodeFrom(node);
  680. if (Children?.Count > 0)
  681. {
  682. var list = new List<FlowNode>();
  683. foreach (var child in Children)
  684. {
  685. var childNode = new FlowNode(newNode);
  686. list.Add((FlowNode)child.NodeFrom(childNode));
  687. }
  688. newNode.Children = list;
  689. }
  690. return newNode;
  691. }
  692. /// <summary>
  693. /// 转换为Model
  694. /// </summary>
  695. /// <param name="node"></param>
  696. /// <returns></returns>
  697. internal override void ModelFrom(NodeBase node)
  698. {
  699. base.ModelFrom(node);
  700. var node2 = (SceneFlowNode)node;
  701. PackageNode = node2;
  702. //if (node.HasChild)
  703. //{
  704. // Children = new List<FlowModel>();
  705. // foreach (var child in node.Children)
  706. // {
  707. // var modal = new FlowModel();
  708. // modal.ModelFrom(child);
  709. // Children.Add(modal);
  710. // }
  711. //}
  712. }
  713. private List<FlowModel> GetFlowModels(FlowModel model)
  714. {
  715. var list = new List<FlowModel>();
  716. if (model == null)
  717. {
  718. return list;
  719. }
  720. list.Add(model);
  721. if (model.Children?.Count > 0)
  722. {
  723. foreach (var child in model.Children)
  724. {
  725. var children = GetFlowModels(child);
  726. list.AddRange(children);
  727. }
  728. }
  729. return list;
  730. }
  731. }
  732. public class FlowModel : ModelBase
  733. {
  734. public int Index { get; set; }
  735. public int FlowDepth { get; set; }
  736. [JsonIgnore]
  737. public string _sceneNos;
  738. public string SceneNos
  739. {
  740. get
  741. {
  742. return _sceneNos ??
  743. string.Join(",", Children?.Select(a => a.Id).ToArray() ?? Array.Empty<string>());
  744. }
  745. set => _sceneNos = value;
  746. }
  747. public string SceneNames => string.Join(",", SceneInfos?.Select(a => a.Name) ?? Array.Empty<string>());
  748. public List<FlowModel> _children;
  749. public new List<FlowModel> Children
  750. {
  751. get
  752. {
  753. if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
  754. {
  755. _children = new List<FlowModel>();
  756. foreach (var child in PackageNode.Children)
  757. {
  758. var modal = new FlowModel();
  759. modal.ModelFrom(child);
  760. _children.Add(modal);
  761. }
  762. }
  763. return _children;
  764. }
  765. set => _children = value;
  766. }
  767. public List<SceneModel> _sceneInfos;
  768. public List<SceneModel> SceneInfos
  769. {
  770. get
  771. {
  772. if (PackageNode != null && (_sceneInfos == null || _sceneInfos.Count == 0))
  773. {
  774. _sceneInfos = new List<SceneModel>();
  775. if (PackageNode != null)
  776. {
  777. var node = (FlowNode)PackageNode;
  778. foreach (var child in node.SceneInfos)
  779. {
  780. var modal = new SceneModel();
  781. modal.ModelFrom(child);
  782. _sceneInfos.Add(modal);
  783. }
  784. }
  785. }
  786. return _sceneInfos;
  787. }
  788. set => _sceneInfos = value;
  789. }
  790. #region ALL MODEL INFO
  791. [JsonIgnore]
  792. public List<SceneModel> AllSceneModels => SceneInfos ?? new List<SceneModel>();
  793. [JsonIgnore]
  794. public List<BehaviorModel> AllBehaviorModels
  795. {
  796. get
  797. {
  798. var list = new List<BehaviorModel>();
  799. foreach (var model in AllSceneModels)
  800. {
  801. list.AddRange(model.AllBehaviorModels);
  802. }
  803. return list;
  804. }
  805. }
  806. [JsonIgnore]
  807. public List<GuideModel> AllGuideModels
  808. {
  809. get
  810. {
  811. var list = new List<GuideModel>();
  812. list.AddRange(GuideInfos ?? new List<GuideModel>());
  813. foreach (var model in AllSceneModels)
  814. {
  815. list.AddRange(model.AllGuideModels);
  816. }
  817. return list;
  818. }
  819. }
  820. [JsonIgnore]
  821. public List<EnvironResourceModel> AllEnvironResourceModels
  822. {
  823. get
  824. {
  825. var list = new List<EnvironResourceModel>();
  826. foreach (var model in AllSceneModels)
  827. {
  828. list.AddRange(model.AllEnvironResourceModels);
  829. }
  830. return list;
  831. }
  832. }
  833. #endregion ALL MODEL INFO
  834. /// <summary>
  835. /// 转换Node
  836. /// </summary>
  837. /// <param name="node">空Node</param>
  838. /// <returns></returns>
  839. internal override NodeBase NodeFrom(NodeBase node)
  840. {
  841. var newNode = (FlowNode)base.NodeFrom(node);
  842. if (Children?.Count > 0)
  843. {
  844. var list = new List<FlowNode>();
  845. foreach (var child in Children)
  846. {
  847. var childNode = new FlowNode(newNode);
  848. list.Add((FlowNode)child.NodeFrom(childNode));
  849. }
  850. newNode.Children = list;
  851. }
  852. if (SceneInfos?.Count > 0)
  853. {
  854. var list = new List<SceneNode>();
  855. foreach (var child in SceneInfos)
  856. {
  857. var childNode = new SceneNode(newNode);
  858. list.Add((SceneNode)child.NodeFrom(childNode));
  859. }
  860. newNode.SceneInfos = list;
  861. }
  862. return newNode;
  863. }
  864. /// <summary>
  865. /// 转换Model
  866. /// </summary>
  867. /// <param name="node"></param>
  868. /// <returns></returns>
  869. internal override void ModelFrom(NodeBase node)
  870. {
  871. base.ModelFrom(node);
  872. var node2 = (FlowNode)node;
  873. PackageNode = node2;
  874. //if (node.HasChild)
  875. //{
  876. // Children = new List<FlowModel>();
  877. // foreach (var child in node.Children)
  878. // {
  879. // var modal = new FlowModel();
  880. // modal.ModelFrom(child);
  881. // Children.Add(modal);
  882. // }
  883. //}
  884. //if (node2.SceneInfos?.Count > 0)
  885. //{
  886. // SceneInfos = new List<SceneModel>();
  887. // foreach (var child in node2.SceneInfos)
  888. // {
  889. // var modal = new SceneModel();
  890. // modal.ModelFrom(child);
  891. // SceneInfos.Add(modal);
  892. // }
  893. //}
  894. }
  895. }
  896. public class SceneModel : ModelBase
  897. {
  898. public SceneModel()
  899. {
  900. Children = new List<BehaviorModel>();
  901. EnvironResources = new List<EnvironResourceModel>();
  902. }
  903. public int SceneType { get; set; }
  904. public string SceneTag { get; set; }
  905. public string _description { get; set; }
  906. public string Description
  907. {
  908. get
  909. {
  910. var desc = _description ?? "";
  911. if (Variables != null && _description.IsNotEmpty())
  912. {
  913. if (desc.IndexOf(IwbVariableType.Local, StringComparison.Ordinal) >= 0)
  914. {
  915. var reg = new Regex("@[0-9,a-z,A-Z]*");
  916. desc = reg.Replace(desc, match => match.ToString().ToUpper());
  917. desc = EvalExpr.TransVariable(desc, Variables);
  918. }
  919. //foreach (DictionaryEntry entry in Variables)
  920. //{
  921. // var variable = (IwbRtVariable)entry.Value;
  922. // desc = desc.Replace(variable.VarName.ToUpper(), variable.GetStringValue());
  923. //}
  924. return desc;
  925. }
  926. return desc;
  927. }
  928. }
  929. [JsonIgnore]
  930. public string _behaviorNos;
  931. public string BehaviorNos
  932. {
  933. get
  934. {
  935. return _behaviorNos ??
  936. string.Join(",", Children?.Select(a => a.Id).ToArray() ?? Array.Empty<string>());
  937. }
  938. set => _behaviorNos = value;
  939. }
  940. [JsonIgnore]
  941. private string _environResourceNos;
  942. public string EnvironResourceNos
  943. {
  944. get
  945. {
  946. return _environResourceNos ??
  947. string.Join(",", EnvironResources?.Select(a => a.Id).ToArray() ?? Array.Empty<string>());
  948. }
  949. set => _environResourceNos = value;
  950. }
  951. private List<EnvironResourceModel> _environResources;
  952. [JsonIgnore]
  953. public List<EnvironResourceModel> EnvironResources
  954. {
  955. get
  956. {
  957. if (_environResources == null)
  958. {
  959. var node = (SceneNode)PackageNode;
  960. _environResources = node?.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ??
  961. new List<EnvironResourceModel>();
  962. }
  963. return _environResources;
  964. }
  965. set => _environResources = value;
  966. }
  967. [JsonIgnore]
  968. public Hashtable _variables;
  969. [JsonIgnore]
  970. public Hashtable Variables
  971. {
  972. get => _variables != null && _variables.Count > 0 ? _variables : GetVariable();
  973. set => _variables = value;
  974. }
  975. [JsonIgnore]
  976. public List<BehaviorModel> _children;
  977. public new List<BehaviorModel> Children
  978. {
  979. get
  980. {
  981. if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
  982. {
  983. _children = new List<BehaviorModel>();
  984. foreach (var child in PackageNode.Children)
  985. {
  986. var modal = new BehaviorModel();
  987. modal.ModelFrom(child);
  988. _children.Add(modal);
  989. }
  990. }
  991. return _children;
  992. }
  993. set => _children = value;
  994. }
  995. #region ALL MODEL INFO
  996. [JsonIgnore]
  997. public List<BehaviorModel> AllBehaviorModels => Children;
  998. [JsonIgnore]
  999. public List<GuideModel> AllGuideModels
  1000. {
  1001. get
  1002. {
  1003. var list = new List<GuideModel>();
  1004. list.AddRange(GuideInfos ?? new List<GuideModel>());
  1005. foreach (var model in AllBehaviorModels)
  1006. {
  1007. list.AddRange(model.AllGuideModels);
  1008. }
  1009. return list;
  1010. }
  1011. }
  1012. [JsonIgnore]
  1013. public List<EnvironResourceModel> AllEnvironResourceModels
  1014. {
  1015. get
  1016. {
  1017. var list = new List<EnvironResourceModel>();
  1018. list.AddRange(EnvironResources ?? new List<EnvironResourceModel>());
  1019. foreach (var model in AllBehaviorModels)
  1020. {
  1021. list.AddRange(model.AllEnvironResourceModels);
  1022. }
  1023. return list;
  1024. }
  1025. }
  1026. #endregion ALL MODEL INFO
  1027. /// <summary>
  1028. /// 转换Node
  1029. /// </summary>
  1030. /// <param name="node">空Node</param>
  1031. /// <returns></returns>
  1032. internal override NodeBase NodeFrom(NodeBase node)
  1033. {
  1034. var newNode = (SceneNode)base.NodeFrom(node);
  1035. newNode.SceneTag = SceneTag;
  1036. newNode.Description = _description;
  1037. newNode.SceneType = (SceneType)SceneType;
  1038. newNode.EnvironResources = EnvironResources?.Select(a => a.NodeFrom()).ToList() ?? new List<EnvironResourceNode>();
  1039. if (Children?.Count > 0)
  1040. {
  1041. var list = new List<BehaviorNode>();
  1042. foreach (var child in Children)
  1043. {
  1044. var childNode = new BehaviorNode(newNode);
  1045. list.Add((BehaviorNode)child.NodeFrom(childNode));
  1046. }
  1047. newNode.Children = list;
  1048. }
  1049. return newNode;
  1050. }
  1051. /// <summary>
  1052. /// 转换为Model
  1053. /// </summary>
  1054. /// <param name="node"></param>
  1055. /// <returns></returns>
  1056. internal override void ModelFrom(NodeBase node)
  1057. {
  1058. base.ModelFrom(node);
  1059. var node2 = (SceneNode)node;
  1060. PackageNode = node2;
  1061. SceneTag = node2.SceneTag;
  1062. SceneType = (int)node2.SceneType;
  1063. _description = node2.Description;
  1064. //EnvironResources = node2.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ?? new List<EnvironResourceModel>();
  1065. //if (node.HasChild)
  1066. //{
  1067. // foreach (var child in node.Children)
  1068. // {
  1069. // var modal = new BehaviorModel();
  1070. // modal.ModelFrom(child);
  1071. // Children.Add(modal);
  1072. // }
  1073. //}
  1074. }
  1075. }
  1076. public class BehaviorModel : ModelBase
  1077. {
  1078. public BehaviorModel()
  1079. {
  1080. EnvironResources = new List<EnvironResourceModel>();
  1081. }
  1082. public string BehaviorTag { get; set; }
  1083. public string Description { get; set; }
  1084. public int BehaviorScoreType { get; set; }
  1085. public int RoleLogicType { get; set; }
  1086. private List<RoleModel> _behaviorRoles { get; set; }
  1087. public List<RoleModel> BehaviorRoles
  1088. {
  1089. get
  1090. {
  1091. if (_behaviorRoles == null)
  1092. {
  1093. var node = (BehaviorNode)PackageNode;
  1094. _behaviorRoles = node?.BehaviorRoles?.Count > 0
  1095. ? node.BehaviorRoles.Select(a => new RoleModel(a.RoleNo, a.RoleName, a.RoleWeight, a.TotalWeight)).ToList()
  1096. : new List<RoleModel>();
  1097. }
  1098. return _behaviorRoles;
  1099. }
  1100. set => _behaviorRoles = value;
  1101. }
  1102. public string RoleNames => string.Join(",", BehaviorRoles?.Select(a => a.RoleName).ToList() ?? new List<string>());
  1103. public string RuleKeyword { get; set; }
  1104. public string KnowledgeNos { get; set; }
  1105. [JsonIgnore]
  1106. private string _environResourceNos;
  1107. public string EnvironResourceNos
  1108. {
  1109. get
  1110. {
  1111. return _environResourceNos ??
  1112. string.Join(",", EnvironResources?.Select(a => a.Id).ToArray() ?? new string[0]);
  1113. }
  1114. set => _environResourceNos = value;
  1115. }
  1116. private List<EnvironResourceModel> _environResources;
  1117. [JsonIgnore]
  1118. public List<EnvironResourceModel> EnvironResources
  1119. {
  1120. get
  1121. {
  1122. if (_environResources == null)
  1123. {
  1124. var node = (BehaviorNode)PackageNode;
  1125. _environResources = node?.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ??
  1126. new List<EnvironResourceModel>();
  1127. }
  1128. return _environResources;
  1129. }
  1130. set => _environResources = value;
  1131. }
  1132. #region ALL MODEL INFO
  1133. [JsonIgnore]
  1134. public List<GuideModel> AllGuideModels => GuideInfos ?? new List<GuideModel>();
  1135. [JsonIgnore]
  1136. public List<EnvironResourceModel> AllEnvironResourceModels =>
  1137. EnvironResources ?? new List<EnvironResourceModel>();
  1138. #endregion ALL MODEL INFO
  1139. /// <summary>
  1140. /// 转换Node
  1141. /// </summary>
  1142. /// <param name="node">空Node</param>
  1143. /// <returns></returns>
  1144. internal override NodeBase NodeFrom(NodeBase node)
  1145. {
  1146. var newNode = (BehaviorNode)base.NodeFrom(node);
  1147. newNode.BehaviorTag = BehaviorTag;
  1148. newNode.BehaviorRoleLogic = (BehaviorRoleLogicType)RoleLogicType;
  1149. newNode.BehaviorScoreType = (BehaviorScoreType)BehaviorScoreType;
  1150. newNode.BehaviorRoles = BehaviorRoles?.Count > 0
  1151. ? BehaviorRoles.Select(a => new RoleNode(a.RoleNo, a.RoleName)).ToList()
  1152. : new List<RoleNode>();
  1153. newNode.EnvironResources = new List<EnvironResourceNode>();
  1154. newNode.Description = Description;
  1155. newNode.BuildKeywordNodes(RuleKeyword);
  1156. newNode.EnvironResources = EnvironResources?.Select(a => a.NodeFrom()).ToList() ?? new List<EnvironResourceNode>();
  1157. return newNode;
  1158. }
  1159. /// <summary>
  1160. /// 转换为Model
  1161. /// </summary>
  1162. /// <param name="node"></param>
  1163. /// <returns></returns>
  1164. internal override void ModelFrom(NodeBase node)
  1165. {
  1166. base.ModelFrom(node);
  1167. var node2 = (BehaviorNode)node;
  1168. BehaviorTag = node2.BehaviorTag;
  1169. RoleLogicType = (int)node2.BehaviorRoleLogic;
  1170. BehaviorScoreType = (int)node2.BehaviorScoreType;
  1171. //BehaviorRoles = node2.BehaviorRoles?.Count > 0
  1172. // ? node2.BehaviorRoles.Select(a => new RoleModel(a.RoleNo, a.RoleName, a.RoleWeight, a.TotalWeight)).ToList()
  1173. // : new List<RoleModel>();
  1174. Description = node2.Description;
  1175. RuleKeyword = node2.Keywords;
  1176. //EnvironResources = node2.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ?? new List<EnvironResourceModel>();
  1177. //if (node.HasChild)
  1178. //{
  1179. // foreach (var child in node.Children)
  1180. // {
  1181. // var modal = new BehaviorModel() ;
  1182. // modal.ModelFrom(child);
  1183. // Children.Add(modal);
  1184. // }
  1185. //}
  1186. }
  1187. }
  1188. public class GuideModel
  1189. {
  1190. public string Id { get; set; }
  1191. /// <summary>
  1192. /// 提示名称
  1193. /// </summary>
  1194. public string Name { get; set; }
  1195. /// <summary>
  1196. /// 提示详情
  1197. /// </summary>
  1198. public string Description { get; set; }
  1199. /// <summary>
  1200. /// 提示类型
  1201. /// </summary>
  1202. public int GuideType { get; set; }
  1203. public GuideNode NodeFrom()
  1204. {
  1205. var node = new GuideNode
  1206. {
  1207. Id = Id,
  1208. Name = Name,
  1209. GuideType = GuideType,
  1210. Description = Description,
  1211. };
  1212. return node;
  1213. }
  1214. public GuideModel ModelFrom(GuideNode node)
  1215. {
  1216. if (node == null)
  1217. {
  1218. return null;
  1219. }
  1220. Id = node.Id;
  1221. Name = node.Name;
  1222. GuideType = node.GuideType;
  1223. Description = node.Description;
  1224. return this;
  1225. }
  1226. }
  1227. public class EnvironResourceModel
  1228. {
  1229. public string Id { get; set; }
  1230. /// <summary>
  1231. /// 资源名称
  1232. /// </summary>
  1233. public string ResourceName { get; set; }
  1234. /// <summary>
  1235. /// 资源类型
  1236. /// </summary>
  1237. public int ResourceType { get; set; }
  1238. /// <summary>
  1239. /// 资源路径
  1240. /// </summary>
  1241. public string ResourcePath { get; set; }
  1242. /// <summary>
  1243. /// 资源描述
  1244. /// </summary>
  1245. public string Description { get; set; }
  1246. public string MessageCode { get; set; }
  1247. public EnvironResourceNode NodeFrom()
  1248. {
  1249. var node = new EnvironResourceNode
  1250. {
  1251. Id = Id,
  1252. ResourceName = ResourceName,
  1253. ResourceType = ResourceType,
  1254. ResourcePath = ResourcePath,
  1255. Description = Description,
  1256. MessageCode = MessageCode
  1257. };
  1258. return node;
  1259. }
  1260. public EnvironResourceModel ModelFrom(EnvironResourceNode node)
  1261. {
  1262. if (node == null)
  1263. {
  1264. return null;
  1265. }
  1266. Id = node.Id;
  1267. ResourceName = node.ResourceName;
  1268. ResourceType = node.ResourceType;
  1269. ResourcePath = node.ResourcePath;
  1270. MessageCode = node.MessageCode;
  1271. Description = node.Description;
  1272. return this;
  1273. }
  1274. }
  1275. public class RoleModel
  1276. {
  1277. public RoleModel()
  1278. {
  1279. }
  1280. public RoleModel(string roleNo, string roleName)
  1281. {
  1282. RoleNo = roleNo;
  1283. RoleName = roleName;
  1284. RoleWeight = 1;
  1285. TotalWeight = 1;
  1286. }
  1287. public RoleModel(string roleNo, string roleName, decimal roleWeight, decimal totalWeight)
  1288. {
  1289. RoleNo = roleNo;
  1290. RoleName = roleName;
  1291. RoleWeight = roleWeight;
  1292. TotalWeight = totalWeight;
  1293. }
  1294. public string RoleNo { get; set; }
  1295. public string RoleName { get; set; }
  1296. public decimal RoleWeight { get; }
  1297. public decimal TotalWeight { get; }
  1298. public decimal RolePer => Math.Round(TotalWeight == 0 ? 0 : RoleWeight * 100 / TotalWeight, 2);
  1299. public static RoleModel ModelFrom(string roles)
  1300. {
  1301. var node = new RoleNode();
  1302. var arr = roles.Split(':');
  1303. node.RoleNo = arr[0];
  1304. if (arr.Length > 1)
  1305. {
  1306. node.RoleName = arr[1];
  1307. }
  1308. if (arr.Length > 2)
  1309. {
  1310. node.SetWeight(int.TryParse(arr[2], out var w) ? w : 0);
  1311. }
  1312. if (arr.Length > 3)
  1313. {
  1314. node.SetTotalWeight(int.TryParse(arr[3], out var w) ? w : 0);
  1315. }
  1316. return new RoleModel(node.RoleNo, node.RoleName, node.RoleWeight, node.TotalWeight);
  1317. }
  1318. public override string ToString()
  1319. {
  1320. return new RoleNode(RoleNo, RoleName, RoleWeight, TotalWeight).ToString();
  1321. }
  1322. }
  1323. }