1、属性分组关联操作crud实现

2、销售属性功能及页面实现
pull/254/head
xjs 4 years ago
parent 8b697a5d0e
commit d75497c7bc

@ -3,9 +3,9 @@ import request from '@/utils/request'
// 获取品牌分组分页数据 // 获取品牌分组分页数据
export function getAttrGroupList(data) { export function getAttrGroupList(data) {
return request({ return request({
url: '/mall-product/product/attrgroup/list/'+data.catelogId, url: '/mall-product/product/attrgroup/list/' + data.catelogId,
method: 'get', method: 'get',
params:data params: data
}) })
} }
@ -22,7 +22,7 @@ export function addAttrGroup(data) {
return request({ return request({
url: `/mall-product/product/attrgroup/save`, url: `/mall-product/product/attrgroup/save`,
method: 'post', method: 'post',
data:data data: data
}) })
} }
@ -31,7 +31,7 @@ export function editAttrGroup(data) {
return request({ return request({
url: `/mall-product/product/attrgroup/update`, url: `/mall-product/product/attrgroup/update`,
method: 'put', method: 'put',
data:data data: data
}) })
} }
@ -40,6 +40,38 @@ export function delAttrGroup(ids) {
return request({ return request({
url: '/mall-product/product/attrgroup/delete', url: '/mall-product/product/attrgroup/delete',
method: 'delete', method: 'delete',
data: ids
})
}
// 获取属性分组关联规格参数
export function attrRelation(attrgroupId) {
return request({
url: `/mall-product/product/attrgroup/${attrgroupId}/attr/relation`,
method: 'get',
})
}
//获取当前分组没有关联的所有属性
export function attrNoRelation(attrgroupId,parms) {
return request({
url: `/mall-product/product/attrgroup/${attrgroupId}/noattr/relation`,
method: 'get',
parms:parms
})
}
//批量保存属性和属性分组关联信息
export function addRelation(ids) {
return request({
url: `/mall-product/product/attrgroup/attr/relation`,
method: 'post',
data:ids data:ids
}) })
} }

@ -19,9 +19,9 @@ export function editAttr(data) {
} }
// 分页获取规格参数 // 分页获取规格参数
export function getBaseAttrList(parms,catelogId) { export function getBaseAttrList(parms,catelogId,attrType) {
return request({ return request({
url: `/mall-product/product/attr/base/list/${catelogId}`, url: `/mall-product/product/attr/${attrType}/list/${catelogId}`,
method: 'get', method: 'get',
params:parms params:parms
}) })
@ -43,3 +43,13 @@ export function getAttr(attrId) {
method: 'get', method: 'get',
}) })
} }
// 删除属性及分组关联
export function deleteRelation(ids) {
return request({
url: `/mall-product/product/attr/relation/delete`,
method: 'delete',
data:ids
})
}

