| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package repositories
- import (
- "fmt"
- "xorm.io/core"
- "xorm.io/xorm"
- "xps/datamodels"
- "xps/viewmodels"
- )
- type GroupMemberPositionRepo struct {
- engine *xorm.Engine
- }
- func NewGroupMemberPositionRepo(engine *xorm.Engine) *GroupMemberPositionRepo {
- return &GroupMemberPositionRepo{
- engine: engine,
- }
- }
- func (d *GroupMemberPositionRepo) GetById(ocId int64, gmpid int64)(*datamodels.GroupMemberPosition, error){
- data := &datamodels.GroupMemberPosition{OcId: ocId, GmpId: gmpid}
- ok, err := d.engine.Get(data)
- if !ok && err != nil {
- return nil, err
- } else {
- return data, nil
- }
- }
- func (d *GroupMemberPositionRepo) GetFirstPositionByGroupIdAndAccountId(ocId, groupId, accountId int64) (*viewmodels.GroupMemberPositionInfo, error) {
- sqlSelect := ` SELECT A.oc_id,
- A.gmp_id,
- A.group_id,
- B.group_name,
- A.account_id,
- C.account_name,
- A.position_id,
- D.position_name `
- sqlFrom := ` FROM s_group_member_position AS A
- LEFT JOIN s_group AS B ON ( A.oc_id = B.oc_id AND A.group_id = B.group_id )
- LEFT JOIN account AS C ON ( A.oc_id = C.oc_id AND A.account_id = C.account_id )
- LEFT JOIN s_position AS D ON ( A.oc_id = D.oc_id AND A.position_id = D.position_id) `
- sqlWhere := ` WHERE A.oc_id = ` + fmt.Sprintf("%d", ocId)
- sqlWhere += ` AND A.group_id = ` + fmt.Sprintf("%d", groupId)
- sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", accountId)
-
- roleMemberPositionInfo := &viewmodels.GroupMemberPositionInfo{}
- has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Limit(1).Get(roleMemberPositionInfo)
- if !has || err != nil {
- return nil, err
- }
- return roleMemberPositionInfo, nil
- }
- func (d *GroupMemberPositionRepo) GetByAccountId(ocId int64, accountId int64)(*datamodels.GroupMemberPosition, error){
- data := &datamodels.GroupMemberPosition{OcId: ocId, AccountId: accountId}
- ok, err := d.engine.Get(data)
- if !ok && err != nil {
- return nil, err
- } else {
- return data, nil
- }
- }
- func (d *GroupMemberPositionRepo) GetList(m map[string]interface{})([]viewmodels.GroupMemberPositionInfo, error){
- ocId := m["ocId"].(int64)
- sqlSelect := ` SELECT A.gmp_id,
- A.oc_id,
- A.group_id,
- B.group_name,
- A.account_id,
- D.account_name,
- D.account_real_name,
- A.position_id,
- C.position_name `
- sqlFrom := ` FROM s_group_member_position A
- LEFT JOIN s_group B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
- LEFT JOIN s_position C ON (A.oc_id = C.oc_id AND A.position_id = C.position_id)
- LEFT JOIN account D ON (A.oc_id = D.oc_id AND A.account_id = D.account_id) `
- sqlWhere := ` WHERE A.deleted_flag = 0
- AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
- if groupId, ok := m["groupId"]; ok {
- sqlWhere += ` AND A.group_id = ` + fmt.Sprintf("%d", groupId)
- }
- if accountId, ok := m["accountId"]; ok {
- sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", accountId)
- }
- if positionId, ok := m["positionId"]; ok {
- sqlWhere += ` AND A.position_id = ` + fmt.Sprintf("%d", positionId)
- }
- if keywords, ok := m["keywords"]; ok {
- sqlWhere += ` AND A.group_cat_title like '%` + fmt.Sprintf("%s", keywords) + `%'`
- }
- nodeLeft, ok1 := m["nodeLeft"]
- nodeRight, ok2 := m["nodeRight"]
- if ok1 && ok2 {
- sqlWhere += ` AND B.node_left >= ` + fmt.Sprintf("%d", nodeLeft)
- sqlWhere += ` AND B.node_right <= ` + fmt.Sprintf("%d", nodeRight)
- }
-
- datalist := make([]viewmodels.GroupMemberPositionInfo, 0)
- err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).OrderBy("group_id DESC").Find(&datalist)
- if err != nil {
- return nil, err
- } else {
- return datalist, nil
- }
- }
- func (d *GroupMemberPositionRepo) Create(data *datamodels.GroupMemberPosition) error {
- _, err := d.engine.Insert(data)
- return err
- }
- func (d *GroupMemberPositionRepo) Update(ocId int64, gmpId int64, data *datamodels.GroupMemberPosition) error {
- _, err := d.engine.ID(core.PK{ocId, gmpId}).Update(data)
- return err
- }
- func (d *GroupMemberPositionRepo) Delete(ocId int64, gmpId int64) error {
- _, err := d.engine.ID(core.PK{ocId, gmpId}).Delete(new(datamodels.GroupMemberPosition))
- return err
- }
- func (d *GroupMemberPositionRepo) DeleteByGroupId(ocId int64, groupId int64) error {
- _, err := d.engine.Where("oc_id = ?", ocId).
- Where("group_id = ?", groupId).
- Delete(new(datamodels.GroupMemberPosition))
- return err
- }
- func (d *GroupMemberPositionRepo) DeleteByAccountId(ocId int64, accountId int64) error {
- _, err := d.engine.Where("oc_id = ?", ocId).
- Where("account_id = ?", accountId).
- Delete(new(datamodels.GroupMemberPosition))
- return err
- }
|