作者 yangfu

重构 去掉repository 添加模型方法注释

package repository
import "opp/models"
type IChanceRepository interface {
GetChanceById(id int64) (v *models.Chance, err error)
}
var _ IChanceRepository = (*ChanceRepository)(nil)
type ChanceRepository struct{}
func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) {
return models.GetChanceById(id)
}
type IChanceFavoriteRepository interface {
GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error)
ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error)
AddChanceFavorite(m *models.ChanceFavorite) (id int64, err error)
UpdateChanceFavorite(userId, companyId int64,sourceId int64,objectType int)error
GetChanceFavorite(userId, companyId int64,sourceId int64,sourceType int)(v *models.ChanceFavorite,err error)
}
var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil)
type ChanceFavoriteRepository struct{}
func (r *ChanceFavoriteRepository) GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) {
return models.GetChanceFavorites(userId, companyId, objectType, chanceType, lastId, pageSize)
}
func (r *ChanceFavoriteRepository) ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) {
return models.ExitsChanceFavorite(userId, companyId, sourceId, objectType)
}
func (r *ChanceFavoriteRepository) AddChanceFavorite(m *models.ChanceFavorite) (id int64, err error) {
return models.AddChanceFavorite(m)
}
func (r *ChanceFavoriteRepository) UpdateChanceFavorite(userId, companyId int64,sourceId int64,objectType int) error{
return models.UpdateChanceFavorite(userId,companyId,sourceId,objectType)
}
func (r *ChanceFavoriteRepository) GetChanceFavorite(userId, companyId int64,sourceId int64,sourceType int)(v *models.ChanceFavorite,err error){
return models.GetChanceFavorite(userId,companyId,sourceId,sourceType)
}
\ No newline at end of file
package repository
import "opp/models"
type ICommendRepository interface {
GetCommends(companyId int64, llastId int, pageSize int) (v []*models.Commend, total int, err error)
}
var _ ICommendRepository = (*CommendRepository)(nil)
type CommendRepository struct{}
func (r *CommendRepository) GetCommends(companyId int64, lastId int, pageSize int) (v []*models.Commend, total int, err error) {
return models.GetCommends(companyId, lastId, pageSize)
}
package repository
import "opp/models"
type ICommentRepository interface {
GetCommentById(id int64) (v *models.Comment, err error)
AddComment(m *models.Comment) (id int64, err error)
GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error)
}
var _ ICommentRepository = (*CommentRepository)(nil)
type CommentRepository struct{}
func (r *CommentRepository) GetCommentById(id int64) (v *models.Comment, err error) {
return models.GetCommentById(id)
}
func (r *CommentRepository) AddComment(m *models.Comment) (id int64, err error) {
return models.AddComment(m)
}
func (r *CommentRepository) GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error) {
return models.GetComments(userId, sourceType, sourceId, lastId, pageSize)
}
package repository
import "opp/models"
type ICompanyRepository interface {
GetCompanyById(companyId int64) (v *models.Company, err error)
}
var _ ICompanyRepository = (*CompanyRepository)(nil)
type CompanyRepository struct{}
func (r *CompanyRepository) GetCompanyById(companyId int64) (v *models.Company, err error) {
return models.GetCompanyById(companyId)
}
package repository
import "opp/models"
type IDepartmentRepository interface {
GetDepartmentById(companyId int) (v *models.Department, err error)
GetDepartmentByCompanyId(companyId int64) (v []*models.Department, err error)
}
var _ IDepartmentRepository = (*DepartmentRepository)(nil)
type DepartmentRepository struct{}
func (r *DepartmentRepository) GetDepartmentById(id int) (v *models.Department, err error) {
return models.GetDepartmentById(id)
}
func (r *DepartmentRepository) GetDepartmentByCompanyId(companyId int64) (v []*models.Department, err error) {
return models.GetDepartmentByCompanyId(companyId)
}
type IUserDepartmentRepository interface {
GetUserDepartment(userId int64, companyId int64, v interface{}) (err error)
}
type UserDepartmentRepository struct{}
func (r *UserDepartmentRepository) GetUserDepartment(userId int64, companyId int64, v interface{}) (err error) {
return models.GetUserDepartments(userId, companyId, v)
}
package repository
import "opp/models"
type IMessageRepository interface {
GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error)
UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error)
GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error)
}
var _ IMessageRepository = (*MessageRepository)(nil)
type MessageRepository struct{}
func (r *MessageRepository) GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) {
return models.GetUserMsgTotals(userId, companyId, msgType, v)
}
func (r *MessageRepository) UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) {
return models.UpdateUserMsgSetRead(userId, companyId, msgType, msgId)
}
func (r *MessageRepository) GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error) {
return models.GetUserMsgs(userId, companyId, msgType, sourceType, lastId, pageSize)
}
package repository
import "opp/models"
type IPositionRepository interface {
GetPositionById(companyId int) (v *models.Position, err error)
}
var _ IPositionRepository = (*PositionRepository)(nil)
type PositionRepository struct{}
func (r *PositionRepository) GetPositionById(id int) (v *models.Position, err error) {
return models.GetPositionById(id)
}
type IUserPositionRepository interface {
GetUserPositions(userId int64, companyId int64, v interface{}) (err error)
}
type UserPositionRepository struct{}
func (r *UserPositionRepository) GetUserPositions(userId int64, companyId int64, v interface{}) (err error) {
return models.GetUserPositions(userId, companyId, v)
}
package repository
import "sync"
//全局
var (
once sync.Once
//User IUserRepository
//UserAuth IUserAuthRepository
//Commend ICommendRepository
//Company ICompanyRepository
//Department IDepartmentRepository
//Position IPositionRepository
//Chance IChanceRepository
//ChanceFavorite IChanceFavoriteRepository
//Comment ICommentRepository
//Message IMessageRepository
//UserCompany IUserCompanyRepository
//UserPosition IUserPositionRepository
//UserDepartment IUserDepartmentRepository
)
func init() {
InitRepository()
}
func InitRepository() {
//User = &UserRepository{}
//UserAuth = &UserAuthRepository{}
//Commend = &CommendRepository{}
//Company = &CompanyRepository{}
//Department = &DepartmentRepository{}
//Position = &PositionRepository{}
//Chance = &ChanceRepository{}
//Comment = &CommentRepository{}
//Message = &MessageRepository{}
//ChanceFavorite = &ChanceFavoriteRepository{}
//UserCompany = &UserCompanyRepository{}
//UserPosition = &UserPositionRepository{}
//UserDepartment = &UserDepartmentRepository{}
}
func InitRepositoryMock() {
once.Do(func() {
//User = &UserMockRepository{}
//UserAuth = &UserAuthMockRepository{}
})
}
package repository
import "opp/models"
type IUserRepository interface {
GetUsersById(uid int64) (v *models.User, err error)
GetUsersByMobile(mobile string) (v *models.User, err error)
UpdateUserInfo(m *models.User) (err error)
}
var _ IUserRepository = (*UserRepository)(nil)
type UserRepository struct{}
func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) {
return models.GetUsersById(uid)
}
func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) {
return models.GetUserByMobile(mobile)
}
func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) {
return models.UpdateUsersById(m)
}
type IUserCompanyRepository interface {
GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error)
}
var _ IUserCompanyRepository = (*UserCompanyRepository)(nil)
type UserCompanyRepository struct{}
func (r *UserCompanyRepository) GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error) {
return models.GetUserCompanyByUserId(uid, companyId)
}
package repository
import "opp/models"
type IUserAuthRepository interface {
GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error)
UpdateUserAuthById(m *models.UserAuth) (err error)
GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error)
GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error)
GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error)
AddUserAuth(m *models.UserAuth) (err error)
}
var _ IUserAuthRepository = (*UserAuthRepository)(nil)
type UserAuthRepository struct{}
func (r *UserAuthRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) {
return models.GetUserAuthByUserId(uid, deviceType)
}
func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) {
return models.UpdateUserAuthById(m)
}
func (r *UserAuthRepository) AddUserAuth(m *models.UserAuth) (err error) {
_, err = models.AddUserAuth(m)
return
}
func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) {
return models.GetUserByAuthCode(authCode)
}
func (r *UserAuthRepository) GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) {
return models.GetUserAuthByRefreshToken(refreshToken)
}
func (r *UserAuthRepository) GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) {
return models.GetUserAuthByToken(refreshToken)
}
package repository
import "opp/models"
var userAuth = &models.UserAuth{
AuthCode: "897ca746f46b11e98771000c29ad8d6d",
AccessToken: "897ca746f46b11e98771000c29ad8d7d",
RefreshToken: "897ca746f46b11e98771000c29ad8d8d",
}
type UserAuthMockRepository struct{}
func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) {
v = userAuth
return
}
func (r *UserAuthMockRepository) UpdateUserAuthById(m *models.UserAuth) (err error) {
return
}
func (r *UserAuthMockRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) {
v = userAuth
return
}
func (r *UserAuthMockRepository) GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) {
v = userAuth
return
}
func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) {
v = userAuth
return
}
func (r *UserAuthMockRepository) AddUserAuth(m *models.UserAuth) (err error) {
//_,err =models.AddUserAuth(m)
return
}
package repository
import "opp/models"
type UserMockRepository struct{}
var userInfo = &models.UserAuth{
AuthCode: "897ca746f46b11e98771000c29ad8d6d",
AccessToken: "897ca746f46b11e98771000c29ad8d7d",
RefreshToken: "897ca746f46b11e98771000c29ad8d8d",
}
var user = &models.User{
Phone: "18065048389",
Passwd: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy",
}
func (r *UserMockRepository) GetUsersById(uid int64) (v *models.User, err error) {
v = user
return
}
func (r *UserMockRepository) GetUsersByMobile(mobile string) (v *models.User, err error) {
v = user
return
}
func (r *UserMockRepository) UpdateUserInfo(m *models.User) (err error) {
return
}
... ... @@ -79,6 +79,7 @@ func DeleteAuditFlowConfig(id int) (err error) {
return
}
//审核配置信息列表
func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowConfig, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_config where audit_template_id=? and audit_group_id=? order by level"
... ... @@ -88,6 +89,8 @@ func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowCo
return
}
//按 1.模板编号 2.审核等级
//查询审核配置列表
func GetAuditFlowConfigsLevel(auditTemplateId int64, level int) (v []*AuditFlowConfig, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_config where audit_template_id=? and level=?"
... ...
... ... @@ -83,6 +83,8 @@ func DeleteAuditForm(id int) (err error) {
return
}
//按1.公司编号 2.模板编号
//获取表单列表
func GetAuditForms(companyId int64, auditTemplateId int64) (v []*AuditForm, err error) {
o := orm.NewOrm()
sql := `select * from audit_form where company_id=? and audit_template_id=? and enable_status=1
... ...
... ... @@ -10,7 +10,7 @@ import (
type AuditTemplate struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
... ... @@ -80,10 +80,12 @@ func DeleteAuditTemplate(id int64) (err error) {
return
}
func GetAuditTemplates(companyId int64, chanceType int) (v []*AuditTemplate, err error) {
//按 1.公司编号 2.机会类型编号
//获取审核模板列表
func GetAuditTemplates(companyId int64, chanceTypeId int) (v []*AuditTemplate, err error) {
o := orm.NewOrm()
sql := "select * from audit_template where company_id=? and chance_type_id=? and enable_status=1"
if _, err = o.Raw(sql, companyId, chanceType).QueryRows(&v); err == nil {
if _, err = o.Raw(sql, companyId, chanceTypeId).QueryRows(&v); err == nil {
return
}
return
... ...
... ... @@ -65,10 +65,12 @@ func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) {
return
}
func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) {
//按 1.公告编号
//获取公告问题
func GetBulletinQuestionBy(bulletinId int) (v *BulletinQuestion, err error) {
o := orm.NewOrm()
sql := "select * from bulletin_question where bulletin_id=?"
if err = o.Raw(sql, id).QueryRow(&v); err == nil {
if err = o.Raw(sql, bulletinId).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
... ...
... ... @@ -80,10 +80,12 @@ func DeleteBulletinQuestionAnswer(id int) (err error) {
return
}
func GetBulletinQuestionAnswerBy(bulletinId int, uid int64) (v *BulletinQuestionAnswer, err error) {
//按 1.公告编号 2.用户公司id
//获取用户公告问题回答
func GetBulletinQuestionAnswerBy(bulletinId int, ucid int64) (v *BulletinQuestionAnswer, err error) {
o := orm.NewOrm()
sql := "select * from bulletin_question_answer where bulletin_id=? and uid=?"
if err = o.Raw(sql, bulletinId, uid).QueryRow(&v); err == nil {
if err = o.Raw(sql, bulletinId, ucid).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
type Chance struct {
Id int64 `orm:"column(id);pk" description:"id 主键"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"`
DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "`
AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"`
Content string `orm:"column(content)" description:"格式化后的文本内容"`
SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"`
ViewTotal int `orm:"column(view_total)" description:"查看总数"`
Id int64 `orm:"column(id);pk" description:"id 主键"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"`
DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "`
AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"`
Content string `orm:"column(content)" description:"格式化后的文本内容"`
SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"`
ViewTotal int `orm:"column(view_total)" description:"查看总数"`
CommentTotal int `orm:"column(comment_total)" description:"评论总数"`
ZanTotal int `orm:"column(zan_total)" description:"点赞总数"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待处理 1:待审核 2:被退回 3:已通过 "`
... ... @@ -62,84 +59,6 @@ func GetChanceById(id int64) (v *Chance, err error) {
return nil, err
}
// GetAllChance retrieves all Chance matches certain condition. Returns empty list if
// no records exist
func GetAllChance(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Chance))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Chance
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateChance updates Chance by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceById(m *Chance) (err error) {
... ...
... ... @@ -8,7 +8,7 @@ import (
)
type ChanceData struct {
Id int64 `orm:"column(id)" description:"唯一编号"`
Id int64 `orm:"column(id)" description:"唯一编号"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
Images string `orm:"column(images);size(1000);null" description:"图片 json"`
Speechs string `orm:"column(speechs);size(1000);null" description:"语音 json"`
... ... @@ -74,11 +74,13 @@ func DeleteChanceData(id int64) (err error) {
return
}
//按 1.机会编号
//获取机会数据 (多媒体)
func GetChanceDataByChanceId(chanceId int64) (v *ChanceData, err error) {
o := orm.NewOrm()
sql :=`select * from chance_data where chance_id=?`
if err = o.Raw(sql,chanceId).QueryRow(&v); err == nil {
sql := `select * from chance_data where chance_id=?`
if err = o.Raw(sql, chanceId).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
\ No newline at end of file
}
... ...
... ... @@ -13,7 +13,7 @@ type ChanceFavorite struct {
Id int64 `orm:"column(id);pk" description:"点赞编号"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
CompanyId int64 `orm:"column(company_id)" description:"company.id 公司编号"`
MarkFlag int `orm:"column(mark_flag)" description:"类型 1:点赞 2:收藏"`
MarkFlag int `orm:"column(mark_flag)" description:"类型 1:点赞 2:收藏"`
SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"`
SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"`
ChanceType int `orm:"column(chance_type)" description:"机会类型编号 - 附加 "`
... ... @@ -79,6 +79,8 @@ func DeleteChanceFavorite(id int64) (err error) {
return
}
//按1.用户id 2.公司id 3.标记类型 4.机会类型编号 5.最后编号 6.页数
//获取用户点赞收藏机会
func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc")
sql.Where(fmt.Sprintf("user_id=%d", userId))
... ... @@ -103,34 +105,35 @@ func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastI
}
//是否已经点赞/收藏 机会
func ExitsChanceFavorite(userId, companyId int64, sourceId int64, markFlag int) (exits bool, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite")
sql.Where(fmt.Sprintf("source_id=%d", sourceId)).
Where(fmt.Sprintf("user_id=%d", userId)).
Where(fmt.Sprintf("company_id=%d", companyId)).
Where(fmt.Sprintf("enable_status=1"))
if markFlag>0{
if markFlag > 0 {
sql.Where(fmt.Sprintf("(mark_flag&%d)>0", markFlag))
}
return sql.QueryExists()
}
func UpdateChanceFavorite(userId, companyId int64,sourceId int64,markFlag int)(err error){
//更新机会点赞/收藏状态
func UpdateChanceFavorite(userId, companyId int64, sourceId int64, markFlag int) (err error) {
o := orm.NewOrm()
sql := `update chance_favorite set mark_flag = mark_flag ^ ?
where user_id =? and company_id =? and source_id=? ` //
if _,err = o.Raw(sql,markFlag,userId,companyId,sourceId).Exec(); err == nil {
if _, err = o.Raw(sql, markFlag, userId, companyId, sourceId).Exec(); err == nil {
return
}
return
}
func GetChanceFavorite(userId, companyId int64,sourceId int64,sourceType int)(v *ChanceFavorite,err error){
o :=orm.NewOrm()
sql :=`select * from chance_favorite where user_id =? and company_id =? and source_id=? and source_type=?`
if err = o.Raw(sql,userId,companyId,sourceId,sourceType).QueryRow(&v);err!=nil{
func GetChanceFavorite(userId, companyId int64, sourceId int64, sourceType int) (v *ChanceFavorite, err error) {
o := orm.NewOrm()
sql := `select * from chance_favorite where user_id =? and company_id =? and source_id=? and source_type=?`
if err = o.Raw(sql, userId, companyId, sourceId, sourceType).QueryRow(&v); err != nil {
return
}
return
}
\ No newline at end of file
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceImage struct {
Id int64 `orm:"column(id);auto" description:"唯一编号"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
Path string `orm:"column(path);size(500)" description:"路径"`
W int `orm:"column(w);null" description:"宽"`
H int `orm:"column(h);null" description:"高"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
}
func (t *ChanceImage) TableName() string {
return "chance_image"
}
func init() {
orm.RegisterModel(new(ChanceImage))
}
// AddChanceImage insert a new ChanceImage into database and returns
// last inserted Id on success.
func AddChanceImage(m *ChanceImage) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceImageById retrieves ChanceImage by Id. Returns error if
// Id doesn't exist
func GetChanceImageById(id int64) (v *ChanceImage, err error) {
o := orm.NewOrm()
v = &ChanceImage{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceImage updates ChanceImage by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceImageById(m *ChanceImage) (err error) {
o := orm.NewOrm()
v := ChanceImage{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceImage deletes ChanceImage by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceImage(id int64) (err error) {
o := orm.NewOrm()
v := ChanceImage{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceImage{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceSpeech struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
Duration int `orm:"column(duration);null" description:"秒数"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
Path string `orm:"column(path);size(500);null" description:"语音路径"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
}
func (t *ChanceSpeech) TableName() string {
return "chance_speech"
}
func init() {
orm.RegisterModel(new(ChanceSpeech))
}
// AddChanceSpeech insert a new ChanceSpeech into database and returns
// last inserted Id on success.
func AddChanceSpeech(m *ChanceSpeech) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceSpeechById retrieves ChanceSpeech by Id. Returns error if
// Id doesn't exist
func GetChanceSpeechById(id int64) (v *ChanceSpeech, err error) {
o := orm.NewOrm()
v = &ChanceSpeech{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceSpeech updates ChanceSpeech by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceSpeechById(m *ChanceSpeech) (err error) {
o := orm.NewOrm()
v := ChanceSpeech{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceSpeech deletes ChanceSpeech by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceSpeech(id int64) (err error) {
o := orm.NewOrm()
v := ChanceSpeech{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceSpeech{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ... @@ -3,12 +3,17 @@ package models
import (
"fmt"
"github.com/astaxie/beego/orm"
"time"
)
type ChanceType struct {
Id int `orm:"column(id);auto" json:"id"`
Name string `orm:"column(name);size(50)" description:"机会类型名称" json:"name"`
Icon string `orm:"column(icon);size(500);null" description:"图标地址" json:"icon"`
Id int `orm:"column(id);auto"`
Name string `orm:"column(name);size(50)" description:"机会类型名称"`
Icon string `orm:"column(icon);size(500);null" description:"图标地址"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
SortNum int `orm:"column(sort_num);null" description:"序号 公司下的序号"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 "`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 "`
}
func (t *ChanceType) TableName() string {
... ... @@ -68,10 +73,11 @@ func DeleteChanceType(id int) (err error) {
return
}
func GetChanceTypeAll() (v []*ChanceType, err error) {
//获取所有机会类型
func GetChanceTypeAll(companyId int64) (v []*ChanceType, err error) {
o := orm.NewOrm()
sql := "select * from chance_type "
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
sql := "select * from chance_type where company_id=? order by sort_num"
if _, err = o.Raw(sql).QueryRows(&v, companyId); err == nil {
return
}
return
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceVideo struct {
Id int64 `orm:"column(id);auto"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会id"`
Path string `orm:"column(path);size(500);null" description:"路径"`
Cover string `orm:"column(cover);size(500);null" description:"封面"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
}
func (t *ChanceVideo) TableName() string {
return "chance_video"
}
func init() {
orm.RegisterModel(new(ChanceVideo))
}
// AddChanceVideo insert a new ChanceVideo into database and returns
// last inserted Id on success.
func AddChanceVideo(m *ChanceVideo) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceVideoById retrieves ChanceVideo by Id. Returns error if
// Id doesn't exist
func GetChanceVideoById(id int64) (v *ChanceVideo, err error) {
o := orm.NewOrm()
v = &ChanceVideo{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceVideo updates ChanceVideo by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceVideoById(m *ChanceVideo) (err error) {
o := orm.NewOrm()
v := ChanceVideo{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceVideo deletes ChanceVideo by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceVideo(id int64) (err error) {
o := orm.NewOrm()
v := ChanceVideo{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceVideo{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
package models
import (
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -48,84 +45,6 @@ func GetCommendById(id int64) (v *Commend, err error) {
return nil, err
}
// GetAllCommend retrieves all Commend matches certain condition. Returns empty list if
// no records exist
func GetAllCommend(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Commend))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Commend
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateCommend updates Commend by Id and returns error if
// the record to be updated doesn't exist
func UpdateCommendById(m *Commend) (err error) {
... ... @@ -156,6 +75,7 @@ func DeleteCommend(id int64) (err error) {
return
}
//获取表彰列表
func GetCommends(companyId int64, lastId int, pageSize int) (v []*Commend, total int, err error) {
sql := mybeego.NewSqlExutor().Table("commend").Order("create_at desc")
sql.Where(fmt.Sprintf("company_id=%d", companyId))
... ...
package models
import (
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -51,84 +48,6 @@ func GetCommentById(id int64) (v *Comment, err error) {
return nil, err
}
// GetAllComment retrieves all Comment matches certain condition. Returns empty list if
// no records exist
func GetAllComment(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Comment))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Comment
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateComment updates Comment by Id and returns error if
// the record to be updated doesn't exist
func UpdateCommentById(m *Comment) (err error) {
... ... @@ -159,6 +78,7 @@ func DeleteComment(id int64) (err error) {
return
}
//获取评论列表
func GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*Comment, total int, err error) {
sql := mybeego.NewSqlExutor().Table("comment").Order("create_at desc")
if userId > 0 {
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -48,84 +45,6 @@ func GetCompanyById(id int64) (v *Company, err error) {
return nil, err
}
// GetAllCompany retrieves all Company matches certain condition. Returns empty list if
// no records exist
func GetAllCompany(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Company))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Company
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateCompany updates Company by Id and returns error if
// the record to be updated doesn't exist
func UpdateCompanyById(m *Company) (err error) {
... ... @@ -156,6 +75,7 @@ func DeleteCompany(id int64) (err error) {
return
}
//获取用户有权限的公司列表
func GetCompanyByPermission(uid int64) (v []*Company, err error) {
o := orm.NewOrm()
sql := `select * from company where id in(
... ...
... ... @@ -77,6 +77,8 @@ func DeleteDepartment(id int) (err error) {
return
}
//按 1.公司编号
//获取部门列表
func GetDepartmentByCompanyId(companyId int64) (v []*Department, err error) {
o := orm.NewOrm()
sql := `
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -48,84 +45,6 @@ func GetPositionById(id int) (v *Position, err error) {
return nil, err
}
// GetAllPosition retrieves all Position matches certain condition. Returns empty list if
// no records exist
func GetAllPosition(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Position))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Position
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdatePosition updates Position by Id and returns error if
// the record to be updated doesn't exist
func UpdatePositionById(m *Position) (err error) {
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -55,84 +52,6 @@ func GetUserAuthById(id int) (v *UserAuth, err error) {
return nil, err
}
// GetAllUserAuth retrieves all UserAuth matches certain condition. Returns empty list if
// no records exist
func GetAllUserAuth(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(UserAuth))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []UserAuth
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateUserAuth updates UserAuth by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserAuthById(m *UserAuth) (err error) {
... ... @@ -163,6 +82,8 @@ func DeleteUserAuth(id int) (err error) {
return
}
//按 authcode
//获取用户权限信息
func GetUserByAuthCode(authCode string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where auth_code=? and auth_code_exp >= Now()"
... ... @@ -172,6 +93,8 @@ func GetUserByAuthCode(authCode string) (v *UserAuth, err error) {
return nil, err
}
//按 refreshToken
//获取用户权限信息
func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" //
... ... @@ -181,6 +104,8 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
return nil, err
}
//按 token
//获取用户权限信息
func GetUserAuthByToken(token string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where access_token=? and access_token_exp >= Now()"
... ... @@ -191,7 +116,7 @@ func GetUserAuthByToken(token string) (v *UserAuth, err error) {
}
// GetUserAuthById retrieves UserAuth by Id. Returns error if
// Id doesn't exist
// 获取用户权限信息
func GetUserAuthByUserId(uid int64, deviceType int) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where user_id=? and device_type=?"
... ...
... ... @@ -87,7 +87,8 @@ func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err err
return nil, err
}
//按user_company.id获取公司信息
//按用户公司编号 公司编号获取用户信息
//获取公司信息
func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) {
o := orm.NewOrm()
sql := "select * from user_company where id=? and company_id=? and enable=1" //
... ... @@ -97,7 +98,9 @@ func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) {
return nil, err
}
func GetUserCompanys(uid int64) (v *UserCompany, err error) {
//按用户编号
//获取用户第一个有效公司
func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) {
o := orm.NewOrm()
sql := "select * from user_company where user_id=? and enable=1 order by create_at desc limit 1" //
if err = o.Raw(sql, uid).QueryRow(&v); err == nil {
... ...
... ... @@ -73,6 +73,8 @@ func DeleteUserDepartment(id int64) (err error) {
return
}
//1.按用户公司编号 2.公司编号
//获取部门列表
func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `
... ...
... ... @@ -34,9 +34,12 @@ const (
SourceTypeBulletin = 3
)
const (
SqlUserMsgsUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //所有未读消息
SqlUserMsgUnRead = "select * from user_msg where source_id=? and company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //特定未读消息
SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
//用户未读消息列表
SqlUserMsgsUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //所有未读消息
//用户未读消息 - 单个
SqlUserMsgUnRead = "select * from user_msg where source_id=? and company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //特定未读消息
//用户消息 - 按 1.源id 2.接收者id 3.消息类型
SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
)
func (t *UserMsg) TableName() string {
... ... @@ -96,6 +99,7 @@ func DeleteUserMsg(id int64) (err error) {
return
}
//消息总数
func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) {
o := orm.NewOrm()
sql := `select COUNT(*) as total,msg_type from user_msg
... ... @@ -107,6 +111,7 @@ GROUP BY msg_type`
return
}
//标记消息已读
func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) {
o := orm.NewOrm()
sql := `update user_msg set is_read = 1
... ... @@ -123,6 +128,7 @@ func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int6
return
}
//获取用户消息列表
func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId int64, pageSize int) (v []*UserMsg, total int, err error) {
sql := mybeego.NewSqlExutor().Table("user_msg").Order("create_at desc")
if lastId > 0 {
... ... @@ -145,6 +151,7 @@ func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId in
return
}
//获取公告消息列表
func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select b.id,b.title,unix_timestamp(b.update_at) update_at,a.is_read `
sqlCount := `select count(0) `
... ...
... ... @@ -73,6 +73,7 @@ func DeleteUserPosition(id int) (err error) {
return
}
//获取用户岗位列表
func GetUserPositions(id int64, companyId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `
... ...
... ... @@ -83,6 +83,8 @@ func DeleteUsers(id int64) (err error) {
return
}
//按手机号
//获取用户信息
func GetUserByMobile(mobile string) (v *User, err error) {
o := orm.NewOrm()
sql := "select * from user where phone=? and enable_status=1"
... ... @@ -92,6 +94,8 @@ func GetUserByMobile(mobile string) (v *User, err error) {
return nil, err
}
//按统一用户中心编号
//获取用户信息
func GetUserByUcenterId(uid int64) (v *User, err error) {
o := orm.NewOrm()
sql := "select * from user where user_center_id=? and enable_status=1"
... ... @@ -100,12 +104,3 @@ func GetUserByUcenterId(uid int64) (v *User, err error) {
}
return nil, err
}
func GetUserByRole(roleId int) (v []*User, err error) {
o := orm.NewOrm()
sql := `select * from user where is_kefu = 1 and enable_status=1`
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -145,7 +145,7 @@ END:
func ChanceType(header *protocol.RequestHeader, request *protocol.ChanceTypeRequest) (rsp *protocol.ChanceTypeResponse, err error) {
var ()
rsp = &protocol.ChanceTypeResponse{}
if rsp.List, err = models.GetChanceTypeAll(); err != nil {
if rsp.List, err = models.GetChanceTypeAll(header.CompanyId); err != nil {
return
}
return
... ... @@ -553,56 +553,3 @@ func getParentDepartmentors(pid int) (ids []int64) {
}
return getParentDepartmentors(department.ParentId)
}
////获取角色对应用户列表
//func getRolesUser(header *protocol.RequestHeader,toRoles string)(ids []int64){
// var roles []int
// if err :=json.Unmarshal([]byte(toRoles),&roles);err!=nil{
// log.Error(err)
// return
// }
// for i:=range roles{
//
// }
// return
//}
func GenSpeechs(id int64, objs []protocol.Speech) (v []*models.ChanceSpeech) {
for i := range objs {
v = append(v, &models.ChanceSpeech{
Id: idgen.Next(),
Duration: objs[i].Duration,
Path: objs[i].Path,
ChanceId: id,
CreateAt: time.Now(),
})
}
return
}
func GenVideos(id int64, objs []protocol.Video) (v []*models.ChanceVideo) {
for i := range objs {
v = append(v, &models.ChanceVideo{
Id: idgen.Next(),
Path: objs[i].Path,
ChanceId: id,
Cover: objs[i].Cover,
CreateAt: time.Now(),
})
}
return
}
func GenImages(id int64, objs []protocol.Picture) (v []*models.ChanceImage) {
for i := range objs {
v = append(v, &models.ChanceImage{
Id: idgen.Next(),
Path: objs[i].Path,
ChanceId: id,
W: objs[i].W,
H: objs[i].H,
CreateAt: time.Now(),
})
}
return
}
... ...
... ... @@ -211,7 +211,7 @@ func H5Announcement(header *protocol.RequestHeader, request *protocol.Announceme
IsRead: int(userMsg.IsRead),
}
if bulletin.QuestionSwitch == 1 {
if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
if question, err = models.GetBulletinQuestionBy(bulletin.Id); err != nil {
log.Error(err.Error())
return
}
... ...
... ... @@ -257,7 +257,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
}
if companyId == 0 {
if userCompany, err = models.GetUserCompanys(header.Uid); err != nil {
if userCompany, err = models.GetUserCompanysFirst(header.Uid); err != nil {
log.Error(err)
return
}
... ...