123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523 |
- package util
- import (
- "../../models"
- "../../pkg/logging"
- "../../pkg/setting"
- "fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
- "github.com/jordan-wright/email"
- "github.com/robfig/cron"
- "log"
- "net/smtp"
- "os"
- "strconv"
- "strings"
- "time"
- )
- // 邮件相关(现代牧业暂未启用)
- func SendMail() {
- defer func(){ // 必须要先声明defer
- if err:=recover();err!=nil{
- logging.Error(" SendMail pnic err",err) // 这里的err其实就是panic传入的内容,55
- }
- }()
- log.Println("******** ******* *******", time.Now())
- e := email.NewEmail()
- // 发件人
- fromName := ""
- pas := ""
- mails := make([]string, 0)
- Engine := models.Engine
- subject := ""
- note := ""
- mailreport, err := Engine.SQL("select * from mailreport where enable = 1").Query().List()
- if err != nil {
- println("err sql", err.Error())
- } else {
- for _, value := range mailreport {
- //GetMailDataByPasture("集团设备指标",value["name"].(string),value["id"],A,f)
- //GetPastureDeptData(value["name"].(string),value["id"],f)
- if value["type"].(string) == "1" {
- fromName = value["addr"].(string)
- pas = value["pas"].(string)
- subject = value["title"].(string)
- note = value["note"].(string)
- } else {
- mails = append(mails, value["addr"].(string))
- }
- println(value["addr"].(string))
- }
- }
- // 发件人
- //e.From = "864919639@qq.com"
- e.From = fromName
- // 收件人(可以有多个)
- e.To = mails
- //e.To = []string{"18322596935@163.com","1406599862@qq.com"} //"1406599862@qq.com"
- // 邮件主题
- //e.Subject = "集团设备指标报表"
- e.Subject = subject
- // 解析html模板
- //t,err := template.ParseFiles("email-template.html")
- //body := new(bytes.Buffer)
- // Execute方法将解析好的模板应用到匿名结构体上,并将输出写入body中
- e.Text = []byte(note)
- // html形式的消息
- //body.Write([]byte("测试"))
- //// 从缓冲中将内容作为附件到邮件中
- //e.Attach(body, "email-template.html", "text/html")
- // 以路径将文件作为附件添加到邮件中
- //_,err := GetMailData()
- filename :=setting.CurrentPath+ "uploads/mailreport/" + time.Now().Format("2006-01-02") + "集团设备指标.xlsx"
- e.AttachFile(filename)
- // 发送邮件(如果使用QQ邮箱发送邮件的话,passwd不是邮箱密码而是授权码)
- err = e.Send("smtp.qq.com:587", smtp.PlainAuth("", fromName, pas, "smtp.qq.com"))
- if err != nil {
- println("sent err", err.Error())
- } else {
- println("发送成功")
- }
- }
- func CronMail() {
- log.Println("Starting Cron...")
- defer func() { // 必须要先声明defer
- if err := recover(); err != nil {
- fmt.Printf("CronTest pnic err%+v \n", err)
- logging.Error("panic recover err ", err)
- //println("pnic err",err.(error).Error()) // 这里的err其实就是panic传入的内容,55
- }
- }()
- c := cron.New()
- _, err := c.AddFunc(setting.ServerSetting.CronFormula, SendMail) //2 * * * * *, 2 表示每分钟的第2s执行一次
- if err != nil {
- println("cron1 err", err.Error())
- _, err = c.AddFunc("0 9 * * *", SendMail) //2 * * * * *, 2 表示每分钟的第2s执行一次
- if err != nil {
- println("cron2 err", err.Error())
- } else {
- println("开始启动定时任务发送邮件 0 9 * * *")
- }
- } else {
- println("开始启动定时任务发送邮件 ", setting.ServerSetting.CronFormula)
- }
- _, err = c.AddFunc("0 1 * * *", GetMailData) //2 * * * * *, 2 表示每分钟的第2s执行一次
- if err != nil {
- println("cron3 err", err.Error())
- }
- //_, err = c.AddFunc("30 * * * *", GetMailData) //2 * * * * *, 2 表示每分钟的第2s执行一次
- //if err != nil {
- // println("cron4 err", err.Error())
- //}
- c.Start()
- }
- func GetMailData() {
- defer func(){ // 必须要先声明defer
- if err:=recover();err!=nil{
- logging.Error("GetMailData pnic err",err) // 这里的err其实就是panic传入的内容,55
- }
- }()
- f := excelize.NewFile()
- f.SetSheetName("Sheet1", "集团设备指标")
- //f.GetSheetMap()
- //f.NewSheet("集团设备指标")
- //f.SetSheetVisible(,false)
- //隐藏名称为 Sheet1 的工作表中的 D 至 F 列:
- //f.SetColVisible("Sheet1", "D:F", false)
- //根据给定的工作表名称(大小写敏感)、列范围和宽度值设置单个或多个列的宽度。
- //例如设置名为 Sheet1 工作表上 A 到 D 列的宽度为 20:
- // 设置单元格的值
- //style, err := f.NewStyle(`{"fill":{"type":"center"}}`)
- //if err != nil {
- // fmt.Println(err)
- //}
- //f.SetCellStyle("集团设备指标", "B1", "M1", style)
- //
- //f.MergeCell("集团设备指标", "N1", "T1")
- //err := f.SetSheetRow("集团设备指标", "B1", &[]interface{}{"1月", nil,nil,nil,nil,nil,nil,"2月", nil,nil,nil,nil,nil,nil,
- // "3月", nil,nil,nil,nil,nil,nil,"4月", nil,nil,nil,nil,nil,nil,"5月", nil,nil,nil,nil,nil,nil,"6月", nil,nil,nil,nil,nil,nil,"1月", nil,nil,nil,nil,nil,nil,
- // "1月", nil,nil,nil,nil,nil,nil,"1月", nil,nil,nil,nil,nil,nil,"1月", nil,nil,nil,nil,nil,nil,"1月", nil,nil,nil,nil,nil,nil,"1月", nil,nil,nil,nil,nil,nil})
- tem := make([]interface{}, 0)
- tem1 := make([]interface{}, 0)
- c := []interface{}{}
- d := []interface{}{}
- e := []interface{}{}
- g := []interface{}{}
- h := []interface{}{}
- o := []interface{}{}
- p := []interface{}{}
- r := []interface{}{}
- for i := 1; i <= 12; i++ {
- a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
- b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
- c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- tem = append(tem, a...)
- tem1 = append(tem1, b...)
- }
- //d := c
- //e := c
- //g := c
- //h := c
- //o := c
- //p := c
- if err := f.SetSheetRow("集团设备指标", "N1", &tem); err != nil {
- println(err.Error())
- }
- year := time.Now().Add(-24 * time.Hour).Format("2006")
- f.SetCellValue("集团设备指标", "A1", "时间")
- f.MergeCell("集团设备指标", "B1", "M1")
- f.MergeCell("集团设备指标", "N1", "T1")
- f.MergeCell("集团设备指标", "U1", "AA1")
- f.MergeCell("集团设备指标", "AB1", "AH1")
- f.MergeCell("集团设备指标", "AI1", "AO1")
- f.MergeCell("集团设备指标", "AP1", "AV1")
- f.MergeCell("集团设备指标", "AW1", "BC1")
- f.MergeCell("集团设备指标", "BD1", "BJ1")
- f.MergeCell("集团设备指标", "BK1", "BQ1")
- f.MergeCell("集团设备指标", "BR1", "BX1")
- f.MergeCell("集团设备指标", "BY1", "CE1")
- f.MergeCell("集团设备指标", "CF1", "CL1")
- f.MergeCell("集团设备指标", "CM1", "CS1")
- f.SetCellValue("集团设备指标", "H1", year+"年")
- f.SetSheetRow("集团设备指标", "A2", &[]interface{}{"牧场", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率", "迄今饲养头日", "迄今产量(公斤)", "迄今实际单头牛成本", "迄今实际公斤奶成本(元/公斤)"})
- if err := f.SetSheetRow("集团设备指标", "N2", &tem1); err != nil {
- println(err.Error())
- }
- Engine := models.Engine
- A := 3
- pastures, err := Engine.SQL("select id,name from pasture where isdel = 0 AND id <> 18 order by sort").Query().List()
- if err != nil {
- println("err sql", err.Error())
- } else {
- for _, value := range pastures {
- GetMailDataByPasture("集团设备指标", value["name"].(string), time.Now().Format("2006-01-02"), value["id"], A, f)
- GetPastureDeptData(value["name"].(string), value["id"], f)
- println(value["name"].(string))
- A = A + 8
- }
- }
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJY").QueryString()
- valuesMap1, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJM").QueryString()
- sqls := ""
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = time.Now().Format("2006-01-02")
- s_params := make([]interface{}, 0)
- if err == nil && len(valuesMap) > 0 {
- sqls = valuesMap[0]["sqlstr"]
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- tem = []interface{}{}
- //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
- values, err := Engine.SQL(sqls, s_params...).Query().List()
- B := A
- //if err==nil {
- // for _, value := range values {
- // tem = append(tem,value["ftype"])
- // tem = append(tem,value["monthBudget"])
- // tem = append(tem,value["monthLimit"])
- // tem = append(tem,value["qmonthBudget"])
- // tem = append(tem,value["sumPrice"])
- // tem = append(tem,value["asave"])
- // tem = append(tem,value["dac"])
- // tem = append(tem,value["dacY"])
- // tem = append(tem,value["cowNum"])
- // tem = append(tem,value["saleNum"])
- // tem = append(tem,value["cowprice"])
- // tem = append(tem,value["milkprice"])
- // if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B),&tem); err != nil {
- // println(err.Error())
- // }
- // tem = []interface{}{}
- // B++
- // }
- //}else {
- // println(err.Error())
- //}
- temMap := make(map[string][]interface{}, 0)
- if err == nil {
- for _, value := range values {
- tem = append(tem, value["ftype"])
- tem = append(tem, value["monthBudget"])
- tem = append(tem, value["monthLimit"])
- tem = append(tem, value["qmonthBudget"])
- tem = append(tem, value["sumPrice"])
- tem = append(tem, value["asave"])
- tem = append(tem, value["dac"])
- tem = append(tem, value["dacY"])
- tem = append(tem, value["cowNum"])
- tem = append(tem, value["saleNum"])
- tem = append(tem, value["cowprice"])
- tem = append(tem, value["milkprice"])
- temMap[value["ftype"].(string)] = tem
- //if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B),&tem); err != nil {
- // println(err.Error())
- //}
- tem = []interface{}{}
- //B++
- }
- } else {
- println(err.Error())
- }
- if m, ok := temMap["维修费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"维修费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["燃动费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"燃动费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["水费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"水费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["设备指标(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"设备指标(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电量(度)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电量(度)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["用水量(吨)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"用水量(吨)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["柴油用量(L)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"柴油用量(L)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- s_params = make([]interface{}, 0)
- if err == nil && len(valuesMap1) > 0 {
- sqls = valuesMap1[0]["sqlstr"]
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = time.Now().Format("2006-01-02")
- paramslist := strings.Split(valuesMap1[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap1[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- f.SetCellValue("集团设备指标", "A"+strconv.Itoa(A), "集团")
- f.MergeCell("集团设备指标", "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
- values, err = Engine.SQL(sqls, s_params...).Query().List()
- tem = []interface{}{}
- //d := append(c,nil)
- //e := append(c,nil)
- //g := append(c,nil)
- //h := append(c,nil)
- //o := append(c,nil)
- //p := append(c,nil)
- tem2 := []interface{}{}
- if err == nil {
- for _, value := range values {
- tem2 = append(tem2, value["monthBudget"])
- tem2 = append(tem2, value["monthLimit"])
- tem2 = append(tem2, value["qmonthBudget"])
- tem2 = append(tem2, value["sumPrice"])
- tem2 = append(tem2, value["asave"])
- tem2 = append(tem2, value["dac"])
- tem2 = append(tem2, value["dacY"])
- num, _ := strconv.Atoi(value["num"].(string))
- switch value["ftype"] {
- case "维修费(万元)":
- c[(num-1)*7] = tem2[0]
- c[(num-1)*7+1] = tem2[1]
- c[(num-1)*7+2] = tem2[2]
- c[(num-1)*7+3] = tem2[3]
- c[(num-1)*7+4] = tem2[4]
- c[(num-1)*7+5] = tem2[5]
- c[(num-1)*7+6] = tem2[6]
- case "电费(万元)":
- d[(num-1)*7] = tem2[0]
- d[(num-1)*7+1] = tem2[1]
- d[(num-1)*7+2] = tem2[2]
- d[(num-1)*7+3] = tem2[3]
- d[(num-1)*7+4] = tem2[4]
- d[(num-1)*7+5] = tem2[5]
- d[(num-1)*7+6] = tem2[6]
- case "燃动费(万元)":
- e[(num-1)*7] = tem2[0]
- e[(num-1)*7+1] = tem2[1]
- e[(num-1)*7+2] = tem2[2]
- e[(num-1)*7+3] = tem2[3]
- e[(num-1)*7+4] = tem2[4]
- e[(num-1)*7+5] = tem2[5]
- e[(num-1)*7+6] = tem2[6]
- case "水费(万元)":
- g[(num-1)*7] = tem2[0]
- g[(num-1)*7+1] = tem2[1]
- g[(num-1)*7+2] = tem2[2]
- g[(num-1)*7+3] = tem2[3]
- g[(num-1)*7+4] = tem2[4]
- g[(num-1)*7+5] = tem2[5]
- g[(num-1)*7+6] = tem2[6]
- case "电量(度)":
- h[(num-1)*7] = tem2[0]
- h[(num-1)*7+1] = tem2[1]
- h[(num-1)*7+2] = tem2[2]
- h[(num-1)*7+3] = tem2[3]
- h[(num-1)*7+4] = tem2[4]
- h[(num-1)*7+5] = tem2[5]
- h[(num-1)*7+6] = tem2[6]
- case "柴油用量(L)":
- o[(num-1)*7] = tem2[0]
- o[(num-1)*7+1] = tem2[1]
- o[(num-1)*7+2] = tem2[2]
- o[(num-1)*7+3] = tem2[3]
- o[(num-1)*7+4] = tem2[4]
- o[(num-1)*7+5] = tem2[5]
- o[(num-1)*7+6] = tem2[6]
- case "用水量(吨)":
- p[(num-1)*7] = tem2[0]
- p[(num-1)*7+1] = tem2[1]
- p[(num-1)*7+2] = tem2[2]
- p[(num-1)*7+3] = tem2[3]
- p[(num-1)*7+4] = tem2[4]
- p[(num-1)*7+5] = tem2[5]
- p[(num-1)*7+6] = tem2[6]
- case "设备指标(万元)":
- r[(num-1)*7] = tem2[0]
- r[(num-1)*7+1] = tem2[1]
- r[(num-1)*7+2] = tem2[2]
- r[(num-1)*7+3] = tem2[3]
- r[(num-1)*7+4] = tem2[4]
- r[(num-1)*7+5] = tem2[5]
- r[(num-1)*7+6] = tem2[6]
- }
- tem2 = []interface{}{}
- }
- } else {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A), &c); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+1), &d); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+2), &e); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+3), &g); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+4), &r); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+5), &h); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+6), &p); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+7), &o); err != nil {
- println(err.Error())
- }
- //sums[2] = sums[2].(int)+value["monthLimit"].(int)
- //sums[1] = sums[1].(int)+value["monthBudget"].(int)
- // 设置月份单元格字体
- monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
- if err != nil {
- println("monthStyle err", err.Error())
- }
- f.SetCellStyle("集团设备指标", "A1", "CS154", monthStyle)
- // 根据指定路径保存文件
- filename := setting.CurrentPath+ "uploads/mailreport/" + time.Now().Format("2006-01-02") + "集团设备指标.xlsx"
- err = PathCheck(setting.CurrentPath+ "uploads/mailreport") //检查路径并创建
- os.Remove(filename)
- if err != nil {
- println("PathCheck err", err)
- }
- if err := f.SaveAs(filename); err != nil {
- println(err.Error())
- }
- }
- func GetMailDataByPasture(sheetName, pastureName, date string, pastureId interface{}, B int, f *excelize.File) {
- tem := make([]interface{}, 0)
- tem1 := make([]interface{}, 0)
- c := []interface{}{}
- d := []interface{}{}
- e := []interface{}{}
- g := []interface{}{}
- h := []interface{}{}
- o := []interface{}{}
- p := []interface{}{}
- r := []interface{}{}
- for i := 1; i <= 12; i++ {
- a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
- b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
- c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- tem = append(tem, a...)
- tem1 = append(tem1, b...)
- }
- Engine := models.Engine
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMY").QueryString()
- valuesMap1, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMM").QueryString()
- sqls := ""
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- parammaps["pastureId"] = pastureId
- s_params := make([]interface{}, 0)
- if err == nil && len(valuesMap) > 0 {
- sqls = valuesMap[0]["sqlstr"]
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- f.SetCellValue(sheetName, "A"+strconv.Itoa(B), pastureName)
- f.MergeCell(sheetName, "A"+strconv.Itoa(B), "A"+strconv.Itoa(B+7))
- tem = []interface{}{}
- temMap := make(map[string][]interface{}, 0)
- //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
- values, err := Engine.SQL(sqls, s_params...).Query().List()
- Bt := B
- if err == nil {
- for _, value := range values {
- tem = append(tem, value["ftype"])
- tem = append(tem, value["monthBudget"])
- tem = append(tem, value["monthLimit"])
- tem = append(tem, value["qmonthBudget"])
- tem = append(tem, value["sumPrice"])
- tem = append(tem, value["asave"])
- tem = append(tem, value["dac"])
- tem = append(tem, value["dacY"])
- tem = append(tem, value["cowNum"])
- tem = append(tem, value["saleNum"])
- tem = append(tem, value["cowprice"])
- tem = append(tem, value["milkprice"])
- temMap[value["ftype"].(string)] = tem
- //if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt),&tem); err != nil {
- // println(err.Error())
- //}
- tem = []interface{}{}
- //Bt++
- }
- } else {
- println(err.Error())
- }
- if m, ok := temMap["维修费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"维修费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["电费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"电费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["燃动费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"燃动费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["水费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"水费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["设备指标(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"设备指标(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["电量(度)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"电量(度)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["用水量(吨)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"用水量(吨)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["柴油用量(L)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"柴油用量(L)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- s_params = make([]interface{}, 0)
- if err == nil && len(valuesMap1) > 0 {
- sqls = valuesMap1[0]["sqlstr"]
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- parammaps["pastureId"] = pastureId
- paramslist := strings.Split(valuesMap1[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap1[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- values, err = Engine.SQL(sqls, s_params...).Query().List()
- tem = []interface{}{}
- //d := append(c,nil)
- //e := append(c,nil)
- //g := append(c,nil)
- //h := append(c,nil)
- //o := append(c,nil)
- //p := append(c,nil)
- tem2 := []interface{}{}
- if err == nil {
- for _, value := range values {
- tem2 = append(tem2, value["monthBudget"])
- tem2 = append(tem2, value["monthLimit"])
- tem2 = append(tem2, value["qmonthBudget"])
- tem2 = append(tem2, value["sumPrice"])
- tem2 = append(tem2, value["asave"])
- tem2 = append(tem2, value["dac"])
- tem2 = append(tem2, value["dacY"])
- num, _ := strconv.Atoi(value["num"].(string))
- switch value["ftype"] {
- case "维修费(万元)":
- c[(num-1)*7] = tem2[0]
- c[(num-1)*7+1] = tem2[1]
- c[(num-1)*7+2] = tem2[2]
- c[(num-1)*7+3] = tem2[3]
- c[(num-1)*7+4] = tem2[4]
- c[(num-1)*7+5] = tem2[5]
- c[(num-1)*7+6] = tem2[6]
- case "电费(万元)":
- d[(num-1)*7] = tem2[0]
- d[(num-1)*7+1] = tem2[1]
- d[(num-1)*7+2] = tem2[2]
- d[(num-1)*7+3] = tem2[3]
- d[(num-1)*7+4] = tem2[4]
- d[(num-1)*7+5] = tem2[5]
- d[(num-1)*7+6] = tem2[6]
- case "燃动费(万元)":
- e[(num-1)*7] = tem2[0]
- e[(num-1)*7+1] = tem2[1]
- e[(num-1)*7+2] = tem2[2]
- e[(num-1)*7+3] = tem2[3]
- e[(num-1)*7+4] = tem2[4]
- e[(num-1)*7+5] = tem2[5]
- e[(num-1)*7+6] = tem2[6]
- case "水费(万元)":
- g[(num-1)*7] = tem2[0]
- g[(num-1)*7+1] = tem2[1]
- g[(num-1)*7+2] = tem2[2]
- g[(num-1)*7+3] = tem2[3]
- g[(num-1)*7+4] = tem2[4]
- g[(num-1)*7+5] = tem2[5]
- g[(num-1)*7+6] = tem2[6]
- case "电量(度)":
- h[(num-1)*7] = tem2[0]
- h[(num-1)*7+1] = tem2[1]
- h[(num-1)*7+2] = tem2[2]
- h[(num-1)*7+3] = tem2[3]
- h[(num-1)*7+4] = tem2[4]
- h[(num-1)*7+5] = tem2[5]
- h[(num-1)*7+6] = tem2[6]
- case "柴油用量(L)":
- o[(num-1)*7] = tem2[0]
- o[(num-1)*7+1] = tem2[1]
- o[(num-1)*7+2] = tem2[2]
- o[(num-1)*7+3] = tem2[3]
- o[(num-1)*7+4] = tem2[4]
- o[(num-1)*7+5] = tem2[5]
- o[(num-1)*7+6] = tem2[6]
- case "用水量(吨)":
- p[(num-1)*7] = tem2[0]
- p[(num-1)*7+1] = tem2[1]
- p[(num-1)*7+2] = tem2[2]
- p[(num-1)*7+3] = tem2[3]
- p[(num-1)*7+4] = tem2[4]
- p[(num-1)*7+5] = tem2[5]
- p[(num-1)*7+6] = tem2[6]
- case "设备指标(万元)":
- r[(num-1)*7] = tem2[0]
- r[(num-1)*7+1] = tem2[1]
- r[(num-1)*7+2] = tem2[2]
- r[(num-1)*7+3] = tem2[3]
- r[(num-1)*7+4] = tem2[4]
- r[(num-1)*7+5] = tem2[5]
- r[(num-1)*7+6] = tem2[6]
- }
- tem2 = []interface{}{}
- }
- } else {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B), &c); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+1), &d); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+2), &e); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+3), &g); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+4), &r); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+5), &h); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+6), &p); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "N"+strconv.Itoa(B+7), &o); err != nil {
- println(err.Error())
- }
- }
- func GetMailDataByDept(sheetName, DeptName, date string, DeptId, pastureId interface{}, B int, f *excelize.File) {
- tem := make([]interface{}, 0)
- tem1 := make([]interface{}, 0)
- c := []interface{}{}
- d := []interface{}{}
- e := []interface{}{}
- g := []interface{}{}
- h := []interface{}{}
- o := []interface{}{}
- p := []interface{}{}
- r := []interface{}{}
- for i := 1; i <= 12; i++ {
- a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
- b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
- c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- tem = append(tem, a...)
- tem1 = append(tem1, b...)
- }
- Engine := models.Engine
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportBY").QueryString()
- valuesMap1, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportBM").QueryString()
- sqls := ""
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- parammaps["pastureId"] = pastureId
- parammaps["departmentId"] = DeptId
- s_params := make([]interface{}, 0)
- if err == nil && len(valuesMap) > 0 {
- sqls = valuesMap[0]["sqlstr"]
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- f.SetCellValue(sheetName, "A"+strconv.Itoa(B), DeptName)
- f.MergeCell(sheetName, "A"+strconv.Itoa(B), "A"+strconv.Itoa(B+7))
- tem = []interface{}{}
- temMap := make(map[string][]interface{}, 0)
- //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
- values, err := Engine.SQL(sqls, s_params...).Query().List()
- Bt := B
- if err == nil {
- for _, value := range values {
- tem = append(tem, value["ftype"])
- tem = append(tem, value["monthBudget"])
- tem = append(tem, value["monthLimit"])
- tem = append(tem, value["qmonthBudget"])
- tem = append(tem, value["sumPrice"])
- tem = append(tem, value["asave"])
- tem = append(tem, value["dac"])
- tem = append(tem, value["dacY"])
- tem = append(tem, value["cowNum"])
- tem = append(tem, value["saleNum"])
- tem = append(tem, value["cowprice"])
- tem = append(tem, value["milkprice"])
- temMap[value["ftype"].(string)] = tem
- //if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt),&tem); err != nil {
- // println(err.Error())
- //}
- tem = []interface{}{}
- //Bt++
- }
- } else {
- println(err.Error())
- }
- if m, ok := temMap["维修费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"维修费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["电费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"电费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["燃动费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"燃动费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["水费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"水费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["设备指标(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"设备指标(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["电量(度)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"电量(度)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["用水量(吨)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"用水量(吨)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- if m, ok := temMap["柴油用量(L)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
- println(err.Error())
- }
- Bt++
- } else {
- temw := []interface{}{"柴油用量(L)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
- println(err.Error())
- }
- Bt++
- }
- s_params = make([]interface{}, 0)
- if err == nil && len(valuesMap1) > 0 {
- sqls = valuesMap1[0]["sqlstr"]
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- parammaps["pastureId"] = pastureId
- parammaps["departmentId"] = DeptId
- paramslist := strings.Split(valuesMap1[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap1[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- values, err = Engine.SQL(sqls, s_params...).Query().List()
- tem = []interface{}{}
- //d := append(c,nil)
- //e := append(c,nil)
- //g := append(c,nil)
- //h := append(c,nil)
- //o := append(c,nil)
- //p := append(c,nil)
- tem2 := []interface{}{}
- if err == nil {
- for _, value := range values {
- //fmt.Printf("va============== %+v\n",value)
- tem2 = append(tem2, value["monthBudget"])
- tem2 = append(tem2, value["monthLimit"])
- tem2 = append(tem2, value["qmonthBudget"])
- tem2 = append(tem2, value["sumPrice"])
- tem2 = append(tem2, value["asave"])
- tem2 = append(tem2, value["dac"])
- tem2 = append(tem2, value["dacY"])
- num := 1
- if _, ok := value["num"]; ok {
- num, _ = strconv.Atoi(value["num"].(string))
- }
- switch value["ftype"] {
- case "维修费(万元)":
- c[(num-1)*7] = tem2[0]
- c[(num-1)*7+1] = tem2[1]
- c[(num-1)*7+2] = tem2[2]
- c[(num-1)*7+3] = tem2[3]
- c[(num-1)*7+4] = tem2[4]
- c[(num-1)*7+5] = tem2[5]
- c[(num-1)*7+6] = tem2[6]
- case "电费(万元)":
- d[(num-1)*7] = tem2[0]
- d[(num-1)*7+1] = tem2[1]
- d[(num-1)*7+2] = tem2[2]
- d[(num-1)*7+3] = tem2[3]
- d[(num-1)*7+4] = tem2[4]
- d[(num-1)*7+5] = tem2[5]
- d[(num-1)*7+6] = tem2[6]
- case "燃动费(万元)":
- e[(num-1)*7] = tem2[0]
- e[(num-1)*7+1] = tem2[1]
- e[(num-1)*7+2] = tem2[2]
- e[(num-1)*7+3] = tem2[3]
- e[(num-1)*7+4] = tem2[4]
- e[(num-1)*7+5] = tem2[5]
- e[(num-1)*7+6] = tem2[6]
- case "水费(万元)":
- g[(num-1)*7] = tem2[0]
- g[(num-1)*7+1] = tem2[1]
- g[(num-1)*7+2] = tem2[2]
- g[(num-1)*7+3] = tem2[3]
- g[(num-1)*7+4] = tem2[4]
- g[(num-1)*7+5] = tem2[5]
- g[(num-1)*7+6] = tem2[6]
- case "电量(度)":
- h[(num-1)*7] = tem2[0]
- h[(num-1)*7+1] = tem2[1]
- h[(num-1)*7+2] = tem2[2]
- h[(num-1)*7+3] = tem2[3]
- h[(num-1)*7+4] = tem2[4]
- h[(num-1)*7+5] = tem2[5]
- h[(num-1)*7+6] = tem2[6]
- case "柴油用量(L)":
- o[(num-1)*7] = tem2[0]
- o[(num-1)*7+1] = tem2[1]
- o[(num-1)*7+2] = tem2[2]
- o[(num-1)*7+3] = tem2[3]
- o[(num-1)*7+4] = tem2[4]
- o[(num-1)*7+5] = tem2[5]
- o[(num-1)*7+6] = tem2[6]
- case "用水量(吨)":
- p[(num-1)*7] = tem2[0]
- p[(num-1)*7+1] = tem2[1]
- p[(num-1)*7+2] = tem2[2]
- p[(num-1)*7+3] = tem2[3]
- p[(num-1)*7+4] = tem2[4]
- p[(num-1)*7+5] = tem2[5]
- p[(num-1)*7+6] = tem2[6]
- case "设备指标(万元)":
- r[(num-1)*7] = tem2[0]
- r[(num-1)*7+1] = tem2[1]
- r[(num-1)*7+2] = tem2[2]
- r[(num-1)*7+3] = tem2[3]
- r[(num-1)*7+4] = tem2[4]
- r[(num-1)*7+5] = tem2[5]
- r[(num-1)*7+6] = tem2[6]
- }
- tem2 = []interface{}{}
- }
- } else {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B), &c); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+1), &d); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+2), &e); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+3), &g); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+4), &r); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+5), &h); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+6), &p); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(B+7), &o); err != nil {
- println(err.Error())
- }
- }
- func GetPastureDeptData(sheetName string, pastureId interface{}, f *excelize.File) {
- f.NewSheet(sheetName)
- tem := make([]interface{}, 0)
- tem1 := make([]interface{}, 0)
- c := []interface{}{}
- d := []interface{}{}
- e := []interface{}{}
- g := []interface{}{}
- h := []interface{}{}
- o := []interface{}{}
- p := []interface{}{}
- r := []interface{}{}
- for i := 1; i <= 12; i++ {
- a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
- b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
- c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- tem = append(tem, a...)
- tem1 = append(tem1, b...)
- }
- //d := c
- //e := c
- //g := c
- //h := c
- //o := c
- //p := c
- if err := f.SetSheetRow(sheetName, "J1", &tem); err != nil {
- println(err.Error())
- }
- year := time.Now().Add(-24 * time.Hour).Format("2006")
- f.SetCellValue(sheetName, "A1", "时间")
- f.MergeCell(sheetName, "B1", "I1")
- f.MergeCell(sheetName, "J1", "P1")
- f.MergeCell(sheetName, "Q1", "W1")
- f.MergeCell(sheetName, "X1", "AD1")
- f.MergeCell(sheetName, "AE1", "AK1")
- f.MergeCell(sheetName, "AL1", "AR1")
- f.MergeCell(sheetName, "AS1", "AY1")
- f.MergeCell(sheetName, "AZ1", "BF1")
- f.MergeCell(sheetName, "BG1", "BM1")
- f.MergeCell(sheetName, "BN1", "BT1")
- f.MergeCell(sheetName, "BU1", "CA1")
- f.MergeCell(sheetName, "CB1", "CH1")
- f.MergeCell(sheetName, "CI1", "CO1")
- f.SetCellValue(sheetName, "H1", year+"年")
- f.SetSheetRow(sheetName, "A2", &[]interface{}{"部门", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率"})
- if err := f.SetSheetRow(sheetName, "J2", &tem1); err != nil {
- println(err.Error())
- }
- Engine := models.Engine
- A := 3
- pastures, err := Engine.SQL("select id,name from department where pastureId=? and isDel = 0 AND enable =1 and id <> ?", pastureId, pastureId).Query().List()
- if err != nil {
- println("err sql", err.Error())
- } else {
- for _, value := range pastures {
- GetMailDataByDept(sheetName, value["name"].(string), time.Now().Format("2006-01-02"), value["id"], pastureId, A, f)
- println(value["name"].(string))
- A = A + 8
- }
- }
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMY").QueryString()
- valuesMap1, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMM").QueryString()
- sqls := ""
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = time.Now().Format("2006-01-02")
- parammaps["pastureId"] = pastureId
- s_params := make([]interface{}, 0)
- if err == nil && len(valuesMap) > 0 {
- sqls = valuesMap[0]["sqlstr"]
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- tem = []interface{}{}
- //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
- values, err := Engine.SQL(sqls, s_params...).Query().List()
- B := A
- temMap := make(map[string][]interface{}, 0)
- if err == nil {
- for _, value := range values {
- tem = append(tem, value["ftype"])
- tem = append(tem, value["monthBudget"])
- tem = append(tem, value["monthLimit"])
- tem = append(tem, value["qmonthBudget"])
- tem = append(tem, value["sumPrice"])
- tem = append(tem, value["asave"])
- tem = append(tem, value["dac"])
- tem = append(tem, value["dacY"])
- temMap[value["ftype"].(string)] = tem
- //if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B),&tem); err != nil {
- // println(err.Error())
- //}
- tem = []interface{}{}
- //B++
- }
- } else {
- println(err.Error())
- }
- if m, ok := temMap["维修费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"维修费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["燃动费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"燃动费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["水费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"水费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["设备指标(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"设备指标(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电量(度)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电量(度)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["用水量(吨)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"用水量(吨)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["柴油用量(L)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"柴油用量(L)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- s_params = make([]interface{}, 0)
- if err == nil && len(valuesMap1) > 0 {
- sqls = valuesMap1[0]["sqlstr"]
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = time.Now().Format("2006-01-02")
- parammaps["pastureId"] = pastureId
- paramslist := strings.Split(valuesMap1[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap1[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- f.SetCellValue(sheetName, "A"+strconv.Itoa(A), sheetName)
- f.MergeCell(sheetName, "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
- values, err = Engine.SQL(sqls, s_params...).Query().List()
- tem = []interface{}{}
- //d := append(c,nil)
- //e := append(c,nil)
- //g := append(c,nil)
- //h := append(c,nil)
- //o := append(c,nil)
- //p := append(c,nil)
- tem2 := []interface{}{}
- if err == nil {
- for _, value := range values {
- tem2 = append(tem2, value["monthBudget"])
- tem2 = append(tem2, value["monthLimit"])
- tem2 = append(tem2, value["qmonthBudget"])
- tem2 = append(tem2, value["sumPrice"])
- tem2 = append(tem2, value["asave"])
- tem2 = append(tem2, value["dac"])
- tem2 = append(tem2, value["dacY"])
- num, _ := strconv.Atoi(value["num"].(string))
- switch value["ftype"] {
- case "维修费(万元)":
- c[(num-1)*7] = tem2[0]
- c[(num-1)*7+1] = tem2[1]
- c[(num-1)*7+2] = tem2[2]
- c[(num-1)*7+3] = tem2[3]
- c[(num-1)*7+4] = tem2[4]
- c[(num-1)*7+5] = tem2[5]
- c[(num-1)*7+6] = tem2[6]
- case "电费(万元)":
- d[(num-1)*7] = tem2[0]
- d[(num-1)*7+1] = tem2[1]
- d[(num-1)*7+2] = tem2[2]
- d[(num-1)*7+3] = tem2[3]
- d[(num-1)*7+4] = tem2[4]
- d[(num-1)*7+5] = tem2[5]
- d[(num-1)*7+6] = tem2[6]
- case "燃动费(万元)":
- e[(num-1)*7] = tem2[0]
- e[(num-1)*7+1] = tem2[1]
- e[(num-1)*7+2] = tem2[2]
- e[(num-1)*7+3] = tem2[3]
- e[(num-1)*7+4] = tem2[4]
- e[(num-1)*7+5] = tem2[5]
- e[(num-1)*7+6] = tem2[6]
- case "水费(万元)":
- g[(num-1)*7] = tem2[0]
- g[(num-1)*7+1] = tem2[1]
- g[(num-1)*7+2] = tem2[2]
- g[(num-1)*7+3] = tem2[3]
- g[(num-1)*7+4] = tem2[4]
- g[(num-1)*7+5] = tem2[5]
- g[(num-1)*7+6] = tem2[6]
- case "电量(度)":
- h[(num-1)*7] = tem2[0]
- h[(num-1)*7+1] = tem2[1]
- h[(num-1)*7+2] = tem2[2]
- h[(num-1)*7+3] = tem2[3]
- h[(num-1)*7+4] = tem2[4]
- h[(num-1)*7+5] = tem2[5]
- h[(num-1)*7+6] = tem2[6]
- case "柴油用量(L)":
- o[(num-1)*7] = tem2[0]
- o[(num-1)*7+1] = tem2[1]
- o[(num-1)*7+2] = tem2[2]
- o[(num-1)*7+3] = tem2[3]
- o[(num-1)*7+4] = tem2[4]
- o[(num-1)*7+5] = tem2[5]
- o[(num-1)*7+6] = tem2[6]
- case "用水量(吨)":
- p[(num-1)*7] = tem2[0]
- p[(num-1)*7+1] = tem2[1]
- p[(num-1)*7+2] = tem2[2]
- p[(num-1)*7+3] = tem2[3]
- p[(num-1)*7+4] = tem2[4]
- p[(num-1)*7+5] = tem2[5]
- p[(num-1)*7+6] = tem2[6]
- case "设备指标(万元)":
- r[(num-1)*7] = tem2[0]
- r[(num-1)*7+1] = tem2[1]
- r[(num-1)*7+2] = tem2[2]
- r[(num-1)*7+3] = tem2[3]
- r[(num-1)*7+4] = tem2[4]
- r[(num-1)*7+5] = tem2[5]
- r[(num-1)*7+6] = tem2[6]
- }
- tem2 = []interface{}{}
- }
- } else {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A), &c); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+1), &d); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+2), &e); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+3), &g); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+4), &r); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+5), &h); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+6), &p); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+7), &o); err != nil {
- println(err.Error())
- }
- //sums[2] = sums[2].(int)+value["monthLimit"].(int)
- //sums[1] = sums[1].(int)+value["monthBudget"].(int)
- // 设置月份单元格字体
- monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
- if err != nil {
- println("monthStyle err", err.Error())
- }
- f.SetCellStyle(sheetName, "A1", "CS300", monthStyle)
- // 根据指定路径保存文件
- }
- func PathCheck(path string) (err error) {
- b, err := PathExists(path)
- if err != nil {
- println("exist err", err)
- }
- if !b {
- err = os.Mkdir(path, 0777)
- if err != nil {
- println("Mkdir err", err)
- }
- }
- return
- }
- func PathExists(path string) (bool, error) {
- _, err := os.Stat(path)
- if err == nil {
- return true, nil
- }
- if os.IsNotExist(err) {
- return false, nil
- }
- return false, err
- }
- func DownloadDataJT(date string) (string, error) {
- filename := setting.CurrentPath+"uploads/Downloadmailreport/" + date + "集团设备指标.xlsx"
- exist, _ := FileExists(filename)
- println(filename,exist)
- if exist {
- //return filename, nil
- }
- f := excelize.NewFile()
- f.SetSheetName("Sheet1", "集团设备指标")
- tem := make([]interface{}, 0)
- tem1 := make([]interface{}, 0)
- c := []interface{}{}
- d := []interface{}{}
- e := []interface{}{}
- g := []interface{}{}
- h := []interface{}{}
- o := []interface{}{}
- p := []interface{}{}
- r := []interface{}{}
- for i := 1; i <= 12; i++ {
- a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
- b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
- c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- tem = append(tem, a...)
- tem1 = append(tem1, b...)
- }
- if err := f.SetSheetRow("集团设备指标", "N1", &tem); err != nil {
- println(err.Error())
- }
- //year :=time.Now().Add(-24*time.Hour).Format("2006")
- year := ""
- datetem, _ := strconv.Atoi(date[:4])
- if date > time.Now().Add(-24*time.Hour).Format("2006")+"-01-01" {
- year = strconv.Itoa(datetem)
- } else {
- year = strconv.Itoa(datetem - 1)
- }
- f.SetCellValue("集团设备指标", "A1", "时间")
- f.MergeCell("集团设备指标", "B1", "M1")
- f.MergeCell("集团设备指标", "N1", "T1")
- f.MergeCell("集团设备指标", "U1", "AA1")
- f.MergeCell("集团设备指标", "AB1", "AH1")
- f.MergeCell("集团设备指标", "AI1", "AO1")
- f.MergeCell("集团设备指标", "AP1", "AV1")
- f.MergeCell("集团设备指标", "AW1", "BC1")
- f.MergeCell("集团设备指标", "BD1", "BJ1")
- f.MergeCell("集团设备指标", "BK1", "BQ1")
- f.MergeCell("集团设备指标", "BR1", "BX1")
- f.MergeCell("集团设备指标", "BY1", "CE1")
- f.MergeCell("集团设备指标", "CF1", "CL1")
- f.MergeCell("集团设备指标", "CM1", "CS1")
- f.SetCellValue("集团设备指标", "H1", year+"年")
- f.SetSheetRow("集团设备指标", "A2", &[]interface{}{"牧场", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率", "迄今饲养头日", "迄今产量(公斤)", "迄今实际单头牛成本", "迄今实际公斤奶成本(元/公斤)"})
- if err := f.SetSheetRow("集团设备指标", "N2", &tem1); err != nil {
- println(err.Error())
- }
- Engine := models.Engine
- A := 3
- pastures, err := Engine.SQL("select id,name from pasture where isdel = 0 AND id <> 18 order by sort").Query().List()
- if err != nil {
- println("err sql", err.Error())
- } else {
- for _, value := range pastures {
- GetMailDataByPasture("集团设备指标", value["name"].(string), date, value["id"], A, f)
- println(value["name"].(string))
- A = A + 8
- }
- }
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJY").QueryString()
- valuesMap1, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJM").QueryString()
- sqls := ""
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- s_params := make([]interface{}, 0)
- if err == nil && len(valuesMap) > 0 {
- sqls = valuesMap[0]["sqlstr"]
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- tem = []interface{}{}
- values, err := Engine.SQL(sqls, s_params...).Query().List()
- B := A
- temMap := make(map[string][]interface{}, 0)
- if err == nil {
- for _, value := range values {
- tem = append(tem, value["ftype"])
- tem = append(tem, value["monthBudget"])
- tem = append(tem, value["monthLimit"])
- tem = append(tem, value["qmonthBudget"])
- tem = append(tem, value["sumPrice"])
- tem = append(tem, value["asave"])
- tem = append(tem, value["dac"])
- tem = append(tem, value["dacY"])
- tem = append(tem, value["cowNum"])
- tem = append(tem, value["saleNum"])
- tem = append(tem, value["cowprice"])
- tem = append(tem, value["milkprice"])
- temMap[value["ftype"].(string)] = tem
- tem = []interface{}{}
- //B++
- }
- } else {
- println(err.Error())
- }
- if m, ok := temMap["维修费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"维修费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["燃动费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"燃动费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["水费(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"水费(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["设备指标(万元)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"设备指标(万元)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电量(度)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电量(度)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["用水量(吨)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"用水量(吨)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["柴油用量(L)"]; ok {
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"柴油用量(L)"}
- if err := f.SetSheetRow("集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- s_params = make([]interface{}, 0)
- if err == nil && len(valuesMap1) > 0 {
- sqls = valuesMap1[0]["sqlstr"]
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- paramslist := strings.Split(valuesMap1[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap1[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- f.SetCellValue("集团设备指标", "A"+strconv.Itoa(A), "集团")
- f.MergeCell("集团设备指标", "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
- values, err = Engine.SQL(sqls, s_params...).Query().List()
- tem = []interface{}{}
- tem2 := []interface{}{}
- if err == nil {
- for _, value := range values {
- tem2 = append(tem2, value["monthBudget"])
- tem2 = append(tem2, value["monthLimit"])
- tem2 = append(tem2, value["qmonthBudget"])
- tem2 = append(tem2, value["sumPrice"])
- tem2 = append(tem2, value["asave"])
- tem2 = append(tem2, value["dac"])
- tem2 = append(tem2, value["dacY"])
- num, _ := strconv.Atoi(value["num"].(string))
- switch value["ftype"] {
- case "维修费(万元)":
- c[(num-1)*7] = tem2[0]
- c[(num-1)*7+1] = tem2[1]
- c[(num-1)*7+2] = tem2[2]
- c[(num-1)*7+3] = tem2[3]
- c[(num-1)*7+4] = tem2[4]
- c[(num-1)*7+5] = tem2[5]
- c[(num-1)*7+6] = tem2[6]
- case "电费(万元)":
- d[(num-1)*7] = tem2[0]
- d[(num-1)*7+1] = tem2[1]
- d[(num-1)*7+2] = tem2[2]
- d[(num-1)*7+3] = tem2[3]
- d[(num-1)*7+4] = tem2[4]
- d[(num-1)*7+5] = tem2[5]
- d[(num-1)*7+6] = tem2[6]
- case "燃动费(万元)":
- e[(num-1)*7] = tem2[0]
- e[(num-1)*7+1] = tem2[1]
- e[(num-1)*7+2] = tem2[2]
- e[(num-1)*7+3] = tem2[3]
- e[(num-1)*7+4] = tem2[4]
- e[(num-1)*7+5] = tem2[5]
- e[(num-1)*7+6] = tem2[6]
- case "水费(万元)":
- g[(num-1)*7] = tem2[0]
- g[(num-1)*7+1] = tem2[1]
- g[(num-1)*7+2] = tem2[2]
- g[(num-1)*7+3] = tem2[3]
- g[(num-1)*7+4] = tem2[4]
- g[(num-1)*7+5] = tem2[5]
- g[(num-1)*7+6] = tem2[6]
- case "电量(度)":
- h[(num-1)*7] = tem2[0]
- h[(num-1)*7+1] = tem2[1]
- h[(num-1)*7+2] = tem2[2]
- h[(num-1)*7+3] = tem2[3]
- h[(num-1)*7+4] = tem2[4]
- h[(num-1)*7+5] = tem2[5]
- h[(num-1)*7+6] = tem2[6]
- case "柴油用量(L)":
- o[(num-1)*7] = tem2[0]
- o[(num-1)*7+1] = tem2[1]
- o[(num-1)*7+2] = tem2[2]
- o[(num-1)*7+3] = tem2[3]
- o[(num-1)*7+4] = tem2[4]
- o[(num-1)*7+5] = tem2[5]
- o[(num-1)*7+6] = tem2[6]
- case "用水量(吨)":
- p[(num-1)*7] = tem2[0]
- p[(num-1)*7+1] = tem2[1]
- p[(num-1)*7+2] = tem2[2]
- p[(num-1)*7+3] = tem2[3]
- p[(num-1)*7+4] = tem2[4]
- p[(num-1)*7+5] = tem2[5]
- p[(num-1)*7+6] = tem2[6]
- case "设备指标(万元)":
- r[(num-1)*7] = tem2[0]
- r[(num-1)*7+1] = tem2[1]
- r[(num-1)*7+2] = tem2[2]
- r[(num-1)*7+3] = tem2[3]
- r[(num-1)*7+4] = tem2[4]
- r[(num-1)*7+5] = tem2[5]
- r[(num-1)*7+6] = tem2[6]
- }
- tem2 = []interface{}{}
- }
- } else {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A), &c); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+1), &d); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+2), &e); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+3), &g); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+4), &r); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+5), &h); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+6), &p); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow("集团设备指标", "N"+strconv.Itoa(A+7), &o); err != nil {
- println(err.Error())
- }
- // 设置月份单元格字体
- monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
- if err != nil {
- println("monthStyle err", err.Error())
- }
- f.SetCellStyle("集团设备指标", "A1", "CS154", monthStyle)
- // 根据指定路径保存文件
- err = PathCheck("uploads/Downloadmailreport") //检查路径并创建
- //os.Remove(filename)
- if err != nil {
- println("PathCheck err", err)
- }
- if err := f.SaveAs(filename); err != nil {
- println(err.Error())
- return "", err
- }
- return filename, err
- }
- func DownloadDataMC(sheetName, date string, pastureId interface{}) (string, error) {
- filename := setting.CurrentPath+ "uploads/Downloadmailreport/" + date + sheetName + "设备指标.xlsx"
- exist, _ := FileExists(filename)
- if exist {
- //return filename, nil
- }
- f := excelize.NewFile()
- f.SetSheetName("Sheet1", sheetName)
- tem := make([]interface{}, 0)
- tem1 := make([]interface{}, 0)
- c := []interface{}{}
- d := []interface{}{}
- e := []interface{}{}
- g := []interface{}{}
- h := []interface{}{}
- o := []interface{}{}
- p := []interface{}{}
- r := []interface{}{}
- for i := 1; i <= 12; i++ {
- a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
- b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
- c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
- tem = append(tem, a...)
- tem1 = append(tem1, b...)
- }
- if err := f.SetSheetRow(sheetName, "J1", &tem); err != nil {
- println(err.Error())
- }
- year := ""
- datetem, _ := strconv.Atoi(date[:4])
- if date > time.Now().Add(-24*time.Hour).Format("2006")+"-01-01" {
- year = strconv.Itoa(datetem)
- } else {
- year = strconv.Itoa(datetem - 1)
- }
- f.SetCellValue(sheetName, "A1", "时间")
- f.MergeCell(sheetName, "B1", "I1")
- f.MergeCell(sheetName, "J1", "P1")
- f.MergeCell(sheetName, "Q1", "W1")
- f.MergeCell(sheetName, "X1", "AD1")
- f.MergeCell(sheetName, "AE1", "AK1")
- f.MergeCell(sheetName, "AL1", "AR1")
- f.MergeCell(sheetName, "AS1", "AY1")
- f.MergeCell(sheetName, "AZ1", "BF1")
- f.MergeCell(sheetName, "BG1", "BM1")
- f.MergeCell(sheetName, "BN1", "BT1")
- f.MergeCell(sheetName, "BU1", "CA1")
- f.MergeCell(sheetName, "CB1", "CH1")
- f.MergeCell(sheetName, "CI1", "CO1")
- f.SetCellValue(sheetName, "H1", year+"年")
- f.SetSheetRow(sheetName, "A2", &[]interface{}{"部门", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率"})
- if err := f.SetSheetRow(sheetName, "J2", &tem1); err != nil {
- println(err.Error())
- }
- Engine := models.Engine
- A := 3
- pastures, err := Engine.SQL("select id,name from department where pastureId=? and isDel = 0 AND enable =1 and id <> ?", pastureId, pastureId).Query().List()
- if err != nil {
- println("err sql", err.Error())
- } else {
- for _, value := range pastures {
- GetMailDataByDept(sheetName, value["name"].(string), date, value["id"], pastureId, A, f)
- println(value["name"].(string))
- A = A + 8
- }
- }
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMY").QueryString()
- valuesMap1, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMM").QueryString()
- sqls := ""
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- parammaps["pastureId"] = pastureId
- s_params := make([]interface{}, 0)
- if err == nil && len(valuesMap) > 0 {
- sqls = valuesMap[0]["sqlstr"]
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- tem = []interface{}{}
- //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
- values, err := Engine.SQL(sqls, s_params...).Query().List()
- B := A
- temMap := make(map[string][]interface{}, 0)
- if err == nil {
- for _, value := range values {
- tem = append(tem, value["ftype"])
- tem = append(tem, value["monthBudget"])
- tem = append(tem, value["monthLimit"])
- tem = append(tem, value["qmonthBudget"])
- tem = append(tem, value["sumPrice"])
- tem = append(tem, value["asave"])
- tem = append(tem, value["dac"])
- tem = append(tem, value["dacY"])
- temMap[value["ftype"].(string)] = tem
- //if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B),&tem); err != nil {
- // println(err.Error())
- //}
- tem = []interface{}{}
- //B++
- }
- } else {
- println(err.Error())
- }
- if m, ok := temMap["维修费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"维修费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["燃动费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"燃动费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["水费(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"水费(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["设备指标(万元)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"设备指标(万元)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["电量(度)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"电量(度)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["用水量(吨)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"用水量(吨)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- if m, ok := temMap["柴油用量(L)"]; ok {
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &m); err != nil {
- println(err.Error())
- }
- B++
- } else {
- temw := []interface{}{"柴油用量(L)"}
- if err := f.SetSheetRow(sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
- println(err.Error())
- }
- B++
- }
- s_params = make([]interface{}, 0)
- if err == nil && len(valuesMap1) > 0 {
- sqls = valuesMap1[0]["sqlstr"]
- parammaps := make(map[string]interface{}, 0)
- parammaps["month"] = date
- parammaps["pastureId"] = pastureId
- paramslist := strings.Split(valuesMap1[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap1[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps[strings.Trim(value, " ")])
- }
- }
- }
- f.SetCellValue(sheetName, "A"+strconv.Itoa(A), sheetName)
- f.MergeCell(sheetName, "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
- values, err = Engine.SQL(sqls, s_params...).Query().List()
- tem = []interface{}{}
- //d := append(c,nil)
- //e := append(c,nil)
- //g := append(c,nil)
- //h := append(c,nil)
- //o := append(c,nil)
- //p := append(c,nil)
- tem2 := []interface{}{}
- if err == nil {
- for _, value := range values {
- tem2 = append(tem2, value["monthBudget"])
- tem2 = append(tem2, value["monthLimit"])
- tem2 = append(tem2, value["qmonthBudget"])
- tem2 = append(tem2, value["sumPrice"])
- tem2 = append(tem2, value["asave"])
- tem2 = append(tem2, value["dac"])
- tem2 = append(tem2, value["dacY"])
- num, _ := strconv.Atoi(value["num"].(string))
- switch value["ftype"] {
- case "维修费(万元)":
- c[(num-1)*7] = tem2[0]
- c[(num-1)*7+1] = tem2[1]
- c[(num-1)*7+2] = tem2[2]
- c[(num-1)*7+3] = tem2[3]
- c[(num-1)*7+4] = tem2[4]
- c[(num-1)*7+5] = tem2[5]
- c[(num-1)*7+6] = tem2[6]
- case "电费(万元)":
- d[(num-1)*7] = tem2[0]
- d[(num-1)*7+1] = tem2[1]
- d[(num-1)*7+2] = tem2[2]
- d[(num-1)*7+3] = tem2[3]
- d[(num-1)*7+4] = tem2[4]
- d[(num-1)*7+5] = tem2[5]
- d[(num-1)*7+6] = tem2[6]
- case "燃动费(万元)":
- e[(num-1)*7] = tem2[0]
- e[(num-1)*7+1] = tem2[1]
- e[(num-1)*7+2] = tem2[2]
- e[(num-1)*7+3] = tem2[3]
- e[(num-1)*7+4] = tem2[4]
- e[(num-1)*7+5] = tem2[5]
- e[(num-1)*7+6] = tem2[6]
- case "水费(万元)":
- g[(num-1)*7] = tem2[0]
- g[(num-1)*7+1] = tem2[1]
- g[(num-1)*7+2] = tem2[2]
- g[(num-1)*7+3] = tem2[3]
- g[(num-1)*7+4] = tem2[4]
- g[(num-1)*7+5] = tem2[5]
- g[(num-1)*7+6] = tem2[6]
- case "电量(度)":
- h[(num-1)*7] = tem2[0]
- h[(num-1)*7+1] = tem2[1]
- h[(num-1)*7+2] = tem2[2]
- h[(num-1)*7+3] = tem2[3]
- h[(num-1)*7+4] = tem2[4]
- h[(num-1)*7+5] = tem2[5]
- h[(num-1)*7+6] = tem2[6]
- case "柴油用量(L)":
- o[(num-1)*7] = tem2[0]
- o[(num-1)*7+1] = tem2[1]
- o[(num-1)*7+2] = tem2[2]
- o[(num-1)*7+3] = tem2[3]
- o[(num-1)*7+4] = tem2[4]
- o[(num-1)*7+5] = tem2[5]
- o[(num-1)*7+6] = tem2[6]
- case "用水量(吨)":
- p[(num-1)*7] = tem2[0]
- p[(num-1)*7+1] = tem2[1]
- p[(num-1)*7+2] = tem2[2]
- p[(num-1)*7+3] = tem2[3]
- p[(num-1)*7+4] = tem2[4]
- p[(num-1)*7+5] = tem2[5]
- p[(num-1)*7+6] = tem2[6]
- case "设备指标(万元)":
- r[(num-1)*7] = tem2[0]
- r[(num-1)*7+1] = tem2[1]
- r[(num-1)*7+2] = tem2[2]
- r[(num-1)*7+3] = tem2[3]
- r[(num-1)*7+4] = tem2[4]
- r[(num-1)*7+5] = tem2[5]
- r[(num-1)*7+6] = tem2[6]
- }
- tem2 = []interface{}{}
- }
- } else {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A), &c); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+1), &d); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+2), &e); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+3), &g); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+4), &r); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+5), &h); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+6), &p); err != nil {
- println(err.Error())
- }
- if err := f.SetSheetRow(sheetName, "J"+strconv.Itoa(A+7), &o); err != nil {
- println(err.Error())
- }
- //sums[2] = sums[2].(int)+value["monthLimit"].(int)
- //sums[1] = sums[1].(int)+value["monthBudget"].(int)
- // 设置月份单元格字体
- monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
- if err != nil {
- println("monthStyle err", err.Error())
- }
- f.SetCellStyle(sheetName, "A1", "CS300", monthStyle)
- // 根据指定路径保存文件
- //filename :="uploads/Downloadmailreport/" + date +sheetName+"设备指标.xlsx"
- err = PathCheck("uploads/Downloadmailreport") //检查路径并创建
- //os.Remove(filename)
- if err != nil {
- println("PathCheck err", err)
- }
- if err := f.SaveAs(filename); err != nil {
- println(err.Error())
- return "", err
- }
- return filename, err
- }
- func FileExists(path string) (bool, error) {
- _, err := os.Stat(path)
- if err == nil {
- return true, nil
- }
- if os.IsNotExist(err) {
- return false, nil
- }
- return false, err
- }
- //测试用的
- func Sssss(){
- sqls :="SELECT bbd.`buyeCode`,p.`providerName`,bd.receiveAmount,bbd.`matchCode`,bd.`amount`,bd.`sumAmount`,bd.departmentName,pa.name pastureName," +
- "bd.note,c.id,c.bigId,c.pastureId,ps.id partId,ifnull(ps.name,c.partName) partName,ifnull(ps.partCode,c.partCode) partCode,"+
- "ifnull(ps.specification,c.specification) specification,ifnull(brand.brandName,c.brand) brand,ifnull(ps.unit,c.unit) unit,"+
- "ifnull(TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM bd.price))),TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))))"+
- "price,brand.id brandId,c.inventoryType,c.planAmount,c.remark,c.enable,c.isZeroStock,e.`empname`,"+
- "DATE_FORMAT(bbd.buyerDate,'%Y-%m-%d')buyerDate,DATE_FORMAT(bbd.DoneDate, '%Y-%m-%d') DoneDate "+
- "FROM buydetail bd INNER JOIN bigbuydetail bbd ON bbd.id = bd.`bigId` LEFT JOIN provider p ON p.id = bbd.`providerId`"+
- "LEFT JOIN contract c ON c.id = bd.`contractId` LEFT JOIN emp e ON e.id = bbd.`buyerPerson` " +
- "LEFT JOIN bigpartdeal bpd ON bpd.`matchCode` = bbd.`matchCode` inner join pasture pa on pa.id = bbd.pastureId " +
- "LEFT JOIN parts ps ON ps.partCode =bd.partCode LEFT JOIN brand ON brand.id=bd.brandId " +
- "where bbd.`enable`=0 and bd.amount > 0 and bbd.buyerDate < ? and bbd.buyerDate > ? and pa.name='通辽牧场' "
- Engine := models.Engine
- queryData, err := Engine.SQL(sqls,"2021-08-27","2021-06-30").Query().List()
- //s_params := make([]interface{}, 0)
- //queryData, err := restful.QueryByListListT(sql, 0, 0, s_params, tx)
- if err != nil{
- fmt.Println(err)
- }else {
- f := excelize.NewFile()
- // 创建一个工作表
- //供应商 单价 申购数量 采购数量 入库数 申购部门 采购人 配单日期 入库时间
- index := f.NewSheet("采购明细")
- f.SetColWidth("采购明细","A","R",20)
- columns := []string{"备件品牌","计量单位","供应商","单价","申购数量","采购数量","入库数","申购部门","采购人","配单日期",
- "入库时间"}
- letters := []string{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
- for i,v :=range columns{
- f.SetCellValue("采购明细",letters[i]+"1",v)
- }
- fmt.Println(len(queryData))
- for i,v := range(queryData){
- // 设置单元格的值
- value :=[]interface{}{v["matchCode"],v["unit"],v["providerName"],v["price"],v["sumAmount"],v["amount"],v["receiveAmount"],
- v["departmentName"],v["empname"],v["buyerDate"],v["DoneDate"]}
- for a,b :=range(value){
- f.SetCellValue("采购明细", letters[a]+strconv.Itoa(i+2),b )
- }
- }
- // 设置工作簿的默认工作表
- f.SetActiveSheet(index)
- // 根据指定路径保存文件
- if err := f.SaveAs("D:/project/go/src/KPTcomm/test/采购明细.xlsx"); err != nil {
- fmt.Println(err)
- }
- }
- }
- // 测试
- func DownloadEquipment(parammaps string)(string, error) {
- //appG := app.Gin{C: context}
- data := make(map[string]interface{}, 0)
- filename := setting.CurrentPath + "uploads/Downloadmailreport/" + "设备指标.xlsx"
- exist, _ := FileExists(filename)
- if exist {
- //return filename, nil
- }
- f := excelize.NewFile()
- Style, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
- columns := []string{"设备指标", "维修费", "水费", "电费", "柴油费", "水量", "电量", "柴油用量"}
- //序号 牧场 部门 预算 内控 迄今内控 迄今实际 实际节约 实际达成率 单头牛预算 单头牛内控 单头牛迄今内控 单头牛迄今实际 单头牛实际节约
- columns1 := []string{"序号", "牧场", "部门", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "实际达成率", "单头牛预算",
- "单头牛内控", "单头牛迄今内控", "单头牛迄今实际", "单头牛实际节约"}
- letters := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
- for i, v := range (columns) {
- f.NewSheet("Sheet" + strconv.Itoa(i+1))
- f.SetSheetName("Sheet"+strconv.Itoa(i+1), v)
- f.MergeCell(v, "A1", "C1")
- f.MergeCell(v, "D1", "I1")
- f.MergeCell(v, "J1", "N1")
- f.SetCellValue(v, "A1", "设备指标")
- f.SetCellValue(v, "D1", "设备指标")
- f.SetCellValue(v, "J1", "单头牛指标")
- f.SetCellStyle(v, "A1", "CS154", Style)
- f.SetCellStyle(v, "D1", "CS154", Style)
- f.SetCellStyle(v, "J1", "CS154", Style)
- f.SetColWidth(v, "A", "N", 20)
- for i1, v1 := range (columns1) {
- f.SetCellValue(v, letters[i1]+"2", v1)
- }
- }
- Engine := models.Engine
- sqlnames := []string{"getChooseEqMonthBudgetListSumAll", "getChooseMonthWX", "getChooseElectricityPrice", "getChooseMonthiolPrice",
- "getChooseWaterPrice", "getChooseMonthElectricity", "getChooseMonthWater", "getChooseMonthOilT"}
- xx := 0
- for z, sqlname := range (sqlnames) {
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", sqlname).QueryString()
- parammap := make(map[string]interface{}, 0)
- json.Unmarshal([]byte(parammaps), ¶mmap)
- s_params := make([]interface{}, 0)
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammap[strings.Trim(value, " ")])
- }
- }
- values, err := Engine.SQL(valuesMap[0]["sqlstr"], s_params...).Query().List()
- if err != nil {
- fmt.Println(err)
- } else {
- for i, v := range (values) {
- value := []interface{}{columns[z], v["pastureName"], "全厂区", v["monthBudget"], v["monthLimit"], v["qmonthBudget"], v["sumPrice"],
- v["asave"], v["realReason"], v["oneCowBudget"], v["oneCowLimit"], v["oneCowQmonthBudget"], v["oneCowSumPrice"], v["oneCowAsave"]}
- for a, b := range (value) {
- f.SetCellValue("设备指标", letters[a]+strconv.Itoa(i+xx+3), b)
- }
- }
- }
- xx += len(values)
- }
- //"维修费","水费","电费","柴油费","水量","电量","柴油用量"
- // 其他的表格
- sqlnamesDepartment := []string{"getChooseMonthWXDepartment", "getChooseWaterPriceDepartment", "getChooseElectricityPriceDepartment", "getChooseMonthiolPriceDepartment",
- "getChooseMonthWaterDepartment", "getChooseMonthElectricityDepartment", "getChooseMonthOilTDepartment"}
- columnss := []string{"维修费", "水费", "电费", "柴油费", "水量", "电量", "柴油用量"}
- for z, sqlname := range (sqlnamesDepartment) {
- valuesMap, err := Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", sqlname).QueryString()
- parammap := make(map[string]interface{}, 0)
- json.Unmarshal([]byte(parammaps), ¶mmap)
- s_params := make([]interface{}, 0)
- paramslist := strings.Split(valuesMap[0]["params"], ",")
- if len(paramslist) > 0 && valuesMap[0]["params"] != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammap[strings.Trim(value, " ")])
- }
- }
- values, err := Engine.SQL(valuesMap[0]["sqlstr"], s_params...).Query().List()
- if err != nil {
- fmt.Println(err)
- } else {
- for i, v := range (values) {
- value := []interface{}{v["sort"], v["pastureName"], v["deptname"], v["monthBudget"], v["monthLimit"], v["qmonthBudget"], v["sumPrice"],
- v["asave"], v["realReason"], v["oneCowBudget"], v["oneCowLimit"], v["oneCowQmonthBudget"], v["oneCowSumPrice"], v["oneCowAsave"]}
- for a, b := range (value) {
- f.SetCellValue(columnss[z], letters[a]+strconv.Itoa(i+3), b)
- }
- }
- }
- }
- if err != nil {
- data["err_count"] = err
- logging.Error("设备指标导出__error:", err)
- } else {
- err = PathCheck("uploads/Downloadmailreport") //检查路径并创建
- //os.Remove(filename)
- if err != nil {
- println("PathCheck err", err)
- }
- if err := f.SaveAs(filename); err != nil {
- println(err.Error())
- return "", err
- }
- //data["success"] = "ok"
- //context.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
- //context.Header("Content-Type","application/octet-stream")
- //context.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
- //context.Header("Content-Transfer-Encoding", "binary")
- //_ = f.Write(context.Writer)
- }
- return filename, err
- //appG.Response(http.StatusOK, e.SUCCESS, data)
- }
|