Merge branch 'master' of https://gitee.com/290198252/background
# Conflicts: # .idea/workspace.xml # .vscode/launch.json # main.gomaster
commit
8bb59b135d
|
@ -2,9 +2,13 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="7cf7b6b3-0082-44ef-bb0f-bfcc57e19eb1" name="Default Changelist" comment="">
|
<list default="true" id="7cf7b6b3-0082-44ef-bb0f-bfcc57e19eb1" name="Default Changelist" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/fork.go" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
|
||||||
|
>>>>>>> aeb0b55a434d20bb6af252ba0528414a00fe60d8
|
||||||
</list>
|
</list>
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
@ -31,13 +35,23 @@
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
<<<<<<< HEAD
|
||||||
<component name="GOROOT" path="C:\Go" />
|
<component name="GOROOT" path="C:\Go" />
|
||||||
|
=======
|
||||||
|
<component name="GOROOT" path="$PROJECT_DIR$/../../../../Program Files/go" />
|
||||||
|
>>>>>>> aeb0b55a434d20bb6af252ba0528414a00fe60d8
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectId" id="1OeBjD7R4KFQzfWAqpMf9jlmzxr" />
|
<component name="ProjectId" id="1OeBjD7R4KFQzfWAqpMf9jlmzxr" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
<property name="DefaultGoTemplateProperty" value="Go File" />
|
<property name="DefaultGoTemplateProperty" value="Go File" />
|
||||||
|
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||||
|
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||||
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||||
<property name="configurable.Global.GOPATH.is.expanded" value="true" />
|
<property name="configurable.Global.GOPATH.is.expanded" value="true" />
|
||||||
|
@ -45,23 +59,18 @@
|
||||||
<property name="configurable.Project.GOPATH.is.expanded" value="true" />
|
<property name="configurable.Project.GOPATH.is.expanded" value="true" />
|
||||||
<property name="go.import.settings.migrated" value="true" />
|
<property name="go.import.settings.migrated" value="true" />
|
||||||
<property name="go.sdk.automatically.set" value="true" />
|
<property name="go.sdk.automatically.set" value="true" />
|
||||||
|
<<<<<<< HEAD
|
||||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
<property name="restartRequiresConfirmation" value="false" />
|
<property name="restartRequiresConfirmation" value="false" />
|
||||||
<property name="settings.editor.selected.configurable" value="vcs.Git" />
|
<property name="settings.editor.selected.configurable" value="vcs.Git" />
|
||||||
|
=======
|
||||||
|
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
|
||||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$/../gobase" />
|
||||||
|
<property name="nodejs_package_manager_path" value="npm" />
|
||||||
|
<property name="settings.editor.selected.configurable" value="go.sdk" />
|
||||||
|
>>>>>>> aeb0b55a434d20bb6af252ba0528414a00fe60d8
|
||||||
</component>
|
</component>
|
||||||
<component name="RunDashboard">
|
<component name="RunManager" selected="Go Build.background">
|
||||||
<option name="ruleStates">
|
|
||||||
<list>
|
|
||||||
<RuleState>
|
|
||||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
|
||||||
</RuleState>
|
|
||||||
<RuleState>
|
|
||||||
<option name="name" value="StatusDashboardGroupingRule" />
|
|
||||||
</RuleState>
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="RunManager">
|
|
||||||
<configuration name="background" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
<configuration name="background" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
||||||
<module name="background" />
|
<module name="background" />
|
||||||
<working_directory value="$PROJECT_DIR$/" />
|
<working_directory value="$PROJECT_DIR$/" />
|
||||||
|
@ -74,21 +83,94 @@
|
||||||
<output_directory value="$PROJECT_DIR$/" />
|
<output_directory value="$PROJECT_DIR$/" />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="fork2" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
|
||||||
|
<module name="background" />
|
||||||
|
<working_directory value="$PROJECT_DIR$/" />
|
||||||
|
<parameters value="background.exe" />
|
||||||
|
<kind value="FILE" />
|
||||||
|
<filePath value="$PROJECT_DIR$/fork.go" />
|
||||||
|
<package value="background" />
|
||||||
|
<directory value="$PROJECT_DIR$/" />
|
||||||
|
<output_directory value="$PROJECT_DIR$" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Go Build.background" />
|
||||||
|
<item itemvalue="Go Build.fork2" />
|
||||||
|
</list>
|
||||||
|
<recent_temporary>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Go Build.fork2" />
|
||||||
|
</list>
|
||||||
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="1" />
|
<option name="version" value="2" />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
<option name="TAB_STATES">
|
<option name="TAB_STATES">
|
||||||
<map>
|
<map>
|
||||||
<entry key="MAIN">
|
<entry key="MAIN">
|
||||||
<value>
|
<value>
|
||||||
<State>
|
<State />
|
||||||
<option name="COLUMN_ORDER" />
|
|
||||||
</State>
|
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="oldMeFiltersMigrated" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="WindowStateProjectService">
|
||||||
|
<state x="767" y="429" key="#Go_Modules" timestamp="1595431702688">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state x="767" y="429" key="#Go_Modules/0.40.2048.1112@0.40.2048.1112" timestamp="1595431702688" />
|
||||||
|
<state x="479" y="251" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1595778748175">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state x="479" y="251" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.40.2048.1112@0.40.2048.1112" timestamp="1595778748175" />
|
||||||
|
<state x="805" y="351" key="FileChooserDialogImpl" timestamp="1595857317209">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state x="805" y="351" key="FileChooserDialogImpl/0.40.2048.1112@0.40.2048.1112" timestamp="1595857317209" />
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.bottom" timestamp="1595778772403">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.bottom/0.40.2048.1112@0.40.2048.1112" timestamp="1595778772403" />
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.center" timestamp="1595778772403">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.center/0.40.2048.1112@0.40.2048.1112" timestamp="1595778772403" />
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.left" timestamp="1595778772403">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.left/0.40.2048.1112@0.40.2048.1112" timestamp="1595778772403" />
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.right" timestamp="1595778772403">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="305" key="GridCell.Tab.0.right/0.40.2048.1112@0.40.2048.1112" timestamp="1595778772403" />
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.bottom" timestamp="1595433941254">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.bottom/0.40.2048.1112@0.40.2048.1112" timestamp="1595433941254" />
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.center" timestamp="1595433941254">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.center/0.40.2048.1112@0.40.2048.1112" timestamp="1595433941254" />
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.left" timestamp="1595433941254">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.left/0.40.2048.1112@0.40.2048.1112" timestamp="1595433941254" />
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.right" timestamp="1595433941254">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state width="2005" height="376" key="GridCell.Tab.1.right/0.40.2048.1112@0.40.2048.1112" timestamp="1595433941254" />
|
||||||
|
<state x="526" y="240" key="SettingsEditor" timestamp="1595432383541">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state x="526" y="240" key="SettingsEditor/0.40.2048.1112@0.40.2048.1112" timestamp="1595432383541" />
|
||||||
|
<state x="687" y="283" width="672" height="678" key="search.everywhere.popup" timestamp="1595757093391">
|
||||||
|
<screen x="0" y="40" width="2048" height="1112" />
|
||||||
|
</state>
|
||||||
|
<state x="687" y="283" width="672" height="678" key="search.everywhere.popup/0.40.2048.1112@0.40.2048.1112" timestamp="1595757093391" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,42 @@
|
||||||
|
listen_api: 4596
|
||||||
|
runmode: debug
|
||||||
|
max_conn: 121
|
||||||
|
logs:
|
||||||
|
dir: /var/log/user
|
||||||
|
file: user.log
|
||||||
|
level: 1
|
||||||
|
savefile: false
|
||||||
|
redis1:
|
||||||
|
addr: 49.235.25.67:16379
|
||||||
|
password: ~
|
||||||
|
db: 1
|
||||||
|
mysql:
|
||||||
|
addr: 49.235.25.67
|
||||||
|
user: caiyu
|
||||||
|
password: 12345678
|
||||||
|
db: background
|
||||||
|
max_open: 100
|
||||||
|
MaxIdle: 99
|
||||||
|
elasticsearch:
|
||||||
|
address: http://hyrtc.net:9200
|
||||||
|
mysql1:
|
||||||
|
addr: 49.235.25.67
|
||||||
|
user: caiyu
|
||||||
|
password: 12345678
|
||||||
|
db: background
|
||||||
|
max_open: 100
|
||||||
|
MaxIdle: 99
|
||||||
|
mongo:
|
||||||
|
addr: 49.235.25.67
|
||||||
|
port: 27017
|
||||||
|
user: root
|
||||||
|
password: root
|
||||||
|
db: test
|
||||||
|
max_open: 100
|
||||||
|
MaxIdle: 99
|
||||||
|
ca_cert: ""
|
||||||
|
client_cert: ""
|
||||||
|
client_key: ""
|
||||||
|
test_arr:
|
||||||
|
- 1
|
||||||
|
- 23
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"description": "{{.Description}}",
|
||||||
|
"title": "大厅功能api",
|
||||||
|
"contact": {},
|
||||||
|
"license": {},
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"host": "localhost:8080",
|
||||||
|
"basePath": "/api/v1",
|
||||||
|
"paths": {}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
basePath: /api/v1
|
||||||
|
host: localhost:8080
|
||||||
|
info:
|
||||||
|
contact: {}
|
||||||
|
description: '{{.Description}}'
|
||||||
|
license: {}
|
||||||
|
title: 大厅功能api
|
||||||
|
version: "1.0"
|
||||||
|
paths: {}
|
||||||
|
swagger: "2.0"
|
|
@ -5,24 +5,25 @@ import (
|
||||||
"background/logs"
|
"background/logs"
|
||||||
"background/model"
|
"background/model"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"qiniupkg.com/x/log.v7"
|
"qiniupkg.com/x/log.v7"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPageParaFromQuery(c *gin.Context) (int,int){
|
func GetPageParaFromQuery(c *gin.Context) (int, int) {
|
||||||
limit := c.Query("limit")
|
limit := c.Query("limit")
|
||||||
offset := c.Query("offset")
|
offset := c.Query("offset")
|
||||||
|
|
||||||
iLmit,e := strconv.Atoi(limit)
|
iLmit, e := strconv.Atoi(limit)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
return 0,0
|
return 0, 0
|
||||||
}
|
}
|
||||||
iOffset,e := strconv.Atoi(offset)
|
iOffset, e := strconv.Atoi(offset)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
return 0,0
|
return 0, 0
|
||||||
}
|
}
|
||||||
return iLmit,iOffset
|
return iLmit, iOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArticles(c *gin.Context) {
|
func GetArticles(c *gin.Context) {
|
||||||
|
@ -31,68 +32,68 @@ func GetArticles(c *gin.Context) {
|
||||||
Type int32 `json:"types"`
|
Type int32 `json:"types"`
|
||||||
}
|
}
|
||||||
var req ReqArticles
|
var req ReqArticles
|
||||||
rsp := RespBase{"ERR",-1,nil}
|
rsp := RespBase{"ERR", -1, nil}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
e := c.BindJSON(&req)
|
e := c.BindJSON(&req)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
article := []model.Doc{}
|
article := []model.Doc{}
|
||||||
limit,offset := GetPageParaFromQuery(c)
|
limit, offset := GetPageParaFromQuery(c)
|
||||||
public := c.Query("is_public")
|
public := c.Query("is_public")
|
||||||
|
|
||||||
var sql string
|
var sql string
|
||||||
if req.Name != ""{
|
if req.Name != "" {
|
||||||
if req.Type == 110{
|
if req.Type == 110 {
|
||||||
is_public := 0
|
is_public := 0
|
||||||
if public == "true"{
|
if public == "true" {
|
||||||
is_public = 0
|
is_public = 0
|
||||||
}else{
|
} else {
|
||||||
is_public = 1
|
is_public = 1
|
||||||
}
|
}
|
||||||
sql = "select * from doc where doc.title like '%%%s%%' and is_public = %d limit %d offset %d "
|
sql = "select * from doc where doc.title like '%%%s%%' and is_public = %d limit %d offset %d "
|
||||||
sql = fmt.Sprintf(sql,req.Name,is_public,limit,offset*limit)
|
sql = fmt.Sprintf(sql, req.Name, is_public, limit, offset*limit)
|
||||||
}else{
|
} else {
|
||||||
is_public := 0
|
is_public := 0
|
||||||
if public == "true" {
|
if public == "true" {
|
||||||
is_public = 0
|
is_public = 0
|
||||||
}else{
|
} else {
|
||||||
is_public = 1
|
is_public = 1
|
||||||
}
|
}
|
||||||
sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d and is_public = %d limit %d offset %d ",
|
sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d and is_public = %d limit %d offset %d ",
|
||||||
req.Name,req.Type,is_public,limit,offset*limit)
|
req.Name, req.Type, is_public, limit, offset*limit)
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if req.Type == 110{
|
if req.Type == 110 {
|
||||||
is_public := 0
|
is_public := 0
|
||||||
if public == "true" {
|
if public == "true" {
|
||||||
is_public = 1
|
is_public = 1
|
||||||
}else{
|
} else {
|
||||||
is_public = 0
|
is_public = 0
|
||||||
}
|
}
|
||||||
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc where is_public = %d " +
|
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc where is_public = %d "+
|
||||||
"order by id desc limit %d offset %d",is_public,limit,offset)
|
"order by id desc limit %d offset %d", is_public, limit, offset)
|
||||||
}else{
|
} else {
|
||||||
is_public := 0
|
is_public := 0
|
||||||
if public == "true" {
|
if public == "true" {
|
||||||
is_public = 1
|
is_public = 1
|
||||||
}else{
|
} else {
|
||||||
is_public = 0
|
is_public = 0
|
||||||
}
|
}
|
||||||
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d and is_public = %d " +
|
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d and is_public = %d "+
|
||||||
" order by id desc limit %d offset %d",req.Type,is_public,limit,offset)
|
" order by id desc limit %d offset %d", req.Type, is_public, limit, offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Print(sql)
|
log.Print(sql)
|
||||||
e = db.GetMysqlClient().Query2(sql,&article)
|
e = db.GetMysqlClient().Query2(sql, &article)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error(),sql)
|
logs.Error(e.Error(), sql)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for k,_ := range article{
|
for k, _ := range article {
|
||||||
article[k].Content += "..."
|
article[k].Content += "..."
|
||||||
}
|
}
|
||||||
rsp.Data = article
|
rsp.Data = article
|
||||||
|
@ -102,20 +103,20 @@ func GetArticles(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArticleCount(c *gin.Context) {
|
func GetArticleCount(c *gin.Context) {
|
||||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
resp := RespBase{Msg: "FAIL", Status: 211}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,resp)
|
c.JSON(200, resp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
query := fmt.Sprintf("select count(*) as cnt from doc")
|
query := fmt.Sprintf("select count(*) as cnt from doc")
|
||||||
type Cnt struct {
|
type Cnt struct {
|
||||||
Cnt int64 `sql:"cnt" json:"cnt"`
|
Cnt int64 `sql:"cnt" json:"cnt"`
|
||||||
}
|
}
|
||||||
cnt := []Cnt{};
|
cnt := []Cnt{}
|
||||||
|
|
||||||
e := db.GetMysqlClient().Query2(query,&cnt)
|
e := db.GetMysqlClient().Query2(query, &cnt)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
log.Print(e.Error())
|
log.Print(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -125,31 +126,31 @@ func GetArticleCount(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArticle(c *gin.Context) {
|
func GetArticle(c *gin.Context) {
|
||||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
resp := RespBase{Msg: "FAIL", Status: 211}
|
||||||
sid := c.Param("id")
|
sid := c.Param("id")
|
||||||
var id int
|
var id int
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,resp)
|
c.JSON(200, resp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if sid == ""{
|
if sid == "" {
|
||||||
return
|
return
|
||||||
}else{
|
} else {
|
||||||
id,err = strconv.Atoi(sid)
|
id, err = strconv.Atoi(sid)
|
||||||
if nil != err{
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
query := fmt.Sprintf("select * from doc where doc.id = '%d'",id)
|
query := fmt.Sprintf("select * from doc where doc.id = '%d'", id)
|
||||||
docs := []model.Doc{}
|
docs := []model.Doc{}
|
||||||
e := db.GetMysqlClient().Query2(query,&docs)
|
e := db.GetMysqlClient().Query2(query, &docs)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
log.Print(e.Error())
|
log.Print(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(docs) > 0{
|
if len(docs) > 0 {
|
||||||
resp.Data = docs[0]
|
resp.Data = docs[0]
|
||||||
resp.Status = 0
|
resp.Status = 0
|
||||||
resp.Msg = "OK"
|
resp.Msg = "OK"
|
||||||
|
@ -158,7 +159,7 @@ func GetArticle(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateArtilce(c *gin.Context) {
|
func UpdateArtilce(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"FAIL", Status:210,}
|
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||||
type ReqUpdateArticle struct {
|
type ReqUpdateArticle struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -169,28 +170,28 @@ func UpdateArtilce(c *gin.Context) {
|
||||||
}
|
}
|
||||||
var req ReqUpdateArticle
|
var req ReqUpdateArticle
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
er := c.BindJSON(&req)
|
er := c.BindJSON(&req)
|
||||||
if nil != er{
|
if nil != er {
|
||||||
logs.Error(er.Error())
|
logs.Error(er.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Title == ""{
|
if req.Title == "" {
|
||||||
rsp.Msg = "title required"
|
rsp.Msg = "title required"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e := model.UpdateDoc(
|
e := model.UpdateDoc(
|
||||||
model.Doc{
|
model.Doc{
|
||||||
Type:req.Type,
|
Type: req.Type,
|
||||||
Title:req.Title,
|
Title: req.Title,
|
||||||
Content:req.Content,
|
Content: req.Content,
|
||||||
Author:req.author,
|
Author: req.author,
|
||||||
ID:req.Id,
|
ID: req.Id,
|
||||||
IsPublic:req.IsPublic,
|
IsPublic: req.IsPublic,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -199,13 +200,13 @@ func UpdateArtilce(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
func SearchArticle(c *gin.Context) {
|
func SearchArticle(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"FAIL", Status:210,}
|
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
func AddArticle(c *gin.Context) {
|
func AddArticle(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"FAIL", Status:210,}
|
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||||
type ReqAddArticle struct {
|
type ReqAddArticle struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -216,27 +217,27 @@ func AddArticle(c *gin.Context) {
|
||||||
}
|
}
|
||||||
var req ReqAddArticle
|
var req ReqAddArticle
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
er := c.BindJSON(&req)
|
er := c.BindJSON(&req)
|
||||||
if nil != er{
|
if nil != er {
|
||||||
logs.Error(er.Error())
|
logs.Error(er.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Title == ""{
|
if req.Title == "" {
|
||||||
rsp.Msg = "title required"
|
rsp.Msg = "title required"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e := model.CreateDoc(
|
e := model.CreateDoc(
|
||||||
model.Doc{
|
model.Doc{
|
||||||
Type:req.Type,
|
Type: req.Type,
|
||||||
Title:req.Title,
|
Title: req.Title,
|
||||||
Content:req.Content,
|
Content: req.Content,
|
||||||
Author:req.author,
|
Author: req.author,
|
||||||
IsPublic:req.Ispublic,
|
IsPublic: req.Ispublic,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -244,28 +245,27 @@ func AddArticle(c *gin.Context) {
|
||||||
rsp.Status = 0
|
rsp.Status = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ArticlesType(c *gin.Context) {
|
func ArticlesType(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"FAIL", Status:210,}
|
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
rsp.Data = model.GetArticlesType()
|
rsp.Data = model.GetArticlesType()
|
||||||
rsp.Msg = "OK"
|
rsp.Msg = "OK"
|
||||||
rsp.Status = 0
|
rsp.Status = 0
|
||||||
}
|
}
|
||||||
func DeleteArticleType(c *gin.Context) {
|
func DeleteArticleType(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"Fail",Status:210}
|
rsp := RespBase{Msg: "Fail", Status: 210}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sid :=c.Query("id")
|
sid := c.Query("id")
|
||||||
if sid == ""{
|
if sid == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id ,e := strconv.Atoi(sid)
|
id, e := strconv.Atoi(sid)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
log.Print(e.Error())
|
log.Print(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -274,66 +274,70 @@ func DeleteArticleType(c *gin.Context) {
|
||||||
rsp.Status = 0
|
rsp.Status = 0
|
||||||
}
|
}
|
||||||
func AddArticleType(c *gin.Context) {
|
func AddArticleType(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"Fail",Status:210}
|
rsp := RespBase{Msg: "Fail", Status: 210}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
typeName :=c.Query("name")
|
typeName := c.Query("name")
|
||||||
|
group := c.Query("group")
|
||||||
|
groupid, e := strconv.Atoi(group)
|
||||||
|
if nil != e {
|
||||||
|
return
|
||||||
|
}
|
||||||
id := c.Query("id")
|
id := c.Query("id")
|
||||||
if id != ""{
|
if id != "" {
|
||||||
if typeName == ""{
|
if typeName == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
articleType := model.ArticleType{
|
articleType := model.ArticleType{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
Name: typeName,
|
Name: typeName,
|
||||||
|
Group: int32(groupid),
|
||||||
}
|
}
|
||||||
rsp.Data = model.UpdateArticleType(articleType)
|
rsp.Data = model.UpdateArticleType(articleType)
|
||||||
rsp.Msg = "OK"
|
rsp.Msg = "OK"
|
||||||
rsp.Status = 0
|
rsp.Status = 0
|
||||||
}else{
|
} else {
|
||||||
if typeName == ""{
|
if typeName == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
articleType := model.ArticleType{
|
articleType := model.ArticleType{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
Name: typeName,
|
Name: typeName,
|
||||||
|
Group: int32(groupid),
|
||||||
}
|
}
|
||||||
rsp.Data = model.AddArticleType(articleType)
|
rsp.Data = model.AddArticleType(articleType)
|
||||||
rsp.Msg = "OK"
|
rsp.Msg = "OK"
|
||||||
rsp.Status = 0
|
rsp.Status = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteArticle(c *gin.Context) {
|
func DeleteArticle(c *gin.Context) {
|
||||||
rsp := RespBase{Msg:"FAIL", Status:210,}
|
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
sid := c.Param("id")
|
sid := c.Param("id")
|
||||||
id,err := strconv.Atoi(sid)
|
id, err := strconv.Atoi(sid)
|
||||||
if nil != err{
|
if nil != err {
|
||||||
rsp.Status = -234
|
rsp.Status = -234
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}
|
}
|
||||||
err = model.DeleteDoc(int64(id))
|
err = model.DeleteDoc(int64(id))
|
||||||
if nil != err{
|
if nil != err {
|
||||||
rsp.Status = -234
|
rsp.Status = -234
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}
|
}
|
||||||
rsp.Data = id
|
rsp.Data = id
|
||||||
rsp.Status = 0
|
rsp.Status = 0
|
||||||
rsp.Msg = "OK"
|
rsp.Msg = "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ArticlesTypes(c *gin.Context) {
|
func ArticlesTypes(c *gin.Context) {
|
||||||
resp := RespBase{"unkown error",-231,nil}
|
resp := RespBase{"unkown error", -231, nil}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,resp)
|
c.JSON(200, resp)
|
||||||
}()
|
}()
|
||||||
type DocType struct {
|
type DocType struct {
|
||||||
Id int64 `sql:"id"`
|
Id int64 `sql:"id"`
|
||||||
|
@ -342,7 +346,7 @@ func ArticlesTypes(c *gin.Context) {
|
||||||
docTypes := []DocType{}
|
docTypes := []DocType{}
|
||||||
e := db.GetMysqlClient().Query2("select * from doc_type",
|
e := db.GetMysqlClient().Query2("select * from doc_type",
|
||||||
&docTypes)
|
&docTypes)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
log.Print(e.Error())
|
log.Print(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -350,3 +354,144 @@ func ArticlesTypes(c *gin.Context) {
|
||||||
resp.Msg = "OK"
|
resp.Msg = "OK"
|
||||||
resp.Status = 0
|
resp.Status = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateMemo(c *gin.Context) {
|
||||||
|
resp := RespBase{"unkown error", -231, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, resp)
|
||||||
|
}()
|
||||||
|
var req model.Memo
|
||||||
|
e := c.BindJSON(&req)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
resp.Msg = "wrong input"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e = model.CreateMemo(req)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.Data = nil
|
||||||
|
resp.Msg = "OK"
|
||||||
|
resp.Status = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateMemo(c *gin.Context) {
|
||||||
|
resp := RespBase{"unkown error", -231, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, resp)
|
||||||
|
}()
|
||||||
|
var req model.Memo
|
||||||
|
e := c.BindJSON(&req)
|
||||||
|
if nil != e {
|
||||||
|
resp.Msg = "wrong input"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e = model.UpdateMemo(req)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.Data = nil
|
||||||
|
resp.Msg = "OK"
|
||||||
|
resp.Status = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDocGroup(c *gin.Context) {
|
||||||
|
rsp := RespBase{"ERR", -1, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, rsp)
|
||||||
|
}()
|
||||||
|
group, e := model.GetAllGroup()
|
||||||
|
if nil != e {
|
||||||
|
log.Print(e.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rsp.Data = group
|
||||||
|
rsp.Status = 0
|
||||||
|
rsp.Msg = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTemplates(c *gin.Context) {
|
||||||
|
rsp := RespBase{"ERR", -1, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMemos(c *gin.Context) {
|
||||||
|
rsp := RespBase{"ERR", -1, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, rsp)
|
||||||
|
}()
|
||||||
|
type ReqMemos struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
req := ReqMemos{}
|
||||||
|
e := c.BindJSON(&req)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
limit, offset := GetPageParaFromQuery(c)
|
||||||
|
if limit != 0 && offset != 0 {
|
||||||
|
dat, e := model.GetMemos(req.Title, 10, 0)
|
||||||
|
if nil != e {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rsp.Data = dat
|
||||||
|
rsp.Status = 0
|
||||||
|
rsp.Msg = "OK"
|
||||||
|
} else {
|
||||||
|
dat, e := model.GetMemos(req.Title, 10, 0)
|
||||||
|
if nil != e {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rsp.Data = dat
|
||||||
|
rsp.Status = 0
|
||||||
|
rsp.Msg = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func GetDocTemplate(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
func GetMemo(c *gin.Context) {
|
||||||
|
rsp := RespBase{"ERR", -1, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, rsp)
|
||||||
|
}()
|
||||||
|
id := c.Query("id")
|
||||||
|
dat, e := model.ReadMemo(int32(db.Atoi(id)))
|
||||||
|
if nil != e {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rsp.Msg = "OK"
|
||||||
|
rsp.Status = 0
|
||||||
|
rsp.Data = dat
|
||||||
|
}
|
||||||
|
func DeleteMemos(c *gin.Context) {
|
||||||
|
resp := RespBase{"unkown error", -231, nil}
|
||||||
|
defer func() {
|
||||||
|
c.JSON(200, resp)
|
||||||
|
}()
|
||||||
|
type DelReq struct {
|
||||||
|
Id int32 `json:"id"`
|
||||||
|
}
|
||||||
|
var req DelReq
|
||||||
|
e := c.BindJSON(&req)
|
||||||
|
if nil != e {
|
||||||
|
resp.Msg = "wrong input"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e = model.DeleteMemo(req.Id)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.Data = nil
|
||||||
|
resp.Msg = "OK"
|
||||||
|
resp.Status = 0
|
||||||
|
}
|
||||||
|
|
|
@ -3,25 +3,26 @@ package controller
|
||||||
import (
|
import (
|
||||||
"background/logs"
|
"background/logs"
|
||||||
"background/model"
|
"background/model"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"qiniupkg.com/x/log.v7"
|
"qiniupkg.com/x/log.v7"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddHardware(c *gin.Context) {
|
func AddHardware(c *gin.Context) {
|
||||||
resp := RespBase{"unkown error",-231,nil}
|
resp := RespBase{"unkown error", -231, nil}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,resp)
|
c.JSON(200, resp)
|
||||||
}()
|
}()
|
||||||
var hardware model.Hardware
|
var hardware model.Hardware
|
||||||
|
|
||||||
e := c.BindJSON(&hardware)
|
e := c.BindJSON(&hardware)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
log.Print(e)
|
log.Print(e)
|
||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e = hardware.CreateHardware()
|
e = hardware.CreateHardware()
|
||||||
if nil != e{
|
if nil != e {
|
||||||
resp.Status = -100
|
resp.Status = -100
|
||||||
resp.Msg = e.Error()
|
resp.Msg = e.Error()
|
||||||
log.Print(e)
|
log.Print(e)
|
||||||
|
@ -33,16 +34,16 @@ func AddHardware(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteHardWare(c *gin.Context) {
|
func DeleteHardWare(c *gin.Context) {
|
||||||
resp := RespBase{"unkown error",-231,nil}
|
resp := RespBase{"unkown error", -231, nil}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,resp)
|
c.JSON(200, resp)
|
||||||
}()
|
}()
|
||||||
name := c.Query("name")
|
name := c.Query("name")
|
||||||
if name == ""{
|
if name == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e := model.DeleteHardware(name)
|
e := model.DeleteHardware(name)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,15 +57,15 @@ func UpdateHardWare(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadHardWare(c *gin.Context) {
|
func ReadHardWare(c *gin.Context) {
|
||||||
rsp := RespBase{"ERR",-1,nil}
|
rsp := RespBase{"ERR", -1, nil}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,rsp)
|
c.JSON(200, rsp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
limit,offset := GetPageParaFromQuery(c)
|
limit, offset := GetPageParaFromQuery(c)
|
||||||
log.Print(limit,offset)
|
log.Print(limit, offset)
|
||||||
hardware,e := model.GetHardwares(limit,offset)
|
hardware, e := model.GetHardwares(limit, offset)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rsp.Data = hardware
|
rsp.Data = hardware
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"background/controller/params"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPageParam(c *gin.Context) (int, int) {
|
||||||
|
var limit, offset int
|
||||||
|
var ok bool
|
||||||
|
limit, ok = c.Keys[params.K_OFFSET].(int)
|
||||||
|
if !ok {
|
||||||
|
}
|
||||||
|
offset, ok = c.Keys[params.K_OFFSET].(int)
|
||||||
|
if !ok {
|
||||||
|
}
|
||||||
|
return limit, offset
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package params
|
||||||
|
|
||||||
|
const K_OFFSET = "offset"
|
||||||
|
const K_LIMIT = "limit"
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"background/config"
|
||||||
|
"background/db"
|
||||||
|
"background/logs"
|
||||||
|
"background/model"
|
||||||
|
"background/redis"
|
||||||
"background/utils"
|
"background/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
|
||||||
"github.com/tommy351/gin-sessions"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
@ -20,15 +21,14 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"background/config"
|
|
||||||
"background/db"
|
"github.com/fatih/structs"
|
||||||
"background/logs"
|
"github.com/gin-gonic/gin"
|
||||||
"background/model"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"background/redis"
|
sessions "github.com/tommy351/gin-sessions"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserController struct {
|
type UserController struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReqSendEmailCode struct {
|
type ReqSendEmailCode struct {
|
||||||
|
@ -75,27 +75,12 @@ func (this *UserController) Auth(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUser godoc
|
|
||||||
// @Summary SetUser
|
|
||||||
// @Description set userinfo
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param q query string false "name search by q"
|
|
||||||
// @Success 200 {array} util.RespBase
|
|
||||||
// @Router /setUser [get]
|
|
||||||
func (this *UserController) SetUser(c *gin.Context) {
|
func (this *UserController) SetUser(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
// SetUser godoc
|
|
||||||
// @Summary SetUser
|
|
||||||
// @Description set userinfo
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param q query string false "name search by q"
|
|
||||||
// @Success 200 {array} util.RespBase
|
|
||||||
// @Router /setUser [get]
|
|
||||||
func (this *UserController) ModifyPasswd(c *gin.Context) {
|
func (this *UserController) ModifyPasswd(c *gin.Context) {
|
||||||
type ReqModifyPasswd struct{
|
type ReqModifyPasswd struct {
|
||||||
id int `json:"id"`
|
id int `json:"id"`
|
||||||
UserName string `json:"user_name"`
|
UserName string `json:"user_name"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
@ -106,16 +91,16 @@ func (this *UserController) ModifyPasswd(c *gin.Context) {
|
||||||
resp.Msg = "err"
|
resp.Msg = "err"
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
c.JSON(200,resp)
|
c.JSON(200, resp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
e := c.BindJSON(&req)
|
e := c.BindJSON(&req)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e = model.ModyfyPassword(req.UserName,req.Password)
|
e = model.ModyfyPassword(req.UserName, req.Password)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -123,14 +108,7 @@ func (this *UserController) ModifyPasswd(c *gin.Context) {
|
||||||
resp.Status = 0
|
resp.Status = 0
|
||||||
|
|
||||||
}
|
}
|
||||||
// DelUser godoc
|
|
||||||
// @Summary Delete a user from database
|
|
||||||
// @Description you must have a token in your parameter
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param q query string false "name search by q"
|
|
||||||
// @Success 200 {array} util.RespBase
|
|
||||||
// @Router /setUser [get]
|
|
||||||
func (this *UserController) DelUser(c *gin.Context) {
|
func (this *UserController) DelUser(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -159,17 +137,6 @@ func (this *UserController) GetUser(c *gin.Context) {
|
||||||
resp.Data = users
|
resp.Data = users
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsers godoc
|
|
||||||
// @Summary GetUsers
|
|
||||||
// @Description Get all user with query
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param page query int 1 "分页的页数"
|
|
||||||
// @Param pageSize query int 10 "name search by q"
|
|
||||||
// @Param displayname query string false "name search by q"
|
|
||||||
// @Param department_id query string false "name search by q"
|
|
||||||
// @Param permission_type query string false "name search by q"
|
|
||||||
// @Router /api/users [get]
|
|
||||||
func (this *UserController) Users(c *gin.Context) {
|
func (this *UserController) Users(c *gin.Context) {
|
||||||
var statuscode int
|
var statuscode int
|
||||||
var resp RespBase
|
var resp RespBase
|
||||||
|
@ -201,17 +168,6 @@ func (this *UserController) Users(c *gin.Context) {
|
||||||
resp.Data = dat
|
resp.Data = dat
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsers godoc
|
|
||||||
// @Summary GetUsers
|
|
||||||
// @Description Get all user with query
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param page query int 1 "分页的页数"
|
|
||||||
// @Param pageSize query int 10 "name search by q"
|
|
||||||
// @Param displayname query string false "name search by q"
|
|
||||||
// @Param department_id query string false "name search by q"
|
|
||||||
// @Param permission_type query string false "name search by q"
|
|
||||||
// @Router /api/users [get]
|
|
||||||
func (this *UserController) SerarchUsers(c *gin.Context) {
|
func (this *UserController) SerarchUsers(c *gin.Context) {
|
||||||
var statuscode int
|
var statuscode int
|
||||||
var resp RespBase
|
var resp RespBase
|
||||||
|
@ -276,17 +232,6 @@ func DefaultOption(c *gin.Context) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login godoc
|
|
||||||
// @Summary Login
|
|
||||||
// @Description login
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param logininfo query {object} LoginReq "登录请求参数"
|
|
||||||
// @Success 200 {array} util.RespBase
|
|
||||||
// @Failure 400 {object} util.RespBase
|
|
||||||
// @Failure 404 {object} util.RespBase
|
|
||||||
// @Failure 500 {object} util.RespBase
|
|
||||||
// @Router /api/login [post]
|
|
||||||
func (this *UserController) Login(c *gin.Context) {
|
func (this *UserController) Login(c *gin.Context) {
|
||||||
type LoginReq struct {
|
type LoginReq struct {
|
||||||
RememberMe int32 `json:"remember_me"`
|
RememberMe int32 `json:"remember_me"`
|
||||||
|
@ -310,7 +255,7 @@ func (this *UserController) Login(c *gin.Context) {
|
||||||
h.Write([]byte(req.UserPwd)) // 需要加密的字符串为 123456
|
h.Write([]byte(req.UserPwd)) // 需要加密的字符串为 123456
|
||||||
passmd5 := h.Sum(nil)
|
passmd5 := h.Sum(nil)
|
||||||
var result []model.Users
|
var result []model.Users
|
||||||
query := fmt.Sprintf("select * from users where user_name = '%s'",req.UserName)
|
query := fmt.Sprintf("select * from users where user_name = '%s'", req.UserName)
|
||||||
er := db.GetMysqlClient().Query2(query,
|
er := db.GetMysqlClient().Query2(query,
|
||||||
&result)
|
&result)
|
||||||
logs.Debug("sql query:" + query)
|
logs.Debug("sql query:" + query)
|
||||||
|
@ -447,7 +392,7 @@ func (this *UserController) Register(c *gin.Context) {
|
||||||
|
|
||||||
func (this *UserController) Logout(c *gin.Context) {
|
func (this *UserController) Logout(c *gin.Context) {
|
||||||
token := c.Param("token")
|
token := c.Param("token")
|
||||||
log.Print("logout token is ",token)
|
log.Print("logout token is ", token)
|
||||||
var resp RespBase
|
var resp RespBase
|
||||||
config.RedisOne().Del(token)
|
config.RedisOne().Del(token)
|
||||||
resp.Msg = "退出成功"
|
resp.Msg = "退出成功"
|
||||||
|
|
|
@ -7,36 +7,50 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-sql-driver/mysql"
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
|
||||||
"gopkg.in/mgo.v2"
|
|
||||||
"gopkg.in/olivere/elastic.v7"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
"gopkg.in/mgo.v2"
|
||||||
|
"gopkg.in/olivere/elastic.v7"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gEla ElkEngine
|
var gEla ElkEngine
|
||||||
var gDb Database
|
var gDb Database
|
||||||
var blogDb Database
|
var blogDb Database
|
||||||
var gMongo *mgo.Session
|
var gMongo *mgo.Session
|
||||||
var gElkEngine ElkEngine
|
var gElkEngine ElkEngine
|
||||||
|
var gOrm *gorm.DB
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
var e error
|
||||||
mysqlconf := config.GetMysqlConfig()
|
mysqlconf := config.GetMysqlConfig()
|
||||||
blogConf := config.GetMysqlBlogConfig()
|
|
||||||
//InitMongoDb()
|
//InitMongoDb()
|
||||||
fmt.Print("api runmode is " + config.ApiConfig().RunMode)
|
log.Print("api runmode is " + config.ApiConfig().RunMode)
|
||||||
if config.ApiConfig().RunMode == "debug"{
|
if config.ApiConfig().RunMode == "debug" {
|
||||||
blogDb = Database{Type: string(""), DB: initMysqlTLS(blogConf)}
|
gDb = Database{Type: string(""), DB: initMysql(mysqlconf)}
|
||||||
}else{
|
sqls := fmt.Sprintf("%s:%s@(%s)/%s?charset=utf8&parseTime=True&loc=Local",
|
||||||
blogDb = Database{Type: string(""), DB: initMysqlTLS(blogConf)}
|
mysqlconf.UserName, mysqlconf.Password, mysqlconf.Addr,
|
||||||
|
mysqlconf.Db)
|
||||||
|
log.Print(sqls)
|
||||||
|
gOrm, e = gorm.Open("mysql", sqls)
|
||||||
|
if nil != e {
|
||||||
|
log.Print(e.Error())
|
||||||
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
if config.ApiConfig().RunMode == "debug"{
|
} else {
|
||||||
gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)}
|
sqls := fmt.Sprintf("%s:%s@/%s?charset=utf8&parseTime=True&loc=Local", mysqlconf.UserName, mysqlconf.Password,
|
||||||
}else{
|
mysqlconf.Db)
|
||||||
gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)}
|
gOrm, e = gorm.Open("mysql", sqls)
|
||||||
|
if nil != e {
|
||||||
|
log.Print(e.Error())
|
||||||
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InitELK()
|
InitELK()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,11 +58,11 @@ func InitELK() {
|
||||||
var e error
|
var e error
|
||||||
elkconf := config.GetElkConfig()
|
elkconf := config.GetElkConfig()
|
||||||
log.Print(elkconf)
|
log.Print(elkconf)
|
||||||
gElkEngine.cli,e = elastic.NewClient(
|
gElkEngine.cli, e = elastic.NewClient(
|
||||||
elastic.SetURL(elkconf.Address),
|
elastic.SetURL(elkconf.Address),
|
||||||
// Must turn off sniff in docker
|
// Must turn off sniff in docker
|
||||||
elastic.SetSniff(false),)
|
elastic.SetSniff(false))
|
||||||
if nil != e{
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
gElkEngine.cli = nil
|
gElkEngine.cli = nil
|
||||||
}
|
}
|
||||||
|
@ -110,20 +124,20 @@ func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
|
||||||
}
|
}
|
||||||
return _db
|
return _db
|
||||||
}
|
}
|
||||||
func initMongoDb(conf *config.MongoConfig) *mgo.Session{
|
func initMongoDb(conf *config.MongoConfig) *mgo.Session {
|
||||||
var url string
|
var url string
|
||||||
if conf.UserName == ""{
|
if conf.UserName == "" {
|
||||||
url = fmt.Sprintf("mongodb://%s:%d/%s",conf.Addr,conf.Port,conf.Db)
|
url = fmt.Sprintf("mongodb://%s:%d/%s", conf.Addr, conf.Port, conf.Db)
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
url = fmt.Sprintf("mongodb://%s:%s@%s:%d/%s",conf.UserName,conf.Password,conf.Addr,conf.Port,conf.Db)
|
url = fmt.Sprintf("mongodb://%s:%s@%s:%d/%s", conf.UserName, conf.Password, conf.Addr, conf.Port, conf.Db)
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Print("connect to url " + url)
|
log.Print("connect to url " + url)
|
||||||
logs.Debug("connect to url " + url)
|
logs.Debug("connect to url " + url)
|
||||||
|
|
||||||
mgo,err := mgo.Dial(url)
|
mgo, err := mgo.Dial(url)
|
||||||
if nil != err{
|
if nil != err {
|
||||||
logs.Error(err.Error())
|
logs.Error(err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -133,7 +147,7 @@ func initMongoDb(conf *config.MongoConfig) *mgo.Session{
|
||||||
func GetMysqlClient() *Database {
|
func GetMysqlClient() *Database {
|
||||||
return &gDb
|
return &gDb
|
||||||
}
|
}
|
||||||
func GetBlogMysql() *Database{
|
func GetBlogMysql() *Database {
|
||||||
return &blogDb
|
return &blogDb
|
||||||
}
|
}
|
||||||
func GetMongoDb() *mgo.Session {
|
func GetMongoDb() *mgo.Session {
|
||||||
|
@ -142,11 +156,14 @@ func GetMongoDb() *mgo.Session {
|
||||||
func InitMongoDb() {
|
func InitMongoDb() {
|
||||||
mongoConf := config.GetMongoDBConfig()
|
mongoConf := config.GetMongoDBConfig()
|
||||||
gMongo = initMongoDb(mongoConf)
|
gMongo = initMongoDb(mongoConf)
|
||||||
if gMongo == nil{
|
if gMongo == nil {
|
||||||
log.Print("error mongo initial")
|
log.Print("error mongo initial")
|
||||||
os.Exit(25)
|
os.Exit(25)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func GetElastic() *ElkEngine{
|
func GetElastic() *ElkEngine {
|
||||||
return &gElkEngine
|
return &gElkEngine
|
||||||
}
|
}
|
||||||
|
func GetOrm() *gorm.DB {
|
||||||
|
return gOrm
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||||
|
// This file was generated by swaggo/swag at
|
||||||
|
// 2020-06-24 21:33:14.5754792 +0800 CST m=+0.035031801
|
||||||
|
|
||||||
|
package docs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/alecthomas/template"
|
||||||
|
"github.com/swaggo/swag"
|
||||||
|
)
|
||||||
|
|
||||||
|
var doc = `{
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"description": "{{.Description}}",
|
||||||
|
"title": "大厅功能api",
|
||||||
|
"contact": {},
|
||||||
|
"license": {},
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"host": "localhost:8080",
|
||||||
|
"basePath": "/api/v1",
|
||||||
|
"paths": {}
|
||||||
|
}`
|
||||||
|
|
||||||
|
type swaggerInfo struct {
|
||||||
|
Version string
|
||||||
|
Host string
|
||||||
|
BasePath string
|
||||||
|
Title string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||||
|
var SwaggerInfo swaggerInfo
|
||||||
|
|
||||||
|
type s struct{}
|
||||||
|
|
||||||
|
func (s *s) ReadDoc() string {
|
||||||
|
t, err := template.New("swagger_info").Parse(doc)
|
||||||
|
if err != nil {
|
||||||
|
return doc
|
||||||
|
}
|
||||||
|
|
||||||
|
var tpl bytes.Buffer
|
||||||
|
if err := t.Execute(&tpl, SwaggerInfo); err != nil {
|
||||||
|
return doc
|
||||||
|
}
|
||||||
|
|
||||||
|
return tpl.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
swag.Register(swag.Name, &s{})
|
||||||
|
}
|
34
main.go
34
main.go
|
@ -5,15 +5,24 @@ import (
|
||||||
"background/controller"
|
"background/controller"
|
||||||
"background/controller/middle"
|
"background/controller/middle"
|
||||||
"background/db"
|
"background/db"
|
||||||
|
_ "background/docs"
|
||||||
"background/logs"
|
"background/logs"
|
||||||
"background/model"
|
"background/model"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
swaggerFiles "github.com/swaggo/files" // swagger embed files
|
||||||
|
ginSwagger "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
||||||
sessions "github.com/tommy351/gin-sessions"
|
sessions "github.com/tommy351/gin-sessions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// @title 大厅功能api
|
||||||
|
// @version 1.0
|
||||||
|
// @host localhost:8080
|
||||||
|
// @BasePath /api/v1
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userController = controller.UserController{}
|
userController = controller.UserController{}
|
||||||
mailContoller = controller.MailController{}
|
mailContoller = controller.MailController{}
|
||||||
|
@ -82,6 +91,8 @@ func InitLogs() {
|
||||||
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
|
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
|
||||||
}
|
}
|
||||||
func main() {
|
func main() {
|
||||||
|
log.Print("gid is", os.Getegid())
|
||||||
|
|
||||||
InitConfig()
|
InitConfig()
|
||||||
InitLogs()
|
InitLogs()
|
||||||
InitRedisConfig()
|
InitRedisConfig()
|
||||||
|
@ -95,6 +106,14 @@ func main() {
|
||||||
store := sessions.NewCookieStore([]byte("secret123"))
|
store := sessions.NewCookieStore([]byte("secret123"))
|
||||||
r.Use(sessions.Middleware("sess_store", store))
|
r.Use(sessions.Middleware("sess_store", store))
|
||||||
r.Use(CORSMiddleware)
|
r.Use(CORSMiddleware)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// programatically set swagger info
|
||||||
|
r := gin.New()
|
||||||
|
// use ginSwagger middleware to serve the API docs
|
||||||
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
r.Run(":9992")
|
||||||
|
}()
|
||||||
api := r.Group("/api")
|
api := r.Group("/api")
|
||||||
{
|
{
|
||||||
/** 添加或修改用户 **/
|
/** 添加或修改用户 **/
|
||||||
|
@ -120,9 +139,9 @@ func main() {
|
||||||
api.POST("/articles", controller.GetArticles) // 获取所有文章
|
api.POST("/articles", controller.GetArticles) // 获取所有文章
|
||||||
api.PUT("/article", controller.AddArticle) // 添加文章
|
api.PUT("/article", controller.AddArticle) // 添加文章
|
||||||
api.PUT("/article_search", controller.SearchArticle) // 添加文章
|
api.PUT("/article_search", controller.SearchArticle) // 添加文章
|
||||||
api.GET("article_type", controller.ArticlesType) //获取所有文章分类
|
api.GET("/article_type", controller.ArticlesType) //获取所有文章分类
|
||||||
api.PUT("article_type", controller.AddArticleType)
|
api.PUT("/article_type", controller.AddArticleType)
|
||||||
api.DELETE("article_type", controller.DeleteArticleType)
|
api.DELETE("/article_type", controller.DeleteArticleType)
|
||||||
|
|
||||||
api.POST("/article_update", controller.UpdateArtilce) //更新文章
|
api.POST("/article_update", controller.UpdateArtilce) //更新文章
|
||||||
api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数
|
api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数
|
||||||
|
@ -140,6 +159,15 @@ func main() {
|
||||||
api.GET("/filelist", fileController.FileList) // 文件列表
|
api.GET("/filelist", fileController.FileList) // 文件列表
|
||||||
api.GET("/fileType", fileController.FileType) // 文件类型
|
api.GET("/fileType", fileController.FileType) // 文件类型
|
||||||
|
|
||||||
|
api.PUT("/memo", controller.CreateMemo) // 备忘录新建
|
||||||
|
api.POST("/memo", controller.UpdateMemo) // 备忘录更新
|
||||||
|
api.POST("/memos", controller.GetMemos) // 备忘录批量
|
||||||
|
api.POST("/delmemo", controller.DeleteMemos) //删除备忘录
|
||||||
|
api.GET("/memo", controller.GetMemo) // 单独读取
|
||||||
|
api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组
|
||||||
|
api.GET("templates", controller.GetDocTemplate) // 获取所有文章的模板
|
||||||
|
|
||||||
|
api.GET("doc_versions", nil) // 获取文章的某个版本
|
||||||
}
|
}
|
||||||
hookapi := r.Group("hookapi")
|
hookapi := r.Group("hookapi")
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,8 +4,9 @@ import (
|
||||||
"background/db"
|
"background/db"
|
||||||
"background/logs"
|
"background/logs"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qiniupkg.com/x/log.v7"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"qiniupkg.com/x/log.v7"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Doc struct {
|
type Doc struct {
|
||||||
|
@ -17,16 +18,30 @@ type Doc struct {
|
||||||
IsPublic int `sql:"is_public" json:"is_public"`
|
IsPublic int `sql:"is_public" json:"is_public"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DocGroup struct {
|
||||||
|
Int int32 `sql:"int"`
|
||||||
|
Name string `sql:"name"`
|
||||||
|
}
|
||||||
type ArticleType struct {
|
type ArticleType struct {
|
||||||
Id int64 `sql:"id" json:"id"`
|
Id int64 `sql:"id" json:"id"`
|
||||||
Name string `sql:"type_name" json:"type_name"`
|
Name string `sql:"type_name" json:"type_name"`
|
||||||
Author string `sql:"author" json:"author"`
|
Author string `sql:"author" json:"author"`
|
||||||
|
Group int32 `sql:"group" json:"group"`
|
||||||
|
GroupName string `json:"group_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArticlesType() []ArticleType {
|
func GetArticlesType() []ArticleType {
|
||||||
ret := []ArticleType{}
|
ret := []ArticleType{}
|
||||||
sql := fmt.Sprintf("select * from doc_type")
|
sql := fmt.Sprintf("select * from doc_type")
|
||||||
e := db.GetBlogMysql().Query2(sql, &ret)
|
e := db.GetBlogMysql().Query2(sql, &ret)
|
||||||
|
for k, _ := range ret {
|
||||||
|
group := []DocGroup{}
|
||||||
|
sql = fmt.Sprintf("select * from doc_group where doc_group.int = %d", ret[k].Group)
|
||||||
|
db.GetBlogMysql().Query2(sql, &group)
|
||||||
|
if len(group) > 0 {
|
||||||
|
ret[k].GroupName = group[0].Name
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Print(ret)
|
log.Print(ret)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -46,7 +61,7 @@ func CreateDoc(doc Doc) error {
|
||||||
DUAL
|
DUAL
|
||||||
WHERE
|
WHERE
|
||||||
NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1),
|
NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1),
|
||||||
doc.Author, doc.Type,doc.IsPublic,doc.Title)
|
doc.Author, doc.Type, doc.IsPublic, doc.Title)
|
||||||
_, e := db.GetMysqlClient().Query(sql)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -55,10 +70,10 @@ func CreateDoc(doc Doc) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateDoc(doc Doc) error{
|
func UpdateDoc(doc Doc) error {
|
||||||
sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' where doc.id = '%d'; `,
|
sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' where doc.id = '%d'; `,
|
||||||
doc.Author, doc.Title, doc.Type,
|
doc.Author, doc.Title, doc.Type,
|
||||||
strings.Replace(doc.Content, "'", "\\'", -1),doc.ID)
|
strings.Replace(doc.Content, "'", "\\'", -1), doc.ID)
|
||||||
_, e := db.GetMysqlClient().Query(sql)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -67,8 +82,8 @@ func UpdateDoc(doc Doc) error{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteDoc(id int64) error{
|
func DeleteDoc(id int64) error {
|
||||||
sql := fmt.Sprintf(`delete from doc where id = %d`,id)
|
sql := fmt.Sprintf(`delete from doc where id = %d`, id)
|
||||||
_, e := db.GetMysqlClient().Query(sql)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -77,8 +92,9 @@ func DeleteDoc(id int64) error{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddArticleType(t ArticleType) error{
|
func AddArticleType(t ArticleType) error {
|
||||||
sql := fmt.Sprintf("insert into doc_type(id,type_name) values ('%d','%s')",t.Id,t.Name)
|
sql := fmt.Sprintf("insert into doc_type(id,type_name,`group`) values ('%d','%s','%d')", t.Id, t.Name, t.Group)
|
||||||
|
log.Print(sql)
|
||||||
_, e := db.GetMysqlClient().Query(sql)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -86,8 +102,8 @@ func AddArticleType(t ArticleType) error{
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func UpdateArticleType(t ArticleType) error{
|
func UpdateArticleType(t ArticleType) error {
|
||||||
sql := fmt.Sprintf("update doc_type set type_name = '%s' where id = %d",t.Name,t.Id)
|
sql := fmt.Sprintf("update doc_type set type_name = '%s' and group = '%d' where id = %d", t.Name, t.Group, t.Id)
|
||||||
_, e := db.GetMysqlClient().Query(sql)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -97,7 +113,7 @@ func UpdateArticleType(t ArticleType) error{
|
||||||
|
|
||||||
}
|
}
|
||||||
func DeleteArticleType(id int32) error {
|
func DeleteArticleType(id int32) error {
|
||||||
sql := fmt.Sprintf("delete from doc_type where id = '%d'",id)
|
sql := fmt.Sprintf("delete from doc_type where id = '%d'", id)
|
||||||
_, e := db.GetMysqlClient().Query(sql)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
@ -106,14 +122,24 @@ func DeleteArticleType(id int32) error {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
func GetAllDocs() ([]Doc,error) {
|
func GetAllDocs() ([]Doc, error) {
|
||||||
ret := []Doc{}
|
ret := []Doc{}
|
||||||
sql := fmt.Sprintf("select * from doc")
|
sql := fmt.Sprintf("select * from doc")
|
||||||
e := db.GetMysqlClient().Query2(sql,&ret)
|
e := db.GetMysqlClient().Query2(sql, &ret)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return nil,e
|
return nil, e
|
||||||
}
|
}
|
||||||
return ret,nil
|
return ret, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func GetAllGroup() ([]DocGroup, error) {
|
||||||
|
ret := []DocGroup{}
|
||||||
|
sql := fmt.Sprintf("select * from doc_group")
|
||||||
|
e := db.GetMysqlClient().Query2(sql, &ret)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return nil, e
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"background/db"
|
||||||
|
"background/logs"
|
||||||
|
"fmt"
|
||||||
|
"qiniupkg.com/x/log.v7"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Memo struct {
|
||||||
|
ID int64 `sql:"id" json:"id"`
|
||||||
|
Title string `sql:"title" json:"title"`
|
||||||
|
CreateTime string `sql:"create_time" json:"create_time"`
|
||||||
|
Content string `sql:"content" json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateMemo(memo Memo) error{
|
||||||
|
sql := fmt.Sprintf(`insert into memo(title,create_time,content) select '%s','%s','%s'
|
||||||
|
from dual where not exists (select * from memo where memo.title='%s') `,
|
||||||
|
memo.Title,memo.CreateTime,strings.Replace(memo.Content, "'", "\\'", -1),memo.Title)
|
||||||
|
log.Print(sql)
|
||||||
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateMemo(memo Memo) error{
|
||||||
|
sql := fmt.Sprintf(`update memo set title = '%s',
|
||||||
|
create_time = '%s',
|
||||||
|
content = '%s' where memo.id = %d`,
|
||||||
|
memo.Title,memo.CreateTime,strings.Replace(memo.Content, "'", "\\'", -1),memo.ID)
|
||||||
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteMemo(id int32) error{
|
||||||
|
sql := fmt.Sprintf(`delete from memo where memo.id = '%d'`,id)
|
||||||
|
log.Print(sql)
|
||||||
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadMemo(id int32) ([]Memo,error){
|
||||||
|
memo := []Memo{}
|
||||||
|
sql := fmt.Sprintf(`select * from memo where memo.id = '%d'`,id)
|
||||||
|
e := db.GetMysqlClient().Query2(sql,&memo)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return nil,e
|
||||||
|
}
|
||||||
|
return memo,nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMemos(title string,limit int,offset int) ([]Memo,error) {
|
||||||
|
memo := []Memo{}
|
||||||
|
sql := fmt.Sprintf(`select * from memo where memo.title like '%s%%' limit %d offset %d`,
|
||||||
|
title,limit,offset)
|
||||||
|
log.Print(sql)
|
||||||
|
e := db.GetMysqlClient().Query2(sql,&memo)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return nil,e
|
||||||
|
}
|
||||||
|
return memo,nil
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"background/db"
|
||||||
|
"background/logs"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DocTemplate struct {
|
||||||
|
Id int32 `sql:"id" json:"id"`
|
||||||
|
Content string `sql:"content" json:"content"`
|
||||||
|
Name string `sql:"content" json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func CreateDocTemplate(templ DocTemplate) error{
|
||||||
|
sql := fmt.Sprintf(`insert into doc_template(content,name) select '%s','%s
|
||||||
|
from dual where not exists (select * from doc_template where doc_template.name='%s') `,
|
||||||
|
templ.Content,templ.Name,templ.Name)
|
||||||
|
log.Print(sql)
|
||||||
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
|
if nil != e {
|
||||||
|
log.Print(sql)
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateDocTemplate(templ DocTemplate) error{
|
||||||
|
sql := fmt.Sprintf(`update doc_template set content = %s,
|
||||||
|
name = %s, where memo.id = '%d'`,templ.Content,templ.Name,templ.Id)
|
||||||
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
|
if nil != e {
|
||||||
|
log.Print(e.Error())
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteDocTemplate(id int32) error{
|
||||||
|
sql := fmt.Sprintf(`delete from doc_template doc_template memo.id = '%d'`,id)
|
||||||
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadDocTemplate(id int32) ([]DocTemplate,error){
|
||||||
|
memo := []DocTemplate{}
|
||||||
|
sql := fmt.Sprintf(`select * from doc_template where doc_template.id = '%d'`,id)
|
||||||
|
e := db.GetMysqlClient().Query2(sql,&memo)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return nil,e
|
||||||
|
}
|
||||||
|
return memo,nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDocTemplate(title string,limit int,offset int) ([]DocTemplate,error) {
|
||||||
|
memo := []DocTemplate{}
|
||||||
|
sql := fmt.Sprintf(`select * from doc_template where doc_template.name like '%s%%' limit %d offset %d`,
|
||||||
|
title,limit,offset)
|
||||||
|
log.Print(sql)
|
||||||
|
e := db.GetMysqlClient().Query2(sql,&memo)
|
||||||
|
if nil != e {
|
||||||
|
logs.Error(e.Error())
|
||||||
|
return nil,e
|
||||||
|
}
|
||||||
|
return memo,nil
|
||||||
|
}
|
Loading…
Reference in New Issue