12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.kmall.admin.utils;
- import com.kmall.common.constant.Dict;
- import com.kmall.admin.fromcomm.entity.SysUserEntity;
- import com.kmall.common.utils.DateUtils;
- import com.kmall.common.utils.RRException;
- import org.apache.commons.lang3.StringUtils;
- import java.util.Map;
- /**
- * 参数工具类
- */
- public class ParamUtils {
- private static String ISO = "iso-8859-1";
- private static String UTF = "utf-8";
- /**
- * 根据用户类型设置查询权限
- *
- * @param params 查询参数
- * @param storeKey 当用户是门店时,放入的key,值为门店id
- * @param merchKey 当用户是商户时,放入的key,值为商户编号
- * @param thirdMerchKey 当用户是商户时,放入的key,值为第三方商户编号
- */
- public static void setQueryPowerByRoleType(Map params, String storeKey, String merchKey, String thirdMerchKey) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- if (user == null) {
- throw new RRException("用户登录超时,请重新登录");
- }
- if (Dict.roleType.item_2.getItem().equals(user.getRoleType())) {
- if (storeKey == null) {
- throw new RRException("参数错误");
- }
- if(StringUtils.isNotEmpty(merchKey)){
- params.put(merchKey, user.getMerchSn());
- }
- if(StringUtils.isNotEmpty(thirdMerchKey)){
- params.put(thirdMerchKey, user.getThirdPartyMerchCode());
- }
- if(StringUtils.isNotEmpty(storeKey)){
- params.put(storeKey, user.getStoreId());
- }
- }
- if (Dict.roleType.item_3.getItem().equals(user.getRoleType())) {
- if(StringUtils.isNotEmpty(merchKey)){
- params.put(merchKey, user.getMerchSn());
- }
- }
- if (Dict.roleType.item_4.getItem().equals(user.getRoleType())) {
- if(StringUtils.isNotEmpty(merchKey)){
- params.put(merchKey, user.getMerchSn());
- }
- if(StringUtils.isNotEmpty(thirdMerchKey)){
- params.put(thirdMerchKey, user.getThirdPartyMerchCode());
- }
- }
- }
- public static void setName(Map params, String nameKey){
- String name = (String) params.get(nameKey);
- if(org.apache.commons.lang3.StringUtils.isNotEmpty(name)){
- try{
- name = new String(name.trim().getBytes(ISO),UTF);
- }catch (Exception e){
- e.printStackTrace();
- }
- params.put(nameKey, name);
- }
- }
- public static Map<String, Object> setTimeMap(Map<String, Object> params){
- String startTime = (String) params.get("startTime");
- String endTime = (String) params.get("endTime");
- if(org.apache.commons.lang.StringUtils.isNotEmpty(startTime)) {
- try {
- startTime = new String(startTime.getBytes(ISO), UTF);
- } catch (Exception e) {
- e.printStackTrace();
- }
- startTime = DateUtils.getDate(startTime);
- params.put("startTime", startTime + " 00:00:00");
- }
- if(org.apache.commons.lang.StringUtils.isNotEmpty(endTime)) {
- try {
- endTime = new String(endTime.getBytes(ISO), UTF);
- } catch (Exception e) {
- e.printStackTrace();
- }
- endTime = DateUtils.getDate(endTime);
- params.put("endTime", endTime + " 59:59:59");
- }
- return params;
- }
- }
|