7 import play.api.data.Forms._
10 import models.services._
11 import infra.services._
12 import controllers.services._
14 import org.squeryl.PrimitiveTypeMode._
15 import scala.collection.immutable.Seq
16 import com.google.inject._
19 object ReplyController extends Controller{
20 val inject = Guice.createInjector(new ServiceModules)
21 val sendMail = inject.getInstance(classOf[SendMail])
22 val replyRegistForm = Form(
24 "message" -> nonEmptyText,
26 "name" -> nonEmptyText
27 )(UserForm.apply)(UserForm.unapply),
30 }(AtachForm.apply)(AtachForm.unapply)
31 )(ReplyForm.apply)(ReplyForm.unapply)
34 def createReply(notifyId: Long, replyId: Long, notifyType: Long, replyType: Long, partId: Long, state: Long) = AuthAction {
35 Action { implicit request =>
37 Ok(views.html.errors.errorNotAuthentication())
39 var logInUser = UserForm("")
40 request.headers.get("remote_user").map { user =>
41 logInUser = UserForm(user)
43 Ok(views.html.createReplyForm(replyRegistForm.fill(ReplyForm("", logInUser, null)), notifyId, replyId, replyType, partId, notifyType, state))
48 def replyRegistration(notifyId: Long, replyId: Long, partId: Long, notifyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
49 replyRegistForm.bindFromRequest.fold(
50 formWithErrors => BadRequest(views.html.createReplyForm(formWithErrors, notifyId, replyId, 0, partId, notifyType, state)),
53 val replyUser = UserManager().getByName(reply.users.name)
54 val newReply = ReplyManager().insert(reply, replyUser, notifyId, replyId)
55 var usersBuffer = Seq[User]()
56 request.body.file("atach").map { atach =>
57 AtachManager().uploadAtach(atach, newReply.atach.grpName, 0, 0, newReply.id)
59 var notify: Notify = null
61 // 通知直下のreplyの場合、notifyより対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
62 notify = NotifyManager().getById(notifyId)
64 // reply配下のreplyの場合、再帰処理によりnotify抽出後、対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
65 val targetReply = ReplyManager().getById(replyId)
66 val topReply = ReplyRecursion().up(targetReply)
67 notify = NotifyManager().getById(topReply.notifyId)
69 // 部品表通知/依頼の回答であれば、Notifyが紐付くPartのプロジェクトメンバにメイル通知。
70 if(notifyType == 0 || notifyType == 1) {
71 val targetPart = notify.part.head
72 val users = targetPart.project.head.users
74 sendMail.sendMail(2, replyUser.email, targetPart.id, 0, notifyType, state, user.email)
77 // 設計変更通知/依頼の回答であれば、Notifyが紐付くDesin ChangeのdelRelation、addRelationの全ての上品番、
78 // 子品番のプロジェクトメンバにメイル通知。
79 if(notifyType == 3 || notifyType == 4) {
81 val targetRelations = notify.designCgange.head.delPartRelation.++:(notify.designCgange.head.addPartRelation)
82 //各リレーションの上位品番と子品番のプロジェクトメンバー抽出
83 for(targetRelation <- targetRelations) {
84 var users = targetRelation.parent.head.project.head.users
88 users = targetRelation.child.head.project.head.users
93 for(user <- usersBuffer.distinct) {
94 sendMail.sendMail(2, replyUser.email, 0, notify.designCgange.head.id, notifyType, state, user.email)
98 Ok(views.html.issueresult(2, notifyType))
103 def showReply(id: Long, partId: Long, designChangeId: Long, notifyType: Long, replyType: Long, state: Long) = AuthAction {
104 Action { implicit request =>
105 if(request == null) {
106 Ok(views.html.errors.errorNotAuthentication())
109 val reply = ReplyManager().getById(id)
110 val replyForm = ReplyForm(reply.message, UserForm(reply.user.assign(reply.user.head).name), null)
111 Ok(views.html.showReplyForm(replyRegistForm.fill(replyForm), id, partId, designChangeId, notifyType, replyType, state, reply))
117 def appendAtach(id: Long, partId: Long, designChangeId: Long, notifyType: Long, replyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
118 replyRegistForm.bindFromRequest.fold(
119 formWithErrors => BadRequest(views.html.showReplyForm(formWithErrors, id, partId, designChangeId, notifyType, replyType, state, null)),
120 // formWithErrors => BadRequest(views.html.error(formWithErrors)),
123 request.body.file("atach").map { atach =>
124 AtachManager().uploadAtach(atach, reply.atach.grpName, 0, 0, id)
126 Redirect(routes.ReplyController.showReply(id, partId, designChangeId, notifyType, replyType, state))