baishaojie %!s(int64=2) %!d(string=hai) anos
pai
achega
dfc2b5631f

+ 5 - 5
apiserver/model/iot/iot_number.go

@@ -6,9 +6,9 @@ const (
 )
 
 type WaterElectricityRequest struct {
-	IotNumber string  `json:"iot_number"` // iot 编号
-	DataType  uint32  `json:"data_type"`  // 数据类型 1 水 2 电
-	EndAmount uint64  `json:"end_amount"` // 用量
-	Price     float64 `json:"price"`      // 单价
-	PastureId int64   `json:"pasture_id"` // 牧场id
+	IotNumber string `json:"iot_number"` // iot 编号
+	DataType  uint32 `json:"data_type"`  // 数据类型 1 水 2 电
+	EndAmount uint64 `json:"end_amount"` // 用量
+	Date      string `json:"date"`       // 时间
+	PastureId int64  `json:"pasture_id"` // 牧场id
 }

+ 28 - 28
apiserver/model/measure.go

@@ -1,34 +1,34 @@
 package model
 
 type Measure struct {
-	Id             int64   `json:"id" gorm:"id"`
-	PId            int     `json:"pId" gorm:"pId"`
-	MeterCode      string  `json:"meterCode" gorm:"meterCode"`
-	MeterName      string  `json:"meterName" gorm:"meterName"`
-	MeterType      string  `json:"meterType" gorm:"meterType"`
-	UseTypeId      int64   `json:"useTypeId" gorm:"useTypeId"`
-	PastureId      int64   `json:"pastureId" gorm:"pastureId"`
-	DepartmentId   string  `json:"departmentId" gorm:"departmentId"`
-	DepartmentName string  `json:"departmentName" gorm:"departmentName"`
-	EmployeId      int64   `json:"employeId" gorm:"employeId"`
-	StartAmount    string  `json:"startAmount" gorm:"startAmount"`
-	Location       string  `json:"location" gorm:"location"`
-	Price          float64 `json:"price" gorm:"price"`
-	Rate           int64   `json:"rate" gorm:"rate"`
-	MaxAmount      int64   `json:"MaxAmount" gorm:"MaxAmount"`
-	IsInfo         int32   `json:"isInfo" gorm:"isInfo"`
-	Enable         int32   `json:"enable" gorm:"enable"`
-	UseType        string  `json:"useType" gorm:"useType"`
-	MeterNumber    string  `json:"meterNumber" gorm:"meterNumber"`
-	IsDel          int64   `json:"isDel" gorm:"isDel"`
-	LastAmount     string  `json:"lastAmount" gorm:"lastAmount"`
-	LastDate       string  `json:"lastDate" gorm:"lastDate"`
-	LastRecodeId   int64   `json:"lastRecodeId" gorm:"lastRecodeId"`
-	EndAmount      string  `json:"endAmount" gorm:"endAmount"`
-	EndDate        string  `json:"endDate" gorm:"endDate"`
-	Multiple       string  `json:"Multiple" gorm:"Multiple"`
-	EmpName        string  `json:"empName" gorm:"empName"`
-	DeleteTime     string  `json:"deleteTime" gorm:"deleteTime"`
+	Id             int64   `json:"id" gorm:"column:id"`
+	PId            int     `json:"pId" gorm:"column:pId"`
+	MeterCode      string  `json:"meterCode" gorm:"column:meterCode"`
+	MeterName      string  `json:"meterName" gorm:"column:meterName"`
+	MeterType      string  `json:"meterType" gorm:"column:meterType"`
+	UseTypeId      int64   `json:"useTypeId" gorm:"column:useTypeId"`
+	PastureId      int64   `json:"pastureId" gorm:"column:pastureId"`
+	DepartmentId   string  `json:"departmentId" gorm:"column:departmentId"`
+	DepartmentName string  `json:"departmentName" gorm:"column:departmentName"`
+	EmployeId      int64   `json:"employeId" gorm:"column:employeId"`
+	StartAmount    string  `json:"startAmount" gorm:"column:startAmount"`
+	Location       string  `json:"location" gorm:"column:location"`
+	Price          float64 `json:"price" gorm:"column:price"`
+	Rate           int64   `json:"rate" gorm:"column:rate"`
+	MaxAmount      int64   `json:"MaxAmount" gorm:"column:MaxAmount"`
+	IsInfo         int32   `json:"isInfo" gorm:"column:isInfo"`
+	Enable         int32   `json:"enable" gorm:"column:enable"`
+	UseType        string  `json:"useType" gorm:"column:useType"`
+	MeterNumber    string  `json:"meterNumber" gorm:"column:meterNumber"`
+	IsDel          int64   `json:"isDel" gorm:"column:isDel"`
+	LastAmount     string  `json:"lastAmount" gorm:"column:lastAmount"`
+	LastDate       string  `json:"lastDate" gorm:"column:lastDate"`
+	LastRecodeId   int64   `json:"lastRecodeId" gorm:"column:lastRecodeId"`
+	EndAmount      string  `json:"endAmount" gorm:"column:endAmount"`
+	EndDate        string  `json:"endDate" gorm:"column:endDate"`
+	Multiple       string  `json:"Multiple" gorm:"column:Multiple"`
+	EmpName        string  `json:"empName" gorm:"column:empName"`
+	DeleteTime     string  `json:"deleteTime" gorm:"column:deleteTime"`
 }
 
 func (m *Measure) TableName() string {

+ 6 - 8
apiserver/service/water_electricity.go

@@ -3,8 +3,6 @@ package service
 import (
 	"context"
 	"errors"
-	"time"
-
 	"gorm.io/gorm"
 
 	"kpt.xdmy/apiserver/model"
@@ -30,11 +28,11 @@ func WaterOrElectricity(ctx context.Context, req *iot.WaterElectricityRequest) e
 			ElecName:        measure.MeterName,
 			EndAmount:       "",
 			ElecConsumption: float64(req.EndAmount),
-			Price:           req.Price,
-			SumPrice:        req.Price * float64(req.EndAmount),
+			Price:           measure.Price,
+			SumPrice:        measure.Price * float64(req.EndAmount),
 			LastAmount:      "",
 			EmployeId:       measure.EmployeId,
-			Date:            time.Now().AddDate(0, 0, -1).Format("2006-01-02"),
+			Date:            req.Date,
 			Note:            "",
 		}
 	}
