router.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package routers
  2. import (
  3. "context"
  4. "fmt"
  5. "../comm"
  6. _ "../docs"
  7. "../middleware/jwt"
  8. "net/http"
  9. "strings"
  10. "../pkg/setting"
  11. "../routers/api"
  12. "../routers/api/sap"
  13. "../routers/api/zc"
  14. "github.com/gin-contrib/gzip"
  15. "github.com/gin-gonic/gin"
  16. ginSwagger "github.com/swaggo/gin-swagger"
  17. "github.com/swaggo/gin-swagger/swaggerFiles"
  18. )
  19. func InitRouter() *gin.Engine {
  20. r := gin.New()
  21. // api.InitMqttClient()
  22. go api.CronScheduled(context.TODO())
  23. // go sap.XdmySapSync()
  24. //正诚配方生产计划同步
  25. // go zc.SyncZC()
  26. r.Use(func(c *gin.Context) {
  27. fmt.Println(c.Request.URL)
  28. })
  29. r.Use(gzip.Gzip(gzip.DefaultCompression))
  30. // ginpprof.Wrap(r)
  31. r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
  32. // 你的自定义格式
  33. return fmt.Sprintf(" %+v \n",
  34. param.Keys,
  35. )
  36. }))
  37. r.Use(gin.Logger()) // 日志
  38. r.Use(Cors()) // 跨域请求rolemenus
  39. r.Use(gin.Recovery())
  40. gin.SetMode(setting.ServerSetting.RunMode)
  41. r.Static("/static", setting.CurrentPath+"/dist/static") // 添加资源路径
  42. r.StaticFile("/", setting.CurrentPath+"/dist/index.html") //前端接口
  43. r.StaticFile("/favicon.ico", setting.CurrentPath+"/dist/favicon.ico") //前端接口
  44. r.Static("/file", setting.CurrentPath+"/uploads/file")
  45. r.Static("/uploads", setting.CurrentPath+"/uploads")
  46. r.POST("/auth", api.Auth) // 获取登录token
  47. r.POST("/authlogin", api.AuthLogin) // 获取登录token
  48. r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // API 注释
  49. // r.GET("/sync", api.Sync)
  50. // r.GET("/UDFeedtempletinfo", api.UDFeedtempletinfo)
  51. // r.GET("/UDUploadadddata", api.UDUploadadddata)
  52. // r.GET("/UDUploaddiliverdata", api.UDUploaddiliverdata)
  53. // r.GET("/UDUploadoverplusdata", api.UDUploadoverplusdata)
  54. if setting.CommSetting.PortName != "" {
  55. r.GET("/comm/:id/:x/:y/", comm.ProcessHttp)
  56. r.GET("/cps/:id/:limit", comm.ProcessHttpCPS)
  57. r.POST("/comm/:id/:x/:y/", comm.ProcessHttp)
  58. r.POST("/cps/:id/:limit", comm.ProcessHttpCPS)
  59. }
  60. eqm := r.Group("/manage/api")
  61. eqm.POST("/login", api.Auth)
  62. eqm.POST("/login/imei", api.AuthImei)
  63. r.GET("/getData", api.GetWxCode)
  64. r.POST("/userwxopenid/binding", api.UserWXOpenIDBinding)
  65. apiV1 := r.Group("/authdata")
  66. apiV1.Use(jwt.JWT()) // token 验证
  67. {
  68. apiV1.POST("/rolemenus", api.GetRecuDataByName)
  69. apiV1.GET("/userinfo", api.GetUserinfo)
  70. apiV1.POST("/logout", api.UserLogout)
  71. apiV1.POST("/GetRecuDataByName", api.GetRecuDataByName) ////
  72. apiV1.POST("/GetDataByName", api.GetDataByName)
  73. apiV1.POST("/GetDataBySqlIN", api.GetDataBySqlIN)
  74. apiV1.POST("/GetDataByNames", api.GetDataByNames)
  75. apiV1.POST("/PostDataByName", api.PostDataByName)
  76. apiV1.POST("/PostDataByNames", api.PostDataByNames)
  77. apiV1.POST("/UpdateDataRelation", api.UpdateDataRelation) //log.error
  78. apiV1.POST("/GetDataByNameForm", api.GetDataByNameForm)
  79. apiV1.POST("/PostDataByNameForm", api.PostDataByNameForm)
  80. apiV1.POST("/GetUpkeepPlan", api.GetUpkeepPlan)
  81. apiV1.POST("/GetReportform", api.GetReportform)
  82. apiV1.POST("/GetArrList", api.GetArrList)
  83. apiV1.POST("/GETNurJudge", api.GETNurJudge)
  84. apiV1.POST("/GETNurJudgeRport", api.GETNurJudgeRport)
  85. apiV1.POST("/ExecDataByConfig", api.ExecDataByConfig)
  86. apiV1.POST("/ImportExcel", api.ImportExcel)
  87. apiV1.POST("/upload/:id/:name", api.UploadFile)
  88. apiV1.POST("/uploads", api.UploadFiles)
  89. apiV1.POST("/uploaderimage", api.UploaderImage)
  90. apiV1.POST("/uploaderTmrImage", api.UploaderTmrImage)
  91. apiV1.POST("/removeimage", api.RemovePicByName)
  92. apiV1.GET("/getthumbnailimage/:filename", api.GetThumbnailImage)
  93. apiV1.POST("/getoriginimage/:filename", api.GetOriginImage)
  94. apiV1.GET("/getfileraw/:filename", api.GetFileRaw)
  95. apiV1.GET("/downloadfile/:filename", api.DownloadFile)
  96. apiV1.POST("/removefile/:id", api.RemoveFileByName)
  97. apiV1.POST("/testdata", api.TestData)
  98. apiV1.POST("/Testpartitions", api.Testpartitions)
  99. //自定义报表
  100. apiV1.POST("/Createchart", api.Createchart)
  101. apiV1.POST("/Updatechart", api.Createchart)
  102. apiV1.POST("/exesql", api.ExecSQL)
  103. apiV1.POST("/Createdashboard", api.Updatedashboard)
  104. apiV1.POST("/Updatedashboard", api.Updatedashboard)
  105. apiV1.POST("/Dashboards", api.Dashboards)
  106. // 格润富德 API 数据获取
  107. apiV1.POST("/getDorm", api.GetDorm) // 牛舍信息
  108. apiV1.POST("/GetRJSBData", api.GetRJSBData)
  109. apiV1.POST("/PostRJSBData", api.PostRJSBData)
  110. apiV1.POST("/PostRJSBDatas", api.PostRJSBDatas)
  111. apiV1.POST("/autogeneration", api.Autogeneration)
  112. apiV1.POST("/spillage", api.GetSpillage)
  113. apiV1.POST("/trains", api.UpdateTrains)
  114. apiV1.POST("/lpplan/edit", api.UpdateLpplan)
  115. apiV1.POST("/lpplan/add", api.AddLpplan)
  116. apiV1.POST("/lpplandtl", api.GetLpplandtl)
  117. apiV1.POST("/lpplandtl/restore", api.RestoreLpplandtl)
  118. apiV1.POST("/lpplandtl/del", api.DelLpplandtl)
  119. apiV1.POST("/spillage/day", api.GetSpillageDay)
  120. apiV1.POST("/trains/day", api.UpdateTrainsDay)
  121. apiV1.POST("/lpplandtl/restore/day", api.RestoreLpplandtlDay)
  122. apiV1.POST("/lpplandtl/del/day", api.DelLpplandtlDay)
  123. apiV1.POST("/lpplandtl/add/day", api.AddLpplanDay)
  124. apiV1.POST("/lpplandtl/day", api.GetLpplandtlDay)
  125. apiV1.POST("/chart/feedEffMR", api.GetFeedEffMR)
  126. apiV1.POST("/chart/feedEffSL", api.GetFeedEffSL)
  127. apiV1.POST("/chart/feedEffHL", api.GetFeedEffHL)
  128. apiV1.POST("/chart/feedEffZH", api.GetFeedEffZH)
  129. apiV1.POST("/chart/feedEffCBFT", api.GetFeedEffCBFT)
  130. apiV1.POST("/chart/accuracyAllFT", api.GetAccuracyAllFT)
  131. apiV1.POST("/chart/accuracyAllJH", api.GetAccuracyAllJH)
  132. apiV1.POST("/chart/accuracyAllNQ", api.GetAccuracyAllNQ)
  133. apiV1.POST("/chart/accuracyAllCC", api.GetAccuracyAllCC)
  134. apiV1.POST("/chart/accuracyAllHL", api.GetAccuracyAllHL)
  135. apiV1.POST("/chart/accuracyAllLS", api.GetAccuracyAllLS)
  136. apiV1.POST("/chart/accuracyAllQX", api.GetAccuracyAllQX)
  137. apiV1.POST("/summary", api.GetSummary)
  138. apiV1.POST("/ftdetail/edit", api.UpdateFTdetail)
  139. apiV1.POST("/fpdetail/edit", api.UpdateFpdetailBar)
  140. apiV1.POST("/ftdetai/del", api.DeleteFTdetail)
  141. apiV1.POST("/lpplandtl/add", api.AddLpplandtl)
  142. apiV1.POST("/lpplandtl/edit/sort", api.UpdateLpplandtlSort)
  143. apiV1.POST("/lpplandtl/date/add", api.AddLpplandtlDate)
  144. apiV1.POST("/lpplandtl/edit/date/sort", api.UpdateLpplandtlDateSort)
  145. apiV1.POST("/processAnalysist", api.GetProcessAnalysis)
  146. apiV1.POST("/feedp/undistribute", api.GetFeedpUndistributed)
  147. apiV1.POST("/feedtemplet/enable", api.UpdateFeedtempletStatus)
  148. apiV1.POST("/ftdry/add", api.AddFtdry)
  149. apiV1.POST("/checkDates", api.CheckDates)
  150. //编辑数据同步勾选状态
  151. apiV1.POST("/scheduled/status/edit", api.UpdateScheduledStatus)
  152. // 立即同步
  153. apiV1.POST("/synchronizeNow", api.SynchronizeNow)
  154. apiV1.POST("/fpdimportexcel", api.FpdImportExcel)
  155. apiV1.POST("/barfeedremain/excel", api.GetBarfeedremainExcel)
  156. //删除当前班次撒料时记录
  157. apiV1.POST("/spillageall/del", api.DeleteSpillageAll)
  158. apiV1.POST("/feedp/history", api.GetFeedpHistory)
  159. //查看撒料修改记录
  160. apiV1.POST("/spillageall/history", api.GetSpillageallHistory)
  161. //查看撒料设备
  162. apiV1.POST("/tmrListEnableTypeAll", api.GetTMRListEnableTypeAll)
  163. //查看提醒设置
  164. apiV1.POST("/remind/list", api.GetRemind)
  165. apiV1.POST("/remind/edit", api.UpdateRemind)
  166. //配方模板修改记录
  167. apiV1.POST("/recipetemplate/history", api.GetRecipeTemplateRecordHistory)
  168. //配方模板修改记录
  169. apiV1.POST("/feedtemplet/history", api.GetFeedtempletHistory)
  170. //app取料接口
  171. apiV1.POST("/downloadedplan", api.GetDownloadedplanMaterial1)
  172. apiV1.POST("/downloadedplan/list", api.GetDownloadedplanMaterialList)
  173. apiV1.POST("/subplan", api.GetSubPlan)
  174. apiV1.POST("/completeplan", api.CompletePlan)
  175. apiV1.POST("/realtimeweight", api.AddRealTimeWeight)
  176. //修改撒料计划tmr编号
  177. apiV1.POST("/materialtmr/edit", api.UpdateMaterialTMR)
  178. apiV1.POST("/materialtmr/date/edit", api.UpdateMaterialTMRDate)
  179. //集团端配方下发
  180. apiV1.POST("/formulaissued", api.AddFormulaIssued)
  181. //盘点单添加
  182. apiV1.POST("/biginventory", api.AddBigInventory)
  183. //sap原料上传
  184. apiV1.POST("/material/sap/upload", sap.MaterialOutbound)
  185. apiV1.POST("/downloadplandtl1/image/upload", api.UploadFile1)
  186. apiV1.POST("/syncSCJH", zc.SyncSCJH)
  187. //修改日执行计划
  188. apiV1.POST("/dailydata/edit", api.UpdateDailyData)
  189. apiV1.POST("/formulastatistics", api.GetFormulaStatistics)
  190. apiV1.POST("/sap/feed", sap.SyncSapFeed)
  191. apiV1.POST("/sap/bar", sap.SyncSapBar)
  192. apiV1.POST("/sap/material", sap.MaterialOutbound)
  193. apiV1.POST("/feedbackup/check", api.CheckFeedTrgaddress)
  194. // apiV1.POST("/ud/feedp/sync", api.UdFeedpSync)
  195. }
  196. //不需要登录验证的接口
  197. r.POST("/getopenid/:code", api.GetOpenID)
  198. apiV3 := r.Group("/thi") // restful 接口 tablename 是 表名字
  199. {
  200. apiV3.POST("/GetDataByName", api.ThiGetDataByName)
  201. apiV3.POST("/PostDataByName", api.PostDataByName)
  202. // apiV3.POST("/getDorm", api.GetDorm) // 牛舍信息
  203. // RJSBData
  204. apiV3.POST("/plandata", api.GetPlanData)
  205. // PostRJSBData
  206. apiV3.POST("/plandata/edit", api.PostPlanData)
  207. // apiV3.POST("/PostRJSBDatas", api.PostRJSBDatas)
  208. }
  209. apiV4 := r.Group("/customreport") // restful 接口 tablename 是 表名字
  210. {
  211. apiV4.POST("/createchart", api.Createchart)
  212. apiV4.POST("/PostDataByName", api.PostDataByName)
  213. }
  214. return r
  215. }
  216. // 跨域
  217. func Cors() gin.HandlerFunc {
  218. return func(c *gin.Context) {
  219. method := c.Request.Method //请求方法
  220. origin := c.Request.Header.Get("Origin") //请求头部
  221. var headerKeys []string // 声明请求头keys
  222. for k, _ := range c.Request.Header {
  223. headerKeys = append(headerKeys, k)
  224. }
  225. headerStr := strings.Join(headerKeys, ", ")
  226. if headerStr != "" {
  227. headerStr = fmt.Sprintf("access-control-allow-origin, access-control-allow-headers, %s", headerStr)
  228. } else {
  229. headerStr = "access-control-allow-origin, access-control-allow-headers"
  230. }
  231. if origin != "" {
  232. c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
  233. c.Header("Access-Control-Allow-Origin", "*") // 这是允许访问所有域
  234. c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") //服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求
  235. // header的类型
  236. 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")
  237. // 允许跨域设置 可以返回其他子段
  238. 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") // 跨域关键设置 让浏览器可以解析
  239. c.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒
  240. c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true
  241. c.Set("content-type", "application/json") // 设置返回格式是json
  242. }
  243. //放行所有OPTIONS方法
  244. if method == "OPTIONS" {
  245. c.JSON(http.StatusOK, "Options Request!")
  246. }
  247. // 处理请求
  248. c.Next() // 处理请求
  249. }
  250. }