|
@@ -42,20 +42,20 @@ public class DataChange {
|
|
|
*/
|
|
|
public static BigDecimal dataToBigDecimal(Object data){
|
|
|
if (data != null){
|
|
|
- if(data instanceof String){
|
|
|
- String data1 = (String) data;
|
|
|
- return new BigDecimal(data1);
|
|
|
- }
|
|
|
- if(data instanceof Double){
|
|
|
- String data3 = data.toString();
|
|
|
- return new BigDecimal(data3);
|
|
|
- }
|
|
|
- if(data instanceof Integer){
|
|
|
- Integer data2 = (Integer) data;
|
|
|
- return new BigDecimal(data2);
|
|
|
- }
|
|
|
if(data instanceof BigDecimal){
|
|
|
return (BigDecimal) data;
|
|
|
+ }else{
|
|
|
+ String str = String.valueOf(data);
|
|
|
+ BigDecimal decimal = null;
|
|
|
+ if(!"".equals(str)){
|
|
|
+ try {
|
|
|
+ decimal = new BigDecimal(str);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(data + ":数据解析失败!返回0");
|
|
|
+ return new BigDecimal(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return decimal;
|
|
|
}
|
|
|
}
|
|
|
return new BigDecimal(0);
|
|
@@ -69,6 +69,8 @@ public class DataChange {
|
|
|
public static String dateToDayDate(Object date){
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date changeDate = null;
|
|
|
+ if(date == null)
|
|
|
+ return null;
|
|
|
try{
|
|
|
changeDate = (Date) date;
|
|
|
}catch (Exception e){
|
|
@@ -108,10 +110,15 @@ public class DataChange {
|
|
|
for (Map<String, Object> map : list) {
|
|
|
for (String s : key) {
|
|
|
//修改数据为带两位小数
|
|
|
- BigDecimal oldDate = (BigDecimal) map.get(s);
|
|
|
- DecimalFormat df = new DecimalFormat("0.00");
|
|
|
- String resultDeduction = df.format(oldDate.doubleValue());
|
|
|
- map.put(s, resultDeduction);
|
|
|
+ try {
|
|
|
+ BigDecimal oldDate = (BigDecimal) map.get(s);
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ String resultDeduction = df.format(oldDate.doubleValue());
|
|
|
+ map.put(s, resultDeduction);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("原料扣减量数据有误");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -136,4 +143,49 @@ public class DataChange {
|
|
|
long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
|
|
|
return day + "天"+ + hour+ "时" + min + "分" + s + "秒";
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成带时间的八位数顺序号
|
|
|
+ * @param start 前缀
|
|
|
+ * @param id 顺序号 主键Id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String generateEightDigitsNumber(String start, Integer id){
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ StringBuilder sb = new StringBuilder(start + sdf.format(new Date()));
|
|
|
+ sb.append(
|
|
|
+ id < 10
|
|
|
+ ? "0000000" + id : id < 100
|
|
|
+ ? "000000" + id : id < 1000
|
|
|
+ ? "00000" + id : id < 10000
|
|
|
+ ? "0000" + id : id < 100000
|
|
|
+ ? "000" + id : id < 1000000
|
|
|
+ ? "00" + id : id < 10000000
|
|
|
+ ? "0" + id : id.toString()
|
|
|
+ );
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据时间段查询数据
|
|
|
+ * @Author TXF
|
|
|
+ * @Date 2022/1/10 23:21
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param map
|
|
|
+ * @param sdf
|
|
|
+ * @return
|
|
|
+ **/
|
|
|
+ public static void queryDataByDate(String startTime, String endTime, Map<String, Object> map, SimpleDateFormat sdf){
|
|
|
+ if (startTime != null && !"null".equals(startTime) && endTime != null && !"null".equals(endTime)) {
|
|
|
+ map.put("startDate", sdf.format(new Date(Long.parseLong(startTime))));
|
|
|
+ map.put("endDate", sdf.format(new Date(Long.parseLong(endTime) + 86400000)));
|
|
|
+ } else if (startTime != null && !"null".equals(startTime)) {
|
|
|
+ map.put("oneDate", sdf.format(new Date(Long.parseLong(startTime))));
|
|
|
+ } else if (endTime != null && !"null".equals(endTime)) {
|
|
|
+ map.put("oneDate", sdf.format(new Date(Long.parseLong(endTime))));
|
|
|
+ } else {
|
|
|
+ map.put("oneDate", sdf.format(new Date()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|