enhance(fee):基本完成物业附加费部分的运算。

This commit is contained in:
徐涛
2022-09-21 22:46:33 +08:00
parent 38ec847f55
commit f8f8a0ced1
4 changed files with 221 additions and 179 deletions

View File

@@ -6,9 +6,11 @@ import (
"electricity_bill_calc/security"
"electricity_bill_calc/service"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"github.com/samber/lo"
"github.com/shopspring/decimal"
)
@@ -18,6 +20,7 @@ func InitializeMaintenanceFeeController(router *gin.Engine) {
router.PUT("/maintenance/fee/:mid", security.EnterpriseAuthorize, modifyMaintenanceFeeRecord)
router.PUT("/maintenance/fee/:mid/enabled", security.EnterpriseAuthorize, changeMaintenanceFeeState)
router.DELETE("/maintenance/fee/:mid", security.EnterpriseAuthorize, deleteMaintenanceFee)
router.GET("/additional/charges", security.MustAuthenticated, statAdditionalCharges)
}
func ensureMaintenanceFeeBelongs(c *gin.Context, result *response.Result, requestMaintenanceFeeId string) bool {
@@ -46,34 +49,51 @@ func listMaintenanceFees(c *gin.Context) {
return
}
requestPark := c.DefaultQuery("park", "")
requestPeriod := c.DefaultQuery("period", "")
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
if err != nil {
result.Error(http.StatusInternalServerError, "不能解析给定的参数[page]。")
return
}
if len(requestPark) > 0 {
if !ensureParkBelongs(c, result, requestPark) {
return
}
fees, err := service.MaintenanceFeeService.ListMaintenanceFees([]string{requestPark})
fees, total, err := service.MaintenanceFeeService.ListMaintenanceFees([]string{requestPark}, requestPeriod, requestPage)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Json(http.StatusOK, "已获取指定园区下的维护费记录", gin.H{"fees": fees})
result.Json(
http.StatusOK,
"已获取指定园区下的维护费记录",
response.NewPagedResponse(requestPage, total).ToMap(),
gin.H{"fees": fees},
)
} else {
parkIds, err := service.ParkService.AllParkIds(userSession.Uid)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
fees, err := service.MaintenanceFeeService.ListMaintenanceFees(parkIds)
fees, total, err := service.MaintenanceFeeService.ListMaintenanceFees(parkIds, requestPeriod, requestPage)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Json(http.StatusOK, "已获取指定用户下的所有维护费记录。", gin.H{"fees": fees})
result.Json(
http.StatusOK,
"已获取指定用户下的所有维护费记录。",
response.NewPagedResponse(requestPage, total).ToMap(),
gin.H{"fees": fees},
)
}
}
type _FeeCreationFormData struct {
ParkId string `json:"parkId" form:"parkId"`
Name string `json:"name" form:"name"`
Period string `json:"period" form:"period"`
Fee decimal.Decimal `json:"fee" form:"fee"`
Memo *string `json:"memo" form:"memo"`
}
@@ -152,3 +172,38 @@ func deleteMaintenanceFee(c *gin.Context) {
}
result.Deleted("指定维护费条目已删除。")
}
func statAdditionalCharges(c *gin.Context) {
result := response.NewResult(c)
session, err := _retreiveSession(c)
if err != nil {
result.Unauthorized(err.Error())
return
}
requestUser := lo.
If(session.Type == model.USER_TYPE_ENT, session.Uid).
Else(c.DefaultQuery("user", ""))
requestPark := c.DefaultQuery("park", "")
if len(requestPark) > 0 && session.Type == model.USER_TYPE_ENT {
if !ensureParkBelongs(c, result, requestPark) {
return
}
}
period := c.DefaultQuery("period", "")
keyword := c.DefaultQuery("keyword", "")
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
if err != nil {
result.Error(http.StatusInternalServerError, "不能解析给定的参数[page]。")
return
}
fees, total, err := service.MaintenanceFeeService.QueryAdditiionalCharges(requestUser, requestPark, period, keyword, requestPage)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Success(
"已经成功获取到物业附加费的统计记录。",
response.NewPagedResponse(requestPage, total).ToMap(),
gin.H{"charges": fees},
)
}

View File

