Bladeren bron

项目月费用

xu 7 maanden geleden
bovenliggende
commit
ba36fd0ebb

+ 12 - 0
server/api/v1/admin/expenses.go

@@ -98,6 +98,18 @@ func (ea *ExpensesApi) QueryProjectMonthFee(c *gin.Context) {
 	response.OkWithData(fee, c)
 }
 
+func (ea *ExpensesApi) QueryMonthExpenses(c *gin.Context) {
+	monthTime := c.Query("monthTime")
+	yearTime := c.Query("yearTime")
+	fee, err := expensesService.QueryMonthExpenses(monthTime, yearTime)
+	if err != nil {
+		response.FailWithMessage("失败", c)
+		global.GVA_LOG.Error("QueryMonthExpenses ====== " + err.Error())
+		return
+	}
+	response.OkWithData(fee, c)
+}
+
 func (ea *ExpensesApi) CreateExpenses(c *gin.Context) {
 	var expenses dao.Expenses
 	err := c.ShouldBindJSON(&expenses)

+ 47 - 0
server/dao/monthExpenses.go

@@ -1,4 +1,51 @@
 package dao
 
+import (
+	"gorm.io/gorm"
+	"server/global"
+)
+
 type MonthExpenses struct {
+	global.GVA_MODEL
+	DepartmentId     int        `json:"departmentId" form:"departmentId" gorm:"comment:部门id"`
+	Department       Department `json:"department" form:"department" gorm:"foreignKey:DepartmentId;references:id;"`
+	TotalDeposit     float64    `json:"totalDeposit" form:"totalDeposit" gorm:"comment:总支入;type:double(10,2)"`
+	TotalExpenditure float64    `json:"totalExpenditure" form:"totalExpenditure" gorm:"comment:总支出;type:double(10,2)"`
+	SettlementMonth  string     `json:"settlementMonth" form:"settlementMonth" gorm:"comment:结算月份"`
+}
+
+func (MonthExpenses) TableName() string {
+	return "month_expenses"
+}
+
+func QueryMonthExpenses(monthTime, yearTime string) (monthExpenses []MonthExpenses, err error) {
+	db := global.GVA_DB.Model(&MonthExpenses{}).Debug().Select("department_id, SUM(total_deposit) AS total_deposit, SUM(total_expenditure) AS total_expenditure")
+	if monthTime != "" {
+		db = db.Where("DATE_FORMAT(CONCAT(settlement_month, '-01'), '%Y-%m') = ?", monthTime)
+	}
+	if yearTime != "" {
+		db = db.Where("DATE_FORMAT(CONCAT(settlement_month, '-01'), '%Y') = ?", yearTime)
+	}
+	err = db.Group("department_id").Preload("Department").Find(&monthExpenses).Error
+	return monthExpenses, err
+}
+
+func CreateMonthExpenses() error {
+	return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
+		tx = tx.Debug()
+		txErr := tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Unscoped().Delete(&MonthExpenses{}).Error
+		if txErr != nil {
+			return txErr
+		}
+		var fees []MonthExpenses
+		txErr = tx.Raw(`SELECT DATE_FORMAT(fee_time, '%Y-%m') AS settlement_month,department_id, SUM(deposit_amount) AS total_deposit, SUM(expenditure_amount) AS total_expenditure FROM  expenses GROUP BY DATE_FORMAT(fee_time, '%Y-%m'),department_id`).Scan(&fees).Error
+		if txErr != nil {
+			return txErr
+		}
+		txErr = tx.Model(&MonthExpenses{}).Create(&fees).Error
+		if txErr != nil {
+			return txErr
+		}
+		return txErr
+	})
 }

+ 0 - 5
server/dao/projectMonthFee.go

@@ -30,11 +30,6 @@ func QueryProjectMonthFee(monthTime, yearTime string) (monthFees []ProjectMonthF
 	return monthFees, err
 }
 
-func QueryProjectMonthFeeBySettlementMonth(settlementMonth string) (monthFees []ProjectMonthFee, err error) {
-	err = global.GVA_DB.Where("settlement_month = ?", settlementMonth).Preload("ProjectFeeGenre").Find(&monthFees).Error
-	return monthFees, err
-}
-
 func CreateProjectMonthFee() error {
 	return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
 		tx = tx.Debug()

+ 1 - 0
server/initialize/gorm.go

@@ -63,6 +63,7 @@ func RegisterTables() {
 		dao.FeeDetails{},
 		dao.Constructor{},
 		dao.Expenses{},
+		dao.MonthExpenses{},
 	)
 	if err != nil {
 		global.GVA_LOG.Error("register table failed", zap.Error(err))

+ 4 - 0
server/initialize/job.go

@@ -14,6 +14,10 @@ func MyJob() {
 		if err != nil {
 			global.GVA_LOG.Error("CreateProjectMonthFee ====== " + err.Error())
 		}
+		err = dao.CreateMonthExpenses()
+		if err != nil {
+			global.GVA_LOG.Error("CreateMonthExpenses ====== " + err.Error())
+		}
 	})
 
 	c.Start()

+ 1 - 0
server/router/admin/expenses.go

@@ -27,5 +27,6 @@ func (s *DepartmentRouter) InitExpensesRouter(Router *gin.RouterGroup) {
 		expensesRouterWithoutRecord.POST("queryExpensesSumByPeople", expensesApi.QueryExpensesSumByPeople)
 		expensesRouterWithoutRecord.GET("querySurplus", expensesApi.QuerySurplus)
 		expensesRouterWithoutRecord.GET("queryProjectMonthFee", expensesApi.QueryProjectMonthFee)
+		expensesRouterWithoutRecord.GET("queryMonthExpenses", expensesApi.QueryMonthExpenses)
 	}
 }

+ 4 - 0
server/service/admin/expenses.go

@@ -51,6 +51,10 @@ func (es *ExpensesService) QueryProjectMonthFee(monthTime, yearTime string) ([]d
 	return dao.QueryProjectMonthFee(monthTime, yearTime)
 }
 
+func (es *ExpensesService) QueryMonthExpenses(monthTime, yearTime string) ([]dao.MonthExpenses, error) {
+	return dao.QueryMonthExpenses(monthTime, yearTime)
+}
+
 func (es *ExpensesService) CreateExpenses(expenses dao.Expenses) error {
 	return expenses.CreateExpenses()
 }

+ 8 - 0
web/src/api/cost.js

@@ -49,3 +49,11 @@ export const peopleCost = (data) => {
   })
 }
 
+// 查询项目月费用
+export const queryProjectMonthFee = (month, year) => {
+  return service({
+    url: '/expenses/queryProjectMonthFee?monthTime=' + month + '&yearTime=' + year,
+    method: 'get',
+  })
+}
+

+ 8 - 0
web/src/api/project.js

@@ -107,3 +107,11 @@ export const queryProjectExpense = (code) => {
     params: { code: code }
   })
 }
+
+// 查询项目总金
+export const queryProjectSum = () => {
+  return service({
+    url: '/project/queryProjectSum',
+    method: 'GET'
+  })
+}

+ 0 - 1
web/src/view/dashboard/dashboardTable/dashboardTable.vue

@@ -73,7 +73,6 @@ const queryData = async() => {
 
 // 计算
 const already = (val) => {
-  console.log(val.collection)
   let sum = 0
   for (const key in val.collection) {
     sum = sum + Number(val.collection[key].collectionPrice)