From caaf7017237027af952f1b1af001b05bf62767f8 Mon Sep 17 00:00:00 2001 From: Kirk Lin Date: Mon, 14 Jun 2021 15:16:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=9C=8D=E5=8A=A1API?= =?UTF-8?q?=E5=93=81=E7=89=8C=E7=AE=A1=E7=90=86-=E5=93=81=E7=89=8C?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=85=B3=E8=81=94=E4=B8=8E=E7=BA=A7=E8=81=94?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kkmall/product/config/MybatisConfig.java | 26 ++++++++++ .../CategoryBrandRelationController.java | 52 +++++++++++-------- .../controller/CategoryController.java | 16 +++--- .../product/dao/CategoryBrandRelationDao.java | 7 ++- .../service/CategoryBrandRelationService.java | 3 ++ .../product/service/CategoryService.java | 4 ++ .../service/impl/BrandServiceImpl.java | 25 +++++---- .../CategoryBrandRelationServiceImpl.java | 38 ++++++++++++-- .../service/impl/CategoryServiceImpl.java | 27 ++++++---- .../product/CategoryBrandRelationDao.xml | 3 ++ .../src/components/upload/multiUpload.vue | 7 +-- .../src/components/upload/policy.js | 5 +- .../src/components/upload/singleUpload.vue | 6 +-- 13 files changed, 152 insertions(+), 67 deletions(-) create mode 100644 kkmall-product/src/main/java/name/lkk/kkmall/product/config/MybatisConfig.java diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/config/MybatisConfig.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/config/MybatisConfig.java new file mode 100644 index 0000000..58bb648 --- /dev/null +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/config/MybatisConfig.java @@ -0,0 +1,26 @@ +package name.lkk.kkmall.product.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + *

Title: MybatisConfig