@@ -47,11 +45,11 @@ func WaterOrElectricity(ctx context.Context, req *iot.WaterElectricityRequest) e
 			WaterName:        measure.MeterName,
 			EndAmount:        "",
 			WaterConsumption: float64(req.EndAmount),
-			Price:            req.Price,
-			SumPrice:         req.Price * float64(req.EndAmount),
+			Price:            measure.Price,
+			SumPrice:         measure.Price * float64(req.EndAmount),
 			LastAmount:       "",
 			EmployeId:        measure.EmployeId,
-			Date:             time.Now().AddDate(0, 0, -1).Format("2006-01-02"),
+			Date:             req.Date,
 			Note:             "",
 		}
 	}

+ 81 - 1
migration/v0002_alter_measure.sql

@@ -1,9 +1,89 @@
+<<<<<<< HEAD
+=======
+## set 1
+>>>>>>> d1edcd799ab9a80c72b438bddf134aeaec36a99b
 ALTER TABLE `measure`
     ADD COLUMN `iotNumber` varchar(255) NOT NULL DEFAULT '' COMMENT 'IOT 编号' AFTER `pId`;
 
 
+<<<<<<< HEAD
 ## apisql表查询语句
 SELECT sqlstr,params FROM `apisql` WHERE sqlname = 'insertMeasure' AND ENABLE>0
 ## 需要更改的内容如下
 ## insert into measure (departmentId,departmentName, location,  startAmount,lastAmount,endAmount, meterName, meterType,useType, price, employeId, pastureId,meterNumber ,lastDate,endDate,Multiple,iotNumber) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
