'commit'
continuous-integration/drone/push Build is passing Details

master
黄海 4 years ago
parent 9b92aa2402
commit 9942c7f7e7

@ -7,9 +7,12 @@
<list default="true" id="19c8c37d-a056-451c-a29d-fb612b9a3e2f" name="Default Changelist" comment="commit">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/FileRelate/FileRelateController/FileReleateController.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/FileRelate/FileRelateController/FileReleateController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/docs.go" beforeDir="false" afterPath="$PROJECT_DIR$/docs/docs.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/swagger.json" beforeDir="false" afterPath="$PROJECT_DIR$/docs/swagger.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/swagger.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/docs/swagger.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/FileRelate/FileRelateDao/FileReleateDao.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/FileRelate/FileRelateDao/FileReleateDao.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/CommonUtil/CommonUtil.go" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/CommonUtil/CommonUtil.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/models/t_zhxy_clouddisk_tree.go" beforeDir="false" afterPath="$PROJECT_DIR$/models/t_zhxy_clouddisk_tree.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -57,7 +60,7 @@
<property name="go.modules.go.list.on.any.changes.was.set" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/Utils" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
@ -66,10 +69,10 @@
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="E:\Work\dsMin\dsSzxy\Utils" />
<recent name="E:\Work\dsMin\dsSzxy" />
<recent name="E:\Work\dsMin\dsSzxy\Utils\CommonUtil" />
<recent name="E:\Work\dsMin\dsSzxy\Tools" />
<recent name="E:\Work\dsMin\dsSzxy\Utils" />
<recent name="E:\Work\dsMin\dsSzxy\Utils\SsdbUtil" />
</key>
</component>

