1.create id列未赋值最新的id
检查id字段是否贴有 `gorm:"column:draftsId;primary_key;type:int(11);not null"`
2.create 测试环境能带出id值,预发环境Create 一直返回0
测试环境db表格带有主键,预发环境db表格未建主键自增
3.使用动态构建查询
//conditionGetList 动态构建查询条件 func conditionGetList(tableName string, info *model.TClientZybDrafts) *gorm.DB { query := dao.InnerDao.Gorm.Table(tableName) if info.ClientID > 0 { query = query.Where("clientId = ?", info.ClientID) } if info.AcademicYear > 0 { query = query.Where("academicYear = ?", info.AcademicYear) } if info.Wenli > 0 { query = query.Where("wenli = ?", info.Wenli) } if info.DiplomaID > 0 { query = query.Where("diplomaId = ?", info.DiplomaID) } if info.Batch > 0 { query = query.Where("batch = ?", info.Batch) } if info.EnrollStage > 0 { query = query.Where("enrollStage = ?", info.EnrollStage) } if info.EnrollMode > 0 { query = query.Where("enrollMode = ?", info.EnrollMode) } if info.EnrollCategory > 0 { query = query.Where("enrollCategory = ?", info.EnrollCategory) } if info.BatchEx > 0 { query = query.Where("batchEx = ?", info.BatchEx) } return query } //使用 sqlErr := conditionGetList(TableClientZybDrafts(orgId), info).Order(" draftsId Desc").Find(&m).Error