package com.java110.job.importData.adapt; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; 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.community.CommunityDto; 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.ICommunityInnerServiceSMO; 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; import com.java110.job.importData.DefaultImportData; import com.java110.job.importData.IImportDataAdapt; import com.java110.po.car.CarInoutPo; import com.java110.po.fee.FeeAttrPo; 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.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; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; /** * 房屋缴费信息导入 适配器 * 前端请求 时 必须传入 * param.append('importAdapt', "importRoomOwner"); */ @Service("importHistoryFeeDetailQueueData") public class ImportHistoryFeeDetailQueueDataAdapt extends DefaultImportData implements IImportDataAdapt { @Autowired private FeeDiscountApi feeDiscountApi; @Autowired private IComputeFeeSMO computeFeeSMOImpl; @Autowired private IImportFeeDetailInnerServiceSMO importFeeDetailInnerServiceSMOImpl; @Autowired private IRoomInnerServiceSMO roomInnerServiceSMOImpl; @Autowired private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl; @Autowired private IFeeInnerServiceSMO feeInnerServiceSMOImpl; @Autowired private IFeeDetailInnerServiceSMO feeDetailInnerServiceSMOImpl; @Autowired private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl; @Autowired private PayFeeCmd payFeeCmd; @Autowired private IFeeAttrInnerServiceSMO feeAttrInnerServiceSMOImpl; @Autowired private IOwnerRoomRelV1InnerServiceSMO ownerRoomRelV1InnerServiceSMOImpl; @Autowired private IRoomInnerServiceSMO iRoomInnerServiceSMOImpl; @Autowired private ICarInoutInnerServiceSMO carInoutInnerServiceSMOImpl; @Autowired private ImportCarHistoryFeeDetailQueueDataAdapt importCarHistoryFeeDetailQueueDataAdapt; @Autowired private IContractPartyaInnerServiceSMO contractPartyaInnerServiceSMOImpl; @Autowired private IContractInnerServiceSMO contractInnerServiceSMOImpl; @Autowired private IPayFeeDetailDiscountNewV1InnerServiceSMO payFeeDetailDiscountNewV1InnerServiceSMOImpl; @Autowired private ImportRoomFeeQueueDataAdapt importRoomFeeQueueDataAdapt; @Autowired private ICommunityInnerServiceSMO communityInnerServiceSMO; @Override public void importData(List assetImportLogDetailDtos) { String communityId = assetImportLogDetailDtos.get(0).getCommunityId(); CommunityDto communityDto = new CommunityDto(); communityDto.setCommunityId(communityId); List communityDtos = communityInnerServiceSMO.queryCommunitys(communityDto); for (AssetImportLogDetailDto assetImportLogDetailDto : assetImportLogDetailDtos) { try { assetImportLogDetailDto.setTakeTime(communityDtos.get(0).getTakeTime()); importDatas(assetImportLogDetailDto); updateImportLogDetailState(assetImportLogDetailDto.getDetailId()); } catch (Exception e) { e.printStackTrace(); updateImportLogDetailState(assetImportLogDetailDto.getDetailId(), e); } } } private void importDatas(AssetImportLogDetailDto assetImportLogDetailDto) { List importRoomFees = new ArrayList<>(); List importCarFees = new ArrayList<>(); List importContractFees = new ArrayList<>(); List carInoutPos = new ArrayList<>(); String communityId = assetImportLogDetailDto.getCommunityId(); JSONObject data = JSONObject.parseObject(assetImportLogDetailDto.getContent()); ImportRoomFee importRoomFee = BeanConvertUtil.covertBean(data, ImportRoomFee.class); if (DateUtil.getDateFromStringB(data.getString("chargeStart").split(" ")[0]).getTime() <= DateUtil.getDateFromStringB(assetImportLogDetailDto.getTakeTime().split(" ")[0]).getTime()){ throw new IllegalStateException("该费用为起始时间小于小区接管时间不进行导入"); } if (importRoomFee.getEndTime() != null){ String[] split = importRoomFee.getEndTime().split(" "); importRoomFee.setEndTime(split[0] + " 23:59:59"); } // List roomTypes = Arrays.asList("住宅物业费","商铺物业费","维修收入","维修基金收入","电费及管理费","代收水费","各类押金","租金收入"); List carTypes = Arrays.asList("临时停车费", "业主产权过道停车费", "小业主产权车辆管理费","地下停车费","地面停车费"); List contractTypes = Arrays.asList("垃圾清运费","其他收入","补贴费用","场地使用费","电梯广告(业委会)","快递柜","电梯广告(联讯)","房产中介","非机动车管理费","其他广告"); FeeConfigDto feeConfigDto = new FeeConfigDto(); feeConfigDto.setCommunityId(importRoomFee.getCommunityId()); feeConfigDto.setFeeNameEq(data.getString("secondaryFeeTypeCd")); // feeConfigDto.setFeeTypeCds(new String[]{"630000007","630000017"}); importRoomFee.setInvoiceNo(data.getString("invoiceReceiptNo")); List feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto); if(feeConfigDtos.size() > 0){ for(FeeConfigDto feeConfigDto1 : feeConfigDtos){ if(feeConfigDto1.getIsContractFee() != null && feeConfigDto1.getIsContractFee().equals("true")){ importRoomFee.setObjType("7777"); } } } // if (importRoomFee.getDoorRoomNum() != null && importRoomFee.getDoorRoomNum().split("-").length < 2) { // 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"); carInout.setVehicleType("temp"); carInout.setDirection("entry"); carInout.setState("100300"); carInout.setInTime(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("chargeStart")); carInout.setStatusCd("0"); 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)); carInout.setDetailId(assetImportLogDetailDto.getDetailId()); carInoutPos.add(carInout); // 如果有结束时间,创建新的对象作为出口记录 if(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).containsKey("chargeEnd")){ // 创建新的对象,而不是修改已添加的对象 CarInoutPo exitCarInout = new CarInoutPo(); // 复制基本属性 exitCarInout.setbId(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("batchId")); exitCarInout.setCommunityId(carInout.getCommunityId()); exitCarInout.setCarNum(carInout.getCarNum()); exitCarInout.setVehicleType(carInout.getVehicleType()); exitCarInout.setInTime(carInout.getInTime()); exitCarInout.setStatusCd(carInout.getStatusCd()); exitCarInout.setCreateTime(carInout.getCreateTime()); // 设置出口相关属性 exitCarInout.setOutTime(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("chargeEnd")); exitCarInout.setDirection("exit"); exitCarInout.setState("100400"); exitCarInout.setInoutId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_inoutId)); exitCarInout.setPaymentAmount(JSONObject.parseObject(assetImportLogDetailDto.getContent().toString()).getString("chargeAmount")); exitCarInout.setDetailId(assetImportLogDetailDto.getDetailId()); carInoutPos.add(exitCarInout); } } 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("chargeTime")); importRoomFee.setReceivableAmount(data.getString("bankDepositAmount")); importRoomFee.setAmount(data.getString("chargeAmount")); importRoomFee.setStaffName(data.getString("charger")); importRoomFee.setIsContractFee("O"); importRoomFee.setInvoiceNo(data.containsKey("invoiceReceiptNo") && data.getString("invoiceReceiptNo") != null ? "Y" : "N"); importRoomFee.setObjType("7777"); LocalDateTime startDate = LocalDateTime.parse(importRoomFee.getStartTime(), formatter); LocalDateTime endDate = LocalDateTime.parse(importRoomFee.getEndTime(), formatter); importRoomFee.setCycle(String.valueOf(ChronoUnit.MONTHS.between(startDate, endDate))); if (new BigDecimal(importRoomFee.getAmount()).doubleValue() < 0){ importRoomFee.setCycle("-"+importRoomFee.getCycle()); } // if(importRoomFee.getPayerObjName()) importCarFees.add(importRoomFee); } else if(carTypes.contains(JSONObject.parseObject(assetImportLogDetailDto.getContent()).get("category22"))){ importRoomFee.setCommunityId(communityId); importRoomFee.setFeeName(data.getString("secondaryFeeTypeCd")); importRoomFee.setDetailId(assetImportLogDetailDto.getDetailId()); importRoomFee.setStartTime(data.getString("chargeStart")); importRoomFee.setEndTime(data.getString("chargeEnd").split(" ")[0]+" 23:59:59"); importRoomFee.setCreateTime(data.getString("chargeTime")); importRoomFee.setReceivableAmount(data.getString("bankDepositAmount")); importRoomFee.setAmount(data.getString("chargeAmount")); importRoomFee.setCarNum(data.getString("licensePlate")); importRoomFee.setStaffName(data.getString("charger")); importRoomFee.setOpenInv(data.containsKey("invoiceReceiptNo") && data.getString("invoiceReceiptNo") != null ? "Y" : "N"); // if(importRoomFee.getPayerObjName()) importRoomFee.setObjType("6666"); LocalDateTime startDate = LocalDateTime.parse(importRoomFee.getStartTime(), formatter); LocalDateTime endDate = LocalDateTime.parse(importRoomFee.getEndTime(), formatter); importRoomFee.setCycle(String.valueOf(ChronoUnit.MONTHS.between(startDate, endDate))); if (new BigDecimal(importRoomFee.getAmount()).doubleValue() < 0){ importRoomFee.setCycle("-"+importRoomFee.getCycle()); } importCarFees.add(importRoomFee); } else{ importRoomFee.setCommunityId(communityId); importRoomFee.setFeeName(data.getString("secondaryFeeTypeCd")); importRoomFee.setDetailId(assetImportLogDetailDto.getDetailId()); importRoomFee.setStartTime(data.getString("chargeStart")); importRoomFee.setEndTime(data.getString("chargeEnd").split(" ")[0]+" 23:59:59"); importRoomFee.setCreateTime(data.getString("chargeTime")); importRoomFee.setReceivableAmount(data.getString("bankDepositAmount")); importRoomFee.setAmount(data.getString("chargeAmount")); importRoomFee.setStaffName(data.getString("charger")); importRoomFee.setOpenInv(data.containsKey("invoiceReceiptNo") && data.getString("invoiceReceiptNo") != null ? "Y" : "N"); // if(importRoomFee.getPayerObjName()) importRoomFees.add(importRoomFee); } importFeeDetailsByCarInout(carInoutPos); if (ListUtil.isNull(importRoomFees) && ListUtil.isNull(importCarFees)) { return; } 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()); } catch (Exception e){ throw new IllegalArgumentException("未知错误:"+e); } } public void importCarFeeDetails2(String storeId, String userId, List 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 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()); } } } private void importFeeDetailsByCarInout(List carInoutPos) { for (CarInoutPo carInoutPo : carInoutPos) { try { ArrayList carInoutPos1 = new ArrayList<>(); carInoutPos1.add(carInoutPo); carInoutInnerServiceSMOImpl.batchSaveCarInout2(carInoutPos1); updateImportLogDetailState(carInoutPo.getDetailId()); }catch (Exception e){ updateImportLogDetailState(carInoutPo.getDetailId(),e); throw new IllegalArgumentException(e.getMessage()); } } } private void importFeeDetails(String storeId, String userId, List importRoomFees, String batchId) { 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())) { 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 updateImportLogDetailState(importRoomFee.getDetailId()); } catch (Exception e) { e.printStackTrace(); updateImportLogDetailState(importRoomFee.getDetailId(), e); throw new IllegalArgumentException(e.getMessage()); } } } DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); /** * 导入 费用历史 * * @param importRoomFee */ private void importFeeDetail(ImportRoomFee importRoomFee, String storeId, String userId, String batchId) { 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]); } } List 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 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 contractPartyaDtos = contractPartyaInnerServiceSMOImpl.queryContractPartyas(contractPartyaDto); if (contractPartyaDtos != null && contractPartyaDtos.size() > 0) { ContractDto contractDto = new ContractDto(); contractDto.setCommunityId(importRoomFee.getCommunityId()); contractDto.setContractCode(importRoomFee.getContractId()); List 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()); if (new BigDecimal(importRoomFee.getAmount()).doubleValue() >= 0){ feeDto2.setStatusCd("0"); feeDto2.setUseStart(DateUtil.getDateFromStringA(importRoomFee.getStartTime())); feeDto2.setUseEnd(DateUtil.getDateFromStringA(importRoomFee.getEndTime())); } List feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto2); if (new BigDecimal(importRoomFee.getAmount()).doubleValue() >= 0) { feeDtos.removeIf(feeDto -> "2009001".equals(feeDto.getState())); } if(feeDtos.size() == 0){ updateImportLogDetailState(importRoomFee.getDetailId(),new IllegalArgumentException("费用项"+importRoomFee.getFeeName()+"不存在")); throw new IllegalArgumentException("费用记录"+importRoomFee.getFeeName()+"不存在"); }else if(feeDtos.size() > 1){ throw new IllegalArgumentException("存在多条记录"); } // if (ListUtil.isNull(feeDtos)) { // throw new IllegalArgumentException("查询不到该记录的费用项:"+importRoomFee.getFeeName()); // List feeAttrsPos = new ArrayList<>(); // PayFeePo payFeePo = new PayFeePo(); // payFeePo.setCommunityId(importRoomFee.getCommunityId()); // payFeePo.setConfigId(feeDto.getConfigId()); // payFeePo.setPayerObjType(FeeDto.PAYER_OBJ_TYPE_ROOM); // payFeePo.setStartTime(importRoomFee.getStartTime()); // payFeePo.setEndTime(DateUtil.getNextSecTime(importRoomFee.getEndTime())); // payFeePo.setAmount(importRoomFee.getAmount()); // payFeePo.setFeeFlag(tmpFeeConfigDto.getFeeFlag()); // payFeePo.setFeeTypeCd(tmpFeeConfigDto.getFeeTypeCd()); // payFeePo.setIncomeObjId(storeId); // payFeePo.setBatchId(batchId); // if (FeeDto.FEE_FLAG_ONCE.equals(tmpFeeConfigDto.getFeeFlag())) { // payFeePo.setState(FeeDto.STATE_FINISH); // } else { // payFeePo.setState(FeeDto.STATE_DOING); // } // payFeePo.setFeeId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_feeId)); // payFeePo.setPayerObjId(importRoomFee.getRoomId()); // payFeePo.setUserId(userId); // payFeePo.setCreateTime(importRoomFee.getCreateTime()); // payFeePos = new ArrayList<>(); // payFeePos.add(payFeePo); // feeInnerServiceSMOImpl.saveFee(payFeePos); // // //查询业主信息 // OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto(); // ownerRoomRelDto.setRoomId(importRoomFee.getRoomId()); // List ownerRoomRelDtos = ownerRoomRelV1InnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto); // if (ownerRoomRelDtos != null && ownerRoomRelDtos.size() > 0) { // if (!FeeDto.FEE_FLAG_CYCLE.equals(tmpFeeConfigDto.getFeeFlag())) { // feeAttrsPos.add(addFeeAttr(payFeePo, FeeAttrDto.SPEC_CD_ONCE_FEE_DEADLINE_TIME, // importRoomFee.getEndTime())); // } // feeAttrsPos.add(addFeeAttr(payFeePo, FeeAttrDto.SPEC_CD_OWNER_ID, ownerRoomRelDtos.get(0).getOwnerId())); // feeAttrsPos.add(addFeeAttr(payFeePo, FeeAttrDto.SPEC_CD_OWNER_LINK, ownerRoomRelDtos.get(0).getLink())); // feeAttrsPos.add(addFeeAttr(payFeePo, FeeAttrDto.SPEC_CD_OWNER_NAME, ownerRoomRelDtos.get(0).getOwnerName())); // feeAttrInnerServiceSMOImpl.saveFeeAttrs(feeAttrsPos); // } // // // feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto); // } 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); } } } public FeeAttrPo addFeeAttr(PayFeePo payFeePo, String specCd, String value) { FeeAttrPo feeAttrPo = new FeeAttrPo(); feeAttrPo.setCommunityId(payFeePo.getCommunityId()); feeAttrPo.setSpecCd(specCd); feeAttrPo.setValue(value); feeAttrPo.setFeeId(payFeePo.getFeeId()); feeAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_attrId)); return feeAttrPo; } private void doImportFeeDetail(FeeDto tmpFeeDto, ImportRoomFee importRoomFee) { PayFeeDetailPo payFeeDetailPo = new PayFeeDetailPo(); if(importRoomFee.getInvoiceNo() != null){ payFeeDetailPo.setInvoiceNo(importRoomFee.getInvoiceNo()); payFeeDetailPo.setOpenInvoice("Y"); }else{ payFeeDetailPo.setOpenInvoice("N"); } payFeeDetailPo.setCommunityId(importRoomFee.getCommunityId()); payFeeDetailPo.setReceivedAmount(importRoomFee.getAmount()); payFeeDetailPo.setPrimeRate("1.0"); payFeeDetailPo.setFeeId(tmpFeeDto.getFeeId()); payFeeDetailPo.setStartTime(importRoomFee.getStartTime()); payFeeDetailPo.setRemark(importRoomFee.getRemark()); payFeeDetailPo.setCreateTime(importRoomFee.getCreateTime()); payFeeDetailPo.setState("1400"); payFeeDetailPo.setCashierName(importRoomFee.getStaffName()); payFeeDetailPo.setPayOrderId(importRoomFee.getPayObjId()); payFeeDetailPo.setB("T"); double cycle = (DateUtil.dayCompare( DateUtil.getDateFromStringA(payFeeDetailPo.getStartTime()), DateUtil.getDateFromStringA(importRoomFee.getEndTime()) )); if (new BigDecimal(payFeeDetailPo.getReceivedAmount()).doubleValue() < 0){ cycle = cycle - cycle - cycle; payFeeDetailPo.setState("1300"); } int count = feeDetailInnerServiceSMOImpl.queryFeeDetailsCountByVo(payFeeDetailPo); payFeeDetailPo.setPayableAmount(importRoomFee.getAmount()); payFeeDetailPo.setCycles(importRoomFee.getCycle()); payFeeDetailPo.setCycles(cycle+""); payFeeDetailPo.setEndTime(importRoomFee.getEndTime()); if (count > 0) { throw new IllegalStateException("重复的缴费记录"); } if (new BigDecimal(payFeeDetailPo.getPayableAmount()).doubleValue() < 0) { payFeeDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId)); payFeeDetailPo.setReceivableAmount("-" + computeFeeByCycle(tmpFeeDto,importRoomFee)+""); payFeeDetailPo.setDiscountAmount("0"); payFeeDetailPo.setState("1300"); int saved = feeDetailInnerServiceSMOImpl.saveFeeDetail(payFeeDetailPo); return; } PayFeeDetailDiscountPo payFeeDetailDiscount = new PayFeeDetailDiscountPo(); try { Map feePriceAll = computeFeeSMOImpl.getFeePrice(tmpFeeDto); FeeDto feeDto = new FeeDto(); feeDto.setFeeId(tmpFeeDto.getFeeId()); feeDto.setCommunityId(tmpFeeDto.getCommunityId()); List feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto); payFeeDetailPo.setReceivableAmount(computeFeeByCycle(tmpFeeDto,importRoomFee)+""); ResponseEntity resultVo = feeDiscountApi.computeFeeDiscount(tmpFeeDto.getFeeId(), tmpFeeDto.getCommunityId(), 105, importRoomFee.getPayObjId(), tmpFeeDto.getPayerObjType(), importRoomFee.getEndTime(), importRoomFee.getEndTime(), importRoomFee.getStartTime(), 1, 20); // 2. 从 ResultVo 中获取 data 并强转为目标类型 if (resultVo != null) { // 假设 data 字段存储的是 List JSONArray data = (JSONArray) JSONObject.parseObject(resultVo.getBody()).get("data"); if(data.size() > 0) { JSONObject o = (JSONObject) data.get(0); String discountPrice = o.get("discountPrice").toString(); String discountId = o.get("discountId").toString(); payFeeDetailPo.setDiscountAmount(discountPrice); payFeeDetailDiscount.setDiscountId(discountId); payFeeDetailDiscount.setDiscountPrice(discountPrice); }else{ } } } catch (ParseException e) { throw new RuntimeException(e.getMessage()); } payFeeDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId)); int saved = feeDetailInnerServiceSMOImpl.saveFeeDetail(payFeeDetailPo); FeeDetailDto feeDetailDto = new FeeDetailDto(); feeDetailDto.setDetailId(payFeeDetailPo.getDetailId()); List feeDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto); if (payFeeDetailDiscount.getDiscountId() != null) { payFeeDetailDiscount.setDetailId(payFeeDetailPo.getDetailId()); payFeeDetailDiscount.setStatusCd("0"); payFeeDetailDiscount.setCommunityId(feeDtos.get(0).getCommunityId()); payFeeDetailDiscount.setFeeId(feeDtos.get(0).getFeeId()); payFeeDetailDiscount.setDetailDiscountId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_discountId)); payFeeDetailDiscountNewV1InnerServiceSMOImpl.savePayFeeDetailDiscountNew(payFeeDetailDiscount); } if (saved < 1) { return; } FeeDto fee = new FeeDto(); fee.setFeeId(tmpFeeDto.getFeeId()); FeeDto feeInfo = feeInnerServiceSMOImpl.queryFees(fee).get(0); // int i = feeInnerServiceSMOImpl.updateFee(feeInfo); if (tmpFeeDto.getEndTime().getTime() >= DateUtil.getDateFromStringA(importRoomFee.getEndTime()).getTime() + 2000) { return; } //如果结束时间小于 缴费结束时间则延期 PayFeePo payFeePo = new PayFeePo(); payFeePo.setCommunityId(importRoomFee.getCommunityId()); payFeePo.setStatusCd(StatusConstant.STATUS_CD_VALID); payFeePo.setFeeId(tmpFeeDto.getFeeId()); 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 (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 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 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 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())); } }