chengf
2025-09-10 35fc2330421c1ea217f00e0cb973c1b30e2363c0
service-job/src/main/java/com/java110/job/importData/adapt/ImportHistoryFeeDetailQueueDataAdapt.java
@@ -5,19 +5,27 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.core.smo.IComputeFeeSMO;
import com.java110.dto.PropertyWhiteListFlowDto;
import com.java110.dto.contract.ContractDto;
import com.java110.dto.contract.ContractPartyaDto;
import com.java110.dto.fee.*;
import com.java110.dto.importData.ImportRoomFee;
import com.java110.dto.log.AssetImportLogDetailDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.owner.OwnerRoomRelDto;
import com.java110.dto.payFee.PayFeeDetailDiscountDto;
import com.java110.dto.room.RoomDto;
import com.java110.dto.system.ComponentValidateResult;
import com.java110.fee.api.FeeDiscountApi;
import com.java110.fee.cmd.fee.PayFeeCmd;
import com.java110.fee.cmd.fee.PayFeePreCmd;
import com.java110.intf.IImportPropertyWhiteListfFlowServiceSMO;
import com.java110.intf.common.ICarInoutInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.fee.*;
import com.java110.intf.store.IContractInnerServiceSMO;
import com.java110.intf.store.IContractPartyaInnerServiceSMO;
import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.intf.user.IOwnerRoomRelV1InnerServiceSMO;
import com.java110.job.cmd.importCarInout.CarInout;
@@ -28,18 +36,18 @@
import com.java110.po.fee.PayFeeDetailPo;
import com.java110.po.fee.PayFeePo;
import com.java110.po.payFee.PayFeeDetailDiscountPo;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.constant.StatusConstant;
import com.java110.utils.exception.DAOException;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.ListUtil;
import com.java110.utils.util.StringUtil;
import com.java110.utils.exception.ListenerExecuteException;
import com.java110.utils.util.*;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -57,6 +65,9 @@
    @Autowired
    private FeeDiscountApi feeDiscountApi;
    @Autowired
    private IComputeFeeSMO computeFeeSMOImpl;
    @Autowired
    private IImportFeeDetailInnerServiceSMO importFeeDetailInnerServiceSMOImpl;
@@ -77,6 +88,9 @@
    private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
    @Autowired
    private PayFeeCmd payFeeCmd;
    @Autowired
    private IFeeAttrInnerServiceSMO feeAttrInnerServiceSMOImpl;
    @Autowired
@@ -90,6 +104,12 @@
    @Autowired
    private ImportCarHistoryFeeDetailQueueDataAdapt importCarHistoryFeeDetailQueueDataAdapt;
    @Autowired
    private IContractPartyaInnerServiceSMO contractPartyaInnerServiceSMOImpl;
    @Autowired
    private IContractInnerServiceSMO contractInnerServiceSMOImpl;
    @Autowired
    private IPayFeeDetailDiscountNewV1InnerServiceSMO payFeeDetailDiscountNewV1InnerServiceSMOImpl;
@@ -118,18 +138,29 @@
        List<ImportRoomFee> importCarFees = new ArrayList<>();
        List<ImportRoomFee> importContractFees = new ArrayList<>();
        List<CarInoutPo> carInoutPos = new ArrayList<>();
            String communityId = assetImportLogDetailDto.getCommunityId();
            JSONObject data = JSONObject.parseObject(assetImportLogDetailDto.getContent());
            ImportRoomFee importRoomFee = BeanConvertUtil.covertBean(data, ImportRoomFee.class);
        String communityId = assetImportLogDetailDto.getCommunityId();
        JSONObject data = JSONObject.parseObject(assetImportLogDetailDto.getContent());
        ImportRoomFee importRoomFee = BeanConvertUtil.covertBean(data, ImportRoomFee.class);
        if (importRoomFee.getEndTime() != null){
            String[] split = importRoomFee.getEndTime().split(" ");
            importRoomFee.setEndTime(split[0] + " 23:59:59");
        }
