|
@@ -6,7 +6,16 @@ import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
|
+import com.alibaba.excel.EasyExcelFactory;
|
|
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
|
|
+import com.alibaba.excel.metadata.Head;
|
|
|
import com.alibaba.excel.util.DateUtils;
|
|
import com.alibaba.excel.util.DateUtils;
|
|
|
|
|
+import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
|
|
|
|
|
+import com.alibaba.excel.write.merge.AbstractMergeStrategy;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
@@ -87,6 +96,13 @@ import com.yc.ship.module.trade.service.refund.TradeRefundRepositoryService;
|
|
|
import com.yc.ship.module.trade.utils.AgencyAuthUtils;
|
|
import com.yc.ship.module.trade.utils.AgencyAuthUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
|
+import org.apache.poi.ss.util.RegionUtil;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.redisson.api.RLock;
|
|
import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
@@ -95,9 +111,12 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
@@ -2518,4 +2537,181 @@ public class OtcTradeOrderServiceImpl implements OtcTradeOrderService {
|
|
|
System.out.println(DateUtil.beginOfDay(new Date()));
|
|
System.out.println(DateUtil.beginOfDay(new Date()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public File createConfirmaction(Long id, Double totalMoney) {
|
|
|
|
|
+ TradeOrderConfirmationVO orderConfirmation = getOrderConfirmation(id);
|
|
|
|
|
+ InputStream template = getClass().getClassLoader().getResourceAsStream("templates/confirmation_template.xlsx");
|
|
|
|
|
+ String tmpFile = "/tmp/" + orderConfirmation.getId() + ".xlsx";
|
|
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(tmpFile).withTemplate(template).build();
|
|
|
|
|
+ ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcelFactory.writerSheet();
|
|
|
|
|
+ WriteSheet writeSheet = excelWriterSheetBuilder.registerWriteHandler(new MergeStrategy()).build(); // 需要合并单元格的writeSheet
|
|
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
|
|
|
|
|
+
|
|
|
|
|
+ // 订单信息
|
|
|
|
|
+ Map<String, Object> orderData = new HashMap<>();
|
|
|
|
|
+ orderData.put("orderNo", orderConfirmation.getOrderNo());
|
|
|
|
|
+ orderData.put("shipName", orderConfirmation.getShipName());
|
|
|
|
|
+ orderData.put("shipNameEn", orderConfirmation.getShipNameEn());
|
|
|
|
|
+ orderData.put("groupNo", orderConfirmation.getGroupNo());
|
|
|
|
|
+ orderData.put("sourceName", orderConfirmation.getSourceName());
|
|
|
|
|
+ orderData.put("linkMan", orderConfirmation.getLinkMan());
|
|
|
|
|
+ orderData.put("linkMobile", orderConfirmation.getLinkMobile());
|
|
|
|
|
+ orderData.put("amount", orderConfirmation.getAmount());
|
|
|
|
|
+
|
|
|
|
|
+ VoyageRespVO voyage = orderConfirmation.getVoyage();
|
|
|
|
|
+ orderData.put("voyageCode", voyage.getCode());
|
|
|
|
|
+
|
|
|
|
|
+ orderData.put("boardingTime", DateUtil.format(Date.from(voyage.getBoardingTime().atZone(ZoneOffset.ofHours(8)).toInstant()), "yyyy-MM-dd HH:mm"));
|
|
|
|
|
+ orderData.put("startTime", DateUtil.format(Date.from(voyage.getStartTime().atZone(ZoneOffset.ofHours(8)).toInstant()), "yyyy-MM-dd HH:mm"));
|
|
|
|
|
+ orderData.put("leaveTime", DateUtil.format(Date.from(voyage.getLeaveTime().atZone(ZoneOffset.ofHours(8)).toInstant()), "yyyy-MM-dd HH:mm"));
|
|
|
|
|
+
|
|
|
|
|
+ String resourceRoute = "宜昌-重庆";
|
|
|
|
|
+ String resourceRouteEn = "Yichang-Chongqing";
|
|
|
|
|
+ if (voyage.getRouteResp() != null && voyage.getRouteResp().getDirection() != null && voyage.getRouteResp().getDirection().intValue() != 1) {
|
|
|
|
|
+ resourceRoute = "重庆-宜昌";
|
|
|
|
|
+ resourceRouteEn = "Chongqing-Yichang";
|
|
|
|
|
+ }
|
|
|
|
|
+ orderData.put("resourceRoute", resourceRoute);
|
|
|
|
|
+ orderData.put("resourceRouteEn", resourceRouteEn);
|
|
|
|
|
+
|
|
|
|
|
+ // 房型信息
|
|
|
|
|
+ List<Map<String, Object>> roomData = new ArrayList<>();
|
|
|
|
|
+ List<TradeOrderCountryBaseVO> countryList = orderConfirmation.getCountryList();
|
|
|
|
|
+ StringBuilder countryDes = new StringBuilder();
|
|
|
|
|
+ AtomicReference<Double> roomModelDes = new AtomicReference<>(0.0d);
|
|
|
|
|
+ if (countryList != null) {
|
|
|
|
|
+ List<String> countryDesList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ countryList.forEach(item -> {
|
|
|
|
|
+ countryDesList.add((item.getAdultNum() + item.getChildNum() + item.getBabyNum()) + item.getCountryName());
|
|
|
|
|
+
|
|
|
|
|
+ List<TradeOrderRoomModelBaseVO> roomModelList = item.getRoomModelList();
|
|
|
|
|
+ roomModelList.forEach(r -> {
|
|
|
|
|
+ roomModelDes.updateAndGet(v -> new Double((double) (v + r.getUseRoomNum())));
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> room = new HashMap<>();
|
|
|
|
|
+ room.put("roomModelName", r.getRoomModelName() + "(" + r.getFloor() + "F)");
|
|
|
|
|
+ room.put("countryName", item.getCountryName());
|
|
|
|
|
+ room.put("personTypeDes", getPersonTypeDes(r));
|
|
|
|
|
+ room.put("personTypeDesEn", getPersonTypeDesEn(r));
|
|
|
|
|
+ room.put("qty", getPersonNum(r));
|
|
|
|
|
+ room.put("price", r.getPrice());
|
|
|
|
|
+ room.put("realMoney", r.getRealMoney());
|
|
|
|
|
+ roomData.add(room);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ countryDes.append(String.join(",", countryDesList));
|
|
|
|
|
+ }
|
|
|
|
|
+ orderData.put("countryDes", countryDes.toString());
|
|
|
|
|
+ orderData.put("roomModelDes", roomModelDes.get());
|
|
|
|
|
+
|
|
|
|
|
+ orderData.put("totalMoney", totalMoney);
|
|
|
|
|
+ orderData.put("creatorName", orderConfirmation.getCreatorName());
|
|
|
|
|
+ orderData.put("firstDate", DateUtil.format(org.apache.commons.lang3.time.DateUtils.addDays(Date.from(orderConfirmation.getUpdateTime().atZone(ZoneOffset.ofHours(8)).toInstant()), 8), "yyyy-MM-dd"));
|
|
|
|
|
+ orderData.put("lastDate", DateUtil.format(org.apache.commons.lang3.time.DateUtils.addDays(Date.from(voyage.getStartTime().atZone(ZoneOffset.ofHours(8)).toInstant()), -21), "yyyy-MM-dd"));
|
|
|
|
|
+ orderData.put("today", DateUtil.format(new Date(), "yyyy-MM-dd"));
|
|
|
|
|
+
|
|
|
|
|
+ // 游客信息
|
|
|
|
|
+ List<Map<String, Object>> tradeVisitorData = new ArrayList<>();
|
|
|
|
|
+ List<TradeVisitorDO> tradeVisitorList = orderConfirmation.getTradeVisitorList();
|
|
|
|
|
+ for (int i = 0; i < tradeVisitorList.size(); i++) {
|
|
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
|
|
+ TradeVisitorDO tradeVisitorDO = tradeVisitorList.get(i);
|
|
|
|
|
+ item.put("index", String.valueOf((i + 1)));
|
|
|
|
|
+ item.put("name", StringUtils.isEmpty(tradeVisitorDO.getName()) ? "" : tradeVisitorDO.getName());
|
|
|
|
|
+ item.put("nationality", StringUtils.isEmpty(tradeVisitorDO.getNationalityName()) ? "" : tradeVisitorDO.getNationalityName());
|
|
|
|
|
+ item.put("gender", (tradeVisitorDO.getGender() == null || tradeVisitorDO.getGender().intValue() == 0) ? "女" : "男");
|
|
|
|
|
+ item.put("dob", StringUtils.isEmpty(tradeVisitorDO.getBirthday()) ? "" : tradeVisitorDO.getBirthday());
|
|
|
|
|
+ item.put("idno", StringUtils.isEmpty(tradeVisitorDO.getCredentialNo()) ? "" : tradeVisitorDO.getCredentialNo());
|
|
|
|
|
+ tradeVisitorData.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 填充单条数据
|
|
|
|
|
+ excelWriter.fill(orderData, writeSheet);
|
|
|
|
|
+ // 填充列表数据
|
|
|
|
|
+ excelWriter.fill(new FillWrapper("room", roomData), fillConfig, writeSheet);
|
|
|
|
|
+ excelWriter.fill(new FillWrapper("visitor", tradeVisitorData), fillConfig, writeSheet);
|
|
|
|
|
+ excelWriter.finish();
|
|
|
|
|
+ return new File(tmpFile);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private int getPersonNum(TradeOrderRoomModelBaseVO roomModel) {
|
|
|
|
|
+ int n = 0;
|
|
|
|
|
+ n += (roomModel.getAdultAloneNum() + roomModel.getAdultTakeNum() + roomModel.getAdultPlusNum());
|
|
|
|
|
+ n += (roomModel.getChildNonTakeNum() + roomModel.getChildTakeNum() + roomModel.getChildPlusNum());
|
|
|
|
|
+ n += (roomModel.getBabyNonTakeNum() + roomModel.getBabyTakeNum() + roomModel.getBabyPlusNum());
|
|
|
|
|
+ return n;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private String getPersonTypeDes(TradeOrderRoomModelBaseVO roomModel) {
|
|
|
|
|
+ List<String> des = new ArrayList();
|
|
|
|
|
+ int adultNum = (roomModel.getAdultAloneNum() + roomModel.getAdultTakeNum() + roomModel.getAdultPlusNum());
|
|
|
|
|
+ int childNum = (roomModel.getChildNonTakeNum() + roomModel.getChildTakeNum() + roomModel.getChildPlusNum());
|
|
|
|
|
+ int babyNum = (roomModel.getBabyNonTakeNum() + roomModel.getBabyTakeNum() + roomModel.getBabyPlusNum());
|
|
|
|
|
+ if (adultNum > 0) {
|
|
|
|
|
+ des.add("成人");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (childNum > 0) {
|
|
|
|
|
+ des.add("儿童");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (babyNum > 0) {
|
|
|
|
|
+ des.add("婴儿");
|
|
|
|
|
+ }
|
|
|
|
|
+ return String.join("/", des);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getPersonTypeDesEn(TradeOrderRoomModelBaseVO roomModel) {
|
|
|
|
|
+ List<String> des = new ArrayList();
|
|
|
|
|
+ int adultNum = (roomModel.getAdultAloneNum() + roomModel.getAdultTakeNum() + roomModel.getAdultPlusNum());
|
|
|
|
|
+ int childNum = (roomModel.getChildNonTakeNum() + roomModel.getChildTakeNum() + roomModel.getChildPlusNum());
|
|
|
|
|
+ int babyNum = (roomModel.getBabyNonTakeNum() + roomModel.getBabyTakeNum() + roomModel.getBabyPlusNum());
|
|
|
|
|
+ if (adultNum > 0) {
|
|
|
|
|
+ des.add("Adults");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (childNum > 0) {
|
|
|
|
|
+ des.add("Children");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (babyNum > 0) {
|
|
|
|
|
+ des.add("Infants");
|
|
|
|
|
+ }
|
|
|
|
|
+ return String.join("/", des);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ class MergeStrategy extends AbstractMergeStrategy {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
|
|
|
|
|
+ if (relativeRowIndex == null || relativeRowIndex == 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ int rowIndex = cell.getRowIndex();
|
|
|
|
|
+ int colIndex = cell.getColumnIndex();
|
|
|
|
|
+ sheet = cell.getSheet();
|
|
|
|
|
+ Row preRow = sheet.getRow(rowIndex - 1);
|
|
|
|
|
+ Cell preCell = preRow.getCell(colIndex);// 获取上一行的该格
|
|
|
|
|
+ List<CellRangeAddress> list = sheet.getMergedRegions();
|
|
|
|
|
+ CellStyle cs = cell.getCellStyle();
|
|
|
|
|
+ cell.setCellStyle(cs);
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ CellRangeAddress cellRangeAddress = list.get(i);
|
|
|
|
|
+ if (cellRangeAddress.containsRow(preCell.getRowIndex()) && cellRangeAddress.containsColumn(preCell.getColumnIndex())) {
|
|
|
|
|
+ int lastColIndex = cellRangeAddress.getLastColumn();
|
|
|
|
|
+ int firstColIndex = cellRangeAddress.getFirstColumn();
|
|
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(cell.getRowIndex(), cell.getRowIndex(), firstColIndex, lastColIndex);
|
|
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
|
|
+ RegionUtil.setBorderBottom(BorderStyle.THIN, cra, sheet);
|
|
|
|
|
+ RegionUtil.setBorderLeft(BorderStyle.THIN, cra, sheet);
|
|
|
|
|
+ RegionUtil.setBorderRight(BorderStyle.THIN, cra, sheet);
|
|
|
|
|
+ RegionUtil.setBorderTop(BorderStyle.THIN, cra, sheet);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|