package com.tofly.feesapi.sfgl.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tofly.feesapi.bmgl.entity.BmSj;
import com.tofly.feesapi.bmgl.entity.BmYmjzConfig;
import com.tofly.feesapi.bmgl.service.BmSjService;
import com.tofly.feesapi.bmgl.service.BmYmjzConfigLsService;
import com.tofly.feesapi.bmgl.service.BmYmjzConfigService;
import com.tofly.feesapi.cbgl.entity.YyCblr;
import com.tofly.feesapi.cbgl.service.YyCblrService;
import com.tofly.feesapi.common.NumberHelper;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.feesapi.bjgl.entity.YhCbkxx;
import com.tofly.feesapi.bjgl.service.YhCbkxxService;
import com.tofly.feesapi.bmgl.entity.BmYslx;
import com.tofly.feesapi.bmgl.service.BmYslxService;
import com.tofly.feesapi.common.Excel.ExcleFileUtil;
import com.tofly.feesapi.common.constant.PjztEnum;
import com.tofly.feesapi.common.core.dto.Order;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import com.tofly.feesapi.common.enums.BglxEnum;
import com.tofly.feesapi.common.exception.FeesErrorCode;
import com.tofly.feesapi.common.exception.FeesException;
import com.tofly.feesapi.common.model.CollectionData;
import com.tofly.feesapi.common.util.CommSearchParams;
import com.tofly.feesapi.common.util.GuidGenerator;
import com.tofly.feesapi.common.util.ToolsUtils;
import com.tofly.feesapi.common.znj.ZNJResult;
import com.tofly.feesapi.common.znj.ZnjCal;
import com.tofly.feesapi.config.FilePathBean;
import com.tofly.feesapi.file.entity.File;
import com.tofly.feesapi.file.service.IFileInfoService;
import com.tofly.feesapi.mxcx.entity.YyBgLog;
import com.tofly.feesapi.mxcx.entity.dto.QftjSeachFilter;
import com.tofly.feesapi.mxcx.service.YyBgLogService;

import com.tofly.feesapi.security.util.SecurityUtils;
import com.tofly.feesapi.sfgl.entity.YyQfmx;
import com.tofly.feesapi.sfgl.entity.YyQfmxGd;
import com.tofly.feesapi.sfgl.entity.dto.*;
import com.tofly.feesapi.sfgl.entity.vo.*;
import com.tofly.feesapi.sfgl.service.YyQfmxGdService;
import com.tofly.feesapi.sfgl.service.YyQfmxService;
import com.tofly.feesapi.sfgl.service.YySspjxxService;
import com.tofly.feesapi.xtgl.service.ISysGdcsbService;
import com.tofly.feesapi.yhgl.entity.YhKhjbxx;
import com.tofly.feesapi.yhgl.service.YhKhjbxxService;
import com.tofly.feesapi.yhgl.service.YhsjqxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("api/sfgl/yyqfmx")
@Api(tags = "欠费明细")
public class YyQfmxController {

    @Autowired
    private YyQfmxService yyQfmxService;
    @Autowired
    private YhCbkxxService yhCbkxxService;
    @Autowired
    private ZnjCal znjCal;
    @Autowired
    private BmYslxService bmYslxService;
    @Autowired
    private YyBgLogService yyBgLogService;
    @Autowired
    private YyCblrService yyCblrService;
    @Autowired
    private BmSjService sjService;
    @Autowired
    private YhKhjbxxService yhKhjbxxService;
    @Autowired
    private ISysGdcsbService gdcsbService;
    @Autowired
    private YyQfmxGdService yyQfmxGdService;
    @Autowired
    private FilePathBean filePathBean;
    @Autowired
    private IFileInfoService iFileInfoService;
    @Autowired
    private YySspjxxService yySspjxxService;
    @Autowired
    private YhsjqxService yhsjqxService;
    @Autowired
    private BmYmjzConfigService bmYmjzConfigService;

    @ApiOperationSupport(order = 1)
    @GetMapping("/page")
    @ApiOperation(value = "查询欠费明细（分页）", tags = {"欠费明细变更", "水费补差", "营业厅收费", "综合查询", "违约金调整"})
    public ResultRespone<PageResult<YyQfmxSelect>> getPage(@ModelAttribute PageDto pageDto, @ModelAttribute YyQfmxFilter filter) {
        return ResultRespone.success(yyQfmxService.getPage(pageDto, filter, filter.getSfbz(), filter.getChbz()));
    }

    @ApiOperationSupport(order = 2)
    @GetMapping("/qfmxbgtj")
    @ApiOperation(value = "查询欠费明细变更统计")
    public ResultRespone qfmxbgtj(@ModelAttribute YyQfmxFilter filter) {
        Map map = yyQfmxService.qfmxbgtj(filter);
        return ResultRespone.success(map);
    }

