Commit fb4c35c1 authored by 罗林杰's avatar 罗林杰

Merge remote-tracking branch 'origin/master'

parents 49c5e112 a4c6027b
...@@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import java.math.BigInteger;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -270,6 +271,11 @@ public class FaceVerifyServiceImpl extends ServiceImpl<MemInfoRepository, MemInf ...@@ -270,6 +271,11 @@ public class FaceVerifyServiceImpl extends ServiceImpl<MemInfoRepository, MemInf
Integer coinCount = Integer.valueOf(dictData.getDictValue()); Integer coinCount = Integer.valueOf(dictData.getDictValue());
memInfo.setMemRealAuthen("1"); memInfo.setMemRealAuthen("1");
memInfo.setMemRealAuthenDate(new Date()); memInfo.setMemRealAuthenDate(new Date());
//截取idCard身份证号 获取出生年月日20021029 变成2002-10-29
String birth = idCard.substring(6, 14);
String birthDate = birth.substring(0, 4) + "-" + birth.substring(4, 6) + "-" + birth.substring(6);
memInfo.setMemBirthday(birthDate);
memInfo.setMemConstellation(getConstellation(birthDate));
memInfo.setMemIdcard(CyAESUtils.encrypt(idCard)); memInfo.setMemIdcard(CyAESUtils.encrypt(idCard));
memInfo.setMemRealName(CyAESUtils.encrypt(realName)); memInfo.setMemRealName(CyAESUtils.encrypt(realName));
memInfo.setGoldCoinsCount(coinCount); memInfo.setGoldCoinsCount(coinCount);
...@@ -280,12 +286,13 @@ public class FaceVerifyServiceImpl extends ServiceImpl<MemInfoRepository, MemInf ...@@ -280,12 +286,13 @@ public class FaceVerifyServiceImpl extends ServiceImpl<MemInfoRepository, MemInf
sysUserRbacRepository.updateById(userRbac); sysUserRbacRepository.updateById(userRbac);
//增加金币流水记录 //增加金币流水记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow(); MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setCreateBy(userId); memGoldCoinFlow.setCreateBy(String.valueOf(1));
memGoldCoinFlow.setUpdateBy(userId); memGoldCoinFlow.setUpdateBy(String.valueOf(1));
memGoldCoinFlow.setCount(coinCount); memGoldCoinFlow.setCount(coinCount);
memGoldCoinFlow.setEndCount(coinCount); memGoldCoinFlow.setEndCount(coinCount);
memGoldCoinFlow.setType("1"); memGoldCoinFlow.setType("1");
memGoldCoinFlow.setActionType("12"); memGoldCoinFlow.setActionType("12");
memGoldCoinFlow.setTargetId(BigInteger.valueOf(Integer.valueOf(userId)));
memGoldCoinFlowRepository.insert(memGoldCoinFlow); memGoldCoinFlowRepository.insert(memGoldCoinFlow);
} else { } else {
HttpServletRequest request1 = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())).getRequest(); HttpServletRequest request1 = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())).getRequest();
...@@ -461,4 +468,36 @@ public class FaceVerifyServiceImpl extends ServiceImpl<MemInfoRepository, MemInf ...@@ -461,4 +468,36 @@ public class FaceVerifyServiceImpl extends ServiceImpl<MemInfoRepository, MemInf
} }
} }
} }
public static String getConstellation(String birth) {
int month = Integer.parseInt(birth.substring(5, 7));
int day = Integer.parseInt(birth.substring(8, 10));
if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) {
return "3";//白羊座
} else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
return "4";//金牛座
} else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) {
return "5";//双子座
} else if ((month == 6 && day >= 22) || (month == 7 && day <= 22)) {
return "6";//巨蟹座
} else if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) {
return "7";//狮子座
} else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
return "8";//处女座
} else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) {
return "9";//天秤座
} else if ((month == 10 && day >= 24) || (month == 11 && day <= 22)) {
return "10";//天蝎座
} else if ((month == 11 && day >= 23) || (month == 12 && day <= 21)) {
return "11";//射手座
} else if ((month == 12 && day >= 22) || (month == 1 && day <= 19)) {
return "12";//摩羯座
} else if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
return "1";//水瓶座
} else {
// 默认返回双鱼座
return "2";//双鱼座
}
}
} }
...@@ -3,46 +3,23 @@ package org.rcisoft.app.appOrder.controller; ...@@ -3,46 +3,23 @@ package org.rcisoft.app.appOrder.controller;
/*固定导入*/ /*固定导入*/
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifIFD0Directory;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import org.jdom.JDOMException;
import org.rcisoft.business.cmsOrder.entity.CmsOrder; import org.rcisoft.business.cmsOrder.entity.CmsOrder;
import org.rcisoft.business.cmsOrder.service.CmsOrderService; import org.rcisoft.business.cmsOrder.service.CmsOrderService;
import org.rcisoft.business.memInfo.entity.MemInfo;
import org.rcisoft.business.memInfo.service.MemInfoService;
import org.rcisoft.core.anno.CyEncryptSm4Anno;
import org.rcisoft.core.anno.CyOpeLogAnno; import org.rcisoft.core.anno.CyOpeLogAnno;
import org.rcisoft.core.component.CyGlobal;
import org.rcisoft.core.constant.CyMessCons; import org.rcisoft.core.constant.CyMessCons;
import org.rcisoft.core.controller.CyPaginationController; import org.rcisoft.core.controller.CyPaginationController;
import org.rcisoft.core.exception.CyServiceException;
import org.rcisoft.core.model.CyGridModel; import org.rcisoft.core.model.CyGridModel;
import org.rcisoft.core.model.CyPersistModel; import org.rcisoft.core.model.CyPersistModel;
import org.rcisoft.core.operlog.enums.CyLogTypeEnum; import org.rcisoft.core.operlog.enums.CyLogTypeEnum;
import org.rcisoft.core.result.CyResult; import org.rcisoft.core.result.CyResult;
import org.rcisoft.core.result.enums.CyResSysExcEnum;
import org.rcisoft.core.service.CyFileStorageService;
import org.rcisoft.core.util.CyResultGenUtil; import org.rcisoft.core.util.CyResultGenUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.validation.Valid; import javax.validation.Valid;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
/** /**
* Created by cy on 2024年12月20日 下午3:35:34. * Created by cy on 2024年12月20日 下午3:35:34.
......
...@@ -182,6 +182,8 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -182,6 +182,8 @@ public class WxMiniServiceImpl implements WxMiniService {
sysUser.setWxNickName(nickName); sysUser.setWxNickName(nickName);
sysUser.setWxAddress(address); sysUser.setWxAddress(address);
sysUserRbacRepository.updateUserWxByPhone(sysUser); sysUserRbacRepository.updateUserWxByPhone(sysUser);
//修改会员表信息
memInfoRepository.updateMemSexByPhone(sysUser);
//重新生成token //重新生成token
List<SysUserRbac> users = sysUserRbacRepository.selectByPhone(phone); List<SysUserRbac> users = sysUserRbacRepository.selectByPhone(phone);
if (CollectionUtils.isNotEmpty(users)) { if (CollectionUtils.isNotEmpty(users)) {
......
package org.rcisoft.business.ScheduledTask.Controller;
/*固定导入*/
import io.swagger.v3.oas.annotations.Operation;
import org.rcisoft.business.ScheduledTask.entity.ScheduledTask;
import org.rcisoft.business.ScheduledTask.service.ScheduledTaskService;
import org.rcisoft.core.anno.CyOpeLogAnno;
import org.rcisoft.core.constant.CyMessCons;
import org.rcisoft.core.model.CyPersistModel;
import org.rcisoft.core.operlog.enums.CyLogTypeEnum;
import org.rcisoft.core.result.CyResult;
import org.rcisoft.core.util.CyResultGenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by cy on 2025年1月6日 下午1:44:44.
*/
@RestController
@RequestMapping("/scheduledTask")
public class ScheduledTaskController{
@Autowired
private ScheduledTaskService scheduledTaskServiceImpl;
@PreAuthorize("@cyPerm.hasPerm('sys:scheduledTask:list')")
@CyOpeLogAnno(title = "system-定时任务管理-查询定时任务", businessType = CyLogTypeEnum.QUERY)
@Operation(summary="查询所有定时任务列表", description="查询所有定时任务列表")
@GetMapping(value = "/scheduledTaskList")
public CyResult scheduledTaskList(ScheduledTask scheduledTask) {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
scheduledTaskServiceImpl.scheduledTaskList(scheduledTask));
}
@PreAuthorize("@cyPerm.hasPerm('sys:scheduledTask:list')")
@CyOpeLogAnno(title = "system-定时任务管理-手动执行定时任务", businessType = CyLogTypeEnum.QUERY)
@Operation(summary="手动执行定时任务", description="手动执行定时任务")
@GetMapping(value = "/executeScheduledTask/{type:\\w+}")
public CyResult executeScheduledTask(@PathVariable String type) {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
scheduledTaskServiceImpl.executeScheduledTask(type));
}
}
package org.rcisoft.business.ScheduledTask.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.rcisoft.core.entity.CyIdNotDataEntity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* Created with cy on 2025年2月20日 上午11:14:19.
*/
@Data
public class ScheduledTask{
/**
* @desc 任务名称
* @column task_name
* @default
*/
private String taskName;
/**
* @desc 执行时间
* @column task_time
* @default
*/
private String taskTime;
/**
* redis定时任务
* 1:订单落库
* 2:订单关闭
* 3:支付确认补救
* 4:退款接口调用补救
* 5:退款确认补救
* 6:订单缓存清除
* 7:定时更新访问量表
* 8:定时更新话题表 刷新话题表的动态数
* 9:定时更新会员表 刷新会员的被关注数和被点赞数
*/
private String type;
}
package org.rcisoft.business.ScheduledTask.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.rcisoft.business.ScheduledTask.entity.ScheduledTask;
import org.rcisoft.business.sysScheduledTaskLog.entity.SysScheduledTaskLog;
import org.rcisoft.core.model.CyPageInfo;
import org.rcisoft.core.model.CyPersistModel;
import java.util.List;
/**
* Created by cy on 2025年2月20日 上午11:14:19.
*/
public interface ScheduledTaskService {
List<ScheduledTask> scheduledTaskList(ScheduledTask ScheduledTask);
CyPersistModel executeScheduledTask(String type);
}
package org.rcisoft.business.ScheduledTask.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.ScheduledTask.entity.ScheduledTask;
import org.rcisoft.business.ScheduledTask.service.ScheduledTaskService;
import org.rcisoft.business.cmsOrder.service.impl.CmsOrderServiceImpl;
import org.rcisoft.business.memInfo.service.impl.MemInfoServiceImpl;
import org.rcisoft.business.memLeaveMessage.service.impl.MemLeaveMessageServiceImpl;
import org.rcisoft.business.memTraffic.service.impl.MemTrafficServiceImpl;
import org.rcisoft.business.opmTopic.service.impl.OpmTopicServiceImpl;
import org.rcisoft.core.model.CyPersistModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* Created by cy on 2025年2月20日 上午11:14:19.
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.NOT_SUPPORTED)
@Slf4j
public class ScheduledTaskServiceImpl implements ScheduledTaskService {
@Autowired
private MemInfoServiceImpl memInfoService;
@Autowired
private CmsOrderServiceImpl orderService;
@Autowired
private MemLeaveMessageServiceImpl memLeaveMessageService;
@Autowired
private MemTrafficServiceImpl memTrafficService;
@Autowired
private OpmTopicServiceImpl opmTopicServiceImpl;
@Override
public List<ScheduledTask> scheduledTaskList(ScheduledTask ScheduledTask) {
List<ScheduledTask> scheduledTaskList = new ArrayList<>();
//1、订单落库定时任务 type:1
ScheduledTask task1 = new ScheduledTask();
task1.setTaskName("订单落库定时任务");
task1.setTaskTime("每1分钟执行一次");
task1.setType("1");
//2、订单落库定时任务 type:1
ScheduledTask task2 = new ScheduledTask();
task2.setTaskName("订单关闭定时任务");
task2.setTaskTime("每1分钟执行一次");
task2.setType("2");
//3、订单落库定时任务 type:1
ScheduledTask task3 = new ScheduledTask();
task3.setTaskName("支付确认补救定时任务");
task3.setTaskTime("每15分钟执行一次");
task3.setType("3");
//4、订单落库定时任务 type:1
ScheduledTask task4 = new ScheduledTask();
task4.setTaskName("退款接口调用补救定时任务");
task4.setTaskTime("每30分钟执行一次");
task4.setType("4");
//5、订单落库定时任务 type:1
ScheduledTask task5 = new ScheduledTask();
task5.setTaskName("退款确认补救定时任务");
task5.setTaskTime("每30分钟执行一次");
task5.setType("5");
//6、订单落库定时任务 type:1
ScheduledTask task6 = new ScheduledTask();
task6.setTaskName("订单缓存清除定时任务");
task6.setTaskTime("每天1点执行一次");
task6.setType("6");
//7、订单落库定时任务 type:1
ScheduledTask task7 = new ScheduledTask();
task7.setTaskName("定时更新访问量表定时任务");
task7.setTaskTime("每15分钟执行一次");
task7.setType("7");
//8、订单落库定时任务 type:1
ScheduledTask task8 = new ScheduledTask();
task8.setTaskName("定时更新话题表定时任务");
task8.setTaskTime("每2小时执行一次");
task8.setType("8");
//9、订单落库定时任务 type:1
ScheduledTask task9 = new ScheduledTask();
task9.setTaskName("定时更新会员表定时任务");
task9.setTaskTime("每2小时执行一次");
task9.setType("9");
scheduledTaskList.add(task1);
scheduledTaskList.add(task2);
scheduledTaskList.add(task3);
scheduledTaskList.add(task4);
scheduledTaskList.add(task5);
scheduledTaskList.add(task6);
scheduledTaskList.add(task7);
scheduledTaskList.add(task8);
scheduledTaskList.add(task9);
return scheduledTaskList;
}
@Override
public CyPersistModel executeScheduledTask(String type) {
int line = 0;
if (type.equals("1")){
try{
orderService.executeInsertOrder();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("2")){
try{
orderService.executeCloseOrder();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("3")){
try{
orderService.executePayOrder();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("4")){
try{
orderService.executeRefundOrder();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("5")){
try{
orderService.executeRefundConfirmOrder();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("6")){
try{
orderService.executeDeleteOrder();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("7")){
try{
memTrafficService.memTrafficSchedule();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("8")){
try{
opmTopicServiceImpl.opmTopicSchedule();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
} else if (type.equals("9")){
try{
memInfoService.refreshMemLikeAndFollowCountSchedule();
line = 1;
} catch (Exception e){
log.error(e.getMessage());
}
}
return new CyPersistModel(1);
}
}
...@@ -246,8 +246,13 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> { ...@@ -246,8 +246,13 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
String getUserIsStop(String userId); String getUserIsStop(String userId);
/** /**
* 根据手机号修改用户信息 * 根据手机号修改会员openid
*/ */
int updateMemWxByPhone(SysUserRbac var1); int updateMemWxByPhone(SysUserRbac var1);
/**
* 根据手机号修改会员性别
*/
int updateMemSexByPhone(SysUserRbac var1);
} }
...@@ -13,6 +13,7 @@ import org.rcisoft.business.memInfo.bean.MemberInfoRedisBean; ...@@ -13,6 +13,7 @@ import org.rcisoft.business.memInfo.bean.MemberInfoRedisBean;
import org.rcisoft.business.memInfo.entity.*; import org.rcisoft.business.memInfo.entity.*;
import org.rcisoft.business.memLeaveMessage.bean.MemLeaveMessageRedisBean; import org.rcisoft.business.memLeaveMessage.bean.MemLeaveMessageRedisBean;
import org.rcisoft.business.memLeaveMessage.entity.MemLeaveMessage; import org.rcisoft.business.memLeaveMessage.entity.MemLeaveMessage;
import org.rcisoft.business.opmArticle.entity.LikeDTO;
import org.rcisoft.business.sysScheduledTaskLog.entity.SysScheduledTaskLog; import org.rcisoft.business.sysScheduledTaskLog.entity.SysScheduledTaskLog;
import org.rcisoft.business.sysScheduledTaskLog.service.SysScheduledTaskLogService; import org.rcisoft.business.sysScheduledTaskLog.service.SysScheduledTaskLogService;
import org.rcisoft.core.constant.CyDelStaCons; import org.rcisoft.core.constant.CyDelStaCons;
...@@ -700,12 +701,12 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -700,12 +701,12 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
Integer userLikeLimitCount = Integer.valueOf(dictData1.getDictValue());//给每个人最多免费点赞次数限制 Integer userLikeLimitCount = Integer.valueOf(dictData1.getDictValue());//给每个人最多免费点赞次数限制
Integer payUserLikeLimitCount = Integer.valueOf(dictData2.getDictValue());//付费的点赞次数限制 Integer payUserLikeLimitCount = Integer.valueOf(dictData2.getDictValue());//付费的点赞次数限制
Integer personalAllCount = userLikeLimitCount + payUserLikeLimitCount;//(个人)免费+付费 次数限制 Integer personalAllCount = userLikeLimitCount + payUserLikeLimitCount;//(个人)免费+付费 次数限制
Integer allCount = Integer.valueOf(dictData3.getDictValue());//(所有人)总共点赞次数限制 Integer allCount = Integer.valueOf(dictData3.getDictValue());//(所有人)总共点赞次数限制(免费)
//获取redis中已存储的限制次数 //获取redis中已存储的限制次数
Object redisUserLikeCount = cyRedisServiceImpl.hget(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId())); Object redisUserLikeCount = cyRedisServiceImpl.hget(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()));
Object redisUserLikeCountAll = cyRedisServiceImpl.get(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId); Object redisUserLikeCountAll = cyRedisServiceImpl.get(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId);
//1.进行总数对比 //1.进行免费总数对比
if (redisUserLikeCountAll != null && (int)redisUserLikeCountAll <= allCount){ if (redisUserLikeCountAll != null && (int)redisUserLikeCountAll < allCount){
//没超出总次数限制 //没超出总次数限制
//2.进行判断对目标用户的点赞总次数 //2.进行判断对目标用户的点赞总次数
if (redisUserLikeCount != null && (int)redisUserLikeCount < personalAllCount){ if (redisUserLikeCount != null && (int)redisUserLikeCount < personalAllCount){
...@@ -716,43 +717,14 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -716,43 +717,14 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
//4.判断用户是否选择付费点赞 //4.判断用户是否选择付费点赞
if (likeDTO.getIsPay().equals("1")){ if (likeDTO.getIsPay().equals("1")){
//付费点赞 //付费点赞
//加redis锁 //扣除金币和增加消费记录
boolean isGetLock = false; consumeGlodCoinForLike(userLikeConfig,userId,likeDTO);
RLock lock = redissonClient.getLock(MemberInfoRedisBean.USER_LIKE_LOCK + userId);
try {
isGetLock = lock.tryLock(Long.parseLong(MemberInfoRedisBean.USER_LIKE_LOCK_WAIT_TIME),
Long.parseLong(MemberInfoRedisBean.USER_LIKE_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
//扣除该用户的金币数量
DictData dictData4 = userLikeConfig.stream().filter(item -> item.getDictLabel().equals("pay_count")).findFirst().orElse(null);
Integer payCount = Integer.valueOf(dictData4.getDictValue());
MemInfo memInfo = memInfoRepository.selectByOpenId(likeDTO.getWxOpenid());
if (memInfo.getGoldCoinsCount() - payCount < 0){
throw new CyServiceException(1003,"金币不足,请先充值");
}
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
//添加消费记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setType("2");
memGoldCoinFlow.setActionType("20");
memGoldCoinFlow.setCount(payCount);
memGoldCoinFlow.setEndCount(memInfo.getGoldCoinsCount());
memGoldCoinFlow.setTargetId(BigInteger.valueOf(likeDTO.getTargetId()));
memGoldCoinFlowRepository.insert(memGoldCoinFlow);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} finally {
lock.unlock();
log.error("释放成功");
}
} else { } else {
//已超出今日对目标用户的点赞限制 //已超出今日对目标用户的点赞限制
throw new CyServiceException(1001,"今日对该用户点赞次数已达上限,请明日再试!"); throw new CyServiceException(1001,"今日对该用户点赞次数已达上限,请明日再试!");
} }
} else {
this.redisTemplate.opsForValue().increment(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId, (long) 1L);
} }
//当天 点赞表对应的记录+1 //当天 点赞表对应的记录+1
// 获取今天的最小时间(00:00:00) // 获取今天的最小时间(00:00:00)
...@@ -770,10 +742,9 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -770,10 +742,9 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
memInfoRepository.addLikeCount(likeDTO); memInfoRepository.addLikeCount(likeDTO);
//没超出免费点赞次数 //没超出免费点赞次数
this.redisTemplate.opsForHash().increment(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), (double) 1L); this.redisTemplate.opsForHash().increment(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), (double) 1L);
this.redisTemplate.opsForValue().increment(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId, (long) 1L);
return new CyPersistModel(1); return new CyPersistModel(1);
} else if (redisUserLikeCount == null){ } else if (redisUserLikeCount == null){
//今日第一次对该用户进行点赞 //今日第一次对该用户进行点赞 并且没超出总免费次数
cyRedisServiceImpl.hset(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), 1L); cyRedisServiceImpl.hset(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId, (long) 1L); this.redisTemplate.opsForValue().increment(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId, (long) 1L);
cyRedisServiceImpl.expire(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, 48 * 60 * 60); // 24小时 cyRedisServiceImpl.expire(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, 48 * 60 * 60); // 24小时
...@@ -797,11 +768,99 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -797,11 +768,99 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
memInfoRepository.addLike(likeDTO); memInfoRepository.addLike(likeDTO);
return new CyPersistModel(1); return new CyPersistModel(1);
} else { } else {
//超出总次数限制 //超出免费总次数限制
throw new CyServiceException(1002,"今日点赞次数已达上限,请明日再试!"); //判断对该用户是否超出今日最大点赞数
if (redisUserLikeCount != null && (int)redisUserLikeCount < personalAllCount){
//没超出 付金币
if (likeDTO.getIsPay().equals("1")){
//付费点赞
//扣除金币和增加消费记录
consumeGlodCoinForLike(userLikeConfig,userId,likeDTO);
//当天 点赞表对应的记录+1
// 获取今天的最小时间(00:00:00)
LocalDateTime startOfDay = today.atStartOfDay();
// 获取今天的最大时间(23:59:59)
LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 最大时间 和 最小时间
String beginTime = startOfDay.format(formatter);
String endTime = endOfDay.format(formatter);
likeDTO.setBeginTime(beginTime);
likeDTO.setEndTime(endTime);
likeDTO.setUserId(Integer.valueOf(userId));
memInfoRepository.addLikeCount(likeDTO);
//没超出免费点赞次数
this.redisTemplate.opsForHash().increment(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), (double) 1L);
return new CyPersistModel(1);
} else {
//已超出今日对目标用户的点赞限制
throw new CyServiceException(1001,"今日对该用户点赞次数已达上限,请明日再试!");
}
} else if (redisUserLikeCount == null){
//当天第一次对这个用户进行点赞
//没超出 但需要付金币进行点赞 因为总免费次数已用完
if (likeDTO.getIsPay().equals("1")){
//付费点赞
//扣除金币和增加消费记录
consumeGlodCoinForLike(userLikeConfig,userId,likeDTO);
} else {
//已超出今日对目标用户的点赞限制
throw new CyServiceException(1001,"今日对该用户点赞次数已达上限,请明日再试!");
}
//今日第一次对该用户进行点赞
cyRedisServiceImpl.hset(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), 1L);
cyRedisServiceImpl.expire(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, 48 * 60 * 60); // 24小时
//新增点赞数据
likeDTO.setUserId(Integer.valueOf(userId));
likeDTO.setLikeCount(1);
memInfoRepository.addLike(likeDTO);
return new CyPersistModel(1);
} else {
//超出了
throw new CyServiceException(1001,"今日对该用户点赞次数已达上限,请明日再试!");
}
}
}
//会员点赞扣除金币和增加消费记录
private void consumeGlodCoinForLike(List<DictData> userLikeConfig, String userId, MemLikeDTO likeDTO) {
//加redis锁
boolean isGetLock = false;
RLock lock = redissonClient.getLock(MemberInfoRedisBean.USER_LIKE_LOCK + userId);
try {
isGetLock = lock.tryLock(Long.parseLong(MemberInfoRedisBean.USER_LIKE_LOCK_WAIT_TIME),
Long.parseLong(MemberInfoRedisBean.USER_LIKE_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
//扣除该用户的金币数量
DictData dictData4 = userLikeConfig.stream().filter(item -> item.getDictLabel().equals("pay_count")).findFirst().orElse(null);
Integer payCount = Integer.valueOf(dictData4.getDictValue());
MemInfo memInfo = memInfoRepository.selectByOpenId(likeDTO.getWxOpenid());
if (memInfo.getGoldCoinsCount() - payCount < 0){
throw new CyServiceException(1003,"金币不足,请先充值");
}
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
//添加消费记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setType("2");
memGoldCoinFlow.setActionType("20");
memGoldCoinFlow.setCount(payCount);
memGoldCoinFlow.setEndCount(memInfo.getGoldCoinsCount());
memGoldCoinFlow.setTargetId(BigInteger.valueOf(likeDTO.getTargetId()));
memGoldCoinFlowRepository.insert(memGoldCoinFlow);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} finally {
lock.unlock();
log.error("释放成功");
} }
} }
/** /**
* 查询排行榜 * 查询排行榜
* @param memInfo * @param memInfo
...@@ -995,16 +1054,16 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo> ...@@ -995,16 +1054,16 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
} }
} }
SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog(); SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog();
sysScheduledTaskLog.setTaskName("定时更新会员表的被点赞数和被关注数定时任务"); sysScheduledTaskLog.setTaskName("定时更新会员表定时任务");
sysScheduledTaskLog.setTaskState("成功"); sysScheduledTaskLog.setTaskState("成功");
sysScheduledTaskLog.setTaskTime("每4小时执行一次"); sysScheduledTaskLog.setTaskTime("每2小时执行一次");
sysScheduledTaskLog.setCreateDate(new Date()); sysScheduledTaskLog.setCreateDate(new Date());
sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog); sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog);
} catch (Exception e){ } catch (Exception e){
SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog(); SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog();
sysScheduledTaskLog.setTaskName("定时更新会员表的被点赞数和被关注数定时任务"); sysScheduledTaskLog.setTaskName("定时更新会员表定时任务");
sysScheduledTaskLog.setTaskState("失败"); sysScheduledTaskLog.setTaskState("失败");
sysScheduledTaskLog.setTaskTime("每4小时执行一次"); sysScheduledTaskLog.setTaskTime("每2你小时执行一次");
sysScheduledTaskLog.setCreateDate(new Date()); sysScheduledTaskLog.setCreateDate(new Date());
sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog); sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog);
} }
......
...@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.memGoldCoinFlow.dao.MemGoldCoinFlowRepository; import org.rcisoft.business.memGoldCoinFlow.dao.MemGoldCoinFlowRepository;
import org.rcisoft.business.memGoldCoinFlow.entity.MemGoldCoinFlow; import org.rcisoft.business.memGoldCoinFlow.entity.MemGoldCoinFlow;
import org.rcisoft.business.memInfo.bean.MemberInfoRedisBean;
import org.rcisoft.business.memInfo.dao.MemInfoRepository; import org.rcisoft.business.memInfo.dao.MemInfoRepository;
import org.rcisoft.business.memInfo.entity.MemInfo; import org.rcisoft.business.memInfo.entity.MemInfo;
import org.rcisoft.business.memInfo.entity.MemLikeDTO;
import org.rcisoft.business.memInfo.service.impl.MemInfoServiceImpl; import org.rcisoft.business.memInfo.service.impl.MemInfoServiceImpl;
import org.rcisoft.business.memLeaveMessage.bean.MemLeaveMessageRedisBean; import org.rcisoft.business.memLeaveMessage.bean.MemLeaveMessageRedisBean;
import org.rcisoft.business.memLeaveMessage.dao.MemLeaveMessageRepository; import org.rcisoft.business.memLeaveMessage.dao.MemLeaveMessageRepository;
...@@ -109,10 +111,10 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -109,10 +111,10 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
Object redisLeaveMessageCount = cyRedisServiceImpl.hget(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId())); Object redisLeaveMessageCount = cyRedisServiceImpl.hget(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()));
Object redisLeaveMessageCountAll = cyRedisServiceImpl.get(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId); Object redisLeaveMessageCountAll = cyRedisServiceImpl.get(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId);
//1.进行总数对比 //1.进行总数对比
if (redisLeaveMessageCountAll != null && (int)redisLeaveMessageCountAll <= allCount){ if (redisLeaveMessageCountAll != null && (int)redisLeaveMessageCountAll < allCount){
//没超出总次数限制 //没超出免费总次数限制
//2.进行判断对目标用户的留言总次数 //2.进行判断对目标用户的留言总次数
if (redisLeaveMessageCount != null && (int)redisLeaveMessageCount <= personalAllCount){ if (redisLeaveMessageCount != null && (int)redisLeaveMessageCount < personalAllCount){
//没超出对目标用户的留言总次数(免费+付费) //没超出对目标用户的留言总次数(免费+付费)
//3.判断对目标用户的免费留言次数 //3.判断对目标用户的免费留言次数
if (redisLeaveMessageCount != null && (int)redisLeaveMessageCount >= leaveMessageLimitCount) { if (redisLeaveMessageCount != null && (int)redisLeaveMessageCount >= leaveMessageLimitCount) {
...@@ -120,43 +122,16 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -120,43 +122,16 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
//4.判断用户是否选择付费留言 //4.判断用户是否选择付费留言
if (memLeaveMessage.getIsPay().equals("1")){ if (memLeaveMessage.getIsPay().equals("1")){
//付费留言 //付费留言
//加redis锁 //扣除金币,增加消费记录
boolean isGetLock = false; consumeGlodCoinForLeaveMessage(leaveMessageConfig,userId,memLeaveMessage);
RLock lock = redissonClient.getLock(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_LOCK + userId);
try {
isGetLock = lock.tryLock(Long.parseLong(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_LOCK_WAIT_TIME),
Long.parseLong(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
//扣除该用户的金币数量
DictData dictData4 = leaveMessageConfig.stream().filter(item -> item.getDictLabel().equals("pay_count")).findFirst().orElse(null);
Integer payCount = Integer.valueOf(dictData4.getDictValue());
MemInfo memInfo = memInfoRepository.selectByOpenId(memLeaveMessage.getWxOpenid());
if (memInfo.getGoldCoinsCount() - payCount < 0){
throw new CyServiceException(1003,"金币不足,请先充值!");
}
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
//添加消费记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setType("2");
memGoldCoinFlow.setActionType("22");
memGoldCoinFlow.setCount(payCount);
memGoldCoinFlow.setEndCount(memInfo.getGoldCoinsCount());
memGoldCoinFlow.setTargetId(BigInteger.valueOf(memLeaveMessage.getTargetId()));
memGoldCoinFlowRepository.insert(memGoldCoinFlow);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} finally {
lock.unlock();
log.error("释放成功");
}
} else { } else {
//不进行留言 //不进行留言
throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!"); throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!");
} }
} else {
//没超出 进行免费留言
//免费留言总次数+1
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
} }
//先插入到留言表 //先插入到留言表
memLeaveMessage.setCreateBy(Integer.valueOf(userId)); memLeaveMessage.setCreateBy(Integer.valueOf(userId));
...@@ -188,10 +163,10 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -188,10 +163,10 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
if (line1 > 0) { if (line1 > 0) {
//插入对话表成功,则更新redis //插入对话表成功,则更新redis
this.redisTemplate.opsForHash().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), (double) 1L); this.redisTemplate.opsForHash().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), (double) 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
} }
return new CyPersistModel(line); return new CyPersistModel(line);
} else if (redisLeaveMessageCount == null){ }
else if (redisLeaveMessageCount == null){
//今日第一次对该用户进行留言 //今日第一次对该用户进行留言
//先插入到留言表 //先插入到留言表
memLeaveMessage.setCreateBy(Integer.valueOf(userId)); memLeaveMessage.setCreateBy(Integer.valueOf(userId));
...@@ -232,10 +207,12 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -232,10 +207,12 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
} }
} }
return new CyPersistModel(line); return new CyPersistModel(line);
} else { }
else {
throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!"); throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!");
} }
} else if (redisLeaveMessageCountAll == null){ }
else if (redisLeaveMessageCountAll == null){
//当天第一次进行留言 //当天第一次进行留言
//先插入到留言表 //先插入到留言表
memLeaveMessage.setCreateBy(Integer.valueOf(userId)); memLeaveMessage.setCreateBy(Integer.valueOf(userId));
...@@ -271,12 +248,143 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -271,12 +248,143 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
cyRedisServiceImpl.expire(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, 48 * 60 * 60); // 24小时 cyRedisServiceImpl.expire(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, 48 * 60 * 60); // 24小时
} }
return new CyPersistModel(line1); return new CyPersistModel(line1);
} else { }
//超出总次数限制 else {
throw new CyServiceException(1002,"今日留言次数已达上限,请明日再试!"); //超出免费总次数限制
//判断对该用户是否超出今日最大留言数
if (redisLeaveMessageCount != null && (int)redisLeaveMessageCount < personalAllCount){
if (memLeaveMessage.getIsPay().equals("1")){
//付费留言
//扣除金币,增加消费记录
consumeGlodCoinForLeaveMessage(leaveMessageConfig,userId,memLeaveMessage);
//先插入到留言表
memLeaveMessage.setCreateBy(Integer.valueOf(userId));
memLeaveMessage.setUpdateBy(Integer.valueOf(userId));
memLeaveMessage.setCreateDate(new Date());
memLeaveMessage.setUpdateDate(new Date());
memLeaveMessage.setReadStatus("0");
int line = memLeaveMessageRepository.insert(memLeaveMessage);
//修改对话表
//查询是否已存在对话
MemLeaveMessage memUserTalks = memLeaveMessageRepository.queryUserTalk(Integer.valueOf(userId),memLeaveMessage.getTargetId());
MemLeaveMessage memUserTalk = new MemLeaveMessage();
memUserTalk.setCreateBy(Integer.valueOf(userId));
memUserTalk.setUpdateBy(Integer.valueOf(userId));
memUserTalk.setTargetId(memLeaveMessage.getTargetId());
memUserTalk.setContent(memLeaveMessage.getContent());
memUserTalk.setCreateDate(new Date());
memUserTalk.setUpdateDate(new Date());
memUserTalk.setDelUser(0);
int line1 = 0;
if (memUserTalks != null){
//如果已经存在该对话,则只更新信息
memUserTalk.setBusinessId(memUserTalks.getBusinessId());
line1 = memLeaveMessageRepository.updateUserTalk(memUserTalk);
} else {
//不存在该对话,则插入对话表
line1 = memLeaveMessageRepository.insertUserTalk(memUserTalk);
}
if (line1 > 0) {
//插入对话表成功,则更新redis
this.redisTemplate.opsForHash().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), (double) 1L);
}
return new CyPersistModel(line);
} else {
//不进行留言
throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!");
}
} else if (redisLeaveMessageCount == null){
//今日第一次对该用户进行留言
if (memLeaveMessage.getIsPay().equals("1")){
//扣除金币,增加消费记录
consumeGlodCoinForLeaveMessage(leaveMessageConfig,userId,memLeaveMessage);
//先插入到留言表
memLeaveMessage.setCreateBy(Integer.valueOf(userId));
memLeaveMessage.setUpdateBy(Integer.valueOf(userId));
memLeaveMessage.setCreateDate(new Date());
memLeaveMessage.setUpdateDate(new Date());
memLeaveMessage.setReadStatus("0");
int line = memLeaveMessageRepository.insert(memLeaveMessage);
//查询是否已存在对话
MemLeaveMessage memUserTalks = memLeaveMessageRepository.queryUserTalk(Integer.valueOf(userId),memLeaveMessage.getTargetId());
//如果已经存在该对话,则只更新信息
MemLeaveMessage memUserTalk = new MemLeaveMessage();
memUserTalk.setCreateBy(Integer.valueOf(userId));
memUserTalk.setUpdateBy(Integer.valueOf(userId));
memUserTalk.setTargetId(memLeaveMessage.getTargetId());
memUserTalk.setContent(memLeaveMessage.getContent());
memUserTalk.setCreateDate(new Date());
memUserTalk.setUpdateDate(new Date());
//留言未删除默认值为0
memUserTalk.setDelUser(0);
if (memUserTalks != null){
//已经给该用户留过言
memUserTalk.setBusinessId(memUserTalks.getBusinessId());
int line1 = memLeaveMessageRepository.updateUserTalk(memUserTalk);
if (line1 > 0) {
//插入对话表成功,则更新redis
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
}
return new CyPersistModel(line1);
} else {
//第一次给该用户进行留言
int line1 = memLeaveMessageRepository.insertUserTalk(memUserTalk);
if (line1 > 0) {
//插入对话表成功,则更新redis
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
}
}
return new CyPersistModel(line);
} else {
throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!");
}
} else {
throw new CyServiceException(1001,"今日留言次数已达上限,请明日再试!");
}
} }
} }
//会员留言扣除金币和增加消费记录
private void consumeGlodCoinForLeaveMessage(List<DictData> leaveMessageConfig, String userId, MemLeaveMessage memLeaveMessage) {
//加redis锁
boolean isGetLock = false;
RLock lock = redissonClient.getLock(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_LOCK + userId);
try {
isGetLock = lock.tryLock(Long.parseLong(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_LOCK_WAIT_TIME),
Long.parseLong(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
//扣除该用户的金币数量
DictData dictData4 = leaveMessageConfig.stream().filter(item -> item.getDictLabel().equals("pay_count")).findFirst().orElse(null);
Integer payCount = Integer.valueOf(dictData4.getDictValue());
MemInfo memInfo = memInfoRepository.selectByOpenId(memLeaveMessage.getWxOpenid());
if (memInfo.getGoldCoinsCount() - payCount < 0){
throw new CyServiceException(1003,"金币不足,请先充值!");
}
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
//添加消费记录
MemGoldCoinFlow memGoldCoinFlow = new MemGoldCoinFlow();
memGoldCoinFlow.setType("2");
memGoldCoinFlow.setActionType("22");
memGoldCoinFlow.setCount(payCount);
memGoldCoinFlow.setEndCount(memInfo.getGoldCoinsCount());
memGoldCoinFlow.setTargetId(BigInteger.valueOf(memLeaveMessage.getTargetId()));
memGoldCoinFlowRepository.insert(memGoldCoinFlow);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} finally {
lock.unlock();
log.error("释放成功");
}
}
/** /**
* 分页查询对话列表 * 分页查询对话列表
* *
......
...@@ -418,6 +418,11 @@ ...@@ -418,6 +418,11 @@
</if> </if>
<if test="entity.loginUserId !=null and entity.loginUserId != '' "> <if test="entity.loginUserId !=null and entity.loginUserId != '' ">
and m.user_id != #{entity.loginUserId} and m.user_id != #{entity.loginUserId}
and m.mem_sex != (
select m.mem_sex
from mem_info m
where m.user_id = #{entity.loginUserId}
)
and m.user_id not in ( and m.user_id not in (
select obl.target_id select obl.target_id
from opm_black_list obl from opm_black_list obl
...@@ -886,4 +891,10 @@ ...@@ -886,4 +891,10 @@
where 1=1 where 1=1
and mem_phone = #{phone} and mem_phone = #{phone}
</update> </update>
<update id="updateMemSexByPhone" parameterType="org.rcisoft.sys.rbac.user.entity.SysUserRbac">
update mem_info
set mem_sex = #{wxSex}
where 1=1
and mem_phone = #{phone}
</update>
</mapper> </mapper>
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