Merge remote-tracking branch 'origin/main'

This commit is contained in:
attiya 2025-05-22 16:56:27 +08:00
commit 7753b79063
16 changed files with 250 additions and 174 deletions

View File

@ -38,19 +38,6 @@
<version>6.10.0</version> <!-- 匹配InfluxDB 2.x版本 -->
</dependency>
<!-- JTS 空间计算库 -->
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.19.0</version>
</dependency>
<!-- Proj4j坐标转换库 -->
<dependency>
<groupId>org.osgeo</groupId>
<artifactId>proj4j</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<build>

View File

@ -1,12 +1,5 @@
package com.cdzy.common.utils;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.osgeo.proj4j.*;
import java.util.List;
/**
* 坐标转换工具类
*
@ -111,78 +104,4 @@ public class CoordinateUtil {
return GCJ02ToBD(gcj02);
}
private static final CRSFactory crsFactory = new CRSFactory();
/**
* GCJ-02 WGS84
* 输入的坐标点必须是GCJ-02坐标系的经纬度
*
* @param lon 经度
* @param lat 纬度
* @return WGS84坐标
*/
public static Double[] GCJ02ToWGS84(double lon, double lat) {
// 使用Proj4j进行坐标转换需添加Proj4j依赖
CoordinateReferenceSystem gcj02 = crsFactory.createFromName("EPSG:4490"); // 国家2000坐标系近似GCJ-02
CoordinateReferenceSystem wgs84 = crsFactory.createFromName("EPSG:4326");
CoordinateTransform transform = new CoordinateTransformFactory().createTransform(gcj02, wgs84);
ProjCoordinate src = new ProjCoordinate(lon, lat);
ProjCoordinate dst = new ProjCoordinate();
transform.transform(src, dst);
return new Double[]{dst.x, dst.y};
}
/**
* GCJ-02 WGS84
* 输入的坐标点必须是GCJ-02坐标系的经纬度
*
* @param lon 经度
* @param lat 纬度
* @return WGS84坐标
*/
public static Coordinate gcj02ToWgs84(double lon, double lat) {
// 使用Proj4j进行坐标转换需添加Proj4j依赖
CoordinateReferenceSystem gcj02 = crsFactory.createFromName("EPSG:4490"); // 国家2000坐标系近似GCJ-02
CoordinateReferenceSystem wgs84 = crsFactory.createFromName("EPSG:4326");
CoordinateTransform transform = new CoordinateTransformFactory().createTransform(gcj02, wgs84);
ProjCoordinate src = new ProjCoordinate(lon, lat);
ProjCoordinate dst = new ProjCoordinate();
transform.transform(src, dst);
return new Coordinate(dst.x, dst.y);
}
private static final GeometryFactory geometryFactory = new GeometryFactory();
/**
* 计算路径总长度单位
* 输入的坐标点必须是WGS84坐标系的经纬度
*
* @param points 坐标点列表每个点为[经度, 纬度]
* @return 总长度
*/
public static Double calculateTotalDistance(List<Double[]> points) {
// 转换坐标并构建线串
LineString lineString = convertToLineString(points);
// 使用JTS计算几何距离需确保坐标系为投影坐标系
return lineString.getLength();
}
/**
* 转换坐标点列表为LineString
*
* @param points 坐标点列表
* @return LineString对象
*/
private static LineString convertToLineString(List<Double[]> points) {
Coordinate[] coords = new Coordinate[points.size()];
for (int i = 0; i < points.size(); i++) {
Double[] p = points.get(i);
Coordinate wgs84Coord = gcj02ToWgs84(p[0], p[1]); // GCJ-02转WGS84
coords[i]= new Coordinate(wgs84Coord.x, wgs84Coord.y);
}
return geometryFactory.createLineString(coords);
}
}

View File

