Browse Source

优化导出功能

java110 5 years ago
parent
commit
db85c51ecd

+ 9 - 0
java110-bean/src/main/java/com/java110/dto/fee/FeeConfigDto.java

@@ -40,6 +40,7 @@ public class FeeConfigDto extends PageDto implements Serializable {
     private String squarePrice;
     private String isDefault;
     private String configId;
+    private String[] configIds;
     private String feeFlag;
     private String feeName;
     private String startTime;
@@ -243,4 +244,12 @@ public class FeeConfigDto extends PageDto implements Serializable {
     public void setComputingFormulaText(String computingFormulaText) {
         this.computingFormulaText = computingFormulaText;
     }
+
+    public String[] getConfigIds() {
+        return configIds;
+    }
+
+    public void setConfigIds(String[] configIds) {
+        this.configIds = configIds;
+    }
 }

+ 151 - 1
service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportReportFeeSMOImpl.java

@@ -5,11 +5,13 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.parser.Feature;
 import com.java110.core.component.BaseComponentSMO;
 import com.java110.core.context.IPageData;
+import com.java110.dto.fee.FeeConfigDto;
 import com.java110.entity.component.ComponentValidateResult;
 import com.java110.front.smo.assetExport.IExportReportFeeSMO;
 import com.java110.utils.constant.ServiceConstant;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -27,6 +29,9 @@ import org.springframework.web.client.RestTemplate;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @ClassName AssetImportSmoImpl
@@ -46,6 +51,7 @@ public class ExportReportFeeSMOImpl extends BaseComponentSMO implements IExportR
     public static final String REPORT_OWE_FEE_DETAIL = "reportOweFeeDetail";
     public static final String REPORT_PAY_FEE_DETAIL = "reportPayFeeDetail";
     public static final String REPORT_YEAR_COLLECTION = "reportYearCollection";
+    public static final String REPORT_LIST_OWE_FEE = "listOweFee";
 
     @Autowired
     private RestTemplate restTemplate;
@@ -87,7 +93,9 @@ public class ExportReportFeeSMOImpl extends BaseComponentSMO implements IExportR
             case REPORT_YEAR_COLLECTION:
                 reportYearCollection(pd, result, workbook);
                 break;
-
+            case REPORT_LIST_OWE_FEE:
+                reportListOweFee(pd, result, workbook);
+                break;
         }
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         MultiValueMap headers = new HttpHeaders();
@@ -112,6 +120,130 @@ public class ExportReportFeeSMOImpl extends BaseComponentSMO implements IExportR
         return new ResponseEntity<Object>(context, headers, HttpStatus.OK);
     }
 