@@ -11,7 +11,6 @@ import (
"strconv"
"time"
"github.com/fufuok/utils"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"github.com/samber/lo"
@@ -26,12 +25,6 @@ func InitializeReportController(router *gin.Engine) {
router.PUT("/report/:rid/summary", security.EnterpriseAuthorize, fillReportSummary)
router.GET("/report/:rid/summary/calculate", security.EnterpriseAuthorize, testCalculateReportSummary)
router.POST("/report/:rid/summary/calculate", security.EnterpriseAuthorize, progressReportSummary)
router.GET("/report/:rid/maintenance", security.EnterpriseAuthorize, fetchWillDilutedFees)
router.POST("/report/:rid/maintenance", security.EnterpriseAuthorize, createTemporaryWillDilutedFee)
router.POST("/report/:rid/maintenance/import", security.EnterpriseAuthorize, importPredefinedMaintenanceFees)
router.PUT("/report/:rid/maintenance/:mid", security.EnterpriseAuthorize, modifyWillDilutedFee)
router.DELETE("/report/:rid/maintenance/:mid", security.EnterpriseAuthorize, deleteTemporaryWillDilutedFee)
router.PUT("/report/:rid/step/diluted/fees", security.EnterpriseAuthorize, progressReportWillDilutedFee)
router.PUT("/report/:rid/step/meter/register", security.EnterpriseAuthorize, progressEndUserRegister)
router.POST("/report/:rid/publish", security.EnterpriseAuthorize, publishReport)
router.GET("/reports", security.MustAuthenticated, searchReports)
@@ -208,161 +201,6 @@ func progressReportSummary(c *gin.Context) {
result.Success("已经完成园区概况的计算,并可以进行到下一步骤。")
}
func fetchWillDilutedFees(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
fees, err := service.ReportService.FetchWillDulutedMaintenanceFees(requestReportId)
if err != nil {
result.NotFound(err.Error())
return
}
result.Json(http.StatusOK, "待摊薄费用已经获取到。", gin.H{"fees": fees})
}
type DilutedFeeCreationFormData struct {
ParkId string `json:"parkId" form:"parkId"`
Name string `json:"name" form:"name"`
Fee decimal.Decimal `json:"fee" form:"fee"`
Memo *string `json:"memo" form:"memo"`
}
func createTemporaryWillDilutedFee(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
formData := new(DilutedFeeCreationFormData)
c.BindJSON(formData)
report, err := service.ReportService.RetreiveReportIndex(requestReportId)
if err != nil {
result.NotFound(err.Error())
return
}
if formData.ParkId != report.ParkId {
result.NotAccept("选择的园区与公示报表所属的园区不一致。")
return
}
newWillDilutedFee := new(model.WillDilutedFee)
copier.Copy(newWillDilutedFee, formData)
newWillDilutedFee.ReportId = report.Id
err = service.ReportService.CreateTemporaryWillDilutedMaintenanceFee(*newWillDilutedFee)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Created("公示报表中所要使用的临时待摊薄费用已添加。")
}
func importPredefinedMaintenanceFees(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
report, err := service.ReportService.RetreiveReportIndex(requestReportId)
if err != nil {
result.NotFound(err.Error())
return
}
maintenanceFees, err := service.MaintenanceFeeService.ListMaintenanceFees([]string{report.ParkId})
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
enabledMaintenanceFees := lo.Filter(
maintenanceFees,
func(elem model.MaintenanceFee, index int) bool {
return elem.Enabled
},
)
if len(enabledMaintenanceFees) == 0 {
result.NotFound("没有找到可供导入的配电维护费记录。")
return
}
dilutedFees := lo.Map(
enabledMaintenanceFees,
func(elem model.MaintenanceFee, index int) model.WillDilutedFee {
fee := &model.WillDilutedFee{
Id: utils.UUIDString(),
ReportId: report.Id,
SourceId: lo.ToPtr(elem.Id),
Name: elem.Name,
Fee: elem.Fee,
Memo: elem.Memo,
}
return *fee
},
)
err = service.ReportService.BatchSaveMaintenanceFee(report.Id, dilutedFees)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Created("预定义的配电维护费已经导入。")
}
type DilutedFeeModificationFormData struct {
Name *string `json:"name,omitempty" form:"name"`
Fee decimal.Decimal `json:"fee" form:"fee"`
Memo *string `json:"memo,omitempty" form:"memo"`
}
func modifyWillDilutedFee(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
requestFeeId := c.Param("mid")
formData := new(DilutedFeeModificationFormData)
c.BindJSON(formData)
updateValues := tools.ConvertStructToMap(formData)
err := service.ReportService.UpdateMaintenanceFee(requestFeeId, updateValues)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Updated("指定待摊薄费用信息已经更新。")
}
func deleteTemporaryWillDilutedFee(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
requestFeeId := c.Param("mid")
err := service.ReportService.DeleteWillDilutedFee(requestFeeId)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Deleted("指定待摊薄费用信息已经删除。")
}
func progressReportWillDilutedFee(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
report, err := service.ReportService.RetreiveReportIndex(requestReportId)
if err != nil {
result.NotFound(err.Error())
return
}
err = service.ReportService.ProgressReportWillDilutedFee(*report)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Success("待摊薄费用编辑步骤已经完成。")
}
func progressEndUserRegister(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")