bulletin.go 3.1 KB
package controllers

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

type BulletinController struct {
	BaseController
}

//BulletinRelease
//@router /release [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 {
		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
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
	//}
	param := this.Ctx.Input.Param(":id")
	id, _ := strconv.ParseInt(param, 10, 64)
	if id == 0 {
		msg = protocol.BadRequestParam("1")
		return
	}
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		msg = protocol.BadRequestParam("1")
		return
	}
	rsp, err := bulletin.GetBulletin(int(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)
}