+    private void reportListOweFee(IPageData pd, ComponentValidateResult result, Workbook workbook) {
+        JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
+        String configIds = reqJson.getString("configIds");
+        //查询楼栋信息
+        JSONArray oweFees = this.getReportListOweFees(pd, result);
+        if (oweFees == null) {
+            return;
+        }
+        //获取费用项
+        List<FeeConfigDto> feeConfigDtos = getFeeConfigs(oweFees);
+        Sheet sheet = workbook.createSheet("欠费清单");
+        Row row = sheet.createRow(0);
+        row.createCell(0).setCellValue("收费对象");
+        row.createCell(1).setCellValue("业主名称");
+        row.createCell(2).setCellValue("开始时间");
+        row.createCell(3).setCellValue("结束时间");
+        if (!StringUtil.isEmpty(configIds)) {
+            for (int feeConfigIndex = 0; feeConfigIndex < feeConfigDtos.size(); feeConfigIndex++) {
+                row.createCell(4 + feeConfigIndex).setCellValue(feeConfigDtos.get(feeConfigIndex).getFeeName());
+            }
+        }
+        row.createCell(4 + feeConfigDtos.size()).setCellValue("合计");
+
+        JSONObject dataObj = null;
+        for (int roomIndex = 0; roomIndex < oweFees.size(); roomIndex++) {
+            row = sheet.createRow(roomIndex + 1);
+            dataObj = oweFees.getJSONObject(roomIndex);
+            row.createCell(0).setCellValue(dataObj.getString("payerObjName"));
+            row.createCell(1).setCellValue(dataObj.getString("ownerName"));
+            row.createCell(2).setCellValue(dataObj.getString("endTime"));
+            row.createCell(3).setCellValue(dataObj.getString("deadlineTime"));
+            if (!StringUtil.isEmpty(configIds)) {
+                for (int feeConfigIndex = 0; feeConfigIndex < feeConfigDtos.size(); feeConfigIndex++) {
+                    row.createCell(4 + feeConfigIndex).setCellValue(getFeeConfigAmount(feeConfigDtos.get(feeConfigIndex), dataObj));
+                }
+            }
+            row.createCell(4 + feeConfigDtos.size()).setCellValue(getAllFeeOweAmount(feeConfigDtos, dataObj));
+        }
+    }
+
+    /**
+     * _getAllFeeOweAmount: function (_fee) {
+     * let _feeConfigNames = $that.listOweFeeInfo.feeConfigNames;
+     * if (_feeConfigNames.length < 1) {
+     * return _fee.amountOwed;
+     * }
+     * <p>
+     * let _amountOwed = 0.0;
+     * let _items = _fee.items;
+     * _feeConfigNames.forEach(_feeItem =>{
+     * _items.forEach(_item=>{
+     * if(_feeItem.configId == _item.configId){
+     * _amountOwed += parseFloat(_item.amountOwed);
+     * }
+     * })
+     * })
+     * return _amountOwed;
+     * }
+     *
+     * @param dataObj
+     * @return
+     */
+    private double getAllFeeOweAmount(List<FeeConfigDto> feeConfigDtos, JSONObject dataObj) {
+        if (feeConfigDtos == null || feeConfigDtos.size() < 1) {
+            return dataObj.getDouble("amountOwed");
+        }
+        JSONArray items = dataObj.getJSONArray("items");
+        BigDecimal oweAmount = new BigDecimal(0);
+        for (FeeConfigDto feeConfigDto : feeConfigDtos) {
+            for (int itemIndex = 0; itemIndex < items.size(); itemIndex++) {
+                if (feeConfigDto.getConfigId().equals(items.getJSONObject(itemIndex).getString("configId"))) {
+                    oweAmount = oweAmount.add(new BigDecimal(items.getJSONObject(itemIndex).getDouble("amountOwed")));
+                }
+            }
+        }
+
+        return oweAmount.doubleValue();
+    }
+
+    private double getFeeConfigAmount(FeeConfigDto feeConfigDto, JSONObject dataObj) {
+        JSONArray items = dataObj.getJSONArray("items");
+
+        double oweAmount = 0;
+        for (int itemIndex = 0; itemIndex < items.size(); itemIndex++) {
+            if (feeConfigDto.getConfigId().equals(items.getJSONObject(itemIndex).getString("configId"))) {
+                oweAmount = items.getJSONObject(itemIndex).getDouble("amountOwed");
+                break;
+            }
+        }
+        return oweAmount;
+    }
+
+
+    private List<FeeConfigDto> getFeeConfigs(JSONArray oweFees) {
+        List<FeeConfigDto> feeConfigDtos = new ArrayList<>();
+        FeeConfigDto feeConfigDto = null;
+        for (int oweFeeIndex = 0; oweFeeIndex < oweFees.size(); oweFeeIndex++) {
+            if (existsFeeConfig(feeConfigDtos, oweFees.getJSONObject(oweFeeIndex))) {
+                continue;
+            }
+
+            feeConfigDto = new FeeConfigDto();
+            feeConfigDto.setConfigId(oweFees.getJSONObject(oweFeeIndex).getString("configId"));
+            feeConfigDto.setFeeName(oweFees.getJSONObject(oweFeeIndex).getString("configName"));
+            feeConfigDtos.add(feeConfigDto);
+        }
+
+        return feeConfigDtos;
+    }
+
+    private boolean existsFeeConfig(List<FeeConfigDto> feeConfigDtos, JSONObject oweFee) {
+        if (feeConfigDtos.size() < 1) {
+            return false;
+        }
+        for (FeeConfigDto feeConfigDto : feeConfigDtos) {
+            if (feeConfigDto.getConfigId().equals(oweFee.getString("configId"))) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
     private void reportPayFeeDetail(IPageData pd, ComponentValidateResult result, Workbook workbook) {
         Sheet sheet = workbook.createSheet("缴费明细表");
         Row row = sheet.createRow(0);
@@ -194,6 +326,24 @@ public class ExportReportFeeSMOImpl extends BaseComponentSMO implements IExportR
         }
     }
 
+    private JSONArray getReportListOweFees(IPageData pd, ComponentValidateResult result) {
+        String apiUrl = "";
+        ResponseEntity<String> responseEntity = null;
+        JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
+        reqJson.put("page", 1);
+        reqJson.put("row", 10000);
+        apiUrl = ServiceConstant.SERVICE_API_URL + "/api//reportOweFee/queryReportAllOweFee" + mapToUrlParam(reqJson);
+        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
+        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
+            return null;
+        }
+        JSONObject savedRoomInfoResults = JSONObject.parseObject(responseEntity.getBody(), Feature.OrderedField);
+        if (!savedRoomInfoResults.containsKey("data")) {
+            return null;
+        }
+        return savedRoomInfoResults.getJSONArray("data");
+    }
+
     private JSONArray getReportPayFeeDetail(IPageData pd, ComponentValidateResult result) {
         String apiUrl = "";
         ResponseEntity<String> responseEntity = null;

+ 24 - 0
service-report/src/main/java/com/java110/report/api/ReportOweFeeApi.java

@@ -111,4 +111,28 @@ public class ReportOweFeeApi {
         }
         return getReportOweFeeBMOImpl.get(reportOweFeeDto);
     }