+ * Description:引入分页插件 + * date:2020/6/2 15:20 + */ +@EnableTransactionManagement +@Configuration +public class MybatisConfig { + + // 最新版 + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } +} diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryBrandRelationController.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryBrandRelationController.java index 3edac5c..c192b69 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryBrandRelationController.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryBrandRelationController.java @@ -1,19 +1,16 @@ package name.lkk.kkmall.product.controller; -import java.util.Arrays; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity; -import name.lkk.kkmall.product.service.CategoryBrandRelationService; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import name.lkk.common.utils.PageUtils; import name.lkk.common.utils.R; +import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity; +import name.lkk.kkmall.product.service.CategoryBrandRelationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; @@ -27,28 +24,40 @@ import name.lkk.common.utils.R; @RestController @RequestMapping("product/categorybrandrelation") public class CategoryBrandRelationController { + @Autowired private CategoryBrandRelationService categoryBrandRelationService; + + + /** + * 获取当前品牌的所有分类列表 + */ + @GetMapping("/catelog/list") + public R list(@RequestParam("brandId") Long brandId){ + List data = categoryBrandRelationService.list( + new QueryWrapper().eq("brand_id",brandId) + ); + + return R.ok().put("data", data); + } + /** * 列表 */ @RequestMapping("/list") - //@RequiresPermissions("product:categorybrandrelation:list") public R list(@RequestParam Map params){ PageUtils page = categoryBrandRelationService.queryPage(params); return R.ok().put("page", page); } - /** * 信息 */ @RequestMapping("/info/{id}") - //@RequiresPermissions("product:categorybrandrelation:info") public R info(@PathVariable("id") Long id){ - CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id); + CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id); return R.ok().put("categoryBrandRelation", categoryBrandRelation); } @@ -57,9 +66,8 @@ public class CategoryBrandRelationController { * 保存 */ @RequestMapping("/save") - //@RequiresPermissions("product:categorybrandrelation:save") public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){ - categoryBrandRelationService.save(categoryBrandRelation); + categoryBrandRelationService.saveDetail(categoryBrandRelation); return R.ok(); } @@ -68,9 +76,8 @@ public class CategoryBrandRelationController { * 修改 */ @RequestMapping("/update") - //@RequiresPermissions("product:categorybrandrelation:update") public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){ - categoryBrandRelationService.updateById(categoryBrandRelation); + categoryBrandRelationService.updateById(categoryBrandRelation); return R.ok(); } @@ -79,11 +86,10 @@ public class CategoryBrandRelationController { * 删除 */ @RequestMapping("/delete") - //@RequiresPermissions("product:categorybrandrelation:delete") public R delete(@RequestBody Long[] ids){ - categoryBrandRelationService.removeByIds(Arrays.asList(ids)); + categoryBrandRelationService.removeByIds(Arrays.asList(ids)); return R.ok(); } - } + diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryController.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryController.java index 60b5c45..be99287 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryController.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/controller/CategoryController.java @@ -1,20 +1,16 @@ package name.lkk.kkmall.product.controller; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - +import name.lkk.common.utils.R; +import name.lkk.kkmall.product.entity.CategoryEntity; +import name.lkk.kkmall.product.service.CategoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import name.lkk.kkmall.product.entity.CategoryEntity; -import name.lkk.kkmall.product.service.CategoryService; -import name.lkk.common.utils.PageUtils; -import name.lkk.common.utils.R; +import java.util.Arrays; +import java.util.List; @@ -89,7 +85,7 @@ public class CategoryController { @RequestMapping("/update") //@RequiresPermissions("product:category:update") public R update(@RequestBody CategoryEntity category){ - categoryService.updateById(category); + categoryService.updateCascade(category); return R.ok(); } diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/dao/CategoryBrandRelationDao.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/dao/CategoryBrandRelationDao.java index 880ab20..3f5cd64 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/dao/CategoryBrandRelationDao.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/dao/CategoryBrandRelationDao.java @@ -1,8 +1,9 @@ package name.lkk.kkmall.product.dao; -import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 品牌分类关联 @@ -13,5 +14,7 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface CategoryBrandRelationDao extends BaseMapper { - + + void updateCategory(@Param("catId") Long catId, String name); + } diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/CategoryBrandRelationService.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/CategoryBrandRelationService.java index 3fbf58b..7834e51 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/CategoryBrandRelationService.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/CategoryBrandRelationService.java @@ -19,5 +19,8 @@ public interface CategoryBrandRelationService extends IService { */ Long[] findCateLogPath(Long catelogId); + /** + * 级联更新所有数据 + */ + void updateCascade(CategoryEntity category); } diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/BrandServiceImpl.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/BrandServiceImpl.java index 2ba8e10..36706ea 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/BrandServiceImpl.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/BrandServiceImpl.java @@ -1,22 +1,21 @@ package name.lkk.kkmall.product.service.impl; -import name.lkk.kkmall.product.service.CategoryBrandRelationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import name.lkk.common.utils.PageUtils; import name.lkk.common.utils.Query; - import name.lkk.kkmall.product.dao.BrandDao; import name.lkk.kkmall.product.entity.BrandEntity; import name.lkk.kkmall.product.service.BrandService; +import name.lkk.kkmall.product.service.CategoryBrandRelationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; + +import java.util.List; +import java.util.Map; @Service("brandService") @@ -26,11 +25,15 @@ public class BrandServiceImpl extends ServiceImpl impleme @Override public PageUtils queryPage(Map params) { + QueryWrapper wrapper = new QueryWrapper<>(); + String key = (String) params.get("key"); + if(!ObjectUtils.isEmpty(key)){ + wrapper.eq("brand_id", key).or().like("name", key); + } IPage page = this.page( new Query().getPage(params), - new QueryWrapper() + wrapper ); - return new PageUtils(page); } @@ -42,7 +45,7 @@ public class BrandServiceImpl extends ServiceImpl impleme public void updateDetail(BrandEntity brand) { // 保证冗余字段的数据一致 this.updateById(brand); - if(!StringUtils.isEmpty(brand.getName())){ + if(!ObjectUtils.isEmpty(brand.getName())){ // 同步更新其他关联表的数据 categoryBrandRelationService.updateBrand(brand.getBrandId(), brand.getName()); // TODO 更新其它关联 diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryBrandRelationServiceImpl.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryBrandRelationServiceImpl.java index e174319..9c5a109 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryBrandRelationServiceImpl.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryBrandRelationServiceImpl.java @@ -1,21 +1,31 @@ package name.lkk.kkmall.product.service.impl; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import org.springframework.stereotype.Service; -import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import name.lkk.common.utils.PageUtils; import name.lkk.common.utils.Query; - +import name.lkk.kkmall.product.dao.BrandDao; import name.lkk.kkmall.product.dao.CategoryBrandRelationDao; +import name.lkk.kkmall.product.dao.CategoryDao; +import name.lkk.kkmall.product.entity.BrandEntity; import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity; +import name.lkk.kkmall.product.entity.CategoryEntity; import name.lkk.kkmall.product.service.CategoryBrandRelationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; @Service("categoryBrandRelationService") public class CategoryBrandRelationServiceImpl extends ServiceImpl implements CategoryBrandRelationService { + @Autowired + private BrandDao brandDao; + + @Autowired + private CategoryDao categoryDao; @Override public PageUtils queryPage(Map params) { @@ -36,4 +46,24 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl().eq("brand_id",brandId)); } + @Override + public void updateCategory(Long catId, String name) { + this.baseMapper.updateCategory(catId, name); + } + + /** + * 根据获取品牌id 、三级分类id查询对应的名字保存到数据库 + */ + @Override + public void saveDetail(CategoryBrandRelationEntity categoryBrandRelation) { + // 获取品牌id 、三级分类id + Long brandId = categoryBrandRelation.getBrandId(); + Long catelogId = categoryBrandRelation.getCatelogId(); + // 根据id查询详细名字 + BrandEntity brandEntity = brandDao.selectById(brandId); + CategoryEntity categoryEntity = categoryDao.selectById(catelogId); + categoryBrandRelation.setBrandName(brandEntity.getName()); + categoryBrandRelation.setCatelogName(categoryEntity.getName()); + this.save(categoryBrandRelation); + } } \ No newline at end of file diff --git a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryServiceImpl.java b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryServiceImpl.java index 4cdc7ba..60aae43 100644 --- a/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryServiceImpl.java +++ b/kkmall-product/src/main/java/name/lkk/kkmall/product/service/impl/CategoryServiceImpl.java @@ -7,8 +7,11 @@ import name.lkk.common.utils.PageUtils; import name.lkk.common.utils.Query; import name.lkk.kkmall.product.dao.CategoryDao; import name.lkk.kkmall.product.entity.CategoryEntity; +import name.lkk.kkmall.product.service.CategoryBrandRelationService; import name.lkk.kkmall.product.service.CategoryService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; @@ -17,6 +20,9 @@ import java.util.stream.Collectors; @Service("categoryService") public class CategoryServiceImpl extends ServiceImpl implements CategoryService { + @Autowired + private CategoryBrandRelationService categoryBrandRelationService; + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -35,15 +41,11 @@ public class CategoryServiceImpl extends ServiceImpl listWithTree() { List entities = baseMapper.selectList(null); // 筛选出所有一级分类 - List level1Menus = entities.stream(). - filter((categoryEntity) -> categoryEntity.getParentCid() == 0) - .map((menu) -> { - menu.setChildren(getChildrens(menu, entities)); - return menu; - }).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) - .collect(Collectors.toList()); - return level1Menus; + return entities.stream(). + filter((categoryEntity) -> categoryEntity.getParentCid() == 0) + .peek((menu) -> menu.setChildren(getChildrens(menu, entities))).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) + .collect(Collectors.toList()); } /** @@ -55,7 +57,7 @@ public class CategoryServiceImpl extends ServiceImpl getChildrens(CategoryEntity root, List all){ List children = all.stream().filter(categoryEntity -> - categoryEntity.getParentCid() == root.getCatId() + categoryEntity.getParentCid().equals(root.getCatId()) ).map(categoryEntity -> { categoryEntity.setChildren(getChildrens(categoryEntity, all)); return categoryEntity; @@ -78,6 +80,13 @@ public class CategoryServiceImpl extends ServiceImpl + + UPDATE `pms_category_brand_relation` SET catelog_name = #{name} WHERE catelog_id = #{catId} + \ No newline at end of file diff --git a/renren-fast-vue/src/components/upload/multiUpload.vue b/renren-fast-vue/src/components/upload/multiUpload.vue index 3322d0f..9190147 100644 --- a/renren-fast-vue/src/components/upload/multiUpload.vue +++ b/renren-fast-vue/src/components/upload/multiUpload.vue @@ -1,7 +1,7 @@