@ -75,10 +75,11 @@ public class EbikeTrackingController {
siteInfo.setSiteId(siteId);
if (siteId == null) {
siteInfo.setSiteName( "不在站点范围内");
}
EbikeSiteRegion siteRegion = ebikeSiteRegionService.getById(siteId);
if (siteRegion != null) {
siteInfo.setSiteName(siteRegion.getSiteName());
}else {
EbikeSiteRegion siteRegion = ebikeSiteRegionService.getById(siteId);
if (siteRegion != null) {
siteInfo.setSiteName(siteRegion.getSiteName());
}
}
return JsonResult.success(siteInfo);
}

View File

@ -4,8 +4,11 @@ import com.cdzy.common.model.JsonResult;
import com.cdzy.common.model.EbikeUserFaultreportDto;
import com.cdzy.common.model.EbikeUserFaultreportQueryDto;
import com.cdzy.common.model.EbikeOrderAttachmentFileDto;
import com.cdzy.orders.model.dto.req.UserOrderFaultQueryDto;
import com.cdzy.orders.model.dto.res.OrderFaultReport;
import com.cdzy.orders.service.EbikeOrderAttachmentFileService;
import com.cdzy.orders.uitls.MinioUtil;
import com.mybatisflex.core.paginate.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -53,7 +56,7 @@ public class EbikeUserFaultreportController {
@PostMapping("remove")
public JsonResult<?> remove(@RequestParam(name = "id") String id) {
boolean r = ebikeUserFaultreportService.deleteById(id);
return r? JsonResult.success() : JsonResult.failed("删除用户上报故障信息失败");
return r ? JsonResult.success() : JsonResult.failed("删除用户上报故障信息失败");
}
/**
@ -65,7 +68,7 @@ public class EbikeUserFaultreportController {
@PostMapping("update")
public JsonResult<?> update(@RequestBody EbikeUserFaultreport ebikeUserFaultreport) {
boolean r = ebikeUserFaultreportService.updateById(ebikeUserFaultreport);
return r? JsonResult.success() : JsonResult.failed("更新用户上报故障信息失败");
return r ? JsonResult.success() : JsonResult.failed("更新用户上报故障信息失败");
}
/**
@ -83,7 +86,7 @@ public class EbikeUserFaultreportController {
return ebikeUserFaultreport;
}).toList();
boolean r = ebikeUserFaultreportService.updateBatch(ebikeUserFaultreportList);
return r? JsonResult.success() : JsonResult.failed("批量更新用户上报故障信息失败");
return r ? JsonResult.success() : JsonResult.failed("批量更新用户上报故障信息失败");
}
/**
@ -102,11 +105,11 @@ public class EbikeUserFaultreportController {
BeanUtils.copyProperties(entity, dto);
// 获取附件信息
List<EbikeOrderAttachmentFileDto> attachmentFiles = ebikeOrderAttachmentFileService.getFilesByBusiId(id)
.stream().map(attachmentFile ->{
EbikeOrderAttachmentFileDto attachmentFileDto = new EbikeOrderAttachmentFileDto();
BeanUtils.copyProperties(attachmentFile, attachmentFileDto);
.stream().map(attachmentFile -> {
EbikeOrderAttachmentFileDto attachmentFileDto = new EbikeOrderAttachmentFileDto();
BeanUtils.copyProperties(attachmentFile, attachmentFileDto);
attachmentFileDto.setUrl(minioUtil.getBucketFileUrl(attachmentFile.getFileKey()));
return attachmentFileDto;
return attachmentFileDto;
}).toList();
dto.setAttachmentFiles(attachmentFiles);
return JsonResult.success(dto);
@ -126,6 +129,7 @@ public class EbikeUserFaultreportController {
}
return JsonResult.success(list);
}
/**
* 根据用户上报故障信息userId获取列表信息
*
@ -133,9 +137,24 @@ public class EbikeUserFaultreportController {
* @return 用户上报故障信息userId获取列表信息
*/
@PostMapping("getFaultListByWeChatUser")
public JsonResult<?> getFaultListByWeChatUser(@RequestBody Map<String,Object> params) {
public JsonResult<?> getFaultListByWeChatUser(@RequestBody Map<String, Object> params) {
List<EbikeUserFaultreport> faultListByWeChatUser = ebikeUserFaultreportService.getFaultListByWeChatUser(params);
return JsonResult.success(faultListByWeChatUser);
}
/**
* 获取用户订单故障上报记录列表
*
* @param userOrderFaultQueryDto
* @return
*/
@PostMapping("getUserOrderFaultRecord")
public JsonResult<?> getUserOrderFaultRecord(@RequestBody UserOrderFaultQueryDto userOrderFaultQueryDto) {
try {
Page<OrderFaultReport> orderFaultReports = ebikeUserFaultreportService.getUserOrderFaultRecord(userOrderFaultQueryDto);
return JsonResult.success(orderFaultReports);
} catch (Exception e) {
return JsonResult.failed("getUserOrderFaultRecord===>出错了");
}
}
}

View File

@ -0,0 +1,28 @@
package com.cdzy.orders.model.dto.req;
import com.cdzy.common.model.PageParam;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* @author:Ding
* @ClassName:UserOrderFaultQueryDto
* @Package:com.cdzy.orders.model.dto.req.UserOrderFaultQueryDto
* @Description:用户订单故障上报查询参数
* @CreateDate:2025年05月22日
* @Version:V1.0
**/
@Data
public class UserOrderFaultQueryDto {
/**
* 订单编号
*/
private String orderId;
/**
* 分页参数
*/
@NotNull(message = "分页参数不能为空")
private PageParam pageParam;
}

View File

@ -1,8 +1,9 @@
package com.cdzy.payment.model.dto;
package com.cdzy.orders.model.dto.res;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author:Ding
@ -15,10 +16,12 @@ import java.time.LocalDateTime;
@Data
public class OrderFaultReport {
private String faultReportId;
/**
* 反馈用户
*/
private String userName;
private String reportUser;
/**
* 坐标
@ -28,20 +31,20 @@ public class OrderFaultReport {
/**
* 故障类型
*/
private String faultType;
private String faultPart;
/**
* 图片
*/
private String image;
private List<String> image;
/**
* 备注
*/
private String remark;
private String faultDescription;
/**
* 创建时间
*/
private LocalDateTime createTime;
private LocalDateTime reportAt;
}

View File

@ -3,6 +3,7 @@ package com.cdzy.orders.model.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
@ -107,4 +108,9 @@ public class EbikeUserFaultreport implements Serializable {
*/
private String workorderId;
/**
* 订单编号
*/
private String orderCode;
}

View File

@ -2,6 +2,9 @@ package com.cdzy.orders.service;
import com.cdzy.common.model.EbikeUserFaultreportQueryDto;
import com.cdzy.common.model.EbikeUserFaultreportDto;
import com.cdzy.orders.model.dto.req.UserOrderFaultQueryDto;
import com.cdzy.orders.model.dto.res.OrderFaultReport;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.cdzy.orders.model.entity.EbikeUserFaultreport;
@ -46,4 +49,11 @@ public interface EbikeUserFaultreportService extends IService<EbikeUserFaultrepo
* @return 用户上报故障信息userId获取列表信息
*/
List<EbikeUserFaultreport> getFaultListByWeChatUser( Map<String,Object> params);
/**
*
* @param userOrderFaultQueryDto
* @return
*/
Page<OrderFaultReport> getUserOrderFaultRecord(UserOrderFaultQueryDto userOrderFaultQueryDto);
}

