| | |
| | | return baseMapper.pageScope(page,queryDTO, DataScope.of("comp_id")); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(DateUtil.beginOfQuarter(DateUtil.parseDate("2026-06-05"))); |
| | | System.out.println(DateUtil.endOfQuarter(DateUtil.parseDate("2026-09-30"))); |
| | | System.out.println(DateUtil.betweenMonth(DateUtil.beginOfQuarter(DateUtil.parseDate("2026-06-05")), |
| | | DateUtil.endOfQuarter(DateUtil.parseDate("2026-09-30")),true)); |
| | | @Override |
| | | public void exportContractTFGSGYPMMWord(Long id, HttpServletResponse response) { |
| | | Contract contract = baseMapper.selectById(id); |
| | | List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId, id).orderByAsc(ContractSubjectMatter::getCreateTime)); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //合同基本信息 |
| | | map.put("partyA", contract.getPartyA()); |
| | | map.put("partyB", contract.getPartyB()); |
| | | map.put("contractNo", contract.getContractNo()); |
| | | map.put("signPlace", contract.getSignPlace()); |
| | | map.put("signDate", DateUtil.formatDate(contract.getSignDate())); |
| | | map.put("signDateYMD", DateUtil.format(contract.getSignDate(), DatePattern.CHINESE_DATE_PATTERN)); |
| | | map.put("total", contract.getAmount()); |
| | | map.put("amountWords", Convert.digitToChinese(contract.getAmount())); |
| | | //标的物 |
| | | List<Map<String, Object>> items = new ArrayList<>(); |
| | | List<RowRenderData> dataList = new ArrayList<>(); |
| | | AtomicReference<Integer> no = new AtomicReference<>(0); |
| | | subjectMatterList.stream().forEach(contractSubjectMatter -> { |
| | | Map<String, Object> item = new HashMap<>(); |
| | | item.put("materialName", contractSubjectMatter.getMaterialName()); |
| | | item.put("guige", contractSubjectMatter.getSpecification()); |
| | | item.put("unit", contractSubjectMatter.getUnit()); |
| | | item.put("quantity", contractSubjectMatter.getQuantity()); |
| | | item.put("unitPrice", contractSubjectMatter.getUnitPrice()); |
| | | item.put("price", contractSubjectMatter.getTotalAmount()); |
| | | |
| | | items.add(item); |
| | | no.updateAndGet(v -> v + 1); |
| | | }); |
| | | map.put("items", items); |
| | | //定制方 |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | map.put("companyName", customer.getRegisterName()); |
| | | map.put("legalPerson", customer.getLegalPerson()); |
| | | map.put("contactPhone", customer.getContactPhone()); |
| | | map.put("bankName", customer.getBankName()); |
| | | map.put("bankAccount", customer.getBankAccount()); |
| | | |
| | | //承揽方 |
| | | R<SysDept> r = remoteDeptService.getById(contract.getPartyBId()); |
| | | SysDept dept = r.getData(); |
| | | map.put("orgName", dept.getOrgName()); |
| | | map.put("legalPerson1", StrUtil.isNotEmpty(dept.getLegalPerson()) ? dept.getLegalPerson() : ""); |
| | | map.put("entrustedAgent", StrUtil.isNotEmpty(dept.getLegalPerson()) ? "" : dept.getEntrustedAgent()); |
| | | map.put("orgContact", dept.getOrgContact()); |
| | | map.put("orgBank", dept.getOrgBank()); |
| | | map.put("orgBankAccount", dept.getOrgBankAccount()); |
| | | |
| | | //生成文件名 |
| | | Long time = new Date().getTime(); |
| | | // 生成的word格式 |
| | | String formatSuffix = ".docx"; |
| | | // 拼接后的文件名 |
| | | String fileName = time + formatSuffix;//文件名 带后缀 |
| | | //导出word |
| | | try { |
| | | // 1. 加载模版 |
| | | // 假设模版在 resources/templates/template.docx |
| | | ClassPathResource resource = new ClassPathResource("template/tfgs/tfgsgypmmht.docx"); |
| | | // 配置列表策略 |
| | | Configure config = Configure.builder() |
| | | .bind("items", new LoopRowTableRenderPolicy()) // 将 items 绑定到行循环策略 |
| | | .build(); |
| | | // 2. 编译并渲染数据 |
| | | XWPFTemplate xwpfTemplate = XWPFTemplate.compile(resource.getInputStream(), config).render(map); |
| | | |
| | | // 3. 设置响应头 |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".docx"); |
| | | |
| | | // 4. 写入输出流 |
| | | OutputStream out = response.getOutputStream(); |
| | | xwpfTemplate.write(out); |
| | | out.flush(); |
| | | out.close(); |
| | | xwpfTemplate.close(); // 重要:关闭模版释放资源 |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |