Task.go 118 KB

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