Task.go 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  1. package controllers
  2. import (
  3. "ColdVerify_server/Nats/NatsServer"
  4. "ColdVerify_server/conf"
  5. "ColdVerify_server/lib"
  6. "ColdVerify_server/logs"
  7. "ColdVerify_server/models/Account"
  8. "ColdVerify_server/models/Device"
  9. "ColdVerify_server/models/InfoCollection"
  10. "ColdVerify_server/models/System"
  11. "ColdVerify_server/models/Task"
  12. "ColdVerify_server/models/VerifyTemplate"
  13. "encoding/json"
  14. "errors"
  15. "fmt"
  16. beego "github.com/beego/beego/v2/server/web"
  17. "github.com/google/uuid"
  18. "github.com/xuri/excelize/v2"
  19. "gonum.org/v1/plot"
  20. "gonum.org/v1/plot/plotter"
  21. "gonum.org/v1/plot/vg"
  22. "gonum.org/v1/plot/vg/draw"
  23. "image/color"
  24. "math"
  25. "os"
  26. "os/exec"
  27. "strings"
  28. "sync"
  29. "time"
  30. )
  31. type TaskController struct {
  32. beego.Controller
  33. }
  34. // 列表 -
  35. func (c *TaskController) List() {
  36. // 验证登录 User_is, User_r
  37. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  38. if !User_is {
  39. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  40. c.ServeJSON()
  41. return
  42. }
  43. var r_jsons lib.R_JSONS
  44. page, _ := c.GetInt("page")
  45. if page < 1 {
  46. page = 1
  47. }
  48. page_z, _ := c.GetInt("page_z")
  49. if page_z < 1 {
  50. page_z = conf.Page_size
  51. }
  52. T_name := c.GetString("T_name")
  53. T_company := c.GetString("T_company") // 公司名称
  54. T_uuid := c.GetString("T_uuid")
  55. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  56. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  57. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  58. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  59. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  60. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  61. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  62. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  63. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  64. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  65. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  66. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  67. var T_company_list []string
  68. if len(T_company) > 0 {
  69. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  70. }
  71. var T_admin string
  72. if User_r.T_power > 2 {
  73. T_admin = User_r.T_uuid
  74. }
  75. var cnt int
  76. List, cnt := Task.Read_Task_List(T_uuid, T_admin, T_name, T_InfoCollection_id, T_scheme, T_collection, T_reporting, T_delivery,
  77. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  78. T_company_list, UserMap, AdminMap, page, page_z)
  79. page_size := math.Ceil(float64(cnt) / float64(page_z))
  80. r_jsons.List = List
  81. r_jsons.Page = page
  82. r_jsons.Page_size = int(page_size)
  83. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  84. r_jsons.Num = cnt
  85. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  86. c.ServeJSON()
  87. return
  88. }
  89. // 报告统计
  90. func (c *TaskController) Stat() {
  91. // 验证登录 User_is, User_r
  92. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  93. if !User_is {
  94. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  95. c.ServeJSON()
  96. return
  97. }
  98. var r_jsons lib.R_JSONS
  99. page, _ := c.GetInt("page")
  100. if page < 1 {
  101. page = 1
  102. }
  103. page_z, _ := c.GetInt("page_z")
  104. if page_z < 1 {
  105. page_z = conf.Page_size
  106. }
  107. T_name := c.GetString("T_name")
  108. T_company := c.GetString("T_company") // 公司名称
  109. T_uuid := c.GetString("T_uuid")
  110. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  111. T_project := c.GetString("T_project") // 项目 负责人UUID
  112. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  113. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  114. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  115. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  116. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  117. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  118. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  119. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  120. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  121. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  122. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  123. var T_company_list []string
  124. if len(T_company) > 0 {
  125. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  126. }
  127. var T_admin string
  128. if User_r.T_power > 2 {
  129. T_admin = User_r.T_uuid
  130. }
  131. var cnt int
  132. List, cnt := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
  133. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  134. T_company_list, UserMap, AdminMap, page, page_z)
  135. page_size := math.Ceil(float64(cnt) / float64(page_z))
  136. r_jsons.List = List
  137. r_jsons.Page = page
  138. r_jsons.Page_size = int(page_size)
  139. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  140. r_jsons.Num = cnt
  141. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  142. c.ServeJSON()
  143. return
  144. }
  145. // 报告统计 - 导出excel
  146. func (c *TaskController) Stat_Excel() {
  147. // 验证登录 User_is, User_r
  148. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  149. if !User_is {
  150. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  151. c.ServeJSON()
  152. return
  153. }
  154. T_name := c.GetString("T_name")
  155. T_company := c.GetString("T_company") // 公司名称
  156. T_uuid := c.GetString("T_uuid")
  157. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  158. T_project := c.GetString("T_project") // 项目 负责人UUID
  159. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  160. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  161. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  162. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  163. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  164. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  165. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  166. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  167. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  168. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  169. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  170. var T_company_list []string
  171. if len(T_company) > 0 {
  172. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  173. }
  174. var T_admin string
  175. if User_r.T_power > 2 {
  176. T_admin = User_r.T_uuid
  177. }
  178. List, _ := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
  179. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  180. T_company_list, UserMap, AdminMap, 0, 9999)
  181. f := excelize.NewFile() // 设置单元格的值
  182. line := 1
  183. // 这里设置表头
  184. f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("A%d", line+1))
  185. f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("B%d", line+1))
  186. f.MergeCell("Sheet1", fmt.Sprintf("C%d", line), fmt.Sprintf("C%d", line+1))
  187. f.MergeCell("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("D%d", line+1))
  188. f.MergeCell("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("E%d", line+1))
  189. f.MergeCell("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("F%d", line+1))
  190. f.MergeCell("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("G%d", line+1))
  191. f.MergeCell("Sheet1", fmt.Sprintf("H%d", line), fmt.Sprintf("H%d", line+1))
  192. f.MergeCell("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("I%d", line+1))
  193. f.MergeCell("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("J%d", line+1))
  194. f.MergeCell("Sheet1", fmt.Sprintf("K%d", line), fmt.Sprintf("K%d", line+1))
  195. f.MergeCell("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("L%d", line+1))
  196. f.MergeCell("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("M%d", line+1))
  197. f.MergeCell("Sheet1", fmt.Sprintf("N%d", line), fmt.Sprintf("N%d", line+1))
  198. f.MergeCell("Sheet1", fmt.Sprintf("O%d", line), fmt.Sprintf("O%d", line+1))
  199. f.MergeCell("Sheet1", fmt.Sprintf("P%d", line), fmt.Sprintf("P%d", line+1))
  200. f.MergeCell("Sheet1", fmt.Sprintf("Q%d", line), fmt.Sprintf("U%d", line))
  201. f.MergeCell("Sheet1", fmt.Sprintf("V%d", line), fmt.Sprintf("AA%d", line))
  202. f.MergeCell("Sheet1", fmt.Sprintf("AB%d", line), fmt.Sprintf("AG%d", line))
  203. f.MergeCell("Sheet1", fmt.Sprintf("AH%d", line), fmt.Sprintf("AM%d", line))
  204. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), "信息表")
  205. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), "方案")
  206. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), "实施")
  207. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), "报告")
  208. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "序号")
  209. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "公司名称")
  210. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), "报告名称")
  211. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), "项目负责人")
  212. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), "地区")
  213. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), "类别")
  214. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), "设备类型")
  215. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), "规格/容积")
  216. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), "验证类型")
  217. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), "标的物名称")
  218. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "验证温度范围")
  219. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), "报告编号")
  220. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), "项目开始时间")
  221. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), "项目用时")
  222. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), "驳回次数")
  223. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), "回款")
  224. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line+1), "编写人")
  225. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line+1), "状态")
  226. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line+1), "开始时间")
  227. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line+1), "退回次数")
  228. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line+1), "所需时间")
  229. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line+1), "编写人")
  230. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line+1), "状态")
  231. f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line+1), "开始时间")
  232. f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line+1), "退回次数")
  233. f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line+1), "所需时间")
  234. f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line+1), "超时时间")
  235. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line+1), "编写人")
  236. f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line+1), "状态")
  237. f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line+1), "开始时间")
  238. f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line+1), "退回次数")
  239. f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line+1), "所需时间")
  240. f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line+1), "超时时间")
  241. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line+1), "编写人")
  242. f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line+1), "状态")
  243. f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line+1), "开始时间")
  244. f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line+1), "退回次数")
  245. f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line+1), "所需时间")
  246. f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line+1), "超时时间")
  247. // 设置列宽
  248. f.SetColWidth("Sheet1", "A", "A", 7)
  249. f.SetColWidth("Sheet1", "B", "B", 20)
  250. f.SetColWidth("Sheet1", "C", "C", 10)
  251. f.SetColWidth("Sheet1", "D", "D", 10)
  252. f.SetColWidth("Sheet1", "E", "E", 12)
  253. f.SetColWidth("Sheet1", "F", "F", 8)
  254. f.SetColWidth("Sheet1", "G", "G", 12)
  255. f.SetColWidth("Sheet1", "H", "H", 14)
  256. f.SetColWidth("Sheet1", "I", "I", 12)
  257. f.SetColWidth("Sheet1", "J", "J", 12)
  258. f.SetColWidth("Sheet1", "K", "K", 12)
  259. f.SetColWidth("Sheet1", "L", "L", 12)
  260. f.SetColWidth("Sheet1", "M", "M", 12)
  261. f.SetColWidth("Sheet1", "N", "N", 12)
  262. f.SetColWidth("Sheet1", "O", "O", 10)
  263. f.SetColWidth("Sheet1", "P", "P", 8)
  264. f.SetColWidth("Sheet1", "Q", "Q", 8)
  265. f.SetColWidth("Sheet1", "R", "R", 8)
  266. f.SetColWidth("Sheet1", "S", "S", 12)
  267. f.SetColWidth("Sheet1", "T", "T", 10)
  268. f.SetColWidth("Sheet1", "U", "U", 10)
  269. f.SetColWidth("Sheet1", "V", "V", 8)
  270. f.SetColWidth("Sheet1", "W", "W", 8)
  271. f.SetColWidth("Sheet1", "X", "X", 12)
  272. f.SetColWidth("Sheet1", "Y", "Y", 10)
  273. f.SetColWidth("Sheet1", "Z", "Z", 12)
  274. f.SetColWidth("Sheet1", "AA", "AA", 12)
  275. f.SetColWidth("Sheet1", "AB", "AB", 8)
  276. f.SetColWidth("Sheet1", "AC", "AC", 8)
  277. f.SetColWidth("Sheet1", "AD", "AD", 12)
  278. f.SetColWidth("Sheet1", "AE", "AE", 10)
  279. f.SetColWidth("Sheet1", "AF", "AF", 12)
  280. f.SetColWidth("Sheet1", "AG", "AG", 12)
  281. f.SetColWidth("Sheet1", "AG", "AG", 10)
  282. f.SetColWidth("Sheet1", "AH", "AH", 8)
  283. f.SetColWidth("Sheet1", "AI", "AI", 8)
  284. f.SetColWidth("Sheet1", "AJ", "AJ", 10)
  285. f.SetColWidth("Sheet1", "AK", "AK", 12)
  286. f.SetColWidth("Sheet1", "AL", "AL", 12)
  287. f.SetColWidth("Sheet1", "AM", "AM", 12)
  288. Style1, _ := f.NewStyle(
  289. &excelize.Style{
  290. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  291. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  292. Border: []excelize.Border{
  293. {Type: "left", Color: "000000", Style: 1},
  294. {Type: "top", Color: "000000", Style: 1},
  295. {Type: "bottom", Color: "000000", Style: 1},
  296. {Type: "right", Color: "000000", Style: 1},
  297. },
  298. })
  299. f.SetCellStyle("Sheet1", "A1", "AM2", Style1)
  300. f.SetRowHeight("Sheet1", 1, 25)
  301. f.SetRowHeight("Sheet1", 2, 25)
  302. line += 1
  303. // 循环写入数据
  304. for i, v := range List {
  305. line++
  306. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  307. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_user_name)
  308. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name)
  309. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_project_name)
  310. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("%s-%s-%s", v.T_province, v.T_city, v.T_district))
  311. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_category)
  312. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_device_type)
  313. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_volume)
  314. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_verify_type)
  315. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_subject_matter)
  316. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.T_temp_range)
  317. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("%s-%s", v.T_report_type, v.T_report_number))
  318. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v.T_start_time)
  319. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), v.T_time_interval)
  320. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v.T_reject_times)
  321. returnedMoney := "否"
  322. if v.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney {
  323. returnedMoney = "是"
  324. }
  325. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), returnedMoney)
  326. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), v.InfoCollection.T_submit_uuid_name)
  327. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), InfoCollection.InfoCollectionStatusMap[v.InfoCollection.T_State])
  328. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), v.InfoCollection.T_start_time)
  329. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), v.InfoCollection.T_return_times)
  330. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), v.InfoCollection.T_time_interval)
  331. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), v.T_scheme_name)
  332. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line), Task.TaskSchemeStateMap[v.T_scheme_state])
  333. f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line), v.T_scheme_start_time)
  334. f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line), v.T_scheme_return_times)
  335. f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line), v.T_scheme_time_interval)
  336. f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line), v.T_scheme_overtime)
  337. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), v.T_collection_name)
  338. f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line), Task.TaskCollectionStateMap[v.T_collection_state])
  339. f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line), v.T_collection_start_time)
  340. f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line), v.T_collection_return_times)
  341. f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line), v.T_collection_time_interval)
  342. f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line), v.T_collection_overtime)
  343. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), v.T_reporting_name)
  344. f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line), Task.TaskReportingStateMap[v.T_reporting_state])
  345. f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line), v.T_reporting_start_time)
  346. f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line), v.T_reporting_return_times)
  347. f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line), v.T_reporting_time_interval)
  348. f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line), v.T_reporting_overtime)
  349. }
  350. Style2, _ := f.NewStyle(
  351. &excelize.Style{
  352. Font: &excelize.Font{Size: 10, Family: "宋体"},
  353. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  354. Border: []excelize.Border{
  355. {Type: "left", Color: "000000", Style: 1},
  356. {Type: "top", Color: "000000", Style: 1},
  357. {Type: "bottom", Color: "000000", Style: 1},
  358. {Type: "right", Color: "000000", Style: 1},
  359. },
  360. })
  361. f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("AM%d", line), Style2)
  362. StyleBlueFill, _ := f.NewStyle(
  363. &excelize.Style{
  364. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  365. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  366. Border: []excelize.Border{
  367. {Type: "left", Color: "000000", Style: 1},
  368. {Type: "top", Color: "000000", Style: 1},
  369. {Type: "bottom", Color: "000000", Style: 1},
  370. {Type: "right", Color: "000000", Style: 1},
  371. },
  372. Fill: excelize.Fill{Type: "pattern", Color: []string{"#DEE5F5"}, Pattern: 1},
  373. })
  374. // 粉色填充
  375. StylePinkFill, _ := f.NewStyle(
  376. &excelize.Style{
  377. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  378. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  379. Border: []excelize.Border{
  380. {Type: "left", Color: "000000", Style: 1},
  381. {Type: "top", Color: "000000", Style: 1},
  382. {Type: "bottom", Color: "000000", Style: 1},
  383. {Type: "right", Color: "000000", Style: 1},
  384. },
  385. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FBDFE2"}, Pattern: 1},
  386. })
  387. StyleOrangeFill, _ := f.NewStyle(
  388. &excelize.Style{
  389. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  390. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  391. Border: []excelize.Border{
  392. {Type: "left", Color: "000000", Style: 1},
  393. {Type: "top", Color: "000000", Style: 1},
  394. {Type: "bottom", Color: "000000", Style: 1},
  395. {Type: "right", Color: "000000", Style: 1},
  396. },
  397. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FCE7D8"}, Pattern: 1},
  398. })
  399. StyleYellowFill, _ := f.NewStyle(
  400. &excelize.Style{
  401. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  402. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  403. Border: []excelize.Border{
  404. {Type: "left", Color: "000000", Style: 1},
  405. {Type: "top", Color: "000000", Style: 1},
  406. {Type: "bottom", Color: "000000", Style: 1},
  407. {Type: "right", Color: "000000", Style: 1},
  408. },
  409. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFF5D0"}, Pattern: 1},
  410. })
  411. StyleGreenFill, _ := f.NewStyle(
  412. &excelize.Style{
  413. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  414. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  415. Border: []excelize.Border{
  416. {Type: "left", Color: "000000", Style: 1},
  417. {Type: "top", Color: "000000", Style: 1},
  418. {Type: "bottom", Color: "000000", Style: 1},
  419. {Type: "right", Color: "000000", Style: 1},
  420. },
  421. Fill: excelize.Fill{Type: "pattern", Color: []string{"#E7F4DE"}, Pattern: 1},
  422. })
  423. f.SetCellStyle("Sheet1", "A1", "AM2", StyleBlueFill)
  424. f.SetCellStyle("Sheet1", "Q1", "U1", StylePinkFill)
  425. f.SetCellStyle("Sheet1", "V1", "AA1", StyleOrangeFill)
  426. f.SetCellStyle("Sheet1", "AB1", "AG1", StyleYellowFill)
  427. f.SetCellStyle("Sheet1", "AH1", "AM1", StyleGreenFill)
  428. // 冻结1-2行
  429. f.SetPanes("Sheet1", &excelize.Panes{
  430. Freeze: true,
  431. Split: false,
  432. XSplit: 3,
  433. YSplit: 2,
  434. TopLeftCell: "A1",
  435. ActivePane: "topRight",
  436. })
  437. lib.Create_Dir("./ofile")
  438. timeStr := time.Now().Format("20060102150405")
  439. // 保存文件
  440. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  441. logs.Error(lib.FuncName(), err)
  442. }
  443. if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx") {
  444. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  445. c.ServeJSON()
  446. return
  447. }
  448. //删除目录
  449. err := os.Remove("ofile/" + timeStr + ".xlsx")
  450. if err != nil {
  451. logs.Error(lib.FuncName(), err)
  452. }
  453. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + timeStr + ".xlsx"}
  454. c.ServeJSON()
  455. return
  456. }
  457. // 获取任务负责人列表
  458. func (c *TaskController) GetTaskUserList() {
  459. // 验证登录 User_is, User_r
  460. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  461. if !User_is {
  462. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  463. c.ServeJSON()
  464. return
  465. }
  466. T_type := c.GetString("T_type") // T_project项目 T_scheme方案 T_collection数据采集 T_reporting报告
  467. list := Task.Get_Task_UserList(T_type)
  468. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  469. var User_list []Account.Admin_R
  470. for _, v := range list {
  471. if len(v) == 0 {
  472. continue
  473. }
  474. User_list = append(User_list, Account.Admin_R{T_uuid: v, T_name: AdminMap[v]})
  475. }
  476. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_list}
  477. c.ServeJSON()
  478. return
  479. }
  480. // 列表 -
  481. func (c *TaskController) UserTaskList() {
  482. // 验证登录 User_is, User_r
  483. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  484. if !User_is {
  485. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  486. c.ServeJSON()
  487. return
  488. }
  489. var r_jsons lib.R_JSONS
  490. page, _ := c.GetInt("page")
  491. if page < 1 {
  492. page = 1
  493. }
  494. page_z, _ := c.GetInt("page_z")
  495. if page_z < 1 {
  496. page_z = conf.Page_size
  497. }
  498. T_name := c.GetString("T_name")
  499. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  500. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  501. var cnt int
  502. List, cnt := Task.Read_UserTask_List(User_r.T_uuid, T_name, UserMap, AdminMap, page, page_z)
  503. page_size := math.Ceil(float64(cnt) / float64(page_z))
  504. r_jsons.List = List
  505. r_jsons.Page = page
  506. r_jsons.Page_size = int(page_size)
  507. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  508. r_jsons.Num = cnt
  509. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  510. c.ServeJSON()
  511. return
  512. }
  513. // 获取-
  514. func (c *TaskController) Get() {
  515. // 验证登录 User_is, User_r
  516. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  517. if !User_is {
  518. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  519. c.ServeJSON()
  520. return
  521. }
  522. T_task_id := c.GetString("T_task_id")
  523. r, is := Task.Read_Task(T_task_id)
  524. if !is {
  525. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  526. c.ServeJSON()
  527. return
  528. }
  529. // 添加浏览量
  530. _ = Task.Add_Task_Visit(r)
  531. r.T_Visit += 1
  532. userMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  533. adminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  534. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Task.TaskToTask_Stat(r, userMap, adminMap)}
  535. c.ServeJSON()
  536. return
  537. }
  538. // 添加-
  539. func (c *TaskController) Add() {
  540. // 验证登录 User_is, User_r
  541. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  542. if !User_is {
  543. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  544. c.ServeJSON()
  545. return
  546. }
  547. dc := Device.DeviceClass{
  548. T_uuid: User_r.T_uuid,
  549. T_State: 1,
  550. }
  551. T_class_id, is := Device.Add_DeviceClass(dc)
  552. if !is {
  553. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  554. c.ServeJSON()
  555. return
  556. }
  557. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
  558. T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
  559. T_name := c.GetString("T_name")
  560. T_uuid := c.GetString("T_uuid") // 用户uuid
  561. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  562. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  563. T_deadline := c.GetString("T_deadline")
  564. T_scheme := c.GetString("T_scheme")
  565. T_collection := c.GetString("T_collection")
  566. T_reporting := c.GetString("T_reporting")
  567. T_delivery := c.GetString("T_delivery")
  568. T_project := c.GetString("T_project") // 项目 负责人UUID
  569. T_province := c.GetString("T_province") // 省
  570. T_city := c.GetString("T_city") // 市
  571. T_district := c.GetString("T_district") // 区
  572. T_province_code := c.GetString("T_province_code") // 省 code
  573. T_city_code := c.GetString("T_city_code") // 市 code
  574. T_district_code := c.GetString("T_district_code") // 区 code
  575. T_category := c.GetString("T_category") // 类别
  576. T_device_type := c.GetString("T_device_type") // 设备类型
  577. T_volume := c.GetString("T_volume") // 规格/容积
  578. T_verify_type := c.GetString("T_verify_type") // 验证类型
  579. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  580. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  581. T_report_number := c.GetString("T_report_number") // 报告编号
  582. T_report_type := c.GetString("T_report_type") // 报告类型
  583. // 查询信息采集信息
  584. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  585. if !is {
  586. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  587. c.ServeJSON()
  588. return
  589. }
  590. var_ := Task.Task{
  591. T_InfoCollection_id: T_InfoCollection_id,
  592. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  593. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  594. T_class: int(T_class_id),
  595. T_uuid: T_uuid,
  596. T_name: T_name,
  597. T_VerifyTemplate_class: T_VerifyTemplate_class,
  598. T_VerifyTemplate_id: T_VerifyTemplate_id,
  599. T_deadline: T_deadline,
  600. T_scheme: T_scheme,
  601. T_collection: T_collection,
  602. T_reporting: T_reporting,
  603. T_delivery: T_delivery,
  604. T_Show: 1,
  605. T_State: 1,
  606. T_project: T_project,
  607. T_province: T_province,
  608. T_city: T_city,
  609. T_district: T_district,
  610. T_province_code: T_province_code,
  611. T_city_code: T_city_code,
  612. T_district_code: T_district_code,
  613. T_category: T_category,
  614. T_device_type: T_device_type,
  615. T_volume: T_volume,
  616. T_verify_type: T_verify_type,
  617. T_subject_matter: T_subject_matter,
  618. T_temp_range: T_temp_range,
  619. T_report_number: T_report_number,
  620. T_report_type: T_report_type,
  621. }
  622. T_task_id, is := Task.Add_Task(var_)
  623. if !is {
  624. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  625. c.ServeJSON()
  626. return
  627. }
  628. NatsServer.Create_Local_Table(T_task_id)
  629. // 添加任务操作日志
  630. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "添加", var_)
  631. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "添加", var_)
  632. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  633. c.ServeJSON()
  634. return
  635. }
  636. // 接收信息采集
  637. func (c *TaskController) ReceiptInfoCollection() {
  638. // 验证登录 User_is, User_r
  639. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  640. if !User_is {
  641. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  642. c.ServeJSON()
  643. return
  644. }
  645. // 修改信息采集状态为已接收
  646. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  647. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  648. if !is {
  649. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  650. c.ServeJSON()
  651. return
  652. }
  653. if infoCollection.T_status != InfoCollection.InfoCollectionStatusSubmitted && infoCollection.T_status != InfoCollection.InfoCollectionStatusReceipt {
  654. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止接收!", InfoCollection.InfoCollectionStatusMap[infoCollection.T_status])}
  655. c.ServeJSON()
  656. return
  657. }
  658. infoCollection.T_status = InfoCollection.InfoCollectionStatusReceipt
  659. if len(infoCollection.T_end_time) == 0 {
  660. infoCollection.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  661. infoCollection.T_time_interval, _ = lib.MinutesDifference(infoCollection.T_start_time, infoCollection.T_end_time)
  662. }
  663. if !InfoCollection.Update_InfoCollection(infoCollection, "T_status", "T_end_time", "T_time_interval") {
  664. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  665. c.ServeJSON()
  666. return
  667. }
  668. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "接收信息采集", infoCollection)
  669. // 修改任务管理实施方案开始时间
  670. T_task_id := c.GetString("T_task_id")
  671. task, is := Task.Read_Task(T_task_id)
  672. if !is {
  673. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  674. c.ServeJSON()
  675. return
  676. }
  677. task.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
  678. if !Task.Update_Task(task, "T_scheme_start_time") {
  679. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  680. c.ServeJSON()
  681. return
  682. }
  683. // 添加任务操作日志
  684. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "接收信息采集", task)
  685. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "接收信息采集", task)
  686. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  687. c.ServeJSON()
  688. return
  689. }
  690. // 添加-
  691. func (c *TaskController) AddData_Tool() {
  692. T_uuid := "3e84dda9-9eec-42b9-9350-0894262fc8a1" // 用户uuid
  693. T_name := c.GetString("T_name")
  694. T_task_id := c.GetString("T_task_id")
  695. T_task_id = strings.ToLower(T_task_id)
  696. r, _ := Task.Read_Task(T_task_id)
  697. if r.T_collection_state == 2 {
  698. c.Data["json"] = lib.JSONS{Code: 200, Msg: "数据采集中..."}
  699. c.ServeJSON()
  700. return
  701. }
  702. if r.Id > 0 {
  703. // 同步1.0数据
  704. NatsServer.Sync1_TaskData(T_task_id)
  705. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  706. c.ServeJSON()
  707. return
  708. }
  709. dc := Device.DeviceClass{
  710. T_uuid: T_uuid,
  711. T_State: 1,
  712. }
  713. T_class_id, is := Device.Add_DeviceClass(dc)
  714. if !is {
  715. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  716. c.ServeJSON()
  717. return
  718. }
  719. var_ := Task.Task{
  720. T_task_id: T_task_id,
  721. T_class: int(T_class_id),
  722. T_uuid: T_uuid,
  723. T_name: T_name,
  724. T_Show: 1,
  725. T_State: 1,
  726. T_collection_state: 2,
  727. }
  728. _, is = Task.Add_Task_Tool(var_)
  729. if !is {
  730. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  731. c.ServeJSON()
  732. return
  733. }
  734. // 创建本地表
  735. NatsServer.Create_Local_Table(T_task_id)
  736. // 同步1.0数据
  737. NatsServer.Sync1_TaskData(T_task_id)
  738. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  739. c.ServeJSON()
  740. return
  741. }
  742. // 修改采集状态-
  743. func (c *TaskController) UpCollectionState() {
  744. // 验证登录 User_is, User_r
  745. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  746. if !User_is {
  747. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  748. c.ServeJSON()
  749. return
  750. }
  751. T_collection_state, _ := c.GetInt("T_collection_state")
  752. T_reason := c.GetString("T_reason") // 退回原因
  753. T_task_id := c.GetString("T_task_id")
  754. r, is := Task.Read_Task(T_task_id)
  755. if !is {
  756. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  757. c.ServeJSON()
  758. return
  759. }
  760. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  761. r.T_collection_state = T_collection_state
  762. clos := make([]string, 0)
  763. clos = append(clos, "T_collection_state")
  764. if T_collection_state == Task.TaskCollectionStateReturn {
  765. r.T_collection_return_times += 1
  766. clos = append(clos, "T_collection_return_times")
  767. }
  768. if T_collection_state == Task.TaskCollectionStateSubmitted ||
  769. T_collection_state == Task.TaskCollectionStateReturn ||
  770. T_collection_state == Task.TaskCollectionStatePass {
  771. // 添加已提交状态验证报告记录
  772. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, T_collection_state, T_reason, "")
  773. if err != nil {
  774. return
  775. }
  776. r.T_collection_audit_record = auditRecordJson
  777. clos = append(clos, "T_collection_audit_record")
  778. }
  779. if T_collection_state == Task.TaskCollectionStatePass {
  780. // 数据编辑审核通过时间为验证报告开始时间
  781. r.T_reporting_start_time = time.Now().Format("2006-01-02 15:04:05")
  782. clos = append(clos, "T_reporting_start_time")
  783. }
  784. if !Task.Update_Task(r, clos...) {
  785. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  786. c.ServeJSON()
  787. return
  788. }
  789. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  790. if T_collection_state == Task.TaskCollectionStateReturn ||
  791. T_collection_state == Task.TaskCollectionStatePass {
  792. System.Add_News(r.T_collection, fmt.Sprintf("【数据编辑】您提交的数据编辑【%s-%s】审核%s", company_r.T_name, r.T_name, Task.TaskCollectionStateMap[T_collection_state]), "")
  793. System.Send_Weichat_News(AdminMap[r.T_collection], fmt.Sprintf("【数据编辑】您提交的数据编辑【%s-%s】审核%s", company_r.T_name, r.T_name, Task.TaskCollectionStateMap[T_collection_state]), "")
  794. }
  795. // 添加任务操作日志
  796. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改采集状态", r)
  797. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改采集状态", r)
  798. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  799. c.ServeJSON()
  800. return
  801. }
  802. func (c *TaskController) UpDeliveryState() {
  803. // 验证登录 User_is, User_r
  804. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  805. if !User_is {
  806. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  807. c.ServeJSON()
  808. return
  809. }
  810. T_delivery_state, _ := c.GetInt("T_delivery_state")
  811. T_task_id := c.GetString("T_task_id")
  812. r, is := Task.Read_Task(T_task_id)
  813. if !is {
  814. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  815. c.ServeJSON()
  816. return
  817. }
  818. r.T_delivery_state = T_delivery_state
  819. if !Task.Update_Task(r, "T_delivery_state") {
  820. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  821. c.ServeJSON()
  822. return
  823. }
  824. // 添加任务操作日志
  825. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改交付审核状态", r)
  826. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改交付审核状态", r)
  827. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  828. c.ServeJSON()
  829. return
  830. }
  831. // 修改-
  832. func (c *TaskController) Up() {
  833. // 验证登录 User_is, User_r
  834. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  835. if !User_is {
  836. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  837. c.ServeJSON()
  838. return
  839. }
  840. T_name := c.GetString("T_name")
  841. T_Show, T_Show_err := c.GetInt("T_Show")
  842. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  843. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  844. T_deadline := c.GetString("T_deadline")
  845. T_scheme := c.GetString("T_scheme")
  846. T_collection := c.GetString("T_collection")
  847. T_collection_state, _ := c.GetInt("T_collection_state")
  848. T_collection_signature := c.GetString("T_collection_signature") // 完成编辑签字图片
  849. T_reporting := c.GetString("T_reporting")
  850. T_delivery := c.GetString("T_delivery")
  851. T_doc1 := c.GetString("T_doc1")
  852. T_pdf1 := c.GetString("T_pdf1")
  853. T_doc2 := c.GetString("T_doc2")
  854. T_pdf2 := c.GetString("T_pdf2")
  855. T_doc3 := c.GetString("T_doc3")
  856. T_pdf3 := c.GetString("T_pdf3")
  857. T_pdf4 := c.GetString("T_pdf4") // 验证标识
  858. T_VerifyDeviceDataStartTime := c.GetString("T_VerifyDeviceDataStartTime") // 验证设备数据开始时间
  859. T_VerifyDeviceDataEndTime := c.GetString("T_VerifyDeviceDataEndTime") // 验证设备数据开始时间
  860. T_BindDeviceDataStartTime := c.GetString("T_BindDeviceDataStartTime") // 绑定设备数据开始时间
  861. T_BindDeviceDataEndTime := c.GetString("T_BindDeviceDataEndTime") // 绑定设备数据结束时间
  862. T_sn := c.GetString("T_sn") // T_sn
  863. T_CalibrationExpirationTime := c.GetString("T_CalibrationExpirationTime") // 校准到期时间
  864. T_project := c.GetString("T_project") // 项目 负责人UUID
  865. T_province := c.GetString("T_province") // 省
  866. T_city := c.GetString("T_city") // 市
  867. T_district := c.GetString("T_district") // 区
  868. T_province_code := c.GetString("T_province_code") // 省 code
  869. T_city_code := c.GetString("T_city_code") // 市 code
  870. T_district_code := c.GetString("T_district_code") // 区 code
  871. T_category := c.GetString("T_category") // 类别
  872. T_device_type := c.GetString("T_device_type") // 设备类型
  873. T_volume := c.GetString("T_volume") // 规格/容积
  874. T_verify_type := c.GetString("T_verify_type") // 验证类型
  875. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  876. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  877. T_report_number := c.GetString("T_report_number") // 报告编号
  878. T_task_id := c.GetString("T_task_id")
  879. r, is := Task.Read_Task(T_task_id)
  880. if !is {
  881. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  882. c.ServeJSON()
  883. return
  884. }
  885. // .......
  886. clos := make([]string, 0)
  887. if len(T_name) > 0 {
  888. r.T_name = T_name
  889. clos = append(clos, "T_name")
  890. }
  891. if T_Show_err == nil {
  892. r.T_Show = T_Show
  893. clos = append(clos, "T_Show")
  894. }
  895. if len(T_VerifyTemplate_class) > 0 {
  896. r.T_VerifyTemplate_class = T_VerifyTemplate_class
  897. clos = append(clos, "T_VerifyTemplate_class")
  898. }
  899. if len(T_VerifyTemplate_id) > 0 {
  900. r.T_VerifyTemplate_id = T_VerifyTemplate_id
  901. clos = append(clos, "T_VerifyTemplate_id")
  902. }
  903. if len(T_deadline) > 0 {
  904. r.T_deadline = T_deadline
  905. clos = append(clos, "T_deadline")
  906. }
  907. if len(T_scheme) > 0 {
  908. r.T_scheme = T_scheme
  909. clos = append(clos, "T_scheme")
  910. }
  911. if len(T_collection) > 0 {
  912. r.T_collection = T_collection
  913. clos = append(clos, "T_collection")
  914. }
  915. if len(T_reporting) > 0 {
  916. r.T_reporting = T_reporting
  917. clos = append(clos, "T_reporting")
  918. }
  919. if len(T_delivery) > 0 {
  920. r.T_delivery = T_delivery
  921. clos = append(clos, "T_delivery")
  922. }
  923. // 完成编辑后设置实施结束时间
  924. if T_collection_state == 4 {
  925. r.T_collection_state = T_collection_state
  926. clos = append(clos, "T_collection_state")
  927. r.T_collection_signature = T_collection_signature
  928. clos = append(clos, "T_collection_signature")
  929. r.T_collection_end_time = time.Now().Format("2006-01-02 15:04:05")
  930. clos = append(clos, "T_collection_end_time")
  931. if len(r.T_collection_start_time) > 0 {
  932. r.T_collection_time_interval, _ = lib.MinutesDifference(r.T_collection_start_time, r.T_collection_end_time)
  933. clos = append(clos, "T_collection_time_interval")
  934. // 所需时间 > 超时时间
  935. if r.T_collection_time_interval > Task.TaskCollectionTimeLimit && len(r.T_report_type) > 0 {
  936. r.T_collection_overtime = r.T_collection_time_interval - Task.TaskCollectionTimeLimit // 超时时间
  937. clos = append(clos, "T_scheme_overtime")
  938. }
  939. }
  940. // 添加已提交状态数据编辑记录
  941. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, r.T_collection_state, "", "")
  942. if err != nil {
  943. return
  944. }
  945. r.T_collection_audit_record = auditRecordJson
  946. clos = append(clos, "T_collection_audit_record")
  947. }
  948. if len(T_doc1) > 0 {
  949. r.T_doc1 = T_doc1
  950. clos = append(clos, "T_doc1")
  951. }
  952. // 验证报告内容T_pdf1,上传后将 当前任务 验证方案 标志 为 5 (0未完成 1已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交)
  953. // 上传后设置方案结束时间,计算所需时间和超时时间
  954. if len(T_pdf1) > 0 {
  955. r.T_pdf1 = T_pdf1
  956. clos = append(clos, "T_pdf1")
  957. //r.T_pdf1_watermark = GetWatermarkPdf(r,T_pdf1,"T_pdf1")
  958. //clos = append(clos, "T_pdf1_watermark")
  959. go GetWatermarkPdf(r, T_pdf1, "T_pdf1")
  960. r.T_scheme_state = 5
  961. clos = append(clos, "T_scheme_state")
  962. // 添加已提交状态验证方案记录
  963. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, "", User_r.T_uuid, r.T_scheme_state, "", "")
  964. if err != nil {
  965. return
  966. }
  967. r.T_scheme_audit_record = auditRecordJson
  968. clos = append(clos, "T_scheme_audit_record")
  969. r.T_scheme_end_time = time.Now().Format("2006-01-02 15:04:05")
  970. clos = append(clos, "T_scheme_end_time")
  971. if len(r.T_scheme_start_time) > 0 {
  972. r.T_scheme_time_interval, _ = lib.MinutesDifference(r.T_scheme_start_time, r.T_scheme_end_time)
  973. clos = append(clos, "T_scheme_time_interval")
  974. // 所需时间 > 超时时间
  975. if r.T_scheme_time_interval > Task.TaskSchemeTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  976. r.T_scheme_overtime = r.T_scheme_time_interval - Task.TaskSchemeTimeLimit[r.T_report_type] // 超时时间
  977. clos = append(clos, "T_scheme_overtime")
  978. }
  979. }
  980. }
  981. if len(T_doc2) > 0 {
  982. r.T_doc2 = T_doc2
  983. clos = append(clos, "T_doc2")
  984. }
  985. // 验证报告内容T_pdf2 ,上传后将 当前任务 报告编写 标志 为 1
  986. // 上传后设置报告结束时间,计算所需时间和超时时间
  987. if len(T_pdf2) > 0 {
  988. r.T_pdf2 = T_pdf2
  989. clos = append(clos, "T_pdf2")
  990. //r.T_pdf2_watermark = GetWatermarkPdf(T_pdf2,"T_pdf1")
  991. //clos = append(clos, "T_pdf2_watermark")
  992. go GetWatermarkPdf(r, T_pdf2, "T_pdf2")
  993. r.T_reporting_state = 5
  994. clos = append(clos, "T_reporting_state")
  995. // 添加已提交状态验证报告记录
  996. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, "", User_r.T_uuid, r.T_reporting_state, "", "")
  997. if err != nil {
  998. return
  999. }
  1000. r.T_reporting_audit_record = auditRecordJson
  1001. clos = append(clos, "T_reporting_audit_record")
  1002. r.T_reporting_end_time = time.Now().Format("2006-01-02 15:04:05")
  1003. clos = append(clos, "T_reporting_end_time")
  1004. if len(r.T_reporting_start_time) > 0 {
  1005. r.T_reporting_time_interval, _ = lib.MinutesDifference(r.T_reporting_start_time, r.T_reporting_end_time)
  1006. clos = append(clos, "T_reporting_time_interval")
  1007. // 所需时间 > 超时时间
  1008. if r.T_reporting_time_interval > Task.TaskReportingTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1009. r.T_reporting_overtime = r.T_reporting_time_interval - Task.TaskReportingTimeLimit[r.T_report_type] // 超时时间
  1010. clos = append(clos, "T_reporting_overtime")
  1011. }
  1012. }
  1013. }
  1014. if len(T_doc3) > 0 {
  1015. r.T_doc3 = T_doc3
  1016. clos = append(clos, "T_doc3")
  1017. }
  1018. if len(T_pdf3) > 0 {
  1019. r.T_pdf3 = T_pdf3
  1020. clos = append(clos, "T_pdf3")
  1021. }
  1022. // 验证标识内容T_pdf4 ,上传后将 当前任务 验证标识 标志 为 1
  1023. if len(T_pdf4) > 0 {
  1024. r.T_pdf4 = T_pdf4
  1025. clos = append(clos, "T_pdf4")
  1026. r.T_marking_state = 1
  1027. clos = append(clos, "T_marking_state")
  1028. }
  1029. if len(T_VerifyDeviceDataStartTime) > 0 {
  1030. r.T_VerifyDeviceDataStartTime = T_VerifyDeviceDataStartTime
  1031. clos = append(clos, "T_VerifyDeviceDataStartTime")
  1032. }
  1033. if len(T_VerifyDeviceDataEndTime) > 0 {
  1034. r.T_VerifyDeviceDataEndTime = T_VerifyDeviceDataEndTime
  1035. clos = append(clos, "T_VerifyDeviceDataEndTime")
  1036. }
  1037. if len(T_BindDeviceDataStartTime) > 0 {
  1038. r.T_BindDeviceDataStartTime = T_BindDeviceDataStartTime
  1039. clos = append(clos, "T_BindDeviceDataStartTime")
  1040. }
  1041. if len(T_BindDeviceDataEndTime) > 0 {
  1042. r.T_BindDeviceDataEndTime = T_BindDeviceDataEndTime
  1043. clos = append(clos, "T_BindDeviceDataEndTime")
  1044. }
  1045. if len(T_sn) > 0 {
  1046. T_sn = strings.TrimSpace(T_sn)
  1047. r.T_sn = T_sn
  1048. clos = append(clos, "T_sn")
  1049. }
  1050. if len(T_CalibrationExpirationTime) > 0 {
  1051. r.T_CalibrationExpirationTime = T_CalibrationExpirationTime
  1052. clos = append(clos, "T_CalibrationExpirationTime")
  1053. }
  1054. if len(T_sn) > 0 && len(T_CalibrationExpirationTime) > 0 {
  1055. err := NatsServer.Cold_UpdateDevice_CalibrationTime(T_sn, T_CalibrationExpirationTime)
  1056. if err != nil {
  1057. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  1058. c.ServeJSON()
  1059. return
  1060. }
  1061. }
  1062. // 从3.0获取校准时间
  1063. if len(T_sn) > 0 && len(T_CalibrationExpirationTime) == 0 {
  1064. device, err := NatsServer.Cold_ReadDeviceByT_sn(T_sn)
  1065. if err != nil {
  1066. err = errors.New("获取SN信息失败,请检查SN是否正确!")
  1067. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  1068. c.ServeJSON()
  1069. return
  1070. }
  1071. if !device.T_CalibrationTime.IsZero() {
  1072. r.T_CalibrationExpirationTime = device.T_CalibrationTime.Format("2006-01-02")
  1073. clos = append(clos, "T_CalibrationExpirationTime")
  1074. }
  1075. }
  1076. if len(T_project) > 0 {
  1077. r.T_project = T_project
  1078. clos = append(clos, "T_project")
  1079. }
  1080. if len(T_province) > 0 {
  1081. r.T_province = T_province
  1082. clos = append(clos, "T_province")
  1083. }
  1084. if len(T_city) > 0 {
  1085. r.T_city = T_city
  1086. clos = append(clos, "T_city")
  1087. }
  1088. if len(T_district) > 0 {
  1089. r.T_district = T_district
  1090. clos = append(clos, "T_district")
  1091. }
  1092. if len(T_province_code) > 0 {
  1093. r.T_province_code = T_province_code
  1094. clos = append(clos, "T_province_code")
  1095. }
  1096. if len(T_city_code) > 0 {
  1097. r.T_city_code = T_city_code
  1098. clos = append(clos, "T_city_code")
  1099. }
  1100. if len(T_district_code) > 0 {
  1101. r.T_district_code = T_district_code
  1102. clos = append(clos, "T_district_code")
  1103. }
  1104. if len(T_category) > 0 {
  1105. r.T_category = T_category
  1106. clos = append(clos, "T_category")
  1107. }
  1108. if len(T_device_type) > 0 {
  1109. r.T_device_type = T_device_type
  1110. clos = append(clos, "T_device_type")
  1111. }
  1112. if len(T_volume) > 0 {
  1113. r.T_volume = T_volume
  1114. clos = append(clos, "T_volume")
  1115. }
  1116. if len(T_verify_type) > 0 {
  1117. r.T_verify_type = T_verify_type
  1118. clos = append(clos, "T_verify_type")
  1119. }
  1120. if len(T_subject_matter) > 0 {
  1121. r.T_subject_matter = T_subject_matter
  1122. clos = append(clos, "T_subject_matter")
  1123. }
  1124. if len(T_temp_range) > 0 {
  1125. r.T_temp_range = T_temp_range
  1126. clos = append(clos, "T_temp_range")
  1127. }
  1128. if len(T_report_number) > 0 {
  1129. r.T_report_number = T_report_number
  1130. clos = append(clos, "T_report_number")
  1131. }
  1132. if !Task.Update_Task(r, clos...) {
  1133. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1134. c.ServeJSON()
  1135. return
  1136. }
  1137. // 添加任务操作日志
  1138. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改", r)
  1139. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改", r)
  1140. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1141. c.ServeJSON()
  1142. return
  1143. }
  1144. // 修改验证方案状态
  1145. func (c *TaskController) UpSchemeState() {
  1146. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1147. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1148. if !Admin_is && !User_is {
  1149. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1150. c.ServeJSON()
  1151. return
  1152. }
  1153. operate_uuid := ""
  1154. if Admin_is {
  1155. operate_uuid = Admin_r.T_uuid
  1156. }
  1157. if User_is {
  1158. operate_uuid = User_r.T_uuid
  1159. }
  1160. T_scheme_state, _ := c.GetInt("T_scheme_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1161. T_reason := c.GetString("T_reason") // 退回原因
  1162. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1163. T_task_id := c.GetString("T_task_id")
  1164. r, is := Task.Read_Task(T_task_id)
  1165. if !is {
  1166. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1167. c.ServeJSON()
  1168. return
  1169. }
  1170. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1171. clos := make([]string, 0)
  1172. if T_scheme_state > 0 {
  1173. r.T_scheme_state = T_scheme_state
  1174. clos = append(clos, "T_scheme_state")
  1175. }
  1176. if len(T_signature) > 0 {
  1177. r.T_scheme_signature = T_signature
  1178. clos = append(clos, "T_scheme_signature")
  1179. }
  1180. if T_scheme_state == Task.TaskSchemeStateClientReturn || T_scheme_state == Task.TaskSchemeStateReturn {
  1181. r.T_scheme_return_times += 1
  1182. clos = append(clos, "T_scheme_return_times")
  1183. // 客户退回时新增驳回次数和驳回记录
  1184. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  1185. r.T_reject_times += 1
  1186. var rejectRecordList []Task.AuditRecord
  1187. if len(r.T_reject_record) > 0 {
  1188. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1189. if err != nil {
  1190. logs.Error("JSON 反序列化失败:", err)
  1191. return
  1192. }
  1193. }
  1194. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1195. T_uuid: User_r.T_uuid,
  1196. T_state: T_scheme_state,
  1197. T_reason: T_reason,
  1198. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1199. T_type: "scheme",
  1200. })
  1201. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1202. if err != nil {
  1203. logs.Error("JSON 反序列化失败:", err)
  1204. return
  1205. }
  1206. r.T_reject_record = string(rejectRecordJson)
  1207. clos = append(clos, "T_reject_times")
  1208. clos = append(clos, "T_reject_record")
  1209. }
  1210. }
  1211. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_scheme_state, T_reason, "")
  1212. if err != nil {
  1213. return
  1214. }
  1215. r.T_scheme_audit_record = auditRecordJson
  1216. clos = append(clos, "T_scheme_audit_record")
  1217. if !Task.Update_Task(r, clos...) {
  1218. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1219. c.ServeJSON()
  1220. return
  1221. }
  1222. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1223. if T_scheme_state == Task.TaskSchemeStateClientReturn ||
  1224. T_scheme_state == Task.TaskSchemeStateReturn ||
  1225. T_scheme_state == Task.TaskSchemeStatePass ||
  1226. T_scheme_state == Task.TaskSchemeStateClientPass {
  1227. System.Add_News(r.T_scheme, fmt.Sprintf("【验证方案】您提交的验证方案【%s-%s】 %s", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  1228. System.Send_Weichat_News(AdminMap[r.T_scheme], fmt.Sprintf("【验证方案】您提交的验证方案【%s-%s】 %s", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  1229. }
  1230. if T_scheme_state == Task.TaskSchemeStateClientPass {
  1231. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案客户已通过,可以进场实施,请到平台进行查看验证方案,确认好后选择进场时间", company_r.T_name, r.T_name), "")
  1232. System.Send_Weichat_News(AdminMap[r.T_collection], fmt.Sprintf("【%s-%s】验证方案客户已通过,可以进场实施,请到平台进行查看验证方案,确认好后选择进场时间", company_r.T_name, r.T_name), "")
  1233. }
  1234. // 添加任务操作日志
  1235. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证方案状态", r)
  1236. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证方案状态", r)
  1237. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1238. c.ServeJSON()
  1239. return
  1240. }
  1241. // 修改验证报告状态
  1242. func (c *TaskController) UpReportingState() {
  1243. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1244. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1245. if !Admin_is && !User_is {
  1246. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1247. c.ServeJSON()
  1248. return
  1249. }
  1250. operate_uuid := ""
  1251. if Admin_is {
  1252. operate_uuid = Admin_r.T_uuid
  1253. }
  1254. if User_is {
  1255. operate_uuid = User_r.T_uuid
  1256. }
  1257. T_reporting_state, _ := c.GetInt("T_reporting_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1258. T_reason := c.GetString("T_reason") // 退回原因
  1259. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1260. T_task_id := c.GetString("T_task_id")
  1261. r, is := Task.Read_Task(T_task_id)
  1262. if !is {
  1263. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1264. c.ServeJSON()
  1265. return
  1266. }
  1267. _, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1268. clos := make([]string, 0)
  1269. if T_reporting_state > 0 {
  1270. r.T_reporting_state = T_reporting_state
  1271. clos = append(clos, "T_reporting_state")
  1272. }
  1273. if len(T_signature) > 0 {
  1274. r.T_reporting_signature = T_signature
  1275. clos = append(clos, "T_reporting_signature")
  1276. }
  1277. if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
  1278. r.T_reporting_return_times += 1
  1279. clos = append(clos, "T_reporting_return_times")
  1280. // 客户退回时新增驳回次数和驳回记录
  1281. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1282. r.T_reject_times += 1
  1283. var rejectRecordList []Task.AuditRecord
  1284. if len(r.T_reject_record) > 0 {
  1285. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1286. if err != nil {
  1287. logs.Error("JSON 反序列化失败:", err)
  1288. return
  1289. }
  1290. }
  1291. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1292. T_uuid: User_r.T_uuid,
  1293. T_state: T_reporting_state,
  1294. T_reason: T_reason,
  1295. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1296. T_type: "reporting",
  1297. })
  1298. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1299. if err != nil {
  1300. logs.Error("JSON 反序列化失败:", err)
  1301. return
  1302. }
  1303. r.T_reject_record = string(rejectRecordJson)
  1304. clos = append(clos, "T_reject_times")
  1305. clos = append(clos, "T_reject_record")
  1306. }
  1307. }
  1308. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
  1309. if err != nil {
  1310. return
  1311. }
  1312. r.T_reporting_audit_record = auditRecordJson
  1313. clos = append(clos, "T_reporting_audit_record")
  1314. // 验证报告客户审核通过后设置结束时间
  1315. if T_reporting_state == Task.TaskReportingStateClientPass {
  1316. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  1317. r.T_time_interval, _ = lib.MinutesDifference(r.T_start_time, r.T_end_time)
  1318. clos = append(clos, "T_end_time")
  1319. clos = append(clos, "T_time_interval")
  1320. }
  1321. if !Task.Update_Task(r, clos...) {
  1322. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1323. c.ServeJSON()
  1324. return
  1325. }
  1326. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1327. if T_reporting_state == Task.TaskSchemeStateClientReturn ||
  1328. T_reporting_state == Task.TaskSchemeStateReturn ||
  1329. T_reporting_state == Task.TaskSchemeStatePass ||
  1330. T_reporting_state == Task.TaskSchemeStateClientPass {
  1331. System.Add_News(r.T_scheme, fmt.Sprintf("【验证报告】您提交的验证报告【%s-%s】 %s", user_r.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1332. System.Send_Weichat_News(AdminMap[r.T_scheme], fmt.Sprintf("【验证报告】您提交的验证报告【%s-%s】 %s", user_r.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1333. }
  1334. // 添加任务操作日志
  1335. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证报告状态", r)
  1336. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证报告状态", r)
  1337. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1338. c.ServeJSON()
  1339. return
  1340. }
  1341. // 进场
  1342. func (c *TaskController) EnterArea() {
  1343. // 验证登录 User_is, User_r
  1344. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1345. if !User_is {
  1346. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1347. c.ServeJSON()
  1348. return
  1349. }
  1350. T_task_id := c.GetString("T_task_id")
  1351. T_time := c.GetString("T_time") // 进场时间
  1352. r, is := Task.Read_Task(T_task_id)
  1353. if !is {
  1354. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1355. c.ServeJSON()
  1356. return
  1357. }
  1358. r.T_enter_area_time = T_time
  1359. if !Task.Update_Task(r, "T_enter_area_time") {
  1360. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改进场时间失败!"}
  1361. c.ServeJSON()
  1362. return
  1363. }
  1364. // 添加任务操作日志
  1365. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "进场", r)
  1366. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "进场", r)
  1367. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1368. c.ServeJSON()
  1369. return
  1370. }
  1371. // 开始验证
  1372. func (c *TaskController) StartVerify() {
  1373. // 验证登录 User_is, User_r
  1374. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1375. if !User_is {
  1376. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1377. c.ServeJSON()
  1378. return
  1379. }
  1380. T_task_id := c.GetString("T_task_id")
  1381. T_time := c.GetString("T_time") // 进场时间
  1382. r, is := Task.Read_Task(T_task_id)
  1383. if !is {
  1384. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1385. c.ServeJSON()
  1386. return
  1387. }
  1388. if len(r.T_collection_start_time) == 0 {
  1389. r.T_collection_start_time = T_time
  1390. if !Task.Update_Task(r, "T_collection_start_time") {
  1391. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
  1392. c.ServeJSON()
  1393. return
  1394. }
  1395. // 添加任务操作日志
  1396. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
  1397. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
  1398. }
  1399. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1400. c.ServeJSON()
  1401. return
  1402. }
  1403. // 删除-
  1404. func (c *TaskController) Del() {
  1405. // 验证登录 User_is, User_r
  1406. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1407. if !User_is {
  1408. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1409. c.ServeJSON()
  1410. return
  1411. }
  1412. T_task_id := c.GetString("T_task_id")
  1413. if r, is := Task.Read_Task(T_task_id); is {
  1414. if !Task.Delete_Task(r) {
  1415. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  1416. c.ServeJSON()
  1417. return
  1418. }
  1419. // 添加任务操作日志
  1420. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
  1421. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
  1422. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1423. c.ServeJSON()
  1424. return
  1425. }
  1426. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1427. c.ServeJSON()
  1428. return
  1429. }
  1430. // 列表 -
  1431. func (c *TaskController) Logs_List() {
  1432. // 验证登录 User_is, User_r
  1433. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1434. if !User_is {
  1435. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1436. c.ServeJSON()
  1437. return
  1438. }
  1439. var r_jsons lib.R_JSONS
  1440. page, _ := c.GetInt("page")
  1441. if page < 1 {
  1442. page = 1
  1443. }
  1444. page_z, _ := c.GetInt("page_z")
  1445. if page_z < 1 {
  1446. page_z = conf.Page_size
  1447. }
  1448. T_task_id := c.GetString("T_task_id")
  1449. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1450. var cnt int
  1451. List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
  1452. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1453. r_jsons.List = List
  1454. r_jsons.Page = page
  1455. r_jsons.Page_size = int(page_size)
  1456. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1457. r_jsons.Num = cnt
  1458. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1459. c.ServeJSON()
  1460. return
  1461. }
  1462. // 查询图片生成状态
  1463. func (c *TaskController) DeviceData_JPGState() {
  1464. T_task_id := c.GetString("T_task_id")
  1465. T_remark := c.GetString("T_remark")
  1466. jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
  1467. if !is {
  1468. c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
  1469. c.ServeJSON()
  1470. return
  1471. }
  1472. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
  1473. c.ServeJSON()
  1474. return
  1475. }
  1476. // 生成温度图片
  1477. func (c *TaskController) DeviceData_JPG() {
  1478. StartTime := c.GetString("StartTime")
  1479. if len(StartTime) > 0 {
  1480. _, ok := lib.TimeStrToTime(StartTime)
  1481. if !ok {
  1482. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1483. c.ServeJSON()
  1484. return
  1485. }
  1486. }
  1487. EndTime := c.GetString("EndTime")
  1488. if len(EndTime) > 0 {
  1489. _, ok := lib.TimeStrToTime(EndTime)
  1490. if !ok {
  1491. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1492. c.ServeJSON()
  1493. return
  1494. }
  1495. } else {
  1496. EndTime = time.Now().Format("2006-01-02 15:04:05")
  1497. }
  1498. T_remark := c.GetString("T_remark")
  1499. TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
  1500. TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
  1501. if TemperatureMin == 0 {
  1502. TemperatureMin = 2
  1503. }
  1504. if TemperatureMax == 0 {
  1505. TemperatureMax = 8
  1506. }
  1507. T_task_id := c.GetString("T_task_id")
  1508. Task_r, is := Task.Read_Task(T_task_id)
  1509. if !is {
  1510. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  1511. c.ServeJSON()
  1512. return
  1513. }
  1514. if Task_r.T_collection_state == 2 {
  1515. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  1516. c.ServeJSON()
  1517. return
  1518. }
  1519. deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  1520. if !is {
  1521. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  1522. c.ServeJSON()
  1523. return
  1524. }
  1525. Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
  1526. // 生成图片
  1527. go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
  1528. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1529. c.ServeJSON()
  1530. return
  1531. }
  1532. // SyncInfoCollection 同步信息采集表
  1533. func (c *TaskController) SyncInfoCollection() {
  1534. T_task_id := c.GetString("T_task_id")
  1535. T_source, _ := c.GetInt("T_source")
  1536. task, is := Task.Read_Task(T_task_id)
  1537. if !is {
  1538. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1539. c.ServeJSON()
  1540. return
  1541. }
  1542. // 获取信息采集表模版信息
  1543. InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
  1544. InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
  1545. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  1546. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  1547. InfoCollectionDataMap := make(map[string]string)
  1548. for _, data := range InfoCollection_Data {
  1549. InfoCollectionDataMap[data.T_name] = data.T_value
  1550. }
  1551. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  1552. for _, v := range Data {
  1553. if len(v.T_value) > 0 {
  1554. continue
  1555. }
  1556. if InfoCollectionDataMap[v.T_name] == "" {
  1557. continue
  1558. }
  1559. val := VerifyTemplate.VerifyTemplateMapData{
  1560. T_source: T_source,
  1561. T_task_id: task.T_task_id,
  1562. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  1563. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  1564. T_flow_sort: v.T_flow_sort,
  1565. T_max_time: v.T_max_time,
  1566. T_min_time: v.T_min_time,
  1567. T_value: InfoCollectionDataMap[v.T_name],
  1568. }
  1569. MapDataList = append(MapDataList, val)
  1570. }
  1571. var ids []int64
  1572. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  1573. if !is {
  1574. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  1575. c.ServeJSON()
  1576. return
  1577. }
  1578. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  1579. c.ServeJSON()
  1580. return
  1581. }
  1582. // 退回记录列表
  1583. func (c *TaskController) AuditRecordList() {
  1584. // 验证登录 User_is, User_r
  1585. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1586. if !User_is {
  1587. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1588. c.ServeJSON()
  1589. return
  1590. }
  1591. T_task_id := c.GetString("T_task_id")
  1592. T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
  1593. //T_task 驳回记录
  1594. //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1595. //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  1596. //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1597. T_state, _ := c.GetInt("T_state") // -1 获取全部
  1598. r, is := Task.Read_Task(T_task_id)
  1599. if !is {
  1600. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1601. c.ServeJSON()
  1602. return
  1603. }
  1604. var auditRecordList []Task.AuditRecord
  1605. switch T_type {
  1606. case "T_task":
  1607. T_state = -1
  1608. if len(r.T_reject_record) > 0 {
  1609. err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
  1610. if err != nil {
  1611. logs.Error("JSON 反序列化失败:", err)
  1612. return
  1613. }
  1614. }
  1615. case "T_scheme":
  1616. if len(r.T_scheme_audit_record) > 0 {
  1617. err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
  1618. if err != nil {
  1619. logs.Error("JSON 反序列化失败:", err)
  1620. return
  1621. }
  1622. }
  1623. case "T_collection":
  1624. if len(r.T_collection_audit_record) > 0 {
  1625. err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
  1626. if err != nil {
  1627. logs.Error("JSON 反序列化失败:", err)
  1628. return
  1629. }
  1630. }
  1631. case "T_reporting":
  1632. if len(r.T_reporting_audit_record) > 0 {
  1633. err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
  1634. if err != nil {
  1635. logs.Error("JSON 反序列化失败:", err)
  1636. return
  1637. }
  1638. }
  1639. }
  1640. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1641. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  1642. var auditRecordList2 []Task.AuditRecord
  1643. // 返回全部
  1644. if T_state == -1 {
  1645. for i := 0; i < len(auditRecordList); i++ {
  1646. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1647. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1648. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1649. }
  1650. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1651. c.ServeJSON()
  1652. return
  1653. }
  1654. if T_state == -2 {
  1655. for i := 0; i < len(auditRecordList); i++ {
  1656. if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
  1657. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1658. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1659. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1660. }
  1661. }
  1662. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1663. c.ServeJSON()
  1664. return
  1665. }
  1666. for i := 0; i < len(auditRecordList); i++ {
  1667. if auditRecordList[i].T_state == T_state {
  1668. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1669. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1670. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1671. }
  1672. }
  1673. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1674. c.ServeJSON()
  1675. return
  1676. }
  1677. // 存档生成图片
  1678. func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
  1679. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1680. State: 1,
  1681. Msg: "图片生成中",
  1682. Url: "",
  1683. })
  1684. msg := ""
  1685. state := 2
  1686. url := ""
  1687. if TemperatureMin == 0 {
  1688. TemperatureMin = 2
  1689. }
  1690. if TemperatureMax == 0 {
  1691. TemperatureMax = 8
  1692. }
  1693. var ymin, ymax float64
  1694. var xminT, xmaxT time.Time
  1695. if len(deviceList) > 0 {
  1696. ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
  1697. }
  1698. // 创建一个新的绘图
  1699. p := plot.New()
  1700. // 设置绘图标题和标签
  1701. p.Title.Text = "温度折线图"
  1702. //p.Legend.ThumbnailWidth = 5 * vg.Inch
  1703. p.X.Label.Text = "时间"
  1704. p.Y.Label.Text = "温度"
  1705. var chData = make(chan int, 10)
  1706. var jobGroup sync.WaitGroup
  1707. var device = make([]Device.DeviceCount, len(deviceList))
  1708. // 创建温度线
  1709. for i := 0; i < len(deviceList); i++ {
  1710. chData <- 1
  1711. jobGroup.Add(1)
  1712. go func(index int) {
  1713. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  1714. defer func() {
  1715. <-chData // 完成时chan取出1个
  1716. jobGroup.Done() // 完成时将等待组值减1
  1717. }()
  1718. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  1719. ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
  1720. if ymin > ymin_ {
  1721. ymin = ymin_
  1722. }
  1723. if ymax < ymax_ {
  1724. ymax = ymax_
  1725. }
  1726. if xminT.After(minTime_) && !minTime_.IsZero() {
  1727. xminT = minTime_
  1728. }
  1729. if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
  1730. xmaxT = maxTime_
  1731. }
  1732. r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  1733. device[index] = Device.DeviceCount{
  1734. T_id: id,
  1735. Num: r_maps_num,
  1736. }
  1737. if r_maps_num == 0 {
  1738. return
  1739. }
  1740. pts := make(plotter.XYs, len(r_maps))
  1741. for j, d := range r_maps {
  1742. t, _ := lib.TimeStrToTime(d.T_time)
  1743. pts[j].X = float64(t.Unix())
  1744. pts[j].Y = float64(d.T_t)
  1745. }
  1746. line, err := plotter.NewLine(pts)
  1747. if err != nil {
  1748. return
  1749. }
  1750. line.Color = randomColor(index)
  1751. p.Add(line)
  1752. }(i)
  1753. }
  1754. jobGroup.Wait()
  1755. xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
  1756. // 添加最高,最低标准线 用红色虚线标识
  1757. p.Add(horizontalLine(xmin, xmax, TemperatureMin))
  1758. p.Add(horizontalLine(xmin, xmax, TemperatureMax))
  1759. if ymax < 8 {
  1760. ymax = 8
  1761. }
  1762. if ymin > 0 {
  1763. ymin = 0
  1764. }
  1765. p.Y.Min, p.Y.Max = ymin, ymax
  1766. p.X.Min, p.X.Max = xmin, xmax
  1767. p.Y.Tick.Marker = commaTicks{}
  1768. //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
  1769. p.X.Tick.Marker = timeTicks{}
  1770. p.X.Tick.Label.Rotation = math.Pi / 5
  1771. p.X.Tick.Label.YAlign = draw.YCenter
  1772. p.X.Tick.Label.XAlign = draw.XRight
  1773. filename := "jpg" + time.Now().Format("20060102150405")
  1774. // 保存文件
  1775. if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
  1776. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1777. State: 3,
  1778. Msg: "图片生成失败",
  1779. Url: url,
  1780. })
  1781. logs.Error(lib.FuncName(), "生成图片失败", err)
  1782. return
  1783. }
  1784. if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
  1785. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1786. State: 3,
  1787. Msg: "图片上传七牛云失败",
  1788. Url: url,
  1789. })
  1790. logs.Error(lib.FuncName(), "上传七牛云失败")
  1791. return
  1792. }
  1793. //删除目录
  1794. os.Remove("ofile/" + filename + ".jpg")
  1795. msg = "图片生成成功"
  1796. url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
  1797. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1798. State: state,
  1799. Msg: msg,
  1800. Url: url,
  1801. Device: device,
  1802. })
  1803. return
  1804. }
  1805. func horizontalLine(xmin, xmax, y float64) *plotter.Line {
  1806. pts := make(plotter.XYs, 2)
  1807. pts[0].X = xmin
  1808. pts[0].Y = y
  1809. pts[1].X = xmax
  1810. pts[1].Y = y
  1811. line, err := plotter.NewLine(pts)
  1812. if err != nil {
  1813. panic(err)
  1814. }
  1815. line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
  1816. line.Color = color.RGBA{R: 255, A: 255}
  1817. return line
  1818. }
  1819. type timeTicks struct{}
  1820. func (timeTicks) Ticks(min, max float64) []plot.Tick {
  1821. tks := plot.TimeTicks{}.Ticks(min, max)
  1822. for i, t := range tks {
  1823. //if t.Label == "" { // Skip minor ticks, they are fine.
  1824. // continue
  1825. //}
  1826. tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
  1827. }
  1828. return tks
  1829. }
  1830. type commaTicks struct{}
  1831. // Ticks computes the default tick marks, but inserts commas
  1832. // into the labels for the major tick marks.
  1833. func (commaTicks) Ticks(min, max float64) []plot.Tick {
  1834. tks := plot.DefaultTicks{}.Ticks(min, max)
  1835. for i, t := range tks {
  1836. //if t.Label == "" { // Skip minor ticks, they are fine.
  1837. // continue
  1838. //}
  1839. tks[i].Label = fmt.Sprintf("%.0f", t.Value)
  1840. }
  1841. return tks
  1842. }
  1843. // 生成随机颜色的辅助函数
  1844. func randomColor(i int) color.RGBA {
  1845. var colors []color.RGBA
  1846. colors = append(colors,
  1847. color.RGBA{R: 52, G: 152, B: 219, A: 255},
  1848. color.RGBA{R: 230, G: 126, B: 34, A: 255},
  1849. color.RGBA{R: 142, G: 68, B: 173, A: 255},
  1850. color.RGBA{R: 211, G: 84, B: 0, A: 255},
  1851. color.RGBA{R: 231, G: 76, B: 60, A: 255},
  1852. color.RGBA{R: 26, G: 188, B: 156, A: 255},
  1853. color.RGBA{R: 243, G: 156, B: 18, A: 255},
  1854. color.RGBA{R: 22, G: 160, B: 133, A: 255},
  1855. color.RGBA{R: 46, G: 204, B: 113, A: 255},
  1856. color.RGBA{R: 39, G: 174, B: 96, A: 255},
  1857. color.RGBA{R: 41, G: 128, B: 185, A: 255},
  1858. color.RGBA{R: 155, G: 89, B: 182, A: 255},
  1859. color.RGBA{R: 192, G: 57, B: 43, A: 255},
  1860. color.RGBA{R: 241, G: 196, B: 15, A: 255},
  1861. )
  1862. return colors[i%len(colors)]
  1863. }
  1864. // 获取加完水印的pdf
  1865. func GetWatermarkPdf(task Task.Task, pdfURL string, flag string) (pdf string) {
  1866. if len(pdfURL) == 0 {
  1867. return
  1868. }
  1869. currentDirectory := lib.GetCurrentDirectory()
  1870. scriptPath := currentDirectory + "/script"
  1871. pdf_file_out_name := uuid.New().String() + ".pdf"
  1872. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  1873. pdf_file_out := currentDirectory + "/ofile/watermark" + pdf_file_out_name
  1874. watermark_pdf := currentDirectory + "/script/watermark.pdf"
  1875. // 执行Python脚本
  1876. cmd := exec.Command("python3", "add_watermark.py", pdfURL, pdfFilename, pdf_file_out, watermark_pdf)
  1877. cmd.Dir = scriptPath
  1878. // 获取命令输出
  1879. _, err := cmd.CombinedOutput()
  1880. if err != nil {
  1881. logs.Error("执行python脚本添加水印错误:", err)
  1882. return
  1883. }
  1884. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  1885. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  1886. err = errors.New("上传水印pdf失败")
  1887. return
  1888. }
  1889. defer func() {
  1890. os.Remove(pdfFilename)
  1891. os.Remove(pdf_file_out)
  1892. }()
  1893. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  1894. switch flag {
  1895. case "T_pdf1":
  1896. task.T_pdf1_watermark = pdf
  1897. Task.Update_Task(task, "T_pdf1_watermark")
  1898. case "T_pdf2":
  1899. task.T_pdf2_watermark = pdf
  1900. Task.Update_Task(task, "T_pdf2_watermark")
  1901. }
  1902. return
  1903. }