Task.go 93 KB

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