MeiTuanSgConvertPrint.java 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.ydd.app.service.impl;
  2. import com.ydd.third.common.utils.DateUtils;
  3. import com.ydd.third.common.vo.waimai.MeituanSgOrderResultVo;
  4. import com.ydd.third.print.request.PrintOrderActDto;
  5. import com.ydd.third.print.request.PrintOrderDto;
  6. import com.ydd.third.waimai.meituanSg.vo.SgOrderDetailVo;
  7. import com.ydd.third.waimai.meituanSg.vo.SgOrderExtraVo;
  8. import org.apache.commons.collections4.CollectionUtils;
  9. import java.io.UnsupportedEncodingException;
  10. import java.math.BigDecimal;
  11. import java.net.URLDecoder;
  12. import java.util.ArrayList;
  13. import java.util.Date;
  14. import java.util.List;
  15. import java.util.stream.Collectors;
  16. /**
  17. * Demo class
  18. *
  19. * @author 14027
  20. * @date 2021/11/10 10:37
  21. */
  22. public class MeiTuanSgConvertPrint {
  23. public static PrintOrderDto convert(MeituanSgOrderResultVo orderVo) throws UnsupportedEncodingException {
  24. PrintOrderDto dto = new PrintOrderDto();
  25. dto.setDaySeq(orderVo.getDaySeq()+"");
  26. dto.setOrderSource("美团闪购外卖");
  27. dto.setShopName(orderVo.getWmPoiName());
  28. long createTime =orderVo.getCtime()*1000;
  29. dto.setCreateTime(DateUtils.format(new Date(createTime),DateUtils.DATE_TIME_PATTERN));
  30. dto.setIsBook(orderVo.getDeliveryTime()==0?0:1);
  31. long deliveryTime =orderVo.getDeliveryTime()*1000L;
  32. String deliverTimeStr = DateUtils.format( new Date(deliveryTime),"MM月dd日 HH:mm")+"送达";
  33. dto.setDeliveryTime(dto.getIsBook()==1?deliverTimeStr:"");
  34. dto.setOutOrderId(orderVo.getWmOrderIdView());
  35. //优惠信息
  36. List<PrintOrderActDto> actDtos = new ArrayList<>();
  37. List<SgOrderExtraVo> list = orderVo.getExtrasList();
  38. if(CollectionUtils.isNotEmpty(list)){
  39. for(SgOrderExtraVo vo:list){
  40. if(vo!=null&&vo.getRemark()!=null){
  41. if(vo!=null&&vo.getRemark()!=null){
  42. PrintOrderActDto actDto = new PrintOrderActDto();
  43. actDto.setAmount(vo.getReduceFee()+"");
  44. actDto.setName(vo.getRemark());
  45. actDto.setType(vo.getType()+"");
  46. actDtos.add(actDto);
  47. }
  48. }
  49. }
  50. }
  51. actDtos = merge(actDtos);
  52. dto.setActDtos(actDtos);
  53. dto.setDeliverFee(orderVo.getShippingFee()+"");
  54. BigDecimal boxFee = BigDecimal.ZERO;
  55. if (CollectionUtils.isNotEmpty(orderVo.getDetailList())) {
  56. for (SgOrderDetailVo vo : orderVo.getDetailList()) {
  57. boxFee = vo.getBoxPrice().multiply(vo.getBoxNum());
  58. }
  59. }
  60. dto.setBoxFee(boxFee.toString());
  61. dto.setOriginalPrice(orderVo.getOriginalPrice());
  62. dto.setTotalPrice(orderVo.getTotal());
  63. if (orderVo.getCaution().contains("收餐人隐私号")){
  64. dto.setCaution(URLDecoder.decode(orderVo.getCaution(), "Utf-8").substring(0,orderVo.getCaution().indexOf("收餐人隐私号")));
  65. }else {
  66. dto.setCaution(URLDecoder.decode(orderVo.getCaution(), "Utf-8"));
  67. }
  68. // if (!orderVo.getLogisticsCode().equals("0000") && !orderVo.getLogisticsCode().equals("5001") && !orderVo.getLogisticsCode().equals("00009003")){
  69. //// String addRess = orderVo.getRecipientAddressDesensitization().replaceAll("\\d+", "*");
  70. // dto.setRecipientAddress(orderVo.getRecipientAddressDesensitization());
  71. // }else {
  72. // dto.setRecipientAddress(orderVo.getRecipientAddress());
  73. // }
  74. dto.setRecipientAddress(URLDecoder.decode(orderVo.getRecipientAddress(), "utf-8"));
  75. // dto.setCaution(orderVo.getCaution().substring(0,orderVo.getCaution().indexOf("收餐人隐私号")));
  76. dto.setRecipientName(URLDecoder.decode(orderVo.getRecipientName(), "utf-8"));
  77. dto.setRecipientPhone(orderVo.getRecipientPhone());
  78. return dto;
  79. }
  80. public static List<PrintOrderActDto> merge(List<PrintOrderActDto> list) {
  81. List<PrintOrderActDto> result = list.stream()
  82. // 表示id为key, 接着如果有重复的,那么从BillsNums对象o1与o2中筛选出一个,这里选择o1,
  83. // 并把id重复,需要将nums和sums与o1进行合并的o2, 赋值给o1,最后返回o1
  84. .collect(Collectors.toMap(PrintOrderActDto::getType, a -> a, (o1, o2)-> {
  85. o1.setAmount(new BigDecimal(o1.getAmount()).add(new BigDecimal(o2.getAmount())).toString());
  86. return o1;
  87. })).values().stream().collect(Collectors.toList());
  88. return result ;
  89. }
  90. }