Task.go 122 KB

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