优化
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package org.dromara.cailiaoshebei.controller;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@ -128,6 +129,16 @@ public class BusMrpBaseController extends BaseController {
|
||||
return toAjax(busMrpBaseService.batchAddOrUpdate(dto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取剩余量
|
||||
*/
|
||||
@GetMapping("/remaining")
|
||||
public R<Integer> remaining(Long suppliespriceId) {
|
||||
BigDecimal remaining = busMrpBaseService.remaining(suppliespriceId);
|
||||
BusBillofquantities byId = busBillofquantitiesService.getById(suppliespriceId);
|
||||
return R.ok(byId.getQuantity().subtract(remaining).intValue());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导入物资需求批次计划
|
||||
|
@ -12,6 +12,7 @@ import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -82,4 +83,9 @@ public interface IBusMrpBaseService extends IService<BusMrpBase>{
|
||||
* 导入物资需求批次计划
|
||||
*/
|
||||
Boolean importData(BusMrpExportDto dto);
|
||||
|
||||
/**
|
||||
* 获取物资已有数量
|
||||
*/
|
||||
BigDecimal remaining(Long suppliespriceId);
|
||||
}
|
||||
|
@ -264,6 +264,24 @@ public class BusMrpBaseServiceImpl extends ServiceImpl<BusMrpBaseMapper, BusMrpB
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal remaining(Long suppliespriceId) {
|
||||
|
||||
// 获取数据库中已有的数量
|
||||
List<BusMaterialbatchdemandplan> existingList = planservice.list(
|
||||
Wrappers.lambdaQuery(BusMaterialbatchdemandplan.class)
|
||||
.eq(BusMaterialbatchdemandplan::getSuppliespriceId, suppliespriceId) // 排除当前批次
|
||||
);
|
||||
if(CollectionUtil.isEmpty(existingList)){
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return existingList.stream()
|
||||
.map(BusMaterialbatchdemandplan::getDemandQuantity)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* 总体流程监听(例如: 草稿,撤销,退回,作废,终止,已完成,单任务完成等)
|
||||
* 正常使用只需#processEvent.flowCode=='leave1'
|
||||
|
@ -59,6 +59,8 @@ import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.FileNameMap;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -350,10 +352,12 @@ public class BusPurchaseDocServiceImpl extends ServiceImpl<BusPurchaseDocMapper,
|
||||
String filePath = constant.getBusPurchaseDocFileUrl(purchaseDoc, now) + "/";
|
||||
String fileName = constant.getBusPurchaseDocFileName(purchaseDoc);
|
||||
File file = new File(filePath + fileName);
|
||||
log.info("{}", file.exists());
|
||||
try {
|
||||
// Word → PDF
|
||||
ByteArrayOutputStream pdfOut = new ByteArrayOutputStream();
|
||||
WordprocessingMLPackage wordML = WordprocessingMLPackage.load(file);
|
||||
log.info(String.valueOf(wordML));
|
||||
Docx4J.toPDF(wordML, pdfOut);
|
||||
FileNameMap fileNameMap = URLConnection.getFileNameMap();
|
||||
String createDate = DateUtils.formatDate(purchaseDoc.getCreateTime());
|
||||
@ -397,10 +401,61 @@ public class BusPurchaseDocServiceImpl extends ServiceImpl<BusPurchaseDocMapper,
|
||||
if (purchaseDoc == null) {
|
||||
throw new ServiceException("物料领料单不存在");
|
||||
}
|
||||
// 创建Word
|
||||
this.createWord(purchaseDoc);
|
||||
// 清理OSS上的旧文件
|
||||
// Long pdfFileId = purchaseDoc.getPdfFileId();
|
||||
// if (pdfFileId != null) {
|
||||
// ossService.deleteWithValidByIds(List.of(pdfFileId), true);
|
||||
// }
|
||||
|
||||
// 准备数据
|
||||
List<BusMaterialbatchdemandplan> items = new ArrayList<>();
|
||||
List<BusPlanDocAssociation> planDocAssociationList = planDocAssociationService.lambdaQuery()
|
||||
.eq(BusPlanDocAssociation::getDocId, purchaseDoc.getId())
|
||||
.list();
|
||||
if (CollUtil.isNotEmpty(planDocAssociationList)) {
|
||||
List<Long> planIds = planDocAssociationList.stream()
|
||||
.map(BusPlanDocAssociation::getPlanId)
|
||||
.toList();
|
||||
items = materialbatchdemandplanService.listByIds(planIds);
|
||||
}
|
||||
BusPurchaseDocWordDto data = this.getReplacementDto(purchaseDoc, items);
|
||||
|
||||
// 生成文件并直接写入响应流
|
||||
try (InputStream is = getClass().getClassLoader().getResourceAsStream(constant.PURCHASE_DOC_TEMPLATE_PATH)) {
|
||||
if (is == null) {
|
||||
throw new ServiceException("模板文件不存在");
|
||||
}
|
||||
|
||||
// 配置模板渲染策略
|
||||
LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
|
||||
Configure config = Configure.builder()
|
||||
.bind("items", hackLoopTableRenderPolicy)
|
||||
.build();
|
||||
|
||||
// 编译模板并渲染数据
|
||||
XWPFTemplate template = XWPFTemplate.compile(is, config);
|
||||
template.render(data);
|
||||
|
||||
// 设置响应头信息
|
||||
String fileName = constant.getBusPurchaseDocFileName(purchaseDoc);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" +
|
||||
URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()));
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
||||
// 直接通过模板的write方法写入响应流
|
||||
try (OutputStream os = response.getOutputStream()) {
|
||||
template.write(os);
|
||||
os.flush();
|
||||
}
|
||||
template.close();
|
||||
} catch (IOException e) {
|
||||
log.error("生成Word文件失败", e);
|
||||
throw new OssException("生成Word文件失败,错误信息: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据主键查询详情PDF地址
|
||||
*
|
||||
|
@ -40,7 +40,7 @@ public class DesVolumeFileViewerVo implements Serializable {
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Translation(type = TransConstant.USER_ID_TO_NAME, mapper = "userId")
|
||||
@Translation(type = TransConstant.USER_ID_TO_NICKNAME, mapper = "userId")
|
||||
private String userName;
|
||||
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
package org.dromara.workflow.filter;
|
||||
|
||||
public class RoleCandidateExcludeFilter {
|
||||
}
|
Reference in New Issue
Block a user