bulletin.go 2.9 KB
package controllers

import (
	"encoding/json"
	"oppmg/common/log"
	"oppmg/protocol"
	"oppmg/services/bulletin"
)

type BulletinController struct {
	BaseController
}

//BulletinRelease
//@router /add [post]
func (this *BulletinController) BulletinRelease() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.BulletinReleaseRequest
	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if !(request.Type == 1 || request.Type == 2) {
		msg = protocol.BadRequestParam("1")
		log.Error("type error :%v", request.Type)
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := bulletin.BulletinRelease(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
	return
}

//BulletinList
//@router /list [post]
func (this *BulletinController) BulletinList() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.BulletinListRequest
	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		msg = protocol.BadRequestParam("1")
		return
	}
	rsp, err := bulletin.BulletinList(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//GetBulletin
//@router /get [post]
func (this *BulletinController) GetBulletin() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.GetBulletinRequest
	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		msg = protocol.BadRequestParam("1")
		return
	}
	rsp, err := bulletin.GetBulletin(request.Id, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//UpdateBulletin
//@router /update [post]
func (this *BulletinController) UpdateBulletin() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.UpdateBulletinRequest
	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		msg = protocol.BadRequestParam("1")
		return
	}
	rsp, err := bulletin.UpdateBulletin(companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}