| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | |
| | |
| | | @Override |
| | | public Date getFeeEndTime() { |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 计算实时欠费金额 |
| | | * |
| | | * @param tmpFeeDto |
| | | */ |
| | | public void computeEveryOweFee(FeeDto tmpFeeDto) { |
| | | |
| | | computeFeePrice(tmpFeeDto); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | feeDto.setDeadlineTime(targetEndDate); |
| | | |
| | | //动态费用 |
| | | if ("4004".equals(computingFormula)) { |
| | | if ("4004".equals(computingFormula) && !FeeDto.STATE_FINISH.equals(feeDto.getState())) { |
| | | feeDto.setAmountOwed(feeDto.getFeePrice() + ""); |
| | | feeDto.setDeadlineTime(DateUtil.getCurrentDate()); |
| | | //feeDto.setDeadlineTime(DateUtil.getCurrentDate()); 欠费日期不对先注释 |
| | | } |
| | | |
| | | } |
| | |
| | | Map<String, Object> targetEndDateAndOweMonth = getTargetEndDateAndOweMonth(feeDto); |
| | | Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate"); |
| | | double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth"); |
| | | RoomDto roomDto = new RoomDto(); |
| | | roomDto.setCommunityId(feeDto.getCommunityId()); |
| | | roomDto.setRoomId(feeDto.getPayerObjId()); |
| | | List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto); |
| | | |
| | | if (roomDtos == null || roomDtos.size() < 1) { //数据有问题 |
| | | return; |
| | | } |
| | | // RoomDto roomDto = new RoomDto(); |
| | | // roomDto.setCommunityId(feeDto.getCommunityId()); |
| | | // roomDto.setRoomId(feeDto.getPayerObjId()); |
| | | // List<RoomDto> roomDtos = feeDto.getCacheRooms(); |
| | | // if(roomDtos == null || roomDtos.size() < 1) { |
| | | // roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto); |
| | | // } |
| | | // |
| | | // if (roomDtos == null || roomDtos.size() < 1) { //数据有问题 |
| | | // return; |
| | | // } |
| | | |
| | | String computingFormula = feeDto.getComputingFormula(); |
| | | double feePrice = getFeePrice(feeDto); |
| | |
| | | feeDto.setDeadlineTime(targetEndDate); |
| | | |
| | | //动态费用 |
| | | if ("4004".equals(computingFormula)) { |
| | | if ("4004".equals(computingFormula) && !FeeDto.STATE_FINISH.equals(feeDto.getState())) { |
| | | feeDto.setAmountOwed(feeDto.getFeePrice() + ""); |
| | | feeDto.setDeadlineTime(DateUtil.getCurrentDate()); |
| | | //feeDto.setDeadlineTime(DateUtil.getCurrentDate()); 欠费日期不对先注释 |
| | | } |
| | | } |
| | | |
| | |
| | | return objName; |
| | | } |
| | | roomDto = roomDtos.get(0); |
| | | objName = roomDto.getFloorNum() + "栋" + roomDto.getUnitNum() + "单元" + roomDto.getRoomNum() + "室"; |
| | | if (RoomDto.ROOM_TYPE_ROOM.equals(roomDto.getRoomType())) { |
| | | objName = roomDto.getFloorNum() + "栋" + roomDto.getUnitNum() + "单元" + roomDto.getRoomNum() + "室"; |
| | | } else { |
| | | objName = roomDto.getFloorNum() + "栋" + roomDto.getRoomNum() + "室"; |
| | | } |
| | | } else if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDto.getPayerObjType())) {//车位相关 |
| | | |
| | | OwnerCarDto ownerCarDto = new OwnerCarDto(); |
| | |
| | | Calendar endCalender = Calendar.getInstance(); |
| | | endCalender.setTime(endTime); |
| | | endCalender.add(Calendar.MONTH, new Double(Math.floor(cycle)).intValue()); |
| | | int hours = new Double((cycle - Math.floor(cycle)) * DateUtil.getCurrentMonthDay() * 24).intValue(); |
| | | // Calendar futureDate = Calendar.getInstance(); |
| | | // futureDate.setTime(endCalender.getTime()); |
| | | // futureDate.add(Calendar.MONTH, 1); |
| | | int futureDay = endCalender.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | int hours = new Double((cycle - Math.floor(cycle)) * futureDay * 24).intValue(); |
| | | endCalender.add(Calendar.HOUR, hours); |
| | | if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) { |
| | | return FeeDto.STATE_FINISH; |
| | |
| | | Calendar endCalender = Calendar.getInstance(); |
| | | endCalender.setTime(endTime); |
| | | endCalender.add(Calendar.MONTH, new Double(Math.floor(cycle)).intValue()); |
| | | int hours = new Double((cycle - Math.floor(cycle)) * DateUtil.getCurrentMonthDay() * 24).intValue(); |
| | | // Calendar futureDate = Calendar.getInstance(); |
| | | // futureDate.setTime(endCalender.getTime()); |
| | | // futureDate.add(Calendar.MONTH, 1); |
| | | int futureDay = endCalender.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | int hours = new Double((cycle - Math.floor(cycle)) * futureDay * 24).intValue(); |
| | | endCalender.add(Calendar.HOUR, hours); |
| | | if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) { |
| | | if (!StringUtil.isEmpty(feeDto.getCurDegrees())) { |
| | |
| | | BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice())); |
| | | BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDtos.get(0).getBuiltUpArea())); |
| | | BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount())); |
| | | feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(3, BigDecimal.ROUND_HALF_EVEN); |
| | | } else if ("2002".equals(computingFormula)) { // 固定费用 |
| | | //feePrice = Double.parseDouble(feeDto.getAdditionalAmount()); |
| | | BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount())); |
| | | feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } else if ("4004".equals(computingFormula)) { |
| | | feePrice = additionalAmount.setScale(3, BigDecimal.ROUND_HALF_EVEN); |
| | | } else if ("4004".equals(computingFormula)) { //动态费用 |
| | | feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount())); |
| | | } else if ("5005".equals(computingFormula)) { |
| | | } else if ("5005".equals(computingFormula)) { //(本期度数-上期度数)*单价+附加费 |
| | | if (StringUtil.isEmpty(feeDto.getCurDegrees())) { |
| | | //throw new IllegalArgumentException("抄表数据异常"); |
| | | } else { |
| | |
| | | throw new IllegalArgumentException("暂不支持该类公式"); |
| | | } |
| | | } |
| | | return feePrice.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | return feePrice.setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | } |
| | | |
| | | public Map getTargetEndDateAndOweMonth(FeeDto feeDto, OwnerCarDto ownerCarDto) { |
| | |
| | | |
| | | @Override |
| | | public double dayCompare(Date fromDate, Date toDate) { |
| | | double resMonth = 0.0; |
| | | Calendar from = Calendar.getInstance(); |
| | | from.setTime(fromDate); |
| | | Calendar to = Calendar.getInstance(); |
| | |
| | | Calendar newFrom = Calendar.getInstance(); |
| | | newFrom.setTime(fromDate); |
| | | newFrom.add(Calendar.MONTH, result); |
| | | //如果加月份后 大于了到期时间 默认加 月份 -1 情况 12-19 21-01-10 |
| | | if (newFrom.getTime().getTime() > toDate.getTime()) { |
| | | newFrom.setTime(fromDate); |
| | | result = result - 1; |
| | | newFrom.add(Calendar.MONTH, result); |
| | | } |
| | | |
| | | long t1 = newFrom.getTimeInMillis(); |
| | | long t2 = to.getTimeInMillis(); |
| | | double days = (t2 - t1)*1.00 / (24 * 60 * 60 * 1000); |
| | | |
| | | long t1 = newFrom.getTime().getTime(); |
| | | long t2 = to.getTime().getTime(); |
| | | double days = (t2 - t1) * 1.00 / (24 * 60 * 60 * 1000); |
| | | BigDecimal tmpDays = new BigDecimal(days); |
| | | BigDecimal monthDay = new BigDecimal(30); |
| | | BigDecimal monthDay = null; |
| | | Calendar newFromMaxDay = Calendar.getInstance(); |
| | | newFromMaxDay.set(newFrom.get(Calendar.YEAR), newFrom.get(Calendar.MONTH), 1, 0, 0, 0); |
| | | newFromMaxDay.add(Calendar.MONTH, 1); |
| | | //在当前月中 |
| | | if (toDate.getTime() < newFromMaxDay.getTime().getTime()) { |
| | | monthDay = new BigDecimal(newFromMaxDay.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | return tmpDays.divide(monthDay, 2, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).doubleValue(); |
| | | } |
| | | // 上月天数 |
| | | days = (newFromMaxDay.getTimeInMillis() - t1) * 1.00 / (24 * 60 * 60 * 1000); |
| | | tmpDays = new BigDecimal(days); |
| | | monthDay = new BigDecimal(newFrom.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | BigDecimal preRresMonth = tmpDays.divide(monthDay, 2, BigDecimal.ROUND_HALF_UP); |
| | | |
| | | return tmpDays.divide(monthDay,2, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).doubleValue(); |
| | | //下月天数 |
| | | days = (t2 - newFromMaxDay.getTimeInMillis()) * 1.00 / (24 * 60 * 60 * 1000); |
| | | tmpDays = new BigDecimal(days); |
| | | monthDay = new BigDecimal(newFromMaxDay.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | resMonth = tmpDays.divide(monthDay, 2, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).add(preRresMonth).doubleValue(); |
| | | return resMonth; |
| | | } |
| | | |
| | | @Override |
| | | public Date getTargetEndTime(double month, Date startDate) { |
| | | Calendar endDate = Calendar.getInstance(); |
| | | endDate.setTime(startDate); |
| | | endDate.add(Calendar.MONTH, (int) month); |
| | | |
| | | Double intMonth = Math.floor(month); |
| | | endDate.add(Calendar.MONTH, intMonth.intValue()); |
| | | double doubleMonth = month - intMonth; |
| | | if (doubleMonth <= 0) { |
| | | return endDate.getTime(); |
| | | } |
| | | // Calendar futureDate = Calendar.getInstance(); |
| | | // futureDate.setTime(endDate.getTime()); |
| | | // futureDate.add(Calendar.MONTH, 1); |
| | | int futureDay = endDate.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | Double hour = doubleMonth * futureDay * 24; |
| | | endDate.add(Calendar.HOUR_OF_DAY, hour.intValue()); |
| | | return endDate.getTime(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | ComputeFeeSMOImpl computeFeeSMO = new ComputeFeeSMOImpl(); |
| | | try { |
| | | double month = computeFeeSMO.dayCompare( |
| | | |
| | | DateUtil.getDateFromString("2020-12-19 00:00:00", DateUtil.DATE_FORMATE_STRING_A), |
| | | DateUtil.getDateFromString("2021-1-10 00:00:00", DateUtil.DATE_FORMATE_STRING_A) |
| | | ); |
| | | |
| | | System.out.println(month); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // public static void main(String[] args) { |
| | | // ComputeFeeSMOImpl computeFeeSMO = new ComputeFeeSMOImpl(); |
| | | // try { |
| | | // Date startTime = DateUtil.getDateFromString("2020-12-31 00:00:00", DateUtil.DATE_FORMATE_STRING_A); |
| | | // Date endTime = DateUtil.getDateFromString("2021-1-2 00:00:00", DateUtil.DATE_FORMATE_STRING_A); |
| | | // double day = (endTime.getTime() - startTime.getTime()) * 1.00 / (24 * 60 * 60 * 1000); |
| | | // |
| | | // System.out.println(day); |
| | | // |
| | | // } catch (ParseException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | } |