提交代码

master
胡锐 4 months ago
parent 59da087d7f
commit 3c6ef38e73
  1. 1
      bweb/src/main/java/com/bweb/config/AuthConfig.java
  2. 3
      bweb/src/main/java/com/bweb/controller/BsAgentMerAccountController.java
  3. 75
      bweb/src/main/java/com/bweb/controller/TestController.java
  4. 36
      schedule/src/main/java/com/hfkj/schedule/OrderSchedule.java
  5. 3
      service/src/main/java/com/hfkj/dao/BsAgentMerAccountMapperExt.java
  6. 11
      service/src/main/java/com/hfkj/dao/BsOrderMapperExt.java
  7. 10
      service/src/main/java/com/hfkj/service/agent/BsAgentMerAccountService.java
  8. 6
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentMerAccountRecordServiceImpl.java
  9. 38
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentMerAccountServiceImpl.java
  10. 5
      service/src/main/java/com/hfkj/service/order/BsOrderService.java
  11. 8
      service/src/main/java/com/hfkj/service/order/OrderCancelService.java
  12. 35
      service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java

@ -94,6 +94,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/agentMer/*") .excludePathPatterns("/agentMer/*")
.excludePathPatterns("/newLinkNotify/*") .excludePathPatterns("/newLinkNotify/*")
.excludePathPatterns("/merchantPayConfig/editConfig") .excludePathPatterns("/merchantPayConfig/editConfig")
.excludePathPatterns("/test/*")
; ;
} }

@ -116,11 +116,12 @@ public class BsAgentMerAccountController {
} else if (SecUserObjectTypeEnum.type5.getCode() == userSession.getAccount().getObjectType()) { } else if (SecUserObjectTypeEnum.type5.getCode() == userSession.getAccount().getObjectType()) {
// 查询代理商工作人员 // 查询代理商工作人员
BsAgentStaff agentStaff = agentStaffService.getStaffDetailById(userSession.getAccount().getId()); BsAgentStaff agentStaff = agentStaffService.getStaffDetailById(userSession.getAccount().getObjectId());
if (agentStaff == null) { if (agentStaff == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
} }
param.put("agentId", agentStaff.getAgentId()); param.put("agentId", agentStaff.getAgentId());
param.put("agentStaffId", agentStaff.getId());
} else { } else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
} }

@ -0,0 +1,75 @@
package com.bweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.channel.gas.shell.CqShellPetroleumRequestService;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpUtils;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.MD5Util;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsGasOrder;
import com.hfkj.entity.SecUser;
import com.hfkj.model.ResponseData;
import com.hfkj.service.sec.SecUserLoginLogService;
import com.hfkj.service.sec.SecUserService;
import com.hfkj.sysenum.SecUserObjectTypeEnum;
import com.hfkj.sysenum.SecUserStatusEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping(value="/test")
@Api(value="测试")
public class TestController {
Logger log = LoggerFactory.getLogger(TestController.class);
@Resource
private SecUserService secUserService;
@Resource
private SecUserLoginLogService secUserLoginLogService;
@RequestMapping(value="/editUser",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "编辑用户")
public ResponseData editUser() {
try {
JSONObject response = HttpsUtils.doGet("https://oil.dctpay.com/crest/gasOrder/queryOilOrder?orderNo=240804110524374697");
BsGasOrder gasOrder = JSONObject.parseObject(response.getJSONObject("return_data").toJSONString(), BsGasOrder.class);
// 推送加好油【重庆壳牌】
JSONObject object = CqShellPetroleumRequestService.gasSyncPayment(gasOrder.getOrderNo(),
gasOrder.getMerNo(),
gasOrder.getPayTime(),
gasOrder.getGasRefuelPrice(),
gasOrder.getGasOilNo(),
gasOrder.getGasGunNo(),
gasOrder.getPayablePrice(),
gasOrder.getTotalDeductionPrice()
);
return ResponseMsgUtil.success(object);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,36 @@
package com.hfkj.schedule;
import com.hfkj.service.order.BsOrderService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 订单结算业务
* @className: OrderSettleService
* @author: HuRui
* @date: 2024/6/25
**/
@Component
public class OrderSchedule {
@Resource
private BsOrderService orderService;
@Scheduled(cron="0 0/1 * * * ?") //每分钟执行一次
public void cancel() {
List<Map<String, Object>> orderList = orderService.getNeedCancelOrderList();
for (Map<String,Object> param : orderList) {
try {
// 取消订单
orderService.cancel(MapUtils.getString(param, "orderNo"));
} catch (Exception e) {
System.out.println(MapUtils.getString(param, "orderNo")+",取消订单失败!");
}
}
}
}

