GoodsOrder.go 15 KB

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