|
@@ -5,19 +5,17 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.jiashanxia.domain.GoodsInfo;
|
|
import com.izouma.jiashanxia.domain.GoodsInfo;
|
|
|
-import com.izouma.jiashanxia.domain.OrderInfo;
|
|
|
|
|
-import com.izouma.jiashanxia.domain.UserSet;
|
|
|
|
|
-import com.izouma.jiashanxia.domain.UserSetFlow;
|
|
|
|
|
|
|
+import com.izouma.jiashanxia.domain.UserPackage;
|
|
|
|
|
+import com.izouma.jiashanxia.domain.UserPackageFlow;
|
|
|
import com.izouma.jiashanxia.dto.*;
|
|
import com.izouma.jiashanxia.dto.*;
|
|
|
import com.izouma.jiashanxia.enums.FlowType;
|
|
import com.izouma.jiashanxia.enums.FlowType;
|
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
|
import com.izouma.jiashanxia.repo.GoodsInfoRepo;
|
|
import com.izouma.jiashanxia.repo.GoodsInfoRepo;
|
|
|
-import com.izouma.jiashanxia.repo.UserSetFlowRepo;
|
|
|
|
|
-import com.izouma.jiashanxia.repo.UserSetRepo;
|
|
|
|
|
|
|
+import com.izouma.jiashanxia.repo.UserPackageFlowRepo;
|
|
|
|
|
+import com.izouma.jiashanxia.repo.UserPackageRepo;
|
|
|
import com.izouma.jiashanxia.utils.JpaUtils;
|
|
import com.izouma.jiashanxia.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
@@ -26,22 +24,22 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
|
-public class UserSetFlowService {
|
|
|
|
|
|
|
+public class UserPackageFlowService {
|
|
|
|
|
|
|
|
- private UserSetFlowRepo userSetFlowRepo;
|
|
|
|
|
- private GoodsInfoRepo goodsInfoRepo;
|
|
|
|
|
- private UserSetRepo userSetRepo;
|
|
|
|
|
|
|
+ private UserPackageFlowRepo userPackageFlowRepo;
|
|
|
|
|
+ private GoodsInfoRepo goodsInfoRepo;
|
|
|
|
|
+ private UserPackageRepo userPackageRepo;
|
|
|
|
|
|
|
|
- public Page<UserSetFlow> all(PageQuery pageQuery) {
|
|
|
|
|
- return userSetFlowRepo.findAll(JpaUtils.toSpecification(pageQuery, UserSetFlow.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
|
|
|
|
+ public Page<UserPackageFlow> all(PageQuery pageQuery) {
|
|
|
|
|
+ return userPackageFlowRepo.findAll(JpaUtils.toSpecification(pageQuery, UserPackageFlow.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
核销列表
|
|
核销列表
|
|
|
*/
|
|
*/
|
|
|
- public Page<UserSetFlow> writeOffAll(PageQuery pageQuery) {
|
|
|
|
|
- return userSetFlowRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
- List<Predicate> and = JpaUtils.toPredicates(pageQuery, UserSetFlow.class, root, criteriaQuery, criteriaBuilder);
|
|
|
|
|
|
|
+ public Page<UserPackageFlow> writeOffAll(PageQuery pageQuery) {
|
|
|
|
|
+ return userPackageFlowRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
+ List<Predicate> and = JpaUtils.toPredicates(pageQuery, UserPackageFlow.class, root, criteriaQuery, criteriaBuilder);
|
|
|
and.add(criteriaBuilder.equal(root.get("type"), FlowType.WRITE_OFF));
|
|
and.add(criteriaBuilder.equal(root.get("type"), FlowType.WRITE_OFF));
|
|
|
if (StrUtil.isNotEmpty(pageQuery.getSearch())) {
|
|
if (StrUtil.isNotEmpty(pageQuery.getSearch())) {
|
|
|
List<Predicate> or = new ArrayList<>();
|
|
List<Predicate> or = new ArrayList<>();
|
|
@@ -56,10 +54,10 @@ public class UserSetFlowService {
|
|
|
}), JpaUtils.toPageRequest(pageQuery));
|
|
}), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<UserSetFlowVO> my(Long userId) {
|
|
|
|
|
- List<UserSetFlowVO> vos = new ArrayList<>();
|
|
|
|
|
|
|
+ public List<UserPackageFlowVO> my(Long userId) {
|
|
|
|
|
+ List<UserPackageFlowVO> vos = new ArrayList<>();
|
|
|
// 查找用户相关
|
|
// 查找用户相关
|
|
|
- List<UserSetFlow> flows = userSetFlowRepo.findAllByUserId(userId);
|
|
|
|
|
|
|
+ List<UserPackageFlow> flows = userPackageFlowRepo.findAllByUserId(userId);
|
|
|
// Set<Long> goodsId = new HashSet<>();
|
|
// Set<Long> goodsId = new HashSet<>();
|
|
|
// // 找出相关商品
|
|
// // 找出相关商品
|
|
|
// flows.forEach(flow -> {
|
|
// flows.forEach(flow -> {
|
|
@@ -72,7 +70,7 @@ public class UserSetFlowService {
|
|
|
// 转vo
|
|
// 转vo
|
|
|
flows.forEach(flow -> {
|
|
flows.forEach(flow -> {
|
|
|
List<GoodsVO> goodsVOS = this.toGoodsVO(flow.getContent(), goodsMap);
|
|
List<GoodsVO> goodsVOS = this.toGoodsVO(flow.getContent(), goodsMap);
|
|
|
- UserSetFlowVO vo = new UserSetFlowVO();
|
|
|
|
|
|
|
+ UserPackageFlowVO vo = new UserPackageFlowVO();
|
|
|
BeanUtil.copyProperties(flow, vo);
|
|
BeanUtil.copyProperties(flow, vo);
|
|
|
vo.setContent(goodsVOS);
|
|
vo.setContent(goodsVOS);
|
|
|
vos.add(vo);
|
|
vos.add(vo);
|
|
@@ -96,19 +94,19 @@ public class UserSetFlowService {
|
|
|
/*
|
|
/*
|
|
|
核销
|
|
核销
|
|
|
*/
|
|
*/
|
|
|
- public UserSetFlow writeOff(WriteOffSaveVO writeOffSaveVO) {
|
|
|
|
|
|
|
+ public UserPackageFlow writeOff(WriteOffSaveVO writeOffSaveVO) {
|
|
|
if (writeOffSaveVO.getUserId().equals(writeOffSaveVO.getWriteOffUserId())) {
|
|
if (writeOffSaveVO.getUserId().equals(writeOffSaveVO.getWriteOffUserId())) {
|
|
|
throw new BusinessException("不可自己核销自己");
|
|
throw new BusinessException("不可自己核销自己");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 用户已有套餐
|
|
// 用户已有套餐
|
|
|
- Map<Long, UserSet> userSetMap = userSetRepo.findAllByUserId(writeOffSaveVO.getUserId())
|
|
|
|
|
|
|
+ Map<Long, UserPackage> userSetMap = userPackageRepo.findAllByUserId(writeOffSaveVO.getUserId())
|
|
|
.stream()
|
|
.stream()
|
|
|
- .collect(Collectors.toMap(UserSet::getGoodsInfoId, userSet -> userSet));
|
|
|
|
|
|
|
+ .collect(Collectors.toMap(UserPackage::getGoodsInfoId, userSet -> userSet));
|
|
|
|
|
|
|
|
List<GoodsDTO> goodsDTOS = JSONObject.parseArray(writeOffSaveVO.getContent(), GoodsDTO.class);
|
|
List<GoodsDTO> goodsDTOS = JSONObject.parseArray(writeOffSaveVO.getContent(), GoodsDTO.class);
|
|
|
goodsDTOS.forEach(goodsDTO -> {
|
|
goodsDTOS.forEach(goodsDTO -> {
|
|
|
- UserSet userSet = userSetMap.get(goodsDTO.getGoodsInfoId());
|
|
|
|
|
|
|
+ UserPackage userSet = userSetMap.get(goodsDTO.getGoodsInfoId());
|
|
|
if (ObjectUtil.isEmpty(userSet)) {
|
|
if (ObjectUtil.isEmpty(userSet)) {
|
|
|
throw new BusinessException("无此项目");
|
|
throw new BusinessException("无此项目");
|
|
|
}
|
|
}
|
|
@@ -118,8 +116,8 @@ public class UserSetFlowService {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 保存套餐流水
|
|
// 保存套餐流水
|
|
|
- return userSetFlowRepo.save(
|
|
|
|
|
- UserSetFlow.builder()
|
|
|
|
|
|
|
+ return userPackageFlowRepo.save(
|
|
|
|
|
+ UserPackageFlow.builder()
|
|
|
.userId(writeOffSaveVO.getUserId())
|
|
.userId(writeOffSaveVO.getUserId())
|
|
|
.content(writeOffSaveVO.getContent())
|
|
.content(writeOffSaveVO.getContent())
|
|
|
.type(FlowType.WRITE_OFF)
|
|
.type(FlowType.WRITE_OFF)
|
|
@@ -128,7 +126,7 @@ public class UserSetFlowService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public WriteOffRecordDTO getDTO(Long id) {
|
|
public WriteOffRecordDTO getDTO(Long id) {
|
|
|
- UserSetFlow writeOffRecord = userSetFlowRepo.findById(id).orElseThrow(new BusinessException("无核销记录"));
|
|
|
|
|
|
|
+ UserPackageFlow writeOffRecord = userPackageFlowRepo.findById(id).orElseThrow(new BusinessException("无核销记录"));
|
|
|
// 转vo
|
|
// 转vo
|
|
|
List<GoodsDTO> goodsDTOS = JSONObject.parseArray(writeOffRecord.getContent(), GoodsDTO.class);
|
|
List<GoodsDTO> goodsDTOS = JSONObject.parseArray(writeOffRecord.getContent(), GoodsDTO.class);
|
|
|
Set<Long> ids = goodsDTOS.stream().map(GoodsDTO::getGoodsInfoId).collect(Collectors.toSet());
|
|
Set<Long> ids = goodsDTOS.stream().map(GoodsDTO::getGoodsInfoId).collect(Collectors.toSet());
|