|
@@ -2,6 +2,7 @@ package com.malk.zhixingtongde.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.malk.server.aliwork.YDConf;
|
|
|
import com.malk.server.aliwork.YDParam;
|
|
@@ -28,8 +29,8 @@ public class ZxtdReportServiceImpl implements ZxtdReportService {
|
|
|
@Autowired
|
|
|
private YDClient ydClient;
|
|
|
|
|
|
- private static String[] PROFIT_CLASSIFYS={"收入","销售费用","管理费用","研发费用","财务费用"};
|
|
|
- private static int[] PROFIT_NUMBERS={15,25,25,25,10};
|
|
|
+ private static String[] PROFIT_CLASSIFYS={"收入","销售费用","管理费用","研发费用","财务费用"};// 分类
|
|
|
+ private static int[] PROFIT_NUMBERS={15,25,25,25,10};// 报表默认长度
|
|
|
|
|
|
String _matchFormUuid(String code) {
|
|
|
Map<String, String> formUuid = UtilMap.empty();
|
|
@@ -45,12 +46,33 @@ public class ZxtdReportServiceImpl implements ZxtdReportService {
|
|
|
@Override
|
|
|
public void exportProfit(HttpServletResponse response,String year) {
|
|
|
// 1.获取宜搭数据
|
|
|
- List<Profit> dataList=getData(year);
|
|
|
- UtilExcel.exportListByTemplate(response,dataList, Profit.class, "利润", "Template_profit.xlsx");
|
|
|
+ Profit[] PROFIT_SUM=new Profit[5];// 分类小计数据
|
|
|
+ List<Profit> dataList=getData(year,PROFIT_SUM);
|
|
|
+ // 计算主数据
|
|
|
+ Map mainData=new HashMap();
|
|
|
+ mainData.put("year",year);
|
|
|
+ // 计算费用合计 与 净利润
|
|
|
+ String payTotalKey="payTotalAmt";
|
|
|
+ String payTotalAmtTotal="0";
|
|
|
+ String netProfitKey="netProfitAmt";
|
|
|
+ String netProfitTotal="0";
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
+ // 费用合计
|
|
|
+ String amt=addAmt(PROFIT_SUM,1,4,i);// 第一位数据是收入,不参与计算
|
|
|
+ mainData.put(payTotalKey+i,amt);
|
|
|
+ payTotalAmtTotal=NumberUtil.add(amt,payTotalAmtTotal).toString();
|
|
|
+ // 净利润
|
|
|
+ String net=subAmt(PROFIT_SUM,1,4,i);
|
|
|
+ mainData.put(netProfitKey+i,net);
|
|
|
+ netProfitTotal=NumberUtil.add(netProfitTotal,net).toString();
|
|
|
+ }
|
|
|
+ mainData.put("payTotalAmtTotal",payTotalAmtTotal);
|
|
|
+ mainData.put("netProfitTotal",netProfitTotal);
|
|
|
+ UtilExcel.exportMapAndListByTemplate(response,mainData,dataList, Profit.class, "利润", "Template_profit.xlsx");
|
|
|
}
|
|
|
|
|
|
// 按月获取利润表数据
|
|
|
- private List<Profit> getData(String year){
|
|
|
+ private List<Profit> getData(String year,Profit[] PROFIT_SUM){
|
|
|
// 查询宜搭底表数据
|
|
|
List<Map> list = (List<Map>) ydClient.queryData(YDParam.builder().formUuid(_matchFormUuid("PROFIT")).searchCondition(
|
|
|
JSONObject.toJSONString(UtilMap.map("textField_lqvp89br",year))
|
|
@@ -107,9 +129,29 @@ public class ZxtdReportServiceImpl implements ZxtdReportService {
|
|
|
list1.add(nullProfit);
|
|
|
}
|
|
|
// 添加小计
|
|
|
- list1.add(totalProfit.buildTotal());
|
|
|
+ PROFIT_SUM[i]=totalProfit.buildTotal();
|
|
|
+ list1.add(PROFIT_SUM[i]);
|
|
|
profitList.addAll(list1);
|
|
|
}
|
|
|
return profitList;
|
|
|
}
|
|
|
+
|
|
|
+ private String addAmt(Profit[] PROFIT_SUM,int start,int end,int i){
|
|
|
+ String result="0";
|
|
|
+ for (int j = start; j <= end; j++) {
|
|
|
+ result = NumberUtil.add(result,ReflectUtil.invoke(PROFIT_SUM[j],"getAmt"+i)).toString();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String subAmt(Profit[] PROFIT_SUM,int start,int end,int i){
|
|
|
+ String result=ReflectUtil.invoke(PROFIT_SUM[0],"getAmt"+i);// 0 是收入,其他是支出;
|
|
|
+ if(StrUtil.isBlankIfStr(result)){
|
|
|
+ result = "0";
|
|
|
+ }
|
|
|
+ for (int j = start; j <= end; j++) {
|
|
|
+ result = NumberUtil.sub(result,ReflectUtil.invoke(PROFIT_SUM[j],"getAmt"+i)).toString();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|