123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- "encoding/json"
- "github.com/gogf/gf/v2/util/gconv"
- "rpc/config"
- "time"
- )
- type WXroBot struct {
- *xweb.Action
- addTaskHandler xweb.Mapper `xweb:"/add/task"` //新增任务
- updateTaskHandler xweb.Mapper `xweb:"/update/task"` //修改任务
- }
- type TaskRequest struct {
- TaskID int64 `json:"taskId,omitempty"`
- TaskName string `json:"taskName"`
- SendGroupID string `json:"sendGroupId"`
- SendGroupName string `json:"sendGroupName"`
- TaskType int64 `json:"taskType"`
- SendTimeType int64 `json:"sendTimeType"`
- SendTime string `json:"sendTime"`
- Content []map[string]interface{} `json:"content"`
- }
- func (a *WXroBot) AddTaskHandler() {
- var req TaskRequest
- err := json.Unmarshal(a.Body(), &req)
- taskId := int64(0)
- msg := ""
- userid := common.ObjToString(a.GetSession("userId"))
- status := int64(0)
- content := gconv.Maps(req.Content)
- if err == nil && len(content) > 0 {
- taskType := req.TaskType
- sendTimeType := req.SendTimeType
- taskId = config.WxRobot.Insert("task", map[string]interface{}{
- "task_name": req.TaskName,
- "send_group_id": req.SendGroupID,
- "task_type": req.TaskType,
- "send_time_type": req.SendTimeType,
- "send_time": req.SendTime,
- "task_status": 0,
- "create_time": time.Now().Format(time.DateTime),
- "update_time": time.Now().Format(time.DateTime),
- "create_person_id": userid,
- "send_group_name": req.SendGroupName,
- })
- if taskId <= 0 {
- msg = "保存失败"
- } else {
- for _, v := range content {
- text := gconv.String(v["text"])
- fileType := gconv.Int64(v["type"])
- config.WxRobot.Insert("task_send_content", map[string]interface{}{
- "task_id": taskId,
- "content": text,
- "content_type": fileType,
- "create_time": time.Now().Format(time.DateTime),
- "update_time": time.Now().Format(time.DateTime),
- "status": 0,
- })
- }
- status = 1
- if taskType == 0 && sendTimeType == 0 {
- go func() {
- allUserMap := InitUser()
- ScheduledTasks(allUserMap, taskId)
- }()
- }
- }
- } else {
- msg = "参数格式不对"
- }
- a.ServeJson(config.Result{Data: config.M{"status": status}, Error_msg: msg})
- }
- func (a *WXroBot) UpdateTaskHandler() {
- var req TaskRequest
- err := json.Unmarshal(a.Body(), &req)
- msg := ""
- status := int64(0)
- content := gconv.Maps(req.Content)
- if err == nil && len(content) > 0 {
- taskId := req.TaskID
- taskType := req.TaskType
- sendTimeType := req.SendTimeType
- ok := config.WxRobot.Update("task", map[string]interface{}{
- "id": taskId,
- }, map[string]interface{}{
- "task_name": req.TaskName,
- "send_group_id": req.SendGroupID,
- "task_type": req.TaskType,
- "send_time_type": req.SendTimeType,
- "send_time": req.SendTime,
- "update_time": time.Now().Format(time.DateTime),
- "send_group_name": req.SendGroupName,
- })
- if ok {
- config.WxRobot.Update("task_send_content", map[string]interface{}{
- "task_id": taskId,
- }, map[string]interface{}{
- "status": 1,
- })
- for _, v := range content {
- text := gconv.String(v["text"])
- fileType := gconv.Int64(v["type"])
- config.WxRobot.Insert("task_send_content", map[string]interface{}{
- "task_id": taskId,
- "content": text,
- "content_type": fileType,
- "create_time": time.Now().Format(time.DateTime),
- "update_time": time.Now().Format(time.DateTime),
- "status": 0,
- })
- }
- status = 1
- if taskType == 0 && sendTimeType == 0 {
- go func() {
- allUserMap := InitUser()
- ScheduledTasks(allUserMap, taskId)
- }()
- }
- } else {
- msg = "修改失败"
- }
- } else {
- msg = "参数格式不对"
- }
- a.ServeJson(config.Result{Data: config.M{"status": status}, Error_msg: msg})
- }
|