mail.go 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485
  1. package util
  2. import (
  3. "fmt"
  4. "log"
  5. "net/smtp"
  6. "os"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "github.com/360EntSecGroup-Skylar/excelize"
  11. "github.com/jordan-wright/email"
  12. "github.com/robfig/cron"
  13. "kpt.xdmy/apiserver/routers/restful"
  14. "kpt.xdmy/pkg/logging"
  15. "kpt.xdmy/pkg/setting"
  16. )
  17. // 邮件相关(现代牧业暂未启用)
  18. func SendMail() {
  19. defer func() { // 必须要先声明defer
  20. if err := recover(); err != nil {
  21. logging.Error(" SendMail pnic err", err) // 这里的err其实就是panic传入的内容,55
  22. }
  23. }()
  24. log.Println("******** ******* *******", time.Now())
  25. e := email.NewEmail()
  26. // 发件人
  27. fromName := ""
  28. pas := ""
  29. mails := make([]string, 0)
  30. //
  31. subject := ""
  32. note := ""
  33. mailreport, err := restful.MapStrList("select * from mailreport where enable = 1")
  34. if err != nil {
  35. println("err sql", err.Error())
  36. } else {
  37. for _, value := range mailreport {
  38. //GetMailDataByPasture("集团设备指标",value["name"],value["id"],A,f)
  39. //GetPastureDeptData(value["name"],value["id"],f)
  40. if value["type"] == "1" {
  41. fromName = value["addr"]
  42. pas = value["pas"]
  43. subject = value["title"]
  44. note = value["note"]
  45. } else {
  46. mails = append(mails, value["addr"])
  47. }
  48. println(value["addr"])
  49. }
  50. }
  51. // 发件人
  52. //e.From = "864919639@qq.com"
  53. e.From = fromName
  54. // 收件人(可以有多个)
  55. e.To = mails
  56. //e.To = []string{"18322596935@163.com","1406599862@qq.com"} //"1406599862@qq.com"
  57. // 邮件主题
  58. //e.Subject = "集团设备指标报表"
  59. e.Subject = subject
  60. // 解析html模板
  61. //t,err := template.ParseFiles("email-template.html")
  62. //body := new(bytes.Buffer)
  63. // Execute方法将解析好的模板应用到匿名结构体上,并将输出写入body中
  64. e.Text = []byte(note)
  65. // html形式的消息
  66. //body.Write([]byte("测试"))
  67. //// 从缓冲中将内容作为附件到邮件中
  68. //e.Attach(body, "email-template.html", "text/html")
  69. // 以路径将文件作为附件添加到邮件中
  70. //_,err := GetMailData()
  71. filename := setting.CurrentPath + "uploads/mailreport/" + time.Now().Format("2006-01-02") + "集团设备指标.xlsx"
  72. e.AttachFile(filename)
  73. // 发送邮件(如果使用QQ邮箱发送邮件的话,passwd不是邮箱密码而是授权码)
  74. err = e.Send("smtp.qq.com:587", smtp.PlainAuth("", fromName, pas, "smtp.qq.com"))
  75. if err != nil {
  76. println("sent err", err.Error())
  77. } else {
  78. println("发送成功")
  79. }
  80. }
  81. func CronMail() {
  82. log.Println("Starting Cron...")
  83. defer func() { // 必须要先声明defer
  84. if err := recover(); err != nil {
  85. fmt.Printf("CronTest pnic err%+v \n", err)
  86. logging.Error("panic recover err ", err)
  87. //println("pnic err",err.(error).Error()) // 这里的err其实就是panic传入的内容,55
  88. }
  89. }()
  90. c := cron.New()
  91. err := c.AddFunc(setting.ServerSetting.CronFormula, SendMail) //2 * * * * *, 2 表示每分钟的第2s执行一次
  92. if err != nil {
  93. println("cron1 err", err.Error())
  94. err = c.AddFunc("0 9 * * *", SendMail) //2 * * * * *, 2 表示每分钟的第2s执行一次
  95. if err != nil {
  96. println("cron2 err", err.Error())
  97. } else {
  98. println("开始启动定时任务发送邮件 0 9 * * *")
  99. }
  100. } else {
  101. println("开始启动定时任务发送邮件 ", setting.ServerSetting.CronFormula)
  102. }
  103. err = c.AddFunc("0 1 * * *", GetMailData) //2 * * * * *, 2 表示每分钟的第2s执行一次
  104. if err != nil {
  105. println("cron3 err", err.Error())
  106. }
  107. //_, err = c.AddFunc("30 * * * *", GetMailData) //2 * * * * *, 2 表示每分钟的第2s执行一次
  108. //if err != nil {
  109. // println("cron4 err", err.Error())
  110. //}
  111. c.Start()
  112. }
  113. func GetMailData() {
  114. defer func() { // 必须要先声明defer
  115. if err := recover(); err != nil {
  116. logging.Error("GetMailData pnic err", err) // 这里的err其实就是panic传入的内容,55
  117. }
  118. }()
  119. f := excelize.NewFile()
  120. f.SetSheetName("Sheet1", "集团设备指标")
  121. //f.GetSheetMap()
  122. //f.NewSheet("集团设备指标")
  123. //f.SetSheetVisible(,false)
  124. //隐藏名称为 Sheet1 的工作表中的 D 至 F 列:
  125. //f.SetColVisible("Sheet1", "D:F", false)
  126. //根据给定的工作表名称(大小写敏感)、列范围和宽度值设置单个或多个列的宽度。
  127. //例如设置名为 Sheet1 工作表上 A 到 D 列的宽度为 20:
  128. // 设置单元格的值
  129. //style, err := f.NewStyle(`{"fill":{"type":"center"}}`)
  130. //if err != nil {
  131. // fmt.Println(err)
  132. //}
  133. //f.SetCellStyle("集团设备指标", "B1", "M1", style)
  134. //
  135. //f.MergeCell("集团设备指标", "N1", "T1")
  136. //err := SetSheetRow(f,"集团设备指标", "B1", &[]interface{}{"1月", nil,nil,nil,nil,nil,nil,"2月", nil,nil,nil,nil,nil,nil,
  137. // "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,
  138. // "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})
  139. tem := make([]interface{}, 0)
  140. tem1 := make([]interface{}, 0)
  141. c := []interface{}{}
  142. d := []interface{}{}
  143. e := []interface{}{}
  144. g := []interface{}{}
  145. h := []interface{}{}
  146. o := []interface{}{}
  147. p := []interface{}{}
  148. r := []interface{}{}
  149. for i := 1; i <= 12; i++ {
  150. a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
  151. b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
  152. c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  153. d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  154. e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  155. g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  156. h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  157. o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  158. p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  159. r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  160. tem = append(tem, a...)
  161. tem1 = append(tem1, b...)
  162. }
  163. //d := c
  164. //e := c
  165. //g := c
  166. //h := c
  167. //o := c
  168. //p := c
  169. if err := SetSheetRow(f, "集团设备指标", "N1", &tem); err != nil {
  170. println(err.Error())
  171. }
  172. year := time.Now().Add(-24 * time.Hour).Format("2006")
  173. f.SetCellValue("集团设备指标", "A1", "时间")
  174. f.MergeCell("集团设备指标", "B1", "M1")
  175. f.MergeCell("集团设备指标", "N1", "T1")
  176. f.MergeCell("集团设备指标", "U1", "AA1")
  177. f.MergeCell("集团设备指标", "AB1", "AH1")
  178. f.MergeCell("集团设备指标", "AI1", "AO1")
  179. f.MergeCell("集团设备指标", "AP1", "AV1")
  180. f.MergeCell("集团设备指标", "AW1", "BC1")
  181. f.MergeCell("集团设备指标", "BD1", "BJ1")
  182. f.MergeCell("集团设备指标", "BK1", "BQ1")
  183. f.MergeCell("集团设备指标", "BR1", "BX1")
  184. f.MergeCell("集团设备指标", "BY1", "CE1")
  185. f.MergeCell("集团设备指标", "CF1", "CL1")
  186. f.MergeCell("集团设备指标", "CM1", "CS1")
  187. f.SetCellValue("集团设备指标", "H1", year+"年")
  188. SetSheetRow(f, "集团设备指标", "A2", &[]interface{}{"牧场", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率", "迄今饲养头日", "迄今产量(公斤)", "迄今实际单头牛成本", "迄今实际公斤奶成本(元/公斤)"})
  189. if err := SetSheetRow(f, "集团设备指标", "N2", &tem1); err != nil {
  190. println(err.Error())
  191. }
  192. //
  193. A := 3
  194. pastures, err := restful.MapStrList("select id,name from pasture where isdel = 0 AND id <> 18 order by sort")
  195. if err != nil {
  196. println("err sql", err.Error())
  197. } else {
  198. for _, value := range pastures {
  199. GetMailDataByPasture("集团设备指标", value["name"], time.Now().Format("2006-01-02"), value["id"], A, f)
  200. GetPastureDeptData(value["name"], value["id"], f)
  201. println(value["name"])
  202. A = A + 8
  203. }
  204. }
  205. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJY")
  206. valuesMap1, err1 := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJM")
  207. sqls := ""
  208. parammaps := make(map[string]interface{}, 0)
  209. parammaps["month"] = time.Now().Format("2006-01-02")
  210. s_params := make([]interface{}, 0)
  211. if err == nil && len(valuesMap) > 0 {
  212. sqls = valuesMap["sqlstr"]
  213. paramslist := strings.Split(valuesMap["params"], ",")
  214. if len(paramslist) > 0 && valuesMap["params"] != "" {
  215. for _, value := range paramslist {
  216. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  217. }
  218. }
  219. }
  220. tem = []interface{}{}
  221. values, err := restful.MapStrList(sqls, s_params...)
  222. B := A
  223. temMap := make(map[string][]interface{}, 0)
  224. if err == nil {
  225. for _, value := range values {
  226. tem = append(tem, value["ftype"])
  227. tem = append(tem, value["monthBudget"])
  228. tem = append(tem, value["monthLimit"])
  229. tem = append(tem, value["qmonthBudget"])
  230. tem = append(tem, value["sumPrice"])
  231. tem = append(tem, value["asave"])
  232. tem = append(tem, value["dac"])
  233. tem = append(tem, value["dacY"])
  234. tem = append(tem, value["cowNum"])
  235. tem = append(tem, value["saleNum"])
  236. tem = append(tem, value["cowprice"])
  237. tem = append(tem, value["milkprice"])
  238. temMap[value["ftype"]] = tem
  239. tem = []interface{}{}
  240. }
  241. } else {
  242. println(err.Error())
  243. }
  244. if m, ok := temMap["维修费(万元)"]; ok {
  245. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  246. println(err.Error())
  247. }
  248. B++
  249. } else {
  250. temw := []interface{}{"维修费(万元)"}
  251. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  252. println(err.Error())
  253. }
  254. B++
  255. }
  256. if m, ok := temMap["电费(万元)"]; ok {
  257. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  258. println(err.Error())
  259. }
  260. B++
  261. } else {
  262. temw := []interface{}{"电费(万元)"}
  263. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  264. println(err.Error())
  265. }
  266. B++
  267. }
  268. if m, ok := temMap["燃动费(万元)"]; ok {
  269. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  270. println(err.Error())
  271. }
  272. B++
  273. } else {
  274. temw := []interface{}{"燃动费(万元)"}
  275. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  276. println(err.Error())
  277. }
  278. B++
  279. }
  280. if m, ok := temMap["水费(万元)"]; ok {
  281. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  282. println(err.Error())
  283. }
  284. B++
  285. } else {
  286. temw := []interface{}{"水费(万元)"}
  287. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  288. println(err.Error())
  289. }
  290. B++
  291. }
  292. if m, ok := temMap["设备指标(万元)"]; ok {
  293. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  294. println(err.Error())
  295. }
  296. B++
  297. } else {
  298. temw := []interface{}{"设备指标(万元)"}
  299. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  300. println(err.Error())
  301. }
  302. B++
  303. }
  304. if m, ok := temMap["电量(度)"]; ok {
  305. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  306. println(err.Error())
  307. }
  308. B++
  309. } else {
  310. temw := []interface{}{"电量(度)"}
  311. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  312. println(err.Error())
  313. }
  314. B++
  315. }
  316. if m, ok := temMap["用水量(吨)"]; ok {
  317. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  318. println(err.Error())
  319. }
  320. B++
  321. } else {
  322. temw := []interface{}{"用水量(吨)"}
  323. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  324. println(err.Error())
  325. }
  326. B++
  327. }
  328. if m, ok := temMap["柴油用量(L)"]; ok {
  329. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  330. println(err.Error())
  331. }
  332. B++
  333. } else {
  334. temw := []interface{}{"柴油用量(L)"}
  335. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  336. println(err.Error())
  337. }
  338. B++
  339. }
  340. s_params = make([]interface{}, 0)
  341. if err1 == nil && len(valuesMap1) > 0 {
  342. sqls = valuesMap1["sqlstr"]
  343. parammaps := make(map[string]interface{}, 0)
  344. parammaps["month"] = time.Now().Format("2006-01-02")
  345. paramslist := strings.Split(valuesMap1["params"], ",")
  346. if len(paramslist) > 0 && valuesMap1["params"] != "" {
  347. for _, value := range paramslist {
  348. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  349. }
  350. }
  351. }
  352. f.SetCellValue("集团设备指标", "A"+strconv.Itoa(A), "集团")
  353. f.MergeCell("集团设备指标", "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
  354. values, err = restful.MapStrList(sqls, s_params...)
  355. tem = []interface{}{}
  356. tem2 := []interface{}{}
  357. if err == nil {
  358. for _, value := range values {
  359. tem2 = append(tem2, value["monthBudget"])
  360. tem2 = append(tem2, value["monthLimit"])
  361. tem2 = append(tem2, value["qmonthBudget"])
  362. tem2 = append(tem2, value["sumPrice"])
  363. tem2 = append(tem2, value["asave"])
  364. tem2 = append(tem2, value["dac"])
  365. tem2 = append(tem2, value["dacY"])
  366. num, _ := strconv.Atoi(value["num"])
  367. switch value["ftype"] {
  368. case "维修费(万元)":
  369. c[(num-1)*7] = tem2[0]
  370. c[(num-1)*7+1] = tem2[1]
  371. c[(num-1)*7+2] = tem2[2]
  372. c[(num-1)*7+3] = tem2[3]
  373. c[(num-1)*7+4] = tem2[4]
  374. c[(num-1)*7+5] = tem2[5]
  375. c[(num-1)*7+6] = tem2[6]
  376. case "电费(万元)":
  377. d[(num-1)*7] = tem2[0]
  378. d[(num-1)*7+1] = tem2[1]
  379. d[(num-1)*7+2] = tem2[2]
  380. d[(num-1)*7+3] = tem2[3]
  381. d[(num-1)*7+4] = tem2[4]
  382. d[(num-1)*7+5] = tem2[5]
  383. d[(num-1)*7+6] = tem2[6]
  384. case "燃动费(万元)":
  385. e[(num-1)*7] = tem2[0]
  386. e[(num-1)*7+1] = tem2[1]
  387. e[(num-1)*7+2] = tem2[2]
  388. e[(num-1)*7+3] = tem2[3]
  389. e[(num-1)*7+4] = tem2[4]
  390. e[(num-1)*7+5] = tem2[5]
  391. e[(num-1)*7+6] = tem2[6]
  392. case "水费(万元)":
  393. g[(num-1)*7] = tem2[0]
  394. g[(num-1)*7+1] = tem2[1]
  395. g[(num-1)*7+2] = tem2[2]
  396. g[(num-1)*7+3] = tem2[3]
  397. g[(num-1)*7+4] = tem2[4]
  398. g[(num-1)*7+5] = tem2[5]
  399. g[(num-1)*7+6] = tem2[6]
  400. case "电量(度)":
  401. h[(num-1)*7] = tem2[0]
  402. h[(num-1)*7+1] = tem2[1]
  403. h[(num-1)*7+2] = tem2[2]
  404. h[(num-1)*7+3] = tem2[3]
  405. h[(num-1)*7+4] = tem2[4]
  406. h[(num-1)*7+5] = tem2[5]
  407. h[(num-1)*7+6] = tem2[6]
  408. case "柴油用量(L)":
  409. o[(num-1)*7] = tem2[0]
  410. o[(num-1)*7+1] = tem2[1]
  411. o[(num-1)*7+2] = tem2[2]
  412. o[(num-1)*7+3] = tem2[3]
  413. o[(num-1)*7+4] = tem2[4]
  414. o[(num-1)*7+5] = tem2[5]
  415. o[(num-1)*7+6] = tem2[6]
  416. case "用水量(吨)":
  417. p[(num-1)*7] = tem2[0]
  418. p[(num-1)*7+1] = tem2[1]
  419. p[(num-1)*7+2] = tem2[2]
  420. p[(num-1)*7+3] = tem2[3]
  421. p[(num-1)*7+4] = tem2[4]
  422. p[(num-1)*7+5] = tem2[5]
  423. p[(num-1)*7+6] = tem2[6]
  424. case "设备指标(万元)":
  425. r[(num-1)*7] = tem2[0]
  426. r[(num-1)*7+1] = tem2[1]
  427. r[(num-1)*7+2] = tem2[2]
  428. r[(num-1)*7+3] = tem2[3]
  429. r[(num-1)*7+4] = tem2[4]
  430. r[(num-1)*7+5] = tem2[5]
  431. r[(num-1)*7+6] = tem2[6]
  432. }
  433. tem2 = []interface{}{}
  434. }
  435. } else {
  436. println(err.Error())
  437. }
  438. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A), &c); err != nil {
  439. println(err.Error())
  440. }
  441. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+1), &d); err != nil {
  442. println(err.Error())
  443. }
  444. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+2), &e); err != nil {
  445. println(err.Error())
  446. }
  447. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+3), &g); err != nil {
  448. println(err.Error())
  449. }
  450. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+4), &r); err != nil {
  451. println(err.Error())
  452. }
  453. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+5), &h); err != nil {
  454. println(err.Error())
  455. }
  456. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+6), &p); err != nil {
  457. println(err.Error())
  458. }
  459. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+7), &o); err != nil {
  460. println(err.Error())
  461. }
  462. //sums[2] = sums[2].(int)+value["monthLimit"].(int)
  463. //sums[1] = sums[1].(int)+value["monthBudget"].(int)
  464. // 设置月份单元格字体
  465. monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
  466. if err != nil {
  467. println("monthStyle err", err.Error())
  468. }
  469. f.SetCellStyle("集团设备指标", "A1", "CS154", monthStyle)
  470. // 根据指定路径保存文件
  471. filename := setting.CurrentPath + "uploads/mailreport/" + time.Now().Format("2006-01-02") + "集团设备指标.xlsx"
  472. err = PathCheck(setting.CurrentPath + "uploads/mailreport") //检查路径并创建
  473. os.Remove(filename)
  474. if err != nil {
  475. println("PathCheck err", err)
  476. }
  477. if err := f.SaveAs(filename); err != nil {
  478. println(err.Error())
  479. }
  480. }
  481. func GetMailDataByPasture(sheetName, pastureName, date string, pastureId interface{}, B int, f *excelize.File) {
  482. tem := make([]interface{}, 0)
  483. tem1 := make([]interface{}, 0)
  484. c := []interface{}{}
  485. d := []interface{}{}
  486. e := []interface{}{}
  487. g := []interface{}{}
  488. h := []interface{}{}
  489. o := []interface{}{}
  490. p := []interface{}{}
  491. r := []interface{}{}
  492. for i := 1; i <= 12; i++ {
  493. a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
  494. b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
  495. c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  496. d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  497. e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  498. g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  499. h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  500. o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  501. p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  502. r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  503. tem = append(tem, a...)
  504. tem1 = append(tem1, b...)
  505. }
  506. //
  507. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMY")
  508. valuesMap1, err1 := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMM")
  509. sqls := ""
  510. parammaps := make(map[string]interface{}, 0)
  511. parammaps["month"] = date
  512. parammaps["pastureId"] = pastureId
  513. s_params := make([]interface{}, 0)
  514. if err == nil && len(valuesMap) > 0 {
  515. sqls = valuesMap["sqlstr"]
  516. paramslist := strings.Split(valuesMap["params"], ",")
  517. if len(paramslist) > 0 && valuesMap["params"] != "" {
  518. for _, value := range paramslist {
  519. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  520. }
  521. }
  522. }
  523. f.SetCellValue(sheetName, "A"+strconv.Itoa(B), pastureName)
  524. f.MergeCell(sheetName, "A"+strconv.Itoa(B), "A"+strconv.Itoa(B+7))
  525. tem = []interface{}{}
  526. temMap := make(map[string][]interface{}, 0)
  527. //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
  528. values, err := restful.MapStrList(sqls, s_params...)
  529. Bt := B
  530. if err == nil {
  531. for _, value := range values {
  532. tem = append(tem, value["ftype"])
  533. tem = append(tem, value["monthBudget"])
  534. tem = append(tem, value["monthLimit"])
  535. tem = append(tem, value["qmonthBudget"])
  536. tem = append(tem, value["sumPrice"])
  537. tem = append(tem, value["asave"])
  538. tem = append(tem, value["dac"])
  539. tem = append(tem, value["dacY"])
  540. tem = append(tem, value["cowNum"])
  541. tem = append(tem, value["saleNum"])
  542. tem = append(tem, value["cowprice"])
  543. tem = append(tem, value["milkprice"])
  544. temMap[value["ftype"]] = tem
  545. //if err := SetSheetRow(f,sheetName, "B"+strconv.Itoa(Bt),&tem); err != nil {
  546. // println(err.Error())
  547. //}
  548. tem = []interface{}{}
  549. //Bt++
  550. }
  551. } else {
  552. println(err.Error())
  553. }
  554. if m, ok := temMap["维修费(万元)"]; ok {
  555. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  556. println(err.Error())
  557. }
  558. Bt++
  559. } else {
  560. temw := []interface{}{"维修费(万元)"}
  561. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  562. println(err.Error())
  563. }
  564. Bt++
  565. }
  566. if m, ok := temMap["电费(万元)"]; ok {
  567. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  568. println(err.Error())
  569. }
  570. Bt++
  571. } else {
  572. temw := []interface{}{"电费(万元)"}
  573. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  574. println(err.Error())
  575. }
  576. Bt++
  577. }
  578. if m, ok := temMap["燃动费(万元)"]; ok {
  579. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  580. println(err.Error())
  581. }
  582. Bt++
  583. } else {
  584. temw := []interface{}{"燃动费(万元)"}
  585. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  586. println(err.Error())
  587. }
  588. Bt++
  589. }
  590. if m, ok := temMap["水费(万元)"]; ok {
  591. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  592. println(err.Error())
  593. }
  594. Bt++
  595. } else {
  596. temw := []interface{}{"水费(万元)"}
  597. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  598. println(err.Error())
  599. }
  600. Bt++
  601. }
  602. if m, ok := temMap["设备指标(万元)"]; ok {
  603. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  604. println(err.Error())
  605. }
  606. Bt++
  607. } else {
  608. temw := []interface{}{"设备指标(万元)"}
  609. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  610. println(err.Error())
  611. }
  612. Bt++
  613. }
  614. if m, ok := temMap["电量(度)"]; ok {
  615. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  616. println(err.Error())
  617. }
  618. Bt++
  619. } else {
  620. temw := []interface{}{"电量(度)"}
  621. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  622. println(err.Error())
  623. }
  624. Bt++
  625. }
  626. if m, ok := temMap["用水量(吨)"]; ok {
  627. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  628. println(err.Error())
  629. }
  630. Bt++
  631. } else {
  632. temw := []interface{}{"用水量(吨)"}
  633. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  634. println(err.Error())
  635. }
  636. Bt++
  637. }
  638. if m, ok := temMap["柴油用量(L)"]; ok {
  639. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  640. println(err.Error())
  641. }
  642. Bt++
  643. } else {
  644. temw := []interface{}{"柴油用量(L)"}
  645. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  646. println(err.Error())
  647. }
  648. Bt++
  649. }
  650. s_params = make([]interface{}, 0)
  651. if err1 == nil && len(valuesMap1) > 0 {
  652. sqls = valuesMap1["sqlstr"]
  653. parammaps := make(map[string]interface{}, 0)
  654. parammaps["month"] = date
  655. parammaps["pastureId"] = pastureId
  656. paramslist := strings.Split(valuesMap1["params"], ",")
  657. if len(paramslist) > 0 && valuesMap1["params"] != "" {
  658. for _, value := range paramslist {
  659. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  660. }
  661. }
  662. }
  663. values, err = restful.MapStrList(sqls, s_params...)
  664. tem = []interface{}{}
  665. tem2 := []interface{}{}
  666. if err == nil {
  667. for _, value := range values {
  668. tem2 = append(tem2, value["monthBudget"])
  669. tem2 = append(tem2, value["monthLimit"])
  670. tem2 = append(tem2, value["qmonthBudget"])
  671. tem2 = append(tem2, value["sumPrice"])
  672. tem2 = append(tem2, value["asave"])
  673. tem2 = append(tem2, value["dac"])
  674. tem2 = append(tem2, value["dacY"])
  675. num, _ := strconv.Atoi(value["num"])
  676. switch value["ftype"] {
  677. case "维修费(万元)":
  678. c[(num-1)*7] = tem2[0]
  679. c[(num-1)*7+1] = tem2[1]
  680. c[(num-1)*7+2] = tem2[2]
  681. c[(num-1)*7+3] = tem2[3]
  682. c[(num-1)*7+4] = tem2[4]
  683. c[(num-1)*7+5] = tem2[5]
  684. c[(num-1)*7+6] = tem2[6]
  685. case "电费(万元)":
  686. d[(num-1)*7] = tem2[0]
  687. d[(num-1)*7+1] = tem2[1]
  688. d[(num-1)*7+2] = tem2[2]
  689. d[(num-1)*7+3] = tem2[3]
  690. d[(num-1)*7+4] = tem2[4]
  691. d[(num-1)*7+5] = tem2[5]
  692. d[(num-1)*7+6] = tem2[6]
  693. case "燃动费(万元)":
  694. e[(num-1)*7] = tem2[0]
  695. e[(num-1)*7+1] = tem2[1]
  696. e[(num-1)*7+2] = tem2[2]
  697. e[(num-1)*7+3] = tem2[3]
  698. e[(num-1)*7+4] = tem2[4]
  699. e[(num-1)*7+5] = tem2[5]
  700. e[(num-1)*7+6] = tem2[6]
  701. case "水费(万元)":
  702. g[(num-1)*7] = tem2[0]
  703. g[(num-1)*7+1] = tem2[1]
  704. g[(num-1)*7+2] = tem2[2]
  705. g[(num-1)*7+3] = tem2[3]
  706. g[(num-1)*7+4] = tem2[4]
  707. g[(num-1)*7+5] = tem2[5]
  708. g[(num-1)*7+6] = tem2[6]
  709. case "电量(度)":
  710. h[(num-1)*7] = tem2[0]
  711. h[(num-1)*7+1] = tem2[1]
  712. h[(num-1)*7+2] = tem2[2]
  713. h[(num-1)*7+3] = tem2[3]
  714. h[(num-1)*7+4] = tem2[4]
  715. h[(num-1)*7+5] = tem2[5]
  716. h[(num-1)*7+6] = tem2[6]
  717. case "柴油用量(L)":
  718. o[(num-1)*7] = tem2[0]
  719. o[(num-1)*7+1] = tem2[1]
  720. o[(num-1)*7+2] = tem2[2]
  721. o[(num-1)*7+3] = tem2[3]
  722. o[(num-1)*7+4] = tem2[4]
  723. o[(num-1)*7+5] = tem2[5]
  724. o[(num-1)*7+6] = tem2[6]
  725. case "用水量(吨)":
  726. p[(num-1)*7] = tem2[0]
  727. p[(num-1)*7+1] = tem2[1]
  728. p[(num-1)*7+2] = tem2[2]
  729. p[(num-1)*7+3] = tem2[3]
  730. p[(num-1)*7+4] = tem2[4]
  731. p[(num-1)*7+5] = tem2[5]
  732. p[(num-1)*7+6] = tem2[6]
  733. case "设备指标(万元)":
  734. r[(num-1)*7] = tem2[0]
  735. r[(num-1)*7+1] = tem2[1]
  736. r[(num-1)*7+2] = tem2[2]
  737. r[(num-1)*7+3] = tem2[3]
  738. r[(num-1)*7+4] = tem2[4]
  739. r[(num-1)*7+5] = tem2[5]
  740. r[(num-1)*7+6] = tem2[6]
  741. }
  742. tem2 = []interface{}{}
  743. }
  744. } else {
  745. println(err.Error())
  746. }
  747. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B), &c); err != nil {
  748. println(err.Error())
  749. }
  750. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+1), &d); err != nil {
  751. println(err.Error())
  752. }
  753. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+2), &e); err != nil {
  754. println(err.Error())
  755. }
  756. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+3), &g); err != nil {
  757. println(err.Error())
  758. }
  759. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+4), &r); err != nil {
  760. println(err.Error())
  761. }
  762. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+5), &h); err != nil {
  763. println(err.Error())
  764. }
  765. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+6), &p); err != nil {
  766. println(err.Error())
  767. }
  768. if err := SetSheetRow(f, sheetName, "N"+strconv.Itoa(B+7), &o); err != nil {
  769. println(err.Error())
  770. }
  771. }
  772. func GetMailDataByDept(sheetName, DeptName, date string, DeptId, pastureId interface{}, B int, f *excelize.File) {
  773. tem := make([]interface{}, 0)
  774. tem1 := make([]interface{}, 0)
  775. c := []interface{}{}
  776. d := []interface{}{}
  777. e := []interface{}{}
  778. g := []interface{}{}
  779. h := []interface{}{}
  780. o := []interface{}{}
  781. p := []interface{}{}
  782. r := []interface{}{}
  783. for i := 1; i <= 12; i++ {
  784. a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
  785. b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
  786. c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  787. d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  788. e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  789. g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  790. h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  791. o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  792. p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  793. r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  794. tem = append(tem, a...)
  795. tem1 = append(tem1, b...)
  796. }
  797. //
  798. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportBY")
  799. valuesMap1, err1 := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportBM")
  800. sqls := ""
  801. parammaps := make(map[string]interface{}, 0)
  802. parammaps["month"] = date
  803. parammaps["pastureId"] = pastureId
  804. parammaps["departmentId"] = DeptId
  805. s_params := make([]interface{}, 0)
  806. if err == nil && len(valuesMap) > 0 {
  807. sqls = valuesMap["sqlstr"]
  808. paramslist := strings.Split(valuesMap["params"], ",")
  809. if len(paramslist) > 0 && valuesMap["params"] != "" {
  810. for _, value := range paramslist {
  811. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  812. }
  813. }
  814. }
  815. f.SetCellValue(sheetName, "A"+strconv.Itoa(B), DeptName)
  816. f.MergeCell(sheetName, "A"+strconv.Itoa(B), "A"+strconv.Itoa(B+7))
  817. tem = []interface{}{}
  818. temMap := make(map[string][]interface{}, 0)
  819. //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
  820. values, err := restful.MapStrList(sqls, s_params...)
  821. Bt := B
  822. if err == nil {
  823. for _, value := range values {
  824. tem = append(tem, value["ftype"])
  825. tem = append(tem, value["monthBudget"])
  826. tem = append(tem, value["monthLimit"])
  827. tem = append(tem, value["qmonthBudget"])
  828. tem = append(tem, value["sumPrice"])
  829. tem = append(tem, value["asave"])
  830. tem = append(tem, value["dac"])
  831. tem = append(tem, value["dacY"])
  832. tem = append(tem, value["cowNum"])
  833. tem = append(tem, value["saleNum"])
  834. tem = append(tem, value["cowprice"])
  835. tem = append(tem, value["milkprice"])
  836. temMap[value["ftype"]] = tem
  837. tem = []interface{}{}
  838. }
  839. } else {
  840. println(err.Error())
  841. }
  842. if m, ok := temMap["维修费(万元)"]; ok {
  843. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  844. println(err.Error())
  845. }
  846. Bt++
  847. } else {
  848. temw := []interface{}{"维修费(万元)"}
  849. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  850. println(err.Error())
  851. }
  852. Bt++
  853. }
  854. if m, ok := temMap["电费(万元)"]; ok {
  855. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  856. println(err.Error())
  857. }
  858. Bt++
  859. } else {
  860. temw := []interface{}{"电费(万元)"}
  861. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  862. println(err.Error())
  863. }
  864. Bt++
  865. }
  866. if m, ok := temMap["燃动费(万元)"]; ok {
  867. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  868. println(err.Error())
  869. }
  870. Bt++
  871. } else {
  872. temw := []interface{}{"燃动费(万元)"}
  873. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  874. println(err.Error())
  875. }
  876. Bt++
  877. }
  878. if m, ok := temMap["水费(万元)"]; ok {
  879. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  880. println(err.Error())
  881. }
  882. Bt++
  883. } else {
  884. temw := []interface{}{"水费(万元)"}
  885. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  886. println(err.Error())
  887. }
  888. Bt++
  889. }
  890. if m, ok := temMap["设备指标(万元)"]; ok {
  891. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  892. println(err.Error())
  893. }
  894. Bt++
  895. } else {
  896. temw := []interface{}{"设备指标(万元)"}
  897. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  898. println(err.Error())
  899. }
  900. Bt++
  901. }
  902. if m, ok := temMap["电量(度)"]; ok {
  903. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  904. println(err.Error())
  905. }
  906. Bt++
  907. } else {
  908. temw := []interface{}{"电量(度)"}
  909. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  910. println(err.Error())
  911. }
  912. Bt++
  913. }
  914. if m, ok := temMap["用水量(吨)"]; ok {
  915. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  916. println(err.Error())
  917. }
  918. Bt++
  919. } else {
  920. temw := []interface{}{"用水量(吨)"}
  921. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  922. println(err.Error())
  923. }
  924. Bt++
  925. }
  926. if m, ok := temMap["柴油用量(L)"]; ok {
  927. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &m); err != nil {
  928. println(err.Error())
  929. }
  930. Bt++
  931. } else {
  932. temw := []interface{}{"柴油用量(L)"}
  933. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(Bt), &temw); err != nil {
  934. println(err.Error())
  935. }
  936. Bt++
  937. }
  938. s_params = make([]interface{}, 0)
  939. if err1 == nil && len(valuesMap1) > 0 {
  940. sqls = valuesMap1["sqlstr"]
  941. parammaps := make(map[string]interface{}, 0)
  942. parammaps["month"] = date
  943. parammaps["pastureId"] = pastureId
  944. parammaps["departmentId"] = DeptId
  945. paramslist := strings.Split(valuesMap1["params"], ",")
  946. if len(paramslist) > 0 && valuesMap1["params"] != "" {
  947. for _, value := range paramslist {
  948. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  949. }
  950. }
  951. }
  952. values, err = restful.MapStrList(sqls, s_params...)
  953. tem = []interface{}{}
  954. tem2 := []interface{}{}
  955. if err == nil {
  956. for _, value := range values {
  957. //fmt.Printf("va============== %+v\n",value)
  958. tem2 = append(tem2, value["monthBudget"])
  959. tem2 = append(tem2, value["monthLimit"])
  960. tem2 = append(tem2, value["qmonthBudget"])
  961. tem2 = append(tem2, value["sumPrice"])
  962. tem2 = append(tem2, value["asave"])
  963. tem2 = append(tem2, value["dac"])
  964. tem2 = append(tem2, value["dacY"])
  965. num := 1
  966. if _, ok := value["num"]; ok {
  967. num, _ = strconv.Atoi(value["num"])
  968. }
  969. switch value["ftype"] {
  970. case "维修费(万元)":
  971. c[(num-1)*7] = tem2[0]
  972. c[(num-1)*7+1] = tem2[1]
  973. c[(num-1)*7+2] = tem2[2]
  974. c[(num-1)*7+3] = tem2[3]
  975. c[(num-1)*7+4] = tem2[4]
  976. c[(num-1)*7+5] = tem2[5]
  977. c[(num-1)*7+6] = tem2[6]
  978. case "电费(万元)":
  979. d[(num-1)*7] = tem2[0]
  980. d[(num-1)*7+1] = tem2[1]
  981. d[(num-1)*7+2] = tem2[2]
  982. d[(num-1)*7+3] = tem2[3]
  983. d[(num-1)*7+4] = tem2[4]
  984. d[(num-1)*7+5] = tem2[5]
  985. d[(num-1)*7+6] = tem2[6]
  986. case "燃动费(万元)":
  987. e[(num-1)*7] = tem2[0]
  988. e[(num-1)*7+1] = tem2[1]
  989. e[(num-1)*7+2] = tem2[2]
  990. e[(num-1)*7+3] = tem2[3]
  991. e[(num-1)*7+4] = tem2[4]
  992. e[(num-1)*7+5] = tem2[5]
  993. e[(num-1)*7+6] = tem2[6]
  994. case "水费(万元)":
  995. g[(num-1)*7] = tem2[0]
  996. g[(num-1)*7+1] = tem2[1]
  997. g[(num-1)*7+2] = tem2[2]
  998. g[(num-1)*7+3] = tem2[3]
  999. g[(num-1)*7+4] = tem2[4]
  1000. g[(num-1)*7+5] = tem2[5]
  1001. g[(num-1)*7+6] = tem2[6]
  1002. case "电量(度)":
  1003. h[(num-1)*7] = tem2[0]
  1004. h[(num-1)*7+1] = tem2[1]
  1005. h[(num-1)*7+2] = tem2[2]
  1006. h[(num-1)*7+3] = tem2[3]
  1007. h[(num-1)*7+4] = tem2[4]
  1008. h[(num-1)*7+5] = tem2[5]
  1009. h[(num-1)*7+6] = tem2[6]
  1010. case "柴油用量(L)":
  1011. o[(num-1)*7] = tem2[0]
  1012. o[(num-1)*7+1] = tem2[1]
  1013. o[(num-1)*7+2] = tem2[2]
  1014. o[(num-1)*7+3] = tem2[3]
  1015. o[(num-1)*7+4] = tem2[4]
  1016. o[(num-1)*7+5] = tem2[5]
  1017. o[(num-1)*7+6] = tem2[6]
  1018. case "用水量(吨)":
  1019. p[(num-1)*7] = tem2[0]
  1020. p[(num-1)*7+1] = tem2[1]
  1021. p[(num-1)*7+2] = tem2[2]
  1022. p[(num-1)*7+3] = tem2[3]
  1023. p[(num-1)*7+4] = tem2[4]
  1024. p[(num-1)*7+5] = tem2[5]
  1025. p[(num-1)*7+6] = tem2[6]
  1026. case "设备指标(万元)":
  1027. r[(num-1)*7] = tem2[0]
  1028. r[(num-1)*7+1] = tem2[1]
  1029. r[(num-1)*7+2] = tem2[2]
  1030. r[(num-1)*7+3] = tem2[3]
  1031. r[(num-1)*7+4] = tem2[4]
  1032. r[(num-1)*7+5] = tem2[5]
  1033. r[(num-1)*7+6] = tem2[6]
  1034. }
  1035. tem2 = []interface{}{}
  1036. }
  1037. } else {
  1038. println(err.Error())
  1039. }
  1040. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B), &c); err != nil {
  1041. println(err.Error())
  1042. }
  1043. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+1), &d); err != nil {
  1044. println(err.Error())
  1045. }
  1046. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+2), &e); err != nil {
  1047. println(err.Error())
  1048. }
  1049. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+3), &g); err != nil {
  1050. println(err.Error())
  1051. }
  1052. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+4), &r); err != nil {
  1053. println(err.Error())
  1054. }
  1055. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+5), &h); err != nil {
  1056. println(err.Error())
  1057. }
  1058. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+6), &p); err != nil {
  1059. println(err.Error())
  1060. }
  1061. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(B+7), &o); err != nil {
  1062. println(err.Error())
  1063. }
  1064. }
  1065. func GetPastureDeptData(sheetName string, pastureId interface{}, f *excelize.File) {
  1066. f.NewSheet(sheetName)
  1067. tem := make([]interface{}, 0)
  1068. tem1 := make([]interface{}, 0)
  1069. c := []interface{}{}
  1070. d := []interface{}{}
  1071. e := []interface{}{}
  1072. g := []interface{}{}
  1073. h := []interface{}{}
  1074. o := []interface{}{}
  1075. p := []interface{}{}
  1076. r := []interface{}{}
  1077. for i := 1; i <= 12; i++ {
  1078. a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
  1079. b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
  1080. c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1081. d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1082. e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1083. g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1084. h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1085. o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1086. p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1087. r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1088. tem = append(tem, a...)
  1089. tem1 = append(tem1, b...)
  1090. }
  1091. //d := c
  1092. //e := c
  1093. //g := c
  1094. //h := c
  1095. //o := c
  1096. //p := c
  1097. if err := SetSheetRow(f, sheetName, "J1", &tem); err != nil {
  1098. println(err.Error())
  1099. }
  1100. year := time.Now().Add(-24 * time.Hour).Format("2006")
  1101. f.SetCellValue(sheetName, "A1", "时间")
  1102. f.MergeCell(sheetName, "B1", "I1")
  1103. f.MergeCell(sheetName, "J1", "P1")
  1104. f.MergeCell(sheetName, "Q1", "W1")
  1105. f.MergeCell(sheetName, "X1", "AD1")
  1106. f.MergeCell(sheetName, "AE1", "AK1")
  1107. f.MergeCell(sheetName, "AL1", "AR1")
  1108. f.MergeCell(sheetName, "AS1", "AY1")
  1109. f.MergeCell(sheetName, "AZ1", "BF1")
  1110. f.MergeCell(sheetName, "BG1", "BM1")
  1111. f.MergeCell(sheetName, "BN1", "BT1")
  1112. f.MergeCell(sheetName, "BU1", "CA1")
  1113. f.MergeCell(sheetName, "CB1", "CH1")
  1114. f.MergeCell(sheetName, "CI1", "CO1")
  1115. f.SetCellValue(sheetName, "H1", year+"年")
  1116. SetSheetRow(f, sheetName, "A2", &[]interface{}{"部门", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率"})
  1117. if err := SetSheetRow(f, sheetName, "J2", &tem1); err != nil {
  1118. println(err.Error())
  1119. }
  1120. //
  1121. A := 3
  1122. pastures, err := restful.MapStrList("select id,name from department where pastureId=? and isDel = 0 AND enable =1 and id <> ?", pastureId, pastureId)
  1123. if err != nil {
  1124. println("err sql", err.Error())
  1125. } else {
  1126. for _, value := range pastures {
  1127. GetMailDataByDept(sheetName, value["name"], time.Now().Format("2006-01-02"), value["id"], pastureId, A, f)
  1128. println(value["name"])
  1129. A = A + 8
  1130. }
  1131. }
  1132. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMY")
  1133. valuesMap1, err1 := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMM")
  1134. sqls := ""
  1135. parammaps := make(map[string]interface{}, 0)
  1136. parammaps["month"] = time.Now().Format("2006-01-02")
  1137. parammaps["pastureId"] = pastureId
  1138. s_params := make([]interface{}, 0)
  1139. if err == nil && len(valuesMap) > 0 {
  1140. sqls = valuesMap["sqlstr"]
  1141. paramslist := strings.Split(valuesMap["params"], ",")
  1142. if len(paramslist) > 0 && valuesMap["params"] != "" {
  1143. for _, value := range paramslist {
  1144. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  1145. }
  1146. }
  1147. }
  1148. tem = []interface{}{}
  1149. //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
  1150. values, err := restful.MapStrList(sqls, s_params...)
  1151. B := A
  1152. temMap := make(map[string][]interface{}, 0)
  1153. if err == nil {
  1154. for _, value := range values {
  1155. tem = append(tem, value["ftype"])
  1156. tem = append(tem, value["monthBudget"])
  1157. tem = append(tem, value["monthLimit"])
  1158. tem = append(tem, value["qmonthBudget"])
  1159. tem = append(tem, value["sumPrice"])
  1160. tem = append(tem, value["asave"])
  1161. tem = append(tem, value["dac"])
  1162. tem = append(tem, value["dacY"])
  1163. temMap[value["ftype"]] = tem
  1164. //if err := SetSheetRow(f,sheetName, "B"+strconv.Itoa(B),&tem); err != nil {
  1165. // println(err.Error())
  1166. //}
  1167. tem = []interface{}{}
  1168. //B++
  1169. }
  1170. } else {
  1171. println(err.Error())
  1172. }
  1173. if m, ok := temMap["维修费(万元)"]; ok {
  1174. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1175. println(err.Error())
  1176. }
  1177. B++
  1178. } else {
  1179. temw := []interface{}{"维修费(万元)"}
  1180. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1181. println(err.Error())
  1182. }
  1183. B++
  1184. }
  1185. if m, ok := temMap["电费(万元)"]; ok {
  1186. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1187. println(err.Error())
  1188. }
  1189. B++
  1190. } else {
  1191. temw := []interface{}{"电费(万元)"}
  1192. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1193. println(err.Error())
  1194. }
  1195. B++
  1196. }
  1197. if m, ok := temMap["燃动费(万元)"]; ok {
  1198. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1199. println(err.Error())
  1200. }
  1201. B++
  1202. } else {
  1203. temw := []interface{}{"燃动费(万元)"}
  1204. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1205. println(err.Error())
  1206. }
  1207. B++
  1208. }
  1209. if m, ok := temMap["水费(万元)"]; ok {
  1210. if err :=
  1211. SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1212. println(err.Error())
  1213. }
  1214. B++
  1215. } else {
  1216. temw := []interface{}{"水费(万元)"}
  1217. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1218. println(err.Error())
  1219. }
  1220. B++
  1221. }
  1222. if m, ok := temMap["设备指标(万元)"]; ok {
  1223. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1224. println(err.Error())
  1225. }
  1226. B++
  1227. } else {
  1228. temw := []interface{}{"设备指标(万元)"}
  1229. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1230. println(err.Error())
  1231. }
  1232. B++
  1233. }
  1234. if m, ok := temMap["电量(度)"]; ok {
  1235. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1236. println(err.Error())
  1237. }
  1238. B++
  1239. } else {
  1240. temw := []interface{}{"电量(度)"}
  1241. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1242. println(err.Error())
  1243. }
  1244. B++
  1245. }
  1246. if m, ok := temMap["用水量(吨)"]; ok {
  1247. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1248. println(err.Error())
  1249. }
  1250. B++
  1251. } else {
  1252. temw := []interface{}{"用水量(吨)"}
  1253. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1254. println(err.Error())
  1255. }
  1256. B++
  1257. }
  1258. if m, ok := temMap["柴油用量(L)"]; ok {
  1259. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1260. println(err.Error())
  1261. }
  1262. B++
  1263. } else {
  1264. temw := []interface{}{"柴油用量(L)"}
  1265. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1266. println(err.Error())
  1267. }
  1268. B++
  1269. }
  1270. s_params = make([]interface{}, 0)
  1271. if err1 == nil && len(valuesMap1) > 0 {
  1272. sqls = valuesMap1["sqlstr"]
  1273. parammaps := make(map[string]interface{}, 0)
  1274. parammaps["month"] = time.Now().Format("2006-01-02")
  1275. parammaps["pastureId"] = pastureId
  1276. paramslist := strings.Split(valuesMap1["params"], ",")
  1277. if len(paramslist) > 0 && valuesMap1["params"] != "" {
  1278. for _, value := range paramslist {
  1279. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  1280. }
  1281. }
  1282. }
  1283. f.SetCellValue(sheetName, "A"+strconv.Itoa(A), sheetName)
  1284. f.MergeCell(sheetName, "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
  1285. values, err = restful.MapStrList(sqls, s_params...)
  1286. tem = []interface{}{}
  1287. //d := append(c,nil)
  1288. //e := append(c,nil)
  1289. //g := append(c,nil)
  1290. //h := append(c,nil)
  1291. //o := append(c,nil)
  1292. //p := append(c,nil)
  1293. tem2 := []interface{}{}
  1294. if err == nil {
  1295. for _, value := range values {
  1296. tem2 = append(tem2, value["monthBudget"])
  1297. tem2 = append(tem2, value["monthLimit"])
  1298. tem2 = append(tem2, value["qmonthBudget"])
  1299. tem2 = append(tem2, value["sumPrice"])
  1300. tem2 = append(tem2, value["asave"])
  1301. tem2 = append(tem2, value["dac"])
  1302. tem2 = append(tem2, value["dacY"])
  1303. num, _ := strconv.Atoi(value["num"])
  1304. switch value["ftype"] {
  1305. case "维修费(万元)":
  1306. c[(num-1)*7] = tem2[0]
  1307. c[(num-1)*7+1] = tem2[1]
  1308. c[(num-1)*7+2] = tem2[2]
  1309. c[(num-1)*7+3] = tem2[3]
  1310. c[(num-1)*7+4] = tem2[4]
  1311. c[(num-1)*7+5] = tem2[5]
  1312. c[(num-1)*7+6] = tem2[6]
  1313. case "电费(万元)":
  1314. d[(num-1)*7] = tem2[0]
  1315. d[(num-1)*7+1] = tem2[1]
  1316. d[(num-1)*7+2] = tem2[2]
  1317. d[(num-1)*7+3] = tem2[3]
  1318. d[(num-1)*7+4] = tem2[4]
  1319. d[(num-1)*7+5] = tem2[5]
  1320. d[(num-1)*7+6] = tem2[6]
  1321. case "燃动费(万元)":
  1322. e[(num-1)*7] = tem2[0]
  1323. e[(num-1)*7+1] = tem2[1]
  1324. e[(num-1)*7+2] = tem2[2]
  1325. e[(num-1)*7+3] = tem2[3]
  1326. e[(num-1)*7+4] = tem2[4]
  1327. e[(num-1)*7+5] = tem2[5]
  1328. e[(num-1)*7+6] = tem2[6]
  1329. case "水费(万元)":
  1330. g[(num-1)*7] = tem2[0]
  1331. g[(num-1)*7+1] = tem2[1]
  1332. g[(num-1)*7+2] = tem2[2]
  1333. g[(num-1)*7+3] = tem2[3]
  1334. g[(num-1)*7+4] = tem2[4]
  1335. g[(num-1)*7+5] = tem2[5]
  1336. g[(num-1)*7+6] = tem2[6]
  1337. case "电量(度)":
  1338. h[(num-1)*7] = tem2[0]
  1339. h[(num-1)*7+1] = tem2[1]
  1340. h[(num-1)*7+2] = tem2[2]
  1341. h[(num-1)*7+3] = tem2[3]
  1342. h[(num-1)*7+4] = tem2[4]
  1343. h[(num-1)*7+5] = tem2[5]
  1344. h[(num-1)*7+6] = tem2[6]
  1345. case "柴油用量(L)":
  1346. o[(num-1)*7] = tem2[0]
  1347. o[(num-1)*7+1] = tem2[1]
  1348. o[(num-1)*7+2] = tem2[2]
  1349. o[(num-1)*7+3] = tem2[3]
  1350. o[(num-1)*7+4] = tem2[4]
  1351. o[(num-1)*7+5] = tem2[5]
  1352. o[(num-1)*7+6] = tem2[6]
  1353. case "用水量(吨)":
  1354. p[(num-1)*7] = tem2[0]
  1355. p[(num-1)*7+1] = tem2[1]
  1356. p[(num-1)*7+2] = tem2[2]
  1357. p[(num-1)*7+3] = tem2[3]
  1358. p[(num-1)*7+4] = tem2[4]
  1359. p[(num-1)*7+5] = tem2[5]
  1360. p[(num-1)*7+6] = tem2[6]
  1361. case "设备指标(万元)":
  1362. r[(num-1)*7] = tem2[0]
  1363. r[(num-1)*7+1] = tem2[1]
  1364. r[(num-1)*7+2] = tem2[2]
  1365. r[(num-1)*7+3] = tem2[3]
  1366. r[(num-1)*7+4] = tem2[4]
  1367. r[(num-1)*7+5] = tem2[5]
  1368. r[(num-1)*7+6] = tem2[6]
  1369. }
  1370. tem2 = []interface{}{}
  1371. }
  1372. } else {
  1373. println(err.Error())
  1374. }
  1375. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A), &c); err != nil {
  1376. println(err.Error())
  1377. }
  1378. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+1), &d); err != nil {
  1379. println(err.Error())
  1380. }
  1381. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+2), &e); err != nil {
  1382. println(err.Error())
  1383. }
  1384. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+3), &g); err != nil {
  1385. println(err.Error())
  1386. }
  1387. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+4), &r); err != nil {
  1388. println(err.Error())
  1389. }
  1390. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+5), &h); err != nil {
  1391. println(err.Error())
  1392. }
  1393. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+6), &p); err != nil {
  1394. println(err.Error())
  1395. }
  1396. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+7), &o); err != nil {
  1397. println(err.Error())
  1398. }
  1399. //sums[2] = sums[2].(int)+value["monthLimit"].(int)
  1400. //sums[1] = sums[1].(int)+value["monthBudget"].(int)
  1401. // 设置月份单元格字体
  1402. monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
  1403. if err != nil {
  1404. println("monthStyle err", err.Error())
  1405. }
  1406. f.SetCellStyle(sheetName, "A1", "CS300", monthStyle)
  1407. // 根据指定路径保存文件
  1408. }
  1409. func PathCheck(path string) (err error) {
  1410. b, err := PathExists(path)
  1411. if err != nil {
  1412. println("exist err", err)
  1413. }
  1414. if !b {
  1415. err = os.Mkdir(path, 0777)
  1416. if err != nil {
  1417. println("Mkdir err", err)
  1418. }
  1419. }
  1420. return
  1421. }
  1422. func PathExists(path string) (bool, error) {
  1423. _, err := os.Stat(path)
  1424. if err == nil {
  1425. return true, nil
  1426. }
  1427. if os.IsNotExist(err) {
  1428. return false, nil
  1429. }
  1430. return false, err
  1431. }
  1432. func DownloadDataJT(date string) (string, error) {
  1433. filename := setting.CurrentPath + "uploads/Downloadmailreport/" + date + "集团设备指标.xlsx"
  1434. exist, _ := FileExists(filename)
  1435. println(filename, exist)
  1436. if exist {
  1437. //return filename, nil
  1438. }
  1439. f := excelize.NewFile()
  1440. f.SetSheetName("Sheet1", "集团设备指标")
  1441. tem := make([]interface{}, 0)
  1442. tem1 := make([]interface{}, 0)
  1443. c := []interface{}{}
  1444. d := []interface{}{}
  1445. e := []interface{}{}
  1446. g := []interface{}{}
  1447. h := []interface{}{}
  1448. o := []interface{}{}
  1449. p := []interface{}{}
  1450. r := []interface{}{}
  1451. for i := 1; i <= 12; i++ {
  1452. a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
  1453. b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
  1454. c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1455. d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1456. e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1457. g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1458. h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1459. o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1460. p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1461. r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1462. tem = append(tem, a...)
  1463. tem1 = append(tem1, b...)
  1464. }
  1465. if err := SetSheetRow(f, "集团设备指标", "N1", &tem); err != nil {
  1466. println(err.Error())
  1467. }
  1468. //year :=time.Now().Add(-24*time.Hour).Format("2006")
  1469. year := ""
  1470. datetem, _ := strconv.Atoi(date[:4])
  1471. if date > time.Now().Add(-24*time.Hour).Format("2006")+"-01-01" {
  1472. year = strconv.Itoa(datetem)
  1473. } else {
  1474. year = strconv.Itoa(datetem - 1)
  1475. }
  1476. f.SetCellValue("集团设备指标", "A1", "时间")
  1477. f.MergeCell("集团设备指标", "B1", "M1")
  1478. f.MergeCell("集团设备指标", "N1", "T1")
  1479. f.MergeCell("集团设备指标", "U1", "AA1")
  1480. f.MergeCell("集团设备指标", "AB1", "AH1")
  1481. f.MergeCell("集团设备指标", "AI1", "AO1")
  1482. f.MergeCell("集团设备指标", "AP1", "AV1")
  1483. f.MergeCell("集团设备指标", "AW1", "BC1")
  1484. f.MergeCell("集团设备指标", "BD1", "BJ1")
  1485. f.MergeCell("集团设备指标", "BK1", "BQ1")
  1486. f.MergeCell("集团设备指标", "BR1", "BX1")
  1487. f.MergeCell("集团设备指标", "BY1", "CE1")
  1488. f.MergeCell("集团设备指标", "CF1", "CL1")
  1489. f.MergeCell("集团设备指标", "CM1", "CS1")
  1490. f.SetCellValue("集团设备指标", "H1", year+"年")
  1491. SetSheetRow(f, "集团设备指标", "A2", &[]interface{}{"牧场", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率", "迄今饲养头日", "迄今产量(公斤)", "迄今实际单头牛成本", "迄今实际公斤奶成本(元/公斤)"})
  1492. if err := SetSheetRow(f, "集团设备指标", "N2", &tem1); err != nil {
  1493. println(err.Error())
  1494. }
  1495. A := 3
  1496. pastures, err := restful.MapStrList("select id,name from pasture where isdel = 0 AND id <> 18 order by sort")
  1497. if err != nil {
  1498. println("err sql", err.Error())
  1499. } else {
  1500. for _, value := range pastures {
  1501. GetMailDataByPasture("集团设备指标", value["name"], date, value["id"], A, f)
  1502. println(value["name"])
  1503. A = A + 8
  1504. }
  1505. }
  1506. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJY")
  1507. valuesMap1, err1 := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportJM")
  1508. sqls := ""
  1509. parammaps := make(map[string]interface{}, 0)
  1510. parammaps["month"] = date
  1511. s_params := make([]interface{}, 0)
  1512. if err == nil && len(valuesMap) > 0 {
  1513. sqls = valuesMap["sqlstr"]
  1514. paramslist := strings.Split(valuesMap["params"], ",")
  1515. if len(paramslist) > 0 && valuesMap["params"] != "" {
  1516. for _, value := range paramslist {
  1517. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  1518. }
  1519. }
  1520. }
  1521. tem = []interface{}{}
  1522. values, err := restful.MapStrList(sqls, s_params...)
  1523. B := A
  1524. temMap := make(map[string][]interface{}, 0)
  1525. if err == nil {
  1526. for _, value := range values {
  1527. tem = append(tem, value["ftype"])
  1528. tem = append(tem, value["monthBudget"])
  1529. tem = append(tem, value["monthLimit"])
  1530. tem = append(tem, value["qmonthBudget"])
  1531. tem = append(tem, value["sumPrice"])
  1532. tem = append(tem, value["asave"])
  1533. tem = append(tem, value["dac"])
  1534. tem = append(tem, value["dacY"])
  1535. tem = append(tem, value["cowNum"])
  1536. tem = append(tem, value["saleNum"])
  1537. tem = append(tem, value["cowprice"])
  1538. tem = append(tem, value["milkprice"])
  1539. temMap[value["ftype"]] = tem
  1540. tem = []interface{}{}
  1541. //B++
  1542. }
  1543. } else {
  1544. println(err.Error())
  1545. }
  1546. if m, ok := temMap["维修费(万元)"]; ok {
  1547. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1548. println(err.Error())
  1549. }
  1550. B++
  1551. } else {
  1552. temw := []interface{}{"维修费(万元)"}
  1553. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1554. println(err.Error())
  1555. }
  1556. B++
  1557. }
  1558. if m, ok := temMap["电费(万元)"]; ok {
  1559. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1560. println(err.Error())
  1561. }
  1562. B++
  1563. } else {
  1564. temw := []interface{}{"电费(万元)"}
  1565. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1566. println(err.Error())
  1567. }
  1568. B++
  1569. }
  1570. if m, ok := temMap["燃动费(万元)"]; ok {
  1571. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1572. println(err.Error())
  1573. }
  1574. B++
  1575. } else {
  1576. temw := []interface{}{"燃动费(万元)"}
  1577. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1578. println(err.Error())
  1579. }
  1580. B++
  1581. }
  1582. if m, ok := temMap["水费(万元)"]; ok {
  1583. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1584. println(err.Error())
  1585. }
  1586. B++
  1587. } else {
  1588. temw := []interface{}{"水费(万元)"}
  1589. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1590. println(err.Error())
  1591. }
  1592. B++
  1593. }
  1594. if m, ok := temMap["设备指标(万元)"]; ok {
  1595. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1596. println(err.Error())
  1597. }
  1598. B++
  1599. } else {
  1600. temw := []interface{}{"设备指标(万元)"}
  1601. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1602. println(err.Error())
  1603. }
  1604. B++
  1605. }
  1606. if m, ok := temMap["电量(度)"]; ok {
  1607. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1608. println(err.Error())
  1609. }
  1610. B++
  1611. } else {
  1612. temw := []interface{}{"电量(度)"}
  1613. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1614. println(err.Error())
  1615. }
  1616. B++
  1617. }
  1618. if m, ok := temMap["用水量(吨)"]; ok {
  1619. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1620. println(err.Error())
  1621. }
  1622. B++
  1623. } else {
  1624. temw := []interface{}{"用水量(吨)"}
  1625. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1626. println(err.Error())
  1627. }
  1628. B++
  1629. }
  1630. if m, ok := temMap["柴油用量(L)"]; ok {
  1631. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &m); err != nil {
  1632. println(err.Error())
  1633. }
  1634. B++
  1635. } else {
  1636. temw := []interface{}{"柴油用量(L)"}
  1637. if err := SetSheetRow(f, "集团设备指标", "B"+strconv.Itoa(B), &temw); err != nil {
  1638. println(err.Error())
  1639. }
  1640. B++
  1641. }
  1642. s_params = make([]interface{}, 0)
  1643. if err1 == nil && len(valuesMap1) > 0 {
  1644. sqls = valuesMap1["sqlstr"]
  1645. parammaps := make(map[string]interface{}, 0)
  1646. parammaps["month"] = date
  1647. paramslist := strings.Split(valuesMap1["params"], ",")
  1648. if len(paramslist) > 0 && valuesMap1["params"] != "" {
  1649. for _, value := range paramslist {
  1650. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  1651. }
  1652. }
  1653. }
  1654. f.SetCellValue("集团设备指标", "A"+strconv.Itoa(A), "集团")
  1655. f.MergeCell("集团设备指标", "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
  1656. values, err = restful.MapStrList(sqls, s_params...)
  1657. tem = []interface{}{}
  1658. tem2 := []interface{}{}
  1659. if err == nil {
  1660. for _, value := range values {
  1661. tem2 = append(tem2, value["monthBudget"])
  1662. tem2 = append(tem2, value["monthLimit"])
  1663. tem2 = append(tem2, value["qmonthBudget"])
  1664. tem2 = append(tem2, value["sumPrice"])
  1665. tem2 = append(tem2, value["asave"])
  1666. tem2 = append(tem2, value["dac"])
  1667. tem2 = append(tem2, value["dacY"])
  1668. num, _ := strconv.Atoi(value["num"])
  1669. switch value["ftype"] {
  1670. case "维修费(万元)":
  1671. c[(num-1)*7] = tem2[0]
  1672. c[(num-1)*7+1] = tem2[1]
  1673. c[(num-1)*7+2] = tem2[2]
  1674. c[(num-1)*7+3] = tem2[3]
  1675. c[(num-1)*7+4] = tem2[4]
  1676. c[(num-1)*7+5] = tem2[5]
  1677. c[(num-1)*7+6] = tem2[6]
  1678. case "电费(万元)":
  1679. d[(num-1)*7] = tem2[0]
  1680. d[(num-1)*7+1] = tem2[1]
  1681. d[(num-1)*7+2] = tem2[2]
  1682. d[(num-1)*7+3] = tem2[3]
  1683. d[(num-1)*7+4] = tem2[4]
  1684. d[(num-1)*7+5] = tem2[5]
  1685. d[(num-1)*7+6] = tem2[6]
  1686. case "燃动费(万元)":
  1687. e[(num-1)*7] = tem2[0]
  1688. e[(num-1)*7+1] = tem2[1]
  1689. e[(num-1)*7+2] = tem2[2]
  1690. e[(num-1)*7+3] = tem2[3]
  1691. e[(num-1)*7+4] = tem2[4]
  1692. e[(num-1)*7+5] = tem2[5]
  1693. e[(num-1)*7+6] = tem2[6]
  1694. case "水费(万元)":
  1695. g[(num-1)*7] = tem2[0]
  1696. g[(num-1)*7+1] = tem2[1]
  1697. g[(num-1)*7+2] = tem2[2]
  1698. g[(num-1)*7+3] = tem2[3]
  1699. g[(num-1)*7+4] = tem2[4]
  1700. g[(num-1)*7+5] = tem2[5]
  1701. g[(num-1)*7+6] = tem2[6]
  1702. case "电量(度)":
  1703. h[(num-1)*7] = tem2[0]
  1704. h[(num-1)*7+1] = tem2[1]
  1705. h[(num-1)*7+2] = tem2[2]
  1706. h[(num-1)*7+3] = tem2[3]
  1707. h[(num-1)*7+4] = tem2[4]
  1708. h[(num-1)*7+5] = tem2[5]
  1709. h[(num-1)*7+6] = tem2[6]
  1710. case "柴油用量(L)":
  1711. o[(num-1)*7] = tem2[0]
  1712. o[(num-1)*7+1] = tem2[1]
  1713. o[(num-1)*7+2] = tem2[2]
  1714. o[(num-1)*7+3] = tem2[3]
  1715. o[(num-1)*7+4] = tem2[4]
  1716. o[(num-1)*7+5] = tem2[5]
  1717. o[(num-1)*7+6] = tem2[6]
  1718. case "用水量(吨)":
  1719. p[(num-1)*7] = tem2[0]
  1720. p[(num-1)*7+1] = tem2[1]
  1721. p[(num-1)*7+2] = tem2[2]
  1722. p[(num-1)*7+3] = tem2[3]
  1723. p[(num-1)*7+4] = tem2[4]
  1724. p[(num-1)*7+5] = tem2[5]
  1725. p[(num-1)*7+6] = tem2[6]
  1726. case "设备指标(万元)":
  1727. r[(num-1)*7] = tem2[0]
  1728. r[(num-1)*7+1] = tem2[1]
  1729. r[(num-1)*7+2] = tem2[2]
  1730. r[(num-1)*7+3] = tem2[3]
  1731. r[(num-1)*7+4] = tem2[4]
  1732. r[(num-1)*7+5] = tem2[5]
  1733. r[(num-1)*7+6] = tem2[6]
  1734. }
  1735. tem2 = []interface{}{}
  1736. }
  1737. } else {
  1738. println(err.Error())
  1739. }
  1740. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A), &c); err != nil {
  1741. println(err.Error())
  1742. }
  1743. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+1), &d); err != nil {
  1744. println(err.Error())
  1745. }
  1746. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+2), &e); err != nil {
  1747. println(err.Error())
  1748. }
  1749. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+3), &g); err != nil {
  1750. println(err.Error())
  1751. }
  1752. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+4), &r); err != nil {
  1753. println(err.Error())
  1754. }
  1755. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+5), &h); err != nil {
  1756. println(err.Error())
  1757. }
  1758. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+6), &p); err != nil {
  1759. println(err.Error())
  1760. }
  1761. if err := SetSheetRow(f, "集团设备指标", "N"+strconv.Itoa(A+7), &o); err != nil {
  1762. println(err.Error())
  1763. }
  1764. // 设置月份单元格字体
  1765. monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
  1766. if err != nil {
  1767. println("monthStyle err", err.Error())
  1768. }
  1769. f.SetCellStyle("集团设备指标", "A1", "CS154", monthStyle)
  1770. // 根据指定路径保存文件
  1771. err = PathCheck("uploads/Downloadmailreport") //检查路径并创建
  1772. //os.Remove(filename)
  1773. if err != nil {
  1774. println("PathCheck err", err)
  1775. }
  1776. if err := f.SaveAs(filename); err != nil {
  1777. println(err.Error())
  1778. return "", err
  1779. }
  1780. return filename, err
  1781. }
  1782. func DownloadDataMC(sheetName, date string, pastureId interface{}) (string, error) {
  1783. filename := setting.CurrentPath + "uploads/Downloadmailreport/" + date + sheetName + "设备指标.xlsx"
  1784. exist, _ := FileExists(filename)
  1785. if exist {
  1786. //return filename, nil
  1787. }
  1788. f := excelize.NewFile()
  1789. f.SetSheetName("Sheet1", sheetName)
  1790. tem := make([]interface{}, 0)
  1791. tem1 := make([]interface{}, 0)
  1792. c := []interface{}{}
  1793. d := []interface{}{}
  1794. e := []interface{}{}
  1795. g := []interface{}{}
  1796. h := []interface{}{}
  1797. o := []interface{}{}
  1798. p := []interface{}{}
  1799. r := []interface{}{}
  1800. for i := 1; i <= 12; i++ {
  1801. a := []interface{}{strconv.Itoa(i) + "月", nil, nil, nil, nil, nil, nil}
  1802. b := []interface{}{"预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "月度达成率"}
  1803. c = append(c, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1804. d = append(d, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1805. e = append(e, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1806. g = append(g, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1807. h = append(h, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1808. o = append(o, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1809. p = append(p, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1810. r = append(r, []interface{}{0, 0, 0, 0, 0, 0, 0}...)
  1811. tem = append(tem, a...)
  1812. tem1 = append(tem1, b...)
  1813. }
  1814. if err := SetSheetRow(f, sheetName, "J1", &tem); err != nil {
  1815. println(err.Error())
  1816. }
  1817. year := ""
  1818. datetem, _ := strconv.Atoi(date[:4])
  1819. if date > time.Now().Add(-24*time.Hour).Format("2006")+"-01-01" {
  1820. year = strconv.Itoa(datetem)
  1821. } else {
  1822. year = strconv.Itoa(datetem - 1)
  1823. }
  1824. f.SetCellValue(sheetName, "A1", "时间")
  1825. f.MergeCell(sheetName, "B1", "I1")
  1826. f.MergeCell(sheetName, "J1", "P1")
  1827. f.MergeCell(sheetName, "Q1", "W1")
  1828. f.MergeCell(sheetName, "X1", "AD1")
  1829. f.MergeCell(sheetName, "AE1", "AK1")
  1830. f.MergeCell(sheetName, "AL1", "AR1")
  1831. f.MergeCell(sheetName, "AS1", "AY1")
  1832. f.MergeCell(sheetName, "AZ1", "BF1")
  1833. f.MergeCell(sheetName, "BG1", "BM1")
  1834. f.MergeCell(sheetName, "BN1", "BT1")
  1835. f.MergeCell(sheetName, "BU1", "CA1")
  1836. f.MergeCell(sheetName, "CB1", "CH1")
  1837. f.MergeCell(sheetName, "CI1", "CO1")
  1838. f.SetCellValue(sheetName, "H1", year+"年")
  1839. SetSheetRow(f, sheetName, "A2", &[]interface{}{"部门", "成本项目", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "迄今达成率", "年度达成率"})
  1840. if err := SetSheetRow(f, sheetName, "J2", &tem1); err != nil {
  1841. println(err.Error())
  1842. }
  1843. A := 3
  1844. pastures, err := restful.MapStrList("select id,name from department where pastureId=? and isDel = 0 AND enable =1 and id <> ?", pastureId, pastureId)
  1845. if err != nil {
  1846. println("err sql", err.Error())
  1847. } else {
  1848. for _, value := range pastures {
  1849. GetMailDataByDept(sheetName, value["name"], date, value["id"], pastureId, A, f)
  1850. println(value["name"])
  1851. A = A + 8
  1852. }
  1853. }
  1854. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMY")
  1855. valuesMap1, err1 := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", "getMailReportMM")
  1856. sqls := ""
  1857. parammaps := make(map[string]interface{}, 0)
  1858. parammaps["month"] = date
  1859. parammaps["pastureId"] = pastureId
  1860. s_params := make([]interface{}, 0)
  1861. if err == nil && len(valuesMap) > 0 {
  1862. sqls = valuesMap["sqlstr"]
  1863. paramslist := strings.Split(valuesMap["params"], ",")
  1864. if len(paramslist) > 0 && valuesMap["params"] != "" {
  1865. for _, value := range paramslist {
  1866. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  1867. }
  1868. }
  1869. }
  1870. tem = []interface{}{}
  1871. //sums := []interface{}{"设备指标(万元)",0,0,0,0,0,0,0,0}
  1872. values, err := restful.MapStrList(sqls, s_params...)
  1873. B := A
  1874. temMap := make(map[string][]interface{}, 0)
  1875. if err == nil {
  1876. for _, value := range values {
  1877. tem = append(tem, value["ftype"])
  1878. tem = append(tem, value["monthBudget"])
  1879. tem = append(tem, value["monthLimit"])
  1880. tem = append(tem, value["qmonthBudget"])
  1881. tem = append(tem, value["sumPrice"])
  1882. tem = append(tem, value["asave"])
  1883. tem = append(tem, value["dac"])
  1884. tem = append(tem, value["dacY"])
  1885. temMap[value["ftype"]] = tem
  1886. //if err := SetSheetRow(f,sheetName, "B"+strconv.Itoa(B),&tem); err != nil {
  1887. // println(err.Error())
  1888. //}
  1889. tem = []interface{}{}
  1890. //B++
  1891. }
  1892. } else {
  1893. println(err.Error())
  1894. }
  1895. if m, ok := temMap["维修费(万元)"]; ok {
  1896. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1897. println(err.Error())
  1898. }
  1899. B++
  1900. } else {
  1901. temw := []interface{}{"维修费(万元)"}
  1902. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1903. println(err.Error())
  1904. }
  1905. B++
  1906. }
  1907. if m, ok := temMap["电费(万元)"]; ok {
  1908. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1909. println(err.Error())
  1910. }
  1911. B++
  1912. } else {
  1913. temw := []interface{}{"电费(万元)"}
  1914. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1915. println(err.Error())
  1916. }
  1917. B++
  1918. }
  1919. if m, ok := temMap["燃动费(万元)"]; ok {
  1920. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1921. println(err.Error())
  1922. }
  1923. B++
  1924. } else {
  1925. temw := []interface{}{"燃动费(万元)"}
  1926. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1927. println(err.Error())
  1928. }
  1929. B++
  1930. }
  1931. if m, ok := temMap["水费(万元)"]; ok {
  1932. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1933. println(err.Error())
  1934. }
  1935. B++
  1936. } else {
  1937. temw := []interface{}{"水费(万元)"}
  1938. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1939. println(err.Error())
  1940. }
  1941. B++
  1942. }
  1943. if m, ok := temMap["设备指标(万元)"]; ok {
  1944. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1945. println(err.Error())
  1946. }
  1947. B++
  1948. } else {
  1949. temw := []interface{}{"设备指标(万元)"}
  1950. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1951. println(err.Error())
  1952. }
  1953. B++
  1954. }
  1955. if m, ok := temMap["电量(度)"]; ok {
  1956. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1957. println(err.Error())
  1958. }
  1959. B++
  1960. } else {
  1961. temw := []interface{}{"电量(度)"}
  1962. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1963. println(err.Error())
  1964. }
  1965. B++
  1966. }
  1967. if m, ok := temMap["用水量(吨)"]; ok {
  1968. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1969. println(err.Error())
  1970. }
  1971. B++
  1972. } else {
  1973. temw := []interface{}{"用水量(吨)"}
  1974. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1975. println(err.Error())
  1976. }
  1977. B++
  1978. }
  1979. if m, ok := temMap["柴油用量(L)"]; ok {
  1980. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &m); err != nil {
  1981. println(err.Error())
  1982. }
  1983. B++
  1984. } else {
  1985. temw := []interface{}{"柴油用量(L)"}
  1986. if err := SetSheetRow(f, sheetName, "B"+strconv.Itoa(B), &temw); err != nil {
  1987. println(err.Error())
  1988. }
  1989. B++
  1990. }
  1991. s_params = make([]interface{}, 0)
  1992. if err1 == nil && len(valuesMap1) > 0 {
  1993. sqls = valuesMap1["sqlstr"]
  1994. parammaps := make(map[string]interface{}, 0)
  1995. parammaps["month"] = date
  1996. parammaps["pastureId"] = pastureId
  1997. paramslist := strings.Split(valuesMap1["params"], ",")
  1998. if len(paramslist) > 0 && valuesMap1["params"] != "" {
  1999. for _, value := range paramslist {
  2000. s_params = append(s_params, parammaps[strings.Trim(value, " ")])
  2001. }
  2002. }
  2003. }
  2004. f.SetCellValue(sheetName, "A"+strconv.Itoa(A), sheetName)
  2005. f.MergeCell(sheetName, "A"+strconv.Itoa(A), "A"+strconv.Itoa(A+7))
  2006. values, err = restful.MapStrList(sqls, s_params...)
  2007. tem = []interface{}{}
  2008. //d := append(c,nil)
  2009. //e := append(c,nil)
  2010. //g := append(c,nil)
  2011. //h := append(c,nil)
  2012. //o := append(c,nil)
  2013. //p := append(c,nil)
  2014. tem2 := []interface{}{}
  2015. if err == nil {
  2016. for _, value := range values {
  2017. tem2 = append(tem2, value["monthBudget"])
  2018. tem2 = append(tem2, value["monthLimit"])
  2019. tem2 = append(tem2, value["qmonthBudget"])
  2020. tem2 = append(tem2, value["sumPrice"])
  2021. tem2 = append(tem2, value["asave"])
  2022. tem2 = append(tem2, value["dac"])
  2023. tem2 = append(tem2, value["dacY"])
  2024. num, _ := strconv.Atoi(value["num"])
  2025. switch value["ftype"] {
  2026. case "维修费(万元)":
  2027. c[(num-1)*7] = tem2[0]
  2028. c[(num-1)*7+1] = tem2[1]
  2029. c[(num-1)*7+2] = tem2[2]
  2030. c[(num-1)*7+3] = tem2[3]
  2031. c[(num-1)*7+4] = tem2[4]
  2032. c[(num-1)*7+5] = tem2[5]
  2033. c[(num-1)*7+6] = tem2[6]
  2034. case "电费(万元)":
  2035. d[(num-1)*7] = tem2[0]
  2036. d[(num-1)*7+1] = tem2[1]
  2037. d[(num-1)*7+2] = tem2[2]
  2038. d[(num-1)*7+3] = tem2[3]
  2039. d[(num-1)*7+4] = tem2[4]
  2040. d[(num-1)*7+5] = tem2[5]
  2041. d[(num-1)*7+6] = tem2[6]
  2042. case "燃动费(万元)":
  2043. e[(num-1)*7] = tem2[0]
  2044. e[(num-1)*7+1] = tem2[1]
  2045. e[(num-1)*7+2] = tem2[2]
  2046. e[(num-1)*7+3] = tem2[3]
  2047. e[(num-1)*7+4] = tem2[4]
  2048. e[(num-1)*7+5] = tem2[5]
  2049. e[(num-1)*7+6] = tem2[6]
  2050. case "水费(万元)":
  2051. g[(num-1)*7] = tem2[0]
  2052. g[(num-1)*7+1] = tem2[1]
  2053. g[(num-1)*7+2] = tem2[2]
  2054. g[(num-1)*7+3] = tem2[3]
  2055. g[(num-1)*7+4] = tem2[4]
  2056. g[(num-1)*7+5] = tem2[5]
  2057. g[(num-1)*7+6] = tem2[6]
  2058. case "电量(度)":
  2059. h[(num-1)*7] = tem2[0]
  2060. h[(num-1)*7+1] = tem2[1]
  2061. h[(num-1)*7+2] = tem2[2]
  2062. h[(num-1)*7+3] = tem2[3]
  2063. h[(num-1)*7+4] = tem2[4]
  2064. h[(num-1)*7+5] = tem2[5]
  2065. h[(num-1)*7+6] = tem2[6]
  2066. case "柴油用量(L)":
  2067. o[(num-1)*7] = tem2[0]
  2068. o[(num-1)*7+1] = tem2[1]
  2069. o[(num-1)*7+2] = tem2[2]
  2070. o[(num-1)*7+3] = tem2[3]
  2071. o[(num-1)*7+4] = tem2[4]
  2072. o[(num-1)*7+5] = tem2[5]
  2073. o[(num-1)*7+6] = tem2[6]
  2074. case "用水量(吨)":
  2075. p[(num-1)*7] = tem2[0]
  2076. p[(num-1)*7+1] = tem2[1]
  2077. p[(num-1)*7+2] = tem2[2]
  2078. p[(num-1)*7+3] = tem2[3]
  2079. p[(num-1)*7+4] = tem2[4]
  2080. p[(num-1)*7+5] = tem2[5]
  2081. p[(num-1)*7+6] = tem2[6]
  2082. case "设备指标(万元)":
  2083. r[(num-1)*7] = tem2[0]
  2084. r[(num-1)*7+1] = tem2[1]
  2085. r[(num-1)*7+2] = tem2[2]
  2086. r[(num-1)*7+3] = tem2[3]
  2087. r[(num-1)*7+4] = tem2[4]
  2088. r[(num-1)*7+5] = tem2[5]
  2089. r[(num-1)*7+6] = tem2[6]
  2090. }
  2091. tem2 = []interface{}{}
  2092. }
  2093. } else {
  2094. println(err.Error())
  2095. }
  2096. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A), &c); err != nil {
  2097. println(err.Error())
  2098. }
  2099. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+1), &d); err != nil {
  2100. println(err.Error())
  2101. }
  2102. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+2), &e); err != nil {
  2103. println(err.Error())
  2104. }
  2105. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+3), &g); err != nil {
  2106. println(err.Error())
  2107. }
  2108. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+4), &r); err != nil {
  2109. println(err.Error())
  2110. }
  2111. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+5), &h); err != nil {
  2112. println(err.Error())
  2113. }
  2114. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+6), &p); err != nil {
  2115. println(err.Error())
  2116. }
  2117. if err := SetSheetRow(f, sheetName, "J"+strconv.Itoa(A+7), &o); err != nil {
  2118. println(err.Error())
  2119. }
  2120. //sums[2] = sums[2].(int)+value["monthLimit"].(int)
  2121. //sums[1] = sums[1].(int)+value["monthBudget"].(int)
  2122. // 设置月份单元格字体
  2123. monthStyle, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
  2124. if err != nil {
  2125. println("monthStyle err", err.Error())
  2126. }
  2127. f.SetCellStyle(sheetName, "A1", "CS300", monthStyle)
  2128. // 根据指定路径保存文件
  2129. //filename :="uploads/Downloadmailreport/" + date +sheetName+"设备指标.xlsx"
  2130. err = PathCheck("uploads/Downloadmailreport") //检查路径并创建
  2131. //os.Remove(filename)
  2132. if err != nil {
  2133. println("PathCheck err", err)
  2134. }
  2135. if err := f.SaveAs(filename); err != nil {
  2136. println(err.Error())
  2137. return "", err
  2138. }
  2139. return filename, err
  2140. }
  2141. func FileExists(path string) (bool, error) {
  2142. _, err := os.Stat(path)
  2143. if err == nil {
  2144. return true, nil
  2145. }
  2146. if os.IsNotExist(err) {
  2147. return false, nil
  2148. }
  2149. return false, err
  2150. }
  2151. //测试用的
  2152. func Sssss() {
  2153. sqls := "SELECT bbd.`buyeCode`,p.`providerName`,bd.receiveAmount,bbd.`matchCode`,bd.`amount`,bd.`sumAmount`,bd.departmentName,pa.name pastureName," +
  2154. "bd.note,c.id,c.bigId,c.pastureId,ps.id partId,ifnull(ps.name,c.partName) partName,ifnull(ps.partCode,c.partCode) partCode," +
  2155. "ifnull(ps.specification,c.specification) specification,ifnull(brand.brandName,c.brand) brand,ifnull(ps.unit,c.unit) unit," +
  2156. "ifnull(TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM bd.price))),TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))))" +
  2157. "price,brand.id brandId,c.inventoryType,c.planAmount,c.remark,c.enable,c.isZeroStock,e.`empname`," +
  2158. "DATE_FORMAT(bbd.buyerDate,'%Y-%m-%d')buyerDate,DATE_FORMAT(bbd.DoneDate, '%Y-%m-%d') DoneDate " +
  2159. "FROM buydetail bd INNER JOIN bigbuydetail bbd ON bbd.id = bd.`bigId` LEFT JOIN provider p ON p.id = bbd.`providerId`" +
  2160. "LEFT JOIN contract c ON c.id = bd.`contractId` LEFT JOIN emp e ON e.id = bbd.`buyerPerson` " +
  2161. "LEFT JOIN bigpartdeal bpd ON bpd.`matchCode` = bbd.`matchCode` inner join pasture pa on pa.id = bbd.pastureId " +
  2162. "LEFT JOIN parts ps ON ps.partCode =bd.partCode LEFT JOIN brand ON brand.id=bd.brandId " +
  2163. "where bbd.`enable`=0 and bd.amount > 0 and bbd.buyerDate < ? and bbd.buyerDate > ? and pa.name='通辽牧场' "
  2164. queryData, err := restful.MapStrList(sqls, "2021-08-27", "2021-06-30")
  2165. //s_params := make([]interface{}, 0)
  2166. //queryData, err := restful.QueryByListListT(sql, 0, 0, s_params, tx)
  2167. if err != nil {
  2168. fmt.Println(err)
  2169. } else {
  2170. f := excelize.NewFile()
  2171. // 创建一个工作表
  2172. //供应商 单价 申购数量 采购数量 入库数 申购部门 采购人 配单日期 入库时间
  2173. index := f.NewSheet("采购明细")
  2174. f.SetColWidth("采购明细", "A", "R", 20)
  2175. columns := []string{"备件品牌", "计量单位", "供应商", "单价", "申购数量", "采购数量", "入库数", "申购部门", "采购人", "配单日期",
  2176. "入库时间"}
  2177. 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"}
  2178. for i, v := range columns {
  2179. f.SetCellValue("采购明细", letters[i]+"1", v)
  2180. }
  2181. fmt.Println(len(queryData))
  2182. for i, v := range queryData {
  2183. // 设置单元格的值
  2184. value := []interface{}{v["matchCode"], v["unit"], v["providerName"], v["price"], v["sumAmount"], v["amount"], v["receiveAmount"],
  2185. v["departmentName"], v["empname"], v["buyerDate"], v["DoneDate"]}
  2186. for a, b := range value {
  2187. f.SetCellValue("采购明细", letters[a]+strconv.Itoa(i+2), b)
  2188. }
  2189. }
  2190. // 设置工作簿的默认工作表
  2191. f.SetActiveSheet(index)
  2192. // 根据指定路径保存文件
  2193. if err := f.SaveAs("D:/project/go/src/KPTcomm/test/采购明细.xlsx"); err != nil {
  2194. fmt.Println(err)
  2195. }
  2196. }
  2197. }
  2198. // 测试
  2199. func DownloadEquipment(parammaps string) (string, error) {
  2200. //appG := app.Gin{C: context}
  2201. data := make(map[string]interface{}, 0)
  2202. filename := setting.CurrentPath + "uploads/Downloadmailreport/" + "设备指标.xlsx"
  2203. exist, _ := FileExists(filename)
  2204. if exist {
  2205. //return filename, nil
  2206. }
  2207. f := excelize.NewFile()
  2208. Style, err := f.NewStyle("{\"Alignment\":{\"Vertical\": \"center\", \"Horizontal\":\"center\"}}")
  2209. columns := []string{"设备指标", "维修费", "水费", "电费", "柴油费", "水量", "电量", "柴油用量"}
  2210. //序号 牧场 部门 预算 内控 迄今内控 迄今实际 实际节约 实际达成率 单头牛预算 单头牛内控 单头牛迄今内控 单头牛迄今实际 单头牛实际节约
  2211. columns1 := []string{"序号", "牧场", "部门", "预算", "内控", "迄今内控", "迄今实际", "实际节约", "实际达成率", "单头牛预算",
  2212. "单头牛内控", "单头牛迄今内控", "单头牛迄今实际", "单头牛实际节约"}
  2213. 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"}
  2214. for i, v := range columns {
  2215. f.NewSheet("Sheet" + strconv.Itoa(i+1))
  2216. f.SetSheetName("Sheet"+strconv.Itoa(i+1), v)
  2217. f.MergeCell(v, "A1", "C1")
  2218. f.MergeCell(v, "D1", "I1")
  2219. f.MergeCell(v, "J1", "N1")
  2220. f.SetCellValue(v, "A1", "设备指标")
  2221. f.SetCellValue(v, "D1", "设备指标")
  2222. f.SetCellValue(v, "J1", "单头牛指标")
  2223. f.SetCellStyle(v, "A1", "CS154", Style)
  2224. f.SetCellStyle(v, "D1", "CS154", Style)
  2225. f.SetCellStyle(v, "J1", "CS154", Style)
  2226. f.SetColWidth(v, "A", "N", 20)
  2227. for i1, v1 := range columns1 {
  2228. f.SetCellValue(v, letters[i1]+"2", v1)
  2229. }
  2230. }
  2231. sqlnames := []string{"getChooseEqMonthBudgetListSumAll", "getChooseMonthWX", "getChooseElectricityPrice", "getChooseMonthiolPrice",
  2232. "getChooseWaterPrice", "getChooseMonthElectricity", "getChooseMonthWater", "getChooseMonthOilT"}
  2233. xx := 0
  2234. for z, sqlname := range sqlnames {
  2235. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", sqlname)
  2236. parammap := make(map[string]interface{}, 0)
  2237. json.Unmarshal([]byte(parammaps), &parammap)
  2238. s_params := make([]interface{}, 0)
  2239. paramslist := strings.Split(valuesMap["params"], ",")
  2240. if len(paramslist) > 0 && valuesMap["params"] != "" {
  2241. for _, value := range paramslist {
  2242. s_params = append(s_params, parammap[strings.Trim(value, " ")])
  2243. }
  2244. }
  2245. values, err := restful.MapStrList(valuesMap["sqlstr"], s_params...)
  2246. if err != nil {
  2247. fmt.Println(err)
  2248. } else {
  2249. for i, v := range values {
  2250. value := []interface{}{columns[z], v["pastureName"], "全厂区", v["monthBudget"], v["monthLimit"], v["qmonthBudget"], v["sumPrice"],
  2251. v["asave"], v["realReason"], v["oneCowBudget"], v["oneCowLimit"], v["oneCowQmonthBudget"], v["oneCowSumPrice"], v["oneCowAsave"]}
  2252. for a, b := range value {
  2253. f.SetCellValue("设备指标", letters[a]+strconv.Itoa(i+xx+3), b)
  2254. }
  2255. }
  2256. }
  2257. xx += len(values)
  2258. }
  2259. //"维修费","水费","电费","柴油费","水量","电量","柴油用量"
  2260. // 其他的表格
  2261. sqlnamesDepartment := []string{
  2262. "getChooseMonthWX",
  2263. "getChooseWaterPrice",
  2264. "getChooseElectricityPrice",
  2265. "getChooseMonthiolPrice",
  2266. "getChooseMonthWater",
  2267. "getChooseMonthElectricity",
  2268. "getChooseMonthOilT"}
  2269. // sqlnamesDepartment := []string{"getChooseMonthWXDepartment", "getChooseWaterPriceDepartment", "getChooseElectricityPriceDepartment", "getChooseMonthiolPriceDepartment",
  2270. // "getChooseMonthWaterDepartment", "getChooseMonthElectricityDepartment", "getChooseMonthOilTDepartment"}
  2271. columnss := []string{"维修费", "水费", "电费", "柴油费", "水量", "电量", "柴油用量"}
  2272. for z, sqlname := range sqlnamesDepartment {
  2273. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", sqlname)
  2274. parammap := make(map[string]interface{}, 0)
  2275. json.Unmarshal([]byte(parammaps), &parammap)
  2276. s_params := make([]interface{}, 0)
  2277. paramslist := strings.Split(valuesMap["params"], ",")
  2278. if len(paramslist) > 0 && valuesMap["params"] != "" {
  2279. for _, value := range paramslist {
  2280. s_params = append(s_params, parammap[strings.Trim(value, " ")])
  2281. }
  2282. }
  2283. values, err := restful.MapStrList(valuesMap["sqlstr"], s_params...)
  2284. if err != nil {
  2285. fmt.Println(err)
  2286. } else {
  2287. for i, v := range values {
  2288. value := []interface{}{v["sort"], v["pastureName"], v["deptname"], v["monthBudget"], v["monthLimit"], v["qmonthBudget"], v["sumPrice"],
  2289. v["asave"], v["realReason"], v["oneCowBudget"], v["oneCowLimit"], v["oneCowQmonthBudget"], v["oneCowSumPrice"], v["oneCowAsave"]}
  2290. for a, b := range value {
  2291. f.SetCellValue(columnss[z], letters[a]+strconv.Itoa(i+3), b)
  2292. }
  2293. }
  2294. }
  2295. }
  2296. if err != nil {
  2297. data["err_count"] = err
  2298. logging.Error("设备指标导出__error:", err)
  2299. } else {
  2300. err = PathCheck("uploads/Downloadmailreport") //检查路径并创建
  2301. //os.Remove(filename)
  2302. if err != nil {
  2303. println("PathCheck err", err)
  2304. }
  2305. if err := f.SaveAs(filename); err != nil {
  2306. println(err.Error())
  2307. return "", err
  2308. }
  2309. //data["success"] = "ok"
  2310. //context.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  2311. //context.Header("Content-Type","application/octet-stream")
  2312. //context.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  2313. //context.Header("Content-Transfer-Encoding", "binary")
  2314. //_ = f.Write(context.Writer)
  2315. }
  2316. return filename, err
  2317. //appG.Response(http.StatusOK, e.SUCCESS, data)
  2318. }
  2319. func SetSheetRow(f *excelize.File, sheet, axis string, slice interface{}) error {
  2320. SetSheetRow(f, sheet, axis, slice)
  2321. return nil
  2322. }