OSDN Git Service

Refactoring to PartsListController
[open-pdm-light/PartList.git] / PartsList / PartsList / app / controllers / services / Recursion.scala
1 package controllers.services
2 import models._
3 import beans._
4 import scala.collection.mutable.ArrayBuffer
5 case class Recursion() {
6   
7   def down(parentPart: Part, partBuffer: ArrayBuffer[PartsListBean], opt: Int):Unit = {
8     for(child <-parentPart.parts) {
9       if(parentPart.partRelation(child.id).delDcId==0) {
10         if(opt!=3 || opt==3 && child.name.startsWith("Unit")) {
11                 partBuffer += PartsListBean(parentPart.name, child.name, parentPart.partRelation(child.id).quantity)
12              }
13             if(opt==1 || opt==2 && !child.name.startsWith("Part") || opt==3) {
14               Recursion().down(child, partBuffer, opt)
15             }
16            }
17     }
18   }
19   
20   def up(childPart: Part, partBuffer: ArrayBuffer[PartsListBean], opt: Int):Unit = {
21     if(childPart.parentParts.size == 0 && opt == 2) {
22            partBuffer += PartsListBean("", childPart.name,0)
23          }
24          for(parent <- childPart.parentParts) {
25            if(parent.partRelation(childPart.id).delDcId == 0 ) {
26              if(opt != 2) {
27                partBuffer += PartsListBean(childPart.name, parent.name, parent.partRelation(childPart.id).quantity)
28               }
29                   if(opt != 1) {
30                     Recursion().up(parent, partBuffer, opt)
31                   }
32                 }
33           }
34
35   }
36
37 }