品类信息的修改和删除
parent
a61f71e52f
commit
11633283ce
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.req.CategoryInfoUpdReq;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -13,11 +14,9 @@ import io.swagger.annotations.*;
|
|||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.product.domain.req.CategoryInfoQueryReq;
|
||||
import com.muyu.product.domain.req.CategoryInfoSaveReq;
|
||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||
import com.muyu.common.core.web.domain.TreeEntity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
|
@ -92,7 +91,7 @@ public class CategoryInfo extends TreeEntity {
|
|||
/**
|
||||
* 修改构造器
|
||||
*/
|
||||
public static CategoryInfo editBuild(Long id, CategoryInfoEditReq categoryInfoEditReq){
|
||||
public static CategoryInfo editBuild(Long id, CategoryInfoUpdReq categoryInfoEditReq){
|
||||
return CategoryInfo.builder()
|
||||
.id(id)
|
||||
.name(categoryInfoEditReq.getName())
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.product.domain.req;
|
||||
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -8,6 +9,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.TreeEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
|
@ -39,4 +42,9 @@ public class CategoryInfoEditReq extends TreeEntity {
|
|||
@ApiModelProperty(name = "介绍", value = "介绍")
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 属性ID集合
|
||||
*/
|
||||
private List<CategoryInfoSaveModel> attributeIdList;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.muyu.product.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CategoryInfoUpdReq {
|
||||
|
||||
|
||||
/** 品类名称 */
|
||||
private String name;
|
||||
|
||||
/** 图片 */
|
||||
private String image;
|
||||
|
||||
/** 是否启用 */
|
||||
private String start;
|
||||
|
||||
/** 介绍 */
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 商品属性组关联ID
|
||||
*/
|
||||
private List<Long> attributeGroupIdList;
|
||||
/**
|
||||
* 商品属性关联ID
|
||||
*/
|
||||
private List<Long> attributeIdList;
|
||||
|
||||
/**
|
||||
* 商品品牌组关联ID
|
||||
*/
|
||||
private List<Long> brandIdList;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.product.domain.resp;
|
||||
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CategoryInfoResp {
|
||||
/** 品类名称 */
|
||||
@ApiModelProperty(name = "品类名称", value = "品类名称", required = true)
|
||||
private String name;
|
||||
|
||||
/** 图片 */
|
||||
@ApiModelProperty(name = "图片", value = "图片", required = true)
|
||||
private String image;
|
||||
|
||||
/** 是否启用 */
|
||||
@ApiModelProperty(name = "是否启用", value = "是否启用", required = true)
|
||||
private String start;
|
||||
|
||||
/** 介绍 */
|
||||
@ApiModelProperty(name = "介绍", value = "介绍")
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 属性ID集合
|
||||
*/
|
||||
private List<CategoryInfoSaveModel> attributeIdList;
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ import com.muyu.product.domain.AttributeGroup;
|
|||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.BrandInfo;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.req.CategoryInfoUpdReq;
|
||||
import com.muyu.product.domain.resp.CategoryCommonElementResp;
|
||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||
import io.swagger.annotations.*;
|
||||
|
@ -112,7 +113,8 @@ public class CategoryInfoController extends BaseController {
|
|||
@Log(title = "品类信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改品类信息")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody CategoryInfoEditReq categoryInfoEditReq) {
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody CategoryInfoUpdReq categoryInfoEditReq) {
|
||||
categoryInfoService.updAsCategoryAttribute(id, categoryInfoEditReq);
|
||||
return toAjax(categoryInfoService.updateById(CategoryInfo.editBuild(id,categoryInfoEditReq)));
|
||||
}
|
||||
|
||||
|
@ -124,8 +126,10 @@ public class CategoryInfoController extends BaseController {
|
|||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除品类信息")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(categoryInfoService.removeBatchByIds(ids));
|
||||
public Result remove(@PathVariable String ids) {
|
||||
categoryInfoService.deleteByIds(ids);
|
||||
return Result.success();
|
||||
// return toAjax(categoryInfoService.removeBatchByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.mapper;
|
|||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.product.domain.CategoryInfo;
|
||||
import com.muyu.product.domain.resp.CategoryInfoResp;
|
||||
|
||||
/**
|
||||
* 品类信息Mapper接口
|
||||
|
@ -12,4 +13,7 @@ import com.muyu.product.domain.CategoryInfo;
|
|||
*/
|
||||
public interface CategoryInfoMapper extends BaseMapper<CategoryInfo> {
|
||||
|
||||
int findById(String ids);
|
||||
|
||||
List<CategoryInfo> getListByIds(String ids);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.product.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface UpdAsCategoryAttributeMapper {
|
||||
void delAsCategoryAttribute(Long id);
|
||||
|
||||
void addAsCategoryAttribute(@Param("id") Long id, @Param("l") Long l);
|
||||
|
||||
void delAsCategoryAttributeGroup(Long id);
|
||||
|
||||
void addAsCategoryAttributeGroup(@Param("id") Long id, @Param("l") Long l);
|
||||
|
||||
void delAsCategoryBrand(Long id);
|
||||
|
||||
void addAsCategoryBrand(@Param("id") Long id, @Param("aLong") Long aLong);
|
||||
}
|
|
@ -2,13 +2,17 @@ package com.muyu.product.service;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.product.domain.AttributeGroup;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.BrandInfo;
|
||||
import com.muyu.product.domain.CategoryInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||
import com.muyu.product.domain.req.CategoryInfoUpdReq;
|
||||
import com.muyu.product.domain.resp.CategoryCommonElementResp;
|
||||
import com.muyu.product.domain.resp.CategoryInfoResp;
|
||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||
|
||||
/**
|
||||
|
@ -69,4 +73,11 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
|
|||
CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId);
|
||||
|
||||
public <T, AS> List<T> getCommon (Long categoryId, IService<AS> iService, IService<T> bsiService);
|
||||
|
||||
void deleteByIds(String ids);
|
||||
|
||||
void updAsCategoryAttribute(Long id, CategoryInfoUpdReq categoryInfoEditReq);
|
||||
|
||||
|
||||
// Result<String> edit(Long id, CategoryInfoEditReq categoryInfoEditReq);
|
||||
}
|
||||
|
|
|
@ -4,15 +4,21 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.product.domain.*;
|
||||
import com.muyu.product.domain.base.CategoryBase;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.model.TemplateAttributeGroupModel;
|
||||
import com.muyu.product.domain.model.TemplateAttributeModel;
|
||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||
import com.muyu.product.domain.req.CategoryInfoUpdReq;
|
||||
import com.muyu.product.domain.resp.CategoryCommonElementResp;
|
||||
import com.muyu.product.domain.resp.CategoryInfoResp;
|
||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||
import com.muyu.product.mapper.CategoryInfoMapper;
|
||||
import com.muyu.product.mapper.UpdAsCategoryAttributeMapper;
|
||||
import com.muyu.product.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -58,6 +64,11 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
@Autowired
|
||||
private AttributeGroupService attributeGroupService;
|
||||
|
||||
@Autowired
|
||||
private CategoryInfoMapper categoryInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private UpdAsCategoryAttributeMapper updAsCategoryAttributeMapper;
|
||||
/**
|
||||
* 查询品类信息列表
|
||||
*
|
||||
|
@ -270,6 +281,73 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByIds(String ids) {
|
||||
//通过id查询子集
|
||||
int num=categoryInfoMapper.findById(ids);
|
||||
//判断num是否大于0
|
||||
if (num>0){
|
||||
throw new RuntimeException("该商品存在子集,不能删除");
|
||||
}
|
||||
//根据id查询查询集合
|
||||
List<CategoryInfo> categoryInfoList = categoryInfoMapper.getListByIds(ids);
|
||||
if (categoryInfoList.size()>0){
|
||||
//遍历
|
||||
for (CategoryInfo categoryInfo : categoryInfoList) {
|
||||
//获取名称
|
||||
String name = categoryInfo.getName();
|
||||
//判断
|
||||
if (StringUtils.isNotEmpty(name)){
|
||||
throw new RuntimeException("目录中有商品,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
categoryInfoMapper.deleteById(ids);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updAsCategoryAttribute(Long id, CategoryInfoUpdReq categoryInfoEditReq) {
|
||||
//删除
|
||||
updAsCategoryAttributeMapper.delAsCategoryAttribute(id);
|
||||
//获取集合
|
||||
List<Long> attributeIdList = categoryInfoEditReq.getAttributeIdList();
|
||||
if (attributeIdList != null){
|
||||
//遍历
|
||||
for (Long l : attributeIdList) {
|
||||
//添加
|
||||
updAsCategoryAttributeMapper.addAsCategoryAttribute(id,l);
|
||||
}
|
||||
}else {
|
||||
throw new RuntimeException("attributeGroupIdList is null");
|
||||
}
|
||||
|
||||
//删除
|
||||
updAsCategoryAttributeMapper.delAsCategoryAttributeGroup(id);
|
||||
//获取集合
|
||||
List<Long> attributeGroupIdList = categoryInfoEditReq.getAttributeGroupIdList();
|
||||
//遍历
|
||||
for (Long l : attributeGroupIdList) {
|
||||
updAsCategoryAttributeMapper.addAsCategoryAttributeGroup(id,l);
|
||||
}
|
||||
//删除
|
||||
updAsCategoryAttributeMapper.delAsCategoryBrand(id);
|
||||
//获取集合
|
||||
List<Long> brandIdList = categoryInfoEditReq.getBrandIdList();
|
||||
//遍历
|
||||
for (Long aLong : brandIdList) {
|
||||
updAsCategoryAttributeMapper.addAsCategoryBrand(id,aLong);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public Result<String> edit(Long id, CategoryInfoEditReq categoryInfoEditReq) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性、属性组、品牌集合
|
||||
*
|
||||
|
|
|
@ -148,23 +148,23 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo> i
|
|||
//添加规格详情表
|
||||
List<RuleAttrAddModel> ruleAttrList = ruleInfoEditReq.getRuleAttrList();
|
||||
//遍历
|
||||
String value="";
|
||||
for (RuleAttrAddModel ruleAttrAddModel : ruleAttrList) {
|
||||
//获取集合
|
||||
List<String> valueList = ruleAttrAddModel.getValueList();
|
||||
//定义值
|
||||
String value="";
|
||||
String valueData=null;
|
||||
|
||||
//遍历
|
||||
for (String s : valueList) {
|
||||
System.out.println(s);
|
||||
valueData=value+","+s;
|
||||
value+=","+s;
|
||||
}
|
||||
System.out.println(valueData);
|
||||
//截取
|
||||
String substring = valueData.substring(1);
|
||||
String substring = value.substring(1);
|
||||
System.out.println(substring);
|
||||
//添加
|
||||
ruleAttrInfoMapper.addRuleAttrModel(id,ruleAttrAddModel.getName(),substring);
|
||||
value="";
|
||||
}
|
||||
// ruleAttrInfoService.delete(id);
|
||||
// List<AttributeInfo> attributeInfoList = ruleInfoEditReq.getAttributeInfoList();
|
||||
|
|
|
@ -21,4 +21,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<sql id="selectCategoryInfoVo">
|
||||
select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info
|
||||
</sql>
|
||||
<select id="findById" resultType="java.lang.Integer">
|
||||
select count(1) from category_info where parent_id = #{ids}
|
||||
</select>
|
||||
<select id="getListByIds" resultType="com.muyu.product.domain.CategoryInfo">
|
||||
select * from category_info where id = #{ids}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.product.mapper.UpdAsCategoryAttributeMapper">
|
||||
<insert id="addAsCategoryAttribute">
|
||||
insert into as_category_attribute(category_id, attribute_id) values (#{id}, #{l})
|
||||
</insert>
|
||||
<insert id="addAsCategoryAttributeGroup">
|
||||
insert into as_category_attribute_group(category_id, attribute_group_id) values (#{id}, #{l})
|
||||
</insert>
|
||||
<insert id="addAsCategoryBrand">
|
||||
insert into as_category_brand(category_id, brand_id) values (#{id}, #{aLong})
|
||||
</insert>
|
||||
|
||||
<delete id="delAsCategoryAttribute">
|
||||
delete
|
||||
from as_category_attribute
|
||||
where category_id = #{id}
|
||||
</delete>
|
||||
<delete id="delAsCategoryAttributeGroup">
|
||||
delete
|
||||
from as_category_attribute_group
|
||||
where category_id = #{id}
|
||||
</delete>
|
||||
<delete id="delAsCategoryBrand">
|
||||
delete
|
||||
from as_category_brand
|
||||
where category_id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
Loading…
Reference in New Issue