1、增加训练数据集管理;

This commit is contained in:
wangjian 2023-05-14 18:23:12 +08:00
parent adca8e6148
commit 1d698fe0a6
19 changed files with 939 additions and 102 deletions

View File

@ -20,6 +20,7 @@ minio:
endpoint: 127.0.0.1:9000 endpoint: 127.0.0.1:9000
accessKeyId: root accessKeyId: root
secretAccessKey: OIxv7QptYBO3 secretAccessKey: OIxv7QptYBO3
bucket: jky-data
consul: consul:
host: http://consul.hpds.cc host: http://consul.hpds.cc
port: 80 port: 80
@ -27,12 +28,21 @@ consul:
timeout: 5 timeout: 5
deregister: 1 deregister: 1
db: db:
conn: root:OIxv7QptYBO3@tcp(114.55.236.153:23306)/diagnostic_platform?charset=utf8mb4 conn: root:OIxv7QptYBO3@tcp(192.168.53.10:3306)/diagnosis?charset=utf8mb4
drive_name: mysql drive_name: mysql
cache: cache:
host: 127.0.0.1 host: 127.0.0.1
port: 6379 port: 6379
db: 0 db: 0
pool_size: 10 pool_size: 10
node:
host: 127.0.0.1
port: 27188
token: 06d36c6f5705507dae778fdce90d0767
functions: functions:
- name: web-sf - name: task-request
dataTag : 12
mqType: 1
- name: task-log
dataTag: 28
mqType: 2

38
go.mod
View File

