提交 392ebc17 authored 作者: 吴德鹏's avatar 吴德鹏

属性管理

上级 a7ca695b
......@@ -146,10 +146,21 @@ public class AttributesController {
LinkedList<AttributesVo> attrNameList = new LinkedList<>();
List<AttributesEntity> list = attributesService.queryList(null);
list.forEach(attr -> {
List<String> attrDescList = new ArrayList<>();
AttributesVo attrNames = new AttributesVo();
attrNames.setId(attr.getId());
attrNames.setAttrName(attr.getAttrName());
List<AttributesDescEntity> descs = attributesDescService.queryByAttrId(attr.getId());
descs.forEach(desc -> {
String attrValue = desc.getAttrValue();
String attrDesc = desc.getAttrDesc();
attrDescList.add(attrValue + "(" + attrDesc + ")");
});
attrNames.setDescList(attrDescList);
attrNameList.add(attrNames);
});
return R.ok().put("list", attrNameList);
}
......@@ -157,35 +168,27 @@ public class AttributesController {
/**
* 属性值
*
* @param id 属性Id
* @param attrDesc 搜索关键字 如(l)
* @return url(../attributes/queryAttrDescs?id=2&attrDesc=l)
* @param id 属性Id
* @return url(../attributes/queryAttrDescs?id=2)
*/
// @RequestMapping("/queryAttrDescs")
// @ResponseBody
// @IgnoreAuth
// public R queryAttrDescs(@RequestParam("id") String id,
// @RequestParam(value = "attrDesc", required = false) String attrDesc) {
// if (StringUtils.isBlank(id)) {
// return R.error("id不能为空!");
// }
// AttributesEntity attributes = attributesService.queryObject(id);
// List<String> list = new ArrayList<>();
// if (attributes != null) {
// String[] descs = attributes.getAttrDesc().split(",");
// list = Arrays.asList(descs);
// list = list.stream().sorted(String::compareTo).collect(Collectors.toList());
// }
//
// if (attrDesc != null && list.size() > 0 && list != null) {
// /*for (String attr : list) {
// if (attr.indexOf(attrDesc) <= -1)
// list.remove(attr);
// }*/
// list = list.stream().filter(attr -> attr.indexOf(attrDesc) > -1).collect(Collectors.toList());
// }
// return R.ok().put("list", list);
// }
@RequestMapping("/queryAttrDescs")
@ResponseBody
@IgnoreAuth
public R queryAttrDescs(@RequestParam("id") String id) {
if (StringUtils.isBlank(id)) {
return R.error("id不能为空!");
}
List<String> attrDescList = new ArrayList<>();
List<AttributesDescEntity> descs = attributesDescService.queryByAttrId(id);
descs.forEach(desc -> {
String attrValue = desc.getAttrValue();
String attrDesc = desc.getAttrDesc();
attrDescList.add(attrValue + "(" + attrDesc + ")");
});
return R.ok().put("list", attrDescList);
}
/**
* 新版商品属性(整合旧版数据)
......
......@@ -74,8 +74,17 @@ public class AttributesServiceImpl implements AttributesService {
int res = attributesDao.update(attributes);
List<AttributesDescEntity> descs = attributes.getDescs();
descs.forEach(attr -> {
attr.setUpdateTime(date);
attributesDescDao.update(attr);
if (attr.getAttrId() != null || !attr.getAttrId().isEmpty()) {
attr.setUpdateTime(date);
attributesDescDao.update(attr);
} else {
attr.setAttrDescId(IdUtil.createIdbyUUID());
attr.setAttrId(attributes.getId());
attr.setStatus(1);
attr.setCreateTime(date);
attr.setUpdateTime(date);
attributesDescDao.save(attr);
}
});
return res;
......
......@@ -2,6 +2,8 @@ package com.platform.vo;
import lombok.Data;
import java.util.List;
/**
* @Auther: wudepeng
* @Date: 2020/12/18
......@@ -11,4 +13,5 @@ import lombok.Data;
public class AttributesVo {
private String id;
private String attrName;
private List<String> descList;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论