From ece58603b6e4144853d6fc8bf884f03467f7970e Mon Sep 17 00:00:00 2001 From: dimengzhe Date: Wed, 10 Jan 2024 15:09:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=8F=82=E6=95=B0=E5=AD=98?= =?UTF-8?q?=E9=94=80=E6=AF=94=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/dailyreport/DailyReportService.java | 176 ++++++++---------- 1 file changed, 74 insertions(+), 102 deletions(-) diff --git a/anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportService.java b/anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportService.java index 7b2670426a..4f93630a56 100644 --- a/anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportService.java +++ b/anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportService.java @@ -344,33 +344,26 @@ public class DailyReportService extends MybatisBaseService row4 = dailyReportVoList.stream().map(v -> { String saleOfStockRatio = ""; - try { - - Field field = v.getClass().getDeclaredField(String.valueOf(v.getSaleAllToThree())); - field.setAccessible(true); - String saleAllToThree = (String) field.get(v);//前三个月销售台数之和 - Field fieldStockTotal = v.getClass().getDeclaredField(String.valueOf(v.getStock_total())); - fieldStockTotal.setAccessible(true); - String stock_total = (String) fieldStockTotal.get(v);//库存总计 - if(StringUtils.isBlank(saleAllToThree)){ - saleOfStockRatio =stock_total+":1"; - }else{ - saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + String saleAllToThree = String.valueOf(v.getSaleAllToThree()); + String stock_total = String.valueOf(v.getStock_total()); + if (StringUtils.isBlank(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + if ("0".equals(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } - return saleOfStockRatio; - - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); } return saleOfStockRatio; }).collect(Collectors.toList()); - int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v->v.getSaleAllToThree()).sum(); - int stock_totalAll = dailyReportVoList.stream().mapToInt(v->v.getStock_total()).sum(); + int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v -> v.getSaleAllToThree()).sum(); + int stock_totalAll = dailyReportVoList.stream().mapToInt(v -> v.getStock_total()).sum(); String saleOfStockRatioString = ""; - if(saleAllToThreeAll == 0){ - saleOfStockRatioString = stock_totalAll+":1"; - }else{ - saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + if (saleAllToThreeAll == 0) { + saleOfStockRatioString = stock_totalAll + ":1"; + } else { + saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } row4.add(saleOfStockRatioString); dailyReportAppVo.setRow4(row4); @@ -617,13 +610,13 @@ public class DailyReportService extends MybatisBaseService row4 = dailyReportVoList.stream().map(v -> { String saleOfStockRatio = ""; - try { - - Field field = v.getClass().getDeclaredField(String.valueOf(v.getSaleAllToThree())); - field.setAccessible(true); - String saleAllToThree = (String) field.get(v);//前三个月销售台数之和 - Field fieldStockTotal = v.getClass().getDeclaredField(String.valueOf(v.getStock_total())); - fieldStockTotal.setAccessible(true); - String stock_total = (String) fieldStockTotal.get(v);//库存总计 - if(StringUtils.isBlank(saleAllToThree)){ - saleOfStockRatio =stock_total+":1"; - }else{ - saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + String saleAllToThree = String.valueOf(v.getSaleAllToThree()); + String stock_total = String.valueOf(v.getStock_total()); + if (StringUtils.isBlank(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + if ("0".equals(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } - return saleOfStockRatio; - - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); } return saleOfStockRatio; }).collect(Collectors.toList()); - int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v->v.getSaleAllToThree()).sum(); - int stock_totalAll = dailyReportVoList.stream().mapToInt(v->v.getStock_total()).sum(); + int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v -> v.getSaleAllToThree()).sum(); + int stock_totalAll = dailyReportVoList.stream().mapToInt(v -> v.getStock_total()).sum(); String saleOfStockRatioString = ""; - if(saleAllToThreeAll == 0){ - saleOfStockRatioString = stock_totalAll+":1"; - }else{ - saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + if (saleAllToThreeAll == 0) { + saleOfStockRatioString = stock_totalAll + ":1"; + } else { + saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } row4.add(saleOfStockRatioString); dailyReportAppVo.setRow4(row4); @@ -985,33 +971,26 @@ public class DailyReportService extends MybatisBaseService row4 = dailyReportVoList.stream().map(v -> { String saleOfStockRatio = ""; - try { - - Field field = v.getClass().getDeclaredField(String.valueOf(v.getSaleAllToThree())); - field.setAccessible(true); - String saleAllToThree = (String) field.get(v);//前三个月销售台数之和 - Field fieldStockTotal = v.getClass().getDeclaredField(String.valueOf(v.getStock_total())); - fieldStockTotal.setAccessible(true); - String stock_total = (String) fieldStockTotal.get(v);//库存总计 - if(StringUtils.isBlank(saleAllToThree)){ - saleOfStockRatio =stock_total+":1"; - }else{ - saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + String saleAllToThree = String.valueOf(v.getSaleAllToThree()); + String stock_total = String.valueOf(v.getStock_total()); + if (StringUtils.isBlank(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + if ("0".equals(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } - return saleOfStockRatio; - - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); } return saleOfStockRatio; }).collect(Collectors.toList()); - int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v->v.getSaleAllToThree()).sum(); - int stock_totalAll = dailyReportVoList.stream().mapToInt(v->v.getStock_total()).sum(); + int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v -> v.getSaleAllToThree()).sum(); + int stock_totalAll = dailyReportVoList.stream().mapToInt(v -> v.getStock_total()).sum(); String saleOfStockRatioString = ""; - if(saleAllToThreeAll == 0){ - saleOfStockRatioString = stock_totalAll+":1"; - }else{ - saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + if (saleAllToThreeAll == 0) { + saleOfStockRatioString = stock_totalAll + ":1"; + } else { + saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } row4.add(saleOfStockRatioString); dailyReportAppVo.setRow4(row4); @@ -1305,33 +1284,26 @@ public class DailyReportService extends MybatisBaseService row4 = dailyReportVoList.stream().map(v -> { String saleOfStockRatio = ""; - try { - - Field field = v.getClass().getDeclaredField(String.valueOf(v.getSaleAllToThree())); - field.setAccessible(true); - String saleAllToThree = (String) field.get(v);//前三个月销售台数之和 - Field fieldStockTotal = v.getClass().getDeclaredField(String.valueOf(v.getStock_total())); - fieldStockTotal.setAccessible(true); - String stock_total = (String) fieldStockTotal.get(v);//库存总计 - if(StringUtils.isBlank(saleAllToThree)){ - saleOfStockRatio =stock_total+":1"; - }else{ - saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + String saleAllToThree = String.valueOf(v.getSaleAllToThree()); + String stock_total = String.valueOf(v.getStock_total()); + if (StringUtils.isBlank(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + if ("0".equals(saleAllToThree)) { + saleOfStockRatio = stock_total + ":1"; + } else { + saleOfStockRatio = new BigDecimal(stock_total).divide((new BigDecimal(saleAllToThree).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } - return saleOfStockRatio; - - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); } return saleOfStockRatio; }).collect(Collectors.toList()); - int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v->v.getSaleAllToThree()).sum(); - int stock_totalAll = dailyReportVoList.stream().mapToInt(v->v.getStock_total()).sum(); + int saleAllToThreeAll = dailyReportVoList.stream().mapToInt(v -> v.getSaleAllToThree()).sum(); + int stock_totalAll = dailyReportVoList.stream().mapToInt(v -> v.getStock_total()).sum(); String saleOfStockRatioString = ""; - if(saleAllToThreeAll == 0){ - saleOfStockRatioString = stock_totalAll+":1"; - }else{ - saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3),4,BigDecimal.ROUND_HALF_UP)),2,BigDecimal.ROUND_HALF_UP).toString()+":1"; + if (saleAllToThreeAll == 0) { + saleOfStockRatioString = stock_totalAll + ":1"; + } else { + saleOfStockRatioString = new BigDecimal(stock_totalAll).divide((new BigDecimal(saleAllToThreeAll).divide(new BigDecimal(3), 4, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP).toString() + ":1"; } row4.add(saleOfStockRatioString); dailyReportAppVo.setRow4(row4);