import modules._
import scala.io.Source
import java.io.FileInputStream
-import scala.concurrent.Future
+
import play.api.libs.concurrent.Execution.Implicits._
+import scala.concurrent.Future
-object PartsListController extends Controller{
+object PartsListController extends Controller{
val inject = Guice.createInjector(new ServiceModules)
val projectManager = inject.getInstance(classOf[ProjectManager])
val Home = Redirect(routes.PartsListController.index(0,0,"",""))
"grpName" -> text
)(CsvForm.apply)(CsvForm.unapply)
)
-
- def index(opt:Int, page:Int, key:String, relationKey:String) = AuthAction {
+
+ def index(opt:Int, page:Int, key:String, relationKey:String) = AuthAction {
Action { implicit request =>
if(request == null) {
Ok(views.html.errors.errorNotAuthentication())
if(request == null) {
Ok(views.html.errors.errorNotAuthentication())
} else {
- val futureOfPartsBuffer: Future[Seq[PartsListShowBean]] = Future {
- inTransaction {
- PartsList().getPartsBuffer(opt, page, key, relationKey)
+ val futureOfPartsBuffer: Future[Seq[PartsListShowBean]] = Future {
+ inTransaction {
+ PartsList().getPartsBuffer(opt, page, key, relationKey)
+ }
}
- }
- val attachment = "attachment; filename=" + key + "_download.csv"
- Async {
- futureOfPartsBuffer.map { fpb =>
- Ok(views.html.partsListsCsv(fpb)).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv")
+ val attachment = "attachment; filename=" + key + "_download.csv"
+// Ok(views.html.partsListsCsv(scala.concurrent.Await.result(futureOfPartsBuffer, scala.concurrent.duration.Duration.Inf))).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv")
+ Async {
+ futureOfPartsBuffer.map { fpb =>
+ var totalCost:Long =0
+ fpb.map(pb =>
+ totalCost += pb.cost
+ )
+ println("Check2")
+ Ok(views.html.partsListsCsv(fpb)).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv")
+ }
}
- }
}
}
}
}
}
-}
\ No newline at end of file
+}
import models._
import beans._
import scala.collection.immutable.Seq
+
case class PartRecursion(){
def down(parentPart: Part, parentQuantity: Long, opt: Int, key: String):Seq[PartsListShowBean] = {
+ println("*********** Check2 **********")
var partBuffer = Seq[PartsListShowBean]()
- for(child <-parentPart.parts) {
- val pr = parentPart.partRelation(child.id)
+ parentPart.parts.map(ch => {
+ val pr = parentPart.partRelation(ch.id)
if(pr.delDcId==0) {
var quantity:Long = 0
if(opt==2) {
- quantity = parentQuantity * pr.quantity
- } else {
- quantity = pr.quantity
- }
- if(opt!=3 || opt==3 && child.name.startsWith("Unit")) {
+ quantity = parentQuantity * pr.quantity
+ } else {
+ quantity = pr.quantity
+ }
+ if(opt!=3 || opt==3 && ch.name.startsWith("Unit")) {
if(key.isEmpty()) {
- partBuffer = partBuffer.:+(PartsListShowBean(parentPart.name, child, quantity, pr.relationKey, quantity * child.price))
+ partBuffer = partBuffer.:+(PartsListShowBean(parentPart.name, ch, quantity, pr.relationKey, quantity * ch.price))
} else {
if(pr.relationKey.equals(key)) {
- partBuffer = partBuffer.:+(PartsListShowBean(parentPart.name, child, quantity, pr.relationKey, quantity * child.price))
- }
- }
- }
- if(opt==1 || opt==2 && child.price.==(0) || opt==3) {
- val partBuffers = PartRecursion().down(child, quantity, opt, key)
- for (returnPartBuffer <- partBuffers) {
- partBuffer = partBuffer.:+(returnPartBuffer)
- }
- }
- }
- }
+ partBuffer = partBuffer.:+(PartsListShowBean(parentPart.name, ch, quantity, pr.relationKey, quantity * ch.price))
+ }
+ }
+ }
+ if(opt==1 || opt==2 && ch.price.==(0) || opt==3) {
+ down(ch, quantity, opt, key).par.map(rpb => partBuffer = partBuffer.:+(rpb))
+ }
+ }
+ })
return partBuffer
}
def up(childPart: Part, opt: Int): Seq[PartsListBean] = {
var partBuffer = Seq[PartsListBean]()
if(childPart.parentParts.size == 0 && opt == 2) {
- partBuffer = partBuffer.:+(PartsListBean("", childPart.name, 0, ""))
- }
- for(parent <- childPart.parentParts) {
- if(parent.partRelation(childPart.id).delDcId == 0 ) {
- if(opt != 2) {
- val pr = parent.partRelation(childPart.id)
- partBuffer = partBuffer.:+(PartsListBean(childPart.name, parent.name, pr.quantity, pr.relationKey))
- }
- if(opt != 1) {
- for(returnPartBuffer <- PartRecursion().up(parent, opt)) {
- partBuffer = partBuffer.:+(returnPartBuffer)
- }
- }
- }
- }
- return partBuffer
+ partBuffer = partBuffer.:+(PartsListBean("", childPart.name, 0, ""))
+ }
+ childPart.parentParts.map( prt => {
+ if(prt.partRelation(childPart.id).delDcId == 0 ) {
+ if(opt != 2) {
+ val pr = prt.partRelation(childPart.id)
+ partBuffer = partBuffer.:+(PartsListBean(childPart.name, prt.name, pr.quantity, pr.relationKey))
+ }
+ if(opt != 1) {
+ up(prt, opt).par.map(rpb => partBuffer = partBuffer.:+(rpb))
+ }
+ }
+ })
+ return partBuffer
}
-
}
\ No newline at end of file
package controllers.services
import scala.collection.immutable.Map
import scala.collection.immutable.Seq
-import org.squeryl.PrimitiveTypeMode._
import beans._
import models._
import models.services._
+import scala.concurrent.Future
+import scala.concurrent.ExecutionContext
+import scala.concurrent.Await
+import scala.concurrent.duration.Duration
+import scala.util.Success
+import scala.util.Failure
+import org.squeryl.PrimitiveTypeMode._
+
case class PartsList() {
- def getPartsBuffer(opt:Int, page:Int, key:String, relationKey:String):Seq[PartsListShowBean] = {
- var partsBuffer = Seq[PartsListShowBean]()
- val targetParts = PartManager().getByName(key)
- if(targetParts.size != 0) {
- for(returnPartBuffer <- PartRecursion().down(PartManager().getByName(key).head, 1, opt, relationKey)) {
- partsBuffer = partsBuffer.:+(returnPartBuffer)
- }
- }
- return partsBuffer
- }
+ def getPartsBuffer(opt:Int, page:Int, key:String, relationKey:String):Seq[PartsListShowBean] = {
+ import ExecutionContext.Implicits.global
+ var partsBuffer = Seq[PartsListShowBean]()
+ val targetParts = PartManager().getByName(key)
+ if(targetParts.size != 0) {
+// PartRecursion().down(PartManager().getByName(key).head, 1, opt, relationKey).par.map(rpb => partsBuffer = partsBuffer.:+(rpb))
+ val futurePartBuffer:Future[Seq[PartsListShowBean]] = Future{
+ inTransaction {
+ PartRecursion().down(PartManager().getByName(key).head, 1, opt, relationKey)
+ }
+ }
+// futurePartBuffer.map(rpbs => rpbs.par.map(rpb => partsBuffer = partsBuffer.:+(rpb)))
- def getMatrixPartsList(partsListBeans: Seq[Seq[PartsListShowBean]], allChildren: Seq[Part]): Map[Part, Seq[MultiPartsListBean]] = {
- var matrixPartsListBeans = Map[Part, Seq[MultiPartsListBean]]()
- // 抽出した各モデル毎の部品表配列に対し、部品の有無をチェエク
- for(partsListBean <- partsListBeans) {
- var allChildrenList = Seq[MultiPartsListBean]()
- // 全ての部品一覧作成
- for(child <- allChildren.distinct.sortBy(p => p.name)) {
- allChildrenList = allChildrenList.:+(MultiPartsListBean(child, 1))
- }
- // 比較対象モデルの部品一覧作成
- var targetChildren = Seq[MultiPartsListBean]()
- for(targetChildlist <- partsListBean) {
- targetChildren = targetChildren.:+(MultiPartsListBean(targetChildlist.child, 1))
- }
- // 全ての部品一覧の各部品が、比較対象モデルの部品一覧に存在するかチェック。
- if(partsListBean.size !=0 ) {
- for(compare <- allChildrenList) {
- if(!targetChildren.contains(compare)) {
- //存在しない場合、表示をOff
- val position:Int = allChildrenList.indexOf(compare)
- allChildrenList(position).showOn = 0
- }
- }
- // 表示制御済みの部品表配列を蓄積
- matrixPartsListBeans = matrixPartsListBeans.+((PartManager().getByName(partsListBean.head.parent).head, allChildrenList))
- // 構成部品なしの場合、全部品を表示Off
- } else {
- for(allChild <- allChildrenList) {
- allChild.showOn = 0
- }
- // 表示制御済みの部品表配列を蓄積
- matrixPartsListBeans =matrixPartsListBeans.+((null, allChildrenList))
+/* futurePartBuffer onComplete {
+ case Success(rpbs) => {
+ println("************** Check *********************** = " + rpbs.size)
+ rpbs.map(
+ rpb => {
+ partsBuffer = partsBuffer.:+(rpb)
+ println(rpb.parent + "/" + rpb.child.name )
+ }
+ )
+ }
+ case Failure(t) => println("エラーが発生しました。" + t.getMessage())
+ }*/
+
+/* futurePartBuffer map {
+ rpbs => {
+ println("************** Check *********************** = " + rpbs.size)
+ rpbs.map(
+ rpb => {
+ partsBuffer = partsBuffer.:+(rpb)
+ println(rpb.parent + "/" + rpb.child.name )
+ }
+ )
+ }
+ }*/
+
+ // 上の2つの処理は共にNonBlockingなので、部品表の展開をまたず、空のpartsBufferを返却し、画面表示(何も表示されない)
+ // 対して、以下の処理は明示的なブロッキング待機なので、部品表展開を待って、partsBufferを蓄積し、画面表示(部品表が表示される)
+ Await.result(futurePartBuffer, Duration.Inf).map(rpb => {
+ println(rpb.parent + "/" + rpb.child.name )
+ partsBuffer = partsBuffer.:+(rpb)
+ })
+ }
+ println("** Check3 **")
+ partsBuffer
+ }
+
+ def getMatrixPartsList(partsListBeans: Seq[Seq[PartsListShowBean]], allChildren: Seq[Part]): Map[Part, Seq[MultiPartsListBean]] = {
+ var matrixPartsListBeans = Map[Part, Seq[MultiPartsListBean]]()
+ // 抽出した各モデル毎の部品表配列に対し、部品の有無をチェエク
+ partsListBeans.map(plb => {
+ var allChildrenList = Seq[MultiPartsListBean]()
+ // 全ての部品一覧作成
+ allChildren.distinct.sortBy(p => p.name).map(ch => allChildrenList = allChildrenList.:+(MultiPartsListBean(ch, 1)))
+ // 比較対象モデルの部品一覧作成
+ var targetChildren = Seq[MultiPartsListBean]()
+ plb.par.map(tch => targetChildren = targetChildren.:+(MultiPartsListBean(tch.child, 1)))
+ // 全ての部品一覧の各部品が、比較対象モデルの部品一覧に存在するかチェック。
+ if(plb.size !=0 ) {
+ allChildrenList.par.map(comp => {
+ if(!targetChildren.contains(comp)) {
+ //存在しない場合、表示をOff
+ val position:Int = allChildrenList.indexOf(comp)
+ allChildrenList(position).showOn = 0
}
- }
- return matrixPartsListBeans
- }
+ })
+ // 表示制御済みの部品表配列を蓄積
+ matrixPartsListBeans = matrixPartsListBeans.+((PartManager().getByName(plb.head.parent).head, allChildrenList))
+ // 構成部品なしの場合、全部品を表示Off
+ } else {
+ allChildrenList.par.map(ac => ac.showOn = 0)
+ // 表示制御済みの部品表配列を蓄積
+ matrixPartsListBeans =matrixPartsListBeans.+((null, allChildrenList))
+ }
+ })
+ matrixPartsListBeans
+ }
}
\ No newline at end of file