Task.go 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527
  1. package controllers
  2. import (
  3. "ColdVerify_server/Nats/NatsServer"
  4. "ColdVerify_server/conf"
  5. "ColdVerify_server/lib"
  6. "ColdVerify_server/lib/wx"
  7. "ColdVerify_server/logs"
  8. "ColdVerify_server/models/Account"
  9. "ColdVerify_server/models/Device"
  10. "ColdVerify_server/models/InfoCollection"
  11. "ColdVerify_server/models/System"
  12. "ColdVerify_server/models/Task"
  13. "ColdVerify_server/models/VerifyTemplate"
  14. "encoding/json"
  15. "errors"
  16. "fmt"
  17. beego "github.com/beego/beego/v2/server/web"
  18. "github.com/google/uuid"
  19. "github.com/xuri/excelize/v2"
  20. "gonum.org/v1/plot"
  21. "gonum.org/v1/plot/plotter"
  22. "gonum.org/v1/plot/vg"
  23. "gonum.org/v1/plot/vg/draw"
  24. "image/color"
  25. "math"
  26. "os"
  27. "os/exec"
  28. "strings"
  29. "sync"
  30. "time"
  31. )
  32. type TaskController struct {
  33. beego.Controller
  34. }
  35. // 列表 -
  36. func (c *TaskController) List() {
  37. // 验证登录 User_is, User_r
  38. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  39. if !User_is {
  40. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  41. c.ServeJSON()
  42. return
  43. }
  44. var r_jsons lib.R_JSONS
  45. page, _ := c.GetInt("page")
  46. if page < 1 {
  47. page = 1
  48. }
  49. page_z, _ := c.GetInt("page_z")
  50. if page_z < 1 {
  51. page_z = conf.Page_size
  52. }
  53. T_name := c.GetString("T_name")
  54. T_company := c.GetString("T_company") // 公司名称
  55. T_uuid := c.GetString("T_uuid")
  56. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  57. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  58. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  59. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  60. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  61. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  62. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  63. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  64. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  65. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  66. CreateTime := c.GetString("CreateTime") // 任务添加时间
  67. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  68. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  69. var T_company_list []string
  70. if len(T_company) > 0 {
  71. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  72. }
  73. var T_admin string
  74. if User_r.T_power > 2 {
  75. T_admin = User_r.T_uuid
  76. }
  77. var cnt int
  78. List, cnt := Task.Read_Task_List(T_uuid, T_admin, T_name, T_InfoCollection_id, T_scheme, T_collection, T_reporting, T_delivery,
  79. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  80. T_company_list, UserMap, AdminMap,CreateTime, page, page_z)
  81. page_size := math.Ceil(float64(cnt) / float64(page_z))
  82. r_jsons.List = List
  83. r_jsons.Page = page
  84. r_jsons.Page_size = int(page_size)
  85. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  86. r_jsons.Num = cnt
  87. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  88. c.ServeJSON()
  89. return
  90. }
  91. // 报告统计
  92. func (c *TaskController) Stat() {
  93. // 验证登录 User_is, User_r
  94. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  95. if !User_is {
  96. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  97. c.ServeJSON()
  98. return
  99. }
  100. var r_jsons lib.R_JSONS
  101. page, _ := c.GetInt("page")
  102. if page < 1 {
  103. page = 1
  104. }
  105. page_z, _ := c.GetInt("page_z")
  106. if page_z < 1 {
  107. page_z = conf.Page_size
  108. }
  109. T_name := c.GetString("T_name")
  110. T_company := c.GetString("T_company") // 公司名称
  111. T_uuid := c.GetString("T_uuid")
  112. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  113. T_project := c.GetString("T_project") // 项目 负责人UUID
  114. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  115. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  116. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  117. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  118. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  119. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  120. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  121. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  122. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  123. CreateTime := c.GetString("CreateTime") // 任务添加时间
  124. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  125. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  126. var T_company_list []string
  127. if len(T_company) > 0 {
  128. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  129. }
  130. var T_admin string
  131. if User_r.T_power > 2 {
  132. T_admin = User_r.T_uuid
  133. }
  134. var cnt int
  135. List, cnt := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
  136. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  137. T_company_list, UserMap, AdminMap,CreateTime, page, page_z)
  138. page_size := math.Ceil(float64(cnt) / float64(page_z))
  139. r_jsons.List = List
  140. r_jsons.Page = page
  141. r_jsons.Page_size = int(page_size)
  142. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  143. r_jsons.Num = cnt
  144. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  145. c.ServeJSON()
  146. return
  147. }
  148. // 报告统计 - 导出excel
  149. func (c *TaskController) Stat_Excel() {
  150. // 验证登录 User_is, User_r
  151. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  152. if !User_is {
  153. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  154. c.ServeJSON()
  155. return
  156. }
  157. T_name := c.GetString("T_name")
  158. T_company := c.GetString("T_company") // 公司名称
  159. T_uuid := c.GetString("T_uuid")
  160. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  161. T_project := c.GetString("T_project") // 项目 负责人UUID
  162. T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
  163. T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
  164. T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
  165. T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
  166. T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  167. T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  168. T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  169. T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
  170. T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
  171. CreateTime := c.GetString("CreateTime") // 任务添加时间
  172. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  173. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  174. var T_company_list []string
  175. if len(T_company) > 0 {
  176. T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
  177. }
  178. var T_admin string
  179. if User_r.T_power > 2 {
  180. T_admin = User_r.T_uuid
  181. }
  182. List, _ := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
  183. T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
  184. T_company_list, UserMap, AdminMap,CreateTime, 0, 9999)
  185. f := excelize.NewFile() // 设置单元格的值
  186. line := 1
  187. // 这里设置表头
  188. f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("A%d", line+1))
  189. f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("B%d", line+1))
  190. f.MergeCell("Sheet1", fmt.Sprintf("C%d", line), fmt.Sprintf("C%d", line+1))
  191. f.MergeCell("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("D%d", line+1))
  192. f.MergeCell("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("E%d", line+1))
  193. f.MergeCell("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("F%d", line+1))
  194. f.MergeCell("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("G%d", line+1))
  195. f.MergeCell("Sheet1", fmt.Sprintf("H%d", line), fmt.Sprintf("H%d", line+1))
  196. f.MergeCell("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("I%d", line+1))
  197. f.MergeCell("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("J%d", line+1))
  198. f.MergeCell("Sheet1", fmt.Sprintf("K%d", line), fmt.Sprintf("K%d", line+1))
  199. f.MergeCell("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("L%d", line+1))
  200. f.MergeCell("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("M%d", line+1))
  201. f.MergeCell("Sheet1", fmt.Sprintf("N%d", line), fmt.Sprintf("N%d", line+1))
  202. f.MergeCell("Sheet1", fmt.Sprintf("O%d", line), fmt.Sprintf("O%d", line+1))
  203. f.MergeCell("Sheet1", fmt.Sprintf("P%d", line), fmt.Sprintf("P%d", line+1))
  204. f.MergeCell("Sheet1", fmt.Sprintf("Q%d", line), fmt.Sprintf("U%d", line))
  205. f.MergeCell("Sheet1", fmt.Sprintf("V%d", line), fmt.Sprintf("AA%d", line))
  206. f.MergeCell("Sheet1", fmt.Sprintf("AB%d", line), fmt.Sprintf("AG%d", line))
  207. f.MergeCell("Sheet1", fmt.Sprintf("AH%d", line), fmt.Sprintf("AM%d", line))
  208. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), "信息表")
  209. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), "方案")
  210. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), "实施")
  211. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), "报告")
  212. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "序号")
  213. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "公司名称")
  214. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), "报告名称")
  215. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), "项目负责人")
  216. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), "地区")
  217. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), "类别")
  218. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), "设备类型")
  219. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), "规格/容积")
  220. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), "验证类型")
  221. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), "标的物名称")
  222. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "验证温度范围")
  223. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), "报告编号")
  224. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), "项目开始时间")
  225. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), "项目用时")
  226. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), "驳回次数")
  227. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), "回款")
  228. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line+1), "编写人")
  229. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line+1), "状态")
  230. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line+1), "开始时间")
  231. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line+1), "退回次数")
  232. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line+1), "所需时间")
  233. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line+1), "编写人")
  234. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line+1), "状态")
  235. f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line+1), "开始时间")
  236. f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line+1), "退回次数")
  237. f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line+1), "所需时间")
  238. f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line+1), "超时时间")
  239. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line+1), "编写人")
  240. f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line+1), "状态")
  241. f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line+1), "开始时间")
  242. f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line+1), "退回次数")
  243. f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line+1), "所需时间")
  244. f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line+1), "超时时间")
  245. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line+1), "编写人")
  246. f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line+1), "状态")
  247. f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line+1), "开始时间")
  248. f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line+1), "退回次数")
  249. f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line+1), "所需时间")
  250. f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line+1), "超时时间")
  251. f.SetCellValue("Sheet1", fmt.Sprintf("AN%d", line+1), "领导备注")
  252. // 设置列宽
  253. f.SetColWidth("Sheet1", "A", "A", 7)
  254. f.SetColWidth("Sheet1", "B", "B", 20)
  255. f.SetColWidth("Sheet1", "C", "C", 10)
  256. f.SetColWidth("Sheet1", "D", "D", 10)
  257. f.SetColWidth("Sheet1", "E", "E", 12)
  258. f.SetColWidth("Sheet1", "F", "F", 8)
  259. f.SetColWidth("Sheet1", "G", "G", 12)
  260. f.SetColWidth("Sheet1", "H", "H", 14)
  261. f.SetColWidth("Sheet1", "I", "I", 12)
  262. f.SetColWidth("Sheet1", "J", "J", 12)
  263. f.SetColWidth("Sheet1", "K", "K", 12)
  264. f.SetColWidth("Sheet1", "L", "L", 12)
  265. f.SetColWidth("Sheet1", "M", "M", 12)
  266. f.SetColWidth("Sheet1", "N", "N", 12)
  267. f.SetColWidth("Sheet1", "O", "O", 10)
  268. f.SetColWidth("Sheet1", "P", "P", 8)
  269. f.SetColWidth("Sheet1", "Q", "Q", 8)
  270. f.SetColWidth("Sheet1", "R", "R", 8)
  271. f.SetColWidth("Sheet1", "S", "S", 12)
  272. f.SetColWidth("Sheet1", "T", "T", 10)
  273. f.SetColWidth("Sheet1", "U", "U", 10)
  274. f.SetColWidth("Sheet1", "V", "V", 8)
  275. f.SetColWidth("Sheet1", "W", "W", 8)
  276. f.SetColWidth("Sheet1", "X", "X", 12)
  277. f.SetColWidth("Sheet1", "Y", "Y", 10)
  278. f.SetColWidth("Sheet1", "Z", "Z", 12)
  279. f.SetColWidth("Sheet1", "AA", "AA", 12)
  280. f.SetColWidth("Sheet1", "AB", "AB", 8)
  281. f.SetColWidth("Sheet1", "AC", "AC", 8)
  282. f.SetColWidth("Sheet1", "AD", "AD", 12)
  283. f.SetColWidth("Sheet1", "AE", "AE", 10)
  284. f.SetColWidth("Sheet1", "AF", "AF", 12)
  285. f.SetColWidth("Sheet1", "AG", "AG", 12)
  286. f.SetColWidth("Sheet1", "AG", "AG", 10)
  287. f.SetColWidth("Sheet1", "AH", "AH", 8)
  288. f.SetColWidth("Sheet1", "AI", "AI", 8)
  289. f.SetColWidth("Sheet1", "AJ", "AJ", 10)
  290. f.SetColWidth("Sheet1", "AK", "AK", 12)
  291. f.SetColWidth("Sheet1", "AL", "AL", 12)
  292. f.SetColWidth("Sheet1", "AM", "AM", 12)
  293. Style1, _ := f.NewStyle(
  294. &excelize.Style{
  295. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  296. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  297. Border: []excelize.Border{
  298. {Type: "left", Color: "000000", Style: 1},
  299. {Type: "top", Color: "000000", Style: 1},
  300. {Type: "bottom", Color: "000000", Style: 1},
  301. {Type: "right", Color: "000000", Style: 1},
  302. },
  303. })
  304. f.SetCellStyle("Sheet1", "A1", "AM2", Style1)
  305. f.SetRowHeight("Sheet1", 1, 25)
  306. f.SetRowHeight("Sheet1", 2, 25)
  307. line += 1
  308. // 循环写入数据
  309. for i, v := range List {
  310. line++
  311. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  312. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_user_name)
  313. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name)
  314. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_project_name)
  315. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("%s-%s-%s", v.T_province, v.T_city, v.T_district))
  316. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_category)
  317. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_device_type)
  318. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_volume)
  319. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_verify_type)
  320. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_subject_matter)
  321. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.T_temp_range)
  322. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("%s-%s", v.T_report_type, v.T_report_number))
  323. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v.T_start_time)
  324. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), v.T_time_interval)
  325. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v.T_reject_times)
  326. returnedMoney := "否"
  327. if v.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney {
  328. returnedMoney = "是"
  329. }
  330. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), returnedMoney)
  331. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), v.InfoCollection.T_submit_uuid_name)
  332. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), InfoCollection.InfoCollectionStatusMap[v.InfoCollection.T_State])
  333. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), v.InfoCollection.T_start_time)
  334. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), v.InfoCollection.T_return_times)
  335. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), v.InfoCollection.T_time_interval)
  336. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), v.T_scheme_name)
  337. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line), Task.TaskSchemeStateMap[v.T_scheme_state])
  338. f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line), v.T_scheme_start_time)
  339. f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line), v.T_scheme_return_times)
  340. f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line), v.T_scheme_time_interval)
  341. f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line), v.T_scheme_overtime)
  342. f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), v.T_collection_name)
  343. f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line), Task.TaskCollectionStateMap[v.T_collection_state])
  344. f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line), v.T_collection_start_time)
  345. f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line), v.T_collection_return_times)
  346. f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line), v.T_collection_time_interval)
  347. f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line), v.T_collection_overtime)
  348. f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), v.T_reporting_name)
  349. f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line), Task.TaskReportingStateMap[v.T_reporting_state])
  350. f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line), v.T_reporting_start_time)
  351. f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line), v.T_reporting_return_times)
  352. f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line), v.T_reporting_time_interval)
  353. f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line), v.T_reporting_overtime)
  354. f.SetCellValue("Sheet1", fmt.Sprintf("AN%d", line), v.T_record)
  355. }
  356. Style2, _ := f.NewStyle(
  357. &excelize.Style{
  358. Font: &excelize.Font{Size: 10, Family: "宋体"},
  359. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  360. Border: []excelize.Border{
  361. {Type: "left", Color: "000000", Style: 1},
  362. {Type: "top", Color: "000000", Style: 1},
  363. {Type: "bottom", Color: "000000", Style: 1},
  364. {Type: "right", Color: "000000", Style: 1},
  365. },
  366. })
  367. f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("AM%d", line), Style2)
  368. StyleBlueFill, _ := f.NewStyle(
  369. &excelize.Style{
  370. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  371. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  372. Border: []excelize.Border{
  373. {Type: "left", Color: "000000", Style: 1},
  374. {Type: "top", Color: "000000", Style: 1},
  375. {Type: "bottom", Color: "000000", Style: 1},
  376. {Type: "right", Color: "000000", Style: 1},
  377. },
  378. Fill: excelize.Fill{Type: "pattern", Color: []string{"#DEE5F5"}, Pattern: 1},
  379. })
  380. // 粉色填充
  381. StylePinkFill, _ := f.NewStyle(
  382. &excelize.Style{
  383. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  384. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  385. Border: []excelize.Border{
  386. {Type: "left", Color: "000000", Style: 1},
  387. {Type: "top", Color: "000000", Style: 1},
  388. {Type: "bottom", Color: "000000", Style: 1},
  389. {Type: "right", Color: "000000", Style: 1},
  390. },
  391. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FBDFE2"}, Pattern: 1},
  392. })
  393. StyleOrangeFill, _ := f.NewStyle(
  394. &excelize.Style{
  395. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  396. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  397. Border: []excelize.Border{
  398. {Type: "left", Color: "000000", Style: 1},
  399. {Type: "top", Color: "000000", Style: 1},
  400. {Type: "bottom", Color: "000000", Style: 1},
  401. {Type: "right", Color: "000000", Style: 1},
  402. },
  403. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FCE7D8"}, Pattern: 1},
  404. })
  405. StyleYellowFill, _ := f.NewStyle(
  406. &excelize.Style{
  407. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  408. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  409. Border: []excelize.Border{
  410. {Type: "left", Color: "000000", Style: 1},
  411. {Type: "top", Color: "000000", Style: 1},
  412. {Type: "bottom", Color: "000000", Style: 1},
  413. {Type: "right", Color: "000000", Style: 1},
  414. },
  415. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFF5D0"}, Pattern: 1},
  416. })
  417. StyleGreenFill, _ := f.NewStyle(
  418. &excelize.Style{
  419. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  420. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  421. Border: []excelize.Border{
  422. {Type: "left", Color: "000000", Style: 1},
  423. {Type: "top", Color: "000000", Style: 1},
  424. {Type: "bottom", Color: "000000", Style: 1},
  425. {Type: "right", Color: "000000", Style: 1},
  426. },
  427. Fill: excelize.Fill{Type: "pattern", Color: []string{"#E7F4DE"}, Pattern: 1},
  428. })
  429. f.SetCellStyle("Sheet1", "A1", "AM2", StyleBlueFill)
  430. f.SetCellStyle("Sheet1", "Q1", "U1", StylePinkFill)
  431. f.SetCellStyle("Sheet1", "V1", "AA1", StyleOrangeFill)
  432. f.SetCellStyle("Sheet1", "AB1", "AG1", StyleYellowFill)
  433. f.SetCellStyle("Sheet1", "AH1", "AM1", StyleGreenFill)
  434. f.SetCellStyle("Sheet1", "AN1", "AN2", StyleBlueFill)
  435. // 冻结1-2行
  436. f.SetPanes("Sheet1", &excelize.Panes{
  437. Freeze: true,
  438. Split: false,
  439. XSplit: 3,
  440. YSplit: 2,
  441. TopLeftCell: "A1",
  442. ActivePane: "topRight",
  443. })
  444. lib.Create_Dir("./ofile")
  445. timeStr := time.Now().Format("20060102150405")
  446. // 保存文件
  447. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  448. logs.Error(lib.FuncName(), err)
  449. }
  450. if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx") {
  451. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  452. c.ServeJSON()
  453. return
  454. }
  455. //删除目录
  456. err := os.Remove("ofile/" + timeStr + ".xlsx")
  457. if err != nil {
  458. logs.Error(lib.FuncName(), err)
  459. }
  460. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + timeStr + ".xlsx"}
  461. c.ServeJSON()
  462. return
  463. }
  464. // 获取任务负责人列表
  465. func (c *TaskController) GetTaskUserList() {
  466. // 验证登录 User_is, User_r
  467. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  468. if !User_is {
  469. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  470. c.ServeJSON()
  471. return
  472. }
  473. T_type := c.GetString("T_type") // T_project项目 T_scheme方案 T_collection数据采集 T_reporting报告
  474. list := Task.Get_Task_UserList(T_type)
  475. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  476. var User_list []Account.Admin_R
  477. for _, v := range list {
  478. if len(v) == 0 {
  479. continue
  480. }
  481. User_list = append(User_list, Account.Admin_R{T_uuid: v, T_name: AdminMap[v]})
  482. }
  483. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_list}
  484. c.ServeJSON()
  485. return
  486. }
  487. // 列表 -
  488. func (c *TaskController) UserTaskList() {
  489. // 验证登录 User_is, User_r
  490. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  491. if !User_is {
  492. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  493. c.ServeJSON()
  494. return
  495. }
  496. var r_jsons lib.R_JSONS
  497. page, _ := c.GetInt("page")
  498. if page < 1 {
  499. page = 1
  500. }
  501. page_z, _ := c.GetInt("page_z")
  502. if page_z < 1 {
  503. page_z = conf.Page_size
  504. }
  505. T_name := c.GetString("T_name")
  506. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  507. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  508. var cnt int
  509. List, cnt := Task.Read_UserTask_List(User_r.T_uuid, T_name, UserMap, AdminMap, page, page_z)
  510. page_size := math.Ceil(float64(cnt) / float64(page_z))
  511. r_jsons.List = List
  512. r_jsons.Page = page
  513. r_jsons.Page_size = int(page_size)
  514. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  515. r_jsons.Num = cnt
  516. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  517. c.ServeJSON()
  518. return
  519. }
  520. // 获取-
  521. func (c *TaskController) Get() {
  522. // 验证登录 User_is, User_r
  523. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  524. if !User_is {
  525. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  526. c.ServeJSON()
  527. return
  528. }
  529. T_task_id := c.GetString("T_task_id")
  530. r, is := Task.Read_Task(T_task_id)
  531. if !is {
  532. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  533. c.ServeJSON()
  534. return
  535. }
  536. // 添加浏览量
  537. _ = Task.Add_Task_Visit(r)
  538. r.T_Visit += 1
  539. userMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  540. adminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  541. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Task.TaskToTask_Stat(r, userMap, adminMap)}
  542. c.ServeJSON()
  543. return
  544. }
  545. // 添加-
  546. func (c *TaskController) Add() {
  547. // 验证登录 User_is, User_r
  548. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  549. if !User_is {
  550. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  551. c.ServeJSON()
  552. return
  553. }
  554. dc := Device.DeviceClass{
  555. T_uuid: User_r.T_uuid,
  556. T_State: 1,
  557. }
  558. T_class_id, is := Device.Add_DeviceClass(dc)
  559. if !is {
  560. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  561. c.ServeJSON()
  562. return
  563. }
  564. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
  565. T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
  566. T_name := c.GetString("T_name")
  567. T_uuid := c.GetString("T_uuid") // 用户uuid
  568. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  569. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  570. T_deadline := c.GetString("T_deadline")
  571. T_scheme := c.GetString("T_scheme")
  572. T_collection := c.GetString("T_collection")
  573. T_reporting := c.GetString("T_reporting")
  574. T_delivery := c.GetString("T_delivery")
  575. T_project := c.GetString("T_project") // 项目 负责人UUID
  576. T_province := c.GetString("T_province") // 省
  577. T_city := c.GetString("T_city") // 市
  578. T_district := c.GetString("T_district") // 区
  579. T_province_code := c.GetString("T_province_code") // 省 code
  580. T_city_code := c.GetString("T_city_code") // 市 code
  581. T_district_code := c.GetString("T_district_code") // 区 code
  582. T_category := c.GetString("T_category") // 类别
  583. T_device_type := c.GetString("T_device_type") // 设备类型
  584. T_volume := c.GetString("T_volume") // 规格/容积
  585. T_verify_type := c.GetString("T_verify_type") // 验证类型
  586. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  587. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  588. T_report_number := c.GetString("T_report_number") // 报告编号
  589. T_report_type := c.GetString("T_report_type") // 报告类型
  590. // 查询信息采集信息
  591. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  592. if !is {
  593. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  594. c.ServeJSON()
  595. return
  596. }
  597. var_ := Task.Task{
  598. T_InfoCollection_id: T_InfoCollection_id,
  599. T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
  600. T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
  601. T_class: int(T_class_id),
  602. T_uuid: T_uuid,
  603. T_name: T_name,
  604. T_VerifyTemplate_class: T_VerifyTemplate_class,
  605. T_VerifyTemplate_id: T_VerifyTemplate_id,
  606. T_deadline: T_deadline,
  607. T_scheme: T_scheme,
  608. T_collection: T_collection,
  609. T_reporting: T_reporting,
  610. T_delivery: T_delivery,
  611. T_Show: 1,
  612. T_State: 1,
  613. T_project: T_project,
  614. T_province: T_province,
  615. T_city: T_city,
  616. T_district: T_district,
  617. T_province_code: T_province_code,
  618. T_city_code: T_city_code,
  619. T_district_code: T_district_code,
  620. T_category: T_category,
  621. T_device_type: T_device_type,
  622. T_volume: T_volume,
  623. T_verify_type: T_verify_type,
  624. T_subject_matter: T_subject_matter,
  625. T_temp_range: T_temp_range,
  626. T_report_number: T_report_number,
  627. T_report_type: T_report_type,
  628. }
  629. T_task_id, is := Task.Add_Task(var_)
  630. if !is {
  631. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  632. c.ServeJSON()
  633. return
  634. }
  635. NatsServer.Create_Local_Table(T_task_id)
  636. // 通知
  637. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  638. go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  639. go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  640. go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  641. go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  642. // 添加任务操作日志
  643. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "添加", var_)
  644. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "添加", var_)
  645. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  646. c.ServeJSON()
  647. return
  648. }
  649. // 接收信息采集
  650. func (c *TaskController) ReceiptInfoCollection() {
  651. // 验证登录 User_is, User_r
  652. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  653. if !User_is {
  654. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  655. c.ServeJSON()
  656. return
  657. }
  658. // 修改信息采集状态为已接收
  659. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  660. //T_status,_ := c.GetInt("T_status")
  661. infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  662. if !is {
  663. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  664. c.ServeJSON()
  665. return
  666. }
  667. if infoCollection.T_status != InfoCollection.InfoCollectionStatusSubmitted && infoCollection.T_status != InfoCollection.InfoCollectionStatusReceipt {
  668. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止接收!", InfoCollection.InfoCollectionStatusMap[infoCollection.T_status])}
  669. c.ServeJSON()
  670. return
  671. }
  672. //infoCollection.T_status = InfoCollection.InfoCollectionStatusReceipt
  673. //if len(infoCollection.T_end_time) == 0 {
  674. // infoCollection.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  675. // infoCollection.T_time_interval, _ = lib.MinutesDifference(infoCollection.T_start_time, infoCollection.T_end_time)
  676. //}
  677. //if !InfoCollection.Update_InfoCollection(infoCollection, "T_status", "T_end_time", "T_time_interval") {
  678. infoCollection.T_status = 3 // 已接收
  679. if !InfoCollection.Update_InfoCollection(infoCollection, "T_status") {
  680. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  681. c.ServeJSON()
  682. return
  683. }
  684. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "接收信息采集", infoCollection)
  685. //if T_status == InfoCollection.InfoCollectionStatusReturn{
  686. // // 通知 报告负责人审核
  687. // _, company_r := Account.Read_User_ByT_uuid(infoCollection.T_uuid)
  688. // System.Add_News(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name), "")
  689. // go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name))
  690. //
  691. //}
  692. // 修改任务管理实施方案开始时间
  693. //T_task_id := c.GetString("T_task_id")
  694. //task, is := Task.Read_Task(T_task_id)
  695. //if !is {
  696. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  697. // c.ServeJSON()
  698. // return
  699. //}
  700. // 添加任务操作日志
  701. //Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "接收信息采集", task)
  702. //System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "接收信息采集", task)
  703. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  704. c.ServeJSON()
  705. return
  706. }
  707. // 添加-
  708. func (c *TaskController) AddData_Tool() {
  709. T_uuid := "3e84dda9-9eec-42b9-9350-0894262fc8a1" // 用户uuid
  710. T_name := c.GetString("T_name")
  711. T_task_id := c.GetString("T_task_id")
  712. T_task_id = strings.ToLower(T_task_id)
  713. r, _ := Task.Read_Task(T_task_id)
  714. if r.T_collection_state == 2 {
  715. c.Data["json"] = lib.JSONS{Code: 200, Msg: "数据采集中..."}
  716. c.ServeJSON()
  717. return
  718. }
  719. if r.Id > 0 {
  720. // 同步1.0数据
  721. NatsServer.Sync1_TaskData(T_task_id)
  722. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  723. c.ServeJSON()
  724. return
  725. }
  726. dc := Device.DeviceClass{
  727. T_uuid: T_uuid,
  728. T_State: 1,
  729. }
  730. T_class_id, is := Device.Add_DeviceClass(dc)
  731. if !is {
  732. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  733. c.ServeJSON()
  734. return
  735. }
  736. var_ := Task.Task{
  737. T_task_id: T_task_id,
  738. T_class: int(T_class_id),
  739. T_uuid: T_uuid,
  740. T_name: T_name,
  741. T_Show: 1,
  742. T_State: 1,
  743. T_collection_state: 2,
  744. }
  745. _, is = Task.Add_Task_Tool(var_)
  746. if !is {
  747. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  748. c.ServeJSON()
  749. return
  750. }
  751. // 创建本地表
  752. NatsServer.Create_Local_Table(T_task_id)
  753. // 同步1.0数据
  754. NatsServer.Sync1_TaskData(T_task_id)
  755. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  756. c.ServeJSON()
  757. return
  758. }
  759. // 修改采集状态-
  760. func (c *TaskController) UpCollectionState() {
  761. // 验证登录 User_is, User_r
  762. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  763. if !User_is {
  764. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  765. c.ServeJSON()
  766. return
  767. }
  768. T_collection_state, _ := c.GetInt("T_collection_state")
  769. T_reason := c.GetString("T_reason") // 退回原因
  770. T_task_id := c.GetString("T_task_id")
  771. r, is := Task.Read_Task(T_task_id)
  772. if !is {
  773. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  774. c.ServeJSON()
  775. return
  776. }
  777. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  778. r.T_collection_state = T_collection_state
  779. clos := make([]string, 0)
  780. clos = append(clos, "T_collection_state")
  781. if T_collection_state == Task.TaskCollectionStateReturn {
  782. r.T_collection_return_times += 1
  783. clos = append(clos, "T_collection_return_times")
  784. }
  785. if T_collection_state == Task.TaskCollectionStateSubmitted ||
  786. T_collection_state == Task.TaskCollectionStateReturn ||
  787. T_collection_state == Task.TaskCollectionStatePass {
  788. // 添加已提交状态验证报告记录
  789. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, T_collection_state, T_reason, "")
  790. if err != nil {
  791. return
  792. }
  793. r.T_collection_audit_record = auditRecordJson
  794. clos = append(clos, "T_collection_audit_record")
  795. }
  796. if T_collection_state == Task.TaskCollectionStatePass {
  797. // 数据编辑审核通过时间为验证报告开始时间
  798. r.T_reporting_start_time = time.Now().Format("2006-01-02 15:04:05")
  799. clos = append(clos, "T_reporting_start_time")
  800. }
  801. if !Task.Update_Task(r, clos...) {
  802. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  803. c.ServeJSON()
  804. return
  805. }
  806. // 已退回(负责人)
  807. if T_collection_state == Task.TaskCollectionStateReturn {
  808. 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), "")
  809. 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))
  810. }
  811. // 添加任务操作日志
  812. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改采集状态", r)
  813. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改采集状态", r)
  814. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  815. c.ServeJSON()
  816. return
  817. }
  818. func (c *TaskController) UpDeliveryState() {
  819. // 验证登录 User_is, User_r
  820. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  821. if !User_is {
  822. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  823. c.ServeJSON()
  824. return
  825. }
  826. T_delivery_state, _ := c.GetInt("T_delivery_state")
  827. T_task_id := c.GetString("T_task_id")
  828. r, is := Task.Read_Task(T_task_id)
  829. if !is {
  830. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  831. c.ServeJSON()
  832. return
  833. }
  834. r.T_delivery_state = T_delivery_state
  835. if !Task.Update_Task(r, "T_delivery_state") {
  836. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  837. c.ServeJSON()
  838. return
  839. }
  840. // 添加任务操作日志
  841. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改交付审核状态", r)
  842. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改交付审核状态", r)
  843. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  844. c.ServeJSON()
  845. return
  846. }
  847. // 更新线上数据后台执行
  848. func (c *TaskDataController) TaskData_Up_TaskData_Back() {
  849. // 验证登录 User_is, User_r
  850. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  851. if !User_is {
  852. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  853. c.ServeJSON()
  854. return
  855. }
  856. T_task_id := c.GetString("T_task_id")
  857. r, is := Task.Read_Task(T_task_id)
  858. if !is {
  859. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  860. c.ServeJSON()
  861. return
  862. }
  863. // 通知 报告人员
  864. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  865. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  866. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name), "")
  867. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name))
  868. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  869. c.ServeJSON()
  870. return
  871. }
  872. // 修改-
  873. func (c *TaskController) Up() {
  874. // 验证登录 User_is, User_r
  875. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  876. if !User_is {
  877. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  878. c.ServeJSON()
  879. return
  880. }
  881. T_name := c.GetString("T_name")
  882. T_Show, T_Show_err := c.GetInt("T_Show")
  883. T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
  884. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  885. T_deadline := c.GetString("T_deadline")
  886. T_scheme := c.GetString("T_scheme")
  887. T_collection := c.GetString("T_collection")
  888. T_collection_state, _ := c.GetInt("T_collection_state")
  889. T_collection_signature := c.GetString("T_collection_signature") // 完成编辑签字图片
  890. T_reporting := c.GetString("T_reporting")
  891. T_delivery := c.GetString("T_delivery")
  892. T_record := c.GetString("T_record")
  893. T_doc1 := c.GetString("T_doc1")
  894. T_pdf1 := c.GetString("T_pdf1")
  895. T_doc2 := c.GetString("T_doc2")
  896. T_pdf2 := c.GetString("T_pdf2")
  897. T_doc3 := c.GetString("T_doc3")
  898. T_pdf3 := c.GetString("T_pdf3")
  899. T_pdf4 := c.GetString("T_pdf4") // 验证标识
  900. T_VerifyDeviceDataStartTime := c.GetString("T_VerifyDeviceDataStartTime") // 验证设备数据开始时间
  901. T_VerifyDeviceDataEndTime := c.GetString("T_VerifyDeviceDataEndTime") // 验证设备数据开始时间
  902. T_BindDeviceDataStartTime := c.GetString("T_BindDeviceDataStartTime") // 绑定设备数据开始时间
  903. T_BindDeviceDataEndTime := c.GetString("T_BindDeviceDataEndTime") // 绑定设备数据结束时间
  904. T_sn := c.GetString("T_sn") // T_sn
  905. T_CalibrationExpirationTime := c.GetString("T_CalibrationExpirationTime") // 校准到期时间
  906. T_project := c.GetString("T_project") // 项目 负责人UUID
  907. T_province := c.GetString("T_province") // 省
  908. T_city := c.GetString("T_city") // 市
  909. T_district := c.GetString("T_district") // 区
  910. T_province_code := c.GetString("T_province_code") // 省 code
  911. T_city_code := c.GetString("T_city_code") // 市 code
  912. T_district_code := c.GetString("T_district_code") // 区 code
  913. T_category := c.GetString("T_category") // 类别
  914. T_device_type := c.GetString("T_device_type") // 设备类型
  915. T_volume := c.GetString("T_volume") // 规格/容积
  916. T_verify_type := c.GetString("T_verify_type") // 验证类型
  917. T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
  918. T_temp_range := c.GetString("T_temp_range") // 验证温度范围
  919. T_report_number := c.GetString("T_report_number") // 报告编号
  920. T_report_type := c.GetString("T_report_type") // 报告编号
  921. T_task_id := c.GetString("T_task_id")
  922. r, is := Task.Read_Task(T_task_id)
  923. if !is {
  924. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  925. c.ServeJSON()
  926. return
  927. }
  928. // .......
  929. clos := make([]string, 0)
  930. if len(T_name) > 0 {
  931. r.T_name = T_name
  932. clos = append(clos, "T_name")
  933. }
  934. if T_Show_err == nil {
  935. r.T_Show = T_Show
  936. clos = append(clos, "T_Show")
  937. }
  938. if len(T_VerifyTemplate_class) > 0 {
  939. r.T_VerifyTemplate_class = T_VerifyTemplate_class
  940. clos = append(clos, "T_VerifyTemplate_class")
  941. }
  942. if len(T_VerifyTemplate_id) > 0 {
  943. r.T_VerifyTemplate_id = T_VerifyTemplate_id
  944. clos = append(clos, "T_VerifyTemplate_id")
  945. }
  946. if len(T_deadline) > 0 {
  947. r.T_deadline = T_deadline
  948. clos = append(clos, "T_deadline")
  949. }
  950. if len(T_scheme) > 0 {
  951. r.T_scheme = T_scheme
  952. clos = append(clos, "T_scheme")
  953. }
  954. if len(T_collection) > 0 {
  955. r.T_collection = T_collection
  956. clos = append(clos, "T_collection")
  957. }
  958. if len(T_reporting) > 0 {
  959. r.T_reporting = T_reporting
  960. clos = append(clos, "T_reporting")
  961. }
  962. if len(T_delivery) > 0 {
  963. r.T_delivery = T_delivery
  964. clos = append(clos, "T_delivery")
  965. }
  966. if len(T_record) > 0 {
  967. r.T_record = T_record
  968. clos = append(clos, "T_record")
  969. }
  970. // 完成编辑后设置实施结束时间
  971. if T_collection_state == 4 {
  972. r.T_collection_state = T_collection_state
  973. clos = append(clos, "T_collection_state")
  974. r.T_collection_signature = T_collection_signature
  975. clos = append(clos, "T_collection_signature")
  976. r.T_collection_end_time = time.Now().Format("2006-01-02 15:04:05")
  977. clos = append(clos, "T_collection_end_time")
  978. if len(r.T_collection_start_time) > 0 {
  979. r.T_collection_time_interval, _ = lib.MinutesDifference(r.T_collection_start_time, r.T_collection_end_time)
  980. // 扣除暂停时间
  981. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 1)
  982. if Task_Compute > 0 {
  983. r.T_collection_time_interval -= float64(Task_Compute)
  984. }
  985. clos = append(clos, "T_collection_time_interval")
  986. // 所需时间 > 超时时间
  987. if r.T_collection_time_interval > Task.TaskCollectionTimeLimit && len(r.T_report_type) > 0 {
  988. r.T_collection_overtime = r.T_collection_time_interval - Task.TaskCollectionTimeLimit // 超时时间
  989. clos = append(clos, "T_collection_overtime")
  990. }
  991. // 通知 报告人员
  992. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  993. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name), "")
  994. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name))
  995. }
  996. // 添加已提交状态数据编辑记录
  997. auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, r.T_collection_state, "", "")
  998. if err == nil {
  999. r.T_collection_audit_record = auditRecordJson
  1000. clos = append(clos, "T_collection_audit_record")
  1001. }
  1002. }
  1003. if len(T_doc1) > 0 {
  1004. r.T_doc1 = T_doc1
  1005. clos = append(clos, "T_doc1")
  1006. }
  1007. // 验证报告内容T_pdf1,上传后将 当前任务 验证方案 标志 为 5 (0未完成 1已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交)
  1008. // 上传后设置方案结束时间,计算所需时间和超时时间
  1009. if len(T_pdf1) > 0 {
  1010. r.T_pdf1 = T_pdf1
  1011. clos = append(clos, "T_pdf1")
  1012. //r.T_pdf1_watermark = GetWatermarkPdf(r,T_pdf1,"T_pdf1")
  1013. //clos = append(clos, "T_pdf1_watermark")
  1014. go GetWatermarkPdf(r, T_pdf1, "T_pdf1")
  1015. r.T_scheme_state = 5
  1016. clos = append(clos, "T_scheme_state")
  1017. // 添加已提交状态验证方案记录
  1018. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, "", User_r.T_uuid, r.T_scheme_state, "", "")
  1019. if err != nil {
  1020. return
  1021. }
  1022. r.T_scheme_audit_record = auditRecordJson
  1023. clos = append(clos, "T_scheme_audit_record")
  1024. r.T_scheme_end_time = time.Now().Format("2006-01-02 15:04:05")
  1025. clos = append(clos, "T_scheme_end_time")
  1026. r.T_scheme_time_interval, _ = lib.MinutesDifference(r.T_scheme_start_time, r.T_scheme_end_time)
  1027. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 0)
  1028. if Task_Compute > 0 {
  1029. r.T_scheme_time_interval -= float64(Task_Compute)
  1030. }
  1031. clos = append(clos, "T_scheme_time_interval")
  1032. // 所需时间 > 超时时间
  1033. if r.T_scheme_time_interval > Task.TaskSchemeTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1034. r.T_scheme_overtime = r.T_scheme_time_interval - Task.TaskSchemeTimeLimit[r.T_report_type] // 超时时间
  1035. if Task.TaskSchemeTimeLimit[r.T_report_type] == 0 {
  1036. r.T_scheme_overtime = 0
  1037. }
  1038. clos = append(clos, "T_scheme_overtime")
  1039. }
  1040. // 通知 实施人员进场
  1041. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1042. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name), "")
  1043. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name))
  1044. }
  1045. if len(T_doc2) > 0 {
  1046. r.T_doc2 = T_doc2
  1047. clos = append(clos, "T_doc2")
  1048. }
  1049. // 验证报告内容T_pdf2 ,上传后将 当前任务 报告编写 标志 为 1
  1050. // 上传后设置报告结束时间,计算所需时间和超时时间
  1051. if len(T_pdf2) > 0 {
  1052. r.T_pdf2 = T_pdf2
  1053. clos = append(clos, "T_pdf2")
  1054. //r.T_pdf2_watermark = GetWatermarkPdf(T_pdf2,"T_pdf1")
  1055. //clos = append(clos, "T_pdf2_watermark")
  1056. go GetWatermarkPdf(r, T_pdf2, "T_pdf2")
  1057. r.T_reporting_state = 5
  1058. clos = append(clos, "T_reporting_state")
  1059. // 添加已提交状态验证报告记录
  1060. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, "", User_r.T_uuid, r.T_reporting_state, "", "")
  1061. if err == nil {
  1062. r.T_reporting_audit_record = auditRecordJson
  1063. clos = append(clos, "T_reporting_audit_record")
  1064. r.T_reporting_end_time = time.Now().Format("2006-01-02 15:04:05")
  1065. clos = append(clos, "T_reporting_end_time")
  1066. if len(r.T_reporting_start_time) > 0 {
  1067. r.T_reporting_time_interval, _ = lib.MinutesDifference(r.T_reporting_start_time, r.T_reporting_end_time)
  1068. clos = append(clos, "T_reporting_time_interval")
  1069. // 扣除暂停时间
  1070. Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 2)
  1071. if Task_Compute > 0 {
  1072. r.T_reporting_time_interval -= float64(Task_Compute)
  1073. }
  1074. clos = append(clos, "T_reporting_time_interval")
  1075. // 所需时间 > 超时时间
  1076. if r.T_reporting_time_interval > Task.TaskReportingTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
  1077. r.T_reporting_overtime = r.T_reporting_time_interval - Task.TaskReportingTimeLimit[r.T_report_type] // 超时时间
  1078. if Task.TaskReportingTimeLimit[r.T_report_type] == 0 {
  1079. r.T_reporting_overtime = 0
  1080. }
  1081. clos = append(clos, "T_reporting_overtime")
  1082. }
  1083. }
  1084. }
  1085. // 通知 报告人员
  1086. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1087. System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name), "")
  1088. go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name))
  1089. }
  1090. if len(T_doc3) > 0 {
  1091. r.T_doc3 = T_doc3
  1092. clos = append(clos, "T_doc3")
  1093. }
  1094. if len(T_pdf3) > 0 {
  1095. r.T_pdf3 = T_pdf3
  1096. clos = append(clos, "T_pdf3")
  1097. }
  1098. // 验证标识内容T_pdf4 ,上传后将 当前任务 验证标识 标志 为 1
  1099. if len(T_pdf4) > 0 {
  1100. r.T_pdf4 = T_pdf4
  1101. clos = append(clos, "T_pdf4")
  1102. r.T_marking_state = 1
  1103. clos = append(clos, "T_marking_state")
  1104. }
  1105. if len(T_VerifyDeviceDataStartTime) > 0 {
  1106. r.T_VerifyDeviceDataStartTime = T_VerifyDeviceDataStartTime
  1107. clos = append(clos, "T_VerifyDeviceDataStartTime")
  1108. }
  1109. if len(T_VerifyDeviceDataEndTime) > 0 {
  1110. r.T_VerifyDeviceDataEndTime = T_VerifyDeviceDataEndTime
  1111. clos = append(clos, "T_VerifyDeviceDataEndTime")
  1112. }
  1113. if len(T_BindDeviceDataStartTime) > 0 {
  1114. r.T_BindDeviceDataStartTime = T_BindDeviceDataStartTime
  1115. clos = append(clos, "T_BindDeviceDataStartTime")
  1116. }
  1117. if len(T_BindDeviceDataEndTime) > 0 {
  1118. r.T_BindDeviceDataEndTime = T_BindDeviceDataEndTime
  1119. clos = append(clos, "T_BindDeviceDataEndTime")
  1120. }
  1121. if len(T_sn) > 0 {
  1122. T_sn = strings.TrimSpace(T_sn)
  1123. r.T_sn = T_sn
  1124. clos = append(clos, "T_sn")
  1125. }
  1126. if len(T_CalibrationExpirationTime) > 0 {
  1127. r.T_CalibrationExpirationTime = T_CalibrationExpirationTime
  1128. clos = append(clos, "T_CalibrationExpirationTime")
  1129. }
  1130. // 从3.0获取校准时间
  1131. if len(T_sn) > 0 && len(T_CalibrationExpirationTime) == 0 {
  1132. go func(r Task.Task,T_sn ,T_CalibrationExpirationTime string) {
  1133. NatsServer.Cold_UpdateDevice_CalibrationTime(T_sn, T_CalibrationExpirationTime)
  1134. device, err := NatsServer.Cold_ReadDeviceByT_sn(T_sn)
  1135. if err == nil {
  1136. if !device.T_CalibrationTime.IsZero() {
  1137. r.T_CalibrationExpirationTime = device.T_CalibrationTime.Format("2006-01-02")
  1138. clos = append(clos, "T_CalibrationExpirationTime")
  1139. Task.Update_Task(r, "T_CalibrationExpirationTime")
  1140. }
  1141. }
  1142. }(r,T_sn,T_CalibrationExpirationTime)
  1143. }
  1144. if len(T_project) > 0 {
  1145. r.T_project = T_project
  1146. clos = append(clos, "T_project")
  1147. }
  1148. if len(T_province) > 0 {
  1149. r.T_province = T_province
  1150. clos = append(clos, "T_province")
  1151. }
  1152. if len(T_city) > 0 {
  1153. r.T_city = T_city
  1154. clos = append(clos, "T_city")
  1155. }
  1156. if len(T_district) > 0 {
  1157. r.T_district = T_district
  1158. clos = append(clos, "T_district")
  1159. }
  1160. if len(T_province_code) > 0 {
  1161. r.T_province_code = T_province_code
  1162. clos = append(clos, "T_province_code")
  1163. }
  1164. if len(T_city_code) > 0 {
  1165. r.T_city_code = T_city_code
  1166. clos = append(clos, "T_city_code")
  1167. }
  1168. if len(T_district_code) > 0 {
  1169. r.T_district_code = T_district_code
  1170. clos = append(clos, "T_district_code")
  1171. }
  1172. if len(T_category) > 0 {
  1173. r.T_category = T_category
  1174. clos = append(clos, "T_category")
  1175. }
  1176. if len(T_device_type) > 0 {
  1177. r.T_device_type = T_device_type
  1178. clos = append(clos, "T_device_type")
  1179. }
  1180. if len(T_volume) > 0 {
  1181. r.T_volume = T_volume
  1182. clos = append(clos, "T_volume")
  1183. }
  1184. if len(T_verify_type) > 0 {
  1185. r.T_verify_type = T_verify_type
  1186. clos = append(clos, "T_verify_type")
  1187. }
  1188. if len(T_subject_matter) > 0 {
  1189. r.T_subject_matter = T_subject_matter
  1190. clos = append(clos, "T_subject_matter")
  1191. }
  1192. if len(T_temp_range) > 0 {
  1193. r.T_temp_range = T_temp_range
  1194. clos = append(clos, "T_temp_range")
  1195. }
  1196. if len(T_report_number) > 0 {
  1197. r.T_report_number = T_report_number
  1198. clos = append(clos, "T_report_number")
  1199. }
  1200. if len(T_report_type) > 0 {
  1201. r.T_report_type = T_report_type
  1202. clos = append(clos, "T_report_type")
  1203. }
  1204. if !Task.Update_Task(r, clos...) {
  1205. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1206. c.ServeJSON()
  1207. return
  1208. }
  1209. // 添加任务操作日志
  1210. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改", r)
  1211. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改", r)
  1212. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1213. c.ServeJSON()
  1214. return
  1215. }
  1216. // 修改验证方案状态
  1217. func (c *TaskController) UpSchemeState() {
  1218. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1219. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1220. if !Admin_is && !User_is {
  1221. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1222. c.ServeJSON()
  1223. return
  1224. }
  1225. operate_uuid := ""
  1226. if Admin_is {
  1227. operate_uuid = Admin_r.T_uuid
  1228. }
  1229. if User_is {
  1230. operate_uuid = User_r.T_uuid
  1231. }
  1232. T_scheme_state, _ := c.GetInt("T_scheme_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1233. T_reason := c.GetString("T_reason") // 退回原因
  1234. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1235. T_task_id := c.GetString("T_task_id")
  1236. r, is := Task.Read_Task(T_task_id)
  1237. if !is {
  1238. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1239. c.ServeJSON()
  1240. return
  1241. }
  1242. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1243. clos := make([]string, 0)
  1244. if T_scheme_state > 0 {
  1245. r.T_scheme_state = T_scheme_state
  1246. clos = append(clos, "T_scheme_state")
  1247. }
  1248. if len(T_signature) > 0 {
  1249. r.T_scheme_signature = T_signature
  1250. clos = append(clos, "T_scheme_signature")
  1251. }
  1252. if T_scheme_state == Task.TaskSchemeStateClientReturn || T_scheme_state == Task.TaskSchemeStateReturn {
  1253. r.T_scheme_return_times += 1
  1254. clos = append(clos, "T_scheme_return_times")
  1255. // 客户退回时新增驳回次数和驳回记录
  1256. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  1257. r.T_reject_times += 1
  1258. var rejectRecordList []Task.AuditRecord
  1259. if len(r.T_reject_record) > 0 {
  1260. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1261. if err != nil {
  1262. logs.Error("JSON 反序列化失败:", err)
  1263. return
  1264. }
  1265. }
  1266. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1267. T_uuid: User_r.T_uuid,
  1268. T_state: T_scheme_state,
  1269. T_reason: T_reason,
  1270. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1271. T_type: "scheme",
  1272. })
  1273. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1274. if err != nil {
  1275. logs.Error("JSON 反序列化失败:", err)
  1276. return
  1277. }
  1278. r.T_reject_record = string(rejectRecordJson)
  1279. clos = append(clos, "T_reject_times")
  1280. clos = append(clos, "T_reject_record")
  1281. }
  1282. }
  1283. auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_scheme_state, T_reason, "")
  1284. if err != nil {
  1285. return
  1286. }
  1287. r.T_scheme_audit_record = auditRecordJson
  1288. clos = append(clos, "T_scheme_audit_record")
  1289. if !Task.Update_Task(r, clos...) {
  1290. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1291. c.ServeJSON()
  1292. return
  1293. }
  1294. //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1295. // 已提交
  1296. if T_scheme_state == Task.TaskSchemeStateSubmitted {
  1297. System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  1298. go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
  1299. }
  1300. // 已通过
  1301. if T_scheme_state == Task.TaskSchemeStatePass {
  1302. infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1303. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
  1304. go wx.WxSend(infoCollection.T_submit_uuid, 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.TaskSchemeStateReturn {
  1308. 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), "")
  1309. 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))
  1310. }
  1311. // 已退回(客户)
  1312. if T_scheme_state == Task.TaskSchemeStateClientReturn {
  1313. 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), "")
  1314. 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))
  1315. 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), "")
  1316. 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))
  1317. 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))
  1318. }
  1319. // 添加任务操作日志
  1320. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证方案状态", r)
  1321. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证方案状态", r)
  1322. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1323. c.ServeJSON()
  1324. return
  1325. }
  1326. // 修改验证报告状态
  1327. func (c *TaskController) UpReportingState() {
  1328. Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1329. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1330. if !Admin_is && !User_is {
  1331. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1332. c.ServeJSON()
  1333. return
  1334. }
  1335. operate_uuid := ""
  1336. if Admin_is {
  1337. operate_uuid = Admin_r.T_uuid
  1338. }
  1339. if User_is {
  1340. operate_uuid = User_r.T_uuid
  1341. }
  1342. T_reporting_state, _ := c.GetInt("T_reporting_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
  1343. T_reason := c.GetString("T_reason") // 退回原因
  1344. T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
  1345. T_task_id := c.GetString("T_task_id")
  1346. r, is := Task.Read_Task(T_task_id)
  1347. if !is {
  1348. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1349. c.ServeJSON()
  1350. return
  1351. }
  1352. //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  1353. clos := make([]string, 0)
  1354. if T_reporting_state > 0 {
  1355. r.T_reporting_state = T_reporting_state
  1356. clos = append(clos, "T_reporting_state")
  1357. }
  1358. if len(T_signature) > 0 {
  1359. r.T_reporting_signature = T_signature
  1360. clos = append(clos, "T_reporting_signature")
  1361. }
  1362. if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
  1363. r.T_reporting_return_times += 1
  1364. clos = append(clos, "T_reporting_return_times")
  1365. // 客户退回时新增驳回次数和驳回记录
  1366. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1367. r.T_reject_times += 1
  1368. var rejectRecordList []Task.AuditRecord
  1369. if len(r.T_reject_record) > 0 {
  1370. err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
  1371. if err != nil {
  1372. logs.Error("JSON 反序列化失败:", err)
  1373. return
  1374. }
  1375. }
  1376. rejectRecordList = append(rejectRecordList, Task.AuditRecord{
  1377. T_uuid: User_r.T_uuid,
  1378. T_state: T_reporting_state,
  1379. T_reason: T_reason,
  1380. T_time: time.Now().Format("2006-01-02 15:04:05"),
  1381. T_type: "reporting",
  1382. })
  1383. rejectRecordJson, err := json.Marshal(rejectRecordList)
  1384. if err != nil {
  1385. logs.Error("JSON 反序列化失败:", err)
  1386. return
  1387. }
  1388. r.T_reject_record = string(rejectRecordJson)
  1389. clos = append(clos, "T_reject_times")
  1390. clos = append(clos, "T_reject_record")
  1391. }
  1392. }
  1393. auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
  1394. if err != nil {
  1395. return
  1396. }
  1397. r.T_reporting_audit_record = auditRecordJson
  1398. clos = append(clos, "T_reporting_audit_record")
  1399. // 查询信息采集信息
  1400. infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
  1401. if !is {
  1402. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  1403. c.ServeJSON()
  1404. return
  1405. }
  1406. // 验证报告客户审核通过后设置结束时间
  1407. if T_reporting_state == Task.TaskReportingStateClientPass {
  1408. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  1409. r.T_time_interval, err = lib.MinutesDifference(infoCollection.T_start_time, r.T_end_time)
  1410. if err != nil {
  1411. logs.Error("UpReportingState:", err.Error())
  1412. }
  1413. clos = append(clos, "T_end_time")
  1414. clos = append(clos, "T_time_interval")
  1415. }
  1416. if !Task.Update_Task(r, clos...) {
  1417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  1418. c.ServeJSON()
  1419. return
  1420. }
  1421. // 已通过
  1422. if T_reporting_state == Task.TaskReportingStatePass {
  1423. System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1424. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
  1425. System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1426. go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
  1427. }
  1428. // 已退回
  1429. if T_reporting_state == Task.TaskReportingStateReturn {
  1430. 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), "")
  1431. 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))
  1432. }
  1433. // 已通过(客户) 通知销售
  1434. if T_reporting_state == Task.TaskReportingStateClientPass {
  1435. go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】 %s,请尽快安排客户回款", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
  1436. }
  1437. if T_reporting_state == Task.TaskReportingStateClientReturn {
  1438. 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), "")
  1439. 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))
  1440. 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), "")
  1441. 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))
  1442. 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), "")
  1443. 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))
  1444. //System.Add_News(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
  1445. //go wx.WxSend(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
  1446. System.Add_News(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state],T_reason), "")
  1447. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state],T_reason))
  1448. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state],T_reason))
  1449. }
  1450. // 添加任务操作日志
  1451. Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证报告状态", r)
  1452. System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证报告状态", r)
  1453. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1454. c.ServeJSON()
  1455. return
  1456. }
  1457. // 进场 改成 方案开始
  1458. func (c *TaskController) EnterArea() {
  1459. // 验证登录 User_is, User_r
  1460. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1461. if !User_is {
  1462. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1463. c.ServeJSON()
  1464. return
  1465. }
  1466. T_task_id := c.GetString("T_task_id")
  1467. r, is := Task.Read_Task(T_task_id)
  1468. if !is {
  1469. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1470. c.ServeJSON()
  1471. return
  1472. }
  1473. // 方案开始
  1474. if len(r.T_scheme_start_time) == 0 {
  1475. r.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
  1476. Task.Update_Task(r,"T_scheme_start_time")
  1477. }
  1478. // 添加任务操作日志
  1479. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "方案开始", r)
  1480. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "方案开始", r)
  1481. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1482. c.ServeJSON()
  1483. return
  1484. }
  1485. // 开始验证
  1486. func (c *TaskController) StartVerify() {
  1487. // 验证登录 User_is, User_r
  1488. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1489. if !User_is {
  1490. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1491. c.ServeJSON()
  1492. return
  1493. }
  1494. T_task_id := c.GetString("T_task_id")
  1495. T_time := c.GetString("T_time") // 进场时间
  1496. r, is := Task.Read_Task(T_task_id)
  1497. if !is {
  1498. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1499. c.ServeJSON()
  1500. return
  1501. }
  1502. if len(r.T_collection_start_time) == 0 {
  1503. r.T_collection_start_time = T_time
  1504. if !Task.Update_Task(r, "T_collection_start_time") {
  1505. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
  1506. c.ServeJSON()
  1507. return
  1508. }
  1509. // 添加任务操作日志
  1510. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
  1511. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
  1512. }
  1513. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1514. c.ServeJSON()
  1515. return
  1516. }
  1517. // 删除-
  1518. func (c *TaskController) Del() {
  1519. // 验证登录 User_is, User_r
  1520. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1521. if !User_is {
  1522. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1523. c.ServeJSON()
  1524. return
  1525. }
  1526. T_task_id := c.GetString("T_task_id")
  1527. if r, is := Task.Read_Task(T_task_id); is {
  1528. if !Task.Delete_Task(r) {
  1529. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  1530. c.ServeJSON()
  1531. return
  1532. }
  1533. // 添加任务操作日志
  1534. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
  1535. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
  1536. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1537. c.ServeJSON()
  1538. return
  1539. }
  1540. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1541. c.ServeJSON()
  1542. return
  1543. }
  1544. // 列表 -
  1545. func (c *TaskController) Logs_List() {
  1546. // 验证登录 User_is, User_r
  1547. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1548. if !User_is {
  1549. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1550. c.ServeJSON()
  1551. return
  1552. }
  1553. var r_jsons lib.R_JSONS
  1554. page, _ := c.GetInt("page")
  1555. if page < 1 {
  1556. page = 1
  1557. }
  1558. page_z, _ := c.GetInt("page_z")
  1559. if page_z < 1 {
  1560. page_z = conf.Page_size
  1561. }
  1562. T_task_id := c.GetString("T_task_id")
  1563. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1564. var cnt int
  1565. List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
  1566. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1567. r_jsons.List = List
  1568. r_jsons.Page = page
  1569. r_jsons.Page_size = int(page_size)
  1570. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1571. r_jsons.Num = cnt
  1572. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1573. c.ServeJSON()
  1574. return
  1575. }
  1576. // 查询图片生成状态
  1577. func (c *TaskController) DeviceData_JPGState() {
  1578. T_task_id := c.GetString("T_task_id")
  1579. T_remark := c.GetString("T_remark")
  1580. jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
  1581. if !is {
  1582. c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
  1583. c.ServeJSON()
  1584. return
  1585. }
  1586. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
  1587. c.ServeJSON()
  1588. return
  1589. }
  1590. // 生成温度图片
  1591. func (c *TaskController) DeviceData_JPG() {
  1592. StartTime := c.GetString("StartTime")
  1593. if len(StartTime) > 0 {
  1594. _, ok := lib.TimeStrToTime(StartTime)
  1595. if !ok {
  1596. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1597. c.ServeJSON()
  1598. return
  1599. }
  1600. }
  1601. EndTime := c.GetString("EndTime")
  1602. if len(EndTime) > 0 {
  1603. _, ok := lib.TimeStrToTime(EndTime)
  1604. if !ok {
  1605. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  1606. c.ServeJSON()
  1607. return
  1608. }
  1609. } else {
  1610. EndTime = time.Now().Format("2006-01-02 15:04:05")
  1611. }
  1612. T_remark := c.GetString("T_remark")
  1613. TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
  1614. TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
  1615. if TemperatureMin == 0 {
  1616. TemperatureMin = 2
  1617. }
  1618. if TemperatureMax == 0 {
  1619. TemperatureMax = 8
  1620. }
  1621. T_task_id := c.GetString("T_task_id")
  1622. Task_r, is := Task.Read_Task(T_task_id)
  1623. if !is {
  1624. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  1625. c.ServeJSON()
  1626. return
  1627. }
  1628. if Task_r.T_collection_state == 2 {
  1629. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
  1630. c.ServeJSON()
  1631. return
  1632. }
  1633. deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
  1634. if !is {
  1635. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  1636. c.ServeJSON()
  1637. return
  1638. }
  1639. Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
  1640. // 生成图片
  1641. go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
  1642. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1643. c.ServeJSON()
  1644. return
  1645. }
  1646. // SyncInfoCollection 同步信息采集表
  1647. func (c *TaskController) SyncInfoCollection() {
  1648. T_task_id := c.GetString("T_task_id")
  1649. T_source, _ := c.GetInt("T_source")
  1650. task, is := Task.Read_Task(T_task_id)
  1651. if !is {
  1652. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1653. c.ServeJSON()
  1654. return
  1655. }
  1656. // 获取信息采集表模版信息
  1657. InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
  1658. InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
  1659. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  1660. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
  1661. InfoCollectionDataMap := make(map[string]string)
  1662. for _, data := range InfoCollection_Data {
  1663. InfoCollectionDataMap[data.T_name] = data.T_value
  1664. }
  1665. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  1666. for _, v := range Data {
  1667. if len(v.T_value) > 0 {
  1668. continue
  1669. }
  1670. if InfoCollectionDataMap[v.T_name] == "" {
  1671. continue
  1672. }
  1673. val := VerifyTemplate.VerifyTemplateMapData{
  1674. T_source: T_source,
  1675. T_task_id: task.T_task_id,
  1676. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  1677. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  1678. T_flow_sort: v.T_flow_sort,
  1679. T_max_time: v.T_max_time,
  1680. T_min_time: v.T_min_time,
  1681. T_value: InfoCollectionDataMap[v.T_name],
  1682. }
  1683. MapDataList = append(MapDataList, val)
  1684. }
  1685. var ids []int64
  1686. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  1687. if !is {
  1688. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  1689. c.ServeJSON()
  1690. return
  1691. }
  1692. c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
  1693. c.ServeJSON()
  1694. return
  1695. }
  1696. // 退回记录列表
  1697. func (c *TaskController) AuditRecordList() {
  1698. // 验证登录 User_is, User_r
  1699. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1700. if !User_is {
  1701. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  1702. c.ServeJSON()
  1703. return
  1704. }
  1705. T_task_id := c.GetString("T_task_id")
  1706. T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
  1707. //T_task 驳回记录
  1708. //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1709. //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
  1710. //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
  1711. T_state, _ := c.GetInt("T_state") // -1 获取全部
  1712. r, is := Task.Read_Task(T_task_id)
  1713. if !is {
  1714. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  1715. c.ServeJSON()
  1716. return
  1717. }
  1718. var auditRecordList []Task.AuditRecord
  1719. switch T_type {
  1720. case "T_task":
  1721. T_state = -1
  1722. if len(r.T_reject_record) > 0 {
  1723. err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
  1724. if err != nil {
  1725. logs.Error("JSON 反序列化失败:", err)
  1726. return
  1727. }
  1728. }
  1729. case "T_scheme":
  1730. if len(r.T_scheme_audit_record) > 0 {
  1731. err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
  1732. if err != nil {
  1733. logs.Error("JSON 反序列化失败:", err)
  1734. return
  1735. }
  1736. }
  1737. case "T_collection":
  1738. if len(r.T_collection_audit_record) > 0 {
  1739. err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
  1740. if err != nil {
  1741. logs.Error("JSON 反序列化失败:", err)
  1742. return
  1743. }
  1744. }
  1745. case "T_reporting":
  1746. if len(r.T_reporting_audit_record) > 0 {
  1747. err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
  1748. if err != nil {
  1749. logs.Error("JSON 反序列化失败:", err)
  1750. return
  1751. }
  1752. }
  1753. }
  1754. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  1755. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  1756. var auditRecordList2 []Task.AuditRecord
  1757. // 返回全部
  1758. if T_state == -1 {
  1759. for i := 0; i < len(auditRecordList); i++ {
  1760. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1761. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1762. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1763. }
  1764. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1765. c.ServeJSON()
  1766. return
  1767. }
  1768. if T_state == -2 {
  1769. for i := 0; i < len(auditRecordList); i++ {
  1770. if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
  1771. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1772. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1773. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1774. }
  1775. }
  1776. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1777. c.ServeJSON()
  1778. return
  1779. }
  1780. for i := 0; i < len(auditRecordList); i++ {
  1781. if auditRecordList[i].T_state == T_state {
  1782. auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
  1783. auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
  1784. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  1785. }
  1786. }
  1787. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  1788. c.ServeJSON()
  1789. return
  1790. }
  1791. // 存档生成图片
  1792. func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
  1793. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1794. State: 1,
  1795. Msg: "图片生成中",
  1796. Url: "",
  1797. })
  1798. msg := ""
  1799. state := 2
  1800. url := ""
  1801. if TemperatureMin == 0 {
  1802. TemperatureMin = 2
  1803. }
  1804. if TemperatureMax == 0 {
  1805. TemperatureMax = 8
  1806. }
  1807. var ymin, ymax float64
  1808. var xminT, xmaxT time.Time
  1809. if len(deviceList) > 0 {
  1810. ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
  1811. }
  1812. // 创建一个新的绘图
  1813. p := plot.New()
  1814. // 设置绘图标题和标签
  1815. p.Title.Text = "温度折线图"
  1816. //p.Legend.ThumbnailWidth = 5 * vg.Inch
  1817. p.X.Label.Text = "时间"
  1818. p.Y.Label.Text = "温度"
  1819. var chData = make(chan int, 10)
  1820. var jobGroup sync.WaitGroup
  1821. var device = make([]Device.DeviceCount, len(deviceList))
  1822. // 创建温度线
  1823. for i := 0; i < len(deviceList); i++ {
  1824. chData <- 1
  1825. jobGroup.Add(1)
  1826. go func(index int) {
  1827. //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
  1828. defer func() {
  1829. <-chData // 完成时chan取出1个
  1830. jobGroup.Done() // 完成时将等待组值减1
  1831. }()
  1832. sn, id := deviceList[index].T_sn, deviceList[index].T_id
  1833. ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
  1834. if ymin > ymin_ {
  1835. ymin = ymin_
  1836. }
  1837. if ymax < ymax_ {
  1838. ymax = ymax_
  1839. }
  1840. if xminT.After(minTime_) && !minTime_.IsZero() {
  1841. xminT = minTime_
  1842. }
  1843. if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
  1844. xmaxT = maxTime_
  1845. }
  1846. r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
  1847. device[index] = Device.DeviceCount{
  1848. T_id: id,
  1849. Num: r_maps_num,
  1850. }
  1851. if r_maps_num == 0 {
  1852. return
  1853. }
  1854. pts := make(plotter.XYs, len(r_maps))
  1855. for j, d := range r_maps {
  1856. t, _ := lib.TimeStrToTime(d.T_time)
  1857. pts[j].X = float64(t.Unix())
  1858. pts[j].Y = float64(d.T_t)
  1859. }
  1860. line, err := plotter.NewLine(pts)
  1861. if err != nil {
  1862. return
  1863. }
  1864. line.Color = randomColor(index)
  1865. p.Add(line)
  1866. }(i)
  1867. }
  1868. jobGroup.Wait()
  1869. xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
  1870. // 添加最高,最低标准线 用红色虚线标识
  1871. p.Add(horizontalLine(xmin, xmax, TemperatureMin))
  1872. p.Add(horizontalLine(xmin, xmax, TemperatureMax))
  1873. if ymax < 8 {
  1874. ymax = 8
  1875. }
  1876. if ymin > 0 {
  1877. ymin = 0
  1878. }
  1879. p.Y.Min, p.Y.Max = ymin, ymax
  1880. p.X.Min, p.X.Max = xmin, xmax
  1881. p.Y.Tick.Marker = commaTicks{}
  1882. //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
  1883. p.X.Tick.Marker = timeTicks{}
  1884. p.X.Tick.Label.Rotation = math.Pi / 5
  1885. p.X.Tick.Label.YAlign = draw.YCenter
  1886. p.X.Tick.Label.XAlign = draw.XRight
  1887. filename := "jpg" + time.Now().Format("20060102150405")
  1888. // 保存文件
  1889. if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
  1890. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1891. State: 3,
  1892. Msg: "图片生成失败",
  1893. Url: url,
  1894. })
  1895. logs.Error(lib.FuncName(), "生成图片失败", err)
  1896. return
  1897. }
  1898. if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
  1899. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1900. State: 3,
  1901. Msg: "图片上传七牛云失败",
  1902. Url: url,
  1903. })
  1904. logs.Error(lib.FuncName(), "上传七牛云失败")
  1905. return
  1906. }
  1907. //删除目录
  1908. os.Remove("ofile/" + filename + ".jpg")
  1909. msg = "图片生成成功"
  1910. url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
  1911. Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
  1912. State: state,
  1913. Msg: msg,
  1914. Url: url,
  1915. Device: device,
  1916. })
  1917. return
  1918. }
  1919. func horizontalLine(xmin, xmax, y float64) *plotter.Line {
  1920. pts := make(plotter.XYs, 2)
  1921. pts[0].X = xmin
  1922. pts[0].Y = y
  1923. pts[1].X = xmax
  1924. pts[1].Y = y
  1925. line, err := plotter.NewLine(pts)
  1926. if err != nil {
  1927. panic(any(err))
  1928. }
  1929. line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
  1930. line.Color = color.RGBA{R: 255, A: 255}
  1931. return line
  1932. }
  1933. type timeTicks struct{}
  1934. func (timeTicks) Ticks(min, max float64) []plot.Tick {
  1935. tks := plot.TimeTicks{}.Ticks(min, max)
  1936. for i, t := range tks {
  1937. //if t.Label == "" { // Skip minor ticks, they are fine.
  1938. // continue
  1939. //}
  1940. tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
  1941. }
  1942. return tks
  1943. }
  1944. type commaTicks struct{}
  1945. // Ticks computes the default tick marks, but inserts commas
  1946. // into the labels for the major tick marks.
  1947. func (commaTicks) Ticks(min, max float64) []plot.Tick {
  1948. tks := plot.DefaultTicks{}.Ticks(min, max)
  1949. for i, t := range tks {
  1950. //if t.Label == "" { // Skip minor ticks, they are fine.
  1951. // continue
  1952. //}
  1953. tks[i].Label = fmt.Sprintf("%.0f", t.Value)
  1954. }
  1955. return tks
  1956. }
  1957. // 生成随机颜色的辅助函数
  1958. func randomColor(i int) color.RGBA {
  1959. var colors []color.RGBA
  1960. colors = append(colors,
  1961. color.RGBA{R: 52, G: 152, B: 219, A: 255},
  1962. color.RGBA{R: 230, G: 126, B: 34, A: 255},
  1963. color.RGBA{R: 142, G: 68, B: 173, A: 255},
  1964. color.RGBA{R: 211, G: 84, B: 0, A: 255},
  1965. color.RGBA{R: 231, G: 76, B: 60, A: 255},
  1966. color.RGBA{R: 26, G: 188, B: 156, A: 255},
  1967. color.RGBA{R: 243, G: 156, B: 18, A: 255},
  1968. color.RGBA{R: 22, G: 160, B: 133, A: 255},
  1969. color.RGBA{R: 46, G: 204, B: 113, A: 255},
  1970. color.RGBA{R: 39, G: 174, B: 96, A: 255},
  1971. color.RGBA{R: 41, G: 128, B: 185, A: 255},
  1972. color.RGBA{R: 155, G: 89, B: 182, A: 255},
  1973. color.RGBA{R: 192, G: 57, B: 43, A: 255},
  1974. color.RGBA{R: 241, G: 196, B: 15, A: 255},
  1975. )
  1976. return colors[i%len(colors)]
  1977. }
  1978. // 获取加完水印的pdf
  1979. func GetWatermarkPdf(task Task.Task, pdfURL string, flag string) (pdf string) {
  1980. if len(pdfURL) == 0 {
  1981. return
  1982. }
  1983. currentDirectory := lib.GetCurrentDirectory()
  1984. scriptPath := currentDirectory + "/script"
  1985. pdf_file_out_name := uuid.New().String() + ".pdf"
  1986. pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
  1987. pdf_file_out := currentDirectory + "/ofile/watermark" + pdf_file_out_name
  1988. watermark_pdf := currentDirectory + "/script/watermark.pdf"
  1989. // 执行Python脚本
  1990. cmd := exec.Command("python3", "add_watermark.py", pdfURL, pdfFilename, pdf_file_out, watermark_pdf)
  1991. cmd.Dir = scriptPath
  1992. // 获取命令输出
  1993. _, err := cmd.CombinedOutput()
  1994. if err != nil {
  1995. logs.Error("执行python脚本添加水印错误:", err)
  1996. return
  1997. }
  1998. lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
  1999. if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
  2000. err = errors.New("上传水印pdf失败")
  2001. return
  2002. }
  2003. defer func() {
  2004. os.Remove(pdfFilename)
  2005. os.Remove(pdf_file_out)
  2006. }()
  2007. pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
  2008. switch flag {
  2009. case "T_pdf1":
  2010. task.T_pdf1_watermark = pdf
  2011. Task.Update_Task(task, "T_pdf1_watermark")
  2012. case "T_pdf2":
  2013. task.T_pdf2_watermark = pdf
  2014. Task.Update_Task(task, "T_pdf2_watermark")
  2015. }
  2016. return
  2017. }
  2018. // 暂停申请
  2019. // 列表 -
  2020. func (c *TaskController) TaskTimeList() {
  2021. // 验证登录 User_is, User_r
  2022. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2023. if !User_is {
  2024. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2025. c.ServeJSON()
  2026. return
  2027. }
  2028. var r_jsons lib.R_JSONS
  2029. T_task_id := c.GetString("T_task_id")
  2030. T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
  2031. var cnt int64
  2032. List, cnt := Task.Read_TaskTime_List(T_task_id, T_task_type)
  2033. r_jsons.List = List
  2034. r_jsons.Num = int(cnt)
  2035. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2036. c.ServeJSON()
  2037. return
  2038. }
  2039. // 添加-
  2040. func (c *TaskController) TaskTimeAdd() {
  2041. // 验证登录 User_is, User_r
  2042. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2043. if !User_is {
  2044. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2045. c.ServeJSON()
  2046. return
  2047. }
  2048. dc := Device.DeviceClass{
  2049. T_uuid: User_r.T_uuid,
  2050. T_State: 1,
  2051. }
  2052. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", dc)
  2053. T_task_id := c.GetString("T_task_id")
  2054. T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
  2055. T_aaa := c.GetString("T_aaa")
  2056. var_ := Task.TaskTime{
  2057. T_task_id: T_task_id,
  2058. T_task_type: T_task_type,
  2059. T_uuid: User_r.T_uuid,
  2060. T_remarks: T_aaa,
  2061. T_start_time: time.Now().Format("2006-01-02 15:04:05"),
  2062. }
  2063. List, _ := Task.Read_TaskTime_List(T_task_id, T_task_type)
  2064. if len(List) > 0 {
  2065. if len(List[len(List)-1].T_end_time) == 0 {
  2066. c.Data["json"] = lib.JSONS{Code: 202, Msg: "上一个任务还没结束!"}
  2067. c.ServeJSON()
  2068. return
  2069. }
  2070. }
  2071. is := Task.Add_TaskTime(var_)
  2072. if !is {
  2073. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  2074. c.ServeJSON()
  2075. return
  2076. }
  2077. // 添加任务操作日志
  2078. Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务暂停", "暂停申请", var_)
  2079. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", var_)
  2080. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
  2081. c.ServeJSON()
  2082. return
  2083. }
  2084. // 添加-
  2085. func (c *TaskController) TaskTimeEnd() {
  2086. // 验证登录 User_is, User_r
  2087. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2088. if !User_is {
  2089. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2090. c.ServeJSON()
  2091. return
  2092. }
  2093. dc := Device.DeviceClass{
  2094. T_uuid: User_r.T_uuid,
  2095. T_State: 1,
  2096. }
  2097. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", dc)
  2098. Id, _ := c.GetInt("Id", 0)
  2099. TaskTime_r, is := Task.Read_TaskTime_ById(Id)
  2100. if !is {
  2101. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  2102. c.ServeJSON()
  2103. return
  2104. }
  2105. TaskTime_r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  2106. is = Task.Update_TaskTime(TaskTime_r, "T_end_time")
  2107. if !is {
  2108. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  2109. c.ServeJSON()
  2110. return
  2111. }
  2112. // 添加任务操作日志
  2113. Task.Add_TaskLogs_T(User_r.T_uuid, TaskTime_r.T_task_id, "任务暂停", "暂停结束", TaskTime_r)
  2114. System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", TaskTime_r)
  2115. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: TaskTime_r.T_task_id}
  2116. c.ServeJSON()
  2117. return
  2118. }
  2119. // 列表 - 统计排名
  2120. func (c *TaskController) StatisticalRanking() {
  2121. // 验证登录 User_is, User_r
  2122. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2123. if !User_is {
  2124. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  2125. c.ServeJSON()
  2126. return
  2127. }
  2128. T_power, _ := c.GetInt("T_power", 0) // 5 数据采集工程师 6 验证报告工程师
  2129. type Admin_T struct {
  2130. T_name string
  2131. T_scheme int // 实施方案
  2132. T_scheme_returnnum int // 退回
  2133. T_scheme_overnum int // 超时
  2134. T_scheme_log string // 日志
  2135. T_collection int // 数据采集
  2136. T_collection_returnnum int // 退回
  2137. T_collection_overnum int // 超时
  2138. T_collection_log string // 日志
  2139. T_reporting int // 报告编写
  2140. T_reporting_returnnum int // 退回
  2141. T_reporting_overnum int // 超时
  2142. T_reporting_log string // 日志
  2143. T_rejectdnum int // 驳回数量
  2144. }
  2145. var Admin_T_List []Admin_T
  2146. Admin_List := Account.Read_Admin_List_ALL_T_power(T_power)
  2147. for _, A := range Admin_List {
  2148. Admin_t := Admin_T{T_name: A.T_name}
  2149. // 方案
  2150. Task_List := Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_scheme") //T_scheme T_collection T_reporting
  2151. for _, T := range Task_List {
  2152. if len(T.T_scheme_end_time) > 0 {
  2153. if is, _ := lib.IsInCurrentMonth(T.T_scheme_end_time); !is {
  2154. continue // 不是本月
  2155. }
  2156. Admin_t.T_scheme += 1
  2157. Admin_t.T_scheme_log += T.T_name
  2158. // 退回
  2159. if T.T_scheme_return_times > 0 {
  2160. Admin_t.T_scheme_returnnum += T.T_scheme_return_times
  2161. Admin_t.T_scheme_log += " | 退回"+ lib.To_string(int(T.T_scheme_return_times))
  2162. }
  2163. // 超时
  2164. if T.T_scheme_overtime > 0 {
  2165. Admin_t.T_scheme_overnum += 1
  2166. Admin_t.T_scheme_log += " | 超时"+ lib.ConvertMinutesToDHM(int(T.T_scheme_overtime))
  2167. }
  2168. // 驳回
  2169. if T.T_reject_times > 0 {
  2170. Admin_t.T_rejectdnum += T.T_reject_times
  2171. Admin_t.T_scheme_log += " | 驳回"+ lib.To_string(int(T.T_reject_times))
  2172. }
  2173. Admin_t.T_scheme_log += "\n"
  2174. }
  2175. }
  2176. // 实施
  2177. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_collection") //T_scheme T_collection T_reporting
  2178. for _, T := range Task_List {
  2179. if len(T.T_collection_end_time) > 0 {
  2180. if is, _ := lib.IsInCurrentMonth(T.T_collection_end_time); !is {
  2181. continue // 不是本月
  2182. }
  2183. Admin_t.T_collection += 1
  2184. Admin_t.T_collection_log += T.T_name
  2185. // 退回
  2186. if T.T_collection_return_times > 0 {
  2187. Admin_t.T_collection_returnnum += T.T_collection_return_times
  2188. Admin_t.T_collection_log += " | 退回"+ lib.To_string(int(T.T_collection_return_times))
  2189. }
  2190. // 超时
  2191. if T.T_collection_overtime > 0 {
  2192. Admin_t.T_collection_overnum += 1
  2193. Admin_t.T_collection_log += " | 超时"+ lib.ConvertMinutesToDHM(int(T.T_collection_overtime))
  2194. }
  2195. // 驳回
  2196. if T.T_reject_times > 0 {
  2197. Admin_t.T_rejectdnum += T.T_reject_times
  2198. Admin_t.T_collection_log += " | 驳回"+ lib.To_string(int(T.T_reject_times))
  2199. }
  2200. Admin_t.T_collection_log += "\n"
  2201. }
  2202. }
  2203. // 报告
  2204. Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_reporting") //T_scheme T_collection T_reporting
  2205. for _, T := range Task_List {
  2206. if len(T.T_reporting_end_time) > 0 {
  2207. if is, _ := lib.IsInCurrentMonth(T.T_reporting_end_time); !is {
  2208. continue // 不是本月
  2209. }
  2210. Admin_t.T_reporting += 1
  2211. Admin_t.T_reporting_log += T.T_name
  2212. // 退回
  2213. if T.T_reporting_return_times > 0 {
  2214. Admin_t.T_reporting_returnnum += T.T_reporting_return_times
  2215. Admin_t.T_reporting_log += " | 退回"+ lib.To_string(int(T.T_reporting_return_times))
  2216. }
  2217. // 超时
  2218. if T.T_reporting_overtime > 0 {
  2219. Admin_t.T_reporting_overnum += 1
  2220. Admin_t.T_reporting_log += " | 超时"+ lib.ConvertMinutesToDHM(int(T.T_reporting_overtime))
  2221. }
  2222. // 驳回
  2223. if T.T_reject_times > 0 {
  2224. Admin_t.T_rejectdnum += T.T_reject_times
  2225. Admin_t.T_reporting_log += " | 驳回"+ lib.To_string(int(T.T_reject_times))
  2226. }
  2227. Admin_t.T_reporting_log += "\n"
  2228. }
  2229. }
  2230. Admin_T_List = append(Admin_T_List, Admin_t)
  2231. }
  2232. var r_jsons lib.R_JSONS
  2233. r_jsons.List = Admin_T_List
  2234. r_jsons.Page = 0
  2235. r_jsons.Page_size = 0
  2236. r_jsons.Pages = lib.Func_page(int64(0), int64(0))
  2237. r_jsons.Num = 0
  2238. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2239. c.ServeJSON()
  2240. return
  2241. }