+
+    /**
+     * 查询所有欠费信息
+     *
+     * @param communityId 小区ID
+     * @return
+     * @serviceCode /reportOweFee/queryReportAllOweFee
+     * @path /app/reportOweFee/queryReportAllOweFee
+     */
+    @RequestMapping(value = "/queryReportAllOweFee", method = RequestMethod.GET)
+    public ResponseEntity<String> queryReportAllOweFee(@RequestParam(value = "communityId") String communityId,
+                                                    @RequestParam(value = "configIds", required = false) String configIds,
+                                                    @RequestParam(value = "payObjType", required = false) String payObjType,
+                                                    @RequestParam(value = "num", required = false) String num) {
+        ReportOweFeeDto reportOweFeeDto = new ReportOweFeeDto();
+        reportOweFeeDto.setPayerObjType(payObjType);
+        reportOweFeeDto.setPayerObjName(num);
+        reportOweFeeDto.setCommunityId(communityId);
+        if (!StringUtil.isEmpty(configIds)) {
+            String[] tmpConfigIds = configIds.split(",");
+            reportOweFeeDto.setConfigIds(tmpConfigIds);
+        }
+        return getReportOweFeeBMOImpl.getAllFees(reportOweFeeDto);
+    }
 }

+ 1 - 0
service-report/src/main/java/com/java110/report/bmo/reportOweFee/IGetReportOweFeeBMO.java

@@ -13,4 +13,5 @@ public interface IGetReportOweFeeBMO {
     ResponseEntity<String> get(ReportOweFeeDto reportOweFeeDto);
 
 
+    ResponseEntity<String> getAllFees(ReportOweFeeDto reportOweFeeDto);
 }

+ 80 - 0
service-report/src/main/java/com/java110/report/bmo/reportOweFee/impl/GetReportOweFeeBMOImpl.java

@@ -1,7 +1,9 @@
 package com.java110.report.bmo.reportOweFee.impl;
 
+import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.reportOweFee.ReportOweFeeDto;
 import com.java110.dto.reportOweFee.ReportOweFeeItemDto;
+import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
 import com.java110.intf.report.IReportOweFeeInnerServiceSMO;
 import com.java110.report.bmo.reportOweFee.IGetReportOweFeeBMO;
 import com.java110.utils.util.DateUtil;