@ -24,10 +24,11 @@ public interface BsAgentMerAccountMapperExt {
" bs_agent_mer_account a" + " bs_agent_mer_account a" +
" LEFT JOIN bs_merchant b ON a.mer_no = b.mer_no" + " LEFT JOIN bs_merchant b ON a.mer_no = b.mer_no" +
" where 1 = 1" + " where 1 = 1" +
" <if test='param.agentStaffId != null'> and mer_id in (select mer_id from bs_agent_mer where agent_staff_id = #{param.agentStaffId} and `status` = 1) </if>" +
" <if test='param.provinceCode != null'> and b.province_code = #{param.provinceCode} </if>" + " <if test='param.provinceCode != null'> and b.province_code = #{param.provinceCode} </if>" +
" <if test='param.cityCode != null'> and b.city_code = #{param.cityCode} </if>" + " <if test='param.cityCode != null'> and b.city_code = #{param.cityCode} </if>" +
" <if test='param.areaCode != null'> and b.area_code = #{param.areaCode} </if>" + " <if test='param.areaCode != null'> and b.area_code = #{param.areaCode} </if>" +
" <if test='param.agentId != null'> and b.agent_id = #{param.agentId} </if>" + " <if test='param.agentId != null'> and a.agent_id = #{param.agentId} </if>" +
" <if test='param.merNo != null'> and b.mer_no like concat('%',#{param.merNo},'%') </if>" + " <if test='param.merNo != null'> and b.mer_no like concat('%',#{param.merNo},'%') </if>" +
" <if test='param.merName != null'> and b.mer_name like concat('%',#{param.merName},'%') </if>" + " <if test='param.merName != null'> and b.mer_name like concat('%',#{param.merName},'%') </if>" +
" ORDER BY a.amount asc" + " ORDER BY a.amount asc" +

@ -1,7 +1,18 @@
package com.hfkj.dao; package com.hfkj.dao;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/** /**
* mapper扩展类 * mapper扩展类
*/ */
public interface BsOrderMapperExt { public interface BsOrderMapperExt {
@Select(" select a.orderNo,a.timestampdiff " +
" from (select order_no orderNo, TIMESTAMPDIFF(MINUTE,create_time,NOW()) timestampdiff from bs_order where order_status = 1) a " +
" where a.timestampdiff > 10")
List<Map<String,Object>> selectNeedCancelOrderList();
} }

@ -1,6 +1,7 @@
package com.hfkj.service.agent; package com.hfkj.service.agent;
import com.hfkj.entity.BsAgentMerAccount; import com.hfkj.entity.BsAgentMerAccount;
import com.hfkj.entity.BsAgentMerAccountRecord;
import com.hfkj.entity.BsMerchantAccount; import com.hfkj.entity.BsMerchantAccount;
import com.hfkj.entity.BsOrderRefund; import com.hfkj.entity.BsOrderRefund;
@ -67,6 +68,15 @@ public interface BsAgentMerAccountService {
*/ */
void refund(Long agentId, String merNo, BigDecimal amount, BsOrderRefund orderRefund) throws Exception; void refund(Long agentId, String merNo, BigDecimal amount, BsOrderRefund orderRefund) throws Exception;
/**
* 是否交易
* @param agentId
* @param merNo
* @param orderNo
* @return
*/
boolean isTrade(Long agentId, String merNo, String orderNo);
/** /**
* 查询商户列表 * 查询商户列表
* @param param * @param param

@ -69,13 +69,17 @@ public class BsAgentMerAccountRecordServiceImpl implements BsAgentMerAccountReco
} }
if (MapUtils.getLong(param, "agentId") != null) { if (MapUtils.getLong(param, "agentId") != null) {
criteria.andAgentMerAccountIdEqualTo(MapUtils.getLong(param, "agentId")); criteria.andAgentIdEqualTo(MapUtils.getLong(param, "agentId"));
} }
if (StringUtils.isNotBlank(MapUtils.getString(param, "merNo"))) { if (StringUtils.isNotBlank(MapUtils.getString(param, "merNo"))) {
criteria.andMerNoEqualTo(MapUtils.getString(param, "merNo")); criteria.andMerNoEqualTo(MapUtils.getString(param, "merNo"));
} }
if (StringUtils.isNotBlank(MapUtils.getString(param, "orderNo"))) {
criteria.andSourceOrderNoEqualTo(MapUtils.getString(param, "orderNo"));
}
example.setOrderByClause("create_time desc"); example.setOrderByClause("create_time desc");
return agentMerAccountRecordMapper.selectByExample(example); return agentMerAccountRecordMapper.selectByExample(example);
} }

@ -18,8 +18,10 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @className: BsAgentMerAccountServiceImpl * @className: BsAgentMerAccountServiceImpl
@ -178,10 +180,6 @@ public class BsAgentMerAccountServiceImpl implements BsAgentMerAccountService {
// 获取锁成功 // 获取锁成功
// 查询账户 // 查询账户
BsAgentMerAccount merAccount = getAccount(agentId, merNo); BsAgentMerAccount merAccount = getAccount(agentId, merNo);
// 余额 是否小于 消费余额
if (merAccount.getAmount().compareTo(amount) == -1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "余额不足,暂时无法交易");
}
// 变更前金额 // 变更前金额
BigDecimal beforeAmount = merAccount.getAmount(); BigDecimal beforeAmount = merAccount.getAmount();
// 计算消费后金额 // 计算消费后金额
@ -266,6 +264,38 @@ public class BsAgentMerAccountServiceImpl implements BsAgentMerAccountService {
} }
} }
@Override
public boolean isTrade(Long agentId, String merNo, String orderNo) {
Map<String,Object> param = new HashMap<>();
param.put("agentId", agentId);
param.put("merNo", merNo);
param.put("orderNo", orderNo);
// 查询订单扣款记录
List<BsAgentMerAccountRecord> list = agentMerAccountRecordService.getList(param);
// 结果
boolean result = false;
if (!list.isEmpty()) {
// 是否有交易
List<BsAgentMerAccountRecord> trade = list
.stream().filter(o -> o.getType().equals(MerchantAccountRecordTypeEnum.type2.getType()))
.collect(Collectors.toList());
if (!trade.isEmpty()) {
result = true;
// 是否有退款给商户
List<BsAgentMerAccountRecord> refund = list
.stream().filter(o -> o.getType().equals(MerchantAccountRecordTypeEnum.type1.getType()))
.collect(Collectors.toList());
if (!refund.isEmpty()) {
// 有退款,为false 不可重复退款给商户
result = false;
}
}
}
return result;
}
@Override @Override
public List<Map<String, Object>> getMerList(Map<String, Object> param) { public List<Map<String, Object>> getMerList(Map<String, Object> param) {
return agentMerAccountMapper.selectMerList(param); return agentMerAccountMapper.selectMerList(param);

@ -81,5 +81,10 @@ public interface BsOrderService {
*/ */
List<BsOrder> getOrderList(Map<String,Object> param); List<BsOrder> getOrderList(Map<String,Object> param);
/**
* 获取需求取消的订单列表
* @return
*/
List<Map<String,Object>> getNeedCancelOrderList();
} }

