luofl
2025-03-24 ed772c2bec3eac88d040514b6b886a505d9fd119
Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
# ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
3个文件已修改
170 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java 151 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/model/TTenant.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
@@ -3,7 +3,6 @@
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.hutool.core.bean.BeanUtil;
import com.aizuda.bpm.engine.entity.FlwTask;
import com.aizuda.bpm.mybatisplus.mapper.FlwTaskMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -298,98 +297,74 @@
        List<TContract> list = contractService.lambdaQuery().in(TContract::getId, dto.getIds()).list();
        List<String> res = new ArrayList<>();
        for (TContract contract : list) {
            String url = generateContract(contract);
            String templateFileName = "1_yzj_租赁合同_个人.docx";
            TBill firstBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId())
                    .orderByDesc(TBill::getStartTime).last("limit 1").one();
            TTenant tenant = tenantService.getById(contract.getTenantId());
            THouse tHouse = houseService.getById(contract.getHouseId());
            Map<String, Object> templateParam = new HashMap<>(5);
            templateParam.put("${contractNumber}", contract.getContractNumber());
            templateParam.put("${partyOneName}", contract.getPartyOneName());
            templateParam.put("${partyTwoName}", contract.getPartyTwoName());
            if (Objects.nonNull(tenant)) {
                templateParam.put("${mailAddress}", StringUtils.isNotBlank(tenant.getMailAddress()) ? tenant.getMailAddress() : "");
                templateParam.put("${idCard}", StringUtils.isNotBlank(tenant.getIdCard()) ? tenant.getIdCard() : "");
                templateParam.put("${residentName}", tenant.getResidentName());
                templateParam.put("${bankNumber}", StringUtils.isNotBlank(tenant.getBankNumber()) ? tenant.getBankNumber() : "");
                templateParam.put("${bankName}", StringUtils.isNotBlank(tenant.getBankName()) ? tenant.getBankName() : "");
                //企业、政府机构、国有企业
                if (Objects.nonNull(tenant.getTenantType()) && (tenant.getTenantType().equals("2") || tenant.getTenantType().equals("5") || tenant.getTenantType().equals("7"))) {
                    templateParam.put("${creditCode}", StringUtils.isNotBlank(tenant.getCreditCode()) ? tenant.getCreditCode() : "");
                    templateParam.put("${legalPerson}", StringUtils.isNotBlank(tenant.getLegalPerson()) ? tenant.getLegalPerson() : "");
                    templateFileName = "1_yzj_租赁合同_企业.docx";
                }
            }
            templateParam.put("${houseAddress}", tHouse.getHouseAddress());
            templateParam.put("${houseArea}", tHouse.getHouseArea()+"m²");
            templateParam.put("${remark}", StringUtils.isNotBlank(contract.getRemark()) ? contract.getRemark() : "");
            templateParam.put("${houseUseScope}", StringUtils.isNotBlank(contract.getHouseUseScope()) ? contract.getHouseUseScope() : "");
            templateParam.put("${days}", ChronoUnit.DAYS.between(contract.getStartTime(), contract.getEndTime()));
            long between = ChronoUnit.DAYS.between(contract.getStartTime(), contract.getStartPayTime())+1;
            templateParam.put("${day}", between);
            templateParam.put("${endTimeFree}", DateUtils.localDateTimeToStringYear(contract.getStartPayTime().plusDays(1)));
            templateParam.put("${startPayTime}", DateUtils.localDateTimeToStringYear(contract.getStartPayTime()));
            templateParam.put("${startTime}", DateUtils.localDateTimeToStringYear(contract.getStartTime()));
            templateParam.put("${endTime}", DateUtils.localDateTimeToStringYear(contract.getEndTime()));
            templateParam.put("${monthRent}", "¥"+contract.getMonthRent()+"元");
            templateParam.put("${monthRentString}", "人民币"+NumberToChineseUtils.numberToChinese(contract.getMonthRent().setScale(2, BigDecimal.ROUND_DOWN).doubleValue()));
            String totalYear = Objects.nonNull(contract.getTotalYear())?contract.getTotalYear().toString():"";
            templateParam.put("${totalYear}", "¥"+totalYear+"元");
            String totalYearString = StringUtils.isNotEmpty(totalYear)?NumberToChineseUtils.numberToChinese(contract.getTotalYear().setScale(2, BigDecimal.ROUND_DOWN).doubleValue()):"";
            templateParam.put("${totalYearString}", "人民币"+totalYearString);
            templateParam.put("${payType}", contract.getPayType().equals("1")?"月":contract.getPayType().equals("2")?"季":"年");
            if(firstBill!=null){
                templateParam.put("${firstRent}", "¥"+(firstBill.getPayableFeesMoney())+"元");
            }else{
                templateParam.put("${firstRent}", "");
            }
            templateParam.put("${firstRentString}", "人民币"+NumberToChineseUtils.numberToChinese((contract.getPayType().equals("1")?contract.getMonthRent():contract.getPayType().equals("2")?contract.getMonthRent().multiply(new BigDecimal("3")):contract.getMonthRent().multiply(new BigDecimal("12")).setScale(2,BigDecimal.ROUND_DOWN)).doubleValue()));
            templateParam.put("${nextPayTime}", contract.getPayType().equals("1")?"月":contract.getPayType().equals("2")?"季":"年");
            templateParam.put("${deposit}", "¥"+contract.getDeposit()+"元");
            templateParam.put("${depositString}", NumberToChineseUtils.numberToChinese(contract.getDeposit().setScale(2, BigDecimal.ROUND_DOWN).doubleValue()));
            templateParam.put("${partyOnePerson}", contract.getPartyOnePerson());
            templateParam.put("${partyOnePhone}", contract.getPartyOnePhone());
            templateParam.put("${partyTwoPerson}", contract.getPartyTwoPerson());
            templateParam.put("${partyTwoPhone}", contract.getPartyTwoPhone());
            // 验收时间
            TCheckAcceptRecord tCheckAcceptRecord = checkAcceptRecordService.lambdaQuery().eq(TCheckAcceptRecord::getContractId, contract.getId()).last("limit 1").one();
            if (tCheckAcceptRecord!=null &&tCheckAcceptRecord.getCheckTime()!=null ){
                templateParam.put("${checkTime}", DateUtils.localDateTimeToStringYear(tCheckAcceptRecord.getCheckTime()));
            }else{
                templateParam.put("${checkTime}", "");
            }
            String url = wordUtil.generatePdf("/usr/local/project/file/", templateFileName, templateParam, "租赁合同", "/usr/local/project/file/");
            res.add(url);
        }
        return R.ok(res);
    }
    private String generateContract(TContract contract) {
        String templateFileName = "1_yzj_租赁合同_个人.docx";
        TBill firstBill = null;
        TTenant tenant = null;
        THouse tHouse = null;
        TCheckAcceptRecord tCheckAcceptRecord = null;
        if (StringUtils.isNotEmpty(contract.getId())){
            firstBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId())
                    .orderByDesc(TBill::getStartTime).last("limit 1").one();
            tenant = tenantService.getById(contract.getTenantId());
            tHouse = houseService.getById(contract.getHouseId());
            // 验收时间
            tCheckAcceptRecord = checkAcceptRecordService.lambdaQuery()
                    .eq(TCheckAcceptRecord::getContractId, contract.getId())
                    .last("limit 1").one();
        }
        Map<String, Object> templateParam = new HashMap<>(5);
        templateParam.put("${contractNumber}", contract.getContractNumber());
        templateParam.put("${partyOneName}", contract.getPartyOneName());
        templateParam.put("${partyTwoName}", contract.getPartyTwoName());
        if (Objects.nonNull(tenant)) {
            templateParam.put("${mailAddress}", StringUtils.isNotBlank(tenant.getMailAddress()) ? tenant.getMailAddress() : "");
            templateParam.put("${idCard}", StringUtils.isNotBlank(tenant.getIdCard()) ? tenant.getIdCard() : "");
            //企业、政府机构、国有企业
            if (tenant.getTenantType().equals("2") || tenant.getTenantType().equals("5") || tenant.getTenantType().equals("7")){
                templateParam.put("${creditCode}", StringUtils.isNotBlank(tenant.getCreditCode()) ? tenant.getCreditCode() : "");
                templateParam.put("${legalPerson}", StringUtils.isNotBlank(tenant.getLegalPerson()) ? tenant.getLegalPerson() : "");
                templateFileName = "1_yzj_租赁合同_企业.docx";
            }
        }
        templateParam.put("${houseAddress}", tHouse.getHouseAddress());
        templateParam.put("${houseArea}", tHouse.getHouseArea()+"m²");
        long between = ChronoUnit.DAYS.between(contract.getStartTime(), contract.getStartPayTime())+1;
        templateParam.put("${day}", between);
        templateParam.put("${endTimeFree}", DateUtils.localDateTimeToStringYear(contract.getStartPayTime().plusDays(1)));
        templateParam.put("${startPayTime}", DateUtils.localDateTimeToStringYear(contract.getStartPayTime()));
        templateParam.put("${startTime}", DateUtils.localDateTimeToStringYear(contract.getStartTime()));
        templateParam.put("${endTime}", DateUtils.localDateTimeToStringYear(contract.getEndTime()));
        templateParam.put("${monthRent}", "¥"+ contract.getMonthRent()+"元");
        templateParam.put("${monthRentString}", "人民币"+NumberToChineseUtils.numberToChinese(contract.getMonthRent().setScale(2, BigDecimal.ROUND_DOWN).doubleValue()));
        String totalYear = Objects.nonNull(contract.getTotalYear())? contract.getTotalYear().toString():"";
        templateParam.put("${totalYear}", "¥"+totalYear+"元");
        String totalYearString = StringUtils.isNotEmpty(totalYear)?NumberToChineseUtils.numberToChinese(contract.getTotalYear().setScale(2, BigDecimal.ROUND_DOWN).doubleValue()):"";
        templateParam.put("${totalYearString}", "人民币"+totalYearString);
        templateParam.put("${payType}", contract.getPayType().equals("1")?"月": contract.getPayType().equals("2")?"季":"年");
        if(firstBill!=null){
            templateParam.put("${firstRent}", "¥"+(firstBill.getPayableFeesMoney())+"元");
        }else{
            templateParam.put("${firstRent}", "");
        }
        templateParam.put("${firstRentString}", "人民币"+NumberToChineseUtils.numberToChinese((contract.getPayType().equals("1")? contract.getMonthRent(): contract.getPayType().equals("2")? contract.getMonthRent().multiply(new BigDecimal("3")): contract.getMonthRent().multiply(new BigDecimal("12")).setScale(2,BigDecimal.ROUND_DOWN)).doubleValue()));
        templateParam.put("${nextPayTime}", contract.getPayType().equals("1")?"月": contract.getPayType().equals("2")?"季":"年");
        templateParam.put("${deposit}", "¥"+ contract.getDeposit()+"元");
        templateParam.put("${depositString}", NumberToChineseUtils.numberToChinese(contract.getDeposit().setScale(2, BigDecimal.ROUND_DOWN).doubleValue()));
        templateParam.put("${partyOnePerson}", contract.getPartyOnePerson());
        templateParam.put("${partyOnePhone}", contract.getPartyOnePhone());
        templateParam.put("${partyTwoPerson}", contract.getPartyTwoPerson());
        templateParam.put("${partyTwoPhone}", contract.getPartyTwoPhone());
        if (tCheckAcceptRecord!=null &&tCheckAcceptRecord.getCheckTime()!=null ){
            templateParam.put("${checkTime}", DateUtils.localDateTimeToStringYear(tCheckAcceptRecord.getCheckTime()));
        }else{
            templateParam.put("${checkTime}", "");
        }
        return wordUtil.generatePdf("/usr/local/project/file/", templateFileName, templateParam, "租赁合同", "/usr/local/project/file/");
    }
    /**
     * 生成预览版合同附件
     */
    @ApiOperation(value = "生成预览版合同附件")
    @PostMapping("/generateContractPreview")
    public R<String> generateContractPreview(@RequestBody TContractDTO dto)
    {
        TContract contract = new TContract();
        BeanUtil.copyProperties(dto,contract);
        return R.ok(generateContract(contract));
    }
    /**
     * 导出
ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java
@@ -1,14 +1,9 @@
package com.ruoyi.system.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseModel;
import io.swagger.annotations.ApiModel;
@@ -17,6 +12,8 @@
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
 * <p>
@@ -183,4 +180,8 @@
    @TableField(exist = false)
    private String instanceId;
    @ApiModelProperty(value = "房屋使用范围")
    @TableField("house_use_scope")
    private String houseUseScope;
}
ruoyi-system/src/main/java/com/ruoyi/system/model/TTenant.java
@@ -96,4 +96,8 @@
    @TableField("credit_code")
    private String creditCode;
    @ApiModelProperty(value = "开户行")
    @TableField("bank_name")
    private String bankName;
}