-## departmentId,departmentName,location,startAmount,startAmount,startAmount,formName,formType,useType,price,employeId, pastureId,formNumber,inputDatetime,inputDatetime,Multiple,iotNumber
+## departmentId,departmentName,location,startAmount,startAmount,startAmount,formName,formType,useType,price,employeId, pastureId,formNumber,inputDatetime,inputDatetime,Multiple,iotNumber
+=======
+## set 2 apisql表查询语句 SELECT sqlstr,params FROM `apisql` WHERE sqlname = 'insertMeasure' AND ENABLE>0;
+## sqlstr 需要更改的内容如下
+insert into measure (departmentId,departmentName, location,  startAmount,lastAmount,endAmount, meterName, meterType,useType, price, employeId, pastureId,meterNumber ,lastDate,endDate,Multiple,iotNumber) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+## set 3 params 更新内容
+## departmentId,departmentName,location,startAmount,startAmount,startAmount,formName,formType,useType,price,employeId, pastureId,formNumber,inputDatetime,inputDatetime,Multiple,iotNumber
+
+## set 4 sqlstr 更新的语句 SELECT sqlstr,params FROM `apisql` WHERE sqlname = 'getMeasureList' AND ENABLE>0;
+SELECT
+(@i := @i + 1) i,
+  a.id,
+  a.meterName AS formName,
+  a.meterType AS formType,
+  a.useType,
+  a.location,
+  a.price,
+  a.meterNumber AS formNumber,
+  p.name pastureName,
+  d.name departName,
+  e.empname employeName,
+  a.isInfo,
+  a.`Multiple`,
+  a.`departmentId`,
+  a.`pastureId`,
+  a.`employeId`,
+  a.endAmount,
+  a.iotNumber,
+DATE_FORMAT(a.endDate, '%Y-%m-%d') endDate
+FROM
+  (SELECT
+    @i := 0) AS i,
+  measure a
+  LEFT JOIN department p
+    ON a.pastureId = p.id
+  LEFT JOIN department d
+    ON a.departmentId = d.id
+  LEFT JOIN emp e
+    ON a.employeId = e.id
+WHERE (
+    d.name LIKE CONCAT("%", ?, "%")
+    OR ? = ''
+  )
+  AND (
+    a.meterNumber LIKE CONCAT("%", ?, "%")
+    OR ? = ''
+  )
+  AND (
+    p.name LIKE CONCAT("%", ?, "%")
+    OR ? = '现代牧业'
+  )
+ AND (
+    a.meterType =  ?
+    OR ? = ''
+  )
+ AND (
+    a.useType=  ?
+    OR ? = ''
+  )
+AND (
+    a.meterName LIKE CONCAT("%", ?, "%")
+    OR ? = ''
+  )
+  AND a.isDel = '0'
+ORDER BY p.sort asc,a.meterType desc,a.meterNumber
+
+
+## set 5  sqlstr 更新的语句 SELECT sqlstr,params FROM `apisql` WHERE sqlname = 'updateMeasure' AND ENABLE>0;
+update measure set meterCode = ?,meterNumber=?,departmentId = ?, location = ?, startAmount = ?, meterName = ?,meterType =?, price = ?,employeId = ?,pastureId =?,isInfo= ?,Multiple=?,iotNumber=? where id = ?
+## set 6 params
+## formNumber,formNumber,departmentId, location,  startAmount, formName, formType, price, employeId, pastureId,isInfo,Multiple,iotNumber,id
+
+## set 6 sqlstr SELECT sqlstr,params FROM `apisql` WHERE sqlname = 'importMeasureNew' AND ENABLE>0;
+## call insert_measurenew(?,?,?,?,?,?,?,?,?,?,?,?,?)
+## 牧场,表名称,表编号,表结构,表类型,部门,位置,最后一次抄表值,单价,管理人,倍率,iot编号,jwt_username
+>>>>>>> d1edcd799ab9a80c72b438bddf134aeaec36a99b