2022-03-01 13:50:13 +08:00
|
|
|
package dao
|
|
|
|
|
|
|
|
import (
|
2023-01-18 17:09:49 +08:00
|
|
|
"cutego/modules/core/entity"
|
2022-03-01 13:50:13 +08:00
|
|
|
"cutego/pkg/common"
|
2023-01-18 17:09:49 +08:00
|
|
|
"cutego/refs"
|
2022-03-01 13:50:13 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type UserPostDao struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// BatchInsert 批量新增用户岗位信息
|
2023-01-18 17:09:49 +08:00
|
|
|
func (d UserPostDao) BatchInsert(posts []entity.SysUserPost) {
|
|
|
|
session := refs.SqlDB.NewSession()
|
2022-03-01 13:50:13 +08:00
|
|
|
session.Begin()
|
2023-01-18 17:09:49 +08:00
|
|
|
_, err := session.Table(entity.SysUserPost{}.TableName()).Insert(&posts)
|
2022-03-01 13:50:13 +08:00
|
|
|
if err != nil {
|
|
|
|
common.ErrorLog(err)
|
|
|
|
session.Rollback()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
session.Commit()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete 删除用户和岗位关系
|
|
|
|
func (d UserPostDao) Delete(id int64) {
|
2023-01-18 17:09:49 +08:00
|
|
|
post := entity.SysUserPost{
|
2022-03-01 13:50:13 +08:00
|
|
|
UserId: id,
|
|
|
|
}
|
2023-01-18 17:09:49 +08:00
|
|
|
session := refs.SqlDB.NewSession()
|
2022-03-01 13:50:13 +08:00
|
|
|
session.Begin()
|
|
|
|
_, err := session.Delete(&post)
|
|
|
|
if err != nil {
|
|
|
|
common.ErrorLog(err)
|
|
|
|
session.Rollback()
|
|
|
|
}
|
|
|
|
session.Commit()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CountById 通过岗位ID查询岗位使用数量
|
|
|
|
func (d UserPostDao) CountById(id int64) int64 {
|
2023-01-18 17:09:49 +08:00
|
|
|
count, err := refs.SqlDB.NewSession().Table("sys_user_post").Cols("post_id").Where("post_id = ?", id).Count()
|
2022-03-01 13:50:13 +08:00
|
|
|
if err != nil {
|
|
|
|
common.ErrorLog(err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|