    @ApiOperationSupport(order = 3)
    @PostMapping(value = "/qfmxbggdsq", headers = "content-type=multipart/form-data")
    @ApiOperation(value = "欠费明细变更工单申请")
    @Transactional
    public ResultRespone qfmxbggdsq(@Valid YyQfmxGd yyQfmxGd,
                                    @RequestParam(value = "fileList", required = false) List<MultipartFile> fileList) {
        if (StringUtil.isEmpty(yyQfmxGd.getGdbz())) {
            throw new FeesException("工单备注不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtil.isEmpty(yyQfmxGd.getGdyx())) {
            throw new FeesException("工单原因不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtil.isNull(yyQfmxGd.getQfids()) || yyQfmxGd.getQfids().size() == 0) {
            throw new FeesException("请选择要变更的欠费明细", FeesErrorCode.BUSINESS_ERROR);
        }
        String gdlsbh = GuidGenerator.getGuid();
        if (yyQfmxService.lambdaUpdate()
                .set(YyQfmx::getGdlsbh, gdlsbh)
                .set(YyQfmx::getGdzt, "0")
                .set(YyQfmx::getGdyx, yyQfmxGd.getGdyx())
                .in(YyQfmx::getId, yyQfmxGd.getQfids())
                .update()) {
            yyQfmxGd.setGdlsbh(gdlsbh);
            if (yyQfmxGdService.save(yyQfmxGd)) {
                String path = filePathBean.getOtherfile();
                if (fileList.size() > 0) {
                    iFileInfoService.saveFileList(fileList, path, gdlsbh, "yy_qfmx_gd", "欠费明细变更工单申请");
                }
                return ResultRespone.success(gdlsbh, "操作成功");
            }
        }
        return ResultRespone.failed("操作失败");
    }

    @ApiOperationSupport(order = 3)
    @GetMapping("/qfmxbggdcx")
    @ApiOperation(value = "欠费明细变更工单查询")
    public ResultRespone<YyQfmxGd> getYyQfmxGd(String gdlsbh) {
        if (StringUtil.isEmpty(gdlsbh)) {
            throw new FeesException("工单流水编号不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        YyQfmxGd yyQfmxGd = yyQfmxGdService.getById(gdlsbh);
        if (StringUtil.isNull(yyQfmxGd)) {
            throw new FeesException("欠费明细变更工单不存在", FeesErrorCode.BUSINESS_ERROR);
        }
        yyQfmxGd.setFileList(iFileInfoService.lambdaQuery()
                .eq(File::getTableName, "yy_qfmx_gd")
                .eq(File::getTableBh, gdlsbh)
                .list());
        return ResultRespone.success(yyQfmxGd);
    }

    @ApiOperationSupport(order = 4)
    @GetMapping
    @ApiOperation(value = "营业厅收费查询欠费明细(查询时预扣)")
    public ResultRespone<CollectionData<YyQfmxSelect>> getList(@ModelAttribute YyQfmxFilter filter) {


        List<YyQfmxSelect> list = yyQfmxService.getList(filter, "0", PjztEnum.正常.getValue());

        if (filter.getOrders().size() > 0) {
            list.sort((o1, o2) -> {
                for (Order order : filter.getOrders()) {
                    String fieldName = order.getColumn();
                    int compareResult;
                    try {
                        Field field = YyQfmxSelect.class.getDeclaredField(fieldName);
                        field.setAccessible(true);
                        Comparable o1Value = (Comparable) field.get(o1);
                        Comparable o2Value = (Comparable) field.get(o2);
                        if (ObjectUtil.isNull(o1Value) || ObjectUtil.isNull(o2Value)) {
                            continue;
                        }

                        // 执行实际比较
                        compareResult = order.isAsc() ? o1Value.compareTo(o2Value) : o2Value.compareTo(o1Value);
                        // 当比较结果不相等时立即返回
                        if (compareResult != 0) {
                            return compareResult;
                        }
                    } catch (Exception ex) {
                        log.error(fieldName + "字段排序错误:", ex);
                    }
                }
                return 0;
            });
        }
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 4)
    @GetMapping("/getListPage")
    @ApiOperation(value = "用户欠费合计催缴")
    public ResultRespone<PageResult<YyqfmxSumSelect>> getListPage(@ModelAttribute PageDto pageDto, @ModelAttribute YyQfmxFilter filter) {
        if (StringUtil.isEmpty(filter.getUserId())) {
            filter.setUserId(SecurityUtils.getUserId().toString());
        }
        PageResult<YyqfmxSumSelect> list = yyQfmxService.getQfmxSumSelect(pageDto, filter);
        return ResultRespone.success(list);
    }

    @ApiOperationSupport(order = 4)
    @GetMapping("/getQfList")
    @ApiOperation(value = "查询欠费(应收)明细", tags = {"群主户收费"})
    public ResultRespone<CollectionData<YyQfmxSelect1>> getQfList(@ModelAttribute YyQfmxFilter filter) {
        List<YyQfmxSelect1> list = yyQfmxService.getQfList(filter, "0", PjztEnum.正常.getValue());
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 4)
    @GetMapping("/getpagelist")
    @ApiOperation(value = "查询欠费(应收)明细（分页）", tags = {"应收明细报表", "欠费明细报表", "冲减明细报表"})
    public ResultRespone<YyQfmxSelectCount> getPageList(@ModelAttribute PageDto page, @ModelAttribute YyQfmxFilter filter) {
        return ResultRespone.success(yyQfmxService.getPageList(page, filter, filter.getSfbz(), filter.getChbz()));
    }

    // TODO: 2025/9/12 接口响应20S+，待优化
    @PostMapping("/jzhztj")
    @ApiOperation(value = "结转汇总统计")
    public ResultRespone<List<JzhztjDto>> jzhztj(@RequestBody JzhztjSeachFilter filter) throws ParseException {
        Integer type = filter.getType();
        if (ObjectUtil.isNull(type)) {
            throw new FeesException("请选择结转汇总报表类型", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtil.isEmpty(filter.getCwrq()) && StringUtil.isEmpty(filter.getNf())) {
            throw new FeesException("请选择财务日期或年份", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtil.isNotEmpty(filter.getCwrq())) {
            Map map = bmYmjzConfigService.getSeachTime(filter.getCwrq(), "1");
            filter.setStartDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("upltime").toString()));
            filter.setEndDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("nowtime").toString()));
        }
        if (StringUtil.isNotEmpty(filter.getNf())) {
            Map map = bmYmjzConfigService.getSeachTime(filter.getNf(), "2");
            filter.setStartDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("upltime").toString()));
            filter.setEndDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("nowtime").toString()));
        }
        switch (type) {
            case 1:
                return ResultRespone.success(yyQfmxService.jzhztj(filter));
            case 2:
                YySspjxxFilter yySspjxxFilter = new YySspjxxFilter();
                yySspjxxFilter.setQueryType(1);
                yySspjxxFilter.setNf(filter.getNf());
                yySspjxxFilter.setCwrq(filter.getCwrq());
                yySspjxxFilter.setSfrqStart(filter.getStartDate());
                yySspjxxFilter.setSfrqEnd(filter.getEndDate());
                return ResultRespone.success(yySspjxxService.sscxby(yySspjxxFilter));
            case 3:
                return ResultRespone.success(yyQfmxService.jzhzqscx(filter));
            case 4:
                YySspjxxFilter sscxFilter = new YySspjxxFilter();
                sscxFilter.setQueryType(2);
                sscxFilter.setCwrq(filter.getCwrq());
                sscxFilter.setSfrqStart(filter.getStartDate());
                sscxFilter.setSfrqEnd(filter.getEndDate());
                return ResultRespone.success(yySspjxxService.sscxby(sscxFilter));
        }
        return ResultRespone.success(new ArrayList<>());

    }

    @ApiOperationSupport(order = 5)
    @GetMapping("/export")
    @ApiOperation(value = "导出欠费明细", tags = {"应收明细报表", "欠费明细报表", "冲减明细报表"})
    public void export(HttpServletResponse response, @ModelAttribute YyQfmxFilter filter) throws IOException {
        List<YyQfmxSelect> list = yyQfmxService.getList(filter, filter.getSfbz(), filter.getChbz());
        if (!list.isEmpty()) {
            //list = list.stream().sorted(Comparator.comparing(YyQfmxSelect::getYsyf).reversed()).collect(Collectors.toList());
            YyQfmxSelect yyQfmxSelect = new YyQfmxSelect();
            yyQfmxSelect.setYhbh("合计");
            yyQfmxSelect.setYssl(list.stream().filter(o -> "1".equals(o.getFylx()) || "2".equals(o.getFylx()))
                    .map(YyQfmxSelect::getYssl).reduce(BigDecimal.ZERO, BigDecimal::add));
            yyQfmxSelect.setYssf(list.stream().map(YyQfmxSelect::getYssf).reduce(BigDecimal.ZERO, BigDecimal::add));
            yyQfmxSelect.setYswsf(list.stream().map(YyQfmxSelect::getYswsf).reduce(BigDecimal.ZERO, BigDecimal::add));
            yyQfmxSelect.setYsljf(list.stream().map(YyQfmxSelect::getYsljf).reduce(BigDecimal.ZERO, BigDecimal::add));
            yyQfmxSelect.setYsszyf(list.stream().map(YyQfmxSelect::getYsszyf).reduce(BigDecimal.ZERO, BigDecimal::add));
            yyQfmxSelect.setYsje(list.stream().map(YyQfmxSelect::getYsje).reduce(BigDecimal.ZERO, BigDecimal::add));
            yyQfmxSelect.setZnj(list.stream().map(YyQfmxSelect::getZnj).reduce(BigDecimal.ZERO, BigDecimal::add));
            list.add(yyQfmxSelect);
            String fileName = GuidGenerator.getGuid();
            ExcleFileUtil.exportExcel(response, list, YyQfmxSelect.class, String.format("%s.xlsx", fileName), filter.getExportFields());
        }
    }

    @ApiOperationSupport(order = 6)
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询欠费明细", tags = "欠费明细变更")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "欠费ID", required = true, dataType = "String")})
    public ResultRespone<YyQfmx> getById(@PathVariable("id") String id) {
        return ResultRespone.success(yyQfmxService.getById(id));
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "撤销算费", tags = "欠费明细变更")
    @PostMapping("/{id}/cxsf")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "欠费ID", required = true, dataType = "String")})
    public ResultRespone<Boolean> cxsf(@PathVariable("id") String id) {

        boolean result = yyQfmxService.cxSf(id);
        return result ? ResultRespone.success(true, "撤销算费成功") : ResultRespone.failed(false, "撤销算费失败");
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "欠费明细变更-[莱阳]")
    @PutMapping
    @Transactional
    public ResultRespone updateById(@RequestBody YyQfmxBg yyQfmxBg) {
        if (StringUtils.isEmpty(yyQfmxBg.getCbkid()))
            throw new FeesException("抄表卡ID为空", FeesErrorCode.BUSINESS_ERROR);

        YyQfmx yyQfmx = yyQfmxService.getById(yyQfmxBg.getId());
        YyQfmx yyQfmx_new = JSON.parseObject(JSON.toJSONString(yyQfmx), YyQfmx.class);
        if (yyQfmx.getSfbz().equals("1")) {
            throw new FeesException("当前欠费已缴费", FeesErrorCode.BUSINESS_ERROR);
        }

        // 同一财务周期内已有交费记录则不能变更欠费明细
        Long chargedCount = yyQfmxService.checkQfmxIsCharged(yyQfmx);
        if (chargedCount > 0) {
            throw new FeesException("当前财务周期内已进行过交费,不能变更", FeesErrorCode.BUSINESS_ERROR);
        }

        yyQfmx.setChbz(PjztEnum.已冲红.getValue());
        yyQfmx.setChsj(new Date());
        yyQfmx.setGdyx(yyQfmxBg.getGdyx());
        yyQfmx.setPzr(yyQfmxBg.getPzr());
        yyQfmx.setBz(yyQfmxBg.getBz());
        yyQfmxService.updateById(yyQfmx);

        YyQfmx YyQfmx_ch = yyQfmxService.createHp(yyQfmx, yyQfmx.getChsj());
        YyQfmx_ch.setSfbc("2");
        YyQfmx_ch.setGdzt("");
        YyQfmx_ch.setGdlsbh("");
        YyQfmx_ch.setGdyx(yyQfmxBg.getGdyx());
        YyQfmx_ch.setPzr(yyQfmxBg.getPzr());
        //YyQfmx_ch.setJyType(yyQfmxBg.getJyType());
        YyQfmx_ch.setBz(yyQfmxBg.getBz());
        yyQfmxService.save(YyQfmx_ch);

        BeanUtils.copyProperties(yyQfmxBg, yyQfmx_new, NumberHelper.getNullPropertyNames(yyQfmxBg));
        yyQfmx_new.setGdzt("");
        yyQfmx_new.setGdlsbh("");
        yyQfmx_new.setGdyx("");
        yyQfmx_new.setPzr("");
        //yyQfmx_new.setJyType("");
        yyQfmx_new.setBz("");
        yyQfmx_new.setChbz(PjztEnum.正常.getValue());
        yyQfmx_new.setSfbc("2");
        yyQfmx_new.setCwrq(gdcsbService.selectCwrq());
        yyQfmx_new.setId(GuidGenerator.getGuid());
        BmSj bmSj = sjService.getById(yyQfmx_new.getSjbm());

        if (bmSj.getJtbz().equals("1")) {
            yyQfmx_new.setJtzqljl(yyQfmxBg.getJtzqljlJsq().add(yyQfmxBg.getYssl()));
            yyQfmx_new.setSj(BigDecimal.ZERO);
        } else {
            yyQfmx_new.setSj(bmSj.getSj());
            yyQfmx_new.setJtzqljl(BigDecimal.ZERO);
            yyQfmx_new.setJt1sf(BigDecimal.ZERO);
            yyQfmx_new.setJt2sf(BigDecimal.ZERO);
            yyQfmx_new.setJt3sf(BigDecimal.ZERO);
            yyQfmx_new.setJt1sl(BigDecimal.ZERO);
            yyQfmx_new.setJt2sl(BigDecimal.ZERO);
            yyQfmx_new.setJt3sl(BigDecimal.ZERO);
            yyQfmx_new.setJt1sj(BigDecimal.ZERO);
            yyQfmx_new.setJt2sj(BigDecimal.ZERO);
            yyQfmx_new.setJt3sj(BigDecimal.ZERO);
        }
        if (StringUtil.isNotEmpty(yyQfmx_new.getSjbm1())) {
            BmSj bmSj1 = sjService.getById(yyQfmx_new.getSjbm1());
            if (!bmSj1.getJtbz().equals("1")) {
                yyQfmx_new.setSj1(bmSj1.getSj());
                yyQfmx_new.setSj1Jt1sf(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt2sf(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt3sf(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt1sl(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt2sl(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt3sl(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt1sj(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt2sj(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt3sj(BigDecimal.ZERO);
            } else {
                yyQfmx_new.setSj1(BigDecimal.ZERO);
            }
        }
        if (StringUtil.isNotEmpty(yyQfmx_new.getSjbm2())) {
            BmSj bmSj2 = sjService.getById(yyQfmx_new.getSjbm2());
            if (!bmSj2.getJtbz().equals("1")) {
                yyQfmx_new.setSj1(bmSj2.getSj());
                yyQfmx_new.setSj1Jt1sf(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt2sf(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt3sf(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt1sl(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt2sl(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt3sl(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt1sj(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt2sj(BigDecimal.ZERO);
                yyQfmx_new.setSj1Jt3sj(BigDecimal.ZERO);
            } else {
                yyQfmx_new.setSj1(BigDecimal.ZERO);
            }
        }

        if (yyQfmx_new.getYssl().compareTo(BigDecimal.ZERO) == 0) {
            yyQfmx_new.setSfbz("4");
        } else {
            yyQfmx_new.setSfbz("0");
        }

        yyQfmx_new.setLrrq(yyQfmx.getChsj());
        yyQfmx_new.setJsrq(yyQfmx.getChsj());
        if (yyQfmx_new.getSl().compareTo(BigDecimal.ZERO) > 0
                && StringUtil.isNotEmpty(yyQfmx_new.getSjbm())) {
            if (yyQfmx_new.getSf().compareTo(BigDecimal.ZERO) > 0) {
                yyQfmx_new.setCbjsbz("0");
                yyQfmx_new.setCbjsfs("正常单价计费");
            }

            if (yyQfmx_new.getJt1sf().compareTo(BigDecimal.ZERO) > 0
                    || yyQfmx_new.getJt2sf().compareTo(BigDecimal.ZERO) > 0
                    || yyQfmx_new.getJt3sf().compareTo(BigDecimal.ZERO) > 0) {
                yyQfmx_new.setCbjsbz("2");
                yyQfmx_new.setCbjsfs("阶梯计费");
            }
        }

        if (yyQfmx_new.getSl1().compareTo(BigDecimal.ZERO) > 0
                && StringUtil.isNotEmpty(yyQfmx_new.getSjbm1())) {
            if (yyQfmx_new.getSf1().compareTo(BigDecimal.ZERO) > 0) {
                yyQfmx_new.setCbjsbz("1");
                yyQfmx_new.setCbjsfs("一表多价计费");
            }
            if (yyQfmx_new.getSj1Jt1sf().compareTo(BigDecimal.ZERO) > 0
                    || yyQfmx_new.getSj1Jt2sf().compareTo(BigDecimal.ZERO) > 0
                    || yyQfmx_new.getSj1Jt3sf().compareTo(BigDecimal.ZERO) > 0) {
                yyQfmx_new.setCbjsbz("3");
                yyQfmx_new.setCbjsfs("一表多价含阶梯计费");
            }
        }

        if (yyQfmx_new.getSl2().compareTo(BigDecimal.ZERO) > 0
                && StringUtil.isNotEmpty(yyQfmx_new.getSjbm2())) {
            if (yyQfmx_new.getSf2().compareTo(BigDecimal.ZERO) > 0) {
                yyQfmx_new.setCbjsbz("1");
                yyQfmx_new.setCbjsfs("一表多价计费");
            }
            if (yyQfmx_new.getSj2Jt1sf().compareTo(BigDecimal.ZERO) > 0
                    || yyQfmx_new.getSj2Jt2sf().compareTo(BigDecimal.ZERO) > 0
                    || yyQfmx_new.getSj2Jt3sf().compareTo(BigDecimal.ZERO) > 0) {
                yyQfmx_new.setCbjsbz("3");
                yyQfmx_new.setCbjsfs("一表多价含阶梯计费");
            }
        }

        YyCblr yyCblr = yyCblrService.getById(yyQfmx_new.getCbkid());
        //更具欠费流水编号获取最早的一笔欠费的cwrq
        String cwrq = yyQfmxService.getFirstCwrq(yyQfmx_new.getQflsbh());
        if (yyCblr.getCwrq().equals(cwrq)) {
            yyCblrService.lambdaUpdate()
                    .set(YyCblr::getScds, yyQfmx_new.getScds())
                    .set(YyCblr::getBcds, yyQfmx_new.getBcds())
                    .set(YyCblr::getJjl, yyQfmx_new.getJjl())
                    .set(YyCblr::getSl, yyQfmx_new.getSl())
                    .set(YyCblr::getLrryxm, yyQfmx_new.getLrryxm())
                    .set(YyCblr::getLrrybm, yyQfmx_new.getLrrybm())
                    .set(YyCblr::getCblx, yyQfmx_new.getCblx())
                    .set(YyCblr::getJbzd, yyQfmx_new.getJbzd())
                    .set(YyCblr::getXbqd, yyQfmx_new.getXbqd())
                    .eq(YyCblr::getCwrq, yyQfmx_new.getCwrq())
                    .eq(YyCblr::getCbkid, yyQfmx_new.getCbkid())
                    .update();
            if (bmSj.getJtbz().equals("1")) {
                yhKhjbxxService.lambdaUpdate().set(YhKhjbxx::getJtzqljl, yyQfmx_new.getJtzqljl())
                        .eq(YhKhjbxx::getYhbh, yyQfmx_new.getYhbh())
                        .update();
            }
        }

        String gdlsbh = yyQfmx.getGdlsbh();
        if (StrUtil.isNotEmpty(gdlsbh)) {
            yyQfmxGdService.update().set("gdyx", yyQfmxBg.getGdyx())
                    .eq("gdlsbh", gdlsbh).update();
        }
        //简单的判断
        BigDecimal zsl = yyQfmx_new.getSl().add(yyQfmx_new.getSl1()).add(yyQfmx_new.getSl2());
        if (yyQfmx_new.getYssl().compareTo(zsl) != 0) {
            throw new FeesException("修改欠费明细失败，水量之和不等于应收水量！", FeesErrorCode.BUSINESS_ERROR);
        }
        BigDecimal zsf = yyQfmx_new.getSf().add(yyQfmx_new.getSf1()).add(yyQfmx_new.getSf2());
        if (yyQfmx_new.getYssf().compareTo(zsf) != 0) {
            throw new FeesException("修改欠费明细失败，收费之和不等于应收收费！", FeesErrorCode.BUSINESS_ERROR);
        }
        BigDecimal zwsf = yyQfmx_new.getWsf().add(yyQfmx_new.getWsf1()).add(yyQfmx_new.getWsf2());
        if (yyQfmx_new.getYswsf().compareTo(zwsf) != 0) {
            throw new FeesException("修改欠费明细失败，污水费之和不等于应收污水费！", FeesErrorCode.BUSINESS_ERROR);
        }
        BigDecimal zszyf = yyQfmx_new.getSzyf().add(yyQfmx_new.getSzyf1()).add(yyQfmx_new.getSzyf2());
        if (yyQfmx_new.getYsszyf().compareTo(zszyf) != 0) {
            throw new FeesException("修改欠费明细失败，水资源税之和不等于应收水资源税！", FeesErrorCode.BUSINESS_ERROR);
        }
        boolean tf = yyQfmxService.save(yyQfmx_new);

        if (tf) {
            YyBgLog yyBgLog = new YyBgLog();
            yyBgLog.setBglxid(yyQfmxBg.getId());
            yyBgLog.setBglx(BglxEnum.QFMXBG.getValue());
            yyBgLog.setBgqjson(JSONObject.toJSONString(yyQfmx));
            yyBgLog.setBghjson(JSONObject.toJSONString(yyQfmx_new));
            yyBgLog.setBgnr(
                    String.format("欠费明细变更调整，用户编号%s-财务日期%s，调整日期：%s 调整人：%s"
                            , yyQfmx.getYhbh()
                            , yyQfmx.getCwrq()
                            , LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
                            , SecurityUtils.getUser().getRealName()
                    ));
            yyBgLog.setGdzt("2");
            yyBgLogService.bglogsave(yyBgLog);
//            List<YyQfmx> list = new ArrayList<>();
//            list.add(yyQfmx_new);
//            znjCal.YyQfmxZnj(yyQfmx_new.getYhbh(), list);
        }
        return ResultRespone.success(tf);
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "阶梯水费计算", tags = "欠费明细变更")
    @PostMapping("jtsfjs")
    public ResultRespone jtSfjs(@RequestBody Jtsfjs jtsfjs) {
        SfJsJg sfJsJg = yyQfmxService.jtSfjs(jtsfjs);
        return ResultRespone.success(sfJsJg);
    }

    public static boolean areFieldsEqual(Object obj1, Object obj2, Set<String> excludeFields) {
        if (obj1 == null || obj2 == null) {
            throw new FeesException("参数对象不能为空！", FeesErrorCode.BUSINESS_ERROR);
        }

        Class<?> clazz1 = obj1.getClass();
        Class<?> clazz2 = obj2.getClass();

        Field[] fields1 = clazz1.getDeclaredFields();
        Field[] fields2 = clazz2.getDeclaredFields();

        Set<String> commonFieldNames = new HashSet<>();
        for (Field field1 : fields1) {
            for (Field field2 : fields2) {
                if (field1.getName().equals(field2.getName()) && field1.getClass().equals(field2.getClass())) {
                    commonFieldNames.add(field1.getName());
                    break;
                }
            }
        }

        for (String fieldName : commonFieldNames) {
            if (excludeFields != null && excludeFields.contains(fieldName)) {
                continue;
            }
            try {
                Field field1 = clazz1.getDeclaredField(fieldName);
                Field field2 = clazz2.getDeclaredField(fieldName);

                field1.setAccessible(true);
                field2.setAccessible(true);

                Object value1 = field1.get(obj1);
                Object value2 = field2.get(obj2);

                if (StringUtils.isEmpty(value1) && StringUtils.isEmpty(value2)) {
                    continue;
                }
                if ((value1 == null && value2 != null && value2.equals(BigDecimal.ZERO)) || (value1 != null && value1.equals(BigDecimal.ZERO) && value2 == null)) {
                    continue;
                }
                if (value1.getClass() == BigDecimal.class) {
                    if (!(((BigDecimal) value1).compareTo((BigDecimal) value2) == 0)) {
                        System.out.println("验证算费参数失败字段：" + fieldName);
                        return false;
                    }
                } else {
                    if (!value1.equals(value2)) {
                        System.out.println("验证算费参数失败字段：" + fieldName);
                        return false;
                    }
                }
            } catch (NoSuchFieldException | IllegalAccessException e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }


    @ApiOperationSupport(order = 14)
    @ApiOperation(value = "生成欠费明细（按抄表本（册）算费）", tags = {"抄表算费"})
    @PostMapping("ccbsf")
    public ResultRespone cbbSf(@RequestBody CbbSf cbbSf) {
        String result = yyQfmxService.cbbSf(cbbSf);
        return ResultRespone.success(result);
    }

    @ApiOperationSupport(order = 15)
    @ApiOperation(value = "生成欠费明细（按用户算费）")
    @PostMapping("/yhsf")
    public ResultRespone yhSf(@RequestBody YhSf yhSf) {
        String result = yyQfmxService.yhSf(yhSf);
        return ResultRespone.success(result);
    }

    @ApiOperationSupport(order = 17)
    @ApiOperation(value = "水费测算", tags = {"水费补差"})
    @PostMapping("sfjs")
    public ResultRespone<SfJsJg> sfJs(@RequestBody Sfcs sfcs) {
        if (StringUtils.isEmpty(sfcs.getCbkid())) {
            throw new FeesException("抄表卡ID不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtils.isEmpty(sfcs.getYsyf())) {
            throw new FeesException("费用月份不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtils.isEmpty(sfcs.getFylx())) {
            throw new FeesException("费用类型不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtils.isEmpty(sfcs.getSjbm())) {
            throw new FeesException("水价1不能为空", FeesErrorCode.BUSINESS_ERROR);
        }
        if (sfcs.getYbdjbz().equals("1")) {
            if (StringUtils.isEmpty(sfcs.getSjbm1())) {
                throw new FeesException("水价2不能为空", FeesErrorCode.BUSINESS_ERROR);
            }
        }
        SfJsJg sfJsJg = yyQfmxService.sfCs(sfcs);
        return ResultRespone.success(sfJsJg);
    }

    @ApiOperationSupport(order = 18)
    @ApiOperation(value = "水费补差", tags = {"水费补差"})
    @PostMapping("sfbc")
    public ResultRespone<Boolean> sfBc(@RequestBody SfBc sfBc) {
        boolean result = yyQfmxService.sfBc(sfBc);
        return result ? ResultRespone.success(true) : ResultRespone.failed(false);
    }

    @ApiOperationSupport(order = 21)
    @GetMapping("/stat")
    @ApiOperation(value = "应收明细统计", tags = {"综合查询"})
    public ResultRespone<YyStat> stat(@ModelAttribute YyQfmxStatFilter filter) {
        YyStat stat = yyQfmxService.stat(filter);
        return ResultRespone.success(stat);
    }

    @ApiOperationSupport(order = 22)
    @PostMapping("/pjyl")
    @ApiOperation(value = "票据预览", tags = {"营业厅收费"})
    public ResultRespone pjyl(@RequestBody pjYl pjyl) {
        return ResultRespone.success(yyQfmxService.pjyl(pjyl));
    }

    @ApiOperationSupport(order = 23)
    @GetMapping("/getqfsjmx")
    @ApiOperation(value = "获取欠费水价明细", tags = {"营业厅收费"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "qfid", value = "欠费ID", required = true, dataType = "String")
    })
    public ResultRespone getqfsjmx(@RequestParam String qfid) {
        return ResultRespone.success(yyQfmxService.getqfsjmx(qfid));
    }

    /***
     * 水费拆分业务处理（水量拆分）水量的分配规则平均分配、按比例分配，限制拆分非阶梯
     * @param qfid 欠费ID
     * @param RulesValue 拆分规则值（值为0到1之间）
     * @return
     */
    @ApiOperation(value = "欠费拆分", tags = {"收费管理"})
    @PostMapping("/saveQfmxSplit")
    @ApiImplicitParams({@ApiImplicitParam(name = "qfid", value = "欠费ID", required = true, dataType = "String"), @ApiImplicitParam(name = "RulesValue", value = "拆分规则值（值为0到1之间）", required = true, dataType = "BigDecimal")})
    public ResultRespone updateSplitQfmx(@RequestParam String qfid, @RequestParam BigDecimal RulesValue) {
        //业务逻辑处理
        if (StringUtils.isEmpty(qfid)) {
            throw new FeesException("欠费明细ID为空", FeesErrorCode.BUSINESS_ERROR);
        }
        YyQfmx yyQfmx = yyQfmxService.getById(qfid);
        if (StringUtil.isNull(yyQfmx)) {
            throw new FeesException("未查询到响应欠费明细", FeesErrorCode.BUSINESS_ERROR);
        }
        if (yyQfmx.getSl() == null || yyQfmx.getSl().equals(BigDecimal.ZERO) || yyQfmx.getSl().compareTo(new BigDecimal(2)) < 0) {
            throw new FeesException("欠费明细水量值为空或0，水量小2", FeesErrorCode.BUSINESS_ERROR);
        }
        if (yyQfmx.getSj() == null || yyQfmx.getSl().equals(BigDecimal.ZERO) || yyQfmx.getSj().equals("0")) {
            throw new FeesException("欠费明细水价不为空或0", FeesErrorCode.BUSINESS_ERROR);
        }
        if (!yyQfmx.getCbjsbz().equals("0")) {
            throw new FeesException("拆分限正常单价计费", FeesErrorCode.BUSINESS_ERROR);
        }
        if (StringUtils.isEmpty(RulesValue)) {
            throw new FeesException("拆分规则值", FeesErrorCode.BUSINESS_ERROR);
        }
        if (RulesValue.compareTo(BigDecimal.ZERO) <= 0 || RulesValue.compareTo(BigDecimal.ONE) >= 0) {
            throw new FeesException("拆分规则值应在0到1之前", FeesErrorCode.BUSINESS_ERROR);
        }
        int zsl = Integer.parseInt(yyQfmx.getSl().toString());
        int pjsl1 = (int) (zsl * RulesValue.doubleValue());
        int pjsl2 = zsl - pjsl1;
        //存储拆分水量
        int[] arrayName = new int[2];
        arrayName[0] = pjsl1;
        arrayName[1] = pjsl2;
        //违约金计算
        List<BmYslx> bmYslxs = bmYslxService.lambdaQuery().inSql(BmYslx::getCode, String.format("select yslx from bm_sj where code='%s'", yyQfmx.getSjbm())).list();
        ZNJResult znjResult = new ZNJResult(BigDecimal.ZERO, 0);
        if (bmYslxs.size() > 0) {
            BmYslx bmYslx = bmYslxs.get(0);
            //计算违约金的金额为：应收水费+污水费+水资源费(现只需应收水费)
            //BigDecimal QFYSJE = yyQfmx.getYssf().add(yyQfmx.getYswsf()).add(yyQfmx.getYsszyf());
            BigDecimal QFYSJE = yyQfmx.getYssf();
            //日期转换
            LocalDate cbrq = yyQfmx.getCbrq().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            znjResult = znjCal.getZNJ(cbrq, bmYslx.getZnjbm(), bmYslx.getZnjday(), bmYslx.getZnj(), QFYSJE, qfid, yyQfmx.getYhbh());
            yyQfmx.setZnjfl(bmYslx.getZnj());
            yyQfmx.setZnj(znjResult.getZnJJe());
            yyQfmx.setZnjts(BigDecimal.valueOf(znjResult.getZnJTs()));
        }
        YhCbkxx yhCbkxx = yhCbkxxService.getById(yyQfmx.getCbkid());
        //进行循环添加欠费明细记录
        int scds_new = 0;
        for (int i = 0; i < arrayName.length; i++) {
            long currentTimeMillis = System.currentTimeMillis();
            String str = String.valueOf(currentTimeMillis);
            yyQfmx.setId(str);//欠费ID
            if (i == 0) {
                int scds = Integer.parseInt(yyQfmx.getScds().toString());
                int bcds = scds + arrayName[i];
                yyQfmx.setScds(new BigDecimal(scds));//上次读数
                yyQfmx.setBcds(new BigDecimal(bcds));//本次读数
                yyQfmx.setSl(new BigDecimal(pjsl1));//水量
                scds_new = bcds;//上次读数
            } else {
                int scds = scds_new;//上次读数
                int bcds = scds + arrayName[i];
                yyQfmx.setScds(new BigDecimal(scds));//上次读数
                yyQfmx.setBcds(new BigDecimal(bcds));//本次读数
                yyQfmx.setSl(new BigDecimal(arrayName[i]));//水量
            }

            //1.水费2.垃圾费3.污水费4.水资源费5.违约金，需重新计算
            //1.计算水费,
            BigDecimal sf = new BigDecimal(arrayName[i]).multiply(yyQfmx.getSj());
            yyQfmx.setSf(sf);
            //2.计算垃圾费
            BigDecimal ljf = BigDecimal.ZERO;
            if (yhCbkxx.getLjffs().equals("1")) {
                //按量计算
                ljf = new BigDecimal(arrayName[i]).multiply(yyQfmx.getLjfdj());
            } else {
                //按户计算只收取一次垃圾费
                if (i == 0) {
                    ljf = yyQfmx.getLjf();
                }
            }
            yyQfmx.setLjf(ljf);
            //3.计算污水费
            BigDecimal wssf = new BigDecimal(arrayName[i]).multiply(yyQfmx.getWsfdj());
            yyQfmx.setWsf(wssf);
            //4.水资源费
            BigDecimal szyf = new BigDecimal(arrayName[i]).multiply(yyQfmx.getSzyfDj());
            yyQfmx.setSzyf(szyf);
            //5.计算违约金
            BigDecimal znj = BigDecimal.ZERO;
            if (znjResult.getZnJJe().compareTo(BigDecimal.ZERO) > 0 && znjResult.getZnJTs() > 0) {
                if (i == 0) {
                    znj = znjResult.getZnJJe().divide(BigDecimal.valueOf(2), 2, RoundingMode.HALF_UP);
                } else {
                    znj = znjResult.getZnJJe().subtract(znjResult.getZnJJe().divide(BigDecimal.valueOf(2), 2, RoundingMode.HALF_UP));
                }
            }
            yyQfmx.setZnj(znj);
            //应收计算
            yyQfmx.setYssl(yyQfmx.getSl());
            yyQfmx.setYssf(sf);
            yyQfmx.setYswsf(wssf);
            yyQfmx.setYsljf(ljf);
            yyQfmx.setYsszyf(szyf);
            yyQfmx.setYsje(sf.add(wssf).add(szyf).add(ljf).add(znj));
            yyQfmxService.save(yyQfmx);
        }

        return ResultRespone.success(yyQfmxService.lambdaUpdate().set(YyQfmx::getSfbz, "4").eq(YyQfmx::getId, qfid).update());
    }

    @ApiOperation(value = "预开发票", tags = {"收费管理"})
    @PostMapping("/ykfp")
    public ResultRespone ykfp(@RequestBody FpykInsert insert) {
        if (yyQfmxService.ykfp(insert)) {
            return ResultRespone.success("成功添加开票申请");
        }
        return ResultRespone.failed("开票申请添加失败");
    }

    @ApiOperationSupport(order = 28)
    @PostMapping(value = "/fytzsave", headers = "content-type=multipart/form-data")
    @ApiOperation(value = "费用调整", tags = {"收费管理"})
    public ResultRespone fytzsave(@Valid fylrDto dto, @RequestParam(value = "fileList", required = false) List<MultipartFile> fileList) {
        String id = yyQfmxService.fytzsave(dto, dto.getGdzt());
        if (StringUtil.isNotEmpty(id)) {
            String path = filePathBean.getOtherfile();
            if (fileList.size() > 0) {
                iFileInfoService.saveFileList(fileList, path, id, "yy_bg_log", "费用调整");
            }
            return ResultRespone.success(id, "费用录入成功");
        }
        return ResultRespone.failed("费用录入失败");
    }

    @ApiOperationSupport(order = 29)
    @GetMapping("/fytzpage")
    @ApiOperation(value = "费用调整分页查询", tags = {"收费管理"})
    public ResultRespone<PageResult<YyQfmxFytzSelect>> fytzpage(@ModelAttribute PageDto pageDto, FytzFilter filter) {
        pageDto.setOrders(new ArrayList<>());
        return ResultRespone.success(yyQfmxService.fytzpage(pageDto, filter));
    }

    @ApiOperationSupport(order = 30)
    @GetMapping("/ljfjm")
    @ApiOperation(value = "垃圾费减免统计", tags = {"垃圾费减免统计"})
    public ResultRespone<CollectionData<LjfjmVo>> ljfjm(@ModelAttribute LjfjmDto dto) {
        List<LjfjmVo> list = yyQfmxService.ljfjm(dto);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 31)
    @GetMapping("/qfmxbgPage")
    @ApiOperation(value = "欠费明细变更统计报表", tags = {"欠费明细变更统计报表"})
    public ResultRespone<PageResult<QfmxbgtjVo>> qfmxbgPage(@ModelAttribute PageDto pageDto, QfmxbgtjDto dto) {
        return ResultRespone.success(yyQfmxService.qfmxbgPage(pageDto, dto));
    }

    @ApiOperationSupport(order = 32)
    @GetMapping("/exportQfmxbg")
    @ApiOperation(value = "导出欠费明细变更统计报表", tags = {"导出欠费明细变更统计报表"})
    public void exportQfmxbg(HttpServletResponse response, @ModelAttribute QfmxbgtjDto dto) throws IOException {
        List<QfmxbgtjVo> list = yyQfmxService.qfmxbgPageList(dto);
        if (!list.isEmpty()) {
            ExcleFileUtil.exportExcel(response, list, QfmxbgtjVo.class, "欠费明细变更统计报表.xlsx", dto.getExportFields());
        }
    }

    @ApiOperationSupport(order = 31)
    @GetMapping("/qfmxbgPlcj")
    @ApiOperation(value = "欠费明细变更", tags = {"欠费明细变更"})
    public ResultRespone qfmxbgPlcj(String ywid) {
        return ResultRespone.success(yyQfmxService.qfmxbgPlcj(ywid));
    }

    @ApiOperationSupport(order = 33)
    @GetMapping("/fylrtjPage")
    @ApiOperation(value = "费用录入统计报表", tags = {"费用录入统计报表"})
    public ResultRespone<PageResult<FylrtjVo>> fylrtjPage(@ModelAttribute PageDto pageDto, FylrtjDto dto) {
        return ResultRespone.success(yyQfmxService.fylrtjPage(pageDto, dto));
    }

    @ApiOperationSupport(order = 34)
    @GetMapping("/exportFylrtj")
    @ApiOperation(value = "导出费用录入统计报表", tags = {"导出费用录入统计报表"})
    public void exportFylrtj(HttpServletResponse response, @ModelAttribute FylrtjDto dto) throws IOException {
        List<FylrtjVo> list = yyQfmxService.fylrtjPageList(dto);
        if (!list.isEmpty()) {
            ExcleFileUtil.exportExcel(response, list, QfmxbgtjVo.class, "费用录入统计报表.xlsx", dto.getExportFields());
        }
    }

    @ApiOperationSupport(order = 30)
    @GetMapping("/ycyetj")
    @ApiOperation(value = "预存余额报表", tags = {"预存余额报表"})
    public ResultRespone<CollectionData<YcyetjVo>> getYcyetj(@ModelAttribute YcyetjDto dto) {
        List<YcyetjVo> list = yyQfmxService.getYcyetj(dto);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 31)
    @GetMapping("/getfyhslbb")
    @ApiOperation(value = "获取费用回收率报表", tags = {"报表管理"})
    public ResultRespone<CollectionData<FyhslSelect>> getfyhslbb(@ModelAttribute FyhslFilter filter) {
        List<FyhslSelect> list = yyQfmxService.getfyhslbb(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 20)
    @GetMapping("/monthlyStat")
    @ApiOperation(value = "报表管理-应收统计/减免统计")
    public ResultRespone<CollectionData<YyQfmxMonthlyStat>> monthlyStat(@ModelAttribute YyQfmxStatFilter filter) {
        List<YyQfmxMonthlyStat> list = yyQfmxService.monthlyStat(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 20)
    @GetMapping("/monthlyStatSummary")
    @ApiOperation(value = "应收汇总月报表（汇总版）")
    public ResultRespone<CollectionData<YyQfmxMonthlyStat>> monthlyStatSummary(@ModelAttribute YyQfmxStatFilter filter) {
        List<YyQfmxMonthlyStat> list = yyQfmxService.monthlyStatSummary(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 32)
    @GetMapping("/monthlyStat1")
    @ApiOperation(value = "欠费统计报表[原]")
    public ResultRespone<CollectionData<YyQfmxMonthlyStat>> monthlyStat1(@ModelAttribute YyQfmxStatFilter filter) {
        List<YyQfmxMonthlyStat> list = yyQfmxService.monthlyStat1(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @ApiOperationSupport(order = 33)
    @GetMapping("/monthlyStatSummary1")
    @ApiOperation(value = "欠费统计报表（汇总版）", tags = {"报表管理"})
    public ResultRespone<CollectionData<YyQfmxMonthlyStat>> monthlyStatSummary1(@ModelAttribute YyQfmxStatFilter filter) {
        List<YyQfmxMonthlyStat> list = yyQfmxService.monthlyStatSummary1(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @GetMapping("/bbglystj")
    @ApiOperation(value = "[莱阳]应收统计报表")
    public ResultRespone<CollectionData<YstjbbVo>> bbglystj(@ModelAttribute YyQfmxStatFilter filter) {
        // 应收统计报表
        List<YstjbbVo> list = yyQfmxService.bbglystj(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }

    @GetMapping("/qftjbb")
    @ApiOperation("[莱阳]报表管理-欠费统计")
    public ResultRespone<CollectionData<YstjbbVo>> bbglqftj(@ModelAttribute YyQfmxStatFilter filter) {
        List<YstjbbVo> bbglqftj = yyQfmxService.bbglqftj(filter);
        return ResultRespone.success(new CollectionData<>(bbglqftj, bbglqftj.size()));
    }

}
