Browse Source

现代牧业首页提交

baishaojie 1 year ago
parent
commit
1a2b7aea43
58 changed files with 1627 additions and 57 deletions
  1. 5 0
      apiserver/model/createCodeN.go
  2. 55 0
      apiserver/model/diesel.go
  3. 11 0
      apiserver/model/emp.go
  4. 12 0
      apiserver/model/home/centralIndexResp.go
  5. 20 0
      apiserver/model/home/home.go
  6. 16 0
      apiserver/model/home/overallIndexResp.go
  7. 15 0
      apiserver/model/home/pastureIndex.go
  8. 25 0
      apiserver/model/http/diesel.go
  9. 22 0
      apiserver/model/oilcard.go
  10. 5 5
      apiserver/routers/api/api.go
  11. 13 1
      apiserver/routers/api/db.go
  12. 41 0
      apiserver/routers/diesel.go
  13. 51 0
      apiserver/routers/home.go
  14. 11 2
      apiserver/routers/router.go
  15. 112 0
      apiserver/service/charge_off.go
  16. 583 0
      apiserver/service/diesel.go
  17. 1 0
      apiserver/service/feequery.go
  18. 511 0
      apiserver/service/home.go
  19. 6 19
      apiserver/service/job.go
  20. 14 14
      cmd/conf/app.ini
  21. 8 8
      cmd/conf/conf.toml
  22. BIN
      cmd/dist(3).zip
  23. 0 0
      cmd/dist(3)/dist/datas/myMap.json
  24. BIN
      cmd/dist(3)/dist/favicon.ico
  25. 0 0
      cmd/dist(3)/dist/index.html
  26. 0 0
      cmd/dist(3)/dist/static/css/app.646e8e6c.css
  27. 0 0
      cmd/dist(3)/dist/static/css/chunk-elementUI.45ab9bc1.css
  28. 0 0
      cmd/dist(3)/dist/static/css/chunk-libs.2e418612.css
  29. BIN
      cmd/dist(3)/dist/static/fonts/element-icons.535877f5.woff
  30. BIN
      cmd/dist(3)/dist/static/fonts/element-icons.732389de.ttf
  31. BIN
      cmd/dist(3)/dist/static/img/1.1ddf085a.png
  32. BIN
      cmd/dist(3)/dist/static/img/404.a57b6f31.png
  33. BIN
      cmd/dist(3)/dist/static/img/404_cloud.0f4bc32b.png
  34. BIN
      cmd/dist(3)/dist/static/img/cow.3495de2a.jpg
  35. BIN
      cmd/dist(3)/dist/static/img/login-bg.dfe7c90f.jpg
  36. BIN
      cmd/dist(3)/dist/static/img/login-bg1.1f1602f0.jpg
  37. BIN
      cmd/dist(3)/dist/static/img/login-bujian.8695940d.png
  38. BIN
      cmd/dist(3)/dist/static/img/logo.4a74cb8a.png
  39. BIN
      cmd/dist(3)/dist/static/img/logo1.d2343c0f.png
  40. BIN
      cmd/dist(3)/dist/static/img/logo_u3.34a9ffae.png
  41. 0 0
      cmd/dist(3)/dist/static/js/app.772b0456.js
  42. 0 0
      cmd/dist(3)/dist/static/js/chunk-39889fb2.0f71ae7a.js
  43. 0 0
      cmd/dist(3)/dist/static/js/chunk-581b2547.c1efae40.js
  44. 0 0
      cmd/dist(3)/dist/static/js/chunk-d17f893e.56c4d12d.js
  45. 0 0
      cmd/dist(3)/dist/static/js/chunk-elementUI.1e8908f6.js
  46. 0 0
      cmd/dist(3)/dist/static/js/chunk-libs.f5a7c3c5.js
  47. BIN
      cmd/dist-tmr-23-10-23.zip
  48. 0 0
      cmd/dist/index.html
  49. 0 0
      cmd/dist/static/css/app.61f02e07.css
  50. 0 0
      cmd/dist/static/css/app.646e8e6c.css
  51. 0 0
      cmd/dist/static/js/app.772b0456.js
  52. 0 0
      cmd/dist/static/js/app.b57d8ddf.js
  53. BIN
      cmd/sh/eqserver
  54. BIN
      cmd/sh/main
  55. 1 0
      go.mod
  56. 5 0
      pkg/util/util.go
  57. 11 5
      pkg/util/wxwork.go
  58. 73 3
      sap.sql

+ 5 - 0
apiserver/model/createCodeN.go

@@ -0,0 +1,5 @@
+package model
+
+type CreateCodeN struct {
+	OrderCode string `gorm:"column:orderCode"`
+}

+ 55 - 0
apiserver/model/diesel.go

@@ -0,0 +1,55 @@
+package model
+
+type Diesel struct {
+	Id         int64   `gorm:"column:id"`
+	PastureId  int64   `gorm:"column:pastureId"`
+	DeptId     int64   `gorm:"column:deptId"`
+	EqId       int64   `gorm:"column:eqId"`
+	EqCode     string  `gorm:"column:eqCode"`
+	OilcardId  int64   `gorm:"column:oilcardId"`
+	CardNumber string  `gorm:"column:cardNumber"`
+	OilClass   string  `gorm:"column:oilClass"`
+	OilAmount  string  `gorm:"column:oilAmount"`
+	NowPrice   float64 `gorm:"column:nowPrice"`
+	Price      string  `gorm:"column:price"`
+	EmpId      string  `gorm:"column:empId"`
+	InputId    int64   `gorm:"column:inputId"`
+	SelTime    string  `gorm:"column:selTime"`
+	Note       string  `gorm:"column:note"`
+	OilType    int64   `gorm:"column:oilType"`
+	OilName    string  `gorm:"column:oilName"`
+	DieselCode string  `gorm:"column:dieselCode"`
+	Sort       int64   `gorm:"column:sort"`
+	ProofCode  string  `gorm:"column:ProofCode"`
+}
+
+func (t Diesel) TableName() string {
+	return "diesel"
+}
+
+type DieselOff struct {
+	Id         int64   `gorm:"column:id"`
+	PastureId  int64   `gorm:"column:pastureId"`
+	DeptId     int64   `gorm:"column:deptId"`
+	EqId       int64   `gorm:"column:eqId"`
+	EqCode     string  `gorm:"column:eqCode"`
+	OilcardId  int64   `gorm:"column:oilcardId"`
+	CardNumber string  `gorm:"column:cardNumber"`
+	OilClass   string  `gorm:"column:oilClass"`
+	OilAmount  string  `gorm:"column:oilAmount"`
+	NowPrice   float64 `gorm:"column:nowPrice"`
+	Price      string  `gorm:"column:price"`
+	EmpId      string  `gorm:"column:empId"`
+	InputId    int64   `gorm:"column:inputId"`
+	SelTime    string  `gorm:"column:selTime"`
+	Note       string  `gorm:"column:note"`
+	OilType    int64   `gorm:"column:oilType"`
+	OilName    string  `gorm:"column:oilName"`
+	DieselCode string  `gorm:"column:dieselCode"`
+	Sort       int64   `gorm:"column:sort"`
+	ProofCode  string  `gorm:"column:ProofCode"`
+}
+
+func (t DieselOff) TableName() string {
+	return "diesel_off"
+}

+ 11 - 0
apiserver/model/emp.go

@@ -0,0 +1,11 @@
+package model
+
+type Emp struct {
+	Id        int64  `gorm:"column:id"`
+	Empname   string `gorm:"column:empname"`
+	PastureId string `gorm:"column:pastureId"`
+}
+
+func (t Emp) TableName() string {
+	return "emp"
+}

+ 12 - 0
apiserver/model/home/centralIndexResp.go

@@ -0,0 +1,12 @@
+package home
+
+type CentralIndexResp struct {
+	Central []*CentralIndex `json:"central"`
+}
+
+type CentralIndex struct {
+	Budget   float64 `json:"budget"`
+	Actual   float64 `json:"actual"`
+	Complete float64 `json:"complete"`
+	Central  string  `json:"central"`
+}

+ 20 - 0
apiserver/model/home/home.go

@@ -0,0 +1,20 @@
+package home
+
+type MonthBudget struct {
+	MonthBudget float64 `gorm:"column:monthBudget"`
+	FeeType     string  `gorm:"column:feeType"`
+	Center      string  `gorm:"column:center"`
+}
+
+type ThisYearActual struct {
+	SumPrice float64 `gorm:"column:sumPrice"`
+	FeeType  string  `gorm:"column:feeType"`
+	Center   string  `gorm:"column:center"`
+}
+
+type GetExpenseResp struct {
+	Repair      []*Overall `json:"repair"`      //维修
+	Water       []*Overall `json:"water"`       //水费
+	Electricity []*Overall `json:"electricity"` //电费
+	Ignition    []*Overall `json:"ignition"`    //燃动
+}

+ 16 - 0
apiserver/model/home/overallIndexResp.go