//            List<String> roomTypes = Arrays.asList("住宅物业费","商铺物业费","维修收入","维修基金收入","电费及管理费","代收水费","各类押金","租金收入");
            List<String> carTypes = Arrays.asList("临时停车费", "业主产权过道停车费", "小业主产权车辆管理费","地下停车费","地面停车费");
            List<String> contractTypes = Arrays.asList("垃圾清运费","其他收入","补贴费用","场地使用费","电梯广告(业委会)","快递柜","电梯广告(联讯)","房产中介","非机动车管理费","其他广告");
        List<String> carTypes = Arrays.asList("临时停车费", "业主产权过道停车费", "小业主产权车辆管理费","地下停车费","地面停车费");
        List<String> contractTypes = Arrays.asList("垃圾清运费","其他收入","补贴费用","场地使用费","电梯广告(业委会)","快递柜","电梯广告(联讯)","房产中介","非机动车管理费","其他广告");
        FeeConfigDto feeConfigDto = new FeeConfigDto();
        feeConfigDto.setFeeName(importRoomFee.getSecondaryFeeTypeCdName());
        feeConfigDto.setFeeName(data.getString("secondaryFeeTypeCd"));
        feeConfigDto.setFeeTypeCds(new String[]{"630000007","630000017"});
        importRoomFee.setInvoiceNo(data.getString("invoiceReceiptNo"));
        List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
        if(importRoomFee.getSecondaryFeeTypeCd()!= null && importRoomFee.getSecondaryFeeTypeCd().equals("临时停车费-其他")){
        if(feeConfigDtos.size() > 0){
            for(FeeConfigDto feeConfigDto1 : feeConfigDtos){
                if(feeConfigDto1.getSecondaryFeeTypeCdName() != null && (feeConfigDto1.getSecondaryFeeTypeCdName().equals("电费及管理费-合同") || feeConfigDto1.getSecondaryFeeTypeCdName().equals("代收水费-合同"))){
                    importRoomFee.setObjType("7777");
                }
            }
        }
        if(importRoomFee.getSecondaryFeeTypeCd()!= null && importRoomFee.getSecondaryFeeTypeCd().equals("临时停车费-其他") &&(importRoomFee.getObjType() == null || !(importRoomFee.getObjType().equals("7777")))){
                CarInoutPo carInout = new CarInoutPo();
                carInout.setCommunityId(communityId);
                carInout.setCarNum("A888888");
@@ -139,7 +170,7 @@
                carInout.setInTime(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("chargeStart"));
                carInout.setStatusCd("0");
                carInout.setCreateTime(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("inputTime"));
                carInout.setCreateTime(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("chargeTime"));
                carInout.setbId(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("batchId"));
                carInout.setInoutId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_inoutId));