@ -74,21 +74,23 @@ public class OrderCancelService {
if (gasOrder.getAgentId() != null) { if (gasOrder.getAgentId() != null) {
try { try {
// 家辉代理商商户金额 // 是否可以退款
boolean isTrade = agentMerAccountService.isTrade(gasOrder.getAgentId(), gasOrder.getMerNo(), gasOrder.getOrderNo());
if (isTrade) {
// 代理商商户金额
Map<String,Object> param = new HashMap<>(); Map<String,Object> param = new HashMap<>();
param.put("sourceType", MerchantAccountRecordSourceTypeEnum.type4.getType()); param.put("sourceType", MerchantAccountRecordSourceTypeEnum.type4.getType());
param.put("sourceOrderNo", gasOrder.getOrderNo()); param.put("sourceOrderNo", gasOrder.getOrderNo());
param.put("sourceOrderContent", "取消加油订单:"+gasOrder.getOrderNo()+",金额:¥" + gasOrder.getGasRefuelPrice()); param.put("sourceOrderContent", "取消加油订单:"+gasOrder.getOrderNo()+",金额:¥" + gasOrder.getGasRefuelPrice());
agentMerAccountService.orderCancel(gasOrder.getAgentId(), gasOrder.getMerNo(), gasOrder.getGasRefuelPrice(), param); agentMerAccountService.orderCancel(gasOrder.getAgentId(), gasOrder.getMerNo(), gasOrder.getGasRefuelPrice(), param);
}
} catch (BaseException e) { } catch (BaseException e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg()); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) { } catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "扣款失败,请稍后重新提交订单"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "扣款失败,请稍后重新提交订单");
} }
} }
} }
} }
} }

