Explorar o código

Merge branch 'feature/tmr-group' of baishaojie/tmrgo into develop

xuyiping hai 1 ano
pai
achega
a130251235
Modificáronse 5 ficheiros con 23 adicións e 17 borrados
  1. 1 1
      go.mod
  2. 2 0
      go.sum
  3. 2 2
      migration/v0001_feedtemplet.sql
  4. 2 1
      models/feed_template.go
  5. 16 13
      module/group.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module tmr-watch
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20230823061528-20b02d357f02
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20231018071345-6ac61c4e4fd2
 	gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584
 	github.com/360EntSecGroup-Skylar/excelize v1.4.1
 	github.com/Anderson-Lu/gofasion v0.0.0-20190530065914-6a05b679ee48

+ 2 - 0
go.sum

@@ -7,6 +7,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8 h1:p6Y97HJ0
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230823061528-20b02d357f02 h1:e4BzweXQdP/RdWBeqk1sshUuxBI/jcLUCNDtv/G1mXg=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230823061528-20b02d357f02/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20231018071345-6ac61c4e4fd2 h1:wwzYo7WbLblOUmQr+1CsNtJ88+nydCiHTa3qlAYORWQ=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20231018071345-6ac61c4e4fd2/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584 h1:5RE5yrMMvnDITrnoX821mFl7dNYfsFA1osDobUV/TDo=
 gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584/go.mod h1:VQ7WztVDQRlXE1dUu/Yqo3ZdhKsfv7IGJtV+vqNqJVw=
 github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=

+ 2 - 2
migration/v0001_feedtemplet.sql

@@ -244,7 +244,7 @@ CREATE TABLE `feed_detail_version_log` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键自增id',
    `pasture_id` bigint(20) unsigned NOT NULL COMMENT '牧场id',
    `version_id` int(11) unsigned NOT NULL COMMENT 'feed_detail_version表id',
-   `feed_formula_id` int(11) unsigned NOT NULL COMMENT '配方id',
+   `feed_template_id` bigint(20) unsigned NOT NULL COMMENT '配方id',
    `forage_id` int(11) unsigned NOT NULL COMMENT '饲料id',
    `forage_name` varchar(255) NOT NULL DEFAULT '' COMMENT '饲料名称',
    `forage_group_name` varchar(155) NOT NULL DEFAULT '' COMMENT '饲料分组名称',
@@ -258,5 +258,5 @@ CREATE TABLE `feed_detail_version_log` (
    `created` datetime NOT NULL COMMENT '创建时间',
    `updated` datetime NOT NULL COMMENT '更新时间',
    PRIMARY KEY (`id`),
-   KEY `idx_feed_formula_id` (`feed_formula_id`)
+   KEY `idx_feed_template_id` (`feed_template_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集团端最新配方详情表'

+ 2 - 1
models/feed_template.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"time"
 
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
@@ -109,7 +110,7 @@ func (f FeedTemplateSlice) ToPB(feedDetailVersionLogs []*FeedDetailVersion) []*p
 		}
 
 		res[i] = &pasturePb.FeedTemplateDataList{
-			Id:                 int32(v.Id),
+			Id:                 fmt.Sprintf("%d", v.Id),
 			Name:               v.TName,
 			Code:               v.TCode,
 			Color:              v.TColor,

+ 16 - 13
module/group.go

@@ -550,41 +550,44 @@ func NewSearchFeedTemplateList(ctx context.Context, req *pasturePb.SearchFeedTem
 
 	res := make([]*models.FeedTemplate, 0)
 
+	if req.PastureId > 0 {
+		DBSession.And("pastureid = ?", req.PastureId)
+	}
+
 	if req.Name != "" {
-		DBSession.Where("name like ?", "%"+req.Name+"%")
+		DBSession.And("tname like ?", "%"+req.Name+"%")
 	}
 
 	if req.CattleCategoryId > 0 {
-		DBSession.Where("ccid = ?", req.CattleCategoryId)
+		DBSession.And("ccid = ?", req.CattleCategoryId)
 	}
 
 	if req.FormulaTypeId > 0 {
-		DBSession.Where("fttypeid = ?", req.FormulaTypeId)
+		DBSession.And("fttypeid = ?", req.FormulaTypeId)
 	}
 
 	switch req.SourceId {
 	case 0:
-		DBSession.Where("source = '自定义'")
+		DBSession.And("source = '自定义'")
 	case 1:
-		DBSession.Where("source = '集团下发未调整'")
+		DBSession.And("source = '集团下发未调整'")
 	case 2:
-		DBSession.Where("source = '集团下发有调整'")
+		DBSession.And("source = '集团下发有调整'")
 	case 3:
-		DBSession.Where("source = '导入'")
+		DBSession.And("source = '导入'")
 	}
 
 	if req.Enable > 0 {
-		DBSession.Where("enable = ?", req.Enable)
+		DBSession.And("enable = ?", req.Enable)
 	}
 	if req.Remark != "" {
-		DBSession.Where("remark = ?", req.Remark)
+		DBSession.And("remark = ?", req.Remark)
 	}
 
-	DBSession.Desc("id")
-	if total, err := DBSession.Count(&res); err != nil {
+	if err := DBSession.Desc("id").Find(&res); err != nil {
 		return nil, 0, err
 	} else {
-		return res, total, nil
+		return res, int64(len(res)), nil
 	}
 }
 
@@ -622,7 +625,7 @@ func GetFeedDetailVersionByDesc(ctx context.Context, pastureId, feedTemplateId i
 func SearchFeedDetailVersionLogById(ctx context.Context, pastureId, feedTemplateId, versionId int64) ([]*models.FeedDetailVersionLog, error) {
 	res := make([]*models.FeedDetailVersionLog, 0)
 	if err := restful.Engine.NewSession().Table(new(models.FeedDetailVersionLog).TableName()).Where("pasture_id = ?", pastureId).
-		And("feed_formula_id = ?", feedTemplateId).And("version = ?", versionId).Find(&res); err != nil {
+		And("feed_template_id = ?", feedTemplateId).And("version_id = ?", versionId).Find(&res); err != nil {
 		return nil, err
 	}
 	return res, nil