Task.go 120 KB

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