| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- package com.zksy.property.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- 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.bo.*;
- import com.zksy.property.domain.dto.ContractFormDTO;
- import com.zksy.property.factory.ContractFactory;
- import com.zksy.property.mapper.AContractInfoMapper;
- import com.zksy.property.service.*;
- 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 java.math.BigDecimal;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.util.List;
- import static com.zksy.utils.util.generateAssetNumber;
- /**
- * @author Administrator
- * @description 针对表【a_contract_info(合同信息表)】的数据库操作Service实现
- * @createDate 2025-07-14 11:59:44
- */
- @Service
- public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, AContractInfo>
- implements AContractInfoService {
- @Autowired
- @Lazy
- private ASimplifiedHouseInfoService aSimplifiedHouseInfoService;
- @Autowired
- private ATenantInfoService aTenantInfoService;
- @Override
- public Page<AContractInfo> findByPage(long pageNum, long pageSize, String contractNumber, String contractDate, String contractStatus) {
- Page<AContractInfo> page = new Page<>(pageNum, pageSize);
- LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
- queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
- queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
- queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
- queryWrapper.orderByDesc(AContractInfo::getUpdateTime);
- Page<AContractInfo> page1 = this.page(page, queryWrapper);
- return page1;
- }
- @Override
- public List<AContractInfo> getAContractInfoList(String contractNumber, String contractDate, String contractStatus) {
- LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
- queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
- queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
- queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
- List<AContractInfo> list = this.list(queryWrapper);
- return list;
- }
- @Override
- public AContractInfo getBySimplifiedHouseId(String simplifiedHouseId) {
- LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AContractInfo::getSimplifiedHouseId, simplifiedHouseId);
- return this.getOne(queryWrapper);
- }
- @Autowired
- private AHouseInfoDetailService aHouseInfoDetailService;
- @Override
- @Transactional
- public String signContract(ContractFormDTO dto) {
- AHouseInfoDetail houseInfoDetail = aHouseInfoDetailService.getBySimplifiedHouseId(dto.getHouseId());
- ASimplifiedHouseInfo aSimplifiedHouseInfo = aSimplifiedHouseInfoService.getById(dto.getHouseId());
- if (!"空闲".equals(aSimplifiedHouseInfo.getStatus())) {
- throw new RuntimeException("此房屋已租");
- }
- Contract baseContract = ContractFactory.createContract(aSimplifiedHouseInfo.getAssetType());
- BeanUtil.copyProperties(dto.getContractData(), baseContract);
- RentalTempBo bo = new RentalTempBo();
- var resPath = "";
- AContractInfo contractInfo = new AContractInfo();
- var contractNumber = generateAssetNumber();
- if (baseContract instanceof ContractA) {
- var contractA = (ContractA) baseContract;
- processContractA(contractA , aSimplifiedHouseInfo, houseInfoDetail, bo);
- resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
- contractInfo.setContractNumber(contractNumber);
- contractInfo.setContractDate(LocalDate.parse(contractA.getTenantTimeStart()));
- contractInfo.setContractTime(contractA.getTenantTime());
- contractInfo.setContractExpirationDate(LocalDate.parse(contractA.getTenantTimeEnd()));
- contractInfo.setContractDeposit(new BigDecimal(contractA.getTenantDepositAmount()));
- contractInfo.setContractStatus("有效");
- contractInfo.setSimplifiedHouseId(dto.getHouseId());
- contractInfo.setOriginalContractUrl(resPath);
- contractInfo.setSignContractUrl(null);
- contractInfo.setCreateTime(LocalDateTime.now());
- contractInfo.setUpdateTime(LocalDateTime.now());
- this.save(contractInfo);
- } else if (baseContract instanceof ContractB) {
- var contractB = (ContractB) baseContract;
- processContractB(contractB, aSimplifiedHouseInfo, houseInfoDetail, bo);
- resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
- contractInfo.setContractNumber(contractNumber);
- contractInfo.setContractDate(LocalDate.parse(contractB.getLeaseStartDate()));
- contractInfo.setContractTime(contractB.getLeaseTermYears());
- contractInfo.setContractExpirationDate(LocalDate.parse(contractB.getLeaseEndDate()));
- contractInfo.setContractDeposit(new BigDecimal(contractB.getDepositAmount()));
- contractInfo.setContractStatus("有效");
- contractInfo.setSimplifiedHouseId(dto.getHouseId());
- contractInfo.setOriginalContractUrl(resPath);
- contractInfo.setSignContractUrl(null);
- contractInfo.setCreateTime(LocalDateTime.now());
- contractInfo.setUpdateTime(LocalDateTime.now());
- this.save(contractInfo);
- } else if (baseContract instanceof ContractC) {
- var contractC = (ContractC) baseContract;
- processContractC(contractC, bo,contractNumber);
- resPath = fillContractData(bo, aSimplifiedHouseInfo.getAssetType());
- contractInfo.setContractNumber(contractNumber);
- contractInfo.setContractDate(LocalDate.parse(contractC.getLeaseStartDate()));
- contractInfo.setContractTime(contractC.getLeaseTermMonths());
- contractInfo.setContractExpirationDate(LocalDate.parse(contractC.getLeaseEndDate()));
- contractInfo.setContractDeposit(new BigDecimal(contractC.getDepositAmount()));
- contractInfo.setContractStatus("有效");
- contractInfo.setSimplifiedHouseId(dto.getHouseId());
- contractInfo.setOriginalContractUrl(resPath);
- contractInfo.setSignContractUrl(null);
- contractInfo.setCreateTime(LocalDateTime.now());
- contractInfo.setUpdateTime(LocalDateTime.now());
- this.save(contractInfo);
- }
- /*aSimplifiedHouseInfo.setStatus("已租");
- aSimplifiedHouseInfoService.updateById(aSimplifiedHouseInfo);
- ATenantInfo aTenantInfo = new ATenantInfo();
- aTenantInfo.setTenantName(dto.getRentalInfo().getRentalName());
- aTenantInfo.setTenantNumber(dto.getRentalInfo().getRentalPhone());
- aTenantInfo.setTenantIdCard(dto.getRentalInfo().getRentalIdCard());
- aTenantInfo.setTenantInDate(LocalDate.parse(dto.getRentalInfo().getRentalTimeStart()));
- aTenantInfo.setTenantTime(dto.getRentalInfo().getRentalTime());
- aTenantInfo.setTenantRent(new BigDecimal(dto.getRentalInfo().getRentalRect()));
- aTenantInfo.setSimplifiedHouseId(dto.getHouseId());
- aTenantInfo.setCreateTime(LocalDateTime.now());
- aTenantInfo.setUpdateTime(LocalDateTime.now());
- aTenantInfoService.save(aTenantInfo);*/
- return resPath;
- }
- private static void processContractC(ContractC baseContract, RentalTempBo bo,String contractNumber) {
- ContractC contractC = baseContract;
- //todo 处理bo
- bo.setC1(contractNumber);
- bo.setC2(contractC.getLessorName());
- bo.setC3(contractC.getLessorLegalRep());
- bo.setC4(contractC.getLessorUniCode());
- bo.setC5(contractC.getLesseeName());
- bo.setC6(contractC.getLesseeLegalRep());
- bo.setC7(contractC.getLesseeIdCode());
- bo.setC8(contractC.getPropertyLocation());
- bo.setC9(contractC.getRentableArea());
- bo.setC10(contractC.getUsableArea());
- bo.setC11(contractC.getSharedArea());
- bo.setC12(contractC.getPropertyUseNature());
- bo.setC13(contractC.getStoreName());
- bo.setC14(contractC.getBrand());
- bo.setC15(contractC.getBusinessScope());
- bo.setC16(contractC.getLeaseTermMonths());
- bo.setC17(contractC.getLeaseStartDate());
- bo.setC18(contractC.getLeaseEndDate());
- bo.setC19(contractC.getRenovationStartDate());
- bo.setC20(contractC.getRenovationEndDate());
- bo.setC21(contractC.getOfficialLeaseStartDate());
- bo.setC22(convertToUppercase(contractC.getAnnualRentLower()));
- bo.setC23(contractC.getAnnualRentLower());
- bo.setC24(convertToUppercase(contractC.getAnnualPropertyFeeLower()));
- bo.setC25(contractC.getAnnualPropertyFeeLower());
- bo.setC26(contractC.getDepositAmount());
- bo.setC27(convertToUppercase(contractC.getDepositAmount()));
- }
- private static void processContractB(ContractB baseContract, ASimplifiedHouseInfo aSimplifiedHouseInfo, AHouseInfoDetail houseDetailInfo, RentalTempBo bo) {
- ContractB contractB = baseContract;
- //todo 处理bo
- bo.setB1(contractB.getPurpose());
- bo.setB2(contractB.getLandlordName());
- bo.setB3(contractB.getLandlordUniCode());
- bo.setB4(contractB.getLandlordLegalRepresentative());
- bo.setB5(contractB.getLandlordDuty());
- bo.setB6(contractB.getTenantName());
- bo.setB7(contractB.getTenantUniCode());
- bo.setB8(contractB.getTenantLegalRepresentative());
- bo.setB9(contractB.getTenantDuty());
- bo.setB10(contractB.getWho());
- bo.setB11(contractB.getWhatTime());
- bo.setB12(contractB.getTitle());
- bo.setB13(aSimplifiedHouseInfo.getHouseName());
- bo.setB14(aSimplifiedHouseInfo.getFloor());
- bo.setB15(houseDetailInfo.getArea());
- bo.setB16(contractB.getSupportingRoomArea());
- bo.setB17(contractB.getOfficeArea());
- bo.setB18(contractB.getCanteenArea());
- bo.setB19(contractB.getTotalLeasedArea());
- bo.setB20(contractB.getDormTotalRooms());
- bo.setB21(contractB.getDormSmallRooms());
- bo.setB22(contractB.getDormLargeRooms());
- bo.setB23(contractB.getDeliveryDate());
- bo.setB24(contractB.getProductionProject());
- bo.setB25(contractB.getLeaseTermYears());
- bo.setB26(contractB.getLeaseStartDate());
- bo.setB27(contractB.getLeaseEndDate());
- bo.setB28(contractB.getRenewNoticeMonths());
- bo.setB29(contractB.getFactorySpecificFloor1());
- bo.setB30(contractB.getRentPerSqmFloor1());
- bo.setB31(contractB.getFactorySpecificFloor2());
- bo.setB32(contractB.getRentPerSqmFloor2());
- bo.setB33(contractB.getFactoryAnnualRent());
- bo.setB34(convertToUppercase(contractB.getFactoryAnnualRent()));
- bo.setB35(contractB.getSupportingRoomRentPerSqm());
- bo.setB36(contractB.getSupportingRoomAnnualRent());
- bo.setB37(convertToUppercase(contractB.getSupportingRoomAnnualRent()));
- bo.setB38(contractB.getDormSmallRoomRent());
- bo.setB39(contractB.getDormLargeRoomRent());
- bo.setB40(contractB.getDormAnnualRent());
- bo.setB41(convertToUppercase(contractB.getDormAnnualRent()));
- bo.setB42(contractB.getTotalAnnualRent());
- bo.setB43(convertToUppercase(contractB.getTotalAnnualRent()));
- bo.setB44(contractB.getPropertyFeePerSqm());
- bo.setB45(contractB.getFactorySupportingPropertyFee());
- bo.setB46(convertToUppercase(contractB.getFactorySupportingPropertyFee()));
- bo.setB47(contractB.getDormSmallRoomPropertyFee());
- bo.setB48(contractB.getDormLargeRoomPropertyFee());
- bo.setB49(contractB.getDormAnnualPropertyFee());
- bo.setB50(convertToUppercase(contractB.getDormAnnualPropertyFee()));
- bo.setB51(contractB.getTotalAnnualPropertyFee());
- bo.setB52(convertToUppercase(contractB.getTotalAnnualPropertyFee()));
- bo.setB53(contractB.getAnnualTotalRentAndPropertyFee());
- bo.setB54(convertToUppercase(contractB.getAnnualTotalRentAndPropertyFee()));
- bo.setB55(contractB.getDepositAmount());
- bo.setB56(convertToUppercase(contractB.getDepositAmount()));
- }
- private static void processContractA(ContractA baseContract, ASimplifiedHouseInfo aSimplifiedHouseInfo, AHouseInfoDetail houseDetailInfo, RentalTempBo bo) {
- ContractA contractA = baseContract;
- bo.setA1(contractA.getLandlordName());
- bo.setA2(contractA.getTenantName());
- bo.setA3(aSimplifiedHouseInfo.getAddress());
- bo.setA4(contractA.getTenantTime());
- bo.setA5(contractA.getTenantTimeStart());
- bo.setA6(contractA.getTenantTimeEnd());
- bo.setA7(contractA.getTenantRent());
- bo.setA8(contractA.getTenantDeposit());
- bo.setA9(contractA.getTenantDepositAmount());
- }
- @Autowired
- private ARentalContractService aRentalContractService;
- private String fillContractData(RentalTempBo bo, String houseType) {
- var f = 0;
- switch (houseType) {
- case "公租房": {
- f = 1;
- break;
- }
- case "厂房": {
- f = 2;
- break;
- }
- case "创新创业基地": {
- f = 3;
- break;
- }
- }
- return aRentalContractService.generatorRental(String.valueOf(f), bo);
- }
- public static String convertToUppercase(String numberStr) {
- // 输入验证
- if (numberStr == null || numberStr.trim().isEmpty()) {
- throw new IllegalArgumentException("输入不能为空");
- }
- numberStr = numberStr.trim();
- // 处理负号
- boolean isNegative = false;
- if (numberStr.startsWith("-")) {
- isNegative = true;
- numberStr = numberStr.substring(1);
- }
- // 验证数字格式
- if (!numberStr.matches("\\d+(\\.\\d{1,2})?")) {
- throw new IllegalArgumentException("输入格式错误,需为合法数字");
- }
- // 转换为double类型(注意:使用BigDecimal可避免精度问题,但此处保持与原方法一致)
- double number = Double.parseDouble(numberStr);
- // 调用原有的转换方法
- String result = convertToUppercase(number);
- // 添加负号前缀
- return isNegative ? "负" + result : result;
- }
- // 数字转中文大写的主方法
- public static String convertToUppercase(double number) {
- if (number < 0) {
- return "负" + convertToUppercase(-number);
- }
- String[] units = {"", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆"};
- String[] digits = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
- long integerPart = (long) number;
- long decimalPart = Math.round((number - integerPart) * 100);
- StringBuilder result = new StringBuilder();
- String integerStr = String.valueOf(integerPart);
- // 处理整数部分
- boolean zeroFlag = false;
- for (int i = 0; i < integerStr.length(); i++) {
- int digit = integerStr.charAt(i) - '0';
- int unitIndex = integerStr.length() - i - 1;
- if (digit == 0) {
- zeroFlag = true;
- // 处理单位:万、亿、兆
- if (unitIndex % 4 == 0) {
- result.append(units[unitIndex]);
- }
- } else {
- if (zeroFlag) {
- result.append("零");
- zeroFlag = false;
- }
- result.append(digits[digit]).append(units[unitIndex]);
- }
- }
- if (result.length() == 0) {
- result.append("零");
- }
- result.append("元");
- // 处理小数部分
- long jiao = decimalPart / 10;
- long fen = decimalPart % 10;
- if (jiao == 0 && fen == 0) {
- result.append("整");
- } else {
- if (jiao != 0) {
- result.append(digits[(int) jiao]).append("角");
- }
- if (fen != 0) {
- result.append(digits[(int) fen]).append("分");
- }
- }
- return result.toString();
- }
- }
|