Commit d9c0acfd by chenxianqi

update

parent 0c4b0773
...@@ -79,7 +79,7 @@ func (c *AdminController) Put() { ...@@ -79,7 +79,7 @@ func (c *AdminController) Put() {
admin := models.Admin{} admin := models.Admin{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &admin); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &admin); err != nil {
logs.Warn("Put update admin error------------", err) logs.Warn("Put update admin error------------", err)
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// admin exist // admin exist
...@@ -117,7 +117,7 @@ func (c *AdminController) Put() { ...@@ -117,7 +117,7 @@ func (c *AdminController) Put() {
"Avatar": admin.Avatar, "Avatar": admin.Avatar,
"AutoReply": admin.AutoReply, "AutoReply": admin.AutoReply,
}); err != nil { }); err != nil {
c.JSON(configs.ResponseFail, "更新失败!", &err) c.JSON(configs.ResponseFail, "更新失败!", err.Error())
} }
admin.Password = "******" admin.Password = "******"
...@@ -158,7 +158,7 @@ func (c *AdminController) Post() { ...@@ -158,7 +158,7 @@ func (c *AdminController) Post() {
valid.MaxSize(newAdmin.Password, 16, "password").Message("密码格式不正确,请输入6-16位字母数字下划线为密码!") valid.MaxSize(newAdmin.Password, 16, "password").Message("密码格式不正确,请输入6-16位字母数字下划线为密码!")
if valid.HasErrors() { if valid.HasErrors() {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, &err) c.JSON(configs.ResponseFail, err.Message, err.Error())
} }
} }
...@@ -204,7 +204,7 @@ func (c *AdminController) Delete() { ...@@ -204,7 +204,7 @@ func (c *AdminController) Delete() {
num, err := c.AdminRepository.Delete(id) num, err := c.AdminRepository.Delete(id)
if err != nil || num == 0 { if err != nil || num == 0 {
logs.Info("Delete remove admin error------------", err) logs.Info("Delete remove admin error------------", err)
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成功!", num) c.JSON(configs.ResponseSucess, "删除成功!", num)
} }
...@@ -215,13 +215,13 @@ func (c *AdminController) List() { ...@@ -215,13 +215,13 @@ func (c *AdminController) List() {
// request body // request body
var paginationDto services.AdminPaginationDto var paginationDto services.AdminPaginationDto
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &paginationDto); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &paginationDto); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
data, err := c.AdminRepository.GetAdmins(&paginationDto) data, err := c.AdminRepository.GetAdmins(&paginationDto)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &data) c.JSON(configs.ResponseSucess, "success", &data)
...@@ -232,7 +232,7 @@ func (c *AdminController) UpdatePassword() { ...@@ -232,7 +232,7 @@ func (c *AdminController) UpdatePassword() {
request := services.UpdatePasswordRequest{} request := services.UpdatePasswordRequest{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &request); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &request); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// GetAuthInfo // GetAuthInfo
...@@ -254,7 +254,7 @@ func (c *AdminController) UpdatePassword() { ...@@ -254,7 +254,7 @@ func (c *AdminController) UpdatePassword() {
valid.Required(request.EnterPassword, "enter_password").Message("请再次输入新密码!") valid.Required(request.EnterPassword, "enter_password").Message("请再次输入新密码!")
if valid.HasErrors() { if valid.HasErrors() {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, &err) c.JSON(configs.ResponseFail, err.Message, err.Error())
} }
} }
...@@ -315,7 +315,7 @@ func (c *AdminController) ChangeCurrentUser() { ...@@ -315,7 +315,7 @@ func (c *AdminController) ChangeCurrentUser() {
"CurrentConUser": uid, "CurrentConUser": uid,
}); err != nil { }); err != nil {
logs.Info("ChangeCurrentUser current connect user Warn------------", err) logs.Info("ChangeCurrentUser current connect user Warn------------", err)
c.JSON(configs.ResponseFail, "更新失败!", &err) c.JSON(configs.ResponseFail, "更新失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "更新成功!", nil) c.JSON(configs.ResponseSucess, "更新成功!", nil)
} }
...@@ -340,7 +340,7 @@ func (c *AdminController) Online() { ...@@ -340,7 +340,7 @@ func (c *AdminController) Online() {
if _, err := c.AdminRepository.Update(admin.ID, orm.Params{ if _, err := c.AdminRepository.Update(admin.ID, orm.Params{
"Online": online, "Online": online,
}); err != nil { }); err != nil {
c.JSON(configs.ResponseFail, "更新在线状态失败!", &err) c.JSON(configs.ResponseFail, "更新在线状态失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "更新在线状态成功!", nil) c.JSON(configs.ResponseSucess, "更新在线状态成功!", nil)
......
...@@ -138,11 +138,11 @@ func (c *AuthController) Logout() { ...@@ -138,11 +138,11 @@ func (c *AuthController) Logout() {
"CurrentConUser": 0, "CurrentConUser": 0,
"Online": 0, "Online": 0,
}); err != nil { }); err != nil {
c.JSON(configs.ResponseFail, "退出失败!", &err) c.JSON(configs.ResponseFail, "退出失败!", err.Error())
} }
} }
if row, err := c.AuthsRepository.Delete(auth.ID); err != nil || row == 0 { if row, err := c.AuthsRepository.Delete(auth.ID); err != nil || row == 0 {
c.JSON(configs.ResponseFail, "退出失败!", &err) c.JSON(configs.ResponseFail, "退出失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "退出成功!", nil) c.JSON(configs.ResponseSucess, "退出成功!", nil)
} }
...@@ -43,7 +43,7 @@ func (c *ContactController) GetContacts() { ...@@ -43,7 +43,7 @@ func (c *ContactController) GetContacts() {
contactDto, err := c.ContactRepository.GetContacts(auth.UID) contactDto, err := c.ContactRepository.GetContacts(auth.UID)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
if len(contactDto) == 0 { if len(contactDto) == 0 {
contactDto = []models.ContactDto{} contactDto = []models.ContactDto{}
...@@ -64,7 +64,7 @@ func (c *ContactController) Delete() { ...@@ -64,7 +64,7 @@ func (c *ContactController) Delete() {
rows, err := c.ContactRepository.Delete(id, auth.UID) rows, err := c.ContactRepository.Delete(id, auth.UID)
if err != nil || rows == 0 { if err != nil || rows == 0 {
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成功!", rows) c.JSON(configs.ResponseSucess, "删除成功!", rows)
...@@ -80,7 +80,7 @@ func (c *ContactController) DeleteAll() { ...@@ -80,7 +80,7 @@ func (c *ContactController) DeleteAll() {
rows, err := c.ContactRepository.DeleteAll(auth.UID) rows, err := c.ContactRepository.DeleteAll(auth.UID)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "清空成功!", &err) c.JSON(configs.ResponseFail, "清空成功!", err.Error())
} }
c.JSON(configs.ResponseSucess, "清空成功!", rows) c.JSON(configs.ResponseSucess, "清空成功!", rows)
} }
......
...@@ -37,7 +37,7 @@ func (c *HomeController) Statistical() { ...@@ -37,7 +37,7 @@ func (c *HomeController) Statistical() {
// request body // request body
statisticalRequest := StatisticalRequest{} statisticalRequest := StatisticalRequest{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &statisticalRequest); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &statisticalRequest); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// validation // validation
...@@ -46,13 +46,13 @@ func (c *HomeController) Statistical() { ...@@ -46,13 +46,13 @@ func (c *HomeController) Statistical() {
valid.Required(statisticalRequest.DateEnd, "date_end").Message("date_end不能为空!") valid.Required(statisticalRequest.DateEnd, "date_end").Message("date_end不能为空!")
if valid.HasErrors() { if valid.HasErrors() {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, &err) c.JSON(configs.ResponseFail, err.Message, err.Error())
} }
} }
countsArr, err := c.StatisticalRepository.GetStatisticals(statisticalRequest.DateStart, statisticalRequest.DateEnd) countsArr, err := c.StatisticalRepository.GetStatisticals(statisticalRequest.DateStart, statisticalRequest.DateEnd)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, err.Error(), &err) c.JSON(configs.ResponseFail, err.Error(), err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &countsArr) c.JSON(configs.ResponseSucess, "success", &countsArr)
...@@ -65,7 +65,7 @@ func (c *HomeController) TodayActionStatistical() { ...@@ -65,7 +65,7 @@ func (c *HomeController) TodayActionStatistical() {
// request body // request body
statisticalRequest := StatisticalRequest{} statisticalRequest := StatisticalRequest{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &statisticalRequest); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &statisticalRequest); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// validation // validation
...@@ -74,13 +74,13 @@ func (c *HomeController) TodayActionStatistical() { ...@@ -74,13 +74,13 @@ func (c *HomeController) TodayActionStatistical() {
valid.Required(statisticalRequest.DateEnd, "date_end").Message("date_end不能为空!") valid.Required(statisticalRequest.DateEnd, "date_end").Message("date_end不能为空!")
if valid.HasErrors() { if valid.HasErrors() {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, &err) c.JSON(configs.ResponseFail, err.Message, err.Error())
} }
} }
statisticalData, err := c.StatisticalRepository.GetTodayActionStatistical(statisticalRequest.DateStart, statisticalRequest.DateEnd) statisticalData, err := c.StatisticalRepository.GetTodayActionStatistical(statisticalRequest.DateStart, statisticalRequest.DateEnd)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, err.Error(), &err) c.JSON(configs.ResponseFail, err.Error(), err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &statisticalData) c.JSON(configs.ResponseSucess, "success", &statisticalData)
......
...@@ -39,7 +39,7 @@ func (c *KnowledgeBaseController) Get() { ...@@ -39,7 +39,7 @@ func (c *KnowledgeBaseController) Get() {
id, err := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64) id, err := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
knowledgeBase := c.KnowledgeBaseRepository.GetKnowledgeBase(id) knowledgeBase := c.KnowledgeBaseRepository.GetKnowledgeBase(id)
...@@ -58,7 +58,7 @@ func (c *KnowledgeBaseController) Post() { ...@@ -58,7 +58,7 @@ func (c *KnowledgeBaseController) Post() {
var knowledgeBase models.KnowledgeBase var knowledgeBase models.KnowledgeBase
knowledgeBase.CreateAt = time.Now().Unix() knowledgeBase.CreateAt = time.Now().Unix()
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &knowledgeBase); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &knowledgeBase); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// validation // validation
...@@ -84,7 +84,7 @@ func (c *KnowledgeBaseController) Post() { ...@@ -84,7 +84,7 @@ func (c *KnowledgeBaseController) Post() {
} }
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "添加失败!", &err) c.JSON(configs.ResponseFail, "添加失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "添加成功!", index) c.JSON(configs.ResponseSucess, "添加成功!", index)
...@@ -96,7 +96,7 @@ func (c *KnowledgeBaseController) Put() { ...@@ -96,7 +96,7 @@ func (c *KnowledgeBaseController) Put() {
// request body // request body
var newKnowledgeBase models.KnowledgeBase var newKnowledgeBase models.KnowledgeBase
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &newKnowledgeBase); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &newKnowledgeBase); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// validation // validation
...@@ -106,7 +106,7 @@ func (c *KnowledgeBaseController) Put() { ...@@ -106,7 +106,7 @@ func (c *KnowledgeBaseController) Put() {
valid.Required(newKnowledgeBase.UID, "uid").Message("用户ID不能为空!") valid.Required(newKnowledgeBase.UID, "uid").Message("用户ID不能为空!")
if valid.HasErrors() { if valid.HasErrors() {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, &err) c.JSON(configs.ResponseFail, err.Message, err.Error())
} }
} }
...@@ -137,7 +137,7 @@ func (c *KnowledgeBaseController) Put() { ...@@ -137,7 +137,7 @@ func (c *KnowledgeBaseController) Put() {
}) })
if err != nil || row == 0 { if err != nil || row == 0 {
c.JSON(configs.ResponseFail, "更新失败!", &err) c.JSON(configs.ResponseFail, "更新失败!", err.Error())
} }
if oldKnowledgeBase != nil { if oldKnowledgeBase != nil {
...@@ -155,7 +155,7 @@ func (c *KnowledgeBaseController) Delete() { ...@@ -155,7 +155,7 @@ func (c *KnowledgeBaseController) Delete() {
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64) id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
num, err := c.KnowledgeBaseRepository.Delete(id) num, err := c.KnowledgeBaseRepository.Delete(id)
if err != nil || num == 0 { if err != nil || num == 0 {
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成功!", num) c.JSON(configs.ResponseSucess, "删除成功!", num)
...@@ -167,13 +167,13 @@ func (c *KnowledgeBaseController) List() { ...@@ -167,13 +167,13 @@ func (c *KnowledgeBaseController) List() {
// request body // request body
var knowledgePaginationDto *models.KnowledgePaginationDto var knowledgePaginationDto *models.KnowledgePaginationDto
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &knowledgePaginationDto); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &knowledgePaginationDto); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// query // query
knowledgePaginationDto, err := c.KnowledgeBaseRepository.GetKnowledgeBases(knowledgePaginationDto) knowledgePaginationDto, err := c.KnowledgeBaseRepository.GetKnowledgeBases(knowledgePaginationDto)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &knowledgePaginationDto) c.JSON(configs.ResponseSucess, "success", &knowledgePaginationDto)
......
...@@ -59,7 +59,7 @@ func (c *MessageController) List() { ...@@ -59,7 +59,7 @@ func (c *MessageController) List() {
// query messages // query messages
returnMessagePaginationDto, err := c.MessageRepository.GetAdminMessages(messagePaginationDto) returnMessagePaginationDto, err := c.MessageRepository.GetAdminMessages(messagePaginationDto)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
// push notify update current service contacts list // push notify update current service contacts list
...@@ -90,7 +90,7 @@ func (c *MessageController) Remove() { ...@@ -90,7 +90,7 @@ func (c *MessageController) Remove() {
row, err := c.MessageRepository.Delete(removeRequestDto) row, err := c.MessageRepository.Delete(removeRequestDto)
if err != nil || row == 0 { if err != nil || row == 0 {
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成!", row) c.JSON(configs.ResponseSucess, "删除成!", row)
......
...@@ -168,7 +168,7 @@ func (c *PlatformController) Delete() { ...@@ -168,7 +168,7 @@ func (c *PlatformController) Delete() {
} }
if _, err := c.PlatformRepository.Delete(id); err != nil { if _, err := c.PlatformRepository.Delete(id); err != nil {
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成功!", nil) c.JSON(configs.ResponseSucess, "删除成功!", nil)
...@@ -180,7 +180,7 @@ func (c *PlatformController) List() { ...@@ -180,7 +180,7 @@ func (c *PlatformController) List() {
platforms, err := c.PlatformRepository.GetPlatformAll("id") platforms, err := c.PlatformRepository.GetPlatformAll("id")
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &platforms) c.JSON(configs.ResponseSucess, "success", &platforms)
......
...@@ -101,7 +101,7 @@ func (c *PublicController) Register() { ...@@ -101,7 +101,7 @@ func (c *PublicController) Register() {
// fetchResult // fetchResult
fetchResult, fetchError = utils.CreateMiMcToken(strconv.FormatInt(user.ID, 10)) fetchResult, fetchError = utils.CreateMiMcToken(strconv.FormatInt(user.ID, 10))
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil { if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", &err) c.JSON(configs.ResponseFail, "注册失败!", err.Error())
} }
// update userinfo // update userinfo
c.UserRepository.Update(user.ID, orm.Params{ c.UserRepository.Update(user.ID, orm.Params{
...@@ -127,7 +127,7 @@ func (c *PublicController) Register() { ...@@ -127,7 +127,7 @@ func (c *PublicController) Register() {
fetchResult, fetchError = utils.CreateMiMcToken(strconv.FormatInt(accountID, 10)) fetchResult, fetchError = utils.CreateMiMcToken(strconv.FormatInt(accountID, 10))
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil { if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", &err) c.JSON(configs.ResponseFail, "注册失败!", err.Error())
} }
// update userinfo // update userinfo
...@@ -137,7 +137,7 @@ func (c *PublicController) Register() { ...@@ -137,7 +137,7 @@ func (c *PublicController) Register() {
}) })
} else { } else {
c.JSON(configs.ResponseFail, "注册失败!", &err) c.JSON(configs.ResponseFail, "注册失败!", err.Error())
} }
} }
...@@ -152,13 +152,13 @@ func (c *PublicController) Register() { ...@@ -152,13 +152,13 @@ func (c *PublicController) Register() {
// imTokenDto // imTokenDto
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil { if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", &err) c.JSON(configs.ResponseFail, "注册失败!", err.Error())
} }
} }
// is Error ? // is Error ?
if fetchError != nil { if fetchError != nil {
c.JSON(configs.ResponseFail, "注册失败!", &fetchError) c.JSON(configs.ResponseFail, "注册失败!", fetchError.Error())
} }
// response data // response data
...@@ -230,7 +230,7 @@ func (c *PublicController) CleanRead() { ...@@ -230,7 +230,7 @@ func (c *PublicController) CleanRead() {
// clear // clear
if _, err := c.MessageRepository.ClearRead(uid); err != nil { if _, err := c.MessageRepository.ClearRead(uid); err != nil {
c.JSON(configs.ResponseFail, "清除失败!", &err) c.JSON(configs.ResponseFail, "清除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "清除成功!", nil) c.JSON(configs.ResponseSucess, "清除成功!", nil)
...@@ -246,7 +246,7 @@ func (c *PublicController) Robot() { ...@@ -246,7 +246,7 @@ func (c *PublicController) Robot() {
// get robot // get robot
robot, err := services.GetRobotRepositoryInstance().GetRobotWithOnline(pid) robot, err := services.GetRobotRepositoryInstance().GetRobotWithOnline(pid)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &robot) c.JSON(configs.ResponseSucess, "success", &robot)
...@@ -322,7 +322,7 @@ func (c *PublicController) LastActivity() { ...@@ -322,7 +322,7 @@ func (c *PublicController) LastActivity() {
"LastActivity": time.Now().Unix(), "LastActivity": time.Now().Unix(),
}) })
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail,用户不存在!", &err) c.JSON(configs.ResponseFail, "fail,用户不存在!", err.Error())
} }
c.JSON(configs.ResponseSucess, "上报成功!", nil) c.JSON(configs.ResponseSucess, "上报成功!", nil)
} }
...@@ -334,7 +334,7 @@ func (c *PublicController) LastActivity() { ...@@ -334,7 +334,7 @@ func (c *PublicController) LastActivity() {
"LastActivity": time.Now().Unix(), "LastActivity": time.Now().Unix(),
}) })
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail,用户不存在!", &err) c.JSON(configs.ResponseFail, "fail,用户不存在!", err.Error())
} }
c.JSON(configs.ResponseSucess, "上报成功!", nil) c.JSON(configs.ResponseSucess, "上报成功!", nil)
...@@ -417,13 +417,13 @@ func (c *PublicController) Upload() { ...@@ -417,13 +417,13 @@ func (c *PublicController) Upload() {
uploadDir := "static/uploads/images/" + time.Now().Format("2006-01-02") + "/" uploadDir := "static/uploads/images/" + time.Now().Format("2006-01-02") + "/"
err := os.MkdirAll(uploadDir, os.ModePerm) err := os.MkdirAll(uploadDir, os.ModePerm)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "上传失败,创建文件夹失败!", &err) c.JSON(configs.ResponseFail, "上传失败,创建文件夹失败!", err.Error())
} }
fpath := uploadDir + fileName fpath := uploadDir + fileName
defer f.Close() defer f.Close()
err = c.SaveToFile("file", fpath) err = c.SaveToFile("file", fpath)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "上传失败!", &err) c.JSON(configs.ResponseFail, "上传失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "上传成功!", "/"+fpath) c.JSON(configs.ResponseSucess, "上传成功!", "/"+fpath)
...@@ -452,7 +452,7 @@ func (c *PublicController) CancelMessage() { ...@@ -452,7 +452,7 @@ func (c *PublicController) CancelMessage() {
_, err := messageRepository.Delete(removeMessageRequestDto) _, err := messageRepository.Delete(removeMessageRequestDto)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "撤回失败!", &err) c.JSON(configs.ResponseFail, "撤回失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "撤回成功!", nil) c.JSON(configs.ResponseSucess, "撤回成功!", nil)
...@@ -501,7 +501,7 @@ func (c *PublicController) GetMessageHistoryList() { ...@@ -501,7 +501,7 @@ func (c *PublicController) GetMessageHistoryList() {
// query messages // query messages
returnMessagePaginationDto, err := c.MessageRepository.GetUserMessages(messagePaginationDto) returnMessagePaginationDto, err := c.MessageRepository.GetUserMessages(messagePaginationDto)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &returnMessagePaginationDto) c.JSON(configs.ResponseSucess, "success", &returnMessagePaginationDto)
......
...@@ -91,7 +91,7 @@ func (c *QiniuController) Put() { ...@@ -91,7 +91,7 @@ func (c *QiniuController) Put() {
"Host": qiniuSetting.Host, "Host": qiniuSetting.Host,
"UpdateAt": time.Now().Unix(), "UpdateAt": time.Now().Unix(),
}); err != nil { }); err != nil {
c.JSON(configs.ResponseFail, "更新失败!", &err) c.JSON(configs.ResponseFail, "更新失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "更新成功!", &qiniuSetting) c.JSON(configs.ResponseSucess, "更新成功!", &qiniuSetting)
......
...@@ -97,7 +97,7 @@ func (c *RobotController) Post() { ...@@ -97,7 +97,7 @@ func (c *RobotController) Post() {
var robot models.Robot var robot models.Robot
robot.CreateAt = time.Now().Unix() robot.CreateAt = time.Now().Unix()
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &robot); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &robot); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// is exist platform? // is exist platform?
......
...@@ -31,7 +31,7 @@ func (c *ServicesStatisticalController) List() { ...@@ -31,7 +31,7 @@ func (c *ServicesStatisticalController) List() {
// request body // request body
var paginationDto models.ServicesStatisticalPaginationDto var paginationDto models.ServicesStatisticalPaginationDto
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &paginationDto); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &paginationDto); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// validation // validation
......
...@@ -122,7 +122,7 @@ func (c *ShortcutController) Delete() { ...@@ -122,7 +122,7 @@ func (c *ShortcutController) Delete() {
auth := c.GetAuthInfo() auth := c.GetAuthInfo()
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64) id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
if row, err := c.ShortcutRepository.Delete(id, auth.UID); err != nil || row == 0 { if row, err := c.ShortcutRepository.Delete(id, auth.UID); err != nil || row == 0 {
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成功!!", nil) c.JSON(configs.ResponseSucess, "删除成功!!", nil)
} }
......
...@@ -82,7 +82,7 @@ func (c *SystemController) Put() { ...@@ -82,7 +82,7 @@ func (c *SystemController) Put() {
"UpdateAt": time.Now().Unix(), "UpdateAt": time.Now().Unix(),
}) })
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "更新失败!", &err) c.JSON(configs.ResponseFail, "更新失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "更新成功!", &system) c.JSON(configs.ResponseSucess, "更新成功!", &system)
} }
...@@ -74,7 +74,7 @@ func (c *UserController) Put() { ...@@ -74,7 +74,7 @@ func (c *UserController) Put() {
"Avatar": user.Avatar, "Avatar": user.Avatar,
}) })
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "更新失败!", &err) c.JSON(configs.ResponseFail, "更新失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "更新成功!", nil) c.JSON(configs.ResponseSucess, "更新成功!", nil)
} }
...@@ -108,7 +108,7 @@ func (c *UserController) Delete() { ...@@ -108,7 +108,7 @@ func (c *UserController) Delete() {
// delete // delete
if _, err := c.UserRepository.Delete(id); err != nil { if _, err := c.UserRepository.Delete(id); err != nil {
c.JSON(configs.ResponseFail, "删除失败!", &err) c.JSON(configs.ResponseFail, "删除失败!", err.Error())
} }
c.JSON(configs.ResponseSucess, "删除成功!", nil) c.JSON(configs.ResponseSucess, "删除成功!", nil)
...@@ -121,7 +121,7 @@ func (c *UserController) Users() { ...@@ -121,7 +121,7 @@ func (c *UserController) Users() {
// request body // request body
var usersPaginationDto models.UsersPaginationDto var usersPaginationDto models.UsersPaginationDto
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &usersPaginationDto); err != nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &usersPaginationDto); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", &err) c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
} }
// validation // validation
...@@ -130,14 +130,14 @@ func (c *UserController) Users() { ...@@ -130,14 +130,14 @@ func (c *UserController) Users() {
valid.Required(usersPaginationDto.PageSize, "page_size").Message("page_size不能为空!") valid.Required(usersPaginationDto.PageSize, "page_size").Message("page_size不能为空!")
if valid.HasErrors() { if valid.HasErrors() {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, &err) c.JSON(configs.ResponseFail, err.Message, err.Error())
} }
} }
// get users // get users
res, err := c.UserRepository.GetUsers(&usersPaginationDto) res, err := c.UserRepository.GetUsers(&usersPaginationDto)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &res) c.JSON(configs.ResponseSucess, "success", &res)
...@@ -148,7 +148,7 @@ func (c *UserController) OnLineCount() { ...@@ -148,7 +148,7 @@ func (c *UserController) OnLineCount() {
rows, err := c.UserRepository.GetOnlineCount() rows, err := c.UserRepository.GetOnlineCount()
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "fail", &err) c.JSON(configs.ResponseFail, "fail", err.Error())
} }
c.JSON(configs.ResponseSucess, "success", &rows) c.JSON(configs.ResponseSucess, "success", &rows)
......
...@@ -5,6 +5,9 @@ import ( ...@@ -5,6 +5,9 @@ import (
"kefu_server/configs" "kefu_server/configs"
"kefu_server/models" "kefu_server/models"
"kefu_server/services" "kefu_server/services"
"strconv"
"github.com/astaxie/beego/orm"
) )
// WorkOrderController struct // WorkOrderController struct
...@@ -56,8 +59,8 @@ func (c *WorkOrderController) Comment() { ...@@ -56,8 +59,8 @@ func (c *WorkOrderController) Comment() {
} }
// PostType add work order type // PostWorkType add work order type
func (c *WorkOrderController) PostType() { func (c *WorkOrderController) PostWorkType() {
// GetAuthInfo // GetAuthInfo
auth := c.GetAuthInfo() auth := c.GetAuthInfo()
...@@ -77,20 +80,79 @@ func (c *WorkOrderController) PostType() { ...@@ -77,20 +80,79 @@ func (c *WorkOrderController) PostType() {
c.JSON(configs.ResponseFail, "类型标题不能为空!!", nil) c.JSON(configs.ResponseFail, "类型标题不能为空!!", nil)
} }
isNew, _, err := c.WorkOrderTypeRepository.Add(workOrderType) isNew, id, err := c.WorkOrderTypeRepository.Add(workOrderType)
if err != nil { if err != nil {
c.JSON(configs.ResponseFail, "添加失败!", err) c.JSON(configs.ResponseFail, "添加失败!", err.Error())
} }
if !isNew { if !isNew {
c.JSON(configs.ResponseFail, "类型名称已存在!", err) c.JSON(configs.ResponseFail, "类型名称已存在!", nil)
}
c.JSON(configs.ResponseSucess, "添加成功!", id)
}
// UpdateWorkType update work order type
func (c *WorkOrderController) UpdateWorkType() {
// GetAuthInfo
auth := c.GetAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin != nil && admin.Root != 1 {
c.JSON(configs.ResponseFail, "没有权限!", nil)
}
// request body
var workOrderType models.WorkOrderType
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &workOrderType); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
// validation
if workOrderType.Title == "" {
c.JSON(configs.ResponseFail, "类型标题不能为空!!", nil)
}
_, err := c.WorkOrderTypeRepository.Update(workOrderType.ID, orm.Params{
"title": workOrderType.Title,
})
if err != nil {
c.JSON(configs.ResponseFail, "修改失败!", err.Error())
}
c.JSON(configs.ResponseSucess, "修改成功!", nil)
}
// DeleteWorkType delete work order type
func (c *WorkOrderController) DeleteWorkType() {
// GetAuthInfo
auth := c.GetAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin != nil && admin.Root != 1 {
c.JSON(configs.ResponseFail, "没有权限!", nil)
} }
c.JSON(configs.ResponseSucess, "添加成功!", nil) // id
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
row, _ := c.WorkOrderTypeRepository.Delete(id)
if row == 0 {
c.JSON(configs.ResponseFail, "删除失败!", nil)
}
c.JSON(configs.ResponseSucess, "删除成功!", nil)
} }
// GetType get work order type // GetType get work order type
func (c *WorkOrderController) GetType() { func (c *WorkOrderController) GetType() {
// id
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
workOrderType, err := c.WorkOrderTypeRepository.GetWorkOrderType(id)
if err != nil {
c.JSON(configs.ResponseFail, "查询失败!", err.Error())
}
c.JSON(configs.ResponseSucess, "查询成功!", workOrderType)
} }
// GetTypes get work order types // GetTypes get work order types
......
...@@ -2,7 +2,7 @@ package models ...@@ -2,7 +2,7 @@ package models
// WorkOrderType model // WorkOrderType model
type WorkOrderType struct { type WorkOrderType struct {
ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // ID ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // ID
Title string `orm:"type(varchar);null;column(title)" json:"title"` // 类型名称 Title string `orm:"unique;type(varchar);null;column(title)" json:"title"` // 类型名称
CreateAt int64 `orm:"type(bigint);column(create_at)" json:"create_at"` // 提交时间 CreateAt int64 `orm:"type(bigint);column(create_at)" json:"create_at"` // 提交时间
} }
...@@ -155,7 +155,9 @@ func init() { ...@@ -155,7 +155,9 @@ func init() {
// Work Order // Work Order
beego.NSNamespace("/workorder", beego.NSNamespace("/workorder",
beego.NSBefore(filters.FilterToken), beego.NSBefore(filters.FilterToken),
beego.NSRouter("/type", &controllers.WorkOrderController{}, "post:PostType"), beego.NSRouter("/type", &controllers.WorkOrderController{}, "post:PostWorkType"),
beego.NSRouter("/type", &controllers.WorkOrderController{}, "put:UpdateWorkType"),
beego.NSRouter("/type/:id", &controllers.WorkOrderController{}, "delete:DeleteWorkType"),
), ),
) )
beego.AddNamespace(ns) beego.AddNamespace(ns)
......
package services package services
import ( import (
"errors"
"kefu_server/models" "kefu_server/models"
"time" "time"
...@@ -10,8 +11,10 @@ import ( ...@@ -10,8 +11,10 @@ import (
// WorkOrderTypeRepositoryInterface interface // WorkOrderTypeRepositoryInterface interface
type WorkOrderTypeRepositoryInterface interface { type WorkOrderTypeRepositoryInterface interface {
GetWorkOrderType() *models.WorkOrderType GetWorkOrderType(id int64) (models.WorkOrderType, error)
Update(id int64, params *orm.Params) (int64, error) GetWorkOrderTypes() []models.WorkOrderType
Update(id int64, params orm.Params) (int64, error)
Delete(id int64) (int64, error)
Add(data models.WorkOrderType) (bool, int64, error) Add(data models.WorkOrderType) (bool, int64, error)
} }
...@@ -30,15 +33,51 @@ func GetWorkOrderTypeRepositoryInstance() *WorkOrderTypeRepository { ...@@ -30,15 +33,51 @@ func GetWorkOrderTypeRepositoryInstance() *WorkOrderTypeRepository {
// Add add a WorkOrderType // Add add a WorkOrderType
func (r *WorkOrderTypeRepository) Add(data models.WorkOrderType) (bool, int64, error) { func (r *WorkOrderTypeRepository) Add(data models.WorkOrderType) (bool, int64, error) {
data.CreateAt = time.Now().Unix() data.CreateAt = time.Now().Unix()
isNew, row, err := r.o.ReadOrCreate(&data, "title") isNew, id, err := r.o.ReadOrCreate(&data, "title")
if err != nil { if err != nil {
logs.Warn("Add add a WorkOrderType------------", err) logs.Warn("Add add a WorkOrderType------------", err)
} }
return isNew, row, err return isNew, id, err
}
// Delete del a WorkOrderType
func (r *WorkOrderTypeRepository) Delete(id int64) (int64, error) {
// 增加工单分类检查是否有内容
row, err := r.q.Filter("id", id).Delete()
if err != nil {
logs.Warn("Delete del a WorkOrderType------------", err)
}
return row, err
}
// GetWorkOrderType get
func (r *WorkOrderTypeRepository) GetWorkOrderType(id int64) (models.WorkOrderType, error) {
var workOrderType models.WorkOrderType
err := r.q.Filter("id", id).One(&workOrderType)
if err != nil {
logs.Warn(" GetWorkOrderType get------------", err)
}
return workOrderType, err
}
// GetWorkOrderTypes get all
func (r *WorkOrderTypeRepository) GetWorkOrderTypes() []models.WorkOrderType {
var workOrderTypes []models.WorkOrderType
_, err := r.q.All(&workOrderTypes)
if err != nil {
logs.Warn("GetWorkOrderTypes get all------------", err)
return []models.WorkOrderType{}
}
return workOrderTypes
} }
// Update WorkOrderType Info // Update WorkOrderType Info
func (r *WorkOrderTypeRepository) Update(id int64, params orm.Params) (int64, error) { func (r *WorkOrderTypeRepository) Update(id int64, params orm.Params) (int64, error) {
var res models.WorkOrderType
err := r.q.Filter("id", id).Filter("title", params["title"].(string)).One(&res)
if err == nil {
return 0, errors.New("title already exists")
}
index, err := r.q.Filter("id", id).Update(params) index, err := r.q.Filter("id", id).Update(params)
if err != nil { if err != nil {
logs.Warn("Update WorkOrderType Info------------", err) logs.Warn("Update WorkOrderType Info------------", err)
......
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