Commit 52c34ec4 by 孙龙

定时任务 发送crm备忘录提醒

parent 944fc278
......@@ -26,10 +26,12 @@ config/proxy.toml.http.addr 修改成你的ip地址或者本地127.0.0.1
### 6.项目启动
go run ./cmd/main.go
go run ./cmd/crm/recv_comuser/main.go -config=./config/prod/ -logdir = ./logs/
go run ./cmd/crm/sync_comuser_to_erp/main.go -config=./config/prod/ -logdir = ./logs/
go run ./cmd/crm/sendmsg/main.go -config=./config/prod/ -logdir = ./logs/
go run ./cmd/crm/cron_sendmsg/main.go -config=./config/prod/ -logdir = ./logs/
go run ./cmd/crm/recv_comuser/main.go -config=./config/dev/ -logdir=./logs/
go run ./cmd/crm/sync_comuser_to_erp/main.go -config=./config/dev/ -logdir=./logs/
go run ./cmd/crm/sendmsg/main.go -config=./config/dev/ -logdir=./logs/
go run ./cmd/crm/cron_sendmsg/main.go -config=./config/dev/ -logdir=./logs/
go run ./cmd/crm/cron_crmschedulememo/main.go -config=./config/dev/ -logdir=./logs/
##项目的目录结构
......
package cron_crm_schedulememo
import (
"github.com/ichunt2019/cfg/lib"
)
type BaseDatabase struct {
DataSourceName string
MaxIdleCons int
MaxOpenCons int
Prefix string
}
type GroupDatabase struct {
DataSourceName []string
MaxIdleCons int
MaxOpenCons int
Prefix string
}
//单、主数据 master
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{
"crm": {
DataSourceName: lib.Instance("db").GetString("crm.data_source_name"),
Prefix: lib.Instance("db").GetString("crm.table_prefix"),
MaxIdleCons:lib.Instance("db").GetInt("crm.max_idle_conn"),
MaxOpenCons:lib.Instance("db").GetInt("crm.max_open_conn"),
},
"cms": {
DataSourceName: lib.Instance("db").GetString("cms.data_source_name"),
Prefix: lib.Instance("db").GetString("cms.table_prefix"),
MaxIdleCons:lib.Instance("db").GetInt("cms.max_idle_conn"),
MaxOpenCons:lib.Instance("db").GetInt("cms.max_open_conn"),
},
}
}
//主从数据 master slave
func BuildGroupDatabaseList() (DatabaseList map[string]GroupDatabase) {
return map[string]GroupDatabase{
//"liexin": {
// DataSourceName:lib.Instance("db").GetStringSlice("liexin.data_source_name"),
// Prefix: lib.Instance("db").GetString("liexin.table_prefix"),
// MaxIdleCons:lib.Instance("db").GetInt("liexin.max_idle_conn"),
// MaxOpenCons:lib.Instance("db").GetInt("liexin.max_open_conn"),
//},
}
}
package cron_crm_schedulememo
import (
"github.com/ichunt2019/cfg/lib"
"time"
)
type RedisGroupDatabase struct {
MasterHost string
Password string //master密码
SlaveHost []string
ReadonlyPassword string //从服务器密码
DialTimeout time.Duration //连接超时
MinIdleConns int //空间链接
ReadTimeout time.Duration //读超时
WriteTimeout time.Duration //写超时
}
//多数据库配置
func BuildRedisGroupConfigs() ( map[string]RedisGroupDatabase) {
//fmt.Println("6666666666")
//fmt.Println(lib.Instance("redis").GetStringSlice("api.slave.host"))
return map[string]RedisGroupDatabase{
"api": {
MasterHost: lib.Instance("redis").GetString("api.master.host"),
Password:lib.Instance("redis").GetString("api.master.password"),
SlaveHost: lib.Instance("redis").GetStringSlice("api.slave.host"),
ReadonlyPassword:lib.Instance("redis").GetString("api.slave.password"),
DialTimeout: time.Duration(lib.Instance("redis").GetInt("api.dial_timeout"))*time.Second,
ReadTimeout: time.Duration(lib.Instance("redis").GetInt("api.read_timeout"))*time.Second,
WriteTimeout: time.Duration(lib.Instance("redis").GetInt("api.write_timeout"))*time.Second,
MinIdleConns:lib.Instance("redis").GetInt("api.min_idle_conns"),
},
"sku": {
MasterHost: lib.Instance("redis").GetString("sku.master.host"),
Password:lib.Instance("redis").GetString("sku.master.password"),
SlaveHost: lib.Instance("redis").GetStringSlice("sku.slave.host"),
ReadonlyPassword:lib.Instance("redis").GetString("sku.slave.password"),
DialTimeout: time.Duration(lib.Instance("redis").GetInt("sku.dial_timeout"))*time.Second,
ReadTimeout: time.Duration(lib.Instance("redis").GetInt("sku.read_timeout"))*time.Second,
WriteTimeout: time.Duration(lib.Instance("redis").GetInt("sku.write_timeout"))*time.Second,
MinIdleConns:lib.Instance("redis").GetInt("sku.min_idle_conns"),
},
}
}
package crm_comuser
package cron_sendmsg
import (
"github.com/ichunt2019/cfg/lib"
......
package crm_comuser
package cron_sendmsg
import (
"github.com/ichunt2019/cfg/lib"
......
package cron_crm_schedulememo
import (
cron_crm_schedulememo "golang-asynctask/app/common/config/cron_crm_schedulememo"
"sync"
"time"
"xorm.io/xorm"
"github.com/go-redis/redis/v7"
_ "github.com/go-sql-driver/mysql"
"github.com/ichunt2019/cfg/lib"
redisPool "github.com/ichunt2019/go-redis-pool"
)
var (
once sync.Once
Dao *dao
)
type dao struct {
db map[string]*xorm.Engine //非主从mysql数据库 连接池
dbGroup map[string]*xorm.EngineGroup //mysql主从 连接池
redisGroup map[string]*redisPool.Pool //redis 主从 连接池
}
//获取db实例
func (self *dao) GetDb(databases string) *xorm.Engine {
return self.db[databases]
}
//获取主从db实例
//获取主从db实例
//func (self *dao) GetDbGroup(databases string) *xorm.EngineGroup {
// return self.dbGroup[databases]
//}
//获取主从db实例
//func (self *dao) GetRedisDbGroup(databases string) *redisPool.Pool {
// return self.redisGroup[databases]
//}
func mysqlSetup(d *dao) *dao {
var (
err error
)
DatabaseList := cron_crm_schedulememo.BuildDatabaseList()
GroupDatabaseList := cron_crm_schedulememo.BuildGroupDatabaseList()
if len(DatabaseList) > 0 {
for conName, db := range DatabaseList {
d.db[conName], err = xorm.NewEngine("mysql", db.DataSourceName)
if err != nil {
panic(err)
}
//日志打印SQL
ShowSql := lib.Instance("db").GetBool("xorm.ShowSQL")
d.db[conName].ShowSQL(ShowSql)
//设置连接池的空闲数大小
d.db[conName].SetMaxIdleConns(db.MaxIdleCons)
//设置最大打开连接数
d.db[conName].SetMaxOpenConns(db.MaxOpenCons)
}
}
if len(GroupDatabaseList) > 0 {
for conName, db := range GroupDatabaseList {
d.dbGroup[conName], err = xorm.NewEngineGroup("mysql", db.DataSourceName)
if err != nil {
panic(err)
}
//日志打印SQL
ShowSql := lib.Instance("db").GetBool("xorm.ShowSQL")
d.dbGroup[conName].ShowSQL(ShowSql)
//设置连接池的空闲数大小
d.dbGroup[conName].SetMaxIdleConns(db.MaxIdleCons)
//设置最大打开连接数
d.dbGroup[conName].SetMaxOpenConns(db.MaxOpenCons)
}
}
return d
}
func redisSetup(d *dao) *dao {
var err error
redisGroupList := cron_crm_schedulememo.BuildRedisGroupConfigs()
//fmt.Println(redisGroupList)
for redisServerName, redisInfo := range redisGroupList {
d.redisGroup[redisServerName], err = redisPool.NewHA(&redisPool.HAConfig{
Master: redisInfo.MasterHost,
Slaves: redisInfo.SlaveHost,
Password: redisInfo.Password,
ReadonlyPassword: redisInfo.ReadonlyPassword,
Options: &redis.Options{
DialTimeout: redisInfo.DialTimeout, //连接超时
MinIdleConns: redisInfo.MinIdleConns, //空闲链接数
ReadTimeout: redisInfo.ReadTimeout,
WriteTimeout: redisInfo.WriteTimeout,
},
AutoEjectHost: true,//是否弹出故障主机
ServerFailureLimit: 3,//达到失败次数时弹出
ServerRetryTimeout: 5 * time.Second,//在“ServerRetryTimeout”之后重试弹出的主机`
MinServerNum: 0,//保留min服务器 针对从服务器
})
if err != nil {
panic(err)
}
}
return d
}
func Init() {
Dao = &dao{}
once.Do(func() {
//单、主数据 master
Dao.db = make(map[string]*xorm.Engine, 0)
////主从数据 master slave
//Dao.dbGroup = make(map[string]*xorm.EngineGroup, 0)
////redis连接池 支持主从 master slave
//Dao.redisGroup = make(map[string]*redisPool.Pool, 0)
Dao = mysqlSetup(Dao)
//Dao = redisSetup(Dao)
})
}
package cron_sendmsg
import (
"golang-asynctask/app/common/config/crm_comuser"
"golang-asynctask/app/common/config/cron_sendmsg"
"sync"
"time"
......@@ -42,8 +43,8 @@ func mysqlSetup(d *dao) *dao {
var (
err error
)
DatabaseList := crm_comuser.BuildDatabaseList()
GroupDatabaseList := crm_comuser.BuildGroupDatabaseList()
DatabaseList := cron_sendmsg.BuildDatabaseList()
GroupDatabaseList := cron_sendmsg.BuildGroupDatabaseList()
if len(DatabaseList) > 0 {
for conName, db := range DatabaseList {
d.db[conName], err = xorm.NewEngine("mysql", db.DataSourceName)
......
package cron_crm_schedulememo
import (
"encoding/json"
"errors"
"fmt"
"github.com/tidwall/gjson"
"golang-asynctask/app/dao/crm/cron_crm_schedulememo"
cfg "github.com/ichunt2019/cfg/lib"
comfunc "golang-asynctask/util/lib"
xlog "github.com/ichunt2019/lxLog/log"
"net/http"
"net/url"
"time"
)
/*
关闭备忘录
*/
func RemindMemo(){
//查询3天前的数据
//defer func(){
// xlog.Instance("cron_crm_schedulememo").Close()
//}()
currentTime := time.Now().Format("2006-01-02")
fmt.Println(currentTime)
start_time_str := currentTime + " 00:00:00"
end_time_str := currentTime + " 23:59:59"
start_time,_ :=time.Parse("2006-01-02 15:04:05",start_time_str);
end_time,_ :=time.Parse("2006-01-02 15:04:05",end_time_str);
sql := "select id,sale_id from lie_schedule_memo where status = 1 and end_time >=? and end_time <=?"
reult,err := cron_crm_schedulememo.Dao.GetDb("crm").SQL(sql,start_time.Unix()+3*24*3600,end_time.Unix()+3*24*3600).QueryString()
if err != nil{
xlog.Instance("cron_crm_schedulememo").Error("err:%s",err);
return
}
for _,item :=range reult{
id := item["id"]
sale_id := item["sale_id"]
if sale_id!=""{
err := postToCrm(id,sale_id);
if err != nil{
xlog.Instance("cron_crm_schedulememo").Error("id:%s;sale_id:%s;err:%s",id,sale_id,err);
}
}
}
}
//关闭已超时的
func CloseTimeoutMemo(){
sql := "update lie_schedule_memo set status = -1 where status = 1 and end_time <= unix_timestamp(now())"
_,err := cron_crm_schedulememo.Dao.GetDb("crm").Exec(sql);
if err != nil{
xlog.Instance("cron_crm_schedulememo").Error("err:%s",err);
}
}
func postToCrm(id string,sale_id string) (err error){
var(
_forwardHeaderStr []byte
)
type forwardHeader struct {
ApiKey string `json:"api-key"`
}
type formData struct {
Id string `json:"id"`
SaleId string `json:"sale_id"`
}
_forwardHeader := forwardHeader{ApiKey:cfg.Instance("config").GetString("apiKey")}
_forwardHeaderStr,err = json.Marshal(_forwardHeader);
if(err != nil){
_forwardHeaderStr = []byte("")
}
_formData := formData{id,sale_id}
_formData_str ,err := json.Marshal(_formData)
if(err != nil){
_formData_str = []byte("")
}
push_url := cfg.Instance("config").GetString("asyncTaskforward")
urlParams := url.Values{}
header := http.Header{}
//异步任务转发http header头部
header.Set("api-key","async task qwert12345")
urlParams.Add("callbackDomain",cfg.Instance("config").GetString("crmDomain"))
urlParams.Add("callbackUri","api/senMsgByMemo")
urlParams.Add("requestType","http")
urlParams.Add("data",string(_formData_str))
urlParams.Add("method","post")
urlParams.Add("serviceType","2")
urlParams.Add("header",string(_forwardHeaderStr))
urlParams.Add("isHttpJson","0")
urlParams.Add("remark","crm发送备忘录提醒")
response,returnData,err := comfunc.HttpPOST(push_url,urlParams,0,header,"")
if err == nil && response.StatusCode == 200{
err_code := gjson.Parse(string(returnData)).Get("err_code").Int()
msg := gjson.Parse(string(returnData)).Get("err_msg").String()
if err_code != 0{
err = errors.New(msg)
}
}
return
}
\ No newline at end of file
package boot
import (
"github.com/ichunt2019/cfg/lib"
crm_schedulememo_dao"golang-asynctask/app/dao/crm/cron_crm_schedulememo"
xlog "github.com/ichunt2019/lxLog/log"
)
func Init(configPath string,logPath string)(err error){
err = lib.Init(configPath)
if err != nil{
panic(err)
}
xlog.Init(logPath,"cron_crm_schedulememo")
//初始化数据库
crm_schedulememo_dao.Init()
return
}
#crm
#邮件提醒任务:未关闭的备忘录在截止时间前3天于每天上午9:00邮件提醒,超时则标记为已超时
\ No newline at end of file
package main
import (
"flag"
"golang-asynctask/app/service/crm/cron_crm_schedulememo"
boot "golang-asynctask/boot/cron_crm_schedulememo"
xlog "github.com/ichunt2019/lxLog/log"
)
var (
configPath string
logPath string
)
func main(){
defer func(){
xlog.Instance("cron_crm_schedulememo").Close()
}()
flag.StringVar(&configPath, "config", "./config/dev/", "配置文件")
flag.StringVar(&logPath, "logdir", "./logs/", "日志文件存储目录")
flag.Parse()
boot.Init(configPath,logPath)
//关闭已超时的
cron_crm_schedulememo.CloseTimeoutMemo()
//备忘录 提醒
cron_crm_schedulememo.RemindMemo()
}
......@@ -6,6 +6,10 @@ pushErpDomain = "http://crm.liexin.net/api/pushComUserRelationToErp"
crmSendMsgByconflictSale = "http://crm.liexin.net/api/sendMsgByconflictSale"
sendMsgByChangeInvoiceCom = "http://crm.liexin.net/api/sendMsgByChangeInvoiceCom"
apiKey = "crm a1b2c3d4e5f6g7h8i9jk"
#crm发送备忘录提醒
crmDomain = "http://crm.liexin.net/"
#异步任务转发url
asyncTaskforward = "http://192.168.1.168:8700/callback"
#推送云芯 微信用户信息
pushWechatYunXinApi = "http://cloud.liexindev.net/inner/oauth/resetopenid"
......
......@@ -8,6 +8,13 @@ ShowSQL = true
table_prefix = "lie_"
max_conn_life_time = 100
[cms]
data_source_name = "ichuntcms:ichuntcms#zsyM@tcp(192.168.1.235:3306)/ichuntcms?charset=utf8&parseTime=true&loc=Asia%2FShanghai"
max_open_conn = 0
max_idle_conn = 0
table_prefix = "lie_"
max_conn_life_time = 100
[liexin]
......@@ -31,7 +38,7 @@ ShowSQL = true
]
[cms]
[micro_service]
dns = "micro_service:lie_micro_service#zsyM@tcp(192.168.2.232:3306)/lie_micro_service?charset=utf8&parseTime=true&loc=Asia%2FChongqing"
max_open_conn = 20
max_idle_conn = 10
......
......@@ -6,6 +6,10 @@ pushErpDomain = "http://crm.ichunt.net/api/pushComUserRelationToErp"
crmSendMsgByconflictSale = "http://crm.ichunt.net/api/sendMsgByconflictSale"
sendMsgByChangeInvoiceCom = "http://crm.ichunt.net/api/sendMsgByChangeInvoiceCom"
apiKey = "crm a1b2c3d4e5f6g7h8i9jk"
#crm发送备忘录提醒
crmDomain = "http://crm.ichunt.net/"
#异步任务转发url
asyncTaskforward = "http://172.18.137.41:60012/callback"
#推送云芯 微信用户信息
pushWechatYunXinApi = "http://cloud.ichunt.com/inner/oauth/resetopenid"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment