Skip to content

Commit

Permalink
功能描述:
Browse files Browse the repository at this point in the history
  1. 删除属性与分组的关联关系
  API: https://easydoc.xyz/doc/75716633/ZUqEdvA4/qn7A2Fht

  2.获取属性分组的关联的所有属性
  API:https://easydoc.xyz/doc/75716633/ZUqEdvA4/LnjzZHPj
  • Loading branch information
cosmoswong committed May 6, 2020
1 parent 30f12ee commit 89c0bc5
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.bigdata.common.utils.PageUtils;
import com.bigdata.common.utils.R;
import com.bigdata.gulimall.product.entity.AttrEntity;
import com.bigdata.gulimall.product.entity.AttrGroupEntity;
import com.bigdata.gulimall.product.service.AttrGroupService;
import com.bigdata.gulimall.product.service.AttrService;
import com.bigdata.gulimall.product.service.CategoryService;
import com.bigdata.gulimall.product.vo.AttrGroupRelationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


Expand All @@ -29,6 +33,36 @@ public class AttrGroupController {
@Autowired
CategoryService categoryService;

@Autowired
AttrService attrService;

/**
* 删除属性与分组的关联关系
* API: https://easydoc.xyz/doc/75716633/ZUqEdvA4/qn7A2Fht
* @param attrGroupRelationVos
* @return
*/
///product/attrgroup/attr/relation/delete
@PostMapping("/attr/relation/delete")
public R delAttrRelation(@RequestBody AttrGroupRelationVo[] attrGroupRelationVos){
attrService.deleteRelation(attrGroupRelationVos);

return R.ok();
}

/**
* 获取属性分组的关联的所有属性
* API:https://easydoc.xyz/doc/75716633/ZUqEdvA4/LnjzZHPj
* //product/attrgroup/{attrgroupId}/attr/relation
* @param attrgroupId 分组ID
* @return
*/
@GetMapping("{attrgroupId}/attr/relation")
public R attrRelation(@PathVariable("attrgroupId") Long attrgroupId){
List<AttrEntity> entityList = attrService.getRelationAtr(attrgroupId);
return R.ok().put("data",entityList);
}

/**
* 列表
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.bigdata.gulimall.product.entity.AttrAttrgroupRelationEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* 属性&属性分组关联
Expand All @@ -13,5 +16,6 @@
*/
@Mapper
public interface AttrAttrgroupRelationDao extends BaseMapper<AttrAttrgroupRelationEntity> {


void deleteBatchRelation(@Param("entityList") List<AttrAttrgroupRelationEntity> entityList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.baomidou.mybatisplus.extension.service.IService;
import com.bigdata.common.utils.PageUtils;
import com.bigdata.gulimall.product.vo.AttrGroupRelationVo;
import com.bigdata.gulimall.product.vo.AttrResponseVo;
import com.bigdata.gulimall.product.vo.AttrVo;
import com.bigdata.gulimall.product.entity.AttrEntity;

import java.util.List;
import java.util.Map;

/**
Expand All @@ -26,5 +28,9 @@ public interface AttrService extends IService<AttrEntity> {
AttrResponseVo getAttrInfo(Long attrId);

void updateAttr(AttrVo attr);

List<AttrEntity> getRelationAtr(Long attrgroupId);

void deleteRelation(AttrGroupRelationVo[] attrGroupRelationVos);
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.bigdata.gulimall.product.entity.AttrGroupEntity;
import com.bigdata.gulimall.product.entity.CategoryEntity;
import com.bigdata.gulimall.product.service.CategoryService;
import com.bigdata.gulimall.product.vo.AttrGroupRelationVo;
import com.bigdata.gulimall.product.vo.AttrResponseVo;
import com.bigdata.gulimall.product.vo.AttrVo;
import com.bigdata.gulimall.product.entity.AttrAttrgroupRelationEntity;
Expand All @@ -14,6 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -179,4 +181,37 @@ public void updateAttr(AttrVo attrVo) {
}
}
}

/**
* 根据分组ID查找关联的所有属性
* @param attrgroupId
* @return
*/
@Override
public List<AttrEntity> getRelationAtr(Long attrgroupId) {
QueryWrapper<AttrAttrgroupRelationEntity> queryWrapper = new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_group_id", attrgroupId);
List<AttrAttrgroupRelationEntity> relationEntities = relationDao.selectList(queryWrapper);
List<AttrEntity> entityList = relationEntities.stream().map(attrAttrgroupRelationEntity -> {
Long attrId = attrAttrgroupRelationEntity.getAttrId();

return this.getById(attrId);
}).filter(attrEntity -> {
return attrEntity != null;
}).collect(Collectors.toList());

return entityList;
}

@Override
public void deleteRelation(AttrGroupRelationVo[] attrGroupRelationVos) {
List<AttrAttrgroupRelationEntity> entityList = Arrays.asList(attrGroupRelationVos).stream().map(param -> {
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
BeanUtils.copyProperties(param, relationEntity);
return relationEntity;
}).collect(Collectors.toList());



relationDao.deleteBatchRelation(entityList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bigdata.gulimall.product.vo;

import lombok.Data;

@Data
public class AttrGroupRelationVo {

//属性ID
private Long attrId;

//属性分组ID
private Long attrGroupId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<result property="attrGroupId" column="attr_group_id"/>
<result property="attrSort" column="attr_sort"/>
</resultMap>

<delete id="deleteBatchRelation">
DELETE FROM `pms_attr_attrgroup_relation` WHERE
<foreach collection="entityList" item="item" separator=" OR ">
(attr_id= #{item.attrId} AND attr_group_id = #{item.attrGroupId})
</foreach>
</delete>

</mapper>

0 comments on commit 89c0bc5

Please sign in to comment.