后台系统平台属性规格参数与后端对接完毕,尚未完善新增功能

g_develop
ddyd 1 month ago
parent 035fa8315f
commit 3752e7e8d0

@ -4,12 +4,9 @@ import java.util.Arrays;
import java.util.Map;
import com.bookstore.bookmall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.bookstore.bookmall.product.entity.AttrEntity;
import com.bookstore.bookmall.product.service.AttrService;
@ -31,6 +28,17 @@ public class AttrController {
@Autowired
private AttrService attrService;
// /product/attr/base/list/{catelogId}
@GetMapping("/base/list/{catelogId}")
public R baseAttrList(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long cateLogId) {
PageUtils page = attrService.queryBasePage(params, cateLogId);
return R.ok().put("page", page);
}
/**
*
*/
@ -58,12 +66,13 @@ public class AttrController {
*/
@RequestMapping("/save")
//@RequiresPermissions("product:attr:save")
public R save(@RequestBody AttrEntity attr){
attrService.save(attr);
public R save(@RequestBody AttrVo attr){
attrService.saveAttr(attr);
return R.ok();
}
/**
*
*/

@ -1,6 +1,7 @@
package com.bookstore.bookmall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bookstore.bookmall.product.vo.AttrVo;
import com.bookstore.common.utils.PageUtils;
import com.bookstore.bookmall.product.entity.AttrEntity;
@ -17,5 +18,10 @@ public interface AttrService extends IService<AttrEntity> {
PageUtils queryPage(Map<String, Object> params);
void saveAttr(AttrVo attr);
PageUtils queryBasePage(Map<String, Object> params, Long cateLogId);
}

@ -1,7 +1,27 @@
package com.bookstore.bookmall.product.service.impl;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.bookstore.bookmall.product.dao.AttrAttrgroupRelationDao;
import com.bookstore.bookmall.product.dao.AttrGroupDao;
import com.bookstore.bookmall.product.dao.CategoryDao;
import com.bookstore.bookmall.product.entity.AttrAttrgroupRelationEntity;
import com.bookstore.bookmall.product.entity.AttrGroupEntity;
import com.bookstore.bookmall.product.entity.CategoryEntity;
import com.bookstore.bookmall.product.service.AttrAttrgroupRelationService;
import com.bookstore.bookmall.product.vo.AttrRespVo;
import com.bookstore.bookmall.product.vo.AttrVo;
import com.mysql.cj.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -11,11 +31,19 @@ import com.bookstore.common.utils.Query;
import com.bookstore.bookmall.product.dao.AttrDao;
import com.bookstore.bookmall.product.entity.AttrEntity;
import com.bookstore.bookmall.product.service.AttrService;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service("attrService")
public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements AttrService {
@Autowired
AttrAttrgroupRelationDao RelationDao;
@Autowired
CategoryDao categoryDao;
@Autowired
AttrGroupDao attrGroupDao;
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<AttrEntity> page = this.page(
@ -26,4 +54,64 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
return new PageUtils(page);
}
@Transactional
@Override
public void saveAttr(AttrVo attr) {
AttrEntity attrEntity = new AttrEntity();
BeanUtils.copyProperties(attr, attrEntity); //复制属性,将attr复制到attrEntity前提是属性名一一对应
//保存基本数据
this.save(attrEntity);
//2、保存关联关系
AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity();
RelationEntity.setAttrGroupId(attr.getAttrGroupId());
RelationEntity.setAttrId(attr.getAttrId());
RelationDao.insert(RelationEntity);
}
//后台管理,查询基本内容和关联分组和关联属性
@Override
public PageUtils queryBasePage(Map<String, Object> params, Long cateLogId) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>();
if (cateLogId != 0) {
wrapper.eq("catelog_id", cateLogId);
}
String key = (String)params.get("key");
if (!StringUtils.isNullOrEmpty(key)) {
wrapper.eq("attr_id", key).or().like("attr_name", key);
}
IPage<AttrEntity> page = this.page(
new Query<AttrEntity>().getPage(params),
wrapper
);
PageUtils pageUtils = new PageUtils(page);
List<AttrEntity> records = (List<AttrEntity>) pageUtils.getList();
List<AttrRespVo> respVos = records.stream().map((attrEntity) -> {
//拷贝基本属性
AttrRespVo attrRespVo = new AttrRespVo();
BeanUtils.copyProperties(attrEntity, attrRespVo);
//设置分组名字和分类名字
//在分组关系中查找id
AttrAttrgroupRelationEntity relationEntity = RelationDao.selectOne(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrEntity.getAttrId()));
if (relationEntity!=null) {
// log.info("查询到relation");
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(relationEntity.getAttrGroupId());
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
// log.info(attrGroupEntity.getAttrGroupName());
}
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
if (categoryEntity!=null) {
// log.info("查询到categoryEntity");
attrRespVo.setCatelogName(categoryEntity.getName());
// log.info(categoryEntity.getName());
}
return attrRespVo;
}).collect(Collectors.toList());
pageUtils.setList(respVos);
return pageUtils;
}
}

@ -0,0 +1,13 @@
package com.bookstore.bookmall.product.vo;
import lombok.Data;
@Data
public class AttrRespVo extends AttrVo{
//cateLogName 所属分类名字
//groupName 所属分组名字
private String catelogName;
private String groupName;
}

@ -0,0 +1,51 @@
package com.bookstore.bookmall.product.vo;
import lombok.Data;
@Data
public class AttrVo {
/**
* id
*/
private Long attrId;
/**
*
*/
private String attrName;
/**
* [0-1-]
*/
private Integer searchType;
/**
* [0-1-]
*/
private Integer valueType;
/**
*
*/
private String icon;
/**
* []
*/
private String valueSelect;
/**
* [0-1-2-]
*/
private Integer attrType;
/**
* [0 - 1 - ]
*/
private Long enable;
/**
*
*/
private Long catelogId;
/**
* 0- 1-sku
*/
private Integer showDesc;
private Long attrGroupId;
}
Loading…
Cancel
Save