Browse Source

修改年缴费统计接口 导出报表不再使用分页 缴费台账接口返回值添加user字段 优化缴费台账统计金额的sql

pull/2/head
zhangxin 4 years ago
parent
commit
15ade1367f
2 changed files with 155 additions and 54 deletions
  1. +33
    -22
      web/controllers/chargetab_controller.go
  2. +122
    -32
      web/models/chargetab.go

+ 33
- 22
web/controllers/chargetab_controller.go View File

@ -429,6 +429,9 @@ func GetChargeStatisticData(ctx iris.Context) {
year = 0 year = 0
} }
selectType := ctx.URLParam("type") selectType := ctx.URLParam("type")
if selectType != "arrearage" && selectType != "current" {
selectType = "total"
}
var charge models.Chargetab var charge models.Chargetab
result, err := charge.GetChargeStatisticData(cid, year, selectType, chargeType, buildingId, propertyId, start, end, currentYear) result, err := charge.GetChargeStatisticData(cid, year, selectType, chargeType, buildingId, propertyId, start, end, currentYear)
if err != nil { if err != nil {
@ -512,6 +515,7 @@ func GetChargeArrearageData(ctx iris.Context) {
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
return return
} }
result.User = user.Role
supports.Ok(ctx, supports.OptionSuccess, result) supports.Ok(ctx, supports.OptionSuccess, result)
} }
@ -594,16 +598,6 @@ func ExportChargeArrearageExcel(ctx iris.Context) {
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord() 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 var cid int
// 如果公司机关部门可以搜索cid // 如果公司机关部门可以搜索cid
if user.Pid == 110 { if user.Pid == 110 {
@ -645,7 +639,7 @@ func ExportChargeArrearageExcel(ctx iris.Context) {
} }
arrearageDate := fmt.Sprintf("%d-12-31", currentYear-1) arrearageDate := fmt.Sprintf("%d-12-31", currentYear-1)
var charge models.Chargetab var charge models.Chargetab
result, err := charge.GetChargeArrearageExcelData(cid, pageIndex, pageSize, year, arrearageDate, chargeType, buildingId, propertyId, start, end, currentYear)
result, err := charge.GetChargeArrearageExcelData(cid, year, arrearageDate, chargeType, buildingId, propertyId, start, end, currentYear)
if err != nil { if err != nil {
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
return return
@ -678,16 +672,6 @@ func ExportChargeWayDataListExcel(ctx iris.Context) {
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord() 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 var cid int
// 如果公司机关部门可以搜索cid // 如果公司机关部门可以搜索cid
if user.Pid == 110 { if user.Pid == 110 {
@ -715,7 +699,7 @@ func ExportChargeWayDataListExcel(ctx iris.Context) {
chargeWay := ctx.URLParam("chargeWay") chargeWay := ctx.URLParam("chargeWay")
chargeType := ctx.URLParam("chargeType") chargeType := ctx.URLParam("chargeType")
var charge models.Chargetab var charge models.Chargetab
result, err := charge.GetExcelChargeWayDataList(cid, chargeWay, chargeType, start, end, pageIndex, pageSize)
result, err := charge.GetExcelChargeWayDataList(cid, chargeWay, chargeType, start, end)
if err != nil { if err != nil {
fmt.Println("error1:", err) fmt.Println("error1:", err)
supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil)
@ -731,3 +715,30 @@ func ExportChargeWayDataListExcel(ctx iris.Context) {
supports.Ok(ctx, supports.OptionSuccess, strUrl) supports.Ok(ctx, supports.OptionSuccess, strUrl)
} }
func GetChargetabStatisticByYear(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
var me models.Chargetab
me.Cid = user.Pid
me.Chargetype, _ = ctx.URLParamInt("chargetype")
year, err := ctx.URLParamInt("year")
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
selectType := ctx.URLParam("type")
result, count, err := me.ChargeTotalStatisticData(year, selectType)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil)
return
}
res := make(map[string]interface{})
res["data"] = result
res["count"] = count
supports.Ok(ctx, supports.OptionSuccess, res)
}

+ 122
- 32
web/models/chargetab.go View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/go-xorm/xorm"
uuid "github.com/iris-contrib/go.uuid" uuid "github.com/iris-contrib/go.uuid"
"github.com/tealeg/xlsx" "github.com/tealeg/xlsx"
"lapp_-wy/db" "lapp_-wy/db"
@ -74,6 +75,7 @@ type ChargeArrearageResponse struct {
Total int64 `json:"total"` Total int64 `json:"total"`
TotalPage int `json:"total_page"` TotalPage int `json:"total_page"`
CurrentPage int `json:"current_page"` CurrentPage int `json:"current_page"`
User string `json:"user"`
} }
type ExcelChargeWayData struct { type ExcelChargeWayData struct {
@ -264,6 +266,8 @@ type SumStruct struct {
PaidInArea float64 `json:"paid_in_area"` PaidInArea float64 `json:"paid_in_area"`
ReceivableMoney float64 `json:"receivable_money"` ReceivableMoney float64 `json:"receivable_money"`
PaidInMoney float64 `json:"paid_in_money"` PaidInMoney float64 `json:"paid_in_money"`
CurrentPercent float64 `json:"current_percent"`
ArrearagePercent float64 `json:"arrearage_percent"`
} }
type BuildingInfo struct { type BuildingInfo struct {
@ -1637,6 +1641,7 @@ func (t *Chargetab) GetChargeWayDataList(cid int, chargeWay, chargeType, start,
query := engine.Table(t.TableName()).Where(`cid = ?`, cid) query := engine.Table(t.TableName()).Where(`cid = ?`, cid)
table := engine.Table(t.TableName()).Where(`cid = ?`, cid) table := engine.Table(t.TableName()).Where(`cid = ?`, cid)
sumQuery := engine.Table(t.TableName()).Where(`cid = ?`, cid) sumQuery := engine.Table(t.TableName()).Where(`cid = ?`, cid)
fmt.Println("chargeWay:", chargeWay)
if chargeWay != "" { if chargeWay != "" {
if chargeWay == "扫码" { if chargeWay == "扫码" {
query = query.And("chargeway = \"扫码\" or chargeway = \"微信\" or chargeway = \"支付宝\"") query = query.And("chargeway = \"扫码\" or chargeway = \"微信\" or chargeway = \"支付宝\"")
@ -1757,34 +1762,51 @@ func (t *Chargetab) GetChargeArrearageData(cid int, pageIndex, pageSize int, yea
func (t *Chargetab) GetChargeStatisticData(cid, year int, selectType string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result *response.ChargeStatisticResponse, err error) { func (t *Chargetab) GetChargeStatisticData(cid, year int, selectType string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result *response.ChargeStatisticResponse, err error) {
result = new(response.ChargeStatisticResponse) result = new(response.ChargeStatisticResponse)
engine := db.MasterEngine() engine := db.MasterEngine()
query := engine.Table(t.TableName()).Where("chargetab.cid = ?", cid)
// 若搜索楼栋id则与物业表连表
var query *xorm.Session
var chargeAllocation Chargeallocationtab var chargeAllocation Chargeallocationtab
if !utils.ValueIsEmpty(buildingId) {
query = query.Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").And("propertytab.buildingid = ?", buildingId)
}
if chargeType != 0 {
query = query.And("chargetab.chargetype = ?", chargeType)
}
if !utils.ValueIsEmpty(propertyId) {
query = query.And("chargetab.propertyid = ?", propertyId)
}
if start != "" {
query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end)
if chargeType == 0 && buildingId == "" && start == "" && end == "" && year == 0{
query = engine.Table(chargeAllocation.TableName()).Where("cid = ?", cid)
} else { } else {
if year != 0 {
start := fmt.Sprintf("%d-01-01", year)
end := fmt.Sprintf("%d-01-01", year+1)
query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end)
chargeLi := make([]Chargetab, 0)
query = engine.Table(t.TableName()).Where("chargetab.cid = ?", cid)
// 若搜索楼栋id则与物业表连表
if !utils.ValueIsEmpty(buildingId) {
query = query.Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").And("propertytab.buildingid = ?", buildingId)
}
if chargeType != 0 {
query = query.And("chargetab.chargetype = ?", chargeType)
}
if !utils.ValueIsEmpty(propertyId) {
query = query.And("chargetab.propertyid = ?", propertyId)
}
if start != "" {
query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end)
} else {
if year != 0 {
start := fmt.Sprintf("%d-01-01", year)
end := fmt.Sprintf("%d-01-01", year+1)
query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end)
}
}
err = query.Find(&chargeLi)
if err != nil {
return nil, err
}
chargeNrLi := make([]int, 0)
for _, charge := range chargeLi {
chargeNrLi = append(chargeNrLi, charge.Chargenr)
} }
query = engine.Table(chargeAllocation.TableName()).Where("cid = ?", cid).In("chargenr", chargeNrLi)
} }
query = query.Join("LEFT", "chargeallocationtab", "chargetab.chargenr = chargeallocationtab.chargenr")
// arrearage 陈欠 current 当年 // arrearage 陈欠 current 当年
if selectType == "arrearage" { if selectType == "arrearage" {
query = query.Where("chargeallocationtab.allocateyear < ?", currentYear) query = query.Where("chargeallocationtab.allocateyear < ?", currentYear)
} else if selectType == "current" { } else if selectType == "current" {
query = query.Where("chargeallocationtab.allocateyear >= ?", currentYear) query = query.Where("chargeallocationtab.allocateyear >= ?", currentYear)
} }
count, err := query.Sum(chargeAllocation, "chargeallocationtab.allocateexpense") count, err := query.Sum(chargeAllocation, "chargeallocationtab.allocateexpense")
result.Cid = cid result.Cid = cid
result.Count = utils.Round(count) result.Count = utils.Round(count)
@ -1792,7 +1814,7 @@ func (t *Chargetab) GetChargeStatisticData(cid, year int, selectType string, cha
return result, nil return result, nil
} }
func (t *Chargetab) GetChargeArrearageExcelData(cid int, pageIndex, pageSize int, year int, arrearageDate string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result []*ChargeArrearageExcelData, err error) {
func (t *Chargetab) GetChargeArrearageExcelData(cid int, year int, arrearageDate string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result []*ChargeArrearageExcelData, err error) {
engine := db.MasterEngine() engine := db.MasterEngine()
chargeLi := make([]*ChargeContactData, 0) chargeLi := make([]*ChargeContactData, 0)
@ -1816,8 +1838,7 @@ func (t *Chargetab) GetChargeArrearageExcelData(cid int, pageIndex, pageSize int
query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end) query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end)
} }
} }
offset := pageSize * (pageIndex - 1)
err = query.Desc("chargetab.createtime").Limit(pageSize, offset).Find(&chargeLi)
err = query.Desc("chargetab.createtime").Find(&chargeLi)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1846,20 +1867,13 @@ func (t *Chargetab) GetChargeArrearageExcelData(cid int, pageIndex, pageSize int
} }
// 获取缴费方式数据列表 // 获取缴费方式数据列表
func (t *Chargetab) GetExcelChargeWayDataList(cid int, chargeWay, chargeType, start, end string, pageIndex, pageSize int) (result []*ExcelChargeWayData, err error) {
func (t *Chargetab) GetExcelChargeWayDataList(cid int, chargeWay, chargeType, start, end string) (result []*ExcelChargeWayData, err error) {
result = make([]*ExcelChargeWayData, 0) result = make([]*ExcelChargeWayData, 0)
tempLi := make([]*ChargeContactData, 0) tempLi := make([]*ChargeContactData, 0)
engine := db.MasterEngine() engine := db.MasterEngine()
//var court Courttab
//exist, err := engine.Table(court.TableName()).ID(cid).Get(&court)
//if err != nil {
// return result, err
//}
//if !exist {
// return result, errors.New("data not exist")
//}
// 扫码包含 微信 支付宝 和 扫码 // 扫码包含 微信 支付宝 和 扫码
query := engine.Table(t.TableName()).Where(`chargetab.cid = ?`, cid).Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid") query := engine.Table(t.TableName()).Where(`chargetab.cid = ?`, cid).Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid")
fmt.Println("chargeWay:", chargeWay)
if chargeWay != "" { if chargeWay != "" {
if chargeWay == "扫码" { if chargeWay == "扫码" {
query = query.And("chargetab.chargeway = \"扫码\" or chargetab.chargeway = \"微信\" or chargetab.chargeway = \"支付宝\"") query = query.And("chargetab.chargeway = \"扫码\" or chargetab.chargeway = \"微信\" or chargetab.chargeway = \"支付宝\"")
@ -1873,8 +1887,7 @@ func (t *Chargetab) GetExcelChargeWayDataList(cid int, chargeWay, chargeType, st
if start != "" { if start != "" {
query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end) query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end)
} }
offset := (pageIndex - 1) * pageSize
err = query.Desc("chargetab.createtime").Limit(pageSize, offset).Find(&tempLi)
err = query.Desc("chargetab.createtime").Find(&tempLi)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2083,9 +2096,86 @@ func (t *Chargetab) ExportChargeWayExcel(datalist []*ExcelChargeWayData) (excelf
exceldir, _ := utils.GetCurrentPath("web/public/uploadxlsx") // 目录+文件名 exceldir, _ := utils.GetCurrentPath("web/public/uploadxlsx") // 目录+文件名
excelfile = exceldir + "/" + filename excelfile = exceldir + "/" + filename
fmt.Println("excelfile:", excelfile)
err = file.Save(excelfile) err = file.Save(excelfile)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
return excelfile, filename, nil return excelfile, filename, nil
} }
//按年统计
func (t *Chargetab) ChargeTotalStatisticData(year int, selectType string) ([]SumStruct, int, error) {
e := db.MasterEngine()
datalist := make([]SumStruct, 0)
currentYear := time.Now().Year()
var startDate string
var endDate string
if selectType == "current" {
if year < currentYear {
year = currentYear
}
startDate = fmt.Sprintf("%d-01-01", year)
endDate = fmt.Sprintf("%d-01-01", 2099)
} else if selectType == "arrearage" {
startDate = fmt.Sprintf("%d-01-01", 2000)
if year >= currentYear {
year = currentYear - 1
}
endDate = fmt.Sprintf("%d-01-01", year+1)
} else {
startDate = fmt.Sprintf("%d-01-01", year)
endDate = fmt.Sprintf("%d-01-01", year+1)
}
//计算实收金额
ss := new(SumStruct)
_, err := e.Table("chargeallocationtab").Select("sum(allocateexpense) as paid_in_money").Where("cid = ? and allocateyear =? ", t.Cid, year).Get(ss)
//计算实收缴费面积
one := SumStruct{}
one.Cid = t.Cid
one.Allocateyear = year
PaidInMoney := fmt.Sprintf("%0.0f", ss.PaidInMoney)
one.PaidInMoney = utils.ValueToFloat(PaidInMoney, 0.0)
info := new(SumStruct)
_, err = e.Table("chargetab").Select("sum(propertytab.constructionarea) as paid_in_area").Join("INNER", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").Where("chargetab.cid = ? and chargetab.chargeenddate >= ? and chargetab.chargeenddate < ?", t.Cid, startDate, endDate).Get(info)
if err != nil {
glog.InfoExtln("年缴费测试", "err1 := ", err)
return nil, 0, err
}
area := fmt.Sprintf("%0.2f", info.PaidInArea)
one.PaidInArea = utils.ValueToFloat(area, 0.0)
//计算应收金额和面积
buildInfo := new(BuildingInfo)
_, err = e.Table("propertytab").Select("propertytypetab.unitprice as unitprice,(SELECT SUM(constructionarea) FROM propertytab WHERE isfree != '3') as constructionarea").Join("INNER", "buildingtab", "propertytab.buildingid=buildingtab.buildingid and propertytab.cid=buildingtab.cid").Join("INNER", "propertytypetab", "propertytypetab.propertytypeid=buildingtab.propertytypeid and propertytypetab.cid=buildingtab.cid").Where("propertytab.cid = ?", t.Cid).Get(buildInfo)
if err != nil {
glog.InfoExtln("年缴费测试", "err2 := ", err)
return nil, 0, err
}
ReceivableArea := fmt.Sprintf("%0.2f", buildInfo.Constructionarea)
one.ReceivableArea = utils.ValueToFloat(ReceivableArea, 0.0)
money := fmt.Sprintf("%0.0f", buildInfo.Constructionarea*buildInfo.Unitprice*12)
one.ReceivableMoney = utils.ValueToFloat(money, 0.0)
if selectType == "current" {
one.CurrentPercent = 1
one.ArrearagePercent = 0
} else if selectType == "arrearage" {
one.CurrentPercent = 0
one.ArrearagePercent = 1
} else {
if year >= currentYear {
one.CurrentPercent = 1
one.ArrearagePercent = 0
} else {
one.CurrentPercent = 0
one.ArrearagePercent = 1
}
}
glog.InfoExtln("年缴费测试", "one := ", one)
datalist = append(datalist, one)
sumMoney := 0.0
for _, v := range datalist {
sumMoney += v.PaidInMoney
}
total := utils.ValueToInt(sumMoney, 0)
return datalist, total, nil
}

Loading…
Cancel
Save