@ -1,6 +1,6 @@
module hpds-iot-web module hpds-iot-web
go 1.18 go 1.19
require ( require (
git.hpds.cc/Component/gin_valid v0.0.0-20230104142509-f956bce255b6 git.hpds.cc/Component/gin_valid v0.0.0-20230104142509-f956bce255b6
@ -8,31 +8,29 @@ require (
git.hpds.cc/Component/network v0.0.0-20230405135741-a4ea724bab76 git.hpds.cc/Component/network v0.0.0-20230405135741-a4ea724bab76
git.hpds.cc/pavement/hpds_node v0.0.0-20230405153516-9403c4d01e12 git.hpds.cc/pavement/hpds_node v0.0.0-20230405153516-9403c4d01e12
github.com/360EntSecGroup-Skylar/excelize v1.4.1 github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-contrib/zap v0.1.0 github.com/gin-contrib/zap v0.1.0
github.com/gin-gonic/gin v1.8.2 github.com/gin-gonic/gin v1.8.2
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/goccy/go-json v0.9.11 github.com/goccy/go-json v0.9.11
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/hashicorp/consul/api v1.15.3 github.com/hashicorp/consul/api v1.15.3
github.com/minio/minio-go/v7 v7.0.46 github.com/minio/minio-go/v7 v7.0.46
github.com/spf13/cobra v0.0.3 github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.14.0 github.com/spf13/viper v1.8.1
go.uber.org/zap v1.24.0 go.uber.org/zap v1.24.0
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 golang.org/x/image v0.1.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
xorm.io/xorm v1.3.2 xorm.io/xorm v1.3.2
) )
require ( require (
cloud.google.com/go v0.104.0 // indirect cloud.google.com/go v0.81.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect cloud.google.com/go/firestore v1.5.0 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/firestore v1.8.0 // indirect
git.hpds.cc/Component/mq_coder v0.0.0-20221010064749-174ae7ae3340 // indirect git.hpds.cc/Component/mq_coder v0.0.0-20221010064749-174ae7ae3340 // indirect
github.com/armon/go-metrics v0.4.0 // indirect github.com/armon/go-metrics v0.4.0 // indirect
github.com/bketelsen/crypt v0.0.4 // indirect
github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fatih/color v1.13.0 // indirect github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
@ -41,7 +39,6 @@ require (
github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
@ -49,8 +46,7 @@ require (
github.com/google/go-cmp v0.5.9 // indirect github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
@ -60,6 +56,7 @@ require (
github.com/hashicorp/serf v0.9.8 // indirect github.com/hashicorp/serf v0.9.8 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/klauspost/compress v1.15.9 // indirect github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect github.com/leodido/go-urn v1.2.1 // indirect
@ -78,12 +75,10 @@ require (
github.com/onsi/ginkgo/v2 v2.2.0 // indirect github.com/onsi/ginkgo/v2 v2.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect github.com/quic-go/quic-go v0.33.0 // indirect
github.com/rs/xid v1.4.0 // indirect github.com/rs/xid v1.4.0 // indirect
github.com/sagikazarmark/crypt v0.8.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.9.2 // indirect github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cast v1.5.0 // indirect
@ -95,7 +90,6 @@ require (
go.etcd.io/etcd/api/v3 v3.5.5 // indirect go.etcd.io/etcd/api/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/v2 v2.305.5 // indirect go.etcd.io/etcd/client/v2 v2.305.5 // indirect
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
go.opencensus.io v0.23.0 // indirect go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect go.opentelemetry.io/otel/trace v1.10.0 // indirect
@ -103,16 +97,14 @@ require (
go.uber.org/multierr v1.8.0 // indirect go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.4.0 // indirect golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.6.0 // indirect golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.4.0 // indirect golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect golang.org/x/text v0.6.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/tools v0.2.0 // indirect golang.org/x/tools v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.47.0 // indirect
google.golang.org/api v0.102.0 // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e // indirect google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e // indirect
google.golang.org/grpc v1.50.1 // indirect google.golang.org/grpc v1.50.1 // indirect

View File

@ -78,3 +78,19 @@ func (s HandlerService) DatasetInfo(c *gin.Context) (data interface{}, err error
go s.SaveLog("获取数据集详情", "Dataset", "", "", ToString(data), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") go s.SaveLog("获取数据集详情", "Dataset", "", "", ToString(data), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return return
} }
func (s HandlerService) CreateTraining(c *gin.Context) (data interface{}, err error) {
repo := service.NewDatasetService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.TrainDatasetRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("CreateTraining", "Training", "", "", ToString(req), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.UserId = userInfo.UserId
data, err = repo.CreateTraining(c, req)
go s.SaveLog("创建训练数据集", "Training", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}

View File

@ -105,7 +105,7 @@ func (s HandlerService) TaskLog(c *gin.Context) (data interface{}, err error) {
repo := service.NewTaskService(s.Engine, s.Logger) repo := service.NewTaskService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser") us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser) userInfo := us.(*model.SystemUser)
var req proto.TaskItemRequest var req proto.TaskLogItem
err = c.ShouldBindJSON(&req) err = c.ShouldBindJSON(&req)
if err != nil { if err != nil {
go s.SaveLog("TaskLog", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") go s.SaveLog("TaskLog", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")

View File

@ -85,3 +85,59 @@ func (s HandlerService) MenuList(c *gin.Context) (data interface{}, err error) {
go s.SaveLog("获取用户菜单列表", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "") go s.SaveLog("获取用户菜单列表", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return return
} }
func (s HandlerService) GetRoleList(c *gin.Context) (data interface{}, err error) {
repo := service.NewUserService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userinfo := us.(*model.SystemUser)
var req proto.RoleRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetRoleList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.GetRoleList(c, req)
if err != nil {
go s.SaveLog("GetRoleList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("获取用户角色列表", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddRole(c *gin.Context) (data interface{}, err error) {
repo := service.NewUserService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userinfo := us.(*model.SystemUser)
var req proto.RoleItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddRole", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddRole(c, req)
if err != nil {
go s.SaveLog("AddRole", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("新增用户角色", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditRole(c *gin.Context) (data interface{}, err error) {
repo := service.NewUserService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userinfo := us.(*model.SystemUser)
var req proto.RoleItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetRoleList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditRole(c, req)
if err != nil {
go s.SaveLog("EditRole", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("修改用户角色", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return
}

View File

@ -8,8 +8,8 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -26,6 +26,7 @@ func (us UserLogin) ToString() string {
type UserRequestItem struct { type UserRequestItem struct {
RealName string `json:"realName"` RealName string `json:"realName"`
Phone string `json:"phone"` Phone string `json:"phone"`
RoleId []int64 `json:"roleId"`
Password string `json:"password"` Password string `json:"password"`
Desc string `json:"desc"` Desc string `json:"desc"`
Status int `json:"status"` Status int `json:"status"`
@ -53,6 +54,37 @@ func (us UserRequest) ToString() string {
return string(data) return string(data)
} }
type RoleRequest struct {
RoleName string `json:"roleName"`
Status int `json:"status"`
BasePageList
}
func (us RoleRequest) ToString() string {
data, err := json.Marshal(us)
if err != nil {
return ""
}
return string(data)
}
type RoleItemRequest struct {
RoleId int64 `json:"roleId"`
RoleName string `json:"roleName"`
RoleValue string `json:"roleValue"`
AliasName string `json:"aliasName"`
Description string `json:"description"`
Status int `json:"status"`
}
func (us RoleItemRequest) ToString() string {
data, err := json.Marshal(us)
if err != nil {
return ""
}
return string(data)
}
type OwnerRequest struct { type OwnerRequest struct {
OwnerName string `json:"ownerName"` OwnerName string `json:"ownerName"`
BasePageList BasePageList
@ -675,6 +707,19 @@ func (p TaskItemRequest) ToString() string {
return string(data) return string(data)
} }
type TaskLogItem struct {
TaskId int64 `json:"taskId"`
LogId int64 `json:"logId"`
}
func (p TaskLogItem) ToString() string {
data, err := json.Marshal(p)
if err != nil {
return ""
}
return string(data)
}
type ReportRequest struct { type ReportRequest struct {
ReportId int64 `json:"reportId,omitempty"` ReportId int64 `json:"reportId,omitempty"`
TaskId int64 `json:"taskId,omitempty"` TaskId int64 `json:"taskId,omitempty"`
@ -688,3 +733,15 @@ func (p ReportRequest) ToString() string {
} }
return string(data) return string(data)
} }
type TrainDatasetRequest struct {
DatasetId int64 `json:"datasetId"`
TrainName string `json:"trainName"`
TrainDesc string `json:"trainDesc"`
TargetData int `json:"targetData"`
TrainNumber int64 `json:"trainNumber"`
ValidationNumber int64 `json:"validationNumber"`
TestNumber int64 `json:"testNumber"`
SplitMethod int `json:"splitMethod"`
UserId int64 `json:"userId"`
}

View File

@ -141,3 +141,30 @@ type TaskResultItem struct {
Memo string `json:"memo"` Memo string `json:"memo"`
Stat bool `json:"stat"` Stat bool `json:"stat"`
} }
// MessageEvent 定义SSE事件
type MessageEvent struct {
TaskId int64
EventId int64
Data interface{}
}
type TaskLogProgress struct {
PayloadType int `json:"payloadType"`
TaskId int64 `json:"taskId"`
TotalCount int64 `json:"totalCount"`
CompletedCount int64 `json:"completedCount"`
FailingCount int64 `json:"failingCount"`
UnfinishedCount int64 `json:"unfinishedCount"`
}
type TaskLogPayload struct {
PayloadType int `json:"payloadType"`
TaskId int64 `json:"taskId"`
TaskCode string `json:"taskCode"`
NodeId int64 `json:"nodeId"`
NodeGuid string `json:"nodeGuid"`
TaskContent string `json:"taskContent"`
Status int `json:"status"` //1执行成功;2:执行失败
EventTime int64 `json:"eventTime"`
}

View File

@ -12,6 +12,7 @@ import (
"net/http" "net/http"
"xorm.io/xorm" "xorm.io/xorm"
m "hpds-iot-web/model"
e "hpds-iot-web/pkg/err" e "hpds-iot-web/pkg/err"
) )
@ -37,6 +38,13 @@ func InitRouter(cfg *config.WebConfig, logger *logging.Logger, engine *xorm.Engi
menu.GET("/list", e.ErrorWrapper(hs.MenuList)) menu.GET("/list", e.ErrorWrapper(hs.MenuList))
} }
} }
role := r.Group("/role")
{
role.Use(middleware.JwtAuthMiddleware(logger.Logger))
role.POST("/list", e.ErrorWrapper(hs.GetRoleList))
role.POST("/edit", e.ErrorWrapper(hs.EditRole))
role.POST("/add", e.ErrorWrapper(hs.AddRole))
}
manage := r.Group("/manage") manage := r.Group("/manage")
{ {
manage.Use(middleware.JwtAuthMiddleware(logger.Logger)) manage.Use(middleware.JwtAuthMiddleware(logger.Logger))
@ -175,26 +183,42 @@ func InitRouter(cfg *config.WebConfig, logger *logging.Logger, engine *xorm.Engi
task.GET("/event", func(c *gin.Context) { task.GET("/event", func(c *gin.Context) {
//us, _ := c.Get("operatorUser") //us, _ := c.Get("operatorUser")
//userInfo := us.(*m.SystemUser) //userInfo := us.(*m.SystemUser)
mq.AddChannel(fmt.Sprintf("%d", 1))
c.Writer.Header().Set("Content-Type", "text/event-stream") c.Writer.Header().Set("Content-Type", "text/event-stream")
c.Writer.Header().Set("Cache-Control", "no-cache") c.Writer.Header().Set("Cache-Control", "no-cache")
c.Writer.Header().Set("Connection", "keep-alive") c.Writer.Header().Set("Connection", "keep-alive")
us, _ := c.Get("operatorUser")
if us == nil {
return
}
userInfo := us.(*m.SystemUser)
mq.AddChannel(fmt.Sprintf("%d", userInfo.UserId))
w := c.Writer w := c.Writer
flusher, _ := w.(http.Flusher) //flusher, _ := w.(http.Flusher)
closeNotify := c.Request.Context().Done() closeNotify := c.Request.Context().Done()
go func() { go func() {
<-closeNotify <-closeNotify
delete(mq.ChannelsMap, fmt.Sprintf("%d", 1)) delete(mq.ChannelsMap, fmt.Sprintf("%d", userInfo.UserId))
logging.L().Info("SSE close for user = " + fmt.Sprintf("%d", 1)) logger.Info("SSE close for user = " + fmt.Sprintf("%d", userInfo.UserId))
return return
}() }()
_, _ = fmt.Fprintf(w, "data: %s\n\n", "--ping--") // 循环监听 SSE 事件通道
flusher.Flush() for {
for msg := range mq.ChannelsMap[fmt.Sprintf("%d", 1)] { // 从通道中读取事件
_, _ = fmt.Fprintf(w, "data: %s\n\n", msg) message := <-mq.ChannelsMap[fmt.Sprintf("%d", userInfo.UserId)]
flusher.Flush()
// 向客户端发送 SSE 事件
_, _ = fmt.Fprintf(w, "%s", &message)
// 刷新 response buffer
w.(http.Flusher).Flush()
} }
//_, _ = fmt.Fprintf(w, "data: %s\n\n", "--ping--")
//flusher.Flush()
//for msg := range mq.ChannelsMap[fmt.Sprintf("%d", userInfo.UserId)] {
// _, _ = fmt.Fprintf(w, "data: %s\n\n", msg)
// flusher.Flush()
//}
}) })
} }
disease := r.Group("/disease") disease := r.Group("/disease")
@ -219,6 +243,19 @@ func InitRouter(cfg *config.WebConfig, logger *logging.Logger, engine *xorm.Engi
dataset.POST("/info", e.ErrorWrapper(hs.DatasetInfo)) dataset.POST("/info", e.ErrorWrapper(hs.DatasetInfo))
} }
training := r.Group("/training")
{
training.Use(middleware.JwtAuthMiddleware(logger.Logger))
training.POST("/create", e.ErrorWrapper(hs.CreateTraining))
//training.POST("/list", e.ErrorWrapper(hs.TrainingList))
//training.POST("/info", e.ErrorWrapper(hs.TrainingInfo))
}
label := r.Group("/label")
{
label.Use(middleware.JwtAuthMiddleware(logger.Logger))
//label.POST("/info", e.ErrorWrapper(hs.LabelInfo))
}
report := r.Group("/report") report := r.Group("/report")
{ {
report.Use(middleware.JwtAuthMiddleware(logger.Logger)) report.Use(middleware.JwtAuthMiddleware(logger.Logger))

View File

@ -7,6 +7,8 @@ import (
"hpds-iot-web/config" "hpds-iot-web/config"
"hpds-iot-web/internal/proto" "hpds-iot-web/internal/proto"
"hpds-iot-web/model" "hpds-iot-web/model"
"math"
"math/rand"
"net/http" "net/http"
"time" "time"
"xorm.io/xorm" "xorm.io/xorm"
@ -17,6 +19,8 @@ type DatasetService interface {
DatasetList(ctx context.Context, req proto.DatasetRequest) (rsp *proto.BaseResponse, err error) DatasetList(ctx context.Context, req proto.DatasetRequest) (rsp *proto.BaseResponse, err error)
ImportDataset(ctx context.Context, req proto.ImportDatasetRequest) (rsp *proto.BaseResponse, err error) ImportDataset(ctx context.Context, req proto.ImportDatasetRequest) (rsp *proto.BaseResponse, err error)
DatasetInfo(ctx context.Context, req proto.DatasetItemRequest) (rsp *proto.BaseResponse, err error) DatasetInfo(ctx context.Context, req proto.DatasetItemRequest) (rsp *proto.BaseResponse, err error)
CreateTraining(ctx context.Context, req proto.TrainDatasetRequest) (rsp *proto.BaseResponse, err error)
} }
func NewDatasetService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) DatasetService { func NewDatasetService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) DatasetService {
@ -224,3 +228,126 @@ ReturnPoint:
} }
return rsp, err return rsp, err
} }
func (rp *repo) CreateTraining(ctx context.Context, req proto.TrainDatasetRequest) (rsp *proto.BaseResponse, err error) {
rsp = new(proto.BaseResponse)
select {
case <-ctx.Done():
err = fmt.Errorf("超时/取消")
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Message = "超时/取消"
rsp.Err = ctx.Err()
return rsp, ctx.Err()
default:
var (
h bool
trainFileList []model.FileManager
valFileList []model.FileManager
testFileList []model.FileManager
//wg sync.WaitGroup
)
log := new(model.DatasetOperationLog)
dataset := new(model.Dataset)
h, err = rp.engine.ID(req.DatasetId).Get(dataset)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的采集数据集")
goto ReturnPoint
}
fileList := make([]model.FileManager, 0)
err = rp.engine.Where("dataset_id = ?", req.DatasetId).Find(&fileList)
if err != nil {
goto ReturnPoint
}
if req.TargetData == 0 {
req.TargetData = len(fileList)
}
if req.TargetData > len(fileList) {
err = fmt.Errorf("超出现有数据集数量")
goto ReturnPoint
}
if req.SplitMethod == 1 { //随机
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(fileList), func(i, j int) {
fileList[i], fileList[j] = fileList[j], fileList[i]
})
}
trainNumber := int(math.Floor(float64(int64(req.TargetData)*req.TrainNumber) / 100))
valNumber := int(math.Floor(float64(int64(req.TargetData)*req.ValidationNumber) / 100))
testNumber := req.TargetData - trainNumber - valNumber
trainFileList = fileList[:trainNumber-1]
valFileList = fileList[trainNumber : valNumber-1]
testFileList = fileList[valNumber:]
train := new(model.TrainingDataset)
h, err = rp.engine.Where("name = ?", req.TrainName).Get(train)
if err != nil {
goto ReturnPoint
}
if !h {
train.Name = req.TrainName
train.DatasetDesc = req.TrainDesc
train.DatasetId = req.DatasetId
train.CategoryId = dataset.CategoryId
_, err = rp.engine.Insert(train)
if err != nil {
goto ReturnPoint
}
}
log.TargetData = int64(req.TargetData)
log.DatasetId = req.DatasetId
log.TrainingDatasetId = train.DatasetId
log.SplitMethod = req.SplitMethod
log.TrainNumber = int64(trainNumber)
log.ValidationNumber = int64(valNumber)
log.TestNumber = int64(testNumber)
log.Creator = req.UserId
_, err = rp.engine.Insert(log)
if err != nil {
goto ReturnPoint
}
//wg.Add(3)
go BatchCopyData(trainFileList, train.DatasetId, log.LogId, req.UserId, 1, rp.engine) //, &wg
go BatchCopyData(valFileList, train.DatasetId, log.LogId, req.UserId, 2, rp.engine) //, &wg
go BatchCopyData(testFileList, train.DatasetId, log.LogId, req.UserId, 3, rp.engine) //, &wg
//wg.Wait()
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp.Err = err
rsp.Data = log
return rsp, err
}
ReturnPoint:
if err != nil {
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Err = err
rsp.Message = "失败"
}
return rsp, err
}
func BatchCopyData(list []model.FileManager, trainId, logId, userId int64, categoryId int, engine *xorm.Engine) { //, wg *sync.WaitGroup
batchList := make([]model.TrainingDatasetDetail, len(list))
for k, v := range list {
item := model.TrainingDatasetDetail{
FileName: v.FileName,
FilePath: v.AccessUrl,
DatasetId: trainId,
CategoryId: categoryId,
FileSize: v.FileSize,
FileMd5: v.FileMd5,
OperationLogId: logId,
Creator: userId,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
batchList[k] = item
}
_, _ = engine.Insert(batchList)
//wg.Done()
}

View File

@ -54,6 +54,9 @@ type UserService interface {
GetUserList(ctx context.Context, req proto.UserRequest) (rsp *proto.BaseResponse, err error) GetUserList(ctx context.Context, req proto.UserRequest) (rsp *proto.BaseResponse, err error)
AddUser(ctx context.Context, req proto.UserRequestItem) (rsp *proto.BaseResponse, err error) AddUser(ctx context.Context, req proto.UserRequestItem) (rsp *proto.BaseResponse, err error)
EditUser(ctx context.Context, req proto.UserRequestItem) (rsp *proto.BaseResponse, err error) EditUser(ctx context.Context, req proto.UserRequestItem) (rsp *proto.BaseResponse, err error)
GetRoleList(ctx context.Context, req proto.RoleRequest) (rsp *proto.BaseResponse, err error)
AddRole(ctx context.Context, req proto.RoleItemRequest) (rsp *proto.BaseResponse, err error)
EditRole(ctx context.Context, req proto.RoleItemRequest) (rsp *proto.BaseResponse, err error)
} }
func NewUserService(engine *xorm.Engine, logger *logging.Logger) UserService { func NewUserService(engine *xorm.Engine, logger *logging.Logger) UserService {
@ -261,14 +264,35 @@ func (rp *repo) GetUserList(ctx context.Context, req proto.UserRequest) (rsp *pr
rsp.Err = ctx.Err() rsp.Err = ctx.Err()
return rsp, ctx.Err() return rsp, ctx.Err()
default: default:
data := make([]model.SystemUser, 0) userList := make([]model.SystemUser, 0)
count, err := rp.engine.Where("(? = '' or phone like ?)", req.Phone, "%"+req.Phone+"%"). count, err := rp.engine.Where("(? = '' or phone like ?)", req.Phone, "%"+req.Phone+"%").
And("(? = '' or real_name like ?)", req.RealName, req.RealName). And("(? = '' or real_name like ?)", req.RealName, req.RealName).
And("status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)). And("status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data) FindAndCount(&userList)
if err != nil { if err != nil {
goto ReturnPoint goto ReturnPoint
} }
data := make([]proto.UserLoginResponse, len(userList))
for k, v := range userList {
roleList := model.GetRolesByUserId(v.UserId)
roles := make([]proto.RoleItem, len(roleList))
for key, val := range roleList {
roles[key] = proto.RoleItem{
RoleId: val.RoleId,
RoleName: val.RoleName,
Value: val.RoleValue,
}
}
data[k] = proto.UserLoginResponse{
UserId: v.UserId,
RealName: v.RealName,
UserName: v.Phone,
Roles: roles,
Avatar: v.Avatar,
Desc: v.Desc,
HomePath: v.HomePath,
}
}
rsp.Code = http.StatusOK rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK) rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功" rsp.Message = "成功"
@ -303,16 +327,38 @@ func (rp *repo) AddUser(ctx context.Context, req proto.UserRequestItem) (rsp *pr
goto ReturnPoint goto ReturnPoint
} }
if !b { if !b {
sess := rp.engine.NewSession()
item.Status = req.Status item.Status = req.Status
item.Phone = req.Phone item.Phone = req.Phone
item.RealName = req.RealName item.RealName = req.RealName
//item.RoleId = req.RoleId
item.Desc = req.Desc item.Desc = req.Desc
item.CreateAt = time.Now().Unix() item.CreateAt = time.Now().Unix()
item.UpdateAt = time.Now().Unix() item.UpdateAt = time.Now().Unix()
item.Salt = utils.RandomString(16, 3) item.Salt = utils.RandomString(16, 3)
item.Pass = utils.GetUserSha1Pass(req.Password, item.Salt) item.Pass = utils.GetUserSha1Pass(req.Password, item.Salt)
_, err = rp.engine.Insert(item) _, err = sess.Insert(item)
if err != nil { if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
if len(req.RoleId) > 0 {
for _, v := range req.RoleId {
role := new(model.SystemUserRole)
role.RoleId = v
role.UserId = item.UserId
role.Status = 1
_, err = sess.Insert(role)
if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
}
}
err = sess.Commit()
if err != nil {
_ = sess.Rollback()
goto ReturnPoint goto ReturnPoint
} }
} else { } else {
@ -348,7 +394,7 @@ func (rp *repo) EditUser(ctx context.Context, req proto.UserRequestItem) (rsp *p
return rsp, ctx.Err() return rsp, ctx.Err()
default: default:
item := new(model.SystemUser) item := new(model.SystemUser)
b, err := rp.engine.Where("phone = ?)", req.Phone). b, err := rp.engine.Where("phone = ?", req.Phone).
Get(item) Get(item)
if err != nil { if err != nil {
goto ReturnPoint goto ReturnPoint
@ -357,6 +403,7 @@ func (rp *repo) EditUser(ctx context.Context, req proto.UserRequestItem) (rsp *p
err = fmt.Errorf("未能找到对应的用户") err = fmt.Errorf("未能找到对应的用户")
goto ReturnPoint goto ReturnPoint
} else { } else {
sess := rp.engine.NewSession()
item.Status = req.Status item.Status = req.Status
if len(item.Phone) > 0 { if len(item.Phone) > 0 {
item.Phone = req.Phone item.Phone = req.Phone
@ -372,6 +419,185 @@ func (rp *repo) EditUser(ctx context.Context, req proto.UserRequestItem) (rsp *p
item.Pass = utils.GetUserSha1Pass(req.Password, item.Salt) item.Pass = utils.GetUserSha1Pass(req.Password, item.Salt)
} }
item.UpdateAt = time.Now().Unix() item.UpdateAt = time.Now().Unix()
_, err = sess.AllCols().Update(item)
if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
role := new(model.SystemUserRole)
role.UserId = item.UserId
role.Status = 0
_, err = sess.Where("user_id = ?", item.UserId).AllCols().Update(role)
if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
if len(req.RoleId) > 0 {
for _, v := range req.RoleId {
role := new(model.SystemUserRole)
b, err = sess.Where("user_id = ?", item.UserId).And("role_id=?", v).Get(role)
if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
if b {
role.Status = 1
_, err = sess.ID(role.UserRoleId).Update(role)
} else {
role.RoleId = v
role.UserId = item.UserId
role.Status = 1
_, err = sess.Insert(role)
}
if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
}
}
err = sess.Commit()
if err != nil {
_ = sess.Rollback()
goto ReturnPoint
}
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp.Err = ctx.Err()
rsp.Data = item
return rsp, err
}
ReturnPoint:
if err != nil {
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Err = err
rsp.Message = "失败"
}
return rsp, err
}
func (rp *repo) GetRoleList(ctx context.Context, req proto.RoleRequest) (rsp *proto.BaseResponse, err error) {
rsp = new(proto.BaseResponse)
select {
case <-ctx.Done():
err = fmt.Errorf("超时/取消")
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Message = "超时/取消"
rsp.Err = ctx.Err()
return rsp, ctx.Err()
default:
data := make([]model.SystemRole, 0)
count, err := rp.engine.Where("(? = '' or role_name like ?)", req.RoleName, "%"+req.RoleName+"%").
And("(? = 0 or status = ?)", req.Status, req.Status).Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
rsp.Err = err
return rsp, err
}
ReturnPoint:
if err != nil {
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Err = err
rsp.Message = "失败"
}
return rsp, err
}
func (rp *repo) AddRole(ctx context.Context, req proto.RoleItemRequest) (rsp *proto.BaseResponse, err error) {
rsp = new(proto.BaseResponse)
select {
case <-ctx.Done():
err = fmt.Errorf("超时/取消")
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Message = "超时/取消"
rsp.Err = ctx.Err()
return rsp, ctx.Err()
default:
item := new(model.SystemRole)
b, err := rp.engine.Where("role_value = ?", req.RoleValue).
Get(item)
if err != nil {
goto ReturnPoint
}
if b {
err = fmt.Errorf("已经存在相同值的角色")
goto ReturnPoint
} else {
item.AliasName = req.AliasName
item.Description = req.Description
item.RoleName = req.RoleName
item.RoleValue = req.RoleValue
item.Status = req.Status
item.CreateAt = time.Now().Unix()
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp.Err = ctx.Err()
rsp.Data = item
return rsp, err
}
ReturnPoint:
if err != nil {
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Err = err
rsp.Message = "失败"
}
return rsp, err
}
func (rp *repo) EditRole(ctx context.Context, req proto.RoleItemRequest) (rsp *proto.BaseResponse, err error) {
rsp = new(proto.BaseResponse)
select {
case <-ctx.Done():
err = fmt.Errorf("超时/取消")
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Message = "超时/取消"
rsp.Err = ctx.Err()
return rsp, ctx.Err()
default:
item := new(model.SystemRole)
b, err := rp.engine.Where("role_id = ?", req.RoleId).
Get(item)
if err != nil {
goto ReturnPoint
}
if !b {
err = fmt.Errorf("未能找到对应的用户")
goto ReturnPoint
} else {
if len(req.AliasName) > 0 && item.AliasName != req.AliasName {
item.AliasName = req.AliasName
}
if len(req.Description) > 0 && item.Description != req.Description {
item.Description = req.Description
}
if len(req.RoleName) > 0 && item.RoleName != req.RoleName {
item.RoleName = req.RoleName
}
if len(req.RoleValue) > 0 && item.RoleValue != req.RoleValue {
item.RoleValue = req.RoleValue
}
item.Status = req.Status
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.AllCols().Update(item) _, err = rp.engine.AllCols().Update(item)
if err != nil { if err != nil {
goto ReturnPoint goto ReturnPoint

View File

@ -1,12 +1,18 @@
package service package service
import ( import (
"bytes"
"context" "context"
"encoding/base64"
"encoding/json"
"fmt" "fmt"
"git.hpds.cc/Component/logging" "git.hpds.cc/Component/logging"
"hpds-iot-web/internal/proto" "hpds-iot-web/internal/proto"
"hpds-iot-web/model" "hpds-iot-web/model"
"hpds-iot-web/mq"
"image"
"net/http" "net/http"
"strconv"
"xorm.io/xorm" "xorm.io/xorm"
"github.com/360EntSecGroup-Skylar/excelize" "github.com/360EntSecGroup-Skylar/excelize"
@ -71,46 +77,273 @@ func (rp *repo) GenerateReport(ctx context.Context, req proto.ReportRequest) (rs
//rsp.Err = ctx.Err() //rsp.Err = ctx.Err()
return rsp, ctx.Err() return rsp, ctx.Err()
default: default:
//data := make([]model.Report, 0) taskResultList := make([]model.TaskResult, 0)
//_, err = rp.engine. err = rp.engine.Where("task_id = ?", req.TaskId).
// Where("(? = 0 or m.report_id = ?)", req.ReportId, req.ReportId). Find(&taskResultList)
// And("t.status > 0").Limit(int(req.Size), int(((req.Page)-1)*req.Size)). if err != nil {
// FindAndCount(&data) err = fmt.Errorf("未能找到对应的结果")
//if err != nil { goto ReturnPoint
// goto ReturnPoint
//}
list := make([]proto.TaskResultItem, 2)
list[0] = proto.TaskResultItem{
FileId: 147,
FileName: "Y016 2.844 I 1 06272008 Color.jpg",
SrcFile: "http://127.0.0.1:9000/jky-data/road/test_dataset/Y016 2.844 I 1 06272008 Color.jpg",
DistFile: "http://127.0.0.1:9000/jky-data/road/test_dataset/Y016 2.844 I 1 06272008 Color.jpg",
DiseaseType: 4,
DiseaseLevel: 2,
KPile: "K229+778",
UpDown: 1,
LineNum: 2,
Length: 0.5,
Width: 1,
Area: 0.5,
HorizontalPositions: 0.5,
Memo: "有裂缝",
} }
list[1] = proto.TaskResultItem{ list := make([]proto.TaskResultItem, 0)
FileId: 149, for _, v := range taskResultList {
FileName: "C279 0.132 I 1 06272008 Color.jpg", var h bool
SrcFile: "http://127.0.0.1:9000/jky-data/road/test_dataset/cba/C279 0.132 I 1 06272008 Color.jpg", file := new(model.FileManager)
DistFile: "http://127.0.0.1:9000/jky-data/road/test_dataset/cba/C279 0.132 I 1 06272008 Color.jpg", h, err = rp.engine.ID(v.FileId).Get(file)
DiseaseType: 0, if err != nil || !h {
DiseaseLevel: 0, continue
}
md := new(model.Model)
h, err = rp.engine.ID(v.ModelId).Get(md)
if err != nil || !h {
continue
}
var (
mr mq.ModelResult
mrList []string
fileDiscern string
memo string
diseaseType int64
diseaseLevel int
length float64
area float64
width float64
diseaseTypeName string
diseaseLevelName string
)
if len(v.Result) > 0 && v.Result[0] == '[' {
mrList = make([]string, 0)
if err := json.Unmarshal([]byte(v.Result), &mrList); err != nil {
continue
}
for _, str := range mrList {
if err := json.Unmarshal([]byte(str), &mr); err != nil {
continue
}
switch mr.Code {
case 0: //轻量化模型返回
lr := new(mq.LightweightResult)
if err := json.Unmarshal([]byte(v.Result), lr); err != nil {
continue
}
//for _, val := range lrList {
if lr.Crack || lr.Pothole {
if lr.Crack {
memo = "检测到裂缝"
} else {
memo = "检测到坑洼"
}
fileDiscern = lr.ImgDiscern
diseaseLevel = 3
diseaseLevelName = "重度"
switch md.BizType {
case 2:
diseaseType = 8
diseaseTypeName = "结构裂缝"
case 3:
diseaseType = 15
diseaseTypeName = "衬砌裂缝"
default:
diseaseType = 4
diseaseTypeName = "横向裂缝"
}
}
fn, _ := base64.StdEncoding.DecodeString(fileDiscern)
buff := bytes.NewBuffer(fn)
_, imgType, _ := image.Decode(buff)
fileDiscern = fmt.Sprintf("data:image/%s;base64,%s", imgType, fileDiscern)
item := proto.TaskResultItem{
FileId: v.FileId,
FileName: v.SrcPath,
SrcFile: file.AccessUrl,
DistFile: fileDiscern,
DiseaseType: int(diseaseType),
DiseaseTypeName: diseaseTypeName,
DiseaseLevel: diseaseLevel,
DiseaseLevelName: diseaseLevelName,
KPile: "", KPile: "",
UpDown: 0, UpDown: 0,
LineNum: 0, LineNum: 0,
Length: 0, Length: length,
Width: 0, Width: width,
Area: 0, Area: area,
HorizontalPositions: 0, HorizontalPositions: 0,
Memo: memo,
Stat: false,
}
list = append(list, item)
//}
case 2000:
ir := new(mq.InsigmaResult)
if err := json.Unmarshal([]byte(str), &ir); err != nil {
continue
}
fileDiscern = ir.Image
fn, _ := base64.StdEncoding.DecodeString(fileDiscern)
buff := bytes.NewBuffer(fn)
_, imgType, _ := image.Decode(buff)
fileDiscern = fmt.Sprintf("data:image/%s;base64,%s", imgType, fileDiscern)
item := proto.TaskResultItem{
FileId: v.FileId,
FileName: v.SrcPath,
SrcFile: file.AccessUrl,
DistFile: fileDiscern,
DiseaseType: int(diseaseType),
DiseaseTypeName: diseaseTypeName,
DiseaseLevel: diseaseLevel,
DiseaseLevelName: diseaseLevelName,
KPile: "",
UpDown: 0,
LineNum: 0,
Length: length,
Width: width,
Area: area,
HorizontalPositions: 0,
Memo: memo,
Stat: false,
}
list = append(list, item)
case 2001:
ir := new(mq.InsigmaResult)
if err := json.Unmarshal([]byte(str), &ir); err != nil {
continue
}
fileDiscern = ir.Image
for _, value := range ir.Diseases {
diseaseType = model.GetDiseaseType(value.Type, md.BizType)
if len(value.Param.MaxWidth) > 0 && width == 0 {
width, _ = strconv.ParseFloat(value.Param.MaxWidth, 64)
}
length = value.Param.Length
area = value.Param.Area
diseaseLevelName = value.Level
diseaseTypeName = value.Type
switch value.Level {
case "重度":
diseaseLevel = 3
case "中度":
diseaseLevel = 2
case "轻度":
diseaseLevel = 1
}
memo += fmt.Sprintf("发现[%s],等级[%s],长度[%f],最大宽度[%s],面积[%f];\n", value.Type, value.Level, value.Param.Length, value.Param.MaxWidth, value.Param.Area)
}
fn, _ := base64.StdEncoding.DecodeString(fileDiscern)
buff := bytes.NewBuffer(fn)
_, imgType, _ := image.Decode(buff)
fileDiscern = fmt.Sprintf("data:image/%s;base64,%s", imgType, fileDiscern)
item := proto.TaskResultItem{
FileId: v.FileId,
FileName: v.SrcPath,
SrcFile: file.AccessUrl,
DistFile: fileDiscern,
DiseaseType: int(diseaseType),
DiseaseTypeName: diseaseTypeName,
DiseaseLevel: diseaseLevel,
DiseaseLevelName: diseaseLevelName,
KPile: "",
UpDown: 0,
LineNum: 0,
Length: length,
Width: width,
Area: area,
HorizontalPositions: 0,
Memo: memo,
Stat: false,
}
list = append(list, item)
}
}
} else {
if err := json.Unmarshal([]byte(v.Result), &mr); err != nil {
continue
}
switch mr.Code {
case 0: //轻量化模型返回
lr := new(mq.LightweightResult)
if err := json.Unmarshal([]byte(v.Result), &lr); err != nil {
continue
}
if lr.Crack || lr.Pothole {
if lr.Crack {
memo = "检测到裂缝"
} else {
memo = "检测到坑洼"
}
fileDiscern = lr.ImgDiscern
diseaseLevel = 3
diseaseLevelName = "重度"
switch md.BizType {
case 2:
diseaseType = 8
diseaseTypeName = "结构裂缝"
case 3:
diseaseType = 15
diseaseTypeName = "衬砌裂缝"
default:
diseaseType = 4
diseaseTypeName = "横向裂缝"
}
}
//
case 2000: //网新返回没有病害
ir := new(mq.InsigmaResult)
if err := json.Unmarshal([]byte(v.Result), &ir); err != nil {
continue
}
fileDiscern = ir.Image
case 2001: //网新返回有病害
ir := new(mq.InsigmaResult)
if err := json.Unmarshal([]byte(v.Result), &ir); err != nil {
continue
}
fileDiscern = ir.Image
for _, val := range ir.Diseases {
diseaseType = model.GetDiseaseType(val.Type, md.BizType)
if len(val.Param.MaxWidth) > 0 && width == 0 {
width, _ = strconv.ParseFloat(val.Param.MaxWidth, 64)
}
length = val.Param.Length
area = val.Param.Area
diseaseLevelName = val.Level
diseaseTypeName = val.Type
switch val.Level {
case "重度":
diseaseLevel = 3
case "中度":
diseaseLevel = 2
case "轻度":
diseaseLevel = 1
}
memo += fmt.Sprintf("发现[%s],等级[%s],长度[%f],最大宽度[%s],面积[%f];\n", val.Type, val.Level, val.Param.Length, val.Param.MaxWidth, val.Param.Area)
}
}
fn, _ := base64.StdEncoding.DecodeString(fileDiscern)
buff := bytes.NewBuffer(fn)
_, imgType, _ := image.Decode(buff)
fileDiscern = fmt.Sprintf("data:image/%s;base64,%s", imgType, fileDiscern)
item := proto.TaskResultItem{
FileId: v.FileId,
FileName: v.SrcPath,
SrcFile: file.AccessUrl,
DistFile: fileDiscern,
DiseaseType: int(diseaseType),
DiseaseTypeName: diseaseTypeName,
DiseaseLevel: diseaseLevel,
DiseaseLevelName: diseaseLevelName,
KPile: "",
UpDown: 0,
LineNum: 0,
Length: length,
Width: width,
Area: area,
HorizontalPositions: 0,
Memo: memo,
Stat: false,
}
list = append(list, item)
}
} }
disTypeList := make([]model.DiseaseType, 0) disTypeList := make([]model.DiseaseType, 0)
err = model.DB.Find(&disTypeList) err = model.DB.Find(&disTypeList)
@ -122,9 +355,9 @@ func (rp *repo) GenerateReport(ctx context.Context, req proto.ReportRequest) (rs
diseaseTypeList[v.TypeId] = v.TypeName diseaseTypeList[v.TypeId] = v.TypeName
} }
diseaseLevelList := make(map[int]string) diseaseLevelList := make(map[int]string)
diseaseLevelList[1] = "一级" diseaseLevelList[1] = "轻度"
diseaseLevelList[2] = "二级" diseaseLevelList[2] = "中度"
diseaseLevelList[3] = "三级" diseaseLevelList[3] = "重度"
xlsx := excelize.NewFile() xlsx := excelize.NewFile()
xlsx.MergeCell("Sheet1", "A1", "L1") xlsx.MergeCell("Sheet1", "A1", "L1")

View File

@ -25,7 +25,7 @@ type TaskService interface {
ReRunTask(ctx context.Context, req proto.TaskItemRequest) (rsp *proto.BaseResponse, err error) ReRunTask(ctx context.Context, req proto.TaskItemRequest) (rsp *proto.BaseResponse, err error)
//EditTask(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) //EditTask(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error)
TaskResult(ctx context.Context, req proto.ReportRequest) (rsp *proto.BaseResponse, err error) TaskResult(ctx context.Context, req proto.ReportRequest) (rsp *proto.BaseResponse, err error)
TaskLog(ctx context.Context, req proto.TaskItemRequest) (rsp *proto.BaseResponse, err error) TaskLog(ctx context.Context, req proto.TaskLogItem) (rsp *proto.BaseResponse, err error)
} }
func NewTaskService(engine *xorm.Engine, logger *logging.Logger) TaskService { func NewTaskService(engine *xorm.Engine, logger *logging.Logger) TaskService {
@ -131,7 +131,7 @@ func (rp *repo) AddTask(ctx context.Context, req proto.TaskItemRequest) (rsp *pr
SubDataset: req.SubDataset, SubDataset: req.SubDataset,
SubDataTag: req.SubDataTag, SubDataTag: req.SubDataTag,
AppointmentTime: req.AppointmentTime, AppointmentTime: req.AppointmentTime,
Status: 1, Status: 2,
CreateAt: time.Now().Unix(), CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(), UpdateAt: time.Now().Unix(),
} }
@ -143,8 +143,10 @@ func (rp *repo) AddTask(ctx context.Context, req proto.TaskItemRequest) (rsp *pr
goto ReturnPoint goto ReturnPoint
} }
item.StartTime = appTime.Unix() item.StartTime = appTime.Unix()
item.Status = 1
} else { } else {
item.StartTime = time.Now().Unix() item.StartTime = time.Now().Unix()
item.Status = 2
} }
_, err = rp.engine.Insert(item) _, err = rp.engine.Insert(item)
if err != nil { if err != nil {
@ -643,7 +645,7 @@ ReturnPoint:
return rsp, err return rsp, err
} }
func (rp *repo) TaskLog(ctx context.Context, req proto.TaskItemRequest) (rsp *proto.BaseResponse, err error) { func (rp *repo) TaskLog(ctx context.Context, req proto.TaskLogItem) (rsp *proto.BaseResponse, err error) {
rsp = new(proto.BaseResponse) rsp = new(proto.BaseResponse)
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -655,7 +657,7 @@ func (rp *repo) TaskLog(ctx context.Context, req proto.TaskItemRequest) (rsp *pr
return rsp, ctx.Err() return rsp, ctx.Err()
default: default:
list := make([]model.TaskLog, 0) list := make([]model.TaskLog, 0)
err = rp.engine.Where("task_id = ?", req.TaskId).Find(&list) err = rp.engine.Where("task_id = ?", req.TaskId).And("task_log_id>?", req.LogId).Find(&list)
if err != nil { if err != nil {
goto ReturnPoint goto ReturnPoint
} }

View File

@ -0,0 +1,15 @@
package model
type DatasetOperationLog struct {
LogId int64 `xorm:"not null pk autoincr INT(11)" json:"logId"`
DatasetId int64 `xorm:"INT(11) index" json:"datasetId"`
TrainingDatasetId int64 `xorm:"INT(11) index" json:"trainingDatasetId"`
TargetData int64 `xorm:"INT(11) default 0" json:"targetData"` //目标数据, 0:全量数据; n:指定数据量
TrainNumber int64 `xorm:"INT(11)" json:"trainNumber"` //训练集数量
ValidationNumber int64 `xorm:"INT(11)" json:"validationNumber"` //检验集数量
TestNumber int64 `xorm:"INT(11)" json:"testNumber"` //测试集数量
SplitMethod int `xorm:"SMALLINT default 1" json:"splitMethod"` //分割方式1:随机分割;2:顺序分割
Creator int64 `xorm:"INT(11) index" json:"creator"` //创建人
CreateAt int64 `xorm:"created" json:"createAt"` //创建时间
UpdateAt int64 `xorm:"updated" json:"updateAt"` //更新时间
}

View File

@ -29,6 +29,7 @@ func New(driveName, dsn string, showSql bool) {
&Brand{}, &Brand{},
&Dataset{}, &Dataset{},
&DatasetDetail{}, &DatasetDetail{},
&DatasetOperationLog{},
&DetectionTask{}, &DetectionTask{},
&Device{}, &Device{},
&DeviceType{}, &DeviceType{},
@ -61,6 +62,8 @@ func New(driveName, dsn string, showSql bool) {
&Task{}, &Task{},
&TaskLog{}, &TaskLog{},
&TaskResult{}, &TaskResult{},
&TrainingDataset{},
&TrainingDatasetDetail{},
) )
if err != nil { if err != nil {
zap.L().Error("同步数据库表结构", zap.Error(err)) zap.L().Error("同步数据库表结构", zap.Error(err))

View File

@ -6,8 +6,18 @@ type SystemRole struct {
RoleName string `xorm:"VARCHAR(32)" json:"roleName"` //角色名 RoleName string `xorm:"VARCHAR(32)" json:"roleName"` //角色名
RoleValue string `xorm:"VARCHAR(32)" json:"roleValue"` //角色值 RoleValue string `xorm:"VARCHAR(32)" json:"roleValue"` //角色值
AliasName string `xorm:"VARCHAR(32)" json:"aliasName"` //简称 AliasName string `xorm:"VARCHAR(32)" json:"aliasName"` //简称
DataRange []int64 `xorm:"VARCHAR(100)" json:"dataRange"` //数据范围
Description string `xorm:"VARCHAR(32)" json:"description"` //说明 Description string `xorm:"VARCHAR(32)" json:"description"` //说明
Status int `xorm:"int not null default 1" json:"status"` //状态 0禁用 1启用 Status int `xorm:"int not null default 1" json:"status"` //状态 0禁用 1启用
CreateAt int64 `xorm:"created" json:"createAt"` //创建时间 CreateAt int64 `xorm:"created" json:"createAt"` //创建时间
UpdateAt int64 `xorm:"updated" json:"updateAt"` //更新时间 UpdateAt int64 `xorm:"updated" json:"updateAt"` //更新时间
} }
func GetRole(id int64) *SystemRole {
item := new(SystemRole)
h, err := DB.ID(id).Get(item)
if err != nil || !h {
return nil
}
return item
}

11
model/trainingDataset.go Normal file
View File

@ -0,0 +1,11 @@
package model
type TrainingDataset struct {
DatasetId int64 `xorm:"not null pk autoincr INT(11)" json:"datasetId"`
Name string `xorm:"VARCHAR(200)" json:"name"`
CategoryId int `xorm:"not null SMALLINT default 1" json:"categoryId"` //业务分类, 1:道路 2:桥梁 3:隧道 4:边坡
DatasetDesc string `xorm:"varchar(200)" json:"datasetDesc"`
StoreName string `xorm:"varchar(200)" json:"storeName"` //存储路径
CreateAt int64 `xorm:"created" json:"createAt"`
UpdateAt int64 `xorm:"updated" json:"updateAt"`
}

View File

@ -0,0 +1,15 @@
package model
type TrainingDatasetDetail struct {
DetailId int64 `xorm:"not null pk autoincr INT(11)" json:"detailId"`
FileName string `xorm:"VARCHAR(200)" json:"fileName"`
FilePath string `xorm:"VARCHAR(1000)" json:"filePath"`
DatasetId int64 `xorm:"INT(11) index default 0" json:"datasetId"` //训练数据集
CategoryId int `xorm:"not null SMALLINT default 1" json:"categoryId"` //训练集分类1训练集;2测试集;3:验证集
FileSize int64 `xorm:"BININT" json:"fileSize"` //文件大小
FileMd5 string `xorm:"VARCHAR(64)" json:"fileMd5"` //文件MD5
OperationLogId int64 `xorm:"INT(11) index" json:"operationLogId"` //操作日志编号
Creator int64 `xorm:"INT(11) index" json:"creator"` //上传人
CreateAt int64 `xorm:"created" json:"createAt"` //上传时间
UpdateAt int64 `xorm:"updated" json:"updateAt"` //更新时间
}

View File

@ -124,13 +124,13 @@ func TaskLogNotificationHandler(data []byte) (frame.Tag, []byte) {
if err != nil { if err != nil {
return 0x0B, []byte(err.Error()) return 0x0B, []byte(err.Error())
} }
str, _ := json.Marshal(cmd.Payload) payload := cmd.Payload.(map[string]interface{})
str, _ := json.Marshal(payload)
for key := range ChannelsMap { for key := range ChannelsMap {
//if strings.Contains(key, userEmail) { //if strings.Contains(key, userEmail) {
// channel := channelsMap[key] // channel := channelsMap[key]
// channel <- string(msgBytes) // channel <- string(msgBytes)
//} //}
channel := ChannelsMap[key] channel := ChannelsMap[key]
channel <- string(str) channel <- string(str)
} }