From e38b2dd55820c622410645563214e819d5063cec Mon Sep 17 00:00:00 2001 From: uyaji Date: Tue, 24 Sep 2013 19:16:16 +0900 Subject: [PATCH] Implementation the cancelDesignCgangeByLine method. --- .../app/controllers/DesignChangeController.scala | 50 ++++++++++++++++++++++ .../app/controllers/PartsListController.scala | 46 -------------------- .../app/models/services/DesignChangeManager.scala | 18 +++++++- .../app/views/designChangeRelationForm.scala.html | 2 +- .../app/views/updateDesignChangeForm.scala.html | 2 + PartsList/PartsList/conf/routes | 5 ++- 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/PartsList/PartsList/app/controllers/DesignChangeController.scala b/PartsList/PartsList/app/controllers/DesignChangeController.scala index e2ff4ff..0b0785d 100644 --- a/PartsList/PartsList/app/controllers/DesignChangeController.scala +++ b/PartsList/PartsList/app/controllers/DesignChangeController.scala @@ -16,6 +16,7 @@ import models.PartRelation object DesignChangeController extends Controller{ val Home = Redirect(routes.DesignChangeController.list(0,"")) + val Home2 = Redirect(routes.PartsListController.index(0,0,"")) val designChangeRegistForm = Form( mapping( @@ -97,6 +98,55 @@ object DesignChangeController extends Controller{ Redirect(routes.DesignChangeController.designChangeCoverModify(id, 0, "")) } } + + def designChangeCancelByLine(designChangeId: Long, delParentName: String, delChildName: String, addParentName: String, addChildName: String) = Action { + inTransaction { + val designChange = DesignChangeManager().getById(designChangeId) + if(!delParentName.isEmpty()) { + val delParent = PartManager().getByName(delParentName) + val delChild = PartManager().getByName(delChildName) + val cancelDelRelation = designChange.delPartRelation.where(pr => pr.parentId === delParent.id and pr.childId === delChild.id).head + DesignChangeManager().designChangeDelCancelBySeq(designChangeId, cancelDelRelation.dcSeq) + } + if(!addParentName.isEmpty()) { + val addParent = PartManager().getByName(addParentName) + val addChild = PartManager().getByName(addChildName) + val cancelAddRelation = designChange.addPartRelation.where(pr => pr.parentId === addParent.id and pr.childId === addChild.id).head + DesignChangeManager().designChangeAddCancelBySeq(designChangeId, cancelAddRelation.dcSeq) + } + } + Redirect(routes.DesignChangeController.designChangeCoverModify(designChangeId, 0, "")) + } + + def designChangeForm(parentName:String, childName:String) = Action { implicit request => + inTransaction { + var designChangeRelationForm = DesignChangeRelationForm(null, null, "") + // 設計変更追加の場合、変更前の上位品番はセットしない。 + if(childName.isEmpty()) { + designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean("", childName), generatePartsListBean(parentName, childName), "") + } else { + designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean(parentName, childName), generatePartsListBean(parentName, childName), "") + } + Ok(views.html.designChangeRelationForm(designChangeRelationRegistForm.fill(designChangeRelationForm), "")) + } + } + + def designChange() = Action { implicit request => + designChangeRelationRegistForm.bindFromRequest.fold( + formWithErrors => BadRequest(views.html.designChangeRelationForm(formWithErrors, "")), + data => { + inTransaction { + val message = Check().loopCheckDc(data) + if(message == null) { + DesignChangeManager().designChange(data) + Home2.flashing("success" -> "Relation %s has been changed".format(data.partsListBeanBefore.parent + "/" + data.partsListBeanBefore.child)) + } else { + Ok(views.html.designChangeRelationForm(designChangeRelationRegistForm.fill(data), Messages(message))) + } + } + } + ) + } def designChangeAppend(designChangeId: Long, dcSeq: Long, targetParentName: String) = Action { inTransaction { diff --git a/PartsList/PartsList/app/controllers/PartsListController.scala b/PartsList/PartsList/app/controllers/PartsListController.scala index b99a012..8a72d7b 100644 --- a/PartsList/PartsList/app/controllers/PartsListController.scala +++ b/PartsList/PartsList/app/controllers/PartsListController.scala @@ -26,22 +26,6 @@ object PartsListController extends Controller{ )(PartsListBean.apply)(PartsListBean.unapply) ) - val designChangeRegistForm = Form( - mapping( - "partsListBeanBefore" -> mapping( - "parent" -> text, - "child" -> text, - "quantity" -> longNumber - )(PartsListBean.apply)(PartsListBean.unapply), - "partsListBeanAfter" -> mapping( - "parent" -> nonEmptyText, - "child" -> text, - "quantity" -> longNumber - )(PartsListBean.apply)(PartsListBean.unapply), - "dcno" -> nonEmptyText - )(DesignChangeRelationForm.apply)(DesignChangeRelationForm.unapply) - ) - def index(opt:Int, page:Int, key:String) = Action { implicit request => var partBuffer = ArrayBuffer[PartsListBean]() inTransaction { @@ -116,36 +100,6 @@ object PartsListController extends Controller{ } } - def designChangeForm(parentName:String, childName:String) = Action { implicit request => - inTransaction { - var designChangeRelationForm = DesignChangeRelationForm(null, null, "") - // 設計変更追加の場合、変更前の上位品番はセットしない。 - if(childName.isEmpty()) { - designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean("", childName), generatePartsListBean(parentName, childName), "") - } else { - designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean(parentName, childName), generatePartsListBean(parentName, childName), "") - } - Ok(views.html.designChangeRelationForm(designChangeRegistForm.fill(designChangeRelationForm), "")) - } - } - - def designChange() = Action { implicit request => - designChangeRegistForm.bindFromRequest.fold( - formWithErrors => BadRequest(views.html.designChangeRelationForm(formWithErrors, "")), - data => { - inTransaction { - val message = Check().loopCheckDc(data) - if(message == null) { - DesignChangeManager().designChange(data) - Home.flashing("success" -> "Relation %s has been changed".format(data.partsListBeanBefore.parent + "/" + data.partsListBeanBefore.child)) - } else { - Ok(views.html.designChangeRelationForm(designChangeRegistForm.fill(data), Messages(message))) - } - } - } - ) - } - def generatePartsListBean(parentNo:String, childNo:String):PartsListBean = { if(childNo.isEmpty()) { PartsListBean(parentNo, childNo, 0) diff --git a/PartsList/PartsList/app/models/services/DesignChangeManager.scala b/PartsList/PartsList/app/models/services/DesignChangeManager.scala index d19206a..876b590 100644 --- a/PartsList/PartsList/app/models/services/DesignChangeManager.scala +++ b/PartsList/PartsList/app/models/services/DesignChangeManager.scala @@ -72,7 +72,7 @@ case class DesignChangeManager() { return designChangeBuffer } - def designChangeCancel(id: Long) ={ + def designChangeCancel(id: Long) = { val cancelDesignChange = getById(id) for (cancelAddRelation <- cancelDesignChange.addPartRelation) { cancelAddRelation.parent.head.parts.dissociate(cancelAddRelation.child.head) @@ -83,6 +83,20 @@ case class DesignChangeManager() { PartsListDb.partRelations.update(cancelDelRelation) } } + + def designChangeAddCancelBySeq(designChangeId: Long, dcSeq: Long) = { + val designChange = getById(designChangeId) + val cancelAddRelation = designChange.addPartRelation.where(pr => pr.dcSeq === dcSeq).head + cancelAddRelation.parent.head.parts.dissociate(cancelAddRelation.child.head) + } + + def designChangeDelCancelBySeq(designChangeId: Long, dcSeq: Long) = { + val designChange = getById(designChangeId) + val cancelDelRelation = designChange.delPartRelation.where(pr => pr.dcSeq === dcSeq).head + cancelDelRelation.delDcId = 0L + cancelDelRelation.dcSeq = 0L + PartsListDb.partRelations.update(cancelDelRelation) + } def designChangeUpdate(data: DesignChangeRelationForm, partName: String) = { val dc = getByName(data.dcno) @@ -98,7 +112,7 @@ case class DesignChangeManager() { val updateRelation = dc.addPartRelation.where(pr => pr.parentId === parent.id and pr.childId === cancelChild.id).head val dcSeq = updateRelation.dcSeq - PartsListDb.partRelations.deleteWhere(pr => pr.addDcId === dc.id and pr.dcSeq === dcSeq) + updateRelation.parent.head.parts.dissociate(updateRelation.child.head) relationAdd(parent.name, child.name, data.partsListBeanAfter.quantity, dc, dcSeq) } } diff --git a/PartsList/PartsList/app/views/designChangeRelationForm.scala.html b/PartsList/PartsList/app/views/designChangeRelationForm.scala.html index 7af335b..ff6e8bc 100644 --- a/PartsList/PartsList/app/views/designChangeRelationForm.scala.html +++ b/PartsList/PartsList/app/views/designChangeRelationForm.scala.html @@ -4,7 +4,7 @@ @main("Design Change by Play 2.1") {

@Messages("title21")

@error - @form(routes.PartsListController.designChange()) { + @form(routes.DesignChangeController.designChange()) { @commonDesignChangeRelationForm(designChangeRelationForm) }
diff --git a/PartsList/PartsList/app/views/updateDesignChangeForm.scala.html b/PartsList/PartsList/app/views/updateDesignChangeForm.scala.html index ded4835..7b64166 100644 --- a/PartsList/PartsList/app/views/updateDesignChangeForm.scala.html +++ b/PartsList/PartsList/app/views/updateDesignChangeForm.scala.html @@ -25,6 +25,7 @@ @Messages("form.header11")@Messages("list.header1") @Messages("form.header11")@Messages("list.header2") @Messages("form.header11")@Messages("list.header3") + @@ -43,6 +44,7 @@ @delRelation.quantityAfter } + @Messages("list.link14") } diff --git a/PartsList/PartsList/conf/routes b/PartsList/PartsList/conf/routes index cf9e2ef..6c19e49 100644 --- a/PartsList/PartsList/conf/routes +++ b/PartsList/PartsList/conf/routes @@ -20,13 +20,14 @@ GET /relationCreate controllers.PartsListController.createRelation(paren POST /relationSave controllers.PartsListController.relationRegistration GET /relationUpdate controllers.PartsListController.updateRelation(parent:String, child:String) POST /relationChange controllers.PartsListController.relationUpdate(childName:String) -GET /designChangeForm controllers.PartsListController.designChangeForm(parentName, childName) -POST /designChange controllers.PartsListController.designChange GET /designChangeCoverForm controllers.DesignChangeController.create POST /designChangeCover controllers.DesignChangeController.designChangeCoverRegistration GET /designChangeCoverModify controllers.DesignChangeController.designChangeCoverModify(designChangeId:Long, dcSeq:Long, message:String) POST /designChangeCoverModification controllers.DesignChangeController.designChangeCoverModification(id: Long) +GET /designChangeForm controllers.DesignChangeController.designChangeForm(parentName, childName) +POST /designChange controllers.DesignChangeController.designChange POST /designChangeCancel controllers.DesignChangeController.designChangeCancel(id:Long) +GET /designChangeCancelByLine controllers.DesignChangeController.designChangeCancelByLine(designChangeId:Long, delParent:String, delChild:String, addParent:String, addChild:String) GET /designChangeAppend controllers.DesignChangeController.designChangeAppend(designChangeId:Long, dcSeq:Long, parentName:String) GET /designChangeModify controllers.DesignChangeController.designChangeRealtionModify(designChangeId: Long, dcDelSeq: Long, dcAddSeq: Long) POST /designChangeModification controllers.DesignChangeController.designChangeRelationModification(partName: String) -- 2.11.0