123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967 |
- 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
- }
- // 经销商下管理员可查看自己经销商下所有的任务
- // 经销商下其他角色只能查看分配给自己的任务
- if len(User_r.T_Distributor_id) > 0 && User_r.T_power <= 2 {
- T_admin = ""
- }
- var cnt int
- List, cnt := Task.Read_Task_List(User_r.T_Distributor_id, T_uuid, T_admin, T_name, T_InfoCollection_id, T_scheme, T_collection, T_reporting, T_delivery,
- 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(User_r.T_Distributor_id, 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(User_r.T_Distributor_id, 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") // 报告类型
- T_device_quantity, _ := c.GetInt("T_device_quantity") // 终端数量
- // 查询信息采集信息
- infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
- c.ServeJSON()
- return
- }
- // 查询信息采集信息
- user, is := Account.Read_User(T_uuid)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid 错误!"}
- c.ServeJSON()
- return
- }
- var_ := Task.Task{
- T_Distributor_id: user.T_Distributor_id,
- 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_device_quantity: T_device_quantity,
- }
- if T_report_number != "/" {
- _, exist := Task.Read_TaskbyT_report_number(T_report_number)
- if exist {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "报告编号已存在!"}
- c.ServeJSON()
- return
- }
- }
- 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)
- Task.Redis_Task_T_report_number_DelK(T_report_number) // 删除redis内的任务编号
- // 通知
- _, 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_device_quantity, _ := c.GetInt("T_device_quantity") // 报告编号
- 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(T_report_number) > 0 && T_report_number != "/" {
- t, exist := Task.Read_TaskbyT_report_number(T_report_number)
- if exist && r.T_task_id != t.T_task_id {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "报告编号已存在!"}
- 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 T_device_quantity > 0 {
- r.T_device_quantity = T_device_quantity
- clos = append(clos, "T_device_quantity")
- }
- 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 T_reporting_state == Task.TaskReportingStatePass {
- r.T_reporting_pass_time = time.Now().Format("2006-01-02 15:04:05")
- clos = append(clos, "T_reporting_pass_time")
- }
- 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,
- T_sn: sn,
- 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
- }
- // 复制-
- func (c *TaskController) Copy() {
- // 验证登录 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_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: "获取信息采集失败!"}
- 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)
- // 查询信息采集信息
- infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
- c.ServeJSON()
- return
- }
- var_ := Task.Task{
- T_Distributor_id: User_r.T_Distributor_id,
- T_InfoCollection_id: r.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: r.T_uuid,
- T_name: T_name,
- T_VerifyTemplate_class: r.T_VerifyTemplate_class,
- T_VerifyTemplate_id: r.T_VerifyTemplate_id,
- T_deadline: r.T_deadline,
- T_scheme: r.T_scheme,
- T_collection: r.T_collection,
- T_reporting: r.T_reporting,
- T_delivery: r.T_delivery,
- T_Show: 1,
- T_State: 1,
- T_project: r.T_project,
- T_province: r.T_province,
- T_city: r.T_city,
- T_district: r.T_district,
- T_province_code: r.T_province_code,
- T_city_code: r.T_city_code,
- T_district_code: r.T_district_code,
- T_category: r.T_category,
- T_device_type: r.T_device_type,
- T_volume: r.T_volume,
- T_verify_type: r.T_verify_type,
- T_subject_matter: r.T_subject_matter,
- T_temp_range: r.T_temp_range,
- T_report_type: r.T_report_type,
- T_device_quantity: r.T_device_quantity,
- }
- var_.T_report_number, _ = Task.GenerateNextT_report_number(var_.T_device_type)
- T_paste_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_paste_task_id)
- Task.Redis_Task_T_report_number_DelK(var_.T_report_number) // 删除redis内的任务编号
- // 复制验证模版数据
- Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(r.T_VerifyTemplate_id, 0, 0)
- copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_task_id, r.T_VerifyTemplate_id, Map_List)
- Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_paste_task_id, r.T_VerifyTemplate_id, Map_List)
- copyDataMap := make(map[string]string)
- for _, data := range copy_task_Data {
- copyDataMap[data.T_name] = data.T_value
- }
- MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
- for _, v := range Data {
- // 已有值则不复制
- if len(v.T_value) > 0 {
- continue
- }
- if copyDataMap[v.T_name] == "" {
- continue
- }
- val := VerifyTemplate.VerifyTemplateMapData{
- T_source: v.T_source,
- T_task_id: T_paste_task_id,
- T_VerifyTemplate_id: r.T_VerifyTemplate_id,
- T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
- T_Required: v.T_Required,
- T_Construction: v.T_Construction,
- T_flow_sort: v.T_flow_sort,
- T_max_time: v.T_max_time,
- T_min_time: v.T_min_time,
- T_value: copyDataMap[v.T_name],
- }
- MapDataList = append(MapDataList, val)
- }
- _, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制标签数据", MapDataList)
- // 通知
- _, 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_paste_task_id, "任务管理", "复制", var_)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_paste_task_id}
- c.ServeJSON()
- return
- }
- // 生成报告编号 设备类型+年+季度+递增编号
- func (c *TaskController) GenT_report_number() {
- // 验证登录 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_device_type := c.GetString("T_device_type")
- number, err := Task.GenerateNextT_report_number(T_device_type)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: number}
- c.ServeJSON()
- return
- }
- // 自动填写布点
- func (c *TaskController) Auto_fill_deploy() {
- // 验证登录 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_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
- }
- verifyTemplate, is := VerifyTemplate.Read_VerifyTemplate(task.T_VerifyTemplate_id)
- verifyTemplate_R := VerifyTemplate.VerifyTemplateToVerifyTemplate_R(verifyTemplate)
- Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
- MapData := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
- T_deploy_list := verifyTemplate_R.T_deploy_list
- //if len(T_deploy_list) == 0 {
- // // 解析设备列表备注的布点
- // deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, "")
- // for _, v := range deviceClassList {
- // splitList := lib.SplitStringSeparator(v.T_remark, "|")
- // for _, T_name := range splitList {
- // T_deploy_list = append(T_deploy_list, VerifyTemplate.VerifyTemplateDeploy{T_name: T_name})
- // }
- // }
- //}
- // 循环查询布点
- deployMap := make(map[string]string)
- for _, deploy := range T_deploy_list {
- deviceClassList := Device.Read_DeviceClassList_List_ByT_remark(task.T_class, deploy.T_name)
- var snList []string
- for _, v := range deviceClassList {
- snList = append(snList, v.T_sn)
- }
- deployMap[deploy.T_name] = strings.Join(snList, "|")
- }
- MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
- for _, v := range MapData {
- if snList, ok := deployMap[v.T_name]; ok {
- val := VerifyTemplate.VerifyTemplateMapData{
- T_source: v.T_source,
- T_task_id: task.T_task_id,
- T_VerifyTemplate_id: task.T_VerifyTemplate_id,
- T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
- T_Required: v.T_Required,
- T_Construction: v.T_Construction,
- T_flow_sort: v.T_flow_sort,
- T_max_time: v.T_max_time,
- T_min_time: v.T_min_time,
- T_value: snList,
- T_start_time: v.T_start_time,
- }
- MapDataList = append(MapDataList, val)
- }
- }
- ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, T_source, User_r.T_uuid)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "自动填写", ids)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
- c.ServeJSON()
- return
- }
- // SyncVerifyTemplateMapData 根据标签名称同步模版数据
- func (c *TaskController) SyncVerifyTemplateMapData() {
- T_copy_task_id := c.GetString("T_copy_task_id")
- T_paste_task_id := c.GetString("T_paste_task_id")
- T_source, _ := c.GetInt("T_source")
- copy_task, is := Task.Read_Task(T_copy_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- paste_task, is := Task.Read_Task(T_paste_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- copy_task_Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(copy_task.T_VerifyTemplate_id, 0, 0)
- copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_copy_task_id, copy_task.T_VerifyTemplate_id, copy_task_Map_List)
- Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(paste_task.T_VerifyTemplate_id, 0, 0)
- Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_paste_task_id, paste_task.T_VerifyTemplate_id, Map_List)
- copyDataMap := make(map[string]string)
- for _, data := range copy_task_Data {
- copyDataMap[data.T_name] = data.T_value
- }
- MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
- for _, v := range Data {
- if len(v.T_value) > 0 {
- continue
- }
- if copyDataMap[v.T_name] == "" {
- continue
- }
- val := VerifyTemplate.VerifyTemplateMapData{
- T_source: v.T_source,
- T_task_id: paste_task.T_task_id,
- T_VerifyTemplate_id: paste_task.T_VerifyTemplate_id,
- T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
- T_Required: v.T_Required,
- T_Construction: v.T_Construction,
- T_flow_sort: v.T_flow_sort,
- T_max_time: v.T_max_time,
- T_min_time: v.T_min_time,
- T_value: copyDataMap[v.T_name],
- }
- MapDataList = append(MapDataList, val)
- }
- var ids []int64
- ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "")
- 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) TaskData_Stat() {
- 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")
- 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
- }
- deviceList, _ := 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
- }
- 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
- _, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
- device[index] = Device.DeviceCount{
- T_id: id,
- T_sn: sn,
- Num: r_maps_num,
- }
- if r_maps_num == 0 {
- return
- }
- }(i)
- }
- jobGroup.Wait()
- c.Data["json"] = lib.JSONS{Data: device, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // SyncPDFWatermark 同步水印
- func (c *TaskController) SyncPDFWatermark() {
- //List, _ := Task.Read_Task_List_For_Watermark("pdf1")
- //for _, task := range List {
- // GetWatermarkPdf(task, task.T_pdf1, "T_pdf1")
- //}
- //List2, _ := Task.Read_Task_List_For_Watermark("pdf2")
- //for _, task := range List2 {
- // GetWatermarkPdf(task, task.T_pdf2, "T_pdf2")
- //}
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|