chengf
2025-09-10 35fc2330421c1ea217f00e0cb973c1b30e2363c0
service-job/src/main/java/com/java110/job/importData/adapt/ImportHistoryFeeDetailQueueDataAdapt.java
@@ -7,19 +7,25 @@
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;
@@ -82,7 +88,7 @@
    private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
    @Autowired
    private PayFeePreCmd payFeePreCmd;
    private PayFeeCmd payFeeCmd;
    @Autowired
    private IFeeAttrInnerServiceSMO feeAttrInnerServiceSMOImpl;
@@ -98,6 +104,12 @@
    @Autowired
    private ImportCarHistoryFeeDetailQueueDataAdapt importCarHistoryFeeDetailQueueDataAdapt;
    @Autowired
    private IContractPartyaInnerServiceSMO contractPartyaInnerServiceSMOImpl;
    @Autowired
    private IContractInnerServiceSMO contractInnerServiceSMOImpl;
    @Autowired
    private IPayFeeDetailDiscountNewV1InnerServiceSMO payFeeDetailDiscountNewV1InnerServiceSMOImpl;
@@ -139,6 +151,7 @@
        FeeConfigDto feeConfigDto = new FeeConfigDto();
        feeConfigDto.setFeeName(data.getString("secondaryFeeTypeCd"));
        feeConfigDto.setFeeTypeCds(new String[]{"630000007","630000017"});
        importRoomFee.setInvoiceNo(data.getString("invoiceReceiptNo"));
        List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
        if(feeConfigDtos.size() > 0){
            for(FeeConfigDto feeConfigDto1 : feeConfigDtos){
@@ -157,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));
@@ -195,7 +208,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"));
@@ -214,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"));
@@ -233,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"));
@@ -247,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());
            }
        }
    }
@@ -320,29 +374,66 @@
     */
    private void importFeeDetail(ImportRoomFee importRoomFee, String storeId, String userId, String batchId) {
        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]);
            }
        }
        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.setUseFeeName(importRoomFee.getFeeName());
        feeDto2.setPayerObjId(importRoomFee.getRoomId());
        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]);
                }
            }
            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("导入失败,为查询到该主体");
            }
        }
        feeDto2.setCommunityId(importRoomFee.getCommunityId());
        feeDto2.setStatusCd("0");
        feeDto2.setUseStart(DateUtil.getDateFromStringA(importRoomFee.getStartTime()));
@@ -354,7 +445,6 @@
            throw new IllegalArgumentException("费用记录"+importRoomFee.getFeeName()+"不存在");
        }
        importRoomFee.setPayObjId(importRoomFee.getRoomId());
//        if (ListUtil.isNull(feeDtos)) {
//            throw new IllegalArgumentException("查询不到该记录的费用项:"+importRoomFee.getFeeName());
//            List<FeeAttrPo> feeAttrsPos = new ArrayList<>();
@@ -406,10 +496,8 @@
        for (FeeDto tmpFeeDto : feeDtos) {
            if(DateUtil.getDateFromStringB(importRoomFee.getEndTime()).getTime() > tmpFeeDto.getMaxEndTime().getTime()){
                throw new IllegalArgumentException("该费用记录结束时间大于费用记录最大缴费时间");
            }else if(importRoomFee.getStartTime().split(" ")[0].equals(tmpFeeDto.getEndTime().toString())){
            }else {
                doImportFeeDetail(tmpFeeDto, importRoomFee);
            }else{
                throw new IllegalArgumentException("请对改费用记录进行拆分处理");
            }
        }
@@ -455,9 +543,9 @@
        payFeeDetailPo.setCycles(cycle+"");
        payFeeDetailPo.setEndTime(importRoomFee.getEndTime());
        if (count > 0) {
            throw new IllegalStateException("重复的缴费记录");
        }
        PayFeeDetailDiscountPo payFeeDetailDiscount = new PayFeeDetailDiscountPo();
        try {
            Map feePriceAll = computeFeeSMOImpl.getFeePrice(tmpFeeDto);
@@ -492,8 +580,8 @@
        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);
@@ -529,7 +617,6 @@
            return;
        }
        double computeFee = computeFee(feeInfo,importRoomFee);
        //如果结束时间小于 缴费结束时间则延期
        PayFeePo payFeePo = new PayFeePo();
@@ -540,6 +627,14 @@
        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);
@@ -562,10 +657,19 @@
        feeInnerServiceSMOImpl.updateFee(payFeePo);
        feeInfo = feeInnerServiceSMOImpl.queryFees(fee).get(0);
        if (importRoomFee.getEndTime().split(" ")[0].equals(DateUtil.getFormatTimeStringB(feeInfo.getMaxEndTime()))) {
            PayFeePo payFee = new PayFeePo();
            payFee.setFeeId(feeInfo.getFeeId());
            payFee.setState(FeeDto.STATE_FINISH);
            int i = feeInnerServiceSMOImpl.updateFee(payFee);
            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);
            }
        }
    }
@@ -581,7 +685,7 @@
        double month = (DateUtil.dayCompare(
                fee.getStartTime(),
                fee.getMaxEndTime()
                DateUtil.getDateFromStringA(DateUtil.getFormatTimeStringB(fee.getMaxEndTime()).split(" ")[0]+" 23:59:59")
        ));
        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
        //todo 计算应收
@@ -613,8 +717,8 @@
        feeDto = feeDtos.get(0);
        double month = (DateUtil.dayCompare(
                DateUtil.getDateFromStringB(importRoomFee.getStartTime()),
                DateUtil.getDateFromStringB(importRoomFee.getEndTime())
                DateUtil.getDateFromStringA(importRoomFee.getStartTime()),
                DateUtil.getDateFromStringA(importRoomFee.getEndTime().split(" ")[0] + " 23:59:59")
        ));
        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
        //todo 计算应收