Compare commits

...

2 Commits

Author SHA1 Message Date
曹鹏飞 5ee255a1be feat(shopping): 添加报价单导出功能
- 在管理员控制器中新增exportPdf方法用于导出报价单
- 在应用控制器中新增exportPdf方法用于导出报价单
- 添加PDF生成相关依赖包导入
- 实现PDF文件响应和下载功能
- 配置HTTP响应头支持PDF文件传输
- 添加临时PDF资源文件返回机制
2026-03-24 19:02:05 +08:00
曹鹏飞 4c42afc6b9 feat(repository): 更新报价模型配置服务接口和实现
- 在 IQuotationModelConfigService 接口中为 getEffectives 方法添加 configId 参数
- 在 QuotationModelConfigMapper 中同步更新 getEffectives 方法签名
- 重构 QuotationModelConfigMapper.xml 中的 SQL 查询逻辑,使用 LEFT JOIN 替代 INNER JOIN
- 在 QuotationModelConfigServiceImpl 中更新方法实现以匹配新的参数列表
- 在 ShoppingController 中调用时传递新增的 configId 参数
- 在 RatioConfigController 中添加空集合检查以避免 NPE 异常
2026-03-24 16:05:15 +08:00
8 changed files with 115 additions and 37 deletions

View File

@ -3,6 +3,9 @@ package com.nflg.mobilebroken.quotation.controller.admin;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itextpdf.text.pdf.BaseFont;
import com.nflg.mobilebroken.common.constant.STATE;
import com.nflg.mobilebroken.common.exception.NflgException;
import com.nflg.mobilebroken.common.pojo.ApiResult;
import com.nflg.mobilebroken.common.pojo.PageData;
import com.nflg.mobilebroken.common.pojo.request.QuotationAdminSearchRequest;
@ -18,10 +21,20 @@ import com.nflg.mobilebroken.repository.service.IAdminUserService;
import com.nflg.mobilebroken.repository.service.IQuotationShoppingOrderAdjustService;
import com.nflg.mobilebroken.repository.service.IQuotationShoppingOrderService;
import com.nflg.mobilebroken.repository.service.ITBaseCustomerService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.xhtmlrenderer.pdf.ITextRenderer;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
@ -63,4 +76,32 @@ public class AdminShoppingController extends ControllerBase {
.list()
);
}
/**
* 导出报价单
* @param id 报价单ID
*/
@GetMapping("/export")
public ResponseEntity<org.springframework.core.io.Resource> exportPdf(HttpServletResponse response, @RequestParam Long id) {
// response.setContentType(MediaType.APPLICATION_PDF_VALUE);
// String encode = URLEncoder.encode( "demo.pdf", StandardCharsets.UTF_8);
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "inline;filename=" + encode);
// try {
// ITextRenderer renderer = new ITextRenderer();
// renderer.getFontResolver().addFont("fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// renderer.setDocumentFromString(html);
// renderer.layout();
// try (OutputStream outputStream = response.getOutputStream()) {
// renderer.createPDF(outputStream);
// }
// } catch (Exception e) {
// log.error("生成pdf出错", e);
// throw new NflgException(STATE.BusinessError, "生成pdf出错");
// }
org.springframework.core.io.Resource resource = new ClassPathResource("templates/demo.pdf");
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"demo.pdf\"")
.body(resource);
}
}

View File

@ -71,6 +71,7 @@ public class RatioConfigController extends ControllerBase {
TargetUserVO vo = new TargetUserVO();
if (isMarketingDirector) {
List<QuotationModelRatioAgentItemDTO> agentItems = ratioAgentItemService.getEffectives();
if (CollectionUtil.isNotEmpty(agentItems)) {
vo.setAppUsers(
appUserService.lambdaQuery()
.in(AppUser::getId, agentItems.stream().map(QuotationModelRatioAgentItemDTO::getUserId).collect(Collectors.toList()))
@ -83,7 +84,9 @@ public class RatioConfigController extends ControllerBase {
)
.collect(Collectors.toList())
);
}
List<QuotationModelRatioDirectItemDTO> directItems = ratioDirectItemService.getEffectives();
if (CollectionUtil.isNotEmpty(directItems)) {
vo.setAdminUsers(
adminUserService.lambdaQuery()
.in(AdminUser::getId, directItems.stream().map(QuotationModelRatioDirectItemDTO::getUserId).collect(Collectors.toList()))
@ -97,6 +100,7 @@ public class RatioConfigController extends ControllerBase {
.collect(Collectors.toList())
);
}
}
return ApiResult.success(vo);
}

View File

@ -33,6 +33,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.Transactional;
@ -212,7 +213,7 @@ public class ShoppingController extends ControllerBase {
vo.setDiscount(vo.getTotalFee().subtract(vo.getActualFee()));
log.debug("机型【{}】价格为{},优惠{}", request.getModelNo(), vo.getActualFee(), vo.getDiscount());
//获取部件配置
List<ModelConfigEffectiveDTO> parts = modelConfigService.getEffectives(modelPrice.getPriceId(), categoryId, MultilingualUtil.getLanguage());
List<ModelConfigEffectiveDTO> parts = modelConfigService.getEffectives(modelPrice.getConfigId(),modelPrice.getPriceId(), categoryId, MultilingualUtil.getLanguage());
VUtils.trueThrowBusinessError(CollectionUtil.isEmpty(parts)).throwMessage("未获取到部件信息");
vo.setStandardParts(parts.stream()
.filter(part -> part.getParentId() == 0L && part.getType() == 1)
@ -851,4 +852,32 @@ public class ShoppingController extends ControllerBase {
return categoryId;
}
}
/**
* 导出报价单
* @param id 报价单ID
*/
@GetMapping("/export")
public ResponseEntity<org.springframework.core.io.Resource> exportPdf(HttpServletResponse response, @RequestParam Long id) {
// response.setContentType(MediaType.APPLICATION_PDF_VALUE);
// String encode = URLEncoder.encode( "demo.pdf", StandardCharsets.UTF_8);
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "inline;filename=" + encode);
// try {
// ITextRenderer renderer = new ITextRenderer();
// renderer.getFontResolver().addFont("fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// renderer.setDocumentFromString(html);
// renderer.layout();
// try (OutputStream outputStream = response.getOutputStream()) {
// renderer.createPDF(outputStream);
// }
// } catch (Exception e) {
// log.error("生成pdf出错", e);
// throw new NflgException(STATE.BusinessError, "生成pdf出错");
// }
org.springframework.core.io.Resource resource = new ClassPathResource("templates/demo.pdf");
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"demo.pdf\"")
.body(resource);
}
}

View File

@ -23,5 +23,5 @@ public interface QuotationModelConfigMapper extends BaseMapper<QuotationModelCon
IPage<ModelConfigVO> search(ModelConfigSearchRequest request, Page<?> objectPage);
List<ModelConfigEffectiveDTO> getEffectives(Long priceId, Long categoryId, String language);
List<ModelConfigEffectiveDTO> getEffectives(Long configId,Long priceId, Long categoryId, String language);
}

View File

@ -22,5 +22,5 @@ public interface IQuotationModelConfigService extends IService<QuotationModelCon
IPage<ModelConfigVO> search(ModelConfigSearchRequest request);
List<ModelConfigEffectiveDTO> getEffectives(Long priceId, Long categoryId, String language);
List<ModelConfigEffectiveDTO> getEffectives(Long configId,Long priceId, Long categoryId, String language);
}

View File

@ -31,7 +31,7 @@ public class QuotationModelConfigServiceImpl extends ServiceImpl<QuotationModelC
}
@Override
public List<ModelConfigEffectiveDTO> getEffectives(Long priceId, Long categoryId, String language) {
return baseMapper.getEffectives(priceId,categoryId,language);
public List<ModelConfigEffectiveDTO> getEffectives(Long configId,Long priceId, Long categoryId, String language) {
return baseMapper.getEffectives(configId,priceId,categoryId,language);
}
}

View File

@ -28,13 +28,17 @@
</select>
<select id="getEffectives" resultType="com.nflg.mobilebroken.common.pojo.dto.ModelConfigEffectiveDTO">
SELECT qmci.id,qmci.parent_id,qmcil.part_name,qmcil.part_remark,qmci.image_url,qmpia.amount,qmci.type,qmci.optional_type
FROM quotation_model_price qmp
INNER JOIN quotation_model_price_item qmpi ON qmpi.price_id=qmp.id
INNER JOIN quotation_model_config_item qmci ON qmci.unique_id=qmpi.config_item_unique_id
INNER JOIN quotation_model_config_item_language qmcil ON qmcil.config_item_id=qmci.id
INNER JOIN `language` l ON l.id=qmcil.language_id
INNER JOIN quotation_model_price_item_area qmpia ON qmpia.price_item_id=qmpi.id
WHERE qmp.id=#{priceId} AND l.`code`=#{language} AND qmpia.area_id=#{categoryId}
SELECT qmci.id,qmci.parent_id,qmcil.part_name,qmcil.part_remark,qmci.image_url,pp.amount,qmci.type,qmci.optional_type
FROM quotation_model_config_item qmci
LEFT JOIN quotation_model_config_item_language qmcil ON qmcil.config_item_id=qmci.id
LEFT JOIN `language` l ON l.id=qmcil.language_id
LEFT JOIN
(
SELECT qmpi.config_item_unique_id,qmpia.amount
FROM quotation_model_price_item qmpi
LEFT JOIN quotation_model_price_item_area qmpia ON qmpia.price_item_id=qmpi.id
WHERE qmpia.price_id=#{priceId} AND qmpia.area_id=#{categoryId}
) pp ON qmci.unique_id=pp.config_item_unique_id
WHERE qmci.`enable` AND qmci.config_id=#{configId} AND l.`code`=#{language}
</select>
</mapper>