AContractInfoServiceImpl.java 14 KB

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