ParamUtils.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.kmall.admin.utils;
  2. import com.kmall.api.contants.Dict;
  3. import com.kmall.common.entity.SysUserEntity;
  4. import com.kmall.common.utils.RRException;
  5. import com.kmall.common.utils.ShiroUtils;
  6. import java.util.Map;
  7. /**
  8. * 参数工具类
  9. */
  10. public class ParamUtils {
  11. /**
  12. * 根据用户类型设置查询权限
  13. *
  14. * @param params 查询参数
  15. * @param storeKey 当用户是门店时,放入的key,值为门店id
  16. * @param merchKey 当用户是商户时,放入的key,值为商户编号
  17. * @param bothSet 为true时,不管是门店还是商户都只设置storeKey和merchKey中不为null的值
  18. */
  19. public static void setQueryPowerByRoleType(Map params, String storeKey, String merchKey, boolean bothSet) {
  20. SysUserEntity user = ShiroUtils.getUserEntity();
  21. if (user != null) {
  22. if (bothSet) {
  23. if (Dict.roleType.item_2.getItem().equals(user.getRoleType()) ||
  24. Dict.roleType.item_3.getItem().equals(user.getRoleType())) {
  25. if (storeKey == null && merchKey == null) {
  26. throw new RRException("参数错误");
  27. }
  28. if (storeKey != null && merchKey != null) {
  29. throw new RRException("参数错误");
  30. }
  31. if (storeKey != null) {
  32. params.put(storeKey, user.getStoreId());
  33. } else if (merchKey != null) {
  34. params.put(merchKey, user.getMerchSn());
  35. }
  36. }
  37. } else {
  38. if (Dict.roleType.item_2.getItem().equals(user.getRoleType())) {
  39. params.put(storeKey, user.getStoreId());
  40. } else if (Dict.roleType.item_3.getItem().equals(user.getRoleType())) {
  41. params.put(merchKey, user.getMerchSn());
  42. }
  43. }
  44. }
  45. }
  46. }