140 lines
3.6 KiB
Go
140 lines
3.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-kratos/kratos/v3/errors"
|
|
"kra/internal/service/business"
|
|
"kra/internal/service/dto"
|
|
)
|
|
|
|
type BusinessPerformance struct {
|
|
service *business.BusinessPerformanceService
|
|
}
|
|
|
|
func (h *BusinessPerformance) Overview(c *gin.Context) {
|
|
var req dto.DashboardQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "首页查询参数不正确")
|
|
return
|
|
}
|
|
v, err := h.service.Overview(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *BusinessPerformance) MyGoal(c *gin.Context) {
|
|
v, err := h.service.MyGoal(c.Request.Context())
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
|
|
func NewBusinessPerformance(service *business.BusinessPerformanceService) *BusinessPerformance {
|
|
return &BusinessPerformance{service: service}
|
|
}
|
|
func (h *BusinessPerformance) Teams(c *gin.Context) {
|
|
v, err := h.service.Teams(c.Request.Context())
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *BusinessPerformance) SaveTeams(c *gin.Context) {
|
|
var req dto.GroupSaveRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "小组参数不正确")
|
|
return
|
|
}
|
|
v, err := h.service.SaveTeams(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *BusinessPerformance) Profile(c *gin.Context) {
|
|
var req dto.MemberProfileRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "商务档案参数不正确")
|
|
return
|
|
}
|
|
if err := h.service.UpdateProfile(c.Request.Context(), &req); err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OK(c)
|
|
}
|
|
func (h *BusinessPerformance) Query(c *gin.Context) { h.query(c, false) }
|
|
func (h *BusinessPerformance) Management(c *gin.Context) { h.query(c, true) }
|
|
func (h *BusinessPerformance) query(c *gin.Context, management bool) {
|
|
var req dto.PerformanceQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "绩效查询参数不正确")
|
|
return
|
|
}
|
|
v, err := h.service.Query(c.Request.Context(), &req, management)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *BusinessPerformance) Details(c *gin.Context) {
|
|
var req dto.PerformanceDetailQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "明细查询参数不正确")
|
|
return
|
|
}
|
|
v, err := h.service.Details(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *BusinessPerformance) Goals(c *gin.Context) {
|
|
var req dto.GoalQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "目标查询参数不正确")
|
|
return
|
|
}
|
|
v, err := h.service.GoalHistory(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *BusinessPerformance) SaveGoal(c *gin.Context) {
|
|
var req dto.GoalRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "目标须为整数或留空")
|
|
return
|
|
}
|
|
if err := h.service.SaveGoal(c.Request.Context(), &req); err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OK(c)
|
|
}
|
|
func (h *BusinessPerformance) Export(c *gin.Context) {
|
|
var req dto.PerformanceQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "导出参数不正确")
|
|
return
|
|
}
|
|
data, err := h.service.Export(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
c.Header("Content-Disposition", "attachment; filename=business-performance.xlsx")
|
|
c.Header("success", "true")
|
|
c.Data(200, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", data)
|
|
}
|