achievement.go 2.5 KB
package controllers

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

type AchievementController struct {
	BaseController
}

//AchievementList 成果列表
//@router /achievement/list
func (c AchievementController) AchievementList() {
	var msg *protocol.ResponseMessage
	defer func() {
		c.ResposeJson(msg)
	}()
	type Parameter struct {
		protocol.RequestPageInfo
		Status int `json:"status"`
	}
	var param Parameter
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
		log.Error("json 解析失败 err:%s", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	companyid := c.GetCompanyId()
	rspdata := serveachievement.GetAchievementList(param.PageIndex, param.PageSize, companyid, param.Status)
	msg = protocol.NewReturnResponse(rspdata, nil)
	return
}

//AddAchievement 添加成果列表
//@router /achievement/add
func (c AchievementController) AddAchievement() {
	var msg *protocol.ResponseMessage
	defer func() {
		c.ResposeJson(msg)
	}()

	var param protocol.RequestAddAchievement
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
		log.Error("json 解析失败 err:%s", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	companyid := c.GetCompanyId()
	err := serveachievement.AddAchievement(&param, companyid)
	msg = protocol.NewReturnResponse(nil, err)
	return
}

//EditAchievement 编辑成果
//@router /achievement/edit
func (c AchievementController) EditAchievement() {
	var msg *protocol.ResponseMessage
	defer func() {
		c.ResposeJson(msg)
	}()

	var param protocol.RequestEditAchievement
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
		log.Error("json 解析失败 err:%s", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	companyid := c.GetCompanyId()
	err := serveachievement.EditAchievement(&param, companyid)
	msg = protocol.NewReturnResponse(nil, err)
	return
}

//EditAchievement 成果详情
//@router /achievement/info
func (c AchievementController) AchievementInfo() {
	var msg *protocol.ResponseMessage
	defer func() {
		c.ResposeJson(msg)
	}()
	type Parameter struct {
		Id int64 `json:"id"`
	}
	var param Parameter
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
		log.Error("json 解析失败 err:%s", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	companyid := c.GetCompanyId()
	rspData := serveachievement.GetAchievementInfo(param.Id, companyid)
	msg = protocol.NewReturnResponse(rspData, nil)
	return
}