| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package system
- 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) GetByList(m map[string]interface{})([]viewmodels.GroupMemberPositionInfo, error){
- ocId := m["ocId"].(int64)
- keywords := m["keywords"].(string)
- sqlSelect := `SELECT A.gm_id,
- A.group_id,
- A.group_name,
- A.account_id,
- A.group_member_remark `
- sqlFrom := ` FROM s_group_member AS A
- LEFT JOIN s_group AS B ON (A.group_id = B.group_id) `
- sqlWhere := `WHERE A.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
- if keywords != "" {
- sqlWhere += ` AND B.group_name like ` + "'%" + keywords + "%'"
- }
-
- datalist := make([]viewmodels.GroupMemberPositionInfo, 0)
- err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).OrderBy("group_id DESC").Find(&datalist)
- if err != nil {
- return nil, err
- }
- 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
- }
|