12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117 |
- package controllers
- import (
- "ColdVerify_server/Nats/NatsServer"
- "ColdVerify_server/conf"
- "ColdVerify_server/lib"
- "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 已完成
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var T_company_list []string
- if len(T_company) > 0 {
- T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
- }
- var T_admin string
- if User_r.T_power > 2 {
- T_admin = User_r.T_uuid
- }
- var cnt int
- List, cnt := Task.Read_Task_List(T_uuid, T_admin, T_name, T_InfoCollection_id, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
- T_company_list, UserMap, AdminMap, 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 已完成
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var T_company_list []string
- if len(T_company) > 0 {
- T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
- }
- var T_admin string
- if User_r.T_power > 2 {
- T_admin = User_r.T_uuid
- }
- var cnt int
- List, cnt := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
- T_company_list, UserMap, AdminMap, 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 已完成
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var T_company_list []string
- if len(T_company) > 0 {
- T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
- }
- var T_admin string
- if User_r.T_power > 2 {
- T_admin = User_r.T_uuid
- }
- List, _ := Task.Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id, T_project, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state,
- T_company_list, UserMap, AdminMap, 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.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)
- }
- 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)
- // 冻结1-2行
- f.SetPanes("Sheet1", &excelize.Panes{
- Freeze: true,
- Split: false,
- XSplit: 3,
- YSplit: 2,
- TopLeftCell: "A1",
- ActivePane: "topRight",
- })
- lib.Create_Dir("./ofile")
- timeStr := time.Now().Format("20060102150405")
- // 保存文件
- if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
- logs.Error(lib.FuncName(), err)
- }
- if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx") {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
- c.ServeJSON()
- return
- }
- //删除目录
- err := os.Remove("ofile/" + timeStr + ".xlsx")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + timeStr + ".xlsx"}
- c.ServeJSON()
- return
- }
- // 获取任务负责人列表
- func (c *TaskController) GetTaskUserList() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_type := c.GetString("T_type") // T_project项目 T_scheme方案 T_collection数据采集 T_reporting报告
- list := Task.Get_Task_UserList(T_type)
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var User_list []Account.Admin_R
- for _, v := range list {
- if len(v) == 0 {
- continue
- }
- User_list = append(User_list, Account.Admin_R{T_uuid: v, T_name: AdminMap[v]})
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_list}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *TaskController) UserTaskList() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var cnt int
- List, cnt := Task.Read_UserTask_List(User_r.T_uuid, T_name, UserMap, AdminMap, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = cnt
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 获取-
- func (c *TaskController) Get() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 添加浏览量
- _ = Task.Add_Task_Visit(r)
- r.T_Visit += 1
- userMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- adminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Task.TaskToTask_Stat(r, userMap, adminMap)}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *TaskController) Add() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- dc := Device.DeviceClass{
- T_uuid: User_r.T_uuid,
- T_State: 1,
- }
- T_class_id, is := Device.Add_DeviceClass(dc)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
- T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
- T_name := c.GetString("T_name")
- T_uuid := c.GetString("T_uuid") // 用户uuid
- T_VerifyTemplate_class := c.GetString("T_VerifyTemplate_class")
- T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
- T_deadline := c.GetString("T_deadline")
- T_scheme := c.GetString("T_scheme")
- T_collection := c.GetString("T_collection")
- T_reporting := c.GetString("T_reporting")
- T_delivery := c.GetString("T_delivery")
- T_project := c.GetString("T_project") // 项目 负责人UUID
- T_province := c.GetString("T_province") // 省
- T_city := c.GetString("T_city") // 市
- T_district := c.GetString("T_district") // 区
- T_province_code := c.GetString("T_province_code") // 省 code
- T_city_code := c.GetString("T_city_code") // 市 code
- T_district_code := c.GetString("T_district_code") // 区 code
- T_category := c.GetString("T_category") // 类别
- T_device_type := c.GetString("T_device_type") // 设备类型
- T_volume := c.GetString("T_volume") // 规格/容积
- T_verify_type := c.GetString("T_verify_type") // 验证类型
- T_subject_matter := c.GetString("T_subject_matter") // 标的物名称
- T_temp_range := c.GetString("T_temp_range") // 验证温度范围
- T_report_number := c.GetString("T_report_number") // 报告编号
- T_report_type := c.GetString("T_report_type") // 报告类型
- // 查询信息采集信息
- infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
- c.ServeJSON()
- return
- }
- var_ := Task.Task{
- T_InfoCollection_id: T_InfoCollection_id,
- T_InfoTemplate_id: infoCollection.T_InfoTemplate_id,
- T_start_time: infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
- T_class: int(T_class_id),
- T_uuid: T_uuid,
- T_name: T_name,
- T_VerifyTemplate_class: T_VerifyTemplate_class,
- T_VerifyTemplate_id: T_VerifyTemplate_id,
- T_deadline: T_deadline,
- T_scheme: T_scheme,
- T_collection: T_collection,
- T_reporting: T_reporting,
- T_delivery: T_delivery,
- T_Show: 1,
- T_State: 1,
- T_project: T_project,
- T_province: T_province,
- T_city: T_city,
- T_district: T_district,
- T_province_code: T_province_code,
- T_city_code: T_city_code,
- T_district_code: T_district_code,
- T_category: T_category,
- T_device_type: T_device_type,
- T_volume: T_volume,
- T_verify_type: T_verify_type,
- T_subject_matter: T_subject_matter,
- T_temp_range: T_temp_range,
- T_report_number: T_report_number,
- T_report_type: T_report_type,
- }
- T_task_id, is := Task.Add_Task(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- NatsServer.Create_Local_Table(T_task_id)
- // 添加任务操作日志
- 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")
- 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") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "接收信息采集", infoCollection)
- // 修改任务管理实施方案开始时间
- 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.T_scheme_start_time = time.Now().Format("2006-01-02 15:04:05")
- if !Task.Update_Task(task, "T_scheme_start_time") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- 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
- }
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- if T_collection_state == Task.TaskCollectionStateReturn ||
- T_collection_state == Task.TaskCollectionStatePass {
- System.Add_News(r.T_collection, fmt.Sprintf("【数据编辑】您提交的数据编辑【%s-%s】审核%s", company_r.T_name, r.T_name, Task.TaskCollectionStateMap[T_collection_state]), "")
- System.Send_Weichat_News(AdminMap[r.T_collection], fmt.Sprintf("【数据编辑】您提交的数据编辑【%s-%s】审核%s", company_r.T_name, r.T_name, Task.TaskCollectionStateMap[T_collection_state]), "")
- }
- // 添加任务操作日志
- 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 *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_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_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // .......
- clos := make([]string, 0)
- if len(T_name) > 0 {
- r.T_name = T_name
- clos = append(clos, "T_name")
- }
- if T_Show_err == nil {
- r.T_Show = T_Show
- clos = append(clos, "T_Show")
- }
- if len(T_VerifyTemplate_class) > 0 {
- r.T_VerifyTemplate_class = T_VerifyTemplate_class
- clos = append(clos, "T_VerifyTemplate_class")
- }
- if len(T_VerifyTemplate_id) > 0 {
- r.T_VerifyTemplate_id = T_VerifyTemplate_id
- clos = append(clos, "T_VerifyTemplate_id")
- }
- if len(T_deadline) > 0 {
- r.T_deadline = T_deadline
- clos = append(clos, "T_deadline")
- }
- if len(T_scheme) > 0 {
- r.T_scheme = T_scheme
- clos = append(clos, "T_scheme")
- }
- if len(T_collection) > 0 {
- r.T_collection = T_collection
- clos = append(clos, "T_collection")
- }
- if len(T_reporting) > 0 {
- r.T_reporting = T_reporting
- clos = append(clos, "T_reporting")
- }
- if len(T_delivery) > 0 {
- r.T_delivery = T_delivery
- clos = append(clos, "T_delivery")
- }
- // 完成编辑后设置实施结束时间
- if 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)
- 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_scheme_overtime")
- }
- }
- // 添加已提交状态数据编辑记录
- auditRecordJson, err := Task.Add_AuditRecord(r.T_collection_audit_record, "", User_r.T_uuid, r.T_collection_state, "", "")
- if err != nil {
- return
- }
- 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")
- if len(r.T_scheme_start_time) > 0 {
- r.T_scheme_time_interval, _ = lib.MinutesDifference(r.T_scheme_start_time, r.T_scheme_end_time)
- 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] // 超时时间
- clos = append(clos, "T_scheme_overtime")
- }
- }
- }
- 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 {
- return
- }
- 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")
- // 所需时间 > 超时时间
- 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] // 超时时间
- clos = append(clos, "T_reporting_overtime")
- }
- }
- }
- 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")
- }
- if len(T_sn) > 0 && len(T_CalibrationExpirationTime) > 0 {
- err := NatsServer.Cold_UpdateDevice_CalibrationTime(T_sn, T_CalibrationExpirationTime)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
- c.ServeJSON()
- return
- }
- }
- // 从3.0获取校准时间
- if len(T_sn) > 0 && len(T_CalibrationExpirationTime) == 0 {
- device, err := NatsServer.Cold_ReadDeviceByT_sn(T_sn)
- if err != nil {
- err = errors.New("获取SN信息失败,请检查SN是否正确!")
- c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
- c.ServeJSON()
- return
- }
- if !device.T_CalibrationTime.IsZero() {
- r.T_CalibrationExpirationTime = device.T_CalibrationTime.Format("2006-01-02")
- clos = append(clos, "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 !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.TaskSchemeStateClientReturn ||
- T_scheme_state == Task.TaskSchemeStateReturn ||
- T_scheme_state == Task.TaskSchemeStatePass ||
- T_scheme_state == Task.TaskSchemeStateClientPass {
- System.Add_News(r.T_scheme, fmt.Sprintf("【验证方案】您提交的验证方案【%s-%s】 %s", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
- System.Send_Weichat_News(AdminMap[r.T_scheme], fmt.Sprintf("【验证方案】您提交的验证方案【%s-%s】 %s", company_r.T_name, r.T_name, Task.TaskSchemeStateMap[T_scheme_state]), "")
- }
- if T_scheme_state == Task.TaskSchemeStateClientPass {
- System.Add_News(r.T_collection, fmt.Sprintf("【%s-%s】验证方案客户已通过,可以进场实施,请到平台进行查看验证方案,确认好后选择进场时间", company_r.T_name, r.T_name), "")
- System.Send_Weichat_News(AdminMap[r.T_collection], fmt.Sprintf("【%s-%s】验证方案客户已通过,可以进场实施,请到平台进行查看验证方案,确认好后选择进场时间", company_r.T_name, r.T_name), "")
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(operate_uuid, T_task_id, "任务管理", "修改验证方案状态", r)
- System.Add_UserLogs_T(operate_uuid, "任务管理", "修改验证方案状态", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 修改验证报告状态
- func (c *TaskController) UpReportingState() {
- Admin_r, Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !Admin_is && !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- operate_uuid := ""
- if Admin_is {
- operate_uuid = Admin_r.T_uuid
- }
- if User_is {
- operate_uuid = User_r.T_uuid
- }
- T_reporting_state, _ := c.GetInt("T_reporting_state") // 1 已完成(客户通过) 5已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人)
- T_reason := c.GetString("T_reason") // 退回原因
- T_signature := c.GetString("T_signature") // 通过后客户签名图片链接
- T_task_id := c.GetString("T_task_id")
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- _, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
- clos := make([]string, 0)
- if T_reporting_state > 0 {
- r.T_reporting_state = T_reporting_state
- clos = append(clos, "T_reporting_state")
- }
- if len(T_signature) > 0 {
- r.T_reporting_signature = T_signature
- clos = append(clos, "T_reporting_signature")
- }
- if T_reporting_state == Task.TaskReportingStateClientReturn || T_reporting_state == Task.TaskReportingStateReturn {
- r.T_reporting_return_times += 1
- clos = append(clos, "T_reporting_return_times")
- // 客户退回时新增驳回次数和驳回记录
- if T_reporting_state == Task.TaskReportingStateClientReturn {
- r.T_reject_times += 1
- var rejectRecordList []Task.AuditRecord
- if len(r.T_reject_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reject_record), &rejectRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- rejectRecordList = append(rejectRecordList, Task.AuditRecord{
- T_uuid: User_r.T_uuid,
- T_state: T_reporting_state,
- T_reason: T_reason,
- T_time: time.Now().Format("2006-01-02 15:04:05"),
- T_type: "reporting",
- })
- rejectRecordJson, err := json.Marshal(rejectRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- r.T_reject_record = string(rejectRecordJson)
- clos = append(clos, "T_reject_times")
- clos = append(clos, "T_reject_record")
- }
- }
- auditRecordJson, err := Task.Add_AuditRecord(r.T_reporting_audit_record, User_r.T_uuid, Admin_r.T_uuid, T_reporting_state, T_reason, "")
- if err != nil {
- return
- }
- r.T_reporting_audit_record = auditRecordJson
- clos = append(clos, "T_reporting_audit_record")
- // 验证报告客户审核通过后设置结束时间
- if T_reporting_state == Task.TaskReportingStateClientPass {
- r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
- r.T_time_interval, _ = lib.MinutesDifference(r.T_start_time, r.T_end_time)
- 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
- }
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- if T_reporting_state == Task.TaskSchemeStateClientReturn ||
- T_reporting_state == Task.TaskSchemeStateReturn ||
- T_reporting_state == Task.TaskSchemeStatePass ||
- T_reporting_state == Task.TaskSchemeStateClientPass {
- System.Add_News(r.T_scheme, fmt.Sprintf("【验证报告】您提交的验证报告【%s-%s】 %s", user_r.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
- System.Send_Weichat_News(AdminMap[r.T_scheme], fmt.Sprintf("【验证报告】您提交的验证报告【%s-%s】 %s", user_r.T_name, r.T_name, Task.TaskReportingStateMap[T_reporting_state]), "")
- }
- // 添加任务操作日志
- 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")
- 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
- }
- r.T_enter_area_time = T_time
- if !Task.Update_Task(r, "T_enter_area_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) StartVerify() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- T_time := c.GetString("T_time") // 进场时间
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if len(r.T_collection_start_time) == 0 {
- r.T_collection_start_time = T_time
- if !Task.Update_Task(r, "T_collection_start_time") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改实施开始时间失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "开始验证", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "开始验证", r)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除-
- func (c *TaskController) Del() {
- // 验证登录 User_is, User_r
- User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- if r, is := Task.Read_Task(T_task_id); is {
- if !Task.Delete_Task(r) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- // 添加任务操作日志
- Task.Add_TaskLogs_T(User_r.T_uuid, T_task_id, "任务管理", "删除", r)
- System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "删除", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *TaskController) Logs_List() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_task_id := c.GetString("T_task_id")
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- var cnt int
- List, cnt := Task.Read_TaskLogs_List(T_task_id, AdminMap, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = cnt
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 查询图片生成状态
- func (c *TaskController) DeviceData_JPGState() {
- T_task_id := c.GetString("T_task_id")
- T_remark := c.GetString("T_remark")
- jpg, is := Device.Redis_DeviceDataJPG_Get(T_task_id + T_remark)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 1202, Msg: "暂无图片正在生成"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
- c.ServeJSON()
- return
- }
- // 生成温度图片
- func (c *TaskController) DeviceData_JPG() {
- StartTime := c.GetString("StartTime")
- if len(StartTime) > 0 {
- _, ok := lib.TimeStrToTime(StartTime)
- if !ok {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
- c.ServeJSON()
- return
- }
- }
- EndTime := c.GetString("EndTime")
- if len(EndTime) > 0 {
- _, ok := lib.TimeStrToTime(EndTime)
- if !ok {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
- c.ServeJSON()
- return
- }
- } else {
- EndTime = time.Now().Format("2006-01-02 15:04:05")
- }
- T_remark := c.GetString("T_remark")
- TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
- TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
- if TemperatureMin == 0 {
- TemperatureMin = 2
- }
- if TemperatureMax == 0 {
- TemperatureMax = 8
- }
- T_task_id := c.GetString("T_task_id")
- Task_r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
- c.ServeJSON()
- return
- }
- if Task_r.T_collection_state == 2 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
- c.ServeJSON()
- return
- }
- deviceClassList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
- c.ServeJSON()
- return
- }
- Device.Redis_DeviceDataJPG_Del(T_task_id + T_remark)
- // 生成图片
- go DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark, deviceClassList, TemperatureMin, TemperatureMax)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // SyncInfoCollection 同步信息采集表
- func (c *TaskController) SyncInfoCollection() {
- T_task_id := c.GetString("T_task_id")
- T_source, _ := c.GetInt("T_source")
- task, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 获取信息采集表模版信息
- InfoCollection_Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(task.T_InfoTemplate_id)
- InfoCollection_Data := InfoCollection.Read_InfoTemplateMapData_List(task.T_InfoCollection_id, task.T_InfoTemplate_id, InfoCollection_Map_List)
- Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
- Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, task.T_VerifyTemplate_id, Map_List)
- InfoCollectionDataMap := make(map[string]string)
- for _, data := range InfoCollection_Data {
- InfoCollectionDataMap[data.T_name] = data.T_value
- }
- MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
- for _, v := range Data {
- if len(v.T_value) > 0 {
- continue
- }
- if InfoCollectionDataMap[v.T_name] == "" {
- continue
- }
- val := VerifyTemplate.VerifyTemplateMapData{
- T_source: T_source,
- T_task_id: task.T_task_id,
- T_VerifyTemplate_id: task.T_VerifyTemplate_id,
- T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
- T_flow_sort: v.T_flow_sort,
- T_max_time: v.T_max_time,
- T_min_time: v.T_min_time,
- T_value: InfoCollectionDataMap[v.T_name],
- }
- MapDataList = append(MapDataList, val)
- }
- var ids []int64
- ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Data: ids, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 退回记录列表
- func (c *TaskController) AuditRecordList() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_task_id := c.GetString("T_task_id")
- T_type := c.GetString("T_type") // T_task任务 T_scheme方案 T_collection数据采集 T_reporting报告
- //T_task 驳回记录
- //T_scheme 实施方案状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- //T_collection 数据采集状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- //T_reporting 报告编写状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_state, _ := c.GetInt("T_state") // -1 获取全部
- r, is := Task.Read_Task(T_task_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- var auditRecordList []Task.AuditRecord
- switch T_type {
- case "T_task":
- T_state = -1
- if len(r.T_reject_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reject_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- case "T_scheme":
- if len(r.T_scheme_audit_record) > 0 {
- err := json.Unmarshal([]byte(r.T_scheme_audit_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- case "T_collection":
- if len(r.T_collection_audit_record) > 0 {
- err := json.Unmarshal([]byte(r.T_collection_audit_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- case "T_reporting":
- if len(r.T_reporting_audit_record) > 0 {
- err := json.Unmarshal([]byte(r.T_reporting_audit_record), &auditRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return
- }
- }
- }
- AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
- UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
- var auditRecordList2 []Task.AuditRecord
- // 返回全部
- if T_state == -1 {
- for i := 0; i < len(auditRecordList); i++ {
- auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
- auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
- auditRecordList2 = append(auditRecordList2, auditRecordList[i])
- }
- c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- if T_state == -2 {
- for i := 0; i < len(auditRecordList); i++ {
- if auditRecordList[i].T_state == 2 || auditRecordList[i].T_state == 4 {
- auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
- auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
- auditRecordList2 = append(auditRecordList2, auditRecordList[i])
- }
- }
- c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- for i := 0; i < len(auditRecordList); i++ {
- if auditRecordList[i].T_state == T_state {
- auditRecordList[i].T_admin_name = AdminMap[auditRecordList[i].T_admin]
- auditRecordList[i].T_uuid_name = UserMap[auditRecordList[i].T_uuid]
- auditRecordList2 = append(auditRecordList2, auditRecordList[i])
- }
- }
- c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 存档生成图片
- func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []Device.DeviceClassList, TemperatureMin, TemperatureMax float64) {
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: 1,
- Msg: "图片生成中",
- Url: "",
- })
- msg := ""
- state := 2
- url := ""
- if TemperatureMin == 0 {
- TemperatureMin = 2
- }
- if TemperatureMax == 0 {
- TemperatureMax = 8
- }
- var ymin, ymax float64
- var xminT, xmaxT time.Time
- if len(deviceList) > 0 {
- ymin, ymax, xminT, xmaxT = Device.Read_DeviceData_T_Min_Max_Time_Min_Max(deviceList[0].T_sn, StartTime, EndTime)
- }
- // 创建一个新的绘图
- p := plot.New()
- // 设置绘图标题和标签
- p.Title.Text = "温度折线图"
- //p.Legend.ThumbnailWidth = 5 * vg.Inch
- p.X.Label.Text = "时间"
- p.Y.Label.Text = "温度"
- var chData = make(chan int, 10)
- var jobGroup sync.WaitGroup
- var device = make([]Device.DeviceCount, len(deviceList))
- // 创建温度线
- for i := 0; i < len(deviceList); i++ {
- chData <- 1
- jobGroup.Add(1)
- go func(index int) {
- //go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
- defer func() {
- <-chData // 完成时chan取出1个
- jobGroup.Done() // 完成时将等待组值减1
- }()
- sn, id := deviceList[index].T_sn, deviceList[index].T_id
- ymin_, ymax_, minTime_, maxTime_ := Device.Read_DeviceData_T_Min_Max_Time_Min_Max(sn, StartTime, EndTime)
- if ymin > ymin_ {
- ymin = ymin_
- }
- if ymax < ymax_ {
- ymax = ymax_
- }
- if xminT.After(minTime_) && !minTime_.IsZero() {
- xminT = minTime_
- }
- if xmaxT.Before(maxTime_) && !maxTime_.IsZero() {
- xmaxT = maxTime_
- }
- r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
- device[index] = Device.DeviceCount{
- T_id: id,
- Num: r_maps_num,
- }
- if r_maps_num == 0 {
- return
- }
- pts := make(plotter.XYs, len(r_maps))
- for j, d := range r_maps {
- t, _ := lib.TimeStrToTime(d.T_time)
- pts[j].X = float64(t.Unix())
- pts[j].Y = float64(d.T_t)
- }
- line, err := plotter.NewLine(pts)
- if err != nil {
- return
- }
- line.Color = randomColor(index)
- p.Add(line)
- }(i)
- }
- jobGroup.Wait()
- xmin, xmax := float64(xminT.Unix()), float64(xmaxT.Unix())
- // 添加最高,最低标准线 用红色虚线标识
- p.Add(horizontalLine(xmin, xmax, TemperatureMin))
- p.Add(horizontalLine(xmin, xmax, TemperatureMax))
- if ymax < 8 {
- ymax = 8
- }
- if ymin > 0 {
- ymin = 0
- }
- p.Y.Min, p.Y.Max = ymin, ymax
- p.X.Min, p.X.Max = xmin, xmax
- p.Y.Tick.Marker = commaTicks{}
- //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
- p.X.Tick.Marker = timeTicks{}
- p.X.Tick.Label.Rotation = math.Pi / 5
- p.X.Tick.Label.YAlign = draw.YCenter
- p.X.Tick.Label.XAlign = draw.XRight
- filename := "jpg" + time.Now().Format("20060102150405")
- // 保存文件
- if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: 3,
- Msg: "图片生成失败",
- Url: url,
- })
- logs.Error(lib.FuncName(), "生成图片失败", err)
- return
- }
- if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: 3,
- Msg: "图片上传七牛云失败",
- Url: url,
- })
- logs.Error(lib.FuncName(), "上传七牛云失败")
- return
- }
- //删除目录
- os.Remove("ofile/" + filename + ".jpg")
- msg = "图片生成成功"
- url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
- Device.Redis_DeviceDataJPG_Set(T_task_id+T_remark, Device.DeviceDataJPG{
- State: state,
- Msg: msg,
- Url: url,
- Device: device,
- })
- return
- }
- func horizontalLine(xmin, xmax, y float64) *plotter.Line {
- pts := make(plotter.XYs, 2)
- pts[0].X = xmin
- pts[0].Y = y
- pts[1].X = xmax
- pts[1].Y = y
- line, err := plotter.NewLine(pts)
- if err != nil {
- panic(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
- }
|