浏览代码

feature(结算): 菜单拆分查询逻辑优化

likai 4 年之前
父节点
当前提交
fe26735def

+ 5 - 1
handler/account.go

@@ -41,8 +41,12 @@ func (a *Account) AccountList(ctx context.Context, req *account.AccountReq, rsp
 	if err != nil {
 		return err
 	}
+	user, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
 	g.Log().Info("Received Account.AccountList request @ " + tenant)
-	list, err := service.NewAccountSrv(tenant).AccountList(req)
+	list, err := service.NewAccountSrv(tenant).AccountList(req, user)
 	_, err, code, _ := myerrors.CheckError(err)
 	if err != nil {
 		rsp.Code = code

+ 5 - 1
handler/settle_account_bill.go

@@ -20,12 +20,16 @@ func (a *SettleAccountBillController) SettleAccountBillList(ctx context.Context,
 	if err != nil {
 		return err
 	}
+	user, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
 	g.Log().Info("Received SettleAccountBillController.SettleAccountBillList request @ " + tenant)
 	if req.Current < 0 {
 		req.Current = DefaultPageCurrent
 	}
 
-	var list, total, errors = service.NewService(tenant).List(*req)
+	var list, total, errors = service.NewService(tenant).List(*req, user)
 	_, err, code, msg := myerrors.CheckError(errors)
 	if err != nil {
 		return err

+ 5 - 1
handler/settle_account_main.go

@@ -20,12 +20,16 @@ func (a *SettleAccountMainController) SettleAccountMainList(ctx context.Context,
 	if err != nil {
 		return err
 	}
+	user, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
 	g.Log().Info("Received SettleAccountMainController.SettleAccountMainList request @ " + tenant)
 	if req.Current < 0 {
 		req.Current = DefaultPageCurrent
 	}
 
-	var list, total, errors = service.NewService(tenant).List(*req)
+	var list, total, errors = service.NewService(tenant).List(*req, user)
 	_, err, code, msg := myerrors.CheckError(errors)
 	if err != nil {
 		return err

+ 1 - 0
model/account/base_account.go

@@ -31,6 +31,7 @@ type AccountReq struct {
 	Account     string `json:"account"`
 	AccountName string `json:"accountName"`
 	RealName    string `json:"realName"`
+	IsSelf       string `json:"isSelf"`  // 1 查看全部;其他 查看自己
 }
 
 type BaseAccountRsp struct {

+ 1 - 0
model/account/settle_account_bill.go

@@ -21,6 +21,7 @@ type SettleAccountBillReq struct {
 	SettleDate      string `json:"settleDate"`
 	SettleUser      string `json:"settleUser"`
 	MainUser      string `json:"mainUser"`
+	IsSelf       string `json:"isSelf"`  // 1 查看全部;其他 查看自己
 }
 
 type AccountBillSettleReq struct {

+ 1 - 0
model/account/settle_account_main.go

@@ -33,6 +33,7 @@ type SettleAccountMainReq struct {
 	SettleEndDate string `json:"settleEndDate"`
 	ActualStartDate string `json:"actualStartDate"`
 	ActualEndDate string `json:"actualEndDate"`
+	SearchType       string `json:"searchType"` // 1 查询全部;2 查询主用户;3或其他 查询从用户
 }
 
 type AccountMainConfirmReq struct {

+ 1 - 1
model/user/base_user.go

@@ -32,7 +32,7 @@ type UserInfoReq struct {
 	UserName     string `json:"user_name"`
 	Mobile       string `json:"mobile"`
 	ReqType      int    `json:"req_type"` // 请求类型 设备预约(1:预约资格 2:优先预约权) 主从用户管理(1:主用户查询 2:从用户查询)
-	IsSelf       string `json:"isSelf"`
+	IsSelf       string `json:"isSelf"`  // 1 查看全部;其他 查看自己
 }
 
 type UserInfoRsp struct {

+ 4 - 1
service/account/account.go

@@ -43,7 +43,7 @@ func (s AccountService) Save(req *account.BaseAccount, user request.UserInfo) er
 }
 
 // AccountList 财务账号分页查询
-func (s AccountService) AccountList(req *account.AccountReq) (infos account.BaseAccountRsp, err error) {
+func (s AccountService) AccountList(req *account.AccountReq, user request.UserInfo) (infos account.BaseAccountRsp, err error) {
 	current := req.PageNun
 	size := req.PageSize
 	model := s.Dao.DB.Model("base_account a")
@@ -56,6 +56,9 @@ func (s AccountService) AccountList(req *account.AccountReq) (infos account.Base
 	if req.AccountName != "" {
 		model = model.WhereLike("AccountName", "%" + req.AccountName + "%")
 	}
+	if req.IsSelf != "1" { // 1 查看全部;其他 查看自己
+		model = model.Where("MainUserId", user.Id)
+	}
 	infos.Total, err = model.Count()
 	if err != nil {
 		return infos, err

+ 4 - 1
service/settle_account_bill/settle_account_bill.go

@@ -26,7 +26,7 @@ func NewService(tenant string) Service {
 }
 
 // List 会议室列表
-func (s Service)  List(req model.ListReq) ([]accountModel.SettleAccountBill, int, error) {
+func (s Service)  List(req model.ListReq, user request.UserInfo) ([]accountModel.SettleAccountBill, int, error) {
 	entityModel := s.Dao.M
 	where := "1=1"
 
@@ -57,6 +57,9 @@ func (s Service)  List(req model.ListReq) ([]accountModel.SettleAccountBill, int
 		if entity.StartDate != "" && entity.EndDate != "" {
 			where += fmt.Sprintf(" AND StartDate>'%v' AND EndDate<'%v'", entity.StartDate, entity.EndDate)
 		}
+		if entity.IsSelf != "1" {  // 1 查看全部;其他 查看自己
+			where += fmt.Sprintf(" AND MainUserId='%v'", user.Id)
+		}
 	}
 	entityModel = entityModel.Where(where)
 	total, err := entityModel.Count()

+ 8 - 1
service/settle_account_main/settle_account_main.go

@@ -26,7 +26,7 @@ func NewService(tenant string) Service {
 }
 
 // List 结算明细
-func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountMain, int, error) {
+func (s Service) List(req model.ListReq, user request.UserInfo) ([]accountModel.SettleAccountMain, int, error) {
 	entityModel := s.Dao.M
 	where := "1=1"
 
@@ -36,6 +36,13 @@ func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountMain, int,
 		if err != nil {
 			return nil, 0, err
 		}
+		if entity.SearchType != "1" { // 1 查询全部;2 查询主用户;3或其他 查询从用户
+			if entity.SearchType == "2" {
+				where += fmt.Sprintf(" AND MainUserId='%v'", user.Id)
+			} else {
+				where += fmt.Sprintf(" AND AttachUserId='%v'", user.Id)
+			}
+		}
 		if entity.MainUserId != 0 {
 			where += fmt.Sprintf(" AND MainUserId='%v'", entity.MainUserId)
 		}

+ 1 - 1
service/system/system.go

@@ -98,7 +98,7 @@ func (s Service) GetUserList(req *user.UserInfoReq, userId int32) (userInfos use
 	if req.ReqType == 1 { // 获取主用户信息
 		count, err = model.InnerJoin("master_user e", "a.Id = e.UserId ").Where(where + " and e.Id is not null").Count()
 	} else if req.ReqType == 2 { // 从用户信息
-		if req.IsSelf == "1" {
+		if req.IsSelf == "1" { // 1 查看全部;其他 查看自己
 			count, err = model.InnerJoin("base_user_relation e", "a.Id = e.UserId").Where(where).Count()
 		} else {
 			count, err = model.InnerJoin("base_user_relation e", "a.Id = e.UserId").Where(where + " and e.Pid = " + strconv.Itoa(int(userId))).Count()