@@ -0,0 +1,16 @@
+package home
+
+type OverallIndexResp struct {
+	Repair      *Overall `json:"repair"`      //维修
+	Water       *Overall `json:"water"`       //水费
+	Electricity *Overall `json:"electricity"` //电费
+	Ignition    *Overall `json:"ignition"`    //燃动
+}
+
+type Overall struct {
+	Budget     float64 `json:"budget"`     //预算
+	Actual     float64 `json:"actual"`     //实际
+	LastActual float64 `json:"lastActual"` //上年实际
+	SingleCow  float64 `json:"singleCow"`  //单头牛
+	Center     string  `gorm:"column:center"`
+}

+ 15 - 0
apiserver/model/home/pastureIndex.go

@@ -0,0 +1,15 @@
+package home
+
+type GetPastureIndexReq struct {
+	PastureId int64 `json:"pastureID"`
+}
+
+type GetPastureIndexResp struct {
+	Budget   float64 `json:"budget"`
+	Actual   float64 `json:"actual"`
+	Complete float64 `json:"complete"`
+}
+
+func (d GetPastureIndexReq) Validate() bool {
+	return true
+}

+ 25 - 0
apiserver/model/http/diesel.go

@@ -0,0 +1,25 @@
+package http
+
+type DieselReq struct {
+	PastureId    int64   `json:"pastureId"`
+	SelTime      string  `json:"selTime"`
+	OilClass     string  `json:"oilClass"`
+	OilAmount    string  `json:"oilAmount"`
+	EqId         int64   `json:"eqId"`
+	EqCode       string  `json:"eqCode"`
+	DepartmentId int64   `json:"departmentId"`
+	Note         string  `json:"note"`
+	NowPrice     float64 `json:"nowPrice"`
+	OilcardId    int64   `json:"oilcardId"`
+	CardNumber   string  `json:"cardNumber"`
+	Price        string  `json:"price"`
+	EmpId        string  `json:"empId"`
+	InputId      int64   `json:"inputId"`
+	OilType      int64   `json:"oilType"`
+	OilName      string  `json:"oilName"`
+	Id           int64   `json:"id"`
+}
+
+func (d DieselReq) Validate() bool {
+	return true
+}

+ 22 - 0
apiserver/model/oilcard.go

@@ -0,0 +1,22 @@
+package model
+
+type Oilcard struct {
+	Id             string `gorm:"column:id"`
+	PastureId      string `gorm:"column:pastureId"`
+	DepartmentName string `gorm:"column:departmentName"`
+	DepartmentId   string `gorm:"column:departmentId"`
+	CardCode       string `gorm:"column:cardCode"`
+	CardType       string `gorm:"column:cardType"`
+	CardAmount     string `gorm:"column:cardAmount"`
+	EqId           string `gorm:"column:eqId"`
+	EqCode         string `gorm:"column:eqCode"`
+	EmpId          string `gorm:"column:empId"`
+	Enable         string `gorm:"column:enable"`
+	LastcardAmount string `gorm:"column:lastcardAmount"`
+	OilType        string `gorm:"column:oilType"`
+	OilName        string `gorm:"column:oilName"`
+}
+
+func (t Oilcard) TableName() string {
+	return "oilcard"
+}

+ 5 - 5
apiserver/routers/api/api.go

@@ -236,19 +236,19 @@ func GetDieselTypeList(c *gin.Context) {
 
 
 	res.Data.DieselType = append(res.Data.DieselType, &modernPb.DieselTypeEnum{
 	res.Data.DieselType = append(res.Data.DieselType, &modernPb.DieselTypeEnum{
 		Value: modernPb.DieselType_Zero,
 		Value: modernPb.DieselType_Zero,
-		Label: "0#",
+		Label: "0",
 	}, &modernPb.DieselTypeEnum{
 	}, &modernPb.DieselTypeEnum{
 		Value: modernPb.DieselType_Ten,
 		Value: modernPb.DieselType_Ten,
-		Label: "-10#",
+		Label: "10号",
 	}, &modernPb.DieselTypeEnum{
 	}, &modernPb.DieselTypeEnum{
 		Value: modernPb.DieselType_Twenty,
 		Value: modernPb.DieselType_Twenty,
-		Label: "-20#",
+		Label: "20号",
 	}, &modernPb.DieselTypeEnum{
 	}, &modernPb.DieselTypeEnum{
 		Value: modernPb.DieselType_Thirty,
 		Value: modernPb.DieselType_Thirty,
-		Label: "-30#",
+		Label: "30号",
 	}, &modernPb.DieselTypeEnum{
 	}, &modernPb.DieselTypeEnum{
 		Value: modernPb.DieselType_Thirty_Five,
 		Value: modernPb.DieselType_Thirty_Five,
-		Label: "-35#",
+		Label: "35号",
 	})
 	})
 
 
 	ginutil.JSONResp(c, res)
 	ginutil.JSONResp(c, res)

+ 13 - 1
apiserver/routers/api/db.go

@@ -3504,7 +3504,19 @@ func GetPartsListSGv2(c *gin.Context) {
 		}
 		}
 		if len(pastureBigcontract) > 0 {
 		if len(pastureBigcontract) > 0 {
 			//partMap[part["contractCode"]] = true
 			//partMap[part["contractCode"]] = true
-			priceExist = append(priceExist, part["price"])
+			//part["lifeCycle"]
+			var lifeCycle, contractVarianceItem string
+			if part["lifeCycle"] == "" {
+				lifeCycle = "无"
+			} else {
+				lifeCycle = part["lifeCycle"]
+			}
+			if part["contractVarianceItem"] == "" {
+				contractVarianceItem = "无"
+			} else {
+				contractVarianceItem = part["contractVarianceItem"]
+			}
+			priceExist = append(priceExist, fmt.Sprintf("%s 使用周期 %s 合同差异性 %s", part["price"], lifeCycle, contractVarianceItem))
 			part["price"] = ""
 			part["price"] = ""
 			resp = part
 			resp = part
 		} else {
 		} else {

+ 41 - 0
apiserver/routers/diesel.go

@@ -0,0 +1,41 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"kpt.xdmy/apiserver/model/http"
+	"kpt.xdmy/pkg/app"
+	"kpt.xdmy/pkg/e"
+)
+
+func InsertDieselData(c *gin.Context) {
+	appG := app.Gin{C: c}
+	p := new(http.DieselReq)
+	if !Bind(c, p) {
+		return
+	}
+	err := svc.InsertDieselData(p)
+	if err != nil {
+		c.JSON(200, map[string]interface{}{"code": 200, "data": err.Error(), "msg": "fail"})
+		return
+	}
+	appG.Response(200, e.SUCCESS, true)
+}
+
+func InsertDieselImportExcel(c *gin.Context) {
+	appG := app.Gin{C: c}
+	data, err := svc.ImportExcel(c)
+	if err != nil {
+		c.JSON(200, map[string]interface{}{"code": 200, "data": err.Error(), "msg": "fail"})
+		return
+	}
+	appG.Response(200, e.SUCCESS, data)
+}
+
+func DieselOff(c *gin.Context) {
+	p := new(http.DieselReq)
+	if !Bind(c, p) {
+		return
+	}
+	hrp := svc.DieselOff(p.Id)
+	c.JSON(200, &hrp)
+}

+ 51 - 0
apiserver/routers/home.go

@@ -0,0 +1,51 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"kpt.xdmy/pkg/app"
+	"kpt.xdmy/pkg/e"
+)
+
+func OverallIndex(c *gin.Context) {
+	appG := app.Gin{C: c}
+	data, err := svc.OverallIndex()
+	if err != nil {
+		c.JSON(200, map[string]interface{}{"code": 200, "data": err.Error(), "msg": "fail"})
+		return
+	}
+	appG.Response(200, e.SUCCESS, data)
+}
+
+func CentralIndex(c *gin.Context) {
+	appG := app.Gin{C: c}
+	data, err := svc.CentralIndex()
+	if err != nil {
+		c.JSON(200, map[string]interface{}{"code": 200, "data": err.Error(), "msg": "fail"})
+		return
+	}
+	appG.Response(200, e.SUCCESS, data)
+}
+
+func GetExpense(c *gin.Context) {
+	appG := app.Gin{C: c}
+	pastureName := c.Query("pastureName")
+	data, err := svc.GetExpense(pastureName)
+	if err != nil {
+		c.JSON(200, map[string]interface{}{"code": 200, "data": err.Error(), "msg": "fail"})
+		return
+	}
+	appG.Response(200, e.SUCCESS, data)
+}
+
+func GetPastureIndex(c *gin.Context) {
+	appG := app.Gin{C: c}
+	//p := new(home.GetPastureIndexReq)
+	pastureName := c.Query("pastureName")
+
+	data, err := svc.GetPastureIndex(pastureName)
+	if err != nil {
+		c.JSON(200, map[string]interface{}{"code": 200, "data": err.Error(), "msg": "fail"})
+		return
+	}
+	appG.Response(200, e.SUCCESS, data)
+}

+ 11 - 2
apiserver/routers/router.go

