|
|
@@ -198,6 +198,13 @@ public class ChargeApiController {
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("stations", resultList);
|
|
|
+
|
|
|
+ // 检查用户是否有新用户优惠
|
|
|
+ if (cacheUser != null) {
|
|
|
+ Map<String, Object> discountInfo = checkUserDiscount(cacheUser);
|
|
|
+ result.put("discountInfo", discountInfo);
|
|
|
+ }
|
|
|
+
|
|
|
return Result.success(result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
@@ -248,6 +255,8 @@ public class ChargeApiController {
|
|
|
*/
|
|
|
@PostMapping("/getDeviceInfo")
|
|
|
public Result<?> getDeviceInfo(@RequestBody Map<String, Object> data, HttpServletRequest request) {
|
|
|
+ UserInfo cacheUser = getUserFromToken(request);
|
|
|
+
|
|
|
try {
|
|
|
Long deviceId = Long.valueOf(data.get("deviceId").toString());
|
|
|
ChargeDevice device = chargeDeviceService.getById(deviceId);
|
|
|
@@ -258,6 +267,12 @@ public class ChargeApiController {
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("device", device);
|
|
|
+
|
|
|
+ // 检查用户是否有新用户优惠
|
|
|
+ if (cacheUser != null) {
|
|
|
+ Map<String, Object> discountInfo = checkUserDiscount(cacheUser);
|
|
|
+ result.put("discountInfo", discountInfo);
|
|
|
+ }
|
|
|
|
|
|
return Result.success(result);
|
|
|
|
|
|
@@ -353,6 +368,199 @@ public class ChargeApiController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取用户账户信息
|
|
|
+ */
|
|
|
+ @PostMapping("/getUserAccount")
|
|
|
+ public Result<?> getUserAccount(HttpServletRequest request) {
|
|
|
+ UserInfo cacheUser = getUserFromToken(request);
|
|
|
+ if (cacheUser == null) {
|
|
|
+ return Result.failed("登录已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ UserAccount userAccount = userAccountService.lambdaQuery()
|
|
|
+ .eq(UserAccount::getUserId, cacheUser.getId())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (userAccount == null) {
|
|
|
+ return Result.failed("账户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("userAccount", userAccount);
|
|
|
+ return Result.success(result);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询用户账户失败", e);
|
|
|
+ return Result.failed("查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户集团账户信息
|
|
|
+ */
|
|
|
+ @PostMapping("/getEcUserAccount")
|
|
|
+ public Result<?> getEcUserAccount(HttpServletRequest request) {
|
|
|
+ UserInfo cacheUser = getUserFromToken(request);
|
|
|
+ if (cacheUser == null) {
|
|
|
+ return Result.failed("登录已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 查询集团用户账户
|
|
|
+ EcUserAccount ecUserAccount = ecUserAccountService.lambdaQuery()
|
|
|
+ .eq(EcUserAccount::getUserId, cacheUser.getId())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (ecUserAccount == null) {
|
|
|
+ return Result.failed("您不是集团用户");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询集团信息
|
|
|
+ EcInfo ecInfo = null;
|
|
|
+ if (cacheUser.getEcId() != null) {
|
|
|
+ ecInfo = ecInfoService.getById(cacheUser.getEcId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("ecUserAccount", ecUserAccount);
|
|
|
+ result.put("ecInfo", ecInfo);
|
|
|
+ return Result.success(result);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询集团账户失败", e);
|
|
|
+ return Result.failed("查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询正在充电的订单
|
|
|
+ */
|
|
|
+ @PostMapping("/queryInChangeByUserId")
|
|
|
+ public Result<?> queryInChangeByUserId(HttpServletRequest request) {
|
|
|
+ UserInfo cacheUser = getUserFromToken(request);
|
|
|
+ if (cacheUser == null) {
|
|
|
+ return Result.failed("登录已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 查询充电中的订单(状态:1-充电中)
|
|
|
+ ChargeOrderInfo orderInfo = chargeOrderInfoService.lambdaQuery()
|
|
|
+ .eq(ChargeOrderInfo::getUserId, cacheUser.getId())
|
|
|
+ .eq(ChargeOrderInfo::getStatus, 1)
|
|
|
+ .one();
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (orderInfo == null) {
|
|
|
+ result.put("isChange", 0); // 没有订单
|
|
|
+ } else {
|
|
|
+ result.put("isChange", 1);
|
|
|
+ result.put("orderInfo", orderInfo);
|
|
|
+ }
|
|
|
+ return Result.success(result);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询充电订单失败", e);
|
|
|
+ return Result.failed("查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户订单列表(按时间和状态筛选)
|
|
|
+ */
|
|
|
+ @PostMapping("/queryOrderList")
|
|
|
+ public Result<?> queryOrderList(@RequestBody Map<String, Object> data, HttpServletRequest request) {
|
|
|
+ UserInfo cacheUser = getUserFromToken(request);
|
|
|
+ if (cacheUser == null) {
|
|
|
+ return Result.failed("登录已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String startDate = data.get("startDate") != null ? data.get("startDate").toString() : null;
|
|
|
+ String endDate = data.get("endDate") != null ? data.get("endDate").toString() : null;
|
|
|
+ String type = data.get("type") != null ? data.get("type").toString() : "-1";
|
|
|
+
|
|
|
+ // 构建查询
|
|
|
+ var query = chargeOrderInfoService.lambdaQuery()
|
|
|
+ .eq(ChargeOrderInfo::getUserId, cacheUser.getId());
|
|
|
+
|
|
|
+ // 根据类型筛选状态
|
|
|
+ if ("-1".equals(type)) {
|
|
|
+ // 全部订单
|
|
|
+ query.in(ChargeOrderInfo::getStatus, 0, 1, 2, 3);
|
|
|
+ } else if ("1".equals(type)) {
|
|
|
+ // 进行中订单(充电中、结算中)
|
|
|
+ query.in(ChargeOrderInfo::getStatus, 1, 2);
|
|
|
+ } else if ("2".equals(type)) {
|
|
|
+ // 已完成订单
|
|
|
+ query.eq(ChargeOrderInfo::getStatus, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按时间筛选(如果需要)
|
|
|
+ // TODO: 添加时间筛选逻辑
|
|
|
+
|
|
|
+ List<ChargeOrderInfo> list = query.orderByDesc(ChargeOrderInfo::getCreateTime).list();
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("list", list);
|
|
|
+ result.put("total", list.size());
|
|
|
+ return Result.success(result);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询订单列表失败", e);
|
|
|
+ return Result.failed("查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户欠费订单
|
|
|
+ */
|
|
|
+ @PostMapping("/queryOrderList-arrearage")
|
|
|
+ public Result<?> queryOrderListByArrearage(HttpServletRequest request) {
|
|
|
+ UserInfo cacheUser = getUserFromToken(request);
|
|
|
+ if (cacheUser == null) {
|
|
|
+ return Result.failed("登录已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 查询待补缴的订单
|
|
|
+ ChargeOrderInfo orderInfo = chargeOrderInfoService.lambdaQuery()
|
|
|
+ .eq(ChargeOrderInfo::getUserId, cacheUser.getId())
|
|
|
+ .eq(ChargeOrderInfo::getMaspStatus, 1) // 待补缴
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (orderInfo == null) {
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(orderInfo);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询欠费订单失败", e);
|
|
|
+ return Result.failed("查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询集团信息
|
|
|
+ */
|
|
|
+ @PostMapping("/queryEcInfo")
|
|
|
+ public Result<?> queryEcInfo(@RequestBody Map<String, Object> data, HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ Long ecId = Long.valueOf(data.get("ecId").toString());
|
|
|
+ EcInfo ecInfo = ecInfoService.getById(ecId);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("ecInfo", ecInfo);
|
|
|
+ return Result.success(result);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询集团信息失败", e);
|
|
|
+ return Result.failed("查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断当前时间是否在时间段内
|
|
|
*/
|
|
|
@@ -424,4 +632,41 @@ public class ChargeApiController {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查用户是否有新用户优惠
|
|
|
+ */
|
|
|
+ private Map<String, Object> checkUserDiscount(UserInfo userInfo) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ try {
|
|
|
+ // 查询该用户是否有充电记录
|
|
|
+ long chargeCount = chargeOrderInfoService.lambdaQuery()
|
|
|
+ .eq(ChargeOrderInfo::getUserId, userInfo.getId())
|
|
|
+ .eq(ChargeOrderInfo::getStatus, 3) // 已完成的订单
|
|
|
+ .count();
|
|
|
+
|
|
|
+ // 如果是新用户(没有充电记录),查询新用户优惠活动
|
|
|
+ if (chargeCount == 0) {
|
|
|
+ NewUserDiscount discount = newUserDiscountService.lambdaQuery()
|
|
|
+ .eq(NewUserDiscount::getStatus, 1)
|
|
|
+ .le(NewUserDiscount::getBeginTime, java.time.LocalDateTime.now())
|
|
|
+ .ge(NewUserDiscount::getEndTime, java.time.LocalDateTime.now())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (discount != null) {
|
|
|
+ result.put("hasDiscount", true);
|
|
|
+ result.put("discount", discount);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("hasDiscount", false);
|
|
|
+ return result;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("检查新用户优惠失败", e);
|
|
|
+ result.put("hasDiscount", false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|