|
|
@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.math.RandomUtils;
|
|
|
+import org.apache.commons.lang.time.DateUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@@ -18,6 +20,8 @@ import shop.alien.mapper.LawyerConsultationOrderMapper;
|
|
|
import shop.alien.store.service.LawyerConsultationOrderService;
|
|
|
import shop.alien.store.service.LawyerUserService;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -74,10 +78,10 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
queryWrapper.orderByDesc(LawyerConsultationOrder::getCreatedTime);
|
|
|
IPage<LawyerConsultationOrder> pageResult = this.page(page, queryWrapper);
|
|
|
-
|
|
|
+
|
|
|
// 轉換為VO並填充律師信息
|
|
|
IPage<LawyerConsultationOrderVO> voPage = convertToVO(pageResult);
|
|
|
-
|
|
|
+
|
|
|
return R.data(voPage);
|
|
|
}
|
|
|
|
|
|
@@ -87,19 +91,19 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private IPage<LawyerConsultationOrderVO> convertToVO(IPage<LawyerConsultationOrder> pageResult) {
|
|
|
// 創建VO分頁對象
|
|
|
Page<LawyerConsultationOrderVO> voPage = new Page<>(pageResult.getCurrent(), pageResult.getSize(), pageResult.getTotal());
|
|
|
-
|
|
|
+
|
|
|
List<LawyerConsultationOrder> records = pageResult.getRecords();
|
|
|
if (records == null || records.isEmpty()) {
|
|
|
voPage.setRecords(Collections.emptyList());
|
|
|
return voPage;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 收集所有律師ID
|
|
|
Set<Integer> lawyerUserIds = records.stream()
|
|
|
.map(LawyerConsultationOrder::getLawyerUserId)
|
|
|
.filter(id -> id != null)
|
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
+
|
|
|
// 批量查詢律師信息
|
|
|
Map<Integer, LawyerUser> lawyerMap = new HashMap<>();
|
|
|
if (!lawyerUserIds.isEmpty()) {
|
|
|
@@ -112,7 +116,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
.collect(Collectors.toMap(LawyerUser::getId, lawyer -> lawyer, (k1, k2) -> k1));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 轉換為VO並填充律師信息
|
|
|
final Map<Integer, LawyerUser> finalLawyerMap = lawyerMap;
|
|
|
List<LawyerConsultationOrderVO> voList = records.stream()
|
|
|
@@ -120,7 +124,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
LawyerConsultationOrderVO vo = new LawyerConsultationOrderVO();
|
|
|
// 複製訂單基本信息
|
|
|
BeanUtils.copyProperties(order, vo);
|
|
|
-
|
|
|
+
|
|
|
// 填充律師信息
|
|
|
LawyerUser lawyer = finalLawyerMap.get(order.getLawyerUserId());
|
|
|
if (lawyer != null) {
|
|
|
@@ -143,11 +147,11 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
vo.setNickName(lawyer.getNickName());
|
|
|
vo.setPersonalIntroduction(lawyer.getPersonalIntroduction());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return vo;
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
+
|
|
|
voPage.setRecords(voList);
|
|
|
return voPage;
|
|
|
}
|
|
|
@@ -181,5 +185,83 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
return R.fail("删除失败");
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Map<String, Object>> startConsultation(Integer lawyerId, String question, String sessionId, Integer clientUserId, Integer problemScenarId) {
|
|
|
+ log.info("LawyerConsultationOrderServiceImpl.startConsultation?lawyerId={},question={},sessionId={},clientUserId={},problemScenarId={}",
|
|
|
+ lawyerId, question, sessionId, clientUserId, problemScenarId);
|
|
|
+
|
|
|
+ // 创建咨询订单
|
|
|
+ LawyerConsultationOrder order = new LawyerConsultationOrder();
|
|
|
+ order.setLawyerUserId(lawyerId);
|
|
|
+ order.setClientUserId(clientUserId);
|
|
|
+ order.setProblemScenarioId(problemScenarId);
|
|
|
+ order.setProblemDescription(question);
|
|
|
+ order.setOrderStatus(0); // 待支付
|
|
|
+ order.setPaymentStatus(0); // 未支付
|
|
|
+
|
|
|
+ boolean saved = this.save(order);
|
|
|
+ if (!saved) {
|
|
|
+ return R.fail("创建咨询订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("consultationId", order.getId());
|
|
|
+ result.put("lawyerId", lawyerId);
|
|
|
+ result.put("status", "pending"); // pending(待响应), active(进行中), closed(已结束)
|
|
|
+ result.put("createTime", order.getCreatedTime() != null ?
|
|
|
+ new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(order.getCreatedTime()) : "");
|
|
|
+
|
|
|
+ return R.data(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<LawyerConsultationOrder> consultNow(Integer clientUserId, Integer lawyerUserId, Integer problemScenarioId, String problemDescription, BigDecimal orderAmount) {
|
|
|
+ log.info("LawyerConsultationOrderServiceImpl.consultNow?clientUserId={},lawyerUserId={},problemScenarioId={},problemDescription={},orderAmount={}",
|
|
|
+ clientUserId, lawyerUserId, problemScenarioId, problemDescription, orderAmount);
|
|
|
+
|
|
|
+ LawyerConsultationOrder order = new LawyerConsultationOrder();
|
|
|
+ order.setClientUserId(clientUserId);
|
|
|
+ order.setLawyerUserId(lawyerUserId);
|
|
|
+ order.setProblemScenarioId(problemScenarioId);
|
|
|
+ order.setProblemDescription(problemDescription);
|
|
|
+ order.setOrderAmount(orderAmount);
|
|
|
+ order.setOrderStatus(0);
|
|
|
+ order.setPaymentStatus(0);
|
|
|
+ order.setOrderTime(new Date());
|
|
|
+ order.setValidityPeriod(DateUtils.addDays(new Date(), 7));
|
|
|
+ order.setCreatedTime(new Date());
|
|
|
+ order.setUpdatedTime(new Date());
|
|
|
+ order.setDeleteFlag(0);
|
|
|
+ //订单编号想要LAW+年月日(8位数字)+随机5位数字这种格式的
|
|
|
+ String orderNumber = "LAW" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%05d", RandomUtils.nextInt(100000));
|
|
|
+ order.setOrderNumber(orderNumber);
|
|
|
+ boolean result = this.save(order);
|
|
|
+ if (result) {
|
|
|
+ return R.data(order);
|
|
|
+ }
|
|
|
+ return R.fail("新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<LawyerConsultationOrder> payStatus(Integer id, Integer paymentStatus, Integer orderStatus) {
|
|
|
+ log.info("LawyerConsultationOrderServiceImpl.payStatus?id={},paymentStatus={},orderStatus={}",
|
|
|
+ id, paymentStatus, orderStatus);
|
|
|
+ LawyerConsultationOrder order = new LawyerConsultationOrder();
|
|
|
+ order.setId(id);
|
|
|
+ order.setPaymentStatus(paymentStatus);
|
|
|
+ order.setOrderStatus(orderStatus);
|
|
|
+ order.setUpdatedTime(new Date());
|
|
|
+ order.setDeleteFlag(0);
|
|
|
+ order.setPaymentTime(new Date());
|
|
|
+ boolean result = this.updateById(order);
|
|
|
+ if (result) {
|
|
|
+ return R.data(order);
|
|
|
+ }
|
|
|
+ return R.fail("失败");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|