|
@@ -1,23 +1,27 @@
|
|
|
package com.miaxis.topic.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.utils.bean.BeanUtils;
|
|
|
+import com.miaxis.customer.domain.CustomerInfo;
|
|
|
import com.miaxis.goods.domain.GoodsInfo;
|
|
|
import com.miaxis.goods.service.IGoodsInfoService;
|
|
|
import com.miaxis.topic.domain.TopicInfo;
|
|
|
import com.miaxis.topic.dto.TopicInfoDto;
|
|
|
import com.miaxis.topic.mapper.TopicInfoMapper;
|
|
|
import com.miaxis.topic.service.ITopicInfoService;
|
|
|
+import com.miaxis.topic.vo.TopicInfoVo;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 专题Service业务层处理
|
|
@@ -36,12 +40,26 @@ public class TopicInfoServiceImpl extends ServiceImpl<TopicInfoMapper, TopicInfo
|
|
|
/**
|
|
|
* 查询专题列表
|
|
|
*
|
|
|
- * @param topicInfo 专题
|
|
|
+ * @param topicInfoVo 专题
|
|
|
* @return 专题
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<TopicInfo> selectTopicInfoList(TopicInfo topicInfo){
|
|
|
- return topicInfoMapper.selectTopicInfoList(topicInfo);
|
|
|
+ public List<TopicInfoVo> selectTopicInfoList(TopicInfoVo topicInfoVo){
|
|
|
+
|
|
|
+ ArrayList<TopicInfoVo> topicInfoVos = new ArrayList<>();
|
|
|
+ //专题列表
|
|
|
+ List<TopicInfo> topicInfos = topicInfoMapper.selectTopicInfoList(topicInfoVo);
|
|
|
+
|
|
|
+ for (TopicInfo topic : topicInfos) {
|
|
|
+ TopicInfoVo topicInfoVo1 = new TopicInfoVo();
|
|
|
+ BeanUtils.copyProperties(topic,topicInfoVo1);
|
|
|
+ topicInfoVo1.setGoodsInfoList(goodsInfoService.listByMap(new HashMap<String, Object>(){{
|
|
|
+ put("status",0);
|
|
|
+ put("topic_id",topic.getId());
|
|
|
+ }}));
|
|
|
+ topicInfoVos.add(topicInfoVo1);
|
|
|
+ }
|
|
|
+ return topicInfoVos;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -54,22 +72,16 @@ public class TopicInfoServiceImpl extends ServiceImpl<TopicInfoMapper, TopicInfo
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Response<Integer> addTopic(TopicInfoDto topicInfoDto) {
|
|
|
|
|
|
- //保存商品信息
|
|
|
- List<GoodsInfo> goodsInfoList = topicInfoDto.getGoodsInfoList();
|
|
|
- goodsInfoService.saveBatch(goodsInfoList);
|
|
|
-
|
|
|
//保存专题信息
|
|
|
TopicInfo topicInfo = new TopicInfo();
|
|
|
BeanUtils.copyProperties(topicInfoDto,topicInfo);
|
|
|
- String s1 = goodsInfoList.stream()
|
|
|
- .map(g -> g.getId() + ",")
|
|
|
- .collect(Collectors.toList())
|
|
|
- .toString()
|
|
|
- .replace("[","")
|
|
|
- .replace("]","");
|
|
|
- topicInfo.setGoodsId(s1);
|
|
|
this.save(topicInfo);
|
|
|
|
|
|
+ //保存商品信息
|
|
|
+ List<GoodsInfo> goodsInfoList = topicInfoDto.getGoodsInfoList();
|
|
|
+ goodsInfoList.forEach(g -> g.setTopicId(Integer.valueOf(topicInfo.getId().toString())));
|
|
|
+ goodsInfoService.saveBatch(goodsInfoList);
|
|
|
+
|
|
|
return Response.success();
|
|
|
}
|
|
|
|
|
@@ -84,19 +96,44 @@ public class TopicInfoServiceImpl extends ServiceImpl<TopicInfoMapper, TopicInfo
|
|
|
public Response<Integer> removeTopicByIds(Long[] ids) {
|
|
|
|
|
|
for (Long id : ids) {
|
|
|
- //首先删除专题对应商品
|
|
|
- String goodsIds = this.getById(id).getGoodsId();
|
|
|
- if (goodsIds.indexOf(",") != -1){
|
|
|
- for (String goodsId : Arrays.asList(goodsIds.split(","))) {
|
|
|
- goodsInfoService.update(new UpdateWrapper<GoodsInfo>().set("status",1).eq("id",goodsId));
|
|
|
- }
|
|
|
- }else {
|
|
|
- goodsInfoService.update(new UpdateWrapper<GoodsInfo>().set("status",1).eq("id",goodsIds));
|
|
|
- }
|
|
|
//删除专题
|
|
|
this.update(new UpdateWrapper<TopicInfo>().set("status",1).eq("id",id));
|
|
|
+ //删除商品
|
|
|
+ goodsInfoService.update(new UpdateWrapper<GoodsInfo>().set("status",1).eq("topic_id",id));
|
|
|
}
|
|
|
return Response.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询专题详情
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @SneakyThrows
|
|
|
+ public Response getTopicById(Long id) {
|
|
|
+ TopicInfoVo topicInfoVo = new TopicInfoVo();
|
|
|
+ TopicInfo topicInfo = this.getById(id);
|
|
|
+ BeanUtils.copyProperties(topicInfo,topicInfoVo);
|
|
|
+ topicInfoVo.setGoodsInfoList(goodsInfoService.list(new QueryWrapper<GoodsInfo>().eq("status",0).eq("topic_id",topicInfo.getId())));
|
|
|
+ return Response.success(topicInfoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新 0:上架 / 1:下架
|
|
|
+ * @param ids
|
|
|
+ * @param shelfStatus
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @SneakyThrows
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response updateShelfStatus(Long[] ids, Integer shelfStatus) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ this.update(new UpdateWrapper<TopicInfo>().set("shelf_status",shelfStatus).eq("id",id));
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|