From 1cdc79618b311787dd36acd0808b6ba73e172ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Thu, 30 Apr 2020 22:50:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=93=E7=AE=97=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E6=8A=A5=E8=A1=A8=E7=9A=84=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erp_web/pages/reports/account_report.html | 29 ++++++--- .../jsh/erp/controller/AccountController.java | 21 +++++++ .../erp/service/account/AccountService.java | 59 +++++++++++++++---- 3 files changed, 88 insertions(+), 21 deletions(-) diff --git a/erp_web/pages/reports/account_report.html b/erp_web/pages/reports/account_report.html index 06c2c0e6..4aea21d2 100644 --- a/erp_web/pages/reports/account_report.html +++ b/erp_web/pages/reports/account_report.html @@ -41,7 +41,8 @@ 打印
- 当前总余额:0   + 本月发生总额:0   + 当前总余额:0
@@ -181,13 +182,25 @@ if(res && res.code === 200){ if(res.data && res.data.page) { $("#tableData").datagrid('loadData', res.data.page); - var total = 0; - res.data.page.rows.forEach(function(value, index, array){ - //执行某些操作 - total += value.currentamount; - }) + } + } + }, + //此处添加错误处理 + error: function () { + $.messager.alert('查询提示', '查询数据后台异常,请稍后再试!', 'error'); + return; + } + }); - $(".first-total").text(total); //当前总余额 + $.ajax({ + type: "get", + url: "/account/getStatistics", + dataType: "json", + success: function (res) { + if (res && res.code === 200) { + if(res.data) { + $("#allMonthAmount").text(res.data.allMonthAmount); + $("#allCurrentAmount").text(res.data.allCurrentAmount); } } }, @@ -258,7 +271,7 @@ } }, {title: '余额', field: 'balance', width: 80}, - {title: '入库出库日期', field: 'operTime', width: 180} + {title: '日期', field: 'operTime', width: 180} ]], onLoadError: function () { $.messager.alert('页面加载提示', '页面加载异常,请稍后再试!', 'error'); diff --git a/src/main/java/com/jsh/erp/controller/AccountController.java b/src/main/java/com/jsh/erp/controller/AccountController.java index 5de82737..54485a3b 100644 --- a/src/main/java/com/jsh/erp/controller/AccountController.java +++ b/src/main/java/com/jsh/erp/controller/AccountController.java @@ -6,6 +6,7 @@ import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.constants.ExceptionConstants; import com.jsh.erp.datasource.entities.Account; import com.jsh.erp.datasource.vo.AccountVo4InOutList; +import com.jsh.erp.datasource.vo.AccountVo4List; import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.service.account.AccountService; import com.jsh.erp.utils.BaseResponseInfo; @@ -182,4 +183,24 @@ public class AccountController { return result; } + /** + * 结算账户的统计 + * @param request + * @return + */ + @GetMapping(value = "/getStatistics") + public BaseResponseInfo getStatistics(HttpServletRequest request) throws Exception { + BaseResponseInfo res = new BaseResponseInfo(); + try { + Map map = accountService.getStatistics(); + res.code = 200; + res.data = map; + } catch(Exception e){ + e.printStackTrace(); + res.code = 500; + res.data = "获取数据失败"; + } + return res; + } + } diff --git a/src/main/java/com/jsh/erp/service/account/AccountService.java b/src/main/java/com/jsh/erp/service/account/AccountService.java index 8adc091b..38b8610a 100644 --- a/src/main/java/com/jsh/erp/service/account/AccountService.java +++ b/src/main/java/com/jsh/erp/service/account/AccountService.java @@ -26,9 +26,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; @Service public class AccountService { @@ -324,21 +322,17 @@ public class AccountService { if (!ids.equals("")) { ids = ids.substring(0, ids.length() - 1); } - AccountItemExample exampleAi = new AccountItemExample(); if (!ids.equals("")) { List idList = StringUtil.strToLongList(ids); exampleAi.createCriteria().andAccountidEqualTo(id).andHeaderidIn(idList) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - } else { - exampleAi.createCriteria().andAccountidEqualTo(id) - .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - } - List dataListOne = accountItemMapper.selectByExample(exampleAi); - if (dataListOne != null) { - for (AccountItem accountItem : dataListOne) { - if(accountItem.getEachamount()!=null) { - accountSum = accountSum.add(accountItem.getEachamount()); + List dataListOne = accountItemMapper.selectByExample(exampleAi); + if (dataListOne != null) { + for (AccountItem accountItem : dataListOne) { + if(accountItem.getEachamount()!=null) { + accountSum = accountSum.add(accountItem.getEachamount()); + } } } } @@ -535,4 +529,43 @@ public class AccountService { return deleteTotal; } + + public Map getStatistics() { + Map map = new HashMap<>(); + try { + List list = getAccount(); + String timeStr = Tools.getCurrentMonth(); + BigDecimal allMonthAmount = BigDecimal.ZERO; + BigDecimal allCurrentAmount = BigDecimal.ZERO; + if (null != list && null !=timeStr) { + for (Account a : list) { + BigDecimal monthAmount = getAccountSum(a.getId(), timeStr, "month").add(getAccountSumByHead(a.getId(), timeStr, "month")) + .add(getAccountSumByDetail(a.getId(), timeStr, "month")).add(getManyAccountSum(a.getId(), timeStr, "month")); + BigDecimal currentAmount = getAccountSum(a.getId(), "", "month").add(getAccountSumByHead(a.getId(), "", "month")) + .add(getAccountSumByDetail(a.getId(), "", "month")).add(getManyAccountSum(a.getId(), "", "month")).add(a.getInitialamount()); + allMonthAmount = allMonthAmount.add(monthAmount); + allCurrentAmount = allCurrentAmount.add(currentAmount); + } + } + map.put("allCurrentAmount", priceFormat(allCurrentAmount)); //当前总金额 + map.put("allMonthAmount", priceFormat(allMonthAmount)); //本月发生额 + } catch (Exception e) { + JshException.readFail(logger, e); + } + return map; + } + + /** + * 价格格式化 + * @param price + * @return + */ + private String priceFormat(BigDecimal price) { + String priceFmt = "0"; + DecimalFormat df = new DecimalFormat(".##"); + if ((price.compareTo(BigDecimal.ZERO))!=0) { + priceFmt = df.format(price); + } + return priceFmt; + } }