|
|
@@ -2,25 +2,34 @@ package com.zksy.property.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.zksy.property.domain.AContractInfo;
|
|
|
-import com.zksy.property.domain.AHouseInfoDetail;
|
|
|
-import com.zksy.property.domain.ASimplifiedHouseInfo;
|
|
|
-import com.zksy.property.domain.ATenantInfo;
|
|
|
+import com.zksy.property.domain.*;
|
|
|
import com.zksy.property.domain.bo.*;
|
|
|
import com.zksy.property.domain.dto.ContractFormDTO;
|
|
|
+import com.zksy.property.domain.dto.ReceiptDto;
|
|
|
+import com.zksy.property.domain.dto.ReturnReceiptDto;
|
|
|
+import com.zksy.property.domain.vo.CanBeGetReceiptVo;
|
|
|
+import com.zksy.property.domain.vo.CanBeGetReturnReceiptVo;
|
|
|
import com.zksy.property.factory.ContractFactory;
|
|
|
import com.zksy.property.mapper.AContractInfoMapper;
|
|
|
import com.zksy.property.service.*;
|
|
|
+import com.zksy.service.MinioFileStorageService;
|
|
|
+import com.zksy.utils.exception.BusinessException;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static com.zksy.utils.util.generateAssetNumber;
|
|
|
@@ -33,6 +42,16 @@ import static com.zksy.utils.util.generateAssetNumber;
|
|
|
@Service
|
|
|
public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, AContractInfo>
|
|
|
implements AContractInfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MinioFileStorageService minioFileStorageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AReceiptInfoService aReceiptInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ARefundService aRefundService;
|
|
|
+
|
|
|
@Override
|
|
|
public String returnRent(String houseId) {
|
|
|
ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(houseId);
|
|
|
@@ -55,6 +74,152 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
|
|
|
return "退租成功";
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @SneakyThrows
|
|
|
+ public String uploadSignContract(String contractId, MultipartFile file) {
|
|
|
+ AContractInfo contractInfo = this.getById(contractId);
|
|
|
+ if (contractInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(contractInfo.getSignContractUrl())){
|
|
|
+ minioFileStorageService.deleteFile(contractInfo.getSignContractUrl());
|
|
|
+ }
|
|
|
+ String path = minioFileStorageService.uploadFile(file, "合同");
|
|
|
+ contractInfo.setSignContractUrl(path);
|
|
|
+ contractInfo.setUpdateTime(LocalDateTime.now());
|
|
|
+ return this.updateById(contractInfo) ? "上传成功" : "上传失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getReceipt(String contractId, ReceiptDto dto) {
|
|
|
+ LambdaQueryWrapper<AReceiptInfo> aReceiptInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ aReceiptInfoLambdaQueryWrapper.eq(AReceiptInfo::getContractId,contractId);
|
|
|
+ var res = aReceiptInfoService.getOne(aReceiptInfoLambdaQueryWrapper);
|
|
|
+ if(res != null){
|
|
|
+ throw new BusinessException(999,"此合同已生成收据",res.getAttachmentUrl());
|
|
|
+ }
|
|
|
+ AContractInfo contractInfo = this.getById(contractId);
|
|
|
+ if (contractInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
|
|
|
+ if(houseInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ String receiptNumber = generateAssetNumber();
|
|
|
+ RentalTempBo bo = new RentalTempBo();
|
|
|
+
|
|
|
+ bo.setD1(dto.getPaymentUnit());
|
|
|
+ bo.setD2(dto.getPaymentMethod());
|
|
|
+ bo.setD3(convertToUppercase(dto.getRmb()));
|
|
|
+ bo.setD4(String.valueOf(dto.getRmb()));
|
|
|
+ bo.setD5(String.valueOf(dto.getZj()));
|
|
|
+ bo.setD6(String.valueOf(dto.getWyf()));
|
|
|
+ bo.setD7(String.valueOf(dto.getYj()));
|
|
|
+ bo.setD8(String.valueOf(dto.getSf()));
|
|
|
+ bo.setD9(dto.getPaymentReason());
|
|
|
+ bo.setD10(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
|
|
|
+ bo.setD11("");
|
|
|
+ bo.setD12(receiptNumber);
|
|
|
+
|
|
|
+ String attachmentUrl = aRentalContractService.generatorRental("4", bo, true);
|
|
|
+ AReceiptInfo receiptInfo = new AReceiptInfo();
|
|
|
+ receiptInfo.setContractId(contractId);
|
|
|
+ receiptInfo.setReceiptNumber(receiptNumber);
|
|
|
+ receiptInfo.setPayer(dto.getPaymentUnit());
|
|
|
+ receiptInfo.setPaymentMethod(dto.getPaymentMethod());
|
|
|
+ receiptInfo.setTotalAmount(dto.getRmb());
|
|
|
+ receiptInfo.setRent(dto.getZj());
|
|
|
+ receiptInfo.setPropertyFee(dto.getWyf());
|
|
|
+ receiptInfo.setDeposit(dto.getYj());
|
|
|
+ receiptInfo.setWaterFee(dto.getSf());
|
|
|
+ receiptInfo.setReceiptReason(dto.getPaymentReason());
|
|
|
+ receiptInfo.setAttachmentUrl(attachmentUrl);
|
|
|
+ receiptInfo.setGenerationDate(LocalDate.now());
|
|
|
+ receiptInfo.setCreateTime(LocalDateTime.now());
|
|
|
+ receiptInfo.setUpdateTime(LocalDateTime.now());
|
|
|
+ aReceiptInfoService.save(receiptInfo);
|
|
|
+ return attachmentUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CanBeGetReceiptVo canBeDetReceiptData(String contractId) {
|
|
|
+ AContractInfo contractInfo = this.getById(contractId);
|
|
|
+ if (contractInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
|
|
|
+ if (houseInfo == null) {
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ CanBeGetReceiptVo vo = new CanBeGetReceiptVo();
|
|
|
+ vo.setJkdw(houseInfo.getHouseName());
|
|
|
+ vo.setZj(houseInfo.getRentRange());
|
|
|
+ vo.setYj(contractInfo.getContractDeposit());
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CanBeGetReturnReceiptVo canBeDetReturnReceiptData(String contractId) {
|
|
|
+ AContractInfo contractInfo = this.getById(contractId);
|
|
|
+ if (contractInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
|
|
|
+ if (houseInfo == null) {
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ return new CanBeGetReturnReceiptVo(
|
|
|
+ houseInfo.getHouseName(),
|
|
|
+ contractInfo.getContractDeposit()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getReturnReceipt(String contractId, ReturnReceiptDto dto) {
|
|
|
+ LambdaQueryWrapper<ARefund> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ARefund::getContractId,contractId);
|
|
|
+ var res = aRefundService.getOne(queryWrapper);
|
|
|
+ if(res != null){
|
|
|
+ throw new BusinessException(999,"此合同已生成退据",res.getAttachmentUrl());
|
|
|
+ }
|
|
|
+ AContractInfo contractInfo = this.getById(contractId);
|
|
|
+ if (contractInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+ ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
|
|
|
+ if(houseInfo == null){
|
|
|
+ throw new RuntimeException("数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ RentalTempBo bo = new RentalTempBo();
|
|
|
+ bo.setE1(dto.getDw());
|
|
|
+ bo.setE2(dto.getZh());
|
|
|
+ bo.setE3(String.valueOf(dto.getYj()));
|
|
|
+ bo.setE4(String.valueOf(dto.getYj()));
|
|
|
+ bo.setE5(String.valueOf(dto.getWyf()));
|
|
|
+ bo.setE6(convertToUppercase(dto.getRmb()));
|
|
|
+ bo.setE7(String.valueOf(dto.getRmb()));
|
|
|
+ bo.setE8(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
|
|
|
+
|
|
|
+ String attachmentUrl = aRentalContractService.generatorRental("5", bo, true);
|
|
|
+ ARefund refund = new ARefund();
|
|
|
+ refund.setContractId(contractId);
|
|
|
+ refund.setUnit(dto.getDw());
|
|
|
+ refund.setTenant(dto.getZh());
|
|
|
+ refund.setDeposit(dto.getYj());
|
|
|
+ refund.setRent(dto.getZj());
|
|
|
+ refund.setPropertyFee(dto.getWyf());
|
|
|
+ refund.setTotalAmount(dto.getRmb());
|
|
|
+ refund.setAttachmentUrl(attachmentUrl);
|
|
|
+ refund.setGenerationDate(LocalDate.now());
|
|
|
+ refund.setCreateTime(LocalDateTime.now());
|
|
|
+ refund.setUpdateTime(LocalDateTime.now());
|
|
|
+ aRefundService.save(refund);
|
|
|
+ return attachmentUrl;
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private ASimplifiedHouseInfoService aSimplifiedHouseInfoService;
|
|
|
@@ -330,21 +495,25 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
|
|
|
// 添加负号前缀
|
|
|
return isNegative ? "负" + result : result;
|
|
|
}
|
|
|
+ public static String convertToUppercase(BigDecimal number) {
|
|
|
+ if (number == null) {
|
|
|
+ return "零元整";
|
|
|
+ }
|
|
|
|
|
|
- // 数字转中文大写的主方法
|
|
|
- public static String convertToUppercase(double number) {
|
|
|
- if (number < 0) {
|
|
|
- return "负" + convertToUppercase(-number);
|
|
|
+ if (number.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ return "负" + convertToUppercase(number.abs());
|
|
|
}
|
|
|
|
|
|
String[] units = {"", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆"};
|
|
|
String[] digits = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
|
|
|
|
|
|
- long integerPart = (long) number;
|
|
|
- long decimalPart = Math.round((number - integerPart) * 100);
|
|
|
+ // 分离整数部分和小数部分
|
|
|
+ BigDecimal roundedNumber = number.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigInteger integerPart = roundedNumber.toBigInteger();
|
|
|
+ int decimalPart = roundedNumber.remainder(BigDecimal.ONE).multiply(BigDecimal.valueOf(100)).intValue();
|
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
- String integerStr = String.valueOf(integerPart);
|
|
|
+ String integerStr = integerPart.toString();
|
|
|
|
|
|
// 处理整数部分
|
|
|
boolean zeroFlag = false;
|
|
|
@@ -355,8 +524,18 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
|
|
|
if (digit == 0) {
|
|
|
zeroFlag = true;
|
|
|
// 处理单位:万、亿、兆
|
|
|
- if (unitIndex % 4 == 0) {
|
|
|
- result.append(units[unitIndex]);
|
|
|
+ if (unitIndex % 4 == 0 && unitIndex > 0) {
|
|
|
+ // 检查是否需要添加单位
|
|
|
+ boolean needUnit = false;
|
|
|
+ for (int j = i + 1; j < Math.min(i + 5, integerStr.length()); j++) {
|
|
|
+ if (integerStr.charAt(j) != '0') {
|
|
|
+ needUnit = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!needUnit) {
|
|
|
+ result.append(units[unitIndex]);
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
if (zeroFlag) {
|
|
|
@@ -374,22 +553,31 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
|
|
|
result.append("元");
|
|
|
|
|
|
// 处理小数部分
|
|
|
- long jiao = decimalPart / 10;
|
|
|
- long fen = decimalPart % 10;
|
|
|
+ int jiao = decimalPart / 10;
|
|
|
+ int fen = decimalPart % 10;
|
|
|
|
|
|
if (jiao == 0 && fen == 0) {
|
|
|
result.append("整");
|
|
|
} else {
|
|
|
if (jiao != 0) {
|
|
|
- result.append(digits[(int) jiao]).append("角");
|
|
|
+ result.append(digits[jiao]).append("角");
|
|
|
}
|
|
|
if (fen != 0) {
|
|
|
- result.append(digits[(int) fen]).append("分");
|
|
|
+ result.append(digits[fen]).append("分");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result.toString();
|
|
|
}
|
|
|
+
|
|
|
+ public static String convertToUppercase(double number) {
|
|
|
+ return convertToUppercase(BigDecimal.valueOf(number));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|