新购代码优化

This commit is contained in:
mashuai 2024-08-30 09:11:59 +08:00
parent 8b627bf00b
commit 1cd5525500
4 changed files with 36 additions and 26 deletions

View File

@ -1,6 +1,5 @@
com.bonus.common.security.config.WebMvcConfig
com.bonus.common.security.service.TokenService
com.bonus.common.security.config.MyFilter
com.bonus.common.security.aspect.PreAuthorizeAspect
com.bonus.common.security.aspect.InnerAuthAspect
com.bonus.common.security.handler.GlobalExceptionHandler

View File

@ -153,7 +153,7 @@ public class BpmPurchaseAcceptServiceImpl implements BpmPurchaseAcceptService {
* @return
*/
private boolean areAllStatusesPendingAcceptance(List<Integer> statusList) {
return CollectionUtils.isNotEmpty(statusList) && statusList.stream().allMatch(status -> status.equals(Constants.PENDING_ACCEPTANCE));
return CollectionUtils.isNotEmpty(statusList) && statusList.stream().anyMatch(status -> status.equals(Constants.PENDING_ACCEPTANCE));
}
/**

View File

@ -20,7 +20,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -75,6 +77,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
@Transactional(rollbackFor = Exception.class)
public void downloadQrCode(HttpServletResponse response, PurchaseDto purchaseDto) {
//生成二维码
Set<String> addedEntries = new HashSet<>();
if (purchaseDto.getId() == null && purchaseDto.getPurchaseId() == null) {
throw new RuntimeException("外层id和内层id不能同时为空");
}
@ -88,10 +91,10 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
}
if (purchaseDto.getId() != null) {
//外层二维码下载
handlePurchaseDto(purchaseDto, codeList, statusList, zos, genMonth);
handlePurchaseDto(addedEntries, purchaseDto, codeList, statusList, zos, genMonth);
} else if (purchaseDto.getPurchaseId() != null) {
//内层二维码下载
handlePurchaseId(purchaseDto, codeList, statusList, zos, genMonth);
handlePurchaseId(addedEntries, purchaseDto, codeList, statusList, zos, genMonth);
}
zos.flush();
} catch (WriterException | IOException e) {
@ -109,12 +112,12 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
* @throws IOException
* @throws WriterException
*/
private void handlePurchaseDto(PurchaseDto purchaseDto, List<PurchaseBindDto> codeList, List<Integer> statusList, ZipOutputStream zos, String genMonth) throws IOException, WriterException {
private void handlePurchaseDto(Set<String> addedEntries, PurchaseDto purchaseDto, List<PurchaseBindDto> codeList, List<Integer> statusList, ZipOutputStream zos, String genMonth) throws IOException, WriterException {
for (Integer status : statusList) {
if (status == 1) {
Select(purchaseDto, zos);
Select(addedEntries, purchaseDto, zos);
} else if (status == 0) {
processNotDownloadedDetails(purchaseDto, codeList, zos, genMonth);
processNotDownloadedDetails(addedEntries, purchaseDto, codeList, zos, genMonth);
}
}
}
@ -129,16 +132,16 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
* @throws IOException
* @throws WriterException
*/
private void handlePurchaseId(PurchaseDto purchaseDto, List<PurchaseBindDto> codeList, List<Integer> statusList, ZipOutputStream zos, String genMonth) throws IOException, WriterException {
private void handlePurchaseId(Set<String> addedEntries, PurchaseDto purchaseDto, List<PurchaseBindDto> codeList, List<Integer> statusList, ZipOutputStream zos, String genMonth) throws IOException, WriterException {
if (statusList.get(0) == 1) {
Select(purchaseDto, zos);
Select(addedEntries, purchaseDto, zos);
} else {
int num = getInitialNum(codeList);
List<PurchaseAcceptVo> details = acceptMapper.getDetails(purchaseDto);
if (CollectionUtils.isNotEmpty(details)) {
PurchaseAcceptVo detail = details.get(0);
purchaseDto.setId(detail.getTaskId());
getString(purchaseDto, genMonth, num, zos, detail.getMaterialModel(), detail.getMaterialName(), detail.getTypeId(), detail.getCheckNum());
getString(addedEntries, purchaseDto, genMonth, num, zos, detail.getMaterialModel(), detail.getMaterialName(), detail.getTypeId(), detail.getCheckNum());
extractedUpStatus(purchaseDto);
}
}
@ -166,7 +169,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
* @throws IOException
* @throws WriterException
*/
private void processNotDownloadedDetails(PurchaseDto purchaseDto, List<PurchaseBindDto> codeList, ZipOutputStream zos, String genMonth) throws IOException, WriterException {
private void processNotDownloadedDetails(Set<String> addedEntries, PurchaseDto purchaseDto, List<PurchaseBindDto> codeList, ZipOutputStream zos, String genMonth) throws IOException, WriterException {
int num = getInitialNum(codeList);
List<PurchaseAcceptVo> details = acceptMapper.getDetails(purchaseDto);
if (CollectionUtils.isNotEmpty(details)) {
@ -174,7 +177,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
.filter(detail -> detail.getIsDownload() == 0)
.collect(Collectors.toList());
for (PurchaseAcceptVo detail : notDownloadedDetails) {
getString(purchaseDto, genMonth, num, zos, detail.getMaterialModel(), detail.getMaterialName(), detail.getTypeId(), detail.getCheckNum());
getString(addedEntries, purchaseDto, genMonth, num, zos, detail.getMaterialModel(), detail.getMaterialName(), detail.getTypeId(), detail.getCheckNum());
num += detail.getCheckNum() / Constants.CARDINAL_NUMBER;
}
extractedUpStatus(purchaseDto);
@ -187,7 +190,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
* @param zos
* @throws IOException
*/
private void Select(PurchaseDto purchaseDto, ZipOutputStream zos) throws IOException {
private void Select(Set<String> addedEntries, PurchaseDto purchaseDto, ZipOutputStream zos) throws IOException {
List<QrUrlVo> list = mapper.selectQrCode(purchaseDto);
if (CollectionUtils.isNotEmpty(list)) {
for (QrUrlVo qrUrlVo : list) {
@ -196,7 +199,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
String path = qrUrlVo.getQrUrl();
String qrCode = qrUrlVo.getQrCode();
path = path.replace("filePath", "/data/imw");
extracted(zos, materialModel, materialName, qrCode, path);
extracted(addedEntries, zos, materialModel, materialName, qrCode, path);
}
}
}
@ -223,7 +226,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
* @throws WriterException
* @throws IOException
*/
private void getString(PurchaseDto purchaseDto, String genMonth, int num, ZipOutputStream zos, String materialModel, String materialName, Integer typeId, Integer checkNum) throws WriterException, IOException {
private void getString(Set<String> addedEntries, PurchaseDto purchaseDto, String genMonth, int num, ZipOutputStream zos, String materialModel, String materialName, Integer typeId, Integer checkNum) throws WriterException, IOException {
for (int j = 1; j <= checkNum / Constants.CARDINAL_NUMBER; j++) {
genMonth = genMonth.replace("-", "");
String code = genMonth + "-" + String.format("%5d", num + j).replace(" ", "0");
@ -249,7 +252,7 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
String qrUrl = saveDirectory + code + ".jpg";
PurchaseDto dto = PurchaseDto.builder().id(purchaseDto.getId()).typeId(typeId).qrCode(code).qrUrl(qrUrl).build();
mapper.insert(dto);
extracted(zos, materialModel, materialName, code, qrUrl);
extracted( addedEntries, zos, materialModel, materialName, code, qrUrl);
}
}
@ -262,20 +265,28 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService {
* @param path
* @throws IOException
*/
private void extracted(ZipOutputStream zos, String materialModel, String materialName, String code, String path) throws IOException {
private void extracted(Set<String> addedEntries, ZipOutputStream zos, String materialModel, String materialName, String code, String path) throws IOException {
// 判断路径是否存在
File imageFile = new File(path);
if (!imageFile.exists()) {
return;
}
zos.setLevel(0);
zos.putNextEntry(new ZipEntry("[" + materialModel + "-" + materialName + "]" + code + ".jpg"));
InputStream fis = new FileInputStream(imageFile);
byte[] buffer = new byte[1024];
int r = 0;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
String entryName = "[" + materialModel + "-" + materialName + "]" + code + ".jpg";
if (addedEntries.contains(entryName)) {
System.out.println("Duplicate entry skipped: " + entryName);
return;
}
fis.close();
addedEntries.add(entryName);
zos.setLevel(0);
zos.putNextEntry(new ZipEntry(entryName));
try (InputStream fis = new FileInputStream(imageFile)) {
byte[] buffer = new byte[1024];
int r;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
}
zos.closeEntry();
}
}

View File

@ -144,7 +144,7 @@
bp.task_id AS id,
bp.id AS detailId,
mt1.`name` AS materialName,
mt.`name` AS specificationCode,
mt.`name` AS materialModel,
bp.type_id AS typeId,
sda.dict_label AS unitName,
bp.purchase_price AS purchasePrice,