Task.go 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610
  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 > 1 {
  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 len(T_signature) > 0 {
  1365. r.T_reporting_signature = T_signature
  1366. clos = append(clos, "T_reporting_signature")
  1367. }
  1368. if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
  1369. r.T_reporting_return_times += 1
  1370. clos = append(clos, "T_reporting_return_times")
  1371. // 客户退回时新增驳回次数和驳回记录
  1372. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1373. r.T_reject_times += 1
  1374. var rejectRecordList []Task.AuditRecord
  1375. if len(r.T_reject_record) > 0 {
  1376. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1377. if err != nil {
  1378. logs.Error("JSON 反序列化失败:", err)
  1379. return
  1380. }
  1381. }
  1382. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1383. T_uuid: User_r.T_uuid,
  1384. T_state: T_reporting_state,
  1385. T_reason: T_reason,
  1386. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1387. T_type: "reporting",
  1388. })
  1389. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1390. if err != nil {
  1391. logs.Error("JSON 反序列化失败:", err)
  1392. return
  1393. }
  1394. r.T_reject_record = string(rejectRecordJson)
  1395. clos = append(clos, "T_reject_times")
  1396. clos = append(clos, "T_reject_record")
  1397. }
  1398. }
  1399. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
  1400. if err != nil {
  1401. return
  1402. }
  1403. r.T_reporting_audit_record = auditRecordJson
  1404. clos = append(clos, "T_reporting_audit_record")
  1405. // 查询信息采集信息
  1406. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1407. if !is {
  1408. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  1409. c.ServeJSON()
  1410. return
  1411. }
  1412. // 验证报告客户审核通过后设置结束时间
  1413. if T_reporting_state == Task.TaskReportingStateClientPass {
  1414. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  1415. r.T_time_interval, err = lib.MinutesDifference(infoCollection.T_start_time, r.T_end_time)
  1416. if err != nil {
  1417. logs.Error("UpReportingState:", err.Error())
  1418. }
  1419. clos = append(clos, "T_end_time")
  1420. clos = append(clos, "T_time_interval")
  1421. }
  1422. if !Task.Update_Task(r, clos...) {
  1423. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1424. c.ServeJSON()
  1425. return
  1426. }
  1427. // 已通过
  1428. if T_reporting_state == Task.TaskReportingStatePass {
  1429. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1430. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1431. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1432. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1433. }
  1434. // 已退回
  1435. if T_reporting_state == Task.TaskReportingStateReturn {
  1436. 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), "")
  1437. 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))
  1438. }
  1439. // 已通过(客户) 通知销售
  1440. if T_reporting_state == Task.TaskReportingStateClientPass {
  1441. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】 %s,请尽快安排客户回款", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1442. }
  1443. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1444. 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), "")
  1445. 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))
  1446. 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), "")
  1447. 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))
  1448. 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), "")
  1449. 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))
  1450. //System.Add_News(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1451. //go wx.WxSend(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
  1452. System.Add_News(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason), "")
  1453. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason))
  1454. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state], T_reason))
  1455. }
  1456. // 添加任务操作日志
  1457. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证报告状态", r)
  1458. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证报告状态", r)
  1459. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1460. c.ServeJSON()
  1461. return
  1462. }
  1463. // 进场 改成 方案开始
  1464. func (c *TaskController) EnterArea() {
  1465. // 验证登录 User_is, User_r
  1466. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1467. if !User_is {
  1468. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1469. c.ServeJSON()
  1470. return
  1471. }
  1472. T_task_id := c.GetString("T_task_id")
  1473. r, is := Task.Read_Task(T_task_id)
  1474. if !is {
  1475. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1476. c.ServeJSON()
  1477. return
  1478. }
  1479. // 方案开始
  1480. if len(r.T_scheme_start_time) == 0 {
  1481. r.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
  1482. Task.Update_Task(r, "T_scheme_start_time")
  1483. }
  1484. // 添加任务操作日志
  1485. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "方案开始", r)
  1486. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "方案开始", r)
  1487. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1488. c.ServeJSON()
  1489. return
  1490. }
  1491. // 开始验证
  1492. func (c *TaskController) StartVerify() {
  1493. // 验证登录 User_is, User_r
  1494. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1495. if !User_is {
  1496. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1497. c.ServeJSON()
  1498. return
  1499. }
  1500. T_task_id := c.GetString("T_task_id")
  1501. T_time := c.GetString("T_time") // 进场时间
  1502. r, is := Task.Read_Task(T_task_id)
  1503. if !is {
  1504. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1505. c.ServeJSON()
  1506. return
  1507. }
  1508. if len(r.T_collection_start_time) == 0 {
  1509. r.T_collection_start_time = T_time
  1510. if !Task.Update_Task(r, "T_collection_start_time") {
  1511. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
  1512. c.ServeJSON()
  1513. return
  1514. }
  1515. // 添加任务操作日志
  1516. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
  1517. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
  1518. }
  1519. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1520. c.ServeJSON()
  1521. return
  1522. }
  1523. // 删除-
  1524. func (c *TaskController) Del() {
  1525. // 验证登录 User_is, User_r
  1526. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1527. if !User_is {
  1528. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1529. c.ServeJSON()
  1530. return
  1531. }
  1532. T_task_id := c.GetString("T_task_id")
  1533. if r, is := Task.Read_Task(T_task_id); is {
  1534. if !Task.Delete_Task(r) {
  1535. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  1536. c.ServeJSON()
  1537. return
  1538. }
  1539. // 添加任务操作日志
  1540. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
  1541. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
  1542. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1543. c.ServeJSON()
  1544. return
  1545. }
  1546. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1547. c.ServeJSON()
  1548. return
  1549. }
  1550. // 列表 -
  1551. func (c *TaskController) Logs_List() {
  1552. // 验证登录 User_is, User_r
  1553. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1554. if !User_is {
  1555. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1556. c.ServeJSON()
  1557. return
  1558. }
  1559. var r_jsons lib.R_JSONS
  1560. page, _ := c.GetInt("page")
  1561. if page < 1 {
  1562. page = 1
  1563. }
  1564. page_z, _ := c.GetInt("page_z")
  1565. if page_z < 1 {
  1566. page_z = conf.Page_size
  1567. }
  1568. T_task_id := c.GetString("T_task_id")
  1569. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1570. var cnt int
  1571. List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
  1572. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1573. r_jsons.List = List
  1574. r_jsons.Page = page
  1575. r_jsons.Page_size = int(page_size)
  1576. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1577. r_jsons.Num = cnt
  1578. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1579. c.ServeJSON()
  1580. return
  1581. }
  1582. // 查询图片生成状态
  1583. func (c *TaskController) DeviceData_JPGState() {
  1584. T_task_id := c.GetString("T_task_id")
  1585. T_remark := c.GetString("T_remark")
  1586. jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
  1587. if !is {
  1588. c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
  1589. c.ServeJSON()
  1590. return
  1591. }
  1592. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
  1593. c.ServeJSON()
  1594. return
  1595. }
  1596. // 生成温度图片
  1597. func (c *TaskController) DeviceData_JPG() {
  1598. StartTime := c.GetString("StartTime")
  1599. if len(StartTime) > 0 {
  1600. _, ok := lib.TimeStrToTime(StartTime)
  1601. if !ok {
  1602. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1603. c.ServeJSON()
  1604. return
  1605. }
  1606. }
  1607. EndTime := c.GetString("EndTime")
  1608. if len(EndTime) > 0 {
  1609. _, ok := lib.TimeStrToTime(EndTime)
  1610. if !ok {
  1611. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1612. c.ServeJSON()
  1613. return
  1614. }
  1615. } else {
  1616. EndTime = time.Now().Format("2006-01-02 15:04:05")
  1617. }
  1618. T_remark := c.GetString("T_remark")
  1619. TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
  1620. TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
  1621. if TemperatureMin == 0 {
  1622. TemperatureMin = 2
  1623. }
  1624. if TemperatureMax == 0 {
  1625. TemperatureMax = 8
  1626. }
  1627. T_task_id := c.GetString("T_task_id")
  1628. Task_r, is := Task.Read_Task(T_task_id)
  1629. if !is {
  1630. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  1631. c.ServeJSON()
  1632. return
  1633. }
  1634. if Task_r.T_collection_state == 2 {
  1635. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  1636. c.ServeJSON()
  1637. return
  1638. }
  1639. deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  1640. if !is {
  1641. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  1642. c.ServeJSON()
  1643. return
  1644. }
  1645. Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
  1646. // 生成图片
  1647. go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
  1648. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1649. c.ServeJSON()
  1650. return
  1651. }
  1652. // SyncInfoCollection 同步信息采集表
  1653. func (c *TaskController) SyncInfoCollection() {
  1654. T_task_id := c.GetString("T_task_id")
  1655. T_source, _ := c.GetInt("T_source")
  1656. task, is := Task.Read_Task(T_task_id)
  1657. if !is {
  1658. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1659. c.ServeJSON()
  1660. return
  1661. }
  1662. // 获取信息采集表模版信息
  1663. InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
  1664. InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
  1665. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  1666. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  1667. InfoCollectionDataMap := make(map[string]string)
  1668. for _, data := range InfoCollection_Data {
  1669. InfoCollectionDataMap[data.T_name] = data.T_value
  1670. }
  1671. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  1672. for _, v := range Data {
  1673. if len(v.T_value) > 0 {
  1674. continue
  1675. }
  1676. if InfoCollectionDataMap[v.T_name] == "" {
  1677. continue
  1678. }
  1679. val := VerifyTemplate.VerifyTemplateMapData{
  1680. T_source: T_source,
  1681. T_task_id: task.T_task_id,
  1682. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  1683. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  1684. T_flow_sort: v.T_flow_sort,
  1685. T_max_time: v.T_max_time,
  1686. T_min_time: v.T_min_time,
  1687. T_value: InfoCollectionDataMap[v.T_name],
  1688. }
  1689. MapDataList = append(MapDataList, val)
  1690. }
  1691. var ids []int64
  1692. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  1693. if !is {
  1694. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  1695. c.ServeJSON()
  1696. return
  1697. }
  1698. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  1699. c.ServeJSON()
  1700. return
  1701. }
  1702. // 退回记录列表
  1703. func (c *TaskController) AuditRecordList() {
  1704. // 验证登录 User_is, User_r
  1705. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1706. if !User_is {
  1707. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1708. c.ServeJSON()
  1709. return
  1710. }
  1711. T_task_id := c.GetString("T_task_id")
  1712. T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
  1713. //T_task 驳回记录
  1714. //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1715. //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  1716. //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1717. T_state, _ := c.GetInt("T_state") // -1 获取全部
  1718. r, is := Task.Read_Task(T_task_id)
  1719. if !is {
  1720. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1721. c.ServeJSON()
  1722. return
  1723. }
  1724. var auditRecordList []Task.AuditRecord
  1725. switch T_type {
  1726. case "T_task":
  1727. T_state = -1
  1728. if len(r.T_reject_record) > 0 {
  1729. err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
  1730. if err != nil {
  1731. logs.Error("JSON 反序列化失败:", err)
  1732. return
  1733. }
  1734. }
  1735. case "T_scheme":
  1736. if len(r.T_scheme_audit_record) > 0 {
  1737. err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
  1738. if err != nil {
  1739. logs.Error("JSON 反序列化失败:", err)
  1740. return
  1741. }
  1742. }
  1743. case "T_collection":
  1744. if len(r.T_collection_audit_record) > 0 {
  1745. err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
  1746. if err != nil {
  1747. logs.Error("JSON 反序列化失败:", err)
  1748. return
  1749. }
  1750. }
  1751. case "T_reporting":
  1752. if len(r.T_reporting_audit_record) > 0 {
  1753. err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
  1754. if err != nil {
  1755. logs.Error("JSON 反序列化失败:", err)
  1756. return
  1757. }
  1758. }
  1759. }
  1760. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1761. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  1762. var auditRecordList2 []Task.AuditRecord
  1763. // 返回全部
  1764. if T_state == -1 {
  1765. for i := 0; i < len(auditRecordList); i++ {
  1766. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1767. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1768. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1769. }
  1770. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1771. c.ServeJSON()
  1772. return
  1773. }
  1774. if T_state == -2 {
  1775. for i := 0; i < len(auditRecordList); i++ {
  1776. if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
  1777. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1778. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1779. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1780. }
  1781. }
  1782. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1783. c.ServeJSON()
  1784. return
  1785. }
  1786. for i := 0; i < len(auditRecordList); i++ {
  1787. if auditRecordList[i].T_state == T_state {
  1788. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1789. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1790. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1791. }
  1792. }
  1793. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1794. c.ServeJSON()
  1795. return
  1796. }
  1797. // 存档生成图片
  1798. func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
  1799. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1800. State: 1,
  1801. Msg: "图片生成中",
  1802. Url: "",
  1803. })
  1804. msg := ""
  1805. state := 2
  1806. url := ""
  1807. if TemperatureMin == 0 {
  1808. TemperatureMin = 2
  1809. }
  1810. if TemperatureMax == 0 {
  1811. TemperatureMax = 8
  1812. }
  1813. var ymin, ymax float64
  1814. var xminT, xmaxT time.Time
  1815. if len(deviceList) > 0 {
  1816. ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
  1817. }
  1818. // 创建一个新的绘图
  1819. p := plot.New()
  1820. // 设置绘图标题和标签
  1821. p.Title.Text = "温度折线图"
  1822. //p.Legend.ThumbnailWidth = 5 * vg.Inch
  1823. p.X.Label.Text = "时间"
  1824. p.Y.Label.Text = "温度"
  1825. var chData = make(chan int, 10)
  1826. var jobGroup sync.WaitGroup
  1827. var device = make([]Device.DeviceCount, len(deviceList))
  1828. // 创建温度线
  1829. for i := 0; i < len(deviceList); i++ {
  1830. chData <- 1
  1831. jobGroup.Add(1)
  1832. go func(index int) {
  1833. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  1834. defer func() {
  1835. <-chData // 完成时chan取出1个
  1836. jobGroup.Done() // 完成时将等待组值减1
  1837. }()
  1838. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  1839. ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
  1840. if ymin > ymin_ {
  1841. ymin = ymin_
  1842. }
  1843. if ymax < ymax_ {
  1844. ymax = ymax_
  1845. }
  1846. if xminT.After(minTime_) && !minTime_.IsZero() {
  1847. xminT = minTime_
  1848. }
  1849. if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
  1850. xmaxT = maxTime_
  1851. }
  1852. r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  1853. device[index] = Device.DeviceCount{
  1854. T_id: id,
  1855. Num: r_maps_num,
  1856. }
  1857. if r_maps_num == 0 {
  1858. return
  1859. }
  1860. pts := make(plotter.XYs, len(r_maps))
  1861. for j, d := range r_maps {
  1862. t, _ := lib.TimeStrToTime(d.T_time)
  1863. pts[j].X = float64(t.Unix())
  1864. pts[j].Y = float64(d.T_t)
  1865. }
  1866. line, err := plotter.NewLine(pts)
  1867. if err != nil {
  1868. return
  1869. }
  1870. line.Color = randomColor(index)
  1871. p.Add(line)
  1872. }(i)
  1873. }
  1874. jobGroup.Wait()
  1875. xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
  1876. // 添加最高,最低标准线 用红色虚线标识
  1877. p.Add(horizontalLine(xmin, xmax, TemperatureMin))
  1878. p.Add(horizontalLine(xmin, xmax, TemperatureMax))
  1879. if ymax < 8 {
  1880. ymax = 8
  1881. }
  1882. if ymin > 0 {
  1883. ymin = 0
  1884. }
  1885. p.Y.Min, p.Y.Max = ymin, ymax
  1886. p.X.Min, p.X.Max = xmin, xmax
  1887. p.Y.Tick.Marker = commaTicks{}
  1888. //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
  1889. p.X.Tick.Marker = timeTicks{}
  1890. p.X.Tick.Label.Rotation = math.Pi / 5
  1891. p.X.Tick.Label.YAlign = draw.YCenter
  1892. p.X.Tick.Label.XAlign = draw.XRight
  1893. filename := "jpg" + time.Now().Format("20060102150405")
  1894. // 保存文件
  1895. if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
  1896. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1897. State: 3,
  1898. Msg: "图片生成失败",
  1899. Url: url,
  1900. })
  1901. logs.Error(lib.FuncName(), "生成图片失败", err)
  1902. return
  1903. }
  1904. if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
  1905. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1906. State: 3,
  1907. Msg: "图片上传七牛云失败",
  1908. Url: url,
  1909. })
  1910. logs.Error(lib.FuncName(), "上传七牛云失败")
  1911. return
  1912. }
  1913. //删除目录
  1914. os.Remove("ofile/" + filename + ".jpg")
  1915. msg = "图片生成成功"
  1916. url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
  1917. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1918. State: state,
  1919. Msg: msg,
  1920. Url: url,
  1921. Device: device,
  1922. })
  1923. return
  1924. }
  1925. func horizontalLine(xmin, xmax, y float64) *plotter.Line {
  1926. pts := make(plotter.XYs, 2)
  1927. pts[0].X = xmin
  1928. pts[0].Y = y
  1929. pts[1].X = xmax
  1930. pts[1].Y = y
  1931. line, err := plotter.NewLine(pts)
  1932. if err != nil {
  1933. panic(any(err))
  1934. }
  1935. line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
  1936. line.Color = color.RGBA{R: 255, A: 255}
  1937. return line
  1938. }
  1939. type timeTicks struct{}
  1940. func (timeTicks) Ticks(min, max float64) []plot.Tick {
  1941. tks := plot.TimeTicks{}.Ticks(min, max)
  1942. for i, t := range tks {
  1943. //if t.Label == "" { // Skip minor ticks, they are fine.
  1944. // continue
  1945. //}
  1946. tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
  1947. }
  1948. return tks
  1949. }
  1950. type commaTicks struct{}
  1951. // Ticks computes the default tick marks, but inserts commas
  1952. // into the labels for the major tick marks.
  1953. func (commaTicks) Ticks(min, max float64) []plot.Tick {
  1954. tks := plot.DefaultTicks{}.Ticks(min, max)
  1955. for i, t := range tks {
  1956. //if t.Label == "" { // Skip minor ticks, they are fine.
  1957. // continue
  1958. //}
  1959. tks[i].Label = fmt.Sprintf("%.0f", t.Value)
  1960. }
  1961. return tks
  1962. }
  1963. // 生成随机颜色的辅助函数
  1964. func randomColor(i int) color.RGBA {
  1965. var colors []color.RGBA
  1966. colors = append(colors,
  1967. color.RGBA{R: 52, G: 152, B: 219, A: 255},
  1968. color.RGBA{R: 230, G: 126, B: 34, A: 255},
  1969. color.RGBA{R: 142, G: 68, B: 173, A: 255},
  1970. color.RGBA{R: 211, G: 84, B: 0, A: 255},
  1971. color.RGBA{R: 231, G: 76, B: 60, A: 255},
  1972. color.RGBA{R: 26, G: 188, B: 156, A: 255},
  1973. color.RGBA{R: 243, G: 156, B: 18, A: 255},
  1974. color.RGBA{R: 22, G: 160, B: 133, A: 255},
  1975. color.RGBA{R: 46, G: 204, B: 113, A: 255},
  1976. color.RGBA{R: 39, G: 174, B: 96, A: 255},
  1977. color.RGBA{R: 41, G: 128, B: 185, A: 255},
  1978. color.RGBA{R: 155, G: 89, B: 182, A: 255},
  1979. color.RGBA{R: 192, G: 57, B: 43, A: 255},
  1980. color.RGBA{R: 241, G: 196, B: 15, A: 255},
  1981. )
  1982. return colors[i%len(colors)]
  1983. }
  1984. // 获取加完水印的pdf
  1985. func GetWatermarkPdf(task Task.Task, pdfURL string, flag string) (pdf string) {
  1986. if len(pdfURL) == 0 {
  1987. return
  1988. }
  1989. currentDirectory := lib.GetCurrentDirectory()
  1990. scriptPath := currentDirectory + "/script"
  1991. pdf_file_out_name := uuid.New().String() + ".pdf"
  1992. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  1993. pdf_file_out := currentDirectory + "/ofile/watermark" + pdf_file_out_name
  1994. watermark_pdf := currentDirectory + "/script/watermark.pdf"
  1995. // 执行Python脚本
  1996. cmd := exec.Command("python3", "add_watermark.py", pdfURL, pdfFilename, pdf_file_out, watermark_pdf)
  1997. cmd.Dir = scriptPath
  1998. // 获取命令输出
  1999. _, err := cmd.CombinedOutput()
  2000. if err != nil {
  2001. logs.Error("执行python脚本添加水印错误:", err)
  2002. return
  2003. }
  2004. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  2005. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  2006. err = errors.New("上传水印pdf失败")
  2007. return
  2008. }
  2009. defer func() {
  2010. os.Remove(pdfFilename)
  2011. os.Remove(pdf_file_out)
  2012. }()
  2013. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  2014. switch flag {
  2015. case "T_pdf1":
  2016. task.T_pdf1_watermark = pdf
  2017. Task.Update_Task(task, "T_pdf1_watermark")
  2018. case "T_pdf2":
  2019. task.T_pdf2_watermark = pdf
  2020. Task.Update_Task(task, "T_pdf2_watermark")
  2021. }
  2022. return
  2023. }
  2024. // 暂停申请
  2025. // 列表 -
  2026. func (c *TaskController) TaskTimeList() {
  2027. // 验证登录 User_is, User_r
  2028. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2029. if !User_is {
  2030. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2031. c.ServeJSON()
  2032. return
  2033. }
  2034. var r_jsons lib.R_JSONS
  2035. T_task_id := c.GetString("T_task_id")
  2036. T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
  2037. var cnt int64
  2038. List, cnt := Task.Read_TaskTime_List(T_task_id, T_task_type)
  2039. r_jsons.List = List
  2040. r_jsons.Num = int(cnt)
  2041. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2042. c.ServeJSON()
  2043. return
  2044. }
  2045. // 添加-
  2046. func (c *TaskController) TaskTimeAdd() {
  2047. // 验证登录 User_is, User_r
  2048. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2049. if !User_is {
  2050. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2051. c.ServeJSON()
  2052. return
  2053. }
  2054. dc := Device.DeviceClass{
  2055. T_uuid: User_r.T_uuid,
  2056. T_State: 1,
  2057. }
  2058. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", dc)
  2059. T_task_id := c.GetString("T_task_id")
  2060. T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
  2061. T_aaa := c.GetString("T_aaa")
  2062. var_ := Task.TaskTime{
  2063. T_task_id: T_task_id,
  2064. T_task_type: T_task_type,
  2065. T_uuid: User_r.T_uuid,
  2066. T_remarks: T_aaa,
  2067. T_start_time: time.Now().Format("2006-01-02 15:04:05"),
  2068. }
  2069. List, _ := Task.Read_TaskTime_List(T_task_id, T_task_type)
  2070. if len(List) > 0 {
  2071. if len(List[len(List)-1].T_end_time) == 0 {
  2072. c.Data["json"] = lib.JSONS{Code: 202, Msg: "上一个任务还没结束!"}
  2073. c.ServeJSON()
  2074. return
  2075. }
  2076. }
  2077. is := Task.Add_TaskTime(var_)
  2078. if !is {
  2079. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  2080. c.ServeJSON()
  2081. return
  2082. }
  2083. // 添加任务操作日志
  2084. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务暂停", "暂停申请", var_)
  2085. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", var_)
  2086. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  2087. c.ServeJSON()
  2088. return
  2089. }
  2090. // 添加-
  2091. func (c *TaskController) TaskTimeEnd() {
  2092. // 验证登录 User_is, User_r
  2093. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2094. if !User_is {
  2095. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2096. c.ServeJSON()
  2097. return
  2098. }
  2099. dc := Device.DeviceClass{
  2100. T_uuid: User_r.T_uuid,
  2101. T_State: 1,
  2102. }
  2103. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", dc)
  2104. Id, _ := c.GetInt("Id", 0)
  2105. TaskTime_r, is := Task.Read_TaskTime_ById(Id)
  2106. if !is {
  2107. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2108. c.ServeJSON()
  2109. return
  2110. }
  2111. TaskTime_r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  2112. is = Task.Update_TaskTime(TaskTime_r, "T_end_time")
  2113. if !is {
  2114. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2115. c.ServeJSON()
  2116. return
  2117. }
  2118. // 添加任务操作日志
  2119. Task.Add_TaskLogs_T(User_r.T_uuid, TaskTime_r.T_task_id, "任务暂停", "暂停结束", TaskTime_r)
  2120. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", TaskTime_r)
  2121. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: TaskTime_r.T_task_id}
  2122. c.ServeJSON()
  2123. return
  2124. }
  2125. // 列表 - 统计排名
  2126. func (c *TaskController) StatisticalRanking() {
  2127. // 验证登录 User_is, User_r
  2128. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2129. if !User_is {
  2130. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2131. c.ServeJSON()
  2132. return
  2133. }
  2134. T_power, _ := c.GetInt("T_power", 0) // 5 数据采集工程师 6 验证报告工程师
  2135. type Admin_T struct {
  2136. T_name string
  2137. T_scheme int // 实施方案
  2138. T_scheme_returnnum int // 退回
  2139. T_scheme_overnum int // 超时
  2140. T_scheme_log string // 日志
  2141. T_collection int // 数据采集
  2142. T_collection_returnnum int // 退回
  2143. T_collection_overnum int // 超时
  2144. T_collection_log string // 日志
  2145. T_reporting int // 报告编写
  2146. T_reporting_returnnum int // 退回
  2147. T_reporting_overnum int // 超时
  2148. T_reporting_log string // 日志
  2149. T_rejectdnum int // 驳回数量
  2150. }
  2151. var Admin_T_List []Admin_T
  2152. Admin_List := Account.Read_Admin_List_ALL_T_power(T_power)
  2153. for _, A := range Admin_List {
  2154. Admin_t := Admin_T{T_name: A.T_name}
  2155. // 方案
  2156. Task_List := Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_scheme") //T_scheme T_collection T_reporting
  2157. for _, T := range Task_List {
  2158. if len(T.T_scheme_end_time) > 0 {
  2159. if is, _ := lib.IsInCurrentMonth(T.T_scheme_end_time); !is {
  2160. continue // 不是本月
  2161. }
  2162. Admin_t.T_scheme += 1
  2163. Admin_t.T_scheme_log += T.T_name
  2164. // 退回
  2165. if T.T_scheme_return_times > 0 {
  2166. Admin_t.T_scheme_returnnum += T.T_scheme_return_times
  2167. Admin_t.T_scheme_log += " | 退回" + lib.To_string(int(T.T_scheme_return_times))
  2168. }
  2169. // 超时
  2170. if T.T_scheme_overtime > 0 {
  2171. Admin_t.T_scheme_overnum += 1
  2172. Admin_t.T_scheme_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_scheme_overtime))
  2173. }
  2174. // 驳回
  2175. if T.T_reject_times > 0 {
  2176. Admin_t.T_rejectdnum += T.T_reject_times
  2177. Admin_t.T_scheme_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  2178. }
  2179. Admin_t.T_scheme_log += "\n"
  2180. }
  2181. }
  2182. // 实施
  2183. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_collection") //T_scheme T_collection T_reporting
  2184. for _, T := range Task_List {
  2185. if len(T.T_collection_end_time) > 0 {
  2186. if is, _ := lib.IsInCurrentMonth(T.T_collection_end_time); !is {
  2187. continue // 不是本月
  2188. }
  2189. Admin_t.T_collection += 1
  2190. Admin_t.T_collection_log += T.T_name
  2191. // 退回
  2192. if T.T_collection_return_times > 0 {
  2193. Admin_t.T_collection_returnnum += T.T_collection_return_times
  2194. Admin_t.T_collection_log += " | 退回" + lib.To_string(int(T.T_collection_return_times))
  2195. }
  2196. // 超时
  2197. if T.T_collection_overtime > 0 {
  2198. Admin_t.T_collection_overnum += 1
  2199. Admin_t.T_collection_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_collection_overtime))
  2200. }
  2201. // 驳回
  2202. if T.T_reject_times > 0 {
  2203. Admin_t.T_rejectdnum += T.T_reject_times
  2204. Admin_t.T_collection_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  2205. }
  2206. Admin_t.T_collection_log += "\n"
  2207. }
  2208. }
  2209. // 报告
  2210. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_reporting") //T_scheme T_collection T_reporting
  2211. for _, T := range Task_List {
  2212. if len(T.T_reporting_end_time) > 0 {
  2213. if is, _ := lib.IsInCurrentMonth(T.T_reporting_end_time); !is {
  2214. continue // 不是本月
  2215. }
  2216. Admin_t.T_reporting += 1
  2217. Admin_t.T_reporting_log += T.T_name
  2218. // 退回
  2219. if T.T_reporting_return_times > 0 {
  2220. Admin_t.T_reporting_returnnum += T.T_reporting_return_times
  2221. Admin_t.T_reporting_log += " | 退回" + lib.To_string(int(T.T_reporting_return_times))
  2222. }
  2223. // 超时
  2224. if T.T_reporting_overtime > 0 {
  2225. Admin_t.T_reporting_overnum += 1
  2226. Admin_t.T_reporting_log += " | 超时" + lib.ConvertMinutesToDHM(int(T.T_reporting_overtime))
  2227. }
  2228. // 驳回
  2229. if T.T_reject_times > 0 {
  2230. Admin_t.T_rejectdnum += T.T_reject_times
  2231. Admin_t.T_reporting_log += " | 驳回" + lib.To_string(int(T.T_reject_times))
  2232. }
  2233. Admin_t.T_reporting_log += "\n"
  2234. }
  2235. }
  2236. Admin_T_List = append(Admin_T_List, Admin_t)
  2237. }
  2238. var r_jsons lib.R_JSONS
  2239. r_jsons.List = Admin_T_List
  2240. r_jsons.Page = 0
  2241. r_jsons.Page_size = 0
  2242. r_jsons.Pages = lib.Func_page(int64(0), int64(0))
  2243. r_jsons.Num = 0
  2244. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2245. c.ServeJSON()
  2246. return
  2247. }
  2248. // 添加-
  2249. func (c *TaskController) Copy() {
  2250. // 验证登录 User_is, User_r
  2251. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2252. if !User_is {
  2253. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2254. c.ServeJSON()
  2255. return
  2256. }
  2257. T_name := c.GetString("T_name")
  2258. T_task_id := c.GetString("T_task_id")
  2259. r, is := Task.Read_Task(T_task_id)
  2260. if !is {
  2261. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  2262. c.ServeJSON()
  2263. return
  2264. }
  2265. // 查询信息采集信息
  2266. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  2267. if !is {
  2268. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  2269. c.ServeJSON()
  2270. return
  2271. }
  2272. var_ := Task.Task{
  2273. T_Distributor_id: User_r.T_Distributor_id,
  2274. T_InfoCollection_id: r.T_InfoCollection_id,
  2275. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  2276. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  2277. T_class: r.T_class,
  2278. T_uuid: r.T_uuid,
  2279. T_name: T_name,
  2280. T_VerifyTemplate_class: r.T_VerifyTemplate_class,
  2281. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  2282. T_deadline: r.T_deadline,
  2283. T_scheme: r.T_scheme,
  2284. T_collection: r.T_collection,
  2285. T_reporting: r.T_reporting,
  2286. T_delivery: r.T_delivery,
  2287. T_Show: 1,
  2288. T_State: 1,
  2289. T_project: r.T_project,
  2290. T_province: r.T_province,
  2291. T_city: r.T_city,
  2292. T_district: r.T_district,
  2293. T_province_code: r.T_province_code,
  2294. T_city_code: r.T_city_code,
  2295. T_district_code: r.T_district_code,
  2296. T_category: r.T_category,
  2297. T_device_type: r.T_device_type,
  2298. T_volume: r.T_volume,
  2299. T_verify_type: r.T_verify_type,
  2300. T_subject_matter: r.T_subject_matter,
  2301. T_temp_range: r.T_temp_range,
  2302. T_report_number: r.T_report_number,
  2303. T_report_type: r.T_report_type,
  2304. }
  2305. id, is := Task.Add_Task(var_)
  2306. if !is {
  2307. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  2308. c.ServeJSON()
  2309. return
  2310. }
  2311. NatsServer.Create_Local_Table(T_task_id)
  2312. // 通知
  2313. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  2314. go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2315. go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2316. go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2317. go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  2318. // 添加任务操作日志
  2319. Task.Add_TaskLogs_T(User_r.T_uuid, id, "任务管理", "添加", var_)
  2320. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "添加", var_)
  2321. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
  2322. c.ServeJSON()
  2323. return
  2324. }