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 9ba7519..50964bb 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 @@ -1,30 +1,30 @@ package com.ruoyi.web.controller.system; -import java.util.List; -import java.util.Set; - import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import com.ruoyi.common.constant.HttpStatus; -import com.ruoyi.common.core.domain.entity.AsUser; -import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.system.service.IAsUserService; -import com.ruoyi.system.service.ISysUserService; -import lombok.extern.slf4j.Slf4j; -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.RequestBody; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.AsUser; +import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginBody; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.framework.web.service.SysLoginService; import com.ruoyi.framework.web.service.SysPermissionService; +import com.ruoyi.system.service.IAsUserService; +import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.system.service.ISysMenuService; +import lombok.extern.slf4j.Slf4j; +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.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Set; /** * 登录验证 @@ -47,6 +47,9 @@ public class SysLoginController @Autowired private IAsUserService userService; + @Autowired + private ISysDeptService deptService; + /** * 登录方法 @@ -114,6 +117,11 @@ public class SysLoginController { Long userId = SecurityUtils.getUserId(); List menus = menuService.selectMenuTreeByUserId(userId); + SysDept sysDept = deptService.selectDeptById(SecurityUtils.getDeptId()); + if(!sysDept.getIsProfitSharing().equals("true")){ + // 去掉 menus 中的名字为‘合伙人管理’的菜单 + menus.removeIf(menu -> menu.getMenuName().equals("合伙人管理")); + } return AjaxResult.success(menuService.buildMenus(menus)); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCallbackLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCallbackLog.java new file mode 100644 index 0000000..00e189f --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCallbackLog.java @@ -0,0 +1,80 @@ +package com.ruoyi.system.domain; + +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_callback_log + * + * @author 邱贞招 + * @date 2024-06-18 + */ +public class EtCallbackLog extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + private Long id; + + /** 未解析的body */ + @Excel(name = "未解析的body") + private String body2; + + /** 解析后 */ + @Excel(name = "解析后") + private String body; + + /** 类型:1-支付回调;2-退款回调 */ + @Excel(name = "类型:1-支付回调;2-退款回调") + private String type; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setBody2(String body2) + { + this.body2 = body2; + } + + public String getBody2() + { + return body2; + } + public void setBody(String body) + { + this.body = body; + } + + public String getBody() + { + return body; + } + public void setType(String type) + { + this.type = type; + } + + public String getType() + { + return type; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("body2", getBody2()) + .append("body", getBody()) + .append("createTime", getCreateTime()) + .append("type", getType()) + .toString(); + } +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCallbackLogMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCallbackLogMapper.java new file mode 100644 index 0000000..f6abfeb --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCallbackLogMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.EtCallbackLog; + +/** + * 回调日志Mapper接口 + * + * @author 邱贞招 + * @date 2024-06-18 + */ +public interface EtCallbackLogMapper +{ + /** + * 查询回调日志 + * + * @param id 回调日志主键 + * @return 回调日志 + */ + public EtCallbackLog selectEtCallbackLogById(Long id); + + /** + * 查询回调日志列表 + * + * @param etCallbackLog 回调日志 + * @return 回调日志集合 + */ + public List selectEtCallbackLogList(EtCallbackLog etCallbackLog); + + /** + * 新增回调日志 + * + * @param etCallbackLog 回调日志 + * @return 结果 + */ + public int insertEtCallbackLog(EtCallbackLog etCallbackLog); + + /** + * 修改回调日志 + * + * @param etCallbackLog 回调日志 + * @return 结果 + */ + public int updateEtCallbackLog(EtCallbackLog etCallbackLog); + + /** + * 删除回调日志 + * + * @param id 回调日志主键 + * @return 结果 + */ + public int deleteEtCallbackLogById(Long id); + + /** + * 批量删除回调日志 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEtCallbackLogByIds(Long[] ids); +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index 61dbc1d..56fc2e9 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -1,5 +1,6 @@ package com.ruoyi.system.mapper; +import java.math.BigDecimal; import java.util.List; import org.apache.ibatis.annotations.Param; import com.ruoyi.common.core.domain.entity.SysDept; @@ -124,4 +125,7 @@ public interface SysDeptMapper * @return 结果 */ SysDept selectEtOperatingAreaBySerialNumber(String wechatpaySerial); + + void changeDeptBalance(@Param("amount")BigDecimal amount,@Param("deptId")Long deptId); + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/electripper-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java index 2c8b84d..f6a156b 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service; +import java.math.BigDecimal; import java.util.List; import com.ruoyi.common.core.domain.TreeSelect; import com.ruoyi.common.core.domain.entity.SysDept; @@ -129,4 +130,11 @@ public interface ISysDeptService * @return 结果 */ SysDept selectEtOperatingAreaBySerialNumber(String wechatpaySerial); + + /** + * 获取运营商余额 + * + * @return 结果 + */ + void changeDeptBalance(BigDecimal negate, Long deptId); } 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 b807a5c..f771e62 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 @@ -688,7 +688,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Override public Boolean ring(String sn) { AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn); - /** TODO 响铃寻车*/ /** 1.获取token*/ String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { @@ -776,7 +775,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); String finalSn = sn; Boolean execute = transactionTemplate.execute(e -> { - /** TODO 临时解锁*/ /** 2.发送命令*/ sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5,"临时解锁"); //间隔1秒 @@ -802,7 +800,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i throw new ServiceException("【临时解锁】记录行程失败"); } }else{ - /** 改变车辆锁状态:1-开 TODO 是否要改变车辆状态?*/ + /** 改变车辆锁状态:1-开 */ asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); int device = asDeviceMapper.updateAsDevice(asDevice); if(device==0){ 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 f93551a..e2e3290 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 @@ -34,7 +34,6 @@ import com.wechat.pay.java.service.profitsharing.model.ReceiverType; import com.wechat.pay.java.service.refund.model.Refund; import com.wechat.pay.java.service.refund.model.RefundNotification; import com.wechat.pay.java.service.refund.model.Status; -import lombok.SneakyThrows; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -112,6 +111,9 @@ public class CallbackServiceImpl implements CallbackService { @Autowired private ISysDeptService deptService; + @Resource + private EtCallbackLogMapper callbackLogMapper; + @Value("${et.handlingCharge}") private String handlingCharge; @@ -125,6 +127,9 @@ public class CallbackServiceImpl implements CallbackService { public void weChat(HttpServletRequest request) { String body = HttpUtils.getBody(request); logger.info("【微信支付回调】接收对象(未验签) : " + JSON.toJSONString(body)); + EtCallbackLog etCallbackLog = new EtCallbackLog(); + etCallbackLog.setBody2(body); + etCallbackLog.setType("1"); // 解析通知数据 Notification notification = JSON.parseObject(body, Notification.class); String outTradeNo; @@ -138,6 +143,7 @@ public class CallbackServiceImpl implements CallbackService { if (Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) { // 充值成功后的业务处理 logger.info("【微信支付回调】交易对象(验签后) : " + JSON.toJSONString(transaction)); + etCallbackLog.setBody(JSON.toJSONString(transaction)); String transactionId = transaction.getTransactionId(); AttachVo attachVo = JSONObject.parseObject(transaction.getAttach(),AttachVo.class); logger.info("【微信支付回调】附加信息 : " + JSON.toJSONString(attachVo)); @@ -227,11 +233,25 @@ public class CallbackServiceImpl implements CallbackService { logger.error("【微信支付回调】更新用户押金失败"); throw new ServiceException("【微信支付回调】更新用户押金失败"); } + //异步保存回调日志 + asynchronousSaveCallbackLog(etCallbackLog); logger.info("=================【微信支付回调】全部结束!!!!!=================="); } } } + private void asynchronousSaveCallbackLog(EtCallbackLog etCallbackLog) { + //开异步线程保存回调参数 + scheduledExecutorService.schedule(() -> { + logger.info("【微信支付回调】异步保存回调参数"); + etCallbackLog.setCreateTime(DateUtils.getNowDate()); + int i = callbackLogMapper.insertEtCallbackLog(etCallbackLog); + if(i>0){ + logger.info("【微信支付回调】异步保存回调参数成功"); + } + }, 0, TimeUnit.SECONDS); + } + /** * 分账处理 * 1.根据订单号查询分账记录,如果有记录直接返回 @@ -435,6 +455,7 @@ public class CallbackServiceImpl implements CallbackService { if(ObjectUtil.isNotNull(etCapitalFlowService.selectEtCapitalFlowByOutTradeNo(order.getOutTradeNo()))){ return; } + SysDept sysDept = wxPayService.getDeptObjByAreaId(order.getAreaId()); EtCapitalFlow capitalFlow = new EtCapitalFlow(); capitalFlow.setAreaId(order.getAreaId()); capitalFlow.setOrderNo(order.getOrderNo()); @@ -443,7 +464,6 @@ public class CallbackServiceImpl implements CallbackService { capitalFlow.setBusType(busType); capitalFlow.setAmount(order.getTotalFee()); if(busType.equals(ServiceConstants.ORDER_TYPE_DEPOSIT) || busType.equals(ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND)){ - capitalFlow.setOperatorBalance(BigDecimal.ZERO); capitalFlow.setOperatorDividend(BigDecimal.ZERO); capitalFlow.setPartnerDividend(BigDecimal.ZERO); }else{ @@ -460,11 +480,13 @@ public class CallbackServiceImpl implements CallbackService { if(type.equals(ServiceConstants.FLOW_TYPE_INCOME)){ capitalFlow.setPartnerDividend(partnerDividend); capitalFlow.setOperatorDividend(operatorDividend); -// todo capitalFlow.setOperatorBalance(); + capitalFlow.setOperatorBalance(capitalFlow.getOperatorBalance().add(operatorDividend)); + deptService.changeDeptBalance(operatorDividend,sysDept.getDeptId()); }else{ capitalFlow.setPartnerDividend(partnerDividend.negate()); capitalFlow.setOperatorDividend(operatorDividend.negate()); -// todo capitalFlow.setOperatorBalance(); + capitalFlow.setOperatorBalance(capitalFlow.getOperatorBalance().subtract(operatorDividend)); + deptService.changeDeptBalance(operatorDividend.negate(),sysDept.getDeptId()); } } BigDecimal bigDecimal = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP); @@ -487,6 +509,9 @@ public class CallbackServiceImpl implements CallbackService { @Transactional public void weChatRefund(HttpServletRequest request) { String body = HttpUtils.getBody(request); + EtCallbackLog etCallbackLog = new EtCallbackLog(); + etCallbackLog.setBody2(body); + etCallbackLog.setType("2"); logger.info("【微信退款回调】接收对象 : " + JSON.toJSONString(body)); // 解析通知数据 Notification notification = JSON.parseObject(body, Notification.class); @@ -496,6 +521,7 @@ public class CallbackServiceImpl implements CallbackService { // 验签、解密并转换成 RefundNotification RefundNotification refundNotification = checkAndParse(request, body, RefundNotification.class); logger.info("【微信退款回调】转换成RefundNotification: " + JSON.toJSONString(refundNotification)); + etCallbackLog.setBody(JSON.toJSONString(refundNotification)); if (Status.SUCCESS.equals(refundNotification.getRefundStatus())) { // 退款成功后 改变 etRefundService String outRefundNo = refundNotification.getOutRefundNo(); @@ -514,6 +540,8 @@ public class CallbackServiceImpl implements CallbackService { logger.info("【微信退款回调】全部结束!!!!!"); } } + //异步保存回调日志 + asynchronousSaveCallbackLog(etCallbackLog); } /** diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 8f93e85..4b921de 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -30,6 +30,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -417,6 +418,16 @@ public class SysDeptServiceImpl implements ISysDeptService return sysDept; } + /** + * 获取运营商余额 + * + * @return 结果 + */ + @Override + public void changeDeptBalance(BigDecimal amount,Long deptId) { + deptMapper.changeDeptBalance(amount,deptId); + } + /** * 递归列表 */ 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 be8ad17..385d224 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 @@ -90,7 +90,7 @@ public class EtTask { * 3.启动时判断是否分账 */ @Transactional -// @PostConstruct + @PostConstruct public void init() { log.info("=========================启动业务处理========================="); log.info("=========================开始========================="); diff --git a/electripper-system/src/main/resources/mapper/system/EtCallbackLogMapper.xml b/electripper-system/src/main/resources/mapper/system/EtCallbackLogMapper.xml new file mode 100644 index 0000000..df033fd --- /dev/null +++ b/electripper-system/src/main/resources/mapper/system/EtCallbackLogMapper.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + select id, body2, body, create_time, type from et_callback_log + + + + + + + + insert into et_callback_log + + id, + body2, + body, + create_time, + type, + + + #{id}, + #{body2}, + #{body}, + #{createTime}, + #{type}, + + + + + update et_callback_log + + body2 = #{body2}, + body = #{body}, + create_time = #{createTime}, + type = #{type}, + + where id = #{id} + + + + delete from et_callback_log where id = #{id} + + + + delete from et_callback_log where id in + + #{id} + + + \ No newline at end of file diff --git a/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml b/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml index bea0208..dc90efc 100644 --- a/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -213,8 +213,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{deptId} + + update sys_dept set balance = balance + #{amount} where dept_id = #{deptId} + - + update sys_dept set del_flag = '2' where dept_id = #{deptId}