Commit 837abe1b 837abe1be04d6f7f173fdd2998d3960a90097859 by xianghan

1.优化

1 parent 76303f7f
Showing 150 changed files with 1470 additions and 1290 deletions
package com.topdraw.business.module.common.domain;
import com.topdraw.business.module.common.validated.UpdateGroup;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
/**
* @author :
......@@ -16,12 +18,13 @@ import javax.persistence.Transient;
*/
@Data
@Accessors(chain = true)
public class DefaultAsyncMqModule {
@Transient
private String platformAccount;
public class AsyncMqModule {
@Transient
@NotNull(message = "memberCode can't be null" , groups = {UpdateGroup.class})
private String memberCode;
/** 运营商平台账号 */
@Transient
private String platformAccount;
}
......
package com.topdraw.business.module.common.validated;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/3/7 21:20
* @version: :
* @modified By:
* @since : modified in 2022/3/7 21:20
*/
public interface CreateGroup {
}
package com.topdraw.business.module.common.validated;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/3/7 21:20
* @version: :
* @modified By:
* @since : modified in 2022/3/7 21:20
*/
public interface UpdateGroup {
}
......@@ -12,6 +12,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
* @author XiangHan
......@@ -24,94 +25,94 @@ import java.sql.Timestamp;
@Table(name="m_coupon")
public class Coupon implements Serializable {
// id
/** id */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 标识
/** 标识 */
@Column(name = "code", nullable = false)
private String code;
// 名称
/** 名称 */
@Column(name = "title", nullable = false)
private String title;
// 图片
/** 图片 */
@Column(name = "images")
private String images;
// 发行量,-1代表不限量
/** 发行量,-1代表不限量 */
@Column(name = "stock")
private Integer stock;
// 剩余量,-1代表不限量
/** 剩余量,-1代表不限量 */
@Column(name = "remain_stock")
private Integer remainStock;
// 优惠形式:1:现金;2:折扣
/** 优惠形式:1:现金;2:折扣 */
@Column(name = "use_type")
private Integer useType;
// 面额
/** 面额 */
@Column(name = "denomination")
private BigDecimal denomination;
// 折扣
/** 折扣 */
@Column(name = "discount")
private BigDecimal discount;
// 适用用户范围:1:新用户;2:全体用户
/** 适用用户范围:1:新用户;2:全体用户 */
@Column(name = "user_range")
private Integer userRange;
// 限领次数 -1:无限次; >0:具体次数
/** 限领次数 -1:无限次; >0:具体次数 */
@Column(name = "collect_limit")
private Integer collectLimit;
// 适用门槛:1:无门槛;2:满减形式
/** 适用门槛:1:无门槛;2:满减形式 */
@Column(name = "threshold_type")
private Integer thresholdType;
// 满减门槛
/** 满减门槛 */
@Column(name = "amount_threshold")
private BigDecimal amountThreshold;
// 产品范围:1:全部商品;2:指定商品
/** 产品范围:1:全部商品;2:指定商品 */
@Column(name = "item_range")
private Integer itemRange;
// 生效形式:1:固定日期;2:相对日期
/** 生效形式:1:固定日期;2:相对日期 */
@Column(name = "effect_type")
private Integer effectType;
// 生效时间
/** 生效时间 */
@Column(name = "start_time")
private Timestamp startTime;
// 过期时间
/** 过期时间 */
@Column(name = "expire_time")
private Timestamp expireTime;
private LocalDateTime expireTime;
// 自领取当日,几天内有效
/** 自领取当日,几天内有效 */
@Column(name = "valid_days")
private Integer validDays;
// 使用说明
/** 使用说明 */
@Column(name = "description")
private String description;
// 状态0:未开始,1:启用;2:停用
/** 状态0:未开始,1:启用;2:停用 */
@Column(name = "status")
private Integer status;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
package com.topdraw.business.module.coupon.domain;
import com.topdraw.business.module.coupon.service.dto.CouponDTO;
import com.topdraw.util.IdWorker;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* 优惠券
*/
public class CouponBuilder {
public static Coupon build(CouponDTO couponDTO){
Coupon coupon = new Coupon();
BeanUtils.copyProperties(couponDTO,coupon);
return build(coupon.getId(),
coupon.getCode(),
coupon.getTitle(),coupon.getImages(),coupon.getStock(),coupon.getRemainStock(),coupon.getUseType(),
coupon.getDenomination(),coupon.getDiscount(),coupon.getUserRange(),coupon.getCollectLimit(),
coupon.getThresholdType(),coupon.getAmountThreshold(),coupon.getItemRange(),coupon.getEffectType(),
coupon.getStartTime(),coupon.getExpireTime(),coupon.getValidDays(),coupon.getDescription(),coupon.getStatus());
}
public static Coupon build(Coupon coupon){
return build(coupon.getId(),
coupon.getCode(),
coupon.getTitle(),coupon.getImages(),coupon.getStock(),coupon.getRemainStock(),coupon.getUseType(),
coupon.getDenomination(),coupon.getDiscount(),coupon.getUserRange(),coupon.getCollectLimit(),
coupon.getThresholdType(),coupon.getAmountThreshold(),coupon.getItemRange(),coupon.getEffectType(),
coupon.getStartTime(),coupon.getExpireTime(),coupon.getValidDays(),coupon.getDescription(),coupon.getStatus());
}
public static Coupon build(Long id , String code , String title,
String images,
Integer stock,
Integer remainStock,
Integer useType,
BigDecimal denomination,
BigDecimal discount,
Integer userRange,
Integer collectLimit,
Integer thresholdType,
BigDecimal amountThreshold,
Integer itemRange,
Integer effectType,
Timestamp startTime,
LocalDateTime expireTime,
Integer validDays,String description , Integer status){
Coupon coupon = new Coupon();
coupon.setId(id);
coupon.setCode(StringUtils.isBlank(code)? IdWorker.generatorCode("coupon"):code);
coupon.setTitle(StringUtils.isBlank(title)?null:title);
coupon.setImages(StringUtils.isBlank(images)?null:images);
coupon.setStock(Objects.isNull(stock)?null:stock);
coupon.setRemainStock(Objects.isNull(remainStock)?null:remainStock);
coupon.setUseType(Objects.isNull(useType)?null:useType);
coupon.setDenomination(Objects.isNull(denomination)?null:denomination);
coupon.setDiscount(Objects.isNull(discount)?null:discount);
coupon.setUserRange(Objects.isNull(userRange)?null:userRange);
coupon.setCollectLimit(collectLimit);
coupon.setThresholdType(Objects.isNull(thresholdType)?null:thresholdType);
coupon.setAmountThreshold(Objects.isNull(amountThreshold)?null:amountThreshold);
coupon.setItemRange(Objects.isNull(itemRange)?null:itemRange);
coupon.setEffectType(Objects.isNull(effectType)?null:effectType);
coupon.setStartTime(Objects.isNull(startTime)?null: startTime);
coupon.setExpireTime(Objects.isNull(expireTime)?null:expireTime);
coupon.setValidDays(validDays);
coupon.setDescription(StringUtils.isBlank(description)?"":description);
coupon.setStatus(Objects.nonNull(status)?status:0);
return coupon;
}
}
......@@ -10,7 +10,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
......@@ -24,54 +23,54 @@ import java.time.LocalDateTime;
@Table(name="m_coupon_history")
public class CouponHistory implements Serializable {
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 优惠券id
/** 优惠券id */
@Column(name = "coupon_id")
private Long couponId;
// 领券用户id(对应账号)
/** 领券用户id(对应账号) */
@Column(name = "user_id")
private Long userId;
// 优惠券code
/** 优惠券code */
@Column(name = "coupon_code")
private String couponCode;
// 领取人昵称
/** 领取人昵称 */
@Column(name = "user_nickname")
private String userNickname;
// 领取时间
/** 领取时间 */
@Column(name = "receive_time")
private LocalDateTime receiveTime;
// 失效时间
/** 失效时间 */
@Column(name = "expire_time")
private LocalDateTime expireTime;
// 使用状态 0:未使用;1:已使用;-1:已过期
/** 使用状态 0:未使用;1:已使用;-1:已过期 */
@Column(name = "use_status")
private Integer useStatus;
// 使用时间
/** 使用时间 */
@Column(name = "use_time")
private LocalDateTime useTime;
// 订单详情id
/** 订单详情id */
@Column(name = "order_detail_id")
private Long orderDetailId;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private LocalDateTime createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private LocalDateTime updateTime;
......
package com.topdraw.business.module.coupon.history.domain;
import com.topdraw.business.module.coupon.domain.Coupon;
import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* 优惠券
*/
public class CouponHistoryBuilder {
public static CouponHistory build(CouponHistory couponHistory){
return build(couponHistory.getId(),
couponHistory.getCouponId(),
couponHistory.getUserId(),
couponHistory.getCouponCode(),
couponHistory.getUserNickname(),
couponHistory.getReceiveTime(),
couponHistory.getExpireTime(),
couponHistory.getUseStatus(),
couponHistory.getUseTime(),
couponHistory.getOrderDetailId());
}
public static CouponHistory build(Coupon coupon, Long userId, String userNickname){
return build(coupon,userId,userNickname,null);
}
public static CouponHistory build(Coupon coupon, Long userId, String userNickname, Long orderDetailId){
return build(null,
coupon.getId(),userId,coupon.getCode(),userNickname,LocalDateTime.now(),
coupon.getExpireTime(),coupon.getStatus(),null,orderDetailId);
}
public static CouponHistory build(Long id , Long couponId , Long userId, String couponCode, String userNickname, LocalDateTime receiveTime,
LocalDateTime expireTime, Integer useStatus, LocalDateTime useTime,
Long orderDetailId) {
CouponHistory couponHistory = new CouponHistory();
couponHistory.setId(id);
couponHistory.setCouponId(Objects.isNull(couponId)?null:couponId);
couponHistory.setUserId(Objects.isNull(userId)?null:userId);
couponHistory.setCouponCode(StringUtils.isBlank(couponCode)?null:couponCode);
couponHistory.setUserNickname(StringUtils.isBlank(userNickname)?null:userNickname);
couponHistory.setReceiveTime(Objects.isNull(receiveTime)?null:receiveTime);
couponHistory.setExpireTime(Objects.isNull(expireTime)?null:expireTime);
couponHistory.setUseStatus(Objects.isNull(useStatus)?0:useStatus);
couponHistory.setUseTime(Objects.isNull(useTime)?null:useTime);
couponHistory.setOrderDetailId(Objects.isNull(orderDetailId)?null:orderDetailId);
return couponHistory;
}
}
......@@ -4,7 +4,6 @@ import com.topdraw.business.module.coupon.history.domain.CouponHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
......
......@@ -2,13 +2,8 @@ package com.topdraw.business.module.coupon.history.service;
import com.topdraw.business.module.coupon.history.domain.CouponHistory;
import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO;
import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -16,20 +11,6 @@ import java.util.Map;
*/
public interface CouponHistoryService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<CouponHistoryDTO>
*/
List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria);
/**
* 根据ID查询
......@@ -38,15 +19,33 @@ public interface CouponHistoryService {
*/
CouponHistoryDTO findById(Long id);
/**
*
* @param resources
*/
void create(CouponHistory resources);
void update(CouponHistory resources);
void delete(Long id);
/**
*
* @param userId
* @return
*/
Long countByUserId(Long userId);
/**
*
* @param userId
* @param now
* @return
*/
Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now);
/**
*
* @param userId
* @param now
* @param expireTime
* @return
*/
Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime);
}
......
......@@ -3,7 +3,6 @@ package com.topdraw.business.module.coupon.history.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
......@@ -14,39 +13,39 @@ import java.time.LocalDateTime;
@Data
public class CouponHistoryDTO implements Serializable {
// 主键
/** 主键 */
private Long id;
// 优惠券id
/** 优惠券id */
private Long couponId;
// 领券用户id(对应账号)
/** 领券用户id(对应账号) */
private Long userId;
// 优惠券code
/** 优惠券code */
private String couponCode;
// 领取人昵称
/** 领取人昵称 */
private String userNickname;
// 领取时间
/** 领取时间 */
private LocalDateTime receiveTime;
// 失效时间
/** 失效时间 */
private LocalDateTime expireTime;
// 使用状态 0:未使用;1:已使用;-1:已过期
/** 使用状态 0:未使用;1:已使用;-1:已过期 */
private Integer useStatus;
// 使用时间
/** 使用时间 */
private LocalDateTime useTime;
// 订单详情id
/** 订单详情id */
private Long orderDetailId;
// 创建时间
/** 创建时间 */
private LocalDateTime createTime;
// 更新时间
/** 更新时间 */
private LocalDateTime updateTime;
}
......
package com.topdraw.business.module.coupon.history.service.impl;
import com.topdraw.business.module.coupon.history.domain.CouponHistory;
import com.topdraw.business.module.coupon.history.domain.CouponHistoryBuilder;
import com.topdraw.business.module.coupon.history.repository.CouponHistoryRepository;
import com.topdraw.business.module.coupon.history.service.CouponHistoryService;
import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO;
import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryQueryCriteria;
import com.topdraw.business.module.coupon.history.service.mapper.CouponHistoryMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -32,67 +23,38 @@ import java.util.Map;
public class CouponHistoryServiceImpl implements CouponHistoryService {
@Autowired
private CouponHistoryRepository CouponHistoryRepository;
private CouponHistoryMapper couponHistoryMapper;
@Autowired
private CouponHistoryMapper CouponHistoryMapper;
@Override
public Map<String, Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable) {
Page<CouponHistory> page = CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(CouponHistoryMapper::toDto));
}
private CouponHistoryRepository couponHistoryRepository;
@Override
public List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria) {
return CouponHistoryMapper.toDto(CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
public CouponHistoryDTO findById(Long id) {
CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseGet(CouponHistory::new);
ValidationUtil.isNull(CouponHistory.getId(),"CouponHistory","id",id);
return CouponHistoryMapper.toDto(CouponHistory);
CouponHistory couponHistory = this.couponHistoryRepository.findById(id).orElseGet(CouponHistory::new);
ValidationUtil.isNull(couponHistory.getId(),"CouponHistory","id",id);
return this.couponHistoryMapper.toDto(couponHistory);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(CouponHistory resources) {
CouponHistoryRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(CouponHistory resources) {
CouponHistory CouponHistory = CouponHistoryRepository.findById(resources.getId()).orElseGet(CouponHistory::new);
ValidationUtil.isNull( CouponHistory.getId(),"CouponHistory","id",resources.getId());
CouponHistory.copy(resources);
CouponHistoryRepository.save(CouponHistory);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", CouponHistory.class, id), 1));
CouponHistoryRepository.delete(CouponHistory);
CouponHistory couponHistory = CouponHistoryBuilder.build(resources);
this.couponHistoryRepository.save(couponHistory);
}
@Override
public Long countByUserId(Long userId) {
return this.CouponHistoryRepository.countByUserId(userId);
return this.couponHistoryRepository.countByUserId(userId);
}
@Override
public Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now) {
return this.CouponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now);
return this.couponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now);
}
@Override
public Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime) {
return this.CouponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime);
return this.couponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime);
}
}
......
......@@ -13,4 +13,5 @@ import java.util.Optional;
public interface CouponRepository extends JpaRepository<Coupon, Long>, JpaSpecificationExecutor<Coupon> {
Optional<Coupon> findFirstByCode(String code);
}
......
package com.topdraw.business.module.coupon.service;
import com.topdraw.business.module.coupon.domain.Coupon;
import com.topdraw.business.module.coupon.service.dto.CouponDTO;
import com.topdraw.business.module.coupon.service.dto.CouponQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,37 +9,18 @@ import java.util.Map;
public interface CouponService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(CouponQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<CouponDTO>
*/
List<CouponDTO> queryAll(CouponQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return CouponDTO
*/
CouponDTO findById(Long id);
void create(Coupon resources);
void update(Coupon resources);
void delete(Long id);
/**
* Code校验
* @param code
* @return CouponDTO
*/
CouponDTO getByCode(String code);
}
......
......@@ -5,6 +5,7 @@ import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
......@@ -14,69 +15,69 @@ import java.sql.Timestamp;
@Data
public class CouponDTO implements Serializable {
// id
/** id */
private Long id;
// 标识
/** 标识 */
private String code;
// 名称
/** 名称 */
private String title;
// 图片
/** 图片 */
private String images;
// 发行量,-1代表不限量
/** 发行量,-1代表不限量 */
private Integer stock;
// 剩余量,-1代表不限量
/** 剩余量,-1代表不限量 */
private Integer remainStock;
// 优惠形式:1:现金;2:折扣
/** 优惠形式:1:现金;2:折扣 */
private Integer useType;
// 面额
/** 面额 */
private BigDecimal denomination;
// 折扣
/** 折扣 */
private BigDecimal discount;
// 适用用户范围:1:新用户;2:全体用户
/** 适用用户范围:1:新用户;2:全体用户 */
private Integer userRange;
// 限领次数 -1:无限次; >0:具体次数
/** 限领次数 -1:无限次; >0:具体次数 */
private Integer collectLimit;
// 适用门槛:1:无门槛;2:满减形式
/** 适用门槛:1:无门槛;2:满减形式 */
private Integer thresholdType;
// 满减门槛
/** 满减门槛 */
private BigDecimal amountThreshold;
// 产品范围:1:全部商品;2:指定商品
/** 产品范围:1:全部商品;2:指定商品 */
private Integer itemRange;
// 生效形式:1:固定日期;2:相对日期
/** 生效形式:1:固定日期;2:相对日期 */
private Integer effectType;
// 生效时间
/** 生效时间 */
private Timestamp startTime;
// 过期时间
private Timestamp expireTime;
/** 过期时间 */
private LocalDateTime expireTime;
// 自领取当日,几天内有效
/** 自领取当日,几天内有效 */
private Integer validDays;
// 使用说明
/** 使用说明 */
private String description;
// 状态0:未开始,1:启用;2:停用
/** 状态0:未开始,1:启用;2:停用 */
private Integer status;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
}
......
package com.topdraw.business.module.coupon.service.dto;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class CouponQueryCriteria{
}
......@@ -4,23 +4,16 @@ import com.topdraw.business.module.coupon.domain.Coupon;
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.dto.CouponQueryCriteria;
import com.topdraw.business.module.coupon.service.mapper.CouponMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -30,58 +23,24 @@ import java.util.Map;
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class CouponServiceImpl implements CouponService {
@Autowired
private CouponRepository CouponRepository;
@Autowired
private CouponMapper CouponMapper;
@Override
public Map<String, Object> queryAll(CouponQueryCriteria criteria, Pageable pageable) {
Page<Coupon> page = CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(CouponMapper::toDto));
}
@Override
public List<CouponDTO> queryAll(CouponQueryCriteria criteria) {
return CouponMapper.toDto(CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
private CouponMapper couponMapper;
@Autowired
private CouponRepository couponRepository;
@Override
public CouponDTO findById(Long id) {
Coupon Coupon = CouponRepository.findById(id).orElseGet(Coupon::new);
ValidationUtil.isNull(Coupon.getId(),"Coupon","id",id);
return CouponMapper.toDto(Coupon);
}
Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL);
@Override
@Transactional(rollbackFor = Exception.class)
public void create(Coupon resources) {
CouponRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Coupon resources) {
Coupon Coupon = CouponRepository.findById(resources.getId()).orElseGet(Coupon::new);
ValidationUtil.isNull( Coupon.getId(),"Coupon","id",resources.getId());
Coupon.copy(resources);
CouponRepository.save(Coupon);
Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new);
ValidationUtil.isNull(coupon.getId(),"Coupon","id",id);
return this.couponMapper.toDto(coupon);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
Coupon Coupon = CouponRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Coupon.class, id), 1));
CouponRepository.delete(Coupon);
}
@Override
public CouponDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? CouponMapper.toDto(CouponRepository.findFirstByCode(code).orElseGet(Coupon::new))
return StringUtils.isNotEmpty(code) ? this.couponMapper.toDto(this.couponRepository.findFirstByCode(code).orElseGet(Coupon::new))
: new CouponDTO();
}
}
......
......@@ -23,70 +23,70 @@ import java.sql.Timestamp;
@Table(name="uc_exp_detail")
public class ExpDetail implements Serializable {
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 标识
/** 标识 */
@Column(name = "code", nullable = false)
private String code;
// 应用code
/** 应用code */
@Column(name = "app_code")
private String appCode;
// 会员id
/** 会员id */
@Column(name = "member_id", nullable = false)
private Long memberId;
// 账号id
/** 账号id */
@Column(name = "account_id")
private Long accountId;
// 原始成长值
/** 原始成长值 */
@Column(name = "original_exp", nullable = false)
private Long originalExp;
// 结果成长值
/** 结果成长值 */
@Column(name = "result_exp", nullable = false)
private Long resultExp;
// 成长值变化,一般为正数
/** 成长值变化,一般为正数 */
@Column(name = "exp", nullable = false)
private Long exp;
// 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
/** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */
@Column(name = "device_type", nullable = false)
private Integer deviceType;
// 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他
/** 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 */
@Column(name = "evt_type", nullable = false)
private Integer evtType;
// 订单id(针对订购操作)
/** 订单id(针对订购操作) */
@Column(name = "order_id")
private Long orderId;
// 节目id(针对观影操作)
/** 节目id(针对观影操作) */
@Column(name = "media_id")
private Long mediaId;
// 活动id(针对参与活动)
/** 活动id(针对参与活动) */
@Column(name = "activity_id")
private Long activityId;
// 成长值变化描述,用于管理侧显示
/** 成长值变化描述,用于管理侧显示 */
@Column(name = "description", nullable = false)
private String description;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
package com.topdraw.business.module.exp.detail.domain;
import com.topdraw.exception.GlobeExceptionMsg;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
import java.util.Objects;
public class ExpDetailBuilder {
public static ExpDetail build(Long memberId, Long originalExp, Long resultExp,
Integer deviceType, Integer evtType){
ExpDetail expDetail = new ExpDetail();
expDetail.setMemberId(memberId);
expDetail.setOriginalExp(originalExp);
expDetail.setResultExp(resultExp);
expDetail.setDeviceType(deviceType);
expDetail.setEvtType(evtType);
return build(expDetail);
}
public static ExpDetail build(ExpDetail expDetail){
return build(expDetail.getId(),
expDetail.getCode(),
expDetail.getAppCode(),
expDetail.getMemberId(),
expDetail.getAccountId(),
expDetail.getOriginalExp(),expDetail.getResultExp(),
expDetail.getExp(),expDetail.getDeviceType(),
expDetail.getEvtType(), expDetail.getOrderId(), expDetail.getMediaId(),
expDetail.getActivityId(),expDetail.getDescription());
}
public static ExpDetail build(Long id, String code,
String appCode, Long memberId, Long accountId,
Long originalExp, Long resultExp, Long exp,
Integer deviceType, Integer evtType, Long orderId,
Long mediaId, Long activityId, String description){
Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL);
ExpDetail expDetail = new ExpDetail();
expDetail.setId(Objects.isNull(id)?null:id);
expDetail.setCode(StringUtils.isBlank(code)?null:code);
expDetail.setAppCode(StringUtils.isBlank(appCode)?null:appCode);
expDetail.setMemberId(Objects.isNull(memberId)?null:memberId);
expDetail.setAccountId(Objects.isNull(accountId)?null:accountId);
expDetail.setOriginalExp(Objects.isNull(originalExp)?0:originalExp);
expDetail.setResultExp(Objects.isNull(resultExp)?0:resultExp);
expDetail.setExp(Objects.isNull(exp)?0:exp);
expDetail.setDeviceType(Objects.isNull(deviceType)?null:deviceType);
expDetail.setEvtType(Objects.isNull(evtType)?null:evtType);
expDetail.setOrderId(Objects.isNull(orderId)?null:orderId);
expDetail.setMediaId(Objects.isNull(mediaId)?null:mediaId);
expDetail.setActivityId(Objects.isNull(activityId)?null:activityId);
expDetail.setDescription(StringUtils.isBlank(description)?null:description);
return expDetail;
}
}
......@@ -2,11 +2,6 @@ package com.topdraw.business.module.exp.detail.service;
import com.topdraw.business.module.exp.detail.domain.ExpDetail;
import com.topdraw.business.module.exp.detail.service.dto.ExpDetailDTO;
import com.topdraw.business.module.exp.detail.service.dto.ExpDetailQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,31 +10,28 @@ import java.util.Map;
public interface ExpDetailService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<ExpDetailDTO>
*/
List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return ExpDetailDTO
*/
ExpDetailDTO findById(Long id);
/**
*
* @param resources
*/
void create(ExpDetail resources);
/**
*
* @param resources
*/
void update(ExpDetail resources);
/**
*
* @param id
*/
void delete(Long id);
/**
......
......@@ -13,51 +13,51 @@ import java.sql.Timestamp;
@Data
public class ExpDetailDTO implements Serializable {
// 主键
/** 主键 */
private Long id;
// 标识
/** 标识 */
private String code;
// 应用code
/** 应用code */
private String appCode;
// 会员id
/** 会员id */
private Long memberId;
// 账号id
/** 账号id */
private Long accountId;
// 原始成长值
/** 原始成长值 */
private Long originalExp;
// 结果成长值
/** 结果成长值 */
private Long resultExp;
// 成长值变化,一般为正数
/** 成长值变化,一般为正数 */
private Long exp;
// 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
/** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */
private Integer deviceType;
// 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他
/** 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 */
private Integer evtType;
// 订单id(针对订购操作)
/** 订单id(针对订购操作) */
private Long orderId;
// 节目id(针对观影操作)
/** 节目id(针对观影操作) */
private Long mediaId;
// 活动id(针对参与活动)
/** 活动id(针对参与活动) */
private Long activityId;
// 成长值变化描述,用于管理侧显示
/** 成长值变化描述,用于管理侧显示 */
private String description;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
}
......
package com.topdraw.business.module.exp.detail.service.dto;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class ExpDetailQueryCriteria{
}
package com.topdraw.business.module.exp.detail.service.impl;
import com.topdraw.business.module.exp.detail.domain.ExpDetail;
import com.topdraw.business.module.exp.detail.domain.ExpDetailBuilder;
import com.topdraw.business.module.exp.detail.repository.ExpDetailRepository;
import com.topdraw.business.module.exp.detail.service.ExpDetailService;
import com.topdraw.business.module.exp.detail.service.dto.ExpDetailDTO;
import com.topdraw.business.module.exp.detail.service.dto.ExpDetailQueryCriteria;
import com.topdraw.business.module.exp.detail.service.mapper.ExpDetailMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -31,57 +26,56 @@ import java.util.Map;
public class ExpDetailServiceImpl implements ExpDetailService {
@Autowired
private ExpDetailRepository ExpDetailRepository;
private ExpDetailRepository expDetailRepository;
@Autowired
private ExpDetailMapper ExpDetailMapper;
@Override
public Map<String, Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable) {
Page<ExpDetail> page = ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(ExpDetailMapper::toDto));
}
private ExpDetailMapper expDetailMapper;
@Override
public List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria) {
return ExpDetailMapper.toDto(ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Autowired
private RedisUtils redisUtils;
@Override
public ExpDetailDTO findById(Long id) {
ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseGet(ExpDetail::new);
ExpDetail ExpDetail = this.expDetailRepository.findById(id).orElseGet(com.topdraw.business.module.exp.detail.domain.ExpDetail::new);
ValidationUtil.isNull(ExpDetail.getId(),"ExpDetail","id",id);
return ExpDetailMapper.toDto(ExpDetail);
return this.expDetailMapper.toDto(ExpDetail);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ExpDetail resources) {
ExpDetailRepository.save(resources);
ExpDetail expDetail = ExpDetailBuilder.build(resources);
this.expDetailRepository.save(expDetail);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ExpDetail resources) {
ExpDetail ExpDetail = ExpDetailRepository.findById(resources.getId()).orElseGet(ExpDetail::new);
ValidationUtil.isNull( ExpDetail.getId(),"ExpDetail","id",resources.getId());
ExpDetail.copy(resources);
ExpDetailRepository.save(ExpDetail);
this.redisUtils.doLock("expDetail::memberId::" + resources.getMemberId());
try {
ExpDetail ExpDetail = this.expDetailRepository.findById(resources.getId()).orElseGet(com.topdraw.business.module.exp.detail.domain.ExpDetail::new);
ValidationUtil.isNull( ExpDetail.getId(),"ExpDetail","id",resources.getId());
ExpDetail.copy(resources);
this.expDetailRepository.save(ExpDetail);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("expDetail::memberId::" + resources.getMemberId());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpDetail.class, id), 1));
ExpDetailRepository.delete(ExpDetail);
ExpDetail ExpDetail = this.expDetailRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.exp.detail.domain.ExpDetail.class, id), 1));
this.expDetailRepository.delete(ExpDetail);
}
@Override
public ExpDetailDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? ExpDetailMapper.toDto(ExpDetailRepository.findFirstByCode(code).orElseGet(ExpDetail::new))
return StringUtils.isNotEmpty(code) ? this.expDetailMapper.toDto(this.expDetailRepository.findFirstByCode(code).orElseGet(ExpDetail::new))
: new ExpDetailDTO();
}
}
......
package com.topdraw.business.module.exp.history.domain;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.util.IdWorker;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
import java.util.Objects;
public class ExpHistoryBuilder {
public ExpHistory build(Long memberId, Long originalExp, Long resultExp, Long exp,Integer deviceType , Integer evtType) {
ExpHistory expHistory = new ExpHistory();
expHistory.setMemberId(memberId);
expHistory.setOriginalExp(originalExp);
expHistory.setResultExp(resultExp);
expHistory.setDeviceType(deviceType);
expHistory.setEvtType(evtType);
expHistory.setExp(exp);
return build(expHistory);
}
public ExpHistory build(ExpHistory expHistory) {
return build(expHistory.getId(),expHistory.getCode(),
expHistory.getMemberId(),expHistory.getAccountId(),
expHistory.getOriginalExp(),expHistory.getResultExp(),expHistory.getExp(),
expHistory.getDeviceType(),expHistory.getEvtType(),expHistory.getOrderId(),
expHistory.getMediaId(),expHistory.getActivityId(),expHistory.getDescription());
}
public ExpHistory build(Long id,String code,Long memberId,Long accountId,
Long originalExp,Long resultExp,Long exp,
Integer deviceType,Integer evtType,Long orderId,
Long mediaId,Long activityId,String description) {
Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL);
ExpHistory expHistory = new ExpHistory();
expHistory.setId(Objects.isNull(id)?null:id);
expHistory.setCode(StringUtils.isBlank(code)? IdWorker.generatorCode("exp") :code);
expHistory.setMemberId(memberId);
expHistory.setAccountId(Objects.isNull(accountId)?null:accountId);
expHistory.setOriginalExp(Objects.isNull(originalExp)?0L:originalExp);
expHistory.setResultExp(Objects.isNull(resultExp)?0L:resultExp);
expHistory.setExp(Objects.isNull(exp)?0L:exp);
expHistory.setDeviceType(Objects.isNull(deviceType)?4:deviceType);
expHistory.setEvtType(Objects.isNull(evtType)?98:evtType);
expHistory.setOrderId(Objects.isNull(orderId)?null:orderId);
expHistory.setMediaId(Objects.isNull(mediaId)?null:mediaId);
expHistory.setActivityId(Objects.isNull(activityId)?null:activityId);
expHistory.setDescription(StringUtils.isBlank(description)?null:description);
return expHistory;
}
}
......@@ -2,11 +2,6 @@ package com.topdraw.business.module.exp.history.service;
import com.topdraw.business.module.exp.history.domain.ExpHistory;
import com.topdraw.business.module.exp.history.service.dto.ExpHistoryDTO;
import com.topdraw.business.module.exp.history.service.dto.ExpHistoryQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,33 +10,18 @@ import java.util.Map;
public interface ExpHistoryService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<ExpHistoryDTO>
*/
List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return ExpHistoryDTO
*/
ExpHistoryDTO findById(Long id);
/**
*
* @param resources
*/
void create(ExpHistory resources);
void update(ExpHistory resources);
void delete(Long id);
/**
* Code校验
* @param code
......
......@@ -4,23 +4,14 @@ import com.topdraw.business.module.exp.history.domain.ExpHistory;
import com.topdraw.business.module.exp.history.repository.ExpHistoryRepository;
import com.topdraw.business.module.exp.history.service.ExpHistoryService;
import com.topdraw.business.module.exp.history.service.dto.ExpHistoryDTO;
import com.topdraw.business.module.exp.history.service.dto.ExpHistoryQueryCriteria;
import com.topdraw.business.module.exp.history.service.mapper.ExpHistoryMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -31,57 +22,28 @@ import java.util.Map;
public class ExpHistoryServiceImpl implements ExpHistoryService {
@Autowired
private ExpHistoryRepository ExpHistoryRepository;
private ExpHistoryMapper expHistoryMapper;
@Autowired
private ExpHistoryMapper ExpHistoryMapper;
private ExpHistoryRepository expHistoryRepository;
@Override
public Map<String, Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable) {
Page<ExpHistory> page = ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(ExpHistoryMapper::toDto));
}
@Override
public List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria) {
return ExpHistoryMapper.toDto(ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
public ExpHistoryDTO findById(Long id) {
ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseGet(ExpHistory::new);
ExpHistory ExpHistory = this.expHistoryRepository.findById(id).orElseGet(ExpHistory::new);
ValidationUtil.isNull(ExpHistory.getId(),"ExpHistory","id",id);
return ExpHistoryMapper.toDto(ExpHistory);
return this.expHistoryMapper.toDto(ExpHistory);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ExpHistory resources) {
ExpHistoryRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ExpHistory resources) {
ExpHistory ExpHistory = ExpHistoryRepository.findById(resources.getId()).orElseGet(ExpHistory::new);
ValidationUtil.isNull( ExpHistory.getId(),"ExpHistory","id",resources.getId());
ExpHistory.copy(resources);
ExpHistoryRepository.save(ExpHistory);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpHistory.class, id), 1));
ExpHistoryRepository.delete(ExpHistory);
this.expHistoryRepository.save(resources);
}
@Override
public ExpHistoryDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? ExpHistoryMapper.toDto(ExpHistoryRepository.findFirstByCode(code).orElseGet(ExpHistory::new))
return StringUtils.isNotEmpty(code) ? this.expHistoryMapper.toDto(this.expHistoryRepository.findFirstByCode(code).orElseGet(ExpHistory::new))
: new ExpHistoryDTO();
}
}
......
......@@ -2,6 +2,7 @@ package com.topdraw.business.module.member.address.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.topdraw.business.module.common.domain.AsyncMqModule;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
......@@ -10,7 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
* @author XiangHan
......@@ -21,78 +22,75 @@ import java.sql.Timestamp;
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_member_address")
public class MemberAddress implements Serializable {
public class MemberAddress extends AsyncMqModule implements Serializable {
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 会员id
/** 会员id */
@Column(name = "member_id", nullable = false)
private Long memberId;
@Transient
private String memberCode;
// 类型 1:家;2:公司;3:学校
/** 类型 1:家;2:公司;3:学校 */
@Column(name = "type", nullable = false)
private Integer type;
// 是否默认地址
/** 是否默认地址 */
@Column(name = "is_default", nullable = false)
private Integer isDefault;
// 显示顺序
/** 显示顺序 */
@Column(name = "sequence")
private Integer sequence;
// 状态 0:不可用;1-可用
/** 状态 0:不可用;1-可用 */
@Column(name = "status", nullable = false)
private Integer status;
// 联系人姓名
/** 联系人姓名 */
@Column(name = "contactor", nullable = false)
private String contactor;
// 联系人电话
/** 联系人电话 */
@Column(name = "cellphone", nullable = false)
private String cellphone;
// 国家
/** 国家 */
@Column(name = "country", nullable = false)
private String country;
// 省份
/** 省份 */
@Column(name = "province", nullable = false)
private String province;
// 城市
/** 城市 */
@Column(name = "city", nullable = false)
private String city;
// 区县
/** 区县 */
@Column(name = "district", nullable = false)
private String district;
// 地址
/** 地址 */
@Column(name = "address", nullable = false)
private String address;
// 邮编
/** 邮编 */
@Column(name = "zip_code")
private String zipCode;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
private LocalDateTime createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
private LocalDateTime updateTime;
public void copy(MemberAddress source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
......
......@@ -4,13 +4,10 @@ import com.topdraw.business.module.member.address.domain.MemberAddress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
/**
* @author XiangHan
* @date 2021-10-22
*/
public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> {
Optional<MemberAddress> findByMemberIdAndSequence(Long memberId, Integer sequence);
}
......
......@@ -33,5 +33,4 @@ public interface MemberAddressService {
* @param resources
*/
void delete(Long resources);
}
......
......@@ -3,7 +3,7 @@ package com.topdraw.business.module.member.address.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
......@@ -13,51 +13,51 @@ import java.sql.Timestamp;
@Data
public class MemberAddressDTO implements Serializable {
// 主键
/** 主键 */
private Long id;
// 会员id
/** 会员id */
private Long memberId;
// 类型 1:家;2:公司;3:学校
/** 类型 1:家;2:公司;3:学校 */
private Integer type;
// 是否默认地址
/** 是否默认地址 */
private Integer isDefault;
// 显示顺序
/** 显示顺序 */
private Integer sequence;
// 状态 0:不可用;1-可用
/** 状态 0:不可用;1-可用 */
private Integer status;
// 联系人姓名
/** 联系人姓名 */
private String contactor;
// 联系人电话
/** 联系人电话 */
private String cellphone;
// 国家
/** 国家 */
private String country;
// 省份
/** 省份 */
private String province;
// 城市
/** 城市 */
private String city;
// 区县
/** 区县 */
private String district;
// 地址
/** 地址 */
private String address;
// 邮编
/** 邮编 */
private String zipCode;
// 创建时间
private Timestamp createTime;
/** 创建时间 */
private LocalDateTime createTime;
// 更新时间
private Timestamp updateTime;
/** 更新时间 */
private LocalDateTime updateTime;
}
......
......@@ -8,7 +8,6 @@ import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO;
import com.topdraw.business.module.member.address.service.mapper.MemberAddressMapper;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
......@@ -34,10 +33,7 @@ public class MemberAddressServiceImpl implements MemberAddressService {
private MemberAddressMapper memberAddressMapper;
@Autowired
private MemberAddressRepository memberAddressRepository;
@Autowired
private RedisUtils redisUtils;
@Override
public MemberAddressDTO findById(Long id) {
Assert.notNull(id,"id can't be null");
......@@ -67,7 +63,6 @@ public class MemberAddressServiceImpl implements MemberAddressService {
log.info("MemberAddressServiceImpl ==>> update ==>> param ==>> [{}]",resources);
Assert.notNull(resources.getId(),"id can't be null");
try {
this.redisUtils.doLock("MemberAddress::update::code" + resources.getId());
MemberDTO memberDTO = this.checkMember(resources);
resources.setMemberCode(memberDTO.getCode());
......@@ -78,13 +73,14 @@ public class MemberAddressServiceImpl implements MemberAddressService {
MemberAddressDTO memberAddressDTO = new MemberAddressDTO();
BeanUtils.copyProperties(memberAddress, memberAddressDTO);
return memberAddressDTO;
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("MemberAddress::update::code" + resources.getId());
}
}
@Override
......@@ -117,5 +113,4 @@ public class MemberAddressServiceImpl implements MemberAddressService {
return this.memberService.checkMember(memberId, memberCode);
}
}
......
......@@ -2,6 +2,7 @@ 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;
......@@ -9,8 +10,8 @@ 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;
import java.time.LocalDateTime;
/**
......@@ -24,115 +25,116 @@ import java.time.LocalDateTime;
@Table(name="uc_member")
public class Member implements Serializable {
// 运营商平台账号
/** 运营商平台账号 */
@Transient
private String platformAccount;
// 会员过期时间
/** 会员过期时间 */
@Column(name = "vip_expire_time", nullable = false)
private LocalDateTime vipExpireTime;
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@NotNull(message = "id can't be null!!",groups = {UpdateGroup.class})
private Long id;
// 标识
/** 标识 */
@Column(name = "code", nullable = false)
private String code;
// 类型 1:大屏;2:小屏
/** 类型 1:大屏;2:小屏 */
@Column(name = "`type`", nullable = false)
private Integer type;
// 状态 0:不可用;1:可用
/** 状态 0:不可用;1:可用 */
@Column(name = "`status`", nullable = false)
private Integer status;
// 昵称 base64
/** 昵称 base64 */
@Column(name = "nickname")
private String nickname;
// 描述
/** 描述 */
@Column(name = "description")
private String description;
// 性别 0:女;1:男;-1:未知
/** 性别 0:女;1:男;-1:未知 */
@Column(name = "gender", nullable = false)
private Integer gender;
// 生日
/** 生日 */
@Column(name = "birthday")
private String birthday;
// 头像
/** 头像 */
@Column(name = "avatar_url")
private String avatarUrl;
// 分组信息
/** 分组信息 */
@Column(name = "`groups`")
private String groups;
// 标签
/** 标签 */
@Column(name = "tags")
private String tags;
// 是否会员 0:非会员;1:会员
/** 是否会员 0:非会员;1:会员 */
@Column(name = "vip", nullable = false)
private Integer vip;
// 会员等级(对应level表的level字段,非id)
/** 会员等级(对应level表的level字段,非id) */
@Column(name = "`level`", nullable = false)
private Integer level;
// 成长值
/** 成长值 */
@Column(name = "`exp`")
private Long exp;
// 当前积分
/** 当前积分 */
@Column(name = "`points`")
private Long points;
// 即将到期积分(一个月内)
/** 即将到期积分(一个月内) */
@Column(name = "due_points")
private Long duePoints;
// 优惠券数量
/** 优惠券数量 */
@Column(name = "coupon_amount")
private Long couponAmount;
// 即将过期优惠券数量
/** 即将过期优惠券数量 */
@Column(name = "due_coupon_amount")
private Long dueCouponAmount;
// iptv账号id
/** iptv账号id */
@Column(name = "user_iptv_id")
private Long userIptvId;
// 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
/** 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 */
@Column(name = "bind_iptv_platform_type")
private Integer bindIptvPlatformType;
// iptv账号绑定时间
/** iptv账号绑定时间 */
@Column(name = "bind_iptv_time")
private LocalDateTime bindIptvTime;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private LocalDateTime createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private LocalDateTime updateTime;
// 是否在黑名单 1:是;0否
/** 是否在黑名单 1:是;0否 */
@Column(name = "black_status")
private Long blackStatus;
public void copy(Member source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false));
}
}
......
package com.topdraw.business.module.member.group.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 luerlong
* @date 2021-09-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_group")
public class Group implements Serializable {
/** ID */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/** CODE */
@Column(name = "code")
private String code;
/** 名称 */
@Column(name = "name")
private String name;
/** 状态 0-下线 1-上线 */
@Column(name = "status")
private Integer status;
/** 权限 0-测试分组 1-鉴权通过(白名单) 2-不允许精准(黑名单)3-可以精准(金名单) */
@Column(name = "permission_type")
private Integer permissionType;
public void copy(Group source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.member.group.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 2021-11-17
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_member_group")
public class MemberGroup implements Serializable {
/** ID */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/** 分组ID */
@Column(name = "group_id")
private Long groupId;
/** 会员ID */
@Column(name = "member_id")
private Long memberId;
/** 运营商平台账号 */
@Column(name = "platform_account")
private String platformAccount;
/** 手机号 */
@Column(name = "cellphone")
private String cellphone;
/** 设备 */
@Column(name = "stb_id")
private String stbId;
/** 有线MAC地址 */
@Column(name = "eth_mac")
private String ethMac;
/** 无线MAC地址 */
@Column(name = "wifi_mac")
private String wifiMac;
/** 描述 */
@Column(name = "description")
private String description;
/** 创建者 */
@Column(name = "create_by")
private String createBy;
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
/** 更新者 */
@Column(name = "update_by")
private String updateBy;
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(MemberGroup source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.member.group.repository;
import com.topdraw.business.module.member.group.domain.Group;
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;
/**
* @author luerlong
* @date 2021-09-27
*/
public interface GroupRepository extends JpaRepository<Group, Long>, JpaSpecificationExecutor<Group> {
Optional<Group> findFirstByCode(String code);
List<Group> findByName(String name);
@Query(value = "select t1.id from uc_group t1 left join uc_user__group t2 on t1.id = t2.group_id where t2.user_id = ?1 and t1.permission_type = ?2 ", nativeQuery = true)
List<Map<String, Object>> findByUserIdAndPermissionType(Long userId, Integer type);
}
package com.topdraw.business.module.member.group.repository;
import com.topdraw.business.module.member.group.domain.MemberGroup;
import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @author XiangHan
* @date 2021-11-17
*/
public interface MemberGroupRepository extends JpaRepository<MemberGroup, Long>, JpaSpecificationExecutor<MemberGroup> {
List<MemberGroupDTO> findByMemberId(Long memberId);
}
package com.topdraw.business.module.member.group.service;
import com.topdraw.business.module.member.group.service.dto.GroupDTO;
/**
* @author luerlong
* @date 2021-09-27
*/
public interface GroupService {
/**
* 根据ID查询
* @param id ID
* @return GroupDTO
*/
GroupDTO findById(Long id);
/**
* Code校验
* @param code
* @return GroupDTO
*/
GroupDTO getByCode(String code);
}
package com.topdraw.business.module.member.group.service;
import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO;
import java.util.List;
/**
* @author XiangHan
* @date 2021-11-17
*/
public interface MemberGroupService {
/**
* 通过会员id获取会员分组列表
* @param memberId
* @return
*/
List<MemberGroupDTO> findByMemberId(Long memberId);
/**
* 根据ID查询
* @param id ID
* @return MemberGroupDTO
*/
MemberGroupDTO findById(Long id);
}
package com.topdraw.business.module.member.group.service.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author luerlong
* @date 2021-09-27
*/
@Data
public class GroupDTO implements Serializable {
/** ID */
private Long id;
/** CODE */
private String code;
/** 名称 */
private String name;
/** 状态 0-下线 1-上线 */
private Integer status;
/** 权限 0-测试分组 1-鉴权通过(白名单) 2-不允许精准(黑名单)3-可以精准(金名单) */
private Integer permissionType;
}
package com.topdraw.business.module.member.group.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2021-11-17
*/
@Data
public class MemberGroupDTO implements Serializable {
/** ID */
private Long id;
/** 分组ID */
private Long groupId;
/** 会员ID */
private Long memberId;
/** 运营商平台账号 */
private String platformAccount;
/** 手机号 */
private String cellphone;
/** 设备 */
private String stbId;
/** 有线MAC地址 */
private String ethMac;
/** 无线MAC地址 */
private String wifiMac;
/** 描述 */
private String description;
/** 创建者 */
private String createBy;
/** 创建时间 */
private Timestamp createTime;
/** 更新者 */
private String updateBy;
/** 更新时间 */
private Timestamp updateTime;
}
package com.topdraw.business.module.member.group.service.impl;
import com.topdraw.business.module.member.group.domain.Group;
import com.topdraw.business.module.member.group.repository.GroupRepository;
import com.topdraw.business.module.member.group.service.GroupService;
import com.topdraw.business.module.member.group.service.dto.GroupDTO;
import com.topdraw.business.module.member.group.service.mapper.GroupMapper;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* @author luerlong
* @date 2021-09-27
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class GroupServiceImpl implements GroupService {
@Autowired
private GroupRepository groupRepository;
@Autowired
private GroupMapper groupMapper;
@Override
public GroupDTO findById(Long id) {
Group group = groupRepository.findById(id).orElseGet(Group::new);
ValidationUtil.isNull(group.getId(),"Group","id",id);
return groupMapper.toDto(group);
}
@Override
public GroupDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? groupMapper.toDto(groupRepository.findFirstByCode(code).orElseGet(Group::new))
: new GroupDTO();
}
}
package com.topdraw.business.module.member.group.service.impl;
import com.topdraw.business.module.member.group.domain.MemberGroup;
import com.topdraw.business.module.member.group.repository.MemberGroupRepository;
import com.topdraw.business.module.member.group.service.MemberGroupService;
import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO;
import com.topdraw.business.module.member.group.service.mapper.MemberGroupMapper;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author XiangHan
* @date 2021-11-17
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MemberGroupServiceImpl implements MemberGroupService {
@Autowired
private MemberGroupRepository memberGroupRepository;
@Autowired
private MemberGroupMapper memberGroupMapper;
@Override
public List<MemberGroupDTO> findByMemberId(Long memberId) {
return this.memberGroupRepository.findByMemberId(memberId);
}
@Override
public MemberGroupDTO findById(Long id) {
MemberGroup memberGroup = this.memberGroupRepository.findById(id).orElseGet(MemberGroup::new);
ValidationUtil.isNull(memberGroup.getId(),"MemberGroup","id",id);
return this.memberGroupMapper.toDto(memberGroup);
}
}
package com.topdraw.business.module.member.group.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.member.group.domain.Group;
import com.topdraw.business.module.member.group.service.dto.GroupDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author luerlong
* @date 2021-09-27
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface GroupMapper extends BaseMapper<GroupDTO, Group> {
}
package com.topdraw.business.module.member.group.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.member.group.domain.MemberGroup;
import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2021-11-17
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MemberGroupMapper extends BaseMapper<MemberGroupDTO, MemberGroup> {
}
......@@ -2,6 +2,8 @@ package com.topdraw.business.module.member.level.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
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;
......@@ -9,6 +11,8 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
......@@ -23,50 +27,53 @@ import java.sql.Timestamp;
@Table(name="uc_member_level")
public class MemberLevel 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", nullable = false)
private String code;
// 名称
/** 名称 */
@Column(name = "name", nullable = false)
private String name;
// 状态 0:未启用;1:启用
/** 状态 0:未启用;1:启用 */
@Column(name = "status", nullable = false)
private Integer status;
// 对应成长值
/** 对应成长值 */
@Column(name = "exp_value", nullable = false)
private Long expValue;
// 等级(不可重复,数字越大等级越高)
/** 等级(不可重复,数字越大等级越高) */
@Column(name = "level", nullable = false)
@Min(message = "level can't less then 1" , value = 1)
@NotNull(message = "level can't be null" , groups = {CreateGroup.class,UpdateGroup.class})
private Integer level;
// 会员徽标
/** 会员徽标 */
@Column(name = "icon_url")
private String iconUrl;
// 描述
/** 描述 */
@Column(name = "description")
private String description;
// 对应任务id,通过此字段可获得该等级所对应的权益
/** 对应任务id,通过此字段可获得该等级所对应的权益 */
@Column(name = "task_id")
private Long taskId;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
package com.topdraw.business.module.member.level.service;
import com.topdraw.business.module.member.level.domain.MemberLevel;
import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO;
import com.topdraw.business.module.member.level.service.dto.MemberLevelQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -22,10 +18,10 @@ public interface MemberLevelService {
MemberLevelDTO findById(Long id);
/**
* Code校验
* @param code
* @return MemberLevelDTO
*/
* Code校验
* @param code
* @return MemberLevelDTO
*/
MemberLevelDTO getByCode(String code);
/**
......@@ -36,4 +32,5 @@ public interface MemberLevelService {
*/
List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status);
}
......
......@@ -13,36 +13,36 @@ import java.sql.Timestamp;
@Data
public class MemberLevelDTO implements Serializable {
// 主键
/** 主键 */
private Long id;
// 标识
/** 标识 */
private String code;
// 名称
/** 名称 */
private String name;
// 状态 0:未启用;1:启用
/** 状态 0:未启用;1:启用 */
private Integer status;
// 对应成长值
/** 对应成长值 */
private Long expValue;
// 等级(不可重复,数字越大等级越高)
/** 等级(不可重复,数字越大等级越高) */
private Integer level;
// 会员徽标
/** 会员徽标 */
private String iconUrl;
// 描述
/** 描述 */
private String description;
// 对应任务id,通过此字段可获得该等级所对应的权益
/** 对应任务id,通过此字段可获得该等级所对应的权益 */
private Long taskId;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
}
......
package com.topdraw.business.module.member.level.service.dto;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class MemberLevelQueryCriteria{
}
......@@ -38,7 +38,7 @@ public class MemberLevelServiceImpl implements MemberLevelService {
@Override
public MemberLevelDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new))
: new MemberLevelDTO();
: new MemberLevelDTO();
}
@Override
......
......@@ -2,6 +2,8 @@ package com.topdraw.business.module.member.profile.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
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;
......@@ -9,6 +11,7 @@ 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;
......@@ -23,76 +26,80 @@ import java.sql.Timestamp;
@Table(name="uc_member_profile")
public class MemberProfile implements Serializable {
/** 会员code */
@Transient
@NotNull(message = "memberCode not be null!!" , groups = {CreateGroup.class, UpdateGroup.class})
private String memberCode;
/** 头像 */
@Transient
private String avatarUrl;
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@NotNull(message = "id not be null!!" , groups = UpdateGroup.class)
private Long id;
// 手机号
@Column(name = "phone")
private String phone;
// 会员id
/** 会员id */
@Column(name = "member_id", nullable = false)
private Long memberId;
@Transient
private String memberCode;
// 姓名
/** 姓名 */
@Column(name = "realname")
private String realname;
// 性别 0:女; 1:男 -1:未知
/** 性别 0:女; 1:男 -1:未知 */
@Column(name = "gender", nullable = false)
private Integer gender;
// 生日
/** 生日 */
@Column(name = "birthday", nullable = false)
private String birthday;
// 星座
/** 手机号 */
@Column(name = "phone")
private String phone;
/** 星座 */
@Column(name = "constellation")
private String constellation;
// 身份证
/** 身份证 */
@Column(name = "id_card", nullable = false)
private String idCard;
// 电子邮件
/** 电子邮件 */
@Column(name = "email")
private String email;
// 国家
/** 国家 */
@Column(name = "country")
private String country;
// 省份
/** 省份 */
@Column(name = "province")
private String province;
// 城市
/** 城市 */
@Column(name = "city")
private String city;
// 区县
/** 区县 */
@Column(name = "district")
private String district;
// 描述
/** 描述 */
@Column(name = "description")
private String description;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
......@@ -19,13 +19,13 @@ public class MemberProfileBuilder {
return memberProfile;
}
public static MemberProfile build(Long memberId , String memberCode, String realname , Integer gender, String birthday){
public static MemberProfile build(Long memberId ,String memberCode, String realname , Integer gender, String birthday){
MemberProfile memberProfile = build(memberId,memberCode,realname,gender,"","","","","","",
"","","",birthday);
return memberProfile;
}
public static MemberProfile build(Long memberId, String memberCode, String realName, Integer sex,
public static MemberProfile build(Long memberId,String memberCode, String realName, Integer sex,
String country, String district, String city, String idCard, String province,
String email, String description, String phone, String constellation,
String birthday) {
......
......@@ -77,5 +77,4 @@ public interface MemberProfileService {
* @param resources
*/
MemberProfileDTO updateMemberProfileAndMember(MemberProfile resources, MemberDTO memberDTO);
}
......
......@@ -13,60 +13,61 @@ import java.sql.Timestamp;
@Data
public class MemberProfileDTO implements Serializable {
// 超时时间
private Long vipExpireTime;
// vip
private Integer vip;
// 头像
private String avatarUrl;
// 主键
/** 主键 */
private Long id;
// 会员id
/** 会员id */
private Long memberId;
// 手机号
private String phone;
// 姓名
/** 姓名 */
private String realname;
// 性别 0:女; 1:男 -1:未知
/** 性别 0:女; 1:男 -1:未知 */
private Integer gender;
// 生日
/** 生日 */
private String birthday;
// 星座
/** 电话 */
private String phone;
/** 星座 */
private String constellation;
// 身份证
/** 身份证 */
private String idCard;
// 电子邮件
/** 电子邮件 */
private String email;
// 国家
/** 国家 */
private String country;
// 省份
/** 省份 */
private String province;
// 城市
/** 城市 */
private String city;
// 区县
/** 区县 */
private String district;
// 描述
/** 描述 */
private String description;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
/** vip */
private Integer vip;
/** vip过期时间 */
private Long vipExpireTime;
/** 头像 */
private String avatarUrl;
}
......
......@@ -9,9 +9,11 @@ import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
import com.topdraw.business.module.member.profile.service.mapper.MemberProfileMapper;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.utils.*;
import com.topdraw.util.Base64Util;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Base64Util;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
......@@ -20,6 +22,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
/**
* @author XiangHan
* @date 2021-10-22
......@@ -116,6 +119,7 @@ public class MemberProfileServiceImpl implements MemberProfileService {
BeanUtils.copyProperties(resources,memberProfile);
MemberProfile _memberProfile = this.memberProfileRepository.save(memberProfile);
MemberProfileDTO memberProfileDTO = new MemberProfileDTO();
BeanUtils.copyProperties(_memberProfile,memberProfileDTO);
return memberProfileDTO;
......@@ -157,5 +161,4 @@ public class MemberProfileServiceImpl implements MemberProfileService {
this.memberService.update(member);
}
}
......
......@@ -2,6 +2,8 @@ package com.topdraw.business.module.member.relatedinfo.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.UpdateGroup;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
......@@ -9,6 +11,7 @@ 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;
import java.time.LocalDate;
......@@ -22,38 +25,36 @@ import java.time.LocalDate;
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_member_related_info")
public class MemberRelatedInfo implements Serializable {
public class MemberRelatedInfo extends AsyncMqModule implements Serializable {
// ID
/** ID */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@NotNull(message = "id can't be null" , groups = {UpdateGroup.class})
private Long id;
// 会员id
/** 会员id */
@Column(name = "member_id", nullable = false)
private Long memberId;
@Transient
private String memberCode;
// 人物关系 0:子女;1:父母
/** 人物关系 0:子女;1:父母 */
@Column(name = "type")
private Integer type;
// 手机号
/** 手机号 */
@Column(name = "cellphone")
private String cellphone;
// 身份证号
/** 身份证号 */
@Column(name = "id_card")
private String idCard;
// 姓名
/** 姓名 */
@Column(name = "name")
private String name;
// 性别 0:女;1:男;-1:未知
/** 性别 0:女;1:男;-1:未知 */
@Column(name = "sex")
private Integer sex;
......@@ -65,12 +66,12 @@ public class MemberRelatedInfo implements Serializable {
@Column(name = "avatar_url")
private String avatarUrl;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
......@@ -4,7 +4,6 @@ import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @author XiangHan
......@@ -14,7 +13,7 @@ public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelated
MemberRelatedInfo findByIdCard(String idCard);
MemberRelatedInfo findByMemberIdAndIdCard(Long memberId , String idCard);
MemberRelatedInfo findByMemberIdAndIdCard(Long memberId, String idCard);
MemberRelatedInfo findByIdOrIdCard(Long id, String idCard);
......
......@@ -3,11 +3,6 @@ package com.topdraw.business.module.member.relatedinfo.service;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo;
import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO;
import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -60,7 +55,7 @@ public interface MemberRelatedInfoService {
* @param idCard
* @return
*/
MemberRelatedInfoDTO findByMemberIdAndIdCard(Long memberId , String idCard);
MemberRelatedInfoDTO findByMemberIdAndIdCard(Long memberId, String idCard);
/**
*
......@@ -68,7 +63,7 @@ public interface MemberRelatedInfoService {
* @param idCard
* @return
*/
MemberRelatedInfoDTO findByMemberCodeAndIdCard(String memberCode , String idCard);
MemberRelatedInfoDTO findByMemberCodeAndIdCard(String memberCode, String idCard);
/**
*
......@@ -83,6 +78,5 @@ public interface MemberRelatedInfoService {
* @param resources
* @return
*/
MemberRelatedInfoDTO findByMemberIdAndIdCard(Member member , MemberRelatedInfo resources);
MemberRelatedInfoDTO findByMemberIdAndIdCard(Member member, MemberRelatedInfo resources);
}
......
package com.topdraw.business.module.member.relatedinfo.service.dto;
import com.topdraw.annotation.Query;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class MemberRelatedInfoQueryCriteria{
@Query
private Long memberId;
}
......@@ -11,11 +11,11 @@ import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.exception.BadRequestException;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.util.Base64Util;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Base64Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
......@@ -41,7 +41,6 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService {
@Autowired
private MemberRelatedInfoRepository memberRelatedInfoRepository;
private static final String DEFAULT_IDCARD = "000000000000000000";
@Override
......@@ -104,17 +103,22 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService {
@Transactional(rollbackFor = Exception.class)
public MemberRelatedInfoDTO update(MemberRelatedInfo resources) {
log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]",resources);
try {
this.checkMemberAndEncodeRealname(resources);
this.checkMemberAndEncodeRealname(resources);
MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new);
ValidationUtil.isNull(memberRelatedInfo.getId(), "MemberRelatedInfo", "id", resources.getId());
memberRelatedInfo.copy(resources);
MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new);
ValidationUtil.isNull(memberRelatedInfo.getId(), "MemberRelatedInfo", "id", resources.getId());
memberRelatedInfo.copy(resources);
this.memberRelatedInfoRepository.save(memberRelatedInfo);
this.memberRelatedInfoRepository.save(memberRelatedInfo);
log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]", resources);
return this.memberRelatedInfoMapper.toDto(memberRelatedInfo);
log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]", resources);
return this.memberRelatedInfoMapper.toDto(memberRelatedInfo);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Override
......@@ -122,7 +126,7 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService {
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
MemberRelatedInfo MemberRelatedInfo = this.memberRelatedInfoRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberRelatedInfo.class, id), 1));
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo.class, id), 1));
this.memberRelatedInfoRepository.delete(MemberRelatedInfo);
}
......@@ -133,10 +137,10 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService {
Assert.notNull(idCard,"idCard can't be null");
if (!idCard.equalsIgnoreCase(DEFAULT_IDCARD)) {
MemberRelatedInfoDTO memberRelatedInfo = this.findByIdCard(idCard);
ValidationUtil.isNull(memberRelatedInfo.getId(),"MemberRelatedInfo","id",resources.getId());
log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> result ==>> [{}]",memberRelatedInfo);
return memberRelatedInfo;
MemberRelatedInfoDTO memberRelatedInfoDTO = this.findByIdCard(idCard);
ValidationUtil.isNull(memberRelatedInfoDTO.getId(),"MemberRelatedInfo","id",resources.getId());
log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> result ==>> [{}]",memberRelatedInfoDTO);
return memberRelatedInfoDTO;
}
return null;
......
......@@ -3,8 +3,6 @@ package com.topdraw.business.module.member.repository;
import com.topdraw.business.module.member.domain.Member;
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.List;
import java.util.Optional;
......@@ -19,9 +17,5 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif
List<Member> findByUserIptvId(Long id);
Optional<Member> findByIdOrCode(Long id,String code);
@Modifying
@Query(value = "update uc_member set `points` = ?2 , `due_points` = ?3 where id = ?1 ",nativeQuery = true)
void updateMemberPoints(Long id, Long points, Long duePoints);
Optional<Member> findByIdOrCode(Long id, String code);
}
......
......@@ -11,6 +11,8 @@ import java.util.List;
*/
public interface MemberService {
/**
* 根据ID查询
* @param id ID
......@@ -63,12 +65,11 @@ public interface MemberService {
* @param id 会员id
* @param memberCode 会员编码
*/
MemberDTO checkMember(Long id , String memberCode);
MemberDTO checkMember(Long id, String memberCode);
/**
* 检查会员信息
* @param member 会员
*/
MemberDTO checkMember(Member member);
}
......
......@@ -3,7 +3,6 @@ package com.topdraw.business.module.member.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
......@@ -14,7 +13,12 @@ import java.time.LocalDateTime;
@Data
public class MemberDTO implements Serializable {
// 会员过期时间
private String platformAccount;
// iptv绑定的主会员 0:否 1:是
private Integer iptvMajor;
// vip过期时间
private LocalDateTime vipExpireTime;
// 主键
......@@ -87,5 +91,5 @@ public class MemberDTO implements Serializable {
private LocalDateTime updateTime;
// 是否在黑名单 1:是;0否
// private Integer blackStatus;
private Long blackStatus;
}
......
......@@ -11,7 +11,8 @@ import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.member.service.mapper.MemberMapper;
import com.topdraw.exception.BadRequestException;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.utils.*;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -27,7 +28,6 @@ import java.util.Objects;
* @author XiangHan
* @date 2021-10-22
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
......@@ -60,7 +60,7 @@ public class MemberServiceImpl implements MemberService {
}
private MemberDTO findByIdOrCode(Long id,String code) {
private MemberDTO findByIdOrCode(Long id, String code) {
Member member = this.memberRepository.findByIdOrCode(id,code).orElseGet(Member::new);
ValidationUtil.isNull(member.getId(),"Member","param",code);
......@@ -129,16 +129,21 @@ public class MemberServiceImpl implements MemberService {
public MemberDTO update(Member resources) {
log.info("MemberServiceImpl ==>> update ==>> resources ==>> [{}]" , resources);
try {
MemberDTO memberDTO = this.checkMember(resources);
MemberDTO memberDTO = this.findByCode(resources.getCode());
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
member.copy(resources);
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
member.copy(resources);
this.save(member);
this.save(member);
return this.memberMapper.toDto(member);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return this.memberMapper.toDto(member);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
......@@ -150,12 +155,22 @@ public class MemberServiceImpl implements MemberService {
@Override
@Transactional(rollbackFor = Exception.class)
public MemberDTO doUpdateMemberPoints(Member resources) {
Member member = this.memberRepository.findById(resources.getId()).orElseGet(Member::new);
ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId());
member.copy(resources);
try {
//this.redisUtils.doLock("member::update::code" + resources.getCode());
this.save(member);
Member member = this.memberRepository.findById(resources.getId()).orElseGet(Member::new);
ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId());
member.copy(resources);
this.save(member);
return this.memberMapper.toDto(member);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return this.memberMapper.toDto(member);
}
}
......
......@@ -2,6 +2,7 @@ package com.topdraw.business.module.member.viphistory.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.topdraw.business.module.common.domain.AsyncMqModule;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
......@@ -22,10 +23,7 @@ import java.time.LocalDateTime;
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_member_vip_history")
public class MemberVipHistory implements Serializable {
@Transient
private String memberCode;
public class MemberVipHistory extends AsyncMqModule implements Serializable {
// 主键
@Id
......
......@@ -3,12 +3,8 @@ package com.topdraw.business.module.member.viphistory.service;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO;
import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* @author luerlong
......
......@@ -9,25 +9,17 @@ import com.topdraw.business.module.member.viphistory.domain.MemberVipHistoryBuil
import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository;
import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService;
import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO;
import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria;
import com.topdraw.business.module.member.viphistory.service.mapper.MemberVipHistoryMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @author luerlong
......@@ -107,5 +99,5 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService {
String code = resources.getCode();
return this.memberService.checkMember(memberId, code);
}
}
......
......@@ -2,6 +2,8 @@ package com.topdraw.business.module.points.available.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.topdraw.business.module.common.domain.AsyncMqModule;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
......@@ -24,53 +26,49 @@ import java.time.LocalDateTime;
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_points_available")
public class PointsAvailable implements Serializable {
public class PointsAvailable extends AsyncMqModule implements Serializable {
/** 会员编号 */
@Transient
private String memberCode;
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 标识
/** 标识 */
@Column(name = "code")
private String code;
// 积分类型 0:通用型
/** 积分类型 0:通用型 */
@Column(name = "points_type")
private Integer pointsType;
// 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
/** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */
@Column(name = "device_type")
private Integer deviceType;
// 会员id
/** 会员id */
@Column(name = "member_id", nullable = false)
private Long memberId;
// 积分值
/** 积分值 */
@Column(name = "points")
private Long points;
// 过期时间
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
/** 过期时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",locale = "")
@Column(name = "expire_time")
private LocalDateTime expireTime;
// 描述
/** 描述 */
@Column(name = "description")
private String description;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
......@@ -25,7 +25,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable
List<PointsAvailableDTO> findByMemberId(Long memberId);
List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId , LocalDateTime now);
List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime now);
/**
* 即将过期的积分
......
......@@ -2,12 +2,9 @@ package com.topdraw.business.module.points.available.service;
import com.topdraw.business.module.points.available.domain.PointsAvailable;
import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO;
import com.topdraw.business.module.points.available.service.dto.PointsAvailableQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -16,21 +13,6 @@ import java.util.Map;
public interface PointsAvailableService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<PointsAvailableDTO>
*/
List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return PointsAvailableDTO
......@@ -41,13 +23,13 @@ public interface PointsAvailableService {
*
* @param resources
*/
void create(PointsAvailable resources);
PointsAvailableDTO create(PointsAvailable resources);
/**
*
* @param resources
*/
void update(PointsAvailable resources);
PointsAvailableDTO update(PointsAvailable resources);
/**
*
......@@ -55,8 +37,6 @@ public interface PointsAvailableService {
*/
void delete(Long id);
void delete4Custom(Long id);
/**
*
* @param id
......@@ -84,7 +64,7 @@ public interface PointsAvailableService {
* @param factor 阈值
* @return
*/
Long findSoonExpireTime(Long memberId,Integer factor);
Long findSoonExpireTime(Long memberId, Integer factor);
/**
*
......@@ -107,6 +87,15 @@ public interface PointsAvailableService {
*/
long findTotalPointsByMemberId(Long memberId);
void create4Custom(PointsAvailable pointsAvailable);
/**
*
* @param id
*/
void delete4Custom(Long id);
/**
*
* @param pointsAvailable
*/
PointsAvailableDTO create4Custom(PointsAvailable pointsAvailable);
}
......
......@@ -14,33 +14,33 @@ import java.time.LocalDateTime;
@Data
public class PointsAvailableDTO implements Serializable {
// 主键
/** 主键 */
private Long id;
// 标识
/** 标识 */
private String code;
// 积分类型 0:通用型
/** 积分类型 0:通用型 */
private Integer pointsType;
// 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
/** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */
private Integer deviceType;
// 会员id
/** 会员id */
private Long memberId;
// 积分值
/** 积分值 */
private Long points;
// 过期时间
/** 过期时间 */
private LocalDateTime expireTime;
// 描述
/** 描述 */
private String description;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
}
......
package com.topdraw.business.module.points.detail.detailhistory.service.impl;
import com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory;
import com.topdraw.business.module.points.detail.detailhistory.repository.PointsDetailHistoryRepository;
import com.topdraw.business.module.points.detail.detailhistory.service.PointsDetailHistoryService;
import com.topdraw.business.module.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO;
import com.topdraw.business.module.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria;
import com.topdraw.business.module.points.detail.detailhistory.service.mapper.PointsDetailHistoryMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.StringUtils;
......@@ -31,10 +29,10 @@ import java.util.Map;
public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryService {
@Autowired
private PointsDetailHistoryRepository PointsDetailHistoryRepository;
private com.topdraw.business.module.points.detail.detailhistory.repository.PointsDetailHistoryRepository PointsDetailHistoryRepository;
@Autowired
private PointsDetailHistoryMapper PointsDetailHistoryMapper;
private com.topdraw.business.module.points.detail.detailhistory.service.mapper.PointsDetailHistoryMapper PointsDetailHistoryMapper;
@Override
public Map<String, Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) {
......@@ -49,7 +47,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic
@Override
public PointsDetailHistoryDTO findById(Long id) {
PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseGet(PointsDetailHistory::new);
PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseGet(com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory::new);
ValidationUtil.isNull(PointsDetailHistory.getId(),"PointsDetailHistory","id",id);
return PointsDetailHistoryMapper.toDto(PointsDetailHistory);
}
......@@ -63,7 +61,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic
@Override
@Transactional(rollbackFor = Exception.class)
public void update(PointsDetailHistory resources) {
PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(resources.getId()).orElseGet(PointsDetailHistory::new);
PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(resources.getId()).orElseGet(com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory::new);
ValidationUtil.isNull( PointsDetailHistory.getId(),"PointsDetailHistory","id",resources.getId());
PointsDetailHistory.copy(resources);
PointsDetailHistoryRepository.save(PointsDetailHistory);
......@@ -74,7 +72,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetailHistory.class, id), 1));
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory.class, id), 1));
PointsDetailHistoryRepository.delete(PointsDetailHistory);
}
......
package com.topdraw.business.module.points.detail.rest;
import io.swagger.annotations.Api;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Api(tags = "PointsDetail管理")
//@RestController
//@RequestMapping("/api/PointsDetail")
public class PointsDetailController {
/*@Autowired
private PointsDetailService PointsDetailService;
@GetMapping
@ApiOperation("查询PointsDetail")
public ResultInfo getPointsDetails(PointsDetailQueryCriteria criteria, Pageable pageable) {
return ResultInfo.successPage(PointsDetailService.queryAll(criteria,pageable));
}
@GetMapping(value = "/all")
@ApiOperation("查询所有PointsDetail")
public ResultInfo getPointsDetails(PointsDetailQueryCriteria criteria) {
return ResultInfo.success(PointsDetailService.queryAll(criteria));
}
@Log
@PostMapping
@ApiOperation("新增PointsDetail")
public ResultInfo create(@Validated @RequestBody PointsDetail resources) {
PointsDetailService.create(resources);
return ResultInfo.success();
}
@Log
@PutMapping
@ApiOperation("修改PointsDetail")
public ResultInfo update(@Validated @RequestBody PointsDetail resources) {
PointsDetailService.update(resources);
return ResultInfo.success();
}
@Log
@DeleteMapping(value = "/{id}")
@ApiOperation("删除PointsDetail")
public ResultInfo delete(@PathVariable Long id) {
PointsDetailService.delete(id);
return ResultInfo.success();
}
@GetMapping(value = "/getByCode/{code}")
@ApiOperation(value = "根据标识查询")
public ResultInfo getByCode(@PathVariable String code) {
return ResultInfo.success(PointsDetailService.getByCode(code));
}*/
}
......@@ -2,11 +2,8 @@ package com.topdraw.business.module.points.detail.service;
import com.topdraw.business.module.points.detail.domain.PointsDetail;
import com.topdraw.business.module.points.detail.service.dto.PointsDetailDTO;
import com.topdraw.business.module.points.detail.service.dto.PointsDetailQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,33 +12,30 @@ import java.util.Map;
public interface PointsDetailService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<PointsDetailDTO>
*/
List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return PointsDetailDTO
*/
PointsDetailDTO findById(Long id);
void create(PointsDetail resources);
void create4Custom(PointsDetail resources);
/**
*
* @param resources
* @return
*/
PointsDetailDTO create(PointsDetail resources);
void update(PointsDetail resources);
/**
*
* @param resources
* @return
*/
PointsDetailDTO update(PointsDetail resources);
/**
*
* @param id
*/
void delete(Long id);
/**
......@@ -51,13 +45,23 @@ public interface PointsDetailService {
*/
PointsDetailDTO getByCode(String code);
/**
*
* @param memberId
* @return
*/
List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId);
/**
* 已过期的积分
* @param memberId
* @return
*/
List<PointsDetailDTO> findByMemberId(Long memberId);
/**
*
* @param pointsDetail
*/
void create4Custom(PointsDetail pointsDetail);
}
......
package com.topdraw.business.module.points.detail.service.impl;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.points.detail.domain.PointsDetail;
import com.topdraw.business.module.points.detail.repository.PointsDetailRepository;
import com.topdraw.business.module.points.detail.service.PointsDetailService;
import com.topdraw.business.module.points.detail.service.dto.PointsDetailDTO;
import com.topdraw.business.module.points.detail.service.dto.PointsDetailQueryCriteria;
import com.topdraw.business.module.points.detail.service.mapper.PointsDetailMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
......@@ -34,81 +26,47 @@ import java.util.Objects;
public class PointsDetailServiceImpl implements PointsDetailService {
@Autowired
private PointsDetailRepository PointsDetailRepository;
@Autowired
private MemberService memberService;
private PointsDetailRepository pointsDetailRepository;
@Autowired
private PointsDetailMapper PointsDetailMapper;
@Override
public Map<String, Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable) {
Page<PointsDetail> page = PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(PointsDetailMapper::toDto));
}
@Override
public List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria) {
return PointsDetailMapper.toDto(PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
private PointsDetailMapper pointsDetailMapper;
@Override
public PointsDetailDTO findById(Long id) {
PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseGet(PointsDetail::new);
ValidationUtil.isNull(PointsDetail.getId(),"PointsDetail","id",id);
return PointsDetailMapper.toDto(PointsDetail);
PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new);
ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id);
return this.pointsDetailMapper.toDto(pointsDetail);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(PointsDetail resources) {
String memberCode = resources.getMemberCode();
if (StringUtils.isNotEmpty(memberCode)) {
MemberDTO memberDTO = this.memberService.findByCode(memberCode);
if (Objects.nonNull(memberDTO)) {
Long memberId = memberDTO.getId();
resources.setMemberId(memberId);
}
}
PointsDetailRepository.save(resources);
}
@Override
public void create4Custom(PointsDetail resources) {
String memberCode = resources.getMemberCode();
if (StringUtils.isNotEmpty(memberCode)) {
MemberDTO memberDTO = this.memberService.findByCode(memberCode);
if (Objects.nonNull(memberDTO)) {
Long memberId = memberDTO.getId();
resources.setMemberId(memberId);
}
}
PointsDetailRepository.save(resources);
public PointsDetailDTO create(PointsDetail resources) {
PointsDetail pointsDetail = this.pointsDetailRepository.save(resources);
return this.pointsDetailMapper.toDto(pointsDetail);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(PointsDetail resources) {
PointsDetail PointsDetail = PointsDetailRepository.findById(resources.getId()).orElseGet(PointsDetail::new);
ValidationUtil.isNull( PointsDetail.getId(),"PointsDetail","id",resources.getId());
PointsDetail.copy(resources);
PointsDetailRepository.save(PointsDetail);
public PointsDetailDTO update(PointsDetail resources) {
PointsDetail pointsDetail = this.pointsDetailRepository.findById(resources.getId()).orElseGet(PointsDetail::new);
ValidationUtil.isNull( pointsDetail.getId(),"PointsDetail","id",resources.getId());
pointsDetail.copy(resources);
PointsDetail _pointsDetail = this.pointsDetailRepository.save(pointsDetail);
return this.pointsDetailMapper.toDto(_pointsDetail);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseThrow(
PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetail.class, id), 1));
PointsDetailRepository.delete(PointsDetail);
this.pointsDetailRepository.delete(pointsDetail);
}
@Override
public PointsDetailDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? PointsDetailMapper.toDto(PointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new))
return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new))
: new PointsDetailDTO();
}
......@@ -120,7 +78,12 @@ public class PointsDetailServiceImpl implements PointsDetailService {
@Override
public List<PointsDetailDTO> findByMemberId(Long memberId) {
return Objects.nonNull(memberId)?
PointsDetailMapper.toDto(PointsDetailRepository.findByMemberId(memberId))
this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId))
:null;
}
@Override
public void create4Custom(PointsDetail pointsDetail) {
this.pointsDetailRepository.save(pointsDetail);
}
}
......
......@@ -27,35 +27,37 @@ public class Points implements Serializable {
@Column(name = "id")
private Long id;
/** 账号id */
@Column(name = "user_id")
private Long userId;
// 积分类型,通用,绑定, 区分大小屏
/** 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏)
21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)*/
@Column(name = "point_type")
private Integer pointType;
// 绑定对应的实体, 如何描述?
/** 绑定对应的实体, 如何描述? */
@Column(name = "target_no")
private String targetNo;
// 本月期初积分值
/** 本月期初积分值 */
@Column(name = "begin_points")
private Integer beginPoints;
// 当前积分余额
/** 当前积分余额 */
@Column(name = "current_points")
private Integer currentPoints;
// 本月到期积分
/** 本月到期积分 */
@Column(name = "expire_points")
private Integer expirePoints;
// 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 最后修改时间
/** 最后修改时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
......@@ -2,11 +2,6 @@ package com.topdraw.business.module.points.service;
import com.topdraw.business.module.points.domain.Points;
import com.topdraw.business.module.points.service.dto.PointsDTO;
import com.topdraw.business.module.points.service.dto.PointsQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,31 +10,28 @@ import java.util.Map;
public interface PointsService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(PointsQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<PointsDTO>
*/
List<PointsDTO> queryAll(PointsQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return PointsDTO
*/
PointsDTO findById(Long id);
void create(Points resources);
/**
*
* @param resources
*/
PointsDTO create(Points resources);
void update(Points resources);
/**
*
* @param resources
*/
PointsDTO update(Points resources);
/**
*
* @param id
*/
void delete(Long id);
}
......
......@@ -19,26 +19,30 @@ public class PointsDTO implements Serializable {
@JsonSerialize(using= ToStringSerializer.class)
private Long id;
/** 账号id */
private Long userId;
// 积分类型,通用,绑定, 区分大小屏 todo
/** 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏)
21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)*/
private Integer pointType;
// 绑定对应的实体, 如何描述?
/** 绑定对应的实体, 如何描述? */
private String targetNo;
// 本月期初积分值
/** 本月期初积分值 */
private Integer beginPoints;
// 当前积分余额
/** 当前积分余额 */
private Integer currentPoints;
// 本月到期积分
/** 本月到期积分 */
private Integer expirePoints;
// 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)
/** 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏)
* 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)
*/
private Timestamp createTime;
// 最后修改时间
/** 最后修改时间 */
private Timestamp updateTime;
}
......
package com.topdraw.business.module.points.service.dto;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class PointsQueryCriteria{
}
package com.topdraw.business.module.points.service.impl;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.topdraw.business.module.points.domain.Points;
import com.topdraw.business.module.points.repository.PointsRepository;
import com.topdraw.business.module.points.service.PointsService;
import com.topdraw.business.module.points.service.dto.PointsDTO;
import com.topdraw.business.module.points.service.dto.PointsQueryCriteria;
import com.topdraw.business.module.points.service.mapper.PointsMapper;
import com.topdraw.util.RedissonUtil;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.ValidationUtil;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -35,48 +24,44 @@ import java.util.Map;
public class PointsServiceImpl implements PointsService {
@Autowired
private PointsRepository PointsRepository;
private PointsRepository pointsRepository;
@Autowired
private PointsMapper PointsMapper;
@Override
public Map<String, Object> queryAll(PointsQueryCriteria criteria, Pageable pageable) {
Page<Points> page = PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(PointsMapper::toDto));
}
@Override
public List<PointsDTO> queryAll(PointsQueryCriteria criteria) {
return PointsMapper.toDto(PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
private PointsMapper pointsMapper;
@Autowired
private RedisUtils redisUtils;
@Override
public PointsDTO findById(Long id) {
Points Points = PointsRepository.findById(id).orElseGet(Points::new);
Points Points = this.pointsRepository.findById(id).orElseGet(Points::new);
ValidationUtil.isNull(Points.getId(),"Points","id",id);
return PointsMapper.toDto(Points);
return this.pointsMapper.toDto(Points);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(Points resources) {
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
resources.setId(snowflake.nextId());
PointsRepository.save(resources);
public PointsDTO create(Points resources) {
Points points = this.pointsRepository.save(resources);
return this.pointsMapper.toDto(points);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Points resources) {
public PointsDTO update(Points resources) {
this.redisUtils.doLock("Points::update::userId"+resources.getUserId().toString());
try {
Points Points = PointsRepository.findById(resources.getId()).orElseGet(Points::new);
ValidationUtil.isNull(Points.getId(), "Points", "id", resources.getId());
Points.copy(resources);
PointsRepository.save(Points);
Points points = this.pointsRepository.findById(resources.getId()).orElseGet(Points::new);
ValidationUtil.isNull(points.getId(), "Points", "id", resources.getId());
points.copy(resources);
this.pointsRepository.save(points);
return this.pointsMapper.toDto(points);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("Points::update::userId"+resources.getUserId().toString());
}
}
......@@ -84,9 +69,9 @@ public class PointsServiceImpl implements PointsService {
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
Points Points = PointsRepository.findById(id).orElseThrow(
Points Points = this.pointsRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Points.class, id), 1));
PointsRepository.delete(Points);
this.pointsRepository.delete(Points);
}
......
package com.topdraw.business.module.points.standingbook.repository;
import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author XiangHan
* @date 2021-10-29
*/
public interface PointsStandingBookRepository extends JpaRepository<PointsStandingBook, Long>, JpaSpecificationExecutor<PointsStandingBook> {
}
package com.topdraw.business.module.points.standingbook.service;
import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook;
import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookDTO;
import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
* @date 2021-10-29
*/
public interface PointsStandingBookService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(PointsStandingBookQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<PointsStandingBookDTO>
*/
List<PointsStandingBookDTO> queryAll(PointsStandingBookQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return PointsStandingBookDTO
*/
PointsStandingBookDTO findById(Long id);
void create(PointsStandingBook resources);
void update(PointsStandingBook resources);
void delete(Long id);
}
package com.topdraw.business.module.points.standingbook.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2021-10-29
*/
@Data
public class PointsStandingBookDTO implements Serializable {
// 主键
private Long id;
// 积分生产
private Long pointsProduce;
// 积分消耗
private Long pointsConsume;
// 可用总积分
private Long pointsAvailable;
// 积分过期
private Long pointsExpire;
// 日期
private String day;
// 创建时间
private Timestamp createTime;
// 创建时间
private Timestamp updateTime;
}
package com.topdraw.business.module.points.standingbook.service.dto;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-29
*/
@Data
public class PointsStandingBookQueryCriteria{
}
package com.topdraw.business.module.points.standingbook.service.impl;
import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook;
import com.topdraw.business.module.points.standingbook.repository.PointsStandingBookRepository;
import com.topdraw.business.module.points.standingbook.service.PointsStandingBookService;
import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookDTO;
import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookQueryCriteria;
import com.topdraw.business.module.points.standingbook.service.mapper.PointsStandingBookMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
* @date 2021-10-29
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class PointsStandingBookServiceImpl implements PointsStandingBookService {
@Autowired
private PointsStandingBookRepository PointsStandingBookRepository;
@Autowired
private PointsStandingBookMapper PointsStandingBookMapper;
@Override
public Map<String, Object> queryAll(PointsStandingBookQueryCriteria criteria, Pageable pageable) {
Page<PointsStandingBook> page = PointsStandingBookRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(PointsStandingBookMapper::toDto));
}
@Override
public List<PointsStandingBookDTO> queryAll(PointsStandingBookQueryCriteria criteria) {
return PointsStandingBookMapper.toDto(PointsStandingBookRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
public PointsStandingBookDTO findById(Long id) {
PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(id).orElseGet(PointsStandingBook::new);
ValidationUtil.isNull(PointsStandingBook.getId(),"PointsStandingBook","id",id);
return PointsStandingBookMapper.toDto(PointsStandingBook);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(PointsStandingBook resources) {
PointsStandingBookRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(PointsStandingBook resources) {
PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(resources.getId()).orElseGet(PointsStandingBook::new);
ValidationUtil.isNull( PointsStandingBook.getId(),"PointsStandingBook","id",resources.getId());
PointsStandingBook.copy(resources);
PointsStandingBookRepository.save(PointsStandingBook);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsStandingBook.class, id), 1));
PointsStandingBookRepository.delete(PointsStandingBook);
}
}
package com.topdraw.business.module.rights.constant;
public class RightsType {
public static String TYPE_1 = "1";
Integer TYPE_2 = 2;
Integer TYPE_3 = 3;
}
......@@ -23,63 +23,63 @@ import java.sql.Timestamp;
@Table(name="tr_rights")
public class Rights implements Serializable {
// 主键
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 标识
/** 标识 */
@Column(name = "code", nullable = false)
private String code;
// 权益名称
// @Column(name = "name")
// private String name;
/** 权益名称 */
@Column(name = "name")
private String name;
// 类型 1:实体类 (预留字段)
/** 类型 1:实体类 (预留字段) */
@Column(name = "type", nullable = false)
private Integer type;
// 终端类型 0:大屏;1:微信小程序/公众号;2:App
/** 终端类型 0:大屏;1:微信小程序/公众号;2:App */
@Column(name = "device_type", nullable = false)
private Integer deviceType;
// 权益的实体类型 1:积分;2成长值;3优惠券
/** 权益的实体类型 1:积分;2成长值;3优惠券 */
@Column(name = "entity_type", nullable = false)
private String entityType;
// 实体id
/** 实体id */
@Column(name = "entity_id", nullable = false)
private Long entityId;
// 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间
/** 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 */
@Column(name = "valid_time")
private Timestamp validTime;
// 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数
/** 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 */
@Column(name = "expire_time")
private Long expireTime;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
// 图片
/** 图片 */
@Column(name = "image")
private String image;
// 图片
/** 图片 */
@Column(name = "images")
private String images;
// 描述
/** 描述 */
@Column(name = "description")
private String description;
......
......@@ -2,7 +2,7 @@ package com.topdraw.business.module.rights.history.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.topdraw.business.module.common.domain.DefaultAsyncMqModule;
import com.topdraw.business.module.common.domain.AsyncMqModule;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
......@@ -23,7 +23,7 @@ import java.time.LocalDateTime;
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="tr_rights_histroy")
public class RightsHistory extends DefaultAsyncMqModule implements Serializable {
public class RightsHistory extends AsyncMqModule implements Serializable {
// 主键id
@Id
......@@ -52,7 +52,7 @@ public class RightsHistory extends DefaultAsyncMqModule implements Serializable
// 发放时间
@Column(name = "send_time")
private LocalDateTime sendTime;
private Timestamp sendTime;
// 失效时间
@Column(name = "expire_time")
......@@ -60,11 +60,11 @@ public class RightsHistory extends DefaultAsyncMqModule implements Serializable
@CreatedDate
@Column(name = "create_time")
private LocalDateTime createTime;
private Timestamp createTime;
@LastModifiedDate
@Column(name = "update_time")
private LocalDateTime updateTime;
private Timestamp updateTime;
public void copy(RightsHistory source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
......
package com.topdraw.business.module.rights.history.repository;
import com.topdraw.business.module.rights.history.domain.RightsHistory;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @author XiangHan
* @date 2021-10-22
*/
public interface RightsHistoryRepository extends JpaRepository<RightsHistory, Long>, JpaSpecificationExecutor<RightsHistory> {
List<RightsHistoryDTO> findByMemberId(Long memberId);
}
......
......@@ -2,11 +2,8 @@ package com.topdraw.business.module.rights.history.service;
import com.topdraw.business.module.rights.history.domain.RightsHistory;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,19 +12,12 @@ import java.util.Map;
public interface RightsHistoryService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<RightsHistoryDTO>
*/
List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria);
*
* @param memberId
* @param memberCode
* @return
*/
List<RightsHistoryDTO> findByMemberIdOrMemberCode(Long memberId, String memberCode);
/**
* 根据ID查询
......
......@@ -30,12 +30,12 @@ public class RightsHistoryDTO implements Serializable {
private String operatorName;
// 发放时间
private LocalDateTime sendTime;
private Timestamp sendTime;
// 失效时间
private LocalDateTime expireTime;
private LocalDateTime createTime;
private Timestamp createTime;
private LocalDateTime updateTime;
private Timestamp updateTime;
}
......
......@@ -6,23 +6,16 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory;
import com.topdraw.business.module.rights.history.repository.RightsHistoryRepository;
import com.topdraw.business.module.rights.history.service.RightsHistoryService;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryQueryCriteria;
import com.topdraw.business.module.rights.history.service.mapper.RightsHistoryMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.ValidationUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -33,60 +26,49 @@ import java.util.Map;
public class RightsHistoryServiceImpl implements RightsHistoryService {
@Autowired
private RightsHistoryRepository RightsHistoryRepository;
@Autowired
private MemberService memberService;
@Autowired
private RightsHistoryMapper RightsHistoryMapper;
private RightsHistoryMapper rightsHistoryMapper;
@Autowired
private RightsHistoryRepository rightsHistoryRepository;
@Override
public Map<String, Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable) {
Page<RightsHistory> page = RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(RightsHistoryMapper::toDto));
}
@Override
public List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria) {
return RightsHistoryMapper.toDto(RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
public List<RightsHistoryDTO> findByMemberIdOrMemberCode(Long memberId, String memberCode) {
MemberDTO memberDTO = this.memberService.checkMember(memberId, memberCode);
List<RightsHistoryDTO> rightsHistoryDTOList = this.rightsHistoryRepository.findByMemberId(memberDTO.getId());
return rightsHistoryDTOList;
}
@Override
public RightsHistoryDTO findById(Long id) {
RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseGet(RightsHistory::new);
RightsHistory RightsHistory = this.rightsHistoryRepository.findById(id).orElseGet(com.topdraw.business.module.rights.history.domain.RightsHistory::new);
ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",id);
return RightsHistoryMapper.toDto(RightsHistory);
return this.rightsHistoryMapper.toDto(RightsHistory);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(RightsHistory resources) {
String memberCode = resources.getMemberCode();
if (StringUtils.isNotBlank(memberCode)) {
MemberDTO memberDTO = this.memberService.findByCode(memberCode);
Long id = memberDTO.getId();
resources.setMemberId(id);
}
RightsHistoryRepository.save(resources);
this.rightsHistoryRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(RightsHistory resources) {
RightsHistory RightsHistory = RightsHistoryRepository.findById(resources.getId()).orElseGet(RightsHistory::new);
ValidationUtil.isNull( RightsHistory.getId(),"RightsHistory","id",resources.getId());
RightsHistory RightsHistory = this.rightsHistoryRepository.findById(resources.getId()).orElseGet(com.topdraw.business.module.rights.history.domain.RightsHistory::new);
ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",resources.getId());
RightsHistory.copy(resources);
RightsHistoryRepository.save(RightsHistory);
this.rightsHistoryRepository.save(RightsHistory);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", RightsHistory.class, id), 1));
RightsHistoryRepository.delete(RightsHistory);
RightsHistory RightsHistory = this.rightsHistoryRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.rights.history.domain.RightsHistory.class, id), 1));
this.rightsHistoryRepository.delete(RightsHistory);
}
......
......@@ -24,58 +24,58 @@ import java.sql.Timestamp;
@Table(name="uc_permanent_rights")
public class PermanentRights implements Serializable {
// ID
/** ID */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 标识
/** 标识 */
@Column(name = "code", nullable = false)
private String code;
// 名称
/** 名称 */
@Column(name = "name", nullable = false)
private String name;
// 永久权益类型 0:vip;1:会员等级
/** 永久权益类型 0:vip;1:会员等级 */
@Column(name = "type")
private Integer type;
// 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)
/** 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) */
@Column(name = "level")
private Integer level;
// 商品折扣,10代表10% off,范围为0-100
/** 商品折扣,10代表10% off,范围为0-100 */
@Column(name = "item_discount", nullable = false)
private BigDecimal itemDiscount;
// 额外积分比率,范围为0-1000
/** 额外积分比率,范围为0-1000 */
@Column(name = "extra_points", nullable = false)
private BigDecimal extraPoints;
// 免广告
/** 免广告 */
@Column(name = "ad_disabled", nullable = false)
private Integer adDisabled;
// 额外活动参与机会
/** 额外活动参与机会 */
@Column(name = "extra_activity_ticket", nullable = false)
private Integer extraActivityTicket;
// 免费试看
/** 免费试看 */
@Column(name = "free_trial", nullable = false)
private Integer freeTrial;
// 上电视专区权益
/** 上电视专区权益 */
@Column(name = "zone_sds", nullable = false)
private Integer zoneSds;
// 创建时间
/** 创建时间 */
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
/** 更新时间 */
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
......
......@@ -13,4 +13,6 @@ import java.util.Optional;
public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> {
Optional<PermanentRights> findFirstByCode(String code);
PermanentRights findByLevel(Integer level);
}
......
package com.topdraw.business.module.rights.permanentrights.service;
import com.topdraw.business.module.rights.permanentrights.domain.PermanentRights;
import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO;
import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -15,37 +9,23 @@ import java.util.Map;
public interface PermanentRightsService {
/**
* 查询数据分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<PermanentRightsDTO>
*/
List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return PermanentRightsDTO
*/
PermanentRightsDTO findById(Long id);
void create(PermanentRights resources);
void update(PermanentRights resources);
void delete(Long id);
/**
* Code校验
* @param code
* @return PermanentRightsDTO
*/
PermanentRightsDTO getByCode(String code);
/**
* 通过会员等级获取对应的永久权益
* @param level
* @return
*/
PermanentRightsDTO findByLevel(Integer level);
}
......
......@@ -14,42 +14,42 @@ import java.sql.Timestamp;
@Data
public class PermanentRightsDTO implements Serializable {
// ID
/** ID */
private Long id;
// 标识
/** 标识 */
private String code;
// 名称
/** 名称 */
private String name;
// 永久权益类型 0:vip;1:会员等级
/** 永久权益类型 0:vip;1:会员等级 */
private Integer type;
// 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)
/** 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) */
private Integer level;
// 商品折扣,10代表10% off,范围为0-100
/** 商品折扣,10代表10% off,范围为0-100 */
private BigDecimal itemDiscount;
// 额外积分比率,范围为0-1000
/** 额外积分比率,范围为0-1000 */
private BigDecimal extraPoints;
// 免广告
/** 免广告 */
private Integer adDisabled;
// 额外活动参与机会
/** 额外活动参与机会 */
private Integer extraActivityTicket;
// 免费试看
/** 免费试看 */
private Integer freeTrial;
// 上电视专区权益
/** 上电视专区权益 */
private Integer zoneSds;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
}
......
package com.topdraw.business.module.rights.permanentrights.service.dto;
import com.topdraw.annotation.Query;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class PermanentRightsQueryCriteria{
@Query(type = Query.Type.EQUAL)
private Integer level;
}
......@@ -4,23 +4,13 @@ import com.topdraw.business.module.rights.permanentrights.domain.PermanentRights
import com.topdraw.business.module.rights.permanentrights.repository.PermanentRightsRepository;
import com.topdraw.business.module.rights.permanentrights.service.PermanentRightsService;
import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO;
import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsQueryCriteria;
import com.topdraw.business.module.rights.permanentrights.service.mapper.PermanentRightsMapper;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.StringUtils;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -31,57 +21,27 @@ import java.util.Map;
public class PermanentRightsServiceImpl implements PermanentRightsService {
@Autowired
private PermanentRightsRepository PermanentRightsRepository;
private PermanentRightsRepository permanentRightsRepository;
@Autowired
private PermanentRightsMapper PermanentRightsMapper;
@Override
public Map<String, Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable) {
Page<PermanentRights> page = PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(PermanentRightsMapper::toDto));
}
@Override
public List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria) {
return PermanentRightsMapper.toDto(PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
private PermanentRightsMapper permanentRightsMapper;
@Override
public PermanentRightsDTO findById(Long id) {
PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseGet(PermanentRights::new);
PermanentRights PermanentRights = this.permanentRightsRepository.findById(id).orElseGet(com.topdraw.business.module.rights.permanentrights.domain.PermanentRights::new);
ValidationUtil.isNull(PermanentRights.getId(),"PermanentRights","id",id);
return PermanentRightsMapper.toDto(PermanentRights);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(PermanentRights resources) {
PermanentRightsRepository.save(resources);
return this.permanentRightsMapper.toDto(PermanentRights);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(PermanentRights resources) {
PermanentRights PermanentRights = PermanentRightsRepository.findById(resources.getId()).orElseGet(PermanentRights::new);
ValidationUtil.isNull( PermanentRights.getId(),"PermanentRights","id",resources.getId());
PermanentRights.copy(resources);
PermanentRightsRepository.save(PermanentRights);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PermanentRights.class, id), 1));
PermanentRightsRepository.delete(PermanentRights);
public PermanentRightsDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? this.permanentRightsMapper.toDto(this.permanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new))
: new PermanentRightsDTO();
}
@Override
public PermanentRightsDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new))
: new PermanentRightsDTO();
public PermanentRightsDTO findByLevel(Integer level) {
PermanentRights PermanentRights = this.permanentRightsRepository.findByLevel(level);
return this.permanentRightsMapper.toDto(PermanentRights);
}
}
......