一次性导入 出入库记录

出入库记录导出
This commit is contained in:
2024-06-21 10:31:35 +08:00
parent 21b5784829
commit 4ed4a68608
9 changed files with 56 additions and 210 deletions

View File

@@ -34,6 +34,8 @@ public class DateUtil {
public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* LocalDateTime 转时间戳
*
@@ -44,6 +46,9 @@ public class DateUtil {
return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
}
public static String getStrTime(Date date) {
return sdfTime.format(date);
}
/**
* 将Date对象转换为时间戳毫秒

View File

@@ -1,9 +1,7 @@
package cn.ysk.cashier.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
@@ -70,84 +68,6 @@ public class JSONUtil {
return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", false, true, false);
}
/**
* 将对象转为JSON字符串。
* 日期转为特别的格式不忽略null值的字段不格式化JSON字符串
*
* @param obj 被转换的对象
* @return JSON字符串发送异常时抛出
*/
public static String toJSONString(Object obj,boolean ignoreNull) {
return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", ignoreNull, true, false);
}
/**
* 将对象转为JSON字符串。不抛出异常专用于日志打印
*
* @param obj 被转换的对象
* @return JSON字符串出异常时返回null
*/
public static String toJSONStringNoThrows(Object obj) {
try {
return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", false, true, false);
} catch (Exception e) {
logError(e);
return null;
}
}
/**
* 解析JSON字符串成为一个Object结果可能是JSONArray(多个)或JSONObject(单个)
* 该方法可用于对json字符串不知道是对象还是列表的时候之用
* 假设json字符串多了某个字段可能是新加上去的显然转换成JSONEntity会有这个字段
*
* @param jsonStr 要解析的JSON字符串
* @return 返回JSONEntity当jsonArrayFlag 为true表示它是 JSONArray否则是JSONObject
*/
public static JSONEntity parseJSONStr2JSONEntity(String jsonStr) {
try {
Object value = JSON.parse(jsonStr);
boolean jsonArrayFlag = false;
if (value instanceof JSONArray) {
jsonArrayFlag = true;
}
return new JSONEntity(jsonArrayFlag, value);
} catch (Exception e) {
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
}
}
/**
* 字符串转为JSON对象,注意数组类型会抛异常[{name:"Stone"}]
* 假设json字符串多了某个字段可能是新加上去的显然转换成JSONObject时会有这个字段因为JSONObject就相当于map
*
* @param jsonStr 传入的JSON字串
* @return 返回转换结果。传入的JSON字串必须是对象而非数组否则会抛出异常
* @author Stone
*/
public static JSONObject parseJSONStr2JSONObject(String jsonStr) {
try {
return (JSONObject) JSONObject.parse(jsonStr);
} catch (Exception e) {
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
}
}
/**
* 字符串转为JSON数组,注意对象类型,非数组的会抛异常{name:"Stone"}
* 假设json字符串多了某个字段可能是新加上去的显然转换成JSONArray时其元素会有这个字段因为JSONArray的元素JSONObject就相当于map
*
* @param jsonStr 传入的JSON字串
* @return 返回转换结果。当传入的JSON字串是非数组形式时会抛出异常
* @author Stone
*/
public static JSONArray parseJSONStr2JSONArray(String jsonStr) {
try {
return (JSONArray) JSONArray.parse(jsonStr);
} catch (Exception e) {
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
}
}
/**
* 字符串转为某个类
@@ -166,14 +86,6 @@ public class JSONUtil {
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
}
}
public static <T> T jsonStrToObject(String jsonStr, Class<T> clazz) {
Object obj = JSONArray.parseObject(jsonStr, clazz);
return (T) obj;
}
public static <T> T jsonstrtoObject(String str,TypeReference<T> tTypeReference ){
return JSON.parseObject(str, tTypeReference);
}
public static void main(String[] args) {
String sss = "{\"bizData\":{\"amount\":1,\"currency\":\"cny\",\"ifCode\":\"sxfpay\",\"mchOrderNo\":\"CZ1715744291232\",\"mercNo\":\"B240510702030\",\"note\":\"等待用户付款\",\"payOrderId\":\"O1790587460614225921\",\"payType\":\"WECHAT\",\"settlementType\":\"D1\",\"state\":\"TRADE_AWAIT\",\"storeId\":\"S2405103298\",\"subject\":\"测试支付\",\"tradeFee\":0},\"code\":\"000000\",\"msg\":\"请求成功\",\"sign\":\"40710a3c293eeac3c7f4a1b0696a2bf6\",\"signType\":\"MD5\",\"timestamp\":\"20240515113813\"}";
@@ -181,56 +93,6 @@ public class JSONUtil {
// PublicResp<MainScanResp> response = JSON.parseObject(sss, typeRef);
System.out.println("pm");
}
/**
* 字符串转为某个类的列表
* 日期字段不管是时间戳形式还是yyyy-MM-dd HH:mm:ss的形式都能成功转换
* 假设json字符串多了某个字段可能是新加上去的T类没有转换成T对象的时候不会抛出异常
*
* @param jsonStr 传入的JSON字串
* @param clazz List里装的元素的类型
* @return 返回转换结果。当传入的JSON字串是非数组的形式时会抛出异常
* @author Stone
*/
public static <T> List<T> parseJSONStr2TList(String jsonStr, Class<T> clazz) {
try {
return JSONObject.parseArray(jsonStr, clazz);
} catch (Exception e) {
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
}
}
public static class JSONEntity {
public JSONEntity() {
}
public JSONEntity(boolean jsonArrayFlag, Object value) {
this.jsonArrayFlag = jsonArrayFlag;
this.value = value;
}
private boolean jsonArrayFlag;
private Object value;
public boolean getJsonArrayFlag() {
return jsonArrayFlag;
}
public Object getValue() {
return value;
}
@Override
public String toString() {
return "JSONEntity{" +
"jsonArrayFlag=" + jsonArrayFlag +
", value=" + value +
'}';
}
}
private static void logError(Exception e) {
e.printStackTrace();
}
}