|
@@ -1,8 +1,11 @@
|
|
package back
|
|
package back
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "database/sql"
|
|
|
|
+ "errors"
|
|
"fmt"
|
|
"fmt"
|
|
"strconv"
|
|
"strconv"
|
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/gin-gonic/contrib/sessions"
|
|
"github.com/gin-gonic/contrib/sessions"
|
|
"github.com/gin-gonic/contrib/static"
|
|
"github.com/gin-gonic/contrib/static"
|
|
@@ -60,6 +63,9 @@ func init() {
|
|
Setting.HTML+"404.html",
|
|
Setting.HTML+"404.html",
|
|
Setting.HTML+"position.html",
|
|
Setting.HTML+"position.html",
|
|
Setting.HTML+"BigBoss.html",
|
|
Setting.HTML+"BigBoss.html",
|
|
|
|
+ Setting.HTML+"Zapis.html",
|
|
|
|
+ Setting.HTML+"Mass.html",
|
|
|
|
+ Setting.HTML+"PageZap.html",
|
|
)
|
|
)
|
|
|
|
|
|
router.GET("/", handlerIndex)
|
|
router.GET("/", handlerIndex)
|
|
@@ -71,14 +77,49 @@ func init() {
|
|
router.GET("/страница/:page", handlerIndexPage)
|
|
router.GET("/страница/:page", handlerIndexPage)
|
|
router.GET("/page/:page", handlerPages)
|
|
router.GET("/page/:page", handlerPages)
|
|
|
|
|
|
|
|
+ router.POST("/order-select-time", handleGetTimeRecord)
|
|
|
|
+ router.POST("/order-insert", handlerInsertOrder)
|
|
|
|
+ router.POST("/order-select", handlerSelectOrder)
|
|
|
|
+
|
|
|
|
+ router.POST("/get-materials", func(c *gin.Context) {
|
|
|
|
+ infa := informationMass{}
|
|
|
|
+ e := infa.Select()
|
|
|
|
+ if e != nil {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": e.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ m := material{}
|
|
|
|
+ var materials []material
|
|
|
|
+ for _, link := range infa.Rows {
|
|
|
|
+ m.Link = link
|
|
|
|
+ e = m.SelectOne()
|
|
|
|
+ if e != nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ materials = append(materials, m)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Materials": materials,
|
|
|
|
+ })
|
|
|
|
+ })
|
|
router.POST("/login", handlerLogin)
|
|
router.POST("/login", handlerLogin)
|
|
router.POST("/logout", handlerLogout)
|
|
router.POST("/logout", handlerLogout)
|
|
|
|
|
|
|
|
+ router.POST("/set-material-list", handleSetMaterialList)
|
|
|
|
+ // router.POST("/get-material-list", handleGetMaterialList)
|
|
|
|
+
|
|
router.NoRoute(handlerNoRoute)
|
|
router.NoRoute(handlerNoRoute)
|
|
|
|
|
|
prepareRouterMenu()
|
|
prepareRouterMenu()
|
|
prepareRouterMaterial()
|
|
prepareRouterMaterial()
|
|
prepareRouterDocument()
|
|
prepareRouterDocument()
|
|
|
|
+
|
|
|
|
+ // buildTimeRecord()
|
|
}
|
|
}
|
|
|
|
|
|
// Run запустить сервер
|
|
// Run запустить сервер
|
|
@@ -100,10 +141,14 @@ func handlerIndex(c *gin.Context) {
|
|
isAdmin := false
|
|
isAdmin := false
|
|
isLogin := false
|
|
isLogin := false
|
|
|
|
|
|
|
|
+ isSecreter := false
|
|
|
|
+
|
|
role := getRoleFromContext(c)
|
|
role := getRoleFromContext(c)
|
|
if len(role) != 0 {
|
|
if len(role) != 0 {
|
|
if role == "__admin" {
|
|
if role == "__admin" {
|
|
isAdmin = true
|
|
isAdmin = true
|
|
|
|
+ } else if role == "_secretary" {
|
|
|
|
+ isSecreter = true
|
|
}
|
|
}
|
|
isLogin = true
|
|
isLogin = true
|
|
}
|
|
}
|
|
@@ -111,6 +156,7 @@ func handlerIndex(c *gin.Context) {
|
|
h := gin.H{}
|
|
h := gin.H{}
|
|
|
|
|
|
h["IsMain"] = isMain
|
|
h["IsMain"] = isMain
|
|
|
|
+ h["isSecreter"] = isSecreter
|
|
h["IsLogin"] = isLogin
|
|
h["IsLogin"] = isLogin
|
|
h["IsAdmin"] = isAdmin
|
|
h["IsAdmin"] = isAdmin
|
|
if isAdmin {
|
|
if isAdmin {
|
|
@@ -121,6 +167,7 @@ func handlerIndex(c *gin.Context) {
|
|
h["MenuTop"] = templateMenuTop
|
|
h["MenuTop"] = templateMenuTop
|
|
}
|
|
}
|
|
h["News"] = templateNews
|
|
h["News"] = templateNews
|
|
|
|
+
|
|
h["Pagination"] = templateNewsPagination
|
|
h["Pagination"] = templateNewsPagination
|
|
h["Notice"] = templateNotice
|
|
h["Notice"] = templateNotice
|
|
h["ServerVersion"] = Setting.ServerVersion
|
|
h["ServerVersion"] = Setting.ServerVersion
|
|
@@ -134,14 +181,27 @@ func handlerPages(c *gin.Context) {
|
|
isAdmin := false
|
|
isAdmin := false
|
|
isLogin := false
|
|
isLogin := false
|
|
|
|
|
|
|
|
+ isSecreter := false
|
|
|
|
+
|
|
|
|
+ role := getRoleFromContext(c)
|
|
|
|
+ if len(role) != 0 {
|
|
|
|
+ if role == "__admin" {
|
|
|
|
+ isAdmin = true
|
|
|
|
+ } else if role == "_secretary" {
|
|
|
|
+ isSecreter = true
|
|
|
|
+ }
|
|
|
|
+ isLogin = true
|
|
|
|
+ }
|
|
|
|
+
|
|
h := gin.H{}
|
|
h := gin.H{}
|
|
|
|
|
|
h["IsMain"] = isMain
|
|
h["IsMain"] = isMain
|
|
h["IsLogin"] = isLogin
|
|
h["IsLogin"] = isLogin
|
|
h["IsAdmin"] = isAdmin
|
|
h["IsAdmin"] = isAdmin
|
|
- h["News"] = templateNews
|
|
|
|
- h["Pagination"] = templateNewsPagination
|
|
|
|
- h["Notice"] = templateNotice
|
|
|
|
|
|
+ h["isSecreter"] = isSecreter
|
|
|
|
+ // h["News"] = templateNews
|
|
|
|
+ // h["Pagination"] = templateNewsPagination
|
|
|
|
+ // h["Notice"] = templateNotice
|
|
h["ServerVersion"] = Setting.ServerVersion
|
|
h["ServerVersion"] = Setting.ServerVersion
|
|
h["AvailableMaterial"] = false
|
|
h["AvailableMaterial"] = false
|
|
h["Page"] = c.Param("page")
|
|
h["Page"] = c.Param("page")
|
|
@@ -154,11 +214,14 @@ func handlerIndexPage(c *gin.Context) {
|
|
isMain := true
|
|
isMain := true
|
|
isAdmin := false
|
|
isAdmin := false
|
|
isLogin := false
|
|
isLogin := false
|
|
|
|
+ isSecreter := false
|
|
|
|
|
|
role := getRoleFromContext(c)
|
|
role := getRoleFromContext(c)
|
|
if len(role) != 0 {
|
|
if len(role) != 0 {
|
|
if role == "__admin" {
|
|
if role == "__admin" {
|
|
isAdmin = true
|
|
isAdmin = true
|
|
|
|
+ } else if role == "_secretary" {
|
|
|
|
+ isSecreter = true
|
|
}
|
|
}
|
|
isLogin = true
|
|
isLogin = true
|
|
}
|
|
}
|
|
@@ -172,6 +235,7 @@ func handlerIndexPage(c *gin.Context) {
|
|
h := gin.H{}
|
|
h := gin.H{}
|
|
|
|
|
|
h["IsMain"] = isMain
|
|
h["IsMain"] = isMain
|
|
|
|
+ h["isSecreter"] = isSecreter
|
|
h["IsLogin"] = isLogin
|
|
h["IsLogin"] = isLogin
|
|
h["IsAdmin"] = isAdmin
|
|
h["IsAdmin"] = isAdmin
|
|
if isAdmin {
|
|
if isAdmin {
|
|
@@ -270,15 +334,20 @@ func handlerNoRoute(c *gin.Context) {
|
|
isAdmin := false
|
|
isAdmin := false
|
|
isLogin := false
|
|
isLogin := false
|
|
|
|
|
|
|
|
+ isSecreter := false
|
|
|
|
+
|
|
role := getRoleFromContext(c)
|
|
role := getRoleFromContext(c)
|
|
if len(role) != 0 {
|
|
if len(role) != 0 {
|
|
if role == "__admin" {
|
|
if role == "__admin" {
|
|
isAdmin = true
|
|
isAdmin = true
|
|
|
|
+ } else if role == "_secretary" {
|
|
|
|
+ isSecreter = true
|
|
}
|
|
}
|
|
isLogin = true
|
|
isLogin = true
|
|
}
|
|
}
|
|
|
|
|
|
h["IsMain"] = false
|
|
h["IsMain"] = false
|
|
|
|
+ h["isSecreter"] = isSecreter
|
|
h["IsLogin"] = isLogin
|
|
h["IsLogin"] = isLogin
|
|
h["IsAdmin"] = isAdmin
|
|
h["IsAdmin"] = isAdmin
|
|
if isAdmin {
|
|
if isAdmin {
|
|
@@ -320,3 +389,307 @@ func handlerCatalog(c *gin.Context) {
|
|
|
|
|
|
c.HTML(200, "index.html", h)
|
|
c.HTML(200, "index.html", h)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func handleSetMaterialList(c *gin.Context) {
|
|
|
|
+ man := getManagerFromContext(c)
|
|
|
|
+
|
|
|
|
+ if man.Role != "__admin" {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": errorAccessRestricted,
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ m := informationMass{}
|
|
|
|
+
|
|
|
|
+ e := c.BindJSON(&m)
|
|
|
|
+ if e != nil {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": e.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ e = m.Insert()
|
|
|
|
+ if e != nil {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": "Материал с указанной ссылкой не существует",
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": nil,
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// func handleGetMaterialList(c *gin.Context) {
|
|
|
|
+// man := getManagerFromContext(c)
|
|
|
|
+
|
|
|
|
+// if man.Role != "__admin" {
|
|
|
|
+// c.JSON(200, gin.H{
|
|
|
|
+// "Error": errorAccessRestricted,
|
|
|
|
+// })
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// m := informationMass{}
|
|
|
|
+
|
|
|
|
+// e := m.Select()
|
|
|
|
+// if e != nil {
|
|
|
|
+// c.JSON(200, gin.H{
|
|
|
|
+// "Error": e.Error(),
|
|
|
|
+// })
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// c.JSON(200, gin.H{
|
|
|
|
+// "Error": nil,
|
|
|
|
+// "Link": m.Rows,
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+type timerecord struct {
|
|
|
|
+ Date string
|
|
|
|
+ Time int64
|
|
|
|
+ Record sql.NullInt64
|
|
|
|
+
|
|
|
|
+ Times []int64
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *timerecord) Insert() error {
|
|
|
|
+ stmt, ok := queries["Insert@TimeRecord@"]
|
|
|
|
+ if !ok {
|
|
|
|
+ return errors.New("Insert@TimeRecord@ not found")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _, e := stmt.Exec(m.Date, m.Time, m.Record)
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *timerecord) Select() error {
|
|
|
|
+ stmt, ok := queries["Select@TimeRecord@Times"]
|
|
|
|
+ if !ok {
|
|
|
|
+ return errors.New("ERROR: stmt[Select@TimeRecord@Times] IS NULL")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rows, e := stmt.Query(m.Date)
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+ defer rows.Close()
|
|
|
|
+
|
|
|
|
+ for rows.Next() {
|
|
|
|
+ e = rows.Scan(&m.Time)
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ m.Times = append(m.Times, m.Time)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *timerecord) Update() error {
|
|
|
|
+ stmt, ok := queries["Update@TimeRecord@"]
|
|
|
|
+ if !ok {
|
|
|
|
+ return errors.New("ERROR: stmt[Update@TimeRecord@] IS NULL")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _, e := stmt.Exec(m.Record, m.Date, m.Time)
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func handlerInsertOrder(c *gin.Context) {
|
|
|
|
+ role := getRoleFromContext(c)
|
|
|
|
+ if role != "__admin" {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": "Отказано в доступе",
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ n := timerecord{}
|
|
|
|
+ m := record{}
|
|
|
|
+
|
|
|
|
+ e := c.BindJSON(&m)
|
|
|
|
+ if e != nil {
|
|
|
|
+ fmt.Println(e)
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": e.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ n.Date = m.Date
|
|
|
|
+ n.Time = m.Time
|
|
|
|
+ n.Record.Valid = true
|
|
|
|
+ e = m.Insert()
|
|
|
|
+ if e != nil {
|
|
|
|
+ fmt.Println(e)
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": e.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ n.Record.Int64 = m.ID
|
|
|
|
+
|
|
|
|
+ e = n.Update()
|
|
|
|
+ if e != nil {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": "Не удалось создать запись. Возможно выбранное время уже кто-то успел занять несколькими секундами ранее :(",
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": nil,
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func handlerSelectOrder(c *gin.Context) {
|
|
|
|
+
|
|
|
|
+ m := record{}
|
|
|
|
+
|
|
|
|
+ e := m.Select()
|
|
|
|
+ if e != nil {
|
|
|
|
+ fmt.Println(e)
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": e.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Error": nil,
|
|
|
|
+ "Data": m.Rows,
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *record) Select() error {
|
|
|
|
+
|
|
|
|
+ stmt, ok := queries["Select#Order#"]
|
|
|
|
+ if !ok {
|
|
|
|
+ return errors.New("Запрос Select#Order# не найден")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rows, e := stmt.Query()
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+ defer rows.Close()
|
|
|
|
+
|
|
|
|
+ n := record{}
|
|
|
|
+ for rows.Next() {
|
|
|
|
+
|
|
|
|
+ //o."ID", o."Name", o."Passport", o."Phone", o."Cause", a."Date", a."Time"
|
|
|
|
+ e = rows.Scan(
|
|
|
|
+ &n.ID,
|
|
|
|
+ &n.Name,
|
|
|
|
+ &n.Passport,
|
|
|
|
+ &n.Phone,
|
|
|
|
+ &n.Cause,
|
|
|
|
+ &n.Date,
|
|
|
|
+ &n.Time,
|
|
|
|
+ )
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ m.Rows = append(m.Rows, n)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type record struct {
|
|
|
|
+ ID int64 `json:"ID"`
|
|
|
|
+ Name string `json:"Name"`
|
|
|
|
+ Passport string `json:"Passport"`
|
|
|
|
+ Phone string `json:"Phone"`
|
|
|
|
+ Cause string `json:"Cause"`
|
|
|
|
+
|
|
|
|
+ Date string `json:"Date"`
|
|
|
|
+ Time int64 `json:"Time"`
|
|
|
|
+
|
|
|
|
+ Rows []record
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *record) Insert() error {
|
|
|
|
+ stmt, ok := queries["Insert@Record@"]
|
|
|
|
+ if !ok {
|
|
|
|
+ return errors.New("ERROR: Insert@Record@ IS NULL")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ row := stmt.QueryRow(m.Name, m.Passport, m.Phone, m.Cause)
|
|
|
|
+ e := row.Scan(&m.ID)
|
|
|
|
+ if e != nil {
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func handleGetTimeRecord(c *gin.Context) {
|
|
|
|
+ m := timerecord{}
|
|
|
|
+
|
|
|
|
+ e := c.BindJSON(&m)
|
|
|
|
+ if e != nil {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Time": nil,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ e = m.Select()
|
|
|
|
+ if e != nil {
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Time": nil,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "Time": m.Times,
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func buildTimeRecord() {
|
|
|
|
+
|
|
|
|
+ m := timerecord{}
|
|
|
|
+
|
|
|
|
+ d := time.Date(2020, time.June, 1, 0, 0, 0, 0, time.UTC)
|
|
|
|
+ for i := 0; i < 90; i++ {
|
|
|
|
+
|
|
|
|
+ if d.Weekday() == 0 || d.Weekday() == 6 {
|
|
|
|
+ d = d.Add(8.64e+13)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var k int64
|
|
|
|
+ for k = 0; k < 5; k++ {
|
|
|
|
+
|
|
|
|
+ m.Date = d.String()[:10]
|
|
|
|
+ m.Time = k
|
|
|
|
+ m.Record.Valid = false
|
|
|
|
+
|
|
|
|
+ m.Insert()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ d = d.Add(8.64e+13)
|
|
|
|
+ }
|
|
|
|
+}
|