@ -52,9 +52,9 @@
<el-row :gutter="15"> <el-row :gutter="15">
<el-form size="medium" label-width="100px" :rules="linkRules" ref="linkRules" :model="requestData"> <el-form size="medium" label-width="100px" :rules="linkRules" ref="linkRules" :model="requestData">
<el-col :span="7"> <el-col :span="12">
<el-form-item prop="link" label="链接"> <el-form-item prop="link" label="链接">
<el-input v-model="requestData.link" placeholder="请输入下载图片链接" :maxlength="200" clearable <el-input v-model="requestData.link" placeholder="请复制微信文章链接地址" :maxlength="200" clearable
prefix-icon='el-icon-s-tools' :style="{width: '100%'}"></el-input> prefix-icon='el-icon-s-tools' :style="{width: '100%'}"></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -84,7 +84,7 @@ export default {
rules: { rules: {
path: [ path: [
{required: true, message: '请输入下载图片路径路径', trigger: 'blur'} {required: true, message: '请复制微信文章链接地址', trigger: 'blur'}
], ],
}, },
linkRules: { linkRules: {

@ -12,8 +12,8 @@
</el-form-item> </el-form-item>
<el-form-item label="属性类型" prop="attrType"> <el-form-item label="属性类型" prop="attrType">
<el-select v-model="dataForm.attrType" placeholder="请选择"> <el-select v-model="dataForm.attrType" placeholder="请选择">
<el-option label="规格参数" :value="1"></el-option> <el-option label="规格参数" :value="1" v-if="dataForm.attrType===1"></el-option>
<el-option label="销售属性" :value="0"></el-option> <el-option label="销售属性" :value="0" v-if="dataForm.attrType===0"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>

@ -0,0 +1,228 @@
<template>
<div>
<el-dialog :close-on-click-modal="false" :visible.sync="visible" @closed="dialogClose">
<el-dialog width="40%" title="选择属性" :visible.sync="innerVisible" append-to-body>
<div>
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.key" placeholder="请输入属性名、可选值等" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()"></el-button>
</el-form-item>
</el-form>
<el-table
:data="dataList"
border
v-loading="dataListLoading"
@selection-change="innerSelectionChangeHandle"
style="width: 100%;"
>
<el-table-column type="selection" header-align="center" align="center"></el-table-column>
<el-table-column prop="attrName" header-align="center" align="center" label="属性名"></el-table-column>
<el-table-column prop="icon" header-align="center" align="center" label="属性图标">
<template slot-scope="scope">
<svg-icon :icon-class="scope.row.icon"/>
</template>
</el-table-column>
<el-table-column prop="valueSelect" header-align="center" align="center" label="可选值列表">
<template slot-scope="scope">
<el-tooltip placement="left">
<div slot="content">
<span v-for="(i,index) in scope.row.valueSelect.split(';')" :key="index">{{ i }}<br/></span>
</div>
<el-tag>{{ scope.row.valueSelect.split(";")[0] + " ..." }}</el-tag>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper"
></el-pagination>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="innerVisible = false"> </el-button>
<el-button type="primary" @click="submitAddRealtion"></el-button>
</div>
</el-dialog>
<el-row>
<el-col :span="24">
<el-button-group style="margin-bottom: 10px">
<el-button type="primary" size="mini" @click="addRelation"></el-button>
<el-button
type="danger"
size="mini"
@click="batchDeleteRelation"
:disabled="dataListSelections.length <= 0"
>批量删除</el-button>
</el-button-group>
<el-table
:data="relationAttrs"
style="width: 100%"
@selection-change="selectionChangeHandle"
border
>
<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
<el-table-column prop="attrName" label="属性名"></el-table-column>
<el-table-column prop="valueSelect" label="可选值">
<template slot-scope="scope">
<el-tooltip placement="top">
<div slot="content">
<span v-for="(i,index) in scope.row.valueSelect.split(';')" :key="index">
{{i}}
<br />
</span>
</div>
<el-tag>{{scope.row.valueSelect.split(";")[0]+" ..."}}</el-tag>
</el-tooltip>
</template>
</el-table-column>
<el-table-column fixed="right" header-align="center" align="center" label="操作">
<template slot-scope="scope">
<el-button type="text" size="small" @click="relationRemove(scope.row.attrId)"></el-button>
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
</el-dialog>
</div>
</template>
<script>
import {addRelation, attrNoRelation, attrRelation} from "@/api/mall/product/attr-group";
import {deleteRelation} from "@/api/mall/product/attr";
export default {
components: {},
props: {},
data() {
//
return {
attrGroupId: 0,
visible: false,
innerVisible: false,
relationAttrs: [],
dataListSelections: [],
dataForm: {
key: ""
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
innerdataListSelections: []
};
},
computed: {},
//data
watch: {},
//
methods: {
selectionChangeHandle(val) {
this.dataListSelections = val;
},
innerSelectionChangeHandle(val) {
this.innerdataListSelections = val;
},
addRelation() {
this.getDataList();
this.innerVisible = true;
},
//
batchDeleteRelation(val) {
let postData = [];
this.dataListSelections.forEach(item => {
postData.push({ attrId: item.attrId, attrGroupId: this.attrGroupId });
});
this.deleteRelation(postData)
},
//
relationRemove(attrId) {
let data = [];
data.push({ attrId, attrGroupId: this.attrGroupId });
this.deleteRelation(data)
},
//
deleteRelation(ids) {
deleteRelation(ids).then(res =>{
this.$modal.notifySuccess("删除成功")
this.init(this.attrGroupId);
})
},
//
submitAddRealtion() {
this.innerVisible = false;
//
if (this.innerdataListSelections.length > 0) {
let postData = [];
this.innerdataListSelections.forEach(item => {
postData.push({ attrId: item.attrId, attrGroupId: this.attrGroupId });
});
addRelation(postData).then(res =>{
this.$modal.notifySuccess("新增关联成功")
this.$emit("refreshData");
this.init(this.attrGroupId);
})
}
},
init(id) {
this.attrGroupId = id || 0;
this.visible = true;
attrRelation(this.attrGroupId).then(res =>{
this.relationAttrs = res.data;
})
},
dialogClose() {},
//
getDataList() {
this.dataListLoading = true;
let params ={
page: this.pageIndex,
limit: this.pageSize,
key: this.dataForm.key
}
attrNoRelation(this.attrGroupId,params).then(res =>{
this.dataList = res.page.list;
this.totalPage = res.page.totalCount;
this.dataListLoading = false;
})
},
//
sizeChangeHandle(val) {
this.pageSize = val;
this.pageIndex = 1;
this.getDataList();
},
//
currentChangeHandle(val) {
this.pageIndex = val;
this.getDataList();
}
}
};
</script>
<style scoped>
</style>

@ -42,7 +42,7 @@
<el-table-column prop="descript" header-align="center" align="center" label="描述"></el-table-column> <el-table-column prop="descript" header-align="center" align="center" label="描述"></el-table-column>
<el-table-column prop="icon" header-align="center" align="center" label="组图标"> <el-table-column prop="icon" header-align="center" align="center" label="组图标">
<template slot-scope="scope"> <template slot-scope="scope">
<svg-icon :icon-class="scope.row.icon" /> <svg-icon :icon-class="scope.row.icon"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="catelogId" header-align="center" align="center" label="分类ID"></el-table-column> <el-table-column prop="catelogId" header-align="center" align="center" label="分类ID"></el-table-column>
@ -78,7 +78,7 @@
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
<!-- 修改关联关系 --> <!-- 修改关联关系 -->
<!-- <relation-update v-if="relationVisible" ref="relationUpdate" @refreshData="getDataList"></relation-update>--> <relation-update v-if="relationVisible" ref="relationUpdate" @refreshData="getDataList"></relation-update>
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
@ -98,10 +98,10 @@ import Category from '../../../components/mall/category'
import {getAttrGroupList, delAttrGroup} from "@/api/mall/product/attr-group"; import {getAttrGroupList, delAttrGroup} from "@/api/mall/product/attr-group";
import AddOrUpdate from "./attrgroup-add-or-update"; import AddOrUpdate from "./attrgroup-add-or-update";
// import RelationUpdate from "./attr-group-relation"; import RelationUpdate from "./attr-group-relation";
export default { export default {
components: {Category, AddOrUpdate, /*RelationUpdate*/}, components: {Category, AddOrUpdate, RelationUpdate},
props: {}, props: {},
data() { data() {
return { return {

@ -58,12 +58,12 @@
</el-table-column> </el-table-column>
<el-table-column prop="icon" header-align="center" align="center" label="图标"> <el-table-column prop="icon" header-align="center" align="center" label="图标">
<template slot-scope="scope"> <template slot-scope="scope">
<svg-icon :icon-class="scope.row.icon" /> <svg-icon :icon-class="scope.row.icon"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="valueSelect" header-align="center" align="center" label="可选值"> <el-table-column prop="valueSelect" header-align="center" align="center" label="可选值">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tooltip placement="top"> <el-tooltip placement="left">
<div slot="content"> <div slot="content">
<span v-for="(i,index) in scope.row.valueSelect.split(';')" :key="index">{{ i }}<br/></span> <span v-for="(i,index) in scope.row.valueSelect.split(';')" :key="index">{{ i }}<br/></span>
</div> </div>
@ -180,10 +180,16 @@ export default {
key: this.dataForm.key key: this.dataForm.key
} }
if (this.attrtype === 0) { if (this.attrtype === 0) {
// todo sale let type = "sale"
getBaseAttrList(params, this.catId, type).then(res => {
this.dataList = res.page.list;
this.totalPage = res.page.totalCount;
this.dataListLoading = false;
})
} else { } else if (this.attrtype === 1) {
getBaseAttrList(params, this.catId).then(res => { let type = "base"
getBaseAttrList(params, this.catId, type).then(res => {
this.dataList = res.page.list; this.dataList = res.page.list;
this.totalPage = res.page.totalCount; this.totalPage = res.page.totalCount;
this.dataListLoading = false; this.dataListLoading = false;

@ -0,0 +1,32 @@
<template>
<div>
<base-attr :attrtype="0"></base-attr>
</div>
</template>
<script>
import BaseAttr from './base-attr'
export default {
//import使
components: {BaseAttr},
props: {},
name:"sale-attr",
data() {
//
return {};
},
computed: {},
//data
watch: {},
//
methods: {},
created() {},
};
</script>
<style scoped>
</style>

@ -3,6 +3,7 @@ package com.xjs.mall.product.controller;
import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.xjs.mall.product.service.AttrService; import com.xjs.mall.product.service.AttrService;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo; import com.xjs.mall.product.vo.AttrResponseVo;
import com.xjs.mall.product.vo.AttrVo; import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils; import com.xjs.utils.PageUtils;
@ -16,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
@ -34,10 +36,21 @@ public class AttrController {
private AttrService attrService; private AttrService attrService;
@GetMapping("/base/list/{catelogId}") @DeleteMapping("relation/delete")
@ApiOperation("删除属性及分组关联")
public R deleteRelation(@RequestBody List<AttrGroupRelationVo> vos) {
attrService.deleteRelation(vos);
return R.ok();
}
@GetMapping("/{attrType}/list/{catelogId}")
@ApiOperation("列表") @ApiOperation("列表")
public R baseAttrList(@RequestParam Map<String, Object> params, @PathVariable("catelogId") Long catelogId) { public R baseAttrList(@RequestParam Map<String, Object> params,
PageUtils page = attrService.queryBaseAttrPage(params, catelogId); @PathVariable("attrType") String attrType,
@PathVariable("catelogId") Long catelogId) {
PageUtils page = attrService.queryBaseAttrPage(params, catelogId, attrType);
return R.ok().put("page", page); return R.ok().put("page", page);
} }

@ -2,9 +2,13 @@ package com.xjs.mall.product.controller;
import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.xjs.mall.product.entity.AttrEntity;
import com.xjs.mall.product.entity.AttrGroupEntity; import com.xjs.mall.product.entity.AttrGroupEntity;
import com.xjs.mall.product.service.AttrAttrgroupRelationService;
import com.xjs.mall.product.service.AttrGroupService; import com.xjs.mall.product.service.AttrGroupService;
import com.xjs.mall.product.service.AttrService;
import com.xjs.mall.product.service.CategoryService; import com.xjs.mall.product.service.CategoryService;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.utils.PageUtils; import com.xjs.utils.PageUtils;
import com.xjs.utils.R; import com.xjs.utils.R;
import com.xjs.validation.group.AddGroup; import com.xjs.validation.group.AddGroup;
@ -36,6 +40,41 @@ public class AttrGroupController {
private AttrGroupService attrGroupService; private AttrGroupService attrGroupService;
@Autowired @Autowired
private CategoryService categoryService; private CategoryService categoryService;
@Autowired
private AttrService attrService;
@Autowired
private AttrAttrgroupRelationService attrAttrgroupRelationService;
/**
*
*
* @param attrgroupId id
* @return r
*/
@GetMapping("/{attrgroupId}/attr/relation")
public R attrRelation(@PathVariable("attrgroupId") Long attrgroupId) {
List<AttrEntity> attrList = attrService.getRelationAttr(attrgroupId);
return R.ok().put("data", attrList);
}
/**
*
* @param attrgroupId id
* @param params
* @return R
*/
@GetMapping("/{attrgroupId}/noattr/relation")
public R attrNoRelation(@PathVariable("attrgroupId") Long attrgroupId, @RequestParam Map<String, Object> params) {
PageUtils page=attrService.getAttrNoRelation(params, attrgroupId);
return R.ok().put("page", page);
}
@PostMapping("/attr/relation")
public R addRelation(@RequestBody List<AttrGroupRelationVo> vos) {
attrAttrgroupRelationService.saveBatch(vos);
return R.ok();
}
/** /**
* *

@ -8,6 +8,7 @@ import com.xjs.validation.group.UpdateGroup;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -53,7 +54,7 @@ public class AttrGroupEntity implements Serializable {
/** /**
* id * id
*/ */
@NotBlank(message = "所属分类id不能为空", groups = {UpdateGroup.class, AddGroup.class}) @NotNull(message = "所属分类id不能为空", groups = {UpdateGroup.class, AddGroup.class})
private Long catelogId; private Long catelogId;
/** /**

@ -2,6 +2,9 @@ package com.xjs.mall.product.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity; import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import java.util.List;
/** /**
* & * &
@ -12,5 +15,10 @@ import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
*/ */
public interface AttrAttrgroupRelationService extends IService<AttrAttrgroupRelationEntity> { public interface AttrAttrgroupRelationService extends IService<AttrAttrgroupRelationEntity> {
/**
*
* @param vos ids
*/
void saveBatch(List<AttrGroupRelationVo> vos);
} }

@ -1,6 +1,7 @@
package com.xjs.mall.product.service; package com.xjs.mall.product.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo; import com.xjs.mall.product.vo.AttrResponseVo;
import com.xjs.mall.product.vo.AttrVo; import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils; import com.xjs.utils.PageUtils;
@ -20,20 +21,24 @@ public interface AttrService extends IService<AttrEntity> {
/** /**
* *
*
* @param attr vo * @param attr vo
*/ */
void saveAttr(AttrVo attr); void saveAttr(AttrVo attr);
/** /**
* *
* @param params *
* @param params
* @param catelogId id * @param catelogId id
* @param attrType base/sale
* @return pageUtils * @return pageUtils
*/ */
PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId); PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId, String attrType);
/** /**
* attr * attr
*
* @param attrId attrId * @param attrId attrId
* @return vo * @return vo
*/ */
@ -41,14 +46,37 @@ public interface AttrService extends IService<AttrEntity> {
/** /**
* *
*
* @param attr * @param attr
*/ */
void updateAttr(AttrVo attr); void updateAttr(AttrVo attr);
/** /**
* *
*
* @param asList ids * @param asList ids
*/ */
void removeAttr(List<Long> asList); void removeAttr(List<Long> asList);
/**
* id
* @param attrgroupId id
* @return attrs
*/
List<AttrEntity> getRelationAttr(Long attrgroupId);
/**
*
* @param vos id
*/
void deleteRelation(List<AttrGroupRelationVo> vos);
/**
*
* @param params
* @param attrgroupId id
* @return page
*/
PageUtils getAttrNoRelation(Map<String, Object> params, Long attrgroupId);
} }

@ -4,12 +4,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjs.mall.product.dao.AttrAttrgroupRelationDao; import com.xjs.mall.product.dao.AttrAttrgroupRelationDao;
import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity; import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
import com.xjs.mall.product.service.AttrAttrgroupRelationService; import com.xjs.mall.product.service.AttrAttrgroupRelationService;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service("attrAttrgroupRelationService") @Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService { public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {
@Override
public void saveBatch(List<AttrGroupRelationVo> vos) {
List<AttrAttrgroupRelationEntity> collect = vos.stream().map(item -> {
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
relationEntity.setAttrId(item.getAttrId());
relationEntity.setAttrGroupId(item.getAttrGroupId());
return relationEntity;
}).collect(Collectors.toList());
super.saveBatch(collect);
}
} }

@ -1,11 +1,12 @@
package com.xjs.mall.product.service.impl; package com.xjs.mall.product.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.xjs.consts.ProductConstant;
import com.xjs.mall.product.dao.AttrAttrgroupRelationDao; import com.xjs.mall.product.dao.AttrAttrgroupRelationDao;
import com.xjs.mall.product.dao.AttrDao; import com.xjs.mall.product.dao.AttrDao;
import com.xjs.mall.product.dao.AttrGroupDao; import com.xjs.mall.product.dao.AttrGroupDao;
@ -17,6 +18,7 @@ import com.xjs.mall.product.entity.CategoryEntity;
import com.xjs.mall.product.service.AttrAttrgroupRelationService; import com.xjs.mall.product.service.AttrAttrgroupRelationService;
import com.xjs.mall.product.service.AttrService; import com.xjs.mall.product.service.AttrService;
import com.xjs.mall.product.service.CategoryService; import com.xjs.mall.product.service.CategoryService;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo; import com.xjs.mall.product.vo.AttrResponseVo;
import com.xjs.mall.product.vo.AttrVo; import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils; import com.xjs.utils.PageUtils;
@ -27,11 +29,15 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.xjs.consts.ProductConstant.AttrEnum.ATTR_TYPE_BASE;
import static com.xjs.consts.ProductConstant.AttrEnum.ATTR_TYPE_SALE;
@Service("attrService") @Service("attrService")
@Transactional @Transactional
@ -56,15 +62,18 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
super.save(attrEntity); super.save(attrEntity);
//保存关联关系 //保存关联关系
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity(); if (attr.getAttrType() == ATTR_TYPE_BASE.getCode()) {
attrAttrgroupRelationEntity.setAttrGroupId(attr.getAttrGroupId()); AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId()); attrAttrgroupRelationEntity.setAttrGroupId(attr.getAttrGroupId());
attrAttrgroupRelationService.save(attrAttrgroupRelationEntity); attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId());
attrAttrgroupRelationService.save(attrAttrgroupRelationEntity);
}
} }
@Override @Override
public PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId) { public PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId, String attrType) {
LambdaQueryWrapper<AttrEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AttrEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AttrEntity::getAttrType, "base".equalsIgnoreCase(attrType) ? ATTR_TYPE_BASE.getCode() : ATTR_TYPE_SALE.getCode());
if (catelogId != 0) { if (catelogId != 0) {
wrapper.eq(AttrEntity::getCatelogId, catelogId); wrapper.eq(AttrEntity::getCatelogId, catelogId);
@ -87,12 +96,14 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
BeanUtils.copyProperties(attrEntity, attrResponseVo); BeanUtils.copyProperties(attrEntity, attrResponseVo);
//1、设置分类和分组的数据 //1、设置分类和分组的数据
AttrAttrgroupRelationEntity attrId = attrAttrgroupRelationDao.selectOne(new LambdaQueryWrapper<AttrAttrgroupRelationEntity>() if ("base".equalsIgnoreCase(attrType)) {
.eq(AttrAttrgroupRelationEntity::getAttrId, attrEntity.getAttrId())); AttrAttrgroupRelationEntity attrId = attrAttrgroupRelationDao.selectOne(new LambdaQueryWrapper<AttrAttrgroupRelationEntity>()
.eq(AttrAttrgroupRelationEntity::getAttrId, attrEntity.getAttrId()));
if (attrId != null) {
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrId.getAttrGroupId()); if (attrId != null) {
attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName()); AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrId.getAttrGroupId());
attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
} }
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId()); CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
@ -114,18 +125,19 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
AttrResponseVo attrResponseVo = new AttrResponseVo(); AttrResponseVo attrResponseVo = new AttrResponseVo();
BeanUtils.copyProperties(attrEntity, attrResponseVo); BeanUtils.copyProperties(attrEntity, attrResponseVo);
//设置分组信息 if (attrEntity.getAttrType() == ATTR_TYPE_BASE.getCode()) {
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationDao.selectOne( //设置分组信息
new LambdaQueryWrapper<AttrAttrgroupRelationEntity>().eq(AttrAttrgroupRelationEntity::getAttrId, attrId) AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationDao.selectOne(
); new LambdaQueryWrapper<AttrAttrgroupRelationEntity>().eq(AttrAttrgroupRelationEntity::getAttrId, attrId)
);
if (attrAttrgroupRelationEntity != null) { if (attrAttrgroupRelationEntity != null) {
attrResponseVo.setAttrGroupId(attrAttrgroupRelationEntity.getAttrGroupId()); attrResponseVo.setAttrGroupId(attrAttrgroupRelationEntity.getAttrGroupId());
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrAttrgroupRelationEntity.getAttrGroupId()); AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrAttrgroupRelationEntity.getAttrGroupId());
if (attrGroupEntity != null) { if (attrGroupEntity != null) {
attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName()); attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
} }
} }
@ -148,7 +160,7 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
BeanUtils.copyProperties(attr, attrEntity); BeanUtils.copyProperties(attr, attrEntity);
this.updateById(attrEntity); this.updateById(attrEntity);
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) { if (attrEntity.getAttrType() == ATTR_TYPE_BASE.getCode()) {
//1、修改分组关联 //1、修改分组关联
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity(); AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
@ -176,8 +188,66 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
//级联删除中间表数据 //级联删除中间表数据
for (Long id : asList) { for (Long id : asList) {
attrAttrgroupRelationService.remove(new LambdaUpdateWrapper<AttrAttrgroupRelationEntity>() attrAttrgroupRelationService.remove(new LambdaUpdateWrapper<AttrAttrgroupRelationEntity>()
.eq(AttrAttrgroupRelationEntity::getAttrId,id)); .eq(AttrAttrgroupRelationEntity::getAttrId, id));
}
}
@Override
public List<AttrEntity> getRelationAttr(Long attrgroupId) {
LambdaQueryWrapper<AttrAttrgroupRelationEntity> queryWrapper = new LambdaQueryWrapper<AttrAttrgroupRelationEntity>()
.eq(AttrAttrgroupRelationEntity::getAttrGroupId, attrgroupId);
List<AttrAttrgroupRelationEntity> entityList = attrAttrgroupRelationDao.selectList(queryWrapper);
List<Long> collect = entityList.stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList());
List<AttrEntity> attrEntities = new ArrayList<>();
if (CollUtil.isNotEmpty(collect)) {
attrEntities = super.listByIds(collect);
} }
return attrEntities;
}
@Override
public void deleteRelation(List<AttrGroupRelationVo> vos) {
LambdaQueryWrapper<AttrAttrgroupRelationEntity> queryWrapper = new LambdaQueryWrapper<>();
//循环拼接条件
for (int i = 0; i < vos.size(); i++) {
int finalI = i;
queryWrapper.eq(AttrAttrgroupRelationEntity::getAttrId, vos.get(finalI).getAttrId()).and(obj -> {
obj.eq(AttrAttrgroupRelationEntity::getAttrGroupId, vos.get(finalI).getAttrGroupId());
}).or(i != vos.size() - 1);
}
attrAttrgroupRelationService.remove(queryWrapper);
}
@Override
public PageUtils getAttrNoRelation(Map<String, Object> params, Long attrgroupId) {
//1、当前分组只能关联自己所属的分类里面的所有属性
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupId);
Long catelogId = attrGroupEntity.getCatelogId();
//2、当前分组只能关联别的分组没有引用的属性
//2.1)、当前分类下的其他分组
List<AttrGroupEntity> group = attrGroupDao.selectList(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
List<Long> collect = group.stream().map(AttrGroupEntity::getAttrGroupId).collect(Collectors.toList());
//2.2)、这些分组关联的属性
List<AttrAttrgroupRelationEntity> groupId = attrAttrgroupRelationDao.selectList(new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", collect));
List<Long> attrIds = groupId.stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList());
//2.3)、从当前分类的所有属性中移除这些属性;
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>().eq("catelog_id", catelogId).eq("attr_type", ATTR_TYPE_BASE.getCode());
if (CollUtil.isNotEmpty(attrIds)) {
wrapper.notIn("attr_id", attrIds);
}
String key = (String) params.get("key");
wrapper.and(StringUtils.isNotEmpty(key), (w) -> {
w.like("value_select", key).or().like("attr_name", key);
});
IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), wrapper);
return new PageUtils(page);
} }
} }

@ -0,0 +1,23 @@
package com.xjs.mall.product.vo;
import lombok.Data;
/**
* vo
* @author xiejs
* @since 2022-03-18
*/
@Data
public class AttrGroupRelationVo {
/**
* id
*/
private Long attrId;
/**
* id
*/
private Long attrGroupId;
}
Loading…
Cancel
Save