@@ -23,6 +25,9 @@ public class GetReportOweFeeBMOImpl implements IGetReportOweFeeBMO {
     @Autowired
     private IReportOweFeeInnerServiceSMO reportOweFeeInnerServiceSMOImpl;
 
+    @Autowired
+    private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
+
 
     /**
      * @param reportOweFeeDto
@@ -48,6 +53,79 @@ public class GetReportOweFeeBMOImpl implements IGetReportOweFeeBMO {
         return responseEntity;
     }
 
+    /**
+     * query all owe fee
+     *
+     * @param reportOweFeeDto
+     * @return
+     */
+    @Override
+    public ResponseEntity<String> getAllFees(ReportOweFeeDto reportOweFeeDto) {
+        //
+        List<ReportOweFeeDto> allReportOweFeeDtos = reportOweFeeInnerServiceSMOImpl.queryReportAllOweFees(reportOweFeeDto);
+        if (allReportOweFeeDtos == null || allReportOweFeeDtos.size() < 1) {
+            return ResultVo.createResponseEntity(allReportOweFeeDtos);
+        }
+
+        //get old report owe fee
+        List<ReportOweFeeDto> oldReportOweFeeDtos = new ArrayList<>();
+        ReportOweFeeDto oldReportOweFeeDto = null;
+        for (ReportOweFeeDto tmpReportOweFeeDto : allReportOweFeeDtos) {
+            if (existsOweFee(oldReportOweFeeDtos, tmpReportOweFeeDto.getPayerObjId())) {
+                continue;
+            }
+            oldReportOweFeeDto = new ReportOweFeeDto();
+            oldReportOweFeeDto.setPayerObjId(tmpReportOweFeeDto.getPayerObjId());
+
+            oldReportOweFeeDtos.add(oldReportOweFeeDto);
+        }
+
+        for (ReportOweFeeDto tmpReportOweFeeDto : oldReportOweFeeDtos) {
+            dealItem(tmpReportOweFeeDto, allReportOweFeeDtos);
+        }
+
+        if (reportOweFeeDto.getConfigIds() == null || reportOweFeeDto.getConfigIds().length < 1) {
+            return ResultVo.createResponseEntity(oldReportOweFeeDtos);
+        }
+
+        //如果费用对象上没有这个费用项时默认写零
+        for (ReportOweFeeDto tmpReportOweFeeDto : oldReportOweFeeDtos) {
+            for (String configId : reportOweFeeDto.getConfigIds()) {
+                if (hasItem(tmpReportOweFeeDto.getItems(), configId) != null) {
+                    continue;
+                }
+                ReportOweFeeItemDto reportOweFeeItemDto = new ReportOweFeeItemDto();
+                reportOweFeeItemDto.setConfigId(configId);
+                reportOweFeeItemDto.setFeeName("");
+                reportOweFeeItemDto.setAmountOwed("0");
+                reportOweFeeItemDto.setPayerObjId("");
+                reportOweFeeItemDto.setPayerObjName("");
+                tmpReportOweFeeDto.getItems().add(reportOweFeeItemDto);
+            }
+        }
+        return ResultVo.createResponseEntity(oldReportOweFeeDtos);
+    }
+
+    /**
+     * exists owe fee in oldReportOweFeeDtos
+     * true is exists false is not
+     *
+     * @param oldReportOweFeeDtos
+     * @param payerObjId
+     * @return
+     */
+    private boolean existsOweFee(List<ReportOweFeeDto> oldReportOweFeeDtos, String payerObjId) {
+        for (ReportOweFeeDto tmpReportOweFeeDto : oldReportOweFeeDtos) {
+            // if equal return true
+            if (tmpReportOweFeeDto.getPayerObjId().equals(payerObjId)) {
+                return true;
+            }
+
+        }
+        //default return false
+        return false;
+    }
+
     private void refreshReportOwe(List<ReportOweFeeDto> oldReportOweFeeDtos, String[] configIds) {
         List<String> payObjIds = new ArrayList<>();
 
@@ -121,6 +199,7 @@ public class GetReportOweFeeBMOImpl implements IGetReportOweFeeBMO {
             }
             oldReportOweFeeDto.setOwnerName(reportOweFeeDto.getOwnerName());
             oldReportOweFeeDto.setUpdateTime(reportOweFeeDto.getUpdateTime());
+            oldReportOweFeeDto.setConfigName(reportOweFeeDto.getConfigName());
         }
 
         //计算总金额
@@ -147,6 +226,7 @@ public class GetReportOweFeeBMOImpl implements IGetReportOweFeeBMO {
         oldReportOweFeeDto.setItems(items);
         oldReportOweFeeDto.setPayerObjName(items.get(0).getPayerObjName());
         oldReportOweFeeDto.setAmountOwed(totalAmount.doubleValue() + "");
+
     }
 
     private ReportOweFeeItemDto hasItem(List<ReportOweFeeItemDto> reportOweFeeItemDtos, String configId) {