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