View File

@ -4,12 +4,17 @@ import cn.hutool.core.map.MapUtil;
import com.cdzy.common.model.EbikeOrderAttachmentFileDto;
import com.cdzy.common.model.EbikeUserFaultreportQueryDto;
import com.cdzy.common.model.EbikeUserFaultreportDto;
import com.cdzy.orders.mapper.EbikeOrderAttachmentFileMapper;
import com.cdzy.orders.model.dto.req.UserOrderFaultQueryDto;
import com.cdzy.orders.model.dto.res.EbikeUserDto;
import com.cdzy.orders.model.dto.res.OrderFaultReport;
import com.cdzy.orders.model.entity.EbikeAttachefileAssociated;
import com.cdzy.orders.model.entity.EbikeOrderAttachmentFile;
import com.cdzy.orders.service.EbikeAttachefileAssociatedService;
import com.cdzy.orders.service.EbikeOrderAttachmentFileService;
import com.cdzy.orders.uitls.MinioUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cdzy.orders.model.entity.EbikeUserFaultreport;
@ -22,11 +27,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.cdzy.orders.model.entity.table.EbikeAttachefileAssociatedTableDef.EBIKE_ATTACHEFILE_ASSOCIATED;
import static com.cdzy.orders.model.entity.table.EbikeOrderAttachmentFileTableDef.EBIKE_ORDER_ATTACHMENT_FILE;
import static com.cdzy.orders.model.entity.table.EbikeUserFaultreportTableDef.EBIKE_USER_FAULTREPORT;
import static com.cdzy.orders.model.entity.table.EbikeUserTableDef.EBIKE_USER;
/**
* 用户上报故障信息 服务层实现
@ -36,7 +44,7 @@ import static com.cdzy.orders.model.entity.table.EbikeUserFaultreportTableDef.EB
*/
@Slf4j
@Service
public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultreportMapper, EbikeUserFaultreport> implements EbikeUserFaultreportService{
public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultreportMapper, EbikeUserFaultreport> implements EbikeUserFaultreportService {
@Resource
private EbikeAttachefileAssociatedService ebikeAttachmentFileAssosiatedService;
@ -47,6 +55,7 @@ public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultr
@Autowired
private EbikeUserFaultreportMapper ebikeUserFaultreportMapper;
@Transactional
@Override
public boolean save(EbikeUserFaultreportDto ebikeUserFaultreport) {
@ -77,7 +86,7 @@ public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultr
@Transactional
@Override
public boolean deleteById(String id) {
try{
try {
// 删除附件信息
List<EbikeOrderAttachmentFile> attachmentFiles = ebikeOrderAttachmentFileService.getFilesByBusiId(id);
if (!attachmentFiles.isEmpty()) {
@ -101,17 +110,17 @@ public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultr
public List<EbikeUserFaultreportDto> list(EbikeUserFaultreportQueryDto queryParam) {
QueryWrapper query = QueryWrapper.create()
.where(EBIKE_USER_FAULTREPORT.BIKE_CODE.eq(queryParam.getBikeCode()));
if(queryParam.getWorkorderId()==null||queryParam.getWorkorderId().isEmpty()){
if (queryParam.getWorkorderId() == null || queryParam.getWorkorderId().isEmpty()) {
query.and(EBIKE_USER_FAULTREPORT.WORKORDER_ID.isNull());
}else{
} else {
query.and(EBIKE_USER_FAULTREPORT.WORKORDER_ID.eq(queryParam.getWorkorderId()));
}
if(queryParam.getFaultPart()!=null&&!queryParam.getFaultPart().isEmpty()){
if (queryParam.getFaultPart() != null && !queryParam.getFaultPart().isEmpty()) {
query.and(EBIKE_USER_FAULTREPORT.FAULT_PART.like(queryParam.getFaultPart()));
}
List<EbikeUserFaultreport> list = list(query);
if (list==null) {
if (list == null) {
return null;
}
List<EbikeUserFaultreportDto> dtoList = list.stream().map(entity -> {
@ -119,7 +128,7 @@ public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultr
BeanUtils.copyProperties(entity, dto);
// 获取附件信息
List<EbikeOrderAttachmentFileDto> attachmentFiles = ebikeOrderAttachmentFileService.getFilesByBusiId(dto.getFaultReportId())
.stream().map(attachmentFile ->{
.stream().map(attachmentFile -> {
EbikeOrderAttachmentFileDto attachmentFileDto = new EbikeOrderAttachmentFileDto();
BeanUtils.copyProperties(attachmentFile, attachmentFileDto);
attachmentFileDto.setFileBucket(MinioUtil.BUCKET_ORDERS);
@ -138,14 +147,46 @@ public class EbikeUserFaultreportServiceImpl extends ServiceImpl<EbikeUserFaultr
* @param params
* @return 用户上报故障信息userId获取列表信息
*/
public List<EbikeUserFaultreport> getFaultListByWeChatUser(Map<String,Object> params) {
String userId= MapUtil.getStr(params,"userId");
Map<String,Object> pageParam = ( Map<String,Object>)params.get("pageParam");
Integer pageNum= MapUtil.getInt(pageParam,"pageNum");
Integer pageSize= MapUtil.getInt(pageParam,"pageSize");
public List<EbikeUserFaultreport> getFaultListByWeChatUser(Map<String, Object> params) {
String userId = MapUtil.getStr(params, "userId");
Map<String, Object> pageParam = (Map<String, Object>) params.get("pageParam");
Integer pageNum = MapUtil.getInt(pageParam, "pageNum");
Integer pageSize = MapUtil.getInt(pageParam, "pageSize");
QueryWrapper query = QueryWrapper.create();
query.eq("report_user",userId);
query.eq("report_user", userId);
Page<EbikeUserFaultreport> paginate = ebikeUserFaultreportMapper.paginate(pageNum, pageSize, query);
return paginate.getRecords();
}
@Override
public Page<OrderFaultReport> getUserOrderFaultRecord(UserOrderFaultQueryDto userOrderFaultQueryDto) {
QueryWrapper query = QueryWrapper.create()
.select(EBIKE_USER_FAULTREPORT.FAULT_PART, EBIKE_USER_FAULTREPORT.REPORT_AT,
EBIKE_USER_FAULTREPORT.FAULT_DESCRIPTION, EBIKE_USER.NICKNAME.as("report_user"),
QueryMethods.concat(EBIKE_USER_FAULTREPORT.LONGITUDE,
EBIKE_USER_FAULTREPORT.LATITUDE).as("coordinate"),
EBIKE_USER_FAULTREPORT.FAULT_REPORT_ID)
.leftJoin(EBIKE_USER).on(EBIKE_USER_FAULTREPORT.REPORT_USER.eq(EBIKE_USER.USER_ID))
.where(EBIKE_USER_FAULTREPORT.ORDER_CODE.eq(userOrderFaultQueryDto.getOrderId()));
Page<OrderFaultReport> page = userOrderFaultQueryDto.getPageParam().getPage();
Page<OrderFaultReport> orderFaultReportPage = ebikeUserFaultreportMapper.paginateAs(page, query, OrderFaultReport.class);
List<OrderFaultReport> records = orderFaultReportPage.getRecords();
for (OrderFaultReport record : records) {
QueryWrapper file = QueryWrapper.create()
.leftJoin(EBIKE_ATTACHEFILE_ASSOCIATED)
.on(EBIKE_ATTACHEFILE_ASSOCIATED.ATTACHE_FILE
.eq(EBIKE_ORDER_ATTACHMENT_FILE.FILE_KEY))
.where(EBIKE_ATTACHEFILE_ASSOCIATED.BUSI_ID.eq(record.getFaultReportId()));
List<EbikeOrderAttachmentFile> list = ebikeOrderAttachmentFileService.list(file);
List<String> fileUrl = new ArrayList<>();
for (EbikeOrderAttachmentFile ebikeOrderAttachmentFile : list) {
String url = minioUtil.getBucketFileUrl(ebikeOrderAttachmentFile.getFileKey());
fileUrl.add(url);
}
record.setImage(fileUrl);
}
return orderFaultReportPage;
}
}

View File

@ -42,7 +42,7 @@ public class PayInfo {
private LocalDateTime payTime;
/**
* 总优惠金额
* 交易流水号
*/
private String tradingNumber;
}

View File

@ -55,5 +55,5 @@ public interface EbikePaymentService extends IService<EbikePayment> {
* @param orderId 退款id
* @return 订单详情
*/
Map getOrderDetail(String orderId);
Map<String, Object> getOrderDetail(String orderId);
}

View File

@ -88,7 +88,7 @@ public class EbikePaymentServiceImpl extends ServiceImpl<EbikePaymentMapper, Ebi
}
@Override
public Map getOrderDetail(String orderId) {
public Map<String, Object> getOrderDetail(String orderId) {
QueryWrapper query = QueryWrapper.create()
.select(EBIKE_PAYMENT.COST_PRICE.as("totalAmount"), EBIKE_PAYMENT.TOTAL.as("actualAmount"),
EBIKE_USER_ORDERS.ORDER_ID.as("orderId"), EBIKE_USER_ORDERS.BIKE_CODE.as("bikeCode"),
@ -99,7 +99,8 @@ public class EbikePaymentServiceImpl extends ServiceImpl<EbikePaymentMapper, Ebi
EBIKE_PAYMENT.PAYMENT_TIME.as("payTime"), QueryMethods.case_(EBIKE_PAYMENT.PAYMENT_METHOD)
.when(PayMethod.wechat.name()).then("微信支付")
.when(PayMethod.alipay.name()).then("支付宝")
.when(PayMethod.balance.name()).then("余额").end().as("payMethod")
.when(PayMethod.balance.name()).then("余额").end().as("payMethod"),
EBIKE_PAYMENT.TRANSACTION_ID.as("tradingNumber")
)
.leftJoin(EBIKE_USER_ORDERS).on(EBIKE_USER_ORDERS.ORDER_ID.eq(EBIKE_PAYMENT.ORDER_ID))
.leftJoin(EBIKE_USER).on(EBIKE_USER.USER_ID.eq(EBIKE_USER_ORDERS.USER_ID))

View File

@ -17,7 +17,6 @@ import com.wechat.pay.java.service.refund.model.Status;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import static com.cdzy.payment.model.entity.table.EbikePaymentTableDef.EBIKE_PAYMENT;

View File

@ -17,6 +17,7 @@ import com.cdzy.payment.service.EbikeRefundService;
import com.cdzy.payment.service.WxPayService;
import com.cdzy.payment.utils.GeoCodingUtil;
import com.cdzy.payment.utils.HttpServletUtils;
import com.cdzy.payment.utils.MapUtils;
import com.cdzy.payment.utils.StringUtils;
import com.ebike.feign.clients.MaintenanceFeignClient;
import com.ebike.feign.clients.OperateFeignClient;
@ -608,7 +609,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override
public ResRefundOrderInfo queryRefundApplyOrderById(String orderId) {
Map recDetail = ebikePaymentService.getOrderDetail(orderId);
Map<String, Object> recDetail = ebikePaymentService.getOrderDetail(orderId);
if (recDetail == null) {
log.error("{} 订单不存在", orderId);
return null;
@ -617,11 +618,11 @@ public class WxPayServiceImpl implements WxPayService {
ResRefundOrderInfo orderInfo = new ResRefundOrderInfo();
// 订单信息
OrderInfo order = new OrderInfo();
BeanUtils.copyProperties(recDetail, order);
MapUtils.copyProperties(recDetail, order);
// 用户信息
UserInfo userInfo = new UserInfo();
BeanUtils.copyProperties(recDetail, orderInfo);
MapUtils.copyProperties(recDetail, userInfo);
orderInfo.setUserInfo(userInfo);
// 车辆基本信息
EbikeBikeBaseInfo bike = null;
@ -634,13 +635,13 @@ public class WxPayServiceImpl implements WxPayService {
// 借用信息
BorrowingInfo borrowingInfo = new BorrowingInfo();
BeanUtils.copyProperties(recDetail, borrowingInfo);
MapUtils.copyProperties(recDetail, borrowingInfo);
Double[] borrowLocation = getBikeLocation(borrowingInfo.getBorrowCarCoordinate());
if (bike != null) {
if (borrowLocation != null) {
ReqEbikeSiteQuery siteQuery = new ReqEbikeSiteQuery();
siteQuery.setLatitude(borrowLocation[0]);
siteQuery.setLongitude(borrowLocation[1]);
siteQuery.setLatitude(borrowLocation[1]);
siteQuery.setLongitude(borrowLocation[0]);
siteQuery.setAreaId(Long.parseLong(bike.getReginId()));
JsonResult<?> siteInfo = operateFeignClient.querySite(siteQuery);
if (siteInfo.getCode() == Code.SUCCESS) {
@ -665,13 +666,13 @@ public class WxPayServiceImpl implements WxPayService {
orderInfo.setBorrowingInfo(borrowingInfo);
// 还车信息
ReturnInfo returnInfo = new ReturnInfo();
BeanUtils.copyProperties(recDetail, returnInfo);
MapUtils.copyProperties(recDetail, returnInfo);
Double[] returnLocation = getBikeLocation(returnInfo.getReturnCarCoordinate());
if (bike != null) {
if (returnLocation != null) {
ReqEbikeSiteQuery siteQuery = new ReqEbikeSiteQuery();
siteQuery.setLatitude(returnLocation[0]);
siteQuery.setLongitude(returnLocation[1]);
siteQuery.setLatitude(returnLocation[1]);
siteQuery.setLongitude(returnLocation[0]);
siteQuery.setAreaId(Long.parseLong(bike.getReginId()));
JsonResult<?> siteInfo = operateFeignClient.querySite(siteQuery);
if (siteInfo.getCode() == Code.SUCCESS) {
@ -695,46 +696,15 @@ public class WxPayServiceImpl implements WxPayService {
}
// 骑行时长
if (order.getUnLockTime() != null && order.getLockTime() != null) {
order.setCyclingDuration(String.valueOf(Duration.between(order.getUnLockTime(), order.getLockTime()).toMinutes()));
}
// 轨迹里程
if (order.getUnLockTime() != null && order.getLockTime() != null&& order.getBikeCode()!=null) {
ReqEbikeTrackingDto trackingDto = new ReqEbikeTrackingDto();
trackingDto.setEbikeCode(order.getBikeCode());
trackingDto.setStartTime(order.getUnLockTime());
trackingDto.setEndTime(order.getLockTime());
trackingDto.setInterval("30s");
JsonResult<?> tracking = operateFeignClient.queryEbikeTracking(trackingDto);
if (tracking.getCode() == Code.SUCCESS) {
List<EbikeTrackingDto> trackingList = JSON.parseArray(JSONObject.toJSONString(tracking.getData()), EbikeTrackingDto.class);
List<Double[]> trackingPoints = new ArrayList<>(trackingList.stream().map(t -> new Double[]{t.getLatitude(), t.getLongitude()}).toList());
if (borrowLocation!=null){
trackingPoints.add(0, borrowLocation);
}
if (returnLocation!=null){
trackingPoints.add(returnLocation);
}
Double distance = CoordinateUtil.calculateTotalDistance(trackingPoints);
if (distance > 1000) {
order.setTrajectoryMileage(String.format("%.3f公里", distance));
}else {
order.setTrajectoryMileage(String.format("%d米", Math.round(distance)));
}
}else {
log.error("获取车辆轨迹信息失败,订单编号: {}", orderId);
}
String duration = StringUtils.getDurationTimeString(order.getUnLockTime(), order.getLockTime());
order.setCyclingDuration(duration);
}
orderInfo.setOrderInfo(order);
orderInfo.setReturnInfo(returnInfo);
// 支付信息
PayInfo payInfo = new PayInfo();
BeanUtils.copyProperties(recDetail, payInfo);
orderInfo.setPayInfo(payInfo);
// 支付详情
OrderDetailInfo detailInfo = new OrderDetailInfo();
BeanUtils.copyProperties(recDetail, detailInfo);
MapUtils.copyProperties(recDetail, detailInfo);
detailInfo.setDiscountAmount(detailInfo.getTotalAmount() - detailInfo.getActualAmount());
//查询订单, orderFeingClient.getOrderById(orderId)
JsonResult<?> result = ordersFeignClient.getPaymentDetails(Long.valueOf(orderId));
@ -750,8 +720,15 @@ public class WxPayServiceImpl implements WxPayService {
}
}
}
orderInfo.setOrderDetailInfo(detailInfo);
// 支付信息
PayInfo payInfo = new PayInfo();
MapUtils.copyProperties(recDetail, payInfo);
// 优惠金额
if (detailInfo.getTotalAmount()!= null && detailInfo.getActualAmount()!= null) {
payInfo.setDiscountAmount(detailInfo.getTotalAmount() - detailInfo.getActualAmount());
}
orderInfo.setPayInfo(payInfo);
return orderInfo;
}

View File

@ -0,0 +1,61 @@
package com.cdzy.payment.utils;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.util.Map;
/**
* Map工具类
*
* @author dingchao
* @date 2025/5/22
* @modified by:
*/
public class MapUtils {
/**
* 将map中的值复制到对象中
* 注意map中的key必须和对象中的字段名一致
*
* @param source
* @param target
*/
public static void copyProperties(Map<String, Object> source, Object target) {
Field[] fields = target.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object value = source.getOrDefault(field.getName(), null);
if (value == null) {
continue;
}
try {
// 类型转换逻辑
Class<?> fieldType = field.getType();
Object convertedValue = convertValue(value, fieldType);
field.set(target, convertedValue);
}catch (IllegalAccessException ignored) {
}
}
}
/**
* 自定义类型转换逻辑
*
* @param source 源值
* @param targetType 目标类型
* @return
*/
private static Object convertValue(Object source, Class<?> targetType) {
if (targetType == Integer.class) {
return Integer.parseInt(source.toString());
} else if (targetType == Double.class) {
return Double.parseDouble(source.toString());
} else if (targetType == LocalDate.class && source instanceof String) {
return LocalDate.parse((String) source);
} else if (targetType.isEnum() && source instanceof String) {
return Enum.valueOf((Class<Enum>) targetType, (String) source);
}
return source; // 其他类型直接赋值
}
}

View File

@ -3,6 +3,7 @@ package com.cdzy.payment.utils;
import com.mybatisflex.core.keygen.IKeyGenerator;
import com.mybatisflex.core.keygen.KeyGeneratorFactory;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
@ -63,7 +64,30 @@ public class StringUtils {
return String.valueOf(key);
}
/**
* 计算两个时间的时间差
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 时间差字符串格式为"小时小时分分秒秒"
*/
public static String getDurationTimeString(LocalDateTime startTime, LocalDateTime endTime) {
Duration duration = Duration.between(startTime, endTime);
long totalSeconds = duration.toSeconds();
final int[] units = {3600, 60, 1};
String[] labels = {"小时", "", ""};
StringBuilder result = new StringBuilder();
for (int i = 0; i < units.length; i++) {
long value = totalSeconds / units[i];
if (value > 0 || !result.isEmpty()) {
result.append(value).append(labels[i]);
totalSeconds %= units[i];
}
}
return result.toString();
}
//public static void main(String[] args) {
// System.out.println(formatLocalDatetime(LocalDateTime.now()));