ParamUtils.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.kmall.admin.utils;
  2. import com.kmall.common.constant.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. throw new RRException("用户登录超时,请重新登录");
  23. }
  24. if (bothSet) {
  25. if (Dict.roleType.item_2.getItem().equals(user.getRoleType()) ||
  26. Dict.roleType.item_3.getItem().equals(user.getRoleType())) {
  27. if (storeKey == null && merchKey == null) {
  28. throw new RRException("参数错误");
  29. }
  30. if (storeKey != null && merchKey != null) {
  31. throw new RRException("参数错误");
  32. }
  33. if (storeKey != null) {
  34. params.put(storeKey, user.getStoreId());
  35. } else if (merchKey != null) {
  36. params.put(merchKey, user.getMerchSn());
  37. }
  38. }
  39. } else {
  40. if (Dict.roleType.item_2.getItem().equals(user.getRoleType())) {
  41. params.put(storeKey, user.getStoreId());
  42. } else if (Dict.roleType.item_3.getItem().equals(user.getRoleType())) {
  43. params.put(merchKey, user.getMerchSn());
  44. }
  45. }
  46. }
  47. }