下载文件接口完善
合同更新接口修改
This commit is contained in:
@@ -13,6 +13,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -101,8 +103,8 @@ public class ContractController implements BusinessControllerMarker {
|
||||
@PostMapping("/download")
|
||||
@Operation(summary = "下载文件")
|
||||
@PreAuthorize("@ss.hasPermission('base:contract:download')")
|
||||
public void download(@RequestBody List<Long> ids) {
|
||||
contractService.download(ids);
|
||||
public ResponseEntity<ByteArrayResource> download(@RequestBody List<Long> ids) {
|
||||
return contractService.download(ids);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.zt.plat.module.contractorder.api.dto.contract.ContractRespDTO;
|
||||
import com.zt.plat.module.contractorder.controller.admin.contract.vo.contract.*;
|
||||
import com.zt.plat.module.contractorder.dal.dataobject.contract.ContractMainDO;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -164,6 +166,7 @@ public interface ContractService {
|
||||
* 下载文件
|
||||
*
|
||||
* @param ids 合同ID集合
|
||||
* @return 压缩文件流
|
||||
*/
|
||||
void download(List<Long> ids);
|
||||
ResponseEntity<ByteArrayResource> download(List<Long> ids);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import com.zt.plat.module.base.controller.admin.templtp.vo.TemplateInstanceDataR
|
||||
import com.zt.plat.module.base.controller.admin.templtp.vo.TemplateInstanceItemRespVO;
|
||||
import com.zt.plat.module.base.dal.dataobject.tmpltp.TemplateInstanceDataDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.tmpltp.TemplateInstanceItemDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.tmpltp.TmplInscBsnRelDO;
|
||||
import com.zt.plat.module.base.dal.mysql.tmpltp.TemplateInstanceDataMapper;
|
||||
import com.zt.plat.module.base.dal.mysql.tmpltp.TemplateInstanceItemMapper;
|
||||
import com.zt.plat.module.base.dal.mysql.tmpltp.TmplInscBsnRelMapper;
|
||||
import com.zt.plat.module.base.service.tmpltp.TemplateInstanceDataService;
|
||||
import com.zt.plat.module.bpm.api.task.BpmProcessInstanceApi;
|
||||
import com.zt.plat.module.bpm.api.task.BpmTaskApi;
|
||||
@@ -40,15 +42,23 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.module.contractorder.enums.ErrorCodeConstants.*;
|
||||
@@ -102,6 +112,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
private SystemRelativityMapper systemRelativityMapper;
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
@Resource
|
||||
private TmplInscBsnRelMapper tmplInscBsnRelMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<ContractMainDO> getContractPage(ContractPageReqVO pageReqVO) {
|
||||
@@ -759,6 +771,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractDetailDO detailDO = BeanUtils.toBean(detail, ContractDetailDO.class);
|
||||
// 设置合同主信息ID
|
||||
detailDO.setContractMainId(id);
|
||||
// 主键
|
||||
detailDO.setId(null);
|
||||
// 保存合同明细
|
||||
contractDetailMapper.insert(detailDO);
|
||||
|
||||
@@ -771,6 +785,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractPlanDO planDO = BeanUtils.toBean(plan, ContractPlanDO.class);
|
||||
// 合同明细主键
|
||||
planDO.setContractDetailId(detailDOId);
|
||||
// 主键
|
||||
planDO.setId(null);
|
||||
// 保存交货计划
|
||||
contractPlanMapper.insert(planDO);
|
||||
});
|
||||
@@ -785,6 +801,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractFormulaDO formulaDO = BeanUtils.toBean(formula, ContractFormulaDO.class);
|
||||
// 合同主键
|
||||
formulaDO.setContractId(id);
|
||||
// 主键
|
||||
formulaDO.setId(null);
|
||||
// 保存价款结算条款
|
||||
contractFormulaMapper.insert(formulaDO);
|
||||
|
||||
@@ -797,6 +815,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractCoefficientDO coefficientDO = BeanUtils.toBean(coefficient, ContractCoefficientDO.class);
|
||||
// 条款主键
|
||||
coefficientDO.setFormulaId(formulaDOId);
|
||||
// 主键
|
||||
coefficientDO.setId(null);
|
||||
// 保存基础系数配置
|
||||
contractCoefficientMapper.insert(coefficientDO);
|
||||
});
|
||||
@@ -808,6 +828,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractGradeDO gradeDO = BeanUtils.toBean(grade, ContractGradeDO.class);
|
||||
// 条款主键
|
||||
gradeDO.setFormulaId(formulaDOId);
|
||||
// 主键
|
||||
gradeDO.setId(null);
|
||||
// 保存品位等级价配置
|
||||
contractGradeMapper.insert(gradeDO);
|
||||
});
|
||||
@@ -819,6 +841,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractDeductDO deductDO = BeanUtils.toBean(deduct, ContractDeductDO.class);
|
||||
// 条款主键
|
||||
deductDO.setFormulaId(formulaDOId);
|
||||
// 主键
|
||||
deductDO.setId(null);
|
||||
// 保存品位等级价配置
|
||||
contractDeductMapper.insert(deductDO);
|
||||
});
|
||||
@@ -830,6 +854,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractPriceDO priceDO = BeanUtils.toBean(price, ContractPriceDO.class);
|
||||
// 条款主键
|
||||
priceDO.setFormulaId(formulaDOId);
|
||||
// 主键
|
||||
priceDO.setId(null);
|
||||
// 保存市场价配置
|
||||
contractPriceMapper.insert(priceDO);
|
||||
});
|
||||
@@ -844,6 +870,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractDemoteDO demoteDO = BeanUtils.toBean(demote, ContractDemoteDO.class);
|
||||
// 设置合同主键
|
||||
demoteDO.setContractId(id);
|
||||
// 主键
|
||||
demoteDO.setId(null);
|
||||
// 保存参数降级规则
|
||||
contractDemoteMapper.insert(demoteDO);
|
||||
});
|
||||
@@ -856,6 +884,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
ContractNotDO notDO = BeanUtils.toBean(not, ContractNotDO.class);
|
||||
// 条款主键
|
||||
notDO.setContractId(id);
|
||||
// 主键
|
||||
notDO.setId(null);
|
||||
// 保存品位不计价规则
|
||||
contractNotMapper.insert(notDO);
|
||||
});
|
||||
@@ -878,11 +908,8 @@ public class ContractServiceImpl implements ContractService {
|
||||
|
||||
// 更新合同主信息
|
||||
int updateNum = contractMainMapper.updateById(newContractMainDO);
|
||||
if (updateNum > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return updateNum > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1359,20 +1386,82 @@ public class ContractServiceImpl implements ContractService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<Long> ids) {
|
||||
public ResponseEntity<ByteArrayResource> download(List<Long> ids) {
|
||||
try {
|
||||
|
||||
// 返回的压缩包
|
||||
ByteArrayOutputStream zipsByte = new ByteArrayOutputStream();
|
||||
ZipOutputStream zips = new ZipOutputStream(zipsByte);
|
||||
|
||||
// 遍历合同ID集合
|
||||
ids.forEach(id -> {
|
||||
|
||||
try {
|
||||
// 查询合同信息
|
||||
ContractMainDO contractMainDO = contractMainMapper.selectById(id);
|
||||
JSONArray fileObjectOther = new JSONArray(contractMainDO.getFileObjectOther());
|
||||
System.out.println(fileObjectOther);
|
||||
CommonResult<FileRespDTO> fileRespDTOResult = fileApi
|
||||
.getFile(fileObjectOther.getJSONObject(0).getLong("id"));
|
||||
});
|
||||
|
||||
// 单个合同文件压缩
|
||||
ByteArrayOutputStream zipByte = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(zipByte);
|
||||
|
||||
// 关联的模版附件查询
|
||||
TmplInscBsnRelDO tmplInscBsnRelDO = tmplInscBsnRelMapper.selectOne("BSN_ID", id);
|
||||
if (tmplInscBsnRelDO != null) {
|
||||
if (StringUtils.isNotEmpty(tmplInscBsnRelDO.getCntt())) {
|
||||
JSONObject cntt = new JSONObject(tmplInscBsnRelDO.getCntt());
|
||||
CommonResult<FileRespDTO> fileRespResult = fileApi
|
||||
.getFile(cntt.getLong("id"));
|
||||
|
||||
zip.putNextEntry(new ZipEntry(System.currentTimeMillis() + fileRespResult.getData().getName()));
|
||||
zip.write(fileRespResult.getData().getContent());
|
||||
zip.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
// 上传模板附件
|
||||
if(StringUtils.isNotBlank(contractMainDO.getFileObject())){
|
||||
JSONArray fileObjects = new JSONArray(contractMainDO.getFileObject());
|
||||
for (int i = 0; i < fileObjects.size(); i++) {
|
||||
JSONObject file = fileObjects.getJSONObject(i);
|
||||
CommonResult<FileRespDTO> fileRespResult = fileApi
|
||||
.getFile(file.getLong("id"));
|
||||
|
||||
zip.putNextEntry(new ZipEntry(System.currentTimeMillis() + fileRespResult.getData().getName()));
|
||||
zip.write(fileRespResult.getData().getContent());
|
||||
zip.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
// 合同其它附件
|
||||
if(StringUtils.isNotBlank(contractMainDO.getFileObjectOther())){
|
||||
JSONArray fileObjectOthers = new JSONArray(contractMainDO.getFileObjectOther());
|
||||
for (int i = 0; i < fileObjectOthers.size(); i++) {
|
||||
JSONObject file = fileObjectOthers.getJSONObject(i);
|
||||
CommonResult<FileRespDTO> fileRespResult = fileApi
|
||||
.getFile(file.getLong("id"));
|
||||
|
||||
zip.putNextEntry(new ZipEntry(System.currentTimeMillis() + fileRespResult.getData().getName()));
|
||||
zip.write(fileRespResult.getData().getContent());
|
||||
zip.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
zip.finish();
|
||||
String zipName = String.format("%s(%s)相关文件.zip", contractMainDO.getContractName(), contractMainDO.getSystemContractNumber());
|
||||
zips.putNextEntry(new ZipEntry(zipName));
|
||||
zips.write(zipByte.toByteArray());
|
||||
zips.closeEntry();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info("添加压缩包异常:" + e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
zips.finish();
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=contract-file-"+ System.currentTimeMillis()+".zip")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(new ByteArrayResource(zipsByte.toByteArray()));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user