Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
kefu_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0c4b0773
authored
Mar 15, 2020
by
chenxianqi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add api
parent
3210f86b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
5 deletions
controllers/workorder_controller.go
services/workorder_type_service.go
controllers/workorder_controller.go
View file @
0c4b0773
package
controllers
package
controllers
import
(
import
(
"encoding/json"
"kefu_server/configs"
"kefu_server/configs"
"kefu_server/models"
"kefu_server/services"
"kefu_server/services"
)
)
...
@@ -56,7 +58,34 @@ func (c *WorkOrderController) Comment() {
...
@@ -56,7 +58,34 @@ func (c *WorkOrderController) Comment() {
// PostType add work order type
// PostType add work order type
func
(
c
*
WorkOrderController
)
PostType
()
{
func
(
c
*
WorkOrderController
)
PostType
()
{
c
.
JSON
(
configs
.
ResponseSucess
,
"success"
,
nil
)
// 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
)
}
isNew
,
_
,
err
:=
c
.
WorkOrderTypeRepository
.
Add
(
workOrderType
)
if
err
!=
nil
{
c
.
JSON
(
configs
.
ResponseFail
,
"添加失败!"
,
err
)
}
if
!
isNew
{
c
.
JSON
(
configs
.
ResponseFail
,
"类型名称已存在!"
,
err
)
}
c
.
JSON
(
configs
.
ResponseSucess
,
"添加成功!"
,
nil
)
}
}
// GetType get work order type
// GetType get work order type
...
...
services/workorder_type_service.go
View file @
0c4b0773
...
@@ -2,6 +2,7 @@ package services
...
@@ -2,6 +2,7 @@ package services
import
(
import
(
"kefu_server/models"
"kefu_server/models"
"time"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/orm"
...
@@ -9,8 +10,9 @@ import (
...
@@ -9,8 +10,9 @@ import (
// WorkOrderTypeRepositoryInterface interface
// WorkOrderTypeRepositoryInterface interface
type
WorkOrderTypeRepositoryInterface
interface
{
type
WorkOrderTypeRepositoryInterface
interface
{
GetWorkOrder
()
*
models
.
WorkOrderType
GetWorkOrderType
()
*
models
.
WorkOrderType
Update
(
id
int64
,
params
*
orm
.
Params
)
(
int64
,
error
)
Update
(
id
int64
,
params
*
orm
.
Params
)
(
int64
,
error
)
Add
(
data
models
.
WorkOrderType
)
(
bool
,
int64
,
error
)
}
}
// WorkOrderTypeRepository struct
// WorkOrderTypeRepository struct
...
@@ -25,10 +27,18 @@ func GetWorkOrderTypeRepositoryInstance() *WorkOrderTypeRepository {
...
@@ -25,10 +27,18 @@ func GetWorkOrderTypeRepositoryInstance() *WorkOrderTypeRepository {
return
instance
return
instance
}
}
// 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"
)
if
err
!=
nil
{
logs
.
Warn
(
"Add add a WorkOrderType------------"
,
err
)
}
return
isNew
,
row
,
err
}
// 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
)
{
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment