|
@@ -63,13 +63,14 @@ type Device_R struct {
|
|
|
// ---------产品信息-----------
|
|
|
T_product_id int
|
|
|
T_product_name string
|
|
|
+ T_product_class int
|
|
|
T_product_class_name string
|
|
|
T_product_model string
|
|
|
T_product_spec string
|
|
|
T_product_img string
|
|
|
}
|
|
|
|
|
|
-func DeviceToDevice_R(t Device) (r Device_R) {
|
|
|
+func DeviceToDevice_R(t Device_R) (r Device_R) {
|
|
|
r.Id = t.Id
|
|
|
r.T_contract_number = t.T_contract_number
|
|
|
r.T_product_id = t.T_product_id
|
|
@@ -83,13 +84,14 @@ func DeviceToDevice_R(t Device) (r Device_R) {
|
|
|
r.T_project = t.T_project
|
|
|
r.T_project_log = t.T_project_log
|
|
|
|
|
|
- r.T_product_id = t.T_product_id
|
|
|
- product, _ := Basic.Read_Product_ById(t.T_product_id)
|
|
|
- r.T_product_name = product.T_name
|
|
|
- r.T_product_class_name = Basic.Read_ProductClass_Get(product.T_class)
|
|
|
- r.T_product_model = product.T_model
|
|
|
- r.T_product_spec = product.T_spec
|
|
|
- r.T_product_img = product.T_img
|
|
|
+ r.T_product_name =t.T_product_name
|
|
|
+ r.T_product_class =t.T_product_class
|
|
|
+ r.T_product_model =t.T_product_model
|
|
|
+ r.T_product_spec =t.T_product_spec
|
|
|
+ r.T_product_img =t.T_product_img
|
|
|
+
|
|
|
+ r.T_product_class_name = Basic.Read_ProductClass_Get(t.T_product_class)
|
|
|
+
|
|
|
return r
|
|
|
}
|
|
|
|
|
@@ -213,49 +215,7 @@ func (dao *DeviceDaoImpl) Read_DeviceSn_List(T_contract_number string, T_product
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (dao *DeviceDaoImpl) Read_Device_List1(T_name string, T_State, page, page_z int) (r []Device_R, cnt int64) {
|
|
|
- qs := dao.orm.QueryTable(new(Device))
|
|
|
- var offset int64
|
|
|
- if page <= 1 {
|
|
|
- offset = 0
|
|
|
- } else {
|
|
|
- offset = int64((page - 1) * page_z)
|
|
|
- }
|
|
|
- // 过滤
|
|
|
- cond := orm.NewCondition()
|
|
|
- cond1 := cond.And("T_State__gt", 0)
|
|
|
- if len(T_name) > 0 {
|
|
|
- cond1 = cond1.AndCond(
|
|
|
- cond.Or("T_contract_number__icontains", T_name).
|
|
|
- Or("T_out_number__icontains", T_name).
|
|
|
- Or("T_sn__icontains", T_name).
|
|
|
- Or("T_iccid__icontains", T_name).
|
|
|
- Or("T_project__icontains", T_name))
|
|
|
- }
|
|
|
-
|
|
|
- if T_State > 0 {
|
|
|
- cond1 = cond1.And("T_State", T_State)
|
|
|
- }
|
|
|
-
|
|
|
- var maps []Device
|
|
|
- _, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).All(&maps)
|
|
|
- if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
- return
|
|
|
- }
|
|
|
- cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
- if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- for _, v := range maps {
|
|
|
- r = append(r, DeviceToDevice_R(v))
|
|
|
- }
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-func (dao *DeviceDaoImpl) Read_Device_List(T_name string, T_State, page, page_z int) (r []Device_R, cnt int64) {
|
|
|
+func (dao *DeviceDaoImpl) Read_Device_List(T_name, T_product_name, T_product_model string, T_State, page, page_z int) (r []Device_R, cnt int64) {
|
|
|
var offset int
|
|
|
if page <= 1 {
|
|
|
offset = 0
|
|
@@ -272,9 +232,15 @@ func (dao *DeviceDaoImpl) Read_Device_List(T_name string, T_State, page, page_z
|
|
|
if T_State > 0 {
|
|
|
sqlWhere += fmt.Sprintf(" AND d.t__state = %d", T_State)
|
|
|
}
|
|
|
+ if len(T_product_name) > 0 {
|
|
|
+ sqlWhere += " AND p.t_name like \"%" + T_product_name + "%\""
|
|
|
+ }
|
|
|
+ if len(T_product_model) > 0 {
|
|
|
+ sqlWhere += " AND p.t_model like \"%" + T_product_model + "%\""
|
|
|
+ }
|
|
|
var maps_z []orm2.ParamsList
|
|
|
// 获取总条数
|
|
|
- sql := "SELECT COUNT(*) FROM device d JOIN (SELECT t_sn, MAX(create_time) AS max_create_time FROM device GROUP BY t_sn) latest " +
|
|
|
+ sql := "SELECT COUNT(*) FROM device d JOIN product p ON d.t_product_id = p.ID JOIN (SELECT t_sn, MAX(create_time) AS max_create_time FROM device GROUP BY t_sn) latest " +
|
|
|
"ON d.t_sn = latest.t_sn AND d.create_time = latest.max_create_time"
|
|
|
sql = sql + sqlWhere
|
|
|
fmt.Println(sql)
|
|
@@ -285,7 +251,8 @@ func (dao *DeviceDaoImpl) Read_Device_List(T_name string, T_State, page, page_z
|
|
|
if len(maps_z) == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
- sql = "SELECT * FROM device d JOIN (SELECT t_sn, MAX(create_time) AS max_create_time FROM device GROUP BY t_sn) latest " +
|
|
|
+ sql = "SELECT *,p.t_name AS t_product_name,p.t_model AS t_product_model,p.t_class AS t_product_class,p.t_spec AS t_product_spec " +
|
|
|
+ "FROM device d JOIN product p ON d.t_product_id = p.ID JOIN (SELECT t_sn, MAX(create_time) AS max_create_time FROM device GROUP BY t_sn) latest " +
|
|
|
"ON d.t_sn = latest.t_sn AND d.create_time = latest.max_create_time"
|
|
|
|
|
|
sql = sql + sqlWhere
|
|
@@ -295,7 +262,7 @@ func (dao *DeviceDaoImpl) Read_Device_List(T_name string, T_State, page, page_z
|
|
|
sql += " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
|
|
|
fmt.Println(sql)
|
|
|
- var maps []Device
|
|
|
+ var maps []Device_R
|
|
|
_, err = dao.orm.Raw(sql).QueryRows(&maps)
|
|
|
if err != nil {
|
|
|
return r, 0
|