chengf
2025-08-21 bde271fdbab51e654a293dba02a31eab8ff3ea8b
service-fee/src/main/java/com/java110/fee/cmd/fee/ReportFeeCmd.java
@@ -8,12 +8,14 @@
import com.java110.dto.community.CommunityDto;
import com.java110.dto.dict.DictDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.report.ReportQueryRecord;
import com.java110.intf.community.ICommunityInnerServiceSMO;
import com.java110.intf.dev.IDictV1InnerServiceSMO;
import com.java110.intf.fee.IReportFeeInnerServiceSMO;
import com.java110.po.fee.PayFeePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.FeeQueryParams;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +23,7 @@
import org.springframework.http.ResponseEntity;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.util.*;
@@ -52,97 +55,285 @@
        feeQueryParams.setStartYear(startYear);
        int currentYear = java.time.Year.now().getValue();
        feeQueryParams.setEndYear(currentYear + 2);
        int endYear = feeQueryParams.getEndYear();
        List<Map> result = reportFeeInnerServiceSMOImpl.repostPaidInFee(feeQueryParams);
        List<Map> resultTwo =  reportFeeInnerServiceSMOImpl.repostPaidInFeeTwo(feeQueryParams);
        DictDto dictDto = new DictDto();
        dictDto.setTableName("pay_fee_config");
        dictDto.setTableColumns("fee_type_cd");
        List<DictDto> dictDtos = dictV1InnerServiceSMOImpl.queryDicts(dictDto);
        int doYear = endYear - startYear;
        List<List<FeeDto>> reportFeeDtoLists = new LinkedList<>();
        reportFeeDtoLists.add(new LinkedList<FeeDto>());
        reportFeeDtoLists.add(new LinkedList<FeeDto>());
        reportFeeDtoLists.add(new LinkedList<FeeDto>());
        reportFeeDtoLists.add(new LinkedList<FeeDto>());
        int ind = 1;
        for (DictDto dictDto1 : dictDtos) {//类型
            List<FeeDto> reportFeeDtos = new LinkedList<>();
            FeeDto feeDto = new FeeDto();
            LinkedList<FeeDto> feeDtos = new LinkedList<>();
            reportFeeDtoLists.add(feeDtos);
            for (int i = startYear; i <= endYear; i++) {//年份
                double[] doubles = new double[doYear+12+1+5];
                feeDto = new FeeDto();
                //0~5
                if(resultTwo != null){
                    for (Map map : resultTwo) {
                        if(map.isEmpty()){
                            break;
                        }
                        else if (map.get("统计周期")!=null&&map.get("统计周期").equals(i)&&map.get("费用类型编码").equals(dictDto1.getStatusCd())){
                            feeDto.setCurYear((i)+"");
                            feeDto.setFeeTypeCdName(map.get("费用类型")+"");
                            doubles[0] = map.get("当年应缴总金额") == null ? 0 : (double) map.get("当年应缴总金额");
                            doubles[1] = map.get("每月费用(合计/月份数)") == null ? 0 : (double) map.get("每月费用(合计/月份数)");
                            doubles[2] = map.get("每月费用月份数") == null ? 0 : ((Long) map.get("每月费用月份数")).intValue();
                        }
                    }
                }
                if(result != null){
                    for (Map map : result) {//类型+年份
                        if(map.isEmpty()){
                            break;
                        }
                        //5 ~ 25
                        else if (map.get("统计周期")!=null&&map.get("统计周期").equals(i)&&map.get("费用类型编码").equals(dictDto1.getStatusCd())){
                            for (int j = startYear ; j <= endYear ; j++) {// 5~(endYear - startYear + 5) = 5 ~ 13
                                if(map.get((j)+"年收费金额(元)")!=null){
                                    feeDto.setCurYear((i)+"");
                                    feeDto.setFeeTypeCdName(map.get("费用类型名称") == null ? null : map.get("费用类型名称")+"");
                                    doubles[j-startYear+5] = ((BigDecimal)map.get((j)+"年收费金额(元)")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                }
                                for (int x = 1 ;x <= 12 ;x++ ){// (endYear - startYear + 6) ~ (endYear - startYear + 6 + 12) = 13 ~ 25
                                    if (map.get((currentYear)+"年"+x+"月收费金额(元)")!=null){
                                        feeDto.setCurYear((i)+"");
                                        feeDto.setFeeTypeCdName(map.get("费用类型名称") == null ? null : map.get("费用类型名称")+"");
                                        doubles[endYear - startYear + x +5] = ((BigDecimal)map.get((currentYear)+"年"+x+"月收费金额(元)")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                    }
                                }
                            }
                        }
                    }
                }
                if(feeDto.getCurYear() != null){
                    feeDto.setReport(doubles);
                    reportFeeDtos.add(feeDto);
                }
            }
            if (ind == 3 || ind == 7){
                reportFeeDtoLists.add(new LinkedList<>());
            }
            reportFeeDtoLists.add(reportFeeDtos);
            if(ind == 1 || ind == 2){
                reportFeeDtoLists.add(new LinkedList<>());
            }
            ind ++;
        if(reqJson.containsKey("endYear") && !reqJson.get("endYear").equals("") && reqJson.get("endYear") != null) {
            currentYear=Integer.parseInt(reqJson.get("endYear")+"");
            feeQueryParams.setEndYear(Integer.parseInt(reqJson.get("endYear")+"")+2);
        }
        int endYear = feeQueryParams.getEndYear();
        int doYear = endYear - startYear;
        ReportQueryRecord reportQueryRecord = new ReportQueryRecord();
        reportQueryRecord.setCommunityId(reqJson.getString("communityId"));
        reportQueryRecord.setQueryStatus("0");
        reportQueryRecord.setEndYear(currentYear+"");
        List<ReportQueryRecord> reportQueryRecords = reportFeeInnerServiceSMOImpl.queryReport(BeanConvertUtil.beanCovertMap(reportQueryRecord));
        if(reportQueryRecords.size()>0 && !reqJson.containsKey("reload")){
            ResultVo resultVo = new ResultVo(JSONObject.parse(reportQueryRecords.get(reportQueryRecords.size()-1).getReportContent()));
            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
            context.setResponseEntity(responseEntity);
        }
        else{
            List<List<FeeDto>> reportFeeDtoLists = new LinkedList<>();
            queryFee(reportFeeDtoLists ,reqJson);
            int[] arr = new int[endYear - startYear + 1];
            int[] arr2 = new int[endYear - startYear + 1 - 3];
            for (int i = startYear; i <= endYear; i++) {
                arr[i-startYear] = i;
            }
            for (int i = startYear; i < currentYear; i++) {
                arr2[i-startYear] = i;
            }
            FeeDto feeDto = new FeeDto();
            feeDto.setRepostList(reportFeeDtoLists);
            feeDto.setYearArr(arr);
            feeDto.setYearArr2(arr2);
            feeDto.setReportLength(doYear - 1 + 20);
            reportQueryRecord.setCommunityId(reqJson.getString("communityId"));
            reportQueryRecord.setQueryStatus("0");
            reportQueryRecord.setEndYear(currentYear+"");
            reportQueryRecord.setReportContent(JSONObject.toJSONString(feeDto));
            int i = reportFeeInnerServiceSMOImpl.saveReport(BeanConvertUtil.beanCovertMap(reportQueryRecord));
            ResultVo resultVo = new ResultVo(feeDto);
            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
            context.setResponseEntity(responseEntity);
        }
    }
    public void queryFee(List<List<FeeDto>> reportFeeDtoLists, JSONObject reqJson) {
        int startYear = 2020;
        CommunityDto communityDto = new CommunityDto();
        communityDto.setCommunityId(reqJson.getString("communityId"));
        List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
        FeeQueryParams feeQueryParams = new FeeQueryParams();
        feeQueryParams.setCommunityId(reqJson.getString("communityId"));
        feeQueryParams.setStartYear(startYear);
        int currentYear = java.time.Year.now().getValue();
        feeQueryParams.setEndYear(currentYear + 2);
        if(reqJson.containsKey("endYear") && !reqJson.get("endYear").equals("") && reqJson.get("endYear") != null){
            currentYear=Integer.parseInt(reqJson.get("endYear")+"");
            feeQueryParams.setEndYear(Integer.parseInt(reqJson.get("endYear")+"")+2);
        }
        int endYear = feeQueryParams.getEndYear();
        int doYear = endYear - startYear;
        LinkedList<FeeDto> col1 = new LinkedList<>();
        FeeDto col = new FeeDto();
        BigDecimal[] col1Fee = new BigDecimal[doYear - 1 + 20];
        col.setReport(col1Fee);
        col.setCurYear("收入合计(白单流水)");
        col1.add(col);
        LinkedList<FeeDto> col2 = new LinkedList<>();
        BigDecimal[] col2Fee = new BigDecimal[doYear - 1 + 20];
        col = new FeeDto();
        col.setReport(col2Fee);
        col.setCurYear("物业费+代收合计");
        col2.add(col);
        LinkedList<FeeDto> col3 = new LinkedList<>();
        col = new FeeDto();
        col.setReport(col2Fee);
        col.setCurYear("物业费合计(1+2)");
        col3.add(col);
        LinkedList<FeeDto> col4 = new LinkedList<>();
        col = new FeeDto();
        col.setReport(new BigDecimal[doYear - 1 + 20]);
        col.setCurYear("物业费代收合计");
        col3.add(col);
        BigDecimal[] col4Fee = new BigDecimal[doYear - 1 + 20];
        BigDecimal[] colByCar = new BigDecimal[doYear - 1 + 20];
        BigDecimal[] colByOther = new BigDecimal[doYear - 1 + 20];
        reportFeeDtoLists.add(col1);
        reportFeeDtoLists.add(col2);
        reportFeeDtoLists.add(col2);
        reportFeeDtoLists.add(col4);
        int ind = 1;
        int[] arr = new int[endYear - startYear + 1];
        for (int i = startYear; i <= endYear; i++) {
            arr[i-startYear] = i;
        }
        FeeDto feeDto = new FeeDto();
        feeDto.setRepostList(reportFeeDtoLists);
        feeDto.setYearArr(arr);
        List<Map> result = reportFeeInnerServiceSMOImpl.repostPaidInFee(feeQueryParams);
        DictDto dictDto = new DictDto();
        dictDto.setTableName("pay_fee_config");
        dictDto.setTableColumns("fee_type_cd");
        List<DictDto> dictDtos = dictV1InnerServiceSMOImpl.queryDicts(dictDto);
        for (DictDto dictDto1 : dictDtos) {//类型
            List<FeeDto> reportFeeDtos = new LinkedList<>();//该类型的数组
            FeeDto feeDto = new FeeDto();
            LinkedList<FeeDto> feeDtos = new LinkedList<>();//总的
            int kg = 0;
            for (Map map : result){
                if(map.get("费用所属年份").equals("类型总计") && map.get("fee_type_cd").equals(dictDto1.getStatusCd())){
                    BigDecimal[] doubles = new BigDecimal[doYear - 1 + 20];
                    doubles[0] = (BigDecimal) map.get("该年应缴总额");
                    doubles[1] = (BigDecimal) map.get("每月费用");
                    doubles[2] = (BigDecimal) map.get("应收月份数");
                    doubles[3] = (BigDecimal) map.get("当年收缴率");
                    doubles[4] = (BigDecimal) map.get("折扣金额");
                    int inde = 0;
                    for (int i : arr){
                        if(i < currentYear){
                            inde++;
                            doubles[i - startYear + 5] = (BigDecimal) map.get(i + "年实缴");
                        }
                    }
                    doubles[inde + 5] =(BigDecimal) map.get("当年预算");
                    doubles[inde + 6] =(BigDecimal) map.get(currentYear + "年实缴");
                    doubles[inde + 7] =(BigDecimal) map.get("当年折扣总额");
                    doubles[inde + 8] =(BigDecimal) map.get("当年欠款");
                    for (int i = 1 ; i <= 12 ; i++){
                        doubles[inde + 8 + i] =(BigDecimal) map.get("当年"+(i < 10 ? "0"+i : i) +"月实缴");
                    }
                    feeDto.setCurYear(dictDto1.getName()+"总计");
                    if(Integer.parseInt(dictDto1.getStatusCd())%630000000 < 3){
                        for(int i = 0 ; i < doubles.length ; i++){
                            if(i == 3){
                                if (doubles[i].intValue() != 0){
                                    col1Fee[i] = BigDecimal.valueOf((doubles[i].add(col1Fee[i])).doubleValue()/2);
                                    col2Fee[i] = BigDecimal.valueOf((doubles[i].add(col1Fee[i])).doubleValue()/2);
                                }
                            }else{
                                col1Fee[i].add(doubleUse(doubles[i]));
                                col2Fee[i].add(doubleUse(doubles[i]));
                            }
                        }
                    }
                    else if(Integer.parseInt(dictDto1.getStatusCd())%630000000 < 8){
                        for(int i = 0 ; i < doubles.length ; i++){
                            if(i == 3){
                                if (doubles[i].intValue() != 0){
                                    col1Fee[i] = BigDecimal.valueOf((doubles[i].add(col1Fee[i])).doubleValue()/2);
                                    col2Fee[i] = BigDecimal.valueOf((doubles[i].add(col1Fee[i])).doubleValue()/2);
                                }
                            }else{
                                col1Fee[i].add(doubleUse(doubles[i]));
                                col2Fee[i].add(doubleUse(doubles[i]));
                            }
                        }
                    }else{
                        for(int i = 0 ; i < doubles.length ; i++){
                            if(i == 3){
                                if (doubles[i].intValue() != 0){
                                    col1Fee[i] = BigDecimal.valueOf((doubles[i].add(col1Fee[i])).doubleValue()/2);
                                    col2Fee[i] = BigDecimal.valueOf((doubles[i].add(col1Fee[i])).doubleValue()/2);
                                }
                            }else{
                                col1Fee[i].add(doubleUse(doubles[i]));
                                col2Fee[i].add(doubleUse(doubles[i]));
                            }
                        }
                    }
                    feeDto.setReport(doubles);
                    feeDto.setCount(ind);
        ResultVo resultVo = new ResultVo(feeDto);
                }
            }
            if (feeDto.getCurYear() == null){
                feeDto.setCurYear("类型总计");
            }
            if (feeDto.getReport() == null){
                feeDto.setReport(new BigDecimal[doYear - 1 + 20]);
            }
            if(feeDto.getFeeTypeCdName() == null) {
                feeDto.setFeeTypeCdName(dictDto1.getName());
            }
            LinkedList<FeeDto> feeDtos1 = new LinkedList<>();
            feeDtos1.add(feeDto);
            reportFeeDtoLists.add(feeDtos1);//添加总金额的
            feeDtos1 = new LinkedList<>();
            feeDto = new FeeDto();
            LinkedList<FeeDto> feeDtos2 = new LinkedList<>();
            for (int i = startYear; i <= endYear; i++) {//年份
                kg = 0;
                for (Map map : result){
                    if(map.get("费用所属年份").equals(i+"") && map.get("fee_type_cd").equals(dictDto1.getStatusCd())){
                        BigDecimal[] doubles = new BigDecimal[doYear - 1 + 20];
                        doubles[0] = (BigDecimal) map.get("该年应缴总额");
                        doubles[1] = (BigDecimal) map.get("每月费用");
                        doubles[2] = (BigDecimal) map.get("应收月份数");
                        doubles[3] = (BigDecimal) map.get("当年收缴率");
                        doubles[4] = (BigDecimal) map.get("折扣金额");
                        int inde = 0;
                        for (int in : arr){
                            if(in < currentYear){
                                inde++;
                                doubles[in - startYear + 5] = (BigDecimal) map.get(i + "年实缴");
                            }
                        }
                        doubles[inde + 5] =(BigDecimal) map.get("当年预算");
                        doubles[inde + 6] =(BigDecimal) map.get(currentYear + "年实缴");
                        doubles[inde + 7] =(BigDecimal) map.get("当年折扣总额");
                        doubles[inde + 8] =(BigDecimal) map.get("当年欠款");
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        context.setResponseEntity(responseEntity);
                        for (int in = 1 ; in <= 12 ; in++){
                            doubles[inde + 8 + in] =(BigDecimal) map.get("当年"+(in < 10 ? "0"+in : in) +"月实缴");
                        }
                        feeDto = new FeeDto();
                        feeDto.setFeeTypeCdName(dictDto1.getName());
                        feeDto.setCurYear(String.valueOf(i));
                        feeDto.setReport(doubles);
                        feeDto.setCount(ind);
                        feeDtos2.add(feeDto);
                        kg = 1;
                    }
                }
                if(kg == 0){
                    feeDto = new FeeDto();
                    feeDto.setFeeTypeCdName(dictDto1.getName());
                    feeDto.setCurYear(String.valueOf(i));
                    feeDto.setReport(new BigDecimal[doYear - 1 + 20]);
                    feeDto.setCount(ind);
                    feeDtos2.add(feeDto);
                }
            }
            reportFeeDtoLists.add(feeDtos2);
            if (ind == 1){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("住宅物业费代收合计");
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            if (ind == 2){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("商铺物业费代收合计");
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            if (ind == 3){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("停车费合计(3+...+7)");
                feeDto1.setReport(colByCar);
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            if (ind == 8){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("其他类合计(8+...+22)");
                feeDto1.setReport(colByOther);
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            ind ++;
        }
    }
    public BigDecimal doubleUse(BigDecimal num){
        return  num;
    }
}