修改充值流程-适配mq+rocketutil
This commit is contained in:
parent
8021669f4c
commit
e96aac959e
@ -38,6 +38,7 @@ public interface CommissionRecordService {
|
||||
* @return 实例对象
|
||||
*/
|
||||
CommissionRecord insert(CommissionRecord commissionRecord);
|
||||
CommissionRecord insert2(CommissionRecord commissionRecord);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
|
@ -64,6 +64,12 @@ public class CommissionRecordServiceImpl implements CommissionRecordService {
|
||||
return commissionRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommissionRecord insert2(CommissionRecord commissionRecord) {
|
||||
return commissionRecord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
|
@ -160,5 +160,11 @@ public class IntegralOrdersController extends BaseController {
|
||||
return getSuccessResult(this.integralOrdersService.checkTheStatusOfYourPaymentByIntegral(orderNumber));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("integralOrdersProcessingUni")
|
||||
public ResponseObject integralOrdersProcessingUni(@RequestBody IntegralOrdersRequest integralOrdersList) {
|
||||
return getSuccessResult(this.integralOrdersService.integralOrdersProcessingUni(integralOrdersList));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,10 @@ public class IntegralSettings extends BaseEntity {
|
||||
* 店铺ID
|
||||
*/
|
||||
private Integer storeId;
|
||||
/**
|
||||
* 连锁店id
|
||||
*/
|
||||
private Integer chainStoreId;
|
||||
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,8 @@
|
||||
|
||||
<!--新增所有列-->
|
||||
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into integral_detail(user_id, points_change, current_points, type, change_reason, store_id, create_time, update_time, create_by, update_by,change_type)
|
||||
values (#{userId}, #{pointsChange}, #{currentPoints}, #{type}, #{changeReason}, #{storeId}, #{createTime}, #{createTime}, #{createBy}, #{updateBy},#{changeType})
|
||||
insert into integral_detail(user_id, points_change, current_points, type, change_reason, store_id, create_time, update_time, create_by, update_by,change_type,chain_store_id)
|
||||
values (#{userId}, #{pointsChange}, #{currentPoints}, #{type}, #{changeReason}, #{storeId}, #{createTime}, #{createTime}, #{createBy}, #{updateBy},#{changeType}, #{chainStoreId})
|
||||
</insert>
|
||||
|
||||
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
||||
@ -187,6 +187,7 @@
|
||||
<if test="type != null">
|
||||
and type = #{type}
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
|
@ -72,5 +72,7 @@ public interface IntegralOrdersService {
|
||||
|
||||
int editPayStatus(String orderNumber, String payStates,Integer storeId);
|
||||
|
||||
IntegralOrders integralOrdersProcessingUni(IntegralOrdersRequest integralOrdersList);
|
||||
|
||||
|
||||
}
|
||||
|
@ -147,9 +147,17 @@ public class IntegralOrdersServiceImpl implements IntegralOrdersService {
|
||||
@Override
|
||||
@Transactional
|
||||
public IntegralOrders integralOrdersProcessing(IntegralOrdersRequest integralOrdersList) {
|
||||
double epsilon = 1e-10; // 阈值
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
// 当为小程序下单时
|
||||
if (ObjectUtil.isNotEmpty(integralOrdersList.getOrderChannel()) & integralOrdersList.getOrderChannel() == -1) {
|
||||
nowAccountInfo.setChainStoreId(integralOrdersList.getChainStoreId());
|
||||
nowAccountInfo.setStoreId(integralOrdersList.getStoreId());
|
||||
integralOrdersList.getIntegralOrdersList().get(0).setUserId(nowAccountInfo.getId());
|
||||
|
||||
}
|
||||
// 首先判断是否足够积分
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById(integralOrdersList.getIntegralOrdersList().get(0).getUserId());
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById2(integralOrdersList.getIntegralOrdersList().get(0).getUserId(),nowAccountInfo.getChainStoreId());
|
||||
if (ljUserVos.getPoints() < integralOrdersList.getAllPoints()) {
|
||||
integralOrdersList.getIntegralOrdersList().get(0).setStatus("un");
|
||||
return integralOrdersList.getIntegralOrdersList().get(0);
|
||||
@ -158,11 +166,10 @@ public class IntegralOrdersServiceImpl implements IntegralOrdersService {
|
||||
List<IntegralOrders> integralOrdersList1 = integralOrdersList.getIntegralOrdersList();
|
||||
if (integralOrdersList1.size()<0) return null;
|
||||
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
|
||||
String status = "unpaid";
|
||||
// 添加储存充值
|
||||
if ("CASH".equals(integralOrdersList.getPaymentType())) {
|
||||
if ("CASH".equals(integralOrdersList.getPaymentType()) || integralOrdersList.getAllAmout() <= epsilon) {
|
||||
status = "paid";
|
||||
}else {
|
||||
status = "unpaid";
|
||||
@ -171,19 +178,20 @@ public class IntegralOrdersServiceImpl implements IntegralOrdersService {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String timestamp = dateFormat.format(new Date());
|
||||
String randomString = UUID.randomUUID().toString().replace("-","").substring(0,6);
|
||||
String orderNo = timestamp+randomString;
|
||||
String orderNo = "2345"+timestamp+randomString;
|
||||
|
||||
// 生成订单编号
|
||||
for (IntegralOrders integralOrders : integralOrdersList1) {
|
||||
integralOrders.setStoreId(nowAccountInfo.getStoreId());
|
||||
integralOrders.setCreateBy(nowAccountInfo.getStaffId().toString());
|
||||
if (ObjectUtil.isNotEmpty(nowAccountInfo.getStaffId())) {
|
||||
integralOrders.setCreateBy(nowAccountInfo.getStaffId().toString());
|
||||
}
|
||||
|
||||
integralOrders.setOrderNumber(orderNo);
|
||||
integralOrders.setStatus(status);
|
||||
}
|
||||
integralOrdersDao.insertBatch(integralOrdersList.getIntegralOrdersList());
|
||||
|
||||
double epsilon = 1e-10; // 阈值
|
||||
boolean flag = false;
|
||||
|
||||
if (!ObjectUtil.isEmpty(integralOrdersList.getAllAmout())
|
||||
@ -288,4 +296,59 @@ public class IntegralOrdersServiceImpl implements IntegralOrdersService {
|
||||
return integralOrdersDao.editPayStatus(orderNumber,payStates,storeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntegralOrders integralOrdersProcessingUni(IntegralOrdersRequest integralOrdersList) {
|
||||
double epsilon = 1e-10; // 阈值
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
|
||||
// 首先判断是否足够积分
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById2(nowAccountInfo.getId(),integralOrdersList.getChainStoreId());
|
||||
if (ljUserVos.getPoints() < integralOrdersList.getAllPoints()) {
|
||||
integralOrdersList.getIntegralOrdersList().get(0).setStatus("un");
|
||||
return integralOrdersList.getIntegralOrdersList().get(0);
|
||||
}
|
||||
|
||||
// 插入订单
|
||||
List<IntegralOrders> integralOrdersList1 = integralOrdersList.getIntegralOrdersList();
|
||||
if (integralOrdersList1.size()<0) return null;
|
||||
|
||||
String status = "unpaid";
|
||||
// 添加储存充值
|
||||
if ("CASH".equals(integralOrdersList.getPaymentType()) || integralOrdersList.getAllAmout() <= epsilon) {
|
||||
status = "paid";
|
||||
}else {
|
||||
status = "unpaid";
|
||||
}
|
||||
// 根据日期生成支付编号
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String timestamp = dateFormat.format(new Date());
|
||||
String randomString = UUID.randomUUID().toString().replace("-","").substring(0,6);
|
||||
String orderNo = timestamp+randomString;
|
||||
|
||||
// 生成订单编号
|
||||
for (IntegralOrders integralOrders : integralOrdersList1) {
|
||||
integralOrders.setStoreId(nowAccountInfo.getStoreId());
|
||||
if (ObjectUtil.isNotEmpty(nowAccountInfo.getStaffId())) {
|
||||
integralOrders.setCreateBy(nowAccountInfo.getStaffId().toString());
|
||||
}
|
||||
|
||||
integralOrders.setOrderNumber(orderNo);
|
||||
integralOrders.setStatus(status);
|
||||
}
|
||||
integralOrdersDao.insertBatch(integralOrdersList.getIntegralOrdersList());
|
||||
|
||||
boolean flag = false;
|
||||
|
||||
if (!ObjectUtil.isEmpty(integralOrdersList.getAllAmout())
|
||||
&& integralOrdersList.getAllAmout() > epsilon
|
||||
&& "unpaid".equals(status)){
|
||||
flag = true;
|
||||
}
|
||||
|
||||
// 支付
|
||||
if (flag) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -229,9 +229,11 @@ public class IntegralSettingsServiceImpl implements IntegralSettingsService {
|
||||
if (integer == 0) {
|
||||
|
||||
// 根据店铺id 查找连锁店id
|
||||
LJStore ljStore = iljStoreService.selectStoreByIdUni(integralSettings.getStoreId());
|
||||
// LJStore ljStore = iljStoreService.selectStoreByIdUni(integralSettings.getStoreId());
|
||||
// 查询当前用户
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById4Chain(nowAccountInfo.getId(),ljStore.getChainStoreId());
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById4Chain(nowAccountInfo.getId(),integralSettings.getChainStoreId());
|
||||
ljUserVos.setChainStoreId(integralSettings.getChainStoreId());
|
||||
ljUserVos.setStoreId(integralSettings.getStoreId());
|
||||
// 查询积分配置
|
||||
IntegralSettings integralSetting = integralSettingsMapper.getByStoreId(integralSettings.getStoreId());
|
||||
|
||||
@ -240,37 +242,55 @@ public class IntegralSettingsServiceImpl implements IntegralSettingsService {
|
||||
// 查询昨天是否签到
|
||||
List<IntegralDetail> signInGifts = integralDetailMapper.signInGiftsYesterday("签到赠送");
|
||||
|
||||
IntegralDetail integralDetail = new IntegralDetail();
|
||||
integralDetail.setStoreId(integralSettings.getStoreId());
|
||||
|
||||
if (ObjectUtil.isEmpty(signInGifts)) {
|
||||
extracted(nowAccountInfo, ljUserVos, jsonArray, integralDetail, 0);
|
||||
extracted(ljUserVos, jsonArray, 0);
|
||||
} else {
|
||||
String changeReason = signInGifts.get(0).getChangeReason();
|
||||
|
||||
// 获取字符串的第4位字符(索引为3)
|
||||
char dayChar = changeReason.charAt(3);
|
||||
// 将字符转换为整数
|
||||
int dayInt = Character.getNumericValue(dayChar);
|
||||
// // 获取字符串的第4位字符(索引为3)
|
||||
// char dayChar = changeReason.charAt(3);
|
||||
// // 将字符转换为整数
|
||||
// int dayInt = Character.getNumericValue(dayChar);
|
||||
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < changeReason.length(); i++) {
|
||||
if (Character.isDigit(changeReason.charAt(i))) {
|
||||
sb.append(changeReason.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
int dayInt = Integer.parseInt(sb.toString());
|
||||
|
||||
// 签到超8天处理
|
||||
if (dayInt >= 8 && 8<= jsonArray.size()) {
|
||||
extracted(nowAccountInfo, ljUserVos, jsonArray, integralDetail, dayInt);
|
||||
} else if (dayInt >= 1 && dayInt <= jsonArray.size()) {
|
||||
extracted(nowAccountInfo, ljUserVos, jsonArray, integralDetail, dayInt);
|
||||
}
|
||||
// if (dayInt > 8 && 8< jsonArray.size()) {
|
||||
// extracted(ljUserVos, jsonArray, dayInt);
|
||||
// } else if (dayInt >= 1 && dayInt <= jsonArray.size()) {
|
||||
extracted(ljUserVos, jsonArray, dayInt);
|
||||
// }
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void extracted(AccountInfo nowAccountInfo, LJUserVo ljUserVos, JSONArray jsonArray, IntegralDetail integralDetail, int dayInt) {
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(dayInt);
|
||||
private void extracted(LJUserVo ljUserVos, JSONArray jsonArray, int dayInt) {
|
||||
IntegralDetail integralDetail = new IntegralDetail();
|
||||
integralDetail.setStoreId(ljUserVos.getStoreId());
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (dayInt >= 8 ) {
|
||||
jsonObject = jsonArray.getJSONObject(7);
|
||||
|
||||
} else {
|
||||
jsonObject = jsonArray.getJSONObject(dayInt);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>(jsonObject);
|
||||
|
||||
String point = map.get("integral").toString(); // 获取积分
|
||||
|
||||
integralDetail.setUserId(nowAccountInfo.getId());
|
||||
integralDetail.setUserId(ljUserVos.getId());
|
||||
integralDetail.setPointsChange(Double.valueOf(point));
|
||||
|
||||
// 计算积分
|
||||
@ -279,6 +299,7 @@ public class IntegralSettingsServiceImpl implements IntegralSettingsService {
|
||||
integralDetail.setCurrentPoints(addPoints.intValue());
|
||||
integralDetail.setChangeType("1");
|
||||
integralDetail.setType("签到赠送");
|
||||
integralDetail.setChainStoreId(ljUserVos.getChainStoreId());
|
||||
|
||||
integralDetail.setChangeReason("签到第"+ (dayInt +1)+"天获得");
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.fuint.business.integral.vo;
|
||||
|
||||
import com.fuint.business.integral.entity.IntegralOrders;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@ -21,6 +22,22 @@ public class IntegralOrdersRequest {
|
||||
*/
|
||||
private Double allPoints;
|
||||
|
||||
/**
|
||||
* 连锁店id
|
||||
*/
|
||||
private Integer chainStoreId;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Integer storeId;
|
||||
|
||||
/**
|
||||
* 下单渠道
|
||||
* -1为小程序
|
||||
*/
|
||||
private Integer orderChannel;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
|
@ -29,12 +29,13 @@
|
||||
<result property="paymentNo" column="payment_no" jdbcType="VARCHAR"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="oilType" column="oil_type" jdbcType="VARCHAR"/>
|
||||
<result property="chainStoreId" column="chain_store_id" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!--查询单个-->
|
||||
<select id="queryById" resultMap="CardFuelRecordMap">
|
||||
select
|
||||
id, mt_user_id, name, mobile, mt_staff_id, real_name, staff_mobile, card_fuel_id, recharge_balance, income_litres, payment_type, remark, points, growth_value, royalty_type, percentage_commissions, amount_commission, create_by, create_time, update_by, update_time, pay_status, store_id, payment_no, type, oil_type
|
||||
id, mt_user_id, name, mobile, mt_staff_id, real_name, staff_mobile, card_fuel_id, recharge_balance, income_litres, payment_type, remark, points, growth_value, royalty_type, percentage_commissions, amount_commission, create_by, create_time, update_by, update_time, pay_status, store_id, payment_no, type, oil_type, chain_store_id
|
||||
from card_fuel_record
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
@ -42,6 +42,7 @@ public interface CardFuelChangeService {
|
||||
* @return 实例对象
|
||||
*/
|
||||
CardFuelChange insert(CardFuelChange cardFuelChange);
|
||||
CardFuelChange insert2(CardFuelChange cardFuelChange);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
|
@ -73,6 +73,11 @@ public class CardFuelChangeServiceImpl implements CardFuelChangeService {
|
||||
return cardFuelChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardFuelChange insert2(CardFuelChange cardFuelChange) {
|
||||
return cardFuelChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
|
@ -152,9 +152,10 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String timestamp = dateFormat.format(new Date());
|
||||
String randomString = UUID.randomUUID().toString().replace("-","").substring(0,6);
|
||||
String orderNo = timestamp+randomString;
|
||||
String orderNo = "2345"+timestamp+randomString;
|
||||
cardFuelRecordDTO.setPaymentNo(orderNo);
|
||||
cardFuelRecordDTO.setStoreId(nowAccountInfo.getStoreId());
|
||||
cardFuelRecordDTO.setChainStoreId(nowAccountInfo.getChainStoreId());
|
||||
|
||||
cardFuelRecordMapper.insert(cardFuelRecordDTO);
|
||||
Double theAmountToBePaid = 0.0;
|
||||
@ -191,9 +192,6 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
|
||||
map.put("privateKey", merchantConfig.getPrivateKey());
|
||||
map.put("type", "CFR");
|
||||
map.put("orderId", cardFuelRecordDTO.getId().toString());
|
||||
|
||||
|
||||
|
||||
// 调用支付接口
|
||||
try {
|
||||
fyPayService.pay(map);
|
||||
@ -209,7 +207,7 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
|
||||
CardFuelRecord cardFuelRecord = cardFuelRecordMapper.queryById(id);
|
||||
if ("paid".equals(cardFuelRecord.getPayStatus())){
|
||||
// 查询用户信息
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById(cardFuelRecord.getMtUserId());
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById2(cardFuelRecord.getMtUserId(),cardFuelRecord.getChainStoreId());
|
||||
|
||||
// 修改该用户的余额信息
|
||||
if (!ObjectUtil.isEmpty(ljUserVos)) {
|
||||
@ -225,7 +223,7 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
|
||||
// 积分表变动
|
||||
if (!ObjectUtil.isEmpty(cardFuelRecord.getPoints()) && cardFuelRecord.getPoints() != 0) {
|
||||
IntegralDetail integralDetail = changesInPoints(cardFuelRecord,ljUserVos);
|
||||
integralDetailService.insert(integralDetail);
|
||||
integralDetailService.insert2(integralDetail);
|
||||
}
|
||||
}else {
|
||||
return cardFuelRecord;
|
||||
@ -286,6 +284,7 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
|
||||
public CardFuelChange editFuelChange (CardFuelRecord cardFuelRecord) {
|
||||
CardFuelChange cardFuelChange = new CardFuelChange();
|
||||
cardFuelChange.setChainStoreId(cardFuelRecord.getChainStoreId());
|
||||
cardFuelChange.setStoreId(cardFuelRecord.getStoreId());
|
||||
cardFuelChange.setUserId(cardFuelRecord.getMtUserId());
|
||||
cardFuelChange.setChangeType("1");
|
||||
cardFuelChange.setFromType("油卡充值赠送");
|
||||
@ -306,6 +305,8 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
|
||||
|
||||
integralDetail.setCurrentPoints(addPoints.intValue());
|
||||
integralDetail.setChangeReason("购买油卡赠送");
|
||||
integralDetail.setStoreId(cardFuelRecord.getStoreId());
|
||||
integralDetail.setChainStoreId(cardFuelRecord.getChainStoreId());
|
||||
return integralDetail;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.fuint.business.marketingActivity.cardValue.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -20,6 +21,7 @@ import com.fuint.business.marketingActivity.cardValue.service.CardValueRecordSer
|
||||
import com.fuint.business.marketingActivity.cardValue.vo.Excel.CardValueRecordExcel;
|
||||
import com.fuint.business.order.entity.CardBalanceChange;
|
||||
import com.fuint.business.order.service.CardBalanceChangeService;
|
||||
import com.fuint.business.record.entity.RocketmqRecord;
|
||||
import com.fuint.business.userManager.entity.LJUser;
|
||||
import com.fuint.business.userManager.entity.UserBalance;
|
||||
import com.fuint.business.userManager.mapper.LJUserMapper;
|
||||
@ -27,12 +29,24 @@ import com.fuint.business.userManager.service.LJUserService;
|
||||
import com.fuint.business.userManager.service.UserBalanceService;
|
||||
import com.fuint.business.userManager.vo.LJUserVo;
|
||||
import com.fuint.common.dto.AccountInfo;
|
||||
import com.fuint.common.util.DistributedLockUtil;
|
||||
import com.fuint.common.util.RedisLock;
|
||||
import com.fuint.common.util.RocketUtil;
|
||||
import com.fuint.common.util.TokenUtil;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.client.producer.SendStatus;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.apache.rocketmq.spring.support.RocketMQHeaders;
|
||||
import org.redisson.api.RLock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -73,6 +87,8 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
@Resource
|
||||
CardValueRecordMapper cardValueRecordMapper;
|
||||
|
||||
@Resource
|
||||
RocketUtil rocketUtil;
|
||||
/**
|
||||
* 储值卡充值(新增)
|
||||
* @param cardValueRecordDTO
|
||||
@ -135,30 +151,37 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
return pay;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CardValueRecordDTO prepaidCardTopUp(CardValueRecordDTO cardValueRecordDTO) {
|
||||
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
|
||||
// 添加储存充值
|
||||
if ("CASH".equals(cardValueRecordDTO.getPaymentType())) {
|
||||
cardValueRecordDTO.setPayStatus("paid");
|
||||
}else {
|
||||
}else if(ObjectUtil.isNotEmpty(cardValueRecordDTO.getAuthCode())){
|
||||
cardValueRecordDTO.setPayStatus("unpaid");
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 根据日期生成支付编号
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String timestamp = dateFormat.format(new Date());
|
||||
String randomString = UUID.randomUUID().toString().replace("-","").substring(0,6);
|
||||
String orderNo = timestamp+randomString;
|
||||
String orderNo = "2345"+timestamp+randomString;
|
||||
cardValueRecordDTO.setPaymentNo(orderNo);
|
||||
cardValueRecordDTO.setStoreId(nowAccountInfo.getStoreId());
|
||||
cardValueRecordDTO.setChainStoreId(nowAccountInfo.getChainStoreId());
|
||||
if (ObjectUtil.isEmpty(cardValueRecordDTO.getBidBalance())) cardValueRecordDTO.setBidBalance(0.0);
|
||||
if (cardValueRecordDTO.getBidBalance() <= 0.0) {
|
||||
if (ObjectUtil.isEmpty(cardValueRecordDTO.getRechargeBalance())) cardValueRecordDTO.setRechargeBalance(0.0);
|
||||
if (ObjectUtil.isEmpty(cardValueRecordDTO.getGiftBalance())) cardValueRecordDTO.setGiftBalance(0.0);
|
||||
// todo
|
||||
|
||||
if (cardValueRecordDTO.getBidBalance() >= 0.0) {
|
||||
BigDecimal bigDecimal = new BigDecimal(cardValueRecordDTO.getBidBalance());
|
||||
bigDecimal = bigDecimal.add(new BigDecimal(cardValueRecordDTO.getGiftBalance()).add(new BigDecimal(cardValueRecordDTO.getRechargeBalance())));
|
||||
bigDecimal = bigDecimal.add(new BigDecimal(cardValueRecordDTO.getGiftBalance()).add(new BigDecimal(cardValueRecordDTO.getRechargeBalance().toString())));
|
||||
cardValueRecordDTO.setBidBalance(bigDecimal.doubleValue());
|
||||
}
|
||||
baseMapper.insert(cardValueRecordDTO);
|
||||
@ -205,6 +228,22 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> msg = new HashMap<>();
|
||||
msg.put("tag","cardTag");
|
||||
msg.put("ordId",cardValueRecordDTO.getId().toString());
|
||||
msg.put("ordNo",orderNo);
|
||||
msg.put("storeId",nowAccountInfo.getStoreId());
|
||||
msg.put("chainStoreId",nowAccountInfo.getChainStoreId());
|
||||
|
||||
// 发起rocket请求
|
||||
rocketUtil.pushMessage(msg);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 支付 payment_type
|
||||
return cardValueRecordDTO;
|
||||
}
|
||||
@ -222,7 +261,7 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
// 支付成功之后
|
||||
if ("paid".equals(cardValueRecord.getPayStatus())){
|
||||
// 查询用户信息
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById(cardValueRecord.getMtUserId());
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById2(cardValueRecord.getMtUserId(), cardValueRecord.getChainStoreId());
|
||||
|
||||
// 修改用户的余额信息
|
||||
UserBalance userBalance = balanceCalculation(cardValueRecord);
|
||||
@ -236,19 +275,25 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
if (cardValueRecord.getGiftBalance()>epsilon) {
|
||||
cardBalanceChange.setFromType("余额充值赠送");
|
||||
cardBalanceChange.setBalance(cardValueRecord.getGiftBalance());
|
||||
cardBalanceChangeService.insertCardBalance(cardBalanceChange);
|
||||
cardBalanceChange.setStoreId(cardValueRecord.getStoreId());
|
||||
cardBalanceChange.setChainStoreId(cardValueRecord.getChainStoreId());
|
||||
cardBalanceChange.setCreateBy(cardValueRecord.getMtStaffId().toString());
|
||||
cardBalanceChangeService.insertCardBalance2(cardBalanceChange);
|
||||
}
|
||||
// 积分表变动
|
||||
if (!ObjectUtil.isEmpty(cardValueRecord.getPoints()) && cardValueRecord.getPoints() != 0) {
|
||||
IntegralDetail integralDetail = changesInPoints(cardValueRecord,ljUserVos);
|
||||
integralDetailService.insert(integralDetail);
|
||||
integralDetail.setStoreId(cardValueRecord.getStoreId());
|
||||
integralDetail.setChainStoreId(cardValueRecord.getChainStoreId());
|
||||
integralDetail.setCreateBy(cardValueRecord.getMtStaffId().toString());
|
||||
integralDetailService.insert2(integralDetail);
|
||||
}
|
||||
// 成长值变动明细
|
||||
|
||||
// 员工提成
|
||||
if (!ObjectUtil.isEmpty(cardValueRecord.getRoyaltyType()) && !"1".equals(cardValueRecord.getRoyaltyType())) {
|
||||
CommissionRecord commissionRecord = employeeCommissions(cardValueRecord);
|
||||
commissionRecordService.insert(commissionRecord);
|
||||
commissionRecordService.insert2(commissionRecord);
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -263,15 +308,15 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
cardBalanceChange.setChangeType("1");
|
||||
cardBalanceChange.setFromType("余额充值");
|
||||
cardBalanceChange.setBalance(cardValueRecord.getRechargeBalance());
|
||||
cardBalanceChange.setStoreId(cardValueRecord.getStoreId());
|
||||
cardBalanceChange.setChainStoreId(cardValueRecord.getChainStoreId());
|
||||
|
||||
return cardBalanceChange;
|
||||
}
|
||||
//用户余额表计算
|
||||
private UserBalance balanceCalculation(CardValueRecord cardValueRecordDTO) {
|
||||
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
// nowAccountInfo
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById(cardValueRecordDTO.getMtUserId());
|
||||
LJUserVo ljUserVos = ljUserMapper.selectAllInfoById2(cardValueRecordDTO.getMtUserId(),cardValueRecordDTO.getChainStoreId());
|
||||
|
||||
if (ObjectUtil.isEmpty(cardValueRecordDTO.getBidBalance())) cardValueRecordDTO.setBidBalance(0.00);
|
||||
if (ObjectUtil.isEmpty(cardValueRecordDTO.getPoints())) cardValueRecordDTO.setPoints(0);
|
||||
@ -283,10 +328,8 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
|
||||
// 计算之后修改对应余额
|
||||
BigDecimal bigBidBalance = new BigDecimal(cardValueRecordDTO.getBidBalance());
|
||||
// BigDecimal recharge = new BigDecimal(cardValueRecordDTO.getRechargeBalance());
|
||||
|
||||
BigDecimal addCardValance = bigBidBalance.add(new BigDecimal(ljUserVos.getCardBalance())); //
|
||||
// BigDecimal addCardValance = bigBidBalance.add(new BigDecimal(ljUserVos.getCardBalance()));
|
||||
|
||||
// 计算积分
|
||||
BigDecimal bigPoints = new BigDecimal(cardValueRecordDTO.getPoints());
|
||||
@ -327,6 +370,7 @@ public class CardValueRecordServiceImpl extends ServiceImpl<CardValueRecordMappe
|
||||
commissionRecord.setOrderNo(cardValueRecord.getPaymentNo());
|
||||
commissionRecord.setDescription("余额充值提成");
|
||||
commissionRecord.setType("余额充值");
|
||||
commissionRecord.setStoreId(cardValueRecord.getStoreId());
|
||||
return commissionRecord;
|
||||
}
|
||||
// 成长值变动
|
||||
|
@ -24,5 +24,6 @@
|
||||
and cbc.store_id = #{cardBalanceChange.storeId}
|
||||
</if>
|
||||
</where>
|
||||
order by cbc.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
@ -15,6 +15,8 @@ public interface CardBalanceChangeService extends IService<CardBalanceChange> {
|
||||
*/
|
||||
public int insertCardBalance(CardBalanceChange cardBalanceChange);
|
||||
|
||||
public int insertCardBalance2(CardBalanceChange cardBalanceChange);
|
||||
|
||||
|
||||
IPage<CardBalanceChangeVo> getCardRecordList(Page page, CardBalanceChange cardBalanceChange);
|
||||
|
||||
|
@ -23,6 +23,12 @@ public class CardBalanceChangeServiceImpl extends ServiceImpl<CardBalanceChangeM
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertCardBalance2(CardBalanceChange cardBalanceChange) {
|
||||
int row = baseMapper.insert(cardBalanceChange);
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<CardBalanceChangeVo> getCardRecordList(Page page, CardBalanceChange cardBalanceChange) {
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
|
@ -0,0 +1,93 @@
|
||||
package com.fuint.business.record.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuint.business.record.entity.RocketmqRecord;
|
||||
import com.fuint.business.record.service.RocketmqRecordService;
|
||||
import com.fuint.framework.web.BaseController;
|
||||
import com.fuint.framework.web.ResponseObject;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* (RocketmqRecord)表控制层
|
||||
*
|
||||
* @author wangh
|
||||
* @since 2023-12-14 10:50:02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("rocketmqRecord")
|
||||
public class RocketmqRecordController extends BaseController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Resource
|
||||
private RocketmqRecordService rocketmqRecordService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param rocketmqRecord 筛选条件
|
||||
* @param pageNo 分页对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
@GetMapping("queryByPage")
|
||||
public ResponseObject queryByPage(@RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
|
||||
@Param("rocketmqRecord") RocketmqRecord rocketmqRecord) {
|
||||
Page page = new Page(pageNo, pageSize);
|
||||
IPage< RocketmqRecord> iPageList = this.rocketmqRecordService.queryByPage(page, rocketmqRecord);
|
||||
return getSuccessResult(iPageList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
public ResponseObject queryById(@PathVariable("id") Integer id) {
|
||||
return getSuccessResult(this.rocketmqRecordService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param rocketmqRecord 实体
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
public ResponseObject add(@RequestBody RocketmqRecord rocketmqRecord) {
|
||||
return getSuccessResult(this.rocketmqRecordService.insert(rocketmqRecord));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
*
|
||||
* @param rocketmqRecord 实体
|
||||
* @return 编辑结果
|
||||
*/
|
||||
@PutMapping
|
||||
public ResponseObject edit(@RequestBody RocketmqRecord rocketmqRecord) {
|
||||
return getSuccessResult(this.rocketmqRecordService.update(rocketmqRecord));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
public ResponseObject deleteById(Integer id) {
|
||||
return getSuccessResult(this.rocketmqRecordService.deleteById(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.fuint.business.record.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fuint.repository.model.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* (RocketmqRecord)实体类
|
||||
*
|
||||
* @author wangh
|
||||
* @since 2023-12-14 10:50:02
|
||||
*/
|
||||
@Data
|
||||
public class RocketmqRecord extends BaseEntity {
|
||||
private static final long serialVersionUID = 126513856778862761L;
|
||||
|
||||
private Integer id;
|
||||
/**
|
||||
* RocketMQ 消息的唯一标识
|
||||
*/
|
||||
private String messageId;
|
||||
/**
|
||||
* 订单类型
|
||||
*/
|
||||
private String orderType;
|
||||
|
||||
/**
|
||||
* 发送的主题
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
private Integer orderId;
|
||||
/**
|
||||
* 处理状态
|
||||
*/
|
||||
private String processStatus;
|
||||
/**
|
||||
* 处理次数
|
||||
*/
|
||||
private Integer processCount;
|
||||
/**
|
||||
* 发送状态
|
||||
*/
|
||||
private String sendStatus;
|
||||
/**
|
||||
* 所属连锁店id
|
||||
*/
|
||||
private Integer chainStoreId;
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Integer storeId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
package com.fuint.business.record.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuint.business.record.entity.RocketmqRecord;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (RocketmqRecord)表数据库访问层
|
||||
*
|
||||
* @author wangh
|
||||
* @since 2023-12-14 10:50:02
|
||||
*/
|
||||
public interface RocketmqRecordMapper {
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
RocketmqRecord queryById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询指定行数据
|
||||
*
|
||||
* @param rocketmqRecord 查询条件
|
||||
* @param page 分页对象
|
||||
* @return 对象列表
|
||||
*/
|
||||
IPage<RocketmqRecord> queryAllByLimit(@Param("page") Page page, RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 统计总行数
|
||||
*
|
||||
* @param rocketmqRecord 查询条件
|
||||
* @return 总行数
|
||||
*/
|
||||
long count(RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param rocketmqRecord 实例对象
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insert(RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<RocketmqRecord> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("entities") List<RocketmqRecord> entities);
|
||||
|
||||
/**
|
||||
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<RocketmqRecord> 实例对象列表
|
||||
* @return 影响行数
|
||||
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
|
||||
*/
|
||||
int insertOrUpdateBatch(@Param("entities") List<RocketmqRecord> entities);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param rocketmqRecord 实例对象
|
||||
* @return 影响行数
|
||||
*/
|
||||
int update(RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 影响行数
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,209 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuint.business.record.mapper.RocketmqRecordMapper">
|
||||
|
||||
<resultMap type="com.fuint.business.record.entity.RocketmqRecord" id="RocketmqRecordMap">
|
||||
<result property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="messageId" column="message_id" jdbcType="VARCHAR"/>
|
||||
<result property="orderType" column="order_type" jdbcType="VARCHAR"/>
|
||||
<result property="orderId" column="order_id" jdbcType="INTEGER"/>
|
||||
<result property="processStatus" column="process_status" jdbcType="VARCHAR"/>
|
||||
<result property="processCount" column="process_count" jdbcType="INTEGER"/>
|
||||
<result property="sendStatus" column="send_status" jdbcType="VARCHAR"/>
|
||||
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="chainStoreId" column="chain_store_id" jdbcType="INTEGER"/>
|
||||
<result property="storeId" column="store_id" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<!--查询单个-->
|
||||
<select id="queryById" resultMap="RocketmqRecordMap">
|
||||
select
|
||||
id, message_id, order_type, order_id, process_status, process_count, send_status, create_by, create_time, update_by, update_time, chain_store_id, store_id
|
||||
from rocketmq_record
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<!--查询指定行数据-->
|
||||
<select id="queryAllByLimit" resultMap="RocketmqRecordMap">
|
||||
select
|
||||
id, message_id, order_type, order_id, process_status, process_count, send_status, create_by, create_time, update_by, update_time, chain_store_id, store_id
|
||||
from rocketmq_record
|
||||
<where>
|
||||
<if test="id != null">
|
||||
and id = #{id}
|
||||
</if>
|
||||
<if test="messageId != null and messageId != ''">
|
||||
and message_id = #{messageId}
|
||||
</if>
|
||||
<if test="orderType != null and orderType != ''">
|
||||
and order_type = #{orderType}
|
||||
</if>
|
||||
<if test="orderId != null">
|
||||
and order_id = #{orderId}
|
||||
</if>
|
||||
<if test="processStatus != null and processStatus != ''">
|
||||
and process_status = #{processStatus}
|
||||
</if>
|
||||
<if test="processCount != null">
|
||||
and process_count = #{processCount}
|
||||
</if>
|
||||
<if test="sendStatus != null and sendStatus != ''">
|
||||
and send_status = #{sendStatus}
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
and create_by = #{createBy}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
and create_time = #{createTime}
|
||||
</if>
|
||||
<if test="updateBy != null and updateBy != ''">
|
||||
and update_by = #{updateBy}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
and update_time = #{updateTime}
|
||||
</if>
|
||||
<if test="chainStoreId != null">
|
||||
and chain_store_id = #{chainStoreId}
|
||||
</if>
|
||||
<if test="storeId != null">
|
||||
and store_id = #{storeId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!--统计总行数-->
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(1)
|
||||
from rocketmq_record
|
||||
<where>
|
||||
<if test="id != null">
|
||||
and id = #{id}
|
||||
</if>
|
||||
<if test="messageId != null and messageId != ''">
|
||||
and message_id = #{messageId}
|
||||
</if>
|
||||
<if test="orderType != null and orderType != ''">
|
||||
and order_type = #{orderType}
|
||||
</if>
|
||||
<if test="orderId != null">
|
||||
and order_id = #{orderId}
|
||||
</if>
|
||||
<if test="processStatus != null and processStatus != ''">
|
||||
and process_status = #{processStatus}
|
||||
</if>
|
||||
<if test="processCount != null">
|
||||
and process_count = #{processCount}
|
||||
</if>
|
||||
<if test="sendStatus != null and sendStatus != ''">
|
||||
and send_status = #{sendStatus}
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
and create_by = #{createBy}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
and create_time = #{createTime}
|
||||
</if>
|
||||
<if test="updateBy != null and updateBy != ''">
|
||||
and update_by = #{updateBy}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
and update_time = #{updateTime}
|
||||
</if>
|
||||
<if test="chainStoreId != null">
|
||||
and chain_store_id = #{chainStoreId}
|
||||
</if>
|
||||
<if test="storeId != null">
|
||||
and store_id = #{storeId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!--新增所有列-->
|
||||
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into rocketmq_record(message_id, order_type, order_id, process_status, process_count, send_status, create_by, create_time, update_by, update_time, chain_store_id, store_id)
|
||||
values (#{messageId}, #{orderType}, #{orderId}, #{processStatus}, #{processCount}, #{sendStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{chainStoreId}, #{storeId})
|
||||
</insert>
|
||||
|
||||
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into rocketmq_record(message_id, order_type, order_id, process_status, process_count, send_status, create_by, create_time, update_by, update_time, chain_store_id, store_id)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#{entity.messageId}, #{entity.orderType}, #{entity.orderId}, #{entity.processStatus}, #{entity.processCount}, #{entity.sendStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}, #{entity.chainStoreId}, #{entity.storeId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into rocketmq_record(message_id, order_type, order_id, process_status, process_count, send_status, create_by, create_time, update_by, update_time, chain_store_id, store_id)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#{entity.messageId}, #{entity.orderType}, #{entity.orderId}, #{entity.processStatus}, #{entity.processCount}, #{entity.sendStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}, #{entity.chainStoreId}, #{entity.storeId})
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
message_id = values(message_id),
|
||||
order_type = values(order_type),
|
||||
order_id = values(order_id),
|
||||
process_status = values(process_status),
|
||||
process_count = values(process_count),
|
||||
send_status = values(send_status),
|
||||
create_by = values(create_by),
|
||||
create_time = values(create_time),
|
||||
update_by = values(update_by),
|
||||
update_time = values(update_time),
|
||||
chain_store_id = values(chain_store_id),
|
||||
store_id = values(store_id)
|
||||
</insert>
|
||||
|
||||
<!--通过主键修改数据-->
|
||||
<update id="update">
|
||||
update rocketmq_record
|
||||
<set>
|
||||
<if test="messageId != null and messageId != ''">
|
||||
message_id = #{messageId},
|
||||
</if>
|
||||
<if test="orderType != null and orderType != ''">
|
||||
order_type = #{orderType},
|
||||
</if>
|
||||
<if test="orderId != null">
|
||||
order_id = #{orderId},
|
||||
</if>
|
||||
<if test="processStatus != null and processStatus != ''">
|
||||
process_status = #{processStatus},
|
||||
</if>
|
||||
<if test="processCount != null">
|
||||
process_count = #{processCount},
|
||||
</if>
|
||||
<if test="sendStatus != null and sendStatus != ''">
|
||||
send_status = #{sendStatus},
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
create_by = #{createBy},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="updateBy != null and updateBy != ''">
|
||||
update_by = #{updateBy},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="chainStoreId != null">
|
||||
chain_store_id = #{chainStoreId},
|
||||
</if>
|
||||
<if test="storeId != null">
|
||||
store_id = #{storeId},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!--通过主键删除-->
|
||||
<delete id="deleteById">
|
||||
delete from rocketmq_record where id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.fuint.business.record.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuint.business.record.entity.RocketmqRecord;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
|
||||
|
||||
/**
|
||||
* (RocketmqRecord)表服务接口
|
||||
*
|
||||
* @author wangh
|
||||
* @since 2023-12-14 10:50:03
|
||||
*/
|
||||
public interface RocketmqRecordService {
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
RocketmqRecord queryById(Integer id);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param rocketmqRecord 筛选条件
|
||||
* @param page 分页对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
IPage<RocketmqRecord> queryByPage(@Param("page") Page page, RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param rocketmqRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
RocketmqRecord insert(RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param rocketmqRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
RocketmqRecord update(RocketmqRecord rocketmqRecord);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteById(Integer id);
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.fuint.business.record.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuint.business.record.entity.RocketmqRecord;
|
||||
import com.fuint.business.record.mapper.RocketmqRecordMapper;
|
||||
import com.fuint.business.record.service.RocketmqRecordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fuint.common.util.TokenUtil;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
import com.fuint.common.dto.AccountInfo;
|
||||
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* (RocketmqRecord)表服务实现类
|
||||
*
|
||||
* @author wangh
|
||||
* @since 2023-12-14 10:50:03
|
||||
*/
|
||||
@Service("rocketmqRecordService")
|
||||
public class RocketmqRecordServiceImpl implements RocketmqRecordService {
|
||||
@Resource
|
||||
private RocketmqRecordMapper rocketmqRecordMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public RocketmqRecord queryById(Integer id) {
|
||||
return this.rocketmqRecordMapper.queryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param rocketmqRecord 筛选条件
|
||||
* @param page 分页对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
@Override
|
||||
public IPage<RocketmqRecord> queryByPage(@Param("page") Page page, RocketmqRecord rocketmqRecord) {
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
rocketmqRecord.setStoreId(nowAccountInfo.getStoreId());
|
||||
return this.rocketmqRecordMapper.queryAllByLimit(page, rocketmqRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param rocketmqRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public RocketmqRecord insert(RocketmqRecord rocketmqRecord) {
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
rocketmqRecord.setStoreId(nowAccountInfo.getStoreId());
|
||||
this.rocketmqRecordMapper.insert(rocketmqRecord);
|
||||
return rocketmqRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param rocketmqRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public RocketmqRecord update(RocketmqRecord rocketmqRecord) {
|
||||
this.rocketmqRecordMapper.update(rocketmqRecord);
|
||||
return this.queryById(rocketmqRecord.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteById(Integer id) {
|
||||
return this.rocketmqRecordMapper.deleteById(id) > 0;
|
||||
}
|
||||
}
|
@ -67,6 +67,8 @@ public interface LJUserMapper extends BaseMapper<LJUser> {
|
||||
|
||||
LJUserVo selectAllInfoById(@Param("userId") Integer userId);
|
||||
|
||||
LJUserVo selectAllInfoById2(@Param("userId") Integer userId,@Param("chainStoreId") Integer chainStoreId);
|
||||
|
||||
|
||||
LJUserVo selectAllInfoById4Chain(@Param("userId") Integer userId, @Param("chainStoreId") Integer chainStoreId);
|
||||
|
||||
|
@ -83,6 +83,19 @@
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectAllInfoById2" resultType="com.fuint.business.userManager.vo.LJUserVo">
|
||||
select mu.*,
|
||||
mub.id balanceId,
|
||||
mub.card_balance cardBalance,
|
||||
mub.points,
|
||||
mub.growth_value growthValue,
|
||||
mub.refuel_money refuelMoney
|
||||
from mt_user mu
|
||||
left join mt_user_balance mub on mu.id = mub.mt_user_id
|
||||
where mu.id = #{userId} and mub.chain_store_id = #{chainStoreId}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectAllInfoById4Chain" resultType="com.fuint.business.userManager.vo.LJUserVo">
|
||||
select mu.*,
|
||||
|
@ -1,2 +1,84 @@
|
||||
package com.fuint.common.config;public class MQConsumerConfiguration {
|
||||
}
|
||||
//package com.fuint.common.config;
|
||||
//
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.boot.SpringBootConfiguration;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Conditional;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//
|
||||
//import com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;
|
||||
//import com.alibaba.rocketmq.client.exception.MQClientException;
|
||||
//import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere;
|
||||
////import com.clouds.common.rocketmq.constants.RocketMQErrorEnum;
|
||||
////import com.clouds.common.rocketmq.exception.RocketMQException;
|
||||
//import org.springframework.boot.SpringBootConfiguration;
|
||||
//
|
||||
//@SpringBootConfiguration
|
||||
//public class MQConsumerConfiguration {
|
||||
//
|
||||
// @Value("${rocketmq.consumer.namesrvAddr}")
|
||||
// private String namesrvAddr;
|
||||
// @Value("${rocketmq.consumer.groupName}")
|
||||
// private String groupName;
|
||||
// @Value("${rocketmq.consumer.consumeThreadMin}")
|
||||
// private int consumeThreadMin;
|
||||
// @Value("${rocketmq.consumer.consumeThreadMax}")
|
||||
// private int consumeThreadMax;
|
||||
// @Value("${rocketmq.consumer.topics}")
|
||||
// private String topics;
|
||||
// @Value("${rocketmq.consumer.consumeMessageBatchMaxSize}")
|
||||
// private int consumeMessageBatchMaxSize;
|
||||
//
|
||||
// @Autowired
|
||||
// private MQConsumeMsgListenerProcessor mqMessageListenerProcessor;
|
||||
//
|
||||
// @Bean
|
||||
// public DefaultMQPushConsumer getRocketMQConsumer() throws RocketMQException {
|
||||
// if (StringUtils.isEmpty(groupName)){
|
||||
// throw new RocketMQException(RocketMQErrorEnum.PARAMM_NULL,"groupName is null !!!",false);
|
||||
// }
|
||||
// if (StringUtils.isEmpty(namesrvAddr)){
|
||||
// throw new RocketMQException(RocketMQErrorEnum.PARAMM_NULL,"namesrvAddr is null !!!",false);
|
||||
// }
|
||||
// if(StringUtils.isEmpty(topics)){
|
||||
// throw new RocketMQException(RocketMQErrorEnum.PARAMM_NULL,"topics is null !!!",false);
|
||||
// }
|
||||
// DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(groupName);
|
||||
// consumer.setNamesrvAddr(namesrvAddr);
|
||||
// consumer.setConsumeThreadMin(consumeThreadMin);
|
||||
// consumer.setConsumeThreadMax(consumeThreadMax);
|
||||
// consumer.registerMessageListener(mqMessageListenerProcessor);
|
||||
// /**
|
||||
// * 设置Consumer第一次启动是从队列头部开始消费还是队列尾部开始消费
|
||||
// * 如果非第一次启动,那么按照上次消费的位置继续消费
|
||||
// */
|
||||
// consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
|
||||
// /**
|
||||
// * 设置消费模型,集群还是广播,默认为集群
|
||||
// */
|
||||
// //consumer.setMessageModel(MessageModel.CLUSTERING);
|
||||
// /**
|
||||
// * 设置一次消费消息的条数,默认为1条
|
||||
// */
|
||||
// consumer.setConsumeMessageBatchMaxSize(consumeMessageBatchMaxSize);
|
||||
// try {
|
||||
// /**
|
||||
// * 设置该消费者订阅的主题和tag,如果是订阅该主题下的所有tag,则tag使用*;如果需要指定订阅该主题下的某些tag,则使用||分割,例如tag1||tag2||tag3
|
||||
// */
|
||||
// String[] topicTagsArr = topics.split(";");
|
||||
// for (String topicTags : topicTagsArr) {
|
||||
// String[] topicTag = topicTags.split("~");
|
||||
// consumer.subscribe(topicTag[0],topicTag[1]);
|
||||
// }
|
||||
// consumer.start();
|
||||
// LOGGER.info("consumer is start !!! groupName:{},topics:{},namesrvAddr:{}",groupName,topics,namesrvAddr);
|
||||
// }catch (MQClientException e){
|
||||
// LOGGER.error("consumer is start !!! groupName:{},topics:{},namesrvAddr:{}",groupName,topics,namesrvAddr,e);
|
||||
// throw new RocketMQException(e);
|
||||
// }
|
||||
// return consumer;
|
||||
// }
|
||||
//}
|
||||
|
@ -1,2 +1,75 @@
|
||||
package com.fuint.common.config;public class MQProducerConfiguration {
|
||||
}
|
||||
//package com.fuint.common.config;
|
||||
//import org.apache.rocketmq.client.exception.MQClientException;
|
||||
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.boot.SpringBootConfiguration;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//
|
||||
////import com.alibaba.rocketmq.client.exception.MQClientException;
|
||||
////import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
|
||||
////import com.clouds.common.rocketmq.constants.RocketMQErrorEnum;
|
||||
////import com.clouds.common.rocketmq.exception.RocketMQException;
|
||||
//
|
||||
//@SpringBootConfiguration
|
||||
//public class MQProducerConfiguration {
|
||||
// /**
|
||||
// * 发送同一类消息的设置为同一个group,保证唯一,默认不需要设置,rocketmq会使用ip@pid(pid代表jvm名字)作为唯一标示
|
||||
// */
|
||||
// @Value("${rocketmq.producer.groupName}")
|
||||
// private String groupName;
|
||||
// @Value("${rocketmq.producer.namesrvAddr}")
|
||||
// private String namesrvAddr;
|
||||
// /**
|
||||
// * 消息最大大小,默认4M
|
||||
// */
|
||||
// @Value("${rocketmq.producer.maxMessageSize}")
|
||||
// private Integer maxMessageSize ;
|
||||
// /**
|
||||
// * 消息发送超时时间,默认3秒
|
||||
// */
|
||||
// @Value("${rocketmq.producer.sendMsgTimeout}")
|
||||
// private Integer sendMsgTimeout;
|
||||
// /**
|
||||
// * 消息发送失败重试次数,默认2次
|
||||
// */
|
||||
// @Value("${rocketmq.producer.retryTimesWhenSendFailed}")
|
||||
// private Integer retryTimesWhenSendFailed;
|
||||
//
|
||||
// @Bean
|
||||
// public DefaultMQProducer getRocketMQProducer() {
|
||||
// if (StringUtils.isEmpty(this.groupName)) {
|
||||
//// throw new RocketMQException(RocketMQErrorEnum.PARAMM_NULL,"groupName is blank",false);
|
||||
// }
|
||||
// if (StringUtils.isEmpty(this.namesrvAddr)) {
|
||||
//// throw new RocketMQException(RocketMQErrorEnum.PARAMM_NULL,"nameServerAddr is blank",false);
|
||||
// }
|
||||
// DefaultMQProducer producer;
|
||||
// producer = new DefaultMQProducer(this.groupName);
|
||||
// producer.setNamesrvAddr(this.namesrvAddr);
|
||||
// //如果需要同一个jvm中不同的producer往不同的mq集群发送消息,需要设置不同的instanceName
|
||||
//// producer.setInstanceName(instanceName);
|
||||
// if(this.maxMessageSize!=null){
|
||||
// producer.setMaxMessageSize(this.maxMessageSize);
|
||||
// }
|
||||
// if(this.sendMsgTimeout!=null){
|
||||
// producer.setSendMsgTimeout(this.sendMsgTimeout);
|
||||
// }
|
||||
// //如果发送消息失败,设置重试次数,默认为2次
|
||||
// if(this.retryTimesWhenSendFailed!=null){
|
||||
// producer.setRetryTimesWhenSendFailed(this.retryTimesWhenSendFailed);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// producer.start();
|
||||
//
|
||||
//// LOGGER.info(String.format("producer is start ! groupName:[%s],namesrvAddr:[%s]"
|
||||
//// , this.groupName, this.namesrvAddr));
|
||||
// } catch (Exception e) {
|
||||
//// LOGGER.error(String.format("producer is error {}"
|
||||
//// , e.getMessage(),e));
|
||||
//// throw new RocketMQException(e);
|
||||
// }
|
||||
// return producer;
|
||||
// }
|
||||
//}
|
||||
|
@ -1,2 +1,50 @@
|
||||
package com.fuint.common.config;public class RedissonConfig {
|
||||
package com.fuint.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* redisson配置
|
||||
* @author wangh
|
||||
*/
|
||||
@Configuration
|
||||
public class RedissonConfig {
|
||||
/**
|
||||
*
|
||||
* 使用方式
|
||||
* @Autowired
|
||||
* private RedisLock redisLock;
|
||||
*redisLock.tryLock(lockKey, 5000, TimeUnit.MILLISECONDS)
|
||||
* // lockKey 锁实例key waitTime 最多等待时间 leaseTime 上锁后自动释放锁时间 unit 时间颗粒度
|
||||
* redisLock.lock(lockKey); // 获取锁
|
||||
* redisLock.tryLock(lockKey, leaseTime); // 尝试获取锁
|
||||
* redisLock.tryLock(lockKey, leaseTime, unit);
|
||||
* redisLock.tryLock(lockKey, waitTime, leaseTime, unit);
|
||||
* redisLock.unlock(lockKey); // 释放锁
|
||||
* redisLock.unlock(lock);
|
||||
*/
|
||||
@Value("${spring.redis.host}")
|
||||
private String host;
|
||||
|
||||
@Value("${spring.redis.port}")
|
||||
private String port;
|
||||
|
||||
@Value("${spring.redis.password}")
|
||||
private String password;
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnMissingBean(RedissonClient.class)
|
||||
public RedissonClient redissonClient()
|
||||
{
|
||||
Config config = new Config();
|
||||
config.useSingleServer().setAddress("redis://" + host + ":" + port); // 更多.set
|
||||
return Redisson.create(config);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,78 @@
|
||||
package com.fuint.common.util;public class DistributedLockUtil {
|
||||
package com.fuint.common.util;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.data.redis.core.script.RedisScript;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class DistributedLockUtil {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
private static final String LOCK_PREFIX = "distributed_lock:";
|
||||
|
||||
public boolean tryLock(String lockKey, String requestId, long expireTime) {
|
||||
try {
|
||||
String key = LOCK_PREFIX + lockKey;
|
||||
RedisScript<Boolean> script = new DefaultRedisScript<>(
|
||||
"local key = KEYS[1]\n" +
|
||||
"local requestId = ARGV[1]\n" +
|
||||
"local expireTime = ARGV[2]\n" +
|
||||
"if redis.call('SETNX', key, requestId) == 1 then\n" +
|
||||
" redis.call('PEXPIRE', key, expireTime)\n" +
|
||||
" return true\n" +
|
||||
"elseif redis.call('PTTL', key) == -1 then\n" +
|
||||
" redis.call('PEXPIRE', key, expireTime)\n" +
|
||||
" return true\n" +
|
||||
"else\n" +
|
||||
" return false\n" +
|
||||
"end",
|
||||
Boolean.class
|
||||
);
|
||||
return redisTemplate.execute(
|
||||
script,
|
||||
Collections.singletonList(key),
|
||||
requestId,
|
||||
String.valueOf(expireTime)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean releaseLock(String lockKey, String requestId) {
|
||||
try {
|
||||
String key = LOCK_PREFIX + lockKey;
|
||||
RedisScript<Boolean> script = new DefaultRedisScript<>(
|
||||
"local key = KEYS[1]\n" +
|
||||
"local requestId = ARGV[1]\n" +
|
||||
"if redis.call('GET', key) == requestId then\n" +
|
||||
" return redis.call('DEL', key)\n" +
|
||||
"else\n" +
|
||||
" return false\n" +
|
||||
"end",
|
||||
Boolean.class
|
||||
);
|
||||
return redisTemplate.execute(
|
||||
script,
|
||||
Collections.singletonList(key),
|
||||
requestId
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,115 @@
|
||||
package com.fuint.common.util;public class RedisLock {
|
||||
package com.fuint.common.util;
|
||||
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* redis锁工具
|
||||
*
|
||||
* @author wangh
|
||||
*/
|
||||
@Component
|
||||
public class RedisLock {
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
/**
|
||||
* 获取锁
|
||||
*
|
||||
* @param lockKey 锁实例key
|
||||
* @return 锁信息
|
||||
*/
|
||||
public RLock getRLock(String lockKey)
|
||||
{
|
||||
return redissonClient.getLock(lockKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加锁
|
||||
*
|
||||
* @param lockKey 锁实例key
|
||||
* @return 锁信息
|
||||
*/
|
||||
public RLock lock(String lockKey)
|
||||
{
|
||||
RLock lock = getRLock(lockKey);
|
||||
lock.lock();
|
||||
return lock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加锁
|
||||
*
|
||||
* @param lockKey 锁实例key
|
||||
* @param leaseTime 上锁后自动释放锁时间
|
||||
* @return true=成功;false=失败
|
||||
*/
|
||||
public Boolean tryLock(String lockKey, long leaseTime)
|
||||
{
|
||||
return tryLock(lockKey, 0, leaseTime, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加锁
|
||||
*
|
||||
* @param lockKey 锁实例key
|
||||
* @param leaseTime 上锁后自动释放锁时间
|
||||
* @param unit 时间颗粒度
|
||||
* @return true=加锁成功;false=加锁失败
|
||||
*/
|
||||
public Boolean tryLock(String lockKey, long leaseTime, TimeUnit unit)
|
||||
{
|
||||
return tryLock(lockKey, 0, leaseTime, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加锁
|
||||
*
|
||||
* @param lockKey 锁实例key
|
||||
* @param waitTime 最多等待时间
|
||||
* @param leaseTime 上锁后自动释放锁时间
|
||||
* @param unit 时间颗粒度
|
||||
* @return true=加锁成功;false=加锁失败
|
||||
*/
|
||||
public Boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit)
|
||||
{
|
||||
RLock rLock = getRLock(lockKey);
|
||||
boolean tryLock = false;
|
||||
try
|
||||
{
|
||||
tryLock = rLock.tryLock(waitTime, leaseTime, unit);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return tryLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放锁
|
||||
*
|
||||
* @param lockKey 锁实例key
|
||||
*/
|
||||
public void unlock(String lockKey)
|
||||
{
|
||||
RLock lock = getRLock(lockKey);
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放锁
|
||||
*
|
||||
* @param lock 锁信息
|
||||
*/
|
||||
public void unlock(RLock lock)
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.ruoyi.rocket.utils;
|
||||
package com.fuint.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -9,17 +9,17 @@ import org.apache.rocketmq.client.producer.SendResult;
|
||||
* rocketmq异步回调监听
|
||||
*/
|
||||
@Slf4j
|
||||
public class SendCallbackListener implements SendCallback {
|
||||
public class RocketSendCallbackListener implements SendCallback {
|
||||
|
||||
private int id;
|
||||
|
||||
public SendCallbackListener(int id) {
|
||||
public RocketSendCallbackListener(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(SendResult sendResult) {
|
||||
log.info("CallBackListener on success11111111 : " + JSONObject.toJSONString(sendResult));
|
||||
log.info("CallBackListener on success : " + JSONObject.toJSONString(sendResult));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,2 +1,99 @@
|
||||
package com.fuint.common.util;public class RocketUtil {
|
||||
package com.fuint.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fuint.business.record.entity.RocketmqRecord;
|
||||
import com.fuint.business.record.service.RocketmqRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.client.producer.SendStatus;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.apache.rocketmq.spring.support.RocketMQHeaders;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* rocketmq请求发送
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RocketUtil {
|
||||
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
@Resource
|
||||
RocketmqRecordService rocketmqRecordService;
|
||||
|
||||
@Value(value = "${rocketmq.producer.topic}")
|
||||
private String syncTag;
|
||||
|
||||
|
||||
/**
|
||||
* rocketmq 同步消息
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean pushMessage(Map<String, Object> msg) {
|
||||
// 记录发送信息
|
||||
sendRecord(msg);
|
||||
log.info("pushMessage start : " + msg.toString());
|
||||
// 构建消息
|
||||
String msgJson = JSONObject.toJSONString(msg);
|
||||
|
||||
String messageStr = msgJson;
|
||||
Message<String> message = MessageBuilder.withPayload(messageStr)
|
||||
.setHeader(RocketMQHeaders.KEYS, msgJson)
|
||||
.build();
|
||||
// 设置发送地和消息信息并发送同步消息
|
||||
SendResult sendResult = rocketMQTemplate.syncSend(syncTag+":"+msg.get("tag"), message);
|
||||
log.info("pushMessage finish : " + msgJson + ", sendResult : " + JSONObject.toJSONString(sendResult));
|
||||
|
||||
// 解析发送结果
|
||||
if (sendResult.getSendStatus() == SendStatus.SEND_OK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 发送异步消息
|
||||
*
|
||||
* @param id 消息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean pushAsyncMessage(String tag, int id) {
|
||||
log.info("pushAsyncMessage start : " + id);
|
||||
// 构建消息
|
||||
String messageStr = "order id : " + id;
|
||||
Message<String> message = MessageBuilder.withPayload(messageStr)
|
||||
.setHeader(RocketMQHeaders.KEYS, id)
|
||||
.build();
|
||||
// 设置发送地和消息信息并发送异步消息
|
||||
rocketMQTemplate.asyncSend(tag, message, new RocketSendCallbackListener(id));
|
||||
log.info("pushAsyncMessage finish : " + id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录消息发送
|
||||
*/
|
||||
public void sendRecord(Map<String, Object> msg) {
|
||||
RocketmqRecord rocketmqRecord = new RocketmqRecord();
|
||||
rocketmqRecord.setOrderId(Integer.parseInt(msg.get("orderId").toString()));
|
||||
rocketmqRecord.setStoreId(Integer.parseInt(msg.get("storeId").toString()));
|
||||
rocketmqRecord.setChainStoreId(Integer.parseInt(msg.get("chainStoreId").toString()));
|
||||
rocketmqRecord.setOrderType(msg.get("tag").toString());
|
||||
rocketmqRecordService.insert(rocketmqRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user