@ -12,6 +12,7 @@ import com.hfkj.model.order.OrderChildModel;
import com.hfkj.model.order.OrderModel; import com.hfkj.model.order.OrderModel;
import com.hfkj.mqtopic.OrderTopic; import com.hfkj.mqtopic.OrderTopic;
import com.hfkj.service.order.*; import com.hfkj.service.order.*;
import com.hfkj.sysenum.merchant.MerchantAccountRecordTypeEnum;
import com.hfkj.sysenum.order.OrderChildProductTypeEnum; import com.hfkj.sysenum.order.OrderChildProductTypeEnum;
import com.hfkj.sysenum.order.OrderChildStatusEnum; import com.hfkj.sysenum.order.OrderChildStatusEnum;
import com.hfkj.sysenum.order.OrderStatusEnum; import com.hfkj.sysenum.order.OrderStatusEnum;
@ -66,6 +67,9 @@ public class BsOrderServiceImpl implements BsOrderService {
private OrderPaySuccessService orderPaySuccessService; private OrderPaySuccessService orderPaySuccessService;
@Resource @Resource
private OrderCancelService orderCancelService; private OrderCancelService orderCancelService;
@Resource
private RedisTemplate<String, Object> redisTemplate;
public BsOrder editData(BsOrder order) { public BsOrder editData(BsOrder order) {
order.setUpdateTime(new Date()); order.setUpdateTime(new Date());
if (order.getId() == null) { if (order.getId() == null) {
@ -261,6 +265,13 @@ public class BsOrderServiceImpl implements BsOrderService {
@Override @Override
@Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class}, timeout = 10) @Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class}, timeout = 10)
public OrderModel cancel(String orderNo) { public OrderModel cancel(String orderNo) {
// 锁编号
String lockKey = "ORDER_CANCEL_"+ orderNo;
// 获取锁
Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, "");
if (Boolean.TRUE.equals(lock)) {
try {
// 获取锁成功
// 查询订单 // 查询订单
OrderModel order = getDetail(orderNo); OrderModel order = getDetail(orderNo);
if (order == null) { if (order == null) {
@ -277,7 +288,6 @@ public class BsOrderServiceImpl implements BsOrderService {
orderChild.setStatus(OrderChildStatusEnum.status5.getCode()); orderChild.setStatus(OrderChildStatusEnum.status5.getCode());
orderChildService.editData(orderChild); orderChildService.editData(orderChild);
} }
/* // 退回优惠券 /* // 退回优惠券
if (order.getDeduction().getUserCouponDiscountId() != null) { if (order.getDeduction().getUserCouponDiscountId() != null) {
// 查询用户优惠券 // 查询用户优惠券
@ -317,13 +327,29 @@ public class BsOrderServiceImpl implements BsOrderService {
source source
); );
}*/ }*/
// 取消订单业务 // 取消订单业务
orderCancelService.orderBusHandle(order); orderCancelService.orderBusHandle(order);
// 释放锁
redisTemplate.delete(lockKey);
// 更新缓存 // 更新缓存
cache(order); cache(order);
return order; return order;
} catch (Exception e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "取消失败!未知原因");
}
} else {
try {
Thread.sleep(100);
} catch (Exception e) {}
cancel(orderNo);
}
return null;
} }
@Override @Override
@ -464,4 +490,9 @@ public class BsOrderServiceImpl implements BsOrderService {
return orderMapper.selectByExample(example); return orderMapper.selectByExample(example);
} }
@Override
public List<Map<String, Object>> getNeedCancelOrderList() {
return orderMapper.selectNeedCancelOrderList();
}
} }

Loading…
Cancel
Save