毕设-仿谷粒商城项目(14周周四)

商品服务-品牌管理

开启分页管理功能:

/**
 * @author 鲤鱼军
 * @version 1.0
 * @description 分页配置
 * @date 2024-05-30 - 上午 8:04
 */
@Configuration
@EnableTransactionManagement
@MapperScan("com.lnut.liyumall.product.dao")
public class MyBatisConfig {
    //引入分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        //设置请求的页面大于最大页后操作,true调回到首页,false继续请求
        paginationInterceptor.setOverflow(true);
        //设置最大单页限制数量,-1不受限制
        paginationInterceptor.setLimit(1000);
        return paginationInterceptor;
    }
}

品牌分类关联与级联更新:

品牌管理,使用方法一:使用querywrapper

    /**
     * 15.获取品牌关联的分类
     */
//    @RequestMapping(value = "/catelog/list",method = RequestMethod.GET)
    @GetMapping("/catelog/list")
    public R cateloglist(@RequestParam("brandId")Long brandId){
        List<CategoryBrandRelationEntity> data = categoryBrandRelationService.queryPage(brandId);
        return R.ok().put("data",data);
    }

    /**
     * 获取当前品牌关联的所有分类列表
     * @param brandId 当前品牌id
     * @return 分类列表
     */
    @Override
    public List<CategoryBrandRelationEntity> queryPage(Long brandId) {
        List<CategoryBrandRelationEntity> data = this.list(
                new QueryWrapper<CategoryBrandRelationEntity>().eq("brand_id",brandId)
        );
        return data;
    }
    /**
     * 16、新增品牌与分类关联关系
     * @param categoryBrandRelation
     * @return
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:categorybrandrelation:save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
        categoryBrandRelationService.saveDetail(categoryBrandRelation);
        return R.ok();
    }

    /**
     * 新增品牌与分类关联关系
     * @param categoryBrandRelation
     */
    @Override
    public void saveDetail(CategoryBrandRelationEntity categoryBrandRelation) {
        Long brandId = categoryBrandRelation.getBrandId();
        Long catelogId = categoryBrandRelation.getCatelogId();
        //根据id查询商品和目录的实体类
        BrandEntity brandEntity = brandDao.selectById(brandId);
        CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
        //再添加name属性
        categoryBrandRelation.setBrandName(brandEntity.getName());
        categoryBrandRelation.setCatelogName(categoryEntity.getName());
        //保存新增
        this.save(categoryBrandRelation);
    }

商品分类管理,方法二:使用sql语句

    /**
     * 修改单个节点信息
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:category:update")
    public R update(@RequestBody CategoryEntity category){
//		categoryService.updateById(category);
    //优化-级联更新
        categoryService.updateCascade(category);
        return R.ok();
    }
@Mapper
public interface CategoryBrandRelationDao extends BaseMapper<CategoryBrandRelationEntity> {

    @Update("update pms_category_brand_relation set catelog_name=#{name} where catelog_id=#{catId}")
    void updateCategory(Long catId, String name);
}

后端操作:

直接拷贝common文件夹和product文件夹

修改操作:需要把common文件夹下的三个文件各自的获取路径更改一下

    getMenus() {
      this.$http({
        url: this.$http.adornUrl("/product/category/list/tree"),
        method: "get"
      }).then(({ data }) => {
        //this.menus = data.data;
        this.menus = data.page;
      });
    },

    getCategorys() {
      this.$http({
        url: this.$http.adornUrl("/product/category/list/tree"),
        method: "get"
      }).then(({ data }) => {
        //this.categorys = data.data;
        this.categorys = data.page;
      });
    }

      this.$http({
        url: this.$http.adornUrl("/product/categorybrandrelation/brands/list"),
        method: "get",
        params: this.$http.adornParams({
          catId: this.catId
        })
      }).then(({ data }) => {
        // this.brands = data.data;
        this.brands = data.page;
      });

规格参数-举例修改方法

路径工具类【通过分类id获取完整的分类路径】:

/**
 * @author 鲤鱼军
 * @version 1.0
 * @description product模块的工具类
 * @date 2024-05-30 - 下午 10:02
 */
@Component
public class ProductUtils implements Serializable {
    @Autowired
    private CategoryServiceImpl categoryService;

    /**
     * 通过分类id获取完整的分类路径
     * @param catelogId 分类id
     * @return 分类完整路径
     */
    public Long[] findCatelogPath(Long catelogId) {
        if (catelogId==0){
            throw new RuntimeException("catelogId为空");
        }
        List<Long> paths = new ArrayList<>();
        List<Long> parentPath = findParentPath(catelogId, paths);
        Collections.reverse(parentPath);
        return parentPath.toArray(new Long[parentPath.size()]);
    }
    /**
     * 递归获得完整路径
     * @param catelogId 当前分类
     * @param paths 完整路径的集合
     * @return
     */
    //225,25,2
    private List<Long> findParentPath(Long catelogId,List<Long> paths){
        //1、收集当前节点id
        paths.add(catelogId);
        CategoryEntity byId = categoryService.getById(catelogId);
        if(byId.getParentCid()!=0){
            findParentPath(byId.getParentCid(),paths);
        }
        return paths;

    }


}
    /**
     * 修改
     * 08、修改属性/product/attr/update
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
//		attrService.updateById(attr);
		//优化修改方法
        attrService.updateAttr(attr);
        return R.ok();
    }


    @Transactional
    public void updateAttr(AttrVo attr) {
        AttrEntity attrEntity = new AttrEntity();
        BeanUtils.copyProperties(attr,attrEntity);
        this.updateById(attrEntity);

        if(attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()){
            //1、修改分组关联
            AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();

            relationEntity.setAttrGroupId(attr.getAttrGroupId());
            relationEntity.setAttrId(attr.getAttrId());

            Integer count = attrgroupRelationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attr.getAttrId()));
            if(count>0){
                attrgroupRelationDao.update(relationEntity,new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attr.getAttrId()));
            }else{
                attrgroupRelationDao.insert(relationEntity);
            }
        }
    }

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值