luofl
2025-03-24 6fdedfd0837c29bbd4254e7d38337cf82e6e56a6
1.租户数量趋势统计
1个文件已修改
238 ■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java 238 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
@@ -3,6 +3,7 @@
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;
@@ -49,6 +50,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
@@ -297,75 +299,185 @@
        List<TContract> list = contractService.lambdaQuery().in(TContract::getId, dto.getIds()).list();
        List<String> res = new ArrayList<>();
        for (TContract contract : list) {
            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/");
            String url = generateContract(contract);
            res.add(url);
        }
        return R.ok(res);
    }
    private String generateContract(TContract contract) {
        String templateFileName = "1_yzj_租赁合同_个人.docx";
        String contractId = contract.getId();
        TBill firstBill = null;
        TCheckAcceptRecord tCheckAcceptRecord = null;
        if (StringUtils.isNotEmpty(contractId)) {
            firstBill = billService.lambdaQuery()
                    .eq(TBill::getContractId, contractId)
                    .orderByDesc(TBill::getStartTime)
                    .last("limit 1")
                    .one();
            tCheckAcceptRecord = checkAcceptRecordService.lambdaQuery()
                    .eq(TCheckAcceptRecord::getContractId, contractId)
                    .last("limit 1")
                    .one();
        }
        TTenant tenant = null;
        THouse tHouse = null;
        if (StringUtils.isNotEmpty(contract.getTenantId())) {
            tenant = tenantService.getById(contract.getTenantId());
            tHouse = houseService.getById(contract.getHouseId());
        }
        Map<String, Object> templateParam = new HashMap<>(5);
        fill(templateParam, "contractNumber", contract.getContractNumber());
        fill(templateParam, "partyOneName", contract.getPartyOneName());
        fill(templateParam, "partyTwoName", contract.getPartyTwoName());
        if (Objects.nonNull(tenant)) {
            fill(templateParam, "mailAddress", tenant.getMailAddress());
            fill(templateParam, "idCard", tenant.getIdCard());
            fill(templateParam, "residentName", tenant.getResidentName());
            fill(templateParam, "bankNumber", tenant.getBankNumber());
            fill(templateParam, "bankName", tenant.getBankName());
            // 企业、政府机构、国有企业
            if (Objects.nonNull(tenant.getTenantType())
                    && (tenant.getTenantType().equals("2")
                    || tenant.getTenantType().equals("5")
                    || tenant.getTenantType().equals("7"))) {
                fill(templateParam, "creditCode", tenant.getCreditCode());
                fill(templateParam, "legalPerson", tenant.getLegalPerson());
                templateFileName = "1_yzj_租赁合同_企业.docx";
            }
        }
        if (Objects.nonNull(tHouse)) {
            fill(templateParam, "houseAddress", tHouse.getHouseAddress());
            fill(templateParam, "houseArea", tHouse.getHouseArea() + "m²");
        }
        // 日期相关参数处理
        fill(templateParam, "remark", contract.getRemark());
        fill(templateParam, "houseUseScope", contract.getHouseUseScope());
        fill(templateParam, "days", ChronoUnit.DAYS.between(
                contract.getStartTime(), contract.getEndTime()));
        long between = ChronoUnit.DAYS.between(
                contract.getStartTime(), contract.getStartPayTime()) + 1;
        fill(templateParam, "day", between);
        // 财务相关参数处理
        fill(templateParam, "endTimeFree", DateUtils.localDateTimeToStringYear(
                contract.getStartPayTime().plusDays(1)));
        fill(templateParam, "startPayTime", DateUtils.localDateTimeToStringYear(
                contract.getStartPayTime()));
        fill(templateParam, "startTime", DateUtils.localDateTimeToStringYear(
                contract.getStartTime()));
        fill(templateParam, "endTime", DateUtils.localDateTimeToStringYear(
                contract.getEndTime()));
        // 金额格式化处理
        fill(templateParam, "monthRent", "¥" + contract.getMonthRent() + "元");
        fill(templateParam, "monthRentString", "人民币" + NumberToChineseUtils.numberToChinese(
                contract.getMonthRent().setScale(2, RoundingMode.DOWN).doubleValue()));
        String totalYear = Objects.nonNull(contract.getTotalYear())
                ? contract.getTotalYear().toString()
                : "";
        fill(templateParam, "totalYear", "¥" + totalYear + "元");
        String totalYearString = StringUtils.isNotEmpty(totalYear)
                ? NumberToChineseUtils.numberToChinese(
                contract.getTotalYear().setScale(2, RoundingMode.DOWN).doubleValue())
                : "";
        fill(templateParam, "totalYearString", "人民币" + totalYearString);
        // 支付类型处理
        String payType = contract.getPayType().equals("1") ? "月"
                : contract.getPayType().equals("2") ? "季"
                : "年";
        fill(templateParam, "payType", payType);
        // 首期租金处理
        if (firstBill != null) {
            fill(templateParam, "firstRent", "¥" + firstBill.getPayableFeesMoney() + "元");
        } else {
            fill(templateParam, "firstRent", "");
        }
        // 其他财务字段
        fill(templateParam, "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, RoundingMode.DOWN).doubleValue()));
        fill(templateParam, "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, RoundingMode.DOWN)).doubleValue()));
        fill(templateParam, "nextPayTime", payType);
        fill(templateParam, "deposit", "¥" + contract.getDeposit() + "元");
        fill(templateParam, "depositString", NumberToChineseUtils.numberToChinese(
                contract.getDeposit().setScale(2, RoundingMode.DOWN).doubleValue()));
        // 联系方式
        fill(templateParam, "partyOnePerson", contract.getPartyOnePerson());
        fill(templateParam, "partyOnePhone", contract.getPartyOnePhone());
        fill(templateParam, "partyTwoPerson", contract.getPartyTwoPerson());
        fill(templateParam, "partyTwoPhone", contract.getPartyTwoPhone());
        // 验收时间处理
        if (tCheckAcceptRecord != null && tCheckAcceptRecord.getCheckTime() != null) {
            fill(templateParam, "checkTime", DateUtils.localDateTimeToStringYear(
                    tCheckAcceptRecord.getCheckTime()));
        } else {
            fill(templateParam, "checkTime", "");
        }
        return wordUtil.generatePdf(
                "/usr/local/project/file/",
                templateFileName,
                templateParam,
                "租赁合同",
                "/usr/local/project/file/");
    }
    private void fill(Map<String, Object> templateParam, String key, Object value) {
        if (StringUtils.isEmpty(key)){
            throw new RuntimeException("key不能为空");
        }
        templateParam.put(StringUtils.format("${{}}", "contractNumber"), value != null ? value : "");
    }
    /**
     * 生成预览版合同附件
     */
    @ApiOperation(value = "生成预览版合同附件")
    @PostMapping("/generateContractPreview")
    public R<String> generateContractPreview(@RequestBody TContractDTO dto)
    {
        TContract contract = new TContract();
        BeanUtil.copyProperties(dto,contract);
        return R.ok(generateContract(contract));
    }
    /**
     * 导出
     */