品类信息修改优化
parent
414ab09bd8
commit
862b7d5427
|
@ -78,7 +78,6 @@ public class CategoryInfoController extends BaseController {
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||||
public Result<CategoryInfo> getInfo(@PathVariable("id") Long id) {
|
public Result<CategoryInfo> getInfo(@PathVariable("id") Long id) {
|
||||||
|
|
||||||
return Result.success(categoryInfoService.getById(id));
|
return Result.success(categoryInfoService.getById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +89,8 @@ public class CategoryInfoController extends BaseController {
|
||||||
@GetMapping(value = "/getTemplateAttribute/{cateGoryId}")
|
@GetMapping(value = "/getTemplateAttribute/{cateGoryId}")
|
||||||
@ApiImplicitParam(name = "cateGoryId", value = "cateGoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "cateGoryId", value = "cateGoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||||
public Result<CategoryCommonElementResp> getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) {
|
public Result<CategoryCommonElementResp> getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) {
|
||||||
return Result.success(categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId));
|
CategoryCommonElementResp templateAttributeByCateGoryId = categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId);
|
||||||
|
return Result.success(templateAttributeByCateGoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,19 +15,6 @@ import org.apache.ibatis.annotations.Param;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CategoryInfoMapper extends BaseMapper<CategoryInfo> {
|
public interface CategoryInfoMapper extends BaseMapper<CategoryInfo> {
|
||||||
|
|
||||||
void delAttributeGroupId(Long id);
|
|
||||||
|
|
||||||
void delAttributeIdList(Long id);
|
|
||||||
|
|
||||||
void delArandIdList(Long id);
|
|
||||||
|
|
||||||
// void addAttributeGroupId(@Param("id") Long id, @Param("attributeGroupId") Long attributeGroupId);
|
|
||||||
void attributeGroupIdList(@Param("id") Long id, @Param("aLong") Long aLong);
|
|
||||||
|
|
||||||
void addAttributeIdList(@Param("id") Long id, @Param("attributeId") Long attributeId);
|
|
||||||
|
|
||||||
void addArandIdList(@Param("id") Long id, @Param("brandId") Long brandId);
|
|
||||||
|
|
||||||
Integer selectByPid(String ids);
|
Integer selectByPid(String ids);
|
||||||
|
|
||||||
Integer selectAsCategoryBrand(String ids);
|
Integer selectAsCategoryBrand(String ids);
|
||||||
|
|
|
@ -20,11 +20,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -280,24 +278,49 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
||||||
public Result updateCategory(Long id, CategoryInfoEditReq categoryInfoEditReq) {
|
public Result updateCategory(Long id, CategoryInfoEditReq categoryInfoEditReq) {
|
||||||
|
|
||||||
|
|
||||||
categoryInfoMapper.delAttributeIdList(id);
|
if(!CollectionUtils.isEmpty(categoryInfoEditReq.getAttributeIdList()) && categoryInfoEditReq.getAttributeIdList()!=null){
|
||||||
List<Long> attributeIdList = categoryInfoEditReq.getAttributeIdList();
|
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<AsCategoryAttribute>().eq(AsCategoryAttribute::getCategoryId,id);
|
||||||
for (Long aLong : attributeIdList) {
|
asCategoryAttributeService.remove(queryWrapper);
|
||||||
categoryInfoMapper.addAttributeIdList(id,aLong);
|
List<AsCategoryAttribute> asCategoryAttributeList = categoryInfoEditReq.getAttributeIdList().stream().map(aLong -> {
|
||||||
|
AsCategoryAttribute asCategoryAttribute = new AsCategoryAttribute();
|
||||||
|
asCategoryAttribute.setCategoryId(id);
|
||||||
|
asCategoryAttribute.setAttributeId(aLong);
|
||||||
|
return asCategoryAttribute;
|
||||||
|
}).toList();
|
||||||
|
asCategoryAttributeService.saveBatch(asCategoryAttributeList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!CollectionUtils.isEmpty(categoryInfoEditReq.getBrandIdList()) && categoryInfoEditReq.getBrandIdList()!=null){
|
||||||
|
LambdaQueryWrapper<AsCategoryBrand> queryWrapper = new LambdaQueryWrapper<AsCategoryBrand>()
|
||||||
|
.eq(AsCategoryBrand::getCategoryId,id);
|
||||||
|
asCategoryBrandService.remove(queryWrapper);
|
||||||
|
|
||||||
|
List<AsCategoryBrand> asCategoryBrandList = categoryInfoEditReq.getBrandIdList().stream().map(aLong -> {
|
||||||
|
AsCategoryBrand asCategoryBrand = new AsCategoryBrand();
|
||||||
|
asCategoryBrand.setCategoryId(id);
|
||||||
|
asCategoryBrand.setBrandId(aLong);
|
||||||
|
return asCategoryBrand;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
asCategoryBrandService.saveBatch(asCategoryBrandList);
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!CollectionUtils.isEmpty(categoryInfoEditReq.getAttributeGroupIdList()) && categoryInfoEditReq.getAttributeGroupIdList()!=null){
|
||||||
|
LambdaQueryWrapper<AsCategoryAttributeGroup> queryWrapper = new LambdaQueryWrapper<AsCategoryAttributeGroup>().eq(AsCategoryAttributeGroup::getCategoryId, id);
|
||||||
|
asCategoryAttributeGroupService.remove(queryWrapper);
|
||||||
|
|
||||||
|
List<AsCategoryAttributeGroup> groupStream = categoryInfoEditReq.getAttributeGroupIdList().stream().map(aLong -> {
|
||||||
|
AsCategoryAttributeGroup asCategoryAttributeGroup = new AsCategoryAttributeGroup();
|
||||||
|
asCategoryAttributeGroup.setCategoryId(id);
|
||||||
|
asCategoryAttributeGroup.setAttributeGroupId(aLong);
|
||||||
|
return asCategoryAttributeGroup;
|
||||||
|
}).toList();
|
||||||
|
asCategoryAttributeGroupService.saveBatch(groupStream);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
categoryInfoMapper.delArandIdList(id);
|
|
||||||
List<Long> brandIdList = categoryInfoEditReq.getBrandIdList();
|
|
||||||
for (Long aLong : brandIdList) {
|
|
||||||
categoryInfoMapper.addArandIdList(id,aLong);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoryInfoMapper.delAttributeGroupId(id);
|
|
||||||
List<Long> attributeGroupIdList = categoryInfoEditReq.getAttributeGroupIdList();
|
|
||||||
for (Long aLong : attributeGroupIdList) {
|
|
||||||
categoryInfoMapper.attributeGroupIdList(id,aLong);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.success(0,"修改成功");
|
return Result.success(0,"修改成功");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,32 +22,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info
|
select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="addAttributeIdList">
|
|
||||||
INSERT INTO `as_category_attribute` ( `category_id`, `attribute_id`)
|
|
||||||
VALUES (#{id},#{attributeId});
|
|
||||||
|
|
||||||
</insert>
|
|
||||||
<insert id="addArandIdList">
|
|
||||||
INSERT INTO `as_category_brand` (`category_id`, `brand_id`) values
|
|
||||||
(#{id},#{brandId})
|
|
||||||
</insert>
|
|
||||||
<insert id="attributeGroupIdList">
|
|
||||||
INSERT INTO `as_category_attribute_group` ( `category_id`, `attribute_group_id`)
|
|
||||||
VALUES (#{id},#{aLong});
|
|
||||||
|
|
||||||
</insert>
|
|
||||||
<delete id="delAttributeGroupId">
|
|
||||||
delete from as_category_attribute where category_id = #{id}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<delete id="delAttributeIdList">
|
|
||||||
delete from as_category_brand where category_id = #{id}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<delete id="delArandIdList">
|
|
||||||
delete from as_category_attribute_group where category_id = #{id}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<select id="selectByPid" resultType="java.lang.Integer">
|
<select id="selectByPid" resultType="java.lang.Integer">
|
||||||
select count(1) from category_info where parent_id = #{ids}
|
select count(1) from category_info where parent_id = #{ids}
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in New Issue