AContractInfoServiceImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.zksy.property.domain.AContractInfo;
  7. import com.zksy.property.domain.AHouseInfoDetail;
  8. import com.zksy.property.domain.ASimplifiedHouseInfo;
  9. import com.zksy.property.domain.bo.*;
  10. import com.zksy.property.domain.dto.ContractFormDTO;
  11. import com.zksy.property.factory.ContractFactory;
  12. import com.zksy.property.mapper.AContractInfoMapper;
  13. import com.zksy.property.service.*;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.context.annotation.Lazy;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import java.math.BigDecimal;
  19. import java.time.LocalDate;
  20. import java.time.LocalDateTime;
  21. import java.util.List;
  22. import static com.zksy.utils.util.generateAssetNumber;
  23. /**
  24. * @author Administrator
  25. * @description 针对表【a_contract_info(合同信息表)】的数据库操作Service实现
  26. * @createDate 2025-07-14 11:59:44
  27. */
  28. @Service
  29. public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, AContractInfo>
  30. implements AContractInfoService {
  31. @Autowired
  32. @Lazy
  33. private ASimplifiedHouseInfoService aSimplifiedHouseInfoService;
  34. @Autowired
  35. private ATenantInfoService aTenantInfoService;
  36. @Override
  37. public Page<AContractInfo> findByPage(long pageNum, long pageSize, String contractNumber, String contractDate, String contractStatus) {
  38. Page<AContractInfo> page = new Page<>(pageNum, pageSize);
  39. LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
  40. queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
  41. queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
  42. queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
  43. queryWrapper.orderByDesc(AContractInfo::getUpdateTime);
  44. Page<AContractInfo> page1 = this.page(page, queryWrapper);
  45. return page1;
  46. }
  47. @Override
  48. public List<AContractInfo> getAContractInfoList(String contractNumber, String contractDate, String contractStatus) {
  49. LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
  50. queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
  51. queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
  52. queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
  53. List<AContractInfo> list = this.list(queryWrapper);
  54. return list;
  55. }
  56. @Override
  57. public AContractInfo getBySimplifiedHouseId(String simplifiedHouseId) {
  58. LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper<>();
  59. queryWrapper.eq(AContractInfo::getSimplifiedHouseId, simplifiedHouseId);
  60. return this.getOne(queryWrapper);
  61. }
  62. @Autowired
  63. private AHouseInfoDetailService aHouseInfoDetailService;
  64. @Override
  65. @Transactional
  66. public String signContract(ContractFormDTO dto) {
  67. AHouseInfoDetail houseInfoDetail = aHouseInfoDetailService.getBySimplifiedHouseId(dto.getHouseId());
  68. ASimplifiedHouseInfo aSimplifiedHouseInfo = aSimplifiedHouseInfoService.getById(dto.getHouseId());
  69. if (!"空闲".equals(aSimplifiedHouseInfo.getStatus())) {
  70. throw new RuntimeException("此房屋已租");
  71. }
  72. Contract baseContract = ContractFactory.createContract(aSimplifiedHouseInfo.getAssetType());
  73. BeanUtil.copyProperties(dto.getContractData(), baseContract);
  74. RentalTempBo bo = new RentalTempBo();
  75. var resPath = "";
  76. AContractInfo contractInfo = new AContractInfo();
  77. var contractNumber = generateAssetNumber();
  78. if (baseContract instanceof ContractA) {
  79. var contractA = (ContractA) baseContract;
  80. processContractA(contractA , aSimplifiedHouseInfo, houseInfoDetail, bo);
  81. resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
  82. contractInfo.setContractNumber(contractNumber);
  83. contractInfo.setContractDate(LocalDate.parse(contractA.getTenantTimeStart()));
  84. contractInfo.setContractTime(contractA.getTenantTime());
  85. contractInfo.setContractExpirationDate(LocalDate.parse(contractA.getTenantTimeEnd()));
  86. contractInfo.setContractDeposit(new BigDecimal(contractA.getTenantDepositAmount()));
  87. contractInfo.setContractStatus("有效");
  88. contractInfo.setSimplifiedHouseId(dto.getHouseId());
  89. contractInfo.setOriginalContractUrl(resPath);
  90. contractInfo.setSignContractUrl(null);
  91. contractInfo.setCreateTime(LocalDateTime.now());
  92. contractInfo.setUpdateTime(LocalDateTime.now());
  93. this.save(contractInfo);
  94. } else if (baseContract instanceof ContractB) {
  95. var contractB = (ContractB) baseContract;
  96. processContractB(contractB, aSimplifiedHouseInfo, houseInfoDetail, bo);
  97. resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
  98. contractInfo.setContractNumber(contractNumber);
  99. contractInfo.setContractDate(LocalDate.parse(contractB.getLeaseStartDate()));
  100. contractInfo.setContractTime(contractB.getLeaseTermYears());
  101. contractInfo.setContractExpirationDate(LocalDate.parse(contractB.getLeaseEndDate()));
  102. contractInfo.setContractDeposit(new BigDecimal(contractB.getDepositAmount()));
  103. contractInfo.setContractStatus("有效");
  104. contractInfo.setSimplifiedHouseId(dto.getHouseId());
  105. contractInfo.setOriginalContractUrl(resPath);
  106. contractInfo.setSignContractUrl(null);
  107. contractInfo.setCreateTime(LocalDateTime.now());
  108. contractInfo.setUpdateTime(LocalDateTime.now());
  109. this.save(contractInfo);
  110. } else if (baseContract instanceof ContractC) {
  111. var contractC = (ContractC) baseContract;
  112. processContractC(contractC, bo,contractNumber);
  113. resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
  114. contractInfo.setContractNumber(contractNumber);
  115. contractInfo.setContractDate(LocalDate.parse(contractC.getLeaseStartDate()));
  116. contractInfo.setContractTime(contractC.getLeaseTermMonths());
  117. contractInfo.setContractExpirationDate(LocalDate.parse(contractC.getLeaseEndDate()));
  118. contractInfo.setContractDeposit(new BigDecimal(contractC.getDepositAmount()));
  119. contractInfo.setContractStatus("有效");
  120. contractInfo.setSimplifiedHouseId(dto.getHouseId());
  121. contractInfo.setOriginalContractUrl(resPath);
  122. contractInfo.setSignContractUrl(null);
  123. contractInfo.setCreateTime(LocalDateTime.now());
  124. contractInfo.setUpdateTime(LocalDateTime.now());
  125. this.save(contractInfo);
  126. }
  127. /*aSimplifiedHouseInfo.setStatus("已租");
  128. aSimplifiedHouseInfoService.updateById(aSimplifiedHouseInfo);
  129. ATenantInfo aTenantInfo = new ATenantInfo();
  130. aTenantInfo.setTenantName(dto.getRentalInfo().getRentalName());
  131. aTenantInfo.setTenantNumber(dto.getRentalInfo().getRentalPhone());
  132. aTenantInfo.setTenantIdCard(dto.getRentalInfo().getRentalIdCard());
  133. aTenantInfo.setTenantInDate(LocalDate.parse(dto.getRentalInfo().getRentalTimeStart()));
  134. aTenantInfo.setTenantTime(dto.getRentalInfo().getRentalTime());
  135. aTenantInfo.setTenantRent(new BigDecimal(dto.getRentalInfo().getRentalRect()));
  136. aTenantInfo.setSimplifiedHouseId(dto.getHouseId());
  137. aTenantInfo.setCreateTime(LocalDateTime.now());
  138. aTenantInfo.setUpdateTime(LocalDateTime.now());
  139. aTenantInfoService.save(aTenantInfo);*/
  140. return resPath;
  141. }
  142. private static void processContractC(ContractC baseContract, RentalTempBo bo,String contractNumber) {
  143. ContractC contractC = baseContract;
  144. //todo 处理bo
  145. bo.setC1(contractNumber);
  146. bo.setC2(contractC.getLessorName());
  147. bo.setC3(contractC.getLessorLegalRep());
  148. bo.setC4(contractC.getLessorUniCode());
  149. bo.setC5(contractC.getLesseeName());
  150. bo.setC6(contractC.getLesseeLegalRep());
  151. bo.setC7(contractC.getLesseeIdCode());
  152. bo.setC8(contractC.getPropertyLocation());
  153. bo.setC9(contractC.getRentableArea());
  154. bo.setC10(contractC.getUsableArea());
  155. bo.setC11(contractC.getSharedArea());
  156. bo.setC12(contractC.getPropertyUseNature());
  157. bo.setC13(contractC.getStoreName());
  158. bo.setC14(contractC.getBrand());
  159. bo.setC15(contractC.getBusinessScope());
  160. bo.setC16(contractC.getLeaseTermMonths());
  161. bo.setC17(contractC.getLeaseStartDate());
  162. bo.setC18(contractC.getLeaseEndDate());
  163. bo.setC19(contractC.getRenovationStartDate());
  164. bo.setC20(contractC.getRenovationEndDate());
  165. bo.setC21(contractC.getOfficialLeaseStartDate());
  166. bo.setC22(convertToUppercase(contractC.getAnnualRentLower()));
  167. bo.setC23(contractC.getAnnualRentLower());
  168. bo.setC24(convertToUppercase(contractC.getAnnualPropertyFeeLower()));
  169. bo.setC25(contractC.getAnnualPropertyFeeLower());
  170. bo.setC26(contractC.getDepositAmount());
  171. bo.setC27(convertToUppercase(contractC.getDepositAmount()));
  172. }
  173. private static void processContractB(ContractB baseContract, ASimplifiedHouseInfo aSimplifiedHouseInfo, AHouseInfoDetail houseDetailInfo, RentalTempBo bo) {
  174. ContractB contractB = baseContract;
  175. //todo 处理bo
  176. bo.setB1(contractB.getPurpose());
  177. bo.setB2(contractB.getLandlordName());
  178. bo.setB3(contractB.getLandlordUniCode());
  179. bo.setB4(contractB.getLandlordLegalRepresentative());
  180. bo.setB5(contractB.getLandlordDuty());
  181. bo.setB6(contractB.getTenantName());
  182. bo.setB7(contractB.getTenantUniCode());
  183. bo.setB8(contractB.getTenantLegalRepresentative());
  184. bo.setB9(contractB.getTenantDuty());
  185. bo.setB10(contractB.getWho());
  186. bo.setB11(contractB.getWhatTime());
  187. bo.setB12(contractB.getTitle());
  188. bo.setB13(aSimplifiedHouseInfo.getHouseName());
  189. bo.setB14(aSimplifiedHouseInfo.getFloor());
  190. bo.setB15(houseDetailInfo.getArea());
  191. bo.setB16(contractB.getSupportingRoomArea());
  192. bo.setB17(contractB.getOfficeArea());
  193. bo.setB18(contractB.getCanteenArea());
  194. bo.setB19(contractB.getTotalLeasedArea());
  195. bo.setB20(contractB.getDormTotalRooms());
  196. bo.setB21(contractB.getDormSmallRooms());
  197. bo.setB22(contractB.getDormLargeRooms());
  198. bo.setB23(contractB.getDeliveryDate());
  199. bo.setB24(contractB.getProductionProject());
  200. bo.setB25(contractB.getLeaseTermYears());
  201. bo.setB26(contractB.getLeaseStartDate());
  202. bo.setB27(contractB.getLeaseEndDate());
  203. bo.setB28(contractB.getRenewNoticeMonths());
  204. bo.setB29(contractB.getFactorySpecificFloor1());
  205. bo.setB30(contractB.getRentPerSqmFloor1());
  206. bo.setB31(contractB.getFactorySpecificFloor2());
  207. bo.setB32(contractB.getRentPerSqmFloor2());
  208. bo.setB33(contractB.getFactoryAnnualRent());
  209. bo.setB34(convertToUppercase(contractB.getFactoryAnnualRent()));
  210. bo.setB35(contractB.getSupportingRoomRentPerSqm());
  211. bo.setB36(contractB.getSupportingRoomAnnualRent());
  212. bo.setB37(convertToUppercase(contractB.getSupportingRoomAnnualRent()));
  213. bo.setB38(contractB.getDormSmallRoomRent());
  214. bo.setB39(contractB.getDormLargeRoomRent());
  215. bo.setB40(contractB.getDormAnnualRent());
  216. bo.setB41(convertToUppercase(contractB.getDormAnnualRent()));
  217. bo.setB42(contractB.getTotalAnnualRent());
  218. bo.setB43(convertToUppercase(contractB.getTotalAnnualRent()));
  219. bo.setB44(contractB.getPropertyFeePerSqm());
  220. bo.setB45(contractB.getFactorySupportingPropertyFee());
  221. bo.setB46(convertToUppercase(contractB.getFactorySupportingPropertyFee()));
  222. bo.setB47(contractB.getDormSmallRoomPropertyFee());
  223. bo.setB48(contractB.getDormLargeRoomPropertyFee());
  224. bo.setB49(contractB.getDormAnnualPropertyFee());
  225. bo.setB50(convertToUppercase(contractB.getDormAnnualPropertyFee()));
  226. bo.setB51(contractB.getTotalAnnualPropertyFee());
  227. bo.setB52(convertToUppercase(contractB.getTotalAnnualPropertyFee()));
  228. bo.setB53(contractB.getAnnualTotalRentAndPropertyFee());
  229. bo.setB54(convertToUppercase(contractB.getAnnualTotalRentAndPropertyFee()));
  230. bo.setB55(contractB.getDepositAmount());
  231. bo.setB56(convertToUppercase(contractB.getDepositAmount()));
  232. }
  233. private static void processContractA(ContractA baseContract, ASimplifiedHouseInfo aSimplifiedHouseInfo, AHouseInfoDetail houseDetailInfo, RentalTempBo bo) {
  234. ContractA contractA = baseContract;
  235. bo.setA1(contractA.getLandlordName());
  236. bo.setA2(contractA.getTenantName());
  237. bo.setA3(aSimplifiedHouseInfo.getAddress());
  238. bo.setA4(contractA.getTenantTime());
  239. bo.setA5(contractA.getTenantTimeStart());
  240. bo.setA6(contractA.getTenantTimeEnd());
  241. bo.setA7(contractA.getTenantRent());
  242. bo.setA8(contractA.getTenantDeposit());
  243. bo.setA9(contractA.getTenantDepositAmount());
  244. }
  245. @Autowired
  246. private ARentalContractService aRentalContractService;
  247. private String fillContractData(RentalTempBo bo, String houseType) {
  248. var f = 0;
  249. switch (houseType) {
  250. case "公租房": {
  251. f = 1;
  252. break;
  253. }
  254. case "厂房": {
  255. f = 2;
  256. break;
  257. }
  258. case "创新创业基地": {
  259. f = 3;
  260. break;
  261. }
  262. }
  263. return aRentalContractService.generatorRental(String.valueOf(f), bo);
  264. }
  265. public static String convertToUppercase(String numberStr) {
  266. // 输入验证
  267. if (numberStr == null || numberStr.trim().isEmpty()) {
  268. throw new IllegalArgumentException("输入不能为空");
  269. }
  270. numberStr = numberStr.trim();
  271. // 处理负号
  272. boolean isNegative = false;
  273. if (numberStr.startsWith("-")) {
  274. isNegative = true;
  275. numberStr = numberStr.substring(1);
  276. }
  277. // 验证数字格式
  278. if (!numberStr.matches("\\d+(\\.\\d{1,2})?")) {
  279. throw new IllegalArgumentException("输入格式错误,需为合法数字");
  280. }
  281. // 转换为double类型(注意:使用BigDecimal可避免精度问题,但此处保持与原方法一致)
  282. double number = Double.parseDouble(numberStr);
  283. // 调用原有的转换方法
  284. String result = convertToUppercase(number);
  285. // 添加负号前缀
  286. return isNegative ? "负" + result : result;
  287. }
  288. // 数字转中文大写的主方法
  289. public static String convertToUppercase(double number) {
  290. if (number < 0) {
  291. return "负" + convertToUppercase(-number);
  292. }
  293. String[] units = {"", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆"};
  294. String[] digits = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
  295. long integerPart = (long) number;
  296. long decimalPart = Math.round((number - integerPart) * 100);
  297. StringBuilder result = new StringBuilder();
  298. String integerStr = String.valueOf(integerPart);
  299. // 处理整数部分
  300. boolean zeroFlag = false;
  301. for (int i = 0; i < integerStr.length(); i++) {
  302. int digit = integerStr.charAt(i) - '0';
  303. int unitIndex = integerStr.length() - i - 1;
  304. if (digit == 0) {
  305. zeroFlag = true;
  306. // 处理单位:万、亿、兆
  307. if (unitIndex % 4 == 0) {
  308. result.append(units[unitIndex]);
  309. }
  310. } else {
  311. if (zeroFlag) {
  312. result.append("零");
  313. zeroFlag = false;
  314. }
  315. result.append(digits[digit]).append(units[unitIndex]);
  316. }
  317. }
  318. if (result.length() == 0) {
  319. result.append("零");
  320. }
  321. result.append("元");
  322. // 处理小数部分
  323. long jiao = decimalPart / 10;
  324. long fen = decimalPart % 10;
  325. if (jiao == 0 && fen == 0) {
  326. result.append("整");
  327. } else {
  328. if (jiao != 0) {
  329. result.append(digits[(int) jiao]).append("角");
  330. }
  331. if (fen != 0) {
  332. result.append(digits[(int) fen]).append("分");
  333. }
  334. }
  335. return result.toString();
  336. }
  337. }