Task.go 94 KB

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