Commit f916b030 f916b030f805fdb406d9071fb08b291e4e022763 by xianghan

1.优化sql

2.添加缓存
1 parent 31b1400d
Showing 52 changed files with 446 additions and 320 deletions
......@@ -32,10 +32,8 @@ public class MemberProfileController {
@RequestMapping(value = "/update")
@ApiOperation("修改会员属性")
@AnonymousAccess
@Deprecated
public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody MemberProfile resources) {
log.info("memberProfile ==>> update ==>> resources ===>> [{}]",resources);
log.info("memberProfile ==>> update ==>> resources ===>> {}",resources);
MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.updateMemberProfileAndMember(resources);
return ResultInfo.success(memberProfileDTO);
}
......@@ -44,8 +42,7 @@ public class MemberProfileController {
@ApiOperation("修改会员属性并同步会员信息")
@AnonymousAccess
public ResultInfo updateMemberProfileAndMember(@Validated @RequestBody MemberProfile resources) {
log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources);
log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> {}",resources);
MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.updateMemberProfileAndMember(resources);
return ResultInfo.success(memberProfileDTO);
}
......@@ -55,9 +52,7 @@ public class MemberProfileController {
@AnonymousAccess
@Deprecated
public ResultInfo create(@Validated(value = {CreateGroup.class}) @RequestBody MemberProfile resources) {
log.info("memberProfile ==>> update ==>> resources ===>> [{}]",resources);
log.info("memberProfile ==>> update ==>> resources ===>> {}",resources);
MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.createMemberProfileAndSyncMember(resources);
return ResultInfo.success(memberProfileDTO);
}
......
......@@ -175,27 +175,26 @@ public class MemberProfileServiceImpl implements MemberProfileService {
return memberProfileDTO;
}
private void synchronizedMemberData(MemberProfile resources, MemberDTO memberDTO) {
private void synchronizedMemberData(MemberProfile memberProfile, MemberDTO memberDTO) {
log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",resources);
log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",memberProfile);
memberDTO.setId(resources.getMemberId());
if(StringUtils.isNotBlank(resources.getRealname())) {
memberDTO.setNickname(resources.getRealname());
Member member = new Member();
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
if(StringUtils.isNotBlank(memberProfile.getRealname())) {
member.setNickname(memberProfile.getRealname());
}
if(Objects.nonNull(resources.getGender()) && resources.getGender() != -1) {
memberDTO.setGender(resources.getGender());
if(Objects.nonNull(memberProfile.getGender()) && memberProfile.getGender() != -1) {
member.setGender(memberProfile.getGender());
}
if(StringUtils.isNotBlank(resources.getBirthday())) {
memberDTO.setBirthday(resources.getBirthday());
if(StringUtils.isNotBlank(memberProfile.getBirthday())) {
member.setBirthday(memberProfile.getBirthday());
}
if(StringUtils.isNotBlank(resources.getAvatarUrl())) {
memberDTO.setAvatarUrl(resources.getAvatarUrl());
if(StringUtils.isNotBlank(memberProfile.getAvatarUrl())) {
member.setAvatarUrl(memberProfile.getAvatarUrl());
}
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
this.memberService.update(member);
this.memberService.doUpdateMemberAvatarUrlAndNicknameAndGender(member);
}
}
......
......@@ -23,24 +23,48 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif
Optional<Member> findByIdOrCode(Long id,String code);
@Modifying
@Query(value = "UPDATE `uc_member` SET `user_iptv_id` = ?2, `update_time` = ?3 , `bind_iptv_platform_type`= 0, " +
"`bind_iptv_time`=?3 WHERE `id` = ?1", nativeQuery = true)
void updateUserIptvIdById(Long id, Long userIptvId, LocalDateTime now);
@Modifying
@Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, `level` = :#{#resources.level} , `update_time`= now() " +
@Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, " +
"`level` = :#{#resources.level} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void updateExpAndLevel(@Param("resources") Member member);
Integer updateExpAndLevel(@Param("resources") Member member);
@Modifying
@Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, `due_points` = :#{#resources.duePoints} , `update_time`= now() " +
@Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, " +
"`due_points` = :#{#resources.duePoints} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void updatePointAndDuePoint(@Param("resources") Member resources);
Integer updatePointAndDuePoint(@Param("resources") Member resources);
@Modifying
@Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, " +
"`due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
Integer doUpdateMemberCoupon(@Param("resources") Member member);
@Query(value = "SELECT um.* FROM uc_member um LEFT JOIN uc_user_tv tv ON um.id = tv.member_id " +
" WHERE tv.platform_account = ?1 ", nativeQuery = true)
Optional<Member> findByPlatformAccount(String platformAccount);
@Modifying
@Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, `due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " +
@Query(value = "UPDATE `uc_member` SET `vip` = :#{#resources.vip}, " +
"`vip_expire_time` = :#{#resources.vipExpireTime} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void doUpdateMemberCoupon(@Param("resources") Member member);
Integer updateMemberVipAndVipExpireTime(@Param("resources") Member member);
@Modifying
@Query(value = "UPDATE `uc_member` SET `user_iptv_id` = :#{#resources.userIptvId}, `update_time` = now() , " +
" `bind_iptv_platform_type`= :#{#resources.bindIptvPlatformType}, " +
" `bind_iptv_time`=:#{#resources.bindIptvTime} WHERE `id` = :#{#resources.id}", nativeQuery = true)
Integer updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(@Param("resources") Member member);
@Modifying
@Query(value = "UPDATE `uc_member` SET `avatar_url` = :#{#resources.avatarUrl}, `update_time` = now() , " +
" `nickname`= :#{#resources.nickname}, " +
" `gender`=:#{#resources.gender} WHERE `id` = :#{#resources.id}", nativeQuery = true)
Integer updateMemberAvatarUrlAndNicknameAndGender(@Param("resources") Member resource);
}
......
......@@ -52,8 +52,8 @@ public class MemberController {
@AnonymousAccess
@ApiOperation("手动修改vip")
public ResultInfo doUpdateVipByCode(@Validated(value = {UpdateGroup.class}) @RequestBody Member resources) {
log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources);
this.memberOperationService.updateMemberVip(resources);
log.info("member ==>> doUpdateVipByCode ==>> param ==>> {}",resources);
this.memberOperationService.doUpdateMemberVipAndVipExpireTime(resources);
return ResultInfo.success();
}
......@@ -67,7 +67,6 @@ public class MemberController {
if (StringUtils.isNotBlank(code)) {
MemberDTO memberDTO = this.memberOperationService.findByCode(code);
resources.setId(memberDTO.getId());
// BeanUtils.copyProperties(resources, memberDTO);
}
MemberDTO memberDTO = this.memberOperationService.update(resources);
......
......@@ -40,13 +40,6 @@ public interface MemberService {
MemberDTO create(Member resources);
/**
* 创建并返回会员
* @param resources 会员
* @return Member
*/
MemberDTO createAndReturnMember(Member resources);
/**
* 修改会员
* @param resources
*/
......@@ -91,4 +84,31 @@ public interface MemberService {
* @return
*/
MemberDTO doUpdateMemberCoupon(Member member);
/**
*
* @param platformAccount
* @return
*/
MemberDTO findByPlatformAccount(String platformAccount);
/**
*
* @param member
* @return
*/
MemberDTO doUpdateMemberVipAndVipExpireTime(Member member);
/**
*
* @param member
* @return
*/
MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member member);
/**
*
* @param member
*/
MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member member);
}
......
package com.topdraw.business.process.domian.constant;
package com.topdraw.business.module.rights.constant;
public enum RightType {
/**积分*/
......
package com.topdraw.business.module.rights.constant;
public class RightsType {
public static String TYPE_1 = "1";
Integer TYPE_2 = 2;
Integer TYPE_3 = 3;
}
......@@ -47,7 +47,7 @@ public class Rights implements Serializable {
/** 权益的实体类型 1:积分;2成长值;3优惠券 */
@Column(name = "entity_type", nullable = false)
private String entityType;
private Integer entityType;
/** 实体id */
@Column(name = "entity_id", nullable = false)
......
......@@ -28,7 +28,7 @@ public class RightsDTO implements Serializable {
private Integer type;
/** 权益的实体类型 1:积分;2成长值;3优惠券 */
private String entityType;
private Integer entityType;
/** 实体id */
private Long entityId;
......
......@@ -16,5 +16,5 @@ public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress,
@Query(value = "select id, member_id, task_id , current_action_amount , \n" +
" target_action_amount , `status` , completion_time,create_time,update_time from uc_tr_task_progress where member_id = ?1 \n" +
" and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true)
List<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
}
......
......@@ -2,6 +2,8 @@ package com.topdraw.business.module.task.progress.service;
import com.topdraw.business.module.task.progress.domain.TrTaskProgress;
import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
import java.time.LocalDateTime;
import java.util.List;
/**
......@@ -21,13 +23,13 @@ public interface TrTaskProgressService {
*
* @param resources
*/
void create(TrTaskProgress resources);
TrTaskProgress create(TrTaskProgress resources, String date);
/**
*
* @param resources
*/
void update(TrTaskProgress resources);
TrTaskProgress update(TrTaskProgress resources, String date);
/**
*
......@@ -42,5 +44,6 @@ public interface TrTaskProgressService {
* @param time1
* @return
*/
List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
TrTaskProgressDTO findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
}
......
package com.topdraw.business.module.task.progress.service.impl;
import com.topdraw.business.module.task.progress.domain.TrTaskProgress;
import com.topdraw.config.RedisKeyConstants;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.task.progress.repository.TrTaskProgressRepository;
import com.topdraw.business.module.task.progress.service.TrTaskProgressService;
import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
import com.topdraw.business.module.task.progress.service.mapper.TrTaskProgressMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import java.time.LocalDateTime;
import java.util.List;
/**
......@@ -21,6 +26,7 @@ import java.util.List;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class TrTaskProgressServiceImpl implements TrTaskProgressService {
@Autowired
......@@ -38,17 +44,21 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
@Override
@Transactional(rollbackFor = Exception.class)
public void create(TrTaskProgress resources) {
this.trTaskProgressRepository.save(resources);
@Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ")
public TrTaskProgress create(TrTaskProgress resources, String date) {
TrTaskProgress trTaskProgress = this.trTaskProgressRepository.save(resources);
return trTaskProgress;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TrTaskProgress resources) {
TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(resources.getId()).orElseGet(TrTaskProgress::new);
ValidationUtil.isNull( TrTaskProgress.getId(),"TrTaskProgress","id",resources.getId());
TrTaskProgress.copy(resources);
this.trTaskProgressRepository.save(TrTaskProgress);
@Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ")
public TrTaskProgress update(TrTaskProgress resources, String date) {
TrTaskProgress trTaskProgress = this.trTaskProgressRepository.findById(resources.getId()).orElseGet(TrTaskProgress::new);
ValidationUtil.isNull( trTaskProgress.getId(),"TrTaskProgress","id",resources.getId());
trTaskProgress.copy(resources);
TrTaskProgress save = this.trTaskProgressRepository.save(trTaskProgress);
return save;
}
@Override
......@@ -61,9 +71,12 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
}
@Override
public List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) {
@Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#memberId+':'+#taskId+':'+#time1", unless = "#result == null")
public TrTaskProgressDTO findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) {
log.info("从数据库查询当前会员今天是否完成了此任务, memberId ==>> {} || taskId ==>> {}", memberId, taskId);
return this.trTaskProgressMapper.toDto(this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1));
}
}
......
......@@ -21,7 +21,13 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat
@Modifying
@Transactional
@Query(value = "UPDATE `tr_task` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true)
void updateDeleteMark(Long id);
Integer updateDeleteMark(Long id);
Optional<Task> findByCode(String code);
@Query(value = "SELECT ta.*, attr.attr_str AS attr FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " +
" LEFT JOIN tr_task_attr attr ON attr.task_id = ta.id " +
" WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " +
" tm.type = ?1 ", nativeQuery = true)
List<Task> findByEvent(Integer event);
}
......
package com.topdraw.business.module.task.service;
import com.topdraw.business.module.task.domain.Task;
import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
import com.topdraw.business.module.task.service.dto.TaskDTO;
import java.time.LocalDateTime;
import java.util.List;
/**
......@@ -47,11 +50,19 @@ public interface TaskService {
*
* @param task
*/
void delete(Task task);
Integer delete(Task task);
/**
*
* @param id
*/
void delete(Long id);
Integer delete(Long id);
/**
*
* @param event
* @return
*/
List<Task> findByEvent(Integer event);
}
......
......@@ -5,11 +5,15 @@ import com.topdraw.business.module.task.repository.TaskRepository;
import com.topdraw.business.module.task.service.TaskService;
import com.topdraw.business.module.task.service.dto.TaskDTO;
import com.topdraw.business.module.task.service.mapper.TaskMapper;
import com.topdraw.config.RedisKeyConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
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;
import java.util.Objects;
......@@ -19,6 +23,7 @@ import java.util.Objects;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class TaskServiceImpl implements TaskService {
@Autowired
......@@ -56,14 +61,20 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public void delete(Task task) {
public Integer delete(Task task) {
Long id = task.getId();
this.delete(id);
return this.delete(id);
}
@Override
public void delete(Long id) {
this.taskRepository.updateDeleteMark(id);
public Integer delete(Long id) {
return this.taskRepository.updateDeleteMark(id);
}
@Override
// @Cacheable(value = RedisKeyConstants.cacheTaskByTaskTemplateId, key = "#event" , unless = "#result.size() == 0")
public List<Task> findByEvent(Integer event) {
log.info("从数据库查询事件列表 ==>> {}", event);
return Objects.nonNull(event) ? this.taskRepository.findByEvent(event) : new ArrayList<>();
}
}
......
......@@ -26,4 +26,6 @@ public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long
@Transactional
@Query(value = "UPDATE `tr_task_template` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true)
void updateDeleteMark(Long id);
Long countByCodeAndType(String code, Integer type);
}
......
......@@ -61,4 +61,11 @@ public interface TaskTemplateService {
* @return
*/
TaskTemplateDTO findByType(Integer event);
/**
*
* @param taskTemplate
* @return
*/
Long countByCodeAndType(TaskTemplate taskTemplate);
}
......
......@@ -83,4 +83,10 @@ public class TaskTemplateServiceImpl implements TaskTemplateService {
return Objects.nonNull(event) ? this.taskTemplateMapper.toDto(this.taskTemplateRepository.findByType(event).orElseGet(TaskTemplate::new)) : new TaskTemplateDTO();
}
@Override
public Long countByCodeAndType(TaskTemplate taskTemplate) {
Long count = this.taskTemplateRepository.countByCodeAndType(taskTemplate.getCode(), taskTemplate.getType());
return count;
}
}
......
......@@ -5,6 +5,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Optional;
......@@ -24,4 +26,9 @@ public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecif
@Modifying
@Query(value = "UPDATE `uc_user_tv` SET `vis_user_id` = ?2, `update_time` = ?3 WHERE `id` = ?1", nativeQuery = true)
Integer updateUserTvVisUserId(Long id, Long visUserId, LocalDateTime now);
@Modifying
@Query(value = "UPDATE `uc_user_tv` SET `priority_member_code` = :#{#resources.priorityMemberCode}, `update_time` = now()" +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
Integer updatePriorityMemberCode(@Param("resources") UserTv resources);
}
......
......@@ -69,7 +69,7 @@ public interface UserTvService {
* @param memberCode
* @return
*/
boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId,String memberCode);
boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode);
/**
*
......@@ -84,4 +84,11 @@ public interface UserTvService {
* @return
*/
UserTvDTO updateUserTvVisUserId(UserTv resources);
/**
*
* @param resources
* @return
*/
UserTvDTO doUpdatePriorityMemberCode(UserTv resources);
}
......
......@@ -5,6 +5,7 @@ import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.process.service.impl.UserOperationServiceImpl;
import com.topdraw.config.RedisKeyConstants;
import com.topdraw.exception.EntityNotFoundException;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.utils.ValidationUtil;
......@@ -16,6 +17,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -96,6 +98,16 @@ public class UserTvServiceImpl implements UserTvService {
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserTvDTO doUpdatePriorityMemberCode(UserTv resources) {
Integer count = this.userTvRepository.updatePriorityMemberCode(resources);
if (Objects.nonNull(count) && count > 0) {
UserTv userTv = this.userTvRepository.findById(resources.getId()).orElseGet(UserTv::new);
return this.userTvMapper.toDto(userTv);
}
return this.userTvMapper.toDto(resources);
}
private MemberDTO findMemberByMemberCode(String memberCode) {
......@@ -157,7 +169,9 @@ public class UserTvServiceImpl implements UserTvService {
}
@Override
@Cacheable(cacheNames = RedisKeyConstants.cacheUserTvByPlatformAccount, key = "#platformAccount")
public UserTvDTO findByPlatformAccount(String platformAccount) {
log.info("从数据库通过大屏账号检索大屏账号信息");
Optional<UserTv> userTv = this.userTvRepository.findByPlatformAccount(platformAccount);
if (userTv.isPresent()) {
ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId());
......
......@@ -29,9 +29,7 @@ public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, J
Optional<UserWeixin> findFirstByMemberId(Long memberId);
@Modifying
@Transactional
@Query(value = "update `uc_user_weixin` set update_time = :#{#resources.updateTime} " +
"where appid = :#{#resources.appid} and openid = :#{#resources.openid}", nativeQuery = true)
void updateTime(@Param("resources") UserWeixin resources);
@Query(value = "UPDATE `uc_user_weixin` SET update_time = now(), `status` = :#{#resources.status}" +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
Integer updateWeixinStatus(@Param("resources") UserWeixin resource);
}
......
......@@ -31,12 +31,6 @@ public interface UserWeixinService {
/**
*
* @param resources
*/
void updateTime(UserWeixin resources);
/**
*
* @param id
*/
void delete(Long id);
......@@ -87,4 +81,11 @@ public interface UserWeixinService {
* @return
*/
UserWeixinDTO findFirstByMemberId(Long memberId);
/**
*
* @param userWeixin
* @return
*/
UserWeixinDTO doUpdateWeixinStatus(UserWeixin userWeixin);
}
......
......@@ -14,6 +14,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import java.util.Objects;
/**
* @author XiangHan
* @date 2021-12-16
......@@ -54,11 +56,6 @@ public class UserWeixinServiceImpl implements UserWeixinService {
}
@Override
public void updateTime(UserWeixin resources) {
this.userWeixinRepository.updateTime(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
......@@ -104,4 +101,15 @@ public class UserWeixinServiceImpl implements UserWeixinService {
return this.userWeixinMapper.toDto(userWeixin);
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserWeixinDTO doUpdateWeixinStatus(UserWeixin resource) {
Integer count = this.userWeixinRepository.updateWeixinStatus(resource);
if (Objects.nonNull(count) && count > 0) {
UserWeixin userWeixin = this.userWeixinRepository.findById(resource.getId()).orElseGet(UserWeixin::new);
return this.userWeixinMapper.toDto(userWeixin);
}
return this.userWeixinMapper.toDto(resource);
}
}
......
......@@ -5,6 +5,7 @@ import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.common.ResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* @author XiangHan
......@@ -22,14 +24,27 @@ import java.util.List;
@Api(tags = "成长值管理")
@RestController
@RequestMapping("/uce/expOperation")
@Slf4j
public class ExpOperationController {
@Autowired
private ExpOperationService expOperationService;
@PostMapping(value = "/grantExpByManual")
@PostMapping(value = "/addExp")
@ApiOperation("手动发放成长值")
public ResultInfo grantExpByManual(@Validated @RequestBody TempExp tempExp) {
log.info("手动发放成长值,参数 ==>> {}", tempExp);
Long memberId = tempExp.getMemberId();
if (Objects.isNull(memberId)) {
log.error("发放成长值失败,参数错误,无会员id");
return ResultInfo.failure("发放成长值失败,参数错误,无会员id");
}
Long rewardExp = tempExp.getRewardExp();
if (Objects.isNull(rewardExp) || rewardExp <= 0L) {
log.error("发放成长值失败,参数错误,成长值为空或者小于0 ==>> {}", rewardExp);
return ResultInfo.failure("发放成长值失败,参数错误,成长值为空或者小于0");
}
List<TempExp> tempExpList = Arrays.asList(tempExp);
this.expOperationService.grantExpByManual(tempExpList);
return ResultInfo.success();
......
......@@ -14,6 +14,7 @@ import com.topdraw.exception.BadRequestException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
......@@ -50,7 +51,7 @@ public class MemberOperationController {
if (Objects.nonNull(vipExpireTime)) {
member.setVipExpireTime(vipExpireTime);
}
this.memberOperationService.update(member);
this.memberOperationService.doUpdateMemberVipAndVipExpireTime(member);
return ResultInfo.success();
}
......@@ -59,23 +60,28 @@ public class MemberOperationController {
@AnonymousAccess
public ResultInfo updateVipByMemberCode(@Validated(value = {UpdateGroup.class}) @RequestBody MemberOperationBean resources) {
log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources);
String memberCode = resources.getMemberCode();
if (StringUtils.isBlank(memberCode)) {
log.error("参数错误,memberCode 不存在");
return ResultInfo.failure("参数错误,memberCode 不存在");
}
Integer vip = resources.getVip();
if (Objects.isNull(vip) || vip < 0) {
log.error("参数错误,vip为空或者小于0 , vip ==>> {}", vip);
return ResultInfo.failure("参数错误,vip为空或者小于0");
}
Timestamp vipExpireTime = resources.getVipExpireTime();
String memberCode = resources.getMemberCode();
MemberDTO memberDTO = this.memberOperationService.findByCode(memberCode);
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
if (Objects.nonNull(vip)) {
member.setCode(memberCode);
member.setVip(vip);
}
if (Objects.nonNull(vipExpireTime)) {
member.setVipExpireTime(vipExpireTime);
}
MemberDTO memberDTO = this.memberOperationService.doUpdateMemberVipAndVipExpireTime(member);
this.createVipHistory(memberDTO.getId(), memberDTO.getCode(), vip, vipExpireTime);
this.memberOperationService.updateMemberVip(member);
return ResultInfo.success();
}
......@@ -93,6 +99,7 @@ public class MemberOperationController {
@GetMapping("/getMemberProfileAndCheckVip/{appId}/{memberId}")
@ApiOperation("获取会员基本信息并且检查vip状态")
@AnonymousAccess
@Deprecated
public IResultInfo getMemberProfileAndCheckVip(@PathVariable(value = "appId") String appId, @PathVariable(value = "memberId") Long memberId) {
MemberProfileDTO memberProfileDTO = this.memberOperationService.getMemberProfileAndCheckVip(memberId, appId);
return ResultInfo.success(memberProfileDTO);
......
......@@ -49,6 +49,7 @@ public class PointsOperationController {
@GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}")
@ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用")
@AnonymousAccess
@Deprecated
public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) {
Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id);
return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong);
......@@ -59,15 +60,22 @@ public class PointsOperationController {
@ApiOperation("手动发放积分")
@AnonymousAccess
public ResultInfo addPoints(@Validated @RequestBody TempPoints tempPoints) {
log.info("手动发放积分,参数 ==>>{} ", tempPoints);
Long memberId = tempPoints.getMemberId();
if (Objects.isNull(memberId)) {
log.error("积分发放失败,参数错误,会员id 不存在");
return ResultInfo.failure("积分发放失败,参数错误");
}
Long points = tempPoints.getPoints();
Assert.notNull(memberId,"memberId can't be null!");
Assert.notNull(points,"points can't be null!");
if (Objects.isNull(points) || points <= 0L) {
log.error("积分发放失败,参数错误,积分不存在或者积分小于0");
return ResultInfo.failure("积分发放失败,参数错误");
}
MemberDTO memberDTO = this.memberService.findById(memberId);
if (Objects.nonNull(memberDTO)) {
String code = memberDTO.getCode();
Assert.notNull(code,"code can't be null!");
tempPoints.setMemberCode(code);
tempPoints.setMemberId(memberDTO.getId());
this.pointsOperationService.grantPointsByManualByTempPoints(tempPoints);
}
return ResultInfo.success();
......@@ -176,7 +184,6 @@ public class PointsOperationController {
return ResultInfo.success(Arrays.asList(b),description);
}
// @Log("积分兑换商品")
@PostMapping(value = "/consumeItemPoints")
@ApiOperation("积分兑换商品")
@AnonymousAccess
......
......@@ -42,11 +42,11 @@ public class TaskOperationController {
long l = System.currentTimeMillis();
// 任务处理
this.taskOperationService.dealTask(criteria.getContent());
ResultInfo resultInfo = this.taskOperationService.dealTask(criteria.getContent());
long l2 = System.currentTimeMillis();
log.info("事件处理,结束,总耗时 ==>> {}", (l2-l));
return ResultInfo.success();
return resultInfo;
}
/**
......@@ -99,12 +99,17 @@ public class TaskOperationController {
@PostMapping(value = "/deleteTask")
@ApiOperation("删除任务")
@AnonymousAccess
public void deleteTask(@RequestBody @Validated Task task) {
public ResultInfo deleteTask(@RequestBody @Validated Task task) {
log.info("taskOperation ==>> deleteTask ==>> param ==>> {}", task);
Long id = task.getId();
// 删除任务
this.taskOperationService.deleteTask(id);
Integer integer = this.taskOperationService.deleteTask(id);
if (integer > 1) {
return ResultInfo.success("删除成功");
} else {
return ResultInfo.failure("删除失败");
}
}
/**
......
......@@ -34,9 +34,8 @@ public class TaskTemplateOperationController {
log.info("taskTemplateOperation ==>> create ==>> param ==>> {}", taskTemplate);
String code = taskTemplate.getCode();
Integer type = taskTemplate.getType();
TaskTemplateDTO taskTemplateDTO_ = this.taskTemplateOperationService.findByCode(code);
TaskTemplateDTO taskTemplateDTO_1 = this.taskTemplateOperationService.findByType(type);
if (Objects.isNull(taskTemplateDTO_.getId()) && Objects.isNull(taskTemplateDTO_1.getId())) {
Long count = this.taskTemplateOperationService.countByCodeAndType(taskTemplate);
if (count < 1) {
// 新增任务
this.taskTemplateOperationService.create(taskTemplate);
}
......
......@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.net.URLDecoder;
import java.sql.Timestamp;
......@@ -89,7 +90,8 @@ public class UserOperationController {
MemberDTO memberDTO = this.memberService.findById(memberId);
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
if (Objects.nonNull(vip)) {
member.setVip(vip);
}
......@@ -97,9 +99,9 @@ public class UserOperationController {
member.setVipExpireTime(vipExpireTime);
}
this.createVipHistory(userId, vip, vipExpireTime);
this.memberOperationService.doUpdateMemberVipAndVipExpireTime(member);
this.memberOperationService.updateMemberVip(member);
this.createVipHistory(userId, vip, vipExpireTime);
return ResultInfo.success();
}
......@@ -152,8 +154,12 @@ public class UserOperationController {
SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class);
// 解析参数
this.parseSubscribe(subscribeBean);
this.userOperationService.subscribe(subscribeBean);
return ResultInfo.success();
boolean subscribe = this.userOperationService.subscribe(subscribeBean);
if (subscribe) {
return ResultInfo.success("关注成功");
} else {
return ResultInfo.failure("关注失败");
}
}
/**
......@@ -266,6 +272,16 @@ public class UserOperationController {
public ResultInfo minaBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources);
Long memberId = resources.getMemberId();
if (Objects.isNull(memberId)) {
return ResultInfo.failure("参数错误,memberId 不存在");
}
String platformAccount = resources.getPlatformAccount();
if (StringUtils.isBlank(platformAccount)) {
return ResultInfo.failure("参数错误,大屏账号不存在");
}
boolean result = this.userOperationService.minaBind(resources);
return ResultInfo.success(result);
}
......@@ -276,8 +292,17 @@ public class UserOperationController {
public ResultInfo minaUnbind(@Validated(value = {UnbindGroup.class}) @RequestBody WeixinUnBindBean weixinUnBindBean) {
log.info("UserOperationController ==> minaUnbind ==>> param ==> [{}]", weixinUnBindBean);
this.userOperationService.minaUnbind(weixinUnBindBean);
return ResultInfo.success();
Long memberId = weixinUnBindBean.getMemberId();
if (Objects.isNull(memberId)) {
log.error("小屏解绑失败,参数错误,memberId不存在");
return ResultInfo.failure("参数错误,会员id不存在");
}
boolean b = this.userOperationService.minaUnbind(weixinUnBindBean);
if (b) {
return ResultInfo.success("解绑成功");
} else {
return ResultInfo.failure("解绑失败");
}
}
/**
......@@ -293,12 +318,18 @@ public class UserOperationController {
public ResultInfo memberPreprocess(@RequestBody String data) {
log.info("UserOperationController ==> saveUserInfo ==>> param ==>> [{}]",data);
Assert.notNull(data, "用户数据不可为空");
if (StringUtils.isBlank(data)) {
log.error("预存大小屏账号信息失败,无参数");
return ResultInfo.failure("参数错误");
}
JSONObject json = JSONObject.parseObject(data);
String unionid = json.getString("unionid");
Assert.state(StrUtil.isNotBlank(unionid), "unionid不可为空");
if (StringUtils.isBlank(unionid)) {
log.error("预存大小屏账号信息失败,参数错误,unionid不存在");
return ResultInfo.failure("参数错误,unionid不存在");
}
List<Object> resultList = new ArrayList<>();
......@@ -471,8 +502,10 @@ public class UserOperationController {
throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
}
this.userOperationService.tvUnbind(resources);
return ResultInfo.success();
boolean b = this.userOperationService.tvUnbind(resources);
if (b) {
return ResultInfo.success("解绑成功");
} else return ResultInfo.failure("解绑失败");
}
@RequestMapping(value = "/changeMainAccount")
......@@ -493,9 +526,9 @@ public class UserOperationController {
UserTv userTv = new UserTv();
userTv.setMemberCode(memberCode);
userTv.setPlatformAccount(platformAccount);
this.userOperationService.changeMainAccount(userTv);
boolean b = this.userOperationService.changeMainAccount(userTv);
return ResultInfo.success();
return ResultInfo.success(b);
}
@PostMapping(value = "/deleteAllCollection")
......
......@@ -13,13 +13,6 @@ import java.util.List;
public interface PointsOperationService {
/**
* 手动发放积分
* @param memberId 会员id
* @param tempPoints 积分详情
*/
void grantPointsByManual(Long memberId , TempPoints tempPoints);
/**
*
* @param tempPoints
*/
......@@ -44,5 +37,6 @@ public interface PointsOperationService {
* @param memberId
* @return
*/
@Deprecated
Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId);
}
......
package com.topdraw.business.process.service;
import com.topdraw.business.module.rights.history.domain.RightsHistory;
import com.topdraw.business.process.domian.constant.RightType;
import com.topdraw.business.module.rights.constant.RightType;
import java.util.List;
import java.util.Map;
......
......@@ -11,8 +11,18 @@ import com.topdraw.common.ResultInfo;
*/
public interface TaskOperationService {
/**
*
* @param id
* @return
*/
TaskDTO findById(Long id);
/**
*
* @param code
* @return
*/
TaskDTO findByCode(String code);
/**
......@@ -26,25 +36,25 @@ public interface TaskOperationService {
*
* @param task
*/
void createTask(Task task);
TaskDTO createTask(Task task);
/**
*
* @param task
*/
void updateTask(Task task);
TaskDTO updateTask(Task task);
/**
*
* @param task
*/
void deleteTask(Task task);
Integer deleteTask(Task task);
/**
*
* @param id
*/
void deleteTask(Long id);
Integer deleteTask(Long id);
/**
*
......@@ -54,6 +64,4 @@ public interface TaskOperationService {
*/
boolean createPoint2ChongQing(String platformAccount, Long points);
}
......
......@@ -43,6 +43,13 @@ public interface TaskTemplateOperationService {
/**
*
* @param taskTemplate
* @return
*/
Long countByCodeAndType(TaskTemplate taskTemplate);
/**
*
* @param id
* @return
*/
......
......@@ -52,13 +52,13 @@ public interface UserOperationService {
* 大屏解绑
* @param userTv
*/
void tvUnbind(TvUnBindBean userTv);
boolean tvUnbind(TvUnBindBean userTv);
/**
* 大屏切换主账户(会员)
* @param userTv
*/
void changeMainAccount(UserTv userTv);
boolean changeMainAccount(UserTv userTv);
/**
* 微信公众号关注
......@@ -114,20 +114,6 @@ public interface UserOperationService {
/**
*
* @param memberCode
* @param platformAccount
*/
void bind(String memberCode, String platformAccount);
/**
*
* @param memberDTO
* @param userTvDTO
*/
void bind(MemberDTO memberDTO, UserTvDTO userTvDTO);
/**
*
* @param memberDTO
* @param platformAccount
* @return
......@@ -152,7 +138,7 @@ public interface UserOperationService {
* 小屏解绑
* @param weixinUnBindBean
*/
void minaUnbind(WeixinUnBindBean weixinUnBindBean);
boolean minaUnbind(WeixinUnBindBean weixinUnBindBean);
/**
*
......
......@@ -12,6 +12,7 @@ import com.topdraw.business.process.service.CouponOperationService;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.business.process.domian.TempCoupon;
import com.topdraw.business.process.service.RightsOperationService;
import com.topdraw.config.RedisKeyConstants;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -73,7 +74,6 @@ public class CouponOperationServiceImpl implements CouponOperationService {
}
}
/**
* 优惠券领取历史记录表
*
......@@ -92,11 +92,10 @@ public class CouponOperationServiceImpl implements CouponOperationService {
* @param tempCoupon 账号id
*/
private void refreshMemberCoupon(TempCoupon tempCoupon) {
// Long userId = tempCoupon.getUserId();
Long memberId = tempCoupon.getMemberId();
Integer rightsAmount = tempCoupon.getRightsAmount();
try {
this.redisUtils.doLock(RedisKeyConstants.updateCacheCouponByMemberId + memberId.toString());
// 1.历史总优惠券数量
Long historyCouponCount = this.getTotalHistoryCoupon(memberId);
// 1.当前总优惠券数量
......@@ -107,15 +106,12 @@ public class CouponOperationServiceImpl implements CouponOperationService {
Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId, EXPIRE_FACTOR_DAY);
// 4.当前优惠券数量 = 总优惠券-已过期的优惠券
Long currentCoupon = this.getCurrentCoupon(totalCouponCount, expireCouponCount);
this.redisUtils.doLock("right::member::id::" + memberId.toString());
// 5.更新用户信息(优惠券数量、即将过期的优惠券数量)
this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount);
} catch (Exception e) {
e.printStackTrace();
throw e;
log.error(e.getMessage());
} finally {
this.redisUtils.doUnLock("right::member::id::" + memberId.toString());
this.redisUtils.doUnLock(RedisKeyConstants.updateCacheCouponByMemberId + memberId.toString());
}
}
......@@ -134,7 +130,6 @@ public class CouponOperationServiceImpl implements CouponOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
// BeanUtils.copyProperties(memberDTO,member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setCouponAmount(currentCoupon);
......
......@@ -11,6 +11,7 @@ import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.business.process.domian.TempExp;
import com.topdraw.config.RedisKeyConstants;
import com.topdraw.util.IdWorker;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.RedisUtils;
......@@ -76,6 +77,7 @@ public class ExpOperationServiceImpl implements ExpOperationService {
*/
private void refresh(TempExp tempExp) {
try {
this.redisUtils.doLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId());
// 原始经验值
long originExp = this.getExpByMemberId(tempExp);
......@@ -84,7 +86,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
long totalExp = this.calculateTotalExp(originExp, tempExp);
log.info("----计算总经验值 ==>> {}", totalExp);
this.redisUtils.doLock("right::member::id::" + tempExp.getMemberId());
// 2.更新成长值与等级
log.info("----更新会员经验值与对应等级 ==>> {}", totalExp);
this.refreshMemberExpAndLevel(tempExp, totalExp);
......@@ -93,10 +94,9 @@ public class ExpOperationServiceImpl implements ExpOperationService {
this.doInsertExpDetail(tempExp, originExp, totalExp);
} catch (Exception e) {
e.printStackTrace();
throw e;
log.error("成长值发放失败,"+e.getMessage());
} finally {
this.redisUtils.doUnLock("right::member::id::" + tempExp.getMemberId());
this.redisUtils.doUnLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId());
}
}
......@@ -148,7 +148,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
// BeanUtils.copyProperties(memberDTO, member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setExp(totalExp);
......
......@@ -17,6 +17,8 @@ import com.topdraw.business.process.service.dto.CustomPointsResult;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.business.process.service.PointsOperationService;
import com.topdraw.business.process.domian.TempPoints;
import com.topdraw.config.RedisKeyConstants;
import com.topdraw.mq.producer.MessageProducer;
import com.topdraw.util.DateUtil;
import com.topdraw.util.IdWorker;
import com.topdraw.util.TimestampUtil;
......@@ -83,26 +85,13 @@ public class PointsOperationServiceImpl implements PointsOperationService {
public void asyncPointsDetail(PointsDetail pointsDetail) {}
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsByManual(Long memberId, TempPoints tempPoints){
if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) {
MemberDTO memberDTo = this.memberService.findById(memberId);
String memberCode = memberDTo.getCode();
tempPoints.setMemberCode(memberCode);
this.refresh(tempPoints);
}
}
@Override
public void grantPointsByManualByTempPoints(TempPoints tempPoints) {
if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) {
Timestamp expireTime = tempPoints.getExpireTime();
if (Objects.isNull(expireTime)){
tempPoints.setExpireTime(TimestampUtil.localDateTime2Timestamp(DateUtil.getLastDateTimeSecondYear()));
}
this.refresh(tempPoints);
}
}
/**
* 积分消耗
......@@ -118,7 +107,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
Long memberId = tempPoints.getMemberId();
try {
this.redisUtils.doLock("member::id::" + memberId.toString());
this.redisUtils.doLock(RedisKeyConstants.cacheMemberById + memberId.toString());
//1.删除过期的积分
this.cleanInvalidAvailablePointsByMemberId(memberId);
log.info("删除过期的积分 ==>> cleanInvalidAvailablePointsByMemberId ==>> ");
......@@ -153,11 +142,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
customPointsResult.setPoint(currentPoints);
}
}catch (Exception e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
log.error("消耗积分失败,"+e.getMessage());
} finally {
this.redisUtils.doUnLock("member::id::" + memberId.toString());
this.redisUtils.doUnLock(RedisKeyConstants.cacheMemberById + memberId.toString());
}
return customPointsResult;
......@@ -445,7 +433,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
Long memberId = tempPoints.getMemberId();
log.info("----------->> 会员id ===>>>>" + memberId);
try {
this.redisUtils.doLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString());
// 1.可用总积分
Long currentPoints = this.findAvailablePointsByMemberId(memberId);
log.info("----------->> 获取会员当前可用总积分 --->>>> {}", currentPoints);
......@@ -466,8 +454,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints);
this.redisUtils.doLock("right::member::id::" + memberId.toString());
// 6.更新会员的总积分
log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints);
this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints);
......@@ -476,7 +462,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("right::member::id::" + memberId.toString());
this.redisUtils.doUnLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString());
}
}
......@@ -530,7 +516,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
// BeanUtils.copyProperties(memberDTO, member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setPoints(Objects.nonNull(currentPoints) ? currentPoints:0);
......@@ -541,7 +526,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member);
} catch (Exception e){
throw e;
log.error("同步会员积分异常,"+e.getMessage());
}
}
......
......@@ -6,7 +6,8 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory;
import com.topdraw.business.module.rights.history.service.RightsHistoryService;
import com.topdraw.business.module.rights.service.RightsService;
import com.topdraw.business.module.rights.service.dto.RightsDTO;
import com.topdraw.business.process.domian.constant.RightType;
import com.topdraw.business.module.rights.constant.RightType;
import com.topdraw.business.module.rights.constant.RightTypeConstants;
import com.topdraw.business.process.service.CouponOperationService;
import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.business.process.service.PointsOperationService;
......@@ -14,8 +15,6 @@ import com.topdraw.business.process.service.RightsOperationService;
import com.topdraw.business.process.domian.*;
import com.topdraw.util.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
......@@ -24,7 +23,6 @@ import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 权益处理
......@@ -148,54 +146,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
* @param tempRightsMap
*/
private void refresh(Map<RightType, Object> tempRightsMap) {
/*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{
log.info(Thread.currentThread().getName() + "=========>> start");
// 积分
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
log.info(Thread.currentThread().getName() + "=========>>grantPoint end");
// 成长值
// this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
// this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
return null;
});
FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{
// 积分
// this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
// 成长值
this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
// this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
return null;
});
FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{
// 积分
// this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
// 成长值
// this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
return null;
});
this.threadPoolTaskExecutor.execute(futureTask1);
this.threadPoolTaskExecutor.execute(futureTask2);
this.threadPoolTaskExecutor.execute(futureTask3);*/
/*this.threadPoolTaskExecutor.execute(() -> {
// 积分
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
// 成长值
this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
});*/
/*this.threadPoolTaskExecutor.execute(() -> {
log.info(Thread.currentThread().getName() + "=========>> start");
// 积分
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
log.info(Thread.currentThread().getName() + "=========>> end");
});*/
this.threadPoolTaskExecutor.execute(() -> {
List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS);
if (!CollectionUtils.isEmpty(tempPointsList)) {
......@@ -252,7 +203,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
// 活动机会
case ACTIVITYCHANCE:
// TODO MOSS 增加活动机会接口
break;
// 积分商品
......@@ -298,7 +249,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
// 权益类型
RightsDTO rightsDTO = this.getRights(rightId);
// 权益的实体类型 1:积分;2成长值;3优惠券
String type = rightsDTO.getEntityType();
Integer type = rightsDTO.getEntityType();
Long expireTime1 = rightsDTO.getExpireTime();
Timestamp expireTime = null;
if (Objects.nonNull(expireTime1)){
......@@ -307,7 +258,8 @@ public class RightsOperationServiceImpl implements RightsOperationService {
switch (type) {
// 优惠券
case "1":
case RightTypeConstants
.DISCOUNT_COUPON:
Long entityId = rightsDTO.getEntityId();
CouponDTO couponDTO = this.findCouponById(entityId);
if (Objects.nonNull(couponDTO)) {
......@@ -319,16 +271,15 @@ public class RightsOperationServiceImpl implements RightsOperationService {
tempCoupon.setRightsSendStrategy(0);
tempCoupon.setCode(couponDTO.getCode());
if (Objects.nonNull(expireTime))
// tempCoupon.setExpireTime(TimestampUtil.long2LocalDateTime(expireTime));
tempCoupon.setExpireTime(expireTime);
tempCouponList.add(tempCoupon);
}
break;
// 观影券
case "2":
case RightTypeConstants.VIEW_COUPON:
break;
// 活动参与机会
case "3":
case RightTypeConstants.JOIN_ACTIVITY:
break;
default:
......
......@@ -82,6 +82,11 @@ public class TaskTemplateOperationServiceImpl implements TaskTemplateOperationSe
}
@Override
public Long countByCodeAndType(TaskTemplate taskTemplate) {
return this.taskTemplateService.countByCodeAndType(taskTemplate);
}
@Override
public TaskTemplateDTO findById(Long id) {
return this.taskTemplateService.findById(id);
}
......
......@@ -3,58 +3,53 @@ package com.topdraw.business.process.service.impl.member;
import cn.hutool.core.util.ObjectUtil;
import com.topdraw.aspect.AsyncMqSend;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.profile.domain.MemberProfile;
import com.topdraw.business.module.member.profile.service.MemberProfileService;
import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService;
import com.topdraw.business.module.task.domain.Task;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
import com.topdraw.business.module.user.weixin.service.UserWeixinService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.domian.weixin.BuyVipBean;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.business.process.service.member.MemberProfileOperationService;
import com.topdraw.config.RedisKeyConstants;
import com.topdraw.exception.EntityNotFoundException;
import com.topdraw.util.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;
@Service
//@CacheConfig(cacheNames = "member")
@Slf4j
@CacheConfig(cacheNames = RedisKeyConstants.cacheMemberById)
public class MemberOperationServiceImpl implements MemberOperationService {
@Autowired
private MemberService memberService;
@Autowired
private UserWeixinService userWeixinService;
@Autowired
private MemberProfileService memberProfileService;
@Autowired
private MemberVipHistoryService memberVipHistoryService;
@Autowired
private UserWeixinService userWeixinService;
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@AsyncMqSend
public void asyncUpdateMemberVip(MemberDTO me) {}
public void asyncUpdateMemberVip(MemberDTO memberDTO) {}
// @CachePut(key = "#resources.memberId")
@Override
public MemberDTO buyVipByUserId(BuyVipBean resources) {
// 小程序账户id
......@@ -96,12 +91,12 @@ public class MemberOperationServiceImpl implements MemberOperationService {
}
memberDTO.setVip(vip1);
memberDTO.setVipExpireTime(vipExpireTime);
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
this.update(member);
member.setVip(vip1);
member.setVipExpireTime(vipExpireTime);
this.doUpdateMemberVipAndVipExpireTime(member);
MemberVipHistory memberVipHistory = new MemberVipHistory();
memberVipHistory.setMemberId(memberId).setVip(vip1).setBeforeVip(vip);
......@@ -148,7 +143,6 @@ public class MemberOperationServiceImpl implements MemberOperationService {
return this.update(resources);
}
// @CachePut(key = "#resources.id")
@Override
public MemberDTO doInsertMember(Member resources) {
return this.memberService.create(resources);
......@@ -160,34 +154,39 @@ public class MemberOperationServiceImpl implements MemberOperationService {
return Objects.nonNull(memberId) ? memberDTO : null;
}
// @CachePut(key = "#resources.id")
@Override
public MemberDTO doUpdateMemberExpAndLevel(Member resources) {
return this.memberService.doUpdateMemberExpAndLevel(resources);
}
// @CachePut(key = "#resources.id")
@Override
public MemberDTO doUpdateMemberPoints(Member resources) {
return this.memberService.doUpdateMemberPoints(resources);
}
// @CachePut(key = "#resources.id")
@Override
@CachePut(cacheNames = RedisKeyConstants.cacheMemberById, key = "#member.id")
public MemberDTO doUpdateMemberCoupon(Member member) {
return this.memberService.doUpdateMemberCoupon(member);
}
@Override
public MemberDTO updateMemberVip(Member member) {
// @CachePut(cacheNames = RedisKeyConstants.cacheMemberById, key = "#member.id")
public MemberDTO doUpdateMemberVipAndVipExpireTime(Member member) {
MemberDTO memberDTO1 = this.memberService.findByCode(member.getCode());
Member member1 = new Member();
BeanUtils.copyProperties(memberDTO1, member1);
member1.setId(memberDTO1.getId());
member1.setCode(memberDTO1.getCode());
member1.setVip(member.getVip());
member1.setVipExpireTime(member.getVipExpireTime());
MemberDTO memberDTO = this.update(member1);
((MemberOperationServiceImpl) AopContext.currentProxy()).asyncUpdateMemberVip(memberDTO);
return memberDTO;
MemberDTO memberDTO_ = this.memberService.doUpdateMemberVipAndVipExpireTime(member1);
((MemberOperationServiceImpl) AopContext.currentProxy()).asyncUpdateMemberVip(memberDTO_);
return memberDTO_;
}
@Override
......@@ -225,11 +224,12 @@ public class MemberOperationServiceImpl implements MemberOperationService {
MemberDTO memberDTO1 = this.checkVipStatus(memberDTO,vipExpireTime,appid);
// 更新会员信息
this.threadPoolTaskExecutor.execute(()->{
Member member = new Member();
BeanUtils.copyProperties(memberDTO1,member);
this.update(member);
});
member.setId(memberDTO1.getId());
member.setCode(memberDTO1.getCode());
member.setVip(memberDTO1.getVip());
member.setVipExpireTime(memberDTO1.getVipExpireTime());
this.doUpdateMemberVipAndVipExpireTime(member);
vip = memberDTO1.getVip();
Timestamp vipExpireTime1 = memberDTO1.getVipExpireTime();
......
......@@ -111,12 +111,15 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation
}
private void syncMember(MemberProfileDTO memberProfileDTO, MemberDTO memberDTO) {
memberDTO.setAvatarUrl(memberProfileDTO.getAvatarUrl());
memberDTO.setNickname(memberProfileDTO.getRealname());
memberDTO.setGender(memberProfileDTO.getGender());
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
this.memberService.update(member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setAvatarUrl(memberProfileDTO.getAvatarUrl());
member.setNickname(memberProfileDTO.getRealname());
member.setGender(memberProfileDTO.getGender());
// this.memberService.update(member);
this.memberService.doUpdateMemberAvatarUrlAndNicknameAndGender(member);
}
......
......@@ -90,5 +90,5 @@ public interface MemberOperationService {
*
* @param member
*/
MemberDTO updateMemberVip(Member member);
MemberDTO doUpdateMemberVipAndVipExpireTime(Member member);
}
......
......@@ -28,4 +28,10 @@ public class LocalConstants {
// 事件类型 3:参加活动
public static final Integer EVT_TYPE_ACTIVITY = 3;
// 会员黑名单状态
public static final Long BLACK_STATUS = 1L;
}
......
package com.topdraw.config;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class ServiceEnvConfig {
// uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧
public static String UC_SERVICE_TYPE;
@Value("${uc.service.type:mobile}")
public void setUcServiceType(String ucServiceType) {
UC_SERVICE_TYPE = ucServiceType;
}
public static boolean isMobile() {
return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_MOBILE);
}
public static boolean isVis() {
return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS);
}
}
......@@ -23,10 +23,9 @@ public class DataSyncMsg implements Serializable {
// 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
private Integer event;
//设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
@NotNull
private Integer deviceType;
// 发送时间
private LocalDateTime time;
private String time;
// 消息体
private String msgData;
......@@ -37,20 +36,32 @@ public class DataSyncMsg implements Serializable {
@AllArgsConstructor
@NoArgsConstructor
public static class MsgData {
private String remarks; //备注
@NotNull
private Long memberId; // 会员id
private Long userId; // 账户id
@NotNull
private String appCode; //用户对应的应用code
/**备注*/
private String remarks;
// 会员id
private Long memberId;
// 账户id
private Long userId;
//用户对应的应用code
private String appCode;
// 会员code
private String memberCode;
private Long accountId; // 账号id
// 账号id
private Long accountId;
// 订单Id
private Long orderId;
// 活动id
private Long activityId;
// 节目id
private Long mediaId;
// 产品id
private Long itemId;
// 模板参数
private String param;
// 描述
private String description;
// 大屏账号
private String platformAccount;
}
}
......
package com.topdraw.mq.producer;
import com.topdraw.business.process.service.impl.PointsOperationServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -57,4 +59,5 @@ public class MessageProducer {
amqpTemplate.convertAndSend(exchange, queue, msg);
log.info("send sendMessage msg || exchange: {} || queue: {} || msg:{} ", exchange, queue, msg);
}
}
......
......@@ -143,3 +143,7 @@ weixin:
api:
uc-service: http://127.0.0.1:8446
uc:
# 主会员是否启用,如果启用任务获得的积分将添加至小屏会员上
validPriorityMember: 0
\ No newline at end of file
......
......@@ -179,6 +179,13 @@ public class TaskOperationControllerTest extends BaseTest {
this.taskOperationController.deleteTask(task);
}
@Test
public void dealTask() {
String content = "{\"deviceType\":1,\"event\":8,\"evt\":\"PLAY\",\"msgData\":\"{\\\"description\\\":\\\"{\\\\\\\"playDuration\\\\\\\":1,\\\\\\\"time\\\\\\\":\\\\\\\"2022-05-03 23:10:09\\\\\\\",\\\\\\\"mediaId\\\\\\\":432,\\\\\\\"mediaCode\\\\\\\":\\\\\\\"media_123\\\\\\\",\\\\\\\"mediaName\\\\\\\":\\\\\\\"白宫陷落\\\\\\\"}\\\",\\\"mediaId\\\":432,\\\"platformAccount\\\":\\\"6002110106@ITVP\\\",\\\"param\\\":\\\"{\\\\\\\"playDuration\\\\\\\":1}\\\"}\",\"time\":\"2022-06-17T13:07:16.433\"}\n";
TaskOperationQueryCriteria task = new TaskOperationQueryCriteria();
task.setContent(content);
this.taskOperationController.dealTask(task);
}
}
......