|
|
@@ -69,6 +69,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* posorderController
|
|
|
@@ -724,54 +725,20 @@ public class PosOrderController extends BaseController {
|
|
|
@GetMapping("/getorderhout")
|
|
|
public AjaxResult getorderhout(@RequestParam String id) {
|
|
|
PosOrder orlist = posOrderService.getById(id);
|
|
|
- JSONObject org = new JSONObject();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- org.put("id", orlist.getId());
|
|
|
- org.put("ddId", orlist.getDdId());
|
|
|
+ // 自动序列化所有PosOrder字段,新增字段无需手动添加
|
|
|
+ JSONObject org = JSON.parseObject(
|
|
|
+ JSON.toJSONStringWithDateFormat(orlist, "yyyy-MM-dd HH:mm:ss")
|
|
|
+ );
|
|
|
+ // 以下为非PosOrder字段或需要特殊处理的字段
|
|
|
org.put("shanghu", infoUserService.getById(orlist.getShId()));
|
|
|
org.put("store", posStoreService.getById(orlist.getMdId()));
|
|
|
- org.put("cretim", sdf.format(orlist.getCretim()));
|
|
|
- org.put("shdzId", orlist.getShdzId());
|
|
|
org.put("shaddress", orlist.getShAddress() == null ? infoAddressService.getById(orlist.getShdzId()) : JSONObject.parseObject(orlist.getShAddress()));
|
|
|
org.put("user", infoUserService.getById(orlist.getUserId()));
|
|
|
- org.put("amount", orlist.getAmount());
|
|
|
- org.put("kefuState", orlist.getKefuState());
|
|
|
- org.put("kefuContent", orlist.getKefuContent());
|
|
|
- org.put("kefuRepeat", orlist.getKefuRepeat());
|
|
|
- org.put("repeatDdId", orlist.getRepeatDdId());
|
|
|
- org.put("remarks", orlist.getRemarks());
|
|
|
- org.put("state", orlist.getState());
|
|
|
- org.put("type", orlist.getType());
|
|
|
- org.put("jvli", orlist.getJvli());
|
|
|
- org.put("freight", orlist.getFreight());
|
|
|
- org.put("delryTime", orlist.getDelryTime());
|
|
|
- org.put("longitude", orlist.getLongitude());
|
|
|
- org.put("latitude", orlist.getLatitude());
|
|
|
org.put("qsuser", infoUserService.getById(orlist.getQsId()));
|
|
|
- org.put("payUrl", orlist.getPayUrl());
|
|
|
QueryWrapper<RiderPosition> query = new QueryWrapper<>();
|
|
|
query.eq("rider_id", orlist.getQsId());
|
|
|
org.put("RiderPosition", orlist.getQsId() == null ? null : riderPositionService.getOne(query));
|
|
|
- org.put("diningStatus", orlist.getDiningStatus());
|
|
|
- org.put("collectPayment", orlist.getCollectPayment());
|
|
|
org.put("food", JSONArray.parseArray(orlist.getFood()));
|
|
|
-// org.put("activity",salesPromotionService.getById(orlist.getActivity()));
|
|
|
- org.put("activity", orlist.getActivity());
|
|
|
- org.put("mdActivity", orlist.getMdActivity());
|
|
|
- org.put("salesReduction", orlist.getSalesReduction());
|
|
|
- org.put("mdSalesReduction", orlist.getMdSalesReduction());
|
|
|
- org.put("salesName", orlist.getSalesName());
|
|
|
- org.put("mdSalesName", orlist.getMdSalesName());
|
|
|
- org.put("mdDiscountAmount", orlist.getMdDiscountAmount());
|
|
|
- org.put("discountAmount", orlist.getDiscountAmount());
|
|
|
- org.put("mdYhId", orlist.getMdYhId());
|
|
|
- org.put("mdYhName", orlist.getMdYhName());
|
|
|
- org.put("yhId", orlist.getYhId());
|
|
|
- org.put("yhName", orlist.getYhName());
|
|
|
- org.put("points", orlist.getPoints());
|
|
|
- org.put("pointsReduction", orlist.getPointsReduction());
|
|
|
- org.put("sdTime", orlist.getSdTime());
|
|
|
- org.put("payType", orlist.getPayType());
|
|
|
return success(org);
|
|
|
}
|
|
|
|
|
|
@@ -859,53 +826,31 @@ public class PosOrderController extends BaseController {
|
|
|
} else {
|
|
|
orlist = posOrderMapper.getqisjvli(longitude, latitude, (page - 1) * 20, juli);
|
|
|
}
|
|
|
- for (int i = 0; i < orlist.size(); i++) {
|
|
|
- JSONObject org = new JSONObject();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- org.put("id", orlist.get(i).getId());
|
|
|
- org.put("ddId", orlist.get(i).getDdId());
|
|
|
- org.put("shanghu", infoUserService.getById(orlist.get(i).getShId()));
|
|
|
- org.put("store", posStoreService.getById(orlist.get(i).getMdId()));
|
|
|
- org.put("cretim", sdf.format(orlist.get(i).getCretim()));
|
|
|
- org.put("shdzId", orlist.get(i).getShdzId());
|
|
|
- org.put("shaddress", orlist.get(i).getShAddress() == null ? infoAddressService.getById(orlist.get(i).getShdzId()) : JSONObject.parseObject(orlist.get(i).getShAddress()));
|
|
|
- org.put("user", infoUserService.getById(orlist.get(i).getUserId()));
|
|
|
- org.put("amount", orlist.get(i).getAmount());
|
|
|
- org.put("kefuState", orlist.get(i).getKefuState());
|
|
|
- org.put("kefuContent", orlist.get(i).getKefuContent());
|
|
|
- org.put("kefuRepeat", orlist.get(i).getKefuRepeat());
|
|
|
- org.put("repeatDdId", orlist.get(i).getRepeatDdId());
|
|
|
- org.put("remarks", orlist.get(i).getRemarks());
|
|
|
- org.put("state", orlist.get(i).getState());
|
|
|
- org.put("type", orlist.get(i).getType());
|
|
|
- DecimalFormat jl = new DecimalFormat("#.0");
|
|
|
- org.put("jvli", jl.format(orlist.get(i).getJvli()));
|
|
|
- org.put("qsjvli", jl.format(orlist.get(i).getJuli()));
|
|
|
- org.put("freight", orlist.get(i).getFreight());
|
|
|
- org.put("delryTime", orlist.get(i).getDelryTime());
|
|
|
- org.put("qsId", orlist.get(i).getQsId());
|
|
|
- org.put("payUrl", orlist.get(i).getPayUrl());
|
|
|
- org.put("diningStatus", orlist.get(i).getDiningStatus());
|
|
|
- org.put("food", JSONArray.parseArray(orlist.get(i).getFood()));
|
|
|
- org.put("collectPayment", orlist.get(i).getCollectPayment());
|
|
|
-// org.put("activity",salesPromotionService.getById(orlist.get(i).getActivity()));
|
|
|
-
|
|
|
- org.put("activity", orlist.get(i).getActivity());
|
|
|
- org.put("mdActivity", orlist.get(i).getMdActivity());
|
|
|
- org.put("salesReduction", orlist.get(i).getSalesReduction());
|
|
|
- org.put("mdSalesReduction", orlist.get(i).getMdSalesReduction());
|
|
|
- org.put("salesName", orlist.get(i).getSalesName());
|
|
|
- org.put("mdSalesName", orlist.get(i).getMdSalesName());
|
|
|
- org.put("mdDiscountAmount", orlist.get(i).getMdDiscountAmount());
|
|
|
- org.put("discountAmount", orlist.get(i).getDiscountAmount());
|
|
|
- org.put("mdYhId", orlist.get(i).getMdYhId());
|
|
|
- org.put("mdYhName", orlist.get(i).getMdYhName());
|
|
|
- org.put("yhId", orlist.get(i).getYhId());
|
|
|
- org.put("yhName", orlist.get(i).getYhName());
|
|
|
- org.put("points", orlist.get(i).getPoints());
|
|
|
- org.put("pointsReduction", orlist.get(i).getPointsReduction());
|
|
|
- org.put("sdTime", orlist.get(i).getSdTime());
|
|
|
- org.put("payType", orlist.get(i).getPayType());
|
|
|
+ // 循环外统一查询,避免N+1问题
|
|
|
+ Set<Long> allUserIds = orlist.stream().flatMap(o -> Stream.of(o.getShId(), o.getUserId())).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> mdIds = orlist.stream().map(PosOrder::getMdId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> shdzIds = orlist.stream().filter(o -> o.getShAddress() == null && o.getShdzId() != null).map(PosOrder::getShdzId).collect(Collectors.toSet());
|
|
|
+ Map<Long, InfoUser> userMap = allUserIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoUserService.listByIds(allUserIds).stream().collect(Collectors.toMap(InfoUser::getUserId, u -> u));
|
|
|
+ Map<Integer, PosStore> storeMap = mdIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ posStoreService.listByIds(mdIds).stream().collect(Collectors.toMap(PosStore::getId, s -> s));
|
|
|
+ Map<Long, InfoAddress> addressMap = shdzIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoAddressService.listByIds(shdzIds).stream().collect(Collectors.toMap(InfoAddress::getId, a -> a));
|
|
|
+
|
|
|
+ DecimalFormat jl = new DecimalFormat("#.0");
|
|
|
+ for (PosOrder order : orlist) {
|
|
|
+ // 自动序列化所有PosOrder字段,新增字段无需手动添加
|
|
|
+ JSONObject org = JSON.parseObject(
|
|
|
+ JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss")
|
|
|
+ );
|
|
|
+ // 以下为非PosOrder字段或需要特殊处理的字段
|
|
|
+ org.put("shanghu", userMap.get(order.getShId()));
|
|
|
+ org.put("store", storeMap.get(order.getMdId().intValue()));
|
|
|
+ org.put("shaddress", order.getShAddress() == null ? addressMap.get(order.getShdzId()) : JSONObject.parseObject(order.getShAddress()));
|
|
|
+ org.put("user", userMap.get(order.getUserId()));
|
|
|
+ org.put("jvli", jl.format(order.getJvli()));
|
|
|
+ org.put("juli", jl.format(order.getJuli()));
|
|
|
+ org.put("food", JSONArray.parseArray(order.getFood()));
|
|
|
arr.add(org);
|
|
|
}
|
|
|
return success(arr);
|
|
|
@@ -920,55 +865,34 @@ public class PosOrderController extends BaseController {
|
|
|
JwtUtil jwtUtil = new JwtUtil();
|
|
|
String id = jwtUtil.getusid(token);
|
|
|
List<PosOrder> orlist = posOrderMapper.getQsOrderList(id, longitude, latitude, (page - 1) * size, size, state);
|
|
|
+ // 循环外统一查询,避免N+1问题
|
|
|
+ Set<Long> allUserIds = orlist.stream().flatMap(o -> Stream.of(o.getShId(), o.getUserId(), o.getQsId())).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> mdIds = orlist.stream().map(PosOrder::getMdId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> shdzIds = orlist.stream().filter(o -> o.getShAddress() == null && o.getShdzId() != null).map(PosOrder::getShdzId).collect(Collectors.toSet());
|
|
|
+ Map<Long, InfoUser> userMap = allUserIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoUserService.listByIds(allUserIds).stream().collect(Collectors.toMap(InfoUser::getUserId, u -> u));
|
|
|
+ Map<Integer, PosStore> storeMap = mdIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ posStoreService.listByIds(mdIds).stream().collect(Collectors.toMap(PosStore::getId, s -> s));
|
|
|
+ Map<Long, InfoAddress> addressMap = shdzIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoAddressService.listByIds(shdzIds).stream().collect(Collectors.toMap(InfoAddress::getId, a -> a));
|
|
|
+
|
|
|
JSONArray arr = new JSONArray();
|
|
|
- for (int i = 0; i < orlist.size(); i++) {
|
|
|
- JSONObject org = new JSONObject();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- org.put("id", orlist.get(i).getId());
|
|
|
- org.put("ddId", orlist.get(i).getDdId());
|
|
|
- org.put("shanghu", infoUserService.getById(orlist.get(i).getShId()));
|
|
|
- org.put("store", posStoreService.getById(orlist.get(i).getMdId()));
|
|
|
- org.put("cretim", sdf.format(orlist.get(i).getCretim()));
|
|
|
- org.put("shdzId", orlist.get(i).getShdzId());
|
|
|
- org.put("shaddress", orlist.get(i).getShAddress() == null ? infoAddressService.getById(orlist.get(i).getShdzId()) : JSONObject.parseObject(orlist.get(i).getShAddress()));
|
|
|
- org.put("user", infoUserService.getById(orlist.get(i).getUserId()));
|
|
|
- org.put("qishou", infoUserService.getById(orlist.get(i).getQsId()));
|
|
|
- org.put("amount", orlist.get(i).getAmount());
|
|
|
- org.put("kefuState", orlist.get(i).getKefuState());
|
|
|
- org.put("kefuContent", orlist.get(i).getKefuContent());
|
|
|
- org.put("kefuRepeat", orlist.get(i).getKefuRepeat());
|
|
|
- org.put("repeatDdId", orlist.get(i).getRepeatDdId());
|
|
|
- org.put("remarks", orlist.get(i).getRemarks());
|
|
|
- org.put("state", orlist.get(i).getState());
|
|
|
- org.put("type", orlist.get(i).getType());
|
|
|
- DecimalFormat jl = new DecimalFormat("#.0");
|
|
|
- org.put("jvli", jl.format(orlist.get(i).getJvli()));
|
|
|
- org.put("qsjvli", jl.format(orlist.get(i).getJuli()));
|
|
|
- org.put("freight", orlist.get(i).getFreight());
|
|
|
- org.put("delryTime", orlist.get(i).getDelryTime());
|
|
|
- org.put("diningStatus", orlist.get(i).getDiningStatus());
|
|
|
- org.put("food", JSONArray.parseArray(orlist.get(i).getFood()));
|
|
|
- org.put("collectPayment", orlist.get(i).getCollectPayment());
|
|
|
-// org.put("activity",salesPromotionService.getById(orlist.get(i).getActivity()));
|
|
|
- org.put("sqImg", orlist.get(i).getQsImg());
|
|
|
-// org.put("discountAmount",orlist.get(i).getDiscountAmount());
|
|
|
-
|
|
|
- org.put("activity", orlist.get(i).getActivity());
|
|
|
- org.put("mdActivity", orlist.get(i).getMdActivity());
|
|
|
- org.put("salesReduction", orlist.get(i).getSalesReduction());
|
|
|
- org.put("mdSalesReduction", orlist.get(i).getMdSalesReduction());
|
|
|
- org.put("salesName", orlist.get(i).getSalesName());
|
|
|
- org.put("mdSalesName", orlist.get(i).getMdSalesName());
|
|
|
- org.put("mdDiscountAmount", orlist.get(i).getMdDiscountAmount());
|
|
|
- org.put("discountAmount", orlist.get(i).getDiscountAmount());
|
|
|
- org.put("mdYhId", orlist.get(i).getMdYhId());
|
|
|
- org.put("mdYhName", orlist.get(i).getMdYhName());
|
|
|
- org.put("yhId", orlist.get(i).getYhId());
|
|
|
- org.put("yhName", orlist.get(i).getYhName());
|
|
|
- org.put("points", orlist.get(i).getPoints());
|
|
|
- org.put("pointsReduction", orlist.get(i).getPointsReduction());
|
|
|
- org.put("sdTime", orlist.get(i).getSdTime());
|
|
|
- org.put("payType", orlist.get(i).getPayType());
|
|
|
+ DecimalFormat jl = new DecimalFormat("#.0");
|
|
|
+ for (PosOrder order : orlist) {
|
|
|
+ // 自动序列化所有PosOrder字段,新增字段无需手动添加
|
|
|
+ JSONObject org = JSON.parseObject(
|
|
|
+ JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss")
|
|
|
+ );
|
|
|
+ // 以下为非PosOrder字段或需要特殊处理的字段
|
|
|
+ org.put("shanghu", userMap.get(order.getShId()));
|
|
|
+ org.put("store", storeMap.get(order.getMdId().intValue()));
|
|
|
+ org.put("shaddress", order.getShAddress() == null ? addressMap.get(order.getShdzId()) : JSONObject.parseObject(order.getShAddress()));
|
|
|
+ org.put("user", userMap.get(order.getUserId()));
|
|
|
+ org.put("qishou", userMap.get(order.getQsId()));
|
|
|
+ org.put("jvli", jl.format(order.getJvli()));
|
|
|
+ org.put("qsjvli", jl.format(order.getJuli()));
|
|
|
+ org.put("food", JSONArray.parseArray(order.getFood()));
|
|
|
+ org.put("sqImg", org.remove("qsImg"));
|
|
|
arr.add(org);
|
|
|
}
|
|
|
return success(arr);
|
|
|
@@ -1008,49 +932,29 @@ public class PosOrderController extends BaseController {
|
|
|
}
|
|
|
IPage<PosOrder> list = posOrderService.page(palist, queryWrapper);
|
|
|
List<PosOrder> orlist = list.getRecords();
|
|
|
+ // 循环外统一查询,避免N+1问题
|
|
|
+ Set<Long> allUserIds = orlist.stream().flatMap(o -> Stream.of(o.getShId(), o.getUserId())).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> mdIds = orlist.stream().map(PosOrder::getMdId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> shdzIds = orlist.stream().filter(o -> o.getShAddress() == null && o.getShdzId() != null).map(PosOrder::getShdzId).collect(Collectors.toSet());
|
|
|
+ Map<Long, InfoUser> userMap = allUserIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoUserService.listByIds(allUserIds).stream().collect(Collectors.toMap(InfoUser::getUserId, u -> u));
|
|
|
+ Map<Integer, PosStore> storeMap = mdIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ posStoreService.listByIds(mdIds).stream().collect(Collectors.toMap(PosStore::getId, s -> s));
|
|
|
+ Map<Long, InfoAddress> addressMap = shdzIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoAddressService.listByIds(shdzIds).stream().collect(Collectors.toMap(InfoAddress::getId, a -> a));
|
|
|
+
|
|
|
JSONArray arr = new JSONArray();
|
|
|
- for (int i = 0; i < orlist.size(); i++) {
|
|
|
- JSONObject org = new JSONObject();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- org.put("id", orlist.get(i).getId());
|
|
|
- org.put("ddId", orlist.get(i).getDdId());
|
|
|
- org.put("shanghu", infoUserService.getById(orlist.get(i).getShId()));
|
|
|
- org.put("store", posStoreService.getById(orlist.get(i).getMdId()));
|
|
|
- org.put("cretim", sdf.format(orlist.get(i).getCretim()));
|
|
|
- org.put("shdzId", orlist.get(i).getShdzId());
|
|
|
- org.put("shaddress", orlist.get(i).getShAddress() == null ? infoAddressService.getById(orlist.get(i).getShdzId()) : JSONObject.parseObject(orlist.get(i).getShAddress()));
|
|
|
- org.put("user", infoUserService.getById(orlist.get(i).getUserId()));
|
|
|
- org.put("amount", orlist.get(i).getAmount());
|
|
|
- org.put("kefuState", orlist.get(i).getKefuState());
|
|
|
- org.put("kefuContent", orlist.get(i).getKefuContent());
|
|
|
- org.put("kefuRepeat", orlist.get(i).getKefuRepeat());
|
|
|
- org.put("repeatDdId", orlist.get(i).getRepeatDdId());
|
|
|
- org.put("remarks", orlist.get(i).getRemarks());
|
|
|
- org.put("state", orlist.get(i).getState());
|
|
|
- org.put("type", orlist.get(i).getType());
|
|
|
- org.put("jvli", orlist.get(i).getJvli());
|
|
|
- org.put("freight", orlist.get(i).getFreight());
|
|
|
- org.put("delryTime", orlist.get(i).getDelryTime());
|
|
|
- org.put("diningStatus", orlist.get(i).getDiningStatus());
|
|
|
- org.put("collectPayment", orlist.get(i).getCollectPayment());
|
|
|
- org.put("discountAmount", orlist.get(i).getDiscountAmount());
|
|
|
- org.put("food", JSONArray.parseArray(orlist.get(i).getFood()));
|
|
|
- org.put("activity", orlist.get(i).getActivity());
|
|
|
- org.put("mdActivity", orlist.get(i).getMdActivity());
|
|
|
- org.put("salesReduction", orlist.get(i).getSalesReduction());
|
|
|
- org.put("mdSalesReduction", orlist.get(i).getMdSalesReduction());
|
|
|
- org.put("salesName", orlist.get(i).getSalesName());
|
|
|
- org.put("mdSalesName", orlist.get(i).getMdSalesName());
|
|
|
- org.put("mdDiscountAmount", orlist.get(i).getMdDiscountAmount());
|
|
|
- org.put("discountAmount", orlist.get(i).getDiscountAmount());
|
|
|
- org.put("mdYhId", orlist.get(i).getMdYhId());
|
|
|
- org.put("mdYhName", orlist.get(i).getMdYhName());
|
|
|
- org.put("yhId", orlist.get(i).getYhId());
|
|
|
- org.put("yhName", orlist.get(i).getYhName());
|
|
|
- org.put("points", orlist.get(i).getPoints());
|
|
|
- org.put("pointsReduction", orlist.get(i).getPointsReduction());
|
|
|
- org.put("sdTime", orlist.get(i).getSdTime());
|
|
|
- org.put("payType", orlist.get(i).getPayType());
|
|
|
+ for (PosOrder order : orlist) {
|
|
|
+ // 自动序列化所有PosOrder字段,新增字段无需手动添加
|
|
|
+ JSONObject org = JSON.parseObject(
|
|
|
+ JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss")
|
|
|
+ );
|
|
|
+ // 以下为非PosOrder字段或需要特殊处理的字段
|
|
|
+ org.put("shanghu", userMap.get(order.getShId()));
|
|
|
+ org.put("store", storeMap.get(order.getMdId().intValue()));
|
|
|
+ org.put("shaddress", order.getShAddress() == null ? addressMap.get(order.getShdzId()) : JSONObject.parseObject(order.getShAddress()));
|
|
|
+ org.put("user", userMap.get(order.getUserId()));
|
|
|
+ org.put("food", JSONArray.parseArray(order.getFood()));
|
|
|
arr.add(org);
|
|
|
}
|
|
|
return success(arr);
|
|
|
@@ -1090,53 +994,35 @@ public class PosOrderController extends BaseController {
|
|
|
if (!parentDdIds.isEmpty()) {
|
|
|
orderParents = orderParentService.list(new LambdaQueryWrapper<>(OrderParent.class).in(OrderParent::getDdId, parentDdIds));
|
|
|
}
|
|
|
+ // 循环外统一查询,避免N+1问题
|
|
|
+ Set<Long> allUserIds = orlist.stream().flatMap(o -> Stream.of(o.getShId(), o.getUserId())).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> mdIds = orlist.stream().map(PosOrder::getMdId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Set<Long> shdzIds = orlist.stream().filter(o -> o.getShAddress() == null && o.getShdzId() != null).map(PosOrder::getShdzId).collect(Collectors.toSet());
|
|
|
+ Map<Long, InfoUser> userMap = allUserIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoUserService.listByIds(allUserIds).stream().collect(Collectors.toMap(InfoUser::getUserId, u -> u));
|
|
|
+ Map<Integer, PosStore> storeMap = mdIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ posStoreService.listByIds(mdIds).stream().collect(Collectors.toMap(PosStore::getId, s -> s));
|
|
|
+ Map<Long, InfoAddress> addressMap = shdzIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ infoAddressService.listByIds(shdzIds).stream().collect(Collectors.toMap(InfoAddress::getId, a -> a));
|
|
|
+ Map<String, OrderParent> orderParentMap = orderParents.stream().collect(Collectors.toMap(OrderParent::getDdId, p -> p));
|
|
|
+
|
|
|
JSONArray arr = new JSONArray();
|
|
|
- for (int i = 0; i < orlist.size(); i++) {
|
|
|
- JSONObject org = new JSONObject();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- org.put("id", orlist.get(i).getId());
|
|
|
- org.put("ddId", orlist.get(i).getDdId().toString());
|
|
|
- org.put("shanghu", infoUserService.getById(orlist.get(i).getShId()));
|
|
|
- org.put("store", posStoreService.getById(orlist.get(i).getMdId()));
|
|
|
- org.put("cretim", sdf.format(orlist.get(i).getCretim()));
|
|
|
- org.put("shdzId", orlist.get(i).getShdzId());
|
|
|
- org.put("shaddress", orlist.get(i).getShAddress() == null ? infoAddressService.getById(orlist.get(i).getShdzId()) : JSONObject.parseObject(orlist.get(i).getShAddress()));
|
|
|
- org.put("user", infoUserService.getById(orlist.get(i).getUserId()));
|
|
|
- org.put("amount", orlist.get(i).getAmount());
|
|
|
- org.put("kefuState", orlist.get(i).getKefuState());
|
|
|
- org.put("kefuContent", orlist.get(i).getKefuContent());
|
|
|
- org.put("kefuRepeat", orlist.get(i).getKefuRepeat());
|
|
|
- org.put("repeatDdId", orlist.get(i).getRepeatDdId());
|
|
|
- org.put("remarks", orlist.get(i).getRemarks());
|
|
|
- org.put("state", orlist.get(i).getState());
|
|
|
- org.put("type", orlist.get(i).getType());
|
|
|
- org.put("jvli", orlist.get(i).getJvli());
|
|
|
- org.put("freight", orlist.get(i).getFreight());
|
|
|
- org.put("delryTime", orlist.get(i).getDelryTime());
|
|
|
- org.put("payUrl", orlist.get(i).getPayUrl());
|
|
|
- org.put("collectPayment", orlist.get(i).getCollectPayment());
|
|
|
- org.put("food", JSONArray.parseArray(orlist.get(i).getFood()));
|
|
|
-// org.put("activity",salesPromotionService.getById(orlist.get(i).getActivity()));
|
|
|
- org.put("activity", orlist.get(i).getActivity());
|
|
|
- org.put("mdActivity", orlist.get(i).getMdActivity());
|
|
|
- org.put("salesReduction", orlist.get(i).getSalesReduction());
|
|
|
- org.put("mdSalesReduction", orlist.get(i).getMdSalesReduction());
|
|
|
- org.put("salesName", orlist.get(i).getSalesName());
|
|
|
- org.put("mdSalesName", orlist.get(i).getMdSalesName());
|
|
|
- org.put("mdDiscountAmount", orlist.get(i).getMdDiscountAmount());
|
|
|
- org.put("discountAmount", orlist.get(i).getDiscountAmount());
|
|
|
- org.put("mdYhId", orlist.get(i).getMdYhId());
|
|
|
- org.put("mdYhName", orlist.get(i).getMdYhName());
|
|
|
- org.put("yhId", orlist.get(i).getYhId());
|
|
|
- org.put("yhName", orlist.get(i).getYhName());
|
|
|
- org.put("points", orlist.get(i).getPoints());
|
|
|
- org.put("pointsReduction", orlist.get(i).getPointsReduction());
|
|
|
- org.put("sdTime", orlist.get(i).getSdTime());
|
|
|
- org.put("payType", orlist.get(i).getPayType());
|
|
|
- int finalI = i;
|
|
|
+ for (PosOrder order : orlist) {
|
|
|
+ // 自动序列化所有PosOrder字段,新增字段无需手动添加
|
|
|
+ JSONObject org = JSON.parseObject(
|
|
|
+ JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss")
|
|
|
+ );
|
|
|
+ // 以下为非PosOrder字段或需要特殊处理的字段
|
|
|
+ org.put("ddId", order.getDdId() == null ? null : order.getDdId().toString());
|
|
|
+ org.put("shanghu", userMap.get(order.getShId()));
|
|
|
+ org.put("store", storeMap.get(order.getMdId().intValue()));
|
|
|
+ org.put("shaddress", order.getShAddress() == null ? addressMap.get(order.getShdzId()) : JSONObject.parseObject(order.getShAddress()));
|
|
|
+ org.put("user", userMap.get(order.getUserId()));
|
|
|
+ org.put("food", JSONArray.parseArray(order.getFood()));
|
|
|
org.put("parentRemarks", "");
|
|
|
- if (StringUtils.isNotEmpty(orlist.get(i).getParentDdId())) {
|
|
|
- orderParents.stream().filter(item -> item.getDdId().equals(orlist.get(finalI).getParentDdId())).findFirst().ifPresent(a -> org.put("parentRemarks", a.getRemarks()));
|
|
|
+ if (StringUtils.isNotEmpty(order.getParentDdId())) {
|
|
|
+ OrderParent parent = orderParentMap.get(order.getParentDdId());
|
|
|
+ if (parent != null) org.put("parentRemarks", parent.getRemarks());
|
|
|
}
|
|
|
arr.add(org);
|
|
|
}
|