main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/robfig/cron"
  5. "github.com/spf13/cobra"
  6. "go.uber.org/zap"
  7. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  8. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  9. "time"
  10. "timedtasks/config"
  11. )
  12. func init() {
  13. config.Init("./common.toml")
  14. InitLog()
  15. log.Info("init success")
  16. }
  17. func main() {
  18. rootCmd := &cobra.Command{Use: "my cmd"}
  19. rootCmd.AddCommand(includedInfo()) // 剑鱼网站统计数据
  20. if err := rootCmd.Execute(); err != nil {
  21. fmt.Println("rootCmd.Execute failed", err.Error())
  22. }
  23. }
  24. func includedInfo() *cobra.Command {
  25. cmdClient := &cobra.Command{
  26. Use: "included_info",
  27. Short: "Start processing included_info data",
  28. Run: func(cmd *cobra.Command, args []string) {
  29. initEs()
  30. InitMysql()
  31. c := cron.New()
  32. //cronstr := "0 */3 * * * *"
  33. // 每月第一天的 0 点
  34. err := c.AddFunc("@monthly", func() {
  35. taskInfo()
  36. })
  37. if err != nil {
  38. panic(err)
  39. }
  40. c.Start()
  41. t := make(chan bool, 1)
  42. <-t
  43. },
  44. }
  45. //cmdClient.Flags().StringVarP(&cfg, "conf", "c", "", "server config [toml]")
  46. return cmdClient
  47. }
  48. func taskInfo() {
  49. bidCount, proCount, entCount, buyerCount := int64(0), int64(0), int64(0), int64(0)
  50. esquery := `{"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],"should":[]}}}`
  51. bidCount = Es.Count(config.Conf.Es.Bidding, esquery)
  52. proCount = Es.Count(config.Conf.Es.Project, esquery)
  53. entCount = Es.Count(config.Conf.Es.Qyxy, `{"query":{"bool":{"must":[{"range":{"company_type_int":{"lte":"20"}}}]}}}`)
  54. buyerCount = Es.Count(config.Conf.Es.Buyer, esquery)
  55. saveM := map[string]interface{}{"bid": bidCount, "project": proCount, "ent": entCount, "buyer": buyerCount,
  56. "bid_day_update": config.Conf.Preset.Bidday,
  57. "bid_field": config.Conf.Preset.Bidfield,
  58. "field_accuracy": config.Conf.Preset.Accuracy}
  59. saveM["create_time"] = time.Now().Format(util.Date_Full_Layout)
  60. log.Info("included_info", zap.Any("m", saveM))
  61. MysqlTool.Insert("included_info", saveM)
  62. }