Browse Source

1.增加模板生成

training
pref_mail@163.com 2 years ago
parent
commit
671ec12b58
  1. 40
      blade-biz-common/src/main/java/org/springblade/common/utils/TemplateUtil.java
  2. 4
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/controller/DistributionDeliveryListController.java
  3. 2
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionDeliveryListService.java
  4. 46
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionDeliveryListServiceImpl.java

40
blade-biz-common/src/main/java/org/springblade/common/utils/TemplateUtil.java

@ -28,24 +28,52 @@ public class TemplateUtil {
* 通过远程URL地址获取模板 * 通过远程URL地址获取模板
* 此方法可以通过URL加载存储在远程服务器上的模板 * 此方法可以通过URL加载存储在远程服务器上的模板
* *
* @param template * @param name 模板名称
* @param map * @param map 填充内容
* @param url * @param url 模板地址
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static String getTemplateByUrl(String template, Map<String, Object> map, String url) throws Exception { public static String getTemplateByUrl(String name, Map<String, Object> map, String url) throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_30); Configuration cfg = new Configuration(Configuration.VERSION_2_3_30);
ByteArrayTemplateLoader byteArrayTemplateLoader = new ByteArrayTemplateLoader(); ByteArrayTemplateLoader byteArrayTemplateLoader = new ByteArrayTemplateLoader();
InputStream initialStream = getInputStreamByGet(url); InputStream initialStream = getInputStreamByGet(url);
byteArrayTemplateLoader.putTemplate(template, byteArrayTemplateLoader.putTemplate(name,
IOUtils.toByteArray(initialStream)); IOUtils.toByteArray(initialStream));
cfg.setTemplateLoader(byteArrayTemplateLoader); cfg.setTemplateLoader(byteArrayTemplateLoader);
cfg.setDefaultEncoding("UTF-8"); cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false); cfg.setLogTemplateExceptions(false);
cfg.setClassicCompatible(true); cfg.setClassicCompatible(true);
Template temp = cfg.getTemplate(template); Template temp = cfg.getTemplate(name);
StringWriter stringWriter = new StringWriter();
temp.process(map, stringWriter);
stringWriter.flush();
stringWriter.close();
String result = stringWriter.getBuffer().toString();
return result;
}
/**
* 根据模板填充模板内容
* @param name 模板名称
* @param map 填充内容
* @param temlate
* @return
* @throws Exception
*/
public static String popTemplate(String name, Map<String, Object> map, String temlate) throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_30);
ByteArrayTemplateLoader byteArrayTemplateLoader = new ByteArrayTemplateLoader();
byteArrayTemplateLoader.putTemplate(name,
temlate.getBytes());
cfg.setTemplateLoader(byteArrayTemplateLoader);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
cfg.setClassicCompatible(true);
Template temp = cfg.getTemplate(name);
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
temp.process(map, stringWriter); temp.process(map, stringWriter);
stringWriter.flush(); stringWriter.flush();

4
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/controller/DistributionDeliveryListController.java