@@ -69,7 +69,6 @@ func InitRouter() *gin.Engine {
 	eqm.POST("/login", api.Auth)
 	eqm.POST("/login", api.Auth)
 
 
 	apiV1 := r.Group("/authdata")
 	apiV1 := r.Group("/authdata")
-
 	apiV1.Use(jwt.JWT()) // token 验证
 	apiV1.Use(jwt.JWT()) // token 验证
 
 
 	{
 	{
@@ -146,6 +145,16 @@ func InitRouter() *gin.Engine {
 		// 备件申购-特殊申购
 		// 备件申购-特殊申购
 		apiV1.POST("/spare/parts/requisitions", api.SparePartsRequisitions)
 		apiV1.POST("/spare/parts/requisitions", api.SparePartsRequisitions)
 		apiV1.GET("/diesel/type/list", api.GetDieselTypeList)
 		apiV1.GET("/diesel/type/list", api.GetDieselTypeList)
+
+		apiV1.POST("/diese/add", InsertDieselData)
+		apiV1.POST("/diese/import/excel", InsertDieselImportExcel)
+		apiV1.POST("/diese/off", DieselOff)
+
+		apiV1.GET("/centra/index", CentralIndex)     //各中心总指标
+		apiV1.GET("/overall/index", OverallIndex)    //集团分项指标
+		apiV1.GET("/expense", GetExpense)            //费用统计
+		apiV1.GET("/pasture/index", GetPastureIndex) //牧场指标
+
 	}
 	}
 
 
 	if setting.ServerSetting.NoAuth > 0 {
 	if setting.ServerSetting.NoAuth > 0 {
@@ -159,7 +168,7 @@ func InitRouter() *gin.Engine {
 			apiV2.POST("/GetDataByNames", api.GetDataByNames)
 			apiV2.POST("/GetDataByNames", api.GetDataByNames)
 			apiV2.POST("/PostDataByName", api.PostDataByName)
 			apiV2.POST("/PostDataByName", api.PostDataByName)
 			apiV2.POST("/PostDataByNames", api.PostDataByNames)
 			apiV2.POST("/PostDataByNames", api.PostDataByNames)
-
+	
 			apiV2.POST("/ExecDataByConfig", api.ExecDataByConfig)
 			apiV2.POST("/ExecDataByConfig", api.ExecDataByConfig)
 
 
 			apiV2.POST("/GetDataByNameForm", api.GetDataByNameForm)
 			apiV2.POST("/GetDataByNameForm", api.GetDataByNameForm)

+ 112 - 0
apiserver/service/charge_off.go

@@ -484,3 +484,115 @@ func (s *Service) quitProofList(p *model.ProofReq) (hrp *http.Response) {
 	hrp.Message = fmt.Sprintf("success  :type = %v OrderNumber = %s", p.NumberType, p.OrderNumber)
 	hrp.Message = fmt.Sprintf("success  :type = %v OrderNumber = %s", p.NumberType, p.OrderNumber)
 	return
 	return
 }
 }
+
+// 柴油凭证冲销
+func (s *Service) DieselOff(id int64) (hrp *http.Response) {
+
+	r := new(http.ChargeOffReq)
+	rp := new(http.SapResp)
+	hrp = new(http.Response)
+	hrp.Code = 200
+	hrp.Msg = "fail"
+	p := new(model.ProofReq)
+
+	tx := s.d.DB.Begin()
+	diesel := new(model.Diesel)
+
+	err := tx.Where("id = ? ", id).First(&diesel).Error
+	if err != nil {
+		hrp.Message += err.Error()
+		tx.Rollback()
+		return
+	}
+
+	r.Dest.DestID = "EQMAN"
+	r.Dest.BussTp = "MM015"
+	//r.Dest.Url = "https://app.modernfarming.cn:7443/sap/Common/MM015/CancelMblnr"
+	//r.Dest.Url = "http://192.168.61.117/SAPP0/Common/MM015/CancelMblnr"
+	r.Dest.Url = fmt.Sprintf("%s/Common/MM015/CancelMblnr", config.Conf.Http.Routing)
+
+	r.Data.ProofCode = diesel.ProofCode
+	r.Data.ProofYear = diesel.SelTime[:4]
+	r.Data.ChargeDate = diesel.SelTime
+	r.Data.OrderNumber = diesel.DieselCode
+	r.Data.HasTicket = util.ZeroStr(p.HasTicket == 1, "X")
+	log.Infof("proofcode: %s", r.Data.ProofCode)
+	sl := r.Data.RowsNumber
+	sl = append(sl, http.ChargeOffDetail{RowNumber: int(diesel.Sort)})
+
+	dieselOff := &model.DieselOff{
+		Id:         diesel.Id,
+		PastureId:  diesel.PastureId,
+		DeptId:     diesel.DeptId,
+		EqId:       diesel.EqId,
+		EqCode:     diesel.EqCode,
+		OilcardId:  diesel.OilcardId,
+		CardNumber: diesel.CardNumber,
+		OilClass:   diesel.OilClass,
+		OilAmount:  diesel.OilAmount,
+		NowPrice:   diesel.NowPrice,
+		Price:      diesel.Price,
+		EmpId:      diesel.EmpId,
+		InputId:    diesel.InputId,
+		SelTime:    diesel.SelTime,
+		Note:       diesel.Note,
+		OilType:    diesel.OilType,
+		OilName:    diesel.OilName,
+		DieselCode: diesel.DieselCode,
+		Sort:       diesel.Sort,
+		ProofCode:  diesel.ProofCode,
+	}
+	err = tx.Exec(`delete from diesel where id = ? `, id).Error
+	if err != nil {
+		hrp.Message += err.Error()
+		tx.Rollback()
+		return
+	}
+	err = tx.Create(&dieselOff).Error
+	if err != nil {
+		hrp.Message += err.Error()
+		tx.Rollback()
+		return
+	}
+
+	r.Data.RowsNumber = sl
+	rbyte, _ := json.Marshal(r)
+	//rbyte, _ := json.Marshal(r)
+	fmt.Println(string(rbyte))
+	e := s.SyncSap(r, rp, rbyte)
+	pp.Print(r)
+	if e == nil {
+		if rp.Data.Status == "S" {
+			hrp.Message = fmt.Sprintf("sap物料冲销成功:%d %s %s", p.NumberType, rp.Data.ProofNumber, rp.Data.EqNumber)
+			log.Info(hrp.Message)
+		} else {
+			hrp.Message = fmt.Sprintf("sap凭证冲销失败:%s", rp.Dest.MessText)
+			log.Infoln(hrp.Message, r, p)
+			tx.Rollback()
+			return
+		}
+	} else {
+		hrp.Message = fmt.Sprintf("sap冲销接口报错:error:%s", e)
+		log.Infoln(hrp.Message, r, p)
+		tx.Rollback()
+		return
+	}
+
+	tx.Commit()
+	hrp.Msg = "ok"
+	return
+}
+
+func (s *Service) zdDieselOff() {
+	dieselList := make([]*model.Diesel, 0)
+	s.d.DB.Where("dieselCode is not null  ").Limit(500).Find(&dieselList)
+	fmt.Println(len(dieselList))
+	for i, diesel := range dieselList {
+		fmt.Println(i, diesel)
+		s.DieselOff(diesel.Id)
+	}
+
+	for i, diesel := range dieselList {
+		fmt.Println(i, diesel)
+	}
+}

+ 583 - 0
apiserver/service/diesel.go

@@ -0,0 +1,583 @@
+package service
+
+import (
+	"fmt"
+	"github.com/360EntSecGroup-Skylar/excelize"
+	"github.com/astaxie/beego/logs"
+	"github.com/gin-gonic/gin"
+	"github.com/goccy/go-json"
+	"github.com/k0kubun/pp/v3"
+	"github.com/pkg/errors"
+	log "github.com/sirupsen/logrus"
+	"gorm.io/gorm"
+	"kpt.xdmy/apiserver/model"
+	"kpt.xdmy/apiserver/model/http"
+	"kpt.xdmy/pkg/util"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func (s *Service) InsertDieselData(req *http.DieselReq) error {
+	code := new(model.CreateCodeN)
+	s.d.DB.Raw(`call createCodeN(?,?)`, req.PastureId, "CY").First(code)
+	return s.d.DB.Transaction(func(tx *gorm.DB) error {
+		diesel := &model.Diesel{
+			PastureId:  req.PastureId,
+			DeptId:     req.DepartmentId,
+			EqId:       req.EqId,
+			EqCode:     req.EqCode,
+			OilcardId:  req.OilcardId,
+			CardNumber: req.CardNumber,
+			OilClass:   req.OilClass,
+			OilAmount:  req.OilAmount,
+			NowPrice:   req.NowPrice,
+			Price:      req.Price,
+			EmpId:      req.EmpId,
+			InputId:    req.InputId,
+			SelTime:    req.SelTime,
+			Note:       req.Note,
+			OilName:    req.OilName,
+			OilType:    req.OilType,
+			DieselCode: code.OrderCode,
+		}
+		resp := tx.Create(diesel)
+
+		if resp.Error != nil {
+			logs.Error(resp.Error)
+			return resp.Error
+		}
+		req.Id = diesel.Id
+		err := tx.Exec(`update oilcard set lastcardAmount=cardAmount,cardAmount =cardAmount -?   where id =?`, req.Id, req.NowPrice).Error
+		if err != nil {
+			logs.Error(err)
+			return err
+		}
+		dieselList := make([]*model.Diesel, 0)
+		dieselList = append(dieselList, diesel)
+		err = s.DieseUseProof(dieselList, tx, strconv.FormatInt(req.PastureId, 10), code.OrderCode, req.SelTime)
+		if err != nil {
+			//logs.Error(err)
+			return err
+		}
+		return nil
+	})
+}
+
+func (s *Service) ImportExcel(c *gin.Context) (map[string]interface{}, error) {
+
+	inputdata := ""
+	if err := c.Request.ParseForm(); err != nil {
+		return nil, err
+	}
+	params := c.Request.Form
+	// file, _, err := c.Request.FormFile("file")
+	fileHeader, err := c.FormFile("file")
+	file, err := fileHeader.Open()
+	if err != nil {
+		return nil, err
+	}
+	if err != nil {
+		return nil, err
+	}
+	pastureId := params.Get("pastureId")
+	sqlnamestr := params.Get("name")
+	sheetname := params.Get("sheetname")
+	importParams := params.Get("importParams")
+	//sql, _ := restful.GetSqlByNameDB(sqlnamestr)
+	// 备件编号,备件名称,规格型号,计量单位,品牌,计划量,单价,备注,jwt_username
+	paramslist := strings.Split(importParams, ",")
+	if sqlnamestr != "importGasoline" && sqlnamestr != "importCoal" && sqlnamestr != "importBiomass" && sqlnamestr != "importEnergy" {
+		paramslist = append(paramslist, "jwt_username")
+	}
+	queryData := make([]interface{}, 0)
+
+	xlsx1, err := excelize.OpenReader(file)
+
+	if err != nil {
+		return nil, err
+	}
+	ok := 0
+	error := 0
+
+	rows := xlsx1.GetRows(sheetname)
+	if len(rows) > 10000 {
+		rows = rows[:10000]
+	}
+	dieselList := make([]*model.Diesel, 0)
+	errBool := false
+	//var selTime string
+	code := new(model.CreateCodeN)
+	s.d.DB.Raw(`call createCodeN(?,?)`, pastureId, "CY").First(code)
+	tx := s.d.DB.Begin()
+	for i, row := range rows {
+		if i > 0 {
+			if len(paramslist) > 0 {
+				s_params := make([]interface{}, 0)
+				entry := make(map[string]string)
+				outentry := make(map[string]interface{})
+				inputdata = ""
+				for _, value := range paramslist {
+					if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
+						if tempv, exists := c.Get("jwt_username"); exists {
+							s_params = append(s_params, tempv.(string))
+						} else {
+							s_params = append(s_params, "")
+						}
+					} else {
+						for j, colCell := range rows[0] {
+							if strings.Trim(value, " ") == colCell {
+								for k, colCell1 := range row {
+									if j == k {
+										outentry[colCell] = colCell1
+										entry[colCell] = colCell1
+										//inputdata = inputdata + colCell + ":" + colCell1 + ";"
+									}
+								}
+							}
+						}
+						s_params = append(s_params, entry[strings.Trim(value, " ")])
+					}
+				}
+				outentry["input"] = inputdata
+				diesel := new(model.Diesel)
+				fmt.Println(entry)
+				//牧场,油卡编号,设备名称,设备编号,加油日期,加油量(升),单价,录入人,加油人,加油工班,备注,柴油类型,jwt_username
+				if _, ok := entry["加油量(升)"]; ok {
+					diesel.OilAmount = entry["加油量(升)"]
+				}
+				if _, ok := entry["单价"]; ok {
+					diesel.Price = entry["单价"]
+				}
+				if _, ok := entry["单价"]; ok {
+					diesel.Price = entry["单价"]
+				}
+				if diesel.OilAmount == "" {
+					outentry["error_msg"] = "加油量必须输入"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+				if diesel.Price == "" {
+					outentry["error_msg"] = "单价不能为空"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+				if _, ok := entry["牧场"]; !ok {
+					outentry["error_msg"] = "牧场不能为空"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+				if _, ok := entry["油卡编号"]; !ok {
+					outentry["error_msg"] = "油卡编号不能为空"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+
+				jyTime, err := time.Parse("2006-01-02", entry["加油日期"])
+				if err != nil {
+					outentry["error_msg"] = err.Error()
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+
+				now, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
+
+				if jyTime.Unix() > now.Unix() {
+					outentry["error_msg"] = "本次抄表日期不可大于当前日期"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+
+				pasture := new(model.Pasture)
+				tx.Where("name = ?", entry["牧场"]).First(pasture)
+				if pasture.ID == 0 {
+					outentry["error_msg"] = "牧场不存在"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+
+				diesel.CardNumber = entry["油卡编号"]
+				diesel.SelTime = entry["加油日期"]
+
+				oilcard := new(model.Oilcard)
+				tx.Where("cardCode = ? and pastureId = ? ", entry["油卡编号"], pasture.ID).First(oilcard)
+				if oilcard.Id == "" {
+					outentry["error_msg"] = entry["油卡编号"] + "油卡不存在"
+					error++
+					queryData = append(queryData, outentry)
+					errBool = true
+					continue
+				}
+
+				if oilcard.CardType != "外部" {
+					equipment := new(model.Equipment)
+					tx.Where("eqCode = ? and pastureId =?  ", entry["设备编号"], pasture.ID).First(equipment)
+					diesel.EqCode = equipment.EqCode
+					diesel.EqId = int64(equipment.Id)
+					if equipment.EqCode == "" {
+						outentry["error_msg"] = entry["设备编号"] + "资产不存在或不在本牧场"
+						error++
+						queryData = append(queryData, outentry)
+						errBool = true
+						continue
+					}
+				}
+
+				if _, ok := entry["录入人"]; ok {
+					emp := new(model.Emp)
+					tx.Where("empname = ? and pastureId = ?", entry["录入人"], pasture.ID).First(emp)
+					diesel.InputId = emp.Id
+				}
+
+				diesel.PastureId = int64(pasture.ID)
+				price, _ := strconv.ParseFloat(diesel.Price, 64)
+				oilAmount, _ := strconv.ParseFloat(diesel.OilAmount, 64)
+				diesel.NowPrice = price * oilAmount
+				if _, ok := entry["备注"]; ok {
+					diesel.Note = entry["备注"]
+				}
+				if _, ok := entry["录入人"]; ok {
+					emp := new(model.Emp)
+					tx.Where("empname = ? and pastureId = ?", entry["录入人"], pasture.ID).First(emp)
+					diesel.EmpId = emp.Empname
+				}
+				if _, ok := entry["加油工班"]; ok {
+					diesel.OilClass = entry["加油工班"]
+				}
+				deptId, _ := strconv.ParseInt(oilcard.DepartmentId, 10, 64)
+				diesel.DeptId = deptId
+				oilcardId, _ := strconv.ParseInt(oilcard.Id, 10, 64)
+				diesel.OilcardId = oilcardId
+
+				//WHEN '0#' THEN
+				//1
+				//WHEN '-10#' THEN
+				//2
+				//WHEN '-20#' THEN
+				//3
+				//WHEN '-30#' THEN
+				//4
+				//WHEN '-35#' THEN
+
+				if _, ok := entry["柴油类型"]; ok {
+					if entry["柴油类型"] == "" {
+						outentry["error_msg"] = "柴油类型不能为空"
+						error++
+						queryData = append(queryData, outentry)
+						//tx.Rollback()
+						errBool = true
+						continue
+					}
+					diesel.OilName = entry["柴油类型"]
+					if entry["柴油类型"] == "0号" {
+						diesel.OilType = 1
+
+					} else if entry["柴油类型"] == "10号" {
+						//diesel.OilName = "-10#"
+						diesel.OilType = 2
+					} else if entry["柴油类型"] == "20号" {
+						//diesel.OilName = "-20#"
+						diesel.OilType = 3
+					} else if entry["柴油类型"] == "30号" {
+						//diesel.OilName = "-30#"
+						diesel.OilType = 4
+					} else if entry["柴油类型"] == "35号" {
+						//diesel.OilName = "-35#"
+						diesel.OilType = 5
+					}
+				} else {
+					outentry["error_msg"] = "柴油类型不能为空"
+					error++
+					queryData = append(queryData, outentry)
+					//tx.Rollback()
+					errBool = true
+					continue
+				}
+
+				diesel.DieselCode = code.OrderCode
+				err = tx.Create(diesel).Error
+				if err != nil {
+					outentry["error_msg"] = err.Error()
+					error++
+					queryData = append(queryData, outentry)
+					//tx.Rollback()
+					errBool = true
+					continue
+				}
+
+				err = tx.Exec(` UPDATE
+    oilcard
+  SET
+    lastcardAmount = cardAmount,
+    cardAmount = cardAmount-CAST( ?*? as decimal(10,2)) 
+  WHERE id = ?;`, oilAmount, price, oilcard.Id).Error
+				if err != nil {
+					outentry["error_msg"] = err.Error()
+					error++
+					queryData = append(queryData, outentry)
+					//tx.Rollback()
+					errBool = true
+					continue
+				}
+				//selTime = diesel.SelTime
+				dieselList = append(dieselList, diesel)
+				ok++
+			}
+		}
+	}
+
+	if errBool {
+		tx.Rollback()
+		data := make(map[string]interface{})
+		data["result"] = queryData
+		//data["success"] = ok
+		data["err_count"] = 1
+		return data, nil
+	}
+
+	//err = s.DieseUseProof(dieselList, tx, pastureId, code.OrderCode, selTime)
+	//if err != nil {
+	//	outentry := make(map[string]interface{})
+	//	outentry["error_msg"] = err.Error()
+	//	error++
+	//	queryData = append(queryData, outentry)
+	//
+	//	data := make(map[string]interface{})
+	//	data["result"] = queryData
+	//	//data["success"] = ok
+	//	data["err_count"] = 1
+	//	tx.Rollback()
+	//	return data, nil
+	//}
+
+	tx.Commit()
+
+	data := make(map[string]interface{})
+	data["result"] = queryData
+	data["success"] = len(dieselList)
+	//data["err_count"] = error
+	return data, nil
+}
+
+func (s *Service) DieseUseProof(reqList []*model.Diesel, tx *gorm.DB, pastureId, dieselCode, selTime string) error {
+	//pr := new(http.ProofPartReq)
+	r := new(http.ProofReq)
+	rp := new(http.ProofResp)
+	//parts := make([]*model.PartUseStr, 0)
+	//bp := new(model.BigPartUse)
+	pa := new(model.Pasture)
+
+	if e := tx.Where("id = ? ", pastureId).First(pa).Error; e != nil {
+		log.Error(e)
+		return errors.New(fmt.Sprintf("查询牧场信息 errors:%v", e))
+	}
+
+	proofDest(r)
+	//{"DEST":{"DEST_ID":"EQMAN","BUSS_TP":"MM001","MESS_ID":"","STATUS":"","MESS_TEXT":"","STATUS_OS":"",
+	//	"Url":"http://192.168.61.117/SAPP0/Common/MM001/ModifyMblnr"},"DATA":{"BLDAT":"20221105",
+	//		"BUDAT":"20221101","FRBNR":"CK03221105003","MSEG":[{"ZEILE":"1","MATNR":"14.02.15.06.000091",
+	//			"WERKS":"M003","LGORT":"1004","MENGE":"1.000000","MEINS":"桶","EBELN":"","EBPLP":"",
+	//	"BWART":"201","SOBKZ":"K","KOSTL":"1002030505","ANLN1":"50300000007","ANLN2":"","LIFNR":"100869"}]}}
+	//b, _ := json.Marshal(pr)
+	//restful.Dbs.DB.Exec(` insert into equipmentlingshi(text)values(?)`, string(b))
+	r.Dest.MESSIDOS = dieselCode
+	r.Dest.BUSSDOCOS = dieselCode
+	r.Data.EqNumber = dieselCode
+	r.Data.CreateTime = time.Now().Format("20060102")
+	if t, e := util.ParseDate(selTime[:10]); e != nil {
+		log.Error(e, selTime)
+	} else {
+		r.Data.PostDate = t.Format("20060102")
+	}
+
+	diesePartMap := map[string]string{
+		"0号":  "20.04.01.01.000001",
+		"10号": "20.04.01.01.000002",
+		"20号": "20.04.01.01.000003",
+		"30号": "20.04.01.01.000004",
+		"35号": "20.04.01.01.000005",
+	}
+
+	//for i, v := range parts {
+	//bc := new(model.BigContract)
+	//c := new(model.Contract)
+	//w := new(model.Warehouse)
+	//pv := new(model.Provider)
+
+	//contractID, _ := strconv.Atoi(v.ContractID.(string))
+
+	//if e := s.d.DB.First(storage, model.PartRepertory{ContractID: contractID}).Error; e != nil {
+	//	log.Errorln(e, v.ContractID)
+	//	return errors.New(fmt.Sprintf("查询库存信息出错 errors:%v", e))
+	//}
+
+	//if e := s.d.DB.First(pv, model.Provider{ID: storage.ProviderID}).Error; e != nil {
+	//	log.Errorln(e, storage.ProviderID)
+	//	return errors.New(fmt.Sprintf("查询供应商信息出错 errors:%v", e))
+	//}
+	//dict := new(model.Dictlist)
+	//tx.First(dict, model.Dictlist{Pid: 21, Value: "物耗"})
+
+	//if e := s.d.DB.First(w, model.Warehouse{ID: v.LocationID}).Error; e != nil {
+	//	log.Errorln(e, v.LocationID)
+	//	return errors.New(fmt.Sprintf("errors:%v", e))
+	//}
+	for i, req := range reqList {
+		eq := new(model.Equipment)
+		//storage := new(model.PartRepertory)
+
+		dp := new(model.Department)
+		if e := tx.Where("id = ? ", req.DeptId).First(dp).Error; e != nil {
+			log.Error(e)
+			return errors.New(fmt.Sprintf("查询部门信息出错 errors:%v", e))
+		}
+		sdetail := http.ProofDetail{}
+		if req.EqCode != "" {
+			if e := tx.Where("id = ?  and pastureid = ? ", req.EqId, req.PastureId).First(eq).Error; e != nil {
+				return errors.New(fmt.Sprintf("errors:%v", e))
+			}
+			sdetail.AssetCode = eq.SapCode
+			sdetail.AssetSon = eq.SonCode
+		}
+
+		sdetail.EXT01 = "6601011703"
+		// 报废出库
+
+		// 领用出库、手动出库
+		//if pr.UseType == 0 || pr.UseType == 1 {
+		sdetail.MoveType = "201"
+		sdetail.CostCenter = dp.CostCenterCode
+		//if dp.Factory == "" {
+		sdetail.Factory = pa.FactoryCode
+		//} else {
+		//	sdetail.Factory = dp.Factory
+		//}
+
+		if sdetail.Factory == "M005" && strings.Contains(dp.Name, "二期") {
+			sdetail.Factory = "M017"
+		}
+
+		sdetail.RowNumber = fmt.Sprintf("%d", i+1)
+		sdetail.Quantity = fmt.Sprintf("%s", req.OilAmount)
+		//sdetail.Unit = v.Unit.(string)
+		sdetail.Code = diesePartMap[req.OilName]
+		sdetail.Location = "1005"
+		//if contractID > 0 && bc.IsZeroStock == 1 {
+		//	sdetail.SaveType = "K"
+		//}
+		//
+		//if sdetail.SaveType == "K" {
+		//	sdetail.Provider = pv.SapCode
+		//}
+		r.Data.Detail = append(r.Data.Detail, sdetail)
+		tx.Exec(`  update diesel set  sort = ?  where id = ?  `, sdetail.RowNumber, req.Id)
+		//if e := s.d.DB.Model(&model.PartUse{}).Where("id=?", v.ID).Update("rowNumber", sdetail.RowNumber).Error; e != nil {
+		//	log.Errorln(e, v.ID)
+		//}
+	}
+
+	//_, err = tx.Exec(` update partuse set rowNumber = ?  where id = ? `, sdetail.RowNumber, v.ID)
+	//if err != nil {
+	//	return err
+	//}
+	//}
+	//}
+	///*
+	pp.Print(r)
+	//log.Infof("bp.pastureId:%d,pa.name:%s,pa.companycode:%s", bp.PastureID, pa.Name, pa.CompanyCode)
+
+	rbyte, _ := json.Marshal(r)
+	fmt.Println(string(rbyte))
+	if e := s.SyncSap(r, rp, rbyte); e != nil {
+		log.Errorf("laid proof error:%v", e)
+		return errors.New(fmt.Sprintf("errors:%s", r.MessText))
+	} else {
+		if rp.Dest.Status == "S" {
+			log.Printf("use proof  success:eqcode=%s,sapcode=%s", rp.Data.EqNumber, rp.Data.SapNumber)
+			//if e := s.d.DB.Model(&model.BigPartUse{}).Where("useform = ?", rp.Data.EqNumber).Update("ProofCode", rp.Data.SapNumber).Error; e != nil {
+			//	log.Errorln(e)
+			//}
+			tx.Exec(`  update diesel set  ProofCode = ?  where dieselCode = ?  `, rp.Data.SapNumber, dieselCode)
+		} else {
+			log.Warnf(" use proof :%s", rp.Dest.MessText)
+			return errors.New(fmt.Sprintf("errors:%s", rp.Dest.MessText))
+		}
+	}
+	return nil
+}
+
+func (s *Service) zdDieselData(pastureId int, date string) error {
+	code := new(model.CreateCodeN)
+	s.d.DB.Raw(`call createCodeN(?,?)`, pastureId, "CY").First(code)
+	return s.d.DB.Transaction(func(tx *gorm.DB) error {
+		deselOffList := make([]*model.DieselOff, 0)
+		err := tx.Where("pastureId = ?", pastureId).Where(" selTime  like concat('%',?,'%') ", date).Find(&deselOffList).Error
+		fmt.Println(err)
+		if err != nil {
+			//logs.Error(err)
+			return err
+		}
+		if len(deselOffList) == 0 {
+			return nil
+		}
+		dieselList := make([]*model.Diesel, 0)
+		for _, item := range deselOffList {
+			//fmt.Println(item)
+			var targetTime = ""
+			t, err := time.Parse(time.RFC3339, item.SelTime)
+			if err != nil {
+				fmt.Println("解析错误:", err)
+				targetTime = item.SelTime
+			} else {
+				targetTime = t.Format("2006-01-02 15:04:05")
+			}
+
+			// 转换为指定格式的时间字符串
+			fmt.Println(targetTime)
+			diesel := &model.Diesel{
+				Id:         item.Id,
+				PastureId:  item.PastureId,
+				DeptId:     item.DeptId,
+				EqId:       item.EqId,
+				EqCode:     item.EqCode,
+				OilcardId:  item.OilcardId,
+				CardNumber: item.CardNumber,
+				OilClass:   item.OilClass,
+				OilAmount:  item.OilAmount,
+				NowPrice:   item.NowPrice,
+				Price:      item.Price,
+				EmpId:      item.EmpId,
+				InputId:    item.InputId,
+				SelTime:    targetTime,
+				Note:       item.Note,
+				OilName:    item.OilName,
+				OilType:    item.OilType,
+				DieselCode: code.OrderCode,
+			}
+			tx.Create(diesel)
+			dieselList = append(dieselList, diesel)
+			tx.Exec(`delete from diesel_off where id = ?`, item.Id)
+		}
+
+		err = s.DieseUseProof(dieselList, tx, strconv.Itoa(pastureId), code.OrderCode, date)
+		if err != nil {
+			//logs.Error(err)
+			return err
+		}
+		return nil
+	})
+}

+ 1 - 0
apiserver/service/feequery.go

@@ -96,6 +96,7 @@ func AutoFeeQuery(werks string, pastureID int) {
 			http.TFYLX{FYLX: "柴油费"})
 			http.TFYLX{FYLX: "柴油费"})
 
 
 		rbyte, _ := json.Marshal(r)
 		rbyte, _ := json.Marshal(r)
+		fmt.Println(string(rbyte))
 		if e = s.SyncSap(r, rp, rbyte); e == nil {
 		if e = s.SyncSap(r, rp, rbyte); e == nil {
 			if rp.Dest.Status == "S" {
 			if rp.Dest.Status == "S" {
 				log.Infof("sap  FeeQuery  success sum=%d", len(rp.Data.Items))
 				log.Infof("sap  FeeQuery  success sum=%d", len(rp.Data.Items))

+ 511 - 0
apiserver/service/home.go

@@ -0,0 +1,511 @@
+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 
+WHERE
+	budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' ) 
+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  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 bpu.sterilisation = 0`).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 like  concat( '%',YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'%')  
+                                                     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  bpu.receiveTime BETWEEN CONCAT(YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'-01-01') AND CONCAT(YEAR(NOW()),'-12-31')
+  AND (bpu.pastureid = (SELECT id FROM pasture WHERE name = '现代牧业') OR '现代牧业' = '现代牧业') and bpu.sterilisation = 0`).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 `).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/1000000, 2)
+		} else if monthBudget.FeeType == "电费" {
+			electricity.Budget = util.Round(monthBudget.MonthBudget/1000000, 2)
+		} else if monthBudget.FeeType == "水费" {
+			water.Budget = util.Round(monthBudget.MonthBudget/1000000, 2)
+		} else if monthBudget.FeeType == "燃动费" {
+			ignition.Budget = util.Round(monthBudget.MonthBudget/1000000, 2)
+		}
+	}
+	cowNum := float64(feedSum.CowNum)
+	for _, item := range thisYearActualList {
+		if item.FeeType == "维修费" {
+			repair.Actual = util.Round(item.SumPrice/1000000, 2)
+			repair.SingleCow = util.Round(item.SumPrice/cowNum, 2)
+		} else if item.FeeType == "电费" {
+			electricity.Actual = util.Round(item.SumPrice/1000000, 2)
+			electricity.SingleCow = util.Round(item.SumPrice/cowNum, 2)
+		} else if item.FeeType == "水费" {
+			water.Actual = util.Round(item.SumPrice/1000000, 2)
+			water.SingleCow = util.Round(item.SumPrice/cowNum, 2)
+		} else if item.FeeType == "燃动费" {
+			ignition.Actual = util.Round(item.SumPrice/1000000, 2)
+			ignition.SingleCow = util.Round(item.SumPrice/cowNum, 2)
+		}
+	}
+	for _, item := range lastYearActualList {
+		if item.FeeType == "维修费" {
+			repair.LastActual = util.Round(item.SumPrice/1000000, 2)
+		} else if item.FeeType == "电费" {
+			electricity.LastActual = util.Round(item.SumPrice/1000000, 2)
+		} else if item.FeeType == "水费" {
+			water.LastActual = util.Round(item.SumPrice/1000000, 2)
+		} else if item.FeeType == "燃动费" {
+			ignition.LastActual = util.Round(item.SumPrice/1000000, 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,
+	p.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 `).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  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 bpu.sterilisation = 0  group by bpu.pastureId)  t  
+    join pasture p on p.id = t.pastureId   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
+	fmt.Println(realDay, sumDay)
+
+	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/1000000, 2)
+			central.Actual = util.Round(central.Actual/1000000, 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.Debug().Raw(`SELECT
+(
+		sum( monthBudget )*(
+			DATEDIFF(
+				NOW(),
+				CONCAT( YEAR ( NOW()), '-01-01' )) / DATEDIFF(
+				CONCAT( YEAR ( NOW()), '-12-31' ),
+			CONCAT( YEAR ( NOW()), '-01-01' )) 
+		)) monthBudget,
+	feeType ,p.center
+FROM
+	month_budget mb join pasture p on p.id = mb.pastureId
+WHERE
+	budgetMonth LIKE concat( '%', date_format( now(), '%Y' ), '%' )  and ( ? = 0  or pastureId = ?)
+GROUP BY
+	feeType,p.center `, pasture.ID, pasture.ID).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  ( ? = 0  or pastureId = ?) and bpu.sterilisation = 0 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 like  concat( '%',YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)),'%')  
+                                                     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 CONCAT(YEAR(NOW()),'-12-31')
+  AND  ( ? = 0  or pastureId = ?)  and bpu.sterilisation = 0 group by p.center`, pasture.ID, pasture.ID, pasture.ID, pasture.ID).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 `).First(feedSum).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/1000000, 2)
+					break
+				}
+			}
+		} else if monthBudget.FeeType == "电费" {
+			for _, electricity := range electricityList {
+				if electricity.Center == monthBudget.Center {
+					electricity.Budget = util.Round(monthBudget.MonthBudget/1000000, 2)
+					break
+				}
+			}
+		} else if monthBudget.FeeType == "水费" {
+			for _, water := range waterList {
+				if water.Center == monthBudget.Center {
+					water.Budget = util.Round(monthBudget.MonthBudget/1000000, 2)
+					break
+				}
+			}
+		} else if monthBudget.FeeType == "燃动费" {
+			for _, ignition := range ignitionList {
+				if ignition.Center == monthBudget.Center {
+					ignition.Budget = util.Round(monthBudget.MonthBudget/1000000, 2)
+					break
+				}
+			}
+		}
+	}
+	cowNum := float64(feedSum.CowNum)
+	for _, item := range thisYearActualList {
+		if item.FeeType == "维修费" {
+			for _, repair := range repairList {
+				if repair.Center == item.Center {
+					repair.Actual = util.Round(item.SumPrice/1000000, 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/1000000, 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/1000000, 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/1000000, 2)
+					break
+				}
+			}
+		}
+	}
+
+	for _, item := range lastYearActualList {
+		if item.FeeType == "维修费" {
+			for _, repair := range repairList {
+				if repair.Center == item.Center {
+					repair.LastActual = util.Round(item.SumPrice/1000000, 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/1000000, 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/1000000, 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/1000000, 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 bpu.sterilisation = 0  group by bpu.pastureId)  t  
+    join pasture p on p.id = t.pastureId   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
+	resp.Complete = util.Round((1+(resp.Budget/sumDay*realDay-(resp.Actual))/resp.Budget)*100, 2)
+	resp.Budget = util.Round(resp.Budget/1000000, 2)
+	resp.Actual = util.Round(resp.Actual/1000000, 2)
+	//resp.Complete = util.Round(1+(resp.Budget/sumDay*realDay-(resp.Actual/10000))/(resp.Budget/sumDay*realDay), 2)
+
+	return resp, nil
+}

+ 6 - 19
apiserver/service/job.go

@@ -11,33 +11,19 @@ import (
 var s *Service
 var s *Service
 
 
 func SapJobInit() {
 func SapJobInit() {
-	AutoSapOrderJob()
+
 	duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
 	duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
 	duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
 	duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
 	spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
 	spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
 	c := cron.New()
 	c := cron.New()
 	c.AddFunc(spec, func() {
 	c.AddFunc(spec, func() {
 		AutoSapOrderJob()
 		AutoSapOrderJob()
-		//AutoSrmOrderJob()
-		//AutoSapReturnOrderJob()
-		//AutoSrmReturnOrderJob()
+		AutoSrmOrderJob()
+		AutoSapReturnOrderJob()
+		AutoSrmReturnOrderJob()
 	})
 	})
-	c.Start()
-
-	//pastureList := make([]*model.Pasture, 0)
-	//s.d.DB.Table("pasture").Find(&pastureList)
-	//var t time.Time
-	//t = time.Now()
-	//i := -320
-	//for {
-	//	i++
-	//for _, pasture := range pastureList {
+	//c.Start()
 
 
-	//}
-	//	if t.AddDate(0, 0, i).Format("2006-01-02") == "2023-08-24" {
-	//		break
-	//	}
-	//}
 	c1 := cron.New()
 	c1 := cron.New()
 	c1.AddFunc("0 40 23 * * ?", func() {
 	c1.AddFunc("0 40 23 * * ?", func() {
 		fmt.Println(time.Now())
 		fmt.Println(time.Now())
@@ -107,6 +93,7 @@ func SapJobInit() {
 	c1.AddFunc("0 20 23 * * ?", func() {
 	c1.AddFunc("0 20 23 * * ?", func() {
 		AutoContractToASP()
 		AutoContractToASP()
 	})
 	})
+	AutoContractToASP()
 	//c1.Start()
 	//c1.Start()
 }
 }
 
 

+ 14 - 14
cmd/conf/app.ini

@@ -48,9 +48,9 @@ WXworkCorpid  = wx93ee6ef7d7810920
 #DingTalkToken = htdt1HPlOfaoKmd4BGxn5gpcphYAFymxU5FnXf4VmbVVasAAU49DClivfRa
 #DingTalkToken = htdt1HPlOfaoKmd4BGxn5gpcphYAFymxU5FnXf4VmbVVasAAU49DClivfRa
 #DingTalkEncodingAESKey = oxutjIUkWb6HvupqTcyspktMbYDWQKAoKKeQ8raEukt
 #DingTalkEncodingAESKey = oxutjIUkWb6HvupqTcyspktMbYDWQKAoKKeQ8raEukt
 
 
-DingTalkAgentid = 2390444980
-DingTalkAppKey = dingx8ltpwbamia4ewq7
-DingTalkAppSecret = Msyw2XheMhT3Z1Aty1E3iSxkfEUwJAO33uSCJhjFIfNhqbAYIXTaDKBhMSGsaAZQ
+DingTalkAgentid = 2067173604
+DingTalkAppKey = dingg52edjccnvxgfuns
+DingTalkAppSecret = M-VfdMdTo0XNcUb8PwGE89xHtlmLwZqWddvZOw6HnRzx97yFhio6rMh6yMjRYL2K
 
 
 #DingTalkAgentid = 2067173604
 #DingTalkAgentid = 2067173604
 #DingTalkAppKey = dingg52edjccnvxgfuns
 #DingTalkAppKey = dingg52edjccnvxgfuns
@@ -71,8 +71,8 @@ EasUrl = http://60.174.151.11:6888
 
 
 
 
 [database]
 [database]
-; ####DsnDsn = eq:Xdmy@1234@tcp(192.168.61.42:3306)/eq?charset=utf8&parseTime=True&loc=Local
-DsnDsn = root:kepaiteng!QAZ@tcp(222.73.129.15:31306)/eq230508?charset=utf8&parseTime=True&loc=Local
+DsnDsn = eq:Xdmy@1234@tcp(192.168.61.42:3306)/eq?charset=utf8&parseTime=True&loc=Local
+; ####DsnDsn = root:kepaiteng!QAZ@tcp(222.73.129.15:31306)/eq230508?charset=utf8&parseTime=True&loc=Local
 ; ####DsnDsn = eq:Xdmy@1234@tcp(192.168.63.42:3306)/eq?charset=utf8&parseTime=True&loc=Local
 ; ####DsnDsn = eq:Xdmy@1234@tcp(192.168.63.42:3306)/eq?charset=utf8&parseTime=True&loc=Local
 ; ####DsnDsn = root:root@tcp(127.0.0.1:3309)/test?charset=utf8&parseTime=True&loc=Local
 ; ####DsnDsn = root:root@tcp(127.0.0.1:3309)/test?charset=utf8&parseTime=True&loc=Local
 ; ####DsnDsn = root:root@tcp(192.168.1.93:3326)/eqdev?charset=utf8&parseTime=True&loc=Local
 ; ####DsnDsn = root:root@tcp(192.168.1.93:3326)/eqdev?charset=utf8&parseTime=True&loc=Local
@@ -80,17 +80,17 @@ DsnDsn = root:kepaiteng!QAZ@tcp(222.73.129.15:31306)/eq230508?charset=utf8&parse
 
 
 Type = mysql
 Type = mysql
 #####本地
 #####本地
-User = root
-Password = kepaiteng!QAZ
-Host = 222.73.129.15:31306
-Name = eq230508
+#User = root
+#Password = kepaiteng!QAZ
+#Host = 222.73.129.15:31306
+#Name = eq230508
 
 
 #####线上
 #####线上
-#User = eq
-#Password = Xdmy@1234
-#Host = 192.168.61.42:3306
-#Name = eq
-TablePrefix =
+User = eq
+Password = Xdmy@1234
+Host = 192.168.61.42:3306
+Name = eq
+#TablePrefix =
 
 
 #####现代牧业测试线
 #####现代牧业测试线
 #User = eq
 #User = eq

+ 8 - 8
cmd/conf/conf.toml

@@ -1,7 +1,7 @@
 [db]
 [db]
 #dsn = "root:root@tcp(127.0.0.1:3309)/test?charset=utf8&parseTime=True&loc=Local"
 #dsn = "root:root@tcp(127.0.0.1:3309)/test?charset=utf8&parseTime=True&loc=Local"
-dsn = "root:kepaiteng!QAZ@tcp(222.73.129.15:31306)/eq230508?charset=utf8&parseTime=True&loc=Local"
-#dsn = "eq:Xdmy@1234@tcp(192.168.61.42:3306)/eq?charset=utf8&parseTime=True&loc=Local"
+#dsn = "root:kepaiteng!QAZ@tcp(222.73.129.15:31306)/eq230508?charset=utf8&parseTime=True&loc=Local"
+dsn = "eq:Xdmy@1234@tcp(192.168.61.42:3306)/eq?charset=utf8&parseTime=True&loc=Local"
 #dsn = "eq:Xdmy@1234@tcp(192.168.63.42:3306)/eq?charset=utf8&parseTime=True&loc=Local"
 #dsn = "eq:Xdmy@1234@tcp(192.168.63.42:3306)/eq?charset=utf8&parseTime=True&loc=Local"
 #dsn = "root:root@tcp(192.168.1.93:3326)/eqdev?charset=utf8&parseTime=True&loc=Local"
 #dsn = "root:root@tcp(192.168.1.93:3326)/eqdev?charset=utf8&parseTime=True&loc=Local"
 
 
@@ -10,18 +10,18 @@ idle_timeout = 3600
 [http]
 [http]
 timeout =600
 timeout =600
 ###sap测试线密码
 ###sap测试线密码
-sapname ="zinf_sheb"
-sappwd ="zinf_sheb@1234"
+#sapname ="zinf_sheb"
+#sappwd ="zinf_sheb@1234"
 
 
 ###sap正式线密码
 ###sap正式线密码
-#sapname ="zinf_sheb"
-#sappwd ="n4mJj^BVMs"
+sapname ="zinf_sheb"
+sappwd ="n4mJj^BVMs"
 #srmname= "PEC"
 #srmname= "PEC"
 #srmpwd = "3FxnFswa0hYb8y4nh6dzTtAS4kQYh0xP"
 #srmpwd = "3FxnFswa0hYb8y4nh6dzTtAS4kQYh0xP"
 ###正式线
 ###正式线
-#routing = "http://192.168.61.117/SAPP0"
+routing = "http://192.168.61.117/SAPP0"
 ##Q系统
 ##Q系统
-routing = "http://192.168.61.117/SAPQ0"
+#routing = "http://192.168.61.117/SAPQ0"
 
 
 
 
 
 

BIN
cmd/dist(2).zip → cmd/dist(3).zip


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/datas/myMap.json


BIN
cmd/dist(3)/dist/favicon.ico


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/index.html


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/css/app.646e8e6c.css


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/css/chunk-elementUI.45ab9bc1.css


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/css/chunk-libs.2e418612.css


BIN
cmd/dist(3)/dist/static/fonts/element-icons.535877f5.woff


BIN
cmd/dist(3)/dist/static/fonts/element-icons.732389de.ttf


BIN
cmd/dist(3)/dist/static/img/1.1ddf085a.png


BIN
cmd/dist(3)/dist/static/img/404.a57b6f31.png


BIN
cmd/dist(3)/dist/static/img/404_cloud.0f4bc32b.png


BIN
cmd/dist(3)/dist/static/img/cow.3495de2a.jpg


BIN
cmd/dist(3)/dist/static/img/login-bg.dfe7c90f.jpg


BIN
cmd/dist(3)/dist/static/img/login-bg1.1f1602f0.jpg


BIN
cmd/dist(3)/dist/static/img/login-bujian.8695940d.png


BIN
cmd/dist(3)/dist/static/img/logo.4a74cb8a.png


BIN
cmd/dist(3)/dist/static/img/logo1.d2343c0f.png


BIN
cmd/dist(3)/dist/static/img/logo_u3.34a9ffae.png


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/js/app.772b0456.js


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/js/chunk-39889fb2.0f71ae7a.js


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/js/chunk-581b2547.c1efae40.js


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/js/chunk-d17f893e.56c4d12d.js


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/js/chunk-elementUI.1e8908f6.js


File diff suppressed because it is too large
+ 0 - 0
cmd/dist(3)/dist/static/js/chunk-libs.f5a7c3c5.js


BIN
cmd/dist-tmr-23-10-23.zip


File diff suppressed because it is too large
+ 0 - 0
cmd/dist/index.html


File diff suppressed because it is too large
+ 0 - 0
cmd/dist/static/css/app.61f02e07.css


File diff suppressed because it is too large
+ 0 - 0
cmd/dist/static/css/app.646e8e6c.css


File diff suppressed because it is too large
+ 0 - 0
cmd/dist/static/js/app.772b0456.js


File diff suppressed because it is too large
+ 0 - 0
cmd/dist/static/js/app.b57d8ddf.js


BIN
cmd/sh/eqserver


BIN
cmd/sh/main


+ 1 - 0
go.mod

@@ -31,6 +31,7 @@ require (
 	github.com/gin-gonic/gin v1.9.0
 	github.com/gin-gonic/gin v1.9.0
 	github.com/go-ini/ini v1.66.6
 	github.com/go-ini/ini v1.66.6
 	github.com/go-sql-driver/mysql v1.7.0
 	github.com/go-sql-driver/mysql v1.7.0
+	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4
 	github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4
 	github.com/jmoiron/sqlx v1.3.5
 	github.com/jmoiron/sqlx v1.3.5
 	github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
 	github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible

+ 5 - 0
pkg/util/util.go

@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"bytes"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
+	"math"
 	"time"
 	"time"
 
 
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
@@ -132,3 +133,7 @@ func NewMap(name string, value interface{}) map[string]interface{} {
 		name: value,
 		name: value,
 	}
 	}
 }
 }
+
+func Round(number float64, size int) float64 {
+	return math.Round(number*100) / 100
+}

+ 11 - 5
pkg/util/wxwork.go

@@ -227,6 +227,7 @@ func SendRun() {
 				}
 				}
 			*/
 			*/
 			///*
 			///*
+
 			if value["dingdingCode"] == "" {
 			if value["dingdingCode"] == "" {
 				//restful.MapStr(` select`)
 				//restful.MapStr(` select`)
 
 
@@ -266,6 +267,11 @@ func SendRun() {
 				fmt.Println(err)
 				fmt.Println(err)
 				continue
 				continue
 			}
 			}
+			fmt.Println(dingTalkSendReqByte)
+			_, err = restful.Dbs.Exec(` update wxworkmsg set statue = 1 ,pushTime = now() where id =  ? `, value["wxworkmsgId"])
+			if err != nil {
+				fmt.Println(err)
+			}
 			fmt.Println(string(sendResp))
 			fmt.Println(string(sendResp))
 			//*/
 			//*/
 		}
 		}
@@ -319,17 +325,17 @@ func GetMsg() {
 		return
 		return
 	}
 	}
 	sqlmsg := sqls[0]["sqlstr"]
 	sqlmsg := sqls[0]["sqlstr"]
-	sqlupdate := sqls[1]["sqlstr"]
+	//sqlupdate := sqls[1]["sqlstr"]
 	var query []map[string]string
 	var query []map[string]string
 	if len(sqls) > 0 {
 	if len(sqls) > 0 {
 		query, err = restful.MapStrListTx(tx, sqlmsg)
 		query, err = restful.MapStrListTx(tx, sqlmsg)
 		if err != nil {
 		if err != nil {
 			logging.Error("select from wxworkmsg err ", err.Error(), len(query))
 			logging.Error("select from wxworkmsg err ", err.Error(), len(query))
 		} else {
 		} else {
-			_, err = tx.Exec(sqlupdate)
-			if err != nil {
-				logging.Error("update wxworkmsg err ", err.Error(), len(query))
-			}
+			//_, err = tx.Exec(sqlupdate)
+			//if err != nil {
+			//	logging.Error("update wxworkmsg err ", err.Error(), len(query))
+			//}
 		}
 		}
 	}
 	}
 
 

+ 73 - 3
sap.sql

@@ -1,3 +1,73 @@
-ALTER TABLE `eq230508`.`bigpartpurchase`
-    ADD COLUMN `financeId` int NULL COMMENT '财务审核id' AFTER `funder_id`,
-ADD COLUMN `financedate` datetime NULL COMMENT '财务审核时间' AFTER `financeId`
+ALTER TABLE `pasture`
+    ADD COLUMN `empId` int NULL COMMENT '供应负责人';
+
+
+ALTER TABLE `diesel`
+    ADD COLUMN `sort` int(11) DEFAULT NULL;
+
+ALTER TABLE `diesel`
+    ADD COLUMN `oilType` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '柴油类型 0: 空 1: 0# 2: -10# 3: -20# 4: -30# 5: -35#';
+ALTER TABLE `diesel`
+    ADD COLUMN `oilName` varchar(255) NOT NULL DEFAULT '' COMMENT '柴油类型名称';
+ALTER TABLE `diesel`
+    ADD COLUMN`dieselCode` varchar(50) DEFAULT NULL;
+
+
+ALTER TABLE `diesel`
+    ADD COLUMN
+        `ProofCode` varchar(50) DEFAULT NULL;
+
+
+CREATE TABLE `diesel_off` (
+                              `id` int(11) NOT NULL,
+                              `pastureId` int(11) NOT NULL COMMENT '牧场ID',
+                              `deptId` int(11) DEFAULT NULL,
+                              `eqId` int(11) DEFAULT NULL COMMENT '备件编号',
+                              `eqCode` varchar(100) DEFAULT NULL,
+                              `oilcardId` int(11) DEFAULT NULL,
+                              `cardNumber` varchar(200) NOT NULL COMMENT '卡号',
+                              `oilClass` varchar(100) DEFAULT NULL COMMENT '加油工班',
+                              `oilAmount` decimal(20,2) DEFAULT NULL COMMENT '油量',
+                              `nowPrice` decimal(10,2) DEFAULT NULL COMMENT '本次金额',
+                              `price` decimal(10,2) DEFAULT NULL COMMENT '单价',
+                              `empId` varchar(100) DEFAULT NULL COMMENT '上班加油工',
+                              `inputId` int(11) DEFAULT NULL COMMENT '录入人',
+                              `selTime` varchar(100) DEFAULT NULL COMMENT '交易时间',
+                              `note` varchar(255) DEFAULT NULL COMMENT '备注',
+                              `ProofCode` varchar(50) DEFAULT NULL,
+                              `oilType` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '柴油类型 0: 空 1: 0# 2: -10# 3: -20# 4: -30# 5: -35#',
+                              `oilName` varchar(255) NOT NULL DEFAULT '' COMMENT '柴油类型名称',
+                              `dieselCode` varchar(50) DEFAULT NULL,
+                              `sort` int(11) DEFAULT NULL,
+                              `createTime` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
+                              PRIMARY KEY (`id`) USING BTREE,
+                              KEY `selTime` (`selTime`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+
+
+
+
+
+-- 水费
+insert into feequery(pastureId,RBUKRS,WERKS,FYLX,GJAHR,POPER,HSL,Date)
+select pastureId,p.company_code,p.factory_code,"水费", date_format(date ,'%Y'),date_format(date ,'%m'),    sum(sumPrice) sumPrice, date_format(date ,'%Y-%m') from water  join pasture p on p.id = pastureId  where date_format(date ,'%Y') = '2022'
+group by pastureId,date_format(date ,'%Y-%m')
+
+
+
+
+-- 电费
+    insert into feequery(pastureId,RBUKRS,WERKS,FYLX,GJAHR,POPER,HSL,Date)
+select pastureId,p.company_code,p.factory_code,"电费", date_format(date ,'%Y'),date_format(date ,'%m'),    sum(sumPrice) sumPrice, date_format(date ,'%Y-%m') from electricity  join pasture p on p.id = pastureId  where date_format(date ,'%Y') = '2022'
+group by pastureId,date_format(date ,'%Y-%m')
+
+
+
+-- 燃动费
+    insert into feequery(pastureId,RBUKRS,WERKS,FYLX,GJAHR,POPER,HSL,Date)
+
+select pastureId,p.company_code,p.factory_code,"燃动费", date_format(selTime ,'%Y'),date_format(selTime ,'%m'),    sum(nowPrice) sumPrice, date_format(selTime ,'%Y-%m') from diesel  join pasture p on p.id = pastureId  where date_format(selTime ,'%Y') = '2022'
+group by pastureId,date_format(selTime ,'%Y-%m')
+

Some files were not shown because too many files changed in this diff