123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- package service
- import (
- "fmt"
- "kpt.xdmy/apiserver/model"
- "kpt.xdmy/apiserver/model/home"
- "kpt.xdmy/pkg/util"
- "time"
- )
- func (s *Service) OverallIndex() (*home.OverallIndexResp, error) {
- resp := new(home.OverallIndexResp)
- monthBudgetList := make([]*home.MonthBudget, 0)
- err := s.d.DB.Raw(`SELECT
- (
- sum( monthBudget )*(
- DATEDIFF(
- NOW(),
- CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
- CONCAT( YEAR ( NOW()), '-12-31' ),
- CONCAT( YEAR ( NOW()), '-01-01' ))
- )) monthBudget,
- feeType
- FROM
- month_budget join pasture on pasture.id = month_budget.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' ) and vendor = 1 and feeType != '维修费'
- GROUP BY
- feeType
- UNION ALL
- SELECT
- (
- sum( monthBudget )*(
- DATEDIFF(
- NOW(),
- CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
- CONCAT( YEAR ( NOW()), '-12-31' ),
- CONCAT( YEAR ( NOW()), '-01-01' ))
- )) monthBudget,
- feeType
- FROM
- month_budget join pasture on pasture.id = month_budget.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' ) and vendor = 1 and feeType = '维修费'
- and (SELECT iscal FROM department d WHERE d.id=month_budget.deptId)= 0 and (SELECT name FROM department d WHERE d.id=month_budget.deptId)not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处')
- GROUP BY
- feeType`).Find(&monthBudgetList).Error
- if err != nil {
- return resp, err
- }
- //
- thisYearActualList := make([]*home.ThisYearActual, 0)
- err = s.d.DB.Raw(`select FYLX feeType,sum(HSL) sumPrice from feequery where Date like concat( '%',YEAR(NOW()),'%') and FYLX in ('水费','燃动费','电费') group by FYLX
- UNION ALL
- SELECT
- '维修费' feeType ,IFNULL(SUM( pu.sumPrice - pu.quitNumber * pu.price),0) sumPrice
- FROM
- partuse pu
- INNER JOIN bigpartuse bpu
- ON pu.bigId = bpu.id
- WHERE bpu.useType <> 3
- AND (
- pu.useTypeV = '维修'
- OR pu.useTypeV = '保养'
- ) AND (SELECT iscal FROM department d WHERE d.id=bpu.departmentId)= 0 and (SELECT name FROM department d WHERE d.id=bpu.departmentId)
- not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处')AND bpu.receiveTime BETWEEN CONCAT(YEAR(NOW()),'-01-01') AND CONCAT(YEAR(NOW()),'-12-31')
- AND (bpu.pastureid = (SELECT id FROM pasture WHERE name = '现代牧业') OR '现代牧业' = '现代牧业') and pu.dflag != 1`).Find(&thisYearActualList).Error
- if err != nil {
- return resp, err
- }
- lastYearActualList := make([]*home.ThisYearActual, 0)
- err = s.d.DB.Raw(`select FYLX feeType,sum(HSL) sumPrice from feequery where DATE_FORMAT(STR_TO_DATE( Date, '%Y-%m' ),'%Y-%m') between CONCAT(YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'-01') and DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 YEAR),'%Y-%m')
- and FYLX in ('水费','燃动费','电费') group by FYLX
- UNION ALL
- SELECT
- '维修费' feeType ,IFNULL(SUM( pu.sumPrice - pu.quitNumber * pu.price),0) sumPrice
- FROM
- partuse pu
- INNER JOIN bigpartuse bpu
- ON pu.bigId = bpu.id
- WHERE bpu.useType <> 3
- AND (
- pu.useTypeV = '维修'
- OR pu.useTypeV = '保养'
- ) AND (SELECT iscal FROM department d WHERE d.id=bpu.departmentId)= 0 and (SELECT name FROM department d WHERE d.id=bpu.departmentId)
- not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处') AND bpu.receiveTime BETWEEN CONCAT(YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'-01-01') AND DATE_SUB(CURDATE(), INTERVAL 1 YEAR)
- AND (bpu.pastureid = (SELECT id FROM pasture WHERE name = '现代牧业') OR '现代牧业' = '现代牧业') and pu.dflag != 1`).Find(&lastYearActualList).Error
- if err != nil {
- return resp, err
- }
- feedSum := new(model.FeedSum)
- err = s.d.DB.Raw(` select sum(cowNum) cowNum from feed_sum where feedDay like concat('%',?,'%')`, time.Now().Format("2006")).First(feedSum).Error
- if err != nil {
- return resp, err
- }
- var repair = new(home.Overall)
- var water = new(home.Overall)
- var electricity = new(home.Overall)
- var ignition = new(home.Overall)
- for _, monthBudget := range monthBudgetList {
- if monthBudget.FeeType == "维修费" {
- repair.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- } else if monthBudget.FeeType == "电费" {
- electricity.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- } else if monthBudget.FeeType == "水费" {
- water.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- } else if monthBudget.FeeType == "燃动费" {
- ignition.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- }
- }
- cowNum := float64(feedSum.CowNum)
- for _, item := range thisYearActualList {
- if item.FeeType == "维修费" {
- repair.Actual = util.Round(item.SumPrice/10000, 2)
- repair.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- } else if item.FeeType == "电费" {
- electricity.Actual = util.Round(item.SumPrice/10000, 2)
- electricity.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- } else if item.FeeType == "水费" {
- water.Actual = util.Round(item.SumPrice/10000, 2)
- water.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- } else if item.FeeType == "燃动费" {
- ignition.Actual = util.Round(item.SumPrice/10000, 2)
- ignition.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- }
- }
- for _, item := range lastYearActualList {
- if item.FeeType == "维修费" {
- repair.LastActual = util.Round(item.SumPrice/10000, 2)
- } else if item.FeeType == "电费" {
- electricity.LastActual = util.Round(item.SumPrice/10000, 2)
- } else if item.FeeType == "水费" {
- water.LastActual = util.Round(item.SumPrice/10000, 2)
- } else if item.FeeType == "燃动费" {
- ignition.LastActual = util.Round(item.SumPrice/10000, 2)
- }
- }
- resp.Repair = repair
- resp.Electricity = electricity
- resp.Water = water
- resp.Ignition = ignition
- return resp, nil
- }
- func (s *Service) CentralIndex() (*home.CentralIndexResp, error) {
- resp := new(home.CentralIndexResp)
- pastureList := make([]*model.Pasture, 0)
- err := s.d.DB.Select("center").Where(" center is not null or center != '' ").Group("center").Order("center_id").Find(&pastureList).Error
- if err != nil {
- return resp, err
- }
- centralIndexList := make([]*home.CentralIndex, 0)
- for _, pasture := range pastureList {
- centralIndexList = append(centralIndexList, &home.CentralIndex{
- Central: pasture.Center,
- })
- }
- monthBudgetList := make([]*home.MonthBudget, 0)
- err = s.d.DB.Raw(`SELECT
- (
- sum( monthBudget )*(
- DATEDIFF(
- NOW(),
- CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
- CONCAT( YEAR ( NOW()), '-12-31' ),
- CONCAT( YEAR ( NOW()), '-01-01' ))
- )) monthBudget,
- center
- FROM
- month_budget mb
- JOIN pasture p ON p.id = mb.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' )
- AND feeType IN ( '电费', '水费', '燃动费' )
- GROUP BY
- center ,feeType
-
- UNION ALL
- SELECT
- (
- sum( monthBudget )*(
- DATEDIFF(
- NOW(),
- CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
- CONCAT( YEAR ( NOW()), '-12-31' ),
- CONCAT( YEAR ( NOW()), '-01-01' ))
- )) monthBudget,
- center
- FROM
- month_budget join pasture on pasture.id = month_budget.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' ) and vendor = 1 and feeType = '维修费'
- and (SELECT iscal FROM department d WHERE d.id=month_budget.deptId)= 0 and (SELECT name FROM department d WHERE d.id=month_budget.deptId)not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处')
- GROUP BY
- center`).Find(&monthBudgetList).Error
- if err != nil {
- return resp, err
- }
- thisYearActualList := make([]*home.ThisYearActual, 0)
- err = s.d.DB.Raw(`select sum(t.sumPrice) sumPrice,p.center from (
- select pastureid,FYLX feeType,sum(HSL) sumPrice from feequery where Date like concat( '%',YEAR(NOW()),'%')
- and FYLX in ('水费','燃动费','电费') group by FYLX,pastureid
- UNION ALL
- SELECT
- bpu.pastureid,'维修费' feeType ,IFNULL(SUM( pu.sumPrice - pu.quitNumber * pu.price),0) sumPrice
- FROM
- partuse pu
- INNER JOIN bigpartuse bpu
- ON pu.bigId = bpu.id
- WHERE bpu.useType <> 3
- AND (
- pu.useTypeV = '维修'
- OR pu.useTypeV = '保养'
- ) AND (SELECT iscal FROM department d WHERE d.id=bpu.departmentId)= 0 and (SELECT name FROM department d WHERE d.id=bpu.departmentId)
- not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处') AND bpu.receiveTime BETWEEN CONCAT(YEAR(NOW()),'-01-01') AND CONCAT(YEAR(NOW()),'-12-31')
- AND (bpu.pastureid = (SELECT id FROM pasture WHERE name = '现代牧业') OR '现代牧业' = '现代牧业') and pu.dflag != 1 group by bpu.pastureId) t
- join pasture p on p.id = t.pastureId and p.vendor = 1 and p.IsEnergy = 0 GROUP BY p.center`).Find(&thisYearActualList).Error
- if err != nil {
- return resp, err
- }
- nowStr := time.Now().Format("2006-01-02")
- now, _ := time.Parse("2006-01-02", nowStr)
- // 获取当年的一月一号
- year := now.Year()
- start := time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)
- fmt.Println(start)
- end := time.Date(year, 12, 31, 0, 0, 0, 0, time.UTC)
- fmt.Println(end)
- real := now.Sub(start)
- sum := end.Sub(start)
- sumDay := sum.Hours() / 24
- realDay := real.Hours() / 24
- for _, central := range centralIndexList {
- for _, monthBudget := range monthBudgetList {
- if monthBudget.Center == central.Central {
- central.Budget += util.Round(monthBudget.MonthBudget, 2)
- //break
- }
- }
- for _, item := range thisYearActualList {
- if item.Center == central.Central {
- central.Actual += util.Round(item.SumPrice, 2)
- //break
- }
- }
- if central.Budget > 0 && central.Actual > 0 {
- central.Complete = util.Round((1+(central.Budget/sumDay*realDay-(central.Actual))/central.Budget)*100, 2)
- central.Budget = util.Round(central.Budget/10000, 2)
- central.Actual = util.Round(central.Actual/10000, 2)
- }
- }
- resp.Central = append(resp.Central, centralIndexList...)
- return resp, nil
- }
- func (s *Service) GetExpense(pastureName string) (*home.GetExpenseResp, error) {
- resp := new(home.GetExpenseResp)
- pasture := new(model.Pasture)
- if pastureName != "现代牧业" && pastureName != "" {
- err := s.d.DB.Where(" name = ? ", pastureName).First(&pasture).Error
- if err != nil {
- return resp, err
- }
- }
- monthBudgetList := make([]*home.MonthBudget, 0)
- err := s.d.DB.Raw(`SELECT
- (
- sum( monthBudget )*(
- DATEDIFF(
- NOW(),
- CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
- CONCAT( YEAR ( NOW()), '-12-31' ),
- CONCAT( YEAR ( NOW()), '-01-01' ))
- )) monthBudget,
- feeType ,pasture.center
- FROM
- month_budget join pasture on pasture.id = month_budget.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' ) and vendor = 1 and feeType != '维修费'
- GROUP BY
- feeType
- UNION ALL
- SELECT
- (
- sum( monthBudget )*(
- DATEDIFF(
- NOW(),
- CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
- CONCAT( YEAR ( NOW()), '-12-31' ),
- CONCAT( YEAR ( NOW()), '-01-01' ))
- )) monthBudget,
- feeType ,pasture.center
- FROM
- month_budget join pasture on pasture.id = month_budget.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' ) and vendor = 1 and feeType = '维修费'
- and (SELECT iscal FROM department d WHERE d.id=month_budget.deptId)= 0 and (SELECT name FROM department d WHERE d.id=month_budget.deptId)not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处')
- GROUP BY
- feeType`).Find(&monthBudgetList).Error
- if err != nil {
- return resp, err
- }
- thisYearActualList := make([]*home.ThisYearActual, 0)
- err = s.d.DB.Debug().Raw(`select FYLX feeType,sum(HSL) sumPrice,p.center from feequery fq join pasture p on p.id = fq.pastureId
- where Date like concat( '%',YEAR(NOW()),'%') and ( ? = 0 or pastureId = ?)
- and FYLX in ('水费','燃动费','电费') group by FYLX,p.center
- UNION ALL
- SELECT
- '维修费' feeType ,IFNULL(SUM( pu.sumPrice - pu.quitNumber * pu.price),0) sumPrice,p.center
- FROM
- partuse pu
- INNER JOIN bigpartuse bpu
- ON pu.bigId = bpu.id
- join pasture p on p.id = bpu.pastureId
- WHERE bpu.useType <> 3
- AND (
- pu.useTypeV = '维修'
- OR pu.useTypeV = '保养'
- ) AND (SELECT iscal FROM department d WHERE d.id=bpu.departmentId)= 0 AND bpu.receiveTime BETWEEN CONCAT(YEAR(NOW()),'-01-01')
- AND CONCAT(YEAR(NOW()),'-12-31') and (SELECT name FROM department d WHERE d.id=bpu.departmentId)
- not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处')
- AND ( ? = 0 or pastureId = ?) and pu.dflag != 1 and p.vendor = 1 group by p.center`, pasture.ID, pasture.ID, pasture.ID, pasture.ID).Find(&thisYearActualList).Error
- if err != nil {
- return resp, err
- }
- lastYearActualList := make([]*home.ThisYearActual, 0)
- err = s.d.DB.Debug().Raw(`select FYLX feeType,sum(HSL) sumPrice,p.center from feequery fq join pasture p on p.id = fq.pastureId where DATE_FORMAT(STR_TO_DATE( Date, '%Y-%m' ),'%Y-%m') between CONCAT(YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'-01') and DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 YEAR),'%Y-%m')
- and FYLX in ('水费','燃动费','电费') and ( ? = 0 or pastureId = ?) group by FYLX,p.center
- UNION ALL
- SELECT
- '维修费' feeType ,IFNULL(SUM( pu.sumPrice - pu.quitNumber * pu.price),0) sumPrice,p.center
- FROM
- partuse pu
- INNER JOIN bigpartuse bpu
- ON pu.bigId = bpu.id
- join pasture p on p.id = bpu.pastureId
- WHERE bpu.useType <> 3
- AND (
- pu.useTypeV = '维修'
- OR pu.useTypeV = '保养'
- ) AND (SELECT iscal FROM department d WHERE d.id=bpu.departmentId)= 0 AND bpu.receiveTime BETWEEN CONCAT(YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'-01-01') AND DATE_SUB(CURDATE(), INTERVAL 1 YEAR)
- AND ( ? = 0 or pastureId = ?) and (SELECT name FROM department d WHERE d.id=bpu.departmentId)
- not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处') and pu.dflag != 1 group by p.center`, pasture.ID, pasture.ID, pasture.ID, pasture.ID).Find(&lastYearActualList).Error
- if err != nil {
- return resp, err
- }
- pastureList := make([]*model.Pasture, 0)
- err = s.d.DB.Select("center").Where(" center is not null or center != '' ").Group("center").Order("center_id").Find(&pastureList).Error
- if err != nil {
- return resp, err
- }
- var repairList = make([]*home.Overall, 0)
- var waterList = make([]*home.Overall, 0)
- var electricityList = make([]*home.Overall, 0)
- var ignitionList = make([]*home.Overall, 0)
- for _, item := range pastureList {
- repairList = append(repairList, &home.Overall{Center: item.Center})
- waterList = append(waterList, &home.Overall{Center: item.Center})
- electricityList = append(electricityList, &home.Overall{Center: item.Center})
- ignitionList = append(ignitionList, &home.Overall{Center: item.Center})
- }
- for _, monthBudget := range monthBudgetList {
- if monthBudget.FeeType == "维修费" {
- for _, repair := range repairList {
- if repair.Center == monthBudget.Center {
- repair.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- break
- }
- }
- } else if monthBudget.FeeType == "电费" {
- for _, electricity := range electricityList {
- if electricity.Center == monthBudget.Center {
- electricity.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- break
- }
- }
- } else if monthBudget.FeeType == "水费" {
- for _, water := range waterList {
- if water.Center == monthBudget.Center {
- water.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- break
- }
- }
- } else if monthBudget.FeeType == "燃动费" {
- for _, ignition := range ignitionList {
- if ignition.Center == monthBudget.Center {
- ignition.Budget = util.Round(monthBudget.MonthBudget/10000, 2)
- break
- }
- }
- }
- }
- feedSumList := make([]*model.FeedSumAndPasture, 0)
- feedSum := new(model.FeedSumAndPasture)
- if pasture.ID == 0 {
- err = s.d.DB.Raw(` select sum(cowNum) cowNum,center from feed_sum join pasture on pasture.id = feed_sum.pastureId
- where feedDay like concat('%',?,'%') group by center`, time.Now().Format("2006")).Find(&feedSumList).Error
- if err != nil {
- return resp, err
- }
- } else {
- err = s.d.DB.Raw(` select sum(cowNum) cowNum from feed_sum join pasture on pasture.id = feed_sum.pastureId
- where feedDay like concat('%',?,'%') and pastureId = ? `, time.Now().Format("2006"), pasture.ID).First(&feedSum).Error
- if err != nil {
- return resp, err
- }
- }
- //cowNum := float64(feedSum.CowNum)
- for _, item := range thisYearActualList {
- var cowNum float64
- if pasture.ID == 0 {
- for _, center := range feedSumList {
- if center.Center == item.Center {
- cowNum = float64(center.CowNum)
- break
- }
- }
- } else {
- cowNum = float64(feedSum.CowNum)
- }
- if item.FeeType == "维修费" {
- for _, repair := range repairList {
- if repair.Center == item.Center {
- repair.Actual = util.Round(item.SumPrice/10000, 2)
- repair.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- break
- }
- }
- } else if item.FeeType == "电费" {
- //electricity.Actual = util.Round(item.SumPrice, 2)
- //electricity.Actual = util.Round(electricity.Actual/cowNum, 2)
- for _, electricity := range electricityList {
- if electricity.Center == item.Center {
- electricity.Actual = util.Round(item.SumPrice/10000, 2)
- electricity.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- break
- }
- }
- } else if item.FeeType == "水费" {
- //water.Actual = util.Round(item.SumPrice, 2)
- //water.Actual = util.Round(water.Actual/cowNum, 2)
- for _, water := range waterList {
- if water.Center == item.Center {
- water.Actual = util.Round(item.SumPrice/10000, 2)
- water.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- break
- }
- }
- } else if item.FeeType == "燃动费" {
- //ignition.Actual = util.Round(item.SumPrice, 2)
- //ignition.Actual = util.Round(ignition.Actual/cowNum, 2)
- for _, ignition := range ignitionList {
- if ignition.Center == item.Center {
- //ignition.Actual = util.Round(item.SumPrice, 2)
- ignition.SingleCow = util.Round(item.SumPrice/cowNum, 2)
- ignition.Actual = util.Round(item.SumPrice/10000, 2)
- break
- }
- }
- }
- }
- for _, item := range lastYearActualList {
- if item.FeeType == "维修费" {
- for _, repair := range repairList {
- if repair.Center == item.Center {
- repair.LastActual = util.Round(item.SumPrice/10000, 2)
- break
- }
- }
- //repair.LastActual = util.Round(item.SumPrice, 2)
- } else if item.FeeType == "电费" {
- //electricity.LastActual = util.Round(item.SumPrice, 2)
- for _, electricity := range electricityList {
- if electricity.Center == item.Center {
- electricity.LastActual = util.Round(item.SumPrice/10000, 2)
- break
- }
- }
- } else if item.FeeType == "水费" {
- //water.LastActual = util.Round(item.SumPrice, 2)
- for _, water := range waterList {
- if water.Center == item.Center {
- water.LastActual = util.Round(item.SumPrice/10000, 2)
- break
- }
- }
- } else if item.FeeType == "燃动费" {
- //ignition.LastActual = util.Round(item.SumPrice, 2)
- for _, ignition := range ignitionList {
- if ignition.Center == item.Center {
- ignition.LastActual = util.Round(item.SumPrice/10000, 2)
- break
- }
- }
- }
- }
- resp.Repair = append(resp.Repair, repairList...)
- resp.Electricity = append(resp.Electricity, electricityList...)
- resp.Water = append(resp.Water, waterList...)
- resp.Ignition = append(resp.Ignition, ignitionList...)
- return resp, nil
- }
- func (s *Service) GetPastureIndex(pastureName string) (*home.GetPastureIndexResp, error) {
- resp := new(home.GetPastureIndexResp)
- monthBudget := new(home.MonthBudget)
- err := s.d.DB.Raw(`SELECT
- sum( monthBudget ) monthBudget
- FROM
- month_budget mb
- JOIN pasture p ON p.id = mb.pastureId
- WHERE
- budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' )
- AND feeType IN ( '维修费', '电费', '水费', '燃动费' ) and p.name = ? `, pastureName).Find(&monthBudget).Error
- if err != nil {
- return resp, err
- }
- thisYearActual := new(home.ThisYearActual)
- err = s.d.DB.Raw(`select sum(t.sumPrice) sumPrice from (
- select pastureid,FYLX feeType,sum(HSL) sumPrice from feequery fq join pasture p on p.id = fq.pastureId where Date like concat( '%',YEAR(NOW()),'%')
- and FYLX in ('水费','燃动费','电费') and p.name = ?
- UNION ALL
- SELECT
- bpu.pastureid,'维修费' feeType ,IFNULL(SUM( pu.sumPrice - pu.quitNumber * pu.price),0) sumPrice
- FROM
- partuse pu
- INNER JOIN bigpartuse bpu
- ON pu.bigId = bpu.id
- join pasture p on p.id = bpu.pastureId
- WHERE bpu.useType <> 3
- AND (
- pu.useTypeV = '维修'
- OR pu.useTypeV = '保养'
- ) AND (SELECT iscal FROM department d WHERE d.id=bpu.departmentId)= 0 AND bpu.receiveTime BETWEEN CONCAT(YEAR(NOW()),'-01-01') AND CONCAT(YEAR(NOW()),'-12-31')
- AND p.name = ? and (SELECT name FROM department d WHERE d.id=bpu.departmentId) not in ('饲养处','犊牛处','品控处','繁育处','兽医处','安环处','供应处') and pu.dflag != 1 group by bpu.pastureId) t
- join pasture p on p.id = t.pastureId and p.vendor = 1 GROUP BY p.center`, pastureName, pastureName).Find(&thisYearActual).Error
- if err != nil {
- return resp, err
- }
- nowStr := time.Now().Format("2006-01-02")
- now, _ := time.Parse("2006-01-02", nowStr)
- // 获取当年的一月一号
- year := now.Year()
- start := time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)
- fmt.Println(start)
- end := time.Date(year, 12, 31, 0, 0, 0, 0, time.UTC)
- fmt.Println(end)
- real := now.Sub(start)
- sum := end.Sub(start)
- sumDay := sum.Hours() / 24
- realDay := real.Hours() / 24
- fmt.Println(realDay, sumDay)
- resp.Budget = monthBudget.MonthBudget
- resp.Actual = thisYearActual.SumPrice
- if resp.Budget != 0 && resp.Actual != 0 {
- resp.Complete = util.Round((1+(resp.Budget/sumDay*realDay-(resp.Actual))/resp.Budget)*100, 2)
- }
- //ROUND(1+((qq.monthLimit/qq.sumDay*qq.realDay-(qq.sumPrice/10000))/(qq.monthLimit/qq.sumDay*qq.realDay)), 2)
- resp.Budget = util.Round(resp.Budget/10000, 2)
- resp.Actual = util.Round(resp.Actual/10000, 2)
- //resp.Complete = util.Round(1+(resp.Budget/sumDay*realDay-(resp.Actual/10000))/(resp.Budget/sumDay*realDay), 2)
- return resp, nil
- }
|