作者 linmadan

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

... ... @@ -1056,7 +1056,9 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
}
}
updateData := tool_funs.SimpleStructToMap(updateTaskCommand)
if task.TaskType == domain.TASK_TYPE_DESIGNATE && updateTaskCommand.AssignedPerson != 0 {
fmt.Println(updateTaskCommand.AssignedPerson != int64(0))
if task.TaskType == domain.TASK_TYPE_DESIGNATE {
if updateTaskCommand.AssignedPerson != int64(0) {
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1074,8 +1076,9 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
if employee == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
}
if _, ok := updateData["assignedPerson"]; ok {
updateData["assignedPerson"] = employee.EmployeeInfo
} else {
updateData["assignedPerson"] = &domain.EmployeeInfo{}
}
}
if err := task.Update(updateData); err != nil {
... ...
... ... @@ -5,7 +5,8 @@ import "os"
const SERVICE_NAME = "mmm-worth"
var LOG_LEVEL = "debug"
var ABILITY_SERVICE_HOST = "https://ability-test.fjmaimaimai.com"
var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
var MMM_OPEN_API_SERVICE_HOST = "http://mmm-open-api-dev.fjmaimaimai.com"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
... ... @@ -14,4 +15,7 @@ func init() {
if os.Getenv("ABILITY_SERVICE_HOST") != "" {
ABILITY_SERVICE_HOST = os.Getenv("ABILITY_SERVICE_HOST")
}
if os.Getenv("MMM_OPEN_API_SERVICE_HOST") != "" {
MMM_OPEN_API_SERVICE_HOST = os.Getenv("MMM_OPEN_API_SERVICE_HOST")
}
}
... ...
package constant
import "os"
var GETUI_APP_ID = "WgrbaaStTk7JElrXOCgUg6"
var GETUI_APP_KEY = "FG5lbqVrHa5rS9NVfxNP7"
var GETUI_APP_SECRET = "FW3jMNLJrRARYKv2iqA5H5"
func init() {
if os.Getenv("GETUI_APP_KEY") != "" {
GETUI_APP_KEY = os.Getenv("GETUI_APP_KEY")
}
if os.Getenv("GETUI_APP_ID") != "" {
GETUI_APP_ID = os.Getenv("GETUI_APP_ID")
}
if os.Getenv("GETUI_APP_SECRET") != "" {
GETUI_APP_SECRET = os.Getenv("GETUI_APP_SECRET")
}
}
... ...
... ... @@ -156,6 +156,9 @@ func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{})
}
if assignedPerson, ok := data["assignedPerson"]; ok {
task.AssignedPerson = assignedPerson.(*EmployeeInfo)
if task.AssignedPerson.Uid == 0 {
task.AssignedPerson = nil
}
}
}
return nil
... ...
... ... @@ -81,8 +81,8 @@ func (repository *SentNotificationRepository) Find(queryOptions map[string]inter
var sentNotificationModels []*models.SentNotification
sentNotifications := make([]*domain.SentNotification, 0)
query := tx.Model(&sentNotificationModels).Relation("Notification")
if receiver, ok := queryOptions["receiver"]; ok && (receiver != int64(0)) {
query = query.Where(`sent_notification.receiver @> '{"uid":?}'`, receiver)
if receiverId, ok := queryOptions["receiverId"]; ok && (receiverId != int64(0)) {
query = query.Where(`sent_notification.receiver @> '{"uid":?}'`, receiverId)
}
if notificationType, ok := queryOptions["notificationType"]; ok && (notificationType != int(0)) {
query = query.Where("notification.notification_type = ?", notificationType)
... ...
package service_gateway
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
"strings"
"time"
)
type HttplibMmmOpenApiServiceGateway struct {
httplibBaseServiceGateway
}
func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, clientIds []string, title string, content string, ext map[string]interface{}) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "push", "pushInfo"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["mmmType"] = 1
options["clientId"] = clientIds
options["appKey"] = constant.GETUI_APP_KEY
options["secret"] = constant.GETUI_APP_SECRET
options["appId"] = constant.GETUI_APP_ID
options["title"] = title
options["content"] = content
options["ext"] = ext
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibPushServiceGateway() *HttplibMmmOpenApiServiceGateway {
return &HttplibMmmOpenApiServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.MMM_OPEN_API_SERVICE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}
... ...
... ... @@ -61,6 +61,30 @@ var _ = Describe("更新任务", func() {
ContainsKey("taskId").ValueEqual("taskId", 1)
})
})
Context("更新指派任务", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "testTaskName", 3, "{}", 1, "{}", 1, pg.Array([]int{1}), 1, 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
Expect(err).NotTo(HaveOccurred())
})
It("返回更新后的任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
}
httpExpect.PUT("/tasks/1").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueEqual("taskId", 1)
})
})
Context("任务不在未发布状态下提交正确的任务数据", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...