Task.go 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362
  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. T_device_quantity, _ := c.GetInt("T_device_quantity") // 终端数量
  596. T_cnas, _ := c.GetInt("T_cnas") // cnas实验室
  597. // 查询信息采集信息
  598. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  599. if !is {
  600. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  601. c.ServeJSON()
  602. return
  603. }
  604. // 查询信息采集信息
  605. user, is := Account.Read_User(T_uuid)
  606. if !is {
  607. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid 错误!"}
  608. c.ServeJSON()
  609. return
  610. }
  611. var_ := Task.Task{
  612. T_Distributor_id: user.T_Distributor_id,
  613. T_InfoCollection_id: T_InfoCollection_id,
  614. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  615. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  616. T_class: int(T_class_id),
  617. T_uuid: T_uuid,
  618. T_name: T_name,
  619. T_VerifyTemplate_class: T_VerifyTemplate_class,
  620. T_VerifyTemplate_id: T_VerifyTemplate_id,
  621. T_deadline: T_deadline,
  622. T_scheme: T_scheme,
  623. T_collection: T_collection,
  624. T_reporting: T_reporting,
  625. T_delivery: T_delivery,
  626. T_Show: 1,
  627. T_State: 1,
  628. T_project: T_project,
  629. T_province: T_province,
  630. T_city: T_city,
  631. T_district: T_district,
  632. T_province_code: T_province_code,
  633. T_city_code: T_city_code,
  634. T_district_code: T_district_code,
  635. T_category: T_category,
  636. T_device_type: T_device_type,
  637. T_volume: T_volume,
  638. T_verify_type: T_verify_type,
  639. T_subject_matter: T_subject_matter,
  640. T_temp_range: T_temp_range,
  641. T_report_number: T_report_number,
  642. T_report_type: T_report_type,
  643. T_device_quantity: T_device_quantity,
  644. T_cnas: T_cnas,
  645. }
  646. if T_report_number != "/" {
  647. _, exist := Task.Read_TaskbyT_report_number(T_report_number)
  648. if exist {
  649. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报告编号已存在!"}
  650. c.ServeJSON()
  651. return
  652. }
  653. }
  654. T_task_id, is := Task.Add_Task(var_)
  655. if !is {
  656. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  657. c.ServeJSON()
  658. return
  659. }
  660. NatsServer.Create_Local_Table(T_task_id)
  661. Task.Redis_Task_T_report_number_DelK(T_report_number) // 删除redis内的任务编号
  662. // 通知
  663. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  664. go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  665. go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  666. go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  667. go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  668. // 添加任务操作日志
  669. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "添加", var_)
  670. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "添加", var_)
  671. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  672. c.ServeJSON()
  673. return
  674. }
  675. // 接收信息采集
  676. func (c *TaskController) ReceiptInfoCollection() {
  677. // 验证登录 User_is, User_r
  678. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  679. if !User_is {
  680. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  681. c.ServeJSON()
  682. return
  683. }
  684. // 修改信息采集状态为已接收
  685. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  686. //T_status,_ := c.GetInt("T_status")
  687. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  688. if !is {
  689. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  690. c.ServeJSON()
  691. return
  692. }
  693. if infoCollection.T_status != InfoCollection.InfoCollectionStatusSubmitted && infoCollection.T_status != InfoCollection.InfoCollectionStatusReceipt {
  694. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止接收!", InfoCollection.InfoCollectionStatusMap[infoCollection.T_status])}
  695. c.ServeJSON()
  696. return
  697. }
  698. //infoCollection.T_status = InfoCollection.InfoCollectionStatusReceipt
  699. //if len(infoCollection.T_end_time) == 0 {
  700. // infoCollection.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  701. // infoCollection.T_time_interval, _ = lib.MinutesDifference(infoCollection.T_start_time, infoCollection.T_end_time)
  702. //}
  703. //if !InfoCollection.Update_InfoCollection(infoCollection, "T_status", "T_end_time", "T_time_interval") {
  704. infoCollection.T_status = 3 // 已接收
  705. if !InfoCollection.Update_InfoCollection(infoCollection, "T_status") {
  706. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  707. c.ServeJSON()
  708. return
  709. }
  710. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "接收信息采集", infoCollection)
  711. //if T_status == InfoCollection.InfoCollectionStatusReturn{
  712. // // 通知 报告负责人审核
  713. // _, company_r := Account.Read_User_ByT_uuid(infoCollection.T_uuid)
  714. // System.Add_News(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name), "")
  715. // go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name))
  716. //
  717. //}
  718. // 修改任务管理实施方案开始时间
  719. //T_task_id := c.GetString("T_task_id")
  720. //task, is := Task.Read_Task(T_task_id)
  721. //if !is {
  722. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  723. // c.ServeJSON()
  724. // return
  725. //}
  726. // 添加任务操作日志
  727. //Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "接收信息采集", task)
  728. //System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "接收信息采集", task)
  729. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  730. c.ServeJSON()
  731. return
  732. }
  733. // 添加-
  734. func (c *TaskController) AddData_Tool() {
  735. T_uuid := "3e84dda9-9eec-42b9-9350-0894262fc8a1" // 用户uuid
  736. T_name := c.GetString("T_name")
  737. T_task_id := c.GetString("T_task_id")
  738. T_task_id = strings.ToLower(T_task_id)
  739. r, _ := Task.Read_Task(T_task_id)
  740. if r.T_collection_state == 2 {
  741. c.Data["json"] = lib.JSONS{Code: 200, Msg: "数据采集中..."}
  742. c.ServeJSON()
  743. return
  744. }
  745. if r.Id > 0 {
  746. // 同步1.0数据
  747. NatsServer.Sync1_TaskData(T_task_id)
  748. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  749. c.ServeJSON()
  750. return
  751. }
  752. dc := Device.DeviceClass{
  753. T_uuid: T_uuid,
  754. T_State: 1,
  755. }
  756. T_class_id, is := Device.Add_DeviceClass(dc)
  757. if !is {
  758. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  759. c.ServeJSON()
  760. return
  761. }
  762. var_ := Task.Task{
  763. T_task_id: T_task_id,
  764. T_class: int(T_class_id),
  765. T_uuid: T_uuid,
  766. T_name: T_name,
  767. T_Show: 1,
  768. T_State: 1,
  769. T_collection_state: 2,
  770. }
  771. _, is = Task.Add_Task_Tool(var_)
  772. if !is {
  773. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  774. c.ServeJSON()
  775. return
  776. }
  777. // 创建本地表
  778. NatsServer.Create_Local_Table(T_task_id)
  779. // 同步1.0数据
  780. NatsServer.Sync1_TaskData(T_task_id)
  781. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  782. c.ServeJSON()
  783. return
  784. }
  785. // 修改采集状态-
  786. func (c *TaskController) UpCollectionState() {
  787. // 验证登录 User_is, User_r
  788. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  789. if !User_is {
  790. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  791. c.ServeJSON()
  792. return
  793. }
  794. T_collection_state, _ := c.GetInt("T_collection_state")
  795. T_reason := c.GetString("T_reason") // 退回原因
  796. T_task_id := c.GetString("T_task_id")
  797. r, is := Task.Read_Task(T_task_id)
  798. if !is {
  799. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  800. c.ServeJSON()
  801. return
  802. }
  803. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  804. r.T_collection_state = T_collection_state
  805. clos := make([]string, 0)
  806. clos = append(clos, "T_collection_state")
  807. if T_collection_state == Task.TaskCollectionStateReturn {
  808. r.T_collection_return_times += 1
  809. clos = append(clos, "T_collection_return_times")
  810. }
  811. if T_collection_state == Task.TaskCollectionStateSubmitted ||
  812. T_collection_state == Task.TaskCollectionStateReturn ||
  813. T_collection_state == Task.TaskCollectionStatePass {
  814. // 添加已提交状态验证报告记录
  815. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, T_collection_state, T_reason, "")
  816. if err != nil {
  817. return
  818. }
  819. r.T_collection_audit_record = auditRecordJson
  820. clos = append(clos, "T_collection_audit_record")
  821. }
  822. if T_collection_state == Task.TaskCollectionStatePass {
  823. // 数据编辑审核通过时间为验证报告开始时间
  824. r.T_reporting_start_time = time.Now().Format("2006-01-02 15:04:05")
  825. clos = append(clos, "T_reporting_start_time")
  826. }
  827. if !Task.Update_Task(r, clos...) {
  828. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  829. c.ServeJSON()
  830. return
  831. }
  832. // 已退回(负责人)
  833. if T_collection_state == Task.TaskCollectionStateReturn {
  834. 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), "")
  835. 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))
  836. }
  837. // 添加任务操作日志
  838. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改采集状态", r)
  839. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改采集状态", r)
  840. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  841. c.ServeJSON()
  842. return
  843. }
  844. func (c *TaskController) UpDeliveryState() {
  845. // 验证登录 User_is, User_r
  846. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  847. if !User_is {
  848. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  849. c.ServeJSON()
  850. return
  851. }
  852. T_delivery_state, _ := c.GetInt("T_delivery_state")
  853. T_task_id := c.GetString("T_task_id")
  854. r, is := Task.Read_Task(T_task_id)
  855. if !is {
  856. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  857. c.ServeJSON()
  858. return
  859. }
  860. r.T_delivery_state = T_delivery_state
  861. if !Task.Update_Task(r, "T_delivery_state") {
  862. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  863. c.ServeJSON()
  864. return
  865. }
  866. // 添加任务操作日志
  867. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改交付审核状态", r)
  868. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改交付审核状态", r)
  869. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  870. c.ServeJSON()
  871. return
  872. }
  873. // 更新线上数据后台执行
  874. func (c *TaskDataController) TaskData_Up_TaskData_Back() {
  875. // 验证登录 User_is, User_r
  876. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  877. if !User_is {
  878. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  879. c.ServeJSON()
  880. return
  881. }
  882. T_task_id := c.GetString("T_task_id")
  883. r, is := Task.Read_Task(T_task_id)
  884. if !is {
  885. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  886. c.ServeJSON()
  887. return
  888. }
  889. // 通知 报告人员
  890. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  891. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  892. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name), "")
  893. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name))
  894. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  895. c.ServeJSON()
  896. return
  897. }
  898. // 修改-
  899. func (c *TaskController) Up() {
  900. // 验证登录 User_is, User_r
  901. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  902. if !User_is {
  903. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  904. c.ServeJSON()
  905. return
  906. }
  907. T_name := c.GetString("T_name")
  908. T_Show, T_Show_err := c.GetInt("T_Show")
  909. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  910. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  911. T_deadline := c.GetString("T_deadline")
  912. T_scheme := c.GetString("T_scheme")
  913. T_collection := c.GetString("T_collection")
  914. T_collection_state, _ := c.GetInt("T_collection_state")
  915. T_collection_signature := c.GetString("T_collection_signature") // 完成编辑签字图片
  916. T_reporting := c.GetString("T_reporting")
  917. T_delivery := c.GetString("T_delivery")
  918. T_record := c.GetString("T_record")
  919. T_doc1 := c.GetString("T_doc1")
  920. T_pdf1 := c.GetString("T_pdf1") // 方案
  921. T_pdf1_stamp, _ := c.GetBool("T_pdf1_stamp") // 方案加盖公章
  922. T_doc2 := c.GetString("T_doc2")
  923. T_pdf2 := c.GetString("T_pdf2") // 证书
  924. T_pdf2_stamp, _ := c.GetBool("T_pdf2_stamp") // 报告加盖公章
  925. T_doc3 := c.GetString("T_doc3")
  926. T_pdf3 := c.GetString("T_pdf3")
  927. T_pdf4 := c.GetString("T_pdf4") // 验证标识
  928. T_pdf5 := c.GetString("T_pdf5") // 检测报告
  929. T_pdf6 := c.GetString("T_pdf6") // 原始记录
  930. T_VerifyDeviceDataStartTime := c.GetString("T_VerifyDeviceDataStartTime") // 验证设备数据开始时间
  931. T_VerifyDeviceDataEndTime := c.GetString("T_VerifyDeviceDataEndTime") // 验证设备数据开始时间
  932. T_BindDeviceDataStartTime := c.GetString("T_BindDeviceDataStartTime") // 绑定设备数据开始时间
  933. T_BindDeviceDataEndTime := c.GetString("T_BindDeviceDataEndTime") // 绑定设备数据结束时间
  934. T_sn := c.GetString("T_sn") // T_sn
  935. T_CalibrationExpirationTime := c.GetString("T_CalibrationExpirationTime") // 校准到期时间
  936. T_project := c.GetString("T_project") // 项目 负责人UUID
  937. T_province := c.GetString("T_province") // 省
  938. T_city := c.GetString("T_city") // 市
  939. T_district := c.GetString("T_district") // 区
  940. T_province_code := c.GetString("T_province_code") // 省 code
  941. T_city_code := c.GetString("T_city_code") // 市 code
  942. T_district_code := c.GetString("T_district_code") // 区 code
  943. T_category := c.GetString("T_category") // 类别
  944. T_device_type := c.GetString("T_device_type") // 设备类型
  945. T_volume := c.GetString("T_volume") // 规格/容积
  946. T_verify_type := c.GetString("T_verify_type") // 验证类型
  947. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  948. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  949. T_report_number := c.GetString("T_report_number") // 报告编号
  950. T_report_type := c.GetString("T_report_type") // 报告编号
  951. T_device_quantity, _ := c.GetInt("T_device_quantity") // 报告编号
  952. T_cnas, _ := c.GetInt("T_cnas") // cnas实验室
  953. T_task_id := c.GetString("T_task_id")
  954. r, is := Task.Read_Task(T_task_id)
  955. if !is {
  956. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  957. c.ServeJSON()
  958. return
  959. }
  960. if len(T_report_number) > 0 && T_report_number != "/" {
  961. t, exist := Task.Read_TaskbyT_report_number(T_report_number)
  962. if exist && r.T_task_id != t.T_task_id {
  963. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报告编号已存在!"}
  964. c.ServeJSON()
  965. return
  966. }
  967. }
  968. // .......
  969. clos := make([]string, 0)
  970. if len(T_name) > 0 {
  971. r.T_name = T_name
  972. clos = append(clos, "T_name")
  973. }
  974. if T_Show_err == nil {
  975. r.T_Show = T_Show
  976. clos = append(clos, "T_Show")
  977. }
  978. if len(T_VerifyTemplate_class) > 0 {
  979. r.T_VerifyTemplate_class = T_VerifyTemplate_class
  980. clos = append(clos, "T_VerifyTemplate_class")
  981. }
  982. if len(T_VerifyTemplate_id) > 0 {
  983. r.T_VerifyTemplate_id = T_VerifyTemplate_id
  984. clos = append(clos, "T_VerifyTemplate_id")
  985. }
  986. if len(T_deadline) > 0 {
  987. r.T_deadline = T_deadline
  988. clos = append(clos, "T_deadline")
  989. }
  990. if len(T_scheme) > 0 {
  991. r.T_scheme = T_scheme
  992. clos = append(clos, "T_scheme")
  993. }
  994. if len(T_collection) > 0 {
  995. r.T_collection = T_collection
  996. clos = append(clos, "T_collection")
  997. }
  998. if len(T_reporting) > 0 {
  999. r.T_reporting = T_reporting
  1000. clos = append(clos, "T_reporting")
  1001. }
  1002. if len(T_delivery) > 0 {
  1003. r.T_delivery = T_delivery
  1004. clos = append(clos, "T_delivery")
  1005. }
  1006. if len(T_record) > 0 {
  1007. r.T_record = T_record
  1008. clos = append(clos, "T_record")
  1009. }
  1010. // 完成编辑后设置实施结束时间
  1011. if T_collection_state == 4 {
  1012. r.T_collection_state = T_collection_state
  1013. clos = append(clos, "T_collection_state")
  1014. r.T_collection_signature = T_collection_signature
  1015. clos = append(clos, "T_collection_signature")
  1016. r.T_collection_end_time = time.Now().Format("2006-01-02 15:04:05")
  1017. clos = append(clos, "T_collection_end_time")
  1018. if len(r.T_collection_start_time) > 0 {
  1019. r.T_collection_time_interval, _ = lib.MinutesDifference(r.T_collection_start_time, r.T_collection_end_time)
  1020. // 扣除暂停时间
  1021. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 1)
  1022. if Task_Compute > 0 {
  1023. r.T_collection_time_interval -= float64(Task_Compute)
  1024. }
  1025. clos = append(clos, "T_collection_time_interval")
  1026. // 所需时间 > 超时时间
  1027. if r.T_collection_time_interval > Task.TaskCollectionTimeLimit && len(r.T_report_type) > 0 {
  1028. r.T_collection_overtime = r.T_collection_time_interval - Task.TaskCollectionTimeLimit // 超时时间
  1029. clos = append(clos, "T_collection_overtime")
  1030. }
  1031. // 通知 报告人员
  1032. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1033. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name), "")
  1034. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name))
  1035. }
  1036. // 添加已提交状态数据编辑记录
  1037. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, r.T_collection_state, "", "")
  1038. if err == nil {
  1039. r.T_collection_audit_record = auditRecordJson
  1040. clos = append(clos, "T_collection_audit_record")
  1041. }
  1042. }
  1043. if len(T_doc1) > 0 {
  1044. r.T_doc1 = T_doc1
  1045. clos = append(clos, "T_doc1")
  1046. }
  1047. // 验证报告内容T_pdf1,上传后将 当前任务 验证方案 标志 为 5 (0未完成 1已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交)
  1048. // 上传后设置方案结束时间,计算所需时间和超时时间
  1049. if len(T_pdf1) > 0 {
  1050. r.T_pdf1 = T_pdf1
  1051. clos = append(clos, "T_pdf1")
  1052. //r.T_pdf1_watermark = GetWatermarkPdf(r,T_pdf1,"T_pdf1")
  1053. //clos = append(clos, "T_pdf1_watermark")
  1054. go GetWatermarkPdf(r, T_pdf1, T_pdf1_stamp, "T_pdf1")
  1055. r.T_scheme_state = 5
  1056. clos = append(clos, "T_scheme_state")
  1057. // 添加已提交状态验证方案记录
  1058. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, "", User_r.T_uuid, r.T_scheme_state, "", "")
  1059. if err != nil {
  1060. return
  1061. }
  1062. r.T_scheme_audit_record = auditRecordJson
  1063. clos = append(clos, "T_scheme_audit_record")
  1064. r.T_scheme_end_time = time.Now().Format("2006-01-02 15:04:05")
  1065. clos = append(clos, "T_scheme_end_time")
  1066. r.T_scheme_time_interval, _ = lib.MinutesDifference(r.T_scheme_start_time, r.T_scheme_end_time)
  1067. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 0)
  1068. if Task_Compute > 0 {
  1069. r.T_scheme_time_interval -= float64(Task_Compute)
  1070. }
  1071. clos = append(clos, "T_scheme_time_interval")
  1072. // 所需时间 > 超时时间
  1073. if r.T_scheme_time_interval > Task.TaskSchemeTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1074. r.T_scheme_overtime = r.T_scheme_time_interval - Task.TaskSchemeTimeLimit[r.T_report_type] // 超时时间
  1075. if Task.TaskSchemeTimeLimit[r.T_report_type] == 0 {
  1076. r.T_scheme_overtime = 0
  1077. }
  1078. clos = append(clos, "T_scheme_overtime")
  1079. }
  1080. // 通知 实施人员进场
  1081. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1082. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name), "")
  1083. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name))
  1084. }
  1085. if len(T_doc2) > 0 {
  1086. r.T_doc2 = T_doc2
  1087. clos = append(clos, "T_doc2")
  1088. }
  1089. // 验证报告内容T_pdf2 ,上传后将 当前任务 报告编写 标志 为 1
  1090. // 上传后设置报告结束时间,计算所需时间和超时时间
  1091. if len(T_pdf2) > 0 {
  1092. r.T_pdf2 = T_pdf2
  1093. clos = append(clos, "T_pdf2")
  1094. //r.T_pdf2_watermark = GetWatermarkPdf(T_pdf2,"T_pdf1")
  1095. //clos = append(clos, "T_pdf2_watermark")
  1096. go GetWatermarkPdf(r, T_pdf2, T_pdf2_stamp, "T_pdf2")
  1097. r.T_reporting_state = 5
  1098. clos = append(clos, "T_reporting_state")
  1099. // 添加已提交状态验证报告记录
  1100. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, "", User_r.T_uuid, r.T_reporting_state, "", "")
  1101. if err == nil {
  1102. r.T_reporting_audit_record = auditRecordJson
  1103. clos = append(clos, "T_reporting_audit_record")
  1104. r.T_reporting_end_time = time.Now().Format("2006-01-02 15:04:05")
  1105. clos = append(clos, "T_reporting_end_time")
  1106. if len(r.T_reporting_start_time) > 0 {
  1107. r.T_reporting_time_interval, _ = lib.MinutesDifference(r.T_reporting_start_time, r.T_reporting_end_time)
  1108. clos = append(clos, "T_reporting_time_interval")
  1109. // 扣除暂停时间
  1110. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 2)
  1111. if Task_Compute > 0 {
  1112. r.T_reporting_time_interval -= float64(Task_Compute)
  1113. }
  1114. clos = append(clos, "T_reporting_time_interval")
  1115. // 所需时间 > 超时时间
  1116. if r.T_reporting_time_interval > Task.TaskReportingTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1117. r.T_reporting_overtime = r.T_reporting_time_interval - Task.TaskReportingTimeLimit[r.T_report_type] // 超时时间
  1118. if Task.TaskReportingTimeLimit[r.T_report_type] == 0 {
  1119. r.T_reporting_overtime = 0
  1120. }
  1121. clos = append(clos, "T_reporting_overtime")
  1122. }
  1123. }
  1124. }
  1125. // 通知 报告人员
  1126. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1127. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name), "")
  1128. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name))
  1129. }
  1130. if len(T_doc3) > 0 {
  1131. r.T_doc3 = T_doc3
  1132. clos = append(clos, "T_doc3")
  1133. }
  1134. if len(T_pdf3) > 0 {
  1135. r.T_pdf3 = T_pdf3
  1136. clos = append(clos, "T_pdf3")
  1137. }
  1138. // 验证标识内容T_pdf4 ,上传后将 当前任务 验证标识 标志 为 1
  1139. if len(T_pdf4) > 0 {
  1140. r.T_pdf4 = T_pdf4
  1141. clos = append(clos, "T_pdf4")
  1142. r.T_marking_state = 1
  1143. clos = append(clos, "T_marking_state")
  1144. }
  1145. if len(T_pdf5) > 0 {
  1146. r.T_pdf5 = T_pdf5
  1147. clos = append(clos, "T_pdf5")
  1148. r.T_examining_report_state = 1
  1149. clos = append(clos, "T_examining_report_state")
  1150. // 添加已提交状态 检测报告记录
  1151. auditRecordJson, err := Task.Add_AuditRecord(r.T_examining_report_audit_record, "", User_r.T_uuid, r.T_examining_report_state, "", "")
  1152. if err == nil {
  1153. r.T_examining_report_audit_record = auditRecordJson
  1154. clos = append(clos, "T_examining_report_audit_record")
  1155. r.T_examining_report_end_time = time.Now().Format("2006-01-02 15:04:05")
  1156. clos = append(clos, "T_examining_report_end_time")
  1157. if len(r.T_examining_report_start_time) > 0 {
  1158. r.T_examining_report_time_interval, _ = lib.MinutesDifference(r.T_examining_report_start_time, r.T_examining_report_end_time)
  1159. clos = append(clos, "T_examining_report_time_interval")
  1160. // 扣除暂停时间
  1161. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 3)
  1162. if Task_Compute > 0 {
  1163. r.T_examining_report_time_interval -= float64(Task_Compute)
  1164. }
  1165. clos = append(clos, "T_examining_report_time_interval")
  1166. }
  1167. }
  1168. // 通知 报告人员
  1169. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1170. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】检测报告 已提交", company_r.T_name, r.T_name), "")
  1171. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】检测报告 已提交", company_r.T_name, r.T_name))
  1172. }
  1173. if len(T_pdf6) > 0 {
  1174. r.T_pdf6 = T_pdf6
  1175. clos = append(clos, "T_pdf6")
  1176. r.T_examining_report_state = 1
  1177. clos = append(clos, "T_original_record_state")
  1178. // 添加已提交状态 原始记录 记录
  1179. auditRecordJson, err := Task.Add_AuditRecord(r.T_original_record_audit_record, "", User_r.T_uuid, r.T_original_record_state, "", "")
  1180. if err == nil {
  1181. r.T_original_record_audit_record = auditRecordJson
  1182. clos = append(clos, "T_original_record_audit_record")
  1183. r.T_original_record_end_time = time.Now().Format("2006-01-02 15:04:05")
  1184. clos = append(clos, "T_original_record_end_time")
  1185. if len(r.T_reporting_start_time) > 0 {
  1186. r.T_original_record_time_interval, _ = lib.MinutesDifference(r.T_original_record_start_time, r.T_original_record_end_time)
  1187. clos = append(clos, "T_original_record_time_interval")
  1188. // 扣除暂停时间
  1189. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 2)
  1190. if Task_Compute > 0 {
  1191. r.T_original_record_time_interval -= float64(Task_Compute)
  1192. }
  1193. clos = append(clos, "T_original_record_time_interval")
  1194. }
  1195. }
  1196. // 通知 报告人员
  1197. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1198. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】原始记录 已提交", company_r.T_name, r.T_name), "")
  1199. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】原始记录 已提交", company_r.T_name, r.T_name))
  1200. }
  1201. if len(T_VerifyDeviceDataStartTime) > 0 {
  1202. r.T_VerifyDeviceDataStartTime = T_VerifyDeviceDataStartTime
  1203. clos = append(clos, "T_VerifyDeviceDataStartTime")
  1204. }
  1205. if len(T_VerifyDeviceDataEndTime) > 0 {
  1206. r.T_VerifyDeviceDataEndTime = T_VerifyDeviceDataEndTime
  1207. clos = append(clos, "T_VerifyDeviceDataEndTime")
  1208. }
  1209. if len(T_BindDeviceDataStartTime) > 0 {
  1210. r.T_BindDeviceDataStartTime = T_BindDeviceDataStartTime
  1211. clos = append(clos, "T_BindDeviceDataStartTime")
  1212. }
  1213. if len(T_BindDeviceDataEndTime) > 0 {
  1214. r.T_BindDeviceDataEndTime = T_BindDeviceDataEndTime
  1215. clos = append(clos, "T_BindDeviceDataEndTime")
  1216. }
  1217. if len(T_sn) > 0 {
  1218. T_sn = strings.TrimSpace(T_sn)
  1219. r.T_sn = T_sn
  1220. clos = append(clos, "T_sn")
  1221. }
  1222. if len(T_CalibrationExpirationTime) > 0 {
  1223. r.T_CalibrationExpirationTime = T_CalibrationExpirationTime
  1224. clos = append(clos, "T_CalibrationExpirationTime")
  1225. }
  1226. // 从3.0获取校准时间
  1227. if len(T_sn) > 0 && len(T_CalibrationExpirationTime) == 0 {
  1228. go func(r Task.Task, T_sn, T_CalibrationExpirationTime string) {
  1229. NatsServer.Cold_UpdateDevice_CalibrationTime(T_sn, T_CalibrationExpirationTime)
  1230. device, err := NatsServer.Cold_ReadDeviceByT_sn(T_sn)
  1231. if err == nil {
  1232. if !device.T_CalibrationTime.IsZero() {
  1233. r.T_CalibrationExpirationTime = device.T_CalibrationTime.Format("2006-01-02")
  1234. clos = append(clos, "T_CalibrationExpirationTime")
  1235. Task.Update_Task(r, "T_CalibrationExpirationTime")
  1236. }
  1237. }
  1238. }(r, T_sn, T_CalibrationExpirationTime)
  1239. }
  1240. if len(T_project) > 0 {
  1241. r.T_project = T_project
  1242. clos = append(clos, "T_project")
  1243. }
  1244. if len(T_province) > 0 {
  1245. r.T_province = T_province
  1246. clos = append(clos, "T_province")
  1247. }
  1248. if len(T_city) > 0 {
  1249. r.T_city = T_city
  1250. clos = append(clos, "T_city")
  1251. }
  1252. if len(T_district) > 0 {
  1253. r.T_district = T_district
  1254. clos = append(clos, "T_district")
  1255. }
  1256. if len(T_province_code) > 0 {
  1257. r.T_province_code = T_province_code
  1258. clos = append(clos, "T_province_code")
  1259. }
  1260. if len(T_city_code) > 0 {
  1261. r.T_city_code = T_city_code
  1262. clos = append(clos, "T_city_code")
  1263. }
  1264. if len(T_district_code) > 0 {
  1265. r.T_district_code = T_district_code
  1266. clos = append(clos, "T_district_code")
  1267. }
  1268. if len(T_category) > 0 {
  1269. r.T_category = T_category
  1270. clos = append(clos, "T_category")
  1271. }
  1272. if len(T_device_type) > 0 {
  1273. r.T_device_type = T_device_type
  1274. clos = append(clos, "T_device_type")
  1275. }
  1276. if len(T_volume) > 0 {
  1277. r.T_volume = T_volume
  1278. clos = append(clos, "T_volume")
  1279. }
  1280. if len(T_verify_type) > 0 {
  1281. r.T_verify_type = T_verify_type
  1282. clos = append(clos, "T_verify_type")
  1283. }
  1284. if len(T_subject_matter) > 0 {
  1285. r.T_subject_matter = T_subject_matter
  1286. clos = append(clos, "T_subject_matter")
  1287. }
  1288. if len(T_temp_range) > 0 {
  1289. r.T_temp_range = T_temp_range
  1290. clos = append(clos, "T_temp_range")
  1291. }
  1292. if len(T_report_number) > 0 {
  1293. r.T_report_number = T_report_number
  1294. clos = append(clos, "T_report_number")
  1295. }
  1296. if len(T_report_type) > 0 {
  1297. r.T_report_type = T_report_type
  1298. clos = append(clos, "T_report_type")
  1299. }
  1300. if T_device_quantity > 0 {
  1301. r.T_device_quantity = T_device_quantity
  1302. clos = append(clos, "T_device_quantity")
  1303. }
  1304. r.T_cnas = T_cnas
  1305. clos = append(clos, "T_cnas")
  1306. if !Task.Update_Task(r, clos...) {
  1307. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1308. c.ServeJSON()
  1309. return
  1310. }
  1311. // 添加任务操作日志
  1312. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改", r)
  1313. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改", r)
  1314. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1315. c.ServeJSON()
  1316. return
  1317. }
  1318. // 修改验证方案状态
  1319. func (c *TaskController) UpSchemeState() {
  1320. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1321. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1322. if !Admin_is && !User_is {
  1323. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1324. c.ServeJSON()
  1325. return
  1326. }
  1327. operate_uuid := ""
  1328. if Admin_is {
  1329. operate_uuid = Admin_r.T_uuid
  1330. }
  1331. if User_is {
  1332. operate_uuid = User_r.T_uuid
  1333. }
  1334. T_scheme_state, _ := c.GetInt("T_scheme_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1335. T_reason := c.GetString("T_reason") // 退回原因
  1336. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1337. T_task_id := c.GetString("T_task_id")
  1338. r, is := Task.Read_Task(T_task_id)
  1339. if !is {
  1340. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1341. c.ServeJSON()
  1342. return
  1343. }
  1344. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1345. clos := make([]string, 0)
  1346. if T_scheme_state > 0 {
  1347. r.T_scheme_state = T_scheme_state
  1348. clos = append(clos, "T_scheme_state")
  1349. }
  1350. if len(T_signature) > 0 {
  1351. r.T_scheme_signature = T_signature
  1352. clos = append(clos, "T_scheme_signature")
  1353. }
  1354. if T_scheme_state == Task.TaskSchemeStateClientReturn || T_scheme_state == Task.TaskSchemeStateReturn {
  1355. r.T_scheme_return_times += 1
  1356. clos = append(clos, "T_scheme_return_times")
  1357. // 客户退回时新增驳回次数和驳回记录
  1358. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  1359. r.T_reject_times += 1
  1360. var rejectRecordList []Task.AuditRecord
  1361. if len(r.T_reject_record) > 0 {
  1362. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1363. if err != nil {
  1364. logs.Error("JSON 反序列化失败:", err)
  1365. return
  1366. }
  1367. }
  1368. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1369. T_uuid: User_r.T_uuid,
  1370. T_state: T_scheme_state,
  1371. T_reason: T_reason,
  1372. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1373. T_type: "scheme",
  1374. })
  1375. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1376. if err != nil {
  1377. logs.Error("JSON 反序列化失败:", err)
  1378. return
  1379. }
  1380. r.T_reject_record = string(rejectRecordJson)
  1381. clos = append(clos, "T_reject_times")
  1382. clos = append(clos, "T_reject_record")
  1383. }
  1384. }
  1385. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_scheme_state, T_reason, "")
  1386. if err != nil {
  1387. return
  1388. }
  1389. r.T_scheme_audit_record = auditRecordJson
  1390. clos = append(clos, "T_scheme_audit_record")
  1391. if !Task.Update_Task(r, clos...) {
  1392. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1393. c.ServeJSON()
  1394. return
  1395. }
  1396. //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1397. // 已提交
  1398. if T_scheme_state == Task.TaskSchemeStateSubmitted {
  1399. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  1400. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
  1401. }
  1402. // 已通过
  1403. if T_scheme_state == Task.TaskSchemeStatePass {
  1404. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1405. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  1406. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
  1407. }
  1408. // 已退回(负责人)
  1409. if T_scheme_state == Task.TaskSchemeStateReturn {
  1410. 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), "")
  1411. 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))
  1412. }
  1413. // 已退回(客户)
  1414. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  1415. 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), "")
  1416. 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))
  1417. 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), "")
  1418. 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))
  1419. 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))
  1420. }
  1421. // 添加任务操作日志
  1422. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证方案状态", r)
  1423. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证方案状态", r)
  1424. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1425. c.ServeJSON()
  1426. return
  1427. }
  1428. // 修改验证报告状态
  1429. func (c *TaskController) UpReportingState() {
  1430. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1431. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1432. if !Admin_is && !User_is {
  1433. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1434. c.ServeJSON()
  1435. return
  1436. }
  1437. operate_uuid := ""
  1438. if Admin_is {
  1439. operate_uuid = Admin_r.T_uuid
  1440. }
  1441. if User_is {
  1442. operate_uuid = User_r.T_uuid
  1443. }
  1444. T_reporting_state, _ := c.GetInt("T_reporting_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1445. T_reason := c.GetString("T_reason") // 退回原因
  1446. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1447. T_task_id := c.GetString("T_task_id")
  1448. r, is := Task.Read_Task(T_task_id)
  1449. if !is {
  1450. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1451. c.ServeJSON()
  1452. return
  1453. }
  1454. //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1455. clos := make([]string, 0)
  1456. if T_reporting_state > 0 {
  1457. r.T_reporting_state = T_reporting_state
  1458. clos = append(clos, "T_reporting_state")
  1459. }
  1460. if T_reporting_state == Task.TaskReportingStatePass {
  1461. r.T_reporting_pass_time = time.Now().Format("2006-01-02 15:04:05")
  1462. clos = append(clos, "T_reporting_pass_time")
  1463. }
  1464. if len(T_signature) > 0 {
  1465. r.T_reporting_signature = T_signature
  1466. clos = append(clos, "T_reporting_signature")
  1467. }
  1468. if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
  1469. r.T_reporting_return_times += 1
  1470. clos = append(clos, "T_reporting_return_times")
  1471. // 客户退回时新增驳回次数和驳回记录
  1472. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1473. r.T_reject_times += 1
  1474. var rejectRecordList []Task.AuditRecord
  1475. if len(r.T_reject_record) > 0 {
  1476. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1477. if err != nil {
  1478. logs.Error("JSON 反序列化失败:", err)
  1479. return
  1480. }
  1481. }
  1482. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1483. T_uuid: User_r.T_uuid,
  1484. T_state: T_reporting_state,
  1485. T_reason: T_reason,
  1486. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1487. T_type: "reporting",
  1488. })
  1489. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1490. if err != nil {
  1491. logs.Error("JSON 反序列化失败:", err)
  1492. return
  1493. }
  1494. r.T_reject_record = string(rejectRecordJson)
  1495. clos = append(clos, "T_reject_times")
  1496. clos = append(clos, "T_reject_record")
  1497. }
  1498. }
  1499. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
  1500. if err != nil {
  1501. return
  1502. }
  1503. r.T_reporting_audit_record = auditRecordJson
  1504. clos = append(clos, "T_reporting_audit_record")
  1505. // 查询信息采集信息
  1506. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1507. if !is {
  1508. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  1509. c.ServeJSON()
  1510. return
  1511. }
  1512. // 验证报告客户审核通过后设置结束时间
  1513. if T_reporting_state == Task.TaskReportingStateClientPass {
  1514. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  1515. r.T_time_interval, err = lib.MinutesDifference(infoCollection.T_start_time, r.T_end_time)
  1516. if err != nil {
  1517. logs.Error("UpReportingState:", err.Error())
  1518. }
  1519. clos = append(clos, "T_end_time")
  1520. clos = append(clos, "T_time_interval")
  1521. }
  1522. if !Task.Update_Task(r, clos...) {
  1523. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1524. c.ServeJSON()
  1525. return
  1526. }
  1527. // 已通过
  1528. if T_reporting_state == Task.TaskReportingStatePass {
  1529. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1530. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1531. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1532. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1533. }
  1534. // 已退回
  1535. if T_reporting_state == Task.TaskReportingStateReturn {
  1536. 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), "")
  1537. 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))
  1538. }
  1539. // 已通过(客户) 通知销售
  1540. if T_reporting_state == Task.TaskReportingStateClientPass {
  1541. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】 %s,请尽快安排客户回款", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1542. }
  1543. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1544. 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), "")
  1545. 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))
  1546. 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), "")
  1547. 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))
  1548. 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), "")
  1549. 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))
  1550. //System.Add_News(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1551. //go wx.WxSend(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
  1552. System.Add_News(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason), "")
  1553. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason))
  1554. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason))
  1555. }
  1556. // 添加任务操作日志
  1557. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证报告状态", r)
  1558. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证报告状态", r)
  1559. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1560. c.ServeJSON()
  1561. return
  1562. }
  1563. // 修改检测报告状态
  1564. func (c *TaskController) UpExaminingReportState() {
  1565. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1566. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1567. if !Admin_is && !User_is {
  1568. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1569. c.ServeJSON()
  1570. return
  1571. }
  1572. operate_uuid := ""
  1573. if Admin_is {
  1574. operate_uuid = Admin_r.T_uuid
  1575. }
  1576. if User_is {
  1577. operate_uuid = User_r.T_uuid
  1578. }
  1579. T_examining_report_state, _ := c.GetInt("T_examining_report_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1580. T_reason := c.GetString("T_reason") // 退回原因
  1581. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1582. T_task_id := c.GetString("T_task_id")
  1583. r, is := Task.Read_Task(T_task_id)
  1584. if !is {
  1585. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1586. c.ServeJSON()
  1587. return
  1588. }
  1589. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1590. clos := make([]string, 0)
  1591. if T_examining_report_state > 0 {
  1592. r.T_examining_report_state = T_examining_report_state
  1593. clos = append(clos, "T_examining_report_state")
  1594. }
  1595. if len(T_signature) > 0 {
  1596. r.T_examining_report_signature = T_signature
  1597. clos = append(clos, "T_examining_report_signature")
  1598. }
  1599. if T_examining_report_state == Task.TaskExaminingReportStateClientReturn || T_examining_report_state == Task.TaskExaminingReportStateReturn {
  1600. r.T_examining_report_return_times += 1
  1601. clos = append(clos, "T_examining_report_return_times")
  1602. // 客户退回时新增驳回次数和驳回记录
  1603. if T_examining_report_state == Task.TaskExaminingReportStateClientReturn {
  1604. r.T_reject_times += 1
  1605. var rejectRecordList []Task.AuditRecord
  1606. if len(r.T_reject_record) > 0 {
  1607. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1608. if err != nil {
  1609. logs.Error("JSON 反序列化失败:", err)
  1610. return
  1611. }
  1612. }
  1613. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1614. T_uuid: User_r.T_uuid,
  1615. T_state: T_examining_report_state,
  1616. T_reason: T_reason,
  1617. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1618. T_type: "examining_report",
  1619. })
  1620. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1621. if err != nil {
  1622. logs.Error("JSON 反序列化失败:", err)
  1623. return
  1624. }
  1625. r.T_reject_record = string(rejectRecordJson)
  1626. clos = append(clos, "T_reject_times")
  1627. clos = append(clos, "T_reject_record")
  1628. }
  1629. }
  1630. auditRecordJson, err := Task.Add_AuditRecord(r.T_examining_report_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_examining_report_state, T_reason, "")
  1631. if err != nil {
  1632. return
  1633. }
  1634. r.T_examining_report_audit_record = auditRecordJson
  1635. clos = append(clos, "T_examining_report_audit_record")
  1636. if !Task.Update_Task(r, clos...) {
  1637. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1638. c.ServeJSON()
  1639. return
  1640. }
  1641. // 已提交
  1642. if T_examining_report_state == Task.TaskExaminingReportStateSubmitted {
  1643. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】检测报告 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state]), "")
  1644. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】检测报告 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state]))
  1645. }
  1646. // 已通过
  1647. if T_examining_report_state == Task.TaskExaminingReportStatePass {
  1648. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1649. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】检测报告 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state]), "")
  1650. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】检测报告 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state]))
  1651. }
  1652. // 已退回(负责人)
  1653. if T_examining_report_state == Task.TaskExaminingReportStateReturn {
  1654. System.Add_News(r.T_scheme, fmt.Sprintf("【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason), "")
  1655. go wx.WxSend(r.T_scheme, fmt.Sprintf("【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason))
  1656. }
  1657. // 已退回(客户)
  1658. if T_examining_report_state == Task.TaskExaminingReportStateClientReturn {
  1659. System.Add_News(r.T_scheme, fmt.Sprintf("!!!【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason), "")
  1660. go wx.WxSend(r.T_scheme, fmt.Sprintf("!!!【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason))
  1661. System.Add_News(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason), "")
  1662. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason))
  1663. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("!!!【%s-%s】检测报告 %s,%s", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state], T_reason))
  1664. }
  1665. // 添加任务操作日志
  1666. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改检测报告状态", r)
  1667. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改检测报告状态", r)
  1668. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1669. c.ServeJSON()
  1670. return
  1671. }
  1672. // 修改原始数据状态
  1673. func (c *TaskController) UpOriginalRecordState() {
  1674. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1675. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1676. if !Admin_is && !User_is {
  1677. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1678. c.ServeJSON()
  1679. return
  1680. }
  1681. operate_uuid := ""
  1682. if Admin_is {
  1683. operate_uuid = Admin_r.T_uuid
  1684. }
  1685. if User_is {
  1686. operate_uuid = User_r.T_uuid
  1687. }
  1688. T_original_record_state, _ := c.GetInt("T_original_record_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1689. T_reason := c.GetString("T_reason") // 退回原因
  1690. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1691. T_task_id := c.GetString("T_task_id")
  1692. r, is := Task.Read_Task(T_task_id)
  1693. if !is {
  1694. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1695. c.ServeJSON()
  1696. return
  1697. }
  1698. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1699. clos := make([]string, 0)
  1700. if T_original_record_state > 0 {
  1701. r.T_original_record_state = T_original_record_state
  1702. clos = append(clos, "T_original_record_state")
  1703. }
  1704. if len(T_signature) > 0 {
  1705. r.T_original_record_signature = T_signature
  1706. clos = append(clos, "T_original_record_signature")
  1707. }
  1708. if T_original_record_state == Task.TaskOriginalRecordStateReturn {
  1709. r.T_original_record_return_times += 1
  1710. clos = append(clos, "T_original_record_return_times")
  1711. }
  1712. auditRecordJson, err := Task.Add_AuditRecord(r.T_original_record_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_original_record_state, T_reason, "")
  1713. if err != nil {
  1714. return
  1715. }
  1716. r.T_original_record_audit_record = auditRecordJson
  1717. clos = append(clos, "T_original_record_audit_record")
  1718. if !Task.Update_Task(r, clos...) {
  1719. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1720. c.ServeJSON()
  1721. return
  1722. }
  1723. // 已提交
  1724. if T_original_record_state == Task.TaskOriginalRecordStateSubmitted {
  1725. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】原始数据 %s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state]), "")
  1726. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】原始数据 %s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state]))
  1727. }
  1728. // 已通过
  1729. if T_original_record_state == Task.TaskOriginalRecordStatePass {
  1730. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1731. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】原始数据 %s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state]), "")
  1732. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】原始数据 %s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state]))
  1733. }
  1734. // 已退回(负责人)
  1735. if T_original_record_state == Task.TaskOriginalRecordStateReturn {
  1736. System.Add_News(r.T_scheme, fmt.Sprintf("【%s-%s】原始数据 %s,%s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state], T_reason), "")
  1737. go wx.WxSend(r.T_scheme, fmt.Sprintf("【%s-%s】原始数据 %s,%s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state], T_reason))
  1738. }
  1739. // 添加任务操作日志
  1740. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改原始数据状态", r)
  1741. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改原始数据状态", r)
  1742. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1743. c.ServeJSON()
  1744. return
  1745. }
  1746. // 进场 改成 方案开始
  1747. func (c *TaskController) EnterArea() {
  1748. // 验证登录 User_is, User_r
  1749. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1750. if !User_is {
  1751. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1752. c.ServeJSON()
  1753. return
  1754. }
  1755. T_task_id := c.GetString("T_task_id")
  1756. r, is := Task.Read_Task(T_task_id)
  1757. if !is {
  1758. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1759. c.ServeJSON()
  1760. return
  1761. }
  1762. // 方案开始
  1763. if len(r.T_scheme_start_time) == 0 {
  1764. r.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
  1765. Task.Update_Task(r, "T_scheme_start_time")
  1766. }
  1767. // 添加任务操作日志
  1768. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "方案开始", r)
  1769. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "方案开始", r)
  1770. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1771. c.ServeJSON()
  1772. return
  1773. }
  1774. // 开始验证
  1775. func (c *TaskController) StartVerify() {
  1776. // 验证登录 User_is, User_r
  1777. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1778. if !User_is {
  1779. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1780. c.ServeJSON()
  1781. return
  1782. }
  1783. T_task_id := c.GetString("T_task_id")
  1784. T_time := c.GetString("T_time") // 进场时间
  1785. r, is := Task.Read_Task(T_task_id)
  1786. if !is {
  1787. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1788. c.ServeJSON()
  1789. return
  1790. }
  1791. if len(r.T_collection_start_time) == 0 {
  1792. r.T_collection_start_time = T_time
  1793. if !Task.Update_Task(r, "T_collection_start_time") {
  1794. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
  1795. c.ServeJSON()
  1796. return
  1797. }
  1798. // 添加任务操作日志
  1799. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
  1800. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
  1801. }
  1802. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1803. c.ServeJSON()
  1804. return
  1805. }
  1806. // 删除-
  1807. func (c *TaskController) Del() {
  1808. // 验证登录 User_is, User_r
  1809. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1810. if !User_is {
  1811. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1812. c.ServeJSON()
  1813. return
  1814. }
  1815. T_task_id := c.GetString("T_task_id")
  1816. if r, is := Task.Read_Task(T_task_id); is {
  1817. if !Task.Delete_Task(r) {
  1818. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  1819. c.ServeJSON()
  1820. return
  1821. }
  1822. // 添加任务操作日志
  1823. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
  1824. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
  1825. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1826. c.ServeJSON()
  1827. return
  1828. }
  1829. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1830. c.ServeJSON()
  1831. return
  1832. }
  1833. // 列表 -
  1834. func (c *TaskController) Logs_List() {
  1835. // 验证登录 User_is, User_r
  1836. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1837. if !User_is {
  1838. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1839. c.ServeJSON()
  1840. return
  1841. }
  1842. var r_jsons lib.R_JSONS
  1843. page, _ := c.GetInt("page")
  1844. if page < 1 {
  1845. page = 1
  1846. }
  1847. page_z, _ := c.GetInt("page_z")
  1848. if page_z < 1 {
  1849. page_z = conf.Page_size
  1850. }
  1851. T_task_id := c.GetString("T_task_id")
  1852. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1853. var cnt int
  1854. List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
  1855. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1856. r_jsons.List = List
  1857. r_jsons.Page = page
  1858. r_jsons.Page_size = int(page_size)
  1859. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1860. r_jsons.Num = cnt
  1861. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1862. c.ServeJSON()
  1863. return
  1864. }
  1865. // 查询图片生成状态
  1866. func (c *TaskController) DeviceData_JPGState() {
  1867. T_task_id := c.GetString("T_task_id")
  1868. T_remark := c.GetString("T_remark")
  1869. jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
  1870. if !is {
  1871. c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
  1872. c.ServeJSON()
  1873. return
  1874. }
  1875. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
  1876. c.ServeJSON()
  1877. return
  1878. }
  1879. // 生成温度图片
  1880. func (c *TaskController) DeviceData_JPG() {
  1881. StartTime := c.GetString("StartTime")
  1882. if len(StartTime) > 0 {
  1883. _, ok := lib.TimeStrToTime(StartTime)
  1884. if !ok {
  1885. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1886. c.ServeJSON()
  1887. return
  1888. }
  1889. }
  1890. EndTime := c.GetString("EndTime")
  1891. if len(EndTime) > 0 {
  1892. _, ok := lib.TimeStrToTime(EndTime)
  1893. if !ok {
  1894. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1895. c.ServeJSON()
  1896. return
  1897. }
  1898. } else {
  1899. EndTime = time.Now().Format("2006-01-02 15:04:05")
  1900. }
  1901. T_remark := c.GetString("T_remark")
  1902. TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
  1903. TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
  1904. if TemperatureMin == 0 {
  1905. TemperatureMin = 2
  1906. }
  1907. if TemperatureMax == 0 {
  1908. TemperatureMax = 8
  1909. }
  1910. T_task_id := c.GetString("T_task_id")
  1911. Task_r, is := Task.Read_Task(T_task_id)
  1912. if !is {
  1913. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  1914. c.ServeJSON()
  1915. return
  1916. }
  1917. if Task_r.T_collection_state == 2 {
  1918. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  1919. c.ServeJSON()
  1920. return
  1921. }
  1922. deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  1923. if !is {
  1924. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  1925. c.ServeJSON()
  1926. return
  1927. }
  1928. Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
  1929. // 生成图片
  1930. go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
  1931. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1932. c.ServeJSON()
  1933. return
  1934. }
  1935. // SyncInfoCollection 同步信息采集表
  1936. func (c *TaskController) SyncInfoCollection() {
  1937. T_task_id := c.GetString("T_task_id")
  1938. T_source, _ := c.GetInt("T_source")
  1939. task, is := Task.Read_Task(T_task_id)
  1940. if !is {
  1941. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1942. c.ServeJSON()
  1943. return
  1944. }
  1945. // 获取信息采集表模版信息
  1946. InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
  1947. InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
  1948. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  1949. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  1950. InfoCollectionDataMap := make(map[string]string)
  1951. for _, data := range InfoCollection_Data {
  1952. InfoCollectionDataMap[data.T_name] = data.T_value
  1953. }
  1954. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  1955. for _, v := range Data {
  1956. if len(v.T_value) > 0 {
  1957. continue
  1958. }
  1959. if InfoCollectionDataMap[v.T_name] == "" {
  1960. continue
  1961. }
  1962. val := VerifyTemplate.VerifyTemplateMapData{
  1963. T_source: T_source,
  1964. T_task_id: task.T_task_id,
  1965. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  1966. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  1967. T_flow_sort: v.T_flow_sort,
  1968. T_max_time: v.T_max_time,
  1969. T_min_time: v.T_min_time,
  1970. T_value: InfoCollectionDataMap[v.T_name],
  1971. }
  1972. MapDataList = append(MapDataList, val)
  1973. }
  1974. var ids []int64
  1975. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  1976. if !is {
  1977. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  1978. c.ServeJSON()
  1979. return
  1980. }
  1981. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  1982. c.ServeJSON()
  1983. return
  1984. }
  1985. // 退回记录列表
  1986. func (c *TaskController) AuditRecordList() {
  1987. // 验证登录 User_is, User_r
  1988. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1989. if !User_is {
  1990. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1991. c.ServeJSON()
  1992. return
  1993. }
  1994. T_task_id := c.GetString("T_task_id")
  1995. T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
  1996. //T_task 驳回记录
  1997. //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1998. //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  1999. //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  2000. T_state, _ := c.GetInt("T_state") // -1 获取全部
  2001. r, is := Task.Read_Task(T_task_id)
  2002. if !is {
  2003. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2004. c.ServeJSON()
  2005. return
  2006. }
  2007. var auditRecordList []Task.AuditRecord
  2008. switch T_type {
  2009. case "T_task":
  2010. T_state = -1
  2011. if len(r.T_reject_record) > 0 {
  2012. err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
  2013. if err != nil {
  2014. logs.Error("JSON 反序列化失败:", err)
  2015. return
  2016. }
  2017. }
  2018. case "T_scheme":
  2019. if len(r.T_scheme_audit_record) > 0 {
  2020. err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
  2021. if err != nil {
  2022. logs.Error("JSON 反序列化失败:", err)
  2023. return
  2024. }
  2025. }
  2026. case "T_collection":
  2027. if len(r.T_collection_audit_record) > 0 {
  2028. err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
  2029. if err != nil {
  2030. logs.Error("JSON 反序列化失败:", err)
  2031. return
  2032. }
  2033. }
  2034. case "T_reporting":
  2035. if len(r.T_reporting_audit_record) > 0 {
  2036. err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
  2037. if err != nil {
  2038. logs.Error("JSON 反序列化失败:", err)
  2039. return
  2040. }
  2041. }
  2042. case "T_examining_report":
  2043. if len(r.T_examining_report_audit_record) > 0 {
  2044. err := json.Unmarshal([]byte(r.T_examining_report_audit_record), &auditRecordList)
  2045. if err != nil {
  2046. logs.Error("JSON 反序列化失败:", err)
  2047. return
  2048. }
  2049. }
  2050. case "T_original_record":
  2051. if len(r.T_original_record_audit_record) > 0 {
  2052. err := json.Unmarshal([]byte(r.T_original_record_audit_record), &auditRecordList)
  2053. if err != nil {
  2054. logs.Error("JSON 反序列化失败:", err)
  2055. return
  2056. }
  2057. }
  2058. }
  2059. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  2060. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  2061. var auditRecordList2 []Task.AuditRecord
  2062. // 返回全部
  2063. if T_state == -1 {
  2064. for i := 0; i < len(auditRecordList); i++ {
  2065. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  2066. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  2067. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  2068. }
  2069. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  2070. c.ServeJSON()
  2071. return
  2072. }
  2073. if T_state == -2 {
  2074. for i := 0; i < len(auditRecordList); i++ {
  2075. if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
  2076. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  2077. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  2078. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  2079. }
  2080. }
  2081. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  2082. c.ServeJSON()
  2083. return
  2084. }
  2085. for i := 0; i < len(auditRecordList); i++ {
  2086. if auditRecordList[i].T_state == T_state {
  2087. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  2088. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  2089. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  2090. }
  2091. }
  2092. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  2093. c.ServeJSON()
  2094. return
  2095. }
  2096. // 存档生成图片
  2097. func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
  2098. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  2099. State: 1,
  2100. Msg: "图片生成中",
  2101. Url: "",
  2102. })
  2103. msg := ""
  2104. state := 2
  2105. url := ""
  2106. if TemperatureMin == 0 {
  2107. TemperatureMin = 2
  2108. }
  2109. if TemperatureMax == 0 {
  2110. TemperatureMax = 8
  2111. }
  2112. var ymin, ymax float64
  2113. var xminT, xmaxT time.Time
  2114. if len(deviceList) > 0 {
  2115. ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
  2116. }
  2117. // 创建一个新的绘图
  2118. p := plot.New()
  2119. // 设置绘图标题和标签
  2120. p.Title.Text = "温度折线图"
  2121. //p.Legend.ThumbnailWidth = 5 * vg.Inch
  2122. p.X.Label.Text = "时间"
  2123. p.Y.Label.Text = "温度"
  2124. var chData = make(chan int, 10)
  2125. var jobGroup sync.WaitGroup
  2126. var device = make([]Device.DeviceCount, len(deviceList))
  2127. // 创建温度线
  2128. for i := 0; i < len(deviceList); i++ {
  2129. chData <- 1
  2130. jobGroup.Add(1)
  2131. go func(index int) {
  2132. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  2133. defer func() {
  2134. <-chData // 完成时chan取出1个
  2135. jobGroup.Done() // 完成时将等待组值减1
  2136. }()
  2137. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  2138. ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
  2139. if ymin > ymin_ {
  2140. ymin = ymin_
  2141. }
  2142. if ymax < ymax_ {
  2143. ymax = ymax_
  2144. }
  2145. if xminT.After(minTime_) && !minTime_.IsZero() {
  2146. xminT = minTime_
  2147. }
  2148. if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
  2149. xmaxT = maxTime_
  2150. }
  2151. r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  2152. device[index] = Device.DeviceCount{
  2153. T_id: id,
  2154. T_sn: sn,
  2155. Num: r_maps_num,
  2156. }
  2157. if r_maps_num == 0 {
  2158. return
  2159. }
  2160. pts := make(plotter.XYs, len(r_maps))
  2161. for j, d := range r_maps {
  2162. t, _ := lib.TimeStrToTime(d.T_time)
  2163. pts[j].X = float64(t.Unix())
  2164. pts[j].Y = float64(d.T_t)
  2165. }
  2166. line, err := plotter.NewLine(pts)
  2167. if err != nil {
  2168. return
  2169. }
  2170. line.Color = randomColor(index)
  2171. p.Add(line)
  2172. }(i)
  2173. }
  2174. jobGroup.Wait()
  2175. xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
  2176. // 添加最高,最低标准线 用红色虚线标识
  2177. p.Add(horizontalLine(xmin, xmax, TemperatureMin))
  2178. p.Add(horizontalLine(xmin, xmax, TemperatureMax))
  2179. if ymax < 8 {
  2180. ymax = 8
  2181. }
  2182. if ymin > 0 {
  2183. ymin = 0
  2184. }
  2185. p.Y.Min, p.Y.Max = ymin, ymax
  2186. p.X.Min, p.X.Max = xmin, xmax
  2187. p.Y.Tick.Marker = commaTicks{}
  2188. //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
  2189. p.X.Tick.Marker = timeTicks{}
  2190. p.X.Tick.Label.Rotation = math.Pi / 5
  2191. p.X.Tick.Label.YAlign = draw.YCenter
  2192. p.X.Tick.Label.XAlign = draw.XRight
  2193. filename := "jpg" + time.Now().Format("20060102150405")
  2194. // 保存文件
  2195. if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
  2196. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  2197. State: 3,
  2198. Msg: "图片生成失败",
  2199. Url: url,
  2200. })
  2201. logs.Error(lib.FuncName(), "生成图片失败", err)
  2202. return
  2203. }
  2204. if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
  2205. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  2206. State: 3,
  2207. Msg: "图片上传七牛云失败",
  2208. Url: url,
  2209. })
  2210. logs.Error(lib.FuncName(), "上传七牛云失败")
  2211. return
  2212. }
  2213. //删除目录
  2214. os.Remove("ofile/" + filename + ".jpg")
  2215. msg = "图片生成成功"
  2216. url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
  2217. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  2218. State: state,
  2219. Msg: msg,
  2220. Url: url,
  2221. Device: device,
  2222. })
  2223. return
  2224. }
  2225. func horizontalLine(xmin, xmax, y float64) *plotter.Line {
  2226. pts := make(plotter.XYs, 2)
  2227. pts[0].X = xmin
  2228. pts[0].Y = y
  2229. pts[1].X = xmax
  2230. pts[1].Y = y
  2231. line, err := plotter.NewLine(pts)
  2232. if err != nil {
  2233. panic(any(err))
  2234. }
  2235. line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
  2236. line.Color = color.RGBA{R: 255, A: 255}
  2237. return line
  2238. }
  2239. type timeTicks struct{}
  2240. func (timeTicks) Ticks(min, max float64) []plot.Tick {
  2241. tks := plot.TimeTicks{}.Ticks(min, max)
  2242. for i, t := range tks {
  2243. //if t.Label == "" { // Skip minor ticks, they are fine.
  2244. // continue
  2245. //}
  2246. tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
  2247. }
  2248. return tks
  2249. }
  2250. type commaTicks struct{}
  2251. // Ticks computes the default tick marks, but inserts commas
  2252. // into the labels for the major tick marks.
  2253. func (commaTicks) Ticks(min, max float64) []plot.Tick {
  2254. tks := plot.DefaultTicks{}.Ticks(min, max)
  2255. for i, t := range tks {
  2256. //if t.Label == "" { // Skip minor ticks, they are fine.
  2257. // continue
  2258. //}
  2259. tks[i].Label = fmt.Sprintf("%.0f", t.Value)
  2260. }
  2261. return tks
  2262. }
  2263. // 生成随机颜色的辅助函数
  2264. func randomColor(i int) color.RGBA {
  2265. var colors []color.RGBA
  2266. colors = append(colors,
  2267. color.RGBA{R: 52, G: 152, B: 219, A: 255},
  2268. color.RGBA{R: 230, G: 126, B: 34, A: 255},
  2269. color.RGBA{R: 142, G: 68, B: 173, A: 255},
  2270. color.RGBA{R: 211, G: 84, B: 0, A: 255},
  2271. color.RGBA{R: 231, G: 76, B: 60, A: 255},
  2272. color.RGBA{R: 26, G: 188, B: 156, A: 255},
  2273. color.RGBA{R: 243, G: 156, B: 18, A: 255},
  2274. color.RGBA{R: 22, G: 160, B: 133, A: 255},
  2275. color.RGBA{R: 46, G: 204, B: 113, A: 255},
  2276. color.RGBA{R: 39, G: 174, B: 96, A: 255},
  2277. color.RGBA{R: 41, G: 128, B: 185, A: 255},
  2278. color.RGBA{R: 155, G: 89, B: 182, A: 255},
  2279. color.RGBA{R: 192, G: 57, B: 43, A: 255},
  2280. color.RGBA{R: 241, G: 196, B: 15, A: 255},
  2281. )
  2282. return colors[i%len(colors)]
  2283. }
  2284. // 获取加完水印的pdf
  2285. func GetWatermarkPdf_command(task Task.Task, pdfURL string, flag string) (pdf string) {
  2286. if len(pdfURL) == 0 {
  2287. return
  2288. }
  2289. currentDirectory := lib.GetCurrentDirectory()
  2290. scriptPath := currentDirectory + "/script"
  2291. pdf_file_out_name := uuid.New().String() + ".pdf"
  2292. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  2293. pdf_file_out := currentDirectory + "/ofile/watermark" + pdf_file_out_name
  2294. watermark_pdf := currentDirectory + "/script/watermark.pdf"
  2295. // 执行Python脚本
  2296. cmd := exec.Command("python3", "add_watermark.py", pdfURL, pdfFilename, pdf_file_out, watermark_pdf)
  2297. cmd.Dir = scriptPath
  2298. // 获取命令输出
  2299. _, err := cmd.CombinedOutput()
  2300. if err != nil {
  2301. logs.Error("执行python脚本添加水印错误:", err)
  2302. return
  2303. }
  2304. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  2305. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  2306. err = errors.New("上传水印pdf失败")
  2307. return
  2308. }
  2309. defer func() {
  2310. os.Remove(pdfFilename)
  2311. os.Remove(pdf_file_out)
  2312. }()
  2313. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  2314. switch flag {
  2315. case "T_pdf1":
  2316. task.T_pdf1_watermark = pdf
  2317. Task.Update_Task(task, "T_pdf1_watermark")
  2318. case "T_pdf2":
  2319. task.T_pdf2_watermark = pdf
  2320. Task.Update_Task(task, "T_pdf2_watermark")
  2321. }
  2322. return
  2323. }
  2324. func GetSignaturePdf_command(task Task.Task, pdfURL string, flag string) (pdf string) {
  2325. if len(pdfURL) == 0 {
  2326. return
  2327. }
  2328. currentDirectory := lib.GetCurrentDirectory()
  2329. scriptPath := currentDirectory + "/script"
  2330. pdf_file_out_name := uuid.New().String() + ".pdf"
  2331. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  2332. pdf_file_out := currentDirectory + "/ofile/signature" + pdf_file_out_name
  2333. signature_img := currentDirectory + "/script/报告专用章.png"
  2334. // 执行Python脚本
  2335. cmd := exec.Command("python3", "add_signature.py", pdfURL, pdfFilename, signature_img, pdf_file_out)
  2336. cmd.Dir = scriptPath
  2337. // 获取命令输出
  2338. _, err := cmd.CombinedOutput()
  2339. if err != nil {
  2340. logs.Error("执行python脚本添加公章错误:", err)
  2341. return
  2342. }
  2343. _, err = os.Stat(pdf_file_out)
  2344. if os.IsNotExist(err) {
  2345. return ""
  2346. }
  2347. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  2348. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  2349. err = errors.New("上传水印pdf失败")
  2350. return
  2351. }
  2352. defer func() {
  2353. os.Remove(pdfFilename)
  2354. os.Remove(pdf_file_out)
  2355. }()
  2356. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  2357. switch flag {
  2358. case "T_pdf1":
  2359. task.T_pdf1_signature = pdf
  2360. Task.Update_Task(task, "T_pdf1_signature")
  2361. case "T_pdf2":
  2362. task.T_pdf2_signature = pdf
  2363. Task.Update_Task(task, "T_pdf2_signature")
  2364. }
  2365. return
  2366. }
  2367. func GetWatermarkPdf(task Task.Task, pdfURL string, stamp bool, flag string) (pdf string) {
  2368. if len(pdfURL) == 0 {
  2369. return
  2370. }
  2371. // 添加公章 T_pdf5为CNAS实验室 ,不添加公章
  2372. var signaturePdf, watermarkPdf string
  2373. var err error
  2374. if flag != "T_pdf5" {
  2375. if stamp {
  2376. signaturePdf, err = lib.GetSignaturePdf(pdfURL)
  2377. if err != nil {
  2378. logs.Error("获取加报告章pdf失败:", err)
  2379. return
  2380. }
  2381. } else {
  2382. signaturePdf = pdfURL
  2383. }
  2384. }
  2385. // 添加水印
  2386. watermarkPdf, err = lib.GetWatermarkPdf(pdfURL)
  2387. if err != nil {
  2388. logs.Error("获取加水印pdf失败:", err)
  2389. return
  2390. }
  2391. switch flag {
  2392. case "T_pdf1":
  2393. task.T_pdf1_watermark = watermarkPdf
  2394. task.T_pdf1_signature = signaturePdf
  2395. Task.Update_Task(task, "T_pdf1_watermark", "T_pdf1_signature")
  2396. case "T_pdf2":
  2397. task.T_pdf2_watermark = watermarkPdf
  2398. task.T_pdf2_signature = signaturePdf
  2399. Task.Update_Task(task, "T_pdf2_watermark", "T_pdf2_signature")
  2400. case "T_pdf5":
  2401. task.T_pdf5_watermark = watermarkPdf
  2402. Task.Update_Task(task, "T_pdf5_watermark")
  2403. }
  2404. return
  2405. }
  2406. // 暂停申请
  2407. // 列表 -
  2408. func (c *TaskController) TaskTimeList() {
  2409. // 验证登录 User_is, User_r
  2410. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2411. if !User_is {
  2412. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2413. c.ServeJSON()
  2414. return
  2415. }
  2416. var r_jsons lib.R_JSONS
  2417. T_task_id := c.GetString("T_task_id")
  2418. T_task_type, _ := c.GetInt("T_task_type", 0)
  2419. var cnt int64
  2420. List, cnt := Task.Read_TaskTime_List(T_task_id, T_task_type)
  2421. r_jsons.List = List
  2422. r_jsons.Num = int(cnt)
  2423. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2424. c.ServeJSON()
  2425. return
  2426. }
  2427. // 添加-
  2428. func (c *TaskController) TaskTimeAdd() {
  2429. // 验证登录 User_is, User_r
  2430. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2431. if !User_is {
  2432. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2433. c.ServeJSON()
  2434. return
  2435. }
  2436. dc := Device.DeviceClass{
  2437. T_uuid: User_r.T_uuid,
  2438. T_State: 1,
  2439. }
  2440. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", dc)
  2441. T_task_id := c.GetString("T_task_id")
  2442. T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
  2443. T_aaa := c.GetString("T_aaa")
  2444. var_ := Task.TaskTime{
  2445. T_task_id: T_task_id,
  2446. T_task_type: T_task_type,
  2447. T_uuid: User_r.T_uuid,
  2448. T_remarks: T_aaa,
  2449. T_start_time: time.Now().Format("2006-01-02 15:04:05"),
  2450. }
  2451. List, _ := Task.Read_TaskTime_List(T_task_id, T_task_type)
  2452. if len(List) > 0 {
  2453. if len(List[len(List)-1].T_end_time) == 0 {
  2454. c.Data["json"] = lib.JSONS{Code: 202, Msg: "上一个任务还没结束!"}
  2455. c.ServeJSON()
  2456. return
  2457. }
  2458. }
  2459. is := Task.Add_TaskTime(var_)
  2460. if !is {
  2461. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  2462. c.ServeJSON()
  2463. return
  2464. }
  2465. // 添加任务操作日志
  2466. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务暂停", "暂停申请", var_)
  2467. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", var_)
  2468. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  2469. c.ServeJSON()
  2470. return
  2471. }
  2472. // 添加-
  2473. func (c *TaskController) TaskTimeEnd() {
  2474. // 验证登录 User_is, User_r
  2475. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2476. if !User_is {
  2477. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2478. c.ServeJSON()
  2479. return
  2480. }
  2481. dc := Device.DeviceClass{
  2482. T_uuid: User_r.T_uuid,
  2483. T_State: 1,
  2484. }
  2485. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", dc)
  2486. Id, _ := c.GetInt("Id", 0)
  2487. TaskTime_r, is := Task.Read_TaskTime_ById(Id)
  2488. if !is {
  2489. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2490. c.ServeJSON()
  2491. return
  2492. }
  2493. TaskTime_r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  2494. is = Task.Update_TaskTime(TaskTime_r, "T_end_time")
  2495. if !is {
  2496. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2497. c.ServeJSON()
  2498. return
  2499. }
  2500. // 添加任务操作日志
  2501. Task.Add_TaskLogs_T(User_r.T_uuid, TaskTime_r.T_task_id, "任务暂停", "暂停结束", TaskTime_r)
  2502. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", TaskTime_r)
  2503. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: TaskTime_r.T_task_id}
  2504. c.ServeJSON()
  2505. return
  2506. }
  2507. // 列表 - 统计排名
  2508. func (c *TaskController) StatisticalRanking() {
  2509. // 验证登录 User_is, User_r
  2510. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2511. if !User_is {
  2512. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2513. c.ServeJSON()
  2514. return
  2515. }
  2516. T_power, _ := c.GetInt("T_power", 0) // 5 数据采集工程师 6 验证报告工程师
  2517. type Admin_T struct {
  2518. T_name string
  2519. T_scheme int // 实施方案
  2520. T_scheme_returnnum int // 退回
  2521. T_scheme_overnum int // 超时
  2522. T_scheme_log string // 日志
  2523. T_collection int // 数据采集
  2524. T_collection_returnnum int // 退回
  2525. T_collection_overnum int // 超时
  2526. T_collection_log string // 日志
  2527. T_reporting int // 报告编写
  2528. T_reporting_returnnum int // 退回
  2529. T_reporting_overnum int // 超时
  2530. T_reporting_log string // 日志
  2531. T_rejectdnum int // 驳回数量
  2532. }
  2533. var Admin_T_List []Admin_T
  2534. Admin_List := Account.Read_Admin_List_ALL_T_power(T_power)
  2535. for _, A := range Admin_List {
  2536. Admin_t := Admin_T{T_name: A.T_name}
  2537. // 方案
  2538. Task_List := Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_scheme") //T_scheme T_collection T_reporting
  2539. for _, T := range Task_List {
  2540. if len(T.T_scheme_end_time) > 0 {
  2541. if is, _ := lib.IsInCurrentMonth(T.T_scheme_end_time); !is {
  2542. continue // 不是本月
  2543. }
  2544. Admin_t.T_scheme += 1
  2545. Admin_t.T_scheme_log += T.T_name
  2546. // 退回
  2547. if T.T_scheme_return_times > 0 {
  2548. Admin_t.T_scheme_returnnum += T.T_scheme_return_times
  2549. Admin_t.T_scheme_log += " | 退回" + lib.To_string(int(T.T_scheme_return_times))
  2550. }
  2551. // 超时
  2552. if T.T_scheme_overtime > 0 {
  2553. Admin_t.T_scheme_overnum += 1
  2554. Admin_t.T_scheme_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_scheme_overtime))
  2555. }
  2556. // 驳回
  2557. if T.T_reject_times > 0 {
  2558. Admin_t.T_rejectdnum += T.T_reject_times
  2559. Admin_t.T_scheme_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  2560. }
  2561. Admin_t.T_scheme_log += "\n"
  2562. }
  2563. }
  2564. // 实施
  2565. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_collection") //T_scheme T_collection T_reporting
  2566. for _, T := range Task_List {
  2567. if len(T.T_collection_end_time) > 0 {
  2568. if is, _ := lib.IsInCurrentMonth(T.T_collection_end_time); !is {
  2569. continue // 不是本月
  2570. }
  2571. Admin_t.T_collection += 1
  2572. Admin_t.T_collection_log += T.T_name
  2573. // 退回
  2574. if T.T_collection_return_times > 0 {
  2575. Admin_t.T_collection_returnnum += T.T_collection_return_times
  2576. Admin_t.T_collection_log += " | 退回" + lib.To_string(int(T.T_collection_return_times))
  2577. }
  2578. // 超时
  2579. if T.T_collection_overtime > 0 {
  2580. Admin_t.T_collection_overnum += 1
  2581. Admin_t.T_collection_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_collection_overtime))
  2582. }
  2583. // 驳回
  2584. if T.T_reject_times > 0 {
  2585. Admin_t.T_rejectdnum += T.T_reject_times
  2586. Admin_t.T_collection_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  2587. }
  2588. Admin_t.T_collection_log += "\n"
  2589. }
  2590. }
  2591. // 报告
  2592. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_reporting") //T_scheme T_collection T_reporting
  2593. for _, T := range Task_List {
  2594. if len(T.T_reporting_end_time) > 0 {
  2595. if is, _ := lib.IsInCurrentMonth(T.T_reporting_end_time); !is {
  2596. continue // 不是本月
  2597. }
  2598. Admin_t.T_reporting += 1
  2599. Admin_t.T_reporting_log += T.T_name
  2600. // 退回
  2601. if T.T_reporting_return_times > 0 {
  2602. Admin_t.T_reporting_returnnum += T.T_reporting_return_times
  2603. Admin_t.T_reporting_log += " | 退回" + lib.To_string(int(T.T_reporting_return_times))
  2604. }
  2605. // 超时
  2606. if T.T_reporting_overtime > 0 {
  2607. Admin_t.T_reporting_overnum += 1
  2608. Admin_t.T_reporting_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_reporting_overtime))
  2609. }
  2610. // 驳回
  2611. if T.T_reject_times > 0 {
  2612. Admin_t.T_rejectdnum += T.T_reject_times
  2613. Admin_t.T_reporting_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  2614. }
  2615. Admin_t.T_reporting_log += "\n"
  2616. }
  2617. }
  2618. Admin_T_List = append(Admin_T_List, Admin_t)
  2619. }
  2620. var r_jsons lib.R_JSONS
  2621. r_jsons.List = Admin_T_List
  2622. r_jsons.Page = 0
  2623. r_jsons.Page_size = 0
  2624. r_jsons.Pages = lib.Func_page(int64(0), int64(0))
  2625. r_jsons.Num = 0
  2626. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2627. c.ServeJSON()
  2628. return
  2629. }
  2630. // 复制-
  2631. func (c *TaskController) Copy() {
  2632. // 验证登录 User_is, User_r
  2633. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2634. if !User_is {
  2635. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2636. c.ServeJSON()
  2637. return
  2638. }
  2639. T_name := c.GetString("T_name")
  2640. T_task_id := c.GetString("T_task_id")
  2641. r, is := Task.Read_Task(T_task_id)
  2642. if !is {
  2643. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  2644. c.ServeJSON()
  2645. return
  2646. }
  2647. dc := Device.DeviceClass{
  2648. T_uuid: User_r.T_uuid,
  2649. T_State: 1,
  2650. }
  2651. T_class_id, is := Device.Add_DeviceClass(dc)
  2652. if !is {
  2653. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  2654. c.ServeJSON()
  2655. return
  2656. }
  2657. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
  2658. // 查询信息采集信息
  2659. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  2660. if !is {
  2661. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  2662. c.ServeJSON()
  2663. return
  2664. }
  2665. var_ := Task.Task{
  2666. T_Distributor_id: r.T_Distributor_id,
  2667. T_InfoCollection_id: r.T_InfoCollection_id,
  2668. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  2669. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  2670. T_class: int(T_class_id),
  2671. T_uuid: r.T_uuid,
  2672. T_name: T_name,
  2673. T_VerifyTemplate_class: r.T_VerifyTemplate_class,
  2674. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  2675. T_deadline: r.T_deadline,
  2676. T_scheme: r.T_scheme,
  2677. T_collection: r.T_collection,
  2678. T_reporting: r.T_reporting,
  2679. T_delivery: r.T_delivery,
  2680. T_Show: 1,
  2681. T_State: 1,
  2682. T_project: r.T_project,
  2683. T_province: r.T_province,
  2684. T_city: r.T_city,
  2685. T_district: r.T_district,
  2686. T_province_code: r.T_province_code,
  2687. T_city_code: r.T_city_code,
  2688. T_district_code: r.T_district_code,
  2689. T_category: r.T_category,
  2690. T_device_type: r.T_device_type,
  2691. T_volume: r.T_volume,
  2692. T_verify_type: r.T_verify_type,
  2693. T_subject_matter: r.T_subject_matter,
  2694. T_temp_range: r.T_temp_range,
  2695. T_report_type: r.T_report_type,
  2696. T_device_quantity: r.T_device_quantity,
  2697. T_cnas: r.T_cnas,
  2698. }
  2699. var_.T_report_number, _ = Task.GenerateNextT_report_number(var_.T_device_type)
  2700. T_paste_task_id, is := Task.Add_Task(var_)
  2701. if !is {
  2702. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  2703. c.ServeJSON()
  2704. return
  2705. }
  2706. NatsServer.Create_Local_Table(T_paste_task_id)
  2707. Task.Redis_Task_T_report_number_DelK(var_.T_report_number) // 删除redis内的任务编号
  2708. // 复制验证模版数据
  2709. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(r.T_VerifyTemplate_id, 0, 0)
  2710. copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_task_id, r.T_VerifyTemplate_id, Map_List)
  2711. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_paste_task_id, r.T_VerifyTemplate_id, Map_List)
  2712. copyDataMap := make(map[string]string)
  2713. for _, data := range copy_task_Data {
  2714. copyDataMap[data.T_name] = data.T_value
  2715. }
  2716. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  2717. for _, v := range Data {
  2718. // 已有值则不复制
  2719. if len(v.T_value) > 0 {
  2720. continue
  2721. }
  2722. if copyDataMap[v.T_name] == "" {
  2723. continue
  2724. }
  2725. val := VerifyTemplate.VerifyTemplateMapData{
  2726. T_source: v.T_source,
  2727. T_task_id: T_paste_task_id,
  2728. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  2729. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  2730. T_Required: v.T_Required,
  2731. T_Construction: v.T_Construction,
  2732. T_flow_sort: v.T_flow_sort,
  2733. T_max_time: v.T_max_time,
  2734. T_min_time: v.T_min_time,
  2735. T_value: copyDataMap[v.T_name],
  2736. }
  2737. MapDataList = append(MapDataList, val)
  2738. }
  2739. _, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "复制", 0, 0, 1)
  2740. if !is {
  2741. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  2742. c.ServeJSON()
  2743. return
  2744. }
  2745. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制标签数据", MapDataList)
  2746. // 通知
  2747. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  2748. go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2749. go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2750. go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2751. go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2752. // 添加任务操作日志
  2753. Task.Add_TaskLogs_T(User_r.T_uuid, T_paste_task_id, "任务管理", "复制", var_)
  2754. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制", var_)
  2755. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_paste_task_id}
  2756. c.ServeJSON()
  2757. return
  2758. }
  2759. // 生成报告编号 设备类型+年+季度+递增编号
  2760. func (c *TaskController) GenT_report_number() {
  2761. // 验证登录 User_is, User_r
  2762. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2763. if !User_is {
  2764. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2765. c.ServeJSON()
  2766. return
  2767. }
  2768. T_device_type := c.GetString("T_device_type")
  2769. number, err := Task.GenerateNextT_report_number(T_device_type)
  2770. if err != nil {
  2771. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  2772. c.ServeJSON()
  2773. return
  2774. }
  2775. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: number}
  2776. c.ServeJSON()
  2777. return
  2778. }
  2779. // 自动填写布点
  2780. func (c *TaskController) Auto_fill_deploy() {
  2781. // 验证登录 User_is, User_r
  2782. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2783. if !User_is {
  2784. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2785. c.ServeJSON()
  2786. return
  2787. }
  2788. T_task_id := c.GetString("T_task_id")
  2789. T_source, _ := c.GetInt("T_source")
  2790. task, is := Task.Read_Task(T_task_id)
  2791. if !is {
  2792. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2793. c.ServeJSON()
  2794. return
  2795. }
  2796. verifyTemplate, is := VerifyTemplate.Read_VerifyTemplate(task.T_VerifyTemplate_id)
  2797. verifyTemplate_R := VerifyTemplate.VerifyTemplateToVerifyTemplate_R(verifyTemplate)
  2798. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  2799. MapData := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  2800. T_deploy_list := verifyTemplate_R.T_deploy_list
  2801. //if len(T_deploy_list) == 0 {
  2802. // // 解析设备列表备注的布点
  2803. // deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, "")
  2804. // for _, v := range deviceClassList {
  2805. // splitList := lib.SplitStringSeparator(v.T_remark, "|")
  2806. // for _, T_name := range splitList {
  2807. // T_deploy_list = append(T_deploy_list, VerifyTemplate.VerifyTemplateDeploy{T_name: T_name})
  2808. // }
  2809. // }
  2810. //}
  2811. // 循环查询布点
  2812. deployMap := make(map[string]string)
  2813. for _, deploy := range T_deploy_list {
  2814. deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, deploy.T_name)
  2815. var snList []string
  2816. for _, v := range deviceClassList {
  2817. snList = append(snList, v.T_sn)
  2818. }
  2819. deployMap[deploy.T_name] = strings.Join(snList, "|")
  2820. }
  2821. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  2822. for _, v := range MapData {
  2823. if snList, ok := deployMap[v.T_name]; ok {
  2824. val := VerifyTemplate.VerifyTemplateMapData{
  2825. T_source: v.T_source,
  2826. T_task_id: task.T_task_id,
  2827. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  2828. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  2829. T_Required: v.T_Required,
  2830. T_Construction: v.T_Construction,
  2831. T_flow_sort: v.T_flow_sort,
  2832. T_max_time: v.T_max_time,
  2833. T_min_time: v.T_min_time,
  2834. T_value: snList,
  2835. T_start_time: v.T_start_time,
  2836. }
  2837. MapDataList = append(MapDataList, val)
  2838. }
  2839. }
  2840. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, T_source, User_r.T_uuid, 0, 0, 0)
  2841. if !is {
  2842. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  2843. c.ServeJSON()
  2844. return
  2845. }
  2846. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "自动填写", ids)
  2847. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  2848. c.ServeJSON()
  2849. return
  2850. }
  2851. // SyncVerifyTemplateMapData 根据标签名称同步模版数据
  2852. func (c *TaskController) SyncVerifyTemplateMapData() {
  2853. T_copy_task_id := c.GetString("T_copy_task_id")
  2854. T_paste_task_id := c.GetString("T_paste_task_id")
  2855. T_source, _ := c.GetInt("T_source")
  2856. copy_task, is := Task.Read_Task(T_copy_task_id)
  2857. if !is {
  2858. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2859. c.ServeJSON()
  2860. return
  2861. }
  2862. paste_task, is := Task.Read_Task(T_paste_task_id)
  2863. if !is {
  2864. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2865. c.ServeJSON()
  2866. return
  2867. }
  2868. copy_task_Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(copy_task.T_VerifyTemplate_id, 0, 0)
  2869. copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_copy_task_id, copy_task.T_VerifyTemplate_id, copy_task_Map_List)
  2870. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(paste_task.T_VerifyTemplate_id, 0, 0)
  2871. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_paste_task_id, paste_task.T_VerifyTemplate_id, Map_List)
  2872. copyDataMap := make(map[string]string)
  2873. for _, data := range copy_task_Data {
  2874. copyDataMap[data.T_name] = data.T_value
  2875. }
  2876. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  2877. for _, v := range Data {
  2878. if len(v.T_value) > 0 {
  2879. continue
  2880. }
  2881. if copyDataMap[v.T_name] == "" {
  2882. continue
  2883. }
  2884. val := VerifyTemplate.VerifyTemplateMapData{
  2885. T_source: v.T_source,
  2886. T_task_id: paste_task.T_task_id,
  2887. T_VerifyTemplate_id: paste_task.T_VerifyTemplate_id,
  2888. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  2889. T_Required: v.T_Required,
  2890. T_Construction: v.T_Construction,
  2891. T_flow_sort: v.T_flow_sort,
  2892. T_max_time: v.T_max_time,
  2893. T_min_time: v.T_min_time,
  2894. T_value: copyDataMap[v.T_name],
  2895. }
  2896. MapDataList = append(MapDataList, val)
  2897. }
  2898. var ids []int64
  2899. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "", 0, 0, 0)
  2900. if !is {
  2901. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  2902. c.ServeJSON()
  2903. return
  2904. }
  2905. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  2906. c.ServeJSON()
  2907. return
  2908. }
  2909. func (c *TaskController) TaskData_Stat() {
  2910. StartTime := c.GetString("StartTime")
  2911. if len(StartTime) > 0 {
  2912. _, ok := lib.TimeStrToTime(StartTime)
  2913. if !ok {
  2914. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  2915. c.ServeJSON()
  2916. return
  2917. }
  2918. }
  2919. EndTime := c.GetString("EndTime")
  2920. if len(EndTime) > 0 {
  2921. _, ok := lib.TimeStrToTime(EndTime)
  2922. if !ok {
  2923. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  2924. c.ServeJSON()
  2925. return
  2926. }
  2927. } else {
  2928. EndTime = time.Now().Format("2006-01-02 15:04:05")
  2929. }
  2930. T_remark := c.GetString("T_remark")
  2931. T_task_id := c.GetString("T_task_id")
  2932. Task_r, is := Task.Read_Task(T_task_id)
  2933. if !is {
  2934. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  2935. c.ServeJSON()
  2936. return
  2937. }
  2938. if Task_r.T_collection_state == 2 {
  2939. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  2940. c.ServeJSON()
  2941. return
  2942. }
  2943. deviceList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  2944. if !is {
  2945. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  2946. c.ServeJSON()
  2947. return
  2948. }
  2949. var chData = make(chan int, 10)
  2950. var jobGroup sync.WaitGroup
  2951. var device = make([]Device.DeviceCount, len(deviceList))
  2952. // 创建温度线
  2953. for i := 0; i < len(deviceList); i++ {
  2954. chData <- 1
  2955. jobGroup.Add(1)
  2956. go func(index int) {
  2957. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  2958. defer func() {
  2959. <-chData // 完成时chan取出1个
  2960. jobGroup.Done() // 完成时将等待组值减1
  2961. }()
  2962. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  2963. _, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  2964. device[index] = Device.DeviceCount{
  2965. T_id: id,
  2966. T_sn: sn,
  2967. Num: r_maps_num,
  2968. }
  2969. if r_maps_num == 0 {
  2970. return
  2971. }
  2972. }(i)
  2973. }
  2974. jobGroup.Wait()
  2975. c.Data["json"] = lib.JSONS{Data: device, Code: 200, Msg: "ok!"}
  2976. c.ServeJSON()
  2977. return
  2978. }
  2979. // SyncPDFWatermark 同步水印
  2980. func (c *TaskController) SyncPDFWatermark() {
  2981. List, _ := Task.Read_Task_List_For_Watermark("pdf1")
  2982. for _, task := range List {
  2983. GetWatermarkPdf_command(task, task.T_pdf1, "T_pdf1")
  2984. GetSignaturePdf_command(task, task.T_pdf1, "T_pdf1")
  2985. }
  2986. List2, _ := Task.Read_Task_List_For_Watermark("pdf2")
  2987. for _, task := range List2 {
  2988. GetWatermarkPdf_command(task, task.T_pdf2, "T_pdf2")
  2989. GetSignaturePdf_command(task, task.T_pdf2, "T_pdf2")
  2990. }
  2991. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2992. c.ServeJSON()
  2993. return
  2994. }