Commit d9c0acfd by chenxianqi

update

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