From 7c401c06665fa323b728d09b6134dcdadbfbb4bb Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Mon, 8 Jul 2024 14:18:58 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8F=90=E7=8E=B0=E6=89=A3=E6=AC=BE=E7=AD=89?= =?UTF-8?q?=202.=E5=91=BD=E4=BB=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/app/AppController.java | 8 +- .../controller/app/AppVerifyController.java | 2 +- .../web/controller/iot/domain/LogEntry.java | 4 + .../iot/receive/ReceiveController.java | 10 +- .../controller/system/AsDeviceController.java | 29 ++-- .../system/EtCommandLogController.java | 104 +++++++++++++ .../controller/system/EtOrderController.java | 50 ++++++ .../controller/system/SysDeptController.java | 3 - .../controller/system/SysLoginController.java | 7 + .../common/constant/ServiceConstants.java | 32 +++- .../core/controller/BaseController.java | 8 +- .../com/ruoyi/common/utils/CommonUtil.java | 42 ++--- .../com/ruoyi/common/utils/PageUtils.java | 2 +- .../com/ruoyi/system/domain/AsDevice.java | 10 ++ .../ruoyi/system/domain/EtCapitalFlow.java | 4 + .../com/ruoyi/system/domain/EtCommandLog.java | 48 ++++++ .../java/com/ruoyi/system/domain/EtModel.java | 5 + .../ruoyi/system/domain/EtOperatingArea.java | 3 + .../java/com/ruoyi/system/domain/EtOrder.java | 9 ++ .../com/ruoyi/system/domain/EtRefund.java | 8 + .../com/ruoyi/system/domain/EtWithdraw.java | 4 + .../ruoyi/system/mapper/AsDeviceMapper.java | 8 + .../system/mapper/EtCommandLogMapper.java | 61 ++++++++ .../ruoyi/system/mapper/EtRefundMapper.java | 2 +- .../system/service/IAsDeviceService.java | 8 + .../system/service/IEtCommandLogService.java | 61 ++++++++ .../ruoyi/system/service/IEtOrderService.java | 2 +- .../system/service/IEtRefundService.java | 2 +- .../ruoyi/system/service/IWxPayService.java | 3 +- .../service/impl/AsDeviceServiceImpl.java | 82 +++++++++- .../service/impl/CallbackServiceImpl.java | 56 ++++--- .../service/impl/EtCommandLogServiceImpl.java | 93 +++++++++++ .../service/impl/EtFaultServiceImpl.java | 6 +- .../service/impl/EtModelServiceImpl.java | 10 ++ .../service/impl/EtOrderServiceImpl.java | 144 ++++++++++++------ .../service/impl/EtRefundServiceImpl.java | 2 +- .../service/impl/EtTripLogServiceImpl.java | 2 +- .../service/impl/EtWithdrawServiceImpl.java | 44 +++++- .../service/impl/SysUserServiceImpl.java | 9 +- .../system/service/impl/WxPayService.java | 5 +- .../java/com/ruoyi/system/task/EtTask.java | 74 ++++----- .../mapper/system/AsArticleMapper.xml | 4 +- .../mapper/system/AsDeviceMapper.xml | 51 ++++++- .../mapper/system/EtAdminOrderMapper.xml | 6 +- .../mapper/system/EtCapitalFlowMapper.xml | 7 +- .../mapper/system/EtCommandLogMapper.xml | 85 +++++++++++ .../mapper/system/EtOperatingAreaMapper.xml | 6 +- .../resources/mapper/system/EtOrderMapper.xml | 20 ++- .../mapper/system/EtRefundMapper.xml | 3 +- .../mapper/system/EtWithdrawMapper.xml | 21 +-- 50 files changed, 1047 insertions(+), 222 deletions(-) create mode 100644 electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCommandLogController.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/mapper/EtCommandLogMapper.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/service/IEtCommandLogService.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCommandLogServiceImpl.java create mode 100644 electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java index 4272102..ac23d79 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java @@ -295,10 +295,10 @@ public class AppController extends BaseController @GetMapping("/getAddress") public AjaxResult deviceList(String location) { - logger.info("根据定位获取地址:【location="+location+"】"); - String address = CommonUtil.getAddressByGeo(location); - logger.info("根据定位获取地址:【address="+address+"】"); - return AjaxResult.success("操作成功", address); +// logger.info("根据定位获取地址:【location="+location+"】"); +// String address = CommonUtil.getAddressByGeo(location); +// logger.info("根据定位获取地址:【address="+address+"】"); + return AjaxResult.success(); } /** diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index d98d39e..1772be6 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -291,7 +291,7 @@ public class AppVerifyController extends BaseController * 押金抵扣 */ @Log(title = "押金抵扣", businessType = BusinessType.DEDUCTION) - @PutMapping("/order/deduction") + @PostMapping("/order/deduction") public AjaxResult deduction(@RequestBody EtOrder etOrder) { logger.info("【押金抵扣请求】:{}", JSON.toJSON(etOrder)); diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/domain/LogEntry.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/domain/LogEntry.java index b04456e..8e61665 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/domain/LogEntry.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/domain/LogEntry.java @@ -35,5 +35,9 @@ public class LogEntry { private Integer bat;//电池电压 "bat":571 ==> 57.1V private Integer csq;//信号强度 + + private Integer s;//卫星数量 + + private Integer q;//质量 } } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java index 8ab1a33..7a44b23 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java @@ -202,6 +202,8 @@ public class ReceiveController { device.setLastTime(DateUtils.getNowDate()); // 信号强度 device.setSignalStrength(value.getCsq()); + device.setSatellites(value.getS()); + device.setQuality(value.getQ()); int i = asDeviceService.updateLocation(device); if(i>0){ log.info("更新定位成功==========================>" +logEntry.getDevName()); @@ -225,7 +227,7 @@ public class ReceiveController { boolean inPolygon = asDeviceService.isNoRidingAreaWithTolerance(device.getSn(), device.getAreaId(),20); if (inPolygon) { log.info("距离禁行区20米内发送警告命令--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "距离禁行区20米内"); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY2, "距离禁行区20米内"); } } /** 3.超出运营区外断电*/ @@ -310,8 +312,8 @@ public class ReceiveController { adminOrder.setLatitude(device.getLatitude()); adminOrder.setLongitude(device.getLongitude()); adminOrder.setType("2"); - String location = device.getLongitude() + ","+device.getLatitude(); - adminOrder.setAddress(CommonUtil.getAddressByGeo(location)); +// String location = device.getLongitude() + ","+device.getLatitude(); +// adminOrder.setAddress(CommonUtil.getAddressByGeo(location)); int i1 = etAdminOrderService.insertEtAdminOrder(adminOrder); if (i1 > 0) { log.info("生成换电工单成功"); @@ -352,6 +354,8 @@ public class ReceiveController { device.setRemainingPower(electricQuantity.toString()); device.setLastTime(DateUtils.getNowDate()); device.setSignalStrength(value.getCsq()); + device.setSatellites(value.getS()); + device.setQuality(value.getQ()); int i = asDeviceService.updateLocation(device); if(i>0){ log.info("未获取到定位===============保存电压等数值成功===========>" +logEntry.getDevName()); diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java index e1f818f..eff0c33 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java @@ -1,27 +1,20 @@ package com.ruoyi.web.controller.system; -import java.util.List; -import javax.servlet.http.HttpServletResponse; - import cn.hutool.core.util.StrUtil; -import com.ruoyi.system.domain.AsDevice; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.system.service.IAsDeviceService; -import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.AsDevice; +import com.ruoyi.system.service.IAsDeviceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * 设备Controller @@ -102,7 +95,7 @@ public class AsDeviceController extends BaseController if(!asDeviceService.checkMACUnique(asDevice)){ return error("修改车辆'" + asDevice.getDeviceName() + "'失败,MAC已存在"); } - return toAjax(asDeviceService.updateAsDevice(asDevice)); + return toAjax(asDeviceService.updateAsDevice2(asDevice)); } /** diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCommandLogController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCommandLogController.java new file mode 100644 index 0000000..cd0adf7 --- /dev/null +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCommandLogController.java @@ -0,0 +1,104 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.EtCommandLog; +import com.ruoyi.system.service.IEtCommandLogService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 命令日志Controller + * + * @author 邱贞招 + * @date 2024-07-06 + */ +@RestController +@RequestMapping("/system/commandLog") +public class EtCommandLogController extends BaseController +{ + @Autowired + private IEtCommandLogService etCommandLogService; + + /** + * 查询命令日志列表 + */ + @PreAuthorize("@ss.hasPermi('system:commandLog:list')") + @GetMapping("/list") + public TableDataInfo list(EtCommandLog etCommandLog) + { + startPage(); + List list = etCommandLogService.selectEtCommandLogList(etCommandLog); + return getDataTable(list); + } + + /** + * 导出命令日志列表 + */ + @PreAuthorize("@ss.hasPermi('system:commandLog:export')") + @Log(title = "命令日志", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, EtCommandLog etCommandLog) + { + List list = etCommandLogService.selectEtCommandLogList(etCommandLog); + ExcelUtil util = new ExcelUtil(EtCommandLog.class); + util.exportExcel(response, list, "命令日志数据"); + } + + /** + * 获取命令日志详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:commandLog:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(etCommandLogService.selectEtCommandLogById(id)); + } + + /** + * 新增命令日志 + */ + @PreAuthorize("@ss.hasPermi('system:commandLog:add')") + @Log(title = "命令日志", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody EtCommandLog etCommandLog) + { + return toAjax(etCommandLogService.insertEtCommandLog(etCommandLog)); + } + + /** + * 修改命令日志 + */ + @PreAuthorize("@ss.hasPermi('system:commandLog:edit')") + @Log(title = "命令日志", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody EtCommandLog etCommandLog) + { + return toAjax(etCommandLogService.updateEtCommandLog(etCommandLog)); + } + + /** + * 删除命令日志 + */ + @PreAuthorize("@ss.hasPermi('system:commandLog:remove')") + @Log(title = "命令日志", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(etCommandLogService.deleteEtCommandLogByIds(ids)); + } +} diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOrderController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOrderController.java index 7d2bb7a..1945378 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOrderController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOrderController.java @@ -1,11 +1,25 @@ package com.ruoyi.web.controller.system; +import java.math.BigDecimal; +import java.util.Comparator; import java.util.List; +import java.util.Optional; import javax.servlet.http.HttpServletResponse; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson2.JSON; +import com.ruoyi.common.constant.ServiceConstants; +import com.ruoyi.common.core.domain.entity.AsUser; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.domain.EtOperatingArea; import com.ruoyi.system.domain.vo.RechargeVo; +import com.ruoyi.system.service.IAsUserService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -36,6 +50,12 @@ public class EtOrderController extends BaseController @Autowired private IEtOrderService etOrderService; + @Autowired + private IAsUserService asUserService; + + @Autowired + private TokenService tokenService; + /** * 查询订单列表 */ @@ -73,6 +93,36 @@ public class EtOrderController extends BaseController util.exportExcel(response, list, "订单数据"); } + /** + * 押金退款 + */ + @Transactional + @Log(title = "押金退款", businessType = BusinessType.REFUND) + @PostMapping("/depositRefund/{orderNo}") + public AjaxResult depositRefund(@PathVariable("orderNo") String orderNo) + { + EtOrder order = etOrderService.selectEtOrderByOrderNo(orderNo); + if(ObjectUtil.isNotNull(order)){ + Long userId = order.getUserId(); + if(userId!=null){ + AsUser asUser = asUserService.selectUserById(userId); + if(asUser!=null){ + // 更新用户并更新缓存 + asUser.setBalance(BigDecimal.ZERO); + if (asUserService.updateUserProfile(asUser) > 0) + { + logger.info("【提现金额】更新用户缓存:"+ JSON.toJSON(asUser)); + } + } + } + logger.info("押金退款:【{}】", order.getPayFee()); + int withdraw = etOrderService.withdraw(order, order.getPayFee()); + return toAjax(withdraw); + }else{ + throw new ServiceException("订单不存在"); + } + } + /** * 获取订单详细信息 */ diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java index bafe728..35d2a97 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java @@ -45,9 +45,6 @@ public class SysDeptController extends BaseController @Resource private EtOperatingAreaMapper etOperatingAreaMapper; - @Resource - private SysUserMapper userMapper; - /** * 获取运营商列表 diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index c5511b4..85c4dd6 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -130,6 +130,13 @@ public class SysLoginController // 去掉 menus 中的名字为‘合伙人管理’的菜单 menus.removeIf(menu -> menu.getMenuName().equals("合伙人管理")); } + if(sysDept.getDeptId() == 101){ + // 找出 menus 中的名字为‘财务管理’的菜单,获取到它子菜单 + menus.stream().filter(menu -> menu.getMenuName().equals("财务管理")).forEach(menu -> { + List children = menu.getChildren(); + children.removeIf(child -> child.getMenuName().equals("提现记录")); + }); + } return AjaxResult.success(menuService.buildMenus(menus)); } diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java index 65e80d5..5f643fa 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java @@ -30,6 +30,11 @@ public class ServiceConstants { */ public static final String ORDER_TYPE_RIDING_REFUND = "4"; + /** + * 订单类型: 5-提现 + */ + public static final String ORDER_TYPE_WITHDRAW = "5"; + /**----------------------------订单类型end----------------------------*/ /**----------------------------支付场景start----------------------------*/ /** 支付场景: 1-骑行支付,2-取消预约支付,3-套餐支付,4-押金支付 */ @@ -123,18 +128,18 @@ public class ServiceConstants { /**----------------------------支付类型end----------------------------*/ /**----------------------------车辆状态start----------------------------*/ - /** 车辆状态: 0 未上架,1-正常,2-预约中,3-骑行中,4-临时锁车,8-下线;9-废弃 */ + /** 车辆状态: 7 未绑定 0 未上架,1-正常,2-预约中,3-骑行中,4-临时锁车,8-下线;9-废弃 */ /** * 车辆状态: 7 未绑定 */ public static final String VEHICLE_STATUS_NOT_BAND = "7"; /** - * 车辆状态: 0 未上架 + * 车辆状态: 0 未上架 回仓库 */ public static final String VEHICLE_STATUS_NOT_LISTING = "0"; /** - * 车辆状态: 1-正常 + * 车辆状态: 1-正常 待骑行 */ public static final String VEHICLE_STATUS_NORMAL = "1"; @@ -144,7 +149,7 @@ public class ServiceConstants { public static final String VEHICLE_STATUS_IN_APPOINTMENT = "2"; /** - * 车辆状态: 3-使用中 + * 车辆状态: 3-使用中 骑行中 */ public static final String VEHICLE_STATUS_IN_USING = "3"; @@ -154,7 +159,7 @@ public class ServiceConstants { public static final String VEHICLE_STATUS_TEMPORARILY_LOCK = "4"; /** - * 车辆状态: 8-下线 + * 车辆状态: 8-下线 禁用 */ public static final String VEHICLE_STATUS_IN_OFFLINE = "8"; @@ -357,6 +362,11 @@ public class ServiceConstants { */ public static final String REFUND_TYPE_DEPOSIT = "2"; + /** + * 退款类型:3-押金抵扣退款 + */ + public static final String REFUND_TYPE_DEPOSIT_DEDUCTION = "3"; + /**----------------------------退款类型end----------------------------*/ @@ -517,4 +527,16 @@ public class ServiceConstants { public static final String WITHDRAW_STATUS_REJECT = "2"; /**----------------------------提现状态end----------------------------*/ + /**----------------------------是否押金抵扣start----------------------------*/ + /** 是否押金抵扣:0-否;1-是 */ + /** + * 是否押金抵扣:否 + */ + public static final String NO_DEPOSIT_DEDUCTION = "0"; + /** + * 是否押金抵扣:是 + */ + public static final String IS_DEPOSIT_DEDUCTION = "1"; + /**----------------------------是否押金抵扣end----------------------------*/ + } diff --git a/electripper-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java b/electripper-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java index a685e06..b29a15e 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java +++ b/electripper-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java @@ -23,7 +23,7 @@ import com.ruoyi.common.utils.sql.SqlUtil; /** * web层通用数据处理 - * + * * @author ruoyi */ public class BaseController @@ -113,7 +113,7 @@ public class BaseController { return AjaxResult.success(message); } - + /** * 返回成功消息 */ @@ -140,7 +140,7 @@ public class BaseController /** * 响应返回结果 - * + * * @param rows 影响行数 * @return 操作结果 */ @@ -151,7 +151,7 @@ public class BaseController /** * 响应返回结果 - * + * * @param result 结果 * @return 操作结果 */ diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java b/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java index 486fc5e..41f6f8d 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java @@ -55,27 +55,27 @@ public class CommonUtil { } - /** - * 根据定位获取地址 - * @author ruoyi - */ - public static String getAddressByGeo(String location) { - String address = null; - try { - String url = StrUtil.format("https://restapi.amap.com/v3/geocode/regeo?key={}&location={}&&radius=1000&extensions=all", GEO_WEB_KEY, location); - String result = HttpUtils.sendGet(url); - log.info("【根据定位获取地址】请求结果result:{}",result); - //将json字符串转换为Object - JSONObject jsonObject = JSONObject.parseObject(result,JSONObject.class); - JSONObject regeocode1 = jsonObject.getJSONObject("regeocode"); - address = regeocode1.getString("formatted_address"); - log.info("【根据定位获取地址】address=:【{}】",result); - return address; - } catch (Exception e) { - log.error("【根据定位获取地址】转换地址报错", e); - } - return address; - } +// /** +// * 根据定位获取地址 +// * @author ruoyi +// */ +// public static String getAddressByGeo(String location) { +// String address = null; +// try { +// String url = StrUtil.format("https://restapi.amap.com/v3/geocode/regeo?key={}&location={}&&radius=1000&extensions=all", GEO_WEB_KEY, location); +// String result = HttpUtils.sendGet(url); +// log.info("【根据定位获取地址】请求结果result:{}",result); +// //将json字符串转换为Object +// JSONObject jsonObject = JSONObject.parseObject(result,JSONObject.class); +// JSONObject regeocode1 = jsonObject.getJSONObject("regeocode"); +// address = regeocode1.getString("formatted_address"); +// log.info("【根据定位获取地址】address=:【{}】",result); +// return address; +// } catch (Exception e) { +// log.error("【根据定位获取地址】转换地址报错", e); +// } +// return address; +// } /** * 获取省市县 diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/PageUtils.java b/electripper-common/src/main/java/com/ruoyi/common/utils/PageUtils.java index 70e9b08..7bce5da 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/PageUtils.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/PageUtils.java @@ -7,7 +7,7 @@ import com.ruoyi.common.utils.sql.SqlUtil; /** * 分页工具类 - * + * * @author ruoyi */ public class PageUtils extends PageHelper diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java b/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java index 3b5bdd1..ccb63e3 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java @@ -168,4 +168,14 @@ public class AsDevice extends BaseEntityPlus implements Serializable { /** 信号强度 */ private Integer signalStrength; + /** 质量*/ + private Integer quality; + + /** 卫星数量 */ + private Integer satellites; + + /** 查询未绑定车辆 */ + @TableField(exist = false) + private String unBand; + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCapitalFlow.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCapitalFlow.java index 604e2ab..12fe7c9 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCapitalFlow.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCapitalFlow.java @@ -53,6 +53,10 @@ public class EtCapitalFlow extends BaseEntity @Excel(name = "手续费") private BigDecimal handlingCharge; + /** 平台服务费 */ + @Excel(name = "平台服务费") + private BigDecimal platformServiceFee; + /** 运营商分账 */ @Excel(name = "运营商分账") private BigDecimal operatorDividend; diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java new file mode 100644 index 0000000..094cd44 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java @@ -0,0 +1,48 @@ +package com.ruoyi.system.domain; + +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 命令日志对象 et_command_log + * + * @author 邱贞招 + * @date 2024-07-06 + */ +@Data +public class EtCommandLog extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + private Long id; + + /** 请求url */ + @Excel(name = "请求url") + private String url; + + /** 命令 */ + @Excel(name = "命令") + private String command; + + /** 类型 */ + @Excel(name = "类型") + private String type; + + /** mac */ + @Excel(name = "mac") + private String mac; + + /** sn */ + @Excel(name = "sn") + private String sn; + + /** 响应 */ + @Excel(name = "响应") + private String result; + + +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java index d9fdb2a..5254865 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java @@ -4,6 +4,8 @@ import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import lombok.Data; +import java.util.List; + /** * 车辆型号对象 et_model * @@ -53,4 +55,7 @@ public class EtModel extends BaseEntity /** 已投放车辆数 */ private Integer deviceNum; + @Excel(name = "运营区列表") + private List areaList; + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java index 2a4e279..2409847 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java @@ -204,4 +204,7 @@ public class EtOperatingArea extends BaseEntityPlus implements Serializable /** 运营区外还车:0-关闭;1-开启*/ private String areaOutReturn; + + /** 是否开启押金抵扣:0-否;1-是 */ + private String isDepositDeduction; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java index dc6a4a0..c552380 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java @@ -226,4 +226,13 @@ public class EtOrder extends BaseEntity /** 1-预约超时,系统自动取消 */ private String appointmentTimeout; + /** 是否押金抵扣:0-否;1-是 */ + @Excel(name = "是否押金抵扣") + private String depositDeduction; + + /** 是否开启押金抵扣:0-否;1-是 */ + @Excel(name = "是否开启押金抵扣") + @TableField(exist = false) + private String isDepositDeduction; + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtRefund.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtRefund.java index d039630..afe4667 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtRefund.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtRefund.java @@ -36,6 +36,14 @@ public class EtRefund extends BaseEntity @Excel(name = "用户") private String userName; + /** 运营区id */ + @Excel(name = "运营区id") + private Long areaId; + + /** 运营区 */ + @Excel(name = "运营区") + private String areaName; + /** 退款金额 */ @Excel(name = "退款金额") private BigDecimal amount; diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtWithdraw.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtWithdraw.java index 262be18..6ed084d 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtWithdraw.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtWithdraw.java @@ -52,4 +52,8 @@ public class EtWithdraw extends BaseEntity @Excel(name = "回调状态") private String callStatus; + /** 驳回原因 */ + @Excel(name = "驳回原因") + private String rejectReason; + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java index 07de655..a947de3 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java @@ -71,6 +71,14 @@ public interface AsDeviceMapper extends BaseMapper */ public int updateAsDevice(AsDevice asDevice); + /** + * 修改设备 + * + * @param asDevice 设备 + * @return 结果 + */ + public int updateAsDevice2(AsDevice asDevice); + /** * 根据SN修改设备 * diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCommandLogMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCommandLogMapper.java new file mode 100644 index 0000000..4166b89 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCommandLogMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.EtCommandLog; + +/** + * 命令日志Mapper接口 + * + * @author 邱贞招 + * @date 2024-07-06 + */ +public interface EtCommandLogMapper +{ + /** + * 查询命令日志 + * + * @param id 命令日志主键 + * @return 命令日志 + */ + public EtCommandLog selectEtCommandLogById(Long id); + + /** + * 查询命令日志列表 + * + * @param etCommandLog 命令日志 + * @return 命令日志集合 + */ + public List selectEtCommandLogList(EtCommandLog etCommandLog); + + /** + * 新增命令日志 + * + * @param etCommandLog 命令日志 + * @return 结果 + */ + public int insertEtCommandLog(EtCommandLog etCommandLog); + + /** + * 修改命令日志 + * + * @param etCommandLog 命令日志 + * @return 结果 + */ + public int updateEtCommandLog(EtCommandLog etCommandLog); + + /** + * 删除命令日志 + * + * @param id 命令日志主键 + * @return 结果 + */ + public int deleteEtCommandLogById(Long id); + + /** + * 批量删除命令日志 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEtCommandLogByIds(Long[] ids); +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtRefundMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtRefundMapper.java index 9f77f18..e2da126 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtRefundMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtRefundMapper.java @@ -73,7 +73,7 @@ public interface EtRefundMapper * @param orderNo 订单号 * @return 退款订单 */ - EtRefund selectEtRefundByOrderNo(String orderNo); + List selectEtRefundByOrderNo(String orderNo); /** * 根据订单号查询退款订单对象 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java index caeb3ad..f567513 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java @@ -75,6 +75,14 @@ public interface IAsDeviceService extends IService */ public int updateAsDevice(AsDevice asDevice); + /** + * 修改设备 + * + * @param asDevice 设备 + * @return 结果 + */ + public int updateAsDevice2(AsDevice asDevice); + /** * 根据SN修改设备 * diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtCommandLogService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtCommandLogService.java new file mode 100644 index 0000000..ed2ef3f --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtCommandLogService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.EtCommandLog; + +/** + * 命令日志Service接口 + * + * @author 邱贞招 + * @date 2024-07-06 + */ +public interface IEtCommandLogService +{ + /** + * 查询命令日志 + * + * @param id 命令日志主键 + * @return 命令日志 + */ + public EtCommandLog selectEtCommandLogById(Long id); + + /** + * 查询命令日志列表 + * + * @param etCommandLog 命令日志 + * @return 命令日志集合 + */ + public List selectEtCommandLogList(EtCommandLog etCommandLog); + + /** + * 新增命令日志 + * + * @param etCommandLog 命令日志 + * @return 结果 + */ + public int insertEtCommandLog(EtCommandLog etCommandLog); + + /** + * 修改命令日志 + * + * @param etCommandLog 命令日志 + * @return 结果 + */ + public int updateEtCommandLog(EtCommandLog etCommandLog); + + /** + * 批量删除命令日志 + * + * @param ids 需要删除的命令日志主键集合 + * @return 结果 + */ + public int deleteEtCommandLogByIds(Long[] ids); + + /** + * 删除命令日志信息 + * + * @param id 命令日志主键 + * @return 结果 + */ + public int deleteEtCommandLogById(Long id); +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java index 6c55a13..dbfb0b4 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java @@ -165,7 +165,7 @@ public interface IEtOrderService /** * 订单支付 */ - public EtRefund createRefund(EtOrder etOrder, BigDecimal refundAmount, BigDecimal appointmentFee, BigDecimal dispatchFee, BigDecimal manageFee, BigDecimal ridingFee, Refund refund, String type); + public EtRefund createRefund(EtOrder etOrder, BigDecimal refundAmount, BigDecimal appointmentFee, BigDecimal dispatchFee, BigDecimal manageFee, BigDecimal ridingFee,String outRefundNo, String type); /** diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtRefundService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtRefundService.java index a118429..4842528 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtRefundService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtRefundService.java @@ -25,7 +25,7 @@ public interface IEtRefundService * @param orderNo 订单号 * @return 退款订单 */ - public EtRefund selectEtRefundByOrderNo(String orderNo); + public List selectEtRefundByOrderNo(String orderNo); /** * 根据退款单号查询退款订单对象 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IWxPayService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IWxPayService.java index ab34ab4..0670b39 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IWxPayService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IWxPayService.java @@ -56,8 +56,9 @@ public interface IWxPayService { * @param etOrder 原订单对象 * @param reason 退款原因 * @param amount 退款金额 + * @param outRefundNo 退款订单号 */ - Refund refund(EtOrder etOrder, String reason, BigDecimal amount); + Refund refund(EtOrder etOrder, String reason, BigDecimal amount, String outRefundNo); /** * 发起商家转账 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index 5c96802..3fdefaf 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -31,6 +31,7 @@ import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.response.OrderResponse; import com.ruoyi.system.domain.vo.*; import com.ruoyi.system.mapper.AsDeviceMapper; +import com.ruoyi.system.mapper.EtCommandLogMapper; import com.ruoyi.system.mapper.EtOrderMapper; import com.ruoyi.system.service.*; import lombok.SneakyThrows; @@ -102,6 +103,9 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Resource private EtOrderMapper etOrderMapper; + @Autowired + private EtCommandLogMapper etCommandLogMapper; + @Value(value = "${iot.iotUrl}") private String iotUrl; @@ -152,7 +156,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i } Long areaId = asDevice.getAreaId(); EtOperatingArea etOperatingArea; - if (ObjectUtil.isNotNull(areaId)) { + if (ObjectUtil.isNotNull(areaId) && areaId!=0) { etOperatingArea = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); }else{ throw new ServiceException("【selectAsDeviceBySn】区域信息不存在"); @@ -164,9 +168,9 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(ObjectUtil.isNotNull(model)){ asDevice.setModel(model.getModel()); } - if(StrUtil.isNotBlank(asDevice.getLongitude()) && StrUtil.isNotBlank(asDevice.getLatitude())){ - asDevice.setLocation(CommonUtil.getAddressByGeo(asDevice.getLongitude() + ","+asDevice.getLatitude())); - } +// if(StrUtil.isNotBlank(asDevice.getLongitude()) && StrUtil.isNotBlank(asDevice.getLatitude())){ +// asDevice.setLocation(CommonUtil.getAddressByGeo(asDevice.getLongitude() + ","+asDevice.getLatitude())); +// } if(StrUtil.isNotBlank(asDevice.getVoltage())){ asDevice.setRemainingMileage(CommonUtil.getRemainingMileage(asDevice.getVoltage(),model.getFullVoltage(),model.getLowVoltage(),model.getFullEndurance())); } @@ -190,7 +194,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i List asDevices = asDeviceMapper.selectAsDeviceList(asDevice); for (AsDevice asDevice1:asDevices){ Long areaId = asDevice1.getAreaId(); - if (ObjectUtil.isNotNull(areaId)){ + if (ObjectUtil.isNotNull(areaId) && areaId!=0){ EtOperatingArea etOperatingArea = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); asDevice1.setAreaName(etOperatingArea.getAreaName()); } @@ -220,10 +224,14 @@ public class AsDeviceServiceImpl extends ServiceImpl i @DataScope(deptAlias = "d") public List selectAsDeviceListWithIsolate(AsDevice asDevice) { + if(ServiceConstants.VEHICLE_STATUS_NOT_BAND.equals(asDevice.getStatus())){ + asDevice.setUnBand("1"); + asDevice.setStatus(null); + } List asDevices = asDeviceMapper.selectAsDeviceListWithIsolate(asDevice); for (AsDevice asDevice1:asDevices){ Long areaId = asDevice1.getAreaId(); - if (ObjectUtil.isNotNull(areaId)){ + if (ObjectUtil.isNotNull(areaId) && areaId!=0){ EtOperatingArea etOperatingArea = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); asDevice1.setAreaName(etOperatingArea.getAreaName()); } @@ -239,10 +247,15 @@ public class AsDeviceServiceImpl extends ServiceImpl i String typeName = sysDictDataService.selectDictLabel("as_device_status", status); asDevice1.setStatusStr(typeName); if(status.equals(ServiceConstants.VEHICLE_STATUS_NOT_BAND) && ObjectUtil.isNotNull(asDevice1.getAreaId())){ - asDevice1.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE); + asDevice1.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_LISTING); + int i = asDeviceMapper.updateAsDevice(asDevice1); } } - if(ObjectUtil.isNotNull(areaId)){ + if(ObjectUtil.isNull(asDevice1.getAreaId())){ + asDevice1.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_BAND); + int i = asDeviceMapper.updateAsDevice(asDevice1); + } + if(ObjectUtil.isNotNull(areaId) && areaId!=0){ SysDept sysDept = wxPayService.getDeptObjByAreaId(areaId); //https://dianche.chuantewulian.cn?sn=https://dche.ccttiot.com?sn=3000900 asDevice1.setQrText(sysDept.getDomain()+"?sn="+asDevice1.getSn()); @@ -284,6 +297,24 @@ public class AsDeviceServiceImpl extends ServiceImpl i return i; } + /** + * 修改设备 + * + * @param asDevice 设备 + * @return 结果 + */ + @Override + public int updateAsDevice2(AsDevice asDevice) + { + asDevice.setUpdateTime(DateUtils.getNowDate()); + if(asDevice.getAreaId() == null){ + asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_BAND); + asDevice.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE); + asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); + } + return asDeviceMapper.updateAsDevice2(asDevice); + } + /** * 根据SN修改设备 * @@ -781,6 +812,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i log.info("【"+type+"】===>IOT请求调用结果:【{}】",result); JSONObject paramsObj = JSON.parseObject(result); String code = paramsObj.getString("code"); + asynchronousSaveLog(sendUrl,command,mac,result,type); //记录命令 if (!HttpStatus.IOT_SUCCESS.equals(code)) { @@ -806,6 +838,25 @@ public class AsDeviceServiceImpl extends ServiceImpl i }, 0, TimeUnit.SECONDS); } + /* 异步保存发送命令日志*/ + private void asynchronousSaveLog(String url,String command,String mac,String result,String type) { + //异步保存发送命令日志 + scheduledExecutorService.schedule(() -> { + EtCommandLog etCommandLog = new EtCommandLog(); + etCommandLog.setUrl(url); + etCommandLog.setCommand(command); + etCommandLog.setType(type); + etCommandLog.setMac(mac); + etCommandLog.setSn(asDeviceMapper.selectAsDeviceByMac(mac).getSn()); + etCommandLog.setResult(result); + etCommandLog.setCreateTime(DateUtils.getNowDate()); + int i = etCommandLogMapper.insertEtCommandLog(etCommandLog); + if(i>0){ + log.info("【发送命令】异步保存发送命令日志"); + } + }, 0, TimeUnit.SECONDS); + } + @Override /** 发送命令*/ public ResponseVo sendCommandWithResp(String mac, String token,String command,String type) { @@ -817,6 +868,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(responseVo.getCode() != 0){ asynchronousUpdateOnlineStatus(mac); } + asynchronousSaveLog(sendUrl,command,mac,result,type); return JSON.parseObject(result,ResponseVo.class); } @@ -1482,6 +1534,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i Boolean inCircle = false; EtParkingArea parkingArea = new EtParkingArea(); parkingArea.setAreaId(areaId); + parkingArea.setStatus("0"); List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){ @@ -1515,6 +1568,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i Boolean inCircle = false; EtParkingArea parkingArea = new EtParkingArea(); parkingArea.setAreaId(areaId); + parkingArea.setStatus("0"); parkingArea.setType(ServiceConstants.PARKING_AREA_TYPE_PARKFING); List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); @@ -1567,6 +1621,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i Boolean inCircle = false; EtParkingArea parkingArea = new EtParkingArea(); parkingArea.setAreaId(areaId); + parkingArea.setStatus("0"); List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){ log.info("运营区【{}】没有禁停区,",areaId); @@ -1600,6 +1655,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i Boolean isNoRiding = false; EtParkingArea parkingArea = new EtParkingArea(); parkingArea.setAreaId(areaId); + parkingArea.setStatus("0"); List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){ log.info("运营区【{}】没有禁行区,",areaId); @@ -1632,6 +1688,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i Boolean isNoRiding = false; EtParkingArea parkingArea = new EtParkingArea(); parkingArea.setAreaId(areaId); + parkingArea.setStatus("0"); List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){ log.info("运营区【{}】没有禁行区,",areaId); @@ -1695,6 +1752,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i wrapper.eq("area_id",areaId); wrapper.eq("status","1"); List asDevices = asDeviceMapper.selectList(wrapper); + // for循环 + for (AsDevice asDevice : asDevices) { + EtModel model = etModelService.selectEtModelByModelId(asDevice.getModelId()); + Integer remainingMileage = CommonUtil.getRemainingMileage(asDevice.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance()); + asDevice.setRemainingMileage(remainingMileage); + } return asDevices; } @@ -1710,6 +1773,8 @@ public class AsDeviceServiceImpl extends ServiceImpl i .set("remaining_power",device.getRemainingPower()) .set("last_time",device.getLastTime()) .set("voltage",device.getVoltage()) + .set("satellites",device.getSatellites()) + .set("quality",device.getQuality()) .set("signal_strength",device.getSignalStrength()); return asDeviceMapper.update(null,wrapper); } @@ -1784,6 +1849,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String latitude1 = device.getLatitude(); Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude1, latitude1, Long.parseLong(areaId)); if(parkingZoneByLocation){ + isInParkingAreaVo.setIsInParkingArea(parkingZoneByLocation); isInParkingAreaVo.setParkingReturn("1".equals(area.getParkingReturn())); return isInParkingAreaVo; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java index 38ef419..20e73bd 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java @@ -18,6 +18,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.vo.AttachVo; import com.ruoyi.system.mapper.*; @@ -203,7 +204,7 @@ public class CallbackServiceImpl implements CallbackService { order.setMark("押金支付"); // 新增资金流水记录 - capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_DEPOSIT); +// capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_DEPOSIT); // 删除用户缓存 String token = attachVo.getToken(); logger.info("【微信支付回调】删除用户缓存:"+token); @@ -397,8 +398,8 @@ public class CallbackServiceImpl implements CallbackService { // 往后推autoRefundDeposit小时执行 scheduledExecutorService.schedule(() -> { // 如果退款成功直接返回 - EtRefund refund2 = etRefundMapper.selectEtRefundByOrderNo(order.getOrderNo()); - if(ObjectUtil.isNotNull(refund2) && refund2.getRefundResult().equals(Constants.SUCCESS2)){ + List refund2 = etRefundMapper.selectEtRefundByOrderNo(order.getOrderNo()); + if(ObjectUtil.isNotNull(refund2) && refund2.size() == 1 && refund2.get(0).getRefundResult().equals(Constants.SUCCESS2)){ return; } logger.info("【微信支付回调】退还押金定时任务开始执行!!!!!!!!"); @@ -423,15 +424,16 @@ public class CallbackServiceImpl implements CallbackService { throw new ServiceException("押金充值记录与当前运营区的押金不同"); } String reason = autoRefundDeposit + "个小时后自动退押金"; - Refund refund = wxPayService.refund(newestOrder,reason, newestOrder.getTotalFee()); + String outRefundNo = IdUtils.getOrderNo("ref"); + Refund refund = wxPayService.refund(newestOrder,reason, newestOrder.getTotalFee(), outRefundNo); newestOrder.setReason(reason); - EtRefund refund1= orderService.createRefund(newestOrder, newestOrder.getTotalFee(), null, null, null, null, refund,ServiceConstants.REFUND_TYPE_DEPOSIT); + EtRefund refund1= orderService.createRefund(newestOrder, newestOrder.getTotalFee(), null, null, null, null, refund.getOutRefundNo(),ServiceConstants.REFUND_TYPE_DEPOSIT); int i = etRefundService.insertEtRefund(refund1); if(i>0){ logger.info("【自动退款】保存退款对象成功"); } // 新增资金流水记录 - capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND); +// capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND); // 更新用户信息,清除缓存 asUser.setBalance(BigDecimal.ZERO); @@ -457,9 +459,9 @@ public class CallbackServiceImpl implements CallbackService { * */ @Override public void capitalFlowRecords(EtOrder order,String type,String busType) { - if(ObjectUtil.isNotNull(etCapitalFlowService.selectEtCapitalFlowByOutTradeNo(order.getOutTradeNo()))){ - return; - } +// if(ObjectUtil.isNotNull(etCapitalFlowService.selectEtCapitalFlowByOutTradeNo(order.getOutTradeNo()))){ +// return; +// } SysDept sysDept = wxPayService.getDeptObjByAreaId(order.getAreaId()); EtCapitalFlow capitalFlow = new EtCapitalFlow(); capitalFlow.setAreaId(order.getAreaId()); @@ -471,15 +473,28 @@ public class CallbackServiceImpl implements CallbackService { logger.info("【微信支付回调--保存资金流水记录】 获取到配置手续费==============handlingCharge=====================:"+handlingCharge); BigDecimal bigDecimal = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 6, BigDecimal.ROUND_HALF_UP); logger.info("【微信支付回调--保存资金流水记录】 转换后手续费==============bigDecimal=====================:"+bigDecimal); - BigDecimal multiply = bigDecimal.multiply(order.getTotalFee()).setScale(2, BigDecimal.ROUND_HALF_UP); - logger.info("【微信支付回调--保存资金流水记录】 计算出的手续费==============multiply=====================:"+multiply); - if(busType.equals(ServiceConstants.ORDER_TYPE_DEPOSIT) || busType.equals(ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND)){ - capitalFlow.setOperatorDividend(BigDecimal.ZERO); + BigDecimal handlingCharge = bigDecimal.multiply(order.getPayFee()).setScale(2, BigDecimal.ROUND_HALF_UP); + logger.info("【微信支付回调--保存资金流水记录】 计算出的手续费==============handlingCharge=====================:"+handlingCharge); + BigDecimal serviceFeeScale = new BigDecimal(sysDept.getPlatformServiceFee()).divide(new BigDecimal(100), 6, BigDecimal.ROUND_HALF_UP); + BigDecimal platformServiceFee = serviceFeeScale.multiply(order.getPayFee()); + logger.info("【微信支付回调--保存资金流水记录】 计算出的平台服务费==============platformServiceFee=====================:"+platformServiceFee); + capitalFlow.setPlatformServiceFee(platformServiceFee); + capitalFlow.setHandlingCharge(handlingCharge);//手续费 + if(busType.equals(ServiceConstants.ORDER_TYPE_WITHDRAW)){//提现,需要手续费,不需要平台服务费 + platformServiceFee = BigDecimal.ZERO; + BigDecimal separateAccountFee = order.getPayFee().subtract(handlingCharge).subtract(platformServiceFee); capitalFlow.setPartnerDividend(BigDecimal.ZERO); + capitalFlow.setPlatformServiceFee(platformServiceFee); + capitalFlow.setOperatorDividend(separateAccountFee.negate()); + capitalFlow.setOperatorBalance(sysDept.getBalance().subtract(separateAccountFee)); + deptService.changeDeptBalance(separateAccountFee.negate(),sysDept.getDeptId()); + logger.info("【微信支付回调--保存资金流水记录】 ==============支出=====================:"); }else{ logger.info("【微信支付回调--保存资金流水记录】 ==============业务类型=====================:"+busType); BigDecimal partnerDividend = BigDecimal.ZERO; - BigDecimal operatorDividend = order.getPayFee(); + BigDecimal separateAccountFee = order.getPayFee().subtract(handlingCharge).subtract(platformServiceFee); + logger.info("【微信支付回调--保存资金流水记录】 ==============扣掉手续费和服务费之后的金额,这个金额拿来分账=====================:"+separateAccountFee); + BigDecimal operatorDividend = separateAccountFee; if(sysDept.getIsProfitSharing().equals("true")){//需要分账 logger.info("【微信支付回调--保存资金流水记录】 ==============需要分账====================="+sysDept.getIsProfitSharing()); //获取所有合伙人列表 @@ -491,26 +506,25 @@ public class CallbackServiceImpl implements CallbackService { .mapToDouble(SysUser::getDividendProportion) .sum();//算出总的分成比例 BigDecimal decimal = new BigDecimal(totalDividendProportion).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP); - partnerDividend = order.getTotalFee().multiply(decimal); - operatorDividend = order.getTotalFee().subtract(partnerDividend); + partnerDividend = operatorDividend.multiply(decimal); + operatorDividend = operatorDividend.subtract(partnerDividend); } logger.info("【微信支付回调--保存资金流水记录】 ==============partnerDividend=====================:"+partnerDividend); logger.info("【微信支付回调--保存资金流水记录】 ==============operatorDividend=====================:"+operatorDividend); if(type.equals(ServiceConstants.FLOW_TYPE_INCOME)){ capitalFlow.setPartnerDividend(partnerDividend); capitalFlow.setOperatorDividend(operatorDividend); - capitalFlow.setOperatorBalance(sysDept.getBalance().add(operatorDividend).subtract(multiply)); + capitalFlow.setOperatorBalance(sysDept.getBalance().add(operatorDividend)); deptService.changeDeptBalance(operatorDividend,sysDept.getDeptId()); logger.info("【微信支付回调--保存资金流水记录】 ==============收入=====================:"); }else{ capitalFlow.setPartnerDividend(partnerDividend.negate()); capitalFlow.setOperatorDividend(operatorDividend.negate()); - capitalFlow.setOperatorBalance(sysDept.getBalance().subtract(operatorDividend).subtract(multiply)); + capitalFlow.setOperatorBalance(sysDept.getBalance().subtract(operatorDividend)); deptService.changeDeptBalance(operatorDividend.negate(),sysDept.getDeptId()); logger.info("【微信支付回调--保存资金流水记录】 ==============支出=====================:"); } } - capitalFlow.setHandlingCharge(multiply);//手续费 capitalFlow.setPayType(ServiceConstants.PAY_TYPE_WX); capitalFlow.setCreateTime(DateUtils.getNowDate()); logger.info("【微信支付回调】保存资金流水记录对象 : " + JSON.toJSONString(capitalFlow)); @@ -556,7 +570,9 @@ public class CallbackServiceImpl implements CallbackService { EtRefund refund = etRefundService.selectEtRefundByRefundNo(outRefundNo); EtOrder order = orderService.selectEtOrderByOrderNo(refund.getOrderNo()); // 新增资金流水记录 - capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_RIDING_REFUND); +// if(order.getOrderNo().contains("qx")){ +// capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_RIDING_REFUND); +// } logger.info("【微信退款回调】全部结束!!!!!"); } } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCommandLogServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCommandLogServiceImpl.java new file mode 100644 index 0000000..84f6cc7 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCommandLogServiceImpl.java @@ -0,0 +1,93 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.EtCommandLogMapper; +import com.ruoyi.system.domain.EtCommandLog; +import com.ruoyi.system.service.IEtCommandLogService; + +/** + * 命令日志Service业务层处理 + * + * @author 邱贞招 + * @date 2024-07-06 + */ +@Service +public class EtCommandLogServiceImpl implements IEtCommandLogService +{ + @Autowired + private EtCommandLogMapper etCommandLogMapper; + + /** + * 查询命令日志 + * + * @param id 命令日志主键 + * @return 命令日志 + */ + @Override + public EtCommandLog selectEtCommandLogById(Long id) + { + return etCommandLogMapper.selectEtCommandLogById(id); + } + + /** + * 查询命令日志列表 + * + * @param etCommandLog 命令日志 + * @return 命令日志 + */ + @Override + public List selectEtCommandLogList(EtCommandLog etCommandLog) + { + return etCommandLogMapper.selectEtCommandLogList(etCommandLog); + } + + /** + * 新增命令日志 + * + * @param etCommandLog 命令日志 + * @return 结果 + */ + @Override + public int insertEtCommandLog(EtCommandLog etCommandLog) + { + return etCommandLogMapper.insertEtCommandLog(etCommandLog); + } + + /** + * 修改命令日志 + * + * @param etCommandLog 命令日志 + * @return 结果 + */ + @Override + public int updateEtCommandLog(EtCommandLog etCommandLog) + { + return etCommandLogMapper.updateEtCommandLog(etCommandLog); + } + + /** + * 批量删除命令日志 + * + * @param ids 需要删除的命令日志主键 + * @return 结果 + */ + @Override + public int deleteEtCommandLogByIds(Long[] ids) + { + return etCommandLogMapper.deleteEtCommandLogByIds(ids); + } + + /** + * 删除命令日志信息 + * + * @param id 命令日志主键 + * @return 结果 + */ + @Override + public int deleteEtCommandLogById(Long id) + { + return etCommandLogMapper.deleteEtCommandLogById(id); + } +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtFaultServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtFaultServiceImpl.java index bbf8800..c9fadb8 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtFaultServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtFaultServiceImpl.java @@ -136,9 +136,9 @@ public class EtFaultServiceImpl implements IEtFaultService throw new ServiceException("该设备不存在"); } //解析地址,将地址保存数据库 - if(StrUtil.isNotBlank(asDevice.getLongitude()) && StrUtil.isNotBlank(asDevice.getLatitude())){ - etFault.setAddress(CommonUtil.getAddressByGeo(asDevice.getLongitude() + ","+asDevice.getLatitude())); - } +// if(StrUtil.isNotBlank(asDevice.getLongitude()) && StrUtil.isNotBlank(asDevice.getLatitude())){ +// etFault.setAddress(CommonUtil.getAddressByGeo(asDevice.getLongitude() + ","+asDevice.getLatitude())); +// } etFault.setAreaId(asDevice.getAreaId()); etFault.setCreateTime(DateUtils.getNowDate()); setType(etFault); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java index 0a18570..1e72470 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java @@ -18,8 +18,10 @@ import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.onenet.ResponseVo; import com.ruoyi.common.utils.onenet.Token; import com.ruoyi.system.domain.AsDevice; +import com.ruoyi.system.domain.EtOperatingArea; import com.ruoyi.system.mapper.AsDeviceMapper; import com.ruoyi.system.service.IAsDeviceService; +import com.ruoyi.system.service.IEtOperatingAreaService; import com.ruoyi.system.service.ISysDeptService; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -54,6 +56,10 @@ public class EtModelServiceImpl implements IEtModelService @Resource private AsDeviceMapper asDeviceMapper; + @Resource + private IEtOperatingAreaService etOperatingAreaService; + + /** * 查询车辆型号 * @@ -67,6 +73,10 @@ public class EtModelServiceImpl implements IEtModelService if(ObjectUtil.isNotNull(etModel)){ Integer allNum = asDeviceService.selectCountByModelId(modelId); etModel.setDeviceNum(allNum); + if(ObjectUtil.isNotNull(etModel.getOperator())){ + List areaList = etOperatingAreaService.selectAreaListByDeptId2(etModel.getOperator()); + etModel.setAreaList(areaList); + } } return etModel; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index 9e3bf81..2d590a4 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -8,16 +8,17 @@ import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.core.domain.entity.AsUser; import com.ruoyi.common.core.domain.entity.SysDept; -import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.CommonUtil; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.vo.*; import com.ruoyi.system.mapper.AsDeviceMapper; +import com.ruoyi.system.mapper.EtOperatingAreaMapper; import com.ruoyi.system.mapper.EtOrderMapper; +import com.ruoyi.system.mapper.EtRefundMapper; import com.ruoyi.system.service.*; import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import com.wechat.pay.java.service.refund.model.Refund; @@ -29,6 +30,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionSynchronizationAdapter; +import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.web.bind.annotation.RequestBody; import javax.annotation.Resource; @@ -86,15 +89,12 @@ public class EtOrderServiceImpl implements IEtOrderService @Autowired private CallbackService callbackService; - @Autowired - private ISysUserService userService; - - @Autowired - private ISysDeptService deptService; - @Value("${et.handlingCharge}") private String handlingCharge; + @Resource + private EtRefundMapper etRefundMapper; + /** * 查询订单 * @@ -118,9 +118,9 @@ public class EtOrderServiceImpl implements IEtOrderService order.setTripLogs(tripLogs); } // 退款记录 - EtRefund refund = etRefundService.selectEtRefundByOrderNo(order.getOrderNo()); - if(ObjectUtils.isNotEmpty(refund)){ - order.setEtRefund(refund); + List refunds = etRefundService.selectEtRefundByOrderNo(order.getOrderNo()); + if(ObjectUtils.isNotEmpty(refunds) && refunds.size() > 0){ + order.setEtRefund(refunds.get(0)); } return order; } @@ -223,9 +223,9 @@ public class EtOrderServiceImpl implements IEtOrderService //如果查询押金则增加退款记录 // if(ServiceConstants.ORDER_TYPE_DEPOSIT.equals(etOrder.getType())){ etOrders.forEach(etOrder1 -> { - EtRefund refund = etRefundService.selectEtRefundByOrderNo(etOrder1.getOrderNo()); - if(ObjectUtil.isNotNull(refund)){ - etOrder1.setEtRefund(refund); + List refund = etRefundService.selectEtRefundByOrderNo(etOrder1.getOrderNo()); + if(ObjectUtil.isNotNull(refund) && refund.size() > 0){ + etOrder1.setEtRefund(refund.get(0)); } }); // } @@ -252,9 +252,9 @@ public class EtOrderServiceImpl implements IEtOrderService //如果查询押金则增加退款记录 if(ServiceConstants.ORDER_TYPE_DEPOSIT.equals(etOrder.getType())){ etOrders.forEach(etOrder1 -> { - EtRefund refund = etRefundService.selectEtRefundByOrderNo(etOrder1.getOrderNo()); - if(ObjectUtil.isNotNull(refund)){ - etOrder1.setEtRefund(refund); + List refund = etRefundService.selectEtRefundByOrderNo(etOrder1.getOrderNo()); + if(ObjectUtil.isNotNull(refund) && refund.size() > 0){ + etOrder1.setEtRefund(refund.get(0)); } }); } @@ -276,6 +276,7 @@ public class EtOrderServiceImpl implements IEtOrderService BeanUtils.copyProperties(etOrder1,rechargeVo); rechargeVo.setRechargeStatus(ServiceConstants.RECHARGE_STATUS_SUCCESS); rechargeVo.setRechargeType(ServiceConstants.ORDER_TYPE_DEPOSIT); + rechargeVo.setTotalFee(etOrder1.getPayFee()); rechargeVoList.add(rechargeVo); }); //如果查询押金则增加退款记录 @@ -283,7 +284,8 @@ public class EtOrderServiceImpl implements IEtOrderService refund.setType(ServiceConstants.REFUND_TYPE_DEPOSIT); refund.setRefundResult(Constants.SUCCESS2); refund.setUserName(etOrder.getUserName()); - List etRefunds = etRefundService.selectEtRefundListWithIsolate(refund); + PageUtils.startPage(); + List etRefunds = etRefundMapper.selectEtRefundList(refund);; etRefunds.forEach(etRefund -> { AsUser asUser = asUserService.selectUserById(etRefund.getUserId()); RechargeVo rechargeVo = new RechargeVo(); @@ -347,6 +349,7 @@ public class EtOrderServiceImpl implements IEtOrderService * 5. 更新押金订单金额(做一个押金抵扣的标记) * 6. 更新骑行订单状态为已支付,支付方式为 押金抵扣 * 7. 更新车辆信息 + * 8. 更新用户余额 */ @Override @Transactional @@ -358,23 +361,58 @@ public class EtOrderServiceImpl implements IEtOrderService EtOrder depositOrder = getDepositOrder(order.getUserId()); BigDecimal deposit = depositOrder.getTotalFee(); BigDecimal ridingFee = order.getTotalFee(); - if(deposit.compareTo(ridingFee) > 0){ - // 押金大于订单金额 扣除后 - BigDecimal afterDeductionFee = deposit.subtract(ridingFee); - order.setTotalFee(afterDeductionFee); - order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); - order.setPayTime(DateUtils.getNowDate()); - order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); - order.setPayType(ServiceConstants.PAY_TYPE_YJ); - order.setMark("押金抵扣"); - int updateEtOrder = etOrderMapper.updateEtOrder(order); - if(updateEtOrder == 0){ - throw new ServiceException("押金抵扣失败,更新订单失败"); - } + BigDecimal afterDeductionFee; + String mark; + if(deposit.compareTo(ridingFee) <= 0){ + afterDeductionFee = BigDecimal.ZERO; + mark = "押金抵扣成功,骑行费【"+ridingFee+"】大于押金【"+deposit+"】"; }else{ - throw new ServiceException("押金抵扣失败,骑行费用大于押金"); + // 押金大于订单金额 扣除后 + afterDeductionFee = deposit.subtract(ridingFee); + mark = "押金抵扣成功,骑行费【"+ridingFee+"】小于押金【"+deposit+"】,扣除后金额【"+afterDeductionFee+"】"; } - return 0; + /** 更新骑行订单*/ + order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); + order.setPayTime(DateUtils.getNowDate()); + order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); + order.setPayType(ServiceConstants.PAY_TYPE_YJ); + order.setMark(mark); + order.setDepositDeduction(ServiceConstants.IS_DEPOSIT_DEDUCTION); + int updateEtOrder = etOrderMapper.updateEtOrder(order); + if(updateEtOrder == 0){ + throw new ServiceException("押金抵扣失败,更新骑行订单失败"); + } + /** 更新押金订单*/ + depositOrder.setPayFee(afterDeductionFee); +// depositOrder.setTotalFee(afterDeductionFee); + depositOrder.setDepositDeduction(ServiceConstants.IS_DEPOSIT_DEDUCTION); + int updateEtOrder1 = etOrderMapper.updateEtOrder(depositOrder); + if(updateEtOrder1 == 0){ + throw new ServiceException("押金抵扣失败,更新押金订单失败"); + } + /** 退款剩余押金*/ + Refund refund = wxPayService.refund(depositOrder, "押金抵扣退款",afterDeductionFee,IdUtils.getOrderNo("ref")); + /** 2.记录退款表 创建退款对象*/ + depositOrder.setReason("押金提现"); + EtRefund refund1= createRefund(depositOrder, afterDeductionFee, null, null, null, null, refund.getOutRefundNo(),ServiceConstants.REFUND_TYPE_DEPOSIT); + int i = etRefundService.insertEtRefund(refund1); + if(i == 0){ + log.info("【押金抵扣】保存退款对象失败"); + throw new ServiceException("【押金抵扣】,保存退款对象失败"); + } + /** 更新用户余额*/ + AsUser asUser = asUserService.selectUserById(depositOrder.getUserId()); + if(asUser!=null){ + // 更新用户并更新缓存 + asUser.setBalance(BigDecimal.ZERO); + if (asUserService.updateUserProfile(asUser) > 0) + { + log.info("【押金抵扣成功】更新用户信息成功:"+ JSON.toJSON(asUser)); + }else{ + throw new ServiceException("【押金抵扣】,更新用户信息失败"); + } + } + return 1; } private EtOrder getDepositOrder(Long userId) { @@ -527,6 +565,9 @@ public class EtOrderServiceImpl implements IEtOrderService }else{ log.info("【预下单】支付场景为:骑行支付"); etOrder = etOrderMapper.selectEtOrderByOrderNo(order.getOrderNo()); + if(!ServiceConstants.ORDER_STATUS_RIDING_END.equals(etOrder.getStatus())){ + throw new ServiceException("【预下单】该订单非‘待支付’状态,状态:"+etOrder.getStatus()+",请刷新页面!"); + } } //TODO 计算订单金额,更新订单金额 还要根据车辆定位, // 判断是否在停车区内, @@ -884,9 +925,9 @@ public class EtOrderServiceImpl implements IEtOrderService BigDecimal payFee = defaultIfNull(etOrderMapper.getPayFee(startDateStr, endDateStr, null, areaId), BigDecimal.ZERO);//新增 BigDecimal refundFee = defaultIfNull(etOrderMapper.getRefundFee(startDateStr, endDateStr, null, areaId), BigDecimal.ZERO);//退款 - BigDecimal incomeFee = defaultIfNull(etOrderMapper.getIncome(startDateStr, endDateStr, null, areaId), BigDecimal.ZERO);//营收 - BigDecimal divide = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 6, RoundingMode.HALF_UP); + BigDecimal divide = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 4, RoundingMode.HALF_UP); BigDecimal serviceFee = payFee.multiply(divide).setScale(2, RoundingMode.HALF_UP);//手续费 + BigDecimal incomeFee = defaultIfNull(payFee.subtract(serviceFee).subtract(refundFee), BigDecimal.ZERO);//营收 reconciliation.setPayFee(payFee); reconciliation.setRefundFee(refundFee); @@ -914,9 +955,14 @@ public class EtOrderServiceImpl implements IEtOrderService private ReconciliationVo.Reconciliation createReconciliationByVehicle(String timeStart, String timeEnd, String sn) { ReconciliationVo.Reconciliation reconciliation = new ReconciliationVo.Reconciliation(); reconciliation.setSn(sn); - reconciliation.setPayFee(etOrderMapper.getPayFee(timeStart, timeEnd, sn, null)); - reconciliation.setRefundFee(etOrderMapper.getRefundFee(timeStart, timeEnd, sn, null)); - reconciliation.setIncome(etOrderMapper.getIncome(timeStart, timeEnd, sn, null)); + BigDecimal payFee = etOrderMapper.getPayFee(timeStart, timeEnd, sn, null); + reconciliation.setPayFee(payFee); + BigDecimal refundFee = etOrderMapper.getRefundFee(timeStart, timeEnd, sn, null); + reconciliation.setRefundFee(refundFee); + BigDecimal divide = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 4, RoundingMode.HALF_UP); + BigDecimal serviceFee = payFee.multiply(divide).setScale(2, RoundingMode.HALF_UP);//手续费 + reconciliation.setIncome(payFee.subtract(refundFee).subtract(serviceFee)); + reconciliation.setServiceFee(serviceFee); return reconciliation; } @@ -991,18 +1037,19 @@ public class EtOrderServiceImpl implements IEtOrderService if(ObjectUtil.isNotNull(ridingFee) && !ridingFee.equals(BigDecimal.ZERO)){ refundAmount = refundAmount.add(ridingFee); } - log.info("总金额:【{}】,退款金额:【{}】", etOrder1.getTotalFee(), refundAmount); - Refund refund = wxPayService.refund(etOrder1, etOrder.getReason(), refundAmount); + // 新增资金流水记录 + etOrder1.setPayFee(refundAmount); + callbackService.capitalFlowRecords(etOrder1,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants. ORDER_TYPE_RIDING_REFUND); //todo 更新订单的payFee = totalFee - refundAmount - + String outRefundNo = IdUtils.getOrderNo("ref"); /** 2.记录退款表 创建退款对象*/ - EtRefund refund1= createRefund(etOrder1, refundAmount, appointmentFee, dispatchFee, manageFee, ridingFee, refund,ServiceConstants.REFUND_TYPE_SYSTEM); + EtRefund refund1= createRefund(etOrder1, refundAmount, appointmentFee, dispatchFee, manageFee, ridingFee, outRefundNo,ServiceConstants.REFUND_TYPE_SYSTEM); int i = etRefundService.insertEtRefund(refund1); if(i>0){ log.info("保存退款对象成功"); } - // 新增资金流水记录 - callbackService.capitalFlowRecords(etOrder1,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_RIDING_REFUND); + log.info("总金额:【{}】,退款金额:【{}】", etOrder1.getTotalFee(), refundAmount); + Refund refund = wxPayService.refund(etOrder1, etOrder.getReason(), refundAmount,outRefundNo); return i; } @@ -1012,19 +1059,20 @@ public class EtOrderServiceImpl implements IEtOrderService @Transactional @Override public int withdraw(EtOrder etOrder1, BigDecimal deposit) { - Refund refund = wxPayService.refund(etOrder1, "押金提现",deposit); + String outRefundNo = IdUtils.getOrderNo("ref"); /** 2.记录退款表 创建退款对象*/ etOrder1.setReason("押金提现"); - EtRefund refund1= createRefund(etOrder1, deposit, null, null, null, null, refund,ServiceConstants.REFUND_TYPE_DEPOSIT); + EtRefund refund1= createRefund(etOrder1, deposit, null, null, null, null, outRefundNo,ServiceConstants.REFUND_TYPE_DEPOSIT); int i = etRefundService.insertEtRefund(refund1); if(i>0){ log.info("【提现金额】保存退款对象成功"); } + Refund refund = wxPayService.refund(etOrder1, "押金提现",deposit,outRefundNo); return i; } @Override - public EtRefund createRefund(EtOrder etOrder, BigDecimal refundAmount, BigDecimal appointmentFee, BigDecimal dispatchFee, BigDecimal manageFee, BigDecimal ridingFee, Refund refund,String type) { + public EtRefund createRefund(EtOrder etOrder, BigDecimal refundAmount, BigDecimal appointmentFee, BigDecimal dispatchFee, BigDecimal manageFee, BigDecimal ridingFee, String outRefundNo,String type) { EtRefund etRefund = new EtRefund(); etRefund.setAmount(refundAmount); etRefund.setReason(etOrder.getReason()); @@ -1034,7 +1082,7 @@ public class EtOrderServiceImpl implements IEtOrderService etRefund.setRidingFee(ridingFee); etRefund.setOrderNo(etOrder.getOrderNo()); etRefund.setUserId(etOrder.getUserId()); - etRefund.setRefundNo(refund.getOutRefundNo()); + etRefund.setRefundNo(outRefundNo); etRefund.setType(type); if(type.equals(ServiceConstants.REFUND_TYPE_DEPOSIT)){ etRefund.setItemDesc("押金自动退款"); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtRefundServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtRefundServiceImpl.java index e5bba6a..740a1d3 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtRefundServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtRefundServiceImpl.java @@ -41,7 +41,7 @@ public class EtRefundServiceImpl implements IEtRefundService * @return 退款订单 */ @Override - public EtRefund selectEtRefundByOrderNo(String orderNo) + public List selectEtRefundByOrderNo(String orderNo) { return etRefundMapper.selectEtRefundByOrderNo(orderNo); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtTripLogServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtTripLogServiceImpl.java index 6907bea..ef803a6 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtTripLogServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtTripLogServiceImpl.java @@ -124,7 +124,7 @@ public class EtTripLogServiceImpl implements IEtTripLogService etTripLog.setLatitude(asDevice.getLatitude()); etTripLog.setLongitude(asDevice.getLongitude()); String location = asDevice.getLongitude() + ","+asDevice.getLatitude(); - etTripLog.setAddress(CommonUtil.getAddressByGeo(location)); +// etTripLog.setAddress(CommonUtil.getAddressByGeo(location)); etTripLog.setSn(sn); } log.info("创建行程记录:{}", JSON.toJSON(etTripLog)); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtWithdrawServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtWithdrawServiceImpl.java index c9e64de..34a9d33 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtWithdrawServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtWithdrawServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson2.JSON; +import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.core.domain.entity.AsUser; import com.ruoyi.common.core.domain.entity.SysDept; @@ -10,17 +11,18 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.uuid.IdUtils; +import com.ruoyi.system.domain.EtOrder; import com.ruoyi.system.domain.EtWithdraw; import com.ruoyi.system.mapper.AsUserMapper; import com.ruoyi.system.mapper.EtWithdrawMapper; +import com.ruoyi.system.mapper.SysDeptMapper; import com.ruoyi.system.mapper.SysUserMapper; -import com.ruoyi.system.service.IEtWithdrawService; -import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.IWxPayService; +import com.ruoyi.system.service.*; import com.wechat.pay.java.service.transferbatch.model.TransferDetailInput; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; @@ -47,12 +49,17 @@ public class EtWithdrawServiceImpl implements IEtWithdrawService @Resource private SysUserMapper userMapper; - @Autowired - private IWxPayService wxPayService; - @Autowired private ISysDeptService deptService; + @Autowired + private CallbackService callbackService; + + @Resource + private IEtOperatingAreaService etOperatingAreaService; + + @Resource + private SysDeptMapper deptMapper; /** * 查询提现记录 * @@ -72,6 +79,7 @@ public class EtWithdrawServiceImpl implements IEtWithdrawService * @return 提现记录 */ @Override + @DataScope(deptAlias = "d") public List selectEtWithdrawList(EtWithdraw etWithdraw) { return etWithdrawMapper.selectEtWithdrawList(etWithdraw); @@ -109,6 +117,7 @@ public class EtWithdrawServiceImpl implements IEtWithdrawService * @return 结果 */ @Override + @Transactional public int updateEtWithdraw(EtWithdraw etWithdraw) { //如果提现是通过,则发起商户转账到零钱 @@ -119,11 +128,30 @@ public class EtWithdrawServiceImpl implements IEtWithdrawService TransferDetailInput transferDetailInput = new TransferDetailInput(); transferDetailInput.setOutDetailNo(IdUtils.getOrderNo("txd"));//明细订单号 transferDetailInput.setTransferAmount(etWithdraw.getAmount().multiply(new BigDecimal(100)).longValue()); - transferDetailInput.setTransferRemark("创特共享电动车提现"); + transferDetailInput.setTransferRemark(sysDept.getDeptName()+"共享电动车提现"); transferDetailInput.setOpenid(etWithdraw.getWxopenid()); transferDetailInputs.add(transferDetailInput); log.info("【审核通过】发起转账到零钱:{}",JSON.toJSONString(transferDetailInputs)); - wxPayService.transfer(sysDept,etWithdraw.getWithdrawNo(),batchName,batchName,etWithdraw.getAmount(),1,transferDetailInputs); + // todo 暂时先不发起真实提现 +// wxPayService.transfer(sysDept,etWithdraw.getWithdrawNo(),batchName,batchName,etWithdraw.getAmount(),1,transferDetailInputs); + //扣余额并记录资金流水 + sysDept.getBalance().subtract(etWithdraw.getAmount()); + int result = deptMapper.updateDept(sysDept); + if(result == 0){ + throw new ServiceException("【提现】提现失败,更新运营商余额失败"); + }else{ + EtOrder order = new EtOrder(); + order.setOrderNo(etWithdraw.getWithdrawNo()); + order.setPayFee(etWithdraw.getAmount()); + order.setTotalFee(etWithdraw.getAmount()); + List longs = etOperatingAreaService.selectAreaListByDeptId(etWithdraw.getDeptId()); + if(longs.size() == 0){ + throw new ServiceException("【提现】提现失败,未找到该运营区,运营商id:"+etWithdraw.getDeptId()); + } + order.setAreaId(longs.get(0)); + //记录资金流水 + callbackService.capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_WITHDRAW); + } } return etWithdrawMapper.updateEtWithdraw(etWithdraw); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index b64b7a8..5c30dde 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -102,7 +102,7 @@ public class SysUserServiceImpl implements ISysUserService for (SysUser sysUser:sysUsers){ sysUser.setDeviceNum(asDeviceService.selectCountByAreaId(sysUser.getAreaId())); Long areaId = sysUser.getAreaId(); - if(ObjectUtil.isNotNull(areaId)){ + if(ObjectUtil.isNotNull(areaId) && areaId!=0){ EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); if(ObjectUtil.isNotNull(area)){ sysUser.setAreaName(area.getAreaName()); @@ -345,7 +345,7 @@ public class SysUserServiceImpl implements ISysUserService */ private void setOperatorId(SysUser user) { Long areaId = user.getAreaId(); - if(ObjectUtil.isNotNull(areaId)){ + if(ObjectUtil.isNotNull(areaId) && areaId!=0){ List areaId1 = etAreaDeptMapper.selectList(new QueryWrapper().eq("area_id", areaId)); if(ObjectUtil.isNotEmpty(areaId1)){ user.setDeptId(areaId1.get(0).getDeptId()); @@ -701,11 +701,6 @@ public class SysUserServiceImpl implements ISysUserService public int bandAppUser(SysUser user) { LoginUser loginUser = SecurityUtils.getLoginUser(); user.setUserId(loginUser.getUserId()); - String token = loginUser.getToken(); - if (StringUtils.isNotNull(token)) - { - redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + token); - } return userMapper.updateUser(user); } } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java index 35e4670..c770240 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java @@ -197,13 +197,14 @@ public class WxPayService implements IWxPayService { * @param etOrder 原订单对象 * @param reason 退款原因 * @param amount 退款金额 + * @param outRefundNo 退款订单号 */ @Override - public Refund refund(EtOrder etOrder,String reason,BigDecimal amount) { + public Refund refund(EtOrder etOrder,String reason,BigDecimal amount,String outRefundNo) { SysDept sysDept = getDeptObjByAreaId(etOrder.getAreaId()); CreateRequest request = new CreateRequest(); request.setOutTradeNo(etOrder.getOutTradeNo()); - request.setOutRefundNo(IdUtils.getOrderNo("ref")); + request.setOutRefundNo(outRefundNo); request.setReason(reason); request.setAmount(getAmountReq(etOrder.getTotalFee(),amount)); request.setNotifyUrl(sysDept.getRefundNotifyUrl()); diff --git a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java index a00df2c..bfdbfe7 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java +++ b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java @@ -11,6 +11,7 @@ import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.mapper.AsDeviceMapper; import com.ruoyi.system.mapper.AsUserMapper; @@ -129,41 +130,45 @@ public class EtTask { log.info("【系统启动】最后一次押金充值记录 金额与押金不一致,订单押金:【{}】,区域押金:【{}】",lastOrder.getTotalFee(),area.getDeposit()); }else{ // 根据最新的订单号,查询是否有退款记录 - EtRefund etRefund = etRefundService.selectEtRefundByOrderNo(lastOrder.getOrderNo()); - // 没有退款记录,发起退款 - if(ObjectUtil.isNull(etRefund)){ - // 根据订单支付时间 autoRefundDeposit个小时后退押金 - String reason = autoRefundDeposit + "个小时后自动退押金"; - Date payTime = order.getPayTime(); - Date refundDepositTime = DateUtils.getTimeAfterXHours(payTime, autoRefundDeposit); - Date nowDate = DateUtils.getNowDate(); - if (nowDate.after(refundDepositTime)) { - log.info("【系统启动】用户【{}】押金充值订单【{}】已过期,开始自动退押金",asUser.getUserId(),lastOrder.getOrderNo()); - refundDeposit(asUser, lastOrder, reason); - }else{ - int timeDifferenceInMinutes = DateUtils.timeDifferenceInMinutes(payTime, nowDate); - int i = autoRefundDeposit * 60; - int delay = i - timeDifferenceInMinutes; - log.info("【系统启动】用户【{}】押金充值订单【{}】未过期,【{}】分钟后退押金",asUser.getUserId(),lastOrder.getOrderNo(),delay); - scheduledExecutorService.schedule(() -> { + List etRefunds = etRefundService.selectEtRefundByOrderNo(lastOrder.getOrderNo()); + if(etRefunds.size() == 1){ + EtRefund etRefund = etRefunds.get(0); + // 没有退款记录,发起退款 + if(ObjectUtil.isNull(etRefund)){ + // 根据订单支付时间 autoRefundDeposit个小时后退押金 + String reason = autoRefundDeposit + "个小时后自动退押金"; + Date payTime = order.getPayTime(); + Date refundDepositTime = DateUtils.getTimeAfterXHours(payTime, autoRefundDeposit); + Date nowDate = DateUtils.getNowDate(); + if (nowDate.after(refundDepositTime)) { + log.info("【系统启动】用户【{}】押金充值订单【{}】已过期,开始自动退押金",asUser.getUserId(),lastOrder.getOrderNo()); refundDeposit(asUser, lastOrder, reason); - }, delay, TimeUnit.MINUTES); - } - }else{ - // 有退款记录,判断是否成功 - if(!Constants.SUCCESS2.equals(etRefund.getRefundResult())){ - log.info("【系统启动】押金退款未成功回调,退款单号:【{}】",etRefund.getRefundNo()); - // 根据退款单号查询退款信息 - Refund refund = wxPayService.queryByOutRefundNo(area.getAreaId(),etRefund.getRefundNo()); - if(ObjectUtil.isNotNull(refund) && Constants.SUCCESS2.equals(refund.getStatus().name())){ - // 更新退款记录 - etRefund.setRefundResult(Constants.SUCCESS2); - etRefund.setUpdateTime(new Date()); - etRefundService.updateEtRefund(etRefund); - log.info("【系统启动】更新押金退款回调成功,退款单号:【{}】",refund.getOutRefundNo()); + }else{ + int timeDifferenceInMinutes = DateUtils.timeDifferenceInMinutes(payTime, nowDate); + int i = autoRefundDeposit * 60; + int delay = i - timeDifferenceInMinutes; + log.info("【系统启动】用户【{}】押金充值订单【{}】未过期,【{}】分钟后退押金",asUser.getUserId(),lastOrder.getOrderNo(),delay); + scheduledExecutorService.schedule(() -> { + refundDeposit(asUser, lastOrder, reason); + }, delay, TimeUnit.MINUTES); + } + }else{ + // 有退款记录,判断是否成功 + if(!Constants.SUCCESS2.equals(etRefund.getRefundResult())){ + log.info("【系统启动】押金退款未成功回调,退款单号:【{}】",etRefund.getRefundNo()); + // 根据退款单号查询退款信息 + Refund refund = wxPayService.queryByOutRefundNo(area.getAreaId(),etRefund.getRefundNo()); + if(ObjectUtil.isNotNull(refund) && Constants.SUCCESS2.equals(refund.getStatus().name())){ + // 更新退款记录 + etRefund.setRefundResult(Constants.SUCCESS2); + etRefund.setUpdateTime(new Date()); + etRefundService.updateEtRefund(etRefund); + log.info("【系统启动】更新押金退款回调成功,退款单号:【{}】",refund.getOutRefundNo()); + } } } } + } } } @@ -213,13 +218,13 @@ public class EtTask { private void refundDeposit(AsUser asUser, EtOrder lastOrder, String reason) { - Refund refund = wxPayService.refund(lastOrder, reason, lastOrder.getTotalFee()); + String outRefundNo = IdUtils.getOrderNo("ref"); lastOrder.setReason(reason); - EtRefund refund1= etOrderService.createRefund(lastOrder, lastOrder.getTotalFee(), null, null, null, null, refund,ServiceConstants.REFUND_TYPE_DEPOSIT); + EtRefund refund1= etOrderService.createRefund(lastOrder, lastOrder.getTotalFee(), null, null, null, null, outRefundNo,ServiceConstants.REFUND_TYPE_DEPOSIT); if(etRefundService.insertEtRefund(refund1)>0){ log.info("【自动退款】保存退款对象成功"); // 新增资金流水记录 - callbackService.capitalFlowRecords(lastOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND); +// callbackService.capitalFlowRecords(lastOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND); // 更新用户信息,清除缓存 asUser.setBalance(BigDecimal.ZERO); int updateUser = asUserMapper.updateUser(asUser); @@ -228,6 +233,7 @@ public class EtTask { // redisCache.deleteObject(keys); log.info("【系统启动】退还押金,更新用户余额成功!"); } + Refund refund = wxPayService.refund(lastOrder, reason, lastOrder.getTotalFee(),outRefundNo); log.info("=================【系统启动】退还押金定时任务结束!!!=================="); }else{ throw new ServiceException("【系统启动】保存退款对象失败"); diff --git a/electripper-system/src/main/resources/mapper/system/AsArticleMapper.xml b/electripper-system/src/main/resources/mapper/system/AsArticleMapper.xml index 883f303..14acc23 100644 --- a/electripper-system/src/main/resources/mapper/system/AsArticleMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsArticleMapper.xml @@ -48,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" a.tag, a.is_hot, a.introduction, - a.content, +-- a.content, a.author, a.create_by, a.create_time, @@ -83,7 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" a.tag, a.is_hot, a.introduction, - a.content, +-- a.content, a.author, a.create_by, a.create_time, diff --git a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml index 56eb66b..37271a8 100644 --- a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml @@ -64,7 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select de.device_id, de.picture, de.device_name, de.mac, de.sn, de.model_id, de.vehicle_num, de.area_id, de.activation_time, de.online_status, de.create_by, de.create_time, de.update_by, de.update_time, de.last_time, de.remark, de.status, de.lock_status, de.location, - de.remaining_power, de.voltage, de.version, de.qrcode, de.longitude, de.latitude, de.is_area_out_outage, de.is_admin_unlocking, de.signal_strength from et_device de + de.remaining_power, de.voltage, de.version, de.qrcode, de.longitude, de.latitude, de.is_area_out_outage, de.is_admin_unlocking, de.signal_strength, de.satellites, de.quality from et_device de left join et_area_dept ad on ad.area_id = de.area_id left join sys_dept d on d.dept_id = ad.dept_id where 1 = 1 @@ -76,8 +76,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and d.dept_id = #{deptId} and de.model_id = #{modelId} and de.online_status = #{onlineStatus} - and de.status = #{status} + + + + and (de.status = '3' or de.status = '4') + + + + and de.status = #{status} + + + and de.lock_status = #{lockStatus} + + + and de.area_id is null + ${params.dataScope} order by de.sn @@ -230,6 +244,39 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where device_id = #{deviceId} + + update et_device + + picture = #{picture}, + device_name = #{deviceName}, + mac = #{mac}, + sn = #{sn}, + model_id = #{modelId}, + vehicle_num = #{vehicleNum}, + version = #{version}, + area_id = #{areaId}, + activation_time = #{activationTime}, + online_status = #{onlineStatus}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + last_time = #{lastTime}, + remark = #{remark}, + status = #{status}, + lock_status = #{lockStatus}, + location = #{location}, + remaining_power = #{remainingPower}, + voltage = #{voltage}, + qrcode = #{qrcode}, + longitude = #{longitude}, + latitude = #{latitude}, + is_area_out_outage = #{isAreaOutOutage}, + is_admin_unlocking = #{isAdminUnlocking}, + + where device_id = #{deviceId} + + update et_device diff --git a/electripper-system/src/main/resources/mapper/system/EtAdminOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtAdminOrderMapper.xml index aaeab70..46262ed 100644 --- a/electripper-system/src/main/resources/mapper/system/EtAdminOrderMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtAdminOrderMapper.xml @@ -63,12 +63,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} diff --git a/electripper-system/src/main/resources/mapper/system/EtCapitalFlowMapper.xml b/electripper-system/src/main/resources/mapper/system/EtCapitalFlowMapper.xml index 0bca9b2..78d0818 100644 --- a/electripper-system/src/main/resources/mapper/system/EtCapitalFlowMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtCapitalFlowMapper.xml @@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select flow_id, area_id, order_no, out_trade_no, type, bus_type, amount, handling_charge, operator_dividend, operator_balance, partner_dividend, pay_type, create_time from et_capital_flow + select flow_id, area_id, order_no, out_trade_no, type, bus_type, amount, handling_charge, platform_service_fee, operator_dividend, operator_balance, partner_dividend, pay_type, create_time from et_capital_flow + + + and url like concat('%', #{url}, '%') + and command like concat('%', #{command}, '%') + and mac like concat('%', #{mac}, '%') + and sn like concat('%', #{sn}, '%') + and type like concat('%', #{type}, '%') + and result like concat('%', #{result}, '%') + + order by create_time desc + + + + + + insert into et_command_log + + url, + command, + type, + mac, + sn, + result, + create_time + + + #{url}, + #{command}, + #{type}, + #{mac}, + #{sn}, + #{result}, + sysdate() + + + + + update et_command_log + + url = #{url}, + command = #{command}, + type = #{type}, + mac = #{mac}, + sn = #{sn}, + result = #{result}, + + where id = #{id} + + + + delete from et_command_log where id = #{id} + + + + delete from et_command_log where id in + + #{id} + + + diff --git a/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml index b6ba072..20c821f 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml @@ -50,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -59,7 +60,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" county, area_out_outage, parking_out_dispatch, area_out_dispatch, no_riding_outage, authentication, msg_switch, undercharge, error, cast(agreement as char) as agreement, deposit, outage, appointment_service_fee, dispatch_fee, vehicle_management_fee, timeout_minutes, - auto_replacement_order, area_time_start, area_time_end, area_out_return, parking_return, service_name1, service_name2, service_name3, service_phone1, service_phone2, service_phone3, custom_service from et_operating_area + auto_replacement_order, area_time_start, area_time_end, area_out_return, parking_return, service_name1, service_name2, + service_name3, service_phone1, service_phone2, service_phone3, custom_service, is_deposit_deduction from et_operating_area @@ -53,6 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" o.order_id, o.area_id, oa.area_name AS area, + oa.is_deposit_deduction isDepositDeduction, u.user_name AS userName, u.phonenumber AS phonenumber, o.order_no, @@ -104,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and u.phonenumber like concat('%', #{phonenumber}, '%') and o.user_id = #{userId} and o.device_mac like concat('%', #{deviceMac}, '%') + and de.vehicle_num like concat('%', #{vehicleNum }, '%') and o.sn like concat('%', #{sn}, '%') and o.type = #{type} and o.status = #{status} @@ -370,6 +373,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select COALESCE(SUM(pay_fee), 0) from et_order and sn = #{sn} + and area_id = #{areaId} AND date_format(create_time,'%y%m%d') >= date_format(#{startDateStr},'%y%m%d') @@ -409,14 +413,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select r.id, r.refund_no, r.order_no, r.user_id, u.user_name userName, r.amount, r.dispatch_fee, r.manage_fee, + select r.id, r.refund_no, o.area_id areaId,oa.area_name areaName,r.order_no, r.user_id, u.user_name userName, r.amount, r.dispatch_fee, r.manage_fee, r.riding_fee, r.appointment_fee, r.type, r.reason, r.create_time, r.item_desc,r.refund_result from et_refund r INNER JOIN et_order o on o.order_no = r.order_no left join et_user u on u.user_id = r.user_id @@ -38,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and r.order_no like concat('%', #{orderNo}, '%') and r.user_id like concat('%', #{userId}, '%') and r.amount = #{amount} + and o.area_id = #{areaId} and r.item_desc like concat('%', #{itemDesc}, '%') and r.refund_result = #{refundResult} and r.type = #{type} diff --git a/electripper-system/src/main/resources/mapper/system/EtWithdrawMapper.xml b/electripper-system/src/main/resources/mapper/system/EtWithdrawMapper.xml index bdd1b6d..1c8d02c 100644 --- a/electripper-system/src/main/resources/mapper/system/EtWithdrawMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtWithdrawMapper.xml @@ -14,21 +14,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, withdraw_no, amount, dept_id, status, applicant, wxopenid, create_time, call_status from et_withdraw + select id, withdraw_no, amount, dept_id, status, applicant, wxopenid, create_time, call_status, reject_reason from et_withdraw