Task.go 103 KB

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