Task.go 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611
  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/Certificate"
  10. "ColdVerify_server/models/Device"
  11. "ColdVerify_server/models/InfoCollection"
  12. "ColdVerify_server/models/System"
  13. "ColdVerify_server/models/Task"
  14. "ColdVerify_server/models/VerifyTemplate"
  15. "archive/zip"
  16. "encoding/json"
  17. "errors"
  18. "fmt"
  19. "image/color"
  20. "io"
  21. "math"
  22. "os"
  23. "os/exec"
  24. "path/filepath"
  25. "regexp"
  26. "strings"
  27. "sync"
  28. "time"
  29. "github.com/xuri/excelize/v2"
  30. beego "github.com/beego/beego/v2/server/web"
  31. "github.com/google/uuid"
  32. "gonum.org/v1/plot"
  33. "gonum.org/v1/plot/plotter"
  34. "gonum.org/v1/plot/vg"
  35. "gonum.org/v1/plot/vg/draw"
  36. )
  37. type TaskController struct {
  38. beego.Controller
  39. }
  40. // 导入Excel创建任务并写入模版数据
  41. func (c *TaskController) Import_Tasks() {
  42. file, fileHeader, err := c.GetFile("file")
  43. if err != nil {
  44. c.Data["json"] = lib.JSONS{Code: 203, Msg: "读取上传文件失败!"}
  45. c.ServeJSON()
  46. return
  47. }
  48. defer file.Close()
  49. // 保存上传的文件到临时位置,以便后续提取图片
  50. lib.Create_Dir("./ofile/temp_excel")
  51. tempExcelPath := fmt.Sprintf("./ofile/temp_excel/%d_%s", time.Now().Unix(), fileHeader.Filename)
  52. err = c.SaveToFile("file", tempExcelPath)
  53. if err != nil {
  54. c.Data["json"] = lib.JSONS{Code: 203, Msg: "保存临时文件失败!"}
  55. c.ServeJSON()
  56. return
  57. }
  58. defer os.Remove(tempExcelPath) // 处理完成后删除临时文件
  59. // 重新打开文件用于读取数据(必须使用文件路径,GetPicture 等功能依赖于完整文件)
  60. f, err := excelize.OpenFile(tempExcelPath)
  61. if err != nil {
  62. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Excel 文件解析失败!"}
  63. c.ServeJSON()
  64. return
  65. }
  66. defer func() {
  67. _ = f.Close()
  68. }()
  69. sheetName := c.GetString("sheet")
  70. if len(sheetName) == 0 {
  71. sheets := f.GetSheetList()
  72. if len(sheets) == 0 {
  73. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Excel 文件为空!"}
  74. c.ServeJSON()
  75. return
  76. }
  77. sheetName = sheets[0]
  78. }
  79. rows, err := f.GetRows(sheetName)
  80. if err != nil {
  81. c.Data["json"] = lib.JSONS{Code: 203, Msg: "读取 Excel 内容失败!"}
  82. c.ServeJSON()
  83. return
  84. }
  85. if len(rows) < 2 {
  86. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Excel 中缺少数据行!"}
  87. c.ServeJSON()
  88. return
  89. }
  90. headers := rows[0]
  91. successIDs := make([]string, 0)
  92. skippedRows := make([]int, 0)
  93. failedRows := make([]string, 0)
  94. // 从 Excel 文件中提取所有图片,建立 DISPIMG ID 到图片数据的映射
  95. // pictureMap key格式: DISPIMG 中的 ID (例如 "ID_53A3119AC46541C694965B07E5E00F81")
  96. pictureMap, err := c.extractPicturesFromExcel(tempExcelPath)
  97. if err != nil {
  98. logs.Warning(fmt.Sprintf("提取 Excel 图片失败: %v,将继续处理数据", err))
  99. pictureMap = make(map[string][]byte)
  100. }
  101. logs.Info(fmt.Sprintf("共提取到 %d 个图片(ID映射)", len(pictureMap)))
  102. // 缓存 InfoCollection,避免同一家公司重复查询或创建
  103. infoCollectionCache := make(map[string]InfoCollection.InfoCollection)
  104. for idx := 1; idx < len(rows); idx++ {
  105. rowCells := rows[idx]
  106. rowData := make(map[string]string, len(headers))
  107. nonEmpty := false
  108. for colIdx, header := range headers {
  109. header = strings.TrimSpace(header)
  110. if len(header) == 0 {
  111. continue
  112. }
  113. value := ""
  114. if colIdx < len(rowCells) {
  115. value = strings.TrimSpace(rowCells[colIdx])
  116. }
  117. if len(value) > 0 {
  118. nonEmpty = true
  119. }
  120. // 处理单元格内是图片的情况:只有value包含DISPIMG时才处理
  121. if strings.Contains(value, "DISPIMG") {
  122. logs.Info(fmt.Sprintf("单元格 %d:%d 包含DISPIMG,可能是图片: %s", idx+1, colIdx+1, value))
  123. // 从 DISPIMG 公式中提取 ID
  124. // 格式: =DISPIMG("ID_53A3119AC46541C694965B07E5E00F81",1) 或 DISPIMG("ID_...",1)
  125. var picData []byte
  126. var foundBy string
  127. // 通过 ID 查找图片(pictureMap 现在使用 DISPIMG ID 作为 key)
  128. dispimgIdRe := regexp.MustCompile(`DISPIMG\s*\(\s*"([^"]+)"`)
  129. idMatches := dispimgIdRe.FindStringSubmatch(value)
  130. if len(idMatches) > 1 {
  131. imageId := idMatches[1]
  132. logs.Info(fmt.Sprintf("从 DISPIMG 公式中提取到 ID: %s", imageId))
  133. if data, exists := pictureMap[imageId]; exists && len(data) > 0 {
  134. picData = data
  135. foundBy = fmt.Sprintf("ID (%s)", imageId)
  136. logs.Info(fmt.Sprintf("通过 ID %s 找到图片数据 (大小: %d 字节)", imageId, len(picData)))
  137. } else {
  138. logs.Warning(fmt.Sprintf("通过 ID %s 未找到图片数据,pictureMap 中有 %d 个图片", imageId, len(pictureMap)))
  139. }
  140. }
  141. // 如果找到了图片数据,上传图片
  142. if picData != nil && len(picData) > 0 {
  143. imageURL, uploadErr := c.uploadImageData(picData, header)
  144. if uploadErr == nil && len(imageURL) > 0 {
  145. value = imageURL
  146. nonEmpty = true
  147. logs.Info(fmt.Sprintf("第%d行 %s 图片上传成功 (通过%s): %s", idx+1, header, foundBy, imageURL))
  148. logs.Info(fmt.Sprintf("第%d行 %s 图片上传成功 (通过%s): %s", idx+1, header, foundBy, imageURL))
  149. } else if uploadErr != nil {
  150. logs.Error(fmt.Sprintf("第%d行 %s 上传单元格图片失败: %v", idx+1, header, uploadErr))
  151. }
  152. } else {
  153. logs.Warning(fmt.Sprintf("第%d行 %s 包含DISPIMG但未找到对应图片数据", idx+1, header))
  154. }
  155. }
  156. rowData[header] = value
  157. }
  158. if !nonEmpty {
  159. continue
  160. }
  161. companyName := strings.TrimSpace(rowData["公司名称"])
  162. taskName := strings.TrimSpace(rowData["任务名称"])
  163. belongYear := strings.TrimSpace(rowData["所属年份"])
  164. if len(companyName) == 0 || len(taskName) == 0 || len(belongYear) == 0 {
  165. skippedRows = append(skippedRows, idx+1)
  166. continue
  167. }
  168. taskID, err := c.importTaskRow(rowData, infoCollectionCache)
  169. if err != nil {
  170. failedRows = append(failedRows, fmt.Sprintf("第%d行: %v", idx+1, err))
  171. continue
  172. }
  173. successIDs = append(successIDs, taskID)
  174. }
  175. msg := fmt.Sprintf("导入完成, 成功 %d 条, 跳过 %d 条, 失败 %d 条", len(successIDs), len(skippedRows), len(failedRows))
  176. respData := map[string]interface{}{
  177. "success_ids": successIDs,
  178. "skipped_rows": skippedRows,
  179. }
  180. if len(failedRows) > 0 {
  181. respData["failed_rows"] = failedRows
  182. }
  183. c.Data["json"] = lib.JSONS{Code: 200, Msg: msg, Data: respData}
  184. c.ServeJSON()
  185. }
  186. func (c *TaskController) importTaskRow(row map[string]string, infoCollectionCache map[string]InfoCollection.InfoCollection) (string, error) {
  187. templateName := strings.TrimSpace(row["模板名称"])
  188. lastOpenBracket := strings.LastIndex(templateName, "[")
  189. lastCloseBracket := strings.LastIndex(templateName, "]")
  190. if lastOpenBracket == -1 || lastCloseBracket == -1 || lastOpenBracket >= lastCloseBracket {
  191. return "", fmt.Errorf("模版名称中未找到模版ID")
  192. }
  193. templateID := templateName[lastOpenBracket+1 : lastCloseBracket]
  194. if len(templateID) == 0 {
  195. return "", fmt.Errorf("模版ID为空")
  196. }
  197. vt, ok := VerifyTemplate.Read_VerifyTemplate(templateID)
  198. if !ok {
  199. return "", fmt.Errorf("模版不存在: %s", templateID)
  200. }
  201. taskUID := strings.TrimSpace(row["唯一标识"])
  202. if len(taskUID) == 0 {
  203. return "", fmt.Errorf("唯一标识缺失")
  204. }
  205. existingTask, taskExists := Task.Read_Task_ByUid(taskUID)
  206. companyName := strings.TrimSpace(row["公司名称"])
  207. if len(companyName) == 0 {
  208. return "", fmt.Errorf("公司名称缺失")
  209. }
  210. cachedUser, found, err := Account.GetCompanyFromCache(companyName)
  211. if err != nil {
  212. return "", fmt.Errorf("公司数据读取失败: %w", err)
  213. }
  214. var user Account.User
  215. if !found {
  216. newUser := Account.User{
  217. T_name: companyName,
  218. T_pass: Account.DefaultCompanyPasswordHash,
  219. T_passstr: Account.DefaultCompanyPasswordPlain,
  220. T_Show: 1,
  221. T_State: 1,
  222. T_pid: 0,
  223. }
  224. newID, ok := Account.Add_User(newUser)
  225. if !ok {
  226. return "", fmt.Errorf("自动创建公司失败")
  227. }
  228. if err := Account.UpdateUserPath(int(newID)); err != nil {
  229. logs.Error("更新新公司路径失败:", err)
  230. }
  231. createdUser, is := Account.Read_User_ById(int(newID))
  232. if !is {
  233. return "", fmt.Errorf("获取新公司信息失败")
  234. }
  235. user = createdUser
  236. Account.UpsertCompanyCache(user)
  237. } else {
  238. user = cachedUser
  239. }
  240. // 根据用户信息获取或创建 InfoCollection,并使用 map 做本次导入缓存,避免重复查询
  241. cacheKey := user.T_uuid
  242. if len(cacheKey) == 0 {
  243. cacheKey = user.T_name
  244. }
  245. infoCollectionRecord, ok := infoCollectionCache[cacheKey]
  246. if !ok {
  247. record, err := InfoCollection.GetOrCreate_InfoCollection(user.T_uuid, user.T_name)
  248. if err != nil {
  249. return "", fmt.Errorf("自动创建信息采集失败: %w", err)
  250. }
  251. infoCollectionRecord = record
  252. infoCollectionCache[cacheKey] = infoCollectionRecord
  253. }
  254. resolveAdminUUID := func(fieldName, fallback string, strict bool) (string, error) {
  255. value, ok := row[fieldName]
  256. if !ok || len(strings.TrimSpace(value)) == 0 {
  257. return fallback, nil
  258. }
  259. admin, err := Account.EnsureAdminByName(strings.TrimSpace(value), "")
  260. if err != nil {
  261. if strict {
  262. return "", err
  263. }
  264. logs.Error(fieldName+" 负责人处理失败:", err)
  265. return fallback, nil
  266. }
  267. return admin.T_uuid, nil
  268. }
  269. taskName := strings.TrimSpace(row["任务名称"])
  270. if len(taskName) == 0 {
  271. return "", fmt.Errorf("任务名称缺失")
  272. }
  273. classPath := ""
  274. if vt.T_class > 0 {
  275. if cls, err := VerifyTemplate.Read_VerifyTemplateClass_ById(vt.T_class); err == nil {
  276. p := cls.T_path
  277. p = strings.Trim(p, "/")
  278. p = strings.TrimPrefix(p, "0/")
  279. classPath = p
  280. }
  281. }
  282. schemeFallback := ""
  283. collectionFallback := ""
  284. reportingFallback := ""
  285. deliveryFallback := ""
  286. projectFallback := ""
  287. categoryFallback := ""
  288. deviceTypeFallback := ""
  289. verifyTypeFallback := ""
  290. if taskExists {
  291. schemeFallback = existingTask.T_scheme
  292. collectionFallback = existingTask.T_collection
  293. reportingFallback = existingTask.T_reporting
  294. deliveryFallback = existingTask.T_delivery
  295. projectFallback = existingTask.T_project
  296. categoryFallback = existingTask.T_category
  297. deviceTypeFallback = existingTask.T_device_type
  298. verifyTypeFallback = existingTask.T_verify_type
  299. }
  300. schemeUUID, err := resolveAdminUUID("实施方案", schemeFallback, false)
  301. if err != nil {
  302. return "", fmt.Errorf("实施方案负责人创建失败: %w", err)
  303. }
  304. collectionUUID, err := resolveAdminUUID("数据采集", collectionFallback, true)
  305. if err != nil {
  306. return "", fmt.Errorf("数据采集负责人创建失败: %w", err)
  307. }
  308. reportingUUID, err := resolveAdminUUID("报告编辑", reportingFallback, true)
  309. if err != nil {
  310. return "", fmt.Errorf("报告编辑负责人创建失败: %w", err)
  311. }
  312. deliveryUUID, err := resolveAdminUUID("交付审核", deliveryFallback, false)
  313. if err != nil {
  314. return "", fmt.Errorf("交付审核负责人创建失败: %w", err)
  315. }
  316. projectUUID, _ := resolveAdminUUID("项目负责人", projectFallback, false)
  317. categoryValue := strings.TrimSpace(row["类别"])
  318. if len(categoryValue) == 0 {
  319. categoryValue = categoryFallback
  320. }
  321. deviceTypeValue := strings.TrimSpace(row["设备类型"])
  322. if len(deviceTypeValue) == 0 {
  323. deviceTypeValue = deviceTypeFallback
  324. } else {
  325. if mapped, ok := Task.DeviceTypeMap[deviceTypeValue]; ok {
  326. deviceTypeValue = mapped
  327. } else {
  328. deviceTypeValue = deviceTypeValue
  329. }
  330. }
  331. verifyTypeValue := strings.TrimSpace(row["验证类型"])
  332. if len(verifyTypeValue) == 0 {
  333. verifyTypeValue = verifyTypeFallback
  334. }
  335. belongYearValue := strings.TrimSpace(row["所属年份"])
  336. infoCollectionID := infoCollectionRecord.T_InfoCollection_id
  337. taskRecord := Task.Task{
  338. T_Distributor_id: user.T_Distributor_id,
  339. T_uuid: user.T_uuid,
  340. T_name: taskName,
  341. T_VerifyTemplate_id: templateID,
  342. T_VerifyTemplate_class: classPath,
  343. T_InfoCollection_id: infoCollectionID,
  344. T_uid: taskUID,
  345. T_scheme: schemeUUID,
  346. T_collection: collectionUUID,
  347. T_reporting: reportingUUID,
  348. T_delivery: deliveryUUID,
  349. T_project: projectUUID,
  350. T_category: categoryValue,
  351. T_device_type: deviceTypeValue,
  352. T_verify_type: verifyTypeValue,
  353. T_belong_year: belongYearValue,
  354. }
  355. var taskID string
  356. if taskExists {
  357. taskRecord.Id = existingTask.Id
  358. taskRecord.T_task_id = existingTask.T_task_id
  359. taskRecord.T_State = existingTask.T_State
  360. if ok := Task.Update_Task(taskRecord, "T_Distributor_id", "T_uuid", "T_name", "T_VerifyTemplate_id", "T_VerifyTemplate_class", "T_uid", "T_scheme", "T_collection", "T_reporting", "T_delivery", "T_project", "T_category", "T_device_type", "T_verify_type", "T_belong_year"); !ok {
  361. return "", fmt.Errorf("更新任务失败")
  362. }
  363. taskID = existingTask.T_task_id
  364. } else {
  365. dc := Device.DeviceClass{
  366. T_uuid: user.T_uuid,
  367. T_State: 1,
  368. }
  369. classID, ok := Device.Add_DeviceClass(dc)
  370. if !ok {
  371. return "", fmt.Errorf("创建分类失败")
  372. }
  373. taskRecord.T_class = int(classID)
  374. taskRecord.T_State = 1
  375. taskRecord.T_deadline = time.Now().AddDate(0, 2, 0).Format("2006-01-02")
  376. if len(strings.TrimSpace(taskRecord.T_device_type)) > 0 {
  377. number, err := Task.GenerateNextT_report_number(taskRecord.T_device_type)
  378. if err != nil {
  379. return "", fmt.Errorf("生成报告编号失败: %w", err)
  380. }
  381. taskRecord.T_report_number = number
  382. }
  383. if newID, ok := Task.Add_Task(taskRecord); !ok {
  384. return "", fmt.Errorf("创建任务失败")
  385. } else {
  386. taskID = newID
  387. }
  388. }
  389. mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(templateID, 0, 0)
  390. labelMap := make(map[string]VerifyTemplate.VerifyTemplateMap_R, len(mapList))
  391. for _, m := range mapList {
  392. labelMap[m.T_name] = m
  393. }
  394. dataList := make([]VerifyTemplate.VerifyTemplateMapData, 0, len(row))
  395. for key, val := range row {
  396. if vtm, exists := labelMap[key]; exists {
  397. logs.Println("key:", key, "val:", val)
  398. dataList = append(dataList, VerifyTemplate.VerifyTemplateMapData{
  399. T_source: vtm.T_source,
  400. T_task_id: taskID,
  401. T_VerifyTemplate_id: templateID,
  402. T_VerifyTemplateMap_id: vtm.T_id,
  403. T_value: val,
  404. T_Required: vtm.T_Required,
  405. T_Construction: vtm.T_Construction,
  406. T_flow_sort: vtm.T_flow_sort,
  407. T_max_time: vtm.T_max_time,
  408. T_min_time: vtm.T_min_time,
  409. T_start_time: int64(vtm.T_start_time),
  410. })
  411. }
  412. }
  413. if len(dataList) > 0 {
  414. if _, ok := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(dataList); !ok {
  415. return "", fmt.Errorf("写入模版数据失败")
  416. }
  417. }
  418. return taskID, nil
  419. }
  420. func (c *TaskController) extractPicturesFromExcel(filePath string) (map[string][]byte, error) {
  421. filePath = strings.TrimSpace(filePath)
  422. if len(filePath) == 0 {
  423. return nil, fmt.Errorf("Excel 文件路径为空")
  424. }
  425. zipReader, err := zip.OpenReader(filePath)
  426. if err != nil {
  427. return nil, fmt.Errorf("打开 Excel 压缩包失败: %w", err)
  428. }
  429. defer zipReader.Close()
  430. return c.extractWpsDispImgPictures(zipReader), nil
  431. }
  432. // extractWpsDispImgPictures 专门处理 WPS / _xlfn.DISPIMG 的图片提取逻辑
  433. // 原理参考: `https://www.hushlll.top/?p=644`
  434. // 1. 读取 xl/cellimages.xml,找到每个图片块中的 name="ID_xxx" 和 r:embed="rIdX"
  435. // 2. 读取 xl/_rels/cellimages.xml.rels(或退回到 xl/drawings/_rels/drawing1.xml.rels),把 rId 映射到具体的图片路径(如 media/image1.jpg)
  436. // 3. 从 ZIP 中按路径取出图片数据,建立 ID -> 图片数据 的映射
  437. func (c *TaskController) extractWpsDispImgPictures(zipReader *zip.ReadCloser) map[string][]byte {
  438. result := make(map[string][]byte)
  439. if zipReader == nil || zipReader.File == nil {
  440. return result
  441. }
  442. // 1. 找到 xl/cellimages.xml
  443. var cellImagesFile *zip.File
  444. for _, f := range zipReader.File {
  445. if f != nil && f.Name == "xl/cellimages.xml" {
  446. cellImagesFile = f
  447. break
  448. }
  449. }
  450. if cellImagesFile == nil {
  451. // 非 WPS / 无 cellimages.xml 的情况,直接返回空
  452. return result
  453. }
  454. rc, err := cellImagesFile.Open()
  455. if err != nil {
  456. logs.Warning(fmt.Sprintf("无法打开 xl/cellimages.xml: %v", err))
  457. return result
  458. }
  459. cellImagesData, err := io.ReadAll(rc)
  460. rc.Close()
  461. if err != nil {
  462. logs.Warning(fmt.Sprintf("无法读取 xl/cellimages.xml: %v", err))
  463. return result
  464. }
  465. cellImagesContent := string(cellImagesData)
  466. // 2. 读取关系文件:优先 xl/_rels/cellimages.xml.rels,找不到再尝试 xl/drawings/_rels/drawing1.xml.rels
  467. var relsFile *zip.File
  468. for _, f := range zipReader.File {
  469. if f != nil && f.Name == "xl/_rels/cellimages.xml.rels" {
  470. relsFile = f
  471. break
  472. }
  473. }
  474. if relsFile == nil {
  475. for _, f := range zipReader.File {
  476. if f != nil && f.Name == "xl/drawings/_rels/drawing1.xml.rels" {
  477. relsFile = f
  478. break
  479. }
  480. }
  481. }
  482. if relsFile == nil {
  483. logs.Warning("未找到 cellimages 对应的关系文件 (cellimages.xml.rels / drawing1.xml.rels)")
  484. return result
  485. }
  486. rc, err = relsFile.Open()
  487. if err != nil {
  488. logs.Warning(fmt.Sprintf("无法打开关系文件 %s: %v", relsFile.Name, err))
  489. return result
  490. }
  491. relsData, err := io.ReadAll(rc)
  492. rc.Close()
  493. if err != nil {
  494. logs.Warning(fmt.Sprintf("无法读取关系文件 %s: %v", relsFile.Name, err))
  495. return result
  496. }
  497. relsContent := string(relsData)
  498. // 2.1 解析关系文件,建立 rId -> Target 的映射
  499. relsMap := make(map[string]string)
  500. reRel := regexp.MustCompile(`Id="([^"]+)"[^>]*Target="([^"]+)"`)
  501. for _, m := range reRel.FindAllStringSubmatch(relsContent, -1) {
  502. if len(m) >= 3 {
  503. id := m[1]
  504. target := m[2]
  505. relsMap[id] = target
  506. }
  507. }
  508. if len(relsMap) == 0 {
  509. logs.Warning(fmt.Sprintf("关系文件 %s 中未解析到任何图片关系", relsFile.Name))
  510. return result
  511. }
  512. // 3. 从 cellimages.xml 中解析每个图片块
  513. // 结构大致类似:
  514. // <xdr:pic> ... <xdr:nvPicPr>...<xdr:cNvPr name="ID_XXXX".../> ...</xdr:nvPicPr> ... <a:blip r:embed="rId1"/> ... </xdr:pic>
  515. picBlocks := regexp.MustCompile(`(?s)<xdr:pic[^>]*>.*?</xdr:pic>`).FindAllString(cellImagesContent, -1)
  516. if len(picBlocks) == 0 {
  517. logs.Warning("xl/cellimages.xml 中未找到任何 <xdr:pic> 图片块")
  518. return result
  519. }
  520. nameRe := regexp.MustCompile(`name="(ID_[^"]+)"`)
  521. embedRe := regexp.MustCompile(`r:embed="([^"]+)"`)
  522. for _, block := range picBlocks {
  523. nameMatch := nameRe.FindStringSubmatch(block)
  524. if len(nameMatch) < 2 {
  525. continue
  526. }
  527. imgID := nameMatch[1]
  528. embedMatch := embedRe.FindStringSubmatch(block)
  529. if len(embedMatch) < 2 {
  530. logs.Warning(fmt.Sprintf("WPS 图片块中 ID %s 未找到 r:embed 属性", imgID))
  531. continue
  532. }
  533. rId := embedMatch[1]
  534. target, ok := relsMap[rId]
  535. if !ok {
  536. logs.Warning(fmt.Sprintf("在关系文件中未找到 rId=%s 对应的图片路径 (ID=%s)", rId, imgID))
  537. continue
  538. }
  539. // 关系文件里的 Target 一般是 media/image1.jpg 或 ../media/image1.jpg
  540. // 在 ZIP 中的真实路径应为 xl/<Target 去掉前导 / >
  541. imagePathInZip := "xl/" + strings.TrimLeft(target, "/")
  542. var imageFile *zip.File
  543. for _, f := range zipReader.File {
  544. if f != nil && f.Name == imagePathInZip {
  545. imageFile = f
  546. break
  547. }
  548. }
  549. if imageFile == nil {
  550. logs.Warning(fmt.Sprintf("在 ZIP 中未找到图片文件 %s (ID=%s, rId=%s)", imagePathInZip, imgID, rId))
  551. continue
  552. }
  553. rcImg, err := imageFile.Open()
  554. if err != nil {
  555. logs.Warning(fmt.Sprintf("无法打开图片文件 %s: %v", imagePathInZip, err))
  556. continue
  557. }
  558. imgData, err := io.ReadAll(rcImg)
  559. rcImg.Close()
  560. if err != nil {
  561. logs.Warning(fmt.Sprintf("无法读取图片文件 %s: %v", imagePathInZip, err))
  562. continue
  563. }
  564. if len(imgData) == 0 {
  565. logs.Warning(fmt.Sprintf("图片文件 %s 为空,跳过 (ID=%s)", imagePathInZip, imgID))
  566. continue
  567. }
  568. result[imgID] = imgData
  569. logs.Info(fmt.Sprintf("WPS cellimages 建立映射: ID %s -> %s (大小: %d 字节)", imgID, imagePathInZip, len(imgData)))
  570. }
  571. logs.Info(fmt.Sprintf("通过 WPS cellimages 共解析出 %d 个 ID->图片 映射", len(result)))
  572. return result
  573. }
  574. // 上传图片数据到七牛云
  575. func (c *TaskController) uploadImageData(imageData []byte, headerName string) (string, error) {
  576. if len(imageData) == 0 {
  577. return "", fmt.Errorf("图片数据为空")
  578. }
  579. // 创建临时目录
  580. tempDir := "./ofile/temp_images"
  581. err := os.MkdirAll(tempDir, 0755)
  582. if err != nil {
  583. return "", fmt.Errorf("创建临时目录失败: %w", err)
  584. }
  585. // 根据图片数据的前几个字节判断图片格式
  586. ext := ".png" // 默认扩展名
  587. if len(imageData) >= 4 {
  588. // PNG: 89 50 4E 47
  589. if imageData[0] == 0x89 && imageData[1] == 0x50 && imageData[2] == 0x4E && imageData[3] == 0x47 {
  590. ext = ".png"
  591. } else if len(imageData) >= 2 {
  592. // JPEG: FF D8
  593. if imageData[0] == 0xFF && imageData[1] == 0xD8 {
  594. ext = ".jpg"
  595. } else if len(imageData) >= 6 {
  596. // GIF: 47 49 46 38
  597. if imageData[0] == 0x47 && imageData[1] == 0x49 && imageData[2] == 0x46 && imageData[3] == 0x38 {
  598. ext = ".gif"
  599. }
  600. }
  601. }
  602. }
  603. fileName := fmt.Sprintf("%s_%s_%d%s", headerName, uuid.New().String(), time.Now().Unix(), ext)
  604. tempFilePath := filepath.Join(tempDir, fileName)
  605. // 保存图片到临时文件
  606. err = os.WriteFile(tempFilePath, imageData, 0644)
  607. if err != nil {
  608. return "", fmt.Errorf("保存图片失败: %w", err)
  609. }
  610. defer func() {
  611. // 确保清理临时文件
  612. if removeErr := os.Remove(tempFilePath); removeErr != nil {
  613. logs.Error(fmt.Sprintf("删除临时文件失败: %s, 错误: %v", tempFilePath, removeErr))
  614. }
  615. }()
  616. // 检查文件是否存在
  617. fileInfo, err := os.Stat(tempFilePath)
  618. if err != nil {
  619. return "", fmt.Errorf("获取文件信息失败: %w", err)
  620. }
  621. // 上传到七牛云
  622. qiniuFileName := fmt.Sprintf("UpImage/excel_import_%s_%d%s", uuid.New().String(), time.Now().Unix(), ext)
  623. logs.Info(fmt.Sprintf("准备上传图片: %s, 大小: %d 字节, 目标: %s", tempFilePath, fileInfo.Size(), qiniuFileName))
  624. imageURL, success := NatsServer.Qiniu_UploadFile(tempFilePath, qiniuFileName)
  625. if !success {
  626. logs.Error(fmt.Sprintf("上传图片到七牛云失败: 文件=%s, 大小=%d 字节, 目标=%s", tempFilePath, fileInfo.Size(), qiniuFileName))
  627. return "", fmt.Errorf("上传图片到七牛云失败,文件大小: %d 字节", fileInfo.Size())
  628. }
  629. if imageURL == "" {
  630. return "", fmt.Errorf("上传图片后未返回URL")
  631. }
  632. logs.Info(fmt.Sprintf("图片上传成功: %s -> %s", tempFilePath, imageURL))
  633. return imageURL, nil
  634. }
  635. // 列表 -
  636. func (c *TaskController) List() {
  637. // 验证登录 User_is, User_r
  638. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  639. if !User_is {
  640. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  641. c.ServeJSON()
  642. return
  643. }
  644. var r_jsons lib.R_JSONS
  645. page, _ := c.GetInt("page")
  646. if page < 1 {
  647. page = 1
  648. }
  649. page_z, _ := c.GetInt("page_z")
  650. if page_z < 1 {
  651. page_z = conf.Page_size
  652. }
  653. T_name := c.GetString("T_name")
  654. T_company := c.GetString("T_company") // 公司名称
  655. T_uuid := c.GetString("T_uuid")
  656. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  657. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  658. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  659. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  660. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  661. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  662. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  663. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  664. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  665. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  666. CreateTime := c.GetString("CreateTime") // 任务添加时间
  667. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  668. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  669. var T_company_list []string
  670. if len(T_company) > 0 {
  671. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  672. }
  673. var T_admin string
  674. if User_r.T_power > 2 {
  675. T_admin = User_r.T_uuid
  676. }
  677. // 经销商下管理员可查看自己经销商下所有的任务
  678. // 经销商下其他角色只能查看分配给自己的任务
  679. if len(User_r.T_Distributor_id) > 0 && User_r.T_power <= 2 {
  680. T_admin = ""
  681. }
  682. var cnt int
  683. 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,
  684. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  685. T_company_list, UserMap, AdminMap, CreateTime, page, page_z)
  686. page_size := math.Ceil(float64(cnt) / float64(page_z))
  687. r_jsons.List = List
  688. r_jsons.Page = page
  689. r_jsons.Page_size = int(page_size)
  690. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  691. r_jsons.Num = cnt
  692. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  693. c.ServeJSON()
  694. return
  695. }
  696. // 报告统计
  697. func (c *TaskController) Stat() {
  698. // 验证登录 User_is, User_r
  699. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  700. if !User_is {
  701. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  702. c.ServeJSON()
  703. return
  704. }
  705. var r_jsons lib.R_JSONS
  706. page, _ := c.GetInt("page")
  707. if page < 1 {
  708. page = 1
  709. }
  710. page_z, _ := c.GetInt("page_z")
  711. if page_z < 1 {
  712. page_z = conf.Page_size
  713. }
  714. T_name := c.GetString("T_name")
  715. T_company := c.GetString("T_company") // 公司名称
  716. T_uuid := c.GetString("T_uuid")
  717. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  718. T_project := c.GetString("T_project") // 项目 负责人UUID
  719. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  720. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  721. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  722. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  723. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  724. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  725. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  726. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  727. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  728. CreateTime := c.GetString("CreateTime") // 任务添加时间
  729. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  730. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  731. var T_company_list []string
  732. if len(T_company) > 0 {
  733. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  734. }
  735. var T_admin string
  736. if User_r.T_power > 2 {
  737. T_admin = User_r.T_uuid
  738. }
  739. var cnt int
  740. 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,
  741. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  742. T_company_list, UserMap, AdminMap, CreateTime, page, page_z)
  743. page_size := math.Ceil(float64(cnt) / float64(page_z))
  744. r_jsons.List = List
  745. r_jsons.Page = page
  746. r_jsons.Page_size = int(page_size)
  747. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  748. r_jsons.Num = cnt
  749. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  750. c.ServeJSON()
  751. return
  752. }
  753. // 报告统计 - 导出excel
  754. func (c *TaskController) Stat_Excel() {
  755. // 验证登录 User_is, User_r
  756. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  757. if !User_is {
  758. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  759. c.ServeJSON()
  760. return
  761. }
  762. T_name := c.GetString("T_name")
  763. T_company := c.GetString("T_company") // 公司名称
  764. T_uuid := c.GetString("T_uuid")
  765. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  766. T_project := c.GetString("T_project") // 项目 负责人UUID
  767. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  768. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  769. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  770. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  771. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  772. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  773. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  774. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  775. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  776. CreateTime := c.GetString("CreateTime") // 任务添加时间
  777. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  778. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  779. var T_company_list []string
  780. if len(T_company) > 0 {
  781. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  782. }
  783. var T_admin string
  784. if User_r.T_power > 2 {
  785. T_admin = User_r.T_uuid
  786. }
  787. 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,
  788. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  789. T_company_list, UserMap, AdminMap, CreateTime, 0, 9999)
  790. f := excelize.NewFile() // 设置单元格的值
  791. line := 1
  792. // 这里设置表头
  793. f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("A%d", line+1))
  794. f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("B%d", line+1))
  795. f.MergeCell("Sheet1", fmt.Sprintf("C%d", line), fmt.Sprintf("C%d", line+1))
  796. f.MergeCell("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("D%d", line+1))
  797. f.MergeCell("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("E%d", line+1))
  798. f.MergeCell("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("F%d", line+1))
  799. f.MergeCell("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("G%d", line+1))
  800. f.MergeCell("Sheet1", fmt.Sprintf("H%d", line), fmt.Sprintf("H%d", line+1))
  801. f.MergeCell("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("I%d", line+1))
  802. f.MergeCell("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("J%d", line+1))
  803. f.MergeCell("Sheet1", fmt.Sprintf("K%d", line), fmt.Sprintf("K%d", line+1))
  804. f.MergeCell("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("L%d", line+1))
  805. f.MergeCell("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("M%d", line+1))
  806. f.MergeCell("Sheet1", fmt.Sprintf("N%d", line), fmt.Sprintf("N%d", line+1))
  807. f.MergeCell("Sheet1", fmt.Sprintf("O%d", line), fmt.Sprintf("O%d", line+1))
  808. f.MergeCell("Sheet1", fmt.Sprintf("P%d", line), fmt.Sprintf("P%d", line+1))
  809. f.MergeCell("Sheet1", fmt.Sprintf("Q%d", line), fmt.Sprintf("U%d", line))
  810. f.MergeCell("Sheet1", fmt.Sprintf("V%d", line), fmt.Sprintf("AA%d", line))
  811. f.MergeCell("Sheet1", fmt.Sprintf("AB%d", line), fmt.Sprintf("AG%d", line))
  812. f.MergeCell("Sheet1", fmt.Sprintf("AH%d", line), fmt.Sprintf("AM%d", line))
  813. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), "信息表")
  814. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), "方案")
  815. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), "实施")
  816. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), "报告")
  817. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "序号")
  818. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "公司名称")
  819. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), "报告名称")
  820. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), "项目负责人")
  821. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), "地区")
  822. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), "类别")
  823. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), "设备类型")
  824. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), "规格/容积")
  825. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), "验证类型")
  826. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), "标的物名称")
  827. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "验证温度范围")
  828. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), "报告编号")
  829. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), "项目开始时间")
  830. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), "项目用时")
  831. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), "驳回次数")
  832. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), "回款")
  833. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line+1), "编写人")
  834. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line+1), "状态")
  835. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line+1), "开始时间")
  836. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line+1), "退回次数")
  837. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line+1), "所需时间")
  838. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line+1), "编写人")
  839. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line+1), "状态")
  840. f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line+1), "开始时间")
  841. f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line+1), "退回次数")
  842. f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line+1), "所需时间")
  843. f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line+1), "超时时间")
  844. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line+1), "编写人")
  845. f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line+1), "状态")
  846. f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line+1), "开始时间")
  847. f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line+1), "退回次数")
  848. f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line+1), "所需时间")
  849. f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line+1), "超时时间")
  850. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line+1), "编写人")
  851. f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line+1), "状态")
  852. f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line+1), "开始时间")
  853. f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line+1), "退回次数")
  854. f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line+1), "所需时间")
  855. f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line+1), "超时时间")
  856. f.SetCellValue("Sheet1", fmt.Sprintf("AN%d", line+1), "领导备注")
  857. // 设置列宽
  858. f.SetColWidth("Sheet1", "A", "A", 7)
  859. f.SetColWidth("Sheet1", "B", "B", 20)
  860. f.SetColWidth("Sheet1", "C", "C", 10)
  861. f.SetColWidth("Sheet1", "D", "D", 10)
  862. f.SetColWidth("Sheet1", "E", "E", 12)
  863. f.SetColWidth("Sheet1", "F", "F", 8)
  864. f.SetColWidth("Sheet1", "G", "G", 12)
  865. f.SetColWidth("Sheet1", "H", "H", 14)
  866. f.SetColWidth("Sheet1", "I", "I", 12)
  867. f.SetColWidth("Sheet1", "J", "J", 12)
  868. f.SetColWidth("Sheet1", "K", "K", 12)
  869. f.SetColWidth("Sheet1", "L", "L", 12)
  870. f.SetColWidth("Sheet1", "M", "M", 12)
  871. f.SetColWidth("Sheet1", "N", "N", 12)
  872. f.SetColWidth("Sheet1", "O", "O", 10)
  873. f.SetColWidth("Sheet1", "P", "P", 8)
  874. f.SetColWidth("Sheet1", "Q", "Q", 8)
  875. f.SetColWidth("Sheet1", "R", "R", 8)
  876. f.SetColWidth("Sheet1", "S", "S", 12)
  877. f.SetColWidth("Sheet1", "T", "T", 10)
  878. f.SetColWidth("Sheet1", "U", "U", 10)
  879. f.SetColWidth("Sheet1", "V", "V", 8)
  880. f.SetColWidth("Sheet1", "W", "W", 8)
  881. f.SetColWidth("Sheet1", "X", "X", 12)
  882. f.SetColWidth("Sheet1", "Y", "Y", 10)
  883. f.SetColWidth("Sheet1", "Z", "Z", 12)
  884. f.SetColWidth("Sheet1", "AA", "AA", 12)
  885. f.SetColWidth("Sheet1", "AB", "AB", 8)
  886. f.SetColWidth("Sheet1", "AC", "AC", 8)
  887. f.SetColWidth("Sheet1", "AD", "AD", 12)
  888. f.SetColWidth("Sheet1", "AE", "AE", 10)
  889. f.SetColWidth("Sheet1", "AF", "AF", 12)
  890. f.SetColWidth("Sheet1", "AG", "AG", 12)
  891. f.SetColWidth("Sheet1", "AG", "AG", 10)
  892. f.SetColWidth("Sheet1", "AH", "AH", 8)
  893. f.SetColWidth("Sheet1", "AI", "AI", 8)
  894. f.SetColWidth("Sheet1", "AJ", "AJ", 10)
  895. f.SetColWidth("Sheet1", "AK", "AK", 12)
  896. f.SetColWidth("Sheet1", "AL", "AL", 12)
  897. f.SetColWidth("Sheet1", "AM", "AM", 12)
  898. Style1, _ := f.NewStyle(
  899. &excelize.Style{
  900. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  901. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  902. Border: []excelize.Border{
  903. {Type: "left", Color: "000000", Style: 1},
  904. {Type: "top", Color: "000000", Style: 1},
  905. {Type: "bottom", Color: "000000", Style: 1},
  906. {Type: "right", Color: "000000", Style: 1},
  907. },
  908. })
  909. f.SetCellStyle("Sheet1", "A1", "AM2", Style1)
  910. f.SetRowHeight("Sheet1", 1, 25)
  911. f.SetRowHeight("Sheet1", 2, 25)
  912. line += 1
  913. // 循环写入数据
  914. for i, v := range List {
  915. line++
  916. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  917. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_user_name)
  918. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name)
  919. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_project_name)
  920. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("%s-%s-%s", v.T_province, v.T_city, v.T_district))
  921. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_category)
  922. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_device_type)
  923. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_volume)
  924. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_verify_type)
  925. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_subject_matter)
  926. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.T_temp_range)
  927. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("%s-%s", v.T_report_type, v.T_report_number))
  928. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v.T_start_time)
  929. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), v.T_time_interval)
  930. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v.T_reject_times)
  931. returnedMoney := "否"
  932. if v.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney {
  933. returnedMoney = "是"
  934. }
  935. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), returnedMoney)
  936. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), v.InfoCollection.T_submit_uuid_name)
  937. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), InfoCollection.InfoCollectionStatusMap[v.InfoCollection.T_State])
  938. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), v.InfoCollection.T_start_time)
  939. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), v.InfoCollection.T_return_times)
  940. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), v.InfoCollection.T_time_interval)
  941. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), v.T_scheme_name)
  942. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line), Task.TaskSchemeStateMap[v.T_scheme_state])
  943. f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line), v.T_scheme_start_time)
  944. f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line), v.T_scheme_return_times)
  945. f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line), v.T_scheme_time_interval)
  946. f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line), v.T_scheme_overtime)
  947. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), v.T_collection_name)
  948. f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line), Task.TaskCollectionStateMap[v.T_collection_state])
  949. f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line), v.T_collection_start_time)
  950. f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line), v.T_collection_return_times)
  951. f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line), v.T_collection_time_interval)
  952. f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line), v.T_collection_overtime)
  953. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), v.T_reporting_name)
  954. f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line), Task.TaskReportingStateMap[v.T_reporting_state])
  955. f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line), v.T_reporting_start_time)
  956. f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line), v.T_reporting_return_times)
  957. f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line), v.T_reporting_time_interval)
  958. f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line), v.T_reporting_overtime)
  959. f.SetCellValue("Sheet1", fmt.Sprintf("AN%d", line), v.T_record)
  960. }
  961. Style2, _ := f.NewStyle(
  962. &excelize.Style{
  963. Font: &excelize.Font{Size: 10, Family: "宋体"},
  964. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  965. Border: []excelize.Border{
  966. {Type: "left", Color: "000000", Style: 1},
  967. {Type: "top", Color: "000000", Style: 1},
  968. {Type: "bottom", Color: "000000", Style: 1},
  969. {Type: "right", Color: "000000", Style: 1},
  970. },
  971. })
  972. f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("AM%d", line), Style2)
  973. StyleBlueFill, _ := f.NewStyle(
  974. &excelize.Style{
  975. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  976. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  977. Border: []excelize.Border{
  978. {Type: "left", Color: "000000", Style: 1},
  979. {Type: "top", Color: "000000", Style: 1},
  980. {Type: "bottom", Color: "000000", Style: 1},
  981. {Type: "right", Color: "000000", Style: 1},
  982. },
  983. Fill: excelize.Fill{Type: "pattern", Color: []string{"#DEE5F5"}, Pattern: 1},
  984. })
  985. // 粉色填充
  986. StylePinkFill, _ := f.NewStyle(
  987. &excelize.Style{
  988. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  989. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  990. Border: []excelize.Border{
  991. {Type: "left", Color: "000000", Style: 1},
  992. {Type: "top", Color: "000000", Style: 1},
  993. {Type: "bottom", Color: "000000", Style: 1},
  994. {Type: "right", Color: "000000", Style: 1},
  995. },
  996. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FBDFE2"}, Pattern: 1},
  997. })
  998. StyleOrangeFill, _ := f.NewStyle(
  999. &excelize.Style{
  1000. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  1001. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  1002. Border: []excelize.Border{
  1003. {Type: "left", Color: "000000", Style: 1},
  1004. {Type: "top", Color: "000000", Style: 1},
  1005. {Type: "bottom", Color: "000000", Style: 1},
  1006. {Type: "right", Color: "000000", Style: 1},
  1007. },
  1008. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FCE7D8"}, Pattern: 1},
  1009. })
  1010. StyleYellowFill, _ := f.NewStyle(
  1011. &excelize.Style{
  1012. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  1013. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  1014. Border: []excelize.Border{
  1015. {Type: "left", Color: "000000", Style: 1},
  1016. {Type: "top", Color: "000000", Style: 1},
  1017. {Type: "bottom", Color: "000000", Style: 1},
  1018. {Type: "right", Color: "000000", Style: 1},
  1019. },
  1020. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFF5D0"}, Pattern: 1},
  1021. })
  1022. StyleGreenFill, _ := f.NewStyle(
  1023. &excelize.Style{
  1024. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  1025. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  1026. Border: []excelize.Border{
  1027. {Type: "left", Color: "000000", Style: 1},
  1028. {Type: "top", Color: "000000", Style: 1},
  1029. {Type: "bottom", Color: "000000", Style: 1},
  1030. {Type: "right", Color: "000000", Style: 1},
  1031. },
  1032. Fill: excelize.Fill{Type: "pattern", Color: []string{"#E7F4DE"}, Pattern: 1},
  1033. })
  1034. f.SetCellStyle("Sheet1", "A1", "AM2", StyleBlueFill)
  1035. f.SetCellStyle("Sheet1", "Q1", "U1", StylePinkFill)
  1036. f.SetCellStyle("Sheet1", "V1", "AA1", StyleOrangeFill)
  1037. f.SetCellStyle("Sheet1", "AB1", "AG1", StyleYellowFill)
  1038. f.SetCellStyle("Sheet1", "AH1", "AM1", StyleGreenFill)
  1039. f.SetCellStyle("Sheet1", "AN1", "AN2", StyleBlueFill)
  1040. // 冻结1-2行
  1041. f.SetPanes("Sheet1", &excelize.Panes{
  1042. Freeze: true,
  1043. Split: false,
  1044. XSplit: 3,
  1045. YSplit: 2,
  1046. TopLeftCell: "A1",
  1047. ActivePane: "topRight",
  1048. })
  1049. lib.Create_Dir("./ofile")
  1050. timeStr := time.Now().Format("20060102150405")
  1051. // 保存文件
  1052. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  1053. logs.Error(lib.FuncName(), err)
  1054. }
  1055. if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx") {
  1056. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  1057. c.ServeJSON()
  1058. return
  1059. }
  1060. //删除目录
  1061. err := os.Remove("ofile/" + timeStr + ".xlsx")
  1062. if err != nil {
  1063. logs.Error(lib.FuncName(), err)
  1064. }
  1065. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + timeStr + ".xlsx"}
  1066. c.ServeJSON()
  1067. return
  1068. }
  1069. // 导出唯一任务标识
  1070. func (c *TaskController) ExportTaskUid() {
  1071. // 验证登录
  1072. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1073. if !User_is {
  1074. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1075. c.ServeJSON()
  1076. return
  1077. }
  1078. T_num, _ := c.GetInt("T_num")
  1079. if T_num <= 0 {
  1080. T_num = 10
  1081. }
  1082. if T_num > 1000 {
  1083. c.Data["json"] = lib.JSONS{Code: 202, Msg: "单次最多生成1000个唯一标识"}
  1084. c.ServeJSON()
  1085. return
  1086. }
  1087. uidList := make([]string, 0, T_num)
  1088. exists := make(map[string]struct{}, T_num)
  1089. exportBatch := fmt.Sprintf("export_%d", time.Now().UnixNano())
  1090. for len(uidList) < T_num {
  1091. candidate := strings.ToUpper(strings.ReplaceAll(uuid.New().String(), "-", ""))
  1092. if len(candidate) > 16 {
  1093. candidate = candidate[:16]
  1094. }
  1095. if _, ok := exists[candidate]; ok {
  1096. continue
  1097. }
  1098. if _, found := Task.Read_Task_ByUid(candidate); found {
  1099. continue
  1100. }
  1101. if Task.TaskUidExists(candidate) {
  1102. continue
  1103. }
  1104. exists[candidate] = struct{}{}
  1105. uidList = append(uidList, candidate)
  1106. }
  1107. f := excelize.NewFile()
  1108. sheet := "Sheet1"
  1109. f.SetCellValue(sheet, "A1", "序号")
  1110. f.SetCellValue(sheet, "B1", "唯一标识")
  1111. for i, uid := range uidList {
  1112. row := i + 2
  1113. f.SetCellValue(sheet, fmt.Sprintf("A%d", row), i+1)
  1114. f.SetCellValue(sheet, fmt.Sprintf("B%d", row), uid)
  1115. }
  1116. f.SetColWidth(sheet, "A", "A", 12)
  1117. f.SetColWidth(sheet, "B", "B", 30)
  1118. lib.Create_Dir("./ofile")
  1119. fileName := fmt.Sprintf("task_uid_%d.xlsx", time.Now().Unix())
  1120. localPath := "ofile/" + fileName
  1121. if err := f.SaveAs(localPath); err != nil {
  1122. logs.Error("ExportTaskUid SaveAs error:", err)
  1123. c.Data["json"] = lib.JSONS{Code: 202, Msg: "生成Excel失败!"}
  1124. c.ServeJSON()
  1125. return
  1126. }
  1127. if !lib.Pload_qiniu(localPath, localPath) {
  1128. c.Data["json"] = lib.JSONS{Code: 203, Msg: "文件上传失败!"}
  1129. c.ServeJSON()
  1130. return
  1131. }
  1132. if err := os.Remove(localPath); err != nil {
  1133. logs.Error("ExportTaskUid remove temp file:", err)
  1134. }
  1135. if err := Task.SaveTaskUids(uidList, exportBatch); err != nil {
  1136. c.Data["json"] = lib.JSONS{Code: 204, Msg: "保存唯一标识失败!"}
  1137. c.ServeJSON()
  1138. return
  1139. }
  1140. url := "https://bzdcoldverifyoss.baozhida.cn/" + localPath
  1141. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1142. c.ServeJSON()
  1143. return
  1144. }
  1145. // 获取任务负责人列表
  1146. func (c *TaskController) GetTaskUserList() {
  1147. // 验证登录 User_is, User_r
  1148. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1149. if !User_is {
  1150. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1151. c.ServeJSON()
  1152. return
  1153. }
  1154. T_type := c.GetString("T_type") // T_project项目 T_scheme方案 T_collection数据采集 T_reporting报告
  1155. list := Task.Get_Task_UserList(T_type)
  1156. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1157. var User_list []Account.Admin_R
  1158. for _, v := range list {
  1159. if len(v) == 0 {
  1160. continue
  1161. }
  1162. User_list = append(User_list, Account.Admin_R{T_uuid: v, T_name: AdminMap[v]})
  1163. }
  1164. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_list}
  1165. c.ServeJSON()
  1166. return
  1167. }
  1168. // 列表 -
  1169. func (c *TaskController) UserTaskList() {
  1170. // 验证登录 User_is, User_r
  1171. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1172. if !User_is {
  1173. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1174. c.ServeJSON()
  1175. return
  1176. }
  1177. var r_jsons lib.R_JSONS
  1178. page, _ := c.GetInt("page")
  1179. if page < 1 {
  1180. page = 1
  1181. }
  1182. page_z, _ := c.GetInt("page_z")
  1183. if page_z < 1 {
  1184. page_z = conf.Page_size
  1185. }
  1186. T_name := c.GetString("T_name")
  1187. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  1188. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1189. var cnt int
  1190. List, cnt := Task.Read_UserTask_List(User_r.T_uuid, T_name, UserMap, AdminMap, page, page_z)
  1191. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1192. r_jsons.List = List
  1193. r_jsons.Page = page
  1194. r_jsons.Page_size = int(page_size)
  1195. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1196. r_jsons.Num = cnt
  1197. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1198. c.ServeJSON()
  1199. return
  1200. }
  1201. // 获取-
  1202. func (c *TaskController) Get() {
  1203. // 验证登录 User_is, User_r
  1204. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1205. if !User_is {
  1206. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1207. c.ServeJSON()
  1208. return
  1209. }
  1210. T_task_id := c.GetString("T_task_id")
  1211. r, is := Task.Read_Task(T_task_id)
  1212. if !is {
  1213. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1214. c.ServeJSON()
  1215. return
  1216. }
  1217. // 添加浏览量
  1218. _ = Task.Add_Task_Visit(r)
  1219. r.T_Visit += 1
  1220. userMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  1221. adminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1222. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Task.TaskToTask_Stat(r, userMap, adminMap)}
  1223. c.ServeJSON()
  1224. return
  1225. }
  1226. // 添加-
  1227. func (c *TaskController) Add() {
  1228. // 验证登录 User_is, User_r
  1229. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1230. if !User_is {
  1231. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1232. c.ServeJSON()
  1233. return
  1234. }
  1235. dc := Device.DeviceClass{
  1236. T_uuid: User_r.T_uuid,
  1237. T_State: 1,
  1238. }
  1239. T_class_id, is := Device.Add_DeviceClass(dc)
  1240. if !is {
  1241. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  1242. c.ServeJSON()
  1243. return
  1244. }
  1245. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
  1246. T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
  1247. T_name := c.GetString("T_name")
  1248. T_uuid := c.GetString("T_uuid") // 用户uuid
  1249. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  1250. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  1251. T_deadline := c.GetString("T_deadline")
  1252. T_scheme := c.GetString("T_scheme")
  1253. T_collection := c.GetString("T_collection")
  1254. T_reporting := c.GetString("T_reporting")
  1255. T_delivery := c.GetString("T_delivery")
  1256. T_project := c.GetString("T_project") // 项目 负责人UUID
  1257. T_province := c.GetString("T_province") // 省
  1258. T_city := c.GetString("T_city") // 市
  1259. T_district := c.GetString("T_district") // 区
  1260. T_province_code := c.GetString("T_province_code") // 省 code
  1261. T_city_code := c.GetString("T_city_code") // 市 code
  1262. T_district_code := c.GetString("T_district_code") // 区 code
  1263. T_category := c.GetString("T_category") // 类别
  1264. T_device_type := c.GetString("T_device_type") // 设备类型
  1265. T_volume := c.GetString("T_volume") // 规格/容积
  1266. T_verify_type := c.GetString("T_verify_type") // 验证类型
  1267. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  1268. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  1269. T_report_number := c.GetString("T_report_number") // 报告编号
  1270. T_report_type := c.GetString("T_report_type") // 报告类型
  1271. T_device_quantity, _ := c.GetInt("T_device_quantity") // 终端数量
  1272. T_cnas, _ := c.GetInt("T_cnas") // cnas实验室
  1273. // 查询信息采集信息
  1274. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  1275. if !is {
  1276. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  1277. c.ServeJSON()
  1278. return
  1279. }
  1280. // 查询信息采集信息
  1281. user, is := Account.Read_User(T_uuid)
  1282. if !is {
  1283. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid 错误!"}
  1284. c.ServeJSON()
  1285. return
  1286. }
  1287. var_ := Task.Task{
  1288. T_Distributor_id: user.T_Distributor_id,
  1289. T_InfoCollection_id: T_InfoCollection_id,
  1290. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  1291. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  1292. T_class: int(T_class_id),
  1293. T_uuid: T_uuid,
  1294. T_name: T_name,
  1295. T_VerifyTemplate_class: T_VerifyTemplate_class,
  1296. T_VerifyTemplate_id: T_VerifyTemplate_id,
  1297. T_deadline: T_deadline,
  1298. T_scheme: T_scheme,
  1299. T_collection: T_collection,
  1300. T_reporting: T_reporting,
  1301. T_delivery: T_delivery,
  1302. T_Show: 1,
  1303. T_State: 1,
  1304. T_project: T_project,
  1305. T_province: T_province,
  1306. T_city: T_city,
  1307. T_district: T_district,
  1308. T_province_code: T_province_code,
  1309. T_city_code: T_city_code,
  1310. T_district_code: T_district_code,
  1311. T_category: T_category,
  1312. T_device_type: T_device_type,
  1313. T_volume: T_volume,
  1314. T_verify_type: T_verify_type,
  1315. T_subject_matter: T_subject_matter,
  1316. T_temp_range: T_temp_range,
  1317. T_report_number: T_report_number,
  1318. T_report_type: T_report_type,
  1319. T_device_quantity: T_device_quantity,
  1320. T_cnas: T_cnas,
  1321. }
  1322. if T_report_number != "/" {
  1323. _, exist := Task.Read_TaskbyT_report_number(T_report_number)
  1324. if exist {
  1325. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报告编号已存在!"}
  1326. c.ServeJSON()
  1327. return
  1328. }
  1329. }
  1330. T_task_id, is := Task.Add_Task(var_)
  1331. if !is {
  1332. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1333. c.ServeJSON()
  1334. return
  1335. }
  1336. NatsServer.Create_Local_Table(T_task_id)
  1337. Task.Redis_Task_T_report_number_DelK(T_report_number) // 删除redis内的任务编号
  1338. // 通知
  1339. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  1340. go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  1341. go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  1342. go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  1343. go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  1344. // 同步信息采集表 --------
  1345. InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(var_.T_InfoTemplate_id)
  1346. InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(var_.T_InfoCollection_id, var_.T_InfoTemplate_id, InfoCollection_Map_List)
  1347. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(var_.T_VerifyTemplate_id, 0, 0)
  1348. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_task_id, var_.T_VerifyTemplate_id, Map_List)
  1349. InfoCollectionDataMap := make(map[string]string)
  1350. for _, data := range InfoCollection_Data {
  1351. InfoCollectionDataMap[data.T_name] = data.T_value
  1352. }
  1353. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  1354. for _, v := range Data {
  1355. if len(v.T_value) > 0 {
  1356. continue
  1357. }
  1358. if InfoCollectionDataMap[v.T_name] == "" {
  1359. continue
  1360. }
  1361. val := VerifyTemplate.VerifyTemplateMapData{
  1362. T_source: v.T_source,
  1363. T_task_id: T_task_id,
  1364. T_VerifyTemplate_id: var_.T_VerifyTemplate_id,
  1365. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  1366. T_flow_sort: v.T_flow_sort,
  1367. T_max_time: v.T_max_time,
  1368. T_min_time: v.T_min_time,
  1369. T_value: InfoCollectionDataMap[v.T_name],
  1370. }
  1371. MapDataList = append(MapDataList, val)
  1372. }
  1373. _, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  1374. if !is {
  1375. c.Data["json"] = lib.JSONS{Code: 202, Msg: "同步信息采集表失败"}
  1376. c.ServeJSON()
  1377. return
  1378. }
  1379. // 同步信息采集表结束 --------
  1380. // 添加任务操作日志
  1381. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "添加", var_)
  1382. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "添加", var_)
  1383. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  1384. c.ServeJSON()
  1385. return
  1386. }
  1387. // 接收信息采集
  1388. func (c *TaskController) ReceiptInfoCollection() {
  1389. // 验证登录 User_is, User_r
  1390. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1391. if !User_is {
  1392. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1393. c.ServeJSON()
  1394. return
  1395. }
  1396. // 修改信息采集状态为已接收
  1397. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  1398. //T_status,_ := c.GetInt("T_status")
  1399. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  1400. if !is {
  1401. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1402. c.ServeJSON()
  1403. return
  1404. }
  1405. if infoCollection.T_status != InfoCollection.InfoCollectionStatusSubmitted && infoCollection.T_status != InfoCollection.InfoCollectionStatusReceipt {
  1406. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止接收!", InfoCollection.InfoCollectionStatusMap[infoCollection.T_status])}
  1407. c.ServeJSON()
  1408. return
  1409. }
  1410. //infoCollection.T_status = InfoCollection.InfoCollectionStatusReceipt
  1411. //if len(infoCollection.T_end_time) == 0 {
  1412. // infoCollection.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  1413. // infoCollection.T_time_interval, _ = lib.MinutesDifference(infoCollection.T_start_time, infoCollection.T_end_time)
  1414. //}
  1415. //if !InfoCollection.Update_InfoCollection(infoCollection, "T_status", "T_end_time", "T_time_interval") {
  1416. infoCollection.T_status = 3 // 已接收
  1417. if !InfoCollection.Update_InfoCollection(infoCollection, "T_status") {
  1418. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1419. c.ServeJSON()
  1420. return
  1421. }
  1422. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "接收信息采集", infoCollection)
  1423. //if T_status == InfoCollection.InfoCollectionStatusReturn{
  1424. // // 通知 报告负责人审核
  1425. // _, company_r := Account.Read_User_ByT_uuid(infoCollection.T_uuid)
  1426. // System.Add_News(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name), "")
  1427. // go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name))
  1428. //
  1429. //}
  1430. // 修改任务管理实施方案开始时间
  1431. //T_task_id := c.GetString("T_task_id")
  1432. //task, is := Task.Read_Task(T_task_id)
  1433. //if !is {
  1434. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1435. // c.ServeJSON()
  1436. // return
  1437. //}
  1438. // 添加任务操作日志
  1439. //Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "接收信息采集", task)
  1440. //System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "接收信息采集", task)
  1441. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1442. c.ServeJSON()
  1443. return
  1444. }
  1445. // 添加-
  1446. func (c *TaskController) AddData_Tool() {
  1447. T_uuid := "3e84dda9-9eec-42b9-9350-0894262fc8a1" // 用户uuid
  1448. T_name := c.GetString("T_name")
  1449. T_task_id := c.GetString("T_task_id")
  1450. T_task_id = strings.ToLower(T_task_id)
  1451. r, _ := Task.Read_Task(T_task_id)
  1452. if r.T_collection_state == 2 {
  1453. c.Data["json"] = lib.JSONS{Code: 200, Msg: "数据采集中..."}
  1454. c.ServeJSON()
  1455. return
  1456. }
  1457. if r.Id > 0 {
  1458. // 同步1.0数据
  1459. NatsServer.Sync1_TaskData(T_task_id)
  1460. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  1461. c.ServeJSON()
  1462. return
  1463. }
  1464. dc := Device.DeviceClass{
  1465. T_uuid: T_uuid,
  1466. T_State: 1,
  1467. }
  1468. T_class_id, is := Device.Add_DeviceClass(dc)
  1469. if !is {
  1470. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  1471. c.ServeJSON()
  1472. return
  1473. }
  1474. var_ := Task.Task{
  1475. T_task_id: T_task_id,
  1476. T_class: int(T_class_id),
  1477. T_uuid: T_uuid,
  1478. T_name: T_name,
  1479. T_Show: 1,
  1480. T_State: 1,
  1481. T_collection_state: 2,
  1482. }
  1483. _, is = Task.Add_Task_Tool(var_)
  1484. if !is {
  1485. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1486. c.ServeJSON()
  1487. return
  1488. }
  1489. // 创建本地表
  1490. NatsServer.Create_Local_Table(T_task_id)
  1491. // 同步1.0数据
  1492. NatsServer.Sync1_TaskData(T_task_id)
  1493. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  1494. c.ServeJSON()
  1495. return
  1496. }
  1497. // 修改采集状态-
  1498. func (c *TaskController) UpCollectionState() {
  1499. // 验证登录 User_is, User_r
  1500. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1501. if !User_is {
  1502. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1503. c.ServeJSON()
  1504. return
  1505. }
  1506. T_collection_state, _ := c.GetInt("T_collection_state")
  1507. T_reason := c.GetString("T_reason") // 退回原因
  1508. T_task_id := c.GetString("T_task_id")
  1509. r, is := Task.Read_Task(T_task_id)
  1510. if !is {
  1511. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1512. c.ServeJSON()
  1513. return
  1514. }
  1515. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1516. r.T_collection_state = T_collection_state
  1517. clos := make([]string, 0)
  1518. clos = append(clos, "T_collection_state")
  1519. if T_collection_state == Task.TaskCollectionStateReturn {
  1520. r.T_collection_return_times += 1
  1521. clos = append(clos, "T_collection_return_times")
  1522. }
  1523. if T_collection_state == Task.TaskCollectionStateSubmitted ||
  1524. T_collection_state == Task.TaskCollectionStateReturn ||
  1525. T_collection_state == Task.TaskCollectionStatePass {
  1526. // 添加已提交状态验证报告记录
  1527. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, T_collection_state, T_reason, "")
  1528. if err != nil {
  1529. return
  1530. }
  1531. r.T_collection_audit_record = auditRecordJson
  1532. clos = append(clos, "T_collection_audit_record")
  1533. }
  1534. if T_collection_state == Task.TaskCollectionStatePass {
  1535. // 数据编辑审核通过时间为验证报告开始时间
  1536. r.T_reporting_start_time = time.Now().Format("2006-01-02 15:04:05")
  1537. clos = append(clos, "T_reporting_start_time")
  1538. }
  1539. if !Task.Update_Task(r, clos...) {
  1540. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1541. c.ServeJSON()
  1542. return
  1543. }
  1544. // 已退回(负责人)
  1545. if T_collection_state == Task.TaskCollectionStateReturn {
  1546. 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), "")
  1547. 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))
  1548. }
  1549. // 添加任务操作日志
  1550. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改采集状态", r)
  1551. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改采集状态", r)
  1552. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1553. c.ServeJSON()
  1554. return
  1555. }
  1556. func (c *TaskController) UpDeliveryState() {
  1557. // 验证登录 User_is, User_r
  1558. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1559. if !User_is {
  1560. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1561. c.ServeJSON()
  1562. return
  1563. }
  1564. T_delivery_state, _ := c.GetInt("T_delivery_state")
  1565. T_task_id := c.GetString("T_task_id")
  1566. r, is := Task.Read_Task(T_task_id)
  1567. if !is {
  1568. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1569. c.ServeJSON()
  1570. return
  1571. }
  1572. r.T_delivery_state = T_delivery_state
  1573. if !Task.Update_Task(r, "T_delivery_state") {
  1574. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1575. c.ServeJSON()
  1576. return
  1577. }
  1578. // 添加任务操作日志
  1579. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改交付审核状态", r)
  1580. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改交付审核状态", r)
  1581. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1582. c.ServeJSON()
  1583. return
  1584. }
  1585. // 更新线上数据后台执行
  1586. func (c *TaskDataController) TaskData_Up_TaskData_Back() {
  1587. // 验证登录 User_is, User_r
  1588. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1589. if !User_is {
  1590. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1591. c.ServeJSON()
  1592. return
  1593. }
  1594. T_task_id := c.GetString("T_task_id")
  1595. r, is := Task.Read_Task(T_task_id)
  1596. if !is {
  1597. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1598. c.ServeJSON()
  1599. return
  1600. }
  1601. // 通知 报告人员
  1602. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1603. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1604. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name), "")
  1605. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name))
  1606. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1607. c.ServeJSON()
  1608. return
  1609. }
  1610. // 修改-
  1611. func (c *TaskController) Up() {
  1612. // 验证登录 User_is, User_r
  1613. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1614. if !User_is {
  1615. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1616. c.ServeJSON()
  1617. return
  1618. }
  1619. T_name := c.GetString("T_name")
  1620. T_Show, T_Show_err := c.GetInt("T_Show")
  1621. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  1622. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  1623. T_deadline := c.GetString("T_deadline")
  1624. T_scheme := c.GetString("T_scheme")
  1625. T_collection := c.GetString("T_collection")
  1626. T_collection_state, _ := c.GetInt("T_collection_state")
  1627. T_collection_signature := c.GetString("T_collection_signature") // 完成编辑签字图片
  1628. T_reporting := c.GetString("T_reporting")
  1629. T_delivery := c.GetString("T_delivery")
  1630. T_record := c.GetString("T_record")
  1631. T_doc1 := c.GetString("T_doc1")
  1632. T_pdf1 := c.GetString("T_pdf1") // 方案
  1633. T_pdf1_stamp, _ := c.GetBool("T_pdf1_stamp") // 方案加盖公章
  1634. T_doc2 := c.GetString("T_doc2")
  1635. T_pdf2 := c.GetString("T_pdf2") // 证书
  1636. T_pdf2_stamp, _ := c.GetBool("T_pdf2_stamp") // 报告加盖公章
  1637. T_doc3 := c.GetString("T_doc3")
  1638. T_pdf3 := c.GetString("T_pdf3")
  1639. T_pdf4 := c.GetString("T_pdf4") // 验证标识
  1640. T_pdf5 := c.GetString("T_pdf5") // 检测报告
  1641. T_pdf6 := c.GetString("T_pdf6") // 原始记录
  1642. T_VerifyDeviceDataStartTime := c.GetString("T_VerifyDeviceDataStartTime") // 验证设备数据开始时间
  1643. T_VerifyDeviceDataEndTime := c.GetString("T_VerifyDeviceDataEndTime") // 验证设备数据开始时间
  1644. T_BindDeviceDataStartTime := c.GetString("T_BindDeviceDataStartTime") // 绑定设备数据开始时间
  1645. T_BindDeviceDataEndTime := c.GetString("T_BindDeviceDataEndTime") // 绑定设备数据结束时间
  1646. T_sn := c.GetString("T_sn") // T_sn
  1647. T_CalibrationExpirationTime := c.GetString("T_CalibrationExpirationTime") // 校准到期时间
  1648. T_project := c.GetString("T_project") // 项目 负责人UUID
  1649. T_province := c.GetString("T_province") // 省
  1650. T_city := c.GetString("T_city") // 市
  1651. T_district := c.GetString("T_district") // 区
  1652. T_province_code := c.GetString("T_province_code") // 省 code
  1653. T_city_code := c.GetString("T_city_code") // 市 code
  1654. T_district_code := c.GetString("T_district_code") // 区 code
  1655. T_category := c.GetString("T_category") // 类别
  1656. T_device_type := c.GetString("T_device_type") // 设备类型
  1657. T_volume := c.GetString("T_volume") // 规格/容积
  1658. T_verify_type := c.GetString("T_verify_type") // 验证类型
  1659. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  1660. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  1661. T_report_number := c.GetString("T_report_number") // 报告编号
  1662. T_report_type := c.GetString("T_report_type") // 报告编号
  1663. T_device_quantity, _ := c.GetInt("T_device_quantity") // 报告编号
  1664. T_cnas, _ := c.GetInt("T_cnas") // cnas实验室
  1665. T_task_id := c.GetString("T_task_id")
  1666. r, is := Task.Read_Task(T_task_id)
  1667. if !is {
  1668. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1669. c.ServeJSON()
  1670. return
  1671. }
  1672. if len(T_report_number) > 0 && T_report_number != "/" {
  1673. t, exist := Task.Read_TaskbyT_report_number(T_report_number)
  1674. if exist && r.T_task_id != t.T_task_id {
  1675. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报告编号已存在!"}
  1676. c.ServeJSON()
  1677. return
  1678. }
  1679. }
  1680. // .......
  1681. clos := make([]string, 0)
  1682. if len(T_name) > 0 {
  1683. r.T_name = T_name
  1684. clos = append(clos, "T_name")
  1685. }
  1686. if T_Show_err == nil {
  1687. r.T_Show = T_Show
  1688. clos = append(clos, "T_Show")
  1689. }
  1690. if len(T_VerifyTemplate_class) > 0 {
  1691. r.T_VerifyTemplate_class = T_VerifyTemplate_class
  1692. clos = append(clos, "T_VerifyTemplate_class")
  1693. }
  1694. if len(T_VerifyTemplate_id) > 0 {
  1695. // 保存旧的 T_VerifyTemplate_id
  1696. old_T_VerifyTemplate_id := r.T_VerifyTemplate_id
  1697. // 判断旧的模版id与新模版id是否一致,如果不一致则复制旧模板数据到新模板
  1698. if old_T_VerifyTemplate_id != T_VerifyTemplate_id && len(old_T_VerifyTemplate_id) > 0 {
  1699. // 创建新任务对象用于复制数据
  1700. new_task := r
  1701. new_task.T_VerifyTemplate_id = T_VerifyTemplate_id
  1702. _, err := CopyMapData(r, new_task, 0)
  1703. if err != nil {
  1704. logs.Error("复制旧模板数据到新模板失败", err)
  1705. }
  1706. }
  1707. r.T_VerifyTemplate_id = T_VerifyTemplate_id
  1708. clos = append(clos, "T_VerifyTemplate_id")
  1709. }
  1710. if len(T_deadline) > 0 {
  1711. r.T_deadline = T_deadline
  1712. clos = append(clos, "T_deadline")
  1713. }
  1714. if len(T_scheme) > 0 {
  1715. r.T_scheme = T_scheme
  1716. clos = append(clos, "T_scheme")
  1717. }
  1718. if len(T_collection) > 0 {
  1719. r.T_collection = T_collection
  1720. clos = append(clos, "T_collection")
  1721. }
  1722. if len(T_reporting) > 0 {
  1723. r.T_reporting = T_reporting
  1724. clos = append(clos, "T_reporting")
  1725. }
  1726. if len(T_delivery) > 0 {
  1727. r.T_delivery = T_delivery
  1728. clos = append(clos, "T_delivery")
  1729. }
  1730. if len(T_record) > 0 {
  1731. r.T_record = T_record
  1732. clos = append(clos, "T_record")
  1733. }
  1734. // 完成编辑后设置实施结束时间
  1735. if T_collection_state == 4 {
  1736. r.T_collection_state = T_collection_state
  1737. clos = append(clos, "T_collection_state")
  1738. r.T_collection_signature = T_collection_signature
  1739. clos = append(clos, "T_collection_signature")
  1740. r.T_collection_end_time = time.Now().Format("2006-01-02 15:04:05")
  1741. clos = append(clos, "T_collection_end_time")
  1742. if len(r.T_collection_start_time) > 0 {
  1743. r.T_collection_time_interval, _ = lib.MinutesDifference(r.T_collection_start_time, r.T_collection_end_time)
  1744. // 扣除暂停时间
  1745. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 1)
  1746. if Task_Compute > 0 {
  1747. r.T_collection_time_interval -= float64(Task_Compute)
  1748. }
  1749. clos = append(clos, "T_collection_time_interval")
  1750. // 所需时间 > 超时时间
  1751. if r.T_collection_time_interval > Task.TaskCollectionTimeLimit && len(r.T_report_type) > 0 {
  1752. r.T_collection_overtime = r.T_collection_time_interval - Task.TaskCollectionTimeLimit // 超时时间
  1753. clos = append(clos, "T_collection_overtime")
  1754. }
  1755. // 通知 报告人员
  1756. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1757. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name), "")
  1758. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name))
  1759. }
  1760. // 添加已提交状态数据编辑记录
  1761. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, r.T_collection_state, "", "")
  1762. if err == nil {
  1763. r.T_collection_audit_record = auditRecordJson
  1764. clos = append(clos, "T_collection_audit_record")
  1765. }
  1766. }
  1767. if len(T_doc1) > 0 {
  1768. r.T_doc1 = T_doc1
  1769. clos = append(clos, "T_doc1")
  1770. }
  1771. // 验证报告内容T_pdf1,上传后将 当前任务 验证方案 标志 为 5 (0未完成 1已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交)
  1772. // 上传后设置方案结束时间,计算所需时间和超时时间
  1773. if len(T_pdf1) > 0 {
  1774. r.T_pdf1 = T_pdf1
  1775. clos = append(clos, "T_pdf1")
  1776. //r.T_pdf1_watermark = GetWatermarkPdf(r,T_pdf1,"T_pdf1")
  1777. //clos = append(clos, "T_pdf1_watermark")
  1778. go GetWatermarkPdf(r, T_pdf1, T_pdf1_stamp, "T_pdf1")
  1779. r.T_scheme_state = 5
  1780. clos = append(clos, "T_scheme_state")
  1781. // 添加已提交状态验证方案记录
  1782. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, "", User_r.T_uuid, r.T_scheme_state, "", "")
  1783. if err != nil {
  1784. return
  1785. }
  1786. r.T_scheme_audit_record = auditRecordJson
  1787. clos = append(clos, "T_scheme_audit_record")
  1788. r.T_scheme_end_time = time.Now().Format("2006-01-02 15:04:05")
  1789. clos = append(clos, "T_scheme_end_time")
  1790. r.T_scheme_time_interval, _ = lib.MinutesDifference(r.T_scheme_start_time, r.T_scheme_end_time)
  1791. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 0)
  1792. if Task_Compute > 0 {
  1793. r.T_scheme_time_interval -= float64(Task_Compute)
  1794. }
  1795. clos = append(clos, "T_scheme_time_interval")
  1796. // 所需时间 > 超时时间
  1797. if r.T_scheme_time_interval > Task.TaskSchemeTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1798. r.T_scheme_overtime = r.T_scheme_time_interval - Task.TaskSchemeTimeLimit[r.T_report_type] // 超时时间
  1799. if Task.TaskSchemeTimeLimit[r.T_report_type] == 0 {
  1800. r.T_scheme_overtime = 0
  1801. }
  1802. clos = append(clos, "T_scheme_overtime")
  1803. }
  1804. // 通知 实施人员进场
  1805. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1806. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name), "")
  1807. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name))
  1808. }
  1809. if len(T_doc2) > 0 {
  1810. r.T_doc2 = T_doc2
  1811. clos = append(clos, "T_doc2")
  1812. }
  1813. // 验证报告内容T_pdf2 ,上传后将 当前任务 报告编写 标志 为 1
  1814. // 上传后设置报告结束时间,计算所需时间和超时时间
  1815. if len(T_pdf2) > 0 {
  1816. r.T_pdf2 = T_pdf2
  1817. clos = append(clos, "T_pdf2")
  1818. //r.T_pdf2_watermark = GetWatermarkPdf(T_pdf2,"T_pdf1")
  1819. //clos = append(clos, "T_pdf2_watermark")
  1820. go GetWatermarkPdf(r, T_pdf2, T_pdf2_stamp, "T_pdf2")
  1821. r.T_reporting_state = 5
  1822. r.T_reporting_submit_time = time.Now().Format("2006-01-02 15:04:05")
  1823. clos = append(clos, "T_reporting_state", "T_reporting_submit_time")
  1824. // 添加已提交状态验证报告记录
  1825. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, "", User_r.T_uuid, r.T_reporting_state, "", "")
  1826. if err == nil {
  1827. r.T_reporting_audit_record = auditRecordJson
  1828. clos = append(clos, "T_reporting_audit_record")
  1829. r.T_reporting_end_time = time.Now().Format("2006-01-02 15:04:05")
  1830. clos = append(clos, "T_reporting_end_time")
  1831. if len(r.T_reporting_start_time) > 0 {
  1832. r.T_reporting_time_interval, _ = lib.MinutesDifference(r.T_reporting_start_time, r.T_reporting_end_time)
  1833. clos = append(clos, "T_reporting_time_interval")
  1834. // 扣除暂停时间
  1835. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 2)
  1836. if Task_Compute > 0 {
  1837. r.T_reporting_time_interval -= float64(Task_Compute)
  1838. }
  1839. clos = append(clos, "T_reporting_time_interval")
  1840. // 所需时间 > 超时时间
  1841. if r.T_reporting_time_interval > Task.TaskReportingTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1842. r.T_reporting_overtime = r.T_reporting_time_interval - Task.TaskReportingTimeLimit[r.T_report_type] // 超时时间
  1843. if Task.TaskReportingTimeLimit[r.T_report_type] == 0 {
  1844. r.T_reporting_overtime = 0
  1845. }
  1846. clos = append(clos, "T_reporting_overtime")
  1847. }
  1848. }
  1849. }
  1850. // 通知 报告人员
  1851. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1852. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name), "")
  1853. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name))
  1854. }
  1855. if len(T_doc3) > 0 {
  1856. r.T_doc3 = T_doc3
  1857. clos = append(clos, "T_doc3")
  1858. }
  1859. if len(T_pdf3) > 0 {
  1860. r.T_pdf3 = T_pdf3
  1861. clos = append(clos, "T_pdf3")
  1862. }
  1863. // 验证标识内容T_pdf4 ,上传后将 当前任务 验证标识 标志 为 1
  1864. if len(T_pdf4) > 0 {
  1865. r.T_pdf4 = T_pdf4
  1866. clos = append(clos, "T_pdf4")
  1867. r.T_marking_state = 1
  1868. clos = append(clos, "T_marking_state")
  1869. }
  1870. if len(T_pdf5) > 0 {
  1871. r.T_pdf5 = T_pdf5
  1872. clos = append(clos, "T_pdf5")
  1873. r.T_examining_report_state = 1
  1874. clos = append(clos, "T_examining_report_state")
  1875. // 添加已提交状态 检测报告记录
  1876. auditRecordJson, err := Task.Add_AuditRecord(r.T_examining_report_audit_record, "", User_r.T_uuid, r.T_examining_report_state, "", "")
  1877. if err == nil {
  1878. r.T_examining_report_audit_record = auditRecordJson
  1879. clos = append(clos, "T_examining_report_audit_record")
  1880. r.T_examining_report_end_time = time.Now().Format("2006-01-02 15:04:05")
  1881. clos = append(clos, "T_examining_report_end_time")
  1882. if len(r.T_examining_report_start_time) > 0 {
  1883. r.T_examining_report_time_interval, _ = lib.MinutesDifference(r.T_examining_report_start_time, r.T_examining_report_end_time)
  1884. clos = append(clos, "T_examining_report_time_interval")
  1885. // 扣除暂停时间
  1886. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 3)
  1887. if Task_Compute > 0 {
  1888. r.T_examining_report_time_interval -= float64(Task_Compute)
  1889. }
  1890. clos = append(clos, "T_examining_report_time_interval")
  1891. }
  1892. }
  1893. // 通知 报告人员
  1894. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1895. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】检测报告 已提交", company_r.T_name, r.T_name), "")
  1896. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】检测报告 已提交", company_r.T_name, r.T_name))
  1897. }
  1898. if len(T_pdf6) > 0 {
  1899. r.T_pdf6 = T_pdf6
  1900. clos = append(clos, "T_pdf6")
  1901. r.T_examining_report_state = 1
  1902. clos = append(clos, "T_original_record_state")
  1903. // 添加已提交状态 原始记录 记录
  1904. auditRecordJson, err := Task.Add_AuditRecord(r.T_original_record_audit_record, "", User_r.T_uuid, r.T_original_record_state, "", "")
  1905. if err == nil {
  1906. r.T_original_record_audit_record = auditRecordJson
  1907. clos = append(clos, "T_original_record_audit_record")
  1908. r.T_original_record_end_time = time.Now().Format("2006-01-02 15:04:05")
  1909. clos = append(clos, "T_original_record_end_time")
  1910. if len(r.T_reporting_start_time) > 0 {
  1911. r.T_original_record_time_interval, _ = lib.MinutesDifference(r.T_original_record_start_time, r.T_original_record_end_time)
  1912. clos = append(clos, "T_original_record_time_interval")
  1913. // 扣除暂停时间
  1914. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 2)
  1915. if Task_Compute > 0 {
  1916. r.T_original_record_time_interval -= float64(Task_Compute)
  1917. }
  1918. clos = append(clos, "T_original_record_time_interval")
  1919. }
  1920. }
  1921. // 通知 报告人员
  1922. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1923. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】原始记录 已提交", company_r.T_name, r.T_name), "")
  1924. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】原始记录 已提交", company_r.T_name, r.T_name))
  1925. }
  1926. if len(T_VerifyDeviceDataStartTime) > 0 {
  1927. r.T_VerifyDeviceDataStartTime = T_VerifyDeviceDataStartTime
  1928. clos = append(clos, "T_VerifyDeviceDataStartTime")
  1929. }
  1930. if len(T_VerifyDeviceDataEndTime) > 0 {
  1931. r.T_VerifyDeviceDataEndTime = T_VerifyDeviceDataEndTime
  1932. clos = append(clos, "T_VerifyDeviceDataEndTime")
  1933. }
  1934. if len(T_BindDeviceDataStartTime) > 0 {
  1935. r.T_BindDeviceDataStartTime = T_BindDeviceDataStartTime
  1936. clos = append(clos, "T_BindDeviceDataStartTime")
  1937. }
  1938. if len(T_BindDeviceDataEndTime) > 0 {
  1939. r.T_BindDeviceDataEndTime = T_BindDeviceDataEndTime
  1940. clos = append(clos, "T_BindDeviceDataEndTime")
  1941. }
  1942. if len(T_sn) > 0 {
  1943. T_sn = strings.TrimSpace(T_sn)
  1944. r.T_sn = T_sn
  1945. clos = append(clos, "T_sn")
  1946. }
  1947. if len(T_CalibrationExpirationTime) > 0 {
  1948. r.T_CalibrationExpirationTime = T_CalibrationExpirationTime
  1949. clos = append(clos, "T_CalibrationExpirationTime")
  1950. }
  1951. // 从3.0获取校准时间
  1952. if len(T_sn) > 0 && len(T_CalibrationExpirationTime) == 0 {
  1953. go func(r Task.Task, T_sn, T_CalibrationExpirationTime string) {
  1954. NatsServer.Cold_UpdateDevice_CalibrationTime(T_sn, T_CalibrationExpirationTime)
  1955. device, err := NatsServer.Cold_ReadDeviceByT_sn(T_sn)
  1956. if err == nil {
  1957. if !device.T_CalibrationTime.IsZero() {
  1958. r.T_CalibrationExpirationTime = device.T_CalibrationTime.Format("2006-01-02")
  1959. clos = append(clos, "T_CalibrationExpirationTime")
  1960. Task.Update_Task(r, "T_CalibrationExpirationTime")
  1961. }
  1962. }
  1963. }(r, T_sn, T_CalibrationExpirationTime)
  1964. }
  1965. if len(T_project) > 0 {
  1966. r.T_project = T_project
  1967. clos = append(clos, "T_project")
  1968. }
  1969. if len(T_province) > 0 {
  1970. r.T_province = T_province
  1971. clos = append(clos, "T_province")
  1972. }
  1973. if len(T_city) > 0 {
  1974. r.T_city = T_city
  1975. clos = append(clos, "T_city")
  1976. }
  1977. if len(T_district) > 0 {
  1978. r.T_district = T_district
  1979. clos = append(clos, "T_district")
  1980. }
  1981. if len(T_province_code) > 0 {
  1982. r.T_province_code = T_province_code
  1983. clos = append(clos, "T_province_code")
  1984. }
  1985. if len(T_city_code) > 0 {
  1986. r.T_city_code = T_city_code
  1987. clos = append(clos, "T_city_code")
  1988. }
  1989. if len(T_district_code) > 0 {
  1990. r.T_district_code = T_district_code
  1991. clos = append(clos, "T_district_code")
  1992. }
  1993. if len(T_category) > 0 {
  1994. r.T_category = T_category
  1995. clos = append(clos, "T_category")
  1996. }
  1997. if len(T_device_type) > 0 {
  1998. r.T_device_type = T_device_type
  1999. clos = append(clos, "T_device_type")
  2000. }
  2001. if len(T_volume) > 0 {
  2002. r.T_volume = T_volume
  2003. clos = append(clos, "T_volume")
  2004. }
  2005. if len(T_verify_type) > 0 {
  2006. r.T_verify_type = T_verify_type
  2007. clos = append(clos, "T_verify_type")
  2008. }
  2009. if len(T_subject_matter) > 0 {
  2010. r.T_subject_matter = T_subject_matter
  2011. clos = append(clos, "T_subject_matter")
  2012. }
  2013. if len(T_temp_range) > 0 {
  2014. r.T_temp_range = T_temp_range
  2015. clos = append(clos, "T_temp_range")
  2016. }
  2017. if len(T_report_number) > 0 {
  2018. r.T_report_number = T_report_number
  2019. clos = append(clos, "T_report_number")
  2020. }
  2021. if len(T_report_type) > 0 {
  2022. r.T_report_type = T_report_type
  2023. clos = append(clos, "T_report_type")
  2024. }
  2025. if T_device_quantity > 0 {
  2026. r.T_device_quantity = T_device_quantity
  2027. clos = append(clos, "T_device_quantity")
  2028. }
  2029. r.T_cnas = T_cnas
  2030. clos = append(clos, "T_cnas")
  2031. if !Task.Update_Task(r, clos...) {
  2032. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2033. c.ServeJSON()
  2034. return
  2035. }
  2036. // 添加任务操作日志
  2037. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改", r)
  2038. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改", r)
  2039. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2040. c.ServeJSON()
  2041. return
  2042. }
  2043. // 修改-
  2044. func (c *TaskController) UpInfoCollection() {
  2045. // 验证登录 User_is, User_r
  2046. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2047. if !User_is {
  2048. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2049. c.ServeJSON()
  2050. return
  2051. }
  2052. T_task_id := c.GetString("T_task_id")
  2053. r, is := Task.Read_Task(T_task_id)
  2054. if !is {
  2055. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2056. c.ServeJSON()
  2057. return
  2058. }
  2059. T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
  2060. // 查询信息采集信息
  2061. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  2062. if !is {
  2063. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  2064. c.ServeJSON()
  2065. return
  2066. }
  2067. r.T_InfoCollection_id = T_InfoCollection_id
  2068. r.T_InfoTemplate_id = infoCollection.T_InfoTemplate_id
  2069. r.T_start_time = infoCollection.T_start_time // 项目开始时间使用信息采集开始时间
  2070. if !Task.Update_Task(r, "T_InfoCollection_id", "T_InfoTemplate_id", "T_start_time") {
  2071. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2072. c.ServeJSON()
  2073. return
  2074. }
  2075. // 添加任务操作日志
  2076. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改信息采集id", r)
  2077. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改信息采集id", r)
  2078. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2079. c.ServeJSON()
  2080. return
  2081. }
  2082. // 修改任务的公司
  2083. func (c *TaskController) UpdateTaskCompany() {
  2084. // 验证登录 User_is, User_r
  2085. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2086. if !User_is {
  2087. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2088. c.ServeJSON()
  2089. return
  2090. }
  2091. T_task_id := c.GetString("T_task_id")
  2092. new_T_uuid := c.GetString("T_uuid") // 新公司UUID
  2093. if len(T_task_id) == 0 {
  2094. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 不能为空!"}
  2095. c.ServeJSON()
  2096. return
  2097. }
  2098. if len(new_T_uuid) == 0 {
  2099. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid 不能为空!"}
  2100. c.ServeJSON()
  2101. return
  2102. }
  2103. // 查询任务
  2104. task, is := Task.Read_Task(T_task_id)
  2105. if !is {
  2106. c.Data["json"] = lib.JSONS{Code: 202, Msg: "任务不存在!"}
  2107. c.ServeJSON()
  2108. return
  2109. }
  2110. // 查询原公司信息
  2111. oldUser, is := Account.Read_User(task.T_uuid)
  2112. if !is {
  2113. c.Data["json"] = lib.JSONS{Code: 202, Msg: "原公司信息不存在!"}
  2114. c.ServeJSON()
  2115. return
  2116. }
  2117. // 查询新公司信息
  2118. newUser, is := Account.Read_User(new_T_uuid)
  2119. if !is {
  2120. c.Data["json"] = lib.JSONS{Code: 202, Msg: "新公司信息不存在!"}
  2121. c.ServeJSON()
  2122. return
  2123. }
  2124. // 查询信息采集
  2125. var infoCollection InfoCollection.InfoCollection
  2126. if len(task.T_InfoCollection_id) > 0 {
  2127. infoCollection, is = InfoCollection.Read_InfoCollection(task.T_InfoCollection_id)
  2128. if !is {
  2129. c.Data["json"] = lib.JSONS{Code: 202, Msg: "信息采集不存在!"}
  2130. c.ServeJSON()
  2131. return
  2132. }
  2133. } else {
  2134. c.Data["json"] = lib.JSONS{Code: 202, Msg: "任务没有关联信息采集!"}
  2135. c.ServeJSON()
  2136. return
  2137. }
  2138. var newInfoCollection InfoCollection.InfoCollection
  2139. var newInfoCollectionId string
  2140. // 判断信息采集名称是否和原公司名称相同
  2141. if infoCollection.T_name == oldUser.T_name {
  2142. // 如果信息采集名称和原公司名称相同,查询新公司下与新公司同名的信息采集
  2143. newInfoCollection, is = InfoCollection.Read_InfoCollection_By_T_uuid_Name(new_T_uuid, newUser.T_name)
  2144. if !is {
  2145. // 如果不存在,创建新公司下的信息采集(使用新公司名称)
  2146. var err error
  2147. newInfoCollection, err = InfoCollection.GetOrCreate_InfoCollection(new_T_uuid, newUser.T_name)
  2148. if err != nil {
  2149. c.Data["json"] = lib.JSONS{Code: 202, Msg: "创建信息采集失败: " + err.Error()}
  2150. c.ServeJSON()
  2151. return
  2152. }
  2153. }
  2154. newInfoCollectionId = newInfoCollection.T_InfoCollection_id
  2155. } else {
  2156. // 如果信息采集名称和原公司名称不相同,查询新公司下有没有同名的信息采集
  2157. newInfoCollection, is = InfoCollection.Read_InfoCollection_By_T_uuid_Name(new_T_uuid, infoCollection.T_name)
  2158. if !is {
  2159. // 如果不存在,创建新公司下的信息采集(使用原信息采集名称)
  2160. var err error
  2161. newInfoCollection, err = InfoCollection.GetOrCreate_InfoCollection(new_T_uuid, infoCollection.T_name)
  2162. if err != nil {
  2163. c.Data["json"] = lib.JSONS{Code: 202, Msg: "创建信息采集失败: " + err.Error()}
  2164. c.ServeJSON()
  2165. return
  2166. }
  2167. }
  2168. newInfoCollectionId = newInfoCollection.T_InfoCollection_id
  2169. }
  2170. // 更新任务的公司和信息采集
  2171. task.T_uuid = new_T_uuid
  2172. task.T_InfoCollection_id = newInfoCollectionId
  2173. if newInfoCollection.T_InfoTemplate_id != "" {
  2174. task.T_InfoTemplate_id = newInfoCollection.T_InfoTemplate_id
  2175. }
  2176. // 更新新公司的分销商ID
  2177. if newUser.T_Distributor_id != "" {
  2178. task.T_Distributor_id = newUser.T_Distributor_id
  2179. }
  2180. // 更新任务
  2181. updateCols := []string{"T_uuid", "T_InfoCollection_id", "T_InfoTemplate_id"}
  2182. if newUser.T_Distributor_id != "" {
  2183. updateCols = append(updateCols, "T_Distributor_id")
  2184. }
  2185. if !Task.Update_Task(task, updateCols...) {
  2186. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改任务失败!"}
  2187. c.ServeJSON()
  2188. return
  2189. }
  2190. // 添加任务操作日志
  2191. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改任务公司", task)
  2192. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改任务公司", task)
  2193. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2194. c.ServeJSON()
  2195. return
  2196. }
  2197. // 保存电子签名pdf
  2198. func (c *TaskController) SaveElectronicSignaturePDF() {
  2199. // 验证登录 User_is, User_r
  2200. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2201. if !User_is {
  2202. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2203. c.ServeJSON()
  2204. return
  2205. }
  2206. T_pdf1 := c.GetString("T_pdf1") // 方案
  2207. T_pdf2 := c.GetString("T_pdf2") // 证书
  2208. T_task_id := c.GetString("T_task_id")
  2209. r, is := Task.Read_Task(T_task_id)
  2210. if !is {
  2211. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2212. c.ServeJSON()
  2213. return
  2214. }
  2215. // .......
  2216. clos := make([]string, 0)
  2217. // 验证报告内容T_pdf1,上传后将 当前任务 验证方案 标志 为 5 (0未完成 1已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交)
  2218. // 上传后设置方案结束时间,计算所需时间和超时时间
  2219. if len(T_pdf1) > 0 {
  2220. r.T_pdf1_elec_signature = T_pdf1
  2221. clos = append(clos, "T_pdf1")
  2222. go GetWatermarkPdf(r, T_pdf1, false, "T_pdf1")
  2223. }
  2224. // 验证报告内容T_pdf2 ,上传后将 当前任务 报告编写 标志 为 1
  2225. // 上传后设置报告结束时间,计算所需时间和超时时间
  2226. if len(T_pdf2) > 0 {
  2227. r.T_pdf1_elec_signature = T_pdf2
  2228. clos = append(clos, "T_pdf2")
  2229. go GetWatermarkPdf(r, T_pdf2, false, "T_pdf2")
  2230. }
  2231. if !Task.Update_Task(r, clos...) {
  2232. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2233. c.ServeJSON()
  2234. return
  2235. }
  2236. // 添加任务操作日志
  2237. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "保存电子签名方案/报告", r)
  2238. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "保存电子签名方案/报告", r)
  2239. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2240. c.ServeJSON()
  2241. return
  2242. }
  2243. // 修改验证方案状态
  2244. func (c *TaskController) UpSchemeState() {
  2245. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2246. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2247. if !Admin_is && !User_is {
  2248. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2249. c.ServeJSON()
  2250. return
  2251. }
  2252. operate_uuid := ""
  2253. if Admin_is {
  2254. operate_uuid = Admin_r.T_uuid
  2255. }
  2256. if User_is {
  2257. operate_uuid = User_r.T_uuid
  2258. }
  2259. T_scheme_state, _ := c.GetInt("T_scheme_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  2260. T_reason := c.GetString("T_reason") // 退回原因
  2261. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  2262. T_task_id := c.GetString("T_task_id")
  2263. r, is := Task.Read_Task(T_task_id)
  2264. if !is {
  2265. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2266. c.ServeJSON()
  2267. return
  2268. }
  2269. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  2270. clos := make([]string, 0)
  2271. if T_scheme_state > 0 {
  2272. r.T_scheme_state = T_scheme_state
  2273. clos = append(clos, "T_scheme_state")
  2274. }
  2275. if len(T_signature) > 0 {
  2276. r.T_scheme_signature = T_signature
  2277. clos = append(clos, "T_scheme_signature")
  2278. }
  2279. if T_scheme_state == Task.TaskSchemeStateClientReturn || T_scheme_state == Task.TaskSchemeStateReturn {
  2280. r.T_scheme_return_times += 1
  2281. clos = append(clos, "T_scheme_return_times")
  2282. // 客户退回时新增驳回次数和驳回记录
  2283. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  2284. r.T_reject_times += 1
  2285. var rejectRecordList []Task.AuditRecord
  2286. if len(r.T_reject_record) > 0 {
  2287. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  2288. if err != nil {
  2289. logs.Error("JSON 反序列化失败:", err)
  2290. return
  2291. }
  2292. }
  2293. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  2294. T_uuid: User_r.T_uuid,
  2295. T_state: T_scheme_state,
  2296. T_reason: T_reason,
  2297. T_time: time.Now().Format("2006-01-02 15:04:05"),
  2298. T_type: "scheme",
  2299. })
  2300. rejectRecordJson, err := json.Marshal(rejectRecordList)
  2301. if err != nil {
  2302. logs.Error("JSON 反序列化失败:", err)
  2303. return
  2304. }
  2305. r.T_reject_record = string(rejectRecordJson)
  2306. clos = append(clos, "T_reject_times")
  2307. clos = append(clos, "T_reject_record")
  2308. }
  2309. }
  2310. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_scheme_state, T_reason, "")
  2311. if err != nil {
  2312. return
  2313. }
  2314. r.T_scheme_audit_record = auditRecordJson
  2315. clos = append(clos, "T_scheme_audit_record")
  2316. if !Task.Update_Task(r, clos...) {
  2317. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2318. c.ServeJSON()
  2319. return
  2320. }
  2321. //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  2322. // 已提交
  2323. if T_scheme_state == Task.TaskSchemeStateSubmitted {
  2324. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  2325. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
  2326. }
  2327. // 已通过
  2328. if T_scheme_state == Task.TaskSchemeStatePass {
  2329. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  2330. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  2331. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
  2332. }
  2333. // 已退回(负责人)
  2334. if T_scheme_state == Task.TaskSchemeStateReturn {
  2335. 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), "")
  2336. 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))
  2337. }
  2338. // 已退回(客户)
  2339. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  2340. 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), "")
  2341. 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))
  2342. 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), "")
  2343. 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))
  2344. 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))
  2345. }
  2346. // 添加任务操作日志
  2347. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证方案状态", r)
  2348. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证方案状态", r)
  2349. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2350. c.ServeJSON()
  2351. return
  2352. }
  2353. // 修改验证报告状态
  2354. func (c *TaskController) UpReportingState() {
  2355. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2356. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2357. if !Admin_is && !User_is {
  2358. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2359. c.ServeJSON()
  2360. return
  2361. }
  2362. operate_uuid := ""
  2363. if Admin_is {
  2364. operate_uuid = Admin_r.T_uuid
  2365. }
  2366. if User_is {
  2367. operate_uuid = User_r.T_uuid
  2368. }
  2369. T_reporting_state, _ := c.GetInt("T_reporting_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  2370. T_reason := c.GetString("T_reason") // 退回原因
  2371. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  2372. T_task_id := c.GetString("T_task_id")
  2373. r, is := Task.Read_Task(T_task_id)
  2374. if !is {
  2375. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2376. c.ServeJSON()
  2377. return
  2378. }
  2379. //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  2380. clos := make([]string, 0)
  2381. if T_reporting_state > 0 {
  2382. r.T_reporting_state = T_reporting_state
  2383. clos = append(clos, "T_reporting_state")
  2384. }
  2385. if T_reporting_state == Task.TaskReportingStatePass {
  2386. r.T_reporting_pass_time = time.Now().Format("2006-01-02 15:04:05")
  2387. clos = append(clos, "T_reporting_pass_time")
  2388. }
  2389. if len(T_signature) > 0 {
  2390. r.T_reporting_signature = T_signature
  2391. clos = append(clos, "T_reporting_signature")
  2392. }
  2393. if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
  2394. r.T_reporting_return_times += 1
  2395. clos = append(clos, "T_reporting_return_times")
  2396. // 客户退回时新增驳回次数和驳回记录
  2397. if T_reporting_state == Task.TaskReportingStateClientReturn {
  2398. r.T_reject_times += 1
  2399. var rejectRecordList []Task.AuditRecord
  2400. if len(r.T_reject_record) > 0 {
  2401. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  2402. if err != nil {
  2403. logs.Error("JSON 反序列化失败:", err)
  2404. return
  2405. }
  2406. }
  2407. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  2408. T_uuid: User_r.T_uuid,
  2409. T_state: T_reporting_state,
  2410. T_reason: T_reason,
  2411. T_time: time.Now().Format("2006-01-02 15:04:05"),
  2412. T_type: "reporting",
  2413. })
  2414. rejectRecordJson, err := json.Marshal(rejectRecordList)
  2415. if err != nil {
  2416. logs.Error("JSON 反序列化失败:", err)
  2417. return
  2418. }
  2419. r.T_reject_record = string(rejectRecordJson)
  2420. clos = append(clos, "T_reject_times")
  2421. clos = append(clos, "T_reject_record")
  2422. }
  2423. }
  2424. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
  2425. if err != nil {
  2426. return
  2427. }
  2428. r.T_reporting_audit_record = auditRecordJson
  2429. clos = append(clos, "T_reporting_audit_record")
  2430. // 查询信息采集信息
  2431. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  2432. if !is {
  2433. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  2434. c.ServeJSON()
  2435. return
  2436. }
  2437. // 验证报告客户审核通过后设置结束时间
  2438. if T_reporting_state == Task.TaskReportingStateClientPass {
  2439. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  2440. r.T_time_interval, err = lib.MinutesDifference(infoCollection.T_start_time, r.T_end_time)
  2441. if err != nil {
  2442. logs.Error("UpReportingState:", err.Error())
  2443. }
  2444. clos = append(clos, "T_end_time")
  2445. clos = append(clos, "T_time_interval")
  2446. }
  2447. if !Task.Update_Task(r, clos...) {
  2448. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2449. c.ServeJSON()
  2450. return
  2451. }
  2452. // 已通过
  2453. if T_reporting_state == Task.TaskReportingStatePass {
  2454. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  2455. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  2456. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  2457. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  2458. }
  2459. // 已退回
  2460. if T_reporting_state == Task.TaskReportingStateReturn {
  2461. 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), "")
  2462. 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))
  2463. }
  2464. // 已通过(客户) 通知销售
  2465. if T_reporting_state == Task.TaskReportingStateClientPass {
  2466. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】 %s,请尽快安排客户回款", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  2467. }
  2468. if T_reporting_state == Task.TaskReportingStateClientReturn {
  2469. 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), "")
  2470. 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))
  2471. 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), "")
  2472. 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))
  2473. 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), "")
  2474. 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))
  2475. //System.Add_News(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  2476. //go wx.WxSend(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
  2477. System.Add_News(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason), "")
  2478. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason))
  2479. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason))
  2480. }
  2481. // 添加任务操作日志
  2482. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证报告状态", r)
  2483. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证报告状态", r)
  2484. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2485. c.ServeJSON()
  2486. return
  2487. }
  2488. // 修改检测报告状态
  2489. func (c *TaskController) UpExaminingReportState() {
  2490. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2491. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2492. if !Admin_is && !User_is {
  2493. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2494. c.ServeJSON()
  2495. return
  2496. }
  2497. operate_uuid := ""
  2498. if Admin_is {
  2499. operate_uuid = Admin_r.T_uuid
  2500. }
  2501. if User_is {
  2502. operate_uuid = User_r.T_uuid
  2503. }
  2504. T_examining_report_state, _ := c.GetInt("T_examining_report_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  2505. T_reason := c.GetString("T_reason") // 退回原因
  2506. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  2507. T_task_id := c.GetString("T_task_id")
  2508. r, is := Task.Read_Task(T_task_id)
  2509. if !is {
  2510. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2511. c.ServeJSON()
  2512. return
  2513. }
  2514. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  2515. clos := make([]string, 0)
  2516. if T_examining_report_state > 0 {
  2517. r.T_examining_report_state = T_examining_report_state
  2518. clos = append(clos, "T_examining_report_state")
  2519. }
  2520. if len(T_signature) > 0 {
  2521. r.T_examining_report_signature = T_signature
  2522. clos = append(clos, "T_examining_report_signature")
  2523. }
  2524. if T_examining_report_state == Task.TaskExaminingReportStateClientReturn || T_examining_report_state == Task.TaskExaminingReportStateReturn {
  2525. r.T_examining_report_return_times += 1
  2526. clos = append(clos, "T_examining_report_return_times")
  2527. // 客户退回时新增驳回次数和驳回记录
  2528. if T_examining_report_state == Task.TaskExaminingReportStateClientReturn {
  2529. r.T_reject_times += 1
  2530. var rejectRecordList []Task.AuditRecord
  2531. if len(r.T_reject_record) > 0 {
  2532. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  2533. if err != nil {
  2534. logs.Error("JSON 反序列化失败:", err)
  2535. return
  2536. }
  2537. }
  2538. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  2539. T_uuid: User_r.T_uuid,
  2540. T_state: T_examining_report_state,
  2541. T_reason: T_reason,
  2542. T_time: time.Now().Format("2006-01-02 15:04:05"),
  2543. T_type: "examining_report",
  2544. })
  2545. rejectRecordJson, err := json.Marshal(rejectRecordList)
  2546. if err != nil {
  2547. logs.Error("JSON 反序列化失败:", err)
  2548. return
  2549. }
  2550. r.T_reject_record = string(rejectRecordJson)
  2551. clos = append(clos, "T_reject_times")
  2552. clos = append(clos, "T_reject_record")
  2553. }
  2554. }
  2555. 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, "")
  2556. if err != nil {
  2557. return
  2558. }
  2559. r.T_examining_report_audit_record = auditRecordJson
  2560. clos = append(clos, "T_examining_report_audit_record")
  2561. if !Task.Update_Task(r, clos...) {
  2562. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2563. c.ServeJSON()
  2564. return
  2565. }
  2566. // 已提交
  2567. if T_examining_report_state == Task.TaskExaminingReportStateSubmitted {
  2568. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】检测报告 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state]), "")
  2569. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】检测报告 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskExaminingReportStateMap[T_examining_report_state]))
  2570. }
  2571. // 已通过
  2572. if T_examining_report_state == Task.TaskExaminingReportStatePass {
  2573. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  2574. 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]), "")
  2575. 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]))
  2576. }
  2577. // 已退回(负责人)
  2578. if T_examining_report_state == Task.TaskExaminingReportStateReturn {
  2579. 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), "")
  2580. 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))
  2581. }
  2582. // 已退回(客户)
  2583. if T_examining_report_state == Task.TaskExaminingReportStateClientReturn {
  2584. 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), "")
  2585. 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))
  2586. 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), "")
  2587. 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))
  2588. 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))
  2589. }
  2590. // 添加任务操作日志
  2591. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改检测报告状态", r)
  2592. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改检测报告状态", r)
  2593. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2594. c.ServeJSON()
  2595. return
  2596. }
  2597. // 修改原始数据状态
  2598. func (c *TaskController) UpOriginalRecordState() {
  2599. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2600. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2601. if !Admin_is && !User_is {
  2602. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2603. c.ServeJSON()
  2604. return
  2605. }
  2606. operate_uuid := ""
  2607. if Admin_is {
  2608. operate_uuid = Admin_r.T_uuid
  2609. }
  2610. if User_is {
  2611. operate_uuid = User_r.T_uuid
  2612. }
  2613. T_original_record_state, _ := c.GetInt("T_original_record_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  2614. T_reason := c.GetString("T_reason") // 退回原因
  2615. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  2616. T_task_id := c.GetString("T_task_id")
  2617. r, is := Task.Read_Task(T_task_id)
  2618. if !is {
  2619. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2620. c.ServeJSON()
  2621. return
  2622. }
  2623. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  2624. clos := make([]string, 0)
  2625. if T_original_record_state > 0 {
  2626. r.T_original_record_state = T_original_record_state
  2627. clos = append(clos, "T_original_record_state")
  2628. }
  2629. if len(T_signature) > 0 {
  2630. r.T_original_record_signature = T_signature
  2631. clos = append(clos, "T_original_record_signature")
  2632. }
  2633. if T_original_record_state == Task.TaskOriginalRecordStateReturn {
  2634. r.T_original_record_return_times += 1
  2635. clos = append(clos, "T_original_record_return_times")
  2636. }
  2637. 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, "")
  2638. if err != nil {
  2639. return
  2640. }
  2641. r.T_original_record_audit_record = auditRecordJson
  2642. clos = append(clos, "T_original_record_audit_record")
  2643. if !Task.Update_Task(r, clos...) {
  2644. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2645. c.ServeJSON()
  2646. return
  2647. }
  2648. // 已提交
  2649. if T_original_record_state == Task.TaskOriginalRecordStateSubmitted {
  2650. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】原始数据 %s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state]), "")
  2651. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】原始数据 %s", company_r.T_name, r.T_name, Task.TaskOriginalRecordStateMap[T_original_record_state]))
  2652. }
  2653. // 已通过
  2654. if T_original_record_state == Task.TaskOriginalRecordStatePass {
  2655. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  2656. 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]), "")
  2657. 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]))
  2658. }
  2659. // 已退回(负责人)
  2660. if T_original_record_state == Task.TaskOriginalRecordStateReturn {
  2661. 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), "")
  2662. 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))
  2663. }
  2664. // 添加任务操作日志
  2665. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改原始数据状态", r)
  2666. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改原始数据状态", r)
  2667. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2668. c.ServeJSON()
  2669. return
  2670. }
  2671. // 进场 改成 方案开始
  2672. func (c *TaskController) EnterArea() {
  2673. // 验证登录 User_is, User_r
  2674. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2675. if !User_is {
  2676. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2677. c.ServeJSON()
  2678. return
  2679. }
  2680. T_task_id := c.GetString("T_task_id")
  2681. r, is := Task.Read_Task(T_task_id)
  2682. if !is {
  2683. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2684. c.ServeJSON()
  2685. return
  2686. }
  2687. // 方案开始
  2688. if len(r.T_scheme_start_time) == 0 {
  2689. r.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
  2690. Task.Update_Task(r, "T_scheme_start_time")
  2691. }
  2692. // 添加任务操作日志
  2693. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "方案开始", r)
  2694. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "方案开始", r)
  2695. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2696. c.ServeJSON()
  2697. return
  2698. }
  2699. // 开始验证
  2700. func (c *TaskController) StartVerify() {
  2701. // 验证登录 User_is, User_r
  2702. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2703. if !User_is {
  2704. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2705. c.ServeJSON()
  2706. return
  2707. }
  2708. T_task_id := c.GetString("T_task_id")
  2709. T_time := c.GetString("T_time") // 进场时间
  2710. r, is := Task.Read_Task(T_task_id)
  2711. if !is {
  2712. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2713. c.ServeJSON()
  2714. return
  2715. }
  2716. if len(r.T_collection_start_time) == 0 {
  2717. r.T_collection_start_time = T_time
  2718. if !Task.Update_Task(r, "T_collection_start_time") {
  2719. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
  2720. c.ServeJSON()
  2721. return
  2722. }
  2723. // 添加任务操作日志
  2724. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
  2725. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
  2726. }
  2727. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2728. c.ServeJSON()
  2729. return
  2730. }
  2731. // 删除-
  2732. func (c *TaskController) Del() {
  2733. // 验证登录 User_is, User_r
  2734. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2735. if !User_is {
  2736. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2737. c.ServeJSON()
  2738. return
  2739. }
  2740. T_task_id := c.GetString("T_task_id")
  2741. if r, is := Task.Read_Task(T_task_id); is {
  2742. if !Task.Delete_Task(r) {
  2743. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  2744. c.ServeJSON()
  2745. return
  2746. }
  2747. // 添加任务操作日志
  2748. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
  2749. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
  2750. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2751. c.ServeJSON()
  2752. return
  2753. }
  2754. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2755. c.ServeJSON()
  2756. return
  2757. }
  2758. // 列表 -
  2759. func (c *TaskController) Logs_List() {
  2760. // 验证登录 User_is, User_r
  2761. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2762. if !User_is {
  2763. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2764. c.ServeJSON()
  2765. return
  2766. }
  2767. var r_jsons lib.R_JSONS
  2768. page, _ := c.GetInt("page")
  2769. if page < 1 {
  2770. page = 1
  2771. }
  2772. page_z, _ := c.GetInt("page_z")
  2773. if page_z < 1 {
  2774. page_z = conf.Page_size
  2775. }
  2776. T_task_id := c.GetString("T_task_id")
  2777. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  2778. var cnt int
  2779. List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
  2780. page_size := math.Ceil(float64(cnt) / float64(page_z))
  2781. r_jsons.List = List
  2782. r_jsons.Page = page
  2783. r_jsons.Page_size = int(page_size)
  2784. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  2785. r_jsons.Num = cnt
  2786. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2787. c.ServeJSON()
  2788. return
  2789. }
  2790. // 查询图片生成状态
  2791. func (c *TaskController) DeviceData_JPGState() {
  2792. T_task_id := c.GetString("T_task_id")
  2793. T_remark := c.GetString("T_remark")
  2794. jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
  2795. if !is {
  2796. c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
  2797. c.ServeJSON()
  2798. return
  2799. }
  2800. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
  2801. c.ServeJSON()
  2802. return
  2803. }
  2804. // 生成温度图片
  2805. func (c *TaskController) DeviceData_JPG() {
  2806. StartTime := c.GetString("StartTime")
  2807. if len(StartTime) > 0 {
  2808. _, ok := lib.TimeStrToTime(StartTime)
  2809. if !ok {
  2810. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  2811. c.ServeJSON()
  2812. return
  2813. }
  2814. }
  2815. EndTime := c.GetString("EndTime")
  2816. if len(EndTime) > 0 {
  2817. _, ok := lib.TimeStrToTime(EndTime)
  2818. if !ok {
  2819. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  2820. c.ServeJSON()
  2821. return
  2822. }
  2823. } else {
  2824. EndTime = time.Now().Format("2006-01-02 15:04:05")
  2825. }
  2826. T_remark := c.GetString("T_remark")
  2827. TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
  2828. TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
  2829. if TemperatureMin == 0 {
  2830. TemperatureMin = 2
  2831. }
  2832. if TemperatureMax == 0 {
  2833. TemperatureMax = 8
  2834. }
  2835. T_task_id := c.GetString("T_task_id")
  2836. Task_r, is := Task.Read_Task(T_task_id)
  2837. if !is {
  2838. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  2839. c.ServeJSON()
  2840. return
  2841. }
  2842. if Task_r.T_collection_state == 2 {
  2843. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  2844. c.ServeJSON()
  2845. return
  2846. }
  2847. deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  2848. if !is {
  2849. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  2850. c.ServeJSON()
  2851. return
  2852. }
  2853. Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
  2854. // 生成图片
  2855. go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
  2856. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2857. c.ServeJSON()
  2858. return
  2859. }
  2860. // SyncInfoCollection 同步信息采集表
  2861. func (c *TaskController) SyncInfoCollection() {
  2862. T_task_id := c.GetString("T_task_id")
  2863. T_source, _ := c.GetInt("T_source")
  2864. task, is := Task.Read_Task(T_task_id)
  2865. if !is {
  2866. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2867. c.ServeJSON()
  2868. return
  2869. }
  2870. // 获取信息采集表模版信息
  2871. InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
  2872. InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
  2873. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  2874. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  2875. InfoCollectionDataMap := make(map[string]string)
  2876. for _, data := range InfoCollection_Data {
  2877. InfoCollectionDataMap[data.T_name] = data.T_value
  2878. }
  2879. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  2880. for _, v := range Data {
  2881. if len(v.T_value) > 0 {
  2882. continue
  2883. }
  2884. if InfoCollectionDataMap[v.T_name] == "" {
  2885. continue
  2886. }
  2887. val := VerifyTemplate.VerifyTemplateMapData{
  2888. T_source: T_source,
  2889. T_task_id: task.T_task_id,
  2890. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  2891. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  2892. T_flow_sort: v.T_flow_sort,
  2893. T_max_time: v.T_max_time,
  2894. T_min_time: v.T_min_time,
  2895. T_value: InfoCollectionDataMap[v.T_name],
  2896. }
  2897. MapDataList = append(MapDataList, val)
  2898. }
  2899. var ids []int64
  2900. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  2901. if !is {
  2902. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  2903. c.ServeJSON()
  2904. return
  2905. }
  2906. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  2907. c.ServeJSON()
  2908. return
  2909. }
  2910. // 退回记录列表
  2911. func (c *TaskController) AuditRecordList() {
  2912. // 验证登录 User_is, User_r
  2913. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2914. if !User_is {
  2915. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2916. c.ServeJSON()
  2917. return
  2918. }
  2919. T_task_id := c.GetString("T_task_id")
  2920. T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
  2921. //T_task 驳回记录
  2922. //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  2923. //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  2924. //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  2925. T_state, _ := c.GetInt("T_state") // -1 获取全部
  2926. r, is := Task.Read_Task(T_task_id)
  2927. if !is {
  2928. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2929. c.ServeJSON()
  2930. return
  2931. }
  2932. var auditRecordList []Task.AuditRecord
  2933. switch T_type {
  2934. case "T_task":
  2935. T_state = -1
  2936. if len(r.T_reject_record) > 0 {
  2937. err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
  2938. if err != nil {
  2939. logs.Error("JSON 反序列化失败:", err)
  2940. return
  2941. }
  2942. }
  2943. case "T_scheme":
  2944. if len(r.T_scheme_audit_record) > 0 {
  2945. err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
  2946. if err != nil {
  2947. logs.Error("JSON 反序列化失败:", err)
  2948. return
  2949. }
  2950. }
  2951. case "T_collection":
  2952. if len(r.T_collection_audit_record) > 0 {
  2953. err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
  2954. if err != nil {
  2955. logs.Error("JSON 反序列化失败:", err)
  2956. return
  2957. }
  2958. }
  2959. case "T_reporting":
  2960. if len(r.T_reporting_audit_record) > 0 {
  2961. err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
  2962. if err != nil {
  2963. logs.Error("JSON 反序列化失败:", err)
  2964. return
  2965. }
  2966. }
  2967. case "T_examining_report":
  2968. if len(r.T_examining_report_audit_record) > 0 {
  2969. err := json.Unmarshal([]byte(r.T_examining_report_audit_record), &auditRecordList)
  2970. if err != nil {
  2971. logs.Error("JSON 反序列化失败:", err)
  2972. return
  2973. }
  2974. }
  2975. case "T_original_record":
  2976. if len(r.T_original_record_audit_record) > 0 {
  2977. err := json.Unmarshal([]byte(r.T_original_record_audit_record), &auditRecordList)
  2978. if err != nil {
  2979. logs.Error("JSON 反序列化失败:", err)
  2980. return
  2981. }
  2982. }
  2983. }
  2984. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  2985. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  2986. var auditRecordList2 []Task.AuditRecord
  2987. // 返回全部
  2988. if T_state == -1 {
  2989. for i := 0; i < len(auditRecordList); i++ {
  2990. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  2991. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  2992. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  2993. }
  2994. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  2995. c.ServeJSON()
  2996. return
  2997. }
  2998. if T_state == -2 {
  2999. for i := 0; i < len(auditRecordList); i++ {
  3000. if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
  3001. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  3002. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  3003. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  3004. }
  3005. }
  3006. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  3007. c.ServeJSON()
  3008. return
  3009. }
  3010. for i := 0; i < len(auditRecordList); i++ {
  3011. if auditRecordList[i].T_state == T_state {
  3012. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  3013. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  3014. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  3015. }
  3016. }
  3017. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  3018. c.ServeJSON()
  3019. return
  3020. }
  3021. // 存档生成图片
  3022. func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
  3023. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  3024. State: 1,
  3025. Msg: "图片生成中",
  3026. Url: "",
  3027. })
  3028. msg := ""
  3029. state := 2
  3030. url := ""
  3031. if TemperatureMin == 0 {
  3032. TemperatureMin = 2
  3033. }
  3034. if TemperatureMax == 0 {
  3035. TemperatureMax = 8
  3036. }
  3037. var ymin, ymax float64
  3038. var xminT, xmaxT time.Time
  3039. if len(deviceList) > 0 {
  3040. ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
  3041. }
  3042. // 创建一个新的绘图
  3043. p := plot.New()
  3044. // 设置绘图标题和标签
  3045. p.Title.Text = "温度折线图"
  3046. //p.Legend.ThumbnailWidth = 5 * vg.Inch
  3047. p.X.Label.Text = "时间"
  3048. p.Y.Label.Text = "温度"
  3049. var chData = make(chan int, 10)
  3050. var jobGroup sync.WaitGroup
  3051. var device = make([]Device.DeviceCount, len(deviceList))
  3052. // 创建温度线
  3053. for i := 0; i < len(deviceList); i++ {
  3054. chData <- 1
  3055. jobGroup.Add(1)
  3056. go func(index int) {
  3057. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  3058. defer func() {
  3059. <-chData // 完成时chan取出1个
  3060. jobGroup.Done() // 完成时将等待组值减1
  3061. }()
  3062. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  3063. ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
  3064. if ymin > ymin_ {
  3065. ymin = ymin_
  3066. }
  3067. if ymax < ymax_ {
  3068. ymax = ymax_
  3069. }
  3070. if xminT.After(minTime_) && !minTime_.IsZero() {
  3071. xminT = minTime_
  3072. }
  3073. if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
  3074. xmaxT = maxTime_
  3075. }
  3076. r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  3077. device[index] = Device.DeviceCount{
  3078. T_id: id,
  3079. T_sn: sn,
  3080. Num: r_maps_num,
  3081. }
  3082. if r_maps_num == 0 {
  3083. return
  3084. }
  3085. pts := make(plotter.XYs, len(r_maps))
  3086. for j, d := range r_maps {
  3087. t, _ := lib.TimeStrToTime(d.T_time)
  3088. pts[j].X = float64(t.Unix())
  3089. pts[j].Y = float64(d.T_t)
  3090. }
  3091. line, err := plotter.NewLine(pts)
  3092. if err != nil {
  3093. return
  3094. }
  3095. line.Color = randomColor(index)
  3096. p.Add(line)
  3097. }(i)
  3098. }
  3099. jobGroup.Wait()
  3100. xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
  3101. // 添加最高,最低标准线 用红色虚线标识
  3102. p.Add(horizontalLine(xmin, xmax, TemperatureMin))
  3103. p.Add(horizontalLine(xmin, xmax, TemperatureMax))
  3104. if ymax < 8 {
  3105. ymax = 8
  3106. }
  3107. if ymin > 0 {
  3108. ymin = 0
  3109. }
  3110. p.Y.Min, p.Y.Max = ymin, ymax
  3111. p.X.Min, p.X.Max = xmin, xmax
  3112. p.Y.Tick.Marker = commaTicks{}
  3113. //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
  3114. p.X.Tick.Marker = timeTicks{}
  3115. p.X.Tick.Label.Rotation = math.Pi / 5
  3116. p.X.Tick.Label.YAlign = draw.YCenter
  3117. p.X.Tick.Label.XAlign = draw.XRight
  3118. filename := "jpg" + time.Now().Format("20060102150405")
  3119. // 保存文件
  3120. if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
  3121. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  3122. State: 3,
  3123. Msg: "图片生成失败",
  3124. Url: url,
  3125. })
  3126. logs.Error(lib.FuncName(), "生成图片失败", err)
  3127. return
  3128. }
  3129. if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
  3130. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  3131. State: 3,
  3132. Msg: "图片上传七牛云失败",
  3133. Url: url,
  3134. })
  3135. logs.Error(lib.FuncName(), "上传七牛云失败")
  3136. return
  3137. }
  3138. //删除目录
  3139. os.Remove("ofile/" + filename + ".jpg")
  3140. msg = "图片生成成功"
  3141. url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
  3142. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  3143. State: state,
  3144. Msg: msg,
  3145. Url: url,
  3146. Device: device,
  3147. })
  3148. return
  3149. }
  3150. func horizontalLine(xmin, xmax, y float64) *plotter.Line {
  3151. pts := make(plotter.XYs, 2)
  3152. pts[0].X = xmin
  3153. pts[0].Y = y
  3154. pts[1].X = xmax
  3155. pts[1].Y = y
  3156. line, err := plotter.NewLine(pts)
  3157. if err != nil {
  3158. panic(any(err))
  3159. }
  3160. line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
  3161. line.Color = color.RGBA{R: 255, A: 255}
  3162. return line
  3163. }
  3164. type timeTicks struct{}
  3165. func (timeTicks) Ticks(min, max float64) []plot.Tick {
  3166. tks := plot.TimeTicks{}.Ticks(min, max)
  3167. for i, t := range tks {
  3168. //if t.Label == "" { // Skip minor ticks, they are fine.
  3169. // continue
  3170. //}
  3171. tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
  3172. }
  3173. return tks
  3174. }
  3175. type commaTicks struct{}
  3176. // Ticks computes the default tick marks, but inserts commas
  3177. // into the labels for the major tick marks.
  3178. func (commaTicks) Ticks(min, max float64) []plot.Tick {
  3179. tks := plot.DefaultTicks{}.Ticks(min, max)
  3180. for i, t := range tks {
  3181. //if t.Label == "" { // Skip minor ticks, they are fine.
  3182. // continue
  3183. //}
  3184. tks[i].Label = fmt.Sprintf("%.0f", t.Value)
  3185. }
  3186. return tks
  3187. }
  3188. // 生成随机颜色的辅助函数
  3189. func randomColor(i int) color.RGBA {
  3190. var colors []color.RGBA
  3191. colors = append(colors,
  3192. color.RGBA{R: 52, G: 152, B: 219, A: 255},
  3193. color.RGBA{R: 230, G: 126, B: 34, A: 255},
  3194. color.RGBA{R: 142, G: 68, B: 173, A: 255},
  3195. color.RGBA{R: 211, G: 84, B: 0, A: 255},
  3196. color.RGBA{R: 231, G: 76, B: 60, A: 255},
  3197. color.RGBA{R: 26, G: 188, B: 156, A: 255},
  3198. color.RGBA{R: 243, G: 156, B: 18, A: 255},
  3199. color.RGBA{R: 22, G: 160, B: 133, A: 255},
  3200. color.RGBA{R: 46, G: 204, B: 113, A: 255},
  3201. color.RGBA{R: 39, G: 174, B: 96, A: 255},
  3202. color.RGBA{R: 41, G: 128, B: 185, A: 255},
  3203. color.RGBA{R: 155, G: 89, B: 182, A: 255},
  3204. color.RGBA{R: 192, G: 57, B: 43, A: 255},
  3205. color.RGBA{R: 241, G: 196, B: 15, A: 255},
  3206. )
  3207. return colors[i%len(colors)]
  3208. }
  3209. // 获取加完水印的pdf
  3210. func GetWatermarkPdf_command(task Task.Task, pdfURL string, flag string) (pdf string) {
  3211. if len(pdfURL) == 0 {
  3212. return
  3213. }
  3214. currentDirectory := lib.GetCurrentDirectory()
  3215. scriptPath := currentDirectory + "/script"
  3216. pdf_file_out_name := uuid.New().String() + ".pdf"
  3217. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  3218. pdf_file_out := currentDirectory + "/ofile/watermark" + pdf_file_out_name
  3219. watermark_pdf := currentDirectory + "/script/watermark.pdf"
  3220. // 执行Python脚本
  3221. cmd := exec.Command("python3", "add_watermark.py", pdfURL, pdfFilename, pdf_file_out, watermark_pdf)
  3222. cmd.Dir = scriptPath
  3223. // 获取命令输出
  3224. _, err := cmd.CombinedOutput()
  3225. if err != nil {
  3226. logs.Error("执行python脚本添加水印错误:", err)
  3227. return
  3228. }
  3229. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  3230. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  3231. err = errors.New("上传水印pdf失败")
  3232. return
  3233. }
  3234. defer func() {
  3235. os.Remove(pdfFilename)
  3236. os.Remove(pdf_file_out)
  3237. }()
  3238. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  3239. switch flag {
  3240. case "T_pdf1":
  3241. task.T_pdf1_watermark = pdf
  3242. Task.Update_Task(task, "T_pdf1_watermark")
  3243. case "T_pdf2":
  3244. task.T_pdf2_watermark = pdf
  3245. Task.Update_Task(task, "T_pdf2_watermark")
  3246. }
  3247. return
  3248. }
  3249. func GetSignaturePdf_command(task Task.Task, pdfURL string, flag string) (pdf string) {
  3250. if len(pdfURL) == 0 {
  3251. return
  3252. }
  3253. currentDirectory := lib.GetCurrentDirectory()
  3254. scriptPath := currentDirectory + "/script"
  3255. pdf_file_out_name := uuid.New().String() + ".pdf"
  3256. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  3257. pdf_file_out := currentDirectory + "/ofile/signature" + pdf_file_out_name
  3258. signature_img := currentDirectory + "/script/报告专用章.png"
  3259. // 执行Python脚本
  3260. cmd := exec.Command("python3", "add_signature.py", pdfURL, pdfFilename, signature_img, pdf_file_out)
  3261. cmd.Dir = scriptPath
  3262. // 获取命令输出
  3263. _, err := cmd.CombinedOutput()
  3264. if err != nil {
  3265. logs.Error("执行python脚本添加公章错误:", err)
  3266. return
  3267. }
  3268. _, err = os.Stat(pdf_file_out)
  3269. if os.IsNotExist(err) {
  3270. return ""
  3271. }
  3272. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  3273. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  3274. err = errors.New("上传水印pdf失败")
  3275. return
  3276. }
  3277. defer func() {
  3278. os.Remove(pdfFilename)
  3279. os.Remove(pdf_file_out)
  3280. }()
  3281. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  3282. switch flag {
  3283. case "T_pdf1":
  3284. task.T_pdf1_signature = pdf
  3285. Task.Update_Task(task, "T_pdf1_signature")
  3286. case "T_pdf2":
  3287. task.T_pdf2_signature = pdf
  3288. Task.Update_Task(task, "T_pdf2_signature")
  3289. }
  3290. return
  3291. }
  3292. func GetWatermarkPdf(task Task.Task, pdfURL string, stamp bool, flag string) (pdf string) {
  3293. if len(pdfURL) == 0 {
  3294. return
  3295. }
  3296. // 添加公章 T_pdf5为CNAS实验室 ,不添加公章
  3297. var signaturePdf, watermarkPdf string
  3298. var err error
  3299. if flag != "T_pdf5" {
  3300. if stamp {
  3301. signaturePdf, err = lib.GetSignaturePdf(pdfURL)
  3302. if err != nil {
  3303. logs.Error("获取加报告章pdf失败:", err)
  3304. return
  3305. }
  3306. } else {
  3307. signaturePdf = pdfURL
  3308. }
  3309. }
  3310. // 添加水印
  3311. watermarkPdf, err = lib.GetWatermarkPdf(pdfURL)
  3312. if err != nil {
  3313. logs.Error("获取加水印pdf失败:", err)
  3314. return
  3315. }
  3316. switch flag {
  3317. case "T_pdf1":
  3318. task.T_pdf1_watermark = watermarkPdf
  3319. task.T_pdf1_signature = signaturePdf
  3320. Task.Update_Task(task, "T_pdf1_watermark", "T_pdf1_signature")
  3321. case "T_pdf2":
  3322. task.T_pdf2_watermark = watermarkPdf
  3323. task.T_pdf2_signature = signaturePdf
  3324. Task.Update_Task(task, "T_pdf2_watermark", "T_pdf2_signature")
  3325. case "T_pdf5":
  3326. task.T_pdf5_watermark = watermarkPdf
  3327. Task.Update_Task(task, "T_pdf5_watermark")
  3328. }
  3329. return
  3330. }
  3331. // 暂停申请
  3332. // 列表 -
  3333. func (c *TaskController) TaskTimeList() {
  3334. // 验证登录 User_is, User_r
  3335. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3336. if !User_is {
  3337. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3338. c.ServeJSON()
  3339. return
  3340. }
  3341. var r_jsons lib.R_JSONS
  3342. T_task_id := c.GetString("T_task_id")
  3343. T_task_type, _ := c.GetInt("T_task_type", 0)
  3344. var cnt int64
  3345. List, cnt := Task.Read_TaskTime_List(T_task_id, T_task_type)
  3346. r_jsons.List = List
  3347. r_jsons.Num = int(cnt)
  3348. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  3349. c.ServeJSON()
  3350. return
  3351. }
  3352. // 添加-
  3353. func (c *TaskController) TaskTimeAdd() {
  3354. // 验证登录 User_is, User_r
  3355. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3356. if !User_is {
  3357. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3358. c.ServeJSON()
  3359. return
  3360. }
  3361. dc := Device.DeviceClass{
  3362. T_uuid: User_r.T_uuid,
  3363. T_State: 1,
  3364. }
  3365. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", dc)
  3366. T_task_id := c.GetString("T_task_id")
  3367. T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
  3368. T_aaa := c.GetString("T_aaa")
  3369. var_ := Task.TaskTime{
  3370. T_task_id: T_task_id,
  3371. T_task_type: T_task_type,
  3372. T_uuid: User_r.T_uuid,
  3373. T_remarks: T_aaa,
  3374. T_start_time: time.Now().Format("2006-01-02 15:04:05"),
  3375. }
  3376. List, _ := Task.Read_TaskTime_List(T_task_id, T_task_type)
  3377. if len(List) > 0 {
  3378. if len(List[len(List)-1].T_end_time) == 0 {
  3379. c.Data["json"] = lib.JSONS{Code: 202, Msg: "上一个任务还没结束!"}
  3380. c.ServeJSON()
  3381. return
  3382. }
  3383. }
  3384. is := Task.Add_TaskTime(var_)
  3385. if !is {
  3386. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  3387. c.ServeJSON()
  3388. return
  3389. }
  3390. // 添加任务操作日志
  3391. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务暂停", "暂停申请", var_)
  3392. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", var_)
  3393. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  3394. c.ServeJSON()
  3395. return
  3396. }
  3397. // 添加-
  3398. func (c *TaskController) TaskTimeEnd() {
  3399. // 验证登录 User_is, User_r
  3400. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3401. if !User_is {
  3402. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3403. c.ServeJSON()
  3404. return
  3405. }
  3406. dc := Device.DeviceClass{
  3407. T_uuid: User_r.T_uuid,
  3408. T_State: 1,
  3409. }
  3410. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", dc)
  3411. Id, _ := c.GetInt("Id", 0)
  3412. TaskTime_r, is := Task.Read_TaskTime_ById(Id)
  3413. if !is {
  3414. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  3415. c.ServeJSON()
  3416. return
  3417. }
  3418. TaskTime_r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  3419. is = Task.Update_TaskTime(TaskTime_r, "T_end_time")
  3420. if !is {
  3421. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  3422. c.ServeJSON()
  3423. return
  3424. }
  3425. // 添加任务操作日志
  3426. Task.Add_TaskLogs_T(User_r.T_uuid, TaskTime_r.T_task_id, "任务暂停", "暂停结束", TaskTime_r)
  3427. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", TaskTime_r)
  3428. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: TaskTime_r.T_task_id}
  3429. c.ServeJSON()
  3430. return
  3431. }
  3432. // 列表 - 统计排名
  3433. func (c *TaskController) StatisticalRanking() {
  3434. // 验证登录 User_is, User_r
  3435. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3436. if !User_is {
  3437. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3438. c.ServeJSON()
  3439. return
  3440. }
  3441. T_power, _ := c.GetInt("T_power", 0) // 5 数据采集工程师 6 验证报告工程师
  3442. type Admin_T struct {
  3443. T_name string
  3444. T_scheme int // 实施方案
  3445. T_scheme_returnnum int // 退回
  3446. T_scheme_overnum int // 超时
  3447. T_scheme_log string // 日志
  3448. T_collection int // 数据采集
  3449. T_collection_returnnum int // 退回
  3450. T_collection_overnum int // 超时
  3451. T_collection_log string // 日志
  3452. T_reporting int // 报告编写
  3453. T_reporting_returnnum int // 退回
  3454. T_reporting_overnum int // 超时
  3455. T_reporting_log string // 日志
  3456. T_rejectdnum int // 驳回数量
  3457. }
  3458. var Admin_T_List []Admin_T
  3459. Admin_List := Account.Read_Admin_List_ALL_T_power(T_power)
  3460. for _, A := range Admin_List {
  3461. Admin_t := Admin_T{T_name: A.T_name}
  3462. // 方案
  3463. Task_List := Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_scheme") //T_scheme T_collection T_reporting
  3464. for _, T := range Task_List {
  3465. if len(T.T_scheme_end_time) > 0 {
  3466. if is, _ := lib.IsInCurrentMonth(T.T_scheme_end_time); !is {
  3467. continue // 不是本月
  3468. }
  3469. Admin_t.T_scheme += 1
  3470. Admin_t.T_scheme_log += T.T_name
  3471. // 退回
  3472. if T.T_scheme_return_times > 0 {
  3473. Admin_t.T_scheme_returnnum += T.T_scheme_return_times
  3474. Admin_t.T_scheme_log += " | 退回" + lib.To_string(int(T.T_scheme_return_times))
  3475. }
  3476. // 超时
  3477. if T.T_scheme_overtime > 0 {
  3478. Admin_t.T_scheme_overnum += 1
  3479. Admin_t.T_scheme_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_scheme_overtime))
  3480. }
  3481. // 驳回
  3482. if T.T_reject_times > 0 {
  3483. Admin_t.T_rejectdnum += T.T_reject_times
  3484. Admin_t.T_scheme_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  3485. }
  3486. Admin_t.T_scheme_log += "\n"
  3487. }
  3488. }
  3489. // 实施
  3490. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_collection") //T_scheme T_collection T_reporting
  3491. for _, T := range Task_List {
  3492. if len(T.T_collection_end_time) > 0 {
  3493. if is, _ := lib.IsInCurrentMonth(T.T_collection_end_time); !is {
  3494. continue // 不是本月
  3495. }
  3496. Admin_t.T_collection += 1
  3497. Admin_t.T_collection_log += T.T_name
  3498. // 退回
  3499. if T.T_collection_return_times > 0 {
  3500. Admin_t.T_collection_returnnum += T.T_collection_return_times
  3501. Admin_t.T_collection_log += " | 退回" + lib.To_string(int(T.T_collection_return_times))
  3502. }
  3503. // 超时
  3504. if T.T_collection_overtime > 0 {
  3505. Admin_t.T_collection_overnum += 1
  3506. Admin_t.T_collection_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_collection_overtime))
  3507. }
  3508. // 驳回
  3509. if T.T_reject_times > 0 {
  3510. Admin_t.T_rejectdnum += T.T_reject_times
  3511. Admin_t.T_collection_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  3512. }
  3513. Admin_t.T_collection_log += "\n"
  3514. }
  3515. }
  3516. // 报告
  3517. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_reporting") //T_scheme T_collection T_reporting
  3518. for _, T := range Task_List {
  3519. if len(T.T_reporting_end_time) > 0 {
  3520. if is, _ := lib.IsInCurrentMonth(T.T_reporting_end_time); !is {
  3521. continue // 不是本月
  3522. }
  3523. Admin_t.T_reporting += 1
  3524. Admin_t.T_reporting_log += T.T_name
  3525. // 退回
  3526. if T.T_reporting_return_times > 0 {
  3527. Admin_t.T_reporting_returnnum += T.T_reporting_return_times
  3528. Admin_t.T_reporting_log += " | 退回" + lib.To_string(int(T.T_reporting_return_times))
  3529. }
  3530. // 超时
  3531. if T.T_reporting_overtime > 0 {
  3532. Admin_t.T_reporting_overnum += 1
  3533. Admin_t.T_reporting_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_reporting_overtime))
  3534. }
  3535. // 驳回
  3536. if T.T_reject_times > 0 {
  3537. Admin_t.T_rejectdnum += T.T_reject_times
  3538. Admin_t.T_reporting_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  3539. }
  3540. Admin_t.T_reporting_log += "\n"
  3541. }
  3542. }
  3543. Admin_T_List = append(Admin_T_List, Admin_t)
  3544. }
  3545. var r_jsons lib.R_JSONS
  3546. r_jsons.List = Admin_T_List
  3547. r_jsons.Page = 0
  3548. r_jsons.Page_size = 0
  3549. r_jsons.Pages = lib.Func_page(int64(0), int64(0))
  3550. r_jsons.Num = 0
  3551. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  3552. c.ServeJSON()
  3553. return
  3554. }
  3555. // 复制-
  3556. func (c *TaskController) Copy() {
  3557. // 验证登录 User_is, User_r
  3558. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3559. if !User_is {
  3560. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3561. c.ServeJSON()
  3562. return
  3563. }
  3564. T_name := c.GetString("T_name")
  3565. T_task_id := c.GetString("T_task_id")
  3566. new_T_uuid := c.GetString("T_uuid") // 新增T_uuid参数
  3567. r, is := Task.Read_Task(T_task_id)
  3568. if !is {
  3569. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  3570. c.ServeJSON()
  3571. return
  3572. }
  3573. // 确定使用的T_uuid
  3574. target_T_uuid := r.T_uuid
  3575. if len(new_T_uuid) > 0 && new_T_uuid != r.T_uuid {
  3576. target_T_uuid = new_T_uuid
  3577. }
  3578. dc := Device.DeviceClass{
  3579. T_uuid: target_T_uuid,
  3580. T_State: 1,
  3581. }
  3582. T_class_id, is := Device.Add_DeviceClass(dc)
  3583. if !is {
  3584. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  3585. c.ServeJSON()
  3586. return
  3587. }
  3588. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
  3589. // 查询信息采集信息
  3590. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  3591. if !is {
  3592. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  3593. c.ServeJSON()
  3594. return
  3595. }
  3596. // 如果T_uuid不同,需要处理信息采集
  3597. target_InfoCollection_id := r.T_InfoCollection_id
  3598. if len(new_T_uuid) > 0 && new_T_uuid != r.T_uuid {
  3599. // 查询新的T_uuid是否有同名的信息采集
  3600. newInfoCollection, found := InfoCollection.Read_InfoCollection_By_T_uuid_Name(new_T_uuid, infoCollection.T_name)
  3601. if found {
  3602. // 如果有则使用该信息采集
  3603. target_InfoCollection_id = newInfoCollection.T_InfoCollection_id
  3604. infoCollection = newInfoCollection
  3605. } else {
  3606. // 如果没有则添加
  3607. // 获取原公司和新公司的名称
  3608. _, oldCompany := Account.Read_User_ByT_uuid(r.T_uuid)
  3609. _, newCompany := Account.Read_User_ByT_uuid(new_T_uuid)
  3610. infoCollectionName := infoCollection.T_name
  3611. // 如果信息采集名称与原公司名称相同,则添加的时候需要将名称更改为新的T_uuid的公司的名称
  3612. if infoCollection.T_name == oldCompany.T_name {
  3613. infoCollectionName = newCompany.T_name
  3614. }
  3615. // 创建新的信息采集
  3616. newInfoCollection := InfoCollection.InfoCollection{
  3617. T_uuid: new_T_uuid,
  3618. T_name: infoCollectionName,
  3619. T_InfoTemplate_class: infoCollection.T_InfoTemplate_class,
  3620. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  3621. T_status: 1,
  3622. T_State: 1,
  3623. T_start_time: infoCollection.T_start_time,
  3624. T_end_time: infoCollection.T_end_time,
  3625. T_time_interval: infoCollection.T_time_interval,
  3626. }
  3627. newInfoCollectionId, err := InfoCollection.Add_InfoCollection(newInfoCollection)
  3628. if err != nil {
  3629. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加信息采集失败: " + err.Error()}
  3630. c.ServeJSON()
  3631. return
  3632. }
  3633. target_InfoCollection_id = newInfoCollectionId
  3634. // 重新读取新创建的信息采集以获取完整信息
  3635. infoCollection, is = InfoCollection.Read_InfoCollection(target_InfoCollection_id)
  3636. if !is {
  3637. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取新创建的信息采集失败!"}
  3638. c.ServeJSON()
  3639. return
  3640. }
  3641. }
  3642. }
  3643. var_ := Task.Task{
  3644. T_Distributor_id: r.T_Distributor_id,
  3645. T_InfoCollection_id: target_InfoCollection_id,
  3646. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  3647. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  3648. T_class: int(T_class_id),
  3649. T_uuid: target_T_uuid,
  3650. T_name: T_name,
  3651. T_VerifyTemplate_class: r.T_VerifyTemplate_class,
  3652. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  3653. T_deadline: time.Now().AddDate(0, 2, 0).Format("2006-01-02"),
  3654. T_scheme: r.T_scheme,
  3655. T_collection: r.T_collection,
  3656. T_reporting: r.T_reporting,
  3657. T_delivery: r.T_delivery,
  3658. T_Show: 1,
  3659. T_State: 1,
  3660. T_project: r.T_project,
  3661. T_province: r.T_province,
  3662. T_city: r.T_city,
  3663. T_district: r.T_district,
  3664. T_province_code: r.T_province_code,
  3665. T_city_code: r.T_city_code,
  3666. T_district_code: r.T_district_code,
  3667. T_category: r.T_category,
  3668. T_device_type: r.T_device_type,
  3669. T_volume: r.T_volume,
  3670. T_verify_type: r.T_verify_type,
  3671. T_subject_matter: T_name,
  3672. T_temp_range: r.T_temp_range,
  3673. T_report_type: r.T_report_type,
  3674. T_device_quantity: r.T_device_quantity,
  3675. T_cnas: r.T_cnas,
  3676. }
  3677. var_.T_report_number, _ = Task.GenerateNextT_report_number(var_.T_device_type)
  3678. T_paste_task_id, is := Task.Add_Task(var_)
  3679. if !is {
  3680. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  3681. c.ServeJSON()
  3682. return
  3683. }
  3684. // 复制 DeviceClassList
  3685. err := CopyDeviceClassList(r, var_)
  3686. if err != nil {
  3687. logs.Error("复制设备列表失败", err)
  3688. }
  3689. // 自动填写备注
  3690. err = AutoFillDeviceClassRemark(T_paste_task_id)
  3691. if err != nil {
  3692. logs.Error("自动填写设备备注失败", err)
  3693. }
  3694. // 自动填写布点
  3695. err = AutoFillDeploy(T_paste_task_id, 0)
  3696. if err != nil {
  3697. logs.Error("自动填写布点失败", err)
  3698. }
  3699. NatsServer.Create_Local_Table(T_paste_task_id)
  3700. Task.Redis_Task_T_report_number_DelK(var_.T_report_number) // 删除redis内的任务编号
  3701. // 复制验证模版数据
  3702. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(r.T_VerifyTemplate_id, 0, 0)
  3703. copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_task_id, r.T_VerifyTemplate_id, Map_List)
  3704. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_paste_task_id, r.T_VerifyTemplate_id, Map_List)
  3705. copyDataMap := make(map[string]string)
  3706. for _, data := range copy_task_Data {
  3707. copyDataMap[data.T_name] = data.T_value
  3708. }
  3709. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  3710. for _, v := range Data {
  3711. // 已有值则不复制
  3712. if len(v.T_value) > 0 {
  3713. continue
  3714. }
  3715. if copyDataMap[v.T_name] == "" {
  3716. continue
  3717. }
  3718. val := VerifyTemplate.VerifyTemplateMapData{
  3719. T_source: v.T_source,
  3720. T_task_id: T_paste_task_id,
  3721. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  3722. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  3723. T_Required: v.T_Required,
  3724. T_Construction: v.T_Construction,
  3725. T_flow_sort: v.T_flow_sort,
  3726. T_max_time: v.T_max_time,
  3727. T_min_time: v.T_min_time,
  3728. T_value: copyDataMap[v.T_name],
  3729. }
  3730. MapDataList = append(MapDataList, val)
  3731. }
  3732. _, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "复制", 0, 0, 1)
  3733. if !is {
  3734. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  3735. c.ServeJSON()
  3736. return
  3737. }
  3738. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制标签数据", MapDataList)
  3739. // 通知
  3740. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  3741. go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  3742. go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  3743. go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  3744. go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  3745. // 添加任务操作日志
  3746. Task.Add_TaskLogs_T(User_r.T_uuid, T_paste_task_id, "任务管理", "复制", var_)
  3747. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制", var_)
  3748. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_paste_task_id}
  3749. c.ServeJSON()
  3750. return
  3751. }
  3752. // 生成报告编号 设备类型+年+季度+递增编号
  3753. func (c *TaskController) GenT_report_number() {
  3754. // 验证登录 User_is, User_r
  3755. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3756. if !User_is {
  3757. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3758. c.ServeJSON()
  3759. return
  3760. }
  3761. T_device_type := c.GetString("T_device_type")
  3762. number, err := Task.GenerateNextT_report_number(T_device_type)
  3763. if err != nil {
  3764. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  3765. c.ServeJSON()
  3766. return
  3767. }
  3768. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: number}
  3769. c.ServeJSON()
  3770. return
  3771. }
  3772. // 自动填写布点
  3773. func (c *TaskController) Auto_fill_deploy() {
  3774. // 验证登录 User_is, User_r
  3775. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  3776. if !User_is {
  3777. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  3778. c.ServeJSON()
  3779. return
  3780. }
  3781. T_task_id := c.GetString("T_task_id")
  3782. T_source, _ := c.GetInt("T_source")
  3783. task, is := Task.Read_Task(T_task_id)
  3784. if !is {
  3785. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  3786. c.ServeJSON()
  3787. return
  3788. }
  3789. verifyTemplate, is := VerifyTemplate.Read_VerifyTemplate(task.T_VerifyTemplate_id)
  3790. verifyTemplate_R := VerifyTemplate.VerifyTemplateToVerifyTemplate_R(verifyTemplate)
  3791. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  3792. MapData := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  3793. T_deploy_list := verifyTemplate_R.T_deploy_list
  3794. //if len(T_deploy_list) == 0 {
  3795. // // 解析设备列表备注的布点
  3796. // deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, "")
  3797. // for _, v := range deviceClassList {
  3798. // splitList := lib.SplitStringSeparator(v.T_remark, "|")
  3799. // for _, T_name := range splitList {
  3800. // T_deploy_list = append(T_deploy_list, VerifyTemplate.VerifyTemplateDeploy{T_name: T_name})
  3801. // }
  3802. // }
  3803. //}
  3804. // 循环查询布点
  3805. deployMap := make(map[string]string)
  3806. for _, deploy := range T_deploy_list {
  3807. deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, deploy.T_name)
  3808. var snList []string
  3809. for _, v := range deviceClassList {
  3810. snList = append(snList, v.T_sn)
  3811. }
  3812. deployMap[deploy.T_name] = strings.Join(snList, "|")
  3813. }
  3814. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  3815. for _, v := range MapData {
  3816. if snList, ok := deployMap[v.T_name]; ok {
  3817. val := VerifyTemplate.VerifyTemplateMapData{
  3818. T_source: v.T_source,
  3819. T_task_id: task.T_task_id,
  3820. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  3821. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  3822. T_Required: v.T_Required,
  3823. T_Construction: v.T_Construction,
  3824. T_flow_sort: v.T_flow_sort,
  3825. T_max_time: v.T_max_time,
  3826. T_min_time: v.T_min_time,
  3827. T_value: snList,
  3828. T_start_time: v.T_start_time,
  3829. }
  3830. MapDataList = append(MapDataList, val)
  3831. }
  3832. }
  3833. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, T_source, User_r.T_uuid, 0, 0, 0)
  3834. if !is {
  3835. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  3836. c.ServeJSON()
  3837. return
  3838. }
  3839. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "自动填写", ids)
  3840. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  3841. c.ServeJSON()
  3842. return
  3843. }
  3844. // SyncVerifyTemplateMapData 根据标签名称同步模版数据
  3845. func (c *TaskController) SyncVerifyTemplateMapData() {
  3846. T_copy_task_id := c.GetString("T_copy_task_id")
  3847. T_paste_task_id := c.GetString("T_paste_task_id")
  3848. T_source, _ := c.GetInt("T_source")
  3849. copy_task, is := Task.Read_Task(T_copy_task_id)
  3850. if !is {
  3851. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  3852. c.ServeJSON()
  3853. return
  3854. }
  3855. paste_task, is := Task.Read_Task(T_paste_task_id)
  3856. if !is {
  3857. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  3858. c.ServeJSON()
  3859. return
  3860. }
  3861. copy_task_Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(copy_task.T_VerifyTemplate_id, 0, 0)
  3862. copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_copy_task_id, copy_task.T_VerifyTemplate_id, copy_task_Map_List)
  3863. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(paste_task.T_VerifyTemplate_id, 0, 0)
  3864. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_paste_task_id, paste_task.T_VerifyTemplate_id, Map_List)
  3865. copyDataMap := make(map[string]string)
  3866. for _, data := range copy_task_Data {
  3867. copyDataMap[data.T_name] = data.T_value
  3868. }
  3869. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  3870. for _, v := range Data {
  3871. if len(v.T_value) > 0 {
  3872. continue
  3873. }
  3874. if copyDataMap[v.T_name] == "" {
  3875. continue
  3876. }
  3877. val := VerifyTemplate.VerifyTemplateMapData{
  3878. T_source: v.T_source,
  3879. T_task_id: paste_task.T_task_id,
  3880. T_VerifyTemplate_id: paste_task.T_VerifyTemplate_id,
  3881. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  3882. T_Required: v.T_Required,
  3883. T_Construction: v.T_Construction,
  3884. T_flow_sort: v.T_flow_sort,
  3885. T_max_time: v.T_max_time,
  3886. T_min_time: v.T_min_time,
  3887. T_value: copyDataMap[v.T_name],
  3888. }
  3889. MapDataList = append(MapDataList, val)
  3890. }
  3891. var ids []int64
  3892. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "", 0, 0, 0)
  3893. if !is {
  3894. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  3895. c.ServeJSON()
  3896. return
  3897. }
  3898. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  3899. c.ServeJSON()
  3900. return
  3901. }
  3902. func (c *TaskController) TaskData_Stat() {
  3903. StartTime := c.GetString("StartTime")
  3904. if len(StartTime) > 0 {
  3905. _, ok := lib.TimeStrToTime(StartTime)
  3906. if !ok {
  3907. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  3908. c.ServeJSON()
  3909. return
  3910. }
  3911. }
  3912. EndTime := c.GetString("EndTime")
  3913. if len(EndTime) > 0 {
  3914. _, ok := lib.TimeStrToTime(EndTime)
  3915. if !ok {
  3916. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  3917. c.ServeJSON()
  3918. return
  3919. }
  3920. } else {
  3921. EndTime = time.Now().Format("2006-01-02 15:04:05")
  3922. }
  3923. T_remark := c.GetString("T_remark")
  3924. T_task_id := c.GetString("T_task_id")
  3925. Task_r, is := Task.Read_Task(T_task_id)
  3926. if !is {
  3927. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  3928. c.ServeJSON()
  3929. return
  3930. }
  3931. if Task_r.T_collection_state == 2 {
  3932. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  3933. c.ServeJSON()
  3934. return
  3935. }
  3936. deviceList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  3937. if !is {
  3938. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  3939. c.ServeJSON()
  3940. return
  3941. }
  3942. var chData = make(chan int, 10)
  3943. var jobGroup sync.WaitGroup
  3944. var device = make([]Device.DeviceCount, len(deviceList))
  3945. // 创建温度线
  3946. for i := 0; i < len(deviceList); i++ {
  3947. chData <- 1
  3948. jobGroup.Add(1)
  3949. go func(index int) {
  3950. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  3951. defer func() {
  3952. <-chData // 完成时chan取出1个
  3953. jobGroup.Done() // 完成时将等待组值减1
  3954. }()
  3955. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  3956. _, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  3957. device[index] = Device.DeviceCount{
  3958. T_id: id,
  3959. T_sn: sn,
  3960. Num: r_maps_num,
  3961. }
  3962. if r_maps_num == 0 {
  3963. return
  3964. }
  3965. }(i)
  3966. }
  3967. jobGroup.Wait()
  3968. c.Data["json"] = lib.JSONS{Data: device, Code: 200, Msg: "ok!"}
  3969. c.ServeJSON()
  3970. return
  3971. }
  3972. // SyncPDFWatermark 同步水印
  3973. func (c *TaskController) SyncPDFWatermark() {
  3974. List, _ := Task.Read_Task_List_For_Watermark("pdf1")
  3975. for _, task := range List {
  3976. GetWatermarkPdf_command(task, task.T_pdf1, "T_pdf1")
  3977. GetSignaturePdf_command(task, task.T_pdf1, "T_pdf1")
  3978. }
  3979. List2, _ := Task.Read_Task_List_For_Watermark("pdf2")
  3980. for _, task := range List2 {
  3981. GetWatermarkPdf_command(task, task.T_pdf2, "T_pdf2")
  3982. GetSignaturePdf_command(task, task.T_pdf2, "T_pdf2")
  3983. }
  3984. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  3985. c.ServeJSON()
  3986. return
  3987. }
  3988. // 复制设备列表
  3989. func CopyDeviceClassList(copy_task, paste_task Task.Task) error {
  3990. // 读取源任务的设备列表
  3991. copyList, _ := Device.Read_DeviceClassList_OrderList(copy_task.T_class, "", "", "", 0, 9999)
  3992. // 遍历源任务的设备列表,为每个设备创建新的 DeviceClassList 并添加到目标任务
  3993. for _, v := range copyList {
  3994. // 读取证书信息
  3995. var pdf Certificate.CertificatePdf
  3996. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(v.T_id, "")
  3997. if len(pdfList) > 0 {
  3998. pdf = pdfList[0]
  3999. }
  4000. var_ := Device.DeviceClassList{
  4001. T_class: paste_task.T_class,
  4002. T_id: v.T_id,
  4003. T_sn: v.T_sn,
  4004. T_failure_time: pdf.T_failure_time,
  4005. T_pdf: pdf.T_pdf,
  4006. T_Certificate_sn: pdf.T_Certificate_sn,
  4007. T_remark: v.T_remark,
  4008. T_terminal: v.T_terminal,
  4009. T_State: 1,
  4010. }
  4011. _, is := Device.Add_DeviceClassList(var_)
  4012. if !is {
  4013. return fmt.Errorf("添加设备列表失败: %s", v.T_id)
  4014. }
  4015. }
  4016. return nil
  4017. }
  4018. // 自动填写设备备注
  4019. func AutoFillDeviceClassRemark(T_task_id string) error {
  4020. task, is := Task.Read_Task(T_task_id)
  4021. if !is {
  4022. return fmt.Errorf("读取任务失败: %s", T_task_id)
  4023. }
  4024. verifyTemplate, is := VerifyTemplate.Read_VerifyTemplate(task.T_VerifyTemplate_id)
  4025. if !is {
  4026. return fmt.Errorf("读取验证模板失败: %s", task.T_VerifyTemplate_id)
  4027. }
  4028. verifyTemplate_R := VerifyTemplate.VerifyTemplateToVerifyTemplate_R(verifyTemplate)
  4029. T_deploy_list := verifyTemplate_R.T_deploy_list
  4030. // 循环查询布点
  4031. deviceClassRemarkMap := make(map[int][]string)
  4032. deviceClassList := Device.Read_DeviceClassList_List_id_By_Terminal(task.T_class, false)
  4033. for _, deploy := range T_deploy_list {
  4034. if len(deploy.T_scope) > 0 {
  4035. dcl := FilterByRange(deviceClassList, deploy.T_scope)
  4036. for _, dc := range dcl {
  4037. deviceClassRemarkMap[dc.Id] = append(deviceClassRemarkMap[dc.Id], deploy.T_name)
  4038. }
  4039. }
  4040. }
  4041. for _, deviceClass := range deviceClassList {
  4042. if remark, ok := deviceClassRemarkMap[deviceClass.Id]; ok {
  4043. deviceClass.T_remark = strings.Join(remark, "|")
  4044. if !Device.Update_DeviceClassList(deviceClass, "T_remark") {
  4045. return fmt.Errorf("修改备注失败: %d", deviceClass.Id)
  4046. }
  4047. }
  4048. }
  4049. return nil
  4050. }
  4051. // 自动填写布点
  4052. func AutoFillDeploy(T_task_id string, T_source int) error {
  4053. task, is := Task.Read_Task(T_task_id)
  4054. if !is {
  4055. return fmt.Errorf("读取任务失败: %s", T_task_id)
  4056. }
  4057. verifyTemplate, is := VerifyTemplate.Read_VerifyTemplate(task.T_VerifyTemplate_id)
  4058. if !is {
  4059. return fmt.Errorf("读取验证模板失败: %s", task.T_VerifyTemplate_id)
  4060. }
  4061. verifyTemplate_R := VerifyTemplate.VerifyTemplateToVerifyTemplate_R(verifyTemplate)
  4062. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  4063. MapData := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  4064. T_deploy_list := verifyTemplate_R.T_deploy_list
  4065. // 循环查询布点
  4066. deployMap := make(map[string]string)
  4067. for _, deploy := range T_deploy_list {
  4068. deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, deploy.T_name)
  4069. var snList []string
  4070. for _, v := range deviceClassList {
  4071. snList = append(snList, v.T_sn)
  4072. }
  4073. deployMap[deploy.T_name] = strings.Join(snList, "|")
  4074. }
  4075. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  4076. for _, v := range MapData {
  4077. if snList, ok := deployMap[v.T_name]; ok {
  4078. val := VerifyTemplate.VerifyTemplateMapData{
  4079. T_source: v.T_source,
  4080. T_task_id: task.T_task_id,
  4081. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  4082. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  4083. T_Required: v.T_Required,
  4084. T_Construction: v.T_Construction,
  4085. T_flow_sort: v.T_flow_sort,
  4086. T_max_time: v.T_max_time,
  4087. T_min_time: v.T_min_time,
  4088. T_value: snList,
  4089. T_start_time: v.T_start_time,
  4090. }
  4091. MapDataList = append(MapDataList, val)
  4092. }
  4093. }
  4094. if len(MapDataList) > 0 {
  4095. _, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, T_source, "", 0, 0, 0)
  4096. if !is {
  4097. return fmt.Errorf("保存布点数据失败")
  4098. }
  4099. }
  4100. return nil
  4101. }