Commit dc92cdb4 dc92cdb47ec862073bd2dd522e583070f9038121 by xianghan

1.优化

1 parent e81bd386
Showing 14 changed files with 109 additions and 27 deletions
......@@ -12,6 +12,8 @@ import com.topdraw.common.ResultInfo;
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;
import org.springframework.web.bind.annotation.*;
......@@ -61,6 +63,13 @@ public class MemberController {
public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody Member resources) {
log.info("member ==>> update ==>> param ==>> [{}]",resources);
String code = resources.getCode();
if (StringUtils.isNotBlank(code)) {
MemberDTO memberDTO = this.memberOperationService.findByCode(code);
resources.setId(memberDTO.getId());
// BeanUtils.copyProperties(resources, memberDTO);
}
MemberDTO memberDTO = this.memberOperationService.update(resources);
return ResultInfo.success(memberDTO);
}
......
package com.topdraw.business.module.member.viphistory.rest;
import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.common.ResultInfo;
import io.swagger.annotations.Api;
......
......@@ -55,10 +55,12 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService {
@AsyncMqSend
public void create(MemberVipHistory resources) {
log.info("MemberVipHistoryServiceImpl ==>> MemberVipHistoryServiceImpl ==>> param ==>> [{}]",resources);
this.checkMember(resources);
MemberDTO memberDTO = this.checkMember(resources);
MemberVipHistory memberVipHistory = MemberVipHistoryBuilder.build(resources);
this.memberVipHistoryRepository.save(memberVipHistory);
MemberVipHistory vipHistory = this.memberVipHistoryRepository.save(memberVipHistory);
vipHistory.setMemberCode(memberDTO.getCode());
}
@Override
......
......@@ -16,4 +16,5 @@ public interface UserCollectionRepository extends JpaRepository<UserCollection,
List<UserCollection> findByUserIdAndType(Long userId, Integer type);
Optional<UserCollection> findFirstByUserIdAndTypeAndName(Long userId, Integer type, String name);
}
......
......@@ -63,7 +63,7 @@ public interface UserCollectionService {
* @param name
* @return
*/
Optional<UserCollection> findFirstByUserIdAndTypeAndName(Long id, Integer type, String name);
UserCollection findFirstByUserIdAndTypeAndName(Long id, Integer type, String name);
/**
*
......
......@@ -88,8 +88,10 @@ public class UserCollectionServiceImpl implements UserCollectionService {
}
@Override
public Optional<UserCollection> findFirstByUserIdAndTypeAndName(Long id, Integer type, String name) {
return Optional.empty();
public UserCollection findFirstByUserIdAndTypeAndName(Long id, Integer type, String name) {
UserCollection userCollection =
this.userCollectionRepository.findFirstByUserIdAndTypeAndName(id, type, name).orElseGet(UserCollection::new);
return userCollection;
}
@Override
......
......@@ -16,6 +16,8 @@ import java.sql.Timestamp;
@Data
public class MemberOperationBean {
private String memberCode;
private Long memberId;
private Integer vip;
......
......@@ -54,6 +54,41 @@ public class MemberOperationController {
return ResultInfo.success();
}
@RequestMapping(value = "/updateVipByMemberCode")
@ApiOperation("手动修改vip")
@AnonymousAccess
public ResultInfo updateVipByMemberCode(@Validated(value = {UpdateGroup.class}) @RequestBody MemberOperationBean resources) {
log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources);
Integer vip = resources.getVip();
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.setVip(vip);
}
if (Objects.nonNull(vipExpireTime)) {
member.setVipExpireTime(vipExpireTime);
}
this.createVipHistory(memberDTO.getId(), vip, vipExpireTime);
this.memberOperationService.update(member);
return ResultInfo.success();
}
private void createVipHistory(Long memberId, Integer vip , Timestamp vipExpireTime){
BuyVipBean buyVipBean = new BuyVipBean();
buyVipBean.setMemberId(memberId);
buyVipBean.setVip(vip);
buyVipBean.setVipExpireTime(vipExpireTime);
this.memberOperationService.buyVipByMemberId(buyVipBean);
}
@GetMapping("/getMemberProfileAndCheckVip/{appId}/{memberId}")
@ApiOperation("获取会员基本信息并且检查vip状态")
@AnonymousAccess
......@@ -65,9 +100,10 @@ public class MemberOperationController {
@PutMapping("/buyVip")
@ApiOperation("购买vip")
@AnonymousAccess
@Deprecated
public ResultInfo buyVip(@RequestBody BuyVipBean buyVipBean) {
// 小程序账户id
/* // 小程序账户id
Long id = buyVipBean.getId();
if (Objects.isNull(id))
throw new BadRequestException("参数异常: id is null !");
......@@ -78,7 +114,8 @@ public class MemberOperationController {
throw new BadRequestException("vip 等级有误");
MemberDTO memberDTO = this.memberOperationService.buyVip(buyVipBean);
return ResultInfo.success(memberDTO);
return ResultInfo.success(memberDTO);*/
return null;
}
}
......
......@@ -81,6 +81,7 @@ public class UserOperationController {
Integer vip = resources.getVip();
Timestamp vipExpireTime = resources.getVipExpireTime();
// 微信账号id
Long userId = resources.getUserId();
UserWeixinDTO userWeixinDTO = this.userOperationService.findById(userId);
......@@ -96,11 +97,22 @@ public class UserOperationController {
member.setVipExpireTime(vipExpireTime);
}
this.createVipHistory(userId, vip, vipExpireTime);
this.memberOperationService.update(member);
return ResultInfo.success();
}
private void createVipHistory(Long weixinUserId, Integer vip , Timestamp vipExpireTime){
BuyVipBean buyVipBean = new BuyVipBean();
buyVipBean.setId(weixinUserId);
buyVipBean.setVip(vip);
buyVipBean.setVipExpireTime(vipExpireTime);
this.memberOperationService.buyVipByUserId(buyVipBean);
}
@PostMapping(value = "/createWeixinUserAndCreateMember")
@ApiOperation("新增小屏账户同时创建会员信息")
@AnonymousAccess
......
......@@ -61,6 +61,7 @@ import org.springframework.util.CollectionUtils;
import springfox.documentation.spring.web.json.Json;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
......@@ -708,6 +709,11 @@ public class UserOperationServiceImpl implements UserOperationService {
@Override
public boolean deleteCollection(String content) {
try {
//处理接口调用 中文不显示问题
content = new String(Base64.getDecoder().decode(content.getBytes(StandardCharsets.UTF_8)));
log.info("receive addCollection add message, content {}", content);
JSONObject jsonObject = JSONObject.parseObject(content);
String platformAccount = jsonObject.getString("platformAccount");
String data = jsonObject.getString("data");
......@@ -733,10 +739,9 @@ public class UserOperationServiceImpl implements UserOperationService {
userCollectionMq.setName("DEFAULT");
}
Optional<UserCollection> userCollectionOptional =
UserCollection userCollection =
this.userCollectionService.findFirstByUserIdAndTypeAndName(id, userCollectionMq.getType(),
userCollectionMq.getName());
UserCollection userCollection = userCollectionOptional.orElseGet(UserCollection::new);
int count = 0;
for (UserCollectionMq collectionMq : value) {
......@@ -770,9 +775,9 @@ public class UserOperationServiceImpl implements UserOperationService {
public boolean addCollection(String content) {
try {
//处理接口调用 中文不显示问题
//content = new String(Base64.getDecoder().decode(content.getBytes(StandardCharsets.UTF_8)));
content = new String(Base64.getDecoder().decode(content.getBytes(StandardCharsets.UTF_8)));
log.info("receive UserCollection add message, content {}", content);
log.info("receive addCollection add message, content {}", content);
JSONObject jsonObject = JSONObject.parseObject(content);
String platformAccount = jsonObject.getString("platformAccount");
......@@ -801,21 +806,25 @@ public class UserOperationServiceImpl implements UserOperationService {
UserCollection userCollection = this.userCollectionService
.findFirstByUserIdAndTypeAndName(tvUserId, userCollectionMq.getType(), userCollectionMq.getName()).orElseGet(UserCollection::new);
.findFirstByUserIdAndTypeAndName(tvUserId, userCollectionMq.getType(), userCollectionMq.getName());
if (Objects.isNull(userCollection.getId())) {
userCollection.setAppId(userCollectionMq.getAppId())
.setUserId(tvUserId)
.setName(userCollectionMq.getName())
.setType(userCollectionMq.getType())
.setCount(userCollection.getCount() == null ? value.size() : userCollection.getCount() + value.size());
log.info("userCollection ==>> [{}]",userCollection);
UserCollection userCollectionSave = this.userCollectionService.save(userCollection);
userCollection = this.userCollectionService.save(userCollection);
}
for (UserCollectionMq collectionMq : value) {
UserCollectionDetail userCollectionDetail = collectionMq2DetailMapper.toEntity(collectionMq);
Optional<UserCollectionDetail> userCollectionDetailOptional = userCollectionDetailRepository
.findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(), userCollectionDetail.getDetailType(), userCollectionSave.getId());
.findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(),
userCollectionDetail.getDetailType(), userCollection.getId());
//观影记录同一天只存一条记录
if (userCollectionDetailOptional.isPresent() &&
DateUtil.isSameDay(new Date(userCollectionDetailOptional.get().getCreateTime().getTime()), new Date())) {
......@@ -825,7 +834,7 @@ public class UserOperationServiceImpl implements UserOperationService {
} else {
userCollectionDetail.setId(null)
.setUserCollectionId(userCollectionSave.getId());
.setUserCollectionId(userCollection.getId());
}
......
......@@ -50,18 +50,23 @@ public class MemberOperationServiceImpl implements MemberOperationService {
// @CachePut(key = "#resources.memberId")
@Override
public MemberDTO buyVip(BuyVipBean resources) {
public MemberDTO buyVipByUserId(BuyVipBean resources) {
// 小程序账户id
Long id = resources.getId();
// 过期时间
Timestamp vipExpireTime1 = resources.getVipExpireTime();
Integer vip1 = resources.getVip();
// 查询微信账户
UserWeixinDTO userWeixin = this.findWeiXinById(id);
Long memberId = userWeixin.getMemberId();
resources.setMemberId(memberId);
return this.buyVipByMemberId(resources);
}
@Override
public MemberDTO buyVipByMemberId(BuyVipBean resources) {
Timestamp vipExpireTime1 = resources.getVipExpireTime();
Integer vip1 = resources.getVip();
Long memberId = resources.getMemberId();
//
MemberDTO memberDTO = this.findById(memberId);
String memberCode = memberDTO.getCode();
......
......@@ -35,7 +35,14 @@ public interface MemberOperationService {
* @param resources
* @return
*/
MemberDTO buyVip(BuyVipBean resources);
MemberDTO buyVipByUserId(BuyVipBean resources);
/**
*
* @param resources
* @return
*/
MemberDTO buyVipByMemberId(BuyVipBean resources);
/**
*
......
......@@ -22,9 +22,6 @@ public class DataSyncMsg implements Serializable {
// 消息体
private MsgData msg;
// 其他属性
private String extraData;
/**
* 消息体
*/
......
......@@ -68,7 +68,7 @@ spring:
# publisher-confirms: true #如果对异步消息需要回调必须设置为true
host: 122.112.214.149 # rabbitmq的连接地址
port: 5672 # rabbitmq的连接端口号
virtual-host: member_center # rabbitmq的虚拟hosthhh
virtual-host: member_center_small_sichuan # rabbitmq的虚拟hosthhh
username: guest # rabbitmq的用户名
password: guest # rabbitmq的密码
publisher-confirms: true #如果对异步消息需要回调必须设置为true
......