@ -30,14 +30,14 @@ func Routers(r *gin.RouterGroup) {
rr.POST("/updateNode", updateNode)
rr.POST("/delNode", delNode)
//返回指定树型结构下的子路径
//TODO
rr.GET("/getFileList", GetFileList)
//文件与文件夹的关系维护
rr.POST("/addNodeFile", addNodeFile)
rr.POST("/delNodeFile", delNodeFile)
//返回指定树型结构下的文件列表
//TODO
rr.GET("/getSyncTree", GetSyncTree)
rr.GET("/getAsyncTree", GetAsyncTree)
}
// @Summary 文件上传
@ -253,7 +253,6 @@ func addNode(c *gin.Context) {
}
}
// @Summary 修改云盘结点
// @Description 修改云盘结点
// @Tags 文件系统管理
@ -282,7 +281,6 @@ func updateNode(c *gin.Context) {
}
}
// @Summary 删除云盘结点
// @Description 删除云盘结点
// @Tags 文件系统管理
@ -323,7 +321,7 @@ func delNode(c *gin.Context) {
func addNodeFile(c *gin.Context) {
nodeId := c.PostForm("node_id")
fileId := c.PostForm("file_id")
success, err := FileRelateDao.AddNodeFile(nodeId,fileId)
success, err := FileRelateDao.AddNodeFile(nodeId, fileId)
if err != nil {
c.JSON(200, gin.H{
"success": success,
@ -337,7 +335,6 @@ func addNodeFile(c *gin.Context) {
}
}
// @Summary 删除云盘结点文件
// @Description 删除云盘结点文件
// @Tags 文件系统管理
@ -352,7 +349,7 @@ func addNodeFile(c *gin.Context) {
func delNodeFile(c *gin.Context) {
nodeId := c.PostForm("node_id")
fileId := c.PostForm("file_id")
success, err := FileRelateDao.DelNodeFile(nodeId,fileId)
success, err := FileRelateDao.DelNodeFile(nodeId, fileId)
if err != nil {
c.JSON(200, gin.H{
"success": success,
@ -365,3 +362,42 @@ func delNodeFile(c *gin.Context) {
})
}
}
/**
*/
func GetFileList(c *gin.Context) {
identityId := CommonUtil.ConvertStringToInt32(c.PostForm("identity_id"))
personId := CommonUtil.ConvertStringToInt32(c.PostForm("person_id"))
nodeId := c.PostForm("node_id")
limit := CommonUtil.ConvertStringToInt32(c.PostForm("limit"))
offset := CommonUtil.ConvertStringToInt32(c.PostForm("offset"))
success, list := FileRelateDao.GetFileList(identityId, personId, nodeId, int(limit), int(offset))
c.JSON(200, gin.H{
"success": success,
"data": list,
})
}
//获取指定树型结构下的子目录(同步)
func GetSyncTree(c *gin.Context) {
identityId := CommonUtil.ConvertStringToInt32(c.PostForm("identity_id"))
personId := CommonUtil.ConvertStringToInt32(c.PostForm("person_id"))
success, list := FileRelateDao.GetSyncTree(identityId, personId)
c.JSON(200, gin.H{
"success": success,
"data": list,
})
}
//获取指定树型结构下的子目录(异步)
func GetAsyncTree(c *gin.Context) {
identityId := CommonUtil.ConvertStringToInt32(c.PostForm("identity_id"))
personId := CommonUtil.ConvertStringToInt32(c.PostForm("person_id"))
nodeId := c.PostForm("node_id")
success, list := FileRelateDao.GetAsyncTree(identityId, personId, nodeId)
c.JSON(200, gin.H{
"success": success,
"data": list,
})
}

@ -4,6 +4,7 @@ import (
"dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/DbUtil"
"dsSzxy/Utils/SqlKit"
"dsSzxy/models"
"errors"
"fmt"
@ -111,7 +112,7 @@ func AddNode(identityId int32, personId int32, parentNodeId string, nodeName str
var model models.TZhxyClouddiskTree
model.NodeId = CommonUtil.GetUUID()
model.NodeName = nodeName
model.IndentityId = identityId
model.IdentityId = identityId
model.PersonId = personId
model.ParentId = parentNodeId
_, err := db.Insert(model)
@ -163,3 +164,48 @@ func DelNodeFile(nodeId string, fileId string) (bool, error) {
}
return true, nil
}
//获取指定树型结构下的子目录(同步)
func GetSyncTree(identityId int32, personId int32) (bool, error) {
sql := `select node_id,node_name,parent_id,identity_id,person_id from t_zhxy_clouddisk_tree where identity_id=? and person_id=?`
_, err := db.SQL(sql, identityId, personId).Execute()
if err != nil {
return false, err
}
return true, nil
}
//获取指定树型结构下的子目录(异步)
func GetAsyncTree(identityId int32, personId int32, parentId string) (bool, error) {
sql := `select node_id,node_name,parent_id,identity_id,person_id from t_zhxy_clouddisk_tree where identity_id=? and person_id=? and parent_id=?`
_, err := db.SQL(sql, identityId, personId, parentId).Execute()
if err != nil {
return false, err
}
return true, nil
}
//获取指定树形结构下的文件列表
func GetFileList(identityId int32, personId int32, nodeId string, limit int, offset int) (int32, []map[string]interface{}) {
var myBuilder = builder.Dialect(builder.MYSQL).Select("t1.*,t2.file_name,t2.file_size").
From(`t_zhxy_clouddisk_tree_file as t1`).
InnerJoin("t_zhxy_file as t2", "t1.file_id=t2.file_id").
Where(builder.Eq{"t2.b_use": 1}).
And(builder.Eq{"t1.identity_id": identityId}).
And(builder.Eq{"t1.person_id": personId}).
And(builder.Eq{"t1.node_id": nodeId}).OrderBy("t1.record_time desc")
//获取拼接完成的SQL语句
sql, err := myBuilder.Limit(limit, offset).ToBoundSQL()
if err != nil {
fmt.Println(err.Error())
}
c, err := SqlKit.Count(sql)
if err != nil {
fmt.Println(err.Error())
}
list, err := db.SQL(sql).Query().List()
if err != nil {
fmt.Println(err.Error())
}
return c, list
}

@ -220,3 +220,16 @@ func IsContain(items []string, item string) bool {
}
return false
}
/**
2020-01-22
*/
func GetSnakeCaseStr(str string) string {
array := strings.Split(str, "_")
var result string
for i := 0; i < len(array); i++ {
result = result + strings.ToUpper(array[i][0:1]) + array[i][1:]
}
return result
}

@ -0,0 +1,56 @@
package SqlKit
import (
"dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/DbUtil"
"dsSzxy/Utils/RedisUtil"
"time"
)
/**
interfacestruct
2020-02-05
*/
type Selector struct {
TableName string
PkField string
RedisPrefix string
}
/**
2020-03-27
*/
func GetBean(tableName string) Selector {
var m = new(Selector)
m.TableName = tableName
m.RedisPrefix = CommonUtil.GetSnakeCaseStr(tableName) + ":"
_, m.PkField = GetTablePk(tableName)
return *m
}
/**
2020-03-26
*/
func GetTablePk(tableName string) (bool, string) {
//优先到缓存中查找
key := "pk_" + tableName
pk, err := RedisUtil.GET(key)
if err != nil {
sql := "select column_name from information_schema.`key_column_usage` where table_schema=? and table_name=? and constraint_name='primary'"
list, err := DbUtil.Engine.SQL(sql, ConfigUtil.MysqlDbName, tableName).Query().List()
if err != nil || len(list) == 0 {
//LogUtil.Error(ErrorConst.SqlQueryError, err.Error())
return false, ""
}
pk = list[0]["column_name"].(string)
//设置缓存
RedisUtil.SET(key, pk, 24*7*time.Hour)
}
return true, pk
}

@ -0,0 +1,106 @@
package SqlKit
import (
"dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/DbUtil"
"fmt"
"strings"
)
//操作数据库的变量
var db = DbUtil.Engine
/**
SQLSQLSQL
2020-02-21
*/
func Count(baseSql string) (int32, error) {
//转小写
baseSql = strings.ToLower(baseSql)
//截取去掉最后面的 limit ?
baseSql = strings.Split(baseSql, " limit ")[0]
countSql := "select count(1) as count from (" + baseSql + ") as t100"
var count int32
_, err := db.SQL(countSql).Get(&count)
if err != nil {
fmt.Println(err.Error())
return 0, err
}
return count, nil
}
/**
sql
2020-06-10
*/
func isMultiFieldSql(sql string) bool {
sql = strings.ToLower(sql)
if strings.Index(sql, " join ") > 0 {
return true
} else {
return false
}
}
/**
distinctsql
2020-06-12
*/
func isDistinctSql(sql string) bool {
sql = strings.ToLower(sql)
if strings.Index(sql, " distinct ") > 0 {
return true
} else {
return false
}
}
/**
SQL
2020-03-25
*/
func pageSql(sql string) ([]map[string]interface{}, int32, error) {
//总数
count, err := Count(sql)
if err != nil {
fmt.Println(err.Error())
return nil, 0, err
}
//数据
list, err := db.SQL(sql).Query().List()
if err != nil {
fmt.Println(err.Error())
return nil, 0, err
}
return list, count, nil
}
/**
2020-6-12
*/
func GetTableColumns(tableName string) ([]map[string]interface{}, error) {
sql := `select COLUMN_NAME from information_schema.COLUMNS where table_name = ? and table_schema = '` + ConfigUtil.MysqlDbName + `'`
return db.SQL(sql, tableName).Query().List()
}
/**
2020-06-12
*/
func GetTableBatchSize(tableName string) int {
var maxFileds = 65535
//计算每个批次的大小
list, _ := GetTableColumns(tableName)
batchSize := maxFileds / len(list)
return batchSize
}

@ -22,6 +22,7 @@ require (
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-redis/redis/v7 v7.4.1 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/golang/snappy v0.0.4 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect

@ -171,6 +171,8 @@ github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPg
github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis/v7 v7.4.1 h1:PASvf36gyUpr2zdOUS/9Zqc80GbM+9BDyiJSJDDOrTI=
github.com/go-redis/redis/v7 v7.4.1/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-redis/redis/v8 v8.0.0-beta.1/go.mod h1:o1M7JtsgfDYyv3o+gBn/jJ1LkqpnCrmil7PSppZGBak=
github.com/go-redis/redis/v8 v8.8.2 h1:O/NcHqobw7SEptA0yA6up6spZVFtwE06SXM8rgLtsP8=
github.com/go-redis/redis/v8 v8.8.2/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y=

@ -41,10 +41,8 @@ func main() {
gin.SetMode(gin.DebugMode)
// 开启gin服务器
r := gin.Default()
//注册swagger
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
//设置静态资源
r.Static("/dsSzxy/static", "./static")
// 使用跨域中间件

@ -4,6 +4,6 @@ type TZhxyClouddiskTree struct {
NodeId string `xorm:"not null pk comment('结点ID') CHAR(36)"`
NodeName string `xorm:"not null comment('结点名称') VARCHAR(255)"`
ParentId string `xorm:"not null comment('父结点ID') CHAR(36)"`
IndentityId int32 `xorm:"not null comment('所有人的身份') INT(11)"`
IdentityId int32 `xorm:"not null comment('所有人的身份') INT(11)"`
PersonId int32 `xorm:"not null comment('所有人的ID') INT(11)"`
}

Loading…
Cancel
Save