This commit is contained in:
mlogclub
2026-04-09 10:01:23 +08:00
commit efe801b8bf
707 changed files with 110595 additions and 0 deletions
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AgentProfileRepository = newAgentProfileRepository()
func newAgentProfileRepository() *agentProfileRepository {
return &agentProfileRepository{}
}
type agentProfileRepository struct {
}
func (r *agentProfileRepository) Get(db *gorm.DB, id int64) *models.AgentProfile {
ret := &models.AgentProfile{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *agentProfileRepository) Take(db *gorm.DB, where ...interface{}) *models.AgentProfile {
ret := &models.AgentProfile{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *agentProfileRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentProfile) {
cnd.Find(db, &list)
return
}
func (r *agentProfileRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.AgentProfile {
ret := &models.AgentProfile{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *agentProfileRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AgentProfile, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *agentProfileRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentProfile, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.AgentProfile{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *agentProfileRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.AgentProfile) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *agentProfileRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *agentProfileRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.AgentProfile{})
}
func (r *agentProfileRepository) Create(db *gorm.DB, t *models.AgentProfile) (err error) {
err = db.Create(t).Error
return
}
func (r *agentProfileRepository) Update(db *gorm.DB, t *models.AgentProfile) (err error) {
err = db.Save(t).Error
return
}
func (r *agentProfileRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.AgentProfile{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *agentProfileRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.AgentProfile{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *agentProfileRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.AgentProfile{}, "id = ?", id)
}
@@ -0,0 +1,90 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AgentRunLogRepository = newAgentRunLogRepository()
func newAgentRunLogRepository() *agentRunLogRepository {
return &agentRunLogRepository{}
}
type agentRunLogRepository struct{}
func (r *agentRunLogRepository) Get(db *gorm.DB, id int64) *models.AgentRunLog {
ret := &models.AgentRunLog{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *agentRunLogRepository) Take(db *gorm.DB, where ...interface{}) *models.AgentRunLog {
ret := &models.AgentRunLog{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *agentRunLogRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentRunLog) {
cnd.Find(db, &list)
return
}
func (r *agentRunLogRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.AgentRunLog {
ret := &models.AgentRunLog{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *agentRunLogRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AgentRunLog, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *agentRunLogRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentRunLog, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.AgentRunLog{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *agentRunLogRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.AgentRunLog{})
}
func (r *agentRunLogRepository) Create(db *gorm.DB, t *models.AgentRunLog) (err error) {
err = db.Create(t).Error
return
}
func (r *agentRunLogRepository) Update(db *gorm.DB, t *models.AgentRunLog) (err error) {
err = db.Save(t).Error
return
}
func (r *agentRunLogRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.AgentRunLog{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *agentRunLogRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.AgentRunLog{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *agentRunLogRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.AgentRunLog{}, "id = ?", id)
}
@@ -0,0 +1,110 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AgentTeamRepository = newAgentTeamRepository()
func newAgentTeamRepository() *agentTeamRepository {
return &agentTeamRepository{}
}
type agentTeamRepository struct {
}
func (r *agentTeamRepository) Get(db *gorm.DB, id int64) *models.AgentTeam {
ret := &models.AgentTeam{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *agentTeamRepository) Take(db *gorm.DB, where ...interface{}) *models.AgentTeam {
ret := &models.AgentTeam{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *agentTeamRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentTeam) {
cnd.Find(db, &list)
return
}
func (r *agentTeamRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.AgentTeam {
ret := &models.AgentTeam{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *agentTeamRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AgentTeam, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *agentTeamRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentTeam, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.AgentTeam{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *agentTeamRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.AgentTeam) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *agentTeamRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *agentTeamRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.AgentTeam{})
}
func (r *agentTeamRepository) Create(db *gorm.DB, t *models.AgentTeam) (err error) {
err = db.Create(t).Error
return
}
func (r *agentTeamRepository) Update(db *gorm.DB, t *models.AgentTeam) (err error) {
err = db.Save(t).Error
return
}
func (r *agentTeamRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.AgentTeam{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *agentTeamRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.AgentTeam{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *agentTeamRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.AgentTeam{}, "id = ?", id)
}
func (r *agentTeamRepository) FindByIds(db *gorm.DB, ids []int64) []models.AgentTeam {
if len(ids) == 0 {
return []models.AgentTeam{}
}
var list []models.AgentTeam
db.Where("id IN ?", ids).Find(&list)
return list
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AgentTeamScheduleRepository = newAgentTeamScheduleRepository()
func newAgentTeamScheduleRepository() *agentTeamScheduleRepository {
return &agentTeamScheduleRepository{}
}
type agentTeamScheduleRepository struct {
}
func (r *agentTeamScheduleRepository) Get(db *gorm.DB, id int64) *models.AgentTeamSchedule {
ret := &models.AgentTeamSchedule{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *agentTeamScheduleRepository) Take(db *gorm.DB, where ...interface{}) *models.AgentTeamSchedule {
ret := &models.AgentTeamSchedule{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *agentTeamScheduleRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentTeamSchedule) {
cnd.Find(db, &list)
return
}
func (r *agentTeamScheduleRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.AgentTeamSchedule {
ret := &models.AgentTeamSchedule{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *agentTeamScheduleRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AgentTeamSchedule, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *agentTeamScheduleRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentTeamSchedule, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.AgentTeamSchedule{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *agentTeamScheduleRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.AgentTeamSchedule) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *agentTeamScheduleRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *agentTeamScheduleRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.AgentTeamSchedule{})
}
func (r *agentTeamScheduleRepository) Create(db *gorm.DB, t *models.AgentTeamSchedule) (err error) {
err = db.Create(t).Error
return
}
func (r *agentTeamScheduleRepository) Update(db *gorm.DB, t *models.AgentTeamSchedule) (err error) {
err = db.Save(t).Error
return
}
func (r *agentTeamScheduleRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.AgentTeamSchedule{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *agentTeamScheduleRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.AgentTeamSchedule{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *agentTeamScheduleRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.AgentTeamSchedule{}, "id = ?", id)
}
@@ -0,0 +1,110 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AIAgentRepository = newAIAgentRepository()
func newAIAgentRepository() *aIAgentRepository {
return &aIAgentRepository{}
}
type aIAgentRepository struct {
}
func (r *aIAgentRepository) Get(db *gorm.DB, id int64) *models.AIAgent {
ret := &models.AIAgent{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *aIAgentRepository) Take(db *gorm.DB, where ...interface{}) *models.AIAgent {
ret := &models.AIAgent{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *aIAgentRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIAgent) {
cnd.Find(db, &list)
return
}
func (r *aIAgentRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.AIAgent {
ret := &models.AIAgent{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *aIAgentRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AIAgent, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *aIAgentRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIAgent, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.AIAgent{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *aIAgentRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.AIAgent) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *aIAgentRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *aIAgentRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.AIAgent{})
}
func (r *aIAgentRepository) Create(db *gorm.DB, t *models.AIAgent) (err error) {
err = db.Create(t).Error
return
}
func (r *aIAgentRepository) Update(db *gorm.DB, t *models.AIAgent) (err error) {
err = db.Save(t).Error
return
}
func (r *aIAgentRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.AIAgent{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *aIAgentRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.AIAgent{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *aIAgentRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.AIAgent{}, "id = ?", id)
}
func (r *aIAgentRepository) FindByIds(db *gorm.DB, ids []int64) []models.AIAgent {
if len(ids) == 0 {
return []models.AIAgent{}
}
var list []models.AIAgent
db.Where("id IN ?", ids).Find(&list)
return list
}
@@ -0,0 +1,110 @@
package repositories
import (
"cs-agent/internal/models"
"cs-agent/internal/pkg/enums"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AIConfigRepository = newAIConfigRepository()
func newAIConfigRepository() *aIConfigRepository {
return &aIConfigRepository{}
}
type aIConfigRepository struct {
}
func (r *aIConfigRepository) Get(db *gorm.DB, id int64) *models.AIConfig {
ret := &models.AIConfig{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *aIConfigRepository) Take(db *gorm.DB, where ...interface{}) *models.AIConfig {
ret := &models.AIConfig{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *aIConfigRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIConfig) {
cnd.Find(db, &list)
return
}
func (r *aIConfigRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.AIConfig {
ret := &models.AIConfig{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *aIConfigRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AIConfig, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *aIConfigRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIConfig, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.AIConfig{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *aIConfigRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.AIConfig) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *aIConfigRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *aIConfigRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.AIConfig{})
}
func (r *aIConfigRepository) Create(db *gorm.DB, t *models.AIConfig) (err error) {
err = db.Create(t).Error
return
}
func (r *aIConfigRepository) Update(db *gorm.DB, t *models.AIConfig) (err error) {
err = db.Save(t).Error
return
}
func (r *aIConfigRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.AIConfig{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *aIConfigRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.AIConfig{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *aIConfigRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.AIConfig{}, "id = ?", id)
}
func (r *aIConfigRepository) GetEnabled(db *gorm.DB, modelType enums.AIModelType) *models.AIConfig {
return r.FindOne(db, sqls.NewCnd().
Eq("model_type", modelType).
Eq("status", enums.StatusOk).
Desc("sort_no").
Desc("id"))
}
+117
View File
@@ -0,0 +1,117 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var AssetRepository = newAssetRepository()
func newAssetRepository() *assetRepository {
return &assetRepository{}
}
type assetRepository struct {
}
func (r *assetRepository) Get(db *gorm.DB, id int64) *models.Asset {
ret := &models.Asset{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *assetRepository) Take(db *gorm.DB, where ...interface{}) *models.Asset {
ret := &models.Asset{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *assetRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Asset) {
cnd.Find(db, &list)
return
}
func (r *assetRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Asset {
ret := &models.Asset{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *assetRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Asset, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *assetRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Asset, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Asset{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *assetRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Asset) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *assetRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *assetRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Asset{})
}
func (r *assetRepository) Create(db *gorm.DB, t *models.Asset) (err error) {
err = db.Create(t).Error
return
}
func (r *assetRepository) Update(db *gorm.DB, t *models.Asset) (err error) {
err = db.Save(t).Error
return
}
func (r *assetRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Asset{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *assetRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Asset{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *assetRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Asset{}, "id = ?", id)
}
func (r *assetRepository) GetByAssetID(db *gorm.DB, assetID string) *models.Asset {
ret := &models.Asset{}
if err := db.First(ret, "asset_id = ?", assetID).Error; err != nil {
return nil
}
return ret
}
func (r *assetRepository) GetByStorageKey(db *gorm.DB, storageKey string) *models.Asset {
ret := &models.Asset{}
if err := db.First(ret, "storage_key = ?", storageKey).Error; err != nil {
return nil
}
return ret
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ChannelMessageOutboxRepository = newChannelMessageOutboxRepository()
func newChannelMessageOutboxRepository() *channelMessageOutboxRepository {
return &channelMessageOutboxRepository{}
}
type channelMessageOutboxRepository struct {
}
func (r *channelMessageOutboxRepository) Get(db *gorm.DB, id int64) *models.ChannelMessageOutbox {
ret := &models.ChannelMessageOutbox{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *channelMessageOutboxRepository) Take(db *gorm.DB, where ...interface{}) *models.ChannelMessageOutbox {
ret := &models.ChannelMessageOutbox{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *channelMessageOutboxRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ChannelMessageOutbox) {
cnd.Find(db, &list)
return
}
func (r *channelMessageOutboxRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ChannelMessageOutbox {
ret := &models.ChannelMessageOutbox{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *channelMessageOutboxRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ChannelMessageOutbox, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *channelMessageOutboxRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ChannelMessageOutbox, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.ChannelMessageOutbox{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *channelMessageOutboxRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.ChannelMessageOutbox) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *channelMessageOutboxRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *channelMessageOutboxRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.ChannelMessageOutbox{})
}
func (r *channelMessageOutboxRepository) Create(db *gorm.DB, t *models.ChannelMessageOutbox) (err error) {
err = db.Create(t).Error
return
}
func (r *channelMessageOutboxRepository) Update(db *gorm.DB, t *models.ChannelMessageOutbox) (err error) {
err = db.Save(t).Error
return
}
func (r *channelMessageOutboxRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.ChannelMessageOutbox{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *channelMessageOutboxRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.ChannelMessageOutbox{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *channelMessageOutboxRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.ChannelMessageOutbox{}, "id = ?", id)
}
+102
View File
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ChannelRepository = newChannelRepository()
func newChannelRepository() *channelRepository {
return &channelRepository{}
}
type channelRepository struct {
}
func (r *channelRepository) Get(db *gorm.DB, id int64) *models.Channel {
ret := &models.Channel{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *channelRepository) Take(db *gorm.DB, where ...interface{}) *models.Channel {
ret := &models.Channel{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *channelRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Channel) {
cnd.Find(db, &list)
return
}
func (r *channelRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Channel {
ret := &models.Channel{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *channelRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Channel, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *channelRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Channel, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Channel{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *channelRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.Channel) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *channelRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *channelRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Channel{})
}
func (r *channelRepository) Create(db *gorm.DB, t *models.Channel) (err error) {
err = db.Create(t).Error
return
}
func (r *channelRepository) Update(db *gorm.DB, t *models.Channel) (err error) {
err = db.Save(t).Error
return
}
func (r *channelRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Channel{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *channelRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Channel{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *channelRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Channel{}, "id = ?", id)
}
+109
View File
@@ -0,0 +1,109 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var CompanyRepository = newCompanyRepository()
func newCompanyRepository() *companyRepository {
return &companyRepository{}
}
type companyRepository struct {
}
func (r *companyRepository) GetByName(db *gorm.DB, name string) *models.Company {
ret := &models.Company{}
if err := db.First(ret, "name = ?", name).Error; err != nil {
return nil
}
return ret
}
func (r *companyRepository) Get(db *gorm.DB, id int64) *models.Company {
ret := &models.Company{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *companyRepository) Take(db *gorm.DB, where ...interface{}) *models.Company {
ret := &models.Company{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *companyRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Company) {
cnd.Find(db, &list)
return
}
func (r *companyRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Company {
ret := &models.Company{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *companyRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Company, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *companyRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Company, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Company{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *companyRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Company) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *companyRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *companyRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Company{})
}
func (r *companyRepository) Create(db *gorm.DB, t *models.Company) (err error) {
err = db.Create(t).Error
return
}
func (r *companyRepository) Update(db *gorm.DB, t *models.Company) (err error) {
err = db.Save(t).Error
return
}
func (r *companyRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Company{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *companyRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Company{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *companyRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Company{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ConversationAssignmentRepository = newConversationAssignmentRepository()
func newConversationAssignmentRepository() *conversationAssignmentRepository {
return &conversationAssignmentRepository{}
}
type conversationAssignmentRepository struct {
}
func (r *conversationAssignmentRepository) Get(db *gorm.DB, id int64) *models.ConversationAssignment {
ret := &models.ConversationAssignment{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationAssignmentRepository) Take(db *gorm.DB, where ...interface{}) *models.ConversationAssignment {
ret := &models.ConversationAssignment{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *conversationAssignmentRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationAssignment) {
cnd.Find(db, &list)
return
}
func (r *conversationAssignmentRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationAssignment {
ret := &models.ConversationAssignment{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationAssignmentRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ConversationAssignment, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *conversationAssignmentRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationAssignment, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.ConversationAssignment{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *conversationAssignmentRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.ConversationAssignment) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *conversationAssignmentRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *conversationAssignmentRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.ConversationAssignment{})
}
func (r *conversationAssignmentRepository) Create(db *gorm.DB, t *models.ConversationAssignment) (err error) {
err = db.Create(t).Error
return
}
func (r *conversationAssignmentRepository) Update(db *gorm.DB, t *models.ConversationAssignment) (err error) {
err = db.Save(t).Error
return
}
func (r *conversationAssignmentRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.ConversationAssignment{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *conversationAssignmentRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.ConversationAssignment{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *conversationAssignmentRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.ConversationAssignment{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ConversationEventLogRepository = newConversationEventLogRepository()
func newConversationEventLogRepository() *conversationEventLogRepository {
return &conversationEventLogRepository{}
}
type conversationEventLogRepository struct {
}
func (r *conversationEventLogRepository) Get(db *gorm.DB, id int64) *models.ConversationEventLog {
ret := &models.ConversationEventLog{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationEventLogRepository) Take(db *gorm.DB, where ...interface{}) *models.ConversationEventLog {
ret := &models.ConversationEventLog{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *conversationEventLogRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationEventLog) {
cnd.Find(db, &list)
return
}
func (r *conversationEventLogRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationEventLog {
ret := &models.ConversationEventLog{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationEventLogRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ConversationEventLog, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *conversationEventLogRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationEventLog, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.ConversationEventLog{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *conversationEventLogRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.ConversationEventLog) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *conversationEventLogRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *conversationEventLogRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.ConversationEventLog{})
}
func (r *conversationEventLogRepository) Create(db *gorm.DB, t *models.ConversationEventLog) (err error) {
err = db.Create(t).Error
return
}
func (r *conversationEventLogRepository) Update(db *gorm.DB, t *models.ConversationEventLog) (err error) {
err = db.Save(t).Error
return
}
func (r *conversationEventLogRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.ConversationEventLog{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *conversationEventLogRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.ConversationEventLog{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *conversationEventLogRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.ConversationEventLog{}, "id = ?", id)
}
@@ -0,0 +1,88 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"gorm.io/gorm"
)
var ConversationInterruptRepository = newConversationInterruptRepository()
func newConversationInterruptRepository() *conversationInterruptRepository {
return &conversationInterruptRepository{}
}
type conversationInterruptRepository struct{}
func (r *conversationInterruptRepository) Get(db *gorm.DB, id int64) *models.ConversationInterrupt {
ret := &models.ConversationInterrupt{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationInterruptRepository) GetByCheckPointID(db *gorm.DB, checkPointID string) *models.ConversationInterrupt {
ret := &models.ConversationInterrupt{}
if err := db.Where("check_point_id = ?", checkPointID).First(ret).Error; err != nil {
return nil
}
return ret
}
func (r *conversationInterruptRepository) FindLatestPendingByConversationID(db *gorm.DB, conversationID int64) *models.ConversationInterrupt {
ret := &models.ConversationInterrupt{}
if err := db.Where("conversation_id = ? AND status = ?", conversationID, "pending").Order("id DESC").First(ret).Error; err != nil {
return nil
}
return ret
}
func (r *conversationInterruptRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationInterrupt) {
cnd.Find(db, &list)
return
}
func (r *conversationInterruptRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationInterrupt {
ret := &models.ConversationInterrupt{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationInterruptRepository) Create(db *gorm.DB, t *models.ConversationInterrupt) error {
return db.Create(t).Error
}
func (r *conversationInterruptRepository) Update(db *gorm.DB, t *models.ConversationInterrupt) error {
return db.Save(t).Error
}
func (r *conversationInterruptRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
return db.Model(&models.ConversationInterrupt{}).Where("id = ?", id).Updates(columns).Error
}
func (r *conversationInterruptRepository) UpsertByCheckPointID(db *gorm.DB, item *models.ConversationInterrupt) error {
current := r.GetByCheckPointID(db, item.CheckPointID)
if current == nil {
return r.Create(db, item)
}
columns := map[string]any{
"conversation_id": item.ConversationID,
"ai_agent_id": item.AIAgentID,
"source_message_id": item.SourceMessageID,
"last_resume_message_id": item.LastResumeMessageID,
"interrupt_id": item.InterruptID,
"interrupt_type": item.InterruptType,
"status": item.Status,
"prompt_text": item.PromptText,
"request_data": item.RequestData,
"check_point_data": item.CheckPointData,
"resume_count": item.ResumeCount,
"expires_at": item.ExpiresAt,
"updated_at": item.UpdatedAt,
}
return r.Updates(db, current.ID, columns)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ConversationParticipantRepository = newConversationParticipantRepository()
func newConversationParticipantRepository() *conversationParticipantRepository {
return &conversationParticipantRepository{}
}
type conversationParticipantRepository struct {
}
func (r *conversationParticipantRepository) Get(db *gorm.DB, id int64) *models.ConversationParticipant {
ret := &models.ConversationParticipant{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationParticipantRepository) Take(db *gorm.DB, where ...interface{}) *models.ConversationParticipant {
ret := &models.ConversationParticipant{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *conversationParticipantRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationParticipant) {
cnd.Find(db, &list)
return
}
func (r *conversationParticipantRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationParticipant {
ret := &models.ConversationParticipant{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationParticipantRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ConversationParticipant, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *conversationParticipantRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationParticipant, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.ConversationParticipant{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *conversationParticipantRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.ConversationParticipant) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *conversationParticipantRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *conversationParticipantRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.ConversationParticipant{})
}
func (r *conversationParticipantRepository) Create(db *gorm.DB, t *models.ConversationParticipant) (err error) {
err = db.Create(t).Error
return
}
func (r *conversationParticipantRepository) Update(db *gorm.DB, t *models.ConversationParticipant) (err error) {
err = db.Save(t).Error
return
}
func (r *conversationParticipantRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.ConversationParticipant{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *conversationParticipantRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.ConversationParticipant{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *conversationParticipantRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.ConversationParticipant{}, "id = ?", id)
}
@@ -0,0 +1,91 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ConversationReadStateRepository = newConversationReadStateRepository()
func newConversationReadStateRepository() *conversationReadStateRepository {
return &conversationReadStateRepository{}
}
type conversationReadStateRepository struct {
}
func (r *conversationReadStateRepository) Get(db *gorm.DB, id int64) *models.ConversationReadState {
ret := &models.ConversationReadState{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationReadStateRepository) Take(db *gorm.DB, where ...interface{}) *models.ConversationReadState {
ret := &models.ConversationReadState{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *conversationReadStateRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationReadState) {
cnd.Find(db, &list)
return
}
func (r *conversationReadStateRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationReadState {
ret := &models.ConversationReadState{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationReadStateRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ConversationReadState, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *conversationReadStateRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationReadState, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.ConversationReadState{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *conversationReadStateRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.ConversationReadState{})
}
func (r *conversationReadStateRepository) Create(db *gorm.DB, t *models.ConversationReadState) (err error) {
err = db.Create(t).Error
return
}
func (r *conversationReadStateRepository) Update(db *gorm.DB, t *models.ConversationReadState) (err error) {
err = db.Save(t).Error
return
}
func (r *conversationReadStateRepository) Updates(db *gorm.DB, id int64, columns map[string]any) (err error) {
err = db.Model(&models.ConversationReadState{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *conversationReadStateRepository) UpdateColumn(db *gorm.DB, id int64, name string, value any) (err error) {
err = db.Model(&models.ConversationReadState{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *conversationReadStateRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.ConversationReadState{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ConversationRepository = newConversationRepository()
func newConversationRepository() *conversationRepository {
return &conversationRepository{}
}
type conversationRepository struct {
}
func (r *conversationRepository) Get(db *gorm.DB, id int64) *models.Conversation {
ret := &models.Conversation{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationRepository) Take(db *gorm.DB, where ...interface{}) *models.Conversation {
ret := &models.Conversation{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *conversationRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Conversation) {
cnd.Find(db, &list)
return
}
func (r *conversationRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Conversation {
ret := &models.Conversation{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Conversation, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *conversationRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Conversation, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Conversation{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *conversationRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Conversation) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *conversationRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *conversationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Conversation{})
}
func (r *conversationRepository) Create(db *gorm.DB, t *models.Conversation) (err error) {
err = db.Create(t).Error
return
}
func (r *conversationRepository) Update(db *gorm.DB, t *models.Conversation) (err error) {
err = db.Save(t).Error
return
}
func (r *conversationRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Conversation{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *conversationRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Conversation{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *conversationRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Conversation{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var ConversationTagRepository = newConversationTagRepository()
func newConversationTagRepository() *conversationTagRepository {
return &conversationTagRepository{}
}
type conversationTagRepository struct {
}
func (r *conversationTagRepository) Get(db *gorm.DB, id int64) *models.ConversationTag {
ret := &models.ConversationTag{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *conversationTagRepository) Take(db *gorm.DB, where ...interface{}) *models.ConversationTag {
ret := &models.ConversationTag{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *conversationTagRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationTag) {
cnd.Find(db, &list)
return
}
func (r *conversationTagRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationTag {
ret := &models.ConversationTag{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *conversationTagRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ConversationTag, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *conversationTagRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationTag, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.ConversationTag{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *conversationTagRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.ConversationTag) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *conversationTagRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *conversationTagRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.ConversationTag{})
}
func (r *conversationTagRepository) Create(db *gorm.DB, t *models.ConversationTag) (err error) {
err = db.Create(t).Error
return
}
func (r *conversationTagRepository) Update(db *gorm.DB, t *models.ConversationTag) (err error) {
err = db.Save(t).Error
return
}
func (r *conversationTagRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.ConversationTag{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *conversationTagRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.ConversationTag{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *conversationTagRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.ConversationTag{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var CustomerContactRepository = newCustomerContactRepository()
func newCustomerContactRepository() *customerContactRepository {
return &customerContactRepository{}
}
type customerContactRepository struct {
}
func (r *customerContactRepository) Get(db *gorm.DB, id int64) *models.CustomerContact {
ret := &models.CustomerContact{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *customerContactRepository) Take(db *gorm.DB, where ...interface{}) *models.CustomerContact {
ret := &models.CustomerContact{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *customerContactRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerContact) {
cnd.Find(db, &list)
return
}
func (r *customerContactRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.CustomerContact {
ret := &models.CustomerContact{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *customerContactRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.CustomerContact, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *customerContactRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerContact, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.CustomerContact{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *customerContactRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.CustomerContact) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *customerContactRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *customerContactRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.CustomerContact{})
}
func (r *customerContactRepository) Create(db *gorm.DB, t *models.CustomerContact) (err error) {
err = db.Create(t).Error
return
}
func (r *customerContactRepository) Update(db *gorm.DB, t *models.CustomerContact) (err error) {
err = db.Save(t).Error
return
}
func (r *customerContactRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.CustomerContact{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *customerContactRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.CustomerContact{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *customerContactRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.CustomerContact{}, "id = ?", id)
}
@@ -0,0 +1,113 @@
package repositories
import (
"cs-agent/internal/models"
"cs-agent/internal/pkg/enums"
"github.com/mlogclub/simple/common/strs"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var CustomerIdentityRepository = newCustomerIdentityRepository()
func newCustomerIdentityRepository() *customerIdentityRepository {
return &customerIdentityRepository{}
}
type customerIdentityRepository struct {
}
func (r *customerIdentityRepository) Get(db *gorm.DB, id int64) *models.CustomerIdentity {
ret := &models.CustomerIdentity{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *customerIdentityRepository) Take(db *gorm.DB, where ...interface{}) *models.CustomerIdentity {
ret := &models.CustomerIdentity{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
// GetBy 按外部来源 + 外部用户标识查询身份映射(与 uk_customer_external 一致)。
func (r *customerIdentityRepository) GetBy(db *gorm.DB, externalSource enums.ExternalSource, externalID string) *models.CustomerIdentity {
if strs.IsAnyBlank(string(externalSource), externalID) {
return nil
}
return r.FindOne(db, sqls.NewCnd().
Eq("external_source", externalSource).
Eq("external_id", externalID))
}
func (r *customerIdentityRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerIdentity) {
cnd.Find(db, &list)
return
}
func (r *customerIdentityRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.CustomerIdentity {
ret := &models.CustomerIdentity{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *customerIdentityRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.CustomerIdentity, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *customerIdentityRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerIdentity, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.CustomerIdentity{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *customerIdentityRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.CustomerIdentity) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *customerIdentityRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *customerIdentityRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.CustomerIdentity{})
}
func (r *customerIdentityRepository) Create(db *gorm.DB, t *models.CustomerIdentity) (err error) {
err = db.Create(t).Error
return
}
func (r *customerIdentityRepository) Update(db *gorm.DB, t *models.CustomerIdentity) (err error) {
err = db.Save(t).Error
return
}
func (r *customerIdentityRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.CustomerIdentity{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *customerIdentityRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.CustomerIdentity{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *customerIdentityRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.CustomerIdentity{}, "id = ?", id)
}
@@ -0,0 +1,126 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var CustomerRepository = newCustomerRepository()
func newCustomerRepository() *customerRepository {
return &customerRepository{}
}
type customerRepository struct {
}
type CompanyCustomerCount struct {
CompanyID int64 `gorm:"column:company_id"`
Count int64 `gorm:"column:cnt"`
}
func (r *customerRepository) CountByCompanyIDs(db *gorm.DB, companyIDs []int64, excludeStatus int) map[int64]int64 {
ret := make(map[int64]int64)
if len(companyIDs) == 0 {
return ret
}
rows := make([]CompanyCustomerCount, 0, len(companyIDs))
db.Model(&models.Customer{}).
Select("company_id, count(1) as cnt").
Where("company_id in ?", companyIDs).
Where("status <> ?", excludeStatus).
Group("company_id").
Scan(&rows)
for _, row := range rows {
ret[row.CompanyID] = row.Count
}
return ret
}
func (r *customerRepository) Get(db *gorm.DB, id int64) *models.Customer {
ret := &models.Customer{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *customerRepository) Take(db *gorm.DB, where ...interface{}) *models.Customer {
ret := &models.Customer{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *customerRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Customer) {
cnd.Find(db, &list)
return
}
func (r *customerRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Customer {
ret := &models.Customer{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *customerRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Customer, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *customerRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Customer, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Customer{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *customerRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Customer) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *customerRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *customerRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Customer{})
}
func (r *customerRepository) Create(db *gorm.DB, t *models.Customer) (err error) {
err = db.Create(t).Error
return
}
func (r *customerRepository) Update(db *gorm.DB, t *models.Customer) (err error) {
err = db.Save(t).Error
return
}
func (r *customerRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Customer{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *customerRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Customer{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *customerRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Customer{}, "id = ?", id)
}
@@ -0,0 +1,108 @@
package repositories
import (
"cs-agent/internal/models"
"cs-agent/internal/pkg/enums"
"time"
"gorm.io/gorm"
)
var DashboardRepository = newDashboardRepository()
func newDashboardRepository() *dashboardRepository {
return &dashboardRepository{}
}
type dashboardRepository struct {
}
func (r *dashboardRepository) CountConversations(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.Conversation{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) ListConversations(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) []models.Conversation {
var list []models.Conversation
tx := db.Model(&models.Conversation{})
if query != nil {
tx = query(tx)
}
tx.Find(&list)
return list
}
func (r *dashboardRepository) ListEnabledAgentProfiles(db *gorm.DB) []models.AgentProfile {
var list []models.AgentProfile
db.Model(&models.AgentProfile{}).Where("status = ?", enums.StatusOk).Find(&list)
return list
}
func (r *dashboardRepository) ListEnabledAgentTeams(db *gorm.DB) []models.AgentTeam {
var list []models.AgentTeam
db.Model(&models.AgentTeam{}).Where("status = ?", enums.StatusOk).Order("id asc").Find(&list)
return list
}
func (r *dashboardRepository) ListActiveTeamSchedules(db *gorm.DB, startAt, endAt time.Time) []models.AgentTeamSchedule {
var list []models.AgentTeamSchedule
db.Model(&models.AgentTeamSchedule{}).
Where("status = ? AND start_at <= ? AND end_at >= ?", enums.StatusOk, endAt, startAt).
Find(&list)
return list
}
func (r *dashboardRepository) CountAIAgents(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.AIAgent{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) ListAIAgents(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) []models.AIAgent {
var list []models.AIAgent
tx := db.Model(&models.AIAgent{})
if query != nil {
tx = query(tx)
}
tx.Find(&list)
return list
}
func (r *dashboardRepository) CountChannels(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.Channel{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) CountKnowledgeRetrieveLogs(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.KnowledgeRetrieveLog{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) CountSkillRunLogs(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.SkillRunLog{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
@@ -0,0 +1,91 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var KnowledgeBaseRepository = newKnowledgeBaseRepository()
func newKnowledgeBaseRepository() *knowledgeBaseRepository {
return &knowledgeBaseRepository{}
}
type knowledgeBaseRepository struct {
}
func (r *knowledgeBaseRepository) Get(db *gorm.DB, id int64) *models.KnowledgeBase {
ret := &models.KnowledgeBase{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeBaseRepository) Take(db *gorm.DB, where ...interface{}) *models.KnowledgeBase {
ret := &models.KnowledgeBase{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeBaseRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeBase) {
cnd.Find(db, &list)
return
}
func (r *knowledgeBaseRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.KnowledgeBase {
ret := &models.KnowledgeBase{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *knowledgeBaseRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.KnowledgeBase, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *knowledgeBaseRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeBase, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.KnowledgeBase{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *knowledgeBaseRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.KnowledgeBase{})
}
func (r *knowledgeBaseRepository) Create(db *gorm.DB, t *models.KnowledgeBase) (err error) {
err = db.Create(t).Error
return
}
func (r *knowledgeBaseRepository) Update(db *gorm.DB, t *models.KnowledgeBase) (err error) {
err = db.Save(t).Error
return
}
func (r *knowledgeBaseRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.KnowledgeBase{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *knowledgeBaseRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.KnowledgeBase{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *knowledgeBaseRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.KnowledgeBase{}, "id = ?", id)
}
@@ -0,0 +1,140 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var KnowledgeChunkRepository = newKnowledgeChunkRepository()
func newKnowledgeChunkRepository() *knowledgeChunkRepository {
return &knowledgeChunkRepository{}
}
type knowledgeChunkRepository struct {
}
func (r *knowledgeChunkRepository) Get(db *gorm.DB, id int64) *models.KnowledgeChunk {
ret := &models.KnowledgeChunk{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeChunkRepository) Take(db *gorm.DB, where ...interface{}) *models.KnowledgeChunk {
ret := &models.KnowledgeChunk{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeChunkRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeChunk) {
cnd.Find(db, &list)
return
}
func (r *knowledgeChunkRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.KnowledgeChunk {
ret := &models.KnowledgeChunk{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *knowledgeChunkRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.KnowledgeChunk, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *knowledgeChunkRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeChunk, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.KnowledgeChunk{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *knowledgeChunkRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.KnowledgeChunk{})
}
func (r *knowledgeChunkRepository) Create(db *gorm.DB, t *models.KnowledgeChunk) (err error) {
err = db.Create(t).Error
return
}
func (r *knowledgeChunkRepository) BatchCreate(db *gorm.DB, list []models.KnowledgeChunk) (err error) {
err = db.Create(&list).Error
return
}
func (r *knowledgeChunkRepository) Update(db *gorm.DB, t *models.KnowledgeChunk) (err error) {
err = db.Save(t).Error
return
}
func (r *knowledgeChunkRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.KnowledgeChunk{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *knowledgeChunkRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.KnowledgeChunk{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *knowledgeChunkRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.KnowledgeChunk{}, "id = ?", id)
}
func (r *knowledgeChunkRepository) DeleteByDocumentID(db *gorm.DB, documentID int64) {
db.Delete(&models.KnowledgeChunk{}, "document_id = ?", documentID)
}
func (r *knowledgeChunkRepository) DeleteByFaqID(db *gorm.DB, faqID int64) {
db.Delete(&models.KnowledgeChunk{}, "faq_id = ?", faqID)
}
func (r *knowledgeChunkRepository) FindByDocumentID(db *gorm.DB, documentID int64) (list []models.KnowledgeChunk) {
db.Where("document_id = ?", documentID).Order("chunk_no asc").Find(&list)
return
}
func (r *knowledgeChunkRepository) FindByFaqID(db *gorm.DB, faqID int64) (list []models.KnowledgeChunk) {
db.Where("faq_id = ?", faqID).Order("chunk_no asc").Find(&list)
return
}
func (r *knowledgeChunkRepository) FindByVectorIDs(db *gorm.DB, vectorIDs []string) (list []models.KnowledgeChunk) {
if len(vectorIDs) == 0 {
return nil
}
db.Where("vector_id IN ?", vectorIDs).Find(&list)
return
}
func (r *knowledgeChunkRepository) CountByDocumentID(db *gorm.DB, documentID int64) int64 {
var count int64
db.Model(&models.KnowledgeChunk{}).Where("document_id = ?", documentID).Count(&count)
return count
}
func (r *knowledgeChunkRepository) CountByFaqID(db *gorm.DB, faqID int64) int64 {
var count int64
db.Model(&models.KnowledgeChunk{}).Where("faq_id = ?", faqID).Count(&count)
return count
}
func (r *knowledgeChunkRepository) CountByKnowledgeBaseID(db *gorm.DB, knowledgeBaseID int64) int64 {
var count int64
db.Model(&models.KnowledgeChunk{}).Where("knowledge_base_id = ?", knowledgeBaseID).Count(&count)
return count
}
@@ -0,0 +1,105 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var KnowledgeDocumentRepository = newKnowledgeDocumentRepository()
func newKnowledgeDocumentRepository() *knowledgeDocumentRepository {
return &knowledgeDocumentRepository{}
}
type knowledgeDocumentRepository struct {
}
func (r *knowledgeDocumentRepository) Get(db *gorm.DB, id int64) *models.KnowledgeDocument {
ret := &models.KnowledgeDocument{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeDocumentRepository) Take(db *gorm.DB, where ...interface{}) *models.KnowledgeDocument {
ret := &models.KnowledgeDocument{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeDocumentRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeDocument) {
cnd.Find(db, &list)
return
}
func (r *knowledgeDocumentRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.KnowledgeDocument {
ret := &models.KnowledgeDocument{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *knowledgeDocumentRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.KnowledgeDocument, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *knowledgeDocumentRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeDocument, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.KnowledgeDocument{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *knowledgeDocumentRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.KnowledgeDocument{})
}
func (r *knowledgeDocumentRepository) Create(db *gorm.DB, t *models.KnowledgeDocument) (err error) {
err = db.Create(t).Error
return
}
func (r *knowledgeDocumentRepository) Update(db *gorm.DB, t *models.KnowledgeDocument) (err error) {
err = db.Save(t).Error
return
}
func (r *knowledgeDocumentRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.KnowledgeDocument{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *knowledgeDocumentRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.KnowledgeDocument{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *knowledgeDocumentRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.KnowledgeDocument{}, "id = ?", id)
}
func (r *knowledgeDocumentRepository) FindByIDs(db *gorm.DB, ids []int64) (list []models.KnowledgeDocument) {
if len(ids) == 0 {
return nil
}
db.Where("id IN ?", ids).Find(&list)
return
}
func (r *knowledgeDocumentRepository) CountByKnowledgeBaseID(db *gorm.DB, knowledgeBaseID int64) int64 {
var count int64
db.Model(&models.KnowledgeDocument{}).Where("knowledge_base_id = ?", knowledgeBaseID).Count(&count)
return count
}
@@ -0,0 +1,71 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var KnowledgeFAQRepository = newKnowledgeFAQRepository()
func newKnowledgeFAQRepository() *knowledgeFAQRepository {
return &knowledgeFAQRepository{}
}
type knowledgeFAQRepository struct{}
func (r *knowledgeFAQRepository) Get(db *gorm.DB, id int64) *models.KnowledgeFAQ {
ret := &models.KnowledgeFAQ{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *knowledgeFAQRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeFAQ) {
cnd.Find(db, &list)
return
}
func (r *knowledgeFAQRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.KnowledgeFAQ, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.KnowledgeFAQ{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *knowledgeFAQRepository) FindPageByParams(db *gorm.DB, queryParams *params.QueryParams) (list []models.KnowledgeFAQ, paging *sqls.Paging) {
return r.FindPageByCnd(db, &queryParams.Cnd)
}
func (r *knowledgeFAQRepository) Create(db *gorm.DB, t *models.KnowledgeFAQ) error {
return db.Create(t).Error
}
func (r *knowledgeFAQRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
return db.Model(&models.KnowledgeFAQ{}).Where("id = ?", id).Updates(columns).Error
}
func (r *knowledgeFAQRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.KnowledgeFAQ{}, "id = ?", id)
}
func (r *knowledgeFAQRepository) FindByIDs(db *gorm.DB, ids []int64) (list []models.KnowledgeFAQ) {
if len(ids) == 0 {
return nil
}
db.Where("id IN ?", ids).Find(&list)
return
}
func (r *knowledgeFAQRepository) CountByKnowledgeBaseID(db *gorm.DB, knowledgeBaseID int64) int64 {
var count int64
db.Model(&models.KnowledgeFAQ{}).Where("knowledge_base_id = ?", knowledgeBaseID).Count(&count)
return count
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var LoginCredentialLogRepository = newLoginCredentialLogRepository()
func newLoginCredentialLogRepository() *loginCredentialLogRepository {
return &loginCredentialLogRepository{}
}
type loginCredentialLogRepository struct {
}
func (r *loginCredentialLogRepository) Get(db *gorm.DB, id int64) *models.LoginCredentialLog {
ret := &models.LoginCredentialLog{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *loginCredentialLogRepository) Take(db *gorm.DB, where ...interface{}) *models.LoginCredentialLog {
ret := &models.LoginCredentialLog{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *loginCredentialLogRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.LoginCredentialLog) {
cnd.Find(db, &list)
return
}
func (r *loginCredentialLogRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.LoginCredentialLog {
ret := &models.LoginCredentialLog{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *loginCredentialLogRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.LoginCredentialLog, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *loginCredentialLogRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.LoginCredentialLog, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.LoginCredentialLog{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *loginCredentialLogRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.LoginCredentialLog) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *loginCredentialLogRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *loginCredentialLogRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.LoginCredentialLog{})
}
func (r *loginCredentialLogRepository) Create(db *gorm.DB, t *models.LoginCredentialLog) (err error) {
err = db.Create(t).Error
return
}
func (r *loginCredentialLogRepository) Update(db *gorm.DB, t *models.LoginCredentialLog) (err error) {
err = db.Save(t).Error
return
}
func (r *loginCredentialLogRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.LoginCredentialLog{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *loginCredentialLogRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.LoginCredentialLog{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *loginCredentialLogRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.LoginCredentialLog{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var LoginSessionRepository = newLoginSessionRepository()
func newLoginSessionRepository() *loginSessionRepository {
return &loginSessionRepository{}
}
type loginSessionRepository struct {
}
func (r *loginSessionRepository) Get(db *gorm.DB, id int64) *models.LoginSession {
ret := &models.LoginSession{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *loginSessionRepository) Take(db *gorm.DB, where ...interface{}) *models.LoginSession {
ret := &models.LoginSession{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *loginSessionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.LoginSession) {
cnd.Find(db, &list)
return
}
func (r *loginSessionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.LoginSession {
ret := &models.LoginSession{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *loginSessionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.LoginSession, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *loginSessionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.LoginSession, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.LoginSession{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *loginSessionRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.LoginSession) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *loginSessionRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *loginSessionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.LoginSession{})
}
func (r *loginSessionRepository) Create(db *gorm.DB, t *models.LoginSession) (err error) {
err = db.Create(t).Error
return
}
func (r *loginSessionRepository) Update(db *gorm.DB, t *models.LoginSession) (err error) {
err = db.Save(t).Error
return
}
func (r *loginSessionRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.LoginSession{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *loginSessionRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.LoginSession{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *loginSessionRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.LoginSession{}, "id = ?", id)
}
+127
View File
@@ -0,0 +1,127 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var MessageRepository = newMessageRepository()
func newMessageRepository() *messageRepository {
return &messageRepository{}
}
type messageRepository struct {
}
func (r *messageRepository) Get(db *gorm.DB, id int64) *models.Message {
ret := &models.Message{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *messageRepository) Take(db *gorm.DB, where ...interface{}) *models.Message {
ret := &models.Message{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *messageRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Message) {
cnd.Find(db, &list)
return
}
func (r *messageRepository) FindLastUnrecalledByConversationID(db *gorm.DB, conversationID int64) *models.Message {
ret := &models.Message{}
if err := db.
Where("conversation_id = ? AND recalled_at IS NULL AND send_status <> ?", conversationID, 6).
Order("seq_no DESC").
Order("id DESC").
Limit(1).
Take(ret).Error; err != nil {
return nil
}
return ret
}
func (r *messageRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Message {
ret := &models.Message{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *messageRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Message, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *messageRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Message, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Message{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *messageRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Message) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *messageRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *messageRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Message{})
}
func (r *messageRepository) Create(db *gorm.DB, t *models.Message) (err error) {
err = db.Create(t).Error
return
}
func (r *messageRepository) Update(db *gorm.DB, t *models.Message) (err error) {
err = db.Save(t).Error
return
}
func (r *messageRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Message{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *messageRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Message{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *messageRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Message{}, "id = ?", id)
}
// GetByClientMsgID 根据 conversationID 和 clientMsgID 获取消息
func (r *messageRepository) GetByClientMsgID(db *gorm.DB, conversationID int64, clientMsgID string) *models.Message {
return r.FindOne(db, sqls.NewCnd().Where("conversation_id = ? AND client_msg_id = ?", conversationID, clientMsgID))
}
// NextSeqNo
func (r *messageRepository) NextSeqNo(db *gorm.DB, conversationID int64) int64 {
if last := r.FindOne(db, sqls.NewCnd().Where("conversation_id = ?", conversationID).Desc("seq_no")); last != nil {
return last.SeqNo + 1
}
return 1
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var MigrationRepository = newMigrationRepository()
func newMigrationRepository() *migrationRepository {
return &migrationRepository{}
}
type migrationRepository struct {
}
func (r *migrationRepository) Get(db *gorm.DB, id int64) *models.Migration {
ret := &models.Migration{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *migrationRepository) Take(db *gorm.DB, where ...interface{}) *models.Migration {
ret := &models.Migration{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *migrationRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Migration) {
cnd.Find(db, &list)
return
}
func (r *migrationRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Migration {
ret := &models.Migration{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *migrationRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Migration, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *migrationRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Migration, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Migration{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *migrationRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Migration) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *migrationRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *migrationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Migration{})
}
func (r *migrationRepository) Create(db *gorm.DB, t *models.Migration) (err error) {
err = db.Create(t).Error
return
}
func (r *migrationRepository) Update(db *gorm.DB, t *models.Migration) (err error) {
err = db.Save(t).Error
return
}
func (r *migrationRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Migration{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *migrationRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Migration{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *migrationRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Migration{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var PermissionRepository = newPermissionRepository()
func newPermissionRepository() *permissionRepository {
return &permissionRepository{}
}
type permissionRepository struct {
}
func (r *permissionRepository) Get(db *gorm.DB, id int64) *models.Permission {
ret := &models.Permission{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *permissionRepository) Take(db *gorm.DB, where ...interface{}) *models.Permission {
ret := &models.Permission{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *permissionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Permission) {
cnd.Find(db, &list)
return
}
func (r *permissionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Permission {
ret := &models.Permission{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *permissionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Permission, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *permissionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Permission, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Permission{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *permissionRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Permission) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *permissionRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *permissionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Permission{})
}
func (r *permissionRepository) Create(db *gorm.DB, t *models.Permission) (err error) {
err = db.Create(t).Error
return
}
func (r *permissionRepository) Update(db *gorm.DB, t *models.Permission) (err error) {
err = db.Save(t).Error
return
}
func (r *permissionRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Permission{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *permissionRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Permission{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *permissionRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Permission{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var QuickReplyRepository = newQuickReplyRepository()
func newQuickReplyRepository() *quickReplyRepository {
return &quickReplyRepository{}
}
type quickReplyRepository struct {
}
func (r *quickReplyRepository) Get(db *gorm.DB, id int64) *models.QuickReply {
ret := &models.QuickReply{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *quickReplyRepository) Take(db *gorm.DB, where ...interface{}) *models.QuickReply {
ret := &models.QuickReply{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *quickReplyRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.QuickReply) {
cnd.Find(db, &list)
return
}
func (r *quickReplyRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.QuickReply {
ret := &models.QuickReply{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *quickReplyRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.QuickReply, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *quickReplyRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.QuickReply, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.QuickReply{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *quickReplyRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.QuickReply) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *quickReplyRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *quickReplyRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.QuickReply{})
}
func (r *quickReplyRepository) Create(db *gorm.DB, t *models.QuickReply) (err error) {
err = db.Create(t).Error
return
}
func (r *quickReplyRepository) Update(db *gorm.DB, t *models.QuickReply) (err error) {
err = db.Save(t).Error
return
}
func (r *quickReplyRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.QuickReply{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *quickReplyRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.QuickReply{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *quickReplyRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.QuickReply{}, "id = ?", id)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var RolePermissionRepository = newRolePermissionRepository()
func newRolePermissionRepository() *rolePermissionRepository {
return &rolePermissionRepository{}
}
type rolePermissionRepository struct {
}
func (r *rolePermissionRepository) Get(db *gorm.DB, id int64) *models.RolePermission {
ret := &models.RolePermission{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *rolePermissionRepository) Take(db *gorm.DB, where ...interface{}) *models.RolePermission {
ret := &models.RolePermission{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *rolePermissionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.RolePermission) {
cnd.Find(db, &list)
return
}
func (r *rolePermissionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.RolePermission {
ret := &models.RolePermission{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *rolePermissionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.RolePermission, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *rolePermissionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.RolePermission, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.RolePermission{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *rolePermissionRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.RolePermission) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *rolePermissionRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *rolePermissionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.RolePermission{})
}
func (r *rolePermissionRepository) Create(db *gorm.DB, t *models.RolePermission) (err error) {
err = db.Create(t).Error
return
}
func (r *rolePermissionRepository) Update(db *gorm.DB, t *models.RolePermission) (err error) {
err = db.Save(t).Error
return
}
func (r *rolePermissionRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.RolePermission{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *rolePermissionRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.RolePermission{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *rolePermissionRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.RolePermission{}, "id = ?", id)
}
+101
View File
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var RoleRepository = newRoleRepository()
func newRoleRepository() *roleRepository {
return &roleRepository{}
}
type roleRepository struct {
}
func (r *roleRepository) Get(db *gorm.DB, id int64) *models.Role {
ret := &models.Role{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *roleRepository) Take(db *gorm.DB, where ...interface{}) *models.Role {
ret := &models.Role{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *roleRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Role) {
cnd.Find(db, &list)
return
}
func (r *roleRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Role {
ret := &models.Role{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *roleRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Role, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *roleRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Role, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Role{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *roleRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Role) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *roleRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *roleRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Role{})
}
func (r *roleRepository) Create(db *gorm.DB, t *models.Role) (err error) {
err = db.Create(t).Error
return
}
func (r *roleRepository) Update(db *gorm.DB, t *models.Role) (err error) {
err = db.Save(t).Error
return
}
func (r *roleRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Role{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *roleRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Role{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *roleRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Role{}, "id = ?", id)
}
@@ -0,0 +1,105 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var SkillDefinitionRepository = newSkillDefinitionRepository()
func newSkillDefinitionRepository() *skillDefinitionRepository {
return &skillDefinitionRepository{}
}
type skillDefinitionRepository struct {
}
func (r *skillDefinitionRepository) Get(db *gorm.DB, id int64) *models.SkillDefinition {
ret := &models.SkillDefinition{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *skillDefinitionRepository) Take(db *gorm.DB, where ...interface{}) *models.SkillDefinition {
ret := &models.SkillDefinition{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *skillDefinitionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.SkillDefinition) {
cnd.Find(db, &list)
return
}
func (r *skillDefinitionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.SkillDefinition {
ret := &models.SkillDefinition{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *skillDefinitionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.SkillDefinition, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *skillDefinitionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.SkillDefinition, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.SkillDefinition{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *skillDefinitionRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.SkillDefinition) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *skillDefinitionRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *skillDefinitionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.SkillDefinition{})
}
func (r *skillDefinitionRepository) Create(db *gorm.DB, t *models.SkillDefinition) (err error) {
err = db.Create(t).Error
return
}
func (r *skillDefinitionRepository) Update(db *gorm.DB, t *models.SkillDefinition) (err error) {
err = db.Save(t).Error
return
}
func (r *skillDefinitionRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.SkillDefinition{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *skillDefinitionRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.SkillDefinition{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *skillDefinitionRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.SkillDefinition{}, "id = ?", id)
}
func (r *skillDefinitionRepository) GetByCode(db *gorm.DB, code string) *models.SkillDefinition {
return r.FindOne(db, sqls.NewCnd().Where("code = ?", code))
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var SkillRunLogRepository = newSkillRunLogRepository()
func newSkillRunLogRepository() *skillRunLogRepository {
return &skillRunLogRepository{}
}
type skillRunLogRepository struct {
}
func (r *skillRunLogRepository) Get(db *gorm.DB, id int64) *models.SkillRunLog {
ret := &models.SkillRunLog{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *skillRunLogRepository) Take(db *gorm.DB, where ...interface{}) *models.SkillRunLog {
ret := &models.SkillRunLog{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *skillRunLogRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.SkillRunLog) {
cnd.Find(db, &list)
return
}
func (r *skillRunLogRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.SkillRunLog {
ret := &models.SkillRunLog{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *skillRunLogRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.SkillRunLog, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *skillRunLogRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.SkillRunLog, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.SkillRunLog{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *skillRunLogRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.SkillRunLog) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *skillRunLogRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *skillRunLogRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.SkillRunLog{})
}
func (r *skillRunLogRepository) Create(db *gorm.DB, t *models.SkillRunLog) (err error) {
err = db.Create(t).Error
return
}
func (r *skillRunLogRepository) Update(db *gorm.DB, t *models.SkillRunLog) (err error) {
err = db.Save(t).Error
return
}
func (r *skillRunLogRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.SkillRunLog{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *skillRunLogRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.SkillRunLog{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *skillRunLogRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.SkillRunLog{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var SystemConfigRepository = newSystemConfigRepository()
func newSystemConfigRepository() *systemConfigRepository {
return &systemConfigRepository{}
}
type systemConfigRepository struct {
}
func (r *systemConfigRepository) Get(db *gorm.DB, id int64) *models.SystemConfig {
ret := &models.SystemConfig{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *systemConfigRepository) Take(db *gorm.DB, where ...interface{}) *models.SystemConfig {
ret := &models.SystemConfig{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *systemConfigRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.SystemConfig) {
cnd.Find(db, &list)
return
}
func (r *systemConfigRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.SystemConfig {
ret := &models.SystemConfig{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *systemConfigRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.SystemConfig, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *systemConfigRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.SystemConfig, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.SystemConfig{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *systemConfigRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.SystemConfig) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *systemConfigRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *systemConfigRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.SystemConfig{})
}
func (r *systemConfigRepository) Create(db *gorm.DB, t *models.SystemConfig) (err error) {
err = db.Create(t).Error
return
}
func (r *systemConfigRepository) Update(db *gorm.DB, t *models.SystemConfig) (err error) {
err = db.Save(t).Error
return
}
func (r *systemConfigRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.SystemConfig{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *systemConfigRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.SystemConfig{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *systemConfigRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.SystemConfig{}, "id = ?", id)
}
+102
View File
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TagRepository = newTagRepository()
func newTagRepository() *tagRepository {
return &tagRepository{}
}
type tagRepository struct {
}
func (r *tagRepository) Get(db *gorm.DB, id int64) *models.Tag {
ret := &models.Tag{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *tagRepository) Take(db *gorm.DB, where ...interface{}) *models.Tag {
ret := &models.Tag{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *tagRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Tag) {
cnd.Find(db, &list)
return
}
func (r *tagRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Tag {
ret := &models.Tag{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *tagRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Tag, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *tagRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Tag, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Tag{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *tagRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.Tag) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *tagRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *tagRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Tag{})
}
func (r *tagRepository) Create(db *gorm.DB, t *models.Tag) (err error) {
err = db.Create(t).Error
return
}
func (r *tagRepository) Update(db *gorm.DB, t *models.Tag) (err error) {
err = db.Save(t).Error
return
}
func (r *tagRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Tag{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *tagRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Tag{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *tagRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Tag{}, "id = ?", id)
}
@@ -0,0 +1,83 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketCollaboratorRepository = newTicketCollaboratorRepository()
func newTicketCollaboratorRepository() *ticketCollaboratorRepository {
return &ticketCollaboratorRepository{}
}
type ticketCollaboratorRepository struct {
}
func (r *ticketCollaboratorRepository) TakeByTicketIDAndUserID(db *gorm.DB, ticketID, userID int64) *models.TicketCollaborator {
ret := &models.TicketCollaborator{}
if err := db.Take(ret, "ticket_id = ? AND user_id = ?", ticketID, userID).Error; err != nil {
return nil
}
return ret
}
func (r *ticketCollaboratorRepository) Get(db *gorm.DB, id int64) *models.TicketCollaborator {
ret := &models.TicketCollaborator{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketCollaboratorRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketCollaborator {
ret := &models.TicketCollaborator{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketCollaboratorRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketCollaborator) {
cnd.Find(db, &list)
return
}
func (r *ticketCollaboratorRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketCollaborator {
ret := &models.TicketCollaborator{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketCollaboratorRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketCollaborator, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketCollaboratorRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketCollaborator, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketCollaborator{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketCollaboratorRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketCollaborator{})
}
func (r *ticketCollaboratorRepository) Create(db *gorm.DB, t *models.TicketCollaborator) error {
return db.Create(t).Error
}
func (r *ticketCollaboratorRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketCollaborator{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketCommentRepository = newTicketCommentRepository()
func newTicketCommentRepository() *ticketCommentRepository {
return &ticketCommentRepository{}
}
type ticketCommentRepository struct {
}
func (r *ticketCommentRepository) Get(db *gorm.DB, id int64) *models.TicketComment {
ret := &models.TicketComment{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketCommentRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketComment {
ret := &models.TicketComment{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketCommentRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketComment) {
cnd.Find(db, &list)
return
}
func (r *ticketCommentRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketComment {
ret := &models.TicketComment{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketCommentRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketComment, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketCommentRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketComment, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketComment{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketCommentRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.TicketComment) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *ticketCommentRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *ticketCommentRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketComment{})
}
func (r *ticketCommentRepository) Create(db *gorm.DB, t *models.TicketComment) (err error) {
err = db.Create(t).Error
return
}
func (r *ticketCommentRepository) Update(db *gorm.DB, t *models.TicketComment) (err error) {
err = db.Save(t).Error
return
}
func (r *ticketCommentRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.TicketComment{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *ticketCommentRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.TicketComment{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *ticketCommentRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketComment{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketEventLogRepository = newTicketEventLogRepository()
func newTicketEventLogRepository() *ticketEventLogRepository {
return &ticketEventLogRepository{}
}
type ticketEventLogRepository struct {
}
func (r *ticketEventLogRepository) Get(db *gorm.DB, id int64) *models.TicketEventLog {
ret := &models.TicketEventLog{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketEventLogRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketEventLog {
ret := &models.TicketEventLog{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketEventLogRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketEventLog) {
cnd.Find(db, &list)
return
}
func (r *ticketEventLogRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketEventLog {
ret := &models.TicketEventLog{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketEventLogRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketEventLog, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketEventLogRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketEventLog, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketEventLog{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketEventLogRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.TicketEventLog) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *ticketEventLogRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *ticketEventLogRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketEventLog{})
}
func (r *ticketEventLogRepository) Create(db *gorm.DB, t *models.TicketEventLog) (err error) {
err = db.Create(t).Error
return
}
func (r *ticketEventLogRepository) Update(db *gorm.DB, t *models.TicketEventLog) (err error) {
err = db.Save(t).Error
return
}
func (r *ticketEventLogRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.TicketEventLog{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *ticketEventLogRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.TicketEventLog{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *ticketEventLogRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketEventLog{}, "id = ?", id)
}
@@ -0,0 +1,74 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketMentionRepository = newTicketMentionRepository()
func newTicketMentionRepository() *ticketMentionRepository {
return &ticketMentionRepository{}
}
type ticketMentionRepository struct {
}
func (r *ticketMentionRepository) TakeByCommentAndUserID(db *gorm.DB, ticketID, commentID, userID int64) *models.TicketMention {
ret := &models.TicketMention{}
if err := db.Take(ret, "ticket_id = ? AND comment_id = ? AND mentioned_user_id = ?", ticketID, commentID, userID).Error; err != nil {
return nil
}
return ret
}
func (r *ticketMentionRepository) Get(db *gorm.DB, id int64) *models.TicketMention {
ret := &models.TicketMention{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketMentionRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketMention {
ret := &models.TicketMention{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketMentionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketMention) {
cnd.Find(db, &list)
return
}
func (r *ticketMentionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketMention {
ret := &models.TicketMention{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketMentionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketMention, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketMentionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketMention, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketMention{})
paging = &sqls.Paging{Page: cnd.Paging.Page, Limit: cnd.Paging.Limit, Total: count}
return
}
func (r *ticketMentionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketMention{})
}
func (r *ticketMentionRepository) Create(db *gorm.DB, t *models.TicketMention) error {
return db.Create(t).Error
}
@@ -0,0 +1,38 @@
package repositories
import (
"cs-agent/internal/models"
"time"
"gorm.io/gorm"
)
var TicketNoSequenceRepository = newTicketNoSequenceRepository()
func newTicketNoSequenceRepository() *ticketNoSequenceRepository {
return &ticketNoSequenceRepository{}
}
type ticketNoSequenceRepository struct{}
func (r *ticketNoSequenceRepository) GetByDateKey(db *gorm.DB, dateKey string) *models.TicketNoSequence {
ret := &models.TicketNoSequence{}
if err := db.Take(ret, "date_key = ?", dateKey).Error; err != nil {
return nil
}
return ret
}
func (r *ticketNoSequenceRepository) Create(db *gorm.DB, t *models.TicketNoSequence) error {
return db.Create(t).Error
}
func (r *ticketNoSequenceRepository) UpdateNextSeq(db *gorm.DB, id int64, currentSeq, nextSeq int64, updatedAt time.Time) (bool, error) {
result := db.Model(&models.TicketNoSequence{}).
Where("id = ? AND next_seq = ?", id, currentSeq).
Updates(map[string]any{
"next_seq": nextSeq,
"updated_at": updatedAt,
})
return result.RowsAffected == 1, result.Error
}
@@ -0,0 +1,81 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketPriorityConfigRepository = newTicketPriorityConfigRepository()
func newTicketPriorityConfigRepository() *ticketPriorityConfigRepository {
return &ticketPriorityConfigRepository{}
}
type ticketPriorityConfigRepository struct{}
func (r *ticketPriorityConfigRepository) Get(db *gorm.DB, id int64) *models.TicketPriorityConfig {
ret := &models.TicketPriorityConfig{}
if err := db.First(ret, id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketPriorityConfigRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketPriorityConfig {
ret := &models.TicketPriorityConfig{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketPriorityConfigRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketPriorityConfig) {
cnd.Find(db, &list)
return
}
func (r *ticketPriorityConfigRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketPriorityConfig {
ret := &models.TicketPriorityConfig{}
if err := cnd.FindOne(db, ret); err != nil {
return nil
}
return ret
}
func (r *ticketPriorityConfigRepository) FindPageByParams(db *gorm.DB, queryParams *params.QueryParams) (list []models.TicketPriorityConfig, paging *sqls.Paging) {
return r.FindPageByCnd(db, &queryParams.Cnd)
}
func (r *ticketPriorityConfigRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketPriorityConfig, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketPriorityConfig{})
paging = &sqls.Paging{Page: cnd.Paging.Page, Limit: cnd.Paging.Limit, Total: count}
return
}
func (r *ticketPriorityConfigRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketPriorityConfig{})
}
func (r *ticketPriorityConfigRepository) Create(db *gorm.DB, t *models.TicketPriorityConfig) error {
return db.Create(t).Error
}
func (r *ticketPriorityConfigRepository) Update(db *gorm.DB, t *models.TicketPriorityConfig) error {
return db.Save(t).Error
}
func (r *ticketPriorityConfigRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
return db.Model(&models.TicketPriorityConfig{}).Where("id = ?", id).Updates(columns).Error
}
func (r *ticketPriorityConfigRepository) UpdateColumn(db *gorm.DB, id int64, name string, value any) error {
return db.Model(&models.TicketPriorityConfig{}).Where("id = ?", id).UpdateColumn(name, value).Error
}
func (r *ticketPriorityConfigRepository) Delete(db *gorm.DB, id int64) error {
return db.Delete(&models.TicketPriorityConfig{}, "id = ?", id).Error
}
@@ -0,0 +1,106 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketRelationRepository = newTicketRelationRepository()
func newTicketRelationRepository() *ticketRelationRepository {
return &ticketRelationRepository{}
}
type ticketRelationRepository struct {
}
func (r *ticketRelationRepository) Get(db *gorm.DB, id int64) *models.TicketRelation {
ret := &models.TicketRelation{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketRelationRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketRelation {
ret := &models.TicketRelation{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketRelationRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketRelation) {
cnd.Find(db, &list)
return
}
func (r *ticketRelationRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketRelation {
ret := &models.TicketRelation{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketRelationRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketRelation, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketRelationRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketRelation, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketRelation{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketRelationRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.TicketRelation) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *ticketRelationRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *ticketRelationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketRelation{})
}
func (r *ticketRelationRepository) Create(db *gorm.DB, t *models.TicketRelation) (err error) {
err = db.Create(t).Error
return
}
func (r *ticketRelationRepository) Update(db *gorm.DB, t *models.TicketRelation) (err error) {
err = db.Save(t).Error
return
}
func (r *ticketRelationRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.TicketRelation{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *ticketRelationRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.TicketRelation{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *ticketRelationRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketRelation{}, "id = ?", id)
}
func (r *ticketRelationRepository) DeleteByTicketRelation(db *gorm.DB, ticketID, relatedTicketID int64, relationType string) error {
return db.Where("ticket_id = ? AND related_ticket_id = ? AND relation_type = ?", ticketID, relatedTicketID, relationType).
Delete(&models.TicketRelation{}).Error
}
+102
View File
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketRepository = newTicketRepository()
func newTicketRepository() *ticketRepository {
return &ticketRepository{}
}
type ticketRepository struct {
}
func (r *ticketRepository) Get(db *gorm.DB, id int64) *models.Ticket {
ret := &models.Ticket{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketRepository) Take(db *gorm.DB, where ...interface{}) *models.Ticket {
ret := &models.Ticket{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Ticket) {
cnd.Find(db, &list)
return
}
func (r *ticketRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Ticket {
ret := &models.Ticket{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Ticket, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Ticket, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Ticket{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.Ticket) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *ticketRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *ticketRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Ticket{})
}
func (r *ticketRepository) Create(db *gorm.DB, t *models.Ticket) (err error) {
err = db.Create(t).Error
return
}
func (r *ticketRepository) Update(db *gorm.DB, t *models.Ticket) (err error) {
err = db.Save(t).Error
return
}
func (r *ticketRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.Ticket{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *ticketRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.Ticket{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *ticketRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.Ticket{}, "id = ?", id)
}
@@ -0,0 +1,81 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketResolutionCodeRepository = newTicketResolutionCodeRepository()
func newTicketResolutionCodeRepository() *ticketResolutionCodeRepository {
return &ticketResolutionCodeRepository{}
}
type ticketResolutionCodeRepository struct{}
func (r *ticketResolutionCodeRepository) Get(db *gorm.DB, id int64) *models.TicketResolutionCode {
ret := &models.TicketResolutionCode{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketResolutionCodeRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketResolutionCode {
ret := &models.TicketResolutionCode{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketResolutionCodeRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketResolutionCode) {
cnd.Find(db, &list)
return
}
func (r *ticketResolutionCodeRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketResolutionCode {
ret := &models.TicketResolutionCode{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketResolutionCodeRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketResolutionCode, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketResolutionCodeRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketResolutionCode, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketResolutionCode{})
paging = &sqls.Paging{Page: cnd.Paging.Page, Limit: cnd.Paging.Limit, Total: count}
return
}
func (r *ticketResolutionCodeRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketResolutionCode{})
}
func (r *ticketResolutionCodeRepository) Create(db *gorm.DB, t *models.TicketResolutionCode) error {
return db.Create(t).Error
}
func (r *ticketResolutionCodeRepository) Update(db *gorm.DB, t *models.TicketResolutionCode) error {
return db.Save(t).Error
}
func (r *ticketResolutionCodeRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) error {
return db.Model(&models.TicketResolutionCode{}).Where("id = ?", id).Updates(columns).Error
}
func (r *ticketResolutionCodeRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) error {
return db.Model(&models.TicketResolutionCode{}).Where("id = ?", id).UpdateColumn(name, value).Error
}
func (r *ticketResolutionCodeRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketResolutionCode{}, "id = ?", id)
}
@@ -0,0 +1,109 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketSLARecordRepository = newTicketSLARecordRepository()
func newTicketSLARecordRepository() *ticketSLARecordRepository {
return &ticketSLARecordRepository{}
}
type ticketSLARecordRepository struct {
}
func (r *ticketSLARecordRepository) TakeByTicketIDAndType(db *gorm.DB, ticketID int64, slaType string) *models.TicketSLARecord {
ret := &models.TicketSLARecord{}
if err := db.Take(ret, "ticket_id = ? AND sla_type = ?", ticketID, slaType).Error; err != nil {
return nil
}
return ret
}
func (r *ticketSLARecordRepository) Get(db *gorm.DB, id int64) *models.TicketSLARecord {
ret := &models.TicketSLARecord{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketSLARecordRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketSLARecord {
ret := &models.TicketSLARecord{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketSLARecordRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketSLARecord) {
cnd.Find(db, &list)
return
}
func (r *ticketSLARecordRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketSLARecord {
ret := &models.TicketSLARecord{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketSLARecordRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketSLARecord, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketSLARecordRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketSLARecord, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketSLARecord{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketSLARecordRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.TicketSLARecord) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *ticketSLARecordRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *ticketSLARecordRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketSLARecord{})
}
func (r *ticketSLARecordRepository) Create(db *gorm.DB, t *models.TicketSLARecord) (err error) {
err = db.Create(t).Error
return
}
func (r *ticketSLARecordRepository) Update(db *gorm.DB, t *models.TicketSLARecord) (err error) {
err = db.Save(t).Error
return
}
func (r *ticketSLARecordRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.TicketSLARecord{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *ticketSLARecordRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.TicketSLARecord{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *ticketSLARecordRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketSLARecord{}, "id = ?", id)
}
@@ -0,0 +1,73 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketTagRepository = newTicketTagRepository()
func newTicketTagRepository() *ticketTagRepository {
return &ticketTagRepository{}
}
type ticketTagRepository struct{}
func (r *ticketTagRepository) Get(db *gorm.DB, id int64) *models.TicketTag {
ret := &models.TicketTag{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketTagRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketTag {
ret := &models.TicketTag{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketTagRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketTag) {
cnd.Find(db, &list)
return
}
func (r *ticketTagRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketTag {
ret := &models.TicketTag{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketTagRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketTag, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketTagRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketTag, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketTag{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketTagRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketTag{})
}
func (r *ticketTagRepository) Create(db *gorm.DB, t *models.TicketTag) error {
return db.Create(t).Error
}
func (r *ticketTagRepository) DeleteByTicketID(db *gorm.DB, ticketID int64) error {
return db.Where("ticket_id = ?", ticketID).Delete(&models.TicketTag{}).Error
}
@@ -0,0 +1,83 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketViewRepository = newTicketViewRepository()
func newTicketViewRepository() *ticketViewRepository {
return &ticketViewRepository{}
}
type ticketViewRepository struct {
}
func (r *ticketViewRepository) Get(db *gorm.DB, id int64) *models.TicketView {
ret := &models.TicketView{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketViewRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketView {
ret := &models.TicketView{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketViewRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketView) {
cnd.Find(db, &list)
return
}
func (r *ticketViewRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketView {
ret := &models.TicketView{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketViewRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketView, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketViewRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketView, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketView{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketViewRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketView{})
}
func (r *ticketViewRepository) Create(db *gorm.DB, t *models.TicketView) error {
return db.Create(t).Error
}
func (r *ticketViewRepository) Update(db *gorm.DB, t *models.TicketView) error {
return db.Save(t).Error
}
func (r *ticketViewRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) error {
return db.Model(&models.TicketView{}).Where("id = ?", id).Updates(columns).Error
}
func (r *ticketViewRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketView{}, "id = ?", id)
}
@@ -0,0 +1,109 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var TicketWatcherRepository = newTicketWatcherRepository()
func newTicketWatcherRepository() *ticketWatcherRepository {
return &ticketWatcherRepository{}
}
type ticketWatcherRepository struct {
}
func (r *ticketWatcherRepository) TakeByTicketIDAndUserID(db *gorm.DB, ticketID, userID int64) *models.TicketWatcher {
ret := &models.TicketWatcher{}
if err := db.Take(ret, "ticket_id = ? AND user_id = ?", ticketID, userID).Error; err != nil {
return nil
}
return ret
}
func (r *ticketWatcherRepository) Get(db *gorm.DB, id int64) *models.TicketWatcher {
ret := &models.TicketWatcher{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *ticketWatcherRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketWatcher {
ret := &models.TicketWatcher{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *ticketWatcherRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketWatcher) {
cnd.Find(db, &list)
return
}
func (r *ticketWatcherRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketWatcher {
ret := &models.TicketWatcher{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *ticketWatcherRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketWatcher, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *ticketWatcherRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketWatcher, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.TicketWatcher{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *ticketWatcherRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.TicketWatcher) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *ticketWatcherRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *ticketWatcherRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.TicketWatcher{})
}
func (r *ticketWatcherRepository) Create(db *gorm.DB, t *models.TicketWatcher) (err error) {
err = db.Create(t).Error
return
}
func (r *ticketWatcherRepository) Update(db *gorm.DB, t *models.TicketWatcher) (err error) {
err = db.Save(t).Error
return
}
func (r *ticketWatcherRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.TicketWatcher{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *ticketWatcherRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.TicketWatcher{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *ticketWatcherRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.TicketWatcher{}, "id = ?", id)
}
@@ -0,0 +1,110 @@
package repositories
import (
"cs-agent/internal/models"
"cs-agent/internal/pkg/enums"
"strings"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var UserIdentityRepository = newUserIdentityRepository()
func newUserIdentityRepository() *userIdentityRepository {
return &userIdentityRepository{}
}
type userIdentityRepository struct {
}
func (r *userIdentityRepository) Get(db *gorm.DB, id int64) *models.UserIdentity {
ret := &models.UserIdentity{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *userIdentityRepository) Take(db *gorm.DB, where ...interface{}) *models.UserIdentity {
ret := &models.UserIdentity{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *userIdentityRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.UserIdentity) {
cnd.Find(db, &list)
return
}
func (r *userIdentityRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.UserIdentity {
ret := &models.UserIdentity{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *userIdentityRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.UserIdentity, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *userIdentityRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.UserIdentity, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.UserIdentity{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *userIdentityRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.UserIdentity) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *userIdentityRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *userIdentityRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.UserIdentity{})
}
func (r *userIdentityRepository) Create(db *gorm.DB, t *models.UserIdentity) (err error) {
err = db.Create(t).Error
return
}
func (r *userIdentityRepository) Update(db *gorm.DB, t *models.UserIdentity) (err error) {
err = db.Save(t).Error
return
}
func (r *userIdentityRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.UserIdentity{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *userIdentityRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.UserIdentity{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *userIdentityRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.UserIdentity{}, "id = ?", id)
}
func (r *userIdentityRepository) GetBy(db *gorm.DB, provider enums.ThirdProvider, corpId, userId string) *models.UserIdentity {
return r.FindOne(db, sqls.NewCnd().
Eq("provider", provider).
Eq("provider_corp_id", strings.TrimSpace(corpId)).
Eq("provider_user_id", strings.TrimSpace(userId)))
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var UserPermissionRepository = newUserPermissionRepository()
func newUserPermissionRepository() *userPermissionRepository {
return &userPermissionRepository{}
}
type userPermissionRepository struct {
}
func (r *userPermissionRepository) Get(db *gorm.DB, id int64) *models.UserPermission {
ret := &models.UserPermission{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *userPermissionRepository) Take(db *gorm.DB, where ...interface{}) *models.UserPermission {
ret := &models.UserPermission{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *userPermissionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.UserPermission) {
cnd.Find(db, &list)
return
}
func (r *userPermissionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.UserPermission {
ret := &models.UserPermission{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *userPermissionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.UserPermission, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *userPermissionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.UserPermission, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.UserPermission{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *userPermissionRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.UserPermission) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *userPermissionRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *userPermissionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.UserPermission{})
}
func (r *userPermissionRepository) Create(db *gorm.DB, t *models.UserPermission) (err error) {
err = db.Create(t).Error
return
}
func (r *userPermissionRepository) Update(db *gorm.DB, t *models.UserPermission) (err error) {
err = db.Save(t).Error
return
}
func (r *userPermissionRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.UserPermission{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *userPermissionRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.UserPermission{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *userPermissionRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.UserPermission{}, "id = ?", id)
}
+135
View File
@@ -0,0 +1,135 @@
package repositories
import (
"cs-agent/internal/models"
"strings"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var UserRepository = newUserRepository()
func newUserRepository() *userRepository {
return &userRepository{}
}
type userRepository struct {
}
func (r *userRepository) Get(db *gorm.DB, id int64) *models.User {
ret := &models.User{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *userRepository) Take(db *gorm.DB, where ...interface{}) *models.User {
ret := &models.User{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *userRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.User) {
cnd.Find(db, &list)
return
}
func (r *userRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.User {
ret := &models.User{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *userRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.User, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *userRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.User, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.User{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *userRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.User) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *userRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *userRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.User{})
}
func (r *userRepository) Create(db *gorm.DB, t *models.User) (err error) {
err = db.Create(t).Error
return
}
func (r *userRepository) Update(db *gorm.DB, t *models.User) (err error) {
err = db.Save(t).Error
return
}
func (r *userRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.User{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *userRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.User{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *userRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.User{}, "id = ?", id)
}
func (r *userRepository) FindByIds(db *gorm.DB, ids []int64) []models.User {
if len(ids) == 0 {
return []models.User{}
}
var list []models.User
db.Where("id IN ?", ids).Find(&list)
return list
}
func (r *userRepository) GetByUsername(db *gorm.DB, username string) *models.User {
username = strings.TrimSpace(username)
if username == "" {
return nil
}
return r.Take(db, "username = ?", username)
}
func (r *userRepository) GetByMobile(db *gorm.DB, mobile string) *models.User {
mobile = strings.TrimSpace(mobile)
if mobile == "" {
return nil
}
return r.Take(db, "mobile = ?", mobile)
}
func (r *userRepository) GetByEmail(db *gorm.DB, email string) *models.User {
email = strings.TrimSpace(email)
if email == "" {
return nil
}
return r.Take(db, "email = ?", email)
}
@@ -0,0 +1,101 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var UserRoleRepository = newUserRoleRepository()
func newUserRoleRepository() *userRoleRepository {
return &userRoleRepository{}
}
type userRoleRepository struct {
}
func (r *userRoleRepository) Get(db *gorm.DB, id int64) *models.UserRole {
ret := &models.UserRole{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *userRoleRepository) Take(db *gorm.DB, where ...interface{}) *models.UserRole {
ret := &models.UserRole{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *userRoleRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.UserRole) {
cnd.Find(db, &list)
return
}
func (r *userRoleRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.UserRole {
ret := &models.UserRole{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *userRoleRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.UserRole, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *userRoleRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.UserRole, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.UserRole{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *userRoleRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.UserRole) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *userRoleRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *userRoleRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.UserRole{})
}
func (r *userRoleRepository) Create(db *gorm.DB, t *models.UserRole) (err error) {
err = db.Create(t).Error
return
}
func (r *userRoleRepository) Update(db *gorm.DB, t *models.UserRole) (err error) {
err = db.Save(t).Error
return
}
func (r *userRoleRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.UserRole{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *userRoleRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.UserRole{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *userRoleRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.UserRole{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var WxWorkKFConversationRepository = newWxWorkKFConversationRepository()
func newWxWorkKFConversationRepository() *wxWorkKFConversationRepository {
return &wxWorkKFConversationRepository{}
}
type wxWorkKFConversationRepository struct {
}
func (r *wxWorkKFConversationRepository) Get(db *gorm.DB, id int64) *models.WxWorkKFConversation {
ret := &models.WxWorkKFConversation{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *wxWorkKFConversationRepository) Take(db *gorm.DB, where ...interface{}) *models.WxWorkKFConversation {
ret := &models.WxWorkKFConversation{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *wxWorkKFConversationRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.WxWorkKFConversation) {
cnd.Find(db, &list)
return
}
func (r *wxWorkKFConversationRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.WxWorkKFConversation {
ret := &models.WxWorkKFConversation{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *wxWorkKFConversationRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.WxWorkKFConversation, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *wxWorkKFConversationRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.WxWorkKFConversation, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.WxWorkKFConversation{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *wxWorkKFConversationRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.WxWorkKFConversation) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *wxWorkKFConversationRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *wxWorkKFConversationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.WxWorkKFConversation{})
}
func (r *wxWorkKFConversationRepository) Create(db *gorm.DB, t *models.WxWorkKFConversation) (err error) {
err = db.Create(t).Error
return
}
func (r *wxWorkKFConversationRepository) Update(db *gorm.DB, t *models.WxWorkKFConversation) (err error) {
err = db.Save(t).Error
return
}
func (r *wxWorkKFConversationRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.WxWorkKFConversation{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *wxWorkKFConversationRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.WxWorkKFConversation{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *wxWorkKFConversationRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.WxWorkKFConversation{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var WxWorkKFMessageRefRepository = newWxWorkKFMessageRefRepository()
func newWxWorkKFMessageRefRepository() *wxWorkKFMessageRefRepository {
return &wxWorkKFMessageRefRepository{}
}
type wxWorkKFMessageRefRepository struct {
}
func (r *wxWorkKFMessageRefRepository) Get(db *gorm.DB, id int64) *models.WxWorkKFMessageRef {
ret := &models.WxWorkKFMessageRef{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *wxWorkKFMessageRefRepository) Take(db *gorm.DB, where ...interface{}) *models.WxWorkKFMessageRef {
ret := &models.WxWorkKFMessageRef{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *wxWorkKFMessageRefRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.WxWorkKFMessageRef) {
cnd.Find(db, &list)
return
}
func (r *wxWorkKFMessageRefRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.WxWorkKFMessageRef {
ret := &models.WxWorkKFMessageRef{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *wxWorkKFMessageRefRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.WxWorkKFMessageRef, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *wxWorkKFMessageRefRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.WxWorkKFMessageRef, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.WxWorkKFMessageRef{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *wxWorkKFMessageRefRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.WxWorkKFMessageRef) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *wxWorkKFMessageRefRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *wxWorkKFMessageRefRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.WxWorkKFMessageRef{})
}
func (r *wxWorkKFMessageRefRepository) Create(db *gorm.DB, t *models.WxWorkKFMessageRef) (err error) {
err = db.Create(t).Error
return
}
func (r *wxWorkKFMessageRefRepository) Update(db *gorm.DB, t *models.WxWorkKFMessageRef) (err error) {
err = db.Save(t).Error
return
}
func (r *wxWorkKFMessageRefRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.WxWorkKFMessageRef{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *wxWorkKFMessageRefRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.WxWorkKFMessageRef{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *wxWorkKFMessageRefRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.WxWorkKFMessageRef{}, "id = ?", id)
}
@@ -0,0 +1,102 @@
package repositories
import (
"cs-agent/internal/models"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
"gorm.io/gorm"
)
var WxWorkKFSyncStateRepository = newWxWorkKFSyncStateRepository()
func newWxWorkKFSyncStateRepository() *wxWorkKFSyncStateRepository {
return &wxWorkKFSyncStateRepository{}
}
type wxWorkKFSyncStateRepository struct {
}
func (r *wxWorkKFSyncStateRepository) Get(db *gorm.DB, id int64) *models.WxWorkKFSyncState {
ret := &models.WxWorkKFSyncState{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *wxWorkKFSyncStateRepository) Take(db *gorm.DB, where ...interface{}) *models.WxWorkKFSyncState {
ret := &models.WxWorkKFSyncState{}
if err := db.Take(ret, where...).Error; err != nil {
return nil
}
return ret
}
func (r *wxWorkKFSyncStateRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.WxWorkKFSyncState) {
cnd.Find(db, &list)
return
}
func (r *wxWorkKFSyncStateRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.WxWorkKFSyncState {
ret := &models.WxWorkKFSyncState{}
if err := cnd.FindOne(db, &ret); err != nil {
return nil
}
return ret
}
func (r *wxWorkKFSyncStateRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.WxWorkKFSyncState, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *wxWorkKFSyncStateRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.WxWorkKFSyncState, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.WxWorkKFSyncState{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *wxWorkKFSyncStateRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (list []models.WxWorkKFSyncState) {
db.Raw(sqlStr, paramArr...).Scan(&list)
return
}
func (r *wxWorkKFSyncStateRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr... interface{}) (count int64) {
db.Raw(sqlStr, paramArr...).Count(&count)
return
}
func (r *wxWorkKFSyncStateRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.WxWorkKFSyncState{})
}
func (r *wxWorkKFSyncStateRepository) Create(db *gorm.DB, t *models.WxWorkKFSyncState) (err error) {
err = db.Create(t).Error
return
}
func (r *wxWorkKFSyncStateRepository) Update(db *gorm.DB, t *models.WxWorkKFSyncState) (err error) {
err = db.Save(t).Error
return
}
func (r *wxWorkKFSyncStateRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
err = db.Model(&models.WxWorkKFSyncState{}).Where("id = ?", id).Updates(columns).Error
return
}
func (r *wxWorkKFSyncStateRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
err = db.Model(&models.WxWorkKFSyncState{}).Where("id = ?", id).UpdateColumn(name, value).Error
return
}
func (r *wxWorkKFSyncStateRepository) Delete(db *gorm.DB, id int64) {
db.Delete(&models.WxWorkKFSyncState{}, "id = ?", id)
}