作者 linmadan

修复通知查询与任务更新bug,添加消息推送网关

@@ -1056,26 +1056,29 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1056,26 +1056,29 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1056 } 1056 }
1057 } 1057 }
1058 updateData := tool_funs.SimpleStructToMap(updateTaskCommand) 1058 updateData := tool_funs.SimpleStructToMap(updateTaskCommand)
1059 - if task.TaskType == domain.TASK_TYPE_DESIGNATE && updateTaskCommand.AssignedPerson != 0 {  
1060 - var employeeRepository domain.EmployeeRepository  
1061 - if value, err := factory.CreateEmployeeRepository(map[string]interface{}{  
1062 - "transactionContext": transactionContext,  
1063 - }); err != nil {  
1064 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1065 - } else {  
1066 - employeeRepository = value  
1067 - }  
1068 - employee, err := employeeRepository.FindOne(map[string]interface{}{  
1069 - "uid": updateTaskCommand.AssignedPerson,  
1070 - })  
1071 - if err != nil {  
1072 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1073 - }  
1074 - if employee == nil {  
1075 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")  
1076 - }  
1077 - if _, ok := updateData["assignedPerson"]; ok { 1059 + fmt.Println(updateTaskCommand.AssignedPerson != int64(0))
  1060 + if task.TaskType == domain.TASK_TYPE_DESIGNATE {
  1061 + if updateTaskCommand.AssignedPerson != int64(0) {
  1062 + var employeeRepository domain.EmployeeRepository
  1063 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  1064 + "transactionContext": transactionContext,
  1065 + }); err != nil {
  1066 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1067 + } else {
  1068 + employeeRepository = value
  1069 + }
  1070 + employee, err := employeeRepository.FindOne(map[string]interface{}{
  1071 + "uid": updateTaskCommand.AssignedPerson,
  1072 + })
  1073 + if err != nil {
  1074 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1075 + }
  1076 + if employee == nil {
  1077 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
  1078 + }
1078 updateData["assignedPerson"] = employee.EmployeeInfo 1079 updateData["assignedPerson"] = employee.EmployeeInfo
  1080 + } else {
  1081 + updateData["assignedPerson"] = &domain.EmployeeInfo{}
1079 } 1082 }
1080 } 1083 }
1081 if err := task.Update(updateData); err != nil { 1084 if err := task.Update(updateData); err != nil {
@@ -5,7 +5,8 @@ import "os" @@ -5,7 +5,8 @@ import "os"
5 const SERVICE_NAME = "mmm-worth" 5 const SERVICE_NAME = "mmm-worth"
6 6
7 var LOG_LEVEL = "debug" 7 var LOG_LEVEL = "debug"
8 -var ABILITY_SERVICE_HOST = "https://ability-test.fjmaimaimai.com" 8 +var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
  9 +var MMM_OPEN_API_SERVICE_HOST = "http://mmm-open-api-dev.fjmaimaimai.com"
9 10
10 func init() { 11 func init() {
11 if os.Getenv("LOG_LEVEL") != "" { 12 if os.Getenv("LOG_LEVEL") != "" {
@@ -14,4 +15,7 @@ func init() { @@ -14,4 +15,7 @@ func init() {
14 if os.Getenv("ABILITY_SERVICE_HOST") != "" { 15 if os.Getenv("ABILITY_SERVICE_HOST") != "" {
15 ABILITY_SERVICE_HOST = os.Getenv("ABILITY_SERVICE_HOST") 16 ABILITY_SERVICE_HOST = os.Getenv("ABILITY_SERVICE_HOST")
16 } 17 }
  18 + if os.Getenv("MMM_OPEN_API_SERVICE_HOST") != "" {
  19 + MMM_OPEN_API_SERVICE_HOST = os.Getenv("MMM_OPEN_API_SERVICE_HOST")
  20 + }
17 } 21 }
  1 +package constant
  2 +
  3 +import "os"
  4 +
  5 +var GETUI_APP_ID = "WgrbaaStTk7JElrXOCgUg6"
  6 +var GETUI_APP_KEY = "FG5lbqVrHa5rS9NVfxNP7"
  7 +var GETUI_APP_SECRET = "FW3jMNLJrRARYKv2iqA5H5"
  8 +
  9 +func init() {
  10 + if os.Getenv("GETUI_APP_KEY") != "" {
  11 + GETUI_APP_KEY = os.Getenv("GETUI_APP_KEY")
  12 + }
  13 + if os.Getenv("GETUI_APP_ID") != "" {
  14 + GETUI_APP_ID = os.Getenv("GETUI_APP_ID")
  15 + }
  16 + if os.Getenv("GETUI_APP_SECRET") != "" {
  17 + GETUI_APP_SECRET = os.Getenv("GETUI_APP_SECRET")
  18 + }
  19 +}
@@ -156,6 +156,9 @@ func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) @@ -156,6 +156,9 @@ func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{})
156 } 156 }
157 if assignedPerson, ok := data["assignedPerson"]; ok { 157 if assignedPerson, ok := data["assignedPerson"]; ok {
158 task.AssignedPerson = assignedPerson.(*EmployeeInfo) 158 task.AssignedPerson = assignedPerson.(*EmployeeInfo)
  159 + if task.AssignedPerson.Uid == 0 {
  160 + task.AssignedPerson = nil
  161 + }
159 } 162 }
160 } 163 }
161 return nil 164 return nil
@@ -81,8 +81,8 @@ func (repository *SentNotificationRepository) Find(queryOptions map[string]inter @@ -81,8 +81,8 @@ func (repository *SentNotificationRepository) Find(queryOptions map[string]inter
81 var sentNotificationModels []*models.SentNotification 81 var sentNotificationModels []*models.SentNotification
82 sentNotifications := make([]*domain.SentNotification, 0) 82 sentNotifications := make([]*domain.SentNotification, 0)
83 query := tx.Model(&sentNotificationModels).Relation("Notification") 83 query := tx.Model(&sentNotificationModels).Relation("Notification")
84 - if receiver, ok := queryOptions["receiver"]; ok && (receiver != int64(0)) {  
85 - query = query.Where(`sent_notification.receiver @> '{"uid":?}'`, receiver) 84 + if receiverId, ok := queryOptions["receiverId"]; ok && (receiverId != int64(0)) {
  85 + query = query.Where(`sent_notification.receiver @> '{"uid":?}'`, receiverId)
86 } 86 }
87 if notificationType, ok := queryOptions["notificationType"]; ok && (notificationType != int(0)) { 87 if notificationType, ok := queryOptions["notificationType"]; ok && (notificationType != int(0)) {
88 query = query.Where("notification.notification_type = ?", notificationType) 88 query = query.Where("notification.notification_type = ?", notificationType)
  1 +package service_gateway
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
  5 + "strings"
  6 + "time"
  7 +)
  8 +
  9 +type HttplibMmmOpenApiServiceGateway struct {
  10 + httplibBaseServiceGateway
  11 +}
  12 +
  13 +func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, clientIds []string, title string, content string, ext map[string]interface{}) (map[string]interface{}, error) {
  14 + url := strings.Join([]string{serviceGateway.baseURL, "push", "pushInfo"}, "/")
  15 + request := serviceGateway.createRequest(url, "post")
  16 + options := make(map[string]interface{})
  17 + options["mmmType"] = 1
  18 + options["clientId"] = clientIds
  19 + options["appKey"] = constant.GETUI_APP_KEY
  20 + options["secret"] = constant.GETUI_APP_SECRET
  21 + options["appId"] = constant.GETUI_APP_ID
  22 + options["title"] = title
  23 + options["content"] = content
  24 + options["ext"] = ext
  25 + request.JSONBody(options)
  26 + response := make(map[string]interface{})
  27 + request.ToJSON(&response)
  28 + data, err := serviceGateway.responseHandle(response)
  29 + return data, err
  30 +}
  31 +
  32 +func NewHttplibPushServiceGateway() *HttplibMmmOpenApiServiceGateway {
  33 + return &HttplibMmmOpenApiServiceGateway{
  34 + httplibBaseServiceGateway: httplibBaseServiceGateway{
  35 + baseURL: constant.MMM_OPEN_API_SERVICE_HOST,
  36 + connectTimeout: 100 * time.Second,
  37 + readWriteTimeout: 30 * time.Second,
  38 + },
  39 + }
  40 +}
@@ -61,6 +61,30 @@ var _ = Describe("更新任务", func() { @@ -61,6 +61,30 @@ var _ = Describe("更新任务", func() {
61 ContainsKey("taskId").ValueEqual("taskId", 1) 61 ContainsKey("taskId").ValueEqual("taskId", 1)
62 }) 62 })
63 }) 63 })
  64 + Context("更新指派任务", func() {
  65 + BeforeEach(func() {
  66 + _, err := pG.DB.QueryOne(
  67 + pg.Scan(),
  68 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  69 + 1, 101, "testTaskName", 3, "{}", 1, "{}", 1, pg.Array([]int{1}), 1, 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
  70 + Expect(err).NotTo(HaveOccurred())
  71 + })
  72 + It("返回更新后的任务数据", func() {
  73 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  74 + body := map[string]interface{}{
  75 + }
  76 + httpExpect.PUT("/tasks/1").
  77 + WithJSON(body).
  78 + Expect().
  79 + Status(http.StatusOK).
  80 + JSON().
  81 + Object().
  82 + ContainsKey("code").ValueEqual("code", 0).
  83 + ContainsKey("msg").ValueEqual("msg", "ok").
  84 + ContainsKey("data").Value("data").Object().
  85 + ContainsKey("taskId").ValueEqual("taskId", 1)
  86 + })
  87 + })
64 Context("任务不在未发布状态下提交正确的任务数据", func() { 88 Context("任务不在未发布状态下提交正确的任务数据", func() {
65 BeforeEach(func() { 89 BeforeEach(func() {
66 _, err := pG.DB.QueryOne( 90 _, err := pG.DB.QueryOne(