Commit 4b03d2c8 authored by liwei's avatar liwei

修改了互换微信相关接口

parent 61ed9e64
...@@ -195,7 +195,12 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> { ...@@ -195,7 +195,12 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
int addWeChatTask(@Param("entity") MemUserTaskDTO memUserTaskDTO); int addWeChatTask(@Param("entity") MemUserTaskDTO memUserTaskDTO);
/** /**
* 修改索要微信任务 * 根据id修改索要微信任务
*/
int updateWeChatTaskById(@Param("entity") MemUserTaskDTO memUserTaskDTO);
/**
* 根据id修改索要微信任务
*/ */
int updateWeChatTask(@Param("entity") MemUserTaskDTO memUserTaskDTO); int updateWeChatTask(@Param("entity") MemUserTaskDTO memUserTaskDTO);
......
...@@ -51,4 +51,9 @@ public class MemUserTaskDTO { ...@@ -51,4 +51,9 @@ public class MemUserTaskDTO {
* 目标用户的memWxCode * 目标用户的memWxCode
*/ */
private String memWxCode; private String memWxCode;
/**
* 再次发起请求 1:被拒绝后再次发送请求 0:不是再次发送
*/
private String againRequest;
} }
...@@ -840,7 +840,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -840,7 +840,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
DictData dictData2 = userLikeConfig.stream().filter(item -> item.getDictLabel().equals("accept_exchange_wechat")).findFirst().orElse(null); DictData dictData2 = userLikeConfig.stream().filter(item -> item.getDictLabel().equals("accept_exchange_wechat")).findFirst().orElse(null);
Integer requestGoldCoinCount = Integer.valueOf(dictData1.getDictValue());//发起请求需消耗的金币数 Integer requestGoldCoinCount = Integer.valueOf(dictData1.getDictValue());//发起请求需消耗的金币数
Integer acceptGoldCoinCount = Integer.valueOf(dictData2.getDictValue());//接收需消耗的金币数 Integer acceptGoldCoinCount = Integer.valueOf(dictData2.getDictValue());//接收需消耗的金币数
if (memUserTaskDTO.getType().equals("1")){ if (memUserTaskDTO.getType().equals("1") && memUserTaskDTO.getAgainRequest().equals("0")){
//发起请求 //发起请求
//扣除该用户的金币数量 //扣除该用户的金币数量
int line = 0; int line = 0;
...@@ -877,7 +877,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -877,7 +877,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
throw new CyServiceException(1004,"服务器繁忙,请稍后再试"); throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} }
return new CyPersistModel(line); return new CyPersistModel(line);
} else { } else if (memUserTaskDTO.getType().equals("2") && memUserTaskDTO.getAgainRequest().equals("0")){
MemUserTaskDTO memUserTaskDTO1 = baseMapper.selectWeChatTask(memUserTaskDTO); MemUserTaskDTO memUserTaskDTO1 = baseMapper.selectWeChatTask(memUserTaskDTO);
memUserTaskDTO.setBusinessId(memUserTaskDTO1.getBusinessId()); memUserTaskDTO.setBusinessId(memUserTaskDTO1.getBusinessId());
//接收请求 //接收请求
...@@ -897,7 +897,9 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -897,7 +897,9 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
throw new CyServiceException(1003,"金币不足,请先充值!"); throw new CyServiceException(1003,"金币不足,请先充值!");
} }
//修改微信任务 //修改微信任务
line = baseMapper.updateWeChatTask(memUserTaskDTO); memUserTaskDTO.setCreateBy(targetId);
memUserTaskDTO.setTargetId(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
line = baseMapper.updateWeChatTaskById(memUserTaskDTO);
//添加金币流水记录 //添加金币流水记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow(); MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setUpdateBy(String.valueOf(createBy)); memGoldCoinFlow.setUpdateBy(String.valueOf(createBy));
...@@ -921,7 +923,46 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -921,7 +923,46 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
} else { } else {
//拒绝 //拒绝
//修改微信任务 //修改微信任务
line = baseMapper.updateWeChatTask(memUserTaskDTO); memUserTaskDTO.setCreateBy(targetId);
memUserTaskDTO.setTargetId(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
line = baseMapper.updateWeChatTaskById(memUserTaskDTO);
}
return new CyPersistModel(line);
} else {
//被拒绝后 再次发送请求
//扣除该用户的金币数量 修改原始的微信任务状态为1 0
int line = 0;
boolean isGetLock = false;
RLock lock = redissonClient.getLock(MemberInfoRedisBean.USER_WECHAT_TASK_LOCK + memUserTaskDTO.getCreateBy());
try {
isGetLock = lock.tryLock(Long.parseLong(MemberInfoRedisBean.USER_WECHAT_TASK_LOCK_WAIT_TIME),
Long.parseLong(MemberInfoRedisBean.USER_WECHAT_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
//查询用户信息
if (memInfo.getGoldCoinsCount() - acceptGoldCoinCount < 0){
throw new CyServiceException(1003,"金币不足,请先充值!");
}
memUserTaskDTO.setType("1");
memUserTaskDTO.setStatus("0");
line = baseMapper.updateWeChatTask(memUserTaskDTO);
//增加金币流水记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setUpdateBy(String.valueOf(createBy));
memGoldCoinFlow.setCount(acceptGoldCoinCount);
memGoldCoinFlow.setEndCount(memInfo.getGoldCoinsCount() - acceptGoldCoinCount);
memGoldCoinFlow.setType("2");
memGoldCoinFlow.setActionType("23");
memGoldCoinFlowRepository.insert(memGoldCoinFlow);
//修改用户金币数量
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - acceptGoldCoinCount);
memInfoRepository.updateById(memInfo);
lock.unlock();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
lock.unlock();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} }
return new CyPersistModel(line); return new CyPersistModel(line);
} }
......
...@@ -53,8 +53,17 @@ ...@@ -53,8 +53,17 @@
<result column="remarks" jdbcType="VARCHAR" property="remarks"/> <result column="remarks" jdbcType="VARCHAR" property="remarks"/>
<result column="avatarUrl" jdbcType="VARCHAR" property="avatarUrl"/> <result column="avatarUrl" jdbcType="VARCHAR" property="avatarUrl"/>
</resultMap> </resultMap>
<update id="updateWeChatTask">
update mem_user_task
set create_date = #{entity.createDate},
type = #{entity.type},
status = #{entity.status}
where 1=1
and create_by = #{entity.createBy}
and target_id = #{entity.targetId}
</update>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
<select id="queryMemInfos" resultMap="BaseResultMap"> <select id="queryMemInfos" resultMap="BaseResultMap">
select * from mem_info select * from mem_info
where 1=1 where 1=1
...@@ -767,7 +776,7 @@ ...@@ -767,7 +776,7 @@
insert into mem_user_task (create_by,create_date,type,status,target_id) insert into mem_user_task (create_by,create_date,type,status,target_id)
values(#{entity.createBy},#{entity.createDate},#{entity.type},#{entity.status},#{entity.targetId}) values(#{entity.createBy},#{entity.createDate},#{entity.type},#{entity.status},#{entity.targetId})
</insert> </insert>
<insert id="updateWeChatTask"> <insert id="updateWeChatTaskById">
update mem_user_task update mem_user_task
set create_by = #{entity.createBy}, set create_by = #{entity.createBy},
create_date = #{entity.createDate}, create_date = #{entity.createDate},
...@@ -810,7 +819,7 @@ ...@@ -810,7 +819,7 @@
select * select *
from mem_user_task from mem_user_task
where 1=1 where 1=1
and (create_by = #{createBy} and target_id = #{targetId}) OR (create_by = #{targetId} and target_id = #{createBy}) and ((create_by = #{createBy} and target_id = #{targetId}) OR (create_by = #{targetId} and target_id = #{createBy}))
and status = '0' and status = '0'
) table1 ) table1
where 1=1 where 1=1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment