正在显示
38 个修改的文件
包含
96 行增加
和
1191 行删除
internal/repository/chance.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type IChanceRepository interface { | ||
| 6 | - GetChanceById(id int64) (v *models.Chance, err error) | ||
| 7 | -} | ||
| 8 | - | ||
| 9 | -var _ IChanceRepository = (*ChanceRepository)(nil) | ||
| 10 | - | ||
| 11 | -type ChanceRepository struct{} | ||
| 12 | - | ||
| 13 | -func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) { | ||
| 14 | - return models.GetChanceById(id) | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | -type IChanceFavoriteRepository interface { | ||
| 18 | - GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) | ||
| 19 | - ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) | ||
| 20 | - AddChanceFavorite(m *models.ChanceFavorite) (id int64, err error) | ||
| 21 | - UpdateChanceFavorite(userId, companyId int64,sourceId int64,objectType int)error | ||
| 22 | - GetChanceFavorite(userId, companyId int64,sourceId int64,sourceType int)(v *models.ChanceFavorite,err error) | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil) | ||
| 26 | - | ||
| 27 | -type ChanceFavoriteRepository struct{} | ||
| 28 | - | ||
| 29 | -func (r *ChanceFavoriteRepository) GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) { | ||
| 30 | - return models.GetChanceFavorites(userId, companyId, objectType, chanceType, lastId, pageSize) | ||
| 31 | -} | ||
| 32 | -func (r *ChanceFavoriteRepository) ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) { | ||
| 33 | - return models.ExitsChanceFavorite(userId, companyId, sourceId, objectType) | ||
| 34 | -} | ||
| 35 | -func (r *ChanceFavoriteRepository) AddChanceFavorite(m *models.ChanceFavorite) (id int64, err error) { | ||
| 36 | - return models.AddChanceFavorite(m) | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -func (r *ChanceFavoriteRepository) UpdateChanceFavorite(userId, companyId int64,sourceId int64,objectType int) error{ | ||
| 40 | - return models.UpdateChanceFavorite(userId,companyId,sourceId,objectType) | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | - | ||
| 44 | -func (r *ChanceFavoriteRepository) GetChanceFavorite(userId, companyId int64,sourceId int64,sourceType int)(v *models.ChanceFavorite,err error){ | ||
| 45 | - return models.GetChanceFavorite(userId,companyId,sourceId,sourceType) | ||
| 46 | -} |
internal/repository/commend.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type ICommendRepository interface { | ||
| 6 | - GetCommends(companyId int64, llastId int, pageSize int) (v []*models.Commend, total int, err error) | ||
| 7 | -} | ||
| 8 | - | ||
| 9 | -var _ ICommendRepository = (*CommendRepository)(nil) | ||
| 10 | - | ||
| 11 | -type CommendRepository struct{} | ||
| 12 | - | ||
| 13 | -func (r *CommendRepository) GetCommends(companyId int64, lastId int, pageSize int) (v []*models.Commend, total int, err error) { | ||
| 14 | - return models.GetCommends(companyId, lastId, pageSize) | ||
| 15 | -} |
internal/repository/comment.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type ICommentRepository interface { | ||
| 6 | - GetCommentById(id int64) (v *models.Comment, err error) | ||
| 7 | - AddComment(m *models.Comment) (id int64, err error) | ||
| 8 | - GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error) | ||
| 9 | -} | ||
| 10 | - | ||
| 11 | -var _ ICommentRepository = (*CommentRepository)(nil) | ||
| 12 | - | ||
| 13 | -type CommentRepository struct{} | ||
| 14 | - | ||
| 15 | -func (r *CommentRepository) GetCommentById(id int64) (v *models.Comment, err error) { | ||
| 16 | - return models.GetCommentById(id) | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -func (r *CommentRepository) AddComment(m *models.Comment) (id int64, err error) { | ||
| 20 | - return models.AddComment(m) | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -func (r *CommentRepository) GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error) { | ||
| 24 | - return models.GetComments(userId, sourceType, sourceId, lastId, pageSize) | ||
| 25 | -} |
internal/repository/company.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type ICompanyRepository interface { | ||
| 6 | - GetCompanyById(companyId int64) (v *models.Company, err error) | ||
| 7 | -} | ||
| 8 | - | ||
| 9 | -var _ ICompanyRepository = (*CompanyRepository)(nil) | ||
| 10 | - | ||
| 11 | -type CompanyRepository struct{} | ||
| 12 | - | ||
| 13 | -func (r *CompanyRepository) GetCompanyById(companyId int64) (v *models.Company, err error) { | ||
| 14 | - return models.GetCompanyById(companyId) | ||
| 15 | -} |
internal/repository/department.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type IDepartmentRepository interface { | ||
| 6 | - GetDepartmentById(companyId int) (v *models.Department, err error) | ||
| 7 | - GetDepartmentByCompanyId(companyId int64) (v []*models.Department, err error) | ||
| 8 | -} | ||
| 9 | - | ||
| 10 | -var _ IDepartmentRepository = (*DepartmentRepository)(nil) | ||
| 11 | - | ||
| 12 | -type DepartmentRepository struct{} | ||
| 13 | - | ||
| 14 | -func (r *DepartmentRepository) GetDepartmentById(id int) (v *models.Department, err error) { | ||
| 15 | - return models.GetDepartmentById(id) | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (r *DepartmentRepository) GetDepartmentByCompanyId(companyId int64) (v []*models.Department, err error) { | ||
| 19 | - return models.GetDepartmentByCompanyId(companyId) | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -type IUserDepartmentRepository interface { | ||
| 23 | - GetUserDepartment(userId int64, companyId int64, v interface{}) (err error) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -type UserDepartmentRepository struct{} | ||
| 27 | - | ||
| 28 | -func (r *UserDepartmentRepository) GetUserDepartment(userId int64, companyId int64, v interface{}) (err error) { | ||
| 29 | - return models.GetUserDepartments(userId, companyId, v) | ||
| 30 | -} |
internal/repository/message.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type IMessageRepository interface { | ||
| 6 | - GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) | ||
| 7 | - UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) | ||
| 8 | - GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error) | ||
| 9 | -} | ||
| 10 | - | ||
| 11 | -var _ IMessageRepository = (*MessageRepository)(nil) | ||
| 12 | - | ||
| 13 | -type MessageRepository struct{} | ||
| 14 | - | ||
| 15 | -func (r *MessageRepository) GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) { | ||
| 16 | - return models.GetUserMsgTotals(userId, companyId, msgType, v) | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -func (r *MessageRepository) UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { | ||
| 20 | - return models.UpdateUserMsgSetRead(userId, companyId, msgType, msgId) | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -func (r *MessageRepository) GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error) { | ||
| 24 | - return models.GetUserMsgs(userId, companyId, msgType, sourceType, lastId, pageSize) | ||
| 25 | -} |
internal/repository/position.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type IPositionRepository interface { | ||
| 6 | - GetPositionById(companyId int) (v *models.Position, err error) | ||
| 7 | -} | ||
| 8 | - | ||
| 9 | -var _ IPositionRepository = (*PositionRepository)(nil) | ||
| 10 | - | ||
| 11 | -type PositionRepository struct{} | ||
| 12 | - | ||
| 13 | -func (r *PositionRepository) GetPositionById(id int) (v *models.Position, err error) { | ||
| 14 | - return models.GetPositionById(id) | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | -type IUserPositionRepository interface { | ||
| 18 | - GetUserPositions(userId int64, companyId int64, v interface{}) (err error) | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | -type UserPositionRepository struct{} | ||
| 22 | - | ||
| 23 | -func (r *UserPositionRepository) GetUserPositions(userId int64, companyId int64, v interface{}) (err error) { | ||
| 24 | - return models.GetUserPositions(userId, companyId, v) | ||
| 25 | -} |
internal/repository/repository.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "sync" | ||
| 4 | - | ||
| 5 | -//全局 | ||
| 6 | -var ( | ||
| 7 | - once sync.Once | ||
| 8 | - //User IUserRepository | ||
| 9 | - //UserAuth IUserAuthRepository | ||
| 10 | - //Commend ICommendRepository | ||
| 11 | - //Company ICompanyRepository | ||
| 12 | - //Department IDepartmentRepository | ||
| 13 | - //Position IPositionRepository | ||
| 14 | - //Chance IChanceRepository | ||
| 15 | - //ChanceFavorite IChanceFavoriteRepository | ||
| 16 | - //Comment ICommentRepository | ||
| 17 | - //Message IMessageRepository | ||
| 18 | - //UserCompany IUserCompanyRepository | ||
| 19 | - //UserPosition IUserPositionRepository | ||
| 20 | - //UserDepartment IUserDepartmentRepository | ||
| 21 | -) | ||
| 22 | - | ||
| 23 | -func init() { | ||
| 24 | - InitRepository() | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -func InitRepository() { | ||
| 28 | - //User = &UserRepository{} | ||
| 29 | - //UserAuth = &UserAuthRepository{} | ||
| 30 | - //Commend = &CommendRepository{} | ||
| 31 | - //Company = &CompanyRepository{} | ||
| 32 | - //Department = &DepartmentRepository{} | ||
| 33 | - //Position = &PositionRepository{} | ||
| 34 | - //Chance = &ChanceRepository{} | ||
| 35 | - //Comment = &CommentRepository{} | ||
| 36 | - //Message = &MessageRepository{} | ||
| 37 | - //ChanceFavorite = &ChanceFavoriteRepository{} | ||
| 38 | - //UserCompany = &UserCompanyRepository{} | ||
| 39 | - //UserPosition = &UserPositionRepository{} | ||
| 40 | - //UserDepartment = &UserDepartmentRepository{} | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | -func InitRepositoryMock() { | ||
| 44 | - once.Do(func() { | ||
| 45 | - //User = &UserMockRepository{} | ||
| 46 | - //UserAuth = &UserAuthMockRepository{} | ||
| 47 | - }) | ||
| 48 | -} |
internal/repository/user.go
已删除
100755 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type IUserRepository interface { | ||
| 6 | - GetUsersById(uid int64) (v *models.User, err error) | ||
| 7 | - GetUsersByMobile(mobile string) (v *models.User, err error) | ||
| 8 | - UpdateUserInfo(m *models.User) (err error) | ||
| 9 | -} | ||
| 10 | - | ||
| 11 | -var _ IUserRepository = (*UserRepository)(nil) | ||
| 12 | - | ||
| 13 | -type UserRepository struct{} | ||
| 14 | - | ||
| 15 | -func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) { | ||
| 16 | - return models.GetUsersById(uid) | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { | ||
| 20 | - return models.GetUserByMobile(mobile) | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { | ||
| 24 | - return models.UpdateUsersById(m) | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -type IUserCompanyRepository interface { | ||
| 28 | - GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error) | ||
| 29 | -} | ||
| 30 | - | ||
| 31 | -var _ IUserCompanyRepository = (*UserCompanyRepository)(nil) | ||
| 32 | - | ||
| 33 | -type UserCompanyRepository struct{} | ||
| 34 | - | ||
| 35 | -func (r *UserCompanyRepository) GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error) { | ||
| 36 | - return models.GetUserCompanyByUserId(uid, companyId) | ||
| 37 | -} |
internal/repository/user_auth.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type IUserAuthRepository interface { | ||
| 6 | - GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) | ||
| 7 | - UpdateUserAuthById(m *models.UserAuth) (err error) | ||
| 8 | - GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) | ||
| 9 | - GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) | ||
| 10 | - GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) | ||
| 11 | - AddUserAuth(m *models.UserAuth) (err error) | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | -var _ IUserAuthRepository = (*UserAuthRepository)(nil) | ||
| 15 | - | ||
| 16 | -type UserAuthRepository struct{} | ||
| 17 | - | ||
| 18 | -func (r *UserAuthRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) { | ||
| 19 | - return models.GetUserAuthByUserId(uid, deviceType) | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) { | ||
| 23 | - return models.UpdateUserAuthById(m) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -func (r *UserAuthRepository) AddUserAuth(m *models.UserAuth) (err error) { | ||
| 27 | - _, err = models.AddUserAuth(m) | ||
| 28 | - return | ||
| 29 | -} | ||
| 30 | - | ||
| 31 | -func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { | ||
| 32 | - return models.GetUserByAuthCode(authCode) | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | -func (r *UserAuthRepository) GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) { | ||
| 36 | - return models.GetUserAuthByRefreshToken(refreshToken) | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -func (r *UserAuthRepository) GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) { | ||
| 40 | - return models.GetUserAuthByToken(refreshToken) | ||
| 41 | -} |
internal/repository/user_auth_mock.go
已删除
100644 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -var userAuth = &models.UserAuth{ | ||
| 6 | - AuthCode: "897ca746f46b11e98771000c29ad8d6d", | ||
| 7 | - AccessToken: "897ca746f46b11e98771000c29ad8d7d", | ||
| 8 | - RefreshToken: "897ca746f46b11e98771000c29ad8d8d", | ||
| 9 | -} | ||
| 10 | - | ||
| 11 | -type UserAuthMockRepository struct{} | ||
| 12 | - | ||
| 13 | -func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) { | ||
| 14 | - v = userAuth | ||
| 15 | - return | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (r *UserAuthMockRepository) UpdateUserAuthById(m *models.UserAuth) (err error) { | ||
| 19 | - return | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -func (r *UserAuthMockRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { | ||
| 23 | - v = userAuth | ||
| 24 | - return | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -func (r *UserAuthMockRepository) GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) { | ||
| 28 | - v = userAuth | ||
| 29 | - return | ||
| 30 | -} | ||
| 31 | - | ||
| 32 | -func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) { | ||
| 33 | - v = userAuth | ||
| 34 | - return | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | -func (r *UserAuthMockRepository) AddUserAuth(m *models.UserAuth) (err error) { | ||
| 38 | - //_,err =models.AddUserAuth(m) | ||
| 39 | - return | ||
| 40 | -} |
internal/repository/user_mock.go
已删除
100755 → 0
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import "opp/models" | ||
| 4 | - | ||
| 5 | -type UserMockRepository struct{} | ||
| 6 | - | ||
| 7 | -var userInfo = &models.UserAuth{ | ||
| 8 | - AuthCode: "897ca746f46b11e98771000c29ad8d6d", | ||
| 9 | - AccessToken: "897ca746f46b11e98771000c29ad8d7d", | ||
| 10 | - RefreshToken: "897ca746f46b11e98771000c29ad8d8d", | ||
| 11 | -} | ||
| 12 | - | ||
| 13 | -var user = &models.User{ | ||
| 14 | - Phone: "18065048389", | ||
| 15 | - Passwd: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy", | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (r *UserMockRepository) GetUsersById(uid int64) (v *models.User, err error) { | ||
| 19 | - v = user | ||
| 20 | - return | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -func (r *UserMockRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { | ||
| 24 | - v = user | ||
| 25 | - return | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -func (r *UserMockRepository) UpdateUserInfo(m *models.User) (err error) { | ||
| 29 | - return | ||
| 30 | -} |
| @@ -79,6 +79,7 @@ func DeleteAuditFlowConfig(id int) (err error) { | @@ -79,6 +79,7 @@ func DeleteAuditFlowConfig(id int) (err error) { | ||
| 79 | return | 79 | return |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | +//审核配置信息列表 | ||
| 82 | func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowConfig, err error) { | 83 | func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowConfig, err error) { |
| 83 | o := orm.NewOrm() | 84 | o := orm.NewOrm() |
| 84 | sql := "select * from audit_flow_config where audit_template_id=? and audit_group_id=? order by level" | 85 | 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 | @@ -88,6 +89,8 @@ func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowCo | ||
| 88 | return | 89 | return |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 92 | +//按 1.模板编号 2.审核等级 | ||
| 93 | +//查询审核配置列表 | ||
| 91 | func GetAuditFlowConfigsLevel(auditTemplateId int64, level int) (v []*AuditFlowConfig, err error) { | 94 | func GetAuditFlowConfigsLevel(auditTemplateId int64, level int) (v []*AuditFlowConfig, err error) { |
| 92 | o := orm.NewOrm() | 95 | o := orm.NewOrm() |
| 93 | sql := "select * from audit_flow_config where audit_template_id=? and level=?" | 96 | sql := "select * from audit_flow_config where audit_template_id=? and level=?" |
| @@ -83,6 +83,8 @@ func DeleteAuditForm(id int) (err error) { | @@ -83,6 +83,8 @@ func DeleteAuditForm(id int) (err error) { | ||
| 83 | return | 83 | return |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | +//按1.公司编号 2.模板编号 | ||
| 87 | +//获取表单列表 | ||
| 86 | func GetAuditForms(companyId int64, auditTemplateId int64) (v []*AuditForm, err error) { | 88 | func GetAuditForms(companyId int64, auditTemplateId int64) (v []*AuditForm, err error) { |
| 87 | o := orm.NewOrm() | 89 | o := orm.NewOrm() |
| 88 | sql := `select * from audit_form where company_id=? and audit_template_id=? and enable_status=1 | 90 | sql := `select * from audit_form where company_id=? and audit_template_id=? and enable_status=1 |
| @@ -10,7 +10,7 @@ import ( | @@ -10,7 +10,7 @@ import ( | ||
| 10 | type AuditTemplate struct { | 10 | type AuditTemplate struct { |
| 11 | Id int64 `orm:"column(id);pk" description:"唯一编号"` | 11 | Id int64 `orm:"column(id);pk" description:"唯一编号"` |
| 12 | CompanyId int `orm:"column(company_id)" description:"公司id"` | 12 | CompanyId int `orm:"column(company_id)" description:"公司id"` |
| 13 | - ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"` | 13 | + ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"` |
| 14 | Name string `orm:"column(name);size(20)" description:"子分类名称"` | 14 | Name string `orm:"column(name);size(20)" description:"子分类名称"` |
| 15 | Doc string `orm:"column(doc);size(255)" description:"说明"` | 15 | Doc string `orm:"column(doc);size(255)" description:"说明"` |
| 16 | Icon string `orm:"column(icon);size(255)" description:"图标"` | 16 | Icon string `orm:"column(icon);size(255)" description:"图标"` |
| @@ -80,10 +80,12 @@ func DeleteAuditTemplate(id int64) (err error) { | @@ -80,10 +80,12 @@ func DeleteAuditTemplate(id int64) (err error) { | ||
| 80 | return | 80 | return |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | -func GetAuditTemplates(companyId int64, chanceType int) (v []*AuditTemplate, err error) { | 83 | +//按 1.公司编号 2.机会类型编号 |
| 84 | +//获取审核模板列表 | ||
| 85 | +func GetAuditTemplates(companyId int64, chanceTypeId int) (v []*AuditTemplate, err error) { | ||
| 84 | o := orm.NewOrm() | 86 | o := orm.NewOrm() |
| 85 | sql := "select * from audit_template where company_id=? and chance_type_id=? and enable_status=1" | 87 | sql := "select * from audit_template where company_id=? and chance_type_id=? and enable_status=1" |
| 86 | - if _, err = o.Raw(sql, companyId, chanceType).QueryRows(&v); err == nil { | 88 | + if _, err = o.Raw(sql, companyId, chanceTypeId).QueryRows(&v); err == nil { |
| 87 | return | 89 | return |
| 88 | } | 90 | } |
| 89 | return | 91 | return |
| @@ -65,10 +65,12 @@ func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) { | @@ -65,10 +65,12 @@ func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) { | ||
| 65 | return | 65 | return |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | -func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) { | 68 | +//按 1.公告编号 |
| 69 | +//获取公告问题 | ||
| 70 | +func GetBulletinQuestionBy(bulletinId int) (v *BulletinQuestion, err error) { | ||
| 69 | o := orm.NewOrm() | 71 | o := orm.NewOrm() |
| 70 | sql := "select * from bulletin_question where bulletin_id=?" | 72 | sql := "select * from bulletin_question where bulletin_id=?" |
| 71 | - if err = o.Raw(sql, id).QueryRow(&v); err == nil { | 73 | + if err = o.Raw(sql, bulletinId).QueryRow(&v); err == nil { |
| 72 | return v, nil | 74 | return v, nil |
| 73 | } | 75 | } |
| 74 | return nil, err | 76 | return nil, err |
| @@ -80,10 +80,12 @@ func DeleteBulletinQuestionAnswer(id int) (err error) { | @@ -80,10 +80,12 @@ func DeleteBulletinQuestionAnswer(id int) (err error) { | ||
| 80 | return | 80 | return |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | -func GetBulletinQuestionAnswerBy(bulletinId int, uid int64) (v *BulletinQuestionAnswer, err error) { | 83 | +//按 1.公告编号 2.用户公司id |
| 84 | +//获取用户公告问题回答 | ||
| 85 | +func GetBulletinQuestionAnswerBy(bulletinId int, ucid int64) (v *BulletinQuestionAnswer, err error) { | ||
| 84 | o := orm.NewOrm() | 86 | o := orm.NewOrm() |
| 85 | sql := "select * from bulletin_question_answer where bulletin_id=? and uid=?" | 87 | sql := "select * from bulletin_question_answer where bulletin_id=? and uid=?" |
| 86 | - if err = o.Raw(sql, bulletinId, uid).QueryRow(&v); err == nil { | 88 | + if err = o.Raw(sql, bulletinId, ucid).QueryRow(&v); err == nil { |
| 87 | return v, nil | 89 | return v, nil |
| 88 | } | 90 | } |
| 89 | return nil, err | 91 | return nil, err |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | - "reflect" | ||
| 7 | - "strings" | ||
| 8 | "time" | 5 | "time" |
| 9 | 6 | ||
| 10 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| 11 | ) | 8 | ) |
| 12 | 9 | ||
| 13 | type Chance struct { | 10 | type Chance struct { |
| 14 | - Id int64 `orm:"column(id);pk" description:"id 主键"` | ||
| 15 | - UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"` | ||
| 16 | - CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"` | ||
| 17 | - DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"` | ||
| 18 | - ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "` | ||
| 19 | - AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"` | ||
| 20 | - AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"` | ||
| 21 | - Content string `orm:"column(content)" description:"格式化后的文本内容"` | ||
| 22 | - SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"` | ||
| 23 | - ViewTotal int `orm:"column(view_total)" description:"查看总数"` | 11 | + Id int64 `orm:"column(id);pk" description:"id 主键"` |
| 12 | + UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"` | ||
| 13 | + CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"` | ||
| 14 | + DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"` | ||
| 15 | + ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "` | ||
| 16 | + AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"` | ||
| 17 | + AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"` | ||
| 18 | + Content string `orm:"column(content)" description:"格式化后的文本内容"` | ||
| 19 | + SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"` | ||
| 20 | + ViewTotal int `orm:"column(view_total)" description:"查看总数"` | ||
| 24 | CommentTotal int `orm:"column(comment_total)" description:"评论总数"` | 21 | CommentTotal int `orm:"column(comment_total)" description:"评论总数"` |
| 25 | ZanTotal int `orm:"column(zan_total)" description:"点赞总数"` | 22 | ZanTotal int `orm:"column(zan_total)" description:"点赞总数"` |
| 26 | ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待处理 1:待审核 2:被退回 3:已通过 "` | 23 | ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待处理 1:待审核 2:被退回 3:已通过 "` |
| @@ -62,84 +59,6 @@ func GetChanceById(id int64) (v *Chance, err error) { | @@ -62,84 +59,6 @@ func GetChanceById(id int64) (v *Chance, err error) { | ||
| 62 | return nil, err | 59 | return nil, err |
| 63 | } | 60 | } |
| 64 | 61 | ||
| 65 | -// GetAllChance retrieves all Chance matches certain condition. Returns empty list if | ||
| 66 | -// no records exist | ||
| 67 | -func GetAllChance(query map[string]string, fields []string, sortby []string, order []string, | ||
| 68 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 69 | - o := orm.NewOrm() | ||
| 70 | - qs := o.QueryTable(new(Chance)) | ||
| 71 | - // query k=v | ||
| 72 | - for k, v := range query { | ||
| 73 | - // rewrite dot-notation to Object__Attribute | ||
| 74 | - k = strings.Replace(k, ".", "__", -1) | ||
| 75 | - if strings.Contains(k, "isnull") { | ||
| 76 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 77 | - } else { | ||
| 78 | - qs = qs.Filter(k, v) | ||
| 79 | - } | ||
| 80 | - } | ||
| 81 | - // order by: | ||
| 82 | - var sortFields []string | ||
| 83 | - if len(sortby) != 0 { | ||
| 84 | - if len(sortby) == len(order) { | ||
| 85 | - // 1) for each sort field, there is an associated order | ||
| 86 | - for i, v := range sortby { | ||
| 87 | - orderby := "" | ||
| 88 | - if order[i] == "desc" { | ||
| 89 | - orderby = "-" + v | ||
| 90 | - } else if order[i] == "asc" { | ||
| 91 | - orderby = v | ||
| 92 | - } else { | ||
| 93 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 94 | - } | ||
| 95 | - sortFields = append(sortFields, orderby) | ||
| 96 | - } | ||
| 97 | - qs = qs.OrderBy(sortFields...) | ||
| 98 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 99 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 100 | - for _, v := range sortby { | ||
| 101 | - orderby := "" | ||
| 102 | - if order[0] == "desc" { | ||
| 103 | - orderby = "-" + v | ||
| 104 | - } else if order[0] == "asc" { | ||
| 105 | - orderby = v | ||
| 106 | - } else { | ||
| 107 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 108 | - } | ||
| 109 | - sortFields = append(sortFields, orderby) | ||
| 110 | - } | ||
| 111 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 112 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 113 | - } | ||
| 114 | - } else { | ||
| 115 | - if len(order) != 0 { | ||
| 116 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 117 | - } | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - var l []Chance | ||
| 121 | - qs = qs.OrderBy(sortFields...) | ||
| 122 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 123 | - if len(fields) == 0 { | ||
| 124 | - for _, v := range l { | ||
| 125 | - ml = append(ml, v) | ||
| 126 | - } | ||
| 127 | - } else { | ||
| 128 | - // trim unused fields | ||
| 129 | - for _, v := range l { | ||
| 130 | - m := make(map[string]interface{}) | ||
| 131 | - val := reflect.ValueOf(v) | ||
| 132 | - for _, fname := range fields { | ||
| 133 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 134 | - } | ||
| 135 | - ml = append(ml, m) | ||
| 136 | - } | ||
| 137 | - } | ||
| 138 | - return ml, nil | ||
| 139 | - } | ||
| 140 | - return nil, err | ||
| 141 | -} | ||
| 142 | - | ||
| 143 | // UpdateChance updates Chance by Id and returns error if | 62 | // UpdateChance updates Chance by Id and returns error if |
| 144 | // the record to be updated doesn't exist | 63 | // the record to be updated doesn't exist |
| 145 | func UpdateChanceById(m *Chance) (err error) { | 64 | func UpdateChanceById(m *Chance) (err error) { |
| @@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | type ChanceData struct { | 10 | type ChanceData struct { |
| 11 | - Id int64 `orm:"column(id)" description:"唯一编号"` | 11 | + Id int64 `orm:"column(id)" description:"唯一编号"` |
| 12 | ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"` | 12 | ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"` |
| 13 | Images string `orm:"column(images);size(1000);null" description:"图片 json"` | 13 | Images string `orm:"column(images);size(1000);null" description:"图片 json"` |
| 14 | Speechs string `orm:"column(speechs);size(1000);null" description:"语音 json"` | 14 | Speechs string `orm:"column(speechs);size(1000);null" description:"语音 json"` |
| @@ -74,11 +74,13 @@ func DeleteChanceData(id int64) (err error) { | @@ -74,11 +74,13 @@ func DeleteChanceData(id int64) (err error) { | ||
| 74 | return | 74 | return |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | +//按 1.机会编号 | ||
| 78 | +//获取机会数据 (多媒体) | ||
| 77 | func GetChanceDataByChanceId(chanceId int64) (v *ChanceData, err error) { | 79 | func GetChanceDataByChanceId(chanceId int64) (v *ChanceData, err error) { |
| 78 | o := orm.NewOrm() | 80 | o := orm.NewOrm() |
| 79 | - sql :=`select * from chance_data where chance_id=?` | ||
| 80 | - if err = o.Raw(sql,chanceId).QueryRow(&v); err == nil { | 81 | + sql := `select * from chance_data where chance_id=?` |
| 82 | + if err = o.Raw(sql, chanceId).QueryRow(&v); err == nil { | ||
| 81 | return v, nil | 83 | return v, nil |
| 82 | } | 84 | } |
| 83 | return nil, err | 85 | return nil, err |
| 84 | -} | ||
| 86 | +} |
| @@ -13,7 +13,7 @@ type ChanceFavorite struct { | @@ -13,7 +13,7 @@ type ChanceFavorite struct { | ||
| 13 | Id int64 `orm:"column(id);pk" description:"点赞编号"` | 13 | Id int64 `orm:"column(id);pk" description:"点赞编号"` |
| 14 | UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` | 14 | UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` |
| 15 | CompanyId int64 `orm:"column(company_id)" description:"company.id 公司编号"` | 15 | CompanyId int64 `orm:"column(company_id)" description:"company.id 公司编号"` |
| 16 | - MarkFlag int `orm:"column(mark_flag)" description:"类型 1:点赞 2:收藏"` | 16 | + MarkFlag int `orm:"column(mark_flag)" description:"类型 1:点赞 2:收藏"` |
| 17 | SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"` | 17 | SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"` |
| 18 | SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"` | 18 | SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"` |
| 19 | ChanceType int `orm:"column(chance_type)" description:"机会类型编号 - 附加 "` | 19 | ChanceType int `orm:"column(chance_type)" description:"机会类型编号 - 附加 "` |
| @@ -79,6 +79,8 @@ func DeleteChanceFavorite(id int64) (err error) { | @@ -79,6 +79,8 @@ func DeleteChanceFavorite(id int64) (err error) { | ||
| 79 | return | 79 | return |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | +//按1.用户id 2.公司id 3.标记类型 4.机会类型编号 5.最后编号 6.页数 | ||
| 83 | +//获取用户点赞收藏机会 | ||
| 82 | func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) { | 84 | func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) { |
| 83 | sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc") | 85 | sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc") |
| 84 | sql.Where(fmt.Sprintf("user_id=%d", userId)) | 86 | sql.Where(fmt.Sprintf("user_id=%d", userId)) |
| @@ -103,34 +105,35 @@ func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastI | @@ -103,34 +105,35 @@ func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastI | ||
| 103 | 105 | ||
| 104 | } | 106 | } |
| 105 | 107 | ||
| 108 | +//是否已经点赞/收藏 机会 | ||
| 106 | func ExitsChanceFavorite(userId, companyId int64, sourceId int64, markFlag int) (exits bool, err error) { | 109 | func ExitsChanceFavorite(userId, companyId int64, sourceId int64, markFlag int) (exits bool, err error) { |
| 107 | sql := mybeego.NewSqlExutor().Table("chance_favorite") | 110 | sql := mybeego.NewSqlExutor().Table("chance_favorite") |
| 108 | sql.Where(fmt.Sprintf("source_id=%d", sourceId)). | 111 | sql.Where(fmt.Sprintf("source_id=%d", sourceId)). |
| 109 | Where(fmt.Sprintf("user_id=%d", userId)). | 112 | Where(fmt.Sprintf("user_id=%d", userId)). |
| 110 | Where(fmt.Sprintf("company_id=%d", companyId)). | 113 | Where(fmt.Sprintf("company_id=%d", companyId)). |
| 111 | Where(fmt.Sprintf("enable_status=1")) | 114 | Where(fmt.Sprintf("enable_status=1")) |
| 112 | - if markFlag>0{ | 115 | + if markFlag > 0 { |
| 113 | sql.Where(fmt.Sprintf("(mark_flag&%d)>0", markFlag)) | 116 | sql.Where(fmt.Sprintf("(mark_flag&%d)>0", markFlag)) |
| 114 | } | 117 | } |
| 115 | return sql.QueryExists() | 118 | return sql.QueryExists() |
| 116 | } | 119 | } |
| 117 | 120 | ||
| 118 | - | ||
| 119 | -func UpdateChanceFavorite(userId, companyId int64,sourceId int64,markFlag int)(err error){ | 121 | +//更新机会点赞/收藏状态 |
| 122 | +func UpdateChanceFavorite(userId, companyId int64, sourceId int64, markFlag int) (err error) { | ||
| 120 | o := orm.NewOrm() | 123 | o := orm.NewOrm() |
| 121 | sql := `update chance_favorite set mark_flag = mark_flag ^ ? | 124 | sql := `update chance_favorite set mark_flag = mark_flag ^ ? |
| 122 | where user_id =? and company_id =? and source_id=? ` // | 125 | where user_id =? and company_id =? and source_id=? ` // |
| 123 | - if _,err = o.Raw(sql,markFlag,userId,companyId,sourceId).Exec(); err == nil { | 126 | + if _, err = o.Raw(sql, markFlag, userId, companyId, sourceId).Exec(); err == nil { |
| 124 | return | 127 | return |
| 125 | } | 128 | } |
| 126 | return | 129 | return |
| 127 | } | 130 | } |
| 128 | 131 | ||
| 129 | -func GetChanceFavorite(userId, companyId int64,sourceId int64,sourceType int)(v *ChanceFavorite,err error){ | ||
| 130 | - o :=orm.NewOrm() | ||
| 131 | - sql :=`select * from chance_favorite where user_id =? and company_id =? and source_id=? and source_type=?` | ||
| 132 | - if err = o.Raw(sql,userId,companyId,sourceId,sourceType).QueryRow(&v);err!=nil{ | 132 | +func GetChanceFavorite(userId, companyId int64, sourceId int64, sourceType int) (v *ChanceFavorite, err error) { |
| 133 | + o := orm.NewOrm() | ||
| 134 | + sql := `select * from chance_favorite where user_id =? and company_id =? and source_id=? and source_type=?` | ||
| 135 | + if err = o.Raw(sql, userId, companyId, sourceId, sourceType).QueryRow(&v); err != nil { | ||
| 133 | return | 136 | return |
| 134 | } | 137 | } |
| 135 | return | 138 | return |
| 136 | -} | ||
| 139 | +} |
models/chance_image.go
已删除
100644 → 0
| 1 | -package models | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "fmt" | ||
| 5 | - "time" | ||
| 6 | - | ||
| 7 | - "github.com/astaxie/beego/orm" | ||
| 8 | -) | ||
| 9 | - | ||
| 10 | -type ChanceImage struct { | ||
| 11 | - Id int64 `orm:"column(id);auto" description:"唯一编号"` | ||
| 12 | - ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"` | ||
| 13 | - Path string `orm:"column(path);size(500)" description:"路径"` | ||
| 14 | - W int `orm:"column(w);null" description:"宽"` | ||
| 15 | - H int `orm:"column(h);null" description:"高"` | ||
| 16 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -func (t *ChanceImage) TableName() string { | ||
| 20 | - return "chance_image" | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -func init() { | ||
| 24 | - orm.RegisterModel(new(ChanceImage)) | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -// AddChanceImage insert a new ChanceImage into database and returns | ||
| 28 | -// last inserted Id on success. | ||
| 29 | -func AddChanceImage(m *ChanceImage) (id int64, err error) { | ||
| 30 | - o := orm.NewOrm() | ||
| 31 | - id, err = o.Insert(m) | ||
| 32 | - return | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | -// GetChanceImageById retrieves ChanceImage by Id. Returns error if | ||
| 36 | -// Id doesn't exist | ||
| 37 | -func GetChanceImageById(id int64) (v *ChanceImage, err error) { | ||
| 38 | - o := orm.NewOrm() | ||
| 39 | - v = &ChanceImage{Id: id} | ||
| 40 | - if err = o.Read(v); err == nil { | ||
| 41 | - return v, nil | ||
| 42 | - } | ||
| 43 | - return nil, err | ||
| 44 | -} | ||
| 45 | - | ||
| 46 | -// UpdateChanceImage updates ChanceImage by Id and returns error if | ||
| 47 | -// the record to be updated doesn't exist | ||
| 48 | -func UpdateChanceImageById(m *ChanceImage) (err error) { | ||
| 49 | - o := orm.NewOrm() | ||
| 50 | - v := ChanceImage{Id: m.Id} | ||
| 51 | - // ascertain id exists in the database | ||
| 52 | - if err = o.Read(&v); err == nil { | ||
| 53 | - var num int64 | ||
| 54 | - if num, err = o.Update(m); err == nil { | ||
| 55 | - fmt.Println("Number of records updated in database:", num) | ||
| 56 | - } | ||
| 57 | - } | ||
| 58 | - return | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | -// DeleteChanceImage deletes ChanceImage by Id and returns error if | ||
| 62 | -// the record to be deleted doesn't exist | ||
| 63 | -func DeleteChanceImage(id int64) (err error) { | ||
| 64 | - o := orm.NewOrm() | ||
| 65 | - v := ChanceImage{Id: id} | ||
| 66 | - // ascertain id exists in the database | ||
| 67 | - if err = o.Read(&v); err == nil { | ||
| 68 | - var num int64 | ||
| 69 | - if num, err = o.Delete(&ChanceImage{Id: id}); err == nil { | ||
| 70 | - fmt.Println("Number of records deleted in database:", num) | ||
| 71 | - } | ||
| 72 | - } | ||
| 73 | - return | ||
| 74 | -} |
models/chance_speech.go
已删除
100644 → 0
| 1 | -package models | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "fmt" | ||
| 5 | - "time" | ||
| 6 | - | ||
| 7 | - "github.com/astaxie/beego/orm" | ||
| 8 | -) | ||
| 9 | - | ||
| 10 | -type ChanceSpeech struct { | ||
| 11 | - Id int64 `orm:"column(id);pk" description:"唯一编号"` | ||
| 12 | - Duration int `orm:"column(duration);null" description:"秒数"` | ||
| 13 | - ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"` | ||
| 14 | - Path string `orm:"column(path);size(500);null" description:"语音路径"` | ||
| 15 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)"` | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (t *ChanceSpeech) TableName() string { | ||
| 19 | - return "chance_speech" | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -func init() { | ||
| 23 | - orm.RegisterModel(new(ChanceSpeech)) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -// AddChanceSpeech insert a new ChanceSpeech into database and returns | ||
| 27 | -// last inserted Id on success. | ||
| 28 | -func AddChanceSpeech(m *ChanceSpeech) (id int64, err error) { | ||
| 29 | - o := orm.NewOrm() | ||
| 30 | - id, err = o.Insert(m) | ||
| 31 | - return | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | -// GetChanceSpeechById retrieves ChanceSpeech by Id. Returns error if | ||
| 35 | -// Id doesn't exist | ||
| 36 | -func GetChanceSpeechById(id int64) (v *ChanceSpeech, err error) { | ||
| 37 | - o := orm.NewOrm() | ||
| 38 | - v = &ChanceSpeech{Id: id} | ||
| 39 | - if err = o.Read(v); err == nil { | ||
| 40 | - return v, nil | ||
| 41 | - } | ||
| 42 | - return nil, err | ||
| 43 | -} | ||
| 44 | - | ||
| 45 | -// UpdateChanceSpeech updates ChanceSpeech by Id and returns error if | ||
| 46 | -// the record to be updated doesn't exist | ||
| 47 | -func UpdateChanceSpeechById(m *ChanceSpeech) (err error) { | ||
| 48 | - o := orm.NewOrm() | ||
| 49 | - v := ChanceSpeech{Id: m.Id} | ||
| 50 | - // ascertain id exists in the database | ||
| 51 | - if err = o.Read(&v); err == nil { | ||
| 52 | - var num int64 | ||
| 53 | - if num, err = o.Update(m); err == nil { | ||
| 54 | - fmt.Println("Number of records updated in database:", num) | ||
| 55 | - } | ||
| 56 | - } | ||
| 57 | - return | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -// DeleteChanceSpeech deletes ChanceSpeech by Id and returns error if | ||
| 61 | -// the record to be deleted doesn't exist | ||
| 62 | -func DeleteChanceSpeech(id int64) (err error) { | ||
| 63 | - o := orm.NewOrm() | ||
| 64 | - v := ChanceSpeech{Id: id} | ||
| 65 | - // ascertain id exists in the database | ||
| 66 | - if err = o.Read(&v); err == nil { | ||
| 67 | - var num int64 | ||
| 68 | - if num, err = o.Delete(&ChanceSpeech{Id: id}); err == nil { | ||
| 69 | - fmt.Println("Number of records deleted in database:", num) | ||
| 70 | - } | ||
| 71 | - } | ||
| 72 | - return | ||
| 73 | -} |
| @@ -3,12 +3,17 @@ package models | @@ -3,12 +3,17 @@ package models | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/astaxie/beego/orm" | 5 | "github.com/astaxie/beego/orm" |
| 6 | + "time" | ||
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| 8 | type ChanceType struct { | 9 | type ChanceType struct { |
| 9 | - Id int `orm:"column(id);auto" json:"id"` | ||
| 10 | - Name string `orm:"column(name);size(50)" description:"机会类型名称" json:"name"` | ||
| 11 | - Icon string `orm:"column(icon);size(500);null" description:"图标地址" json:"icon"` | 10 | + Id int `orm:"column(id);auto"` |
| 11 | + Name string `orm:"column(name);size(50)" description:"机会类型名称"` | ||
| 12 | + Icon string `orm:"column(icon);size(500);null" description:"图标地址"` | ||
| 13 | + CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"` | ||
| 14 | + SortNum int `orm:"column(sort_num);null" description:"序号 公司下的序号"` | ||
| 15 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 "` | ||
| 16 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 "` | ||
| 12 | } | 17 | } |
| 13 | 18 | ||
| 14 | func (t *ChanceType) TableName() string { | 19 | func (t *ChanceType) TableName() string { |
| @@ -68,10 +73,11 @@ func DeleteChanceType(id int) (err error) { | @@ -68,10 +73,11 @@ func DeleteChanceType(id int) (err error) { | ||
| 68 | return | 73 | return |
| 69 | } | 74 | } |
| 70 | 75 | ||
| 71 | -func GetChanceTypeAll() (v []*ChanceType, err error) { | 76 | +//获取所有机会类型 |
| 77 | +func GetChanceTypeAll(companyId int64) (v []*ChanceType, err error) { | ||
| 72 | o := orm.NewOrm() | 78 | o := orm.NewOrm() |
| 73 | - sql := "select * from chance_type " | ||
| 74 | - if _, err = o.Raw(sql).QueryRows(&v); err == nil { | 79 | + sql := "select * from chance_type where company_id=? order by sort_num" |
| 80 | + if _, err = o.Raw(sql).QueryRows(&v, companyId); err == nil { | ||
| 75 | return | 81 | return |
| 76 | } | 82 | } |
| 77 | return | 83 | return |
models/chance_video.go
已删除
100644 → 0
| 1 | -package models | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "fmt" | ||
| 5 | - "time" | ||
| 6 | - | ||
| 7 | - "github.com/astaxie/beego/orm" | ||
| 8 | -) | ||
| 9 | - | ||
| 10 | -type ChanceVideo struct { | ||
| 11 | - Id int64 `orm:"column(id);auto"` | ||
| 12 | - ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会id"` | ||
| 13 | - Path string `orm:"column(path);size(500);null" description:"路径"` | ||
| 14 | - Cover string `orm:"column(cover);size(500);null" description:"封面"` | ||
| 15 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)"` | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (t *ChanceVideo) TableName() string { | ||
| 19 | - return "chance_video" | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -func init() { | ||
| 23 | - orm.RegisterModel(new(ChanceVideo)) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -// AddChanceVideo insert a new ChanceVideo into database and returns | ||
| 27 | -// last inserted Id on success. | ||
| 28 | -func AddChanceVideo(m *ChanceVideo) (id int64, err error) { | ||
| 29 | - o := orm.NewOrm() | ||
| 30 | - id, err = o.Insert(m) | ||
| 31 | - return | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | -// GetChanceVideoById retrieves ChanceVideo by Id. Returns error if | ||
| 35 | -// Id doesn't exist | ||
| 36 | -func GetChanceVideoById(id int64) (v *ChanceVideo, err error) { | ||
| 37 | - o := orm.NewOrm() | ||
| 38 | - v = &ChanceVideo{Id: id} | ||
| 39 | - if err = o.Read(v); err == nil { | ||
| 40 | - return v, nil | ||
| 41 | - } | ||
| 42 | - return nil, err | ||
| 43 | -} | ||
| 44 | - | ||
| 45 | -// UpdateChanceVideo updates ChanceVideo by Id and returns error if | ||
| 46 | -// the record to be updated doesn't exist | ||
| 47 | -func UpdateChanceVideoById(m *ChanceVideo) (err error) { | ||
| 48 | - o := orm.NewOrm() | ||
| 49 | - v := ChanceVideo{Id: m.Id} | ||
| 50 | - // ascertain id exists in the database | ||
| 51 | - if err = o.Read(&v); err == nil { | ||
| 52 | - var num int64 | ||
| 53 | - if num, err = o.Update(m); err == nil { | ||
| 54 | - fmt.Println("Number of records updated in database:", num) | ||
| 55 | - } | ||
| 56 | - } | ||
| 57 | - return | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -// DeleteChanceVideo deletes ChanceVideo by Id and returns error if | ||
| 61 | -// the record to be deleted doesn't exist | ||
| 62 | -func DeleteChanceVideo(id int64) (err error) { | ||
| 63 | - o := orm.NewOrm() | ||
| 64 | - v := ChanceVideo{Id: id} | ||
| 65 | - // ascertain id exists in the database | ||
| 66 | - if err = o.Read(&v); err == nil { | ||
| 67 | - var num int64 | ||
| 68 | - if num, err = o.Delete(&ChanceVideo{Id: id}); err == nil { | ||
| 69 | - fmt.Println("Number of records deleted in database:", num) | ||
| 70 | - } | ||
| 71 | - } | ||
| 72 | - return | ||
| 73 | -} |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" |
| 7 | - "reflect" | ||
| 8 | - "strings" | ||
| 9 | "time" | 6 | "time" |
| 10 | 7 | ||
| 11 | "github.com/astaxie/beego/orm" | 8 | "github.com/astaxie/beego/orm" |
| @@ -48,84 +45,6 @@ func GetCommendById(id int64) (v *Commend, err error) { | @@ -48,84 +45,6 @@ func GetCommendById(id int64) (v *Commend, err error) { | ||
| 48 | return nil, err | 45 | return nil, err |
| 49 | } | 46 | } |
| 50 | 47 | ||
| 51 | -// GetAllCommend retrieves all Commend matches certain condition. Returns empty list if | ||
| 52 | -// no records exist | ||
| 53 | -func GetAllCommend(query map[string]string, fields []string, sortby []string, order []string, | ||
| 54 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 55 | - o := orm.NewOrm() | ||
| 56 | - qs := o.QueryTable(new(Commend)) | ||
| 57 | - // query k=v | ||
| 58 | - for k, v := range query { | ||
| 59 | - // rewrite dot-notation to Object__Attribute | ||
| 60 | - k = strings.Replace(k, ".", "__", -1) | ||
| 61 | - if strings.Contains(k, "isnull") { | ||
| 62 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 63 | - } else { | ||
| 64 | - qs = qs.Filter(k, v) | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - // order by: | ||
| 68 | - var sortFields []string | ||
| 69 | - if len(sortby) != 0 { | ||
| 70 | - if len(sortby) == len(order) { | ||
| 71 | - // 1) for each sort field, there is an associated order | ||
| 72 | - for i, v := range sortby { | ||
| 73 | - orderby := "" | ||
| 74 | - if order[i] == "desc" { | ||
| 75 | - orderby = "-" + v | ||
| 76 | - } else if order[i] == "asc" { | ||
| 77 | - orderby = v | ||
| 78 | - } else { | ||
| 79 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 80 | - } | ||
| 81 | - sortFields = append(sortFields, orderby) | ||
| 82 | - } | ||
| 83 | - qs = qs.OrderBy(sortFields...) | ||
| 84 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 85 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 86 | - for _, v := range sortby { | ||
| 87 | - orderby := "" | ||
| 88 | - if order[0] == "desc" { | ||
| 89 | - orderby = "-" + v | ||
| 90 | - } else if order[0] == "asc" { | ||
| 91 | - orderby = v | ||
| 92 | - } else { | ||
| 93 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 94 | - } | ||
| 95 | - sortFields = append(sortFields, orderby) | ||
| 96 | - } | ||
| 97 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 98 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 99 | - } | ||
| 100 | - } else { | ||
| 101 | - if len(order) != 0 { | ||
| 102 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 103 | - } | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - var l []Commend | ||
| 107 | - qs = qs.OrderBy(sortFields...) | ||
| 108 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 109 | - if len(fields) == 0 { | ||
| 110 | - for _, v := range l { | ||
| 111 | - ml = append(ml, v) | ||
| 112 | - } | ||
| 113 | - } else { | ||
| 114 | - // trim unused fields | ||
| 115 | - for _, v := range l { | ||
| 116 | - m := make(map[string]interface{}) | ||
| 117 | - val := reflect.ValueOf(v) | ||
| 118 | - for _, fname := range fields { | ||
| 119 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 120 | - } | ||
| 121 | - ml = append(ml, m) | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - return ml, nil | ||
| 125 | - } | ||
| 126 | - return nil, err | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | // UpdateCommend updates Commend by Id and returns error if | 48 | // UpdateCommend updates Commend by Id and returns error if |
| 130 | // the record to be updated doesn't exist | 49 | // the record to be updated doesn't exist |
| 131 | func UpdateCommendById(m *Commend) (err error) { | 50 | func UpdateCommendById(m *Commend) (err error) { |
| @@ -156,6 +75,7 @@ func DeleteCommend(id int64) (err error) { | @@ -156,6 +75,7 @@ func DeleteCommend(id int64) (err error) { | ||
| 156 | return | 75 | return |
| 157 | } | 76 | } |
| 158 | 77 | ||
| 78 | +//获取表彰列表 | ||
| 159 | func GetCommends(companyId int64, lastId int, pageSize int) (v []*Commend, total int, err error) { | 79 | func GetCommends(companyId int64, lastId int, pageSize int) (v []*Commend, total int, err error) { |
| 160 | sql := mybeego.NewSqlExutor().Table("commend").Order("create_at desc") | 80 | sql := mybeego.NewSqlExutor().Table("commend").Order("create_at desc") |
| 161 | sql.Where(fmt.Sprintf("company_id=%d", companyId)) | 81 | sql.Where(fmt.Sprintf("company_id=%d", companyId)) |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | 6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" |
| 8 | - "reflect" | ||
| 9 | - "strings" | ||
| 10 | "time" | 7 | "time" |
| 11 | 8 | ||
| 12 | "github.com/astaxie/beego/orm" | 9 | "github.com/astaxie/beego/orm" |
| @@ -51,84 +48,6 @@ func GetCommentById(id int64) (v *Comment, err error) { | @@ -51,84 +48,6 @@ func GetCommentById(id int64) (v *Comment, err error) { | ||
| 51 | return nil, err | 48 | return nil, err |
| 52 | } | 49 | } |
| 53 | 50 | ||
| 54 | -// GetAllComment retrieves all Comment matches certain condition. Returns empty list if | ||
| 55 | -// no records exist | ||
| 56 | -func GetAllComment(query map[string]string, fields []string, sortby []string, order []string, | ||
| 57 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 58 | - o := orm.NewOrm() | ||
| 59 | - qs := o.QueryTable(new(Comment)) | ||
| 60 | - // query k=v | ||
| 61 | - for k, v := range query { | ||
| 62 | - // rewrite dot-notation to Object__Attribute | ||
| 63 | - k = strings.Replace(k, ".", "__", -1) | ||
| 64 | - if strings.Contains(k, "isnull") { | ||
| 65 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 66 | - } else { | ||
| 67 | - qs = qs.Filter(k, v) | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - // order by: | ||
| 71 | - var sortFields []string | ||
| 72 | - if len(sortby) != 0 { | ||
| 73 | - if len(sortby) == len(order) { | ||
| 74 | - // 1) for each sort field, there is an associated order | ||
| 75 | - for i, v := range sortby { | ||
| 76 | - orderby := "" | ||
| 77 | - if order[i] == "desc" { | ||
| 78 | - orderby = "-" + v | ||
| 79 | - } else if order[i] == "asc" { | ||
| 80 | - orderby = v | ||
| 81 | - } else { | ||
| 82 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 83 | - } | ||
| 84 | - sortFields = append(sortFields, orderby) | ||
| 85 | - } | ||
| 86 | - qs = qs.OrderBy(sortFields...) | ||
| 87 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 88 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 89 | - for _, v := range sortby { | ||
| 90 | - orderby := "" | ||
| 91 | - if order[0] == "desc" { | ||
| 92 | - orderby = "-" + v | ||
| 93 | - } else if order[0] == "asc" { | ||
| 94 | - orderby = v | ||
| 95 | - } else { | ||
| 96 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 97 | - } | ||
| 98 | - sortFields = append(sortFields, orderby) | ||
| 99 | - } | ||
| 100 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 101 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 102 | - } | ||
| 103 | - } else { | ||
| 104 | - if len(order) != 0 { | ||
| 105 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 106 | - } | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - var l []Comment | ||
| 110 | - qs = qs.OrderBy(sortFields...) | ||
| 111 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 112 | - if len(fields) == 0 { | ||
| 113 | - for _, v := range l { | ||
| 114 | - ml = append(ml, v) | ||
| 115 | - } | ||
| 116 | - } else { | ||
| 117 | - // trim unused fields | ||
| 118 | - for _, v := range l { | ||
| 119 | - m := make(map[string]interface{}) | ||
| 120 | - val := reflect.ValueOf(v) | ||
| 121 | - for _, fname := range fields { | ||
| 122 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 123 | - } | ||
| 124 | - ml = append(ml, m) | ||
| 125 | - } | ||
| 126 | - } | ||
| 127 | - return ml, nil | ||
| 128 | - } | ||
| 129 | - return nil, err | ||
| 130 | -} | ||
| 131 | - | ||
| 132 | // UpdateComment updates Comment by Id and returns error if | 51 | // UpdateComment updates Comment by Id and returns error if |
| 133 | // the record to be updated doesn't exist | 52 | // the record to be updated doesn't exist |
| 134 | func UpdateCommentById(m *Comment) (err error) { | 53 | func UpdateCommentById(m *Comment) (err error) { |
| @@ -159,6 +78,7 @@ func DeleteComment(id int64) (err error) { | @@ -159,6 +78,7 @@ func DeleteComment(id int64) (err error) { | ||
| 159 | return | 78 | return |
| 160 | } | 79 | } |
| 161 | 80 | ||
| 81 | +//获取评论列表 | ||
| 162 | func GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*Comment, total int, err error) { | 82 | func GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*Comment, total int, err error) { |
| 163 | sql := mybeego.NewSqlExutor().Table("comment").Order("create_at desc") | 83 | sql := mybeego.NewSqlExutor().Table("comment").Order("create_at desc") |
| 164 | if userId > 0 { | 84 | if userId > 0 { |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | - "reflect" | ||
| 7 | - "strings" | ||
| 8 | "time" | 5 | "time" |
| 9 | 6 | ||
| 10 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| @@ -48,84 +45,6 @@ func GetCompanyById(id int64) (v *Company, err error) { | @@ -48,84 +45,6 @@ func GetCompanyById(id int64) (v *Company, err error) { | ||
| 48 | return nil, err | 45 | return nil, err |
| 49 | } | 46 | } |
| 50 | 47 | ||
| 51 | -// GetAllCompany retrieves all Company matches certain condition. Returns empty list if | ||
| 52 | -// no records exist | ||
| 53 | -func GetAllCompany(query map[string]string, fields []string, sortby []string, order []string, | ||
| 54 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 55 | - o := orm.NewOrm() | ||
| 56 | - qs := o.QueryTable(new(Company)) | ||
| 57 | - // query k=v | ||
| 58 | - for k, v := range query { | ||
| 59 | - // rewrite dot-notation to Object__Attribute | ||
| 60 | - k = strings.Replace(k, ".", "__", -1) | ||
| 61 | - if strings.Contains(k, "isnull") { | ||
| 62 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 63 | - } else { | ||
| 64 | - qs = qs.Filter(k, v) | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - // order by: | ||
| 68 | - var sortFields []string | ||
| 69 | - if len(sortby) != 0 { | ||
| 70 | - if len(sortby) == len(order) { | ||
| 71 | - // 1) for each sort field, there is an associated order | ||
| 72 | - for i, v := range sortby { | ||
| 73 | - orderby := "" | ||
| 74 | - if order[i] == "desc" { | ||
| 75 | - orderby = "-" + v | ||
| 76 | - } else if order[i] == "asc" { | ||
| 77 | - orderby = v | ||
| 78 | - } else { | ||
| 79 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 80 | - } | ||
| 81 | - sortFields = append(sortFields, orderby) | ||
| 82 | - } | ||
| 83 | - qs = qs.OrderBy(sortFields...) | ||
| 84 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 85 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 86 | - for _, v := range sortby { | ||
| 87 | - orderby := "" | ||
| 88 | - if order[0] == "desc" { | ||
| 89 | - orderby = "-" + v | ||
| 90 | - } else if order[0] == "asc" { | ||
| 91 | - orderby = v | ||
| 92 | - } else { | ||
| 93 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 94 | - } | ||
| 95 | - sortFields = append(sortFields, orderby) | ||
| 96 | - } | ||
| 97 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 98 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 99 | - } | ||
| 100 | - } else { | ||
| 101 | - if len(order) != 0 { | ||
| 102 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 103 | - } | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - var l []Company | ||
| 107 | - qs = qs.OrderBy(sortFields...) | ||
| 108 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 109 | - if len(fields) == 0 { | ||
| 110 | - for _, v := range l { | ||
| 111 | - ml = append(ml, v) | ||
| 112 | - } | ||
| 113 | - } else { | ||
| 114 | - // trim unused fields | ||
| 115 | - for _, v := range l { | ||
| 116 | - m := make(map[string]interface{}) | ||
| 117 | - val := reflect.ValueOf(v) | ||
| 118 | - for _, fname := range fields { | ||
| 119 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 120 | - } | ||
| 121 | - ml = append(ml, m) | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - return ml, nil | ||
| 125 | - } | ||
| 126 | - return nil, err | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | // UpdateCompany updates Company by Id and returns error if | 48 | // UpdateCompany updates Company by Id and returns error if |
| 130 | // the record to be updated doesn't exist | 49 | // the record to be updated doesn't exist |
| 131 | func UpdateCompanyById(m *Company) (err error) { | 50 | func UpdateCompanyById(m *Company) (err error) { |
| @@ -156,6 +75,7 @@ func DeleteCompany(id int64) (err error) { | @@ -156,6 +75,7 @@ func DeleteCompany(id int64) (err error) { | ||
| 156 | return | 75 | return |
| 157 | } | 76 | } |
| 158 | 77 | ||
| 78 | +//获取用户有权限的公司列表 | ||
| 159 | func GetCompanyByPermission(uid int64) (v []*Company, err error) { | 79 | func GetCompanyByPermission(uid int64) (v []*Company, err error) { |
| 160 | o := orm.NewOrm() | 80 | o := orm.NewOrm() |
| 161 | sql := `select * from company where id in( | 81 | sql := `select * from company where id in( |
| @@ -77,6 +77,8 @@ func DeleteDepartment(id int) (err error) { | @@ -77,6 +77,8 @@ func DeleteDepartment(id int) (err error) { | ||
| 77 | return | 77 | return |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | +//按 1.公司编号 | ||
| 81 | +//获取部门列表 | ||
| 80 | func GetDepartmentByCompanyId(companyId int64) (v []*Department, err error) { | 82 | func GetDepartmentByCompanyId(companyId int64) (v []*Department, err error) { |
| 81 | o := orm.NewOrm() | 83 | o := orm.NewOrm() |
| 82 | sql := ` | 84 | sql := ` |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | - "reflect" | ||
| 7 | - "strings" | ||
| 8 | "time" | 5 | "time" |
| 9 | 6 | ||
| 10 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| @@ -48,84 +45,6 @@ func GetPositionById(id int) (v *Position, err error) { | @@ -48,84 +45,6 @@ func GetPositionById(id int) (v *Position, err error) { | ||
| 48 | return nil, err | 45 | return nil, err |
| 49 | } | 46 | } |
| 50 | 47 | ||
| 51 | -// GetAllPosition retrieves all Position matches certain condition. Returns empty list if | ||
| 52 | -// no records exist | ||
| 53 | -func GetAllPosition(query map[string]string, fields []string, sortby []string, order []string, | ||
| 54 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 55 | - o := orm.NewOrm() | ||
| 56 | - qs := o.QueryTable(new(Position)) | ||
| 57 | - // query k=v | ||
| 58 | - for k, v := range query { | ||
| 59 | - // rewrite dot-notation to Object__Attribute | ||
| 60 | - k = strings.Replace(k, ".", "__", -1) | ||
| 61 | - if strings.Contains(k, "isnull") { | ||
| 62 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 63 | - } else { | ||
| 64 | - qs = qs.Filter(k, v) | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - // order by: | ||
| 68 | - var sortFields []string | ||
| 69 | - if len(sortby) != 0 { | ||
| 70 | - if len(sortby) == len(order) { | ||
| 71 | - // 1) for each sort field, there is an associated order | ||
| 72 | - for i, v := range sortby { | ||
| 73 | - orderby := "" | ||
| 74 | - if order[i] == "desc" { | ||
| 75 | - orderby = "-" + v | ||
| 76 | - } else if order[i] == "asc" { | ||
| 77 | - orderby = v | ||
| 78 | - } else { | ||
| 79 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 80 | - } | ||
| 81 | - sortFields = append(sortFields, orderby) | ||
| 82 | - } | ||
| 83 | - qs = qs.OrderBy(sortFields...) | ||
| 84 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 85 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 86 | - for _, v := range sortby { | ||
| 87 | - orderby := "" | ||
| 88 | - if order[0] == "desc" { | ||
| 89 | - orderby = "-" + v | ||
| 90 | - } else if order[0] == "asc" { | ||
| 91 | - orderby = v | ||
| 92 | - } else { | ||
| 93 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 94 | - } | ||
| 95 | - sortFields = append(sortFields, orderby) | ||
| 96 | - } | ||
| 97 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 98 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 99 | - } | ||
| 100 | - } else { | ||
| 101 | - if len(order) != 0 { | ||
| 102 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 103 | - } | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - var l []Position | ||
| 107 | - qs = qs.OrderBy(sortFields...) | ||
| 108 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 109 | - if len(fields) == 0 { | ||
| 110 | - for _, v := range l { | ||
| 111 | - ml = append(ml, v) | ||
| 112 | - } | ||
| 113 | - } else { | ||
| 114 | - // trim unused fields | ||
| 115 | - for _, v := range l { | ||
| 116 | - m := make(map[string]interface{}) | ||
| 117 | - val := reflect.ValueOf(v) | ||
| 118 | - for _, fname := range fields { | ||
| 119 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 120 | - } | ||
| 121 | - ml = append(ml, m) | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - return ml, nil | ||
| 125 | - } | ||
| 126 | - return nil, err | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | // UpdatePosition updates Position by Id and returns error if | 48 | // UpdatePosition updates Position by Id and returns error if |
| 130 | // the record to be updated doesn't exist | 49 | // the record to be updated doesn't exist |
| 131 | func UpdatePositionById(m *Position) (err error) { | 50 | func UpdatePositionById(m *Position) (err error) { |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | - "reflect" | ||
| 7 | - "strings" | ||
| 8 | "time" | 5 | "time" |
| 9 | 6 | ||
| 10 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| @@ -55,84 +52,6 @@ func GetUserAuthById(id int) (v *UserAuth, err error) { | @@ -55,84 +52,6 @@ func GetUserAuthById(id int) (v *UserAuth, err error) { | ||
| 55 | return nil, err | 52 | return nil, err |
| 56 | } | 53 | } |
| 57 | 54 | ||
| 58 | -// GetAllUserAuth retrieves all UserAuth matches certain condition. Returns empty list if | ||
| 59 | -// no records exist | ||
| 60 | -func GetAllUserAuth(query map[string]string, fields []string, sortby []string, order []string, | ||
| 61 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 62 | - o := orm.NewOrm() | ||
| 63 | - qs := o.QueryTable(new(UserAuth)) | ||
| 64 | - // query k=v | ||
| 65 | - for k, v := range query { | ||
| 66 | - // rewrite dot-notation to Object__Attribute | ||
| 67 | - k = strings.Replace(k, ".", "__", -1) | ||
| 68 | - if strings.Contains(k, "isnull") { | ||
| 69 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 70 | - } else { | ||
| 71 | - qs = qs.Filter(k, v) | ||
| 72 | - } | ||
| 73 | - } | ||
| 74 | - // order by: | ||
| 75 | - var sortFields []string | ||
| 76 | - if len(sortby) != 0 { | ||
| 77 | - if len(sortby) == len(order) { | ||
| 78 | - // 1) for each sort field, there is an associated order | ||
| 79 | - for i, v := range sortby { | ||
| 80 | - orderby := "" | ||
| 81 | - if order[i] == "desc" { | ||
| 82 | - orderby = "-" + v | ||
| 83 | - } else if order[i] == "asc" { | ||
| 84 | - orderby = v | ||
| 85 | - } else { | ||
| 86 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 87 | - } | ||
| 88 | - sortFields = append(sortFields, orderby) | ||
| 89 | - } | ||
| 90 | - qs = qs.OrderBy(sortFields...) | ||
| 91 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 92 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 93 | - for _, v := range sortby { | ||
| 94 | - orderby := "" | ||
| 95 | - if order[0] == "desc" { | ||
| 96 | - orderby = "-" + v | ||
| 97 | - } else if order[0] == "asc" { | ||
| 98 | - orderby = v | ||
| 99 | - } else { | ||
| 100 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 101 | - } | ||
| 102 | - sortFields = append(sortFields, orderby) | ||
| 103 | - } | ||
| 104 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 105 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 106 | - } | ||
| 107 | - } else { | ||
| 108 | - if len(order) != 0 { | ||
| 109 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 110 | - } | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - var l []UserAuth | ||
| 114 | - qs = qs.OrderBy(sortFields...) | ||
| 115 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 116 | - if len(fields) == 0 { | ||
| 117 | - for _, v := range l { | ||
| 118 | - ml = append(ml, v) | ||
| 119 | - } | ||
| 120 | - } else { | ||
| 121 | - // trim unused fields | ||
| 122 | - for _, v := range l { | ||
| 123 | - m := make(map[string]interface{}) | ||
| 124 | - val := reflect.ValueOf(v) | ||
| 125 | - for _, fname := range fields { | ||
| 126 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 127 | - } | ||
| 128 | - ml = append(ml, m) | ||
| 129 | - } | ||
| 130 | - } | ||
| 131 | - return ml, nil | ||
| 132 | - } | ||
| 133 | - return nil, err | ||
| 134 | -} | ||
| 135 | - | ||
| 136 | // UpdateUserAuth updates UserAuth by Id and returns error if | 55 | // UpdateUserAuth updates UserAuth by Id and returns error if |
| 137 | // the record to be updated doesn't exist | 56 | // the record to be updated doesn't exist |
| 138 | func UpdateUserAuthById(m *UserAuth) (err error) { | 57 | func UpdateUserAuthById(m *UserAuth) (err error) { |
| @@ -163,6 +82,8 @@ func DeleteUserAuth(id int) (err error) { | @@ -163,6 +82,8 @@ func DeleteUserAuth(id int) (err error) { | ||
| 163 | return | 82 | return |
| 164 | } | 83 | } |
| 165 | 84 | ||
| 85 | +//按 authcode | ||
| 86 | +//获取用户权限信息 | ||
| 166 | func GetUserByAuthCode(authCode string) (v *UserAuth, err error) { | 87 | func GetUserByAuthCode(authCode string) (v *UserAuth, err error) { |
| 167 | o := orm.NewOrm() | 88 | o := orm.NewOrm() |
| 168 | sql := "select * from user_auth where auth_code=? and auth_code_exp >= Now()" | 89 | 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) { | @@ -172,6 +93,8 @@ func GetUserByAuthCode(authCode string) (v *UserAuth, err error) { | ||
| 172 | return nil, err | 93 | return nil, err |
| 173 | } | 94 | } |
| 174 | 95 | ||
| 96 | +//按 refreshToken | ||
| 97 | +//获取用户权限信息 | ||
| 175 | func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) { | 98 | func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) { |
| 176 | o := orm.NewOrm() | 99 | o := orm.NewOrm() |
| 177 | sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" // | 100 | 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) { | @@ -181,6 +104,8 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) { | ||
| 181 | return nil, err | 104 | return nil, err |
| 182 | } | 105 | } |
| 183 | 106 | ||
| 107 | +//按 token | ||
| 108 | +//获取用户权限信息 | ||
| 184 | func GetUserAuthByToken(token string) (v *UserAuth, err error) { | 109 | func GetUserAuthByToken(token string) (v *UserAuth, err error) { |
| 185 | o := orm.NewOrm() | 110 | o := orm.NewOrm() |
| 186 | sql := "select * from user_auth where access_token=? and access_token_exp >= Now()" | 111 | 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) { | @@ -191,7 +116,7 @@ func GetUserAuthByToken(token string) (v *UserAuth, err error) { | ||
| 191 | } | 116 | } |
| 192 | 117 | ||
| 193 | // GetUserAuthById retrieves UserAuth by Id. Returns error if | 118 | // GetUserAuthById retrieves UserAuth by Id. Returns error if |
| 194 | -// Id doesn't exist | 119 | +// 获取用户权限信息 |
| 195 | func GetUserAuthByUserId(uid int64, deviceType int) (v *UserAuth, err error) { | 120 | func GetUserAuthByUserId(uid int64, deviceType int) (v *UserAuth, err error) { |
| 196 | o := orm.NewOrm() | 121 | o := orm.NewOrm() |
| 197 | sql := "select * from user_auth where user_id=? and device_type=?" | 122 | 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 | @@ -87,7 +87,8 @@ func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err err | ||
| 87 | return nil, err | 87 | return nil, err |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | -//按user_company.id获取公司信息 | 90 | +//按用户公司编号 公司编号获取用户信息 |
| 91 | +//获取公司信息 | ||
| 91 | func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) { | 92 | func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) { |
| 92 | o := orm.NewOrm() | 93 | o := orm.NewOrm() |
| 93 | sql := "select * from user_company where id=? and company_id=? and enable=1" // | 94 | 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) { | @@ -97,7 +98,9 @@ func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) { | ||
| 97 | return nil, err | 98 | return nil, err |
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | -func GetUserCompanys(uid int64) (v *UserCompany, err error) { | 101 | +//按用户编号 |
| 102 | +//获取用户第一个有效公司 | ||
| 103 | +func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) { | ||
| 101 | o := orm.NewOrm() | 104 | o := orm.NewOrm() |
| 102 | sql := "select * from user_company where user_id=? and enable=1 order by create_at desc limit 1" // | 105 | sql := "select * from user_company where user_id=? and enable=1 order by create_at desc limit 1" // |
| 103 | if err = o.Raw(sql, uid).QueryRow(&v); err == nil { | 106 | if err = o.Raw(sql, uid).QueryRow(&v); err == nil { |
| @@ -73,6 +73,8 @@ func DeleteUserDepartment(id int64) (err error) { | @@ -73,6 +73,8 @@ func DeleteUserDepartment(id int64) (err error) { | ||
| 73 | return | 73 | return |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | +//1.按用户公司编号 2.公司编号 | ||
| 77 | +//获取部门列表 | ||
| 76 | func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) { | 78 | func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) { |
| 77 | o := orm.NewOrm() | 79 | o := orm.NewOrm() |
| 78 | sql := ` | 80 | sql := ` |
| @@ -34,9 +34,12 @@ const ( | @@ -34,9 +34,12 @@ const ( | ||
| 34 | SourceTypeBulletin = 3 | 34 | SourceTypeBulletin = 3 |
| 35 | ) | 35 | ) |
| 36 | const ( | 36 | const ( |
| 37 | - SqlUserMsgsUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //所有未读消息 | ||
| 38 | - 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" //特定未读消息 | ||
| 39 | - SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息 | 37 | + //用户未读消息列表 |
| 38 | + SqlUserMsgsUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //所有未读消息 | ||
| 39 | + //用户未读消息 - 单个 | ||
| 40 | + 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" //特定未读消息 | ||
| 41 | + //用户消息 - 按 1.源id 2.接收者id 3.消息类型 | ||
| 42 | + SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息 | ||
| 40 | ) | 43 | ) |
| 41 | 44 | ||
| 42 | func (t *UserMsg) TableName() string { | 45 | func (t *UserMsg) TableName() string { |
| @@ -96,6 +99,7 @@ func DeleteUserMsg(id int64) (err error) { | @@ -96,6 +99,7 @@ func DeleteUserMsg(id int64) (err error) { | ||
| 96 | return | 99 | return |
| 97 | } | 100 | } |
| 98 | 101 | ||
| 102 | +//消息总数 | ||
| 99 | func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) { | 103 | func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) { |
| 100 | o := orm.NewOrm() | 104 | o := orm.NewOrm() |
| 101 | sql := `select COUNT(*) as total,msg_type from user_msg | 105 | sql := `select COUNT(*) as total,msg_type from user_msg |
| @@ -107,6 +111,7 @@ GROUP BY msg_type` | @@ -107,6 +111,7 @@ GROUP BY msg_type` | ||
| 107 | return | 111 | return |
| 108 | } | 112 | } |
| 109 | 113 | ||
| 114 | +//标记消息已读 | ||
| 110 | func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { | 115 | func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { |
| 111 | o := orm.NewOrm() | 116 | o := orm.NewOrm() |
| 112 | sql := `update user_msg set is_read = 1 | 117 | sql := `update user_msg set is_read = 1 |
| @@ -123,6 +128,7 @@ func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int6 | @@ -123,6 +128,7 @@ func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int6 | ||
| 123 | return | 128 | return |
| 124 | } | 129 | } |
| 125 | 130 | ||
| 131 | +//获取用户消息列表 | ||
| 126 | func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId int64, pageSize int) (v []*UserMsg, total int, err error) { | 132 | func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId int64, pageSize int) (v []*UserMsg, total int, err error) { |
| 127 | sql := mybeego.NewSqlExutor().Table("user_msg").Order("create_at desc") | 133 | sql := mybeego.NewSqlExutor().Table("user_msg").Order("create_at desc") |
| 128 | if lastId > 0 { | 134 | if lastId > 0 { |
| @@ -145,6 +151,7 @@ func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId in | @@ -145,6 +151,7 @@ func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId in | ||
| 145 | return | 151 | return |
| 146 | } | 152 | } |
| 147 | 153 | ||
| 154 | +//获取公告消息列表 | ||
| 148 | func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pageSize int, v interface{}) (total int, err error) { | 155 | func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pageSize int, v interface{}) (total int, err error) { |
| 149 | sql := `select b.id,b.title,unix_timestamp(b.update_at) update_at,a.is_read ` | 156 | sql := `select b.id,b.title,unix_timestamp(b.update_at) update_at,a.is_read ` |
| 150 | sqlCount := `select count(0) ` | 157 | sqlCount := `select count(0) ` |
| @@ -73,6 +73,7 @@ func DeleteUserPosition(id int) (err error) { | @@ -73,6 +73,7 @@ func DeleteUserPosition(id int) (err error) { | ||
| 73 | return | 73 | return |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | +//获取用户岗位列表 | ||
| 76 | func GetUserPositions(id int64, companyId int64, v interface{}) (err error) { | 77 | func GetUserPositions(id int64, companyId int64, v interface{}) (err error) { |
| 77 | o := orm.NewOrm() | 78 | o := orm.NewOrm() |
| 78 | sql := ` | 79 | sql := ` |
| @@ -83,6 +83,8 @@ func DeleteUsers(id int64) (err error) { | @@ -83,6 +83,8 @@ func DeleteUsers(id int64) (err error) { | ||
| 83 | return | 83 | return |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | +//按手机号 | ||
| 87 | +//获取用户信息 | ||
| 86 | func GetUserByMobile(mobile string) (v *User, err error) { | 88 | func GetUserByMobile(mobile string) (v *User, err error) { |
| 87 | o := orm.NewOrm() | 89 | o := orm.NewOrm() |
| 88 | sql := "select * from user where phone=? and enable_status=1" | 90 | sql := "select * from user where phone=? and enable_status=1" |
| @@ -92,6 +94,8 @@ func GetUserByMobile(mobile string) (v *User, err error) { | @@ -92,6 +94,8 @@ func GetUserByMobile(mobile string) (v *User, err error) { | ||
| 92 | return nil, err | 94 | return nil, err |
| 93 | } | 95 | } |
| 94 | 96 | ||
| 97 | +//按统一用户中心编号 | ||
| 98 | +//获取用户信息 | ||
| 95 | func GetUserByUcenterId(uid int64) (v *User, err error) { | 99 | func GetUserByUcenterId(uid int64) (v *User, err error) { |
| 96 | o := orm.NewOrm() | 100 | o := orm.NewOrm() |
| 97 | sql := "select * from user where user_center_id=? and enable_status=1" | 101 | sql := "select * from user where user_center_id=? and enable_status=1" |
| @@ -100,12 +104,3 @@ func GetUserByUcenterId(uid int64) (v *User, err error) { | @@ -100,12 +104,3 @@ func GetUserByUcenterId(uid int64) (v *User, err error) { | ||
| 100 | } | 104 | } |
| 101 | return nil, err | 105 | return nil, err |
| 102 | } | 106 | } |
| 103 | - | ||
| 104 | -func GetUserByRole(roleId int) (v []*User, err error) { | ||
| 105 | - o := orm.NewOrm() | ||
| 106 | - sql := `select * from user where is_kefu = 1 and enable_status=1` | ||
| 107 | - if _, err = o.Raw(sql).QueryRows(&v); err == nil { | ||
| 108 | - return v, nil | ||
| 109 | - } | ||
| 110 | - return nil, err | ||
| 111 | -} |
| @@ -145,7 +145,7 @@ END: | @@ -145,7 +145,7 @@ END: | ||
| 145 | func ChanceType(header *protocol.RequestHeader, request *protocol.ChanceTypeRequest) (rsp *protocol.ChanceTypeResponse, err error) { | 145 | func ChanceType(header *protocol.RequestHeader, request *protocol.ChanceTypeRequest) (rsp *protocol.ChanceTypeResponse, err error) { |
| 146 | var () | 146 | var () |
| 147 | rsp = &protocol.ChanceTypeResponse{} | 147 | rsp = &protocol.ChanceTypeResponse{} |
| 148 | - if rsp.List, err = models.GetChanceTypeAll(); err != nil { | 148 | + if rsp.List, err = models.GetChanceTypeAll(header.CompanyId); err != nil { |
| 149 | return | 149 | return |
| 150 | } | 150 | } |
| 151 | return | 151 | return |
| @@ -553,56 +553,3 @@ func getParentDepartmentors(pid int) (ids []int64) { | @@ -553,56 +553,3 @@ func getParentDepartmentors(pid int) (ids []int64) { | ||
| 553 | } | 553 | } |
| 554 | return getParentDepartmentors(department.ParentId) | 554 | return getParentDepartmentors(department.ParentId) |
| 555 | } | 555 | } |
| 556 | - | ||
| 557 | -////获取角色对应用户列表 | ||
| 558 | -//func getRolesUser(header *protocol.RequestHeader,toRoles string)(ids []int64){ | ||
| 559 | -// var roles []int | ||
| 560 | -// if err :=json.Unmarshal([]byte(toRoles),&roles);err!=nil{ | ||
| 561 | -// log.Error(err) | ||
| 562 | -// return | ||
| 563 | -// } | ||
| 564 | -// for i:=range roles{ | ||
| 565 | -// | ||
| 566 | -// } | ||
| 567 | -// return | ||
| 568 | -//} | ||
| 569 | - | ||
| 570 | -func GenSpeechs(id int64, objs []protocol.Speech) (v []*models.ChanceSpeech) { | ||
| 571 | - for i := range objs { | ||
| 572 | - v = append(v, &models.ChanceSpeech{ | ||
| 573 | - Id: idgen.Next(), | ||
| 574 | - Duration: objs[i].Duration, | ||
| 575 | - Path: objs[i].Path, | ||
| 576 | - ChanceId: id, | ||
| 577 | - CreateAt: time.Now(), | ||
| 578 | - }) | ||
| 579 | - } | ||
| 580 | - return | ||
| 581 | -} | ||
| 582 | - | ||
| 583 | -func GenVideos(id int64, objs []protocol.Video) (v []*models.ChanceVideo) { | ||
| 584 | - for i := range objs { | ||
| 585 | - v = append(v, &models.ChanceVideo{ | ||
| 586 | - Id: idgen.Next(), | ||
| 587 | - Path: objs[i].Path, | ||
| 588 | - ChanceId: id, | ||
| 589 | - Cover: objs[i].Cover, | ||
| 590 | - CreateAt: time.Now(), | ||
| 591 | - }) | ||
| 592 | - } | ||
| 593 | - return | ||
| 594 | -} | ||
| 595 | - | ||
| 596 | -func GenImages(id int64, objs []protocol.Picture) (v []*models.ChanceImage) { | ||
| 597 | - for i := range objs { | ||
| 598 | - v = append(v, &models.ChanceImage{ | ||
| 599 | - Id: idgen.Next(), | ||
| 600 | - Path: objs[i].Path, | ||
| 601 | - ChanceId: id, | ||
| 602 | - W: objs[i].W, | ||
| 603 | - H: objs[i].H, | ||
| 604 | - CreateAt: time.Now(), | ||
| 605 | - }) | ||
| 606 | - } | ||
| 607 | - return | ||
| 608 | -} |
| @@ -211,7 +211,7 @@ func H5Announcement(header *protocol.RequestHeader, request *protocol.Announceme | @@ -211,7 +211,7 @@ func H5Announcement(header *protocol.RequestHeader, request *protocol.Announceme | ||
| 211 | IsRead: int(userMsg.IsRead), | 211 | IsRead: int(userMsg.IsRead), |
| 212 | } | 212 | } |
| 213 | if bulletin.QuestionSwitch == 1 { | 213 | if bulletin.QuestionSwitch == 1 { |
| 214 | - if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil { | 214 | + if question, err = models.GetBulletinQuestionBy(bulletin.Id); err != nil { |
| 215 | log.Error(err.Error()) | 215 | log.Error(err.Error()) |
| 216 | return | 216 | return |
| 217 | } | 217 | } |
| @@ -257,7 +257,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | @@ -257,7 +257,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | ||
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | if companyId == 0 { | 259 | if companyId == 0 { |
| 260 | - if userCompany, err = models.GetUserCompanys(header.Uid); err != nil { | 260 | + if userCompany, err = models.GetUserCompanysFirst(header.Uid); err != nil { |
| 261 | log.Error(err) | 261 | log.Error(err) |
| 262 | return | 262 | return |
| 263 | } | 263 | } |
-
请 注册 或 登录 后发表评论