Browse Source

add:添加产品列表排序

zoie 5 months ago
parent
commit
913e2b4f28
6 changed files with 57 additions and 57 deletions
  1. 26 0
      controllers/Basic.go
  2. 3 1
      controllers/Stock.go
  3. 1 1
      dto/Stock.go
  4. 4 1
      models/Basic/Product.go
  5. 21 54
      models/Stock/Device.go
  6. 2 0
      routers/Basic.go

+ 26 - 0
controllers/Basic.go

@@ -438,6 +438,32 @@ func (c *BasicController) Product_Del() {
 	return
 }
 
+// 修改产品排序
+func (c *BasicController) Product_Edit_Sort() {
+
+	T_id, _ := c.GetInt("T_id")
+	T_sort, _ := c.GetInt("T_sort")
+	Product_r, err := Basic.Read_Product_ById(T_id)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+		c.ServeJSON()
+		return
+	}
+	Product_r.T_sort = T_sort
+	if err = Basic.Update_Product(Product_r, "T_sort"); err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
+		c.ServeJSON()
+		return
+	}
+
+
+	NatsServer.AddUserLogs(c.User.T_uuid, "产品", "修改排序", Product_r)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+}
+
 // 验证项目
 func (c *BasicController) VerifyItem_List() {
 

+ 3 - 1
controllers/Stock.go

@@ -49,9 +49,11 @@ func (c *StockController) Device_List() {
 
 	T_state, _ := c.GetInt("T_state")
 	T_name := c.GetString("T_name")
+	T_product_name := c.GetString("T_product_name")   // 产品名称
+	T_product_model := c.GetString("T_product_model") // 产品型号
 
 	DeviceDao := Stock.NewDevice(orm.NewOrm())
-	R_List, R_cnt := DeviceDao.Read_Device_List(T_name, T_state, page, page_z)
+	R_List, R_cnt := DeviceDao.Read_Device_List(T_name, T_product_name, T_product_model, T_state, page, page_z)
 
 	var r_jsons lib.R_JSONS
 	r_jsons.Num = R_cnt

+ 1 - 1
dto/Stock.go

@@ -25,7 +25,7 @@ func StockProductListsEqual(a, b []StockProduct) (isEqual bool, needDelete, need
 	needAdd = make(map[int]StockProduct)
 	needEdit = make(map[int]StockProduct)
 	snDiff = make(map[int]StockProductRelationSn)
-	isEqual = true
+	isEqual = false
 	// 原始数据
 	aMap := make(map[int]StockProduct)
 	aProductList := []int{}

+ 4 - 1
models/Basic/Product.go

@@ -28,6 +28,7 @@ type Product struct {
 	T_State       int       `orm:"size(2);default(1)"`                                    // 0 删除(伪删除)   1 正常
 	T_remark      string    `orm:"type(text);null"`                                       // 备注
 	T_price       float32   `orm:"digits(12);decimals(2)"`                                // 单价
+	T_sort        int       `orm:"size(20);default(0)"`                                         // 排序
 	CreateTime    time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	UpdateTime    time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
 }
@@ -106,6 +107,7 @@ type Product_R struct {
 	T_relation_sn int     // 关联sn 0-否 1-是
 	T_img         string  // 图片
 	T_remark      string  // 备注
+	T_sort        int     // 排序
 }
 
 func ProductToProduct_R(t Product) (r Product_R) {
@@ -120,6 +122,7 @@ func ProductToProduct_R(t Product) (r Product_R) {
 	r.T_relation_sn = t.T_relation_sn
 	r.T_img = t.T_img
 	r.T_remark = t.T_remark
+	r.T_sort = t.T_sort
 	return r
 }
 
@@ -223,7 +226,7 @@ func Read_Product_List(T_name, T_model string, T_class, T_VerifyContract, page,
 
 	// 查询
 	var r []Product
-	_, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_class", "-Id").All(&r)
+	_, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort").All(&r)
 
 	if err != nil {
 		logs.Error(lib.FuncName(), err)

+ 21 - 54
models/Stock/Device.go

@@ -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

+ 2 - 0
routers/Basic.go

@@ -17,6 +17,8 @@ func init() {
 	product := beego.NewNamespace("/Product",
 		beego.NSRouter("/List", &controllers.BasicController{}, "*:Product_List"), // 产品列表
 		beego.NSRouter("/Add", &controllers.BasicController{}, "*:Product_Add"),   // 添加产品
+		beego.NSRouter("/Edit_Sort", &controllers.BasicController{}, "*:Product_Edit_Sort"),       // 修改排序
+
 		beego.NSRouter("/Edit", &controllers.BasicController{}, "*:Product_Edit"), // 编辑产品
 		beego.NSRouter("/Del", &controllers.BasicController{}, "*:Product_Del"),   // 删除产品