|
@@ -1,19 +1,22 @@
|
|
|
package com.miaxis.collection.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.miaxis.collection.domain.CollectionInfo;
|
|
|
import com.miaxis.collection.mapper.CollectionInfoMapper;
|
|
|
import com.miaxis.collection.service.ICollectionInfoService;
|
|
|
-import com.miaxis.collection.vo.CollectionCustomerVo;
|
|
|
+import com.miaxis.collection.strategy.BaseStrategy;
|
|
|
+import com.miaxis.collection.vo.AppletCollectionVo;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
-import com.miaxis.customer.mapper.CustomerInfoMapper;
|
|
|
+import com.miaxis.common.strategy.StrategyManager;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -28,18 +31,44 @@ public class CollectionInfoServiceImpl extends ServiceImpl<CollectionInfoMapper,
|
|
|
|
|
|
private final CollectionInfoMapper collectionInfoMapper;
|
|
|
|
|
|
- private final CustomerInfoMapper customerInfoMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询用户收藏列表
|
|
|
+ *
|
|
|
* @param userInfo
|
|
|
+ * @param collectionType
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
@SneakyThrows
|
|
|
- public List<CollectionCustomerVo> collectionList(UserInfo userInfo) {
|
|
|
- return customerInfoMapper.getCollectionList(userInfo.getId());
|
|
|
+ public Response collectionList(UserInfo userInfo,String collectionType) {
|
|
|
+ //返回list
|
|
|
+ ArrayList<AppletCollectionVo> collectionVos = new ArrayList<>();
|
|
|
+
|
|
|
+ //根据收藏列表list
|
|
|
+ List<CollectionInfo> collectionInfos;
|
|
|
+
|
|
|
+ if ("1".equals(collectionType)){
|
|
|
+ collectionInfos = collectionInfoMapper
|
|
|
+ .selectList(new QueryWrapper<CollectionInfo>()
|
|
|
+ .eq("user_id", userInfo.getId()));
|
|
|
+ }else{
|
|
|
+ collectionInfos = collectionInfoMapper
|
|
|
+ .selectList(new QueryWrapper<CollectionInfo>()
|
|
|
+ .eq("user_id", userInfo.getId())
|
|
|
+ .eq("collection_type",collectionType));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (CollectionInfo collectionInfo : collectionInfos) {
|
|
|
+ //获取对应策略
|
|
|
+ BaseStrategy baseStrategy = (BaseStrategy) StrategyManager.getInstance().getStrategy(collectionInfo.getCollectionType());
|
|
|
+ //策略不存在
|
|
|
+ if (baseStrategy == null) continue;
|
|
|
+ AppletCollectionVo collectionVo = baseStrategy.getCollectionVo(collectionInfo.getId(),collectionInfo.getCollectionId());
|
|
|
+ collectionVos.add(collectionVo);
|
|
|
+ }
|
|
|
+ return Response.success(collectionVos);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -61,7 +90,7 @@ public class CollectionInfoServiceImpl extends ServiceImpl<CollectionInfoMapper,
|
|
|
//保存收藏表
|
|
|
CollectionInfo collectionInfo = new CollectionInfo();
|
|
|
collectionInfo.setUserId(userInfo.getId());
|
|
|
- collectionInfo.setCustomerId(id);
|
|
|
+ collectionInfo.setCollectionId(id);
|
|
|
collectionInfoMapper.insert(collectionInfo);
|
|
|
}
|
|
|
return Response.success();
|
|
@@ -94,4 +123,28 @@ public class CollectionInfoServiceImpl extends ServiceImpl<CollectionInfoMapper,
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 通用收藏接口
|
|
|
+ * @param userInfo
|
|
|
+ * @param id
|
|
|
+ * @param collectionType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response collectionOperation(UserInfo userInfo, Long id, String collectionType) {
|
|
|
+ try{
|
|
|
+ //保存收藏表
|
|
|
+ CollectionInfo collectionInfo = new CollectionInfo();
|
|
|
+ collectionInfo.setUserId(userInfo.getId());
|
|
|
+ collectionInfo.setCollectionId(id);
|
|
|
+ collectionInfo.setCollectionType(collectionType);
|
|
|
+ collectionInfoMapper.insert(collectionInfo);
|
|
|
+ return Response.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|