Commit 87410231 87410231672cd7c244b1c582610265cb45beb293 by xianghan

1.优化

1 parent 5f7c8284
Showing 28 changed files with 228 additions and 343 deletions
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 java.util.List;
/**
* @author XiangHan
* @date 2021-10-22
......
......@@ -12,6 +12,7 @@ import java.util.List;
* @date 2021-10-22
*/
public interface ExpHistoryService {
/**
* 根据ID查询
* @param id ID
......
......@@ -28,47 +28,47 @@ import java.io.Serializable;
@Table(name="uc_points_available")
public class PointsAvailable extends AsyncMqModule implements Serializable {
// 主键
/** 主键 */
@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",locale = "")
/** 过期时间 */
@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;
......
......@@ -26,13 +26,13 @@ public interface PointsAvailableService {
*
* @param resources
*/
void create(PointsAvailable resources);
PointsAvailableDTO create(PointsAvailable resources);
/**
*
* @param resources
*/
void update(PointsAvailable resources);
PointsAvailableDTO update(PointsAvailable resources);
/**
*
......@@ -90,7 +90,15 @@ public interface PointsAvailableService {
*/
long findTotalPointsByMemberId(Long memberId);
/**
*
* @param id
*/
void delete4Custom(Long id);
void create4Custom(PointsAvailable pointsAvailable);
/**
*
* @param pointsAvailable
*/
PointsAvailableDTO create4Custom(PointsAvailable pointsAvailable);
}
......
......@@ -13,33 +13,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;
}
......
......@@ -27,32 +27,33 @@ import java.util.*;
public class PointsAvailableServiceImpl implements PointsAvailableService {
@Autowired
private PointsAvailableRepository PointsAvailableRepository;
private PointsAvailableRepository pointsAvailableRepository;
@Autowired
private PointsAvailableMapper PointsAvailableMapper;
private PointsAvailableMapper pointsAvailableMapper;
@Autowired
private RedisUtils redisUtils;
@Override
public List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId) {
return PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdOrderByExpireTime(memberId));
return this.pointsAvailableMapper.toDto(this.pointsAvailableRepository.findByMemberIdOrderByExpireTime(memberId));
}
@Override
public PointsAvailableDTO findById(Long id) {
PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseGet(PointsAvailable::new);
ValidationUtil.isNull(PointsAvailable.getId(),"PointsAvailable","id",id);
return PointsAvailableMapper.toDto(PointsAvailable);
PointsAvailable pointsAvailable = this.pointsAvailableRepository.findById(id).orElseGet(PointsAvailable::new);
ValidationUtil.isNull(pointsAvailable.getId(),"PointsAvailable","id",id);
return this.pointsAvailableMapper.toDto(pointsAvailable);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(PointsAvailable resources) {
this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString());
public PointsAvailableDTO create(PointsAvailable resources) {
try {
PointsAvailableRepository.save(resources);
this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString());
PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources);
return this.pointsAvailableMapper.toDto(pointsAvailable);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -63,13 +64,15 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(PointsAvailable resources) {
this.redisUtils.doLock("PointsAvailable::update::id"+resources.getMemberId().toString());
public PointsAvailableDTO update(PointsAvailable resources) {
try {
PointsAvailable PointsAvailable = PointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new);
ValidationUtil.isNull( PointsAvailable.getId(),"PointsAvailable","id",resources.getId());
PointsAvailable.copy(resources);
PointsAvailableRepository.save(PointsAvailable);
this.redisUtils.doLock("PointsAvailable::update::id"+resources.getMemberId().toString());
PointsAvailable pointsAvailable = this.pointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new);
ValidationUtil.isNull(pointsAvailable.getId(),"PointsAvailable","id",resources.getId());
pointsAvailable.copy(resources);
PointsAvailable _pointsAvailable = this.pointsAvailableRepository.save(pointsAvailable);
return this.pointsAvailableMapper.toDto(_pointsAvailable);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -84,9 +87,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
Assert.notNull(id, "The given id must not be null!");
this.redisUtils.doLock("PointsAvailable::delete::id"+id);
try {
PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow(
PointsAvailable PointsAvailable = this.pointsAvailableRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1));
PointsAvailableRepository.delete(PointsAvailable);
this.pointsAvailableRepository.delete(PointsAvailable);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -100,7 +103,7 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
public void deleteBatchByIds(List<Long> id) {
this.redisUtils.doLock("PointsAvailable::create::id"+id);
try {
PointsAvailableRepository.deleteBatchByIds(id);
this.pointsAvailableRepository.deleteBatchByIds(id);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -112,31 +115,31 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
@Override
public PointsAvailableDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? PointsAvailableMapper.toDto(PointsAvailableRepository.findFirstByCode(code).orElseGet(PointsAvailable::new))
return StringUtils.isNotEmpty(code) ? this.pointsAvailableMapper.toDto(this.pointsAvailableRepository.findFirstByCode(code).orElseGet(PointsAvailable::new))
: new PointsAvailableDTO();
}
@Override
public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime timestamp) {
return Objects.nonNull(memberId)?
PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp))
this.pointsAvailableMapper.toDto(this.pointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp))
:null;
}
@Override
public Long findSoonExpireTime(Long memberId, Integer factor) {
return PointsAvailableRepository.findSoonExpireTime(memberId, factor);
return this.pointsAvailableRepository.findSoonExpireTime(memberId, factor);
}
@Override
public long findAvailablePointsByMemberId(long memberId) {
Long availablePoints = this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId);
Long availablePoints = this.pointsAvailableRepository.findAvailablePointsByMemberId(memberId);
return availablePoints == null ? 0L : availablePoints;
}
@Override
public long findTotalPointsByMemberId(Long memberId) {
return this.PointsAvailableRepository.findTotalCountByMemberId(memberId);
return this.pointsAvailableRepository.findTotalCountByMemberId(memberId);
}
@Override
......@@ -144,9 +147,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
Assert.notNull(id, "The given id must not be null!");
this.redisUtils.doLock("PointsAvailable::delete::id"+id);
try {
PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow(
PointsAvailable PointsAvailable = this.pointsAvailableRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1));
PointsAvailableRepository.delete(PointsAvailable);
this.pointsAvailableRepository.delete(PointsAvailable);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -156,10 +159,11 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
}
@Override
public void create4Custom(PointsAvailable resources) {
public PointsAvailableDTO create4Custom(PointsAvailable resources) {
this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString());
try {
PointsAvailableRepository.save(resources);
PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources);
return this.pointsAvailableMapper.toDto(pointsAvailable);
} catch (Exception e) {
e.printStackTrace();
throw e;
......
......@@ -2,10 +2,7 @@ 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.Map;
import java.util.List;
/**
......@@ -15,31 +12,30 @@ import java.util.List;
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);
/**
*
* @param resources
* @return
*/
PointsDetailDTO create(PointsDetail resources);
void update(PointsDetail resources);
/**
*
* @param resources
* @return
*/
PointsDetailDTO update(PointsDetail resources);
/**
*
* @param id
*/
void delete(Long id);
/**
......@@ -49,9 +45,13 @@ public interface PointsDetailService {
*/
PointsDetailDTO getByCode(String code);
/**
*
* @param memberId
* @return
*/
List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId);
/**
* 已过期的积分
* @param memberId
......@@ -59,5 +59,9 @@ public interface PointsDetailService {
*/
List<PointsDetailDTO> findByMemberId(Long memberId);
/**
*
* @param pointsDetail
*/
void create4Custom(PointsDetail pointsDetail);
}
......
package com.topdraw.business.module.points.detail.service.impl;
import com.topdraw.aspect.AsyncMqSend;
import com.topdraw.business.module.points.detail.domain.PointsDetail;
import com.topdraw.utils.ValidationUtil;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
......@@ -33,57 +26,47 @@ import java.util.Objects;
public class PointsDetailServiceImpl implements PointsDetailService {
@Autowired
private PointsDetailRepository PointsDetailRepository;
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) {
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();
}
......@@ -95,12 +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) {
PointsDetailRepository.save(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,10 +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.Map;
import java.util.List;
/**
* @author XiangHan
......@@ -14,31 +10,28 @@ import java.util.List;
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);
}
......
......@@ -18,26 +18,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{
}
......@@ -6,23 +6,14 @@ import com.topdraw.utils.ValidationUtil;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
......@@ -33,49 +24,39 @@ import java.util.Map;
public class PointsServiceImpl implements PointsService {
@Autowired
private PointsRepository PointsRepository;
private PointsRepository pointsRepository;
@Autowired
private PointsMapper PointsMapper;
private PointsMapper pointsMapper;
@Autowired
private RedisUtils redisUtils;
@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)));
}
@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;
......@@ -88,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);
}
......
......@@ -23,63 +23,63 @@ import java.io.Serializable;
@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;
......
......@@ -12,44 +12,45 @@ import java.io.Serializable;
@Data
public class RightsDTO implements Serializable {
// 主键
/** 主键 */
private Long id;
// 标识
/** 标识 */
private String code;
// 权益名称
// private String name;
// 终端类型 0:大屏;1:微信小程序/公众号;2:App
/** 权益名称 */
private String name;
/** 终端类型 0:大屏;1:微信小程序/公众号;2:App */
private Integer deviceType;
// 类型 1:实体类 (预留字段)
/** 类型 1:实体类 (预留字段) */
private Integer type;
// 权益的实体类型 1:积分;2成长值;3优惠券
/** 权益的实体类型 1:积分;2成长值;3优惠券 */
private String entityType;
// 实体id
/** 实体id */
private Long entityId;
// 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间
/** 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 */
private Timestamp validTime;
// 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数
/** 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 */
private Long expireTime;
// 创建时间
/** 创建时间 */
private Timestamp createTime;
// 更新时间
/** 更新时间 */
private Timestamp updateTime;
// 图片
/** 图片 */
private String image;
// 图片
/** 图片 */
private String images;
// 描述
/** 描述 */
private String description;
}
......
package com.topdraw.business.module.rights.service.dto;
import com.topdraw.annotation.Query;
import lombok.Data;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Data
public class RightsQueryCriteria{
@Query
private Long memberId;
private RightsQueryType queryType;
}
package com.topdraw.business.module.rights.service.dto;
public enum RightsQueryType {
// 全部
ALL,
// 可用
AVAILABLE_ONLY
}
......@@ -20,24 +20,20 @@ import org.springframework.transaction.annotation.Transactional;
public class RightsServiceImpl implements RightsService {
@Autowired
private RightsRepository RightsRepository;
@Autowired
private RightsMapper RightsMapper;
private RightsRepository rightsRepository;
@Autowired
private RedisUtils redisUtils;
private RightsMapper rightsMapper;
@Override
public RightsDTO findById(Long id) {
Rights Rights = RightsRepository.findById(id).orElseGet(Rights::new);
Rights Rights = this.rightsRepository.findById(id).orElseGet(Rights::new);
ValidationUtil.isNull(Rights.getId(),"Rights","id",id);
return RightsMapper.toDto(Rights);
return this.rightsMapper.toDto(Rights);
}
@Override
public RightsDTO getByCode(String code) {
return StringUtils.isNotEmpty(code) ? RightsMapper.toDto(RightsRepository.findFirstByCode(code).orElseGet(Rights::new))
return StringUtils.isNotEmpty(code) ? this.rightsMapper.toDto(this.rightsRepository.findFirstByCode(code).orElseGet(Rights::new))
: new RightsDTO();
}
}
......
......@@ -22,13 +22,13 @@ public interface UserTvService {
* @param resources
* @return
*/
UserTv create(UserTv resources);
UserTvDTO create(UserTv resources);
/**
*
* @param resources
*/
void update(UserTv resources);
UserTvDTO update(UserTv resources);
/**
*
......
......@@ -81,24 +81,25 @@ public class UserTvServiceImpl implements UserTvService {
@Override
@Transactional(rollbackFor = Exception.class)
public UserTv create(UserTv resources) {
public UserTvDTO create(UserTv resources) {
MemberDTO memberDTO = memberService.findByCode(resources.getMemberCode());
if (Objects.nonNull(memberDTO)) {
Long id = memberDTO.getId();
resources.setMemberId(id);
this.userTvRepository.save(resources);
return resources;
UserTv userTv = this.userTvRepository.save(resources);
return this.userTvMapper.toDto(userTv);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(UserTv resources) {
UserTv UserTv = this.userTvRepository.findById(resources.getId()).orElseGet(UserTv::new);
ValidationUtil.isNull( UserTv.getId(),"UserTv","id",resources.getId());
UserTv.copy(resources);
this.userTvRepository.save(UserTv);
public UserTvDTO update(UserTv resources) {
UserTv userTv = this.userTvRepository.findById(resources.getId()).orElseGet(UserTv::new);
ValidationUtil.isNull(userTv.getId(),"UserTv","id",resources.getId());
userTv.copy(resources);
UserTv _userTv = this.userTvRepository.save(userTv);
return this.userTvMapper.toDto(_userTv);
}
@Override
......
package com.topdraw.business.process.rest;
import com.topdraw.aop.log.Log;
import com.topdraw.business.process.domian.TempCoupon;
import com.topdraw.business.process.service.CouponOperationService;
import com.topdraw.common.ResultInfo;
......@@ -14,14 +15,15 @@ import java.util.List;
* @author XiangHan
* @date 2021-10-22
*/
@Api(tags = "CouponOperation管理")
@Api(tags = "优惠券管理")
@RestController
@RequestMapping("/ucEngine/api/couponOperation")
@RequestMapping("/ucEngine/couponOperation")
public class CouponOperationController {
@Autowired
private CouponOperationService couponOperationService;
@Log("手动发放优惠券")
@PostMapping(value = "/grantCouponByManual")
@ApiOperation("手动发放优惠券")
public ResultInfo grantCouponByManual(List<TempCoupon> tempCouponList) {
......
package com.topdraw.business.process.rest;
import com.topdraw.business.process.domian.TempCoupon;
import com.topdraw.aop.log.Log;
import com.topdraw.business.process.domian.TempExp;
import com.topdraw.business.process.service.CouponOperationService;
import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.common.ResultInfo;
import io.swagger.annotations.Api;
......@@ -21,14 +20,15 @@ import java.util.List;
* @author XiangHan
* @date 2021-10-22
*/
@Api(tags = "ExpOperation管理")
@Api(tags = "成长值管理")
@RestController
@RequestMapping("/ucEngine/api/expOperation")
@RequestMapping("/ucEngine/expOperation")
public class ExpOperationController {
@Autowired
private ExpOperationService expOperationService;
@Log("手动发放成长值")
@PostMapping(value = "/grantExpByManual")
@ApiOperation("手动发放成长值")
public ResultInfo grantExpByManual(@Validated @RequestBody TempExp tempExp) {
......
......@@ -46,14 +46,6 @@ public class PointsOperationController {
@Autowired
private PointsOperationService pointsOperationService;
@GetMapping(value = "/pagePointsDetails")
@ApiOperation("查询PointsDetail")
@AnonymousAccess
public ResultInfo pagePointsDetails(PointsDetailQueryCriteria criteria, Pageable pageable) {
return ResultInfo.successPage(pointsDetailService.queryAll(criteria,pageable));
}
@GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}")
@ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用")
@AnonymousAccess
......
package com.topdraw.business.process.rest;
import com.topdraw.aop.log.Log;
import com.topdraw.business.module.rights.history.domain.RightsHistory;
import com.topdraw.business.module.rights.history.service.RightsHistoryService;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryQueryCriteria;
import com.topdraw.business.module.rights.history.service.dto.RightsHistoryQueryType;
import com.topdraw.business.process.service.RightsOperationService;
import com.topdraw.common.ResultInfo;
import com.topdraw.util.TimestampUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
......@@ -23,32 +19,20 @@ import java.util.List;
*/
@Api(tags = "Rights管理")
@RestController
@RequestMapping("/ucEngine/api/rightsOperation")
@RequestMapping("/ucEngine/rightsOperation")
public class RightsOperationController {
@Autowired
private RightsOperationService rightsOperationService;
@Autowired
private RightsHistoryService rightsHistoryService;
/**
*
* @param id
* @return
*/
@GetMapping(value = "/findRightsHistoryById/{id}")
@ApiOperation("查询RightsHistory")
public ResultInfo findRightsHistoryById(@PathVariable Long id) {
return ResultInfo.success(rightsHistoryService.findById(id));
}
/**
*
* @param rightsHistory
* @return
*/
@Log("手动发放优惠券")
@PostMapping(value = "/grantRightsByManual")
@ApiOperation("查询RightsHistory")
@ApiOperation("手动发放优惠券")
public ResultInfo grantRightsByManual(@Validated @RequestBody RightsHistory rightsHistory) {
List<RightsHistory> rightsHistories = Arrays.asList(rightsHistory);
this.rightsOperationService.grantRightsByManual(rightsHistories);
......
package com.topdraw.business.process.service;
import com.topdraw.business.process.domian.TempCoupon;
import com.topdraw.business.process.domian.TempExp;
import com.topdraw.business.process.domian.TempRights;
import java.util.List;
......
......@@ -52,11 +52,9 @@ public class ExpOperationServiceImpl implements ExpOperationService {
@Override
@AsyncMqSend
public void grantPointsThroughTempExp(List<TempExp> tempExpList) {
for (TempExp tempExp : tempExpList) {
this.refresh(tempExp);
}
}
@Override
......@@ -73,7 +71,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
}
}
/**
*
* @param tempExp
......@@ -105,6 +102,11 @@ public class ExpOperationServiceImpl implements ExpOperationService {
return rewardExp + originalExp;
}
/**
*
* @param tempExp
* @return
*/
private long getExpByMemberId(TempExp tempExp) {
Long memberId = tempExp.getMemberId();
MemberDTO memberDTO = this.memberOperationService.findById(memberId);
......@@ -115,7 +117,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
return 0L;
}
/**
* 更新成长值与等级
*
......
......@@ -43,8 +43,6 @@ import java.util.stream.Collectors;
@Slf4j
public class PointsOperationServiceImpl implements PointsOperationService {
private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class);
@Autowired
PointsService pointsService;
@Autowired
......@@ -69,8 +67,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
private static final String DELETE_AVAILABLE_POINTS = "delete";
private static final String INSERT_AVAILABLE_POINTS = "insert";
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsByManual(Long memberId,TempPoints tempPoints){
......@@ -361,15 +357,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
/**
*
* @param pointsAvailableDTOS
*/
private void doDeleteBatchInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) {
List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList());
this.pointsAvailableService.deleteBatchByIds(collect);
}
/**
*
* @param pointsAvailableDTO
*/
private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) {
......@@ -515,16 +502,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
}
/**
* 计算当前总积分
* @param memberId 会员id
* @return
*/
private Long findAvailablePointsByMemberId(long memberId){
Long availablePoints = this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
return Objects.nonNull(availablePoints) ? availablePoints : 0L;
}
/**
* 更新可用积分表
* @param tempPoints
*/
......
......@@ -1087,10 +1087,7 @@ public class UserOperationServiceImpl implements UserOperationService {
resources.setMemberId(memberId);
resources.setMemberCode(memberCode);
UserTv userTv = this.userTvService.create(resources);
UserTvDTO userTvDTO = new UserTvDTO();
BeanUtils.copyProperties(userTv,userTvDTO);
UserTvDTO userTvDTO = this.userTvService.create(resources);
return userTvDTO;
}
......