eladmin-master/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
@@ -351,6 +351,24 @@ } } /** * 下载ZIP */ public static void downloadZip(ByteArrayOutputStream byteArrayOutputStream, HttpServletResponse response) throws IOException { // response为HttpServletResponse对象 response.setContentType("application/zip"); // test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 response.setHeader("Content-Disposition", "attachment;filename=file.zip"); // ServletOutputStream ServletOutputStream out = response.getOutputStream(); // 写入 out.write(byteArrayOutputStream.toByteArray()); // flush out.flush(); //此处记得关闭输出Servlet流 IoUtil.close(out); } public static String getMd5(File file) { return getMd5(getByte(file)); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/domain/Contract.java
@@ -128,6 +128,10 @@ @ApiModelProperty(value = "合同终版文件") private String relatedDocumentsFinal; @Column(name = "`related_documents_attachment`") @ApiModelProperty(value = "合同附件") private String relatedDocumentsAttachment; @Column(name = "`contract_status`") @ApiModelProperty(value = "合同状态") private String contractStatus; @@ -136,6 +140,10 @@ @ApiModelProperty(value = "验收状态") private String acceptStatus; @Column(name = "`warning_status`") @ApiModelProperty(value = "预警状态") private Integer warningStatus; @Column(name = "`remarks`") @ApiModelProperty(value = "备注信息") private String remarks; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/rest/ContractController.java
@@ -15,22 +15,23 @@ */ package me.zhengjie.modules.contract.rest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import me.zhengjie.annotation.Log; import me.zhengjie.modules.contract.domain.Contract; import me.zhengjie.modules.contract.service.ContractService; import me.zhengjie.modules.contract.service.dto.ContractQueryCriteria; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * @website https://eladmin.vip @@ -159,6 +160,15 @@ return new ResponseEntity<>(contractService.receivePaymentTotalMoney(criteria),HttpStatus.OK); } @PostMapping(value = "/addWarningStatus") @Log("添加预警") @ApiOperation("添加预警") @PreAuthorize("@el.check('contract:edit')") public ResponseEntity<Object> addWarningStatus(@RequestBody Long[] ids) { contractService.addWarningStatus(ids); return new ResponseEntity<>(HttpStatus.OK); } @PostMapping(value = "/upload") @Log("批量导入合同详情") @ApiOperation("批量导入合同详情") @@ -166,4 +176,12 @@ public ResponseEntity<Object> batchUpload(@RequestParam MultipartFile file){ return new ResponseEntity<>(contractService.batchUpload(file), HttpStatus.OK); } @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/downloadContractAttachments") @PreAuthorize("@el.check('contract:download')") public void downloadContractAttachments(HttpServletResponse response, Long id) { contractService.downloadContractAttachments(id, response); } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/ContractService.java
@@ -21,11 +21,11 @@ import org.springframework.data.domain.Pageable; import org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; import java.util.Map; import java.util.List; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; /** * @website https://eladmin.vip @@ -146,4 +146,19 @@ * @return Map<String, Object> */ Map<String, Object> batchUpload(MultipartFile file); /** * 预警 * @param ids * @return */ void addWarningStatus(Long[] ids); /** * 下载合同附件 * * @param id * @return Map<String, Object> */ void downloadContractAttachments(Long id, HttpServletResponse response); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractDto.java
@@ -98,12 +98,18 @@ /** 合同终版文件 */ private String relatedDocumentsFinal; /** 合同附件 */ private String relatedDocumentsAttachment; /** 合同状态 */ private String contractStatus; /** 验收状态 */ private String acceptStatus; /** 预警状态 */ private Integer warningStatus; /** 备注信息 */ private String remarks; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java
@@ -15,16 +15,23 @@ */ package me.zhengjie.modules.contract.service.impl; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import lombok.RequiredArgsConstructor; import me.zhengjie.config.FileProperties; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.constant.ChinaArea; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.contract.domain.*; import me.zhengjie.modules.contract.repository.*; import me.zhengjie.modules.contract.service.dto.*; import me.zhengjie.modules.contract.service.ContractService; import me.zhengjie.modules.contract.service.dto.ContractDto; import me.zhengjie.modules.contract.service.dto.ContractFirstDto; import me.zhengjie.modules.contract.service.dto.ContractQueryCriteria; import me.zhengjie.modules.contract.service.dto.ContractSecondDto; import me.zhengjie.modules.contract.service.mapstruct.ContractMapper; import me.zhengjie.modules.system.domain.Dict; import me.zhengjie.modules.system.domain.DictDetail; import me.zhengjie.modules.system.domain.SysCompany; @@ -32,15 +39,14 @@ import me.zhengjie.modules.system.repository.DictRepository; import me.zhengjie.modules.system.repository.SysCompanyRepository; import me.zhengjie.utils.*; import lombok.RequiredArgsConstructor; import me.zhengjie.modules.contract.service.ContractService; import me.zhengjie.modules.contract.service.mapstruct.ContractMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.math.BigDecimal; import java.sql.Timestamp; import java.text.ParseException; @@ -49,10 +55,10 @@ import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.*; import java.io.IOException; import java.util.function.Function; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** * @website https://eladmin.vip @@ -1474,4 +1480,75 @@ return false; } } /** * 预警 * * @param ids * @return */ @Override public void addWarningStatus(Long[] ids) { for (Long id : ids) { Contract contract = contractRepository.findById(id).orElseGet(Contract::new); if (contract.getWarningStatus() != null) { if (contract.getWarningStatus() == 0) { contract.setWarningStatus(1); } else { contract.setWarningStatus(0); } } else { contract.setWarningStatus(1); } contractRepository.save(contract); } } /** * 下载合同附件 * * @param id * @return Map<String, Object> */ @Override public void downloadContractAttachments(Long id, HttpServletResponse response) { ByteArrayOutputStream byteArrayOutputStream = null; ZipOutputStream zipOutputStream = null; FileInputStream fis = null; BufferedInputStream bis = null; // 合同 Contract contract = contractRepository.findById(id).orElseGet(Contract::new); try { byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); String relatedDocumentsAttachment = contract.getRelatedDocumentsAttachment(); String[] attachments = relatedDocumentsAttachment.split(","); for (String attachment : attachments) { if (StringUtils.isNotBlank(attachment)) { String fileName = attachment.substring(attachment.lastIndexOf("/") + 1); String suffix = FileUtil.getExtensionName(fileName); String type = FileUtil.getFileType(suffix); File file = new File(properties.getPath().getPath() + type + File.separator + fileName); fis = new FileInputStream(file); bis = new BufferedInputStream(fis); ZipEntry zipEntry = new ZipEntry(fileName); zipOutputStream.putNextEntry(zipEntry); byte[] buffer = new byte[1024]; int length; while ((length = bis.read(buffer)) > 0) { zipOutputStream.write(buffer, 0, length); } zipOutputStream.flush(); zipOutputStream.closeEntry(); } } IoUtil.close(zipOutputStream); FileUtil.downloadZip(byteArrayOutputStream, response); } catch (Exception e) { throw new BadRequestException(e.getMessage()); } finally { IoUtil.close(zipOutputStream); IoUtil.close(byteArrayOutputStream); } } } eladmin-web-master/src/api/contract/contract.js
@@ -89,4 +89,20 @@ }) } export function addWarningStatus(ids) { return request({ url: 'api/contract/addWarningStatus', method: 'post', data: ids }) } export function downloadContractAttachments(params) { return request({ url: 'api/contract/downloadContractAttachments' + '?' + qs.stringify(params, { indices: false }), method: 'get', responseType: 'blob' }) } export default { getAll, add, edit, del } eladmin-web-master/src/views/contract/contract/index.vue
@@ -126,6 +126,18 @@ > 查看分配 </el-button> <el-button slot="right" v-permission="permission.edit" class="filter-item" size="mini" type="success" icon="el-icon-edit" :loading="addWarningStatusLoading" :disabled="crud.selections.length === 0" style="margin-left: 4px !important;" @click="addWarningStatus(crud.selections)" >预警</el-button> </crudOperation> <el-row :gutter="40" style="color: red; font-weight: bolder;"> <el-col :xs="12" :sm="12" :lg="6"> @@ -302,6 +314,9 @@ <el-form-item label="合同终版文件" prop="relatedDocumentsFinal"> <file-upload :key="random" ref="fileFinalUpload" :file-url="form.relatedDocumentsFinal == null || form.relatedDocumentsFinal === '' ? null : form.relatedDocumentsFinal" :limit="5" @fileInfo="getFinalFileInfo" /> </el-form-item> <el-form-item label="合同附件" prop="relatedDocumentsAttachment"> <file-upload :key="random" ref="fileAttachmentUpload" :file-url="form.relatedDocumentsAttachment == null || form.relatedDocumentsAttachment === '' ? null : form.relatedDocumentsAttachment" :limit="5" @fileInfo="getAttachmentFileInfo" /> </el-form-item> <el-form-item label="合同状态" prop="contractStatus"> <el-select v-model="form.contractStatus" filterable placeholder="请选择" style="width: 200px;"> <el-option @@ -351,7 +366,7 @@ </div> </el-dialog> <!--表格渲染--> <el-table ref="table" v-loading="crud.loading" :data="crud.data" stripe size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler"> <el-table ref="table" v-loading="crud.loading" :data="crud.data" stripe size="small" style="width: 100%;" :row-class-name="warningRowClassName" @selection-change="crud.selectionChangeHandler"> <el-table-column type="selection" width="55" /> <el-table-column fixed="left" type="expand"> <template slot-scope="props"> @@ -518,6 +533,11 @@ </template> </el-table-column> </el-table-column> <el-table-column label="合同附件" width="100" align="center"> <template slot-scope="scope"> <el-button type="success" icon="el-icon-download" :loading="downloadAttachmentLoading" @click="toDownloadContractAttachments(scope.row.contractId)" /> </template> </el-table-column> <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注信息" width="100" /> <el-table-column :show-overflow-tooltip="true" prop="acceptStatus" label="验收状态" width="100"> <template slot-scope="scope"> @@ -636,11 +656,13 @@ import constant from '../../../utils/constant' import { contractTotalMoney, contractDelayTotalAmount, contractDelayTotalMoney, advancePaymentTotalMoney } from '@/api/contract/contract' import { serviceTotalMoney, serviceDelayTotalAmount, serviceDelayTotalMoney, receivePaymentTotalMoney } from '@/api/contract/contract' import { addWarningStatus, downloadContractAttachments } from '@/api/contract/contract' import Dict from '@/components/Dict/Dict' import { mapGetters } from 'vuex' import { getToken } from '@/utils/auth' import { downloadFile } from '@/utils/index' const defaultForm = { contractId: null, contractNumber: null, contractName: null, firstId: null, secondId: null, signDate: null, startDate: null, endDate: null, contractAreaCode: null, contractArea: null, contractType: null, contractSecondType: null, contractContent: null, contractAmount: null, contractPaymentDate: null, contractPaymentState: null, serviceStartsDate: null, serviceAmount: null, servicePaymentDate: null, servicePaymentState: null, relatedDocumentsFirst: null, relatedDocumentsFinal: null, contractStatus: null, acceptStatus: null, remarks: null, createBy: null, updateBy: null, createTime: null, updateTime: null } const defaultForm = { contractId: null, contractNumber: null, contractName: null, firstId: null, secondId: null, signDate: null, startDate: null, endDate: null, contractAreaCode: null, contractArea: null, contractType: null, contractSecondType: null, contractContent: null, contractAmount: null, contractPaymentDate: null, contractPaymentState: null, serviceStartsDate: null, serviceAmount: null, servicePaymentDate: null, servicePaymentState: null, relatedDocumentsFirst: null, relatedDocumentsFinal: null, relatedDocumentsAttachment: null, contractStatus: null, remarks: null, createBy: null, updateBy: null, createTime: null, updateTime: null } export default { name: 'InServiceContract', components: { pagination, crudOperation, rrOperation, udOperation, moneyInput, fileUpload, DateRangePicker }, @@ -850,6 +872,10 @@ divideStatus: false, // 分配表单加载 divideLoading: false, // 分配表单加载 addWarningStatusLoading: false, // 分配表单加载 downloadAttachmentLoading: false, // 分配表单数据 divideForm: { contractId: null, contractName: null, projectId: null, fundType: null, allocatedAmount: null }, // 分配表单验证 @@ -991,6 +1017,8 @@ that.$refs.fileFirstUpload.submit() // 通过“that.$refs.fileFinalUpload”找到子页面,“submit”是子页面的方法。 that.$refs.fileFinalUpload.submit() // 通过“that.$refs.fileAttachmentUpload”找到子页面,“submit”是子页面的方法。 that.$refs.fileAttachmentUpload.submit() }, // 获取文件信息 getFirstFileInfo(info) { @@ -1050,13 +1078,42 @@ } } }, // 获取文件信息 getAttachmentFileInfo(info) { const that = this // 判断返回数据 if (info.length === 0) { // 表单文件路径赋值 that.crud.form.relatedDocumentsAttachment = null // 表单提交 that.referSubmitCU() // 终止 return } // 循环返回数据 for (let i = 0; i < info.length; i++) { // 判断循环下标 if (i === 0) { // 表单文件路径赋值 that.crud.form.relatedDocumentsAttachment = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName } else { // 表单文件路径赋值 that.crud.form.relatedDocumentsAttachment += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName } // 判断循环是否结束 if (i === info.length - 1) { // 表单提交 that.referSubmitCU() } } }, // 表单提交 referSubmitCU() { const that = this // 提交触发次数自增 that.triggerCount++ // 判断提交触发次数 if (that.triggerCount === 2) { if (that.triggerCount === 3) { // 表单提交 that.crud.submitCU() } @@ -1342,11 +1399,53 @@ duration: 2500 }) that.uploadDialog.loading = false }, // 预警 addWarningStatus(data) { this.addWarningStatusLoading = true const ids = [] if (data instanceof Array) { data.forEach(val => { ids.push(val['contractId']) }) } else { ids.push(data['contractId']) } // 添加预警 addWarningStatus(ids).then(() => { this.addWarningStatusLoading = false // 消息提示 this.crud.notify('添加预警成功', CRUD.NOTIFICATION_TYPE.SUCCESS) // 刷新页面 this.crud.refresh() }).catch(() => { this.addWarningStatusLoading = false }) }, // 预警 warningRowClassName({ row, rowIndex }) { if (row.warningStatus === 1) { return 'warning-row' } else { return '' } }, toDownloadContractAttachments(id) { this.downloadAttachmentLoading = true // 添加预警 downloadContractAttachments({ 'id': id }).then(result => { downloadFile(result, '合同附件', 'zip') this.downloadAttachmentLoading = false }).catch(() => { this.downloadAttachmentLoading = false }) } } } </script> <style scoped> <style> .warning-row td { background-color: #F9D7BC !important; } </style>