字典管理

资源管理
资源类型管理
团购卷订单管理
团购卷订单退款
团购卷商品(套餐商品修改与保存)
This commit is contained in:
2024-05-15 16:32:34 +08:00
parent a4cbb3798e
commit 6ba4aadccb
49 changed files with 1778 additions and 393 deletions

View File

@@ -0,0 +1,150 @@
package cn.ysk.cashier.utils;
import org.apache.commons.lang3.StringUtils;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
public class BeanUtil {
// Map --> Bean 1: 利用Introspector,PropertyDescriptor实现 Map --> Bean
public static void transMap2Bean(Map<String, Object> map, Object obj) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo
.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
if (map.containsKey(key)) {
Object value = map.get(key);
// 得到property对应的setter方法
Method setter = property.getWriteMethod();
setter.invoke(obj, value);
}
}
} catch (Exception e) {
System.out.println("transMap2Bean Error " + e);
}
return;
}
public static String mapOrderStr(Map<String, Object> map) {
List<Entry<String, Object>> list = new ArrayList<Entry<String, Object>>(map.entrySet());
Collections.sort(list, new Comparator<Entry<String, Object>>() {
@Override
public int compare(Entry<String, Object> o1, Entry<String, Object> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
StringBuilder sb = new StringBuilder();
for (Entry<String, Object> mapping : list) {
sb.append(mapping.getKey() + "=" + mapping.getValue() + "&");
}
return sb.substring(0, sb.length() - 1);
}
// Bean --> Map 1: 利用Introspector和PropertyDescriptor 将Bean --> Map
public static Map<String, Object> transBean2Map(Object obj) {
if (obj == null) {
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
// 过滤class属性
if (!key.equals("class")) {
// 得到property对应的getter方法
Method getter = property.getReadMethod();
Object value = getter.invoke(obj);
if(null !=value && !"".equals(value)){
map.put(key, value);
}
}
}
} catch (Exception e) {
System.out.println("transBean2Map Error " + e);
}
return map;
}
public static LinkedHashMap<String, Object> transBeanMap(Object obj) {
if (obj == null) {
return null;
}
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
// 过滤class属性
if (!key.equals("class")) {
// 得到property对应的getter方法
Method getter = property.getReadMethod();
Object value = getter.invoke(obj);
if(null !=value && !"".equals(value)){
map.put(key, value);
}
}
}
} catch (Exception e) {
System.out.println("transBean2Map Error " + e);
}
return map;
}
public static <T> T mapToEntity(Map<String, Object> map, Class<T> entity) {
T t = null;
try {
t = entity.newInstance();
for(Field field : entity.getDeclaredFields()) {
if (map.containsKey(field.getName())) {
boolean flag = field.isAccessible();
field.setAccessible(true);
Object object = map.get(field.getName());
if (object!= null && field.getType().isAssignableFrom(object.getClass())) {
field.set(t, object);
}
field.setAccessible(flag);
}
}
return t;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return t;
}
}

View File

@@ -3,12 +3,16 @@ package cn.ysk.cashier.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* json工具类所有JSON转换通用该JSON工具类不许直接使用外部JSON转换后期会封闭掉直接调用JSON转换。
@@ -38,7 +42,7 @@ public final class FastJsonUtils {
* @param object 转换对象
* @return 转换结果
*/
public static String toJSONString(Object object) {
public static String toJSONString(Object object){
//不可序列化的类型直接打印其类名称
if (object instanceof HttpServletRequest
|| object instanceof HttpServletResponse

View File

@@ -1,10 +1,12 @@
package cn.ysk.cashier.utils;
import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
public class MD5Utils {
private static String byteArrayToHexString(byte b[]) {
@@ -121,4 +123,30 @@ public class MD5Utils {
}
}
/**
* @Title: encrypt
* @Description: (16位或32位密码)
* @param @param
* plainText
* @param @param
* flag true为32位,false为16位
* @throws UnsupportedEncodingException
*/
public static String encrypt(Map<String, Object> map, String privateKey, boolean flag) {
String param = null;
map.remove("sign");
map.remove("encrypt");
String result = BeanUtil.mapOrderStr(map);
if (StringUtils.isEmpty(result)) {
return null;
}
param = encrypt(encrypt(result)+privateKey);
if (flag) {
return param;
} else {
param = param.substring(8, 24);
}
return param;
}
}