Commit 202d49bc 202d49bc18fb80c855aa2af20361c2c6aa5005a1 by xianghan

1.修改任务处理消息结构

2.新增分享数据统计功能
1 parent 71ce5729
Showing 19 changed files with 400 additions and 35 deletions
......@@ -45,4 +45,5 @@ public class UserWeixinController {
return ResultInfo.success();
}
}
......
package com.topdraw.weixin.subscribe.domain;
package com.topdraw.business.module.user.weixin.subscribe.domain;
import lombok.Data;
import lombok.experimental.Accessors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.sql.Timestamp;
import java.util.UUID;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
......
package com.topdraw.weixin.subscribe.repository;
package com.topdraw.business.module.user.weixin.subscribe.repository;
import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
......
package com.topdraw.weixin.subscribe.service;
package com.topdraw.business.module.user.weixin.subscribe.service;
import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
/**
* @author XiangHan
......
package com.topdraw.weixin.subscribe.service.dto;
package com.topdraw.business.module.user.weixin.subscribe.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
import java.sql.Timestamp;
/**
......
package com.topdraw.weixin.subscribe.service.impl;
package com.topdraw.business.module.user.weixin.subscribe.service.impl;
import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.weixin.subscribe.repository.WechatSubscribeRecordRepository;
import com.topdraw.weixin.subscribe.service.WechatSubscribeRecordService;
import com.topdraw.weixin.subscribe.service.mapper.WechatSubscribeRecordMapper;
import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.business.module.user.weixin.subscribe.repository.WechatSubscribeRecordRepository;
import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService;
import com.topdraw.business.module.user.weixin.subscribe.service.mapper.WechatSubscribeRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
......
package com.topdraw.weixin.subscribe.service.mapper;
package com.topdraw.business.module.user.weixin.subscribe.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.weixin.subscribe.service.dto.WechatSubscribeRecordDTO;
import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.business.module.user.weixin.subscribe.service.dto.WechatSubscribeRecordDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......
package com.topdraw.business.module.user.weixin.wechatshare.domain;
import lombok.Data;
import lombok.experimental.Accessors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.sql.Timestamp;
import java.util.UUID;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-06
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_wechat_share_record")
public class WechatShareRecord implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 标识
@Column(name = "code", nullable = false)
private String code;
// 微信账号id
@Column(name = "user_id")
private Long userId;
// 会员id
@Column(name = "member_id", nullable = false)
private Long memberId;
// 会员code
@Column(name = "member_code", nullable = false)
private String memberCode;
// 实例id
@Column(name = "entity_id")
private Long entityId;
// 实例code
@Column(name = "entity_code")
private String entityCode;
// 实例类型 1:营销活动;2:小程序;3:商品;4:投票对象;5:文章;6:视频;99:其他;
@Column(name = "entity_type")
private Long entityType;
// 分享对象 1:朋友;2:朋友圈;99:其他;
@Column(name = "share_type")
private Integer shareType;
// 分享对象昵称
@Column(name = "share_to")
private String shareTo;
// 分享对象查看次数
@Column(name = "click_count")
private Long clickCount;
// 分享对象查看次数
@Column(name = "share_count")
private Long shareCount;
// 来源描述
@Column(name = "source_info")
private String sourceInfo;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(WechatShareRecord source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.weixin.wechatshare.repository;
import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
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 java.util.Optional;
/**
* @author XiangHan
* @date 2022-06-06
*/
public interface WechatShareRecordRepository extends JpaRepository<WechatShareRecord, Long>, JpaSpecificationExecutor<WechatShareRecord> {
Optional<WechatShareRecord> findFirstByCode(String code);
Optional<WechatShareRecord> findFirstByMemberCodeAndEntityCode(String memberCode, String entityCode);
@Modifying
@Query(value = "UPDATE uc_wechat_share_record SET `share_count` = ?2 WHERE id = ?1", nativeQuery = true)
void updateShareCount(Long id, long l);
}
package com.topdraw.business.module.user.weixin.wechatshare.rest;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.common.ResultInfo;
import com.topdraw.annotation.Log;
import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
import com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
/**
* @author XiangHan
* @date 2022-06-06
*/
@Api(tags = "WechatShareRecord管理")
@RestController
@RequestMapping("/uce/wechatShareRecord/")
@Slf4j
public class WechatShareRecordController {
@Autowired
private WechatShareRecordService wechatShareRecordService;
@Log
@PostMapping(value = "/create")
@ApiOperation("新增WechatShareRecord")
public ResultInfo create(@Validated @RequestBody WechatShareRecord resources) {
this.wechatShareRecordService.create(resources);
return ResultInfo.success();
}
@Log
@PostMapping(value = "/update")
@ApiOperation("修改WechatShareRecord")
public ResultInfo update(@Validated @RequestBody WechatShareRecord resources) {
this.wechatShareRecordService.update(resources);
return ResultInfo.success();
}
@Log
@PostMapping(value = "/createOrUpdate")
@ApiOperation("修改WechatShareRecord")
public ResultInfo createOrUpdate(@Validated @RequestBody String content) {
log.info("wechatShareRecord ==>> createOrUpdate ==>> {}",content);
WechatShareRecord wechatShareRecord = JSONObject.parseObject(content, WechatShareRecord.class);
this.wechatShareRecordService.createOrUpdate(wechatShareRecord);
return ResultInfo.success();
}
@GetMapping(value = "/getByCode")
@ApiOperation(value = "根据标识查询")
public ResultInfo getByCode(@RequestParam(value = "code") String code) {
return ResultInfo.success(this.wechatShareRecordService.getByCode(code));
}
}
package com.topdraw.business.module.user.weixin.wechatshare.service;
import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
import com.topdraw.business.module.user.weixin.wechatshare.service.dto.WechatShareRecordDTO;
/**
* @author XiangHan
* @date 2022-06-06
*/
public interface WechatShareRecordService {
/**
* 根据ID查询
* @param id ID
* @return WechatShareRecordDTO
*/
WechatShareRecordDTO findById(Long id);
/**
*
* @param resources
*/
void create(WechatShareRecord resources);
/**
*
* @param resources
*/
void update(WechatShareRecord resources);
/**
* Code校验
* @param code
* @return WechatShareRecordDTO
*/
WechatShareRecordDTO getByCode(String code);
void createOrUpdate(WechatShareRecord resources);
}
package com.topdraw.business.module.user.weixin.wechatshare.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-06
*/
@Data
public class WechatShareRecordDTO implements Serializable {
// ID
private Long id;
// 标识
private String code;
// 微信账号id
private Long userId;
// 会员id
private Long memberId;
// 会员code
private String memberCode;
// 实例id
private Long entityId;
// 实例code
private String entityCode;
// 实例类型 1:营销活动;2:小程序;3:商品;4:投票对象;5:文章;6:视频;99:其他;
private Long entityType;
// 分享对象 1:朋友;2:朋友圈;99:其他;
private Integer shareType;
// 分享对象昵称
private String shareTo;
// 分享对象查看次数
private Long clickCount;
// 分享次数
private Long shareCount;
// 来源描述
private String sourceInfo;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
}
package com.topdraw.business.module.user.weixin.wechatshare.service.impl;
import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
import com.topdraw.util.IdWorker;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.user.weixin.wechatshare.repository.WechatShareRecordRepository;
import com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService;
import com.topdraw.business.module.user.weixin.wechatshare.service.dto.WechatShareRecordDTO;
import com.topdraw.business.module.user.weixin.wechatshare.service.mapper.WechatShareRecordMapper;
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 com.topdraw.utils.StringUtils;
import java.util.*;
/**
* @author XiangHan
* @date 2022-06-06
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class WechatShareRecordServiceImpl implements WechatShareRecordService {
@Autowired
private WechatShareRecordRepository wechatShareRecordRepository;
@Autowired
private WechatShareRecordMapper wechatShareRecordMapper;
@Override
public WechatShareRecordDTO findById(Long id) {
WechatShareRecord wechatShareRecord = this.wechatShareRecordRepository.findById(id).orElseGet(WechatShareRecord::new);
ValidationUtil.isNull(wechatShareRecord.getId(),"WechatShareRecord","id",id);
return this.wechatShareRecordMapper.toDto(wechatShareRecord);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(WechatShareRecord resources) {
this.wechatShareRecordRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(WechatShareRecord resources) {
WechatShareRecord wechatShareRecord = this.wechatShareRecordRepository.findById(resources.getId()).orElseGet(WechatShareRecord::new);
ValidationUtil.isNull( wechatShareRecord.getId(),"WechatShareRecord","id",resources.getId());
wechatShareRecord.copy(resources);
this.wechatShareRecordRepository.save(wechatShareRecord);
}
@Override
public WechatShareRecordDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ?
this.wechatShareRecordMapper.toDto(this.wechatShareRecordRepository.findFirstByCode(code).orElseGet(WechatShareRecord::new))
: new WechatShareRecordDTO();
}
@Transactional(rollbackFor = Exception.class)
@Override
public void createOrUpdate(WechatShareRecord resources) {
String memberCode = resources.getMemberCode();
Long memberId = resources.getMemberId();
String entityCode = resources.getEntityCode();
Long entityId = resources.getEntityId();
WechatShareRecord wechatShareRecord =
this.wechatShareRecordRepository.findFirstByMemberCodeAndEntityCode(memberCode, entityCode).orElseGet(WechatShareRecord::new);
if (Objects.isNull(wechatShareRecord.getId())) {
resources.setCode(IdWorker.generatorString());
resources.setShareCount(1L);
resources.setClickCount(0L);
this.create(resources);
} else {
Long id = wechatShareRecord.getId();
Long shareCount = wechatShareRecord.getShareCount();
if (Objects.isNull(shareCount))
shareCount = 0L;
this.wechatShareRecordRepository.updateShareCount(id, shareCount+1);
}
}
}
package com.topdraw.business.module.user.weixin.wechatshare.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
import com.topdraw.business.module.user.weixin.wechatshare.service.dto.WechatShareRecordDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-06-06
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface WechatShareRecordMapper extends BaseMapper<WechatShareRecordDTO, WechatShareRecord> {
}
......@@ -26,6 +26,8 @@ import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository;
import com.topdraw.business.module.user.weixin.service.UserWeixinService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria;
import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService;
import com.topdraw.business.process.domian.weixin.*;
import com.topdraw.business.process.service.UserOperationService;
import com.topdraw.business.process.service.dto.MemberAndUserTvDTO;
......@@ -37,13 +39,10 @@ import com.topdraw.exception.BadRequestException;
import com.topdraw.exception.EntityNotFoundException;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.resttemplate.RestTemplateClient;
import com.topdraw.util.Base64Util;
import com.topdraw.util.IdWorker;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.RedisUtils;
import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.weixin.subscribe.service.WechatSubscribeRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.aop.framework.AopContext;
......@@ -58,7 +57,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.util.CollectionUtils;
import springfox.documentation.spring.web.json.Json;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
......
......@@ -39,13 +39,9 @@ public class DataSyncMsg implements Serializable {
public static class MsgData {
private String remarks; //备注
@NotNull
private Integer event; // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
@NotNull
private Long memberId; // 会员id
private Long userId; // 账户id
@NotNull
private Integer deviceType; //设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
@NotNull
private String appCode; //用户对应的应用code
private String memberCode;
private Long accountId; // 账号id
......
......@@ -39,16 +39,16 @@ public class GeneratorCode extends BaseTest {
@Rollback(value = false)
@Transactional(rollbackFor = Exception.class)
public void generator() {
var dbName = "uc_wechat_subscribe_record";
var dbName = "uc_wechat_share_record";
// 表名称,支持多表
var tableNames = Arrays.asList(dbName);
String[] s = dbName.split("_");
var pre = s[0];
var target1 = s[s.length-1];
var preRoute = "com.topdraw.weixin.";
var preRoute = "com.topdraw.business.module.user.weixin.";
StringBuilder builder = new StringBuilder(preRoute);
builder.append("subscribe");
builder.append("wechatshare");
// builder.append(target);
tableNames.forEach(tableName -> {
......
......@@ -20,10 +20,8 @@ public class TaskOperationServiceTest extends BaseTest {
// dataSyncMsg.setEntityType(EntityType.MEMBER);
dataSyncMsg.setEvt(EventType.LOGIN.name());
DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
msgData.setEvent(1);
msgData.setRemarks("remark");
msgData.setMemberId(memberId);
msgData.setDeviceType(2);
msgData.setAppCode("WEI_XIN_GOLD_PANDA");
dataSyncMsg.setMsg(msgData);
......
......@@ -23,10 +23,8 @@ public class MqTest extends BaseTest {
// dataSyncMsg.setEventType(EventType.LOGIN.name());
dataSyncMsg.setEvt(EventType.LOGIN.name());
DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
msgData.setEvent(1);
msgData.setRemarks("remark");
msgData.setMemberId(1L);
msgData.setDeviceType(2);
msgData.setAppCode("WEI_XIN_GOLD_PANDA");
dataSyncMsg.setMsg(msgData);
String s = JSON.toJSONString(dataSyncMsg);
......