ParamUtils.java 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.kmall.admin.utils;
  2. import com.kmall.common.constant.Dict;
  3. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  4. import com.kmall.common.utils.DateUtils;
  5. import com.kmall.common.utils.RRException;
  6. import org.apache.commons.lang3.StringUtils;
  7. import java.util.Map;
  8. /**
  9. * 参数工具类
  10. */
  11. public class ParamUtils {
  12. private static String ISO = "iso-8859-1";
  13. private static String UTF = "utf-8";
  14. /**
  15. * 根据用户类型设置查询权限
  16. *
  17. * @param params 查询参数
  18. * @param storeKey 当用户是门店时,放入的key,值为门店id
  19. * @param merchKey 当用户是商户时,放入的key,值为商户编号
  20. * @param thirdMerchKey 当用户是商户时,放入的key,值为第三方商户编号
  21. */
  22. public static void setQueryPowerByRoleType(Map params, String storeKey, String merchKey, String thirdMerchKey) {
  23. SysUserEntity user = ShiroUtils.getUserEntity();
  24. if (user == null) {
  25. throw new RRException("用户登录超时,请重新登录");
  26. }
  27. if (Dict.roleType.item_2.getItem().equals(user.getRoleType())) {
  28. if (storeKey == null) {
  29. throw new RRException("参数错误");
  30. }
  31. if(StringUtils.isNotEmpty(merchKey)){
  32. params.put(merchKey, user.getMerchSn());
  33. }
  34. if(StringUtils.isNotEmpty(thirdMerchKey)){
  35. params.put(thirdMerchKey, user.getThirdPartyMerchCode());
  36. }
  37. if(StringUtils.isNotEmpty(storeKey)){
  38. params.put(storeKey, user.getStoreId());
  39. }
  40. }
  41. if (Dict.roleType.item_3.getItem().equals(user.getRoleType())) {
  42. if(StringUtils.isNotEmpty(merchKey)){
  43. params.put(merchKey, user.getMerchSn());
  44. }
  45. }
  46. if (Dict.roleType.item_4.getItem().equals(user.getRoleType())) {
  47. if(StringUtils.isNotEmpty(merchKey)){
  48. params.put(merchKey, user.getMerchSn());
  49. }
  50. if(StringUtils.isNotEmpty(thirdMerchKey)){
  51. params.put(thirdMerchKey, user.getThirdPartyMerchCode());
  52. }
  53. }
  54. }
  55. public static void setName(Map params, String nameKey){
  56. String name = (String) params.get(nameKey);
  57. if(org.apache.commons.lang3.StringUtils.isNotEmpty(name)){
  58. try{
  59. name = new String(name.trim().getBytes(ISO),UTF);
  60. }catch (Exception e){
  61. e.printStackTrace();
  62. }
  63. params.put(nameKey, name);
  64. }
  65. }
  66. public static Map<String, Object> setTimeMap(Map<String, Object> params){
  67. String startTime = (String) params.get("startTime");
  68. String endTime = (String) params.get("endTime");
  69. if(org.apache.commons.lang.StringUtils.isNotEmpty(startTime)) {
  70. try {
  71. startTime = new String(startTime.getBytes(ISO), UTF);
  72. } catch (Exception e) {
  73. e.printStackTrace();
  74. }
  75. startTime = DateUtils.getDate(startTime);
  76. params.put("startTime", startTime + " 00:00:00");
  77. }
  78. if(org.apache.commons.lang.StringUtils.isNotEmpty(endTime)) {
  79. try {
  80. endTime = new String(endTime.getBytes(ISO), UTF);
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. }
  84. endTime = DateUtils.getDate(endTime);
  85. params.put("endTime", endTime + " 59:59:59");
  86. }
  87. return params;
  88. }
  89. }