7 import play.api.data.Forms._
10 import models.services._
11 import infra.services._
13 import controllers.services._
15 import org.squeryl.PrimitiveTypeMode._
16 import scala.collection.mutable.ArrayBuffer
18 object NotifyController extends Controller{
20 var notifies :org.squeryl.Query[Notify] = null
22 val notifyRegistForm = Form(
24 "message" -> nonEmptyText,
26 "name" -> nonEmptyText
27 )(UserForm.apply)(UserForm.unapply),
31 )(AtachForm.apply)(AtachForm.unapply)
32 )(NotifyForm.apply)(NotifyForm.unapply)
35 def createNotify(partId: Long, designChangeId: Long, notifyType: Long) = Action{ implicit request =>
36 Ok(views.html.createNotifyForm(notifyRegistForm, partId, designChangeId, notifyType))
39 def notifyRegistration(partId: Long, designChangeId: Long, notifyType: Long) = Action(parse.multipartFormData) { implicit request =>
40 notifyRegistForm.bindFromRequest.fold(
41 formWithErrors => BadRequest(views.html.createNotifyForm(formWithErrors, partId, designChangeId, notifyType)),
42 // formWithErrors => BadRequest(views.html.error(formWithErrors)),
45 val announceUser = UserManager().getByName(notify.users.name)
46 val paramState = Integer.decode(notify.state)
47 val newNotify = NotifyManager().insert(notify, notifyType, partId, designChangeId, paramState)
48 request.body.file("atach").map { atach =>
49 AtachManager().uploadAtach(atach, notify.atach.grpName, 0, newNotify.id, 0)
51 var usersBuffer = ArrayBuffer[User]()
54 val targetPart = newNotify.part.head
55 val users = targetPart.project.head.users
56 val sendMail = SendMail(notifyType, announceUser.email, targetPart.id, 0, notifyType, paramState.longValue())
58 sendMail.sendMail(user.email)
63 val targetRelations = DesignChangeManager().getTargetRelationByDesignChangeId(designChangeId)
64 //各リレーションの上位品番と子品番のプロジェクトメンバー抽出
65 for(targetRelation <- targetRelations) {
66 var users = targetRelation.parent.head.project.head.users
67 users.copyToBuffer(usersBuffer)
68 users = targetRelation.child.head.project.head.users
69 users.copyToBuffer(usersBuffer)
71 //前述処理で抽出した全メンバーにメイル送信
72 val sendMail = SendMail(notifyType, announceUser.email, 0, designChangeId, notifyType, paramState.longValue())
73 for(user <- usersBuffer.distinct) {
74 sendMail.sendMail(user.email)
77 Ok(views.html.issueresult(notifyType, notifyType))
83 def showNotify(id: Long, partId: Long, designChangeId: Long, notifyType: Long, state: Long) = Action { implicit request =>
85 val notify = NotifyManager().getById(id)
86 val notifyForm = NotifyForm(notify.message, UserForm(notify.user.assign(notify.user.head).name), Messages("notify.state" + notify.state), null)
87 Ok(views.html.showNotifyForm(notifyRegistForm.fill(notifyForm), id, partId, designChangeId, notifyType, state, notify))
91 def updateState(id: Long, partId: Long, designChangeId: Long, notifyType: Long, state: Long) = Action { implicit request =>
93 val notify = NotifyManager().getById(id)
95 NotifyManager().update(notify)
96 val notifyForm = NotifyForm(notify.message, UserForm(notify.user.assign(notify.user.head).name), Messages("notify.state" + notify.state), null)
97 Ok(views.html.showNotifyForm(notifyRegistForm.fill(notifyForm),id, partId, designChangeId: Long, notifyType, state, notify))
101 def appendAtach(id: Long, partId: Long, designChangeId: Long, notifyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
102 notifyRegistForm.bindFromRequest.fold(
103 formWithErrors => BadRequest(views.html.showNotifyForm(formWithErrors, id, partId, designChangeId, notifyType, state, null)),
106 request.body.file("atach").map{ atach =>
107 AtachManager().uploadAtach(atach, notify.atach.grpName, 0, id, 0)
109 Redirect(routes.NotifyController.showNotify(id, partId, designChangeId, notifyType, state))
115 def listRecursion(page: Int, partId: Long, notifyType: Long, state: Long) = Action { implicit request =>
116 val notifyBuffer = ArrayBuffer[NotifyBean]()
118 val row = Integer.decode(Messages("list.row"))
119 val notifyPart = PartManager().getById(partId)
121 notifies = notifyPart.notifies.where(n => n.notifyType === notifyType)
123 notifies = notifyPart.notifies.where(n => n.notifyType === notifyType and n.state === state)
125 for(notify <- notifies) {
127 notifyBuffer += NotifyBean(i, notify.message, notify.user.head.name, notify.id, Messages("notify.state" + notify.state), notify.atachs)
128 for(reply <- notify.replies) {
129 // ReplyRecursion().down(reply, notifyBuffer, i)
130 for(returnNotifyBuffer <- ReplyRecursion().down(reply, i)) {
131 notifyBuffer += returnNotifyBuffer
135 Ok(views.html.notifylist(notifyBuffer.drop(page*row).take(row), notifyBuffer.size, partId, 0, notifyPart.name, page, notifyType, state))
140 def designChangeListRecursion(page: Int, designChangeId: Long, notifyType: Long, state: Long) = Action { implicit request =>
141 val notifyBuffer = ArrayBuffer[NotifyBean]()
143 val row = Integer.decode(Messages("list.row"))
144 val designChange = DesignChangeManager().getById(designChangeId)
146 notifies = designChange.notifies.where(n => n.notifyType === notifyType)
148 notifies = designChange.notifies.where(n => n.notifyType === notifyType and n.state === state)
150 for(notify <- notifies) {
152 notifyBuffer += NotifyBean(i, notify.message, notify.user.assign(notify.user.head).name, notify.id, Messages("notify.state" + notify.state), notify.atachs)
153 for(reply <- notify.replies) {
154 for(returnNotifyBuffer <- ReplyRecursion().down(reply, i)) {
155 notifyBuffer += returnNotifyBuffer
159 Ok(views.html.notifylist(notifyBuffer.drop(page*row).take(row), notifyBuffer.size, 0, designChange.id, designChange.dcNo, page, notifyType, state))