提交代码

dev
胡锐 3 months ago
parent cc8af5bd32
commit 59da087d7f
  1. 164
      bweb/src/main/java/com/bweb/controller/BsAgentMerAccountController.java
  2. 30
      service/src/main/java/com/hfkj/dao/BsAgentMerAccountMapperExt.java
  3. 12
      service/src/main/java/com/hfkj/service/agent/BsAgentMerAccountService.java
  4. 29
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentMerAccountRecordServiceImpl.java
  5. 63
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentMerAccountServiceImpl.java
  6. 29
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentMerServiceImpl.java
  7. 26
      service/src/main/java/com/hfkj/service/order/OrderCancelService.java
  8. 3
      service/src/main/java/com/hfkj/service/order/OrderCreateService.java
  9. 14
      service/src/main/java/com/hfkj/service/order/OrderRefundBusiness.java
  10. 5
      service/src/main/java/com/hfkj/sysenum/merchant/MerchantAccountRecordSourceTypeEnum.java

@ -0,0 +1,164 @@
package com.bweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsAgentMerAccount;
import com.hfkj.entity.BsAgentStaff;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.agent.BsAgentMerAccountRecordService;
import com.hfkj.service.agent.BsAgentMerAccountService;
import com.hfkj.service.agent.BsAgentStaffService;
import com.hfkj.service.merchant.BsMerchantAccountRecordService;
import com.hfkj.service.merchant.BsMerchantAccountService;
import com.hfkj.sysenum.SecUserObjectTypeEnum;
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;
/**
* @className: BsMerchantAccountController
* @author: HuRui
* @date: 2024/7/2
**/
@Controller
@RequestMapping(value = "/agentMerAccount")
@Api(value = "代理商商户账户")
public class BsAgentMerAccountController {
private static Logger log = LoggerFactory.getLogger(BsAgentMerAccountController.class);
@Resource
private BsAgentMerAccountService agentMerAccountService;
@Resource
private BsAgentMerAccountRecordService agentMerAccountRecordService;
@Resource
private BsAgentStaffService agentStaffService;
@Resource
private UserCenter userCenter;
@RequestMapping(value = "/getAccount", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询账户")
public ResponseData getAccount(@RequestParam(value = "agentId", required = true) Long agentId,
@RequestParam(value = "merNo", required = true) String merNo) {
try {
// 查询账户
return ResponseMsgUtil.success(agentMerAccountService.getAccount(agentId, merNo));
} catch (Exception e) {
log.error("BsAgentMerAccountController --> getAccount() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/recharge", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "充值")
public ResponseData recharge(@RequestBody JSONObject body) {
try {
SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
if (SecUserObjectTypeEnum.type1.getCode() != userSession.getAccount().getObjectType()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
}
if (body == null
|| body.getLong("agentId") == null
|| StringUtils.isBlank(body.getString("merNo"))
|| body.getBigDecimal("amount") == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 账户充值
agentMerAccountService.recharge(body.getLong("agentId"), body.getString("merNo"), body.getBigDecimal("amount"));
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("BsAgentMerAccountController --> recharge() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getMerList", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询商户列表")
public ResponseData getMerList(@RequestParam(value = "agentId", required = false) Long agentId,
@RequestParam(value = "merNo", required = false) String merNo,
@RequestParam(value = "merName", required = false) String merName,
@RequestParam(value = "provinceCode", required = false) Long provinceCode,
@RequestParam(value = "cityCode", required = false) Long cityCode,
@RequestParam(value = "areaCode", required = false) Long areaCode,
@RequestParam(value = "pageNum", required = true) Integer pageNum,
@RequestParam(value = "pageSize", required = true) Integer pageSize) {
try {
SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
Map<String,Object> param = new HashMap<>();
if (SecUserObjectTypeEnum.type1.getCode() == userSession.getAccount().getObjectType()) {
param.put("agentId", agentId);
} else if (SecUserObjectTypeEnum.type4.getCode() == userSession.getAccount().getObjectType()) {
param.put("agentId", userSession.getAccount().getObjectId());
} else if (SecUserObjectTypeEnum.type5.getCode() == userSession.getAccount().getObjectType()) {
// 查询代理商工作人员
BsAgentStaff agentStaff = agentStaffService.getStaffDetailById(userSession.getAccount().getId());
if (agentStaff == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
}
param.put("agentId", agentStaff.getAgentId());
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
}
param.put("merNo", merNo);
param.put("merName", merName);
param.put("provinceCode", provinceCode);
param.put("cityCode", cityCode);
param.put("areaCode", areaCode);
PageHelper.startPage(pageNum,pageSize);
return ResponseMsgUtil.success(new PageInfo<>(agentMerAccountService.getMerList(param)));
} catch (Exception e) {
log.error("BsMerchantAccountController --> getRecordList() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getRecordList", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "记录列表")
public ResponseData getRecordList(@RequestParam(value = "agentId", required = true) Long agentId,
@RequestParam(value = "merNo", required = true) String merNo,
@RequestParam(value = "pageNum", required = true) Integer pageNum,
@RequestParam(value = "pageSize", required = true) Integer pageSize) {
try {
Map<String,Object> param = new HashMap<>();
param.put("agentId", agentId);
param.put("merNo", merNo);
PageHelper.startPage(pageNum,pageSize);
return ResponseMsgUtil.success(new PageInfo<>(agentMerAccountRecordService.getList(param)));
} catch (Exception e) {
log.error("BsAgentMerAccountController --> getRecordList() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -1,7 +1,37 @@
package com.hfkj.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* mapper扩展类
*/
public interface BsAgentMerAccountMapperExt {
@Select("<script>" +
" SELECT" +
" b.province_name provinceName," +
" b.city_name cityName," +
" b.area_name areaName," +
" b.mer_no merNo," +
" b.mer_name merName," +
" b.address," +
" a.amount " +
" FROM" +
" bs_agent_mer_account a" +
" LEFT JOIN bs_merchant b ON a.mer_no = b.mer_no" +
" where 1 = 1" +
" <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.areaCode != null'> and b.area_code = #{param.areaCode} </if>" +
" <if test='param.agentId != null'> and b.agent_id = #{param.agentId} </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>" +
" ORDER BY a.amount asc" +
"</script>")
List<Map<String,Object>> selectMerList(@Param("param") Map<String,Object> param);
}

@ -45,7 +45,17 @@ public interface BsAgentMerAccountService {
* @param amount 金额
* @param otherParam 其他参数
*/
void consume(Long agentId,String merNo, BigDecimal amount, Map<String, Object> otherParam) throws Exception;
void consume(Long agentId, String merNo, BigDecimal amount, Map<String, Object> otherParam) throws Exception;
/**
* 订单取消
*
* @param agentId 代理商id
* @param merNo 商户号
* @param amount 金额
* @param otherParam 其他参数
*/
void orderCancel(Long agentId, String merNo, BigDecimal amount, Map<String, Object> otherParam) throws Exception;
/**
* 退款

@ -1,8 +1,11 @@
package com.hfkj.service.agent.impl;
import com.hfkj.common.security.UserCenter;
import com.hfkj.dao.BsAgentMerAccountRecordMapper;
import com.hfkj.entity.BsAgentMerAccountRecord;
import com.hfkj.entity.BsAgentMerAccountRecordExample;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.agent.BsAgentMerAccountRecordService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
@ -23,9 +26,35 @@ import java.util.Map;
public class BsAgentMerAccountRecordServiceImpl implements BsAgentMerAccountRecordService {
@Resource
private BsAgentMerAccountRecordMapper agentMerAccountRecordMapper;
@Resource
private UserCenter userCenter;
@Override
public void create(BsAgentMerAccountRecord data) {
try {
SecUserSessionObject secUserSessionObject = userCenter.getSessionModel(SecUserSessionObject.class);
if (secUserSessionObject != null) {
data.setOpUserType(1);
data.setOpUserId(secUserSessionObject.getAccount().getId());
data.setOpUserName(secUserSessionObject.getAccount().getUserName());
data.setOpUserPhone(secUserSessionObject.getAccount().getTelephone());
}
} catch (Exception e) {
System.out.println("获取管理员信息失败");
}
try {
UserSessionObject userModel = userCenter.getSessionModel(UserSessionObject.class);
if (userModel != null) {
data.setOpUserType(2);
data.setOpUserId(userModel.getUser().getId());
data.setOpUserName(userModel.getUser().getUserName());
data.setOpUserPhone(userModel.getUser().getPhone());
}
} catch (Exception e) {
System.out.println("获取客户信息失败");
}
data.setStatus(1);
data.setCreateTime(new Date());
agentMerAccountRecordMapper.insert(data);
}

@ -1,5 +1,6 @@
package com.hfkj.service.agent.impl;
import com.hfkj.common.exception.BaseException;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
@ -150,6 +151,63 @@ public class BsAgentMerAccountServiceImpl implements BsAgentMerAccountService {
// 释放锁
redisTemplate.delete(lockKey);
} catch (BaseException e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知错误");
}
} else {
Thread.sleep(100);
consume(agentId, merNo, amount, otherParam);
}
}
@Override
public void orderCancel(Long agentId, String merNo, BigDecimal amount, Map<String, Object> otherParam) throws Exception {
// 锁编号
String lockKey = LOCK_KEY+agentId+"_"+merNo;
// 获取锁
Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, "");
if (Boolean.TRUE.equals(lock)) {
try {
// 获取锁成功
// 查询账户
BsAgentMerAccount merAccount = getAccount(agentId, merNo);
// 余额 是否小于 消费余额
if (merAccount.getAmount().compareTo(amount) == -1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "余额不足,暂时无法交易");
}
// 变更前金额
BigDecimal beforeAmount = merAccount.getAmount();
// 计算消费后金额
merAccount.setAmount(merAccount.getAmount().add(amount));
// 累积消费金额
merAccount.setAmountConsume(merAccount.getAmountConsume().subtract(amount));
editData(merAccount);
// 变更后金额
BigDecimal afterAmount = merAccount.getAmount();
BsAgentMerAccountRecord record = new BsAgentMerAccountRecord();
record.setAgentId(agentId);
record.setAgentMerAccountId(merAccount.getId());
record.setMerNo(merAccount.getMerNo());
record.setType(MerchantAccountRecordTypeEnum.type1.getType());
record.setTransactionAmount(amount);
record.setBeforeAmount(beforeAmount);
record.setAfterAmount(afterAmount);
record.setSourceType(MapUtils.getInteger(otherParam, "sourceType"));
record.setSourceId(MapUtils.getLong(otherParam, "sourceId"));
record.setSourceOrderNo(MapUtils.getString(otherParam, "sourceOrderNo"));
record.setSourceContent(MapUtils.getString(otherParam, "sourceContent"));
agentMerAccountRecordService.create(record);
// 释放锁
redisTemplate.delete(lockKey);
} catch (Exception e) {
e.printStackTrace();
// 释放锁
@ -170,7 +228,7 @@ public class BsAgentMerAccountServiceImpl implements BsAgentMerAccountService {
if (Boolean.TRUE.equals(lock)) {
try {
// 获取锁成功
// 查询车队油卡
// 查询账户
BsAgentMerAccount merAccount = getAccount(agentId, merNo);
// 变更前金额
BigDecimal beforeAmount = merAccount.getAmount();
@ -210,6 +268,7 @@ public class BsAgentMerAccountServiceImpl implements BsAgentMerAccountService {
@Override
public List<Map<String, Object>> getMerList(Map<String, Object> param) {
return null;
return agentMerAccountMapper.selectMerList(param);
}
}

@ -6,16 +6,19 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsAgentMerMapper;
import com.hfkj.entity.*;
import com.hfkj.model.AgentMerAllot;
import com.hfkj.service.agent.BsAgentMerAccountService;
import com.hfkj.service.merchant.BsMerchantService;
import com.hfkj.service.agent.BsAgentMerService;
import com.hfkj.service.agent.BsAgentService;
import com.hfkj.service.agent.BsAgentStaffService;
import com.hfkj.sysenum.MerchantSourceTypeEnum;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
@ -37,6 +40,8 @@ public class BsAgentMerServiceImpl implements BsAgentMerService {
private BsAgentStaffService agentStaffService;
@Resource
private BsMerchantService merchantService;
@Resource
private BsAgentMerAccountService agentMerAccountService;
@Override
public void editData(BsAgentMer data) {
data.setUpdateTime(new Date());
@ -89,6 +94,17 @@ public class BsAgentMerServiceImpl implements BsAgentMerService {
agentMer.setCreateTime(new Date());
agentMer.setUpdateTime(new Date());
dataList.add(agentMer);
if (merchant.getSourceType().equals(MerchantSourceTypeEnum.type1.getNumber())) {
BsAgentMerAccount account = new BsAgentMerAccount();
account.setAgentId(agentId);
account.setMerId(merchant.getId());
account.setMerNo(merchant.getMerNo());
account.setAmount(new BigDecimal("0"));
account.setAmountConsume(new BigDecimal("0"));
account.setStatus(1);
agentMerAccountService.editData(account);
}
}
}
agentMerService.addData(dataList);
@ -112,6 +128,19 @@ public class BsAgentMerServiceImpl implements BsAgentMerService {
example.clear();
example.createCriteria().andAgentStaffIdIn(staffIdList).andMerNoIn(merNoArray).andStatusNotEqualTo(0);
agentMerMapper.updateByExampleSelective(agentMer, example);
for (String merNo : merNoArray) {
// 查询门店
BsMerchant merchant = merchantService.getMerchant(merNo);
if (merchant != null && MerchantSourceTypeEnum.type1.getNumber().equals(merchant.getSourceType())) {
// 删除代理商下的商户账户
BsAgentMerAccount account = agentMerAccountService.getAccount(agentId, merchant.getMerNo());
if (account != null) {
account.setStatus(0);
agentMerAccountService.editData(account);
}
}
}
}
@Override

@ -1,11 +1,17 @@
package com.hfkj.service.order;
import com.hfkj.common.exception.BaseException;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.entity.*;
import com.hfkj.model.order.OrderChildModel;
import com.hfkj.model.order.OrderModel;
import com.hfkj.service.agent.BsAgentMerAccountService;
import com.hfkj.service.gas.BsGasOrderService;
import com.hfkj.sysenum.gas.OrderOilStatus;
import com.hfkj.sysenum.merchant.MerchantAccountRecordSourceTypeEnum;
import com.hfkj.sysenum.order.OrderChildProductTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,6 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 取消订单业务
@ -35,6 +43,8 @@ public class OrderCancelService {
private BsOrderChildService orderChildService;
@Resource
private BsGasOrderService gasOrderService;
@Resource
private BsAgentMerAccountService agentMerAccountService;
/**
* 订单业务处理
* @param order
@ -61,6 +71,22 @@ public class OrderCancelService {
gasOrder.setStatus(OrderOilStatus.STATUS3.getNumber());
gasOrder.setCancelTime(new Date());
gasOrderService.updateGasOrder(gasOrder);
if (gasOrder.getAgentId() != null) {
try {
// 家辉代理商商户金额
Map<String,Object> param = new HashMap<>();
param.put("sourceType", MerchantAccountRecordSourceTypeEnum.type4.getType());
param.put("sourceOrderNo", gasOrder.getOrderNo());
param.put("sourceOrderContent", "取消加油订单:"+gasOrder.getOrderNo()+",金额:¥" + gasOrder.getGasRefuelPrice());
agentMerAccountService.orderCancel(gasOrder.getAgentId(), gasOrder.getMerNo(), gasOrder.getGasRefuelPrice(), param);
} catch (BaseException e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "扣款失败,请稍后重新提交订单");
}
}
}
}

@ -1,5 +1,6 @@
package com.hfkj.service.order;
import com.hfkj.common.exception.BaseException;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
@ -113,6 +114,8 @@ public class OrderCreateService {
param.put("sourceOrderNo", gasOrder.getOrderNo());
param.put("sourceOrderContent", "创建加油订单:"+gasOrder.getOrderNo()+",加油金额:¥" +orderChild.getProductPrice());
agentMerAccountService.consume(agentMer.getAgentId(), agentMer.getMerNo(), orderChild.getProductPrice(), param);
} catch (BaseException e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "扣款失败,请稍后重新提交订单");
}

@ -12,6 +12,7 @@ import com.hfkj.entity.BsMerchantAccount;
import com.hfkj.entity.BsOrderChild;
import com.hfkj.entity.BsOrderRefund;
import com.hfkj.model.order.OrderChildModel;
import com.hfkj.service.agent.BsAgentMerAccountService;
import com.hfkj.service.gas.BsGasOrderService;
import com.hfkj.service.merchant.BsMerchantAccountService;
import com.hfkj.sysenum.MerchantSourceTypeEnum;
@ -39,6 +40,8 @@ public class OrderRefundBusiness {
private BsGasOrderService gasOrderService;
@Resource
private BsMerchantAccountService merchantAccountService;
@Resource
private BsAgentMerAccountService agentMerAccountService;
/**
* 前置业务处理
@ -87,6 +90,17 @@ public class OrderRefundBusiness {
gasOrder.setRefundRemarks(refund.getRefundRemark());
gasOrderService.updateGasOrder(gasOrder);
if (MerchantSourceTypeEnum.type1.getNumber().equals(gasOrder.getChannelType())) {
try {
// 代理商商户账户退款
agentMerAccountService.refund(gasOrder.getAgentId(), gasOrder.getMerNo(), gasOrder.getGasRefuelPrice(), refund);
} catch (BaseException e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "扣款失败,请稍后重新提交订单");
}
}
try {
// 订单是否异常 false:无异常 true:有异常
if (gasOrder.getAbnormal().equals(false)) {

@ -22,6 +22,11 @@ public enum MerchantAccountRecordSourceTypeEnum {
* 订单退款
*/
type3(3 , "订单退款"),
/**
* 订单取消
*/
type4(4 , "订单取消"),
;
private Integer type;

Loading…
Cancel
Save