提交 69a0a048 authored 作者: 吴德鹏's avatar 吴德鹏

属性管理

上级 59aa44e2
......@@ -276,18 +276,55 @@ public class AttributesController {
// });
//===================================================================================================
//查询商品的属性
// //属性值
// List<String> names = paramList.stream().filter(t -> StringUtils.isBlank(t.getAttrId())).map(TbCfItemParamEntity::getParamName).collect(Collectors.toList());
// //所有的属性
// List<AttributesEntity> allAttributes = attributesService.queryList(null);
// //属性值
// List<String> list = allAttributes.stream().map(AttributesEntity::getAttrName).collect(Collectors.toList());
// //所有属性与商品属性的差集
// List<String> collect = list.stream().filter(attr -> !names.contains(attr)).collect(Collectors.toList());
// collect.forEach(c -> {
// //追加新的属性
// AttributesEntity attributes = attributesService.queryByAttrName(c);
// TbCfItemParamEntity param = new TbCfItemParamEntity();
// param.setParamName(attributes.getAttrName());
// param.setAttrId(attributes.getId());
// paramList.add(param);
// });
List<TbCfItemParamEntity> paramList = itemParamService.queryParamByItemId(itemId);
List<String> names = paramList.stream()/*.filter(t -> StringUtils.isBlank(t.getAttrId()))*/.map(TbCfItemParamEntity::getParamName).collect(Collectors.toList());
List<AttributesEntity> allAttributes = attributesService.queryList(null);
List<String> list = allAttributes.stream().map(AttributesEntity::getAttrName).collect(Collectors.toList());
List<String> collect = list.stream().filter(attr -> !names.contains(attr)).collect(Collectors.toList());
collect.forEach(c -> {
AttributesEntity attributes = attributesService.queryByAttrName(c);
TbCfItemParamEntity param = new TbCfItemParamEntity();
param.setParamName(attributes.getAttrName());
param.setAttrId(attributes.getId());
paramList.add(param);
paramList.forEach(param -> {
AttributesEntity attr = attributesService.queryObject(param.getAttrId());
if (attr != null) {
param.setAttrId(attr.getId());
param.setParamName(attr.getAttrName());
if (!StringUtils.isBlank(param.getAttrDescId())) {
String[] arr = param.getAttrDescId().split(",");
List<AttributesDescEntity> descEntities = attributesDescService.queryDescByIds(arr);
List<AttributesDescVo> list = new ArrayList<>();
descEntities.forEach(desc -> {
AttributesDescVo attVo = new AttributesDescVo();
param.setAttrDescId(desc.getAttrDescId());
String value = desc.getAttrValue();
attVo.setAttrDescId(desc.getAttrDescId());
if (!StringUtils.isBlank(desc.getAttrDesc())) {
value = value + "(" + desc.getAttrDesc() + ")";
}
attVo.setAttrValue(value);
list.add(attVo);
});
param.setList(list);
}
}
});
paramList.forEach(p -> {
p.setParamName(null);
p.setParamValue(null);
});
return R.ok().put("list", paramList);
......
......@@ -14,5 +14,7 @@ public interface AttributesDescDao extends BaseDao<AttributesDescEntity> {
List<AttributesDescEntity> queryByAttrId(String id);
List<AttributesDescEntity> queryDescByIds(String[] ids);
}
package com.platform.entity;
import com.platform.vo.AttributesDescVo;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 商品参数实体
......@@ -46,6 +49,16 @@ public class TbCfItemParamEntity implements Serializable {
*/
private String attrDescId;
private List<AttributesDescVo> list;
public List<AttributesDescVo> getList() {
return list;
}
public void setList(List<AttributesDescVo> list) {
this.list = list;
}
/**
* 设置:商品参数ID
*/
......
......@@ -70,4 +70,6 @@ public interface AttributesDescService {
int deleteBatch(String[] attrDescIds);
List<AttributesDescEntity> queryByAttrId(String id);
List<AttributesDescEntity> queryDescByIds(String[] ids);
}
......@@ -73,4 +73,6 @@ public interface AttributesService {
List<AttributesExtends> queryAttributesList(Map<String, Object> map);
AttributesEntity queryByAttrName(String name);
}
......@@ -61,4 +61,9 @@ public class AttributesDescServiceImpl implements AttributesDescService {
public List<AttributesDescEntity> queryByAttrId(String id) {
return attributesDescDao.queryByAttrId(id);
}
@Override
public List<AttributesDescEntity> queryDescByIds(String[] ids) {
return attributesDescDao.queryDescByIds(ids);
}
}
......@@ -13,7 +13,7 @@
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.AttributesDescEntity">
<select id="queryObject" resultType="com.platform.entity.AttributesDescEntity">
select
`attr_desc_id`,
`attr_id`,
......@@ -26,7 +26,23 @@
where attr_desc_id = #{id}
</select>
<select id="queryByAttrId" resultType="com.platform.entity.AttributesDescEntity">
<select id="queryDescByIds" resultType="com.platform.entity.AttributesDescEntity">
select
`attr_desc_id`,
`attr_id`,
`attr_value`,
`attr_desc`,
`status`,
`create_time`,
`update_time`
from attributes_desc
where attr_desc_id in
<foreach item="attrDescId" collection="array" open="(" separator="," close=")">
#{attrDescId}
</foreach>
</select>
<select id="queryByAttrId" resultType="com.platform.entity.AttributesDescEntity">
select
`attr_desc_id`,
`attr_id`,
......@@ -39,42 +55,42 @@
where attr_id = #{id}
</select>
<select id="queryList" resultType="com.platform.entity.AttributesDescEntity">
select
`attr_desc_id`,
`attr_id`,
`attr_value`,
`attr_desc`,
`status`,
`create_time`,
`update_time`
from attributes_desc
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<select id="queryList" resultType="com.platform.entity.AttributesDescEntity">
select
`attr_desc_id`,
`attr_id`,
`attr_value`,
`attr_desc`,
`status`,
`create_time`,
`update_time`
from attributes_desc
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
<otherwise>
order by attr_desc_id desc
</otherwise>
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from attributes_desc
WHERE 1=1
<select id="queryTotal" resultType="int">
select count(*) from attributes_desc
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
</select>
<insert id="save" parameterType="com.platform.entity.AttributesDescEntity">
<insert id="save" parameterType="com.platform.entity.AttributesDescEntity">
insert into attributes_desc(
`attr_desc_id`,
`attr_id`,
......@@ -93,28 +109,28 @@
#{updateTime})
</insert>
<update id="update" parameterType="com.platform.entity.AttributesDescEntity">
update attributes_desc
<set>
<if test="attrId != null">`attr_id` = #{attrId}, </if>
<if test="attrValue != null">`attr_value` = #{attrValue}, </if>
<if test="attrDesc != null">`attr_desc` = #{attrDesc}, </if>
<if test="status != null">`status` = #{status}, </if>
<if test="createTime != null">`create_time` = #{createTime}, </if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where attr_desc_id = #{attrDescId}
</update>
<update id="update" parameterType="com.platform.entity.AttributesDescEntity">
update attributes_desc
<set>
<if test="attrId != null">`attr_id` = #{attrId},</if>
<if test="attrValue != null">`attr_value` = #{attrValue},</if>
<if test="attrDesc != null">`attr_desc` = #{attrDesc},</if>
<if test="status != null">`status` = #{status},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where attr_desc_id = #{attrDescId}
</update>
<delete id="delete">
<delete id="delete">
delete from attributes_desc where attr_desc_id = #{value}
</delete>
<delete id="deleteBatch">
delete from attributes_desc where attr_desc_id in
<foreach item="attrDescId" collection="array" open="(" separator="," close=")">
#{attrDescId}
</foreach>
</delete>
<delete id="deleteBatch">
delete from attributes_desc where attr_desc_id in
<foreach item="attrDescId" collection="array" open="(" separator="," close=")">
#{attrDescId}
</foreach>
</delete>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论