后台系统销售属性

develop
ddyd 2 weeks ago
parent 708a4954bd
commit b7de4e50d0

@ -0,0 +1,24 @@
package com.bookstore.bookmall.product.constant;
public class ProductConstant {
public enum AttrEnum{
ATTR_TYPE_SALE(0, "销售属性"), ATTR_TYPE_BASE(1,"基本属性");
private int code;
private String msg;
AttrEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
}

@ -30,22 +30,23 @@ public class AttrController {
private AttrService attrService;
// /product/attr/base/list/{catelogId}
@GetMapping("/base/list/{catelogId}")
@GetMapping("/{attrType}/list/{catelogId}")
public R baseAttrList(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long cateLogId) {
PageUtils page = attrService.queryBasePage(params, cateLogId);
@PathVariable("catelogId") Long cateLogId,
@PathVariable("attrType") String attrType) {
PageUtils page = attrService.queryBasePage(params, cateLogId, attrType);
return R.ok().put("page", page);
}
/**
*
*/
@RequestMapping("/list/{catelogId}")
//@RequiresPermissions("product:attr:list")
public R list(@RequestParam Map<String, Object> params){
public R list(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long catelogId){
PageUtils page = attrService.queryPage(params);
return R.ok().put("page", page);
@ -81,8 +82,8 @@ public class AttrController {
*/
@RequestMapping("/update")
//@RequiresPermissions("product:attr:update")
public R update(@RequestBody AttrEntity attr){
attrService.updateById(attr);
public R update(@RequestBody AttrVo attrVo){
attrService.updateAttr(attrVo);
return R.ok();
}

@ -21,9 +21,12 @@ public interface AttrService extends IService<AttrEntity> {
void saveAttr(AttrVo attr);
PageUtils queryBasePage(Map<String, Object> params, Long cateLogId);
PageUtils queryBasePage(Map<String, Object> params, Long cateLogId, String attrType);
AttrRespVo getAttrInfo(Long attrId);
void updateAttr(AttrVo attrVo);
}

@ -1,14 +1,13 @@
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.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bookstore.bookmall.product.constant.ProductConstant;
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.service.CategoryService;
import com.bookstore.bookmall.product.vo.AttrRespVo;
import com.bookstore.bookmall.product.vo.AttrVo;
@ -16,7 +15,6 @@ 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;
@ -65,18 +63,21 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
//保存基本数据
this.save(attrEntity);
//2、保存关联关系
AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity();
RelationEntity.setAttrGroupId(attr.getAttrGroupId());
RelationEntity.setAttrId(attr.getAttrId());
RelationDao.insert(RelationEntity);
if (attr.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
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) {
public PageUtils queryBasePage(Map<String, Object> params, Long cateLogId, String attrType) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>();
if (cateLogId != 0) {
wrapper.eq("catelog_id", cateLogId);
wrapper.eq("catelog_id", cateLogId).eq("attr_name", "base".equalsIgnoreCase(attrType)?1:0);
}
String key = (String)params.get("key");
if (!StringUtils.isNullOrEmpty(key)) {
@ -94,14 +95,17 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
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());
}
if ("base".equalsIgnoreCase(attrType)) {
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");
@ -122,20 +126,24 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
AttrRespVo respVo = new AttrRespVo();
AttrEntity attrEntity = this.getById(attrId);
//设置分组id
BeanUtils.copyProperties(attrEntity, respVo);
//如果是base
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
//设置分组id
BeanUtils.copyProperties(attrEntity, respVo);
// log.info("beanutilzhengchang");
AttrAttrgroupRelationEntity RelationEntity = RelationDao.selectOne(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrId));
AttrAttrgroupRelationEntity RelationEntity = RelationDao.selectOne(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrId));
if (RelationEntity!=null) {
if (RelationEntity!=null) {
// log.info("查询属性relation正常");
respVo.setAttrGroupId(RelationEntity.getAttrGroupId());
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(RelationEntity.getAttrGroupId());
if (attrGroupEntity!=null) {
respVo.setGroupName(attrGroupEntity.getAttrGroupName());
respVo.setAttrGroupId(RelationEntity.getAttrGroupId());
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(RelationEntity.getAttrGroupId());
if (attrGroupEntity!=null) {
respVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
}
}
// log.info("设置分组");
//设置分类信息
Long catelogId = attrEntity.getCatelogId();
@ -149,5 +157,32 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
return respVo;
}
@Transactional
@Override
public void updateAttr(AttrVo attrVo) {
//保存基本属性
AttrEntity attrEntity = new AttrEntity();
BeanUtils.copyProperties(attrVo, attrEntity);
this.updateById(attrEntity);
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
relationEntity.setAttrGroupId(attrVo.getAttrGroupId());
relationEntity.setAttrId(attrVo.getAttrId());
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
//如果一开始就没有分组属性,实际要做的就是新增操作,所以这里还要进行判断
Long count = RelationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrVo.getAttrId()));
if (count > 0) {
//修改关联属性
RelationDao.update(relationEntity, new UpdateWrapper<AttrAttrgroupRelationEntity>().eq(
"attr_id", attrVo.getAttrId()
));
} else {
RelationDao.insert(relationEntity);
}
}
}
}
Loading…
Cancel
Save