Files
zmkgC/internal/app/system/controller/plan_daily.go
2025-07-07 20:11:59 +08:00

118 lines
3.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==========================================================================
// GFast自动生成controller操作代码。
// 生成日期2023-09-26 14:31:07
// 生成路径: internal/app/system/controller/plan_daily.go
// 生成人gfast
// desc:日报
// company:云南奇讯科技有限公司
// ==========================================================================
package controller
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"math/rand"
"strconv"
"strings"
"time"
)
type planDailyController struct {
BaseController
}
var PlanDaily = new(planDailyController)
// List 列表
func (c *planDailyController) List(ctx context.Context, req *system.PlanDailySearchReq) (res *system.PlanDailySearchRes, err error) {
res, err = service.PlanDaily().List(ctx, req)
return
}
// Get 获取日报
func (c *planDailyController) Get(ctx context.Context, req *system.PlanDailyGetReq) (res *system.PlanDailyGetRes, err error) {
res = new(system.PlanDailyGetRes)
res.PlanDailyInfoRes, err = service.PlanDaily().GetById(ctx, req.Id)
return
}
// Add 添加日报
func (c *planDailyController) Add(ctx context.Context, req *system.PlanDailyAddReq) (res *system.PlanDailyAddRes, err error) {
err = service.PlanDaily().Add(ctx, req)
return
}
// Edit 修改日报
func (c *planDailyController) Edit(ctx context.Context, req *system.PlanDailyEditReq) (res *system.PlanDailyEditRes, err error) {
err = service.PlanDaily().Edit(ctx, req)
return
}
// Delete 删除日报
func (c *planDailyController) Delete(ctx context.Context, req *system.PlanDailyDeleteReq) (res *system.PlanDailyDeleteRes, err error) {
err = service.PlanDaily().Delete(ctx, req.Ids)
return
}
var mp = make(map[string]string)
type DayEntity struct {
ProjectId string `json:"project_id"`
SourceId string `json:"source_id"`
Name string `json:"name"`
Table string `json:"table"`
//PlanName string `json:"plan_name"`
//PlanId string `json:"plan_id"`
//WeekRealityId string `json:"week_reality_id"`
SourceType string `json:"source_type"`
Cnt int `json:"cnt"`
DataTime string `json:"data_time"`
}
// 模拟日报-自动生成数据
func myTask(ctx context.Context) {
//1、随机哪几张表
mp["1"] = "qianqi_xiangbian"
mp["2"] = "qianqi_nibianqi"
mp["3"] = "qianqi_guangfuban_ids_zhuangdian"
mp["4"] = "qianqi_guangfuban_ids_zhijia"
mp["5"] = "qianqi_guangfuban_ids_lizhu"
mp["6"] = "qianqi_guangfuban_ids"
//2、创建随机种子
rand.Seed(time.Now().Unix())
intn := rand.Intn(6) + 1
intnTwo := rand.Intn(6) + 1
//3、随机挑选一个表查询,随机获取数据
table := mp[strconv.Itoa(intn)]
array, _ := g.DB().Model(table).Ctx(ctx).OrderRandom().Limit(intnTwo).All()
var oneEntity []*DayEntity
for _, data := range array {
var twoEntity = new(DayEntity)
data.Struct(twoEntity)
twoEntity.Table = table
twoEntity.SourceType = strings.ReplaceAll(table, "qianqi_", "")
twoEntity.Cnt = intnTwo
twoEntity.DataTime = time.Unix(1621741532, 0).Format("2006-01-02")
oneEntity = append(oneEntity, twoEntity)
}
g.DB().Model("plan_daily").Ctx(ctx).Insert(oneEntity)
}
func init() {
ctx := gctx.New()
ticker := time.NewTicker(6 * time.Hour)
go func() {
for {
select {
case <-ticker.C:
myTask(ctx)
}
}
}()
}