GoodsOrder.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. package controllers
  2. import (
  3. "Cold_GoodsOrder/Nats/NatsServer"
  4. "Cold_GoodsOrder/conf"
  5. "Cold_GoodsOrder/lib"
  6. "Cold_GoodsOrder/models/Account"
  7. "Cold_GoodsOrder/models/Device"
  8. "Cold_GoodsOrder/models/Function"
  9. "fmt"
  10. beego "github.com/beego/beego/v2/server/web"
  11. "github.com/signintech/gopdf"
  12. "math"
  13. "os"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // Handle
  19. type GoodsOrderController struct {
  20. beego.Controller
  21. }
  22. func (c *GoodsOrderController) GoodsOrder_List() {
  23. type R_JSONS struct {
  24. //必须的大写开头
  25. Data []Function.GoodsOrderR
  26. Num int64
  27. Page int
  28. Page_size int
  29. }
  30. var r_jsons R_JSONS
  31. page, _ := c.GetInt("page")
  32. println(page)
  33. if page < 1 {
  34. page = 1
  35. }
  36. page_z, _ := c.GetInt("page_z")
  37. if page_z < 1 {
  38. page_z = conf.Page_size
  39. }
  40. T_pid := Account.User_r.T_pid
  41. if T_pid == 0 {
  42. T_pid, _ = c.GetInt("T_pid")
  43. }
  44. Name := c.GetString("T_name")
  45. c.Data["Name"] = Name
  46. r_jsons.Data, r_jsons.Num = Function.Read_GoodsOrder_List(T_pid, page, page_z, Name)
  47. r_jsons.Page = page
  48. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  49. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  50. c.ServeJSON()
  51. return
  52. }
  53. func (c *GoodsOrderController) GoodsOrder_Get() {
  54. id, _ := c.GetInt("T_id")
  55. T_pid := Account.User_r.T_pid
  56. if T_pid == 0 {
  57. T_pid, _ = c.GetInt("T_pid")
  58. }
  59. r := Function.Read_GoodsOrder_ById(id)
  60. if r.Id == 0 {
  61. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id !"}
  62. c.ServeJSON()
  63. return
  64. }
  65. if T_pid != r.T_pid {
  66. c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
  67. c.ServeJSON()
  68. return
  69. }
  70. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Function.GoodsOrderToGoodsOrderR(r)}
  71. c.ServeJSON()
  72. return
  73. }
  74. func (c *GoodsOrderController) GoodsOrder_Add() {
  75. T_orderid := c.GetString("T_orderid")
  76. T_outorderid := c.GetString("T_outorderid")
  77. T_sn := c.GetString("T_sn")
  78. T_receiving := c.GetString("T_receiving")
  79. T_time := c.GetString("T_time")
  80. T_text := c.GetString("T_text")
  81. T_start_Ut_T, _ := c.GetFloat("T_start_Ut_T")
  82. T_end_Ut_T, _ := c.GetFloat("T_end_Ut_T")
  83. T_time_s := strings.Split(T_time, "|")
  84. if len(T_time_s) != 2 {
  85. c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
  86. c.ServeJSON()
  87. return
  88. }
  89. T_pid := Account.User_r.T_pid
  90. if T_pid == 0 {
  91. T_pid, _ = c.GetInt("T_pid")
  92. }
  93. T_start_Ut_, err := time.ParseInLocation("2006-01-02 15:04:05", T_time_s[0], time.Local)
  94. T_end_Ut_, err := time.ParseInLocation("2006-01-02 15:04:05", T_time_s[1], time.Local)
  95. if err != nil {
  96. c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
  97. c.ServeJSON()
  98. return
  99. }
  100. var_ := Function.GoodsOrder{
  101. T_pid: T_pid,
  102. T_orderid: T_orderid,
  103. T_outorderid: T_outorderid,
  104. T_sn: T_sn,
  105. T_receiving: T_receiving,
  106. T_start_Ut: T_start_Ut_,
  107. T_end_Ut: T_end_Ut_,
  108. T_text: T_text,
  109. T_State: 1,
  110. T_start_Ut_T: float32(T_start_Ut_T),
  111. T_end_Ut_T: float32(T_end_Ut_T),
  112. }
  113. id, err := Function.Add_GoodsOrder(var_)
  114. if err != nil {
  115. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  116. c.ServeJSON()
  117. return
  118. }
  119. NatsServer.AddUserLogs(Account.User_r.T_uuid, "订单系统", "添加", var_)
  120. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
  121. c.ServeJSON()
  122. return
  123. }
  124. func (c *GoodsOrderController) GoodsOrder_Edit() {
  125. id, _ := c.GetInt("T_id")
  126. T_pid := Account.User_r.T_pid
  127. if T_pid == 0 {
  128. T_pid, _ = c.GetInt("T_pid")
  129. }
  130. r := Function.Read_GoodsOrder_ById(id)
  131. if r.Id == 0 {
  132. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id !"}
  133. c.ServeJSON()
  134. return
  135. }
  136. if T_pid != r.T_pid {
  137. c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
  138. c.ServeJSON()
  139. return
  140. }
  141. T_orderid := c.GetString("T_orderid")
  142. T_outorderid := c.GetString("T_outorderid")
  143. T_sn := c.GetString("T_sn")
  144. T_receiving := c.GetString("T_receiving")
  145. T_time := c.GetString("T_time")
  146. T_text := c.GetString("T_text")
  147. T_start_Ut_T, T_start_Ut_T_Err := c.GetFloat("T_start_Ut_T")
  148. T_end_Ut_T, T_end_Ut_T_Err := c.GetFloat("T_end_Ut_T")
  149. T_time_s := strings.Split(T_time, "|")
  150. if len(T_time_s) != 2 {
  151. c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
  152. c.ServeJSON()
  153. return
  154. }
  155. println("T_time_s:", T_time_s)
  156. T_start_Ut_, T_start_Ut_Err := time.ParseInLocation("2006-01-02 15:04:05", T_time_s[0], time.Local)
  157. T_end_Ut_, T_end_Ut_Err := time.ParseInLocation("2006-01-02 15:04:05", T_time_s[1], time.Local)
  158. if len(T_orderid) > 0 {
  159. r.T_orderid = T_orderid
  160. }
  161. if len(T_outorderid) > 0 {
  162. r.T_outorderid = T_outorderid
  163. }
  164. if len(T_sn) > 0 {
  165. r.T_sn = T_sn
  166. }
  167. if len(T_receiving) > 0 {
  168. r.T_receiving = T_receiving
  169. }
  170. if len(T_text) > 0 {
  171. r.T_text = T_text
  172. }
  173. if T_start_Ut_T_Err == nil {
  174. r.T_start_Ut_T = float32(T_start_Ut_T)
  175. }
  176. if T_end_Ut_T_Err == nil {
  177. r.T_end_Ut_T = float32(T_end_Ut_T)
  178. }
  179. if T_start_Ut_Err == nil {
  180. r.T_start_Ut = T_start_Ut_
  181. }
  182. if T_end_Ut_Err == nil {
  183. r.T_end_Ut = T_end_Ut_
  184. }
  185. is := Function.Update_GoodsOrder(r, "T_orderid", "T_outorderid", "T_sn", "T_receiving", "T_start_Ut", "T_end_Ut", "T_start_Ut_T", "T_end_Ut_T", "T_text")
  186. if !is {
  187. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  188. c.ServeJSON()
  189. return
  190. }
  191. NatsServer.AddUserLogs(Account.User_r.T_uuid, "订单系统", "修改", r)
  192. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  193. c.ServeJSON()
  194. return
  195. }
  196. func (c *GoodsOrderController) GoodsOrder_Del() {
  197. Id, _ := c.GetInt("T_id")
  198. T_pid := Account.User_r.T_pid
  199. if T_pid == 0 {
  200. T_pid, _ = c.GetInt("T_pid")
  201. }
  202. r := Function.Read_GoodsOrder_ById(Id)
  203. if r.Id == 0 {
  204. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  205. c.ServeJSON()
  206. return
  207. }
  208. if T_pid != r.T_pid {
  209. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  210. c.ServeJSON()
  211. return
  212. }
  213. if is := Function.Delete_GoodsOrder(r); !is {
  214. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  215. c.ServeJSON()
  216. return
  217. }
  218. NatsServer.AddUserLogs(Account.User_r.T_uuid, "订单系统", "删除", r)
  219. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  220. c.ServeJSON()
  221. return
  222. }
  223. // 列表 - 接口
  224. func (c *GoodsOrderController) GoodsOrder_PDF() {
  225. var err error
  226. Id, _ := c.GetInt("T_id")
  227. if Id == 0 {
  228. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id e!"}
  229. c.ServeJSON()
  230. return
  231. }
  232. GoodsOrder_r := Function.Read_GoodsOrder_ById(Id)
  233. if GoodsOrder_r.Id == 0 {
  234. c.Data["json"] = lib.JSONS{Code: 207, Msg: "Id e!"}
  235. c.ServeJSON()
  236. return
  237. }
  238. Device_r, err := NatsServer.ReadDeviceByT_sn(GoodsOrder_r.T_sn)
  239. if err != nil {
  240. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sn Err!"}
  241. c.ServeJSON()
  242. return
  243. }
  244. DeviceSensor_r := NatsServer.ReadDeviceSensorALLByT_sn(GoodsOrder_r.T_sn)
  245. if len(DeviceSensor_r) == 0 {
  246. c.Data["json"] = lib.JSONS{Code: 202, Msg: GoodsOrder_r.T_sn + "设备没有数据!"}
  247. c.ServeJSON()
  248. return
  249. }
  250. var DeviceSensor_data []Device.DeviceData_R
  251. DeviceSensor_data, _ = NatsServer.ReadDeviceDataListBy_T_snid(GoodsOrder_r.T_sn+","+strconv.Itoa(DeviceSensor_r[0].T_id), GoodsOrder_r.T_start_Ut.Format("2006-01-02 15:04:05"), GoodsOrder_r.T_end_Ut.Format("2006-01-02 15:04:05"), 0, 9999)
  252. pdf := &gopdf.GoPdf{}
  253. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
  254. //err = GetFont(pdf, "LiberationSerif-Regular.ttf")
  255. //if err != nil {
  256. // log.Fatalln(err)
  257. //}
  258. //err = pdf.SetFont("Ubuntu-L", "", 14)
  259. //if err != nil {
  260. // log.Fatalln(err)
  261. //}
  262. err = pdf.AddTTFFont("simsun", "static/fonts/三极行楷简体-粗.ttf")
  263. if err != nil {
  264. c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!", Data: err}
  265. c.ServeJSON()
  266. return
  267. }
  268. err = pdf.SetFont("simsun", "", 24)
  269. if err != nil {
  270. c.Data["json"] = lib.JSONS{Code: 205, Msg: "ok!", Data: err}
  271. c.ServeJSON()
  272. return
  273. }
  274. pdf.SetGrayFill(0.5)
  275. pdf.SetMargins(0, 20, 0, 20)
  276. pdf.AddPage()
  277. //use path
  278. //pdf.Image("logo.png", 100, 50, &gopdf.Rect{W: 50, H: 50})
  279. textw, _ := pdf.MeasureTextWidth(Account.User_r.T_name)
  280. pdf.SetX((595 / 2) - (textw / 2))
  281. pdf.SetY(40)
  282. pdf.Text(Account.User_r.T_name)
  283. // 线
  284. pdf.SetLineWidth(2)
  285. pdf.SetLineType("dashed")
  286. pdf.Line(10, 60, 585, 60)
  287. err = pdf.AddTTFFont("wts", "static/fonts/MiSans-Medium.ttf")
  288. if err != nil {
  289. c.Data["json"] = lib.JSONS{Code: 206, Msg: "ok!", Data: err}
  290. c.ServeJSON()
  291. return
  292. }
  293. err = pdf.SetFont("wts", "", 10)
  294. if err != nil {
  295. c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
  296. c.ServeJSON()
  297. return
  298. }
  299. //fmt.Sprintf(" %.1f ", v.T_t)
  300. //lib.RectFillColor(pdf, "历史数据["+Time_start+" / "+Time_end+"]", 14, 22, 80, 550, 40, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  301. // -------------
  302. x := 22.0
  303. w1 := 80.0
  304. w2 := 195.0
  305. lib.RectFillColor(pdf, "订单号:", 12, x, 80, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  306. x += w1
  307. lib.RectFillColor(pdf, GoodsOrder_r.T_orderid, 12, x, 80, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  308. x += w2
  309. lib.RectFillColor(pdf, "出库订单号:", 12, x, 80, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  310. x += w1
  311. lib.RectFillColor(pdf, GoodsOrder_r.T_outorderid, 12, x, 80, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  312. x += w2
  313. // -------------
  314. x = 22.0
  315. w1 = 80.0
  316. w2 = 195.0
  317. lib.RectFillColor(pdf, "设备名称:", 12, x, 100, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  318. x += w1
  319. lib.RectFillColor(pdf, Device_r.T_devName, 12, x, 100, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  320. x += w2
  321. lib.RectFillColor(pdf, "设备编号:", 12, x, 100, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  322. x += w1
  323. lib.RectFillColor(pdf, Device_r.T_sn, 12, x, 100, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  324. x += w2
  325. // -------------
  326. x = 22.0
  327. w1 = 80.0
  328. w2 = 240.0
  329. T_time := fmt.Sprintf("%s", GoodsOrder_r.T_start_Ut.Format("2006-01-02 15:04:05")+" - "+GoodsOrder_r.T_end_Ut.Format("2006-01-02 15:04:05"))
  330. lib.RectFillColor(pdf, "送货时间:", 12, x, 120, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  331. x += w1
  332. lib.RectFillColor(pdf, T_time, 12, x, 120, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  333. x += w2
  334. T_time = fmt.Sprintf("%s", GoodsOrder_r.CreateTime.Format("2006-01-02 15:04:05"))
  335. lib.RectFillColor(pdf, "订单时间:", 12, x, 120, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  336. x += w1
  337. lib.RectFillColor(pdf, T_time, 12, x, 120, 150, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  338. // -------------
  339. x = 22.0
  340. w1 = 80.0
  341. w2 = 195.0*2 + 80
  342. T_text := fmt.Sprintf("%s", GoodsOrder_r.T_receiving)
  343. lib.RectFillColor(pdf, "收货单位:", 12, x, 140, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  344. x += w1
  345. lib.RectFillColor(pdf, T_text, 12, x, 140, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  346. x += w2
  347. // -----------
  348. textw, _ = pdf.MeasureTextWidth("历史数据")
  349. pdf.SetX(20)
  350. pdf.SetY(210)
  351. pdf.Text("历史数据:")
  352. // 数据展示--------------------------------
  353. var y float64 = 220
  354. x = 22.0
  355. w1 = 94.0
  356. w2 = 43.0
  357. lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  358. x += w1
  359. lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  360. x += w2
  361. lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  362. x += w1
  363. lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  364. x += w2
  365. lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  366. x += w1
  367. lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  368. x += w2
  369. lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  370. x += w1
  371. lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  372. x += w2
  373. // 数据展示--------------------------------
  374. y = 240
  375. err = pdf.SetFont("wts", "", 8)
  376. if err != nil {
  377. c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
  378. c.ServeJSON()
  379. return
  380. }
  381. nln := 0
  382. x = 22.0
  383. var T_t_l float32 = 100.0
  384. var T_t_u float32 = 0.0
  385. var T_t_v float32 = 0.0
  386. for n := 0; len(DeviceSensor_data) > n; n++ {
  387. // -计算温度
  388. if DeviceSensor_data[n].T_t < T_t_l {
  389. T_t_l = DeviceSensor_data[n].T_t
  390. }
  391. if DeviceSensor_data[n].T_t > T_t_u {
  392. T_t_u = DeviceSensor_data[n].T_t
  393. }
  394. T_t_v += DeviceSensor_data[n].T_t
  395. //text := fmt.Sprintf(" %d ", i+1)
  396. var textH float64 = 25 // if text height is 25px.
  397. pdf.SetNewY(y, textH)
  398. y = pdf.GetY()
  399. nln++
  400. if nln > 4 {
  401. nln = 1
  402. x = 22.0
  403. y += 18
  404. }
  405. // ------------------
  406. T_t := fmt.Sprintf(" %.1f ", DeviceSensor_data[n].T_t)
  407. T_time = fmt.Sprintf("%s", DeviceSensor_data[n].T_time)
  408. lib.RectFillColor(pdf, T_time, 10, x, y, w1, 18, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  409. x += w1
  410. lib.RectFillColor(pdf, T_t, 10, x, y, w2, 18, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  411. x += w2
  412. }
  413. err = pdf.SetFont("wts", "", 10)
  414. if err != nil {
  415. c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
  416. c.ServeJSON()
  417. return
  418. }
  419. // 数据汇总--------------------------------
  420. y = 160
  421. x = 22.0
  422. w1 = 60.0
  423. w2 = 50.0
  424. T_t := fmt.Sprintf(" %.1f℃ ", DeviceSensor_data[len(DeviceSensor_data)-1].T_t)
  425. lib.RectFillColor(pdf, "起送温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  426. x += w1
  427. lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  428. x += w2
  429. T_t = fmt.Sprintf(" %.1f℃ ", DeviceSensor_data[0].T_t)
  430. lib.RectFillColor(pdf, "送达温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  431. x += w1
  432. lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  433. x += w2
  434. T_t = fmt.Sprintf(" %.1f℃ ", T_t_l)
  435. lib.RectFillColor(pdf, "最低温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  436. x += w1
  437. lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  438. x += w2
  439. T_t = fmt.Sprintf(" %.1f℃ ", float32(T_t_v/float32(len(DeviceSensor_data)-1)))
  440. lib.RectFillColor(pdf, "平均温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  441. x += w1
  442. lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  443. x += w2
  444. T_t = fmt.Sprintf(" %.1f℃ ", T_t_u)
  445. lib.RectFillColor(pdf, "最高温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  446. x += w1
  447. lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
  448. x += w2
  449. //----------------
  450. timeStr := "ofile/" + time.Now().Format("20060102150405") + ".pdf"
  451. err = pdf.WritePdf(timeStr)
  452. if err != nil {
  453. c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
  454. c.ServeJSON()
  455. return
  456. }
  457. // 上传 OSS
  458. url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/"+timeStr, timeStr)
  459. if !is {
  460. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  461. c.ServeJSON()
  462. return
  463. }
  464. //删除目录
  465. err = os.Remove(timeStr)
  466. if err != nil {
  467. fmt.Println(err)
  468. }
  469. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  470. c.ServeJSON()
  471. return
  472. }