后台系统销售属性

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

@ -21,9 +21,12 @@ public interface AttrService extends IService<AttrEntity> {
void saveAttr(AttrVo attr); 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); AttrRespVo getAttrInfo(Long attrId);
void updateAttr(AttrVo attrVo);
} }

@ -1,14 +1,13 @@
package com.bookstore.bookmall.product.service.impl; package com.bookstore.bookmall.product.service.impl;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; import com.bookstore.bookmall.product.constant.ProductConstant;
import com.bookstore.bookmall.product.dao.AttrAttrgroupRelationDao; import com.bookstore.bookmall.product.dao.AttrAttrgroupRelationDao;
import com.bookstore.bookmall.product.dao.AttrGroupDao; import com.bookstore.bookmall.product.dao.AttrGroupDao;
import com.bookstore.bookmall.product.dao.CategoryDao; import com.bookstore.bookmall.product.dao.CategoryDao;
import com.bookstore.bookmall.product.entity.AttrAttrgroupRelationEntity; import com.bookstore.bookmall.product.entity.AttrAttrgroupRelationEntity;
import com.bookstore.bookmall.product.entity.AttrGroupEntity; import com.bookstore.bookmall.product.entity.AttrGroupEntity;
import com.bookstore.bookmall.product.entity.CategoryEntity; 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.service.CategoryService;
import com.bookstore.bookmall.product.vo.AttrRespVo; import com.bookstore.bookmall.product.vo.AttrRespVo;
import com.bookstore.bookmall.product.vo.AttrVo; import com.bookstore.bookmall.product.vo.AttrVo;
@ -16,7 +15,6 @@ import com.mysql.cj.util.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -65,18 +63,21 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
//保存基本数据 //保存基本数据
this.save(attrEntity); this.save(attrEntity);
//2、保存关联关系 //2、保存关联关系
if (attr.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity(); AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity();
RelationEntity.setAttrGroupId(attr.getAttrGroupId()); RelationEntity.setAttrGroupId(attr.getAttrGroupId());
RelationEntity.setAttrId(attr.getAttrId()); RelationEntity.setAttrId(attr.getAttrId());
RelationDao.insert(RelationEntity); RelationDao.insert(RelationEntity);
} }
}
//后台管理,查询基本内容和关联分组和关联属性 //后台管理,查询基本内容和关联分组和关联属性
@Override @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>(); QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>();
if (cateLogId != 0) { 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"); String key = (String)params.get("key");
if (!StringUtils.isNullOrEmpty(key)) { if (!StringUtils.isNullOrEmpty(key)) {
@ -94,6 +95,7 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
BeanUtils.copyProperties(attrEntity, attrRespVo); BeanUtils.copyProperties(attrEntity, attrRespVo);
//设置分组名字和分类名字 //设置分组名字和分类名字
//在分组关系中查找id //在分组关系中查找id
if ("base".equalsIgnoreCase(attrType)) {
AttrAttrgroupRelationEntity relationEntity = RelationDao.selectOne( AttrAttrgroupRelationEntity relationEntity = RelationDao.selectOne(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrEntity.getAttrId())); new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrEntity.getAttrId()));
if (relationEntity!=null) { if (relationEntity!=null) {
@ -102,6 +104,8 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName()); attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
// log.info(attrGroupEntity.getAttrGroupName()); // log.info(attrGroupEntity.getAttrGroupName());
} }
}
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId()); CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
if (categoryEntity!=null) { if (categoryEntity!=null) {
// log.info("查询到categoryEntity"); // log.info("查询到categoryEntity");
@ -122,6 +126,8 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
AttrRespVo respVo = new AttrRespVo(); AttrRespVo respVo = new AttrRespVo();
AttrEntity attrEntity = this.getById(attrId); AttrEntity attrEntity = this.getById(attrId);
//如果是base
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
//设置分组id //设置分组id
BeanUtils.copyProperties(attrEntity, respVo); BeanUtils.copyProperties(attrEntity, respVo);
// log.info("beanutilzhengchang"); // log.info("beanutilzhengchang");
@ -136,6 +142,8 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
respVo.setGroupName(attrGroupEntity.getAttrGroupName()); respVo.setGroupName(attrGroupEntity.getAttrGroupName());
} }
} }
}
// log.info("设置分组"); // log.info("设置分组");
//设置分类信息 //设置分类信息
Long catelogId = attrEntity.getCatelogId(); Long catelogId = attrEntity.getCatelogId();
@ -149,5 +157,32 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
return respVo; 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