@@ -170,14 +201,14 @@
                }
            }
            else if(contractTypes.contains(JSONObject.parseObject(assetImportLogDetailDto.getContent()).get("category22"))){
            else if(contractTypes.contains(JSONObject.parseObject(assetImportLogDetailDto.getContent()).get("category22")) || (importRoomFee.getObjType() != null && importRoomFee.getObjType().equals("7777"))){
                importRoomFee.setFeeName(data.getString("secondaryFeeTypeCd"));
                importRoomFee.setCommunityId(communityId);
                importRoomFee.setDetailId(assetImportLogDetailDto.getDetailId());
                importRoomFee.setStartTime(data.getString("chargeStart"));
                importRoomFee.setEndTime(data.getString("chargeEnd").split(" ")[0]+" 23:59:59");
                importRoomFee.setCreateTime(data.getString("inputTime"));
                importRoomFee.setCreateTime(data.getString("chargeTime"));
                importRoomFee.setReceivableAmount(data.getString("bankDepositAmount"));
                importRoomFee.setAmount(data.getString("chargeAmount"));
                importRoomFee.setStaffName(data.getString("charger"));
@@ -196,7 +227,7 @@
                importRoomFee.setDetailId(assetImportLogDetailDto.getDetailId());
                importRoomFee.setStartTime(data.getString("chargeStart"));
                importRoomFee.setEndTime(data.getString("chargeEnd").split(" ")[0]+" 23:59:59");
                importRoomFee.setCreateTime(data.getString("inputTime"));
                importRoomFee.setCreateTime(data.getString("chargeTime"));
                importRoomFee.setReceivableAmount(data.getString("bankDepositAmount"));
                importRoomFee.setAmount(data.getString("chargeAmount"));
                importRoomFee.setCarNum(data.getString("licensePlate"));
@@ -215,7 +246,7 @@
                importRoomFee.setDetailId(assetImportLogDetailDto.getDetailId());
                importRoomFee.setStartTime(data.getString("chargeStart"));
                importRoomFee.setEndTime(data.getString("chargeEnd").split(" ")[0]+" 23:59:59");
                importRoomFee.setCreateTime(data.getString("inputTime"));
                importRoomFee.setCreateTime(data.getString("chargeTime"));
                importRoomFee.setReceivableAmount(data.getString("bankDepositAmount"));
                importRoomFee.setAmount(data.getString("chargeAmount"));
                importRoomFee.setStaffName(data.getString("charger"));
@@ -229,11 +260,52 @@
            return;
        }
        if(!(ListUtil.isNull(importRoomFees))){
            importFeeDetails(importRoomFees.get(0).getStoreId(), importRoomFees.get(0).getUserId(), importRoomFees, importRoomFees.get(0).getBatchId());
        try{
            if(!(ListUtil.isNull(importRoomFees))){
                importFeeDetails(importRoomFees.get(0).getStoreId(), importRoomFees.get(0).getUserId(), importRoomFees, importRoomFees.get(0).getBatchId());
            }
            if(!(ListUtil.isNull(importCarFees))){
                importCarFeeDetails2(importCarFees.get(0).getStoreId(), importCarFees.get(0).getUserId(), importCarFees, importCarFees.get(0).getBatchId());
            }
        }catch (IllegalStateException e){
            throw new IllegalArgumentException(e.getMessage());
        }catch (IllegalArgumentException e){
            throw new IllegalArgumentException(e.getMessage());
        }
        if(!(ListUtil.isNull(importCarFees))){
            importCarHistoryFeeDetailQueueDataAdapt.importCarFeeDetails2(importCarFees.get(0).getStoreId(), importCarFees.get(0).getUserId(), importCarFees, importCarFees.get(0).getBatchId());
        catch (Exception e){
            throw new IllegalArgumentException("未知错误:"+e);
        }
    }
    public void importCarFeeDetails2(String storeId, String userId, List<ImportRoomFee> importCarFees, String batchId) {
        importCarFees = ownerCarInnerServiceSMOImpl.freshCarIds(importCarFees);
        for (ImportRoomFee importCarFee : importCarFees) {
            try {
                if (StringUtil.isEmpty(importCarFee.getCarNum())) {
                    if(importCarFee.getObjType() != null && (importCarFee.getObjType().equals("7777"))){
                        importFeeDetail(importCarFee, storeId, userId, batchId);
                        updateImportLogDetailState(importCarFee.getDetailId());
                    }
                }
                else{
                    OwnerCarDto ownerCarDto = new OwnerCarDto();
                    ownerCarDto.setCommunityId(importCarFee.getCommunityId());
                    ownerCarDto.setCarNum(importCarFee.getCarNum());
                    List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
                    if (ownerCarDtos != null && ownerCarDtos.size() > 0) {
                        importCarFee.setCarId(ownerCarDtos.get(0).getCarId());
                    }else{
                        throw new IllegalStateException("车牌号不存在或存在多辆重复车牌号车");
                    }
                    importFeeDetail(importCarFee, storeId, userId, batchId);
                    updateImportLogDetailState(importCarFee.getDetailId());
                }
            } catch (Exception e) {
                updateImportLogDetailState(importCarFee.getDetailId(), e);
                throw new IllegalArgumentException(e.getMessage());
            }
        }
    }
@@ -258,17 +330,27 @@
        importRoomFees = roomInnerServiceSMOImpl.freshRoomIds(importRoomFees);
        String endTime = "";
        for (ImportRoomFee importRoomFee : importRoomFees) {
            endTime = importRoomFee.getEndTime();
            if (!endTime.contains(":")) {
                endTime += " 23:59:59";
                importRoomFee.setEndTime(endTime);
            }
            try {
                if (StringUtil.isEmpty(importRoomFee.getRoomId())) {
                    continue;
                    throw new IllegalArgumentException("房屋号不存在");
                }
                RoomDto roomDto = new RoomDto();
//                roomDto.setDoorRoomNum(importRoomFee.getDoorRoomNum());
                roomDto.setCommunityId(importRoomFee.getCommunityId());
                if(importRoomFee.getDoorRoomNum()!=null){
                    String[] split = importRoomFee.getDoorRoomNum().split("-");
                    if(split.length < 2){
                        throw new IllegalArgumentException("门室号"+importRoomFee.getDoorRoomNum()+"未遵循x-x-x");
                    }else if(split.length > 2){
                        roomDto.setFloorNum(split[0]);
                        roomDto.setUnitNum(split[1]);
                        roomDto.setRoomNum(split[2]);
                    }
                }
                importFeeDetail(importRoomFee, storeId, userId, batchId);
//                feeDiscountApi
@@ -292,41 +374,79 @@
     */
    private void importFeeDetail(ImportRoomFee importRoomFee, String storeId, String userId, String batchId) {
        RoomDto roomDto = new RoomDto();
        FeeDto feeDto2 = new FeeDto();
        feeDto2.setUseFeeName(importRoomFee.getFeeName());
        if (importRoomFee.getObjType() == null||importRoomFee.getObjType().equals("3333")){
            RoomDto roomDto = new RoomDto();
//        roomDto.setDoorRoomNum(importRoomFee.getDoorRoomNum());
        roomDto.setCommunityId(importRoomFee.getCommunityId());
        if(importRoomFee.getDoorRoomNum()!=null){
            String[] split = importRoomFee.getDoorRoomNum().split("-");
            if(split.length < 2){
                throw new IllegalArgumentException("门室号"+importRoomFee.getDoorRoomNum()+"未遵循x-x-x");
            }else if(split.length > 2){
                roomDto.setFloorNum(split[0]);
                roomDto.setUnitNum(split[1]);
                roomDto.setRoomNum(split[2]);
            roomDto.setCommunityId(importRoomFee.getCommunityId());
            if(importRoomFee.getDoorRoomNum()!=null){
                String[] split = importRoomFee.getDoorRoomNum().split("-");
                if(split.length < 2){
                    throw new IllegalArgumentException("门室号"+importRoomFee.getDoorRoomNum()+"未遵循x-x-x");
                }else if(split.length > 2){
                    roomDto.setFloorNum(split[0]);
                    roomDto.setUnitNum(split[1]);
                    roomDto.setRoomNum(split[2]);
                }
            }
            List<RoomDto> roomDtos = iRoomInnerServiceSMOImpl.queryRooms(roomDto);
            try {
                importRoomFee.setRoomId(roomDtos.get(0).getRoomId());
            }catch (Exception e){
                throw new IllegalArgumentException("门室号"+importRoomFee.getDoorRoomNum()+"未查询到房屋");
            }
            feeDto2.setPayerObjId(importRoomFee.getRoomId());
            importRoomFee.setPayObjId(importRoomFee.getRoomId());
        }else if (importRoomFee.getObjType().equals("6666")){
            if (importRoomFee.getCarNum() == null){
                throw new IllegalArgumentException("车牌号为空");
            }
            OwnerCarDto ownerCarDto = new OwnerCarDto();
            ownerCarDto.setCommunityId(importRoomFee.getCommunityId());
            ownerCarDto.setCarNum(importRoomFee.getCarNum());
            List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
            if (ownerCarDtos != null && ownerCarDtos.size() > 0) {
                feeDto2.setPayerObjId(ownerCarDtos.get(0).getCarId());
                importRoomFee.setCarId(ownerCarDtos.get(0).getCarId());
                importRoomFee.setPayObjId(importRoomFee.getCarId());
            }else{
                throw new IllegalStateException("车牌号不存在或存在多辆重复车牌号车");
            }
        }else {
            ContractPartyaDto contractPartyaDto = new ContractPartyaDto();
            contractPartyaDto.setCommunityId(importRoomFee.getCommunityId());
            contractPartyaDto.setPartyA(importRoomFee.getDoorRoomNum());
            List<ContractPartyaDto> contractPartyaDtos = contractPartyaInnerServiceSMOImpl.queryContractPartyas(contractPartyaDto);
            if (contractPartyaDtos != null && contractPartyaDtos.size() > 0) {
                ContractDto contractDto = new ContractDto();
                contractDto.setCommunityId(importRoomFee.getCommunityId());
                contractDto.setContractCode(importRoomFee.getContractId());
                List<ContractDto> contractDtos = contractInnerServiceSMOImpl.queryContracts(contractDto);
                if (contractDtos.size() == 0) {
                    importRoomFee.setContractId(contractDtos.get(0).getContractId());
                }
                feeDto2.setPayerObjId(contractPartyaDtos.get(0).getPartyaId());
                importRoomFee.setRoomId(contractPartyaDtos.get(0).getPartyaId());
                importRoomFee.setPayObjId(importRoomFee.getRoomId());
            } else {
                throw new IllegalArgumentException("导入失败,为查询到该主体");
            }
        }
        List<RoomDto> roomDtos = iRoomInnerServiceSMOImpl.queryRooms(roomDto);
        try {
            importRoomFee.setRoomId(roomDtos.get(0).getRoomId());
        }catch (Exception e){
            throw new IllegalArgumentException("门室号"+importRoomFee.getDoorRoomNum()+"未查询到房屋");
        }
        FeeDto feeDto2 = new FeeDto();
        feeDto2.setFeeName(importRoomFee.getFeeName());
        feeDto2.setPayerObjId(importRoomFee.getRoomId());
        feeDto2.setCommunityId(importRoomFee.getCommunityId());
        feeDto2.setStatusCd("0");
        feeDto2.setUseStart(DateUtil.getDateFromStringA(importRoomFee.getStartTime()));
        feeDto2.setUseEnd(DateUtil.getDateFromStringA(importRoomFee.getEndTime()));
        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto2);
        feeDtos.removeIf(feeDto -> "2009001".equals(feeDto.getState()));
        if(feeDtos.size() == 0){
            updateImportLogDetailState(importRoomFee.getDetailId(),new IllegalArgumentException("费用项"+importRoomFee.getFeeName()+"不存在"));
            throw new IllegalArgumentException("费用项"+importRoomFee.getFeeName()+"不存在");
            throw new IllegalArgumentException("费用记录"+importRoomFee.getFeeName()+"不存在");
        }
        importRoomFee.setPayObjId(importRoomFee.getRoomId());
        if (ListUtil.isNull(feeDtos)) {
            throw new IllegalArgumentException("查询不到该记录的费用项:"+importRoomFee.getFeeName());
//        if (ListUtil.isNull(feeDtos)) {
//            throw new IllegalArgumentException("查询不到该记录的费用项:"+importRoomFee.getFeeName());
//            List<FeeAttrPo> feeAttrsPos = new ArrayList<>();
//            PayFeePo payFeePo = new PayFeePo();
//            payFeePo.setCommunityId(importRoomFee.getCommunityId());
@@ -369,15 +489,16 @@
//
//
//            feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
        }
        if(feeDtos.size()>1){
//        }
        if(feeDtos.size() > 1){
            throw new IllegalArgumentException(importRoomFee.getDoorRoomNum() +importRoomFee.getFeeName() + "+" + importRoomFee.getStartTime() + "-" + importRoomFee.getEndTime() + "未匹配到收费项");
        }
        for (FeeDto tmpFeeDto : feeDtos) {
            if(DateUtil.getDateFromStringB(importRoomFee.getEndTime()).getTime() > tmpFeeDto.getMaxEndTime().getTime()){
                throw new IllegalArgumentException("该费用记录结束时间大于费用记录最大缴费时间");
            }else {
                doImportFeeDetail(tmpFeeDto, importRoomFee);
            }
            doImportFeeDetail(tmpFeeDto, importRoomFee);
        }
    }
@@ -422,11 +543,17 @@
        payFeeDetailPo.setCycles(cycle+"");
        payFeeDetailPo.setEndTime(importRoomFee.getEndTime());
        if (count > 0) {
            throw new IllegalStateException("重复的缴费记录");
        }
        PayFeeDetailDiscountPo payFeeDetailDiscount = new PayFeeDetailDiscountPo();
        try {
            Map feePriceAll = computeFeeSMOImpl.getFeePrice(tmpFeeDto);
            FeeDto feeDto = new FeeDto();
            feeDto.setFeeId(tmpFeeDto.getFeeId());
            feeDto.setCommunityId(tmpFeeDto.getCommunityId());
            List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
            payFeeDetailPo.setReceivableAmount(computeFeeByCycle(tmpFeeDto,importRoomFee)+"");
            ResponseEntity<String> resultVo = feeDiscountApi.computeFeeDiscount(tmpFeeDto.getFeeId(), tmpFeeDto.getCommunityId(), 105, importRoomFee.getPayObjId(),
                    tmpFeeDto.getPayerObjType(), importRoomFee.getEndTime(), importRoomFee.getEndTime(), importRoomFee.getStartTime(), 1, 20);
@@ -440,11 +567,11 @@
                    String discountPrice = o.get("discountPrice").toString();
                    String discountId =  o.get("discountId").toString();
                    payFeeDetailPo.setDiscountAmount(discountPrice);
                    payFeeDetailPo.setReceivableAmount((Double.parseDouble(payFeeDetailPo.getReceivedAmount()) + Double.parseDouble(payFeeDetailPo.getDiscountAmount()))+"");
                    payFeeDetailDiscount.setDiscountId(discountId);
                    payFeeDetailDiscount.setDiscountPrice(discountPrice);
                }else{
                    payFeeDetailPo.setReceivableAmount(payFeeDetailPo.getReceivedAmount()+"");
                }
            }
        } catch (ParseException e) {
@@ -453,10 +580,12 @@
        payFeeDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
        if(importRoomFee.getOpenInv() != null){
            payFeeDetailPo.setOpenInvoice(importRoomFee.getOpenInv());
        if(importRoomFee.getInvoiceNo() != null){
            payFeeDetailPo.setOpenInvoice(importRoomFee.getInvoiceNo());
        }
        int saved = feeDetailInnerServiceSMOImpl.saveFeeDetail(payFeeDetailPo);
        FeeDetailDto feeDetailDto = new FeeDetailDto();
        feeDetailDto.setDetailId(payFeeDetailPo.getDetailId());
@@ -488,21 +617,115 @@
            return;
        }
        //如果结束时间小于 缴费结束时间则延期
        PayFeePo payFeePo = new PayFeePo();
        payFeePo.setCommunityId(importRoomFee.getCommunityId());
        payFeePo.setStatusCd(StatusConstant.STATUS_CD_VALID);
        payFeePo.setFeeId(tmpFeeDto.getFeeId());
        payFeePo.setState(FeeDto.STATE_FINISH);
        String[] arr = importRoomFee.getEndTime().split(" ");
        if (arr.length >= 2 && arr[1].equals("23:59:59")){
            payFeePo.setEndTime(DateUtil.getNextSecTime(importRoomFee.getEndTime()));
            if(!(FeeDto.FEE_FLAG_ONCE.equals(tmpFeeDto.getFeeFlag()))){
                importRoomFee.setCycle((DateUtil.dayCompare(
                        DateUtil.getDateFromStringA(importRoomFee.getStartTime()),
                        DateUtil.getDateFromStringA(importRoomFee.getEndTime())
                ))+"");
                payFeeCmd.ifCustomStartEndTimePayFee(importRoomFee.getCycle(), DateUtil.getDateFromStringB(importRoomFee.getStartTime().split(" ")[0]), feeDtos.get(0) , feeInfo, importRoomFee.getStartTime());
            }
        }
        if (FeeDto.FEE_FLAG_ONCE.equals(tmpFeeDto.getFeeFlag())) {
            payFeePo.setState(FeeDto.STATE_FINISH);
        }
//        if (FeeDto.FEE_FLAG_ONCE.equals(tmpFeeDto.getFeeFlag())) {
//            payFeePo.setState(FeeDto.STATE_FINISH);
//        }
//        else{
//            payFeePo.setEndTime(DateUtil.getFormatTimeStringA(feeInfo.getMaxEndTime()));
//        }
//        //状态修改为费用结束
//        if (computeFee <= 0 && computeFee > -1){// 10为误差
//            payFeePo.setState(FeeDto.STATE_FINISH);
//        }else{
//            throw new IllegalArgumentException("异常数据:应缴金额小于实缴金额");
//        }
        feeInnerServiceSMOImpl.updateFee(payFeePo);
        feeInfo = feeInnerServiceSMOImpl.queryFees(fee).get(0);
        if (DateUtil.getFormatTimeStringB(feeInfo.getEndTime()).equals(DateUtil.getFormatTimeStringB(feeInfo.getMaxEndTime()))) {
            PayFeePo payFee = new PayFeePo();
            payFee.setFeeId(feeInfo.getFeeId());
            payFee.setState(FeeDto.STATE_FINISH);
            int i = feeInnerServiceSMOImpl.updateFee(payFee);
        if (importRoomFee.getEndTime().split(" ")[0].equals(DateUtil.getFormatTimeStringB(feeInfo.getMaxEndTime()))) {
            double computeFee = computeFee(feeInfo,importRoomFee);
            if(computeFee <= 1 && computeFee >= -1){
                PayFeePo payFee = new PayFeePo();
                payFee.setFeeId(feeInfo.getFeeId());
                payFee.setState(FeeDto.STATE_FINISH);
                payFee.setEndTime(payFee.getMaxTime());
                int i = feeInnerServiceSMOImpl.updateFee(payFee);
            }else{
                PayFeePo payFee = new PayFeePo();
                payFee.setFeeId(feeInfo.getFeeId());
                payFee.setEndTime(DateUtil.getFormatTimeStringA(feeInfo.getMaxEndTime()));
                int i = feeInnerServiceSMOImpl.updateFee(payFee);
            }
        }
    }
    private double computeFee(FeeDto fee,ImportRoomFee importRoomFee) {
        FeeDto feeDto = new FeeDto();
        feeDto.setFeeId(fee.getFeeId());
        feeDto.setCommunityId(fee.getCommunityId());
        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
        if (feeDtos == null || feeDtos.size() != 1) {
            throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "查询费用信息失败,未查到数据或查到多条数据");
        }
        feeDto = feeDtos.get(0);
        double month = (DateUtil.dayCompare(
                fee.getStartTime(),
                DateUtil.getDateFromStringA(DateUtil.getFormatTimeStringB(fee.getMaxEndTime()).split(" ")[0]+" 23:59:59")
        ));
        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
        //todo 计算应收
        BigDecimal receivableAmount = new BigDecimal(feePriceAll.get("feePrice").toString());
        BigDecimal cycles = new BigDecimal(month);
        double tmpReceivableAmount = cycles.multiply(receivableAmount).setScale(4, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        tmpReceivableAmount = MoneyUtil.computePriceScale(tmpReceivableAmount, feeDto.getScale(), Integer.parseInt(feeDto.getDecimalPlace()));
        FeeDetailDto feeDetailDto1 = new FeeDetailDto();
        feeDetailDto1.setFeeId(fee.getFeeId());
        List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto1);
        double computedFee = 0;
        for (FeeDetailDto feeDetail : feeDetailDtos) {
            computedFee += Double.parseDouble(feeDetail.getReceivedAmount()) + Double.parseDouble(feeDetail.getDiscountAmount());
        }
        return tmpReceivableAmount - computedFee;
    }
    private double computeFeeByCycle(FeeDto fee,ImportRoomFee importRoomFee) {
        FeeDto feeDto = new FeeDto();
        feeDto.setFeeId(fee.getFeeId());
        feeDto.setCommunityId(fee.getCommunityId());
        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
        if (feeDtos == null || feeDtos.size() != 1) {
            throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "查询费用信息失败,未查到数据或查到多条数据");
        }
        feeDto = feeDtos.get(0);
        double month = (DateUtil.dayCompare(
                DateUtil.getDateFromStringA(importRoomFee.getStartTime()),
                DateUtil.getDateFromStringA(importRoomFee.getEndTime().split(" ")[0] + " 23:59:59")
        ));
        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
        //todo 计算应收
        BigDecimal receivableAmount = new BigDecimal(feePriceAll.get("feePrice").toString());
        BigDecimal cycles = new BigDecimal(month);
        double tmpReceivableAmount = cycles.multiply(receivableAmount).setScale(4, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        return MoneyUtil.computePriceScale(tmpReceivableAmount, feeDto.getScale(), Integer.parseInt(feeDto.getDecimalPlace()));
    }
}