AContractInfoServiceImpl.java 28 KB

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