AContractInfoServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package com.zksy.property.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.zksy.property.domain.*;
  8. import com.zksy.property.domain.bo.*;
  9. import com.zksy.property.domain.dto.ContractFormDTO;
  10. import com.zksy.property.domain.dto.ReceiptDto;
  11. import com.zksy.property.domain.dto.ReturnReceiptDto;
  12. import com.zksy.property.domain.vo.CanBeGetReceiptVo;
  13. import com.zksy.property.domain.vo.CanBeGetReturnReceiptVo;
  14. import com.zksy.property.factory.ContractFactory;
  15. import com.zksy.property.mapper.AContractInfoMapper;
  16. import com.zksy.property.service.*;
  17. import com.zksy.service.MinioFileStorageService;
  18. import com.zksy.utils.exception.BusinessException;
  19. import lombok.SneakyThrows;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.context.annotation.Lazy;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import java.math.BigDecimal;
  26. import java.math.BigInteger;
  27. import java.math.RoundingMode;
  28. import java.time.LocalDate;
  29. import java.time.LocalDateTime;
  30. import java.time.format.DateTimeFormatter;
  31. import java.util.List;
  32. import static com.zksy.utils.util.generateAssetNumber;
  33. /**
  34. * @author Administrator
  35. * @description 针对表【a_contract_info(合同信息表)】的数据库操作Service实现
  36. * @createDate 2025-07-14 11:59:44
  37. */
  38. @Service
  39. public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, AContractInfo>
  40. implements AContractInfoService {
  41. @Autowired
  42. private MinioFileStorageService minioFileStorageService;
  43. @Autowired
  44. private AReceiptInfoService aReceiptInfoService;
  45. @Autowired
  46. private ARefundService aRefundService;
  47. @Override
  48. public String returnRent(String houseId) {
  49. ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(houseId);
  50. if(houseInfo.getStatus().equals("空闲")){
  51. throw new RuntimeException("此房屋未出租");
  52. }
  53. AContractInfo contractInfo = this.getBySimplifiedHouseId(houseId);
  54. if(contractInfo == null){
  55. throw new RuntimeException("数据不存在");
  56. }
  57. houseInfo.setStatus("空闲");
  58. //删除租户信息
  59. ATenantInfo tenantInfo = aTenantInfoService.getBySimplifiedHouseId(houseId);
  60. if(tenantInfo != null){
  61. aTenantInfoService.removeById(tenantInfo);
  62. }
  63. aSimplifiedHouseInfoService.updateById(houseInfo);
  64. contractInfo.setContractStatus("已退租");
  65. this.updateById(contractInfo);
  66. return "退租成功";
  67. }
  68. @Override
  69. @SneakyThrows
  70. public String uploadSignContract(String contractId, MultipartFile file) {
  71. AContractInfo contractInfo = this.getById(contractId);
  72. if (contractInfo == null){
  73. throw new RuntimeException("数据不存在");
  74. }
  75. if(StringUtils.isNotBlank(contractInfo.getSignContractUrl())){
  76. minioFileStorageService.deleteFile(contractInfo.getSignContractUrl());
  77. }
  78. String path = minioFileStorageService.uploadFile(file, "合同");
  79. contractInfo.setSignContractUrl(path);
  80. contractInfo.setUpdateTime(LocalDateTime.now());
  81. return this.updateById(contractInfo) ? "上传成功" : "上传失败";
  82. }
  83. @Override
  84. public String getReceipt(String contractId, ReceiptDto dto) {
  85. LambdaQueryWrapper<AReceiptInfo> aReceiptInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
  86. aReceiptInfoLambdaQueryWrapper.eq(AReceiptInfo::getContractId,contractId);
  87. var res = aReceiptInfoService.getOne(aReceiptInfoLambdaQueryWrapper);
  88. if(res != null){
  89. throw new BusinessException(999,"此合同已生成收据",res.getAttachmentUrl());
  90. }
  91. AContractInfo contractInfo = this.getById(contractId);
  92. if (contractInfo == null){
  93. throw new RuntimeException("数据不存在");
  94. }
  95. ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
  96. if(houseInfo == null){
  97. throw new RuntimeException("数据不存在");
  98. }
  99. String receiptNumber = generateAssetNumber();
  100. RentalTempBo bo = new RentalTempBo();
  101. bo.setD1(dto.getPaymentUnit());
  102. bo.setD2(dto.getPaymentMethod());
  103. bo.setD3(convertToUppercase(dto.getRmb()));
  104. bo.setD4(String.valueOf(dto.getRmb()));
  105. bo.setD5(String.valueOf(dto.getZj()));
  106. bo.setD6(String.valueOf(dto.getWyf()));
  107. bo.setD7(String.valueOf(dto.getYj()));
  108. bo.setD8(String.valueOf(dto.getSf()));
  109. bo.setD9(dto.getPaymentReason());
  110. bo.setD10(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
  111. bo.setD11(dto.getOperator());
  112. bo.setD12(receiptNumber);
  113. DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  114. DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy年M月d日");
  115. LocalDate rzrqDate = LocalDate.parse(dto.getRzrq(), inputFormatter);
  116. bo.setD13(rzrqDate.format(outputFormatter));
  117. bo.setD14(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
  118. bo.setD15(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
  119. String attachmentUrl = aRentalContractService.generatorRental("4", bo, true);
  120. AReceiptInfo receiptInfo = new AReceiptInfo();
  121. receiptInfo.setContractId(contractId);
  122. receiptInfo.setReceiptNumber(receiptNumber);
  123. receiptInfo.setPayer(dto.getPaymentUnit());
  124. receiptInfo.setPaymentMethod(dto.getPaymentMethod());
  125. receiptInfo.setTotalAmount(dto.getRmb());
  126. receiptInfo.setRent(dto.getZj());
  127. receiptInfo.setPropertyFee(dto.getWyf());
  128. receiptInfo.setDeposit(dto.getYj());
  129. receiptInfo.setWaterFee(dto.getSf());
  130. receiptInfo.setAccountingDate(LocalDate.parse(dto.getRzrq()));
  131. receiptInfo.setReceiptReason(dto.getPaymentReason());
  132. receiptInfo.setAttachmentUrl(attachmentUrl);
  133. receiptInfo.setGenerationDate(LocalDate.now());
  134. receiptInfo.setStartDate(LocalDate.parse(dto.getStartDate()));
  135. receiptInfo.setEndDate(LocalDate.parse(dto.getEndDate()));
  136. receiptInfo.setCreateTime(LocalDateTime.now());
  137. receiptInfo.setUpdateTime(LocalDateTime.now());
  138. aReceiptInfoService.save(receiptInfo);
  139. return attachmentUrl;
  140. }
  141. @Override
  142. public CanBeGetReceiptVo canBeDetReceiptData(String contractId) {
  143. AContractInfo contractInfo = this.getById(contractId);
  144. if (contractInfo == null){
  145. throw new RuntimeException("数据不存在");
  146. }
  147. ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
  148. if (houseInfo == null) {
  149. throw new RuntimeException("数据不存在");
  150. }
  151. CanBeGetReceiptVo vo = new CanBeGetReceiptVo();
  152. vo.setJkdw(houseInfo.getHouseName());
  153. vo.setZj(houseInfo.getRentRange());
  154. vo.setYj(contractInfo.getContractDeposit());
  155. return vo;
  156. }
  157. @Override
  158. public CanBeGetReturnReceiptVo canBeDetReturnReceiptData(String contractId) {
  159. AContractInfo contractInfo = this.getById(contractId);
  160. if (contractInfo == null){
  161. throw new RuntimeException("数据不存在");
  162. }
  163. ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
  164. if (houseInfo == null) {
  165. throw new RuntimeException("数据不存在");
  166. }
  167. return new CanBeGetReturnReceiptVo(
  168. houseInfo.getHouseName(),
  169. contractInfo.getContractDeposit()
  170. );
  171. }
  172. @Override
  173. public String getReturnReceipt(String contractId, ReturnReceiptDto dto) {
  174. LambdaQueryWrapper<ARefund> queryWrapper = new LambdaQueryWrapper<>();
  175. queryWrapper.eq(ARefund::getContractId,contractId);
  176. var res = aRefundService.getOne(queryWrapper);
  177. if(res != null){
  178. throw new BusinessException(999,"此合同已生成退据",res.getAttachmentUrl());
  179. }
  180. AContractInfo contractInfo = this.getById(contractId);
  181. if (contractInfo == null){
  182. throw new RuntimeException("数据不存在");
  183. }
  184. ASimplifiedHouseInfo houseInfo = aSimplifiedHouseInfoService.getById(contractInfo.getSimplifiedHouseId());
  185. if(houseInfo == null){
  186. throw new RuntimeException("数据不存在");
  187. }
  188. RentalTempBo bo = new RentalTempBo();
  189. bo.setE1(dto.getDw());
  190. bo.setE2(dto.getZh());
  191. bo.setE3(String.valueOf(dto.getYj()));
  192. bo.setE4(String.valueOf(dto.getYj()));
  193. bo.setE5(String.valueOf(dto.getWyf()));
  194. bo.setE6(convertToUppercase(dto.getRmb()));
  195. bo.setE7(String.valueOf(dto.getRmb()));
  196. bo.setE8(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
  197. String attachmentUrl = aRentalContractService.generatorRental("5", bo, true);
  198. ARefund refund = new ARefund();
  199. refund.setContractId(contractId);
  200. refund.setUnit(dto.getDw());
  201. refund.setTenant(dto.getZh());
  202. refund.setDeposit(dto.getYj());
  203. refund.setRent(dto.getZj());
  204. refund.setPropertyFee(dto.getWyf());
  205. refund.setTotalAmount(dto.getRmb());
  206. refund.setAttachmentUrl(attachmentUrl);
  207. refund.setGenerationDate(LocalDate.now());
  208. refund.setCreateTime(LocalDateTime.now());
  209. refund.setUpdateTime(LocalDateTime.now());
  210. aRefundService.save(refund);
  211. return attachmentUrl;
  212. }
  213. @Autowired
  214. @Lazy
  215. private ASimplifiedHouseInfoService aSimplifiedHouseInfoService;
  216. @Autowired
  217. private ATenantInfoService aTenantInfoService;
  218. @Override
  219. public Page<AContractInfo> findByPage(long pageNum, long pageSize, String contractNumber, String contractDate, String contractStatus) {
  220. Page<AContractInfo> page = new Page<>(pageNum, pageSize);
  221. LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
  222. queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
  223. queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
  224. queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
  225. queryWrapper.orderByDesc(AContractInfo::getUpdateTime);
  226. Page<AContractInfo> page1 = this.page(page, queryWrapper);
  227. return page1;
  228. }
  229. @Override
  230. public List<AContractInfo> getAContractInfoList(String contractNumber, String contractDate, String contractStatus) {
  231. LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
  232. queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
  233. queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
  234. queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
  235. List<AContractInfo> list = this.list(queryWrapper);
  236. return list;
  237. }
  238. @Override
  239. public AContractInfo getBySimplifiedHouseId(String simplifiedHouseId) {
  240. LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper<>();
  241. queryWrapper.eq(AContractInfo::getSimplifiedHouseId, simplifiedHouseId);
  242. queryWrapper.eq(AContractInfo::getContractStatus, "有效");
  243. return this.getOne(queryWrapper);
  244. }
  245. @Autowired
  246. private AHouseInfoDetailService aHouseInfoDetailService;
  247. @Override
  248. @Transactional
  249. public String signContract(ContractFormDTO dto) {
  250. AHouseInfoDetail houseInfoDetail = aHouseInfoDetailService.getBySimplifiedHouseId(dto.getHouseId());
  251. ASimplifiedHouseInfo aSimplifiedHouseInfo = aSimplifiedHouseInfoService.getById(dto.getHouseId());
  252. if (!"空闲".equals(aSimplifiedHouseInfo.getStatus())) {
  253. throw new RuntimeException("此房屋已租");
  254. }
  255. Contract baseContract = ContractFactory.createContract(aSimplifiedHouseInfo.getAssetType());
  256. BeanUtil.copyProperties(dto.getContractData(), baseContract);
  257. RentalTempBo bo = new RentalTempBo();
  258. var resPath = "";
  259. AContractInfo contractInfo = new AContractInfo();
  260. var contractNumber = generateAssetNumber();
  261. if (baseContract instanceof ContractA) {
  262. var contractA = (ContractA) baseContract;
  263. processContractA(contractA , aSimplifiedHouseInfo, houseInfoDetail, bo);
  264. resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
  265. contractInfo.setContractNumber(contractNumber);
  266. contractInfo.setContractDate(LocalDate.parse(contractA.getTenantTimeStart()));
  267. contractInfo.setContractTime(contractA.getTenantTime());
  268. contractInfo.setContractExpirationDate(LocalDate.parse(contractA.getTenantTimeEnd()));
  269. contractInfo.setContractDeposit(new BigDecimal(contractA.getTenantDepositAmount()));
  270. contractInfo.setContractStatus("有效");
  271. contractInfo.setSimplifiedHouseId(dto.getHouseId());
  272. contractInfo.setOriginalContractUrl(resPath);
  273. contractInfo.setSignContractUrl(null);
  274. contractInfo.setCreateTime(LocalDateTime.now());
  275. contractInfo.setUpdateTime(LocalDateTime.now());
  276. this.save(contractInfo);
  277. } else if (baseContract instanceof ContractB) {
  278. var contractB = (ContractB) baseContract;
  279. processContractB(contractB, aSimplifiedHouseInfo, houseInfoDetail, bo);
  280. resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
  281. contractInfo.setContractNumber(contractNumber);
  282. contractInfo.setContractDate(LocalDate.parse(contractB.getLeaseStartDate()));
  283. contractInfo.setContractTime(contractB.getLeaseTermYears());
  284. contractInfo.setContractExpirationDate(LocalDate.parse(contractB.getLeaseEndDate()));
  285. contractInfo.setContractDeposit(new BigDecimal(contractB.getDepositAmount()));
  286. contractInfo.setContractStatus("有效");
  287. contractInfo.setSimplifiedHouseId(dto.getHouseId());
  288. contractInfo.setOriginalContractUrl(resPath);
  289. contractInfo.setSignContractUrl(null);
  290. contractInfo.setCreateTime(LocalDateTime.now());
  291. contractInfo.setUpdateTime(LocalDateTime.now());
  292. this.save(contractInfo);
  293. } else if (baseContract instanceof ContractC) {
  294. var contractC = (ContractC) baseContract;
  295. processContractC(contractC, bo,contractNumber);
  296. resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
  297. contractInfo.setContractNumber(contractNumber);
  298. contractInfo.setContractDate(LocalDate.parse(contractC.getLeaseStartDate()));
  299. contractInfo.setContractTime(contractC.getLeaseTermMonths());
  300. contractInfo.setContractExpirationDate(LocalDate.parse(contractC.getLeaseEndDate()));
  301. contractInfo.setContractDeposit(new BigDecimal(contractC.getDepositAmount()));
  302. contractInfo.setContractStatus("有效");
  303. contractInfo.setSimplifiedHouseId(dto.getHouseId());
  304. contractInfo.setOriginalContractUrl(resPath);
  305. contractInfo.setSignContractUrl(null);
  306. contractInfo.setCreateTime(LocalDateTime.now());
  307. contractInfo.setUpdateTime(LocalDateTime.now());
  308. this.save(contractInfo);
  309. }
  310. aSimplifiedHouseInfo.setStatus("已租");
  311. aSimplifiedHouseInfoService.updateById(aSimplifiedHouseInfo);
  312. ATenantInfo aTenantInfo = new ATenantInfo();
  313. aTenantInfo.setTenantName(dto.getRentalInfo().getRentalName());
  314. aTenantInfo.setTenantNumber(dto.getRentalInfo().getRentalPhone());
  315. aTenantInfo.setTenantIdCard(dto.getRentalInfo().getRentalIdCard());
  316. aTenantInfo.setTenantInDate(LocalDate.parse(dto.getRentalInfo().getRentalTimeStart()));
  317. aTenantInfo.setTenantTime(dto.getRentalInfo().getRentalTime());
  318. aTenantInfo.setTenantRent(new BigDecimal(dto.getRentalInfo().getRentalRect()));
  319. aTenantInfo.setSimplifiedHouseId(dto.getHouseId());
  320. aTenantInfo.setCreateTime(LocalDateTime.now());
  321. aTenantInfo.setUpdateTime(LocalDateTime.now());
  322. aTenantInfoService.save(aTenantInfo);
  323. return "签约成功";
  324. }
  325. private static void processContractC(ContractC baseContract, RentalTempBo bo,String contractNumber) {
  326. ContractC contractC = baseContract;
  327. //todo 处理bo
  328. bo.setC1(contractNumber);
  329. bo.setC2(contractC.getLessorName());
  330. bo.setC3(contractC.getLessorLegalRep());
  331. bo.setC4(contractC.getLessorUniCode());
  332. bo.setC5(contractC.getLesseeName());
  333. bo.setC6(contractC.getLesseeLegalRep());
  334. bo.setC7(contractC.getLesseeIdCode());
  335. bo.setC8(contractC.getPropertyLocation());
  336. bo.setC9(contractC.getRentableArea());
  337. bo.setC10(contractC.getUsableArea());
  338. bo.setC11(contractC.getSharedArea());
  339. bo.setC12(contractC.getPropertyUseNature());
  340. bo.setC13(contractC.getStoreName());
  341. bo.setC14(contractC.getBrand());
  342. bo.setC15(contractC.getBusinessScope());
  343. bo.setC16(contractC.getLeaseTermMonths());
  344. bo.setC17(contractC.getLeaseStartDate());
  345. bo.setC18(contractC.getLeaseEndDate());
  346. bo.setC19(contractC.getRenovationStartDate());
  347. bo.setC20(contractC.getRenovationEndDate());
  348. bo.setC21(contractC.getOfficialLeaseStartDate());
  349. bo.setC22(convertToUppercase(contractC.getAnnualRentLower()));
  350. bo.setC23(contractC.getAnnualRentLower());
  351. bo.setC24(convertToUppercase(contractC.getAnnualPropertyFeeLower()));
  352. bo.setC25(contractC.getAnnualPropertyFeeLower());
  353. bo.setC26(contractC.getDepositAmount());
  354. bo.setC27(convertToUppercase(contractC.getDepositAmount()));
  355. }
  356. private static void processContractB(ContractB baseContract, ASimplifiedHouseInfo aSimplifiedHouseInfo, AHouseInfoDetail houseDetailInfo, RentalTempBo bo) {
  357. ContractB contractB = baseContract;
  358. //todo 处理bo
  359. bo.setB1(contractB.getPurpose());
  360. bo.setB2(contractB.getLandlordName());
  361. bo.setB3(contractB.getLandlordUniCode());
  362. bo.setB4(contractB.getLandlordLegalRepresentative());
  363. bo.setB5(contractB.getLandlordDuty());
  364. bo.setB6(contractB.getTenantName());
  365. bo.setB7(contractB.getTenantUniCode());
  366. bo.setB8(contractB.getTenantLegalRepresentative());
  367. bo.setB9(contractB.getTenantDuty());
  368. bo.setB10(contractB.getWho());
  369. bo.setB11(contractB.getWhatTime());
  370. bo.setB12(contractB.getTitle());
  371. bo.setB13(aSimplifiedHouseInfo.getHouseName());
  372. bo.setB14(aSimplifiedHouseInfo.getFloor());
  373. bo.setB15(houseDetailInfo.getArea());
  374. bo.setB16(contractB.getSupportingRoomArea());
  375. bo.setB17(contractB.getOfficeArea());
  376. bo.setB18(contractB.getCanteenArea());
  377. bo.setB19(contractB.getTotalLeasedArea());
  378. bo.setB20(contractB.getDormTotalRooms());
  379. bo.setB21(contractB.getDormSmallRooms());
  380. bo.setB22(contractB.getDormLargeRooms());
  381. bo.setB23(contractB.getDeliveryDate());
  382. bo.setB24(contractB.getProductionProject());
  383. bo.setB25(contractB.getLeaseTermYears());
  384. bo.setB26(contractB.getLeaseStartDate());
  385. bo.setB27(contractB.getLeaseEndDate());
  386. bo.setB28(contractB.getRenewNoticeMonths());
  387. bo.setB29(contractB.getFactorySpecificFloor1());
  388. bo.setB30(contractB.getRentPerSqmFloor1());
  389. bo.setB31(contractB.getFactorySpecificFloor2());
  390. bo.setB32(contractB.getRentPerSqmFloor2());
  391. bo.setB33(contractB.getFactoryAnnualRent());
  392. bo.setB34(convertToUppercase(contractB.getFactoryAnnualRent()));
  393. bo.setB35(contractB.getSupportingRoomRentPerSqm());
  394. bo.setB36(contractB.getSupportingRoomAnnualRent());
  395. bo.setB37(convertToUppercase(contractB.getSupportingRoomAnnualRent()));
  396. bo.setB38(contractB.getDormSmallRoomRent());
  397. bo.setB39(contractB.getDormLargeRoomRent());
  398. bo.setB40(contractB.getDormAnnualRent());
  399. bo.setB41(convertToUppercase(contractB.getDormAnnualRent()));
  400. bo.setB42(contractB.getTotalAnnualRent());
  401. bo.setB43(convertToUppercase(contractB.getTotalAnnualRent()));
  402. bo.setB44(contractB.getPropertyFeePerSqm());
  403. bo.setB45(contractB.getFactorySupportingPropertyFee());
  404. bo.setB46(convertToUppercase(contractB.getFactorySupportingPropertyFee()));
  405. bo.setB47(contractB.getDormSmallRoomPropertyFee());
  406. bo.setB48(contractB.getDormLargeRoomPropertyFee());
  407. bo.setB49(contractB.getDormAnnualPropertyFee());
  408. bo.setB50(convertToUppercase(contractB.getDormAnnualPropertyFee()));
  409. bo.setB51(contractB.getTotalAnnualPropertyFee());
  410. bo.setB52(convertToUppercase(contractB.getTotalAnnualPropertyFee()));
  411. bo.setB53(contractB.getAnnualTotalRentAndPropertyFee());
  412. bo.setB54(convertToUppercase(contractB.getAnnualTotalRentAndPropertyFee()));
  413. bo.setB55(contractB.getDepositAmount());
  414. bo.setB56(convertToUppercase(contractB.getDepositAmount()));
  415. }
  416. private static void processContractA(ContractA baseContract, ASimplifiedHouseInfo aSimplifiedHouseInfo, AHouseInfoDetail houseDetailInfo, RentalTempBo bo) {
  417. ContractA contractA = baseContract;
  418. bo.setA1(contractA.getLandlordName());
  419. bo.setA2(contractA.getTenantName());
  420. bo.setA3(aSimplifiedHouseInfo.getAddress());
  421. bo.setA4(contractA.getTenantTime());
  422. bo.setA5(contractA.getTenantTimeStart());
  423. bo.setA6(contractA.getTenantTimeEnd());
  424. bo.setA7(contractA.getTenantRent());
  425. bo.setA8(contractA.getTenantDeposit());
  426. bo.setA9(contractA.getTenantDepositAmount());
  427. }
  428. @Autowired
  429. private ARentalContractService aRentalContractService;
  430. private String fillContractData(RentalTempBo bo, String houseType) {
  431. var f = 0;
  432. switch (houseType) {
  433. case "公租房": {
  434. f = 1;
  435. break;
  436. }
  437. case "厂房": {
  438. f = 2;
  439. break;
  440. }
  441. case "创新创业基地": {
  442. f = 3;
  443. break;
  444. }
  445. }
  446. return aRentalContractService.generatorRental(String.valueOf(f), bo);
  447. }
  448. public static String convertToUppercase(String numberStr) {
  449. // 输入验证
  450. if (numberStr == null || numberStr.trim().isEmpty()) {
  451. throw new IllegalArgumentException("输入不能为空");
  452. }
  453. numberStr = numberStr.trim();
  454. // 处理负号
  455. boolean isNegative = false;
  456. if (numberStr.startsWith("-")) {
  457. isNegative = true;
  458. numberStr = numberStr.substring(1);
  459. }
  460. // 验证数字格式
  461. if (!numberStr.matches("\\d+(\\.\\d{1,2})?")) {
  462. throw new IllegalArgumentException("输入格式错误,需为合法数字");
  463. }
  464. // 转换为double类型(注意:使用BigDecimal可避免精度问题,但此处保持与原方法一致)
  465. double number = Double.parseDouble(numberStr);
  466. // 调用原有的转换方法
  467. String result = convertToUppercase(number);
  468. // 添加负号前缀
  469. return isNegative ? "负" + result : result;
  470. }
  471. public static String convertToUppercase(BigDecimal number) {
  472. if (number == null) {
  473. return "零元整";
  474. }
  475. if (number.compareTo(BigDecimal.ZERO) < 0) {
  476. return "负" + convertToUppercase(number.abs());
  477. }
  478. String[] units = {"", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆"};
  479. String[] digits = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
  480. // 分离整数部分和小数部分
  481. BigDecimal roundedNumber = number.setScale(2, RoundingMode.HALF_UP);
  482. BigInteger integerPart = roundedNumber.toBigInteger();
  483. int decimalPart = roundedNumber.remainder(BigDecimal.ONE).multiply(BigDecimal.valueOf(100)).intValue();
  484. StringBuilder result = new StringBuilder();
  485. String integerStr = integerPart.toString();
  486. // 处理整数部分
  487. boolean zeroFlag = false;
  488. for (int i = 0; i < integerStr.length(); i++) {
  489. int digit = integerStr.charAt(i) - '0';
  490. int unitIndex = integerStr.length() - i - 1;
  491. if (digit == 0) {
  492. zeroFlag = true;
  493. // 处理单位:万、亿、兆
  494. if (unitIndex % 4 == 0 && unitIndex > 0) {
  495. // 检查是否需要添加单位
  496. boolean needUnit = false;
  497. for (int j = i + 1; j < Math.min(i + 5, integerStr.length()); j++) {
  498. if (integerStr.charAt(j) != '0') {
  499. needUnit = true;
  500. break;
  501. }
  502. }
  503. if (!needUnit) {
  504. result.append(units[unitIndex]);
  505. }
  506. }
  507. } else {
  508. if (zeroFlag) {
  509. result.append("零");
  510. zeroFlag = false;
  511. }
  512. result.append(digits[digit]).append(units[unitIndex]);
  513. }
  514. }
  515. if (result.length() == 0) {
  516. result.append("零");
  517. }
  518. result.append("元");
  519. // 处理小数部分
  520. int jiao = decimalPart / 10;
  521. int fen = decimalPart % 10;
  522. if (jiao == 0 && fen == 0) {
  523. result.append("整");
  524. } else {
  525. if (jiao != 0) {
  526. result.append(digits[jiao]).append("角");
  527. }
  528. if (fen != 0) {
  529. result.append(digits[fen]).append("分");
  530. }
  531. }
  532. return result.toString();
  533. }
  534. public static String convertToUppercase(double number) {
  535. return convertToUppercase(BigDecimal.valueOf(number));
  536. }
  537. }