5 import play.api.data.Forms._
11 import org.squeryl.PrimitiveTypeMode._
12 import scala.collection.mutable.ArrayBuffer
13 object ReplyController extends Controller{
14 val replyRegistForm = Form(
16 "message" -> nonEmptyText,
18 "name" -> nonEmptyText
19 )(UserForm.apply)(UserForm.unapply),
22 }(AtachForm.apply)(AtachForm.unapply)
23 )(ReplyForm.apply)(ReplyForm.unapply)
26 def createReply(notifyId: Long, replyId: Long, notifyType: Long, replyType: Long, partId: Long, state: Long) = Action { implicit request =>
27 Ok(views.html.createReplyForm(replyRegistForm, notifyId, replyId, replyType, partId, notifyType, state))
30 def replyRegistration(notifyId: Long, replyId: Long, partId: Long, notifyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
31 replyRegistForm.bindFromRequest.fold(
32 formWithErrors => BadRequest(views.html.createReplyForm(formWithErrors, notifyId, replyId, 0, partId, notifyType, state)),
35 val replyUser = PartsListDb.users.where(u => u.name like reply.users.name + "%").head
36 val newReply = PartsListDb.replies.insert(Reply(reply.message, replyUser.id, notifyId, replyId, reply.atach))
37 var usersBuffer = ArrayBuffer[User]()
38 request.body.file("atach").map { atach =>
39 AtachManager().uploadAtach(atach, newReply.atach.grpName, 0, 0, newReply.id)
41 var notify: Notify = null
43 // 通知直下のreplyの場合、notifyより対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
44 notify = PartsListDb.notifies.where(n => n.id === notifyId).head
46 // reply配下のreplyの場合、再帰処理によりnotify抽出後、対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
47 val targetReply = PartsListDb.replies.where(tr => tr.id === replyId).head
48 val topReply = upRecursion(targetReply)
49 notify = PartsListDb.notifies.where(n => n.id === topReply.notifyId).head
51 // 部品表通知/依頼の回答であれば、Notifyが紐付くPartのプロジェクトメンバにメイル通知。
52 if(notifyType == 0 || notifyType == 1) {
53 val targetPart = notify.part.assign(notify.part.head)
54 val users = targetPart.project.assign(targetPart.project.head).users
55 val sendMail = SendMail(2, replyUser.email, targetPart.id, 0, notifyType, state)
57 sendMail.sendMail(user.email)
60 // 設計変更通知/依頼の回答であれば、Notifyが紐付くDesin ChangeのdelRelation、addRelationの全ての上品番、
61 // 子品番のプロジェクトメンバにメイル通知。
62 if(notifyType == 3 || notifyType == 4) {
64 val targetRelations = notify.designCgange.assign(notify.designCgange.head).delPartRelation.++:(notify.designCgange.assign(notify.designCgange.head).addPartRelation)
65 //各リレーションの上位品番と子品番のプロジェクトメンバー抽出
66 for(targetRelation <- targetRelations) {
67 var users = targetRelation.parent.head.project.assign(targetRelation.parent.head.project.head).users
68 users.copyToBuffer(usersBuffer)
69 users = targetRelation.child.head.project.assign(targetRelation.child.head.project.head).users
70 users.copyToBuffer(usersBuffer)
72 val sendMail = SendMail(2, replyUser.email, 0, notify.designCgange.head.id, notifyType, state)
73 for(user <- usersBuffer.distinct) {
74 sendMail.sendMail(user.email)
78 Ok(views.html.issueresult(2, notifyType))
83 def showReply(id: Long, partId: Long, notifyType: Long, replyType: Long, state: Long) = Action { implicit request =>
85 val reply = PartsListDb.replies.where(r => r.id === id).head
86 val replyForm = ReplyForm(reply.message, UserForm(reply.user.assign(reply.user.head).name), null)
87 Ok(views.html.showReplyForm(replyRegistForm.fill(replyForm), id, partId, notifyType, replyType, state, reply))
91 def upRecursion(reply: Reply):Reply = {
92 if(reply.parentReply.size == 0) {
95 println("Messages " + reply.message)
96 upRecursion(reply.parentReply.head)
100 def appendAtach(id: Long, partId: Long, notifyType: Long, replyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
101 replyRegistForm.bindFromRequest.fold(
102 formWithErrors => BadRequest(views.html.showReplyForm(formWithErrors, id, partId, notifyType, replyType, state, null)),
103 // formWithErrors => BadRequest(views.html.error(formWithErrors)),
106 request.body.file("atach").map { atach =>
107 AtachManager().uploadAtach(atach, reply.atach.grpName, 0, 0, id)
109 Redirect(routes.ReplyController.showReply(id, partId, notifyType, replyType, state))