Commit 8189259a 8189259af592c47545929f81786d211967df96e0 by xianghan

Merge branch '2.2.0-release'

# Conflicts:
#	.gitignore
#	member-service-impl/src/main/java/com/topdraw/business/module/member/domain/Member.java
#	member-service-impl/src/main/java/com/topdraw/business/module/member/repository/MemberRepository.java
#	member-service-impl/src/main/java/com/topdraw/business/module/member/service/impl/MemberServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/domian/constant/RightType.java
#	member-service-impl/src/main/java/com/topdraw/business/process/rest/TaskOperationController.java
#	member-service-impl/src/main/java/com/topdraw/business/process/rest/UserOperationController.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/CouponOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/ExpOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/PointsOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/RightsOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/TaskOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/UserOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/mq/module/mq/DataSyncMsg.java
#	member-service-impl/src/main/resources/config/application-dev.yml
#	member-service-impl/src/test/java/com/topdraw/test/business/process/rest/TaskOperationControllerTest.java
#	member-service-impl/src/test/java/com/topdraw/test/business/process/service/TaskOperationServiceTest.java
#	member-service-impl/src/test/java/com/topdraw/test/mq/MqTest.java
2 parents 7d0ef571 4fb34343
Showing 200 changed files with 2670 additions and 209 deletions
......@@ -3,4 +3,4 @@
/logs/
/member-service-impl/target/
/member-service-api/target/
member-service.iml
/.member-service.iml
\ No newline at end of file
......
package com.topdraw.config;
package com.topdraw.business;
public class LocalConstants {
......@@ -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.business;
/**
* @author :
* @description:\
* @function :
* @date :Created in 2022/6/18 13:25
* @version: :
* @modified By:
* @since : modified in 2022/6/18 13:25
*/
public interface RedisKeyConstants {
// 全量会员信息
String cacheMemberById = "uce::member::id";
// 任务处理时会员信息
String cacheMemberSimpleById = "uce::memberSimple::id";
String cacheMemberSimpleByCode = "uce::memberSimple::code";
// 会员全量信息
String cacheMemberByCode = "uce::member::code";
// 修改会员积分时的分布式锁
String updateCachePointsByMemberId = "uce::updatePoints::memberId";
// 修改会员成长值时的分布式锁
String updateCacheExpByMemberId = "uce::updateExp::memberId";
// 修改会员优惠券时的分布式锁
String updateCacheCouponByMemberId = "uce::updateCoupon::memberId";
// 全量大屏信息
String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount";
String cacheVisUserByPlatformAccount = "uus::visUser";
// 会员已完成的任务进度
String cacheTaskProcessByMemberId = "uce::taskProcess::memberId";
// 任务模板类型对应的全量任务
String cacheTaskByEvent = "uce::task::event";
// 全量优惠券信息
String cacheCouponById = "uce::coupon::id";
// 权益全量信息
String cacheRightById = "uce::right::id";
// 会员可以做的任务
String cacheTaskByEventAndMemberLevelAndVip = "uce::task::eventAndMemberLevelAndVip";
// 全量会员等级
String cacheMemberLevelByLevel = "uce::memberLevel::level";
// 今天处理完成任务数量
String cacheTodayFinishTaskCount = "uce::todayCount::memberId";
// 历史完成的任务数量
String cacheTotalFinishTaskCount = "uce::totalCount::memberId";
String CACHE_PLATFROMACCOUNT_PLAYDURATION = "uce::eventPlay::playduration";
String CACHE_TODAY_FINISH_COUNT = "todayFinishCount";
String CACHE_TOTAL_FINISH_COUNT = "totalFinishCount";
}
package com.topdraw.business.module.coupon.service.impl;
import com.topdraw.business.module.coupon.domain.Coupon;
import com.topdraw.business.RedisKeyConstants;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.coupon.repository.CouponRepository;
import com.topdraw.business.module.coupon.service.CouponService;
import com.topdraw.business.module.coupon.service.dto.CouponDTO;
import com.topdraw.business.module.coupon.service.mapper.CouponMapper;
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;
......@@ -30,9 +31,9 @@ public class CouponServiceImpl implements CouponService {
private CouponRepository couponRepository;
@Override
@Cacheable(cacheNames = RedisKeyConstants.cacheCouponById, key = "#id", unless = "#result.id == null")
public CouponDTO findById(Long id) {
Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL);
Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new);
// ValidationUtil.isNull(coupon.getId(),"Coupon","id",id);
return this.couponMapper.toDto(coupon);
......
......@@ -3,6 +3,9 @@ package com.topdraw.business.module.exp.detail.repository;
import com.topdraw.business.module.exp.detail.domain.ExpDetail;
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 java.util.Optional;
......@@ -13,4 +16,15 @@ import java.util.Optional;
public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> {
Optional<ExpDetail> findFirstByCode(String code);
@Modifying
@Query(value = "INSERT INTO `uc_exp_detail`(`code`, `member_id`, `account_id`, `original_exp`, `result_exp`, `exp`, " +
"`device_type`, `evt_type`, `order_id`, `media_id`, `activity_id`, `description`, `app_code`, `create_time`, `update_time`)\n" +
" VALUES (:#{#resources.code}, :#{#resources.memberId}, :#{#resources.accountId}, :#{#resources.originalExp}, " +
" :#{#resources.resultExp}, :#{#resources.exp}, :#{#resources.deviceType}, :#{#resources.evtType}, " +
" :#{#resources.orderId}, :#{#resources.mediaId}, :#{#resources.activityId}, '#', NULL, now(), now())", nativeQuery = true)
void insertIntoExpDetail(@Param("resources") ExpDetail expDetail);
}
......
......@@ -44,7 +44,7 @@ public class ExpDetailServiceImpl implements ExpDetailService {
@Transactional(rollbackFor = Exception.class)
public void create(ExpDetail resources) {
ExpDetail expDetail = ExpDetailBuilder.build(resources);
this.expDetailRepository.save(expDetail);
this.expDetailRepository.insertIntoExpDetail(expDetail);
}
@Override
......
......@@ -3,6 +3,7 @@ package com.topdraw.business.module.member.address.repository;
import com.topdraw.business.module.member.address.domain.MemberAddress;
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;
/**
......@@ -14,4 +15,12 @@ public interface MemberAddressRepository extends JpaRepository<MemberAddress, Lo
@Query(value = "select IFNULL(max(sequence),0) from uc_member_address where member_id = ?1" , nativeQuery = true)
int findMaxSequenceByMemberId(Long memberId);
@Modifying
@Query(value = "UPDATE `uc_member_address` SET `is_default` = 1, `update_time` = now() WHERE `id` = ?1", nativeQuery = true)
Integer updateDefaultMemberAddressById(Long id);
@Modifying
@Query(value = "UPDATE `uc_member_address` SET `is_default` = 0, `update_time` = now() WHERE `member_id` = ?1", nativeQuery = true)
Integer updateUnDefaultMemberAddressByMemberId(Long memberId);
}
......
......@@ -40,4 +40,8 @@ public interface MemberAddressService {
* @return
*/
int findMaxSequenceByMemberId(Long memberId);
Integer updateDefaultMemberAddressById(Long id);
Integer updateUnDefaultMemberAddressByMemberId(Long memberId);
}
......
......@@ -105,6 +105,18 @@ public class MemberAddressServiceImpl implements MemberAddressService {
return this.memberAddressRepository.findMaxSequenceByMemberId(memberId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateDefaultMemberAddressById(Long id) {
return this.memberAddressRepository.updateDefaultMemberAddressById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateUnDefaultMemberAddressByMemberId(Long memberId) {
return this.memberAddressRepository.updateUnDefaultMemberAddressByMemberId(memberId);
}
/**
* 检查会员
* @param memberAddress
......
......@@ -44,7 +44,7 @@ public class Member implements Serializable {
@Column(name = "code")
private String code;
/** 类型 1:大屏;2:小屏 */
/** 类型 1:大屏;2:小屏 3:app;*/
@Column(name = "`type`")
private Integer type;
......
package com.topdraw.business.module.member.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.topdraw.business.module.common.validated.UpdateGroup;
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 javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_member")
public class MemberSimple implements Serializable {
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@NotNull(message = "id can't be null!!",groups = {UpdateGroup.class})
private Long id;
/** 标识 */
@Column(name = "code")
private String code;
/** 状态 0:不可用;1:可用 */
@Column(name = "`status`")
private Integer status;
/** 分组信息 */
@Column(name = "`groups`")
private String groups;
/** 是否会员 0:非会员;1:会员 */
@Column(name = "vip")
private Integer vip;
/** 会员等级(对应level表的level字段,非id) */
@Column(name = "`level`")
private Integer level;
/** iptv账号id */
@Column(name = "user_iptv_id")
private Long userIptvId;
/** 是否在黑名单 1:是;0否 */
@Column(name = "black_status")
private Long blackStatus;
public void copy(MemberSimple source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false));
}
}
package com.topdraw.business.module.member.domain;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/27 15:38
* @version: :
* @modified By:
* @since : modified in 2022/6/27 15:38
*/
public interface MemberTypeConstant {
// 大屏
Integer vis = 1;
// 微信
Integer weixin = 2;
// app
Integer app = 3;
}
......@@ -15,5 +15,5 @@ public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>,
Optional<MemberLevel> findFirstByCode(String code);
List<MemberLevel> findByLevelAndStatus(Integer level, Integer status);
Optional<MemberLevel> findByLevelAndStatus(Integer level, Integer status);
}
......
......@@ -25,12 +25,9 @@ public interface MemberLevelService {
MemberLevelDTO getByCode(String code);
/**
* 通过等级和状态检索
*
* @param i
* @param status
* @return
*/
List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status);
MemberLevelDTO findByLevel(int i);
}
......
package com.topdraw.business.module.member.level.service.impl;
import com.topdraw.business.module.member.level.domain.MemberLevel;
import com.topdraw.business.RedisKeyConstants;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.member.level.repository.MemberLevelRepository;
import com.topdraw.business.module.member.level.service.MemberLevelService;
import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO;
import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper;
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 com.topdraw.utils.StringUtils;
import java.util.List;
/**
* @author XiangHan
* @date 2021-10-22
......@@ -29,6 +29,7 @@ public class MemberLevelServiceImpl implements MemberLevelService {
private MemberLevelMapper memberLevelMapper;
@Override
@Transactional(readOnly = true)
public MemberLevelDTO findById(Long id) {
MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new);
ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id);
......@@ -36,14 +37,18 @@ public class MemberLevelServiceImpl implements MemberLevelService {
}
@Override
@Transactional(readOnly = true)
public MemberLevelDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new))
: new MemberLevelDTO();
}
@Override
public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) {
return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level,status));
@Transactional(readOnly = true)
@Cacheable(cacheNames = RedisKeyConstants.cacheMemberLevelByLevel, key = "#level", unless = "#result.id == null")
public MemberLevelDTO findByLevel(int level) {
MemberLevel memberLevel = this.memberLevelRepository.findByLevelAndStatus(level, 1).orElseGet(MemberLevel::new);
return this.memberLevelMapper.toDto(memberLevel);
}
}
......
......@@ -7,7 +7,6 @@ import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
import com.topdraw.business.process.service.member.MemberProfileOperationService;
import com.topdraw.common.ResultInfo;
import com.topdraw.business.module.member.profile.domain.MemberProfile;
import com.topdraw.business.module.member.profile.service.MemberProfileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
......@@ -32,10 +31,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 +41,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 +51,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);
}
......
......@@ -6,6 +6,7 @@ import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.util.Base64Util;
import com.topdraw.util.RegexUtil;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.member.profile.repository.MemberProfileRepository;
......@@ -141,6 +142,13 @@ public class MemberProfileServiceImpl implements MemberProfileService {
memberProfile.setGender(_memberProfileDTO1.getGender());
}
String phone = resources.getPhone();
if (StringUtils.isNotBlank(phone) && RegexUtil.mobileRegex(phone)) {
memberProfile.setPhone(phone);
} else {
memberProfile.setPhone(_memberProfileDTO1.getPhone());
}
MemberProfile _memberProfile = this.memberProfileRepository.save(memberProfile);
MemberProfileDTO memberProfileDTO = new MemberProfileDTO();
......@@ -171,31 +179,35 @@ public class MemberProfileServiceImpl implements MemberProfileService {
log.info("MemberProfileServiceImpl ==>> updateMemberProfileAndMember ==>> resources ===>> [{}]",resources);
MemberProfileDTO memberProfileDTO = this.update(resources);
// 同步会员信息
this.synchronizedMemberData(resources, memberDTO);
return memberProfileDTO;
}
private void synchronizedMemberData(MemberProfile resources, MemberDTO memberDTO) {
log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",resources);
log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",memberProfileDTO);
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(memberProfileDTO.getRealname())) {
member.setNickname(memberProfileDTO.getRealname());
} else {
member.setNickname(memberDTO.getNickname());
}
if(Objects.nonNull(resources.getGender()) && resources.getGender() != -1) {
memberDTO.setGender(resources.getGender());
if(Objects.nonNull(memberProfileDTO.getGender()) && memberProfileDTO.getGender() != -1) {
member.setGender(memberProfileDTO.getGender());
} else {
member.setGender(memberDTO.getGender());
}
if(StringUtils.isNotBlank(resources.getBirthday())) {
memberDTO.setBirthday(resources.getBirthday());
if(StringUtils.isNotBlank(memberProfileDTO.getBirthday())) {
member.setBirthday(memberProfileDTO.getBirthday());
} else {
member.setBirthday(memberDTO.getBirthday());
}
if(StringUtils.isNotBlank(resources.getAvatarUrl())) {
memberDTO.setAvatarUrl(resources.getAvatarUrl());
member.setAvatarUrl(resources.getAvatarUrl());
} else {
member.setAvatarUrl(memberDTO.getAvatarUrl());
}
this.memberService.doUpdateMemberAvatarUrlAndNicknameAndGender(member);
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
this.memberService.update(member);
return memberProfileDTO;
}
}
......
package com.topdraw.business.module.member.repository;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.domain.MemberSimple;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
......@@ -10,6 +11,7 @@ import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
* @author XiangHan
......@@ -23,7 +25,6 @@ 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)
......@@ -32,15 +33,40 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif
@Modifying
@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() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void updatePointAndDuePoint(@Param("resources") Member resources);
@Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, `update_time`= now() WHERE `id` = :#{#resources.id}", nativeQuery = true)
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)
void doUpdateMemberCoupon(@Param("resources") Member member);
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 `vip` = :#{#resources.vip}, `vip_expire_time` = :#{#resources.vipExpireTime} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
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);
@Query(value = "SELECT IFNULL(`exp`,0) AS exp FROM uc_member WHERE `id` = ?1 ", nativeQuery = true)
Long findExpByMemberId(Long memberId);
@Modifying
@Query(value = "UPDATE `uc_member` SET `groups` = ?1, `update_time` = now() WHERE `code` IN ?2 ", nativeQuery = true)
Integer doUpdateGroupsBatch(String groups, Set<String> codes);
}
......
package com.topdraw.business.module.member.repository;
import com.topdraw.business.module.member.domain.MemberSimple;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.Optional;
/**
* @author XiangHan
* @date 2021-10-22
*/
public interface MemberSimpleRepository extends JpaRepository<MemberSimple, Long>, JpaSpecificationExecutor<MemberSimple> {
@Query(value = "SELECT `id`, `code`, `status`, `groups`, `vip`, `level`,`user_iptv_id`, `black_status` FROM `uc_member` WHERE `id` = ?1", nativeQuery = true)
Optional<MemberSimple> findSimpleById(Long id);
@Query(value = "SELECT `id`, `code`, `status`, `groups`, `vip`, `level`,`user_iptv_id`, `black_status` FROM `uc_member` WHERE `code` = ?1", nativeQuery = true)
Optional<MemberSimple> findSimpleByCode(String code);
}
......@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
......@@ -52,11 +53,22 @@ 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();
}
@RequestMapping(value = "/doUpdateGroupsBatch")
@AnonymousAccess
@ApiOperation("批量手动修改会员分组")
public ResultInfo doUpdateGroupsBatch(@Validated(value = {UpdateGroup.class}) @RequestBody List<Member> resources) {
log.info("doUpdateGroupsBatch ==>> param ==>> {}",resources);
Integer count = this.memberOperationService.doUpdateGroupsBatch(resources);
return ResultInfo.success(count);
}
@PutMapping(value = "/update")
@ApiOperation("修改会员信息")
@AnonymousAccess
......@@ -67,7 +79,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);
......
......@@ -2,6 +2,8 @@ package com.topdraw.business.module.member.service;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -26,6 +28,13 @@ public interface MemberService {
MemberDTO findById(Long id);
/**
*
* @param id
* @return
*/
MemberSimpleDTO findSimpleById(Long id);
/**
* 通过code查询会员
* @param code 会员编码
* @return MemberDTO
......@@ -33,6 +42,13 @@ public interface MemberService {
MemberDTO findByCode(String code);
/**
*
* @param code
* @return
*/
MemberSimpleDTO findSimpleByCode(String code);
/**
* 保存
* @param resources
* @return Long id
......@@ -40,13 +56,6 @@ public interface MemberService {
MemberDTO create(Member resources);
/**
* 创建并返回会员
* @param resources 会员
* @return Member
*/
MemberDTO createAndReturnMember(Member resources);
/**
* 修改会员
* @param resources
*/
......@@ -56,7 +65,7 @@ public interface MemberService {
* 修改会员积分
* @param member 会员
*/
MemberDTO doUpdateMemberPoints(Member member);
Integer doUpdateMemberPoints(Member member);
/**
* 查询绑定了大屏会员列表
......@@ -83,12 +92,53 @@ public interface MemberService {
* @param resources
* @return
*/
MemberDTO doUpdateMemberExpAndLevel(Member resources);
Integer doUpdateMemberExpAndLevel(Member resources);
/**
*
* @param member
* @return
*/
MemberDTO doUpdateMemberCoupon(Member member);
Integer 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);
/**
*
* @param memberId
* @return
*/
Long findExpByMemberId(Long memberId);
/**
*
* @param resources
* @return
*/
Integer doUpdateGroupsBatch(List<Member> resources);
}
......
package com.topdraw.business.module.member.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class MemberSimpleDTO implements Serializable {
/** 主键 */
private Long id;
/** 标识 */
private String code;
/** 昵称 */
private String nickname;
/** 状态 0:不可用;1:可用 */
private Integer status;
/** 分组信息 */
private String groups;
/** 是否会员 0:非会员;1:会员 */
private Integer vip;
/** vip过期时间 */
private Timestamp vipExpireTime;
/** 会员等级(对应level表的level字段,非id) */
private Integer level;
/** iptv账号id */
private Long userIptvId;
/** 是否在黑名单 1:是;0否 */
private Long blackStatus;
}
package com.topdraw.business.module.member.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.member.domain.MemberSimple;
import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MemberSimpleMapper extends BaseMapper<MemberSimpleDTO, MemberSimple> {
}
package com.topdraw.business.module.member.viphistory.rest;
import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.common.ResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author luerlong
* @date 2021-12-10
*/
@Api(tags = "会员vip历史管理")
@RestController
@RequestMapping("/uce/memberVipHistory")
public class MemberVipHistoryController {
@Autowired
private MemberOperationService memberOperationService;
@PostMapping
@ApiOperation("新增MemberVipHistory")
public ResultInfo create(@Validated @RequestBody MemberVipHistory resources) {
this.memberOperationService.createVipHistory(resources);
return ResultInfo.success();
}
}
......@@ -24,7 +24,7 @@ public interface MemberVipHistoryService {
*
* @param resources
*/
void create(MemberVipHistory resources);
MemberVipHistoryDTO create(MemberVipHistory resources);
/**
*
......
......@@ -52,15 +52,14 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService {
@Override
@Transactional(rollbackFor = Exception.class)
@AsyncMqSend
public void create(MemberVipHistory resources) {
public MemberVipHistoryDTO create(MemberVipHistory resources) {
log.info("MemberVipHistoryServiceImpl ==>> MemberVipHistoryServiceImpl ==>> param ==>> [{}]",resources);
MemberDTO memberDTO = this.checkMember(resources);
MemberVipHistory memberVipHistory = MemberVipHistoryBuilder.build(resources);
MemberVipHistory vipHistory = this.memberVipHistoryRepository.save(memberVipHistory);
vipHistory.setMemberCode(memberDTO.getCode());
return this.memberVipHistoryMapper.toDto(vipHistory);
}
@Override
......
......@@ -101,5 +101,5 @@ public interface PointsAvailableService {
*
* @param pointsAvailable
*/
PointsAvailableDTO create4Custom(PointsAvailable pointsAvailable);
void create4Custom(PointsAvailable pointsAvailable);
}
......
......@@ -160,17 +160,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
}
@Override
public PointsAvailableDTO create4Custom(PointsAvailable resources) {
this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString());
try {
PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources);
return this.pointsAvailableMapper.toDto(pointsAvailable);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("PointsAvailable::create::id"+resources.getMemberId().toString());
}
public void create4Custom(PointsAvailable resources) {
this.pointsAvailableRepository.save(resources);
}
}
......
......@@ -88,6 +88,10 @@ public class PointsDetail implements Serializable {
@Column(name = "item_id")
private Long itemId;
// 状态:0:异常;1:正常
@Column(name = "status")
private Long status;
// 创建时间
@CreatedDate
@Column(name = "create_time")
......
......@@ -3,6 +3,9 @@ package com.topdraw.business.module.points.detail.repository;
import com.topdraw.business.module.points.detail.domain.PointsDetail;
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 java.util.List;
import java.util.Optional;
......@@ -16,4 +19,14 @@ public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long
Optional<PointsDetail> findFirstByCode(String code);
List<PointsDetail> findByMemberId(Long memberId);
@Modifying
@Query(value = "INSERT INTO `uc_points_detail`(`code`, `app_code`, `member_id`, `account_id`, `original_points`, `result_points`, " +
" `points`, `device_type`, `evt_type`, `order_id`, `media_id`, `activity_id`, `item_id`, `status`, `description`, `create_time`, `update_time`)" +
" VALUES (:#{#resources.code}, :#{#resources.appCode}, :#{#resources.memberId}, :#{#resources.accountId}," +
" :#{#resources.originalPoints}, :#{#resources.resultPoints}, :#{#resources.points}, :#{#resources.deviceType}," +
" :#{#resources.evtType}, :#{#resources.orderId}, :#{#resources.mediaId}, :#{#resources.activityId}, " +
" :#{#resources.itemId}, :#{#resources.status}, :#{#resources.description}, now(), now())", nativeQuery = true)
Integer insertPointsDetail(@Param("resources") PointsDetail pointsDetail);
}
......
......@@ -46,13 +46,6 @@ public interface PointsDetailService {
PointsDetailDTO getByCode(String code);
/**
*
* @param memberId
* @return
*/
List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId);
/**
* 已过期的积分
* @param memberId
* @return
......@@ -63,5 +56,5 @@ public interface PointsDetailService {
*
* @param pointsDetail
*/
void create4Custom(PointsDetail pointsDetail);
void insertPointsDetail(PointsDetail pointsDetail);
}
......
......@@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable {
// 积分变化描述,用于管理侧显示
private String description;
// 状态:0:异常;1:正常
private Long status;
// 商品id
private Long itemId;
......
......@@ -31,6 +31,7 @@ public class PointsDetailServiceImpl implements PointsDetailService {
private PointsDetailMapper pointsDetailMapper;
@Override
@Transactional(readOnly = true)
public PointsDetailDTO findById(Long id) {
PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new);
ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id);
......@@ -40,8 +41,7 @@ public class PointsDetailServiceImpl implements PointsDetailService {
@Override
@Transactional(rollbackFor = Exception.class)
public PointsDetailDTO create(PointsDetail resources) {
PointsDetail pointsDetail = this.pointsDetailRepository.save(resources);
return this.pointsDetailMapper.toDto(pointsDetail);
return this.pointsDetailMapper.toDto(this.pointsDetailRepository.save(resources));
}
@Override
......@@ -65,17 +65,14 @@ public class PointsDetailServiceImpl implements PointsDetailService {
@Override
@Transactional(readOnly = true)
public PointsDetailDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new))
: new PointsDetailDTO();
}
@Override
public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) {
return null;
}
@Override
@Transactional(readOnly = true)
public List<PointsDetailDTO> findByMemberId(Long memberId) {
return Objects.nonNull(memberId)?
this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId))
......@@ -83,7 +80,8 @@ public class PointsDetailServiceImpl implements PointsDetailService {
}
@Override
public void create4Custom(PointsDetail pointsDetail) {
this.pointsDetailRepository.save(pointsDetail);
@Transactional(rollbackFor = Exception.class)
public void insertPointsDetail(PointsDetail pointsDetail) {
this.pointsDetailRepository.insertPointsDetail(pointsDetail);
}
}
......
package com.topdraw.business.process.domian.constant;
package com.topdraw.business.module.rights.constant;
public enum RightType {
/**积分*/
......
package com.topdraw.business.module.rights.constant;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/18 16:06
* @version: :
* @modified By:
* @since : modified in 2022/6/18 16:06
*/
public interface RightTypeConstants {
// 优惠券
int DISCOUNT_COUPON = 1;
// 观影券
int VIEW_COUPON= 2;
// 参加活动
int JOIN_ACTIVITY = 3;
// 积分商品
int POINTS_GOODS = 4;
// IPTV产品包
int IPTV_PRODUCT = 5;
// IPTV观影权益
int IPTV_VIEW = 6;
}
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;
......
package com.topdraw.business.module.rights.service.impl;
import com.topdraw.business.module.rights.domain.Rights;
import com.topdraw.business.RedisKeyConstants;
import com.topdraw.utils.*;
import com.topdraw.business.module.rights.repository.RightsRepository;
import com.topdraw.business.module.rights.service.RightsService;
import com.topdraw.business.module.rights.service.dto.RightsDTO;
import com.topdraw.business.module.rights.service.mapper.RightsMapper;
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;
......@@ -25,9 +27,9 @@ public class RightsServiceImpl implements RightsService {
private RightsMapper rightsMapper;
@Override
@Cacheable(cacheNames = RedisKeyConstants.cacheRightById, key = "#id", unless = "#result.id == null")
public RightsDTO findById(Long id) {
Rights Rights = this.rightsRepository.findById(id).orElseGet(Rights::new);
ValidationUtil.isNull(Rights.getId(),"Rights","id",id);
return this.rightsMapper.toDto(Rights);
}
......
......@@ -3,8 +3,12 @@ package com.topdraw.business.module.task.attribute.repository;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* @author XiangHan
......@@ -13,4 +17,7 @@ import java.util.Optional;
public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> {
Optional<TaskAttr> findByTaskId(Long taskId);
@Query(value = "SELECT * FROM `tr_task_attr` WHERE task_id IN(?1)", nativeQuery = true)
List<Map<String, Object>> findTasksByTaskIds(Set<Object> taskIds);
}
......
......@@ -3,6 +3,9 @@ package com.topdraw.business.module.task.attribute.service;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
import java.util.List;
import java.util.Set;
/**
* @author XiangHan
* @date 2022-01-13
......@@ -39,4 +42,6 @@ public interface TaskAttrService {
* @return
*/
TaskAttrDTO findByTaskId(Long taskId);
List<TaskAttrDTO> findTasksByTaskIds(Set<Object> id);
}
......
package com.topdraw.business.module.task.attribute.service.impl;
import com.alibaba.fastjson.JSON;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository;
......@@ -12,6 +13,12 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author XiangHan
......@@ -64,5 +71,20 @@ public class TaskAttrServiceImpl implements TaskAttrService {
return this.taskAttrMapper.toDto(taskAttr);
}
@Override
public List<TaskAttrDTO> findTasksByTaskIds(Set<Object> taskIds) {
List<Map<String,Object>> maps = this.taskAttrRepository.findTasksByTaskIds(taskIds);
if (!CollectionUtils.isEmpty(maps)) {
List<TaskAttr> taskAttrs = new ArrayList<>();
for (Map<String, Object> map : maps) {
TaskAttr taskAttr = JSON.parseObject(JSON.toJSONString(map), TaskAttr.class);
taskAttrs.add(taskAttr);
}
return this.taskAttrMapper.toDto(taskAttrs);
}
return new ArrayList<>();
}
}
......
......@@ -15,6 +15,7 @@ import java.sql.Timestamp;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author XiangHan
......@@ -151,6 +152,9 @@ public class Task implements Serializable {
@Transient
private String attr;
@Transient
private Integer event;
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
......
......@@ -61,7 +61,7 @@ public class TaskBuilder {
task_.setDeleteMark(Objects.isNull(task.getDeleteMark()) ? 0 : task.getDeleteMark());
task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr());
// task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr());
return task_;
}
......
......@@ -27,6 +27,9 @@ import java.io.Serializable;
@NoArgsConstructor
public class TrTaskProgress implements Serializable {
@Transient
private String memberCode;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
......
......@@ -5,7 +5,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author XiangHan
......@@ -13,8 +16,17 @@ import java.util.List;
*/
public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<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" +
@Query(value = "select id, member_id, task_id, current_action_amount," +
" target_action_amount, `status`, completion_time, create_time, update_time from uc_tr_task_progress where member_id = ?1 " +
" and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true)
List<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
Optional<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
Integer countByMemberIdAndTaskId(Long memberId, Long taskId);
@Query(value = "select `task_id` AS taskId, count(*) AS finishCount from uc_tr_task_progress where member_id = ?1 and `status` = 1 GROUP BY `task_id` ", nativeQuery = true)
List<Map<String, Object>> countFinishTaskGroupByMemberId(Long memberId);
@Query(value = "select `task_id` AS taskId, count(*) AS finishCount from uc_tr_task_progress where member_id = ?1 and Date(completion_time) = ?2 and `status` = 1 GROUP BY `task_id`", nativeQuery = true)
List<Map<String, Object>> countFinishTaskGroupByMemberIdAndToday(Long memberId, String todayStart);
}
......
......@@ -2,7 +2,11 @@ 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.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -21,13 +25,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 +46,28 @@ public interface TrTaskProgressService {
* @param time1
* @return
*/
List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
/**
*
* @param memberId
* @param taskId
* @return
*/
Integer countByMemberIdAndTaskId(Long memberId, Long taskId);
/**
*
* @param id
* @return
*/
Map<Object, Object> countTotalFinishTaskByMemberId(Long id);
/**
*
* @param id
* @param todayStart
* @return
*/
Map<Object, Object> countTodayFinishTaskByMemberId(Long id, String todayStart);
}
......
package com.topdraw.business.module.task.progress.service.impl;
import com.topdraw.business.module.task.progress.domain.TrTaskProgress;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.RedisKeyConstants;
import com.topdraw.utils.RedisUtils;
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.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 org.springframework.util.CollectionUtils;
import java.util.List;
import java.time.LocalDate;
import java.util.*;
/**
* @author XiangHan
......@@ -21,34 +25,35 @@ import java.util.List;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class TrTaskProgressServiceImpl implements TrTaskProgressService {
@Autowired
private TrTaskProgressRepository trTaskProgressRepository;
@Autowired
private TrTaskProgressMapper trTaskProgressMapper;
@Autowired
private RedisUtils redisUtils;
@Override
public TrTaskProgressDTO findById(Long id) {
TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new);
ValidationUtil.isNull(TrTaskProgress.getId(),"TrTaskProgress","id",id);
return this.trTaskProgressMapper.toDto(TrTaskProgress);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(TrTaskProgress resources) {
this.trTaskProgressRepository.save(resources);
// @CachePut(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ")
public TrTaskProgress create(TrTaskProgress resources, String date) {
return this.trTaskProgressRepository.save(resources);
}
@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);
// @CachePut(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ")
public TrTaskProgress update(TrTaskProgress resources, String date) {
return this.trTaskProgressRepository.save(resources);
}
@Override
......@@ -61,8 +66,73 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
}
@Override
public List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) {
return this.trTaskProgressMapper.toDto(this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1));
// @Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#memberId+':'+#taskId+':'+#time1", unless = "#result.id == null")
public TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) {
log.info("从数据库查询当前会员今天是否完成了此任务, memberId ==>> {} || taskId ==>> {}", memberId, taskId);
return this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId, taskId, time1).orElseGet(TrTaskProgress::new);
}
@Override
public Integer countByMemberIdAndTaskId(Long memberId, Long taskId) {
return this.trTaskProgressRepository.countByMemberIdAndTaskId(memberId, taskId);
}
@Override
public Map<Object, Object> countTotalFinishTaskByMemberId(Long memberId) {
Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId);
if (Objects.isNull(hmget)) {
List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberId(memberId);
if (!CollectionUtils.isEmpty(maps)) {
Map<Object, Object> finishTasks = new HashMap<>();
for (Map<String, Object> map : maps) {
Object taskId = map.get("taskId");
if (Objects.isNull(taskId)) {
continue;
}
finishTasks.put(taskId, Integer.valueOf(map.get("finishCount").toString()));
}
if (finishTasks.size() > 0) {
// 总记录一直存储
this.redisUtils.hmset(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks);
}
return finishTasks;
}
}
return hmget;
}
@Override
public Map<Object, Object> countTodayFinishTaskByMemberId(Long memberId, String todayStart) {
Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + todayStart);
if (Objects.isNull(hmget)) {
List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberIdAndToday(memberId, todayStart);
if (!CollectionUtils.isEmpty(maps)){
Map<Object, Object> finishTasks = new HashMap<>();
for (Map<String, Object> map : maps) {
Object taskId = map.get("taskId");
if (Objects.isNull(taskId)) {
continue;
}
finishTasks.put(taskId, Integer.valueOf(map.get("finishCount").toString()));
}
if (finishTasks.size() > 0) {
// 单天的记录只存储一天
this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60);
}
return finishTasks;
}
}
return hmget;
}
......
......@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
......@@ -21,7 +22,12 @@ 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.* FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " +
" WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " +
" tm.type = ?1 AND ta.`member_level` <= ?2 and ta.`member_vip` <= ?3", nativeQuery = true)
List<Map<String,Object>> findByEventAndLevelAndVip(Integer event, Integer level, Integer vip);
}
......
package com.topdraw.business.module.task.service;
import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
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 +51,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> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip);
}
......
package com.topdraw.business.module.task.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.business.module.task.attribute.service.TaskAttrService;
import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
import com.topdraw.business.module.task.domain.Task;
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.business.RedisKeyConstants;
import com.topdraw.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author XiangHan
......@@ -19,12 +31,18 @@ import java.util.Objects;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class TaskServiceImpl implements TaskService {
@Autowired
private TaskAttrService taskAttrService;
@Autowired
private TaskMapper taskMapper;
@Autowired
private TaskRepository taskRepository;
@Autowired
private RedisUtils redisUtils;
@Override
public TaskDTO findById(Long id) {
......@@ -56,14 +74,70 @@ 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
@Transactional(readOnly = true)
public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) {
try {
boolean b = this.redisUtils.hasKey(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip);
if (b) {
List<Object> tasksObjs = redisUtils.lGet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, 0, -1);
return JSONArray.parseArray(tasksObjs.get(0).toString(), Task.class);
}
List<Map<String, Object>> maps = this.taskRepository.findByEventAndLevelAndVip(event, level, vip);
List<Task> tasks = new ArrayList<>();
if (CollectionUtils.isEmpty(maps)) {
return tasks;
}
List<TaskAttrDTO> taskAttrDTOS = this.taskAttrService.findTasksByTaskIds(maps.stream().map(t -> t.get("id")).collect(Collectors.toSet()));
if (!CollectionUtils.isEmpty(taskAttrDTOS)) {
for (Map<String, Object> map : maps) {
Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class);
List<String> taskAttrs = taskAttrDTOS.stream().filter(taskAttrDTO -> taskAttrDTO.getTaskId().equals(task.getId())).
map(TaskAttrDTO::getAttrStr).collect(Collectors.toList());
log.info("任务属性值, dealTask# taskAttrs ==>> {}", taskAttrs);
if (!CollectionUtils.isEmpty(taskAttrs)) {
task.setAttr(String.join(",", taskAttrs));
}
tasks.add(task);
}
} else {
for (Map<String, Object> map : maps) {
Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class);
tasks.add(task);
}
}
if (!CollectionUtils.isEmpty(tasks)) {
this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60);
}
return tasks;
} catch (Exception e) {
log.error(e.getMessage());
}
return new ArrayList<>();
}
}
......
package com.topdraw.business.module.task.template.constant;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/18 14:30
* @version: :
* @modified By:
* @since : modified in 2022/6/18 14:30
*/
public interface TaskEventType {
//类型 1:登录;2:观影;3:参加活动;4:订购;5:优享会员;6:签到;7:完成设置;
// 8:播放记录;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
int LOGIN = 1;
int VIEW = 2;
int ACTIVITY = 3;
int ORDER = 4;
int MEMBER_PRIORITY = 5;
int SIGN = 6;
int COMPLETE_INFO = 7;
int PLAY = 8;
int BINDING = 10;
int POINTS_TRANS = 11;
int POINTS_EXCHANGE_GOODS = 30;
int SYSTEM_OPERATE = 98;
int OHHER = 99;
}
......@@ -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;
}
}
......
package com.topdraw.business.module.user.app.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.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_app")
public class UserApp implements Serializable {
// 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
@Transient
private Integer accountType;
// 第三方账号
@Transient
private String account;
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 会员id
@Column(name = "member_id")
private Long memberId;
// 用户名(一般为手机号)
@Column(name = "username", nullable = false)
private String username;
// 密码
@Column(name = "password")
private String password;
// 类型 0:苹果;1:安卓;-1:未知
@Column(name = "type", nullable = false)
private Integer type;
// 状态 0:禁用;1:生效;-1:注销
@Column(name = "status", nullable = false)
private Integer status;
// 昵称
@Column(name = "nickname")
private String nickname;
// 头像地址
@Column(name = "headimgurl")
private String headimgurl;
// 邮箱
@Column(name = "email")
private String email;
// 手机号
@Column(name = "cellphone")
private String cellphone;
// 性别 0:女;1:男;-1:其他
@Column(name = "gender")
private Integer gender;
// 生日
@Column(name = "birthday")
private String birthday;
// 最近活跃时间
@Column(name = "last_active_time")
private Timestamp lastActiveTime;
// 注销时间
@Column(name = "delete_time")
private Timestamp deleteTime;
// 标签
@Column(name = "tags")
private String tags;
// 描述
@Column(name = "description")
private String description;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(UserApp source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.app.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.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_app_bind")
public class UserAppBind implements Serializable {
@Transient
private String username;
@Transient
private String password;
@Transient
private String headimgurl;
// 主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
@Column(name = "account_type", nullable = false)
private Integer accountType;
// 第三方账号
@Column(name = "account", nullable = false)
private String account;
// app账号id
@Column(name = "user_app_id", nullable = false)
private Long userAppId;
// 绑定状态 0:解绑;1 绑定
@Column(name = "status", nullable = false)
private Integer status;
// 昵称
@Column(name = "nickname", nullable = false)
private String nickname;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(UserAppBind source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.app.domain;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/30 13:18
* @version: :
* @modified By:
* @since : modified in 2022/6/30 13:18
*/
public class UserAppBindBuilder {
public static UserAppBind build(Long userAppId, String account, Integer accountType){
UserAppBind userAppBind = new UserAppBind();
userAppBind.setAccount(account);
userAppBind.setUserAppId(userAppId);
userAppBind.setAccountType(accountType);
userAppBind.setStatus(UserAppStatusConstant.VALID_STATUS);
return userAppBind;
}
}
package com.topdraw.business.module.user.app.domain;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/30 11:42
* @version: :
* @modified By:
* @since : modified in 2022/6/30 11:42
*/
public interface UserAppBindStatusConstant {
// 绑定状态 0:解绑;1 绑定
Integer VALID_STATUS = 1;
Integer INVALID_STATUS = 0;
}
package com.topdraw.business.module.user.app.domain;
import com.topdraw.util.TimestampUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import java.util.Objects;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/30 11:35
* @version: :
* @modified By:
* @since : modified in 2022/6/30 11:35
*/
public class UserAppBuilder {
public static UserApp build(Long memberId, UserApp resource){
UserApp userApp = new UserApp();
userApp.setId(null);
userApp.setMemberId(memberId);
userApp.setUsername(resource.getUsername());
userApp.setTags(resource.getTags());
userApp.setLastActiveTime(TimestampUtil.now());
userApp.setEmail(resource.getEmail());
userApp.setType(Objects.isNull(resource.getType()) ? -1 : resource.getType());
userApp.setNickname(StringUtils.isNotBlank(resource.getNickname()) ? resource.getNickname() : resource.getUsername());
userApp.setHeadimgurl(resource.getHeadimgurl());
userApp.setPassword(resource.getPassword());
userApp.setCellphone(StringUtils.isNotBlank(resource.getCellphone()) ? resource.getCellphone() : resource.getUsername());
userApp.setBirthday(StringUtils.isNotBlank(resource.getBirthday()) ? resource.getBirthday() : null);
userApp.setGender(Objects.nonNull(resource.getGender()) ? resource.getGender() : -1);
userApp.setStatus(UserAppStatusConstant.VALID_STATUS);
userApp.setCreateTime(null);
userApp.setUpdateTime(null);
return userApp;
}
}
package com.topdraw.business.module.user.app.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
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 javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_app")
public class UserAppIdManual implements Serializable {
// 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
@Transient
private Integer accountType;
// 第三方账号
@Transient
private String account;
@Transient
private String memberCode;
// ID
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;
// 会员id
@Column(name = "member_id")
private Long memberId;
// 用户名(一般为手机号)
@Column(name = "username", nullable = false)
private String username;
// 密码
@Column(name = "password")
private String password;
// 类型 0:苹果;1:安卓;-1:未知
@Column(name = "type", nullable = false)
private Integer type;
// 状态 0:禁用;1:生效;-1:注销
@Column(name = "status", nullable = false)
private Integer status;
// 昵称
@Column(name = "nickname")
private String nickname;
// 头像地址
@Column(name = "headimgurl")
private String headimgurl;
// 邮箱
@Column(name = "email")
private String email;
// 手机号
@Column(name = "cellphone")
private String cellphone;
// 性别 0:女;1:男;-1:其他
@Column(name = "gender")
private Integer gender;
// 生日
@Column(name = "birthday")
private String birthday;
// 最近活跃时间
@Column(name = "last_active_time")
private Timestamp lastActiveTime;
// 注销时间
@Column(name = "delete_time")
private Timestamp deleteTime;
// 标签
@Column(name = "tags")
private String tags;
// 描述
@Column(name = "description")
private String description;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(UserAppIdManual source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.app.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_app")
public class UserAppSimple implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 会员id
@Column(name = "member_id")
private Long memberId;
// 用户名(一般为手机号)
@Column(name = "username", nullable = false)
private String username;
// 状态 0:禁用;1:生效;-1:注销
@Column(name = "status", nullable = false)
private Integer status;
// 昵称
@Column(name = "nickname")
private String nickname;
// 头像地址
@Column(name = "headimgurl")
private String headimgurl;
// 邮箱
@Column(name = "email")
private String email;
// 手机号
@Column(name = "cellphone")
private String cellphone;
// 性别 0:女;1:男;-1:其他
@Column(name = "gender")
private Integer gender;
// 生日
@Column(name = "birthday")
private String birthday;
// 标签
@Column(name = "tags")
private String tags;
// 描述
@Column(name = "description")
private String description;
public void copy(UserAppSimple source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.app.domain;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/30 11:42
* @version: :
* @modified By:
* @since : modified in 2022/6/30 11:42
*/
public interface UserAppStatusConstant {
// 状态 0:禁用;1:生效;-1:注销
Integer VALID_STATUS = 1;
Integer FORBID_STATUS = 0;
Integer INVALID_STATUS = -1;
}
package com.topdraw.business.module.user.app.repository;
import com.topdraw.business.module.user.app.domain.UserAppBind;
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.util.List;
import java.util.Optional;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppBindRepository extends JpaRepository<UserAppBind, Long>, JpaSpecificationExecutor<UserAppBind> {
Optional<UserAppBind> findFirstByAccount(String account);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `status` = 0 , `update_time` = now() WHERE `account` = ?1 AND `account_type` = ?2", nativeQuery = true)
Integer cancelUserAppBind(String account, Integer accountType);
Optional<UserAppBind> findFirstByAccountAndAccountType(String account, Integer accountType);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `status` = :#{#resources.status}, `update_time` = now(), " +
" `user_app_id` = :#{#resources.userAppId}, `nickname` = :#{#resources.nickname} " +
" WHERE `account` = :#{#resources.account} AND accountType = :#{#resources.accountType}", nativeQuery = true)
Integer updateThirdAccount(@Param("resources") UserAppBind resources);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `status` = :#{#resources.status}, `update_time` = now(), " +
" `user_app_id` = :#{#resources.userAppId} WHERE `account` = :#{#resources.account} AND accountType = :#{#resources.accountType}",
nativeQuery = true)
Integer updateThirdAccountStatusAndUserAppId(@Param("resources") UserAppBind resources);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `status` = 1, `update_time` = now(), " +
" `user_app_id` = :#{#resources.userAppId} WHERE `account` = :#{#resources.account} AND accountType = :#{#resources.accountType}",
nativeQuery = true)
Integer updateValidStatusAndUserAppId(@Param("resources") UserAppBind resources);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `update_time` = now(), `nickname` = :#{#resources.nickname} " +
" WHERE `account` = :#{#resources.account} AND `account_type` = :#{#resources.accountType}", nativeQuery = true)
Integer updateThirdAccountNickname(@Param("resources") UserAppBind resources);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `update_time` = now(), `nickname` = :#{#resources.nickname}, `status` = 1, `user_app_id` = :#{#resources.userAppId} " +
" WHERE `account` = :#{#resources.account} AND `account_type` = :#{#resources.accountType}", nativeQuery = true)
Integer updateValidStatusAndUserAppIdAndNickname(@Param("resources") UserAppBind resources);
@Modifying
@Query(value = "UPDATE `uc_user_app_bind` SET `update_time` = now(), `status` = 0 WHERE `id` IN ?1", nativeQuery = true)
Integer appCancellation(List<Long> ids);
List<UserAppBind> findByUserAppId(Long id);
}
package com.topdraw.business.module.user.app.repository;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.domain.UserAppIdManual;
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 java.util.Optional;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppRepository extends JpaRepository<UserApp, Long>, JpaSpecificationExecutor<UserApp> {
@Query(value = "SELECT ua.* FROM uc_user_app ua WHERE ua.`username` = ?1 and ua.`status` IN (0 , 1)", nativeQuery = true)
Optional<UserApp> findByUsername(String username);
Optional<UserApp> findByUsernameAndPassword(String username, String password);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `last_active_time` = now() WHERE `username` = ?1 AND `status` = 1 ", nativeQuery = true)
Integer updateLastActiveTime(String username);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `password` = ?2 WHERE `username` = ?1 AND `status` = 1", nativeQuery = true)
Integer updatePasswordByUsername(String username, String password);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `nickname` = :#{#resources.nickname}, " +
" `headimgurl` = :#{#resources.headimgurl}, `email` = :#{#resources.email}, `cellphone` = :#{#resources.cellphone}, " +
" `gender` = :#{#resources.gender}, `birthday` = :#{#resources.birthday}, `tags` = :#{#resources.tags}, `description` = :#{#resources.description}" +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
Integer updateAppInfo(@Param("resources") UserApp resources);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `password` = ?2 WHERE `id` = ?1", nativeQuery = true)
Integer updatePasswordById(Long id, String password);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `delete_time` = now(), `status` = -1 WHERE `id` = ?1", nativeQuery = true)
Integer appCancellation(Long id);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `last_active_time` = now(), `nickname` = ?2, `headimgurl` = ?3 " +
" WHERE `username` = ?1 and `status` = 1 ", nativeQuery = true)
Integer updateAppLastActiveTimeAndNicknameAndHeadImg(String username, String nickname, String headimgurl);
@Modifying
@Query(value = "UPDATE `uc_user_app` SET `cellphone`= :#{#resources.cellphone}, `username`= :#{#resources.username},`last_active_time` = now(), `nickname` = :#{#resources.nickname}, `headimgurl` = :#{#resources.headimgurl} " +
" WHERE `id` = :#{#resources.id} and `status` = 1 ", nativeQuery = true)
Integer updateAppLastActiveTimeAndNicknameAndHeadImgById(@Param("resources") UserApp userApp);
@Modifying
@Query(value = "INSERT INTO `uc_user_app`(`id`, `member_id`, `username`, `password`, `type`, `status`, `nickname`, `headimgurl`, `email`, `cellphone`, `gender`, `birthday`, `last_active_time`, `delete_time`, `tags`, `description`, `create_time`, `update_time`) " +
" VALUES (:#{#resources.id}, :#{#resources.memberId}, :#{#resources.username}, :#{#resources.password}, :#{#resources.type}," +
" 1, :#{#resources.nickname}, :#{#resources.headimgurl}, :#{#resources.email}, :#{#resources.cellphone}, " +
" :#{#resources.gender}, NULL, now(), NULL, :#{#resources.tags}, " +
" :#{#resources.description}, :#{#resources.createTime}, now());", nativeQuery = true)
void saveByIdManual(@Param("resources") UserAppIdManual userAppIdManual);
}
package com.topdraw.business.module.user.app.repository;
import com.topdraw.business.module.user.app.domain.UserAppSimple;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppSimpleRepository extends JpaRepository<UserAppSimple, Long>, JpaSpecificationExecutor<UserAppSimple> {
}
package com.topdraw.business.module.user.app.service;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
import java.util.List;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppBindService {
/**
* 根据ID查询
* @param id ID
* @return UserAppBindDTO
*/
UserAppBindDTO findById(Long id);
/**
*
* @param resources
*/
UserAppBindDTO create(UserAppBind resources);
/**
*
* @param resources
*/
void update(UserAppBind resources);
/**
*
* @param id
*/
void delete(Long id);
/**
*
* @param account
* @return
*/
UserAppBindDTO findFirstByAccount(String account);
/**
*
* @param account
* @return
*/
boolean cancelUserAppBind(String account, Integer accountType);
/**
*
* @param account
* @param accountType
* @return
*/
UserAppBindDTO findFirstByAccountAndAccountType(String account, Integer accountType);
/**
*
* @param resources
* @return
*/
boolean updateThirdAccount(UserAppBind resources);
/**
*
* @param resources
* @return
*/
boolean updateThirdAccountNickname(UserAppBind resources);
/**
*
* @param resources
* @return
*/
boolean updateValidStatusAndUserAppIdAndNickname(UserAppBind resources);
boolean appCancellation(List<Long> ids);
List<UserAppBindDTO> findByUserAppId(Long id);
}
package com.topdraw.business.module.user.app.service;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
import com.topdraw.common.ResultInfo;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppService {
/**
* 根据ID查询
* @param id ID
* @return UserAppDTO
*/
UserAppDTO findById(Long id);
/**
* 检查账号和秘密
* @param username
* @return
*/
UserAppDTO findByUsername(String username);
/**
*
* @param resources
*/
UserAppDTO create(UserApp resources);
/**
*
* @param resources
*/
UserAppDTO update(UserApp resources);
/**
*
* @param id
*/
void delete(Long id);
/**
*
* @param resources
* @return
*/
boolean updateLastActiveTime(UserAppBind resources);
/**
*
* @param resources
* @return
*/
boolean updatePasswordByUsername(UserApp resources);
/**
*
* @param resources
* @return
*/
boolean updatePasswordById(UserApp resources);
/**
*
* @param resources
* @return
*/
UserAppSimpleDTO updateAppInfo(UserApp resources);
boolean appCancellation(Long id);
boolean updateAppLastActiveTimeAndNicknameAndHeadImg(UserApp resources);
boolean updateAppLastActiveTimeAndNicknameAndHeadImgById(UserApp resources);
ResultInfo saveAppAndBindApple4Vis(VisUserApple resources);
ResultInfo saveAppAndBindWeibo4Vis(VisUserWeibo resources);
ResultInfo saveAppAndBindWeixin4Vis(VisUserWeixin resources);
ResultInfo saveAppAndBindQq4Vis(VisUserQq resources);
}
package com.topdraw.business.module.user.app.service.dto;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import lombok.Data;
import java.io.Serializable;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/7/11 21:21
* @version: :
* @modified By:
* @since : modified in 2022/7/11 21:21
*/
@Data
public class AppRegisterDTO implements Serializable {
private UserAppDTO userAppDTO;
private MemberDTO memberDTO;
}
package com.topdraw.business.module.user.app.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Data
public class UserAppBindDTO implements Serializable {
// 主键
private Long id;
// 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
private Integer accountType;
// 第三方账号
private String account;
// app账号id
private Long userAppId;
// 绑定状态 0:解绑;1 绑定
private Integer status;
// 昵称
private String nickname;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
}
package com.topdraw.business.module.user.app.service.dto;
import lombok.Data;
import javax.persistence.Transient;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Data
public class UserAppDTO implements Serializable {
private Integer accountType;
// 第三方账号
private String account;
// ID
private Long id;
// 会员id
private Long memberId;
// 用户名(一般为手机号)
private String username;
// 密码
private String password;
// 类型 0:苹果;1:安卓;-1:未知
private Integer type;
// 状态 0:禁用;1:生效;-1:注销
private Integer status;
// 昵称
private String nickname;
// 头像地址
private String headimgurl;
// 邮箱
private String email;
// 手机号
private String cellphone;
// 性别 0:女;1:男;-1:其他
private Integer gender;
// 生日
private String birthday;
// 最近活跃时间
private Timestamp lastActiveTime;
// 注销时间
private Timestamp deleteTime;
// 标签
private String tags;
// 描述
private String description;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
}
package com.topdraw.business.module.user.app.service.dto;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Data
public class UserAppSimpleDTO implements Serializable {
// ID
private Long id;
// 会员id
private Long memberId;
// 用户名(一般为手机号)
private String username;
// 状态 0:禁用;1:生效;-1:注销
private Integer status;
// 昵称
private String nickname;
// 头像地址
private String headimgurl;
// 邮箱
private String email;
// 手机号
private String cellphone;
// 性别 0:女;1:男;-1:其他
private Integer gender;
// 生日
private String birthday;
// 标签
private String tags;
// 描述
private String description;
private MemberSimpleDTO member;
}
package com.topdraw.business.module.user.app.service.impl;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.user.app.repository.UserAppBindRepository;
import com.topdraw.business.module.user.app.service.UserAppBindService;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
import com.topdraw.business.module.user.app.service.mapper.UserAppBindMapper;
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 org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import java.util.List;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserAppBindServiceImpl implements UserAppBindService {
@Autowired
private UserAppBindRepository userAppBindRepository;
@Autowired
private UserAppBindMapper userAppBindMapper;
@Override
public UserAppBindDTO findById(Long id) {
UserAppBind userAppBind = this.userAppBindRepository.findById(id).orElseGet(UserAppBind::new);
ValidationUtil.isNull(userAppBind.getId(),"UserAppBind","id",id);
return this.userAppBindMapper.toDto(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserAppBindDTO create(UserAppBind resources) {
UserAppBind userAppBind = this.userAppBindRepository.save(resources);
return this.userAppBindMapper.toDto(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(UserAppBind resources) {
UserAppBind userAppBind = this.userAppBindRepository.findById(resources.getId()).orElseGet(UserAppBind::new);
ValidationUtil.isNull( userAppBind.getId(),"UserAppBind","id",resources.getId());
userAppBind.copy(resources);
this.userAppBindRepository.save(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
UserAppBind UserAppBind = this.userAppBindRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserAppBind.class, id), 1));
this.userAppBindRepository.delete(UserAppBind);
}
@Override
public UserAppBindDTO findFirstByAccount(String account) {
UserAppBind userAppBind = this.userAppBindRepository.findFirstByAccount(account).orElseGet(UserAppBind::new);
return this.userAppBindMapper.toDto(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean cancelUserAppBind(String account, Integer accountType) {
return this.userAppBindRepository.cancelUserAppBind(account, accountType) > 0;
}
@Override
@Transactional(readOnly = true)
public UserAppBindDTO findFirstByAccountAndAccountType(String account, Integer accountType) {
UserAppBind userAppBind = this.userAppBindRepository.findFirstByAccountAndAccountType(account, accountType).orElseGet(UserAppBind::new);
return this.userAppBindMapper.toDto(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateThirdAccount(UserAppBind resources) {
return this.userAppBindRepository.updateThirdAccount(resources) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateThirdAccountNickname(UserAppBind resources) {
return this.userAppBindRepository.updateThirdAccountNickname(resources) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateValidStatusAndUserAppIdAndNickname(UserAppBind resources) {
return this.userAppBindRepository.updateValidStatusAndUserAppIdAndNickname(resources) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean appCancellation(List<Long> ids) {
return this.userAppBindRepository.appCancellation(ids) > 0;
}
@Override
@Transactional(readOnly = true)
public List<UserAppBindDTO> findByUserAppId(Long id) {
List<UserAppBind> userAppBinds = this.userAppBindRepository.findByUserAppId(id);
return this.userAppBindMapper.toDto(userAppBinds);
}
}
package com.topdraw.business.module.user.app.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserAppBindMapper extends BaseMapper<UserAppBindDTO, UserAppBind> {
}
package com.topdraw.business.module.user.app.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserAppMapper extends BaseMapper<UserAppDTO, UserApp> {
}
package com.topdraw.business.module.user.app.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.domain.UserAppSimple;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserAppSimpleMapper extends BaseMapper<UserAppSimpleDTO, UserAppSimple> {
}
......@@ -24,28 +24,17 @@ public class UserTvBuilder {
private static final String DEFAULT_CREATE_BY = "system";
private static final String DEFAULT_UPDATE_BY = "system";
public static UserTv build(UserTv userTv){
return build(userTv.getMemberId(),userTv.getMemberCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
}
public static UserTv build(Long memberId, String memberCode , UserTv userTv){
return build(memberId,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
}
public static UserTv build(String memberCode, UserTv userTv){
return build(null,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
}
public static UserTv build(Member member, UserTv userTv){
return build(member.getId() , member.getCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId(),
userTv.getPlatform(), userTv.getPassword(), userTv.getGroups());
}
public static UserTv build(Long memberId , String memberCode , Long id , String platformAccount , String nickname , String username,
Integer loginDays , Integer status ,Integer continueDays , String createBy , String updateBy,Long visUserId){
Integer loginDays , Integer status ,Integer continueDays , String createBy , String updateBy,Long visUserId,
String platform, String password, String groups){
Assert.notNull(memberId,GlobeExceptionMsg.MEMBER_ID_IS_NULL);
Assert.notNull(memberCode,GlobeExceptionMsg.MEMBER_CODE_IS_NULL);
Assert.notNull(platformAccount,GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
......@@ -55,10 +44,13 @@ public class UserTvBuilder {
UserTv userTv = new UserTv();
userTv.setId(id);
userTv.setPlatformAccount(platformAccount);
userTv.setPlatform(platform);
userTv.setMemberCode(memberCode);
userTv.setMemberId(memberId);
userTv.setNickname(StringUtils.isBlank(nickname)?platformAccount:nickname);
userTv.setUsername(StringUtils.isBlank(username)?platformAccount:username);
userTv.setPassword(password);
userTv.setGroups(groups);
userTv.setLoginDays(Objects.nonNull(loginDays)?loginDays:DEFAULT_VALUE);
userTv.setLoginType(DEFAULT_VALUE);
userTv.setStatus(Objects.nonNull(status)?status:DEFAULT_VALUE);
......
package com.topdraw.business.module.user.iptv.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.topdraw.business.module.common.domain.AsyncMqModule;
import com.topdraw.business.module.common.validated.CreateGroup;
import com.topdraw.business.module.common.validated.UpdateGroup;
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 javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2021-12-16
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_tv")
public class UserTvSimple extends AsyncMqModule implements Serializable {
/** ID */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/** 会员id */
@Column(name = "member_id")
private Long memberId;
/** 原vis_user_id */
@Column(name = "vis_user_id")
private Long visUserId;
/** 绑定的小屏账户会员编码 */
@Column(name = "priority_member_code")
private String priorityMemberCode;
/** 绑定的小屏账户会员编码 */
@Column(name = "platform_account")
private String platformAccount;
public void copy(UserTvSimple source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false));
}
}
package com.topdraw.business.module.user.iptv.growreport.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.io.Serializable;
/**
* @author XiangHan
* @date 2022-07-07
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_growth_report")
public class GrowthReport implements Serializable {
@Id
@Column(name = "id")
private Long id;
// 用户id
@Column(name = "user_id")
private Long userId;
// 会员id
@Column(name = "member_id")
private Long memberId;
// 会员code
@Column(name = "member_code")
private String memberCode;
// 大屏账号
@Column(name = "platform_account")
private String platformAccount;
// 开始日期
@Column(name = "start_date")
private String startDate;
// 结束时间
@Column(name = "end_date")
private String endDate;
// 栏目播放时长数据
@Column(name = "data")
private String data;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 修改时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(GrowthReport source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.iptv.growreport.repository;
import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
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-07-07
*/
public interface GrowthReportRepository extends JpaRepository<GrowthReport, Long>, JpaSpecificationExecutor<GrowthReport> {
Optional<GrowthReport> findByPlatformAccountAndStartDateAndEndDate(String platformAccount, String weekFirstDay, String weekLastDay);
@Modifying
@Query(value = "UPDATE `uc_growth_report` SET `data` = ?2, `update_time` = now() WHERE `id` =?1", nativeQuery = true)
Integer updateGrowthReportData(Long id, String data);
}
package com.topdraw.business.module.user.iptv.growreport.rest;
import com.topdraw.common.ResultInfo;
import com.topdraw.annotation.Log;
import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
/**
* @author XiangHan
* @date 2022-07-07
*/
@Api(tags = "GrowthReport管理")
@RestController
@RequestMapping("/api/GrowthReport")
public class GrowthReportController {
@Autowired
private GrowthReportService GrowthReportService;
@Log
@PostMapping
@ApiOperation("新增GrowthReport")
public ResultInfo create(@Validated @RequestBody GrowthReport resources) {
GrowthReportService.create(resources);
return ResultInfo.success();
}
@Log
@PutMapping
@ApiOperation("修改GrowthReport")
public ResultInfo update(@Validated @RequestBody GrowthReport resources) {
GrowthReportService.update(resources);
return ResultInfo.success();
}
@Log
@DeleteMapping(value = "/{id}")
@ApiOperation("删除GrowthReport")
public ResultInfo delete(@PathVariable Long id) {
GrowthReportService.delete(id);
return ResultInfo.success();
}
}
package com.topdraw.business.module.user.iptv.growreport.service;
import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
/**
* @author XiangHan
* @date 2022-07-07
*/
public interface GrowthReportService {
/**
* 根据ID查询
* @param id ID
* @return GrowthReportDTO
*/
GrowthReportDTO findById(Long id);
void create(GrowthReport resources);
void update(GrowthReport resources);
void delete(Long id);
/**
*
* @param platformAccount
* @param weekFirstDay
* @param weekLastDay
* @return
*/
GrowthReportDTO findByPlatformAccountAndStartDateAndEndDate(String platformAccount, String weekFirstDay, String weekLastDay);
Integer updateGrowthReportData(Long id, String data);
}
package com.topdraw.business.module.user.iptv.growreport.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
/**
* @author XiangHan
* @date 2022-07-07
*/
@Data
public class GrowthReportDTO implements Serializable {
// 处理精度丢失问题
@JsonSerialize(using= ToStringSerializer.class)
private Long id;
// 用户id
private Long userId;
// 会员id
private Long memberId;
// 会员code
private String memberCode;
// 大屏账号
private String platformAccount;
// 开始日期
private String startDate;
// 结束时间
private String endDate;
// 栏目播放时长数据
private String data;
// 创建时间
private Timestamp createTime;
// 修改时间
private Timestamp updateTime;
}
package com.topdraw.business.module.user.iptv.growreport.service.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
/**
* @author XiangHan
* @date 2022-07-07
*/
@Data
public class GrowthReportRequest implements Serializable {
private String platformAccount;
private List<CategoryContent> playDurationWithCategory;
@Data
public static class CategoryContent{
private String categoryName;
private Long playDuration;
private String categoryCode;
}
}
package com.topdraw.business.module.user.iptv.growreport.service.impl;
import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.user.iptv.growreport.repository.GrowthReportRepository;
import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService;
import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
import com.topdraw.business.module.user.iptv.growreport.service.mapper.GrowthReportMapper;
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 org.springframework.dao.EmptyResultDataAccessException;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
* @date 2022-07-07
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class GrowthReportServiceImpl implements GrowthReportService {
@Autowired
private GrowthReportRepository growthReportRepository;
@Autowired
private GrowthReportMapper growthReportMapper;
@Override
@Transactional(readOnly = true)
public GrowthReportDTO findById(Long id) {
GrowthReport growthReport = this.growthReportRepository.findById(id).orElseGet(GrowthReport::new);
ValidationUtil.isNull(growthReport.getId(),"GrowthReport","id",id);
return this.growthReportMapper.toDto(growthReport);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(GrowthReport resources) {
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
resources.setId(snowflake.nextId());
this.growthReportRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(GrowthReport resources) {
GrowthReport growthReport = this.growthReportRepository.findById(resources.getId()).orElseGet(GrowthReport::new);
ValidationUtil.isNull( growthReport.getId(),"GrowthReport","id",resources.getId());
growthReport.copy(resources);
this.growthReportRepository.save(growthReport);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
GrowthReport growthReport = this.growthReportRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", GrowthReport.class, id), 1));
this.growthReportRepository.delete(growthReport);
}
@Override
@Transactional(readOnly = true)
public GrowthReportDTO findByPlatformAccountAndStartDateAndEndDate(String platformAccount, String weekFirstDay, String weekLastDay) {
GrowthReport growthReport = this.growthReportRepository.findByPlatformAccountAndStartDateAndEndDate(platformAccount, weekFirstDay, weekLastDay).orElseGet(GrowthReport::new);
return this.growthReportMapper.toDto(growthReport);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateGrowthReportData(Long id, String data) {
return this.growthReportRepository.updateGrowthReportData(id, data);
}
}
package com.topdraw.business.module.user.iptv.growreport.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-07-07
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface GrowthReportMapper extends BaseMapper<GrowthReportDTO, GrowthReport> {
}
package com.topdraw.business.module.user.iptv.repository;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
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;
/**
......@@ -17,4 +23,13 @@ public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecif
Optional<UserTv> findByPriorityMemberCode(String memberCode);
Optional<UserTv> findByMemberId(Long memberId);
@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);
}
......
package com.topdraw.business.module.user.iptv.repository;
import com.topdraw.business.module.user.iptv.domain.UserTvSimple;
import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
/**
* @author XiangHan
* @date 2021-12-16
*/
public interface UserTvSimpleRepository extends JpaRepository<UserTvSimple, Long>, JpaSpecificationExecutor<UserTvSimple> {
@Query(value = "SELECT `id`, `vis_user_id` , `member_id` , `platform_account`, `priority_member_code` FROM `uc_user_tv` WHERE `platform_account` = ?1", nativeQuery = true)
UserTvSimple findSimpleByPlatformAccount(String platformAccount);
}
package com.topdraw.business.module.user.iptv.rest;
import com.topdraw.annotation.AnonymousAccess;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.UserTvService;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.common.ResultInfo;
import com.topdraw.exception.BadRequestException;
import com.topdraw.exception.GlobeExceptionMsg;
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.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
* @author XiangHan
* @date 2021-12-16
*/
@Api(tags = "微信管理")
@RestController
@RequestMapping("/uce/userTv")
@Slf4j
public class UserTvController {
@Autowired
private UserTvService userTvService;
@PostMapping(value = "/updateUserTvVisUserId")
@ApiOperation("新增UserWeixin")
@AnonymousAccess
public ResultInfo updateUserTvVisUserId(@Validated @RequestBody UserTv resources) {
log.info("UserOperationController ==> updateUserTvVisUserId ==>> param ==> {}",resources);
if (StringUtils.isBlank(resources.getPlatformAccount())){
throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
}
if (Objects.isNull(resources.getVisUserId())){
throw new BadRequestException(GlobeExceptionMsg.VIS_USER_ID_IS_NULL);
}
UserTvDTO userTvDTO = this.userTvService.updateUserTvVisUserId(resources);
if (Objects.nonNull(userTvDTO.getId()))
return ResultInfo.success(userTvDTO);
else return ResultInfo.failure("操作失败,请检查 ==>> /uce/userTv/updateUserTvVisUserId");
}
}
......@@ -3,6 +3,7 @@ package com.topdraw.business.module.user.iptv.service;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
/**
* @author XiangHan
......@@ -51,6 +52,13 @@ public interface UserTvService {
/**
*
* @param platformAccount
* @return
*/
UserTvSimpleDTO findSimpleByPlatformAccount(String platformAccount);
/**
*
* @param memberCode
* @return
*/
......@@ -69,7 +77,7 @@ public interface UserTvService {
* @param memberCode
* @return
*/
boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId,String memberCode);
boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode);
/**
*
......@@ -77,4 +85,18 @@ public interface UserTvService {
* @return
*/
MemberDTO findMemberByPlatformAccount(String platformAccount);
/**
*
* @param resources
* @return
*/
UserTvDTO updateUserTvVisUserId(UserTv resources);
/**
*
* @param resources
* @return
*/
UserTvDTO doUpdatePriorityMemberCode(UserTv resources);
}
......
package com.topdraw.business.module.user.iptv.service.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2021-12-16
*/
@Data
public class UserTvSimpleDTO implements Serializable {
private Long visUserId;
/** 绑定的小屏账户会员编码 */
private String priorityMemberCode;
/** 会员id */
private Long memberId;
private String platformAccount;
}
package com.topdraw.business.module.user.iptv.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.aspect.AsyncMqSend;
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.module.user.iptv.domain.UserTvSimple;
import com.topdraw.business.module.user.iptv.repository.UserTvSimpleRepository;
import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
import com.topdraw.business.module.user.iptv.service.mapper.UserTvSimpleMapper;
import com.topdraw.business.RedisKeyConstants;
import com.topdraw.exception.EntityNotFoundException;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.user.iptv.repository.UserTvRepository;
import com.topdraw.business.module.user.iptv.service.UserTvService;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper;
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.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
......@@ -18,6 +29,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
......@@ -27,15 +40,26 @@ import java.util.Optional;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class UserTvServiceImpl implements UserTvService {
@Autowired
private UserTvMapper userTvMapper;
@Autowired
private UserTvSimpleMapper userTvSimpleMapper;
@Autowired
private MemberService memberService;
@Autowired
private UserTvRepository userTvRepository;
@Autowired
private UserTvSimpleRepository userTvSimpleRepository;
@Autowired
private RedisUtils redisUtils;
@AsyncMqSend
public void asyncUpdateUserTvVisUserId(UserTvDTO userTvDTO) {}
/**
* 获取大屏账户对应的会员
......@@ -46,6 +70,7 @@ public class UserTvServiceImpl implements UserTvService {
* @return
*/
@Override
@Transactional(readOnly = true)
public MemberDTO findMemberByPlatformAccount(String platformAccount){
// 大屏账户
UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
......@@ -64,6 +89,41 @@ public class UserTvServiceImpl implements UserTvService {
throw new EntityNotFoundException(UserTvDTO.class,"platformAccount", GlobeExceptionMsg.IPTV_IS_NULL);
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserTvDTO updateUserTvVisUserId(UserTv resources) {
String platformAccount = resources.getPlatformAccount();
UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
if (Objects.nonNull(userTvDTO.getId())) {
Integer integer = this.userTvRepository.updateUserTvVisUserId(userTvDTO.getId(), resources.getVisUserId(), LocalDateTime.now());
if (integer == 1) {
log.info("修改大屏vis_user id成功,同步至大屏侧数据库, userTvDTO ==>> {}", userTvDTO);
((UserTvServiceImpl) AopContext.currentProxy()).asyncUpdateUserTvVisUserId(userTvDTO);
}
return this.findById(userTvDTO.getId());
}
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) {
return this.memberService.findByCode(memberCode);
}
......@@ -73,6 +133,7 @@ public class UserTvServiceImpl implements UserTvService {
}
@Override
@Transactional(readOnly = true)
public UserTvDTO findById(Long id) {
UserTv UserTv = this.userTvRepository.findById(id).orElseGet(UserTv::new);
ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id);
......@@ -123,16 +184,38 @@ public class UserTvServiceImpl implements UserTvService {
}
@Override
@Transactional(readOnly = true)
public UserTvDTO findByPlatformAccount(String platformAccount) {
Optional<UserTv> userTv = this.userTvRepository.findByPlatformAccount(platformAccount);
if (userTv.isPresent()) {
ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId());
return this.userTvMapper.toDto(userTv.get());
UserTv userTv = this.userTvRepository.findByPlatformAccount(platformAccount).orElseGet(UserTv::new);
return this.userTvMapper.toDto(userTv);
}
return null;
@Override
// @Cacheable(cacheNames = RedisKeyConstants.cacheUserTvByPlatformAccount, key = "#platformAccount")
public UserTvSimpleDTO findSimpleByPlatformAccount(String platformAccount) {
Object userTvSimpleObj = this.redisUtils.get(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount);
if (Objects.nonNull(userTvSimpleObj)) {
Map<String, Object> map = (Map<String, Object>)userTvSimpleObj;
UserTvSimpleDTO userTvSimpleDTO = new UserTvSimpleDTO();
userTvSimpleDTO.setPlatformAccount(map.get("platformAccount").toString());
userTvSimpleDTO.setMemberId(Long.valueOf(map.get("memberId").toString()));
userTvSimpleDTO.setPriorityMemberCode(map.get("priorityMemberCode") == null ? "" : map.get("priorityMemberCode").toString());
return userTvSimpleDTO;
}
UserTvSimple userTvSimple = this.userTvSimpleRepository.findSimpleByPlatformAccount(platformAccount);
if (Objects.nonNull(userTvSimple)) {
JSONObject userTvSimpleJSON = JSONObject.parseObject(JSON.toJSONString(userTvSimple), JSONObject.class);
this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, userTvSimpleJSON);
return this.userTvSimpleMapper.toDto(userTvSimple);
}
return this.userTvSimpleMapper.toDto(userTvSimple);
}
@Override
@Transactional(readOnly = true)
public UserTvDTO findByPriorityMemberCode(String memberCode) {
Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode);
if (userTv.isPresent()) {
......@@ -143,6 +226,7 @@ public class UserTvServiceImpl implements UserTvService {
}
@Override
@Transactional(readOnly = true)
public UserTvDTO findByMemberId(Long memberId) {
Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId);
if (userTv.isPresent()) {
......@@ -153,6 +237,7 @@ public class UserTvServiceImpl implements UserTvService {
}
@Override
@Transactional(readOnly = true)
public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) {
// 检查会员是否存在
this.checkMember(memberId, memberCode);
......
package com.topdraw.business.module.user.iptv.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.domain.UserTvSimple;
import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2021-12-16
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserTvSimpleMapper extends BaseMapper<UserTvSimpleDTO, UserTvSimple> {
}
......@@ -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);
}
}
......
package com.topdraw.weixin.subscribe.domain;
package com.topdraw.business.module.user.weixin.subscribe.domain;
import lombok.Data;
import lombok.experimental.Accessors;
......@@ -54,14 +54,22 @@ public class WechatSubscribeRecord implements Serializable {
@Column(name = "entity_type")
private Integer entityType;
// 来源类型 1:大屏;2:营销活动;3:其他;
@Column(name = "source_type")
private Integer sourceType;
// 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他;
@Column(name = "source_scence")
private Integer sourceScence;
// 来源描述
// 来源描述,前端参数源
@Column(name = "source_info")
private String sourceInfo;
// 来源描述,系统/运营手动维护
@Column(name = "source_desc")
private String sourceDesc;
// 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
@Column(name = "wx_scence")
private Integer wxScence;
// 创建时间
@CreatedDate
@Column(name = "create_time")
......