@ -346,10 +346,10 @@ public class DistributionDeliveryListController extends BladeController {
@PostMapping("/printBatch") @PostMapping("/printBatch")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "批量打印") @ApiOperation(value = "批量打印")
public R<PrintPreviewVO> printBatch(@ApiParam(value = "主键集合", required = true) @RequestParam String ids ,@ApiParam(value = "打印类型", required = true) @RequestParam Integer type) { public R<List<PrintPreviewVO>> printBatch(@ApiParam(value = "主键集合", required = true) @RequestParam String ids ,@ApiParam(value = "打印类型", required = true) @RequestParam Integer type) {
try { try {
PrintPreviewVO printPreviewVOS = distributionDeliveryListService.printBatch(ids,type); List<PrintPreviewVO> printPreviewVOS = distributionDeliveryListService.printBatch(ids,type);
return R.data(printPreviewVOS); return R.data(printPreviewVOS);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);

2
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionDeliveryListService.java

@ -225,5 +225,5 @@ public interface IDistributionDeliveryListService extends BaseService<Distributi
* @param ids * @param ids
* @return * @return
*/ */
PrintPreviewVO printBatch(String ids,Integer type) throws Exception; List<PrintPreviewVO> printBatch(String ids,Integer type) throws Exception;
} }

46
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionDeliveryListServiceImpl.java

@ -3155,7 +3155,7 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
@Override @Override
public PrintPreviewVO printBatch(String ids,Integer type) throws Exception { public List<PrintPreviewVO> printBatch(String ids, Integer type) throws Exception {
PrintPreviewVO printPreviewVO = new PrintPreviewVO(); PrintPreviewVO printPreviewVO = new PrintPreviewVO();
@ -3163,21 +3163,24 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
BasicPrintTemplateEntity template = getPrintTemplate(type); BasicPrintTemplateEntity template = getPrintTemplate(type);
String html = TemplateUtil.getTemplateByUrl(template.getTemplateUrl()); String html = TemplateUtil.getTemplateByUrl(template.getTemplateUrl());
printPreviewVO.setTemplateHtml(html); // printPreviewVO.setTemplateHtml(html);
printPreviewVO.setTemplateId(template.getId()); // printPreviewVO.setTemplateId(template.getId());
String[] idArray = ids.split(","); String[] idArray = ids.split(",");
if (ObjectUtils.isNull(idArray)) { if (ObjectUtils.isNull(idArray)) {
throw new ServiceException("参数错误"); throw new ServiceException("参数错误");
} }
if (1 == type) { if (1 == type) {
handleShiPeiData(printPreviewVO,idArray);
return handleShiPeiData(template, idArray,html);
} else if (2 == type) { } else if (2 == type) {
handleShangPeiData(printPreviewVO, idArray); handleShangPeiData(printPreviewVO, idArray);
} else { } else {
log.warn("###########printBatch: 未知的打印类型"); log.warn("###########printBatch: 未知的打印类型");
throw new CustomerException(403, "未知的打印类型"); throw new CustomerException(403, "未知的打印类型");
} }
return printPreviewVO; return null;
} }
private void handleShangPeiData(PrintPreviewVO printPreviewVO, String[] idArray) { private void handleShangPeiData(PrintPreviewVO printPreviewVO, String[] idArray) {
@ -3185,7 +3188,17 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
} }
private void handleShiPeiData(PrintPreviewVO printPreviewVO,String[] idArray){ /**
* 得到填充内容
* @param template
* @param idArray
* @param html
* @return
* @throws Exception
*/
private List<PrintPreviewVO> handleShiPeiData(BasicPrintTemplateEntity template, String[] idArray,String html) throws Exception {
List<PrintPreviewVO> result = new ArrayList<>();
List<Map> data = new ArrayList<>(); List<Map> data = new ArrayList<>();
for (String id : idArray) { for (String id : idArray) {
@ -3208,7 +3221,7 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
for (DistributionReservationEntity distributionReservationEntity : distributionReservationEntityList) { for (DistributionReservationEntity distributionReservationEntity : distributionReservationEntityList) {
map.put("配送单号", distributionReservationEntity.getReservationCode()); map.put("配送单号", distributionReservationEntity.getReservationCode());
// todo 商场电话是否需要查询商场信息得到电话 // todo 查询运单的收货人电话
map.put("商场电话", distributionReservationEntity.getReservationCode()); map.put("商场电话", distributionReservationEntity.getReservationCode());
map.put("送货日期", DateUtil.format(distributionReservationEntity.getReservationDate(), "yyyy-MM-dd") + " 全天"); map.put("送货日期", DateUtil.format(distributionReservationEntity.getReservationDate(), "yyyy-MM-dd") + " 全天");
@ -3222,24 +3235,24 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
// 通过预约单查询预约下面的订单 --1 或者 库存品 --2 // 通过预约单查询预约下面的订单 --1 或者 库存品 --2
List<Map<String, Object>> spaclOrderList = buildSpaclOrders(distributionReservationEntity, 1); List<Map<String, Object>> spaclOrderList = buildSpaclOrders(distributionReservationEntity, 1);
map.put("定制品集合", spaclOrderList); map.put("定制品集合", spaclOrderList);
map.put("备注", distributionReservationEntity.getRemarks()); map.put("备注", distributionReservationEntity.getRemarks());
} }
map.put("送货司机", byId.getVehicleName() + "/" + byId.getDriverName());
map.put("送货司机", byId.getTrainNumber() + "/" + byId.getDriverName());
data.add(map); data.add(map);
String popHtml =TemplateUtil.popTemplate("市配配送单",map,html);
PrintPreviewVO printPreviewVO = new PrintPreviewVO();
printPreviewVO.setTemplateId(template.getId());
printPreviewVO.setTemplateHtml(popHtml);
result.add(printPreviewVO);
} }
printPreviewVO.setDataList(data);
return result;
} }
@ -3257,7 +3270,6 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
} }
/** /**
* 构建预约单下面的订单信息 * 构建预约单下面的订单信息
* *

Loading…
Cancel
Save