Initial commit
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
package innerserverser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
"os"
|
||||
"stat/api/proto"
|
||||
"stat/common/log"
|
||||
"stat/common/utils"
|
||||
"stat/tool/pubtest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExel1(t *testing.T) {
|
||||
var f *excelize.File
|
||||
newxlslfile := false
|
||||
day0 := utils.BeginOfYesterday()
|
||||
dir := day0.Format("2006-01")
|
||||
filePath := "/usr/local" + "/bakmonth/" + dir + "/"
|
||||
//filename := utils.BeginOfYesterday().Format("2006-01-02")
|
||||
if !DocExsit(filePath) {
|
||||
err := os.MkdirAll(filePath, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Error("InnerServerDailyStat:export save file to disk failed",
|
||||
log.Any("fileName", filePath),
|
||||
log.E(err))
|
||||
return
|
||||
}
|
||||
f = excelize.NewFile()
|
||||
newxlslfile = true
|
||||
} else {
|
||||
if !DocExsit(filePath + dir + ".xlsx") {
|
||||
f = excelize.NewFile()
|
||||
newxlslfile = true
|
||||
} else {
|
||||
f, _ = excelize.OpenFile(filePath + dir + ".xlsx")
|
||||
}
|
||||
}
|
||||
|
||||
// 设置表头样式
|
||||
headStyleID, _ := f.NewStyle(`{
|
||||
"font":{
|
||||
"color":"#333333",
|
||||
"bold":true,
|
||||
"size":16,
|
||||
"family":"arial"
|
||||
},
|
||||
"alignment":{
|
||||
"vertical":"center",
|
||||
"horizontal":"center",
|
||||
"wrap_text":true
|
||||
}
|
||||
}`)
|
||||
|
||||
headStyleID0, _ := f.NewStyle(`{
|
||||
"font":{
|
||||
"color":"#333333",
|
||||
"bold":false,
|
||||
"size":10,
|
||||
"family":"arial"
|
||||
},
|
||||
"alignment":{
|
||||
"vertical":"center",
|
||||
"horizontal":"center",
|
||||
"wrap_text":true
|
||||
}
|
||||
}`)
|
||||
pubtest.TestInit("/Users/mac/Desktop/madou/stat_center")
|
||||
ctx := context.Background()
|
||||
list := make([]*proto.InnerDailyRecharge, 0)
|
||||
yesterday := utils.BeginOfYesterday0()
|
||||
bililist, appinfo, err := GetDbList(ctx, &day0, &yesterday)
|
||||
if err != nil {
|
||||
log.Error("InnerServerDailyStat:GetDbList", log.E(err))
|
||||
}
|
||||
|
||||
for _, info := range bililist {
|
||||
name := ""
|
||||
if data, ok := appinfo[info.AppId]; ok {
|
||||
name = data.Name
|
||||
}
|
||||
temp := &proto.InnerDailyRecharge{
|
||||
AppId: info.AppId,
|
||||
Name: name,
|
||||
Type: "",
|
||||
DateTime: "",
|
||||
DailyVistCount: info.TotalVisitCount,
|
||||
DailyRegister: info.NewTotalCount,
|
||||
DailyAppAmount: info.TotalAmount,
|
||||
DailyGameAmount: info.GameRechageAmount,
|
||||
RechargeOrder: info.SuccessRechargeOrder,
|
||||
}
|
||||
list = append(list, temp)
|
||||
}
|
||||
|
||||
temp := &proto.InnerDailyRecharge{}
|
||||
for _, info := range list {
|
||||
temp.AppId = 0
|
||||
temp.Name = "天宇总充值"
|
||||
temp.DailyVistCount += info.DailyVistCount
|
||||
temp.DailyRegister += info.DailyRegister
|
||||
temp.DailyAppAmount += info.DailyAppAmount
|
||||
temp.DailyGameAmount += info.DailyGameAmount
|
||||
temp.RechargeOrder += info.RechargeOrder
|
||||
}
|
||||
list = append(list, temp)
|
||||
for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
|
||||
list[i], list[j] = list[j], list[i]
|
||||
}
|
||||
|
||||
if newxlslfile {
|
||||
NewXlslFile0(f, list, headStyleID, headStyleID0)
|
||||
} else {
|
||||
OpenOldXlsl(f, list)
|
||||
}
|
||||
|
||||
row := 1
|
||||
day := yesterday.Format("2006-01-02")
|
||||
cols := f.GetRows("Sheet1")
|
||||
for rowindex, col := range cols {
|
||||
for colindex, rowCell := range col {
|
||||
if rowCell == "" {
|
||||
continue
|
||||
}
|
||||
if colindex == 0 {
|
||||
if rowCell == day {
|
||||
row = rowindex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, info := range list {
|
||||
cellday, serr := utils.CoordinatesToCellName(info.BeginCol, row)
|
||||
if serr != nil {
|
||||
log.Error("OpenOldXlsl CoordinatesToCellName ", log.Any("err", serr))
|
||||
continue
|
||||
}
|
||||
cellregister, serr := utils.CoordinatesToCellName(info.BeginCol+1, row)
|
||||
if serr != nil {
|
||||
log.Error("OpenOldXlsl CoordinatesToCellName ", log.Any("err", serr))
|
||||
continue
|
||||
}
|
||||
cellrecharge, serr := utils.CoordinatesToCellName(info.BeginCol+2, row)
|
||||
if serr != nil {
|
||||
log.Error("OpenOldXlsl CoordinatesToCellName ", log.Any("err", serr))
|
||||
continue
|
||||
}
|
||||
cellgame, serr := utils.CoordinatesToCellName(info.BeginCol+3, row)
|
||||
if serr != nil {
|
||||
log.Error("OpenOldXlsl CoordinatesToCellName ", log.Any("err", serr))
|
||||
continue
|
||||
}
|
||||
cellorder, serr := utils.CoordinatesToCellName(info.BeginCol+4, row)
|
||||
if serr != nil {
|
||||
log.Error("OpenOldXlsl CoordinatesToCellName ", log.Any("err", serr))
|
||||
continue
|
||||
}
|
||||
|
||||
f.SetCellStyle("Sheet1", cellday, cellday, headStyleID0)
|
||||
totalamount := fmt.Sprintf("%.2f", float64(info.DailyVistCount)*0.01)
|
||||
f.SetCellValue("Sheet1", cellday, totalamount)
|
||||
f.SetCellStyle("Sheet1", cellregister, cellday, headStyleID0)
|
||||
totalamount = fmt.Sprintf("%.2f", float64(info.DailyRegister)*0.01)
|
||||
f.SetCellValue("Sheet1", cellregister, totalamount)
|
||||
f.SetCellStyle("Sheet1", cellrecharge, cellday, headStyleID0)
|
||||
totalamount = fmt.Sprintf("%.2f", float64(info.DailyAppAmount)*0.0001)
|
||||
f.SetCellValue("Sheet1", cellrecharge, totalamount)
|
||||
f.SetCellStyle("Sheet1", cellgame, cellday, headStyleID0)
|
||||
if info.AppId == 0 || info.AppId == 888 {
|
||||
totalamount = fmt.Sprintf("%.2f", float64(info.DailyGameAmount)*0.0001)
|
||||
}
|
||||
f.SetCellValue("Sheet1", cellgame, totalamount)
|
||||
f.SetCellStyle("Sheet1", cellorder, cellday, headStyleID0)
|
||||
totalamount = fmt.Sprintf("%.2f", float64(info.RechargeOrder)*0.01)
|
||||
f.SetCellValue("Sheet1", cellorder, totalamount)
|
||||
}
|
||||
if newxlslfile {
|
||||
f.SaveAs(filePath + dir + ".xlsx")
|
||||
} else {
|
||||
f.Save()
|
||||
}
|
||||
}
|
||||
|
||||
func TestExel0(t *testing.T) {
|
||||
rowday := fmt.Sprintf("%s-%02d", "", 9)
|
||||
fmt.Println(rowday)
|
||||
}
|
||||
Reference in New Issue
Block a user