123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- package routers
- import (
- "context"
- "fmt"
- "../comm"
- _ "../docs"
- "../middleware/jwt"
- "net/http"
- "strings"
- "../pkg/setting"
- "../routers/api"
- "../routers/api/sap"
- "../routers/api/zc"
- "github.com/gin-contrib/gzip"
- "github.com/gin-gonic/gin"
- ginSwagger "github.com/swaggo/gin-swagger"
- "github.com/swaggo/gin-swagger/swaggerFiles"
- )
- func InitRouter() *gin.Engine {
- r := gin.New()
-
- go api.CronScheduled(context.TODO())
-
-
-
- r.Use(func(c *gin.Context) {
- fmt.Println(c.Request.URL)
- })
- r.Use(gzip.Gzip(gzip.DefaultCompression))
-
- r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
-
- return fmt.Sprintf(" %+v \n",
- param.Keys,
- )
- }))
- r.Use(gin.Logger())
- r.Use(Cors())
- r.Use(gin.Recovery())
- gin.SetMode(setting.ServerSetting.RunMode)
- r.Static("/static", setting.CurrentPath+"/dist/static")
- r.StaticFile("/", setting.CurrentPath+"/dist/index.html")
- r.StaticFile("/favicon.ico", setting.CurrentPath+"/dist/favicon.ico")
- r.Static("/file", setting.CurrentPath+"/uploads/file")
- r.Static("/uploads", setting.CurrentPath+"/uploads")
- r.POST("/auth", api.Auth)
- r.POST("/authlogin", api.AuthLogin)
- r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
-
-
-
-
-
- if setting.CommSetting.PortName != "" {
- r.GET("/comm/:id/:x/:y/", comm.ProcessHttp)
- r.GET("/cps/:id/:limit", comm.ProcessHttpCPS)
- r.POST("/comm/:id/:x/:y/", comm.ProcessHttp)
- r.POST("/cps/:id/:limit", comm.ProcessHttpCPS)
- }
- eqm := r.Group("/manage/api")
- eqm.POST("/login", api.Auth)
- eqm.POST("/login/imei", api.AuthImei)
- r.GET("/getData", api.GetWxCode)
- r.POST("/userwxopenid/binding", api.UserWXOpenIDBinding)
- apiV1 := r.Group("/authdata")
- apiV1.Use(jwt.JWT())
- {
- apiV1.POST("/rolemenus", api.GetRecuDataByName)
- apiV1.GET("/userinfo", api.GetUserinfo)
- apiV1.POST("/logout", api.UserLogout)
- apiV1.POST("/GetRecuDataByName", api.GetRecuDataByName)
- apiV1.POST("/GetDataByName", api.GetDataByName)
- apiV1.POST("/GetDataBySqlIN", api.GetDataBySqlIN)
- apiV1.POST("/GetDataByNames", api.GetDataByNames)
- apiV1.POST("/PostDataByName", api.PostDataByName)
- apiV1.POST("/PostDataByNames", api.PostDataByNames)
- apiV1.POST("/UpdateDataRelation", api.UpdateDataRelation)
- apiV1.POST("/GetDataByNameForm", api.GetDataByNameForm)
- apiV1.POST("/PostDataByNameForm", api.PostDataByNameForm)
- apiV1.POST("/GetUpkeepPlan", api.GetUpkeepPlan)
- apiV1.POST("/GetReportform", api.GetReportform)
- apiV1.POST("/GetArrList", api.GetArrList)
- apiV1.POST("/GETNurJudge", api.GETNurJudge)
- apiV1.POST("/GETNurJudgeRport", api.GETNurJudgeRport)
- apiV1.POST("/ExecDataByConfig", api.ExecDataByConfig)
- apiV1.POST("/ImportExcel", api.ImportExcel)
- apiV1.POST("/upload/:id/:name", api.UploadFile)
- apiV1.POST("/uploads", api.UploadFiles)
- apiV1.POST("/uploaderimage", api.UploaderImage)
- apiV1.POST("/uploaderTmrImage", api.UploaderTmrImage)
- apiV1.POST("/removeimage", api.RemovePicByName)
- apiV1.GET("/getthumbnailimage/:filename", api.GetThumbnailImage)
- apiV1.POST("/getoriginimage/:filename", api.GetOriginImage)
- apiV1.GET("/getfileraw/:filename", api.GetFileRaw)
- apiV1.GET("/downloadfile/:filename", api.DownloadFile)
- apiV1.POST("/removefile/:id", api.RemoveFileByName)
- apiV1.POST("/testdata", api.TestData)
- apiV1.POST("/Testpartitions", api.Testpartitions)
-
- apiV1.POST("/Createchart", api.Createchart)
- apiV1.POST("/Updatechart", api.Createchart)
- apiV1.POST("/exesql", api.ExecSQL)
- apiV1.POST("/Createdashboard", api.Updatedashboard)
- apiV1.POST("/Updatedashboard", api.Updatedashboard)
- apiV1.POST("/Dashboards", api.Dashboards)
-
- apiV1.POST("/getDorm", api.GetDorm)
- apiV1.POST("/GetRJSBData", api.GetRJSBData)
- apiV1.POST("/PostRJSBData", api.PostRJSBData)
- apiV1.POST("/PostRJSBDatas", api.PostRJSBDatas)
- apiV1.POST("/autogeneration", api.Autogeneration)
- apiV1.POST("/spillage", api.GetSpillage)
- apiV1.POST("/trains", api.UpdateTrains)
- apiV1.POST("/lpplan/edit", api.UpdateLpplan)
- apiV1.POST("/lpplan/add", api.AddLpplan)
- apiV1.POST("/lpplandtl", api.GetLpplandtl)
- apiV1.POST("/lpplandtl/restore", api.RestoreLpplandtl)
- apiV1.POST("/lpplandtl/del", api.DelLpplandtl)
- apiV1.POST("/spillage/day", api.GetSpillageDay)
- apiV1.POST("/trains/day", api.UpdateTrainsDay)
- apiV1.POST("/lpplandtl/restore/day", api.RestoreLpplandtlDay)
- apiV1.POST("/lpplandtl/del/day", api.DelLpplandtlDay)
- apiV1.POST("/lpplandtl/add/day", api.AddLpplanDay)
- apiV1.POST("/lpplandtl/day", api.GetLpplandtlDay)
- apiV1.POST("/chart/feedEffMR", api.GetFeedEffMR)
- apiV1.POST("/chart/feedEffSL", api.GetFeedEffSL)
- apiV1.POST("/chart/feedEffHL", api.GetFeedEffHL)
- apiV1.POST("/chart/feedEffZH", api.GetFeedEffZH)
- apiV1.POST("/chart/feedEffCBFT", api.GetFeedEffCBFT)
- apiV1.POST("/chart/accuracyAllFT", api.GetAccuracyAllFT)
- apiV1.POST("/chart/accuracyAllJH", api.GetAccuracyAllJH)
- apiV1.POST("/chart/accuracyAllNQ", api.GetAccuracyAllNQ)
- apiV1.POST("/chart/accuracyAllCC", api.GetAccuracyAllCC)
- apiV1.POST("/chart/accuracyAllHL", api.GetAccuracyAllHL)
- apiV1.POST("/chart/accuracyAllLS", api.GetAccuracyAllLS)
- apiV1.POST("/chart/accuracyAllQX", api.GetAccuracyAllQX)
- apiV1.POST("/summary", api.GetSummary)
- apiV1.POST("/ftdetail/edit", api.UpdateFTdetail)
- apiV1.POST("/fpdetail/edit", api.UpdateFpdetailBar)
- apiV1.POST("/ftdetai/del", api.DeleteFTdetail)
- apiV1.POST("/lpplandtl/add", api.AddLpplandtl)
- apiV1.POST("/lpplandtl/edit/sort", api.UpdateLpplandtlSort)
- apiV1.POST("/lpplandtl/date/add", api.AddLpplandtlDate)
- apiV1.POST("/lpplandtl/edit/date/sort", api.UpdateLpplandtlDateSort)
- apiV1.POST("/processAnalysist", api.GetProcessAnalysis)
- apiV1.POST("/feedp/undistribute", api.GetFeedpUndistributed)
- apiV1.POST("/feedtemplet/enable", api.UpdateFeedtempletStatus)
- apiV1.POST("/ftdry/add", api.AddFtdry)
- apiV1.POST("/checkDates", api.CheckDates)
-
- apiV1.POST("/scheduled/status/edit", api.UpdateScheduledStatus)
-
- apiV1.POST("/synchronizeNow", api.SynchronizeNow)
- apiV1.POST("/fpdimportexcel", api.FpdImportExcel)
- apiV1.POST("/barfeedremain/excel", api.GetBarfeedremainExcel)
-
- apiV1.POST("/spillageall/del", api.DeleteSpillageAll)
- apiV1.POST("/feedp/history", api.GetFeedpHistory)
-
- apiV1.POST("/spillageall/history", api.GetSpillageallHistory)
-
- apiV1.POST("/tmrListEnableTypeAll", api.GetTMRListEnableTypeAll)
-
- apiV1.POST("/remind/list", api.GetRemind)
- apiV1.POST("/remind/edit", api.UpdateRemind)
-
- apiV1.POST("/recipetemplate/history", api.GetRecipeTemplateRecordHistory)
-
- apiV1.POST("/feedtemplet/history", api.GetFeedtempletHistory)
-
- apiV1.POST("/downloadedplan", api.GetDownloadedplanMaterial1)
- apiV1.POST("/downloadedplan/list", api.GetDownloadedplanMaterialList)
- apiV1.POST("/subplan", api.GetSubPlan)
- apiV1.POST("/completeplan", api.CompletePlan)
- apiV1.POST("/realtimeweight", api.AddRealTimeWeight)
-
- apiV1.POST("/materialtmr/edit", api.UpdateMaterialTMR)
- apiV1.POST("/materialtmr/date/edit", api.UpdateMaterialTMRDate)
-
- apiV1.POST("/formulaissued", api.AddFormulaIssued)
-
- apiV1.POST("/biginventory", api.AddBigInventory)
-
- apiV1.POST("/material/sap/upload", sap.MaterialOutbound)
- apiV1.POST("/downloadplandtl1/image/upload", api.UploadFile1)
- apiV1.POST("/syncSCJH", zc.SyncSCJH)
- }
-
- r.POST("/getopenid/:code", api.GetOpenID)
- apiV3 := r.Group("/thi")
- {
- apiV3.POST("/GetDataByName", api.GetDataByName)
- apiV3.POST("/PostDataByName", api.PostDataByName)
- }
- apiV4 := r.Group("/customreport")
- {
- apiV4.POST("/createchart", api.Createchart)
- apiV4.POST("/PostDataByName", api.PostDataByName)
- }
- return r
- }
- func Cors() gin.HandlerFunc {
- return func(c *gin.Context) {
- method := c.Request.Method
- origin := c.Request.Header.Get("Origin")
- var headerKeys []string
- for k, _ := range c.Request.Header {
- headerKeys = append(headerKeys, k)
- }
- headerStr := strings.Join(headerKeys, ", ")
- if headerStr != "" {
- headerStr = fmt.Sprintf("access-control-allow-origin, access-control-allow-headers, %s", headerStr)
- } else {
- headerStr = "access-control-allow-origin, access-control-allow-headers"
- }
- if origin != "" {
- c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
- c.Header("Access-Control-Allow-Origin", "*")
- c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
-
- c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, id, Token, name, optname, thumbnail, session, X_Requested_With, Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma")
-
- c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma, FooBar")
- c.Header("Access-Control-Max-Age", "172800")
- c.Header("Access-Control-Allow-Credentials", "false")
- c.Set("content-type", "application/json")
- }
-
- if method == "OPTIONS" {
- c.JSON(http.StatusOK, "Options Request!")
- }
-
- c.Next()
- }
- }
|