From 63d45eabccfcdba5ba61333150a378befb5fbcdb Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Tue, 16 Feb 2021 15:44:26 +0800 Subject: [PATCH] no message --- controller/plan.go | 36 ++++++++++++++++++++++++++++++++++++ main.go | 9 +++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/controller/plan.go b/controller/plan.go index a306863..864f408 100644 --- a/controller/plan.go +++ b/controller/plan.go @@ -3,6 +3,7 @@ package controller import ( "background/db" "background/model" + "fmt" "log" "strconv" @@ -87,3 +88,38 @@ func (this *PlanController) DelPlan(c *gin.Context) { resp.Msg = "OK" resp.Status = 0 } + +type ReqDate struct { + Date string `gorm:"date" json:"date"` +} + +func (m *ReqDate) TableName() string { + return "plan" +} + +func (this *PlanController) PlanDay(c *gin.Context) { + + var req ReqDate + resp := RespBase{ + Msg: "ERROR", + Status: 23, + } + defer c.JSON(200, &resp) + + e := c.BindJSON(&req) + if nil != e { + log.Print(e.Error()) + return + } + ret := make([]ReqDate, 1) + sql := fmt.Sprintf(`SELECT distinct plan.date FROM plan where DATE_FORMAT(plan.date,'%%Y-%%m')=DATE_FORMAT('%s','%%Y-%%m')`, req.Date) + log.Print(sql) + e = db.GetOrm().Raw(sql).Find(&ret).Error + if nil != e { + log.Print(e.Error()) + return + } + resp.Data = ret + resp.Msg = "OK" + resp.Status = 0 +} diff --git a/main.go b/main.go index fef1fc4..704874a 100644 --- a/main.go +++ b/main.go @@ -176,10 +176,11 @@ func main() { api.POST("/delbook", controller.Delbook) // 删除书籍 api.GET("/bookcount", controller.BookCount) // 删除书籍 - api.POST("/get_plans", planController.GetPlanDates) - api.PUT("/plan", planController.AddPlan) - api.DELETE("/plan", planController.DelPlan) - + api.POST("/get_plans", planController.GetPlanDates) // 获取当天的所有计划 + api.PUT("/plan", planController.AddPlan) // 添加计划 + api.DELETE("/plan", planController.DelPlan) // 删除计划 + api.POST("/plan_days", planController.PlanDay) // 获取本月有计划天数 + api.GET("planDays") } openapi := r.Group("openapi")