Browse Source

添加导出报表功能

pull/2/head
zhangxin 4 years ago
parent
commit
e5bd88c503
1 changed files with 197 additions and 8 deletions
  1. +197
    -8
      web/controllers/chargetab_controller.go

+ 197
- 8
web/controllers/chargetab_controller.go View File

@ -401,13 +401,26 @@ func GetChargeStatisticData(ctx iris.Context) {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
var chargeTab models.Chargeallocationtab
//chargeTab.Cid = user.Pid
year := time.Now().Year()
start := fmt.Sprintf("%d0101", year)
end := fmt.Sprintf("%d1231", year)
var chargeTab models.Chargetab
currentYear := time.Now().Year()
var year int
yearStr := ctx.URLParam("year")
if yearStr == "" {
year = currentYear
} else {
year = utils.ValueToInt(yearStr, 0)
}
selectType := ctx.URLParam("type")
result, err := chargeTab.GetChargeStatisticData(cid, year, start, end, selectType)
date := ctx.URLParam("date")
if date != "" {
tDate, err1 := utils.TimeParseyyyyMMdd(date)
if err1 != nil {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
date = utils.TimeFormat(tDate, "yyyy-MM-dd")
}
result, err := chargeTab.GetChargeStatisticData(cid, year, selectType, date, currentYear)
if err != nil {
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
return
@ -522,11 +535,31 @@ func GetChargeArrearageData(ctx iris.Context) {
}
buildingId := ctx.URLParam("buildingid")
propertyId := ctx.URLParam("propertyid")
year := time.Now().Year()
start := ctx.URLParam("start")
end := ctx.URLParam("end")
if start != "" || end != "" {
startT, err1 := utils.TimeParseyyyyMMdd(start)
endT, err2 := utils.TimeParseyyyyMMdd(end)
if err1 != nil || err2 != nil {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
start = utils.TimeFormat(startT, "yyyy-MM-dd")
end = utils.TimeFormat(endT, "yyyy-MM-dd")
}
currentYear := time.Now().Year()
var year int
yearStr := ctx.URLParam("year")
if yearStr != "" {
year = utils.ValueToInt(yearStr, 0)
} else {
year = currentYear
}
selectType := ctx.URLParam("type")
arrearageDate := fmt.Sprintf("%d-12-31", year-1)
var charge models.Chargetab
result, err := charge.GetChargeArrearageData(cid, pageIndex, pageSize, year, arrearageDate, selectType, chargeType, buildingId, propertyId)
result, err := charge.GetChargeArrearageData(cid, pageIndex, pageSize, year, arrearageDate, selectType, chargeType, buildingId, propertyId, start, end, currentYear)
if err != nil {
fmt.Println("outer error:", err)
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
@ -534,3 +567,159 @@ func GetChargeArrearageData(ctx iris.Context) {
}
supports.Ok(ctx, supports.OptionSuccess, result)
}
func ExportChargeArrearageExcel(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
logs := new(models.LeitServerLog)
logs.File = "/controllers/Chargetab_controller.go"
logs.Level = "info"
logs.Function = "GetChargeArrearageData"
logs.Message = "按日期查看缴费陈欠数据"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
var pageSize = 10
var pageIndex = 1
if size := ctx.URLParam("size"); size != "" {
pageSize = utils.ValueToInt(size, 0)
}
if index := ctx.URLParam("index"); index != "" {
pageIndex = utils.ValueToInt(index, 0)
}
var cid int
// 如果公司机关部门可以搜索cid
if user.Pid == 110 {
cidStr := ctx.URLParam("cid")
cid = utils.ValueToInt(cidStr, 0)
} else {
cid = user.Pid
}
if cid == 0 {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
chargeType, err := ctx.URLParamInt("chargetype")
if err != nil {
chargeType = 0
}
buildingId := ctx.URLParam("buildingid")
propertyId := ctx.URLParam("propertyid")
start := ctx.URLParam("start")
end := ctx.URLParam("end")
if start != "" || end != "" {
startT, err1 := utils.TimeParseyyyyMMdd(start)
endT, err2 := utils.TimeParseyyyyMMdd(end)
if err1 != nil || err2 != nil {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
start = utils.TimeFormat(startT, "yyyy-MM-dd")
end = utils.TimeFormat(endT, "yyyy-MM-dd")
}
currentYear := time.Now().Year()
var year int
yearStr := ctx.URLParam("year")
if yearStr != "" {
year = utils.ValueToInt(yearStr, 0)
} else {
year = currentYear
}
selectType := ctx.URLParam("type")
arrearageDate := fmt.Sprintf("%d-12-31", year-1)
var charge models.Chargetab
fmt.Println("before get result")
result, err := charge.GetChargeArrearageExcelData(cid, pageIndex, pageSize, year, arrearageDate, selectType, chargeType, buildingId, propertyId, start, end, currentYear)
if err != nil {
fmt.Println("outer error:", err)
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
return
}
_, filename, err := charge.ExportChargeArrearageExcel(result)
if err != nil {
fmt.Printf("错误err : %v", err)
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil)
return
}
strUrl := "public/uploadxlsx/" + filename
supports.Ok(ctx, supports.OptionSuccess, strUrl)
}
// 按日期和缴费类型获取缴费数据
func ExportChargeTypeExcel(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
logs := new(models.LeitServerLog)
logs.File = "/controllers/Chargetab_controller.go"
logs.Level = "info"
logs.Function = "ExportChargeTypeExcel"
logs.Message = "导出按日期和收款类型查看缴费数据"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
var pageSize = 10
var pageIndex = 1
if size := ctx.URLParam("size"); size != "" {
pageSize = utils.ValueToInt(size, 0)
}
if index := ctx.URLParam("index"); index != "" {
pageIndex = utils.ValueToInt(index, 0)
}
var cid int
// 如果公司机关部门可以搜索cid
if user.Pid == 110 {
cidStr := ctx.URLParam("cid")
cid = utils.ValueToInt(cidStr, 0)
} else {
cid = user.Pid
}
if cid == 0 {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
date := ctx.URLParam("date")
tDate, err1 := utils.TimeParseyyyyMMdd(date)
if err1 != nil {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
// 如为传入或传入的chargeType 不合规则使用-1 进行所有chargeType的分类统计
date = utils.TimeFormat(tDate, "yyyy-MM-dd")
chargeWay := ctx.URLParam("charge_way")
if chargeWay == "" {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
var charge models.Chargetab
result, err := charge.GetChargeTypeData(cid, chargeWay, date, pageIndex, pageSize)
if err != nil {
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
return
}
_, filename, err := charge.ExportChargeWayExcel(result.Items)
if err != nil {
fmt.Printf("错误err : %v", err)
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil)
return
}
strUrl := "public/uploadxlsx/" + filename
supports.Ok(ctx, supports.OptionSuccess, strUrl)
}

Loading…
Cancel
Save