1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527 |
- package controllers
- import (
- "ColdVerify_server/Nats/NatsServer"
- "ColdVerify_server/conf"
- "ColdVerify_server/lib"
- "ColdVerify_server/lib/wx"
- "ColdVerify_server/logs"
- "ColdVerify_server/models/Account"
- "ColdVerify_server/models/Device"
- "ColdVerify_server/models/InfoCollection"
- "ColdVerify_server/models/System"
- "ColdVerify_server/models/Task"
- "ColdVerify_server/models/VerifyTemplate"
- "encoding/json"
- "errors"
- "fmt"
- beego "github.com/beego/beego/v2/server/web"
- "github.com/google/uuid"
- "github.com/xuri/excelize/v2"
- "gonum.org/v1/plot"
- "gonum.org/v1/plot/plotter"
- "gonum.org/v1/plot/vg"
- "gonum.org/v1/plot/vg/draw"
- "image/color"
- "math"
- "os"
- "os/exec"
- "strings"
- "sync"
- "time"
- )
- type TaskController struct {
- beego.Controller
- }
- // 列表 -
- func (c *TaskController) List() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- T_company := c.GetString("T_company") // 公司名称
- T_uuid := c.GetString("T_uuid")
- T_InfoCollection_id := c.GetString("T_InfoCollection_id")
- T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
- T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
- T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
- T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
- T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
- T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
- CreateTime := c.GetString("CreateTime") // 任务添加时间
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var T_company_list []string
- if len(T_company) > 0 {
- T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
- }
- var T_admin string
- if User_r.T_power > 2 {
- T_admin = User_r.T_uuid
- }
- var cnt int
- List, cnt := Task.Read_Task_List(T_uuid, T_admin, T_name, T_InfoCollection_id, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
- T_company_list, UserMap, AdminMap,CreateTime, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = cnt
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 报告统计
- func (c *TaskController) Stat() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- T_company := c.GetString("T_company") // 公司名称
- T_uuid := c.GetString("T_uuid")
- T_InfoCollection_id := c.GetString("T_InfoCollection_id")
- T_project := c.GetString("T_project") // 项目 负责人UUID
- T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
- T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
- T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
- T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
- T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
- T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
- CreateTime := c.GetString("CreateTime") // 任务添加时间
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var T_company_list []string
- if len(T_company) > 0 {
- T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
- }
- var T_admin string
- if User_r.T_power > 2 {
- T_admin = User_r.T_uuid
- }
- var cnt int
- 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,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
- T_company_list, UserMap, AdminMap,CreateTime, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = cnt
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 报告统计 - 导出excel
- func (c *TaskController) Stat_Excel() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- T_company := c.GetString("T_company") // 公司名称
- T_uuid := c.GetString("T_uuid")
- T_InfoCollection_id := c.GetString("T_InfoCollection_id")
- T_project := c.GetString("T_project") // 项目 负责人UUID
- T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
- T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
- T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
- T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
- T_scheme_state := c.GetString("T_scheme_state") // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_collection_state := c.GetString("T_collection_state") // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- T_reporting_state := c.GetString("T_reporting_state") // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_delivery_state := c.GetString("T_delivery_state") // 交付审核 状态 0 未完成 1 已完成 2 处理中
- T_marking_state := c.GetString("T_marking_state") // 验证标识 状态 0 未完成 1 已完成
- CreateTime := c.GetString("CreateTime") // 任务添加时间
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var T_company_list []string
- if len(T_company) > 0 {
- T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
- }
- var T_admin string
- if User_r.T_power > 2 {
- T_admin = User_r.T_uuid
- }
- List, _ := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
- T_company_list, UserMap, AdminMap,CreateTime, 0, 9999)
- f := excelize.NewFile() // 设置单元格的值
- line := 1
- // 这里设置表头
- f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("A%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("B%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("C%d", line), fmt.Sprintf("C%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("D%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("E%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("F%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("G%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("H%d", line), fmt.Sprintf("H%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("I%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("J%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("K%d", line), fmt.Sprintf("K%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("L%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("M%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("N%d", line), fmt.Sprintf("N%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("O%d", line), fmt.Sprintf("O%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("P%d", line), fmt.Sprintf("P%d", line+1))
- f.MergeCell("Sheet1", fmt.Sprintf("Q%d", line), fmt.Sprintf("U%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("V%d", line), fmt.Sprintf("AA%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("AB%d", line), fmt.Sprintf("AG%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("AH%d", line), fmt.Sprintf("AM%d", line))
- f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), "信息表")
- f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), "方案")
- f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), "实施")
- f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), "报告")
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "序号")
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "公司名称")
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), "报告名称")
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), "项目负责人")
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), "地区")
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), "类别")
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), "设备类型")
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), "规格/容积")
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), "验证类型")
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), "标的物名称")
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "验证温度范围")
- f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), "报告编号")
- f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), "项目开始时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), "项目用时")
- f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), "驳回次数")
- f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), "回款")
- f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line+1), "编写人")
- f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line+1), "状态")
- f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line+1), "开始时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line+1), "退回次数")
- f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line+1), "所需时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line+1), "编写人")
- f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line+1), "状态")
- f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line+1), "开始时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line+1), "退回次数")
- f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line+1), "所需时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line+1), "超时时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line+1), "编写人")
- f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line+1), "状态")
- f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line+1), "开始时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line+1), "退回次数")
- f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line+1), "所需时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line+1), "超时时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line+1), "编写人")
- f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line+1), "状态")
- f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line+1), "开始时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line+1), "退回次数")
- f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line+1), "所需时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line+1), "超时时间")
- f.SetCellValue("Sheet1", fmt.Sprintf("AN%d", line+1), "领导备注")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 7)
- f.SetColWidth("Sheet1", "B", "B", 20)
- f.SetColWidth("Sheet1", "C", "C", 10)
- f.SetColWidth("Sheet1", "D", "D", 10)
- f.SetColWidth("Sheet1", "E", "E", 12)
- f.SetColWidth("Sheet1", "F", "F", 8)
- f.SetColWidth("Sheet1", "G", "G", 12)
- f.SetColWidth("Sheet1", "H", "H", 14)
- f.SetColWidth("Sheet1", "I", "I", 12)
- f.SetColWidth("Sheet1", "J", "J", 12)
- f.SetColWidth("Sheet1", "K", "K", 12)
- f.SetColWidth("Sheet1", "L", "L", 12)
- f.SetColWidth("Sheet1", "M", "M", 12)
- f.SetColWidth("Sheet1", "N", "N", 12)
- f.SetColWidth("Sheet1", "O", "O", 10)
- f.SetColWidth("Sheet1", "P", "P", 8)
- f.SetColWidth("Sheet1", "Q", "Q", 8)
- f.SetColWidth("Sheet1", "R", "R", 8)
- f.SetColWidth("Sheet1", "S", "S", 12)
- f.SetColWidth("Sheet1", "T", "T", 10)
- f.SetColWidth("Sheet1", "U", "U", 10)
- f.SetColWidth("Sheet1", "V", "V", 8)
- f.SetColWidth("Sheet1", "W", "W", 8)
- f.SetColWidth("Sheet1", "X", "X", 12)
- f.SetColWidth("Sheet1", "Y", "Y", 10)
- f.SetColWidth("Sheet1", "Z", "Z", 12)
- f.SetColWidth("Sheet1", "AA", "AA", 12)
- f.SetColWidth("Sheet1", "AB", "AB", 8)
- f.SetColWidth("Sheet1", "AC", "AC", 8)
- f.SetColWidth("Sheet1", "AD", "AD", 12)
- f.SetColWidth("Sheet1", "AE", "AE", 10)
- f.SetColWidth("Sheet1", "AF", "AF", 12)
- f.SetColWidth("Sheet1", "AG", "AG", 12)
- f.SetColWidth("Sheet1", "AG", "AG", 10)
- f.SetColWidth("Sheet1", "AH", "AH", 8)
- f.SetColWidth("Sheet1", "AI", "AI", 8)
- f.SetColWidth("Sheet1", "AJ", "AJ", 10)
- f.SetColWidth("Sheet1", "AK", "AK", 12)
- f.SetColWidth("Sheet1", "AL", "AL", 12)
- f.SetColWidth("Sheet1", "AM", "AM", 12)
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A1", "AM2", Style1)
- f.SetRowHeight("Sheet1", 1, 25)
- f.SetRowHeight("Sheet1", 2, 25)
- line += 1
- // 循环写入数据
- for i, v := range List {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_user_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_project_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("%s-%s-%s", v.T_province, v.T_city, v.T_district))
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_category)
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_device_type)
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_volume)
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_verify_type)
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_subject_matter)
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.T_temp_range)
- f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("%s-%s", v.T_report_type, v.T_report_number))
- f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v.T_start_time)
- f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), v.T_time_interval)
- f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v.T_reject_times)
- returnedMoney := "否"
- if v.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney {
- returnedMoney = "是"
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), returnedMoney)
- f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), v.InfoCollection.T_submit_uuid_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), InfoCollection.InfoCollectionStatusMap[v.InfoCollection.T_State])
- f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), v.InfoCollection.T_start_time)
- f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), v.InfoCollection.T_return_times)
- f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), v.InfoCollection.T_time_interval)
- f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), v.T_scheme_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line), Task.TaskSchemeStateMap[v.T_scheme_state])
- f.SetCellValue("Sheet1", fmt.Sprintf("X%d", line), v.T_scheme_start_time)
- f.SetCellValue("Sheet1", fmt.Sprintf("Y%d", line), v.T_scheme_return_times)
- f.SetCellValue("Sheet1", fmt.Sprintf("Z%d", line), v.T_scheme_time_interval)
- f.SetCellValue("Sheet1", fmt.Sprintf("AA%d", line), v.T_scheme_overtime)
- f.SetCellValue("Sheet1", fmt.Sprintf("AB%d", line), v.T_collection_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line), Task.TaskCollectionStateMap[v.T_collection_state])
- f.SetCellValue("Sheet1", fmt.Sprintf("AD%d", line), v.T_collection_start_time)
- f.SetCellValue("Sheet1", fmt.Sprintf("AE%d", line), v.T_collection_return_times)
- f.SetCellValue("Sheet1", fmt.Sprintf("AF%d", line), v.T_collection_time_interval)
- f.SetCellValue("Sheet1", fmt.Sprintf("AG%d", line), v.T_collection_overtime)
- f.SetCellValue("Sheet1", fmt.Sprintf("AH%d", line), v.T_reporting_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("AI%d", line), Task.TaskReportingStateMap[v.T_reporting_state])
- f.SetCellValue("Sheet1", fmt.Sprintf("AJ%d", line), v.T_reporting_start_time)
- f.SetCellValue("Sheet1", fmt.Sprintf("AK%d", line), v.T_reporting_return_times)
- f.SetCellValue("Sheet1", fmt.Sprintf("AL%d", line), v.T_reporting_time_interval)
- f.SetCellValue("Sheet1", fmt.Sprintf("AM%d", line), v.T_reporting_overtime)
- f.SetCellValue("Sheet1", fmt.Sprintf("AN%d", line), v.T_record)
- }
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("AM%d", line), Style2)
- StyleBlueFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#DEE5F5"}, Pattern: 1},
- })
- // 粉色填充
- StylePinkFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#FBDFE2"}, Pattern: 1},
- })
- StyleOrangeFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#FCE7D8"}, Pattern: 1},
- })
- StyleYellowFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFF5D0"}, Pattern: 1},
- })
- StyleGreenFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#E7F4DE"}, Pattern: 1},
- })
- f.SetCellStyle("Sheet1", "A1", "AM2", StyleBlueFill)
- f.SetCellStyle("Sheet1", "Q1", "U1", StylePinkFill)
- f.SetCellStyle("Sheet1", "V1", "AA1", StyleOrangeFill)
- f.SetCellStyle("Sheet1", "AB1", "AG1", StyleYellowFill)
- f.SetCellStyle("Sheet1", "AH1", "AM1", StyleGreenFill)
- f.SetCellStyle("Sheet1", "AN1", "AN2", StyleBlueFill)
- // 冻结1-2行
- f.SetPanes("Sheet1", &excelize.Panes{
- Freeze: true,
- Split: false,
- XSplit: 3,
- YSplit: 2,
- TopLeftCell: "A1",
- ActivePane: "topRight",
- })
- lib.Create_Dir("./ofile")
- timeStr := time.Now().Format("20060102150405")
- // 保存文件
- if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
- logs.Error(lib.FuncName(), err)
- }
- if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx") {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
- c.ServeJSON()
- return
- }
- //删除目录
- err := os.Remove("ofile/" + timeStr + ".xlsx")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + timeStr + ".xlsx"}
- c.ServeJSON()
- return
- }
- // 获取任务负责人列表
- func (c *TaskController) GetTaskUserList() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_type := c.GetString("T_type") // T_project项目 T_scheme方案 T_collection数据采集 T_reporting报告
- list := Task.Get_Task_UserList(T_type)
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var User_list []Account.Admin_R
- for _, v := range list {
- if len(v) == 0 {
- continue
- }
- User_list = append(User_list, Account.Admin_R{T_uuid: v, T_name: AdminMap[v]})
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_list}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *TaskController) UserTaskList() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var cnt int
- List, cnt := Task.Read_UserTask_List(User_r.T_uuid, T_name, UserMap, AdminMap, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = cnt
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 获取-
- func (c *TaskController) Get() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 添加浏览量
- _ = Task.Add_Task_Visit(r)
- r.T_Visit += 1
- userMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- adminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Task.TaskToTask_Stat(r, userMap, adminMap)}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *TaskController) Add() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- dc := Device.DeviceClass{
- T_uuid: User_r.T_uuid,
- T_State: 1,
- }
- T_class_id, is := Device.Add_DeviceClass(dc)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
- T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
- T_name := c.GetString("T_name")
- T_uuid := c.GetString("T_uuid") // 用户uuid
- T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
- T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
- T_deadline := c.GetString("T_deadline")
- T_scheme := c.GetString("T_scheme")
- T_collection := c.GetString("T_collection")
- T_reporting := c.GetString("T_reporting")
- T_delivery := c.GetString("T_delivery")
- T_project := c.GetString("T_project") // 项目 负责人UUID
- T_province := c.GetString("T_province") // 省
- T_city := c.GetString("T_city") // 市
- T_district := c.GetString("T_district") // 区
- T_province_code := c.GetString("T_province_code") // 省 code
- T_city_code := c.GetString("T_city_code") // 市 code
- T_district_code := c.GetString("T_district_code") // 区 code
- T_category := c.GetString("T_category") // 类别
- T_device_type := c.GetString("T_device_type") // 设备类型
- T_volume := c.GetString("T_volume") // 规格/容积
- T_verify_type := c.GetString("T_verify_type") // 验证类型
- T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
- T_temp_range := c.GetString("T_temp_range") // 验证温度范围
- T_report_number := c.GetString("T_report_number") // 报告编号
- T_report_type := c.GetString("T_report_type") // 报告类型
- // 查询信息采集信息
- infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
- c.ServeJSON()
- return
- }
- var_ := Task.Task{
- T_InfoCollection_id: T_InfoCollection_id,
- T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
- T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
- T_class: int(T_class_id),
- T_uuid: T_uuid,
- T_name: T_name,
- T_VerifyTemplate_class: T_VerifyTemplate_class,
- T_VerifyTemplate_id: T_VerifyTemplate_id,
- T_deadline: T_deadline,
- T_scheme: T_scheme,
- T_collection: T_collection,
- T_reporting: T_reporting,
- T_delivery: T_delivery,
- T_Show: 1,
- T_State: 1,
- T_project: T_project,
- T_province: T_province,
- T_city: T_city,
- T_district: T_district,
- T_province_code: T_province_code,
- T_city_code: T_city_code,
- T_district_code: T_district_code,
- T_category: T_category,
- T_device_type: T_device_type,
- T_volume: T_volume,
- T_verify_type: T_verify_type,
- T_subject_matter: T_subject_matter,
- T_temp_range: T_temp_range,
- T_report_number: T_report_number,
- T_report_type: T_report_type,
- }
- T_task_id, is := Task.Add_Task(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- NatsServer.Create_Local_Table(T_task_id)
- // 通知
- _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
- go wx.WxSend(var_.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
- go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
- go wx.WxSend(var_.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
- go wx.WxSend(var_.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "添加", var_)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
- c.ServeJSON()
- return
- }
- // 接收信息采集
- func (c *TaskController) ReceiptInfoCollection() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- // 修改信息采集状态为已接收
- T_InfoCollection_id := c.GetString("T_InfoCollection_id")
- //T_status,_ := c.GetInt("T_status")
- infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if infoCollection.T_status != InfoCollection.InfoCollectionStatusSubmitted && infoCollection.T_status != InfoCollection.InfoCollectionStatusReceipt {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止接收!", InfoCollection.InfoCollectionStatusMap[infoCollection.T_status])}
- c.ServeJSON()
- return
- }
- //infoCollection.T_status = InfoCollection.InfoCollectionStatusReceipt
- //if len(infoCollection.T_end_time) == 0 {
- // infoCollection.T_end_time = time.Now().Format("2006-01-02 15:04:05")
- // infoCollection.T_time_interval, _ = lib.MinutesDifference(infoCollection.T_start_time, infoCollection.T_end_time)
- //}
- //if !InfoCollection.Update_InfoCollection(infoCollection, "T_status", "T_end_time", "T_time_interval") {
- infoCollection.T_status = 3 // 已接收
- if !InfoCollection.Update_InfoCollection(infoCollection, "T_status") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "接收信息采集", infoCollection)
- //if T_status == InfoCollection.InfoCollectionStatusReturn{
- // // 通知 报告负责人审核
- // _, company_r := Account.Read_User_ByT_uuid(infoCollection.T_uuid)
- // System.Add_News(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name), "")
- // go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 已退回", company_r.T_name, infoCollection.T_name))
- //
- //}
- // 修改任务管理实施方案开始时间
- //T_task_id := c.GetString("T_task_id")
- //task, is := Task.Read_Task(T_task_id)
- //if !is {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- // c.ServeJSON()
- // return
- //}
-
- // 添加任务操作日志
- //Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "接收信息采集", task)
- //System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "接收信息采集", task)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *TaskController) AddData_Tool() {
- T_uuid := "3e84dda9-9eec-42b9-9350-0894262fc8a1" // 用户uuid
- T_name := c.GetString("T_name")
- T_task_id := c.GetString("T_task_id")
- T_task_id = strings.ToLower(T_task_id)
- r, _ := Task.Read_Task(T_task_id)
- if r.T_collection_state == 2 {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "数据采集中..."}
- c.ServeJSON()
- return
- }
- if r.Id > 0 {
- // 同步1.0数据
- NatsServer.Sync1_TaskData(T_task_id)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
- c.ServeJSON()
- return
- }
- dc := Device.DeviceClass{
- T_uuid: T_uuid,
- T_State: 1,
- }
- T_class_id, is := Device.Add_DeviceClass(dc)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
- c.ServeJSON()
- return
- }
- var_ := Task.Task{
- T_task_id: T_task_id,
- T_class: int(T_class_id),
- T_uuid: T_uuid,
- T_name: T_name,
- T_Show: 1,
- T_State: 1,
- T_collection_state: 2,
- }
- _, is = Task.Add_Task_Tool(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- // 创建本地表
- NatsServer.Create_Local_Table(T_task_id)
- // 同步1.0数据
- NatsServer.Sync1_TaskData(T_task_id)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
- c.ServeJSON()
- return
- }
- // 修改采集状态-
- func (c *TaskController) UpCollectionState() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_collection_state, _ := c.GetInt("T_collection_state")
- T_reason := c.GetString("T_reason") // 退回原因
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
- r.T_collection_state = T_collection_state
- clos := make([]string, 0)
- clos = append(clos, "T_collection_state")
- if T_collection_state == Task.TaskCollectionStateReturn {
- r.T_collection_return_times += 1
- clos = append(clos, "T_collection_return_times")
- }
- if T_collection_state == Task.TaskCollectionStateSubmitted ||
- T_collection_state == Task.TaskCollectionStateReturn ||
- T_collection_state == Task.TaskCollectionStatePass {
- // 添加已提交状态验证报告记录
- auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, T_collection_state, T_reason, "")
- if err != nil {
- return
- }
- r.T_collection_audit_record = auditRecordJson
- clos = append(clos, "T_collection_audit_record")
- }
- if T_collection_state == Task.TaskCollectionStatePass {
- // 数据编辑审核通过时间为验证报告开始时间
- r.T_reporting_start_time = time.Now().Format("2006-01-02 15:04:05")
- clos = append(clos, "T_reporting_start_time")
- }
- if !Task.Update_Task(r, clos...) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 已退回(负责人)
- if T_collection_state == Task.TaskCollectionStateReturn {
- 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), "")
- 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))
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改采集状态", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改采集状态", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *TaskController) UpDeliveryState() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_delivery_state, _ := c.GetInt("T_delivery_state")
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- r.T_delivery_state = T_delivery_state
- if !Task.Update_Task(r, "T_delivery_state") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改交付审核状态", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改交付审核状态", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 更新线上数据后台执行
- func (c *TaskDataController) TaskData_Up_TaskData_Back() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 通知 报告人员
- _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
- infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
- System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name), "")
- go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】报告已完成,请及时通知客户审核", company_r.T_name, r.T_name))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 修改-
- func (c *TaskController) Up() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- T_Show, T_Show_err := c.GetInt("T_Show")
- T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
- T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
- T_deadline := c.GetString("T_deadline")
- T_scheme := c.GetString("T_scheme")
- T_collection := c.GetString("T_collection")
- T_collection_state, _ := c.GetInt("T_collection_state")
- T_collection_signature := c.GetString("T_collection_signature") // 完成编辑签字图片
- T_reporting := c.GetString("T_reporting")
- T_delivery := c.GetString("T_delivery")
- T_record := c.GetString("T_record")
- T_doc1 := c.GetString("T_doc1")
- T_pdf1 := c.GetString("T_pdf1")
- T_doc2 := c.GetString("T_doc2")
- T_pdf2 := c.GetString("T_pdf2")
- T_doc3 := c.GetString("T_doc3")
- T_pdf3 := c.GetString("T_pdf3")
- T_pdf4 := c.GetString("T_pdf4") // 验证标识
- T_VerifyDeviceDataStartTime := c.GetString("T_VerifyDeviceDataStartTime") // 验证设备数据开始时间
- T_VerifyDeviceDataEndTime := c.GetString("T_VerifyDeviceDataEndTime") // 验证设备数据开始时间
- T_BindDeviceDataStartTime := c.GetString("T_BindDeviceDataStartTime") // 绑定设备数据开始时间
- T_BindDeviceDataEndTime := c.GetString("T_BindDeviceDataEndTime") // 绑定设备数据结束时间
- T_sn := c.GetString("T_sn") // T_sn
- T_CalibrationExpirationTime := c.GetString("T_CalibrationExpirationTime") // 校准到期时间
- T_project := c.GetString("T_project") // 项目 负责人UUID
- T_province := c.GetString("T_province") // 省
- T_city := c.GetString("T_city") // 市
- T_district := c.GetString("T_district") // 区
- T_province_code := c.GetString("T_province_code") // 省 code
- T_city_code := c.GetString("T_city_code") // 市 code
- T_district_code := c.GetString("T_district_code") // 区 code
- T_category := c.GetString("T_category") // 类别
- T_device_type := c.GetString("T_device_type") // 设备类型
- T_volume := c.GetString("T_volume") // 规格/容积
- T_verify_type := c.GetString("T_verify_type") // 验证类型
- T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
- T_temp_range := c.GetString("T_temp_range") // 验证温度范围
- T_report_number := c.GetString("T_report_number") // 报告编号
- T_report_type := c.GetString("T_report_type") // 报告编号
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // .......
- clos := make([]string, 0)
- if len(T_name) > 0 {
- r.T_name = T_name
- clos = append(clos, "T_name")
- }
- if T_Show_err == nil {
- r.T_Show = T_Show
- clos = append(clos, "T_Show")
- }
- if len(T_VerifyTemplate_class) > 0 {
- r.T_VerifyTemplate_class = T_VerifyTemplate_class
- clos = append(clos, "T_VerifyTemplate_class")
- }
- if len(T_VerifyTemplate_id) > 0 {
- r.T_VerifyTemplate_id = T_VerifyTemplate_id
- clos = append(clos, "T_VerifyTemplate_id")
- }
- if len(T_deadline) > 0 {
- r.T_deadline = T_deadline
- clos = append(clos, "T_deadline")
- }
- if len(T_scheme) > 0 {
- r.T_scheme = T_scheme
- clos = append(clos, "T_scheme")
- }
- if len(T_collection) > 0 {
- r.T_collection = T_collection
- clos = append(clos, "T_collection")
- }
- if len(T_reporting) > 0 {
- r.T_reporting = T_reporting
- clos = append(clos, "T_reporting")
- }
- if len(T_delivery) > 0 {
- r.T_delivery = T_delivery
- clos = append(clos, "T_delivery")
- }
- if len(T_record) > 0 {
- r.T_record = T_record
- clos = append(clos, "T_record")
- }
- // 完成编辑后设置实施结束时间
- if T_collection_state == 4 {
- r.T_collection_state = T_collection_state
- clos = append(clos, "T_collection_state")
- r.T_collection_signature = T_collection_signature
- clos = append(clos, "T_collection_signature")
- r.T_collection_end_time = time.Now().Format("2006-01-02 15:04:05")
- clos = append(clos, "T_collection_end_time")
- if len(r.T_collection_start_time) > 0 {
- r.T_collection_time_interval, _ = lib.MinutesDifference(r.T_collection_start_time, r.T_collection_end_time)
- // 扣除暂停时间
- Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 1)
- if Task_Compute > 0 {
- r.T_collection_time_interval -= float64(Task_Compute)
- }
- clos = append(clos, "T_collection_time_interval")
- // 所需时间 > 超时时间
- if r.T_collection_time_interval > Task.TaskCollectionTimeLimit && len(r.T_report_type) > 0 {
- r.T_collection_overtime = r.T_collection_time_interval - Task.TaskCollectionTimeLimit // 超时时间
- clos = append(clos, "T_collection_overtime")
- }
- // 通知 报告人员
- _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
- System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name), "")
- go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】数据采集 已提交", company_r.T_name, r.T_name))
- }
- // 添加已提交状态数据编辑记录
- auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, r.T_collection_state, "", "")
- if err == nil {
- r.T_collection_audit_record = auditRecordJson
- clos = append(clos, "T_collection_audit_record")
- }
- }
- if len(T_doc1) > 0 {
- r.T_doc1 = T_doc1
- clos = append(clos, "T_doc1")
- }
- // 验证报告内容T_pdf1,上传后将 当前任务 验证方案 标志 为 5 (0未完成 1已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交)
- // 上传后设置方案结束时间,计算所需时间和超时时间
- if len(T_pdf1) > 0 {
- r.T_pdf1 = T_pdf1
- clos = append(clos, "T_pdf1")
- //r.T_pdf1_watermark = GetWatermarkPdf(r,T_pdf1,"T_pdf1")
- //clos = append(clos, "T_pdf1_watermark")
- go GetWatermarkPdf(r, T_pdf1, "T_pdf1")
- r.T_scheme_state = 5
- clos = append(clos, "T_scheme_state")
- // 添加已提交状态验证方案记录
- auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, "", User_r.T_uuid, r.T_scheme_state, "", "")
- if err != nil {
- return
- }
- r.T_scheme_audit_record = auditRecordJson
- clos = append(clos, "T_scheme_audit_record")
- r.T_scheme_end_time = time.Now().Format("2006-01-02 15:04:05")
- clos = append(clos, "T_scheme_end_time")
- r.T_scheme_time_interval, _ = lib.MinutesDifference(r.T_scheme_start_time, r.T_scheme_end_time)
- Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 0)
- if Task_Compute > 0 {
- r.T_scheme_time_interval -= float64(Task_Compute)
- }
- clos = append(clos, "T_scheme_time_interval")
- // 所需时间 > 超时时间
- if r.T_scheme_time_interval > Task.TaskSchemeTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
- r.T_scheme_overtime = r.T_scheme_time_interval - Task.TaskSchemeTimeLimit[r.T_report_type] // 超时时间
- if Task.TaskSchemeTimeLimit[r.T_report_type] == 0 {
- r.T_scheme_overtime = 0
- }
- clos = append(clos, "T_scheme_overtime")
- }
- // 通知 实施人员进场
- _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
- System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name), "")
- go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 已提交", company_r.T_name, r.T_name))
- }
- if len(T_doc2) > 0 {
- r.T_doc2 = T_doc2
- clos = append(clos, "T_doc2")
- }
- // 验证报告内容T_pdf2 ,上传后将 当前任务 报告编写 标志 为 1
- // 上传后设置报告结束时间,计算所需时间和超时时间
- if len(T_pdf2) > 0 {
- r.T_pdf2 = T_pdf2
- clos = append(clos, "T_pdf2")
- //r.T_pdf2_watermark = GetWatermarkPdf(T_pdf2,"T_pdf1")
- //clos = append(clos, "T_pdf2_watermark")
- go GetWatermarkPdf(r, T_pdf2, "T_pdf2")
- r.T_reporting_state = 5
- clos = append(clos, "T_reporting_state")
- // 添加已提交状态验证报告记录
- auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, "", User_r.T_uuid, r.T_reporting_state, "", "")
- if err == nil {
- r.T_reporting_audit_record = auditRecordJson
- clos = append(clos, "T_reporting_audit_record")
- r.T_reporting_end_time = time.Now().Format("2006-01-02 15:04:05")
- clos = append(clos, "T_reporting_end_time")
- if len(r.T_reporting_start_time) > 0 {
- r.T_reporting_time_interval, _ = lib.MinutesDifference(r.T_reporting_start_time, r.T_reporting_end_time)
- clos = append(clos, "T_reporting_time_interval")
- // 扣除暂停时间
- Task_Compute := Task.Read_TaskTime_Compute(r.T_task_id, 2)
- if Task_Compute > 0 {
- r.T_reporting_time_interval -= float64(Task_Compute)
- }
- clos = append(clos, "T_reporting_time_interval")
- // 所需时间 > 超时时间
- if r.T_reporting_time_interval > Task.TaskReportingTimeLimit[r.T_report_type] && len(r.T_report_type) > 0 {
- r.T_reporting_overtime = r.T_reporting_time_interval - Task.TaskReportingTimeLimit[r.T_report_type] // 超时时间
- if Task.TaskReportingTimeLimit[r.T_report_type] == 0 {
- r.T_reporting_overtime = 0
- }
- clos = append(clos, "T_reporting_overtime")
- }
- }
- }
- // 通知 报告人员
- _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
- System.Add_News(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name), "")
- go wx.WxSend(r.T_delivery, fmt.Sprintf("【%s-%s】验证报告 已提交", company_r.T_name, r.T_name))
- }
- if len(T_doc3) > 0 {
- r.T_doc3 = T_doc3
- clos = append(clos, "T_doc3")
- }
- if len(T_pdf3) > 0 {
- r.T_pdf3 = T_pdf3
- clos = append(clos, "T_pdf3")
- }
- // 验证标识内容T_pdf4 ,上传后将 当前任务 验证标识 标志 为 1
- if len(T_pdf4) > 0 {
- r.T_pdf4 = T_pdf4
- clos = append(clos, "T_pdf4")
- r.T_marking_state = 1
- clos = append(clos, "T_marking_state")
- }
- if len(T_VerifyDeviceDataStartTime) > 0 {
- r.T_VerifyDeviceDataStartTime = T_VerifyDeviceDataStartTime
- clos = append(clos, "T_VerifyDeviceDataStartTime")
- }
- if len(T_VerifyDeviceDataEndTime) > 0 {
- r.T_VerifyDeviceDataEndTime = T_VerifyDeviceDataEndTime
- clos = append(clos, "T_VerifyDeviceDataEndTime")
- }
- if len(T_BindDeviceDataStartTime) > 0 {
- r.T_BindDeviceDataStartTime = T_BindDeviceDataStartTime
- clos = append(clos, "T_BindDeviceDataStartTime")
- }
- if len(T_BindDeviceDataEndTime) > 0 {
- r.T_BindDeviceDataEndTime = T_BindDeviceDataEndTime
- clos = append(clos, "T_BindDeviceDataEndTime")
- }
- if len(T_sn) > 0 {
- T_sn = strings.TrimSpace(T_sn)
- r.T_sn = T_sn
- clos = append(clos, "T_sn")
- }
- if len(T_CalibrationExpirationTime) > 0 {
- r.T_CalibrationExpirationTime = T_CalibrationExpirationTime
- clos = append(clos, "T_CalibrationExpirationTime")
- }
- // 从3.0获取校准时间
- if len(T_sn) > 0 && len(T_CalibrationExpirationTime) == 0 {
- go func(r Task.Task,T_sn ,T_CalibrationExpirationTime string) {
- NatsServer.Cold_UpdateDevice_CalibrationTime(T_sn, T_CalibrationExpirationTime)
- device, err := NatsServer.Cold_ReadDeviceByT_sn(T_sn)
- if err == nil {
- if !device.T_CalibrationTime.IsZero() {
- r.T_CalibrationExpirationTime = device.T_CalibrationTime.Format("2006-01-02")
- clos = append(clos, "T_CalibrationExpirationTime")
- Task.Update_Task(r, "T_CalibrationExpirationTime")
- }
- }
- }(r,T_sn,T_CalibrationExpirationTime)
- }
- if len(T_project) > 0 {
- r.T_project = T_project
- clos = append(clos, "T_project")
- }
- if len(T_province) > 0 {
- r.T_province = T_province
- clos = append(clos, "T_province")
- }
- if len(T_city) > 0 {
- r.T_city = T_city
- clos = append(clos, "T_city")
- }
- if len(T_district) > 0 {
- r.T_district = T_district
- clos = append(clos, "T_district")
- }
- if len(T_province_code) > 0 {
- r.T_province_code = T_province_code
- clos = append(clos, "T_province_code")
- }
- if len(T_city_code) > 0 {
- r.T_city_code = T_city_code
- clos = append(clos, "T_city_code")
- }
- if len(T_district_code) > 0 {
- r.T_district_code = T_district_code
- clos = append(clos, "T_district_code")
- }
- if len(T_category) > 0 {
- r.T_category = T_category
- clos = append(clos, "T_category")
- }
- if len(T_device_type) > 0 {
- r.T_device_type = T_device_type
- clos = append(clos, "T_device_type")
- }
- if len(T_volume) > 0 {
- r.T_volume = T_volume
- clos = append(clos, "T_volume")
- }
- if len(T_verify_type) > 0 {
- r.T_verify_type = T_verify_type
- clos = append(clos, "T_verify_type")
- }
- if len(T_subject_matter) > 0 {
- r.T_subject_matter = T_subject_matter
- clos = append(clos, "T_subject_matter")
- }
- if len(T_temp_range) > 0 {
- r.T_temp_range = T_temp_range
- clos = append(clos, "T_temp_range")
- }
- if len(T_report_number) > 0 {
- r.T_report_number = T_report_number
- clos = append(clos, "T_report_number")
- }
- if len(T_report_type) > 0 {
- r.T_report_type = T_report_type
- clos = append(clos, "T_report_type")
- }
- if !Task.Update_Task(r, clos...) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "修改", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 修改验证方案状态
- func (c *TaskController) UpSchemeState() {
- Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !Admin_is && !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- operate_uuid := ""
- if Admin_is {
- operate_uuid = Admin_r.T_uuid
- }
- if User_is {
- operate_uuid = User_r.T_uuid
- }
- T_scheme_state, _ := c.GetInt("T_scheme_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
- T_reason := c.GetString("T_reason") // 退回原因
- T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
- clos := make([]string, 0)
- if T_scheme_state > 0 {
- r.T_scheme_state = T_scheme_state
- clos = append(clos, "T_scheme_state")
- }
- if len(T_signature) > 0 {
- r.T_scheme_signature = T_signature
- clos = append(clos, "T_scheme_signature")
- }
- if T_scheme_state == Task.TaskSchemeStateClientReturn || T_scheme_state == Task.TaskSchemeStateReturn {
- r.T_scheme_return_times += 1
- clos = append(clos, "T_scheme_return_times")
- // 客户退回时新增驳回次数和驳回记录
- if T_scheme_state == Task.TaskSchemeStateClientReturn {
- r.T_reject_times += 1
- var rejectRecordList []Task.AuditRecord
- if len(r.T_reject_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- rejectRecordList = append(rejectRecordList, Task.AuditRecord{
- T_uuid: User_r.T_uuid,
- T_state: T_scheme_state,
- T_reason: T_reason,
- T_time: time.Now().Format("2006-01-02 15:04:05"),
- T_type: "scheme",
- })
- rejectRecordJson, err := json.Marshal(rejectRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- r.T_reject_record = string(rejectRecordJson)
- clos = append(clos, "T_reject_times")
- clos = append(clos, "T_reject_record")
- }
- }
- auditRecordJson, err := Task.Add_AuditRecord(r.T_scheme_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_scheme_state, T_reason, "")
- if err != nil {
- return
- }
- r.T_scheme_audit_record = auditRecordJson
- clos = append(clos, "T_scheme_audit_record")
- if !Task.Update_Task(r, clos...) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- // 已提交
- if T_scheme_state == Task.TaskSchemeStateSubmitted {
- System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
- go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
- }
- // 已通过
- if T_scheme_state == Task.TaskSchemeStatePass {
- infoCollection, _ := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
- System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
- go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证方案 %s,请尽快与客户沟通确定", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]))
- }
- // 已退回(负责人)
- if T_scheme_state == Task.TaskSchemeStateReturn {
- 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), "")
- 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))
- }
- // 已退回(客户)
- if T_scheme_state == Task.TaskSchemeStateClientReturn {
- 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), "")
- 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))
- 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), "")
- 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))
- 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))
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证方案状态", r)
- System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证方案状态", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 修改验证报告状态
- func (c *TaskController) UpReportingState() {
- Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !Admin_is && !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- operate_uuid := ""
- if Admin_is {
- operate_uuid = Admin_r.T_uuid
- }
- if User_is {
- operate_uuid = User_r.T_uuid
- }
- T_reporting_state, _ := c.GetInt("T_reporting_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
- T_reason := c.GetString("T_reason") // 退回原因
- T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
- clos := make([]string, 0)
- if T_reporting_state > 0 {
- r.T_reporting_state = T_reporting_state
- clos = append(clos, "T_reporting_state")
- }
- if len(T_signature) > 0 {
- r.T_reporting_signature = T_signature
- clos = append(clos, "T_reporting_signature")
- }
- if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
- r.T_reporting_return_times += 1
- clos = append(clos, "T_reporting_return_times")
- // 客户退回时新增驳回次数和驳回记录
- if T_reporting_state == Task.TaskReportingStateClientReturn {
- r.T_reject_times += 1
- var rejectRecordList []Task.AuditRecord
- if len(r.T_reject_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- rejectRecordList = append(rejectRecordList, Task.AuditRecord{
- T_uuid: User_r.T_uuid,
- T_state: T_reporting_state,
- T_reason: T_reason,
- T_time: time.Now().Format("2006-01-02 15:04:05"),
- T_type: "reporting",
- })
- rejectRecordJson, err := json.Marshal(rejectRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- r.T_reject_record = string(rejectRecordJson)
- clos = append(clos, "T_reject_times")
- clos = append(clos, "T_reject_record")
- }
- }
- auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
- if err != nil {
- return
- }
- r.T_reporting_audit_record = auditRecordJson
- clos = append(clos, "T_reporting_audit_record")
- // 查询信息采集信息
- infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
- c.ServeJSON()
- return
- }
- // 验证报告客户审核通过后设置结束时间
- if T_reporting_state == Task.TaskReportingStateClientPass {
- r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
- r.T_time_interval, err = lib.MinutesDifference(infoCollection.T_start_time, r.T_end_time)
- if err != nil {
- logs.Error("UpReportingState:", err.Error())
- }
- clos = append(clos, "T_end_time")
- clos = append(clos, "T_time_interval")
- }
- if !Task.Update_Task(r, clos...) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 已通过
- if T_reporting_state == Task.TaskReportingStatePass {
- System.Add_News(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
- go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
- System.Add_News(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
- go wx.WxSend(r.T_reporting, fmt.Sprintf("【%s-%s】验证报告 %s,请及时 打印报告", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
- }
- // 已退回
- if T_reporting_state == Task.TaskReportingStateReturn {
- 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), "")
- 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))
- }
- // 已通过(客户) 通知销售
- if T_reporting_state == Task.TaskReportingStateClientPass {
- go wx.WxSend(infoCollection.T_submit_uuid, fmt.Sprintf("【%s-%s】 %s,请尽快安排客户回款", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]))
- }
- if T_reporting_state == Task.TaskReportingStateClientReturn {
- 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), "")
- 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))
- 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), "")
- 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))
- 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), "")
- 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))
- //System.Add_News(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
- //go wx.WxSend(r.T_delivery, fmt.Sprintf("!!!【%s-%s】验证报告 %s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state]))
- System.Add_News(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state],T_reason), "")
- go wx.WxSend(conf.VdelUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name,Task.TaskReportingStateMap[T_reporting_state],T_reason))
- go wx.WxSend(conf.BoosUuid, fmt.Sprintf("!!!【%s-%s】验证报告 %s,%s", infoCollection.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state],T_reason))
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证报告状态", r)
- System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证报告状态", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 进场 改成 方案开始
- func (c *TaskController) EnterArea() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 方案开始
- if len(r.T_scheme_start_time) == 0 {
- r.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
- Task.Update_Task(r,"T_scheme_start_time")
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "方案开始", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "方案开始", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 开始验证
- func (c *TaskController) StartVerify() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- T_time := c.GetString("T_time") // 进场时间
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if len(r.T_collection_start_time) == 0 {
- r.T_collection_start_time = T_time
- if !Task.Update_Task(r, "T_collection_start_time") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除-
- func (c *TaskController) Del() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- if r, is := Task.Read_Task(T_task_id); is {
- if !Task.Delete_Task(r) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *TaskController) Logs_List() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_task_id := c.GetString("T_task_id")
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var cnt int
- List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = cnt
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 查询图片生成状态
- func (c *TaskController) DeviceData_JPGState() {
- T_task_id := c.GetString("T_task_id")
- T_remark := c.GetString("T_remark")
- jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
- c.ServeJSON()
- return
- }
- // 生成温度图片
- func (c *TaskController) DeviceData_JPG() {
- StartTime := c.GetString("StartTime")
- if len(StartTime) > 0 {
- _, ok := lib.TimeStrToTime(StartTime)
- if !ok {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
- c.ServeJSON()
- return
- }
- }
- EndTime := c.GetString("EndTime")
- if len(EndTime) > 0 {
- _, ok := lib.TimeStrToTime(EndTime)
- if !ok {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
- c.ServeJSON()
- return
- }
- } else {
- EndTime = time.Now().Format("2006-01-02 15:04:05")
- }
- T_remark := c.GetString("T_remark")
- TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
- TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
- if TemperatureMin == 0 {
- TemperatureMin = 2
- }
- if TemperatureMax == 0 {
- TemperatureMax = 8
- }
- T_task_id := c.GetString("T_task_id")
- Task_r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
- c.ServeJSON()
- return
- }
- if Task_r.T_collection_state == 2 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
- c.ServeJSON()
- return
- }
- deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
- c.ServeJSON()
- return
- }
- Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
- // 生成图片
- go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // SyncInfoCollection 同步信息采集表
- func (c *TaskController) SyncInfoCollection() {
- T_task_id := c.GetString("T_task_id")
- T_source, _ := c.GetInt("T_source")
- task, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 获取信息采集表模版信息
- InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
- InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
- Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
- Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
- InfoCollectionDataMap := make(map[string]string)
- for _, data := range InfoCollection_Data {
- InfoCollectionDataMap[data.T_name] = data.T_value
- }
- MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
- for _, v := range Data {
- if len(v.T_value) > 0 {
- continue
- }
- if InfoCollectionDataMap[v.T_name] == "" {
- continue
- }
- val := VerifyTemplate.VerifyTemplateMapData{
- T_source: T_source,
- T_task_id: task.T_task_id,
- T_VerifyTemplate_id: task.T_VerifyTemplate_id,
- T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
- T_flow_sort: v.T_flow_sort,
- T_max_time: v.T_max_time,
- T_min_time: v.T_min_time,
- T_value: InfoCollectionDataMap[v.T_name],
- }
- MapDataList = append(MapDataList, val)
- }
- var ids []int64
- ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 退回记录列表
- func (c *TaskController) AuditRecordList() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
- //T_task 驳回记录
- //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_state, _ := c.GetInt("T_state") // -1 获取全部
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- var auditRecordList []Task.AuditRecord
- switch T_type {
- case "T_task":
- T_state = -1
- if len(r.T_reject_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- case "T_scheme":
- if len(r.T_scheme_audit_record) > 0 {
- err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- case "T_collection":
- if len(r.T_collection_audit_record) > 0 {
- err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- case "T_reporting":
- if len(r.T_reporting_audit_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- }
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- var auditRecordList2 []Task.AuditRecord
- // 返回全部
- if T_state == -1 {
- for i := 0; i < len(auditRecordList); i++ {
- auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
- auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
- auditRecordList2 = append(auditRecordList2, auditRecordList[i])
- }
- c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- if T_state == -2 {
- for i := 0; i < len(auditRecordList); i++ {
- if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
- auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
- auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
- auditRecordList2 = append(auditRecordList2, auditRecordList[i])
- }
- }
- c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- for i := 0; i < len(auditRecordList); i++ {
- if auditRecordList[i].T_state == T_state {
- auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
- auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
- auditRecordList2 = append(auditRecordList2, auditRecordList[i])
- }
- }
- c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 存档生成图片
- func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: 1,
- Msg: "图片生成中",
- Url: "",
- })
- msg := ""
- state := 2
- url := ""
- if TemperatureMin == 0 {
- TemperatureMin = 2
- }
- if TemperatureMax == 0 {
- TemperatureMax = 8
- }
- var ymin, ymax float64
- var xminT, xmaxT time.Time
- if len(deviceList) > 0 {
- ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
- }
- // 创建一个新的绘图
- p := plot.New()
- // 设置绘图标题和标签
- p.Title.Text = "温度折线图"
- //p.Legend.ThumbnailWidth = 5 * vg.Inch
- p.X.Label.Text = "时间"
- p.Y.Label.Text = "温度"
- var chData = make(chan int, 10)
- var jobGroup sync.WaitGroup
- var device = make([]Device.DeviceCount, len(deviceList))
- // 创建温度线
- for i := 0; i < len(deviceList); i++ {
- chData <- 1
- jobGroup.Add(1)
- go func(index int) {
- //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
- defer func() {
- <-chData // 完成时chan取出1个
- jobGroup.Done() // 完成时将等待组值减1
- }()
- sn, id := deviceList[index].T_sn, deviceList[index].T_id
- ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
- if ymin > ymin_ {
- ymin = ymin_
- }
- if ymax < ymax_ {
- ymax = ymax_
- }
- if xminT.After(minTime_) && !minTime_.IsZero() {
- xminT = minTime_
- }
- if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
- xmaxT = maxTime_
- }
- r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
- device[index] = Device.DeviceCount{
- T_id: id,
- Num: r_maps_num,
- }
- if r_maps_num == 0 {
- return
- }
- pts := make(plotter.XYs, len(r_maps))
- for j, d := range r_maps {
- t, _ := lib.TimeStrToTime(d.T_time)
- pts[j].X = float64(t.Unix())
- pts[j].Y = float64(d.T_t)
- }
- line, err := plotter.NewLine(pts)
- if err != nil {
- return
- }
- line.Color = randomColor(index)
- p.Add(line)
- }(i)
- }
- jobGroup.Wait()
- xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
- // 添加最高,最低标准线 用红色虚线标识
- p.Add(horizontalLine(xmin, xmax, TemperatureMin))
- p.Add(horizontalLine(xmin, xmax, TemperatureMax))
- if ymax < 8 {
- ymax = 8
- }
- if ymin > 0 {
- ymin = 0
- }
- p.Y.Min, p.Y.Max = ymin, ymax
- p.X.Min, p.X.Max = xmin, xmax
- p.Y.Tick.Marker = commaTicks{}
- //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
- p.X.Tick.Marker = timeTicks{}
- p.X.Tick.Label.Rotation = math.Pi / 5
- p.X.Tick.Label.YAlign = draw.YCenter
- p.X.Tick.Label.XAlign = draw.XRight
- filename := "jpg" + time.Now().Format("20060102150405")
- // 保存文件
- if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: 3,
- Msg: "图片生成失败",
- Url: url,
- })
- logs.Error(lib.FuncName(), "生成图片失败", err)
- return
- }
- if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: 3,
- Msg: "图片上传七牛云失败",
- Url: url,
- })
- logs.Error(lib.FuncName(), "上传七牛云失败")
- return
- }
- //删除目录
- os.Remove("ofile/" + filename + ".jpg")
- msg = "图片生成成功"
- url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: state,
- Msg: msg,
- Url: url,
- Device: device,
- })
- return
- }
- func horizontalLine(xmin, xmax, y float64) *plotter.Line {
- pts := make(plotter.XYs, 2)
- pts[0].X = xmin
- pts[0].Y = y
- pts[1].X = xmax
- pts[1].Y = y
- line, err := plotter.NewLine(pts)
- if err != nil {
- panic(any(err))
- }
- line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
- line.Color = color.RGBA{R: 255, A: 255}
- return line
- }
- type timeTicks struct{}
- func (timeTicks) Ticks(min, max float64) []plot.Tick {
- tks := plot.TimeTicks{}.Ticks(min, max)
- for i, t := range tks {
- //if t.Label == "" { // Skip minor ticks, they are fine.
- // continue
- //}
- tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
- }
- return tks
- }
- type commaTicks struct{}
- // Ticks computes the default tick marks, but inserts commas
- // into the labels for the major tick marks.
- func (commaTicks) Ticks(min, max float64) []plot.Tick {
- tks := plot.DefaultTicks{}.Ticks(min, max)
- for i, t := range tks {
- //if t.Label == "" { // Skip minor ticks, they are fine.
- // continue
- //}
- tks[i].Label = fmt.Sprintf("%.0f", t.Value)
- }
- return tks
- }
- // 生成随机颜色的辅助函数
- func randomColor(i int) color.RGBA {
- var colors []color.RGBA
- colors = append(colors,
- color.RGBA{R: 52, G: 152, B: 219, A: 255},
- color.RGBA{R: 230, G: 126, B: 34, A: 255},
- color.RGBA{R: 142, G: 68, B: 173, A: 255},
- color.RGBA{R: 211, G: 84, B: 0, A: 255},
- color.RGBA{R: 231, G: 76, B: 60, A: 255},
- color.RGBA{R: 26, G: 188, B: 156, A: 255},
- color.RGBA{R: 243, G: 156, B: 18, A: 255},
- color.RGBA{R: 22, G: 160, B: 133, A: 255},
- color.RGBA{R: 46, G: 204, B: 113, A: 255},
- color.RGBA{R: 39, G: 174, B: 96, A: 255},
- color.RGBA{R: 41, G: 128, B: 185, A: 255},
- color.RGBA{R: 155, G: 89, B: 182, A: 255},
- color.RGBA{R: 192, G: 57, B: 43, A: 255},
- color.RGBA{R: 241, G: 196, B: 15, A: 255},
- )
- return colors[i%len(colors)]
- }
- // 获取加完水印的pdf
- func GetWatermarkPdf(task Task.Task, pdfURL string, flag string) (pdf string) {
- if len(pdfURL) == 0 {
- return
- }
- currentDirectory := lib.GetCurrentDirectory()
- scriptPath := currentDirectory + "/script"
- pdf_file_out_name := uuid.New().String() + ".pdf"
- pdfFilename := currentDirectory + "/ofile/" + uuid.New().String() + ".pdf"
- pdf_file_out := currentDirectory + "/ofile/watermark" + pdf_file_out_name
- watermark_pdf := currentDirectory + "/script/watermark.pdf"
- // 执行Python脚本
- cmd := exec.Command("python3", "add_watermark.py", pdfURL, pdfFilename, pdf_file_out, watermark_pdf)
- cmd.Dir = scriptPath
- // 获取命令输出
- _, err := cmd.CombinedOutput()
- if err != nil {
- logs.Error("执行python脚本添加水印错误:", err)
- return
- }
- lib.Pload_qiniu(pdf_file_out, pdf_file_out_name)
- if !lib.Pload_qiniu(pdf_file_out, pdf_file_out) {
- err = errors.New("上传水印pdf失败")
- return
- }
- defer func() {
- os.Remove(pdfFilename)
- os.Remove(pdf_file_out)
- }()
- pdf = "https://bzdcoldverifyoss.baozhida.cn/" + pdf_file_out_name
- switch flag {
- case "T_pdf1":
- task.T_pdf1_watermark = pdf
- Task.Update_Task(task, "T_pdf1_watermark")
- case "T_pdf2":
- task.T_pdf2_watermark = pdf
- Task.Update_Task(task, "T_pdf2_watermark")
- }
- return
- }
- // 暂停申请
- // 列表 -
- func (c *TaskController) TaskTimeList() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- T_task_id := c.GetString("T_task_id")
- T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
- var cnt int64
- List, cnt := Task.Read_TaskTime_List(T_task_id, T_task_type)
- r_jsons.List = List
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *TaskController) TaskTimeAdd() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- dc := Device.DeviceClass{
- T_uuid: User_r.T_uuid,
- T_State: 1,
- }
- System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", dc)
- T_task_id := c.GetString("T_task_id")
- T_task_type, _ := c.GetInt("T_task_type", 0) // 公司名称
- T_aaa := c.GetString("T_aaa")
- var_ := Task.TaskTime{
- T_task_id: T_task_id,
- T_task_type: T_task_type,
- T_uuid: User_r.T_uuid,
- T_remarks: T_aaa,
- T_start_time: time.Now().Format("2006-01-02 15:04:05"),
- }
- List, _ := Task.Read_TaskTime_List(T_task_id, T_task_type)
- if len(List) > 0 {
- if len(List[len(List)-1].T_end_time) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "上一个任务还没结束!"}
- c.ServeJSON()
- return
- }
- }
- is := Task.Add_TaskTime(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务暂停", "暂停申请", var_)
- System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停申请", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_task_id}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *TaskController) TaskTimeEnd() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- dc := Device.DeviceClass{
- T_uuid: User_r.T_uuid,
- T_State: 1,
- }
- System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", dc)
- Id, _ := c.GetInt("Id", 0)
- TaskTime_r, is := Task.Read_TaskTime_ById(Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- TaskTime_r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
- is = Task.Update_TaskTime(TaskTime_r, "T_end_time")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, TaskTime_r.T_task_id, "任务暂停", "暂停结束", TaskTime_r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务暂停", "暂停结束", TaskTime_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: TaskTime_r.T_task_id}
- c.ServeJSON()
- return
- }
- // 列表 - 统计排名
- func (c *TaskController) StatisticalRanking() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_power, _ := c.GetInt("T_power", 0) // 5 数据采集工程师 6 验证报告工程师
- type Admin_T struct {
- T_name string
- T_scheme int // 实施方案
- T_scheme_returnnum int // 退回
- T_scheme_overnum int // 超时
- T_scheme_log string // 日志
- T_collection int // 数据采集
- T_collection_returnnum int // 退回
- T_collection_overnum int // 超时
- T_collection_log string // 日志
- T_reporting int // 报告编写
- T_reporting_returnnum int // 退回
- T_reporting_overnum int // 超时
- T_reporting_log string // 日志
- T_rejectdnum int // 驳回数量
- }
- var Admin_T_List []Admin_T
- Admin_List := Account.Read_Admin_List_ALL_T_power(T_power)
- for _, A := range Admin_List {
- Admin_t := Admin_T{T_name: A.T_name}
- // 方案
- Task_List := Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_scheme") //T_scheme T_collection T_reporting
- for _, T := range Task_List {
- if len(T.T_scheme_end_time) > 0 {
- if is, _ := lib.IsInCurrentMonth(T.T_scheme_end_time); !is {
- continue // 不是本月
- }
- Admin_t.T_scheme += 1
- Admin_t.T_scheme_log += T.T_name
- // 退回
- if T.T_scheme_return_times > 0 {
- Admin_t.T_scheme_returnnum += T.T_scheme_return_times
- Admin_t.T_scheme_log += " | 退回"+ lib.To_string(int(T.T_scheme_return_times))
- }
- // 超时
- if T.T_scheme_overtime > 0 {
- Admin_t.T_scheme_overnum += 1
- Admin_t.T_scheme_log += " | 超时"+ lib.ConvertMinutesToDHM(int(T.T_scheme_overtime))
- }
- // 驳回
- if T.T_reject_times > 0 {
- Admin_t.T_rejectdnum += T.T_reject_times
- Admin_t.T_scheme_log += " | 驳回"+ lib.To_string(int(T.T_reject_times))
- }
- Admin_t.T_scheme_log += "\n"
- }
- }
- // 实施
- Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_collection") //T_scheme T_collection T_reporting
- for _, T := range Task_List {
- if len(T.T_collection_end_time) > 0 {
- if is, _ := lib.IsInCurrentMonth(T.T_collection_end_time); !is {
- continue // 不是本月
- }
- Admin_t.T_collection += 1
- Admin_t.T_collection_log += T.T_name
- // 退回
- if T.T_collection_return_times > 0 {
- Admin_t.T_collection_returnnum += T.T_collection_return_times
- Admin_t.T_collection_log += " | 退回"+ lib.To_string(int(T.T_collection_return_times))
- }
- // 超时
- if T.T_collection_overtime > 0 {
- Admin_t.T_collection_overnum += 1
- Admin_t.T_collection_log += " | 超时"+ lib.ConvertMinutesToDHM(int(T.T_collection_overtime))
- }
- // 驳回
- if T.T_reject_times > 0 {
- Admin_t.T_rejectdnum += T.T_reject_times
- Admin_t.T_collection_log += " | 驳回"+ lib.To_string(int(T.T_reject_times))
- }
- Admin_t.T_collection_log += "\n"
- }
- }
- // 报告
- Task_List = Task.Read_UserTask_StatisticalRanking(A.T_uuid, "T_reporting") //T_scheme T_collection T_reporting
- for _, T := range Task_List {
- if len(T.T_reporting_end_time) > 0 {
- if is, _ := lib.IsInCurrentMonth(T.T_reporting_end_time); !is {
- continue // 不是本月
- }
- Admin_t.T_reporting += 1
- Admin_t.T_reporting_log += T.T_name
- // 退回
- if T.T_reporting_return_times > 0 {
- Admin_t.T_reporting_returnnum += T.T_reporting_return_times
- Admin_t.T_reporting_log += " | 退回"+ lib.To_string(int(T.T_reporting_return_times))
- }
- // 超时
- if T.T_reporting_overtime > 0 {
- Admin_t.T_reporting_overnum += 1
- Admin_t.T_reporting_log += " | 超时"+ lib.ConvertMinutesToDHM(int(T.T_reporting_overtime))
- }
- // 驳回
- if T.T_reject_times > 0 {
- Admin_t.T_rejectdnum += T.T_reject_times
- Admin_t.T_reporting_log += " | 驳回"+ lib.To_string(int(T.T_reject_times))
- }
- Admin_t.T_reporting_log += "\n"
- }
- }
- Admin_T_List = append(Admin_T_List, Admin_t)
- }
- var r_jsons lib.R_JSONS
- r_jsons.List = Admin_T_List
- r_jsons.Page = 0
- r_jsons.Page_size = 0
- r_jsons.Pages = lib.Func_page(int64(0), int64(0))
- r_jsons.Num = 0
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
|