From 58d40166df85d63f2349327fc8cde0903a3f7df9 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Sat, 8 Jun 2024 20:39:22 +0800 Subject: [PATCH 01/14] =?UTF-8?q?-84=E5=93=81=E7=89=8C=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E5=86=97=E4=BD=99=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../valid/groups/DeleteGroupsInterface.java | 8 ++++ .../controller/AttrGroupController.java | 27 ++++++++--- .../product/controller/BrandController.java | 35 ++++++++------- .../mall/product/entity/AttrGroupEntity.java | 9 ++++ .../carl/mall/product/entity/BrandEntity.java | 8 ++-- .../product/service/AttrGroupService.java | 2 + .../mall/product/service/BrandService.java | 2 + .../mall/product/service/CategoryService.java | 2 + .../service/impl/AttrGroupServiceImpl.java | 45 +++++++++++++++++++ .../service/impl/BrandServiceImpl.java | 8 ++++ .../service/impl/CategoryServiceImpl.java | 23 ++++++++++ .../product/MallProductApplicationTest.java | 4 ++ .../io/renren/RenrenApplicationTests.java | 16 ------- 13 files changed, 149 insertions(+), 40 deletions(-) create mode 100644 mall-commons/src/main/java/com/carl/common/valid/groups/DeleteGroupsInterface.java delete mode 100644 renren-generator-master/src/test/java/io/renren/RenrenApplicationTests.java diff --git a/mall-commons/src/main/java/com/carl/common/valid/groups/DeleteGroupsInterface.java b/mall-commons/src/main/java/com/carl/common/valid/groups/DeleteGroupsInterface.java new file mode 100644 index 0000000..26d98c4 --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/valid/groups/DeleteGroupsInterface.java @@ -0,0 +1,8 @@ +package com.carl.common.valid.groups; + + +/** + * 删除的标签 + */ +public interface DeleteGroupsInterface { +} diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java index 27eb461..673489b 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.mall.product.service.CategoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -31,14 +32,27 @@ public class AttrGroupController { @Autowired private AttrGroupService attrGroupService; + @Autowired + private CategoryService categoryService; + /** * 列表 + * 分页查询 + * 前端提交请求需要封装对应的分页数据 + * { + * page:1,//当前页 + * limit:10,//每页显示记录数 + * sidx:"id",//排序字段 + * order:"asc/desc"//排序方式 + * key: "小米"//查询的关键字 + * } */ - @RequestMapping("/list") + @RequestMapping("/list/{catelogId}") //@RequiresPermissions("product:attrgroup:list") - public R list(@RequestParam Map params){ - PageUtils page = attrGroupService.queryPage(params); - + public R list(@RequestParam Map params, + @PathVariable("catelogId") Long catelogId){ +// PageUtils page = attrGroupService.queryPage(params); + PageUtils page = attrGroupService.queryPageWithTree(params,catelogId); return R.ok().put("page", page); } @@ -50,7 +64,9 @@ public class AttrGroupController { //@RequiresPermissions("product:attrgroup:info") public R info(@PathVariable("attrGroupId") Long attrGroupId){ AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId); - + Long catelogId = attrGroup.getCatelogId(); + Long[] catelogPath = categoryService.findCatelogPath(catelogId); + attrGroup.setCatelogPath(catelogPath); return R.ok().put("attrGroup", attrGroup); } @@ -61,7 +77,6 @@ public class AttrGroupController { //@RequiresPermissions("product:attrgroup:save") public R save(@RequestBody AttrGroupEntity attrGroup){ attrGroupService.save(attrGroup); - return R.ok(); } diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/BrandController.java b/mall-product/src/main/java/com/carl/mall/product/controller/BrandController.java index be883e4..2f92c69 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/BrandController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/BrandController.java @@ -10,8 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - import com.carl.mall.product.entity.BrandEntity; + import com.carl.mall.product.service.BrandService; import com.carl.common.utils.PageUtils; import com.carl.common.utils.R; @@ -32,10 +32,10 @@ public class BrandController { private BrandService brandService; @GetMapping("/all") - public R queryAllBrand(){ + public R queryAllBrand() { BrandEntity brandEntity = new BrandEntity(); brandEntity.setName("华为"); - return R.ok().put("brands",brandEntity); + return R.ok().put("brands", brandEntity); } /** @@ -43,9 +43,8 @@ public class BrandController { */ @RequestMapping("/list") //@RequiresPermissions("product:brand:list") - public R list(@RequestParam Map params){ + public R list(@RequestParam Map params) { PageUtils page = brandService.queryPage(params); - return R.ok().put("page", page); } @@ -55,8 +54,8 @@ public class BrandController { */ @RequestMapping("/info/{brandId}") //@RequiresPermissions("product:brand:info") - public R info(@PathVariable("brandId") Long brandId){ - BrandEntity brand = brandService.getById(brandId); + public R info(@PathVariable("brandId") Long brandId) { + BrandEntity brand = brandService.getById(brandId); return R.ok().put("brand", brand); } @@ -66,7 +65,7 @@ public class BrandController { */ @RequestMapping("/save") //@RequiresPermissions("product:brand:save") - public R save(@Validated(AddGroupsInterface.class) @RequestBody BrandEntity brand){ + public R save(@Validated(AddGroupsInterface.class) @RequestBody BrandEntity brand) { // if (result.hasErrors()){ // HashMap map = new HashMap<>(); // List fieldErrors = result.getFieldErrors(); @@ -79,8 +78,8 @@ public class BrandController { // } // return R.error(400,"参数有问题重新按规则输入").put("data",map); // } - - brandService.save(brand); +// brand.setDelFlag(1); + brandService.save(brand); return R.ok(); } @@ -89,8 +88,8 @@ public class BrandController { */ @RequestMapping("/update") //@RequiresPermissions("product:brand:update") - public R update(@Validated(UpdateGroupsInterface.class) @RequestBody BrandEntity brand){ - //brandService.updateById(brand); + public R update(@Validated(UpdateGroupsInterface.class) @RequestBody BrandEntity brand) { + //brandService.updateById(brand); brandService.updateDetail(brand); return R.ok(); @@ -101,9 +100,15 @@ public class BrandController { */ @RequestMapping("/delete") //@RequiresPermissions("product:brand:delete") - public R delete(@RequestBody Long[] brandIds){ - brandService.removeByIds(Arrays.asList(brandIds)); + public R delete(@RequestBody Long[] brandIds) { +// List brandEntities = brandService.listByIds(Arrays.asList(brandIds)); +// for (BrandEntity brandEntity : brandEntities) { +// brandEntity.setShowStatus(0); +// brandService.updateDetail(brandEntity); +// } + brandService.deleteBatchIds(Arrays.asList(brandIds)); return R.ok(); - } +// } + } } diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/AttrGroupEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/AttrGroupEntity.java index 71a041c..eacdc2a 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/AttrGroupEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/AttrGroupEntity.java @@ -1,5 +1,6 @@ package com.carl.mall.product.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -44,4 +45,12 @@ public class AttrGroupEntity implements Serializable { */ private Long catelogId; + /** + * 修改数据和关联数据时记录类别信息 + * [2,22,225] + * 所属分类path + */ + @TableField(exist = false) + private Long[] catelogPath; + } diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/BrandEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/BrandEntity.java index 712a12e..e15b336 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/BrandEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/BrandEntity.java @@ -1,13 +1,14 @@ package com.carl.mall.product.entity; import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableLogic; + import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import com.carl.common.valid.ListValue; import com.carl.common.valid.groups.AddGroupsInterface; + import com.carl.common.valid.groups.UpdateGroupsInterface; import lombok.Data; import org.hibernate.validator.constraints.URL; @@ -58,6 +59,7 @@ public class BrandEntity implements Serializable { @NotNull(message = "显示状态不能为空",groups = AddGroupsInterface.class) //自定义注解 @ListValue(val={0,1},groups = {AddGroupsInterface.class,UpdateGroupsInterface.class}) + //@TableLogic(value = "1",delval = "0") private Integer showStatus; /** * 检索首字母 @@ -72,8 +74,8 @@ public class BrandEntity implements Serializable { @Min(value = 0,message = "排序不能小于0",groups = {UpdateGroupsInterface.class,AddGroupsInterface.class}) private Integer sort; - @TableLogic(delval = "0",value = "1") - private int delFlag; +// @TableLogic(delval = "0",value = "1") +// private int delFlag; diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java index 8405051..8290ea9 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java @@ -16,5 +16,7 @@ import java.util.Map; public interface AttrGroupService extends IService { PageUtils queryPage(Map params); + + PageUtils queryPageWithTree(Map params, Long catelogId); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/BrandService.java b/mall-product/src/main/java/com/carl/mall/product/service/BrandService.java index c6040ad..27bc650 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/BrandService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/BrandService.java @@ -21,5 +21,7 @@ public interface BrandService extends IService { void updateDetail(BrandEntity brand); + + void deleteBatchIds(List list); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/CategoryService.java b/mall-product/src/main/java/com/carl/mall/product/service/CategoryService.java index 979f53a..bdc19c1 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/CategoryService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/CategoryService.java @@ -23,5 +23,7 @@ public interface CategoryService extends IService { public void removeCategoryByIds(List ids); void updateDetail(CategoryEntity categoryEntity); + + Long[] findCatelogPath(Long catelogId); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java index 979ef7d..bb84524 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java @@ -11,6 +11,7 @@ import com.carl.common.utils.Query; import com.carl.mall.product.dao.AttrGroupDao; import com.carl.mall.product.entity.AttrGroupEntity; import com.carl.mall.product.service.AttrGroupService; +import org.springframework.util.StringUtils; @Service("attrGroupService") @@ -26,4 +27,48 @@ public class AttrGroupServiceImpl extends ServiceImpl params, Long catelogId) { + //获取检索的关键字 + String key = (String) params.get("key"); + QueryWrapper wrapper = new QueryWrapper<>(); + if (!StringUtils.isEmpty(key)){ + /* + * 继续构造查询条件,通过lambda表达式指定查询条件。 + * 这里使用了方法引用 obj.eq("attr_group_id", key) 来判断属性组ID是否等于给定的key, + * 并使用 or() 方法连接另一个条件,即使用 like("attr_group_name", key) 方法判断属性组名称是否包含给定的key。 + * 这样做的目的是为了同时匹配属性组ID和属性组名称,以提高查询的准确性和灵活性。 + */ + wrapper.and(obj -> { + obj.eq("attr_group_id", key).or().like("attr_group_name", key); + }); + + } + if (catelogId == 0){ + //根据分页条件params查询(所有的)属性组信息 + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + return new PageUtils(page); + }else { + //根据类别编号查询属性组信息 + wrapper.eq("catelog_id",catelogId); + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + return new PageUtils(page); + } + + + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/BrandServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/BrandServiceImpl.java index 9aa1293..e6368d3 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/BrandServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/BrandServiceImpl.java @@ -7,6 +7,7 @@ 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; @@ -58,6 +59,13 @@ public class BrandServiceImpl extends ServiceImpl impleme // TODO 同步更新其他的品牌名称的冗余数据 } } + + @Override + public void deleteBatchIds(List list) { + baseMapper.deleteBatchIds(list); } +} + + diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/CategoryServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/CategoryServiceImpl.java index bfce1a5..91aacb3 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/CategoryServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/CategoryServiceImpl.java @@ -4,6 +4,8 @@ import com.carl.mall.product.service.CategoryBrandRelationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -107,4 +109,25 @@ public class CategoryServiceImpl extends ServiceImpl path = new ArrayList<>(); + List parentPath = findParentPath(catelogId,path); + Collections.reverse(parentPath); + return parentPath.toArray(new Long[parentPath.size()]); + } + + public List findParentPath(Long catelogId,List pa){ + pa.add(catelogId); + //Long parentCid = this.getById(catelogId).getParentCid(); + Long parentCid = baseMapper + .selectOne(new QueryWrapper().eq("cat_id", catelogId)).getParentCid(); + if (parentCid != 0){ + findParentPath(parentCid, pa); + } + return pa; + + } + + } \ No newline at end of file diff --git a/mall-product/src/test/java/com/carl/mall/product/MallProductApplicationTest.java b/mall-product/src/test/java/com/carl/mall/product/MallProductApplicationTest.java index 13923f3..03a4d8c 100644 --- a/mall-product/src/test/java/com/carl/mall/product/MallProductApplicationTest.java +++ b/mall-product/src/test/java/com/carl/mall/product/MallProductApplicationTest.java @@ -15,6 +15,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.List; +import java.util.Scanner; @SpringBootTest(classes = MallProductApplication.class) public class MallProductApplicationTest { @@ -78,6 +79,9 @@ public class MallProductApplicationTest { System.out.println("长传图片成功..."); } + + + } diff --git a/renren-generator-master/src/test/java/io/renren/RenrenApplicationTests.java b/renren-generator-master/src/test/java/io/renren/RenrenApplicationTests.java deleted file mode 100644 index bacacc8..0000000 --- a/renren-generator-master/src/test/java/io/renren/RenrenApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.renren; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class RenrenApplicationTests { - - @Test - public void contextLoads() { - } - -} -- Gitee From 9edf5182f49879e427646980dd24ecffdde7518a Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Sun, 9 Jun 2024 19:14:03 +0800 Subject: [PATCH 02/14] =?UTF-8?q?85-=E8=A7=84=E6=A0=BC=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mall-commons/pom.xml | 11 ++++ .../product/controller/AttrController.java | 11 ++-- .../product/convert/EntityToVoConvert.java | 15 +++++ .../carl/mall/product/entity/AttrEntity.java | 1 - .../service/AttrAttrgroupRelationService.java | 1 + .../mall/product/service/AttrService.java | 3 + .../product/service/impl/AttrServiceImpl.java | 32 +++++++++++ .../carl/mall/product/vo/AttrEntityVO.java | 56 +++++++++++++++++++ 8 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/AttrEntityVO.java diff --git a/mall-commons/pom.xml b/mall-commons/pom.xml index 3828058..7cc5704 100644 --- a/mall-commons/pom.xml +++ b/mall-commons/pom.xml @@ -72,6 +72,17 @@ spring-boot-starter-web 2.4.12 + + + org.mapstruct + mapstruct + 1.4.2.Final + + + org.mapstruct + mapstruct-processor + 1.4.2.Final + diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java index b7e934f..07090ad 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.mall.product.vo.AttrEntityVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -55,14 +56,14 @@ public class AttrController { } /** - * 保存 + * 保存属性 */ @RequestMapping("/save") //@RequiresPermissions("product:attr:save") - public R save(@RequestBody AttrEntity attr){ - attrService.save(attr); - - return R.ok(); + public R save(@RequestBody AttrEntityVO attrEntityVO){ + //attrService.save(attr); + attrService.saveAttr(attrEntityVO); + return R.ok("保存成功"); } /** diff --git a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java new file mode 100644 index 0000000..9f9f7b3 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java @@ -0,0 +1,15 @@ +package com.carl.mall.product.convert; + + +import com.carl.mall.product.entity.AttrEntity; +import com.carl.mall.product.vo.AttrEntityVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface EntityToVoConvert { + EntityToVoConvert INSTANCE = Mappers.getMapper(EntityToVoConvert.class); + + AttrEntity attrEntityToVO(AttrEntityVO attrEntityVO); + +} diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/AttrEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/AttrEntity.java index beede40..bbbab43 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/AttrEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/AttrEntity.java @@ -18,7 +18,6 @@ import lombok.Data; @TableName("pms_attr") public class AttrEntity implements Serializable { private static final long serialVersionUID = 1L; - /** * 属性id */ diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java index 06995b7..0fa3f2a 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java @@ -17,5 +17,6 @@ import java.util.Map; public interface AttrAttrgroupRelationService extends IService { PageUtils queryPage(Map params); + } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java index 516a0e8..11919bf 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java @@ -3,6 +3,7 @@ package com.carl.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrEntity; +import com.carl.mall.product.vo.AttrEntityVO; import java.util.Map; @@ -16,5 +17,7 @@ import java.util.Map; public interface AttrService extends IService { PageUtils queryPage(Map params); + + void saveAttr(AttrEntityVO attrEntityVO); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java index 0b58da9..b5f86be 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java @@ -1,5 +1,11 @@ package com.carl.mall.product.service.impl; +import com.carl.mall.product.convert.EntityToVoConvert; +import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; +import com.carl.mall.product.service.AttrAttrgroupRelationService; +import com.carl.mall.product.service.AttrGroupService; +import com.carl.mall.product.vo.AttrEntityVO; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -16,6 +22,12 @@ import com.carl.mall.product.service.AttrService; @Service("attrService") public class AttrServiceImpl extends ServiceImpl implements AttrService { + + @Autowired + private AttrAttrgroupRelationService attrAttrgroupRelationService; + + @Autowired + private AttrGroupService attrGroupService; @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +38,24 @@ public class AttrServiceImpl extends ServiceImpl implements return new PageUtils(page); } + @Override + public void saveAttr(AttrEntityVO attrEntityVO) { + + AttrEntity attrEntity = EntityToVoConvert.INSTANCE.attrEntityToVO(attrEntityVO); + //1.保存规格参数的信息 + this.save(attrEntity); + //2.保存规格参数和属性组的关联关系 + Long attrGroupId = attrEntityVO.getAttrGroupId(); + //查询属性分组中的排序值 + Integer sort = attrGroupService.getById(attrGroupId).getSort(); + if (attrGroupId != null && attrGroupId > 0) { + AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity(); + attrAttrgroupRelationEntity.setAttrGroupId(attrGroupId); + attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId()); //这个是属性的id 必须从实体entity获取 + attrAttrgroupRelationEntity.setAttrSort(sort); //属性分组中的排序 + attrAttrgroupRelationService.save(attrAttrgroupRelationEntity); + } + + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/AttrEntityVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/AttrEntityVO.java new file mode 100644 index 0000000..d2e9480 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/AttrEntityVO.java @@ -0,0 +1,56 @@ +package com.carl.mall.product.vo; + + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +/** + * 属性实体VO 与数据库实体的差别是多了一个属性:属性分组id + */ +@Data +public class AttrEntityVO { + /** + * 属性id + */ + @TableId + private Long attrId; + /** + * 属性名 + */ + private String attrName; + /** + * 是否需要检索[0-不需要,1-需要] + */ + private Integer searchType; + /** + * 属性图标 + */ + private String icon; + /** + * 可选值列表[用逗号分隔] + */ + private String valueSelect; + /** + * 属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性] + */ + private Integer attrType; + /** + * 启用状态[0 - 禁用,1 - 启用] + */ + private Long enable; + /** + * 所属分类 + */ + private Long catelogId; + /** + * 快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整 + */ + private Integer showDesc; + + /** + * 属性分组id(与数据库实体的差别就在这) 需要与前端约定好 + */ + private Long attrGroupId; + + +} -- Gitee From 07a6b9397eeffd49183959d390b8e9dada33810e Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Mon, 10 Jun 2024 15:20:58 +0800 Subject: [PATCH 03/14] =?UTF-8?q?87-=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/controller/AttrController.java | 11 +++- .../product/convert/EntityToVoConvert.java | 4 ++ .../mall/product/service/AttrService.java | 2 + .../product/service/impl/AttrServiceImpl.java | 63 ++++++++++++++++++- .../carl/mall/product/vo/AttrResponseVO.java | 15 +++++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java index 07090ad..eda12f6 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java @@ -32,6 +32,16 @@ public class AttrController { @Autowired private AttrService attrService; + + //http://localhost:9006/app/product/attr/base/list/0?t=1717931509778&page=1&limit=10&key= + /** + * 列表 + */ + @RequestMapping("/base/list/{catelogId}") + public R baseList(@RequestParam Map params, @PathVariable("catelogId") Long catelogId){ + PageUtils page = attrService.queryByPage(params, catelogId); + return R.ok().put("page",page); + } /** * 列表 */ @@ -39,7 +49,6 @@ public class AttrController { //@RequiresPermissions("product:attr:list") public R list(@RequestParam Map params){ PageUtils page = attrService.queryPage(params); - return R.ok().put("page", page); } diff --git a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java index 9f9f7b3..49ff79e 100644 --- a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java +++ b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java @@ -3,6 +3,7 @@ package com.carl.mall.product.convert; import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrResponseVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -12,4 +13,7 @@ public interface EntityToVoConvert { AttrEntity attrEntityToVO(AttrEntityVO attrEntityVO); + AttrResponseVO attrEntityToResponseVO(AttrEntity attrEntity); + + } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java index 11919bf..755bd37 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java @@ -19,5 +19,7 @@ public interface AttrService extends IService { PageUtils queryPage(Map params); void saveAttr(AttrEntityVO attrEntityVO); + + PageUtils queryByPage(Map params, Long catelogId); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java index b5f86be..7ed5230 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java @@ -1,13 +1,21 @@ package com.carl.mall.product.service.impl; import com.carl.mall.product.convert.EntityToVoConvert; +import com.carl.mall.product.dao.AttrAttrgroupRelationDao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; +import com.carl.mall.product.entity.CategoryEntity; import com.carl.mall.product.service.AttrAttrgroupRelationService; import com.carl.mall.product.service.AttrGroupService; +import com.carl.mall.product.service.CategoryService; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrResponseVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -17,6 +25,8 @@ import com.carl.common.utils.Query; import com.carl.mall.product.dao.AttrDao; import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.service.AttrService; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; @Service("attrService") @@ -28,6 +38,12 @@ public class AttrServiceImpl extends ServiceImpl implements @Autowired private AttrGroupService attrGroupService; + + @Autowired + private CategoryService categoryService; + + @Autowired + private AttrAttrgroupRelationDao attrAttrgroupRelationDao; @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -38,9 +54,9 @@ public class AttrServiceImpl extends ServiceImpl implements return new PageUtils(page); } + @Transactional @Override public void saveAttr(AttrEntityVO attrEntityVO) { - AttrEntity attrEntity = EntityToVoConvert.INSTANCE.attrEntityToVO(attrEntityVO); //1.保存规格参数的信息 this.save(attrEntity); @@ -58,4 +74,49 @@ public class AttrServiceImpl extends ServiceImpl implements } + @Override + public PageUtils queryByPage(Map params, Long catelogId) { + + QueryWrapper wrapper= new QueryWrapper<>(); + + if (catelogId != 0) { + wrapper.eq("catelog_id",catelogId); + } + + String key =(String) params.get("key"); + if (!StringUtils.isEmpty(key)){ + wrapper.and(obj -> { + obj.eq("attr_id",key) + .or() + .like("attr_name",key); + }); + } + + IPage page = this + .page( + new Query().getPage(params), + wrapper); + + PageUtils pageUtils = new PageUtils(page); + //关联的我们需要查询出类别名称和属性组的名称 + List records = page.getRecords(); + List collect = records.stream().map((attrEntity) -> { + AttrResponseVO attrResponseVO = EntityToVoConvert.INSTANCE.attrEntityToResponseVO(attrEntity); + //设置分类名称 + CategoryEntity entity = categoryService.getById(attrEntity.getCatelogId()); + if (entity != null) { + attrResponseVO.setCatelogName(entity.getName()); + } + //设置属性组名称 + AttrAttrgroupRelationEntity attrGroupRelation = attrAttrgroupRelationDao + .selectOne(new QueryWrapper().eq("attr_id", attrEntity.getAttrId())); + String attrGroupName = attrGroupService.getById(attrGroupRelation.getAttrGroupId()).getAttrGroupName(); + attrResponseVO.setGroupName(attrGroupName); + return attrResponseVO; + }).collect(Collectors.toList()); + pageUtils.setList(collect); + return pageUtils; + + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java new file mode 100644 index 0000000..43773a3 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java @@ -0,0 +1,15 @@ +package com.carl.mall.product.vo; + + +import lombok.Data; + +@Data +public class AttrResponseVO extends AttrEntityVO{ + + private String catelogName; + + private String groupName; + + + +} -- Gitee From 8c9c7fa05aa714ec0e241b2dfe3d23d03f268e76 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Tue, 11 Jun 2024 14:35:29 +0800 Subject: [PATCH 04/14] =?UTF-8?q?89-=E5=8F=82=E6=95=B0=E8=A7=84=E6=A0=BC-?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/controller/AttrController.java | 17 ++++---- .../mall/product/service/AttrService.java | 5 +++ .../product/service/impl/AttrServiceImpl.java | 42 +++++++++++++++++++ .../carl/mall/product/vo/AttrResponseVO.java | 2 + 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java index eda12f6..bd08e9f 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java @@ -5,6 +5,7 @@ import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrResponseVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -39,8 +40,8 @@ public class AttrController { */ @RequestMapping("/base/list/{catelogId}") public R baseList(@RequestParam Map params, @PathVariable("catelogId") Long catelogId){ - PageUtils page = attrService.queryByPage(params, catelogId); - return R.ok().put("page",page); + PageUtils pageUtils = attrService.queryByPage(params, catelogId); + return R.ok().put("page",pageUtils); } /** * 列表 @@ -59,9 +60,9 @@ public class AttrController { @RequestMapping("/info/{attrId}") //@RequiresPermissions("product:attr:info") public R info(@PathVariable("attrId") Long attrId){ - AttrEntity attr = attrService.getById(attrId); - - return R.ok().put("attr", attr); + //AttrEntity attr = attrService.getById(attrId); + AttrResponseVO attrResponseVO = attrService.queryByAttrId(attrId); + return R.ok().put("attr", attrResponseVO); } /** @@ -80,9 +81,9 @@ public class AttrController { */ @RequestMapping("/update") //@RequiresPermissions("product:attr:update") - public R update(@RequestBody AttrEntity attr){ - attrService.updateById(attr); - + public R update(@RequestBody AttrEntityVO attrEntityVO){ + //attrService.updateById(attr); + attrService.updateByEntity(attrEntityVO); return R.ok(); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java index 755bd37..93d444b 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrResponseVO; import java.util.Map; @@ -21,5 +22,9 @@ public interface AttrService extends IService { void saveAttr(AttrEntityVO attrEntityVO); PageUtils queryByPage(Map params, Long catelogId); + + AttrResponseVO queryByAttrId(Long attrId); + + void updateByEntity(AttrEntityVO attrEntityVO); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java index 7ed5230..2117a21 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java @@ -1,8 +1,10 @@ package com.carl.mall.product.service.impl; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.carl.mall.product.convert.EntityToVoConvert; import com.carl.mall.product.dao.AttrAttrgroupRelationDao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; +import com.carl.mall.product.entity.AttrGroupEntity; import com.carl.mall.product.entity.CategoryEntity; import com.carl.mall.product.service.AttrAttrgroupRelationService; import com.carl.mall.product.service.AttrGroupService; @@ -99,6 +101,7 @@ public class AttrServiceImpl extends ServiceImpl implements PageUtils pageUtils = new PageUtils(page); //关联的我们需要查询出类别名称和属性组的名称 + //List list = (List) pageUtils.getList();//这么写也没毛病 List records = page.getRecords(); List collect = records.stream().map((attrEntity) -> { AttrResponseVO attrResponseVO = EntityToVoConvert.INSTANCE.attrEntityToResponseVO(attrEntity); @@ -119,4 +122,43 @@ public class AttrServiceImpl extends ServiceImpl implements } + @Override + public AttrResponseVO queryByAttrId(Long attrId) { + //找出所属分类和所属分组 + AttrEntity attrEntity = this.getById(attrId); + AttrResponseVO attrResponseVO = EntityToVoConvert.INSTANCE.attrEntityToResponseVO(attrEntity); + AttrAttrgroupRelationEntity relationEntity = + attrAttrgroupRelationDao.selectOne(new QueryWrapper().eq("attr_id", attrId)); + if (!StringUtils.isEmpty(relationEntity)){ + AttrGroupEntity attrGroupEntity = attrGroupService.getById(relationEntity.getAttrGroupId()); + attrResponseVO.setAttrGroupId(attrGroupEntity.getAttrGroupId()); + if (!StringUtils.isEmpty(attrGroupEntity)) { + attrResponseVO.setGroupName(attrGroupEntity.getAttrGroupName()); + } + } + Long catelogId = attrEntity.getCatelogId(); + Long[] catelogPath = categoryService.findCatelogPath(catelogId); + attrResponseVO.setCatelogPath(catelogPath); + return attrResponseVO; + } + + @Override + public void updateByEntity(AttrEntityVO attrEntityVO) { + AttrEntity attrEntity = EntityToVoConvert.INSTANCE.attrEntityToVO(attrEntityVO); + this.updateById(attrEntity); + AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity(); + relationEntity.setAttrId(attrEntityVO.getAttrId()); + relationEntity.setAttrGroupId(attrEntityVO.getAttrGroupId()); + Integer integer = attrAttrgroupRelationDao + .selectCount(new QueryWrapper() + .eq("attr_id", attrEntityVO.getAttrId())); + if (integer > 0){ + attrAttrgroupRelationDao + .update(relationEntity,new UpdateWrapper() + .eq("attr_id", attrEntityVO.getAttrId())); + }else { + attrAttrgroupRelationDao.insert(relationEntity); + } + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java index 43773a3..d257cd0 100644 --- a/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java +++ b/mall-product/src/main/java/com/carl/mall/product/vo/AttrResponseVO.java @@ -10,6 +10,8 @@ public class AttrResponseVO extends AttrEntityVO{ private String groupName; + private Long[] catelogPath; + } -- Gitee From c9b468a7a224868f4303b5889a3af594515d3a6a Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Tue, 11 Jun 2024 14:36:09 +0800 Subject: [PATCH 05/14] =?UTF-8?q?89-=E5=8F=82=E6=95=B0=E8=A7=84=E6=A0=BC-?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/carl/mall/product/service/impl/AttrServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java index 2117a21..fcbf0fb 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java @@ -141,7 +141,7 @@ public class AttrServiceImpl extends ServiceImpl implements attrResponseVO.setCatelogPath(catelogPath); return attrResponseVO; } - + @Transactional @Override public void updateByEntity(AttrEntityVO attrEntityVO) { AttrEntity attrEntity = EntityToVoConvert.INSTANCE.attrEntityToVO(attrEntityVO); -- Gitee From a46189546dc393dcbaed52c3811d1ea987af5116 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Tue, 11 Jun 2024 19:52:15 +0800 Subject: [PATCH 06/14] =?UTF-8?q?91-=E9=94=80=E5=94=AE=E5=B1=9E=E6=80=A7-?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/carl/common/constant/AttrEnum.java | 30 ++++++ .../product/controller/AttrController.java | 14 ++- .../mall/product/service/AttrService.java | 4 +- .../product/service/impl/AttrServiceImpl.java | 99 +++++++++++++------ 4 files changed, 109 insertions(+), 38 deletions(-) create mode 100644 mall-commons/src/main/java/com/carl/common/constant/AttrEnum.java diff --git a/mall-commons/src/main/java/com/carl/common/constant/AttrEnum.java b/mall-commons/src/main/java/com/carl/common/constant/AttrEnum.java new file mode 100644 index 0000000..9a27a4f --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/constant/AttrEnum.java @@ -0,0 +1,30 @@ +package com.carl.common.constant; + + +/** + * 销售属性和基本属性常量 + */ +public enum AttrEnum { + + ATTR_TYPE_BASE(1,"基本属性"), + + ATTR_TYPE_SALE(0,"销售属性"); + + private Integer code; + + private String desc; + + + AttrEnum(Integer code, String desc) { + this.code = code; + this.desc = desc; + } + + public Integer getCode() { + return code; + } + + public String getDesc() { + return desc; + } +} diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java index bd08e9f..430c950 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java @@ -36,11 +36,13 @@ public class AttrController { //http://localhost:9006/app/product/attr/base/list/0?t=1717931509778&page=1&limit=10&key= /** - * 列表 + * 规格参数 和销售属性 */ - @RequestMapping("/base/list/{catelogId}") - public R baseList(@RequestParam Map params, @PathVariable("catelogId") Long catelogId){ - PageUtils pageUtils = attrService.queryByPage(params, catelogId); + @RequestMapping("/{attrType}/list/{catelogId}") + public R baseList(@RequestParam Map params, + @PathVariable("catelogId") Long catelogId + ,@PathVariable("attrType") String attrType){ + PageUtils pageUtils = attrService.queryByPage(params, catelogId,attrType); return R.ok().put("page",pageUtils); } /** @@ -93,7 +95,9 @@ public class AttrController { @RequestMapping("/delete") //@RequiresPermissions("product:attr:delete") public R delete(@RequestBody Long[] attrIds){ - attrService.removeByIds(Arrays.asList(attrIds)); + + //attrService.removeByIds(Arrays.asList(attrIds)); + attrService.removeByAttrIds(attrIds); return R.ok(); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java index 93d444b..0786fd3 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java @@ -21,10 +21,12 @@ public interface AttrService extends IService { void saveAttr(AttrEntityVO attrEntityVO); - PageUtils queryByPage(Map params, Long catelogId); + PageUtils queryByPage(Map params, Long catelogId, String attrType); AttrResponseVO queryByAttrId(Long attrId); void updateByEntity(AttrEntityVO attrEntityVO); + + void removeByAttrIds(Long[] attrIds); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java index fcbf0fb..683f8f3 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java @@ -1,6 +1,7 @@ package com.carl.mall.product.service.impl; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.carl.common.constant.AttrEnum; import com.carl.mall.product.convert.EntityToVoConvert; import com.carl.mall.product.dao.AttrAttrgroupRelationDao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; @@ -16,6 +17,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -64,23 +66,29 @@ public class AttrServiceImpl extends ServiceImpl implements this.save(attrEntity); //2.保存规格参数和属性组的关联关系 Long attrGroupId = attrEntityVO.getAttrGroupId(); - //查询属性分组中的排序值 - Integer sort = attrGroupService.getById(attrGroupId).getSort(); - if (attrGroupId != null && attrGroupId > 0) { - AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity(); - attrAttrgroupRelationEntity.setAttrGroupId(attrGroupId); - attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId()); //这个是属性的id 必须从实体entity获取 - attrAttrgroupRelationEntity.setAttrSort(sort); //属性分组中的排序 - attrAttrgroupRelationService.save(attrAttrgroupRelationEntity); + //查询属性分组中的排序值 穿过来的属性类型为基本属性才会更新到属性属性组关联表中 + if (!StringUtils.isEmpty(attrGroupId) && Objects.equals(attrEntityVO.getAttrType(), AttrEnum.ATTR_TYPE_BASE.getCode())){ + Integer sort = attrGroupService.getById(attrGroupId).getSort(); + if (attrGroupId > 0) { + AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity(); + attrAttrgroupRelationEntity.setAttrGroupId(attrGroupId); + attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId()); //这个是属性的id 必须从实体entity获取 + attrAttrgroupRelationEntity.setAttrSort(sort); //属性分组中的排序 + attrAttrgroupRelationService.save(attrAttrgroupRelationEntity); + } } + } @Override - public PageUtils queryByPage(Map params, Long catelogId) { + public PageUtils queryByPage(Map params, Long catelogId, String attrType) { QueryWrapper wrapper= new QueryWrapper<>(); + //为1 查attr_type = 1 否则查attr_type = 0 + wrapper.eq("attr_type","base".equalsIgnoreCase(attrType) ? 1 : 0); + if (catelogId != 0) { wrapper.eq("catelog_id",catelogId); } @@ -110,11 +118,17 @@ public class AttrServiceImpl extends ServiceImpl implements if (entity != null) { attrResponseVO.setCatelogName(entity.getName()); } - //设置属性组名称 - AttrAttrgroupRelationEntity attrGroupRelation = attrAttrgroupRelationDao - .selectOne(new QueryWrapper().eq("attr_id", attrEntity.getAttrId())); - String attrGroupName = attrGroupService.getById(attrGroupRelation.getAttrGroupId()).getAttrGroupName(); - attrResponseVO.setGroupName(attrGroupName); + //如果为基本属性参数,则需要返回属性组名称 + if ("base".equalsIgnoreCase(attrType)) { + //设置属性组名称 + AttrAttrgroupRelationEntity attrGroupRelation = attrAttrgroupRelationDao + .selectOne(new QueryWrapper().eq("attr_id", attrEntity.getAttrId())); + //如果attrGroupRelation不为空那就在AttrAttrgroupRelationEntity这个表里查 如果为空就不用查了证明是销售属性 不用给AttrGroupName + if (!StringUtils.isEmpty(attrGroupRelation)) { + String attrGroupName = attrGroupService.getById(attrGroupRelation.getAttrGroupId()).getAttrGroupName(); + attrResponseVO.setGroupName(attrGroupName); + } + } return attrResponseVO; }).collect(Collectors.toList()); pageUtils.setList(collect); @@ -127,13 +141,16 @@ public class AttrServiceImpl extends ServiceImpl implements //找出所属分类和所属分组 AttrEntity attrEntity = this.getById(attrId); AttrResponseVO attrResponseVO = EntityToVoConvert.INSTANCE.attrEntityToResponseVO(attrEntity); - AttrAttrgroupRelationEntity relationEntity = - attrAttrgroupRelationDao.selectOne(new QueryWrapper().eq("attr_id", attrId)); - if (!StringUtils.isEmpty(relationEntity)){ - AttrGroupEntity attrGroupEntity = attrGroupService.getById(relationEntity.getAttrGroupId()); - attrResponseVO.setAttrGroupId(attrGroupEntity.getAttrGroupId()); - if (!StringUtils.isEmpty(attrGroupEntity)) { - attrResponseVO.setGroupName(attrGroupEntity.getAttrGroupName()); + if (attrEntity.getAttrType().equals(AttrEnum.ATTR_TYPE_BASE.getCode())){ + AttrAttrgroupRelationEntity relationEntity = + attrAttrgroupRelationDao.selectOne(new QueryWrapper() + .eq("attr_id", attrId)); + if (!StringUtils.isEmpty(relationEntity)){ + AttrGroupEntity attrGroupEntity = attrGroupService.getById(relationEntity.getAttrGroupId()); + attrResponseVO.setAttrGroupId(attrGroupEntity.getAttrGroupId()); + if (!StringUtils.isEmpty(attrGroupEntity)) { + attrResponseVO.setGroupName(attrGroupEntity.getAttrGroupName()); + } } } Long catelogId = attrEntity.getCatelogId(); @@ -146,18 +163,36 @@ public class AttrServiceImpl extends ServiceImpl implements public void updateByEntity(AttrEntityVO attrEntityVO) { AttrEntity attrEntity = EntityToVoConvert.INSTANCE.attrEntityToVO(attrEntityVO); this.updateById(attrEntity); - AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity(); - relationEntity.setAttrId(attrEntityVO.getAttrId()); - relationEntity.setAttrGroupId(attrEntityVO.getAttrGroupId()); - Integer integer = attrAttrgroupRelationDao - .selectCount(new QueryWrapper() - .eq("attr_id", attrEntityVO.getAttrId())); - if (integer > 0){ - attrAttrgroupRelationDao - .update(relationEntity,new UpdateWrapper() + if (attrEntity.getAttrType().equals(AttrEnum.ATTR_TYPE_BASE.getCode())){ + AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity(); + relationEntity.setAttrId(attrEntityVO.getAttrId()); + relationEntity.setAttrGroupId(attrEntityVO.getAttrGroupId()); + Integer integer = attrAttrgroupRelationDao + .selectCount(new QueryWrapper() .eq("attr_id", attrEntityVO.getAttrId())); - }else { - attrAttrgroupRelationDao.insert(relationEntity); + if (integer > 0){ + attrAttrgroupRelationDao + .update(relationEntity,new UpdateWrapper() + .eq("attr_id", attrEntityVO.getAttrId())); + }else { + attrAttrgroupRelationDao.insert(relationEntity); + } + } + } + + @Override + public void removeByAttrIds(Long[] attrIds) { + for (Long attrId : attrIds) { + AttrEntity attrEntity = this.getById(attrId); + if (attrEntity.getAttrType().equals(AttrEnum.ATTR_TYPE_BASE.getCode())){ + AttrAttrgroupRelationEntity relationEntity = attrAttrgroupRelationDao.selectOne(new QueryWrapper() + .eq("attr_id", attrId)); + attrAttrgroupRelationDao + .delete(new UpdateWrapper() + .eq("attr_id", attrEntity.getAttrId())); + this.removeById(attrId); + } + this.removeById(attrId); } } -- Gitee From 44a01e4838d54fb5a1a93b9b2028158dfb33ff92 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Tue, 11 Jun 2024 22:40:37 +0800 Subject: [PATCH 07/14] =?UTF-8?q?92-=E5=B1=9E=E6=80=A7=E7=BB=84=E5=92=8C?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AttrGroupController.java | 15 +++++++++++- .../product/service/AttrGroupService.java | 3 +++ .../mall/product/service/AttrService.java | 3 +++ .../service/impl/AttrGroupServiceImpl.java | 7 ++++++ .../product/service/impl/AttrServiceImpl.java | 23 +++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java index 673489b..d267015 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java @@ -1,10 +1,13 @@ package com.carl.mall.product.controller; import java.util.Arrays; +import java.util.List; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.mall.product.service.AttrService; import com.carl.mall.product.service.CategoryService; +import com.carl.mall.product.vo.AttrResponseVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -35,6 +38,9 @@ public class AttrGroupController { @Autowired private CategoryService categoryService; + @Autowired + private AttrService attrService; + /** * 列表 * 分页查询 @@ -98,8 +104,15 @@ public class AttrGroupController { //@RequiresPermissions("product:attrgroup:delete") public R delete(@RequestBody Long[] attrGroupIds){ attrGroupService.removeByIds(Arrays.asList(attrGroupIds)); - return R.ok(); } + // /app/product/attrgroup/7/attr/relation?t=1718108299955 + //查询关联关系 + @RequestMapping("/{attrGroupId}/attr/relation") + public R listByAttrRelationGroup(@PathVariable("attrGroupId") Long attrGroupId){ + List responseVOS = attrService.queryByAttrGroupId(attrGroupId); + return R.ok().put("data",responseVOS); + } + } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java index 8290ea9..560a881 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java @@ -3,7 +3,9 @@ package com.carl.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrGroupEntity; +import com.carl.mall.product.vo.AttrResponseVO; +import java.util.List; import java.util.Map; /** @@ -18,5 +20,6 @@ public interface AttrGroupService extends IService { PageUtils queryPage(Map params); PageUtils queryPageWithTree(Map params, Long catelogId); + } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java index 0786fd3..7cff9e9 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java @@ -6,6 +6,7 @@ import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.vo.AttrEntityVO; import com.carl.mall.product.vo.AttrResponseVO; +import java.util.List; import java.util.Map; /** @@ -28,5 +29,7 @@ public interface AttrService extends IService { void updateByEntity(AttrEntityVO attrEntityVO); void removeByAttrIds(Long[] attrIds); + + List queryByAttrGroupId(Long attrGroupId); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java index bb84524..00215c9 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java @@ -1,6 +1,9 @@ package com.carl.mall.product.service.impl; + import org.springframework.stereotype.Service; + + import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -17,6 +20,8 @@ import org.springframework.util.StringUtils; @Service("attrGroupService") public class AttrGroupServiceImpl extends ServiceImpl implements AttrGroupService { + + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -71,4 +76,6 @@ public class AttrGroupServiceImpl extends ServiceImpl implements @Autowired private CategoryService categoryService; + @Autowired + private AttrService attrService; + @Autowired private AttrAttrgroupRelationDao attrAttrgroupRelationDao; @Override @@ -196,4 +200,23 @@ public class AttrServiceImpl extends ServiceImpl implements } } + @Override + public List queryByAttrGroupId(Long attrGroupId) { + List attrResponseVOS = null; + if (!StringUtils.isEmpty(attrGroupId)){ + List relationEntities = attrAttrgroupRelationDao + .selectList(new QueryWrapper().eq("attr_group_id", attrGroupId)); + attrResponseVOS = relationEntities + .stream() + .filter(Objects::nonNull) + .map((e) -> { + AttrEntity attrEntity = attrService.getById(e.getAttrId()); + AttrResponseVO attrResponseVO = EntityToVoConvert.INSTANCE.attrEntityToResponseVO(attrEntity); + return attrResponseVO; + }).collect(Collectors.toList()); + } + return attrResponseVOS; + + } + } \ No newline at end of file -- Gitee From 98a7d64c024ca43bae61d97fd878f84abcc11b55 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Wed, 12 Jun 2024 23:55:02 +0800 Subject: [PATCH 08/14] =?UTF-8?q?95-=E5=B1=9E=E6=80=A7=E7=BB=84=E5=92=8C?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=85=B3=E8=81=94-=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=9C=AA=E5=85=B3=E8=81=94=E5=B1=9E=E6=80=A7=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AttrGroupController.java | 26 ++++++-- .../product/dao/AttrAttrgroupRelationDao.java | 6 +- .../mall/product/service/AttrService.java | 5 ++ .../service/impl/AttrGroupServiceImpl.java | 8 +++ .../product/service/impl/AttrServiceImpl.java | 60 +++++++++++++++++-- .../mall/product/vo/AttrGroupRelationVO.java | 15 +++++ .../product/AttrAttrgroupRelationDao.xml | 10 ++++ 7 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupRelationVO.java diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java index d267015..c48f9cd 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java @@ -7,13 +7,10 @@ import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; import com.carl.mall.product.service.AttrService; import com.carl.mall.product.service.CategoryService; +import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; 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 org.springframework.web.bind.annotation.*; import com.carl.mall.product.entity.AttrGroupEntity; import com.carl.mall.product.service.AttrGroupService; @@ -41,6 +38,7 @@ public class AttrGroupController { @Autowired private AttrService attrService; + /** * 列表 * 分页查询 @@ -115,4 +113,22 @@ public class AttrGroupController { return R.ok().put("data",responseVOS); } + ///product/attrgroup/attr/relation/delete 接触关联关系 + @PostMapping("/attr/relation/delete") + public R removeByEntity(@RequestBody AttrGroupRelationVO[] vos){ + attrService.deleteRelation(vos); + return R.ok(); + } + + ///app/product/attrgroup/7/noattr/relation? 查询未关联属性 + @RequestMapping("/{attrGroupId}/noattr/relation") + public R listNoAttr(@RequestParam Map params, + @PathVariable("attrGroupId") Long attrGroupId){ + PageUtils page = attrService.queryPageWithTreeNoAttr(params,attrGroupId); + return R.ok().put("page", page); + } + + + + } diff --git a/mall-product/src/main/java/com/carl/mall/product/dao/AttrAttrgroupRelationDao.java b/mall-product/src/main/java/com/carl/mall/product/dao/AttrAttrgroupRelationDao.java index 20f3cdd..953dbf5 100644 --- a/mall-product/src/main/java/com/carl/mall/product/dao/AttrAttrgroupRelationDao.java +++ b/mall-product/src/main/java/com/carl/mall/product/dao/AttrAttrgroupRelationDao.java @@ -3,6 +3,9 @@ package com.carl.mall.product.dao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 属性&属性分组关联 @@ -13,5 +16,6 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface AttrAttrgroupRelationDao extends BaseMapper { - + + void removeByBatchIds(@Param("entityList") List entityList); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java index 7cff9e9..e43c452 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; import java.util.List; @@ -31,5 +32,9 @@ public interface AttrService extends IService { void removeByAttrIds(Long[] attrIds); List queryByAttrGroupId(Long attrGroupId); + + void deleteRelation(AttrGroupRelationVO[] vos); + + PageUtils queryPageWithTreeNoAttr(Map params, Long attrGroupId); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java index 00215c9..7c5b38f 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java @@ -1,10 +1,18 @@ package com.carl.mall.product.service.impl; +import com.carl.common.constant.AttrEnum; +import com.carl.mall.product.dao.AttrAttrgroupRelationDao; +import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; +import com.carl.mall.product.entity.AttrEntity; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java index c0e4481..b5d4850 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.carl.common.constant.AttrEnum; import com.carl.mall.product.convert.EntityToVoConvert; import com.carl.mall.product.dao.AttrAttrgroupRelationDao; +import com.carl.mall.product.dao.AttrGroupDao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; import com.carl.mall.product.entity.AttrGroupEntity; import com.carl.mall.product.entity.CategoryEntity; @@ -11,14 +12,13 @@ import com.carl.mall.product.service.AttrAttrgroupRelationService; import com.carl.mall.product.service.AttrGroupService; import com.carl.mall.product.service.CategoryService; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -50,6 +50,9 @@ public class AttrServiceImpl extends ServiceImpl implements @Autowired private AttrService attrService; + @Autowired + private AttrGroupDao attrGroupDao; + @Autowired private AttrAttrgroupRelationDao attrAttrgroupRelationDao; @Override @@ -219,4 +222,53 @@ public class AttrServiceImpl extends ServiceImpl implements } + @Override + public void deleteRelation(AttrGroupRelationVO[] vos) { + List entityList = Arrays.asList(vos).stream().map((item) -> { + AttrAttrgroupRelationEntity entity = new AttrAttrgroupRelationEntity(); + BeanUtils.copyProperties(item, entity); + return entity; + }).collect(Collectors.toList()); + //批量删除关联数据 + //attrAttrgroupRelationDao.deleteBatchIds(entityList); + attrAttrgroupRelationDao.removeByBatchIds(entityList); + } + + @Override + public PageUtils queryPageWithTreeNoAttr(Map params, Long attrGroupId) { + //通过分组id在查出分组表的实体 + AttrGroupEntity groupEntity = attrGroupService.getById(attrGroupId); + //根据这个分组表的实体查到其分类id + Long catelogId = groupEntity.getCatelogId(); + //找到这个类别下的所有分组信息 + List attrGroupEntities = attrGroupDao + .selectList(new QueryWrapper().eq("catelog_id", catelogId)); + //获取所有分组的ids + List groupIds = attrGroupEntities.stream().map(AttrGroupEntity::getAttrGroupId) + .collect(Collectors.toList()); + //找出关联表的所有关联实体类的信息 + List relationEntities = attrAttrgroupRelationDao + .selectList(new QueryWrapper().in("attr_group_id", groupIds)); + //通过这个实体找到分类的id + List attrIds = relationEntities.stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList()); + //构造查询条件 是base的 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("catelog_id",catelogId) + .eq("attr_type", AttrEnum.ATTR_TYPE_BASE.getCode()); + //如果中间表里没有数据则就是表明还没有关联,只需要在排除上面的attrIds + if (!attrIds.isEmpty()){ + wrapper.notIn("attr_id",attrIds); + } + String key = (String) params.get("key"); + if(!StringUtils.isEmpty(key)){ + wrapper.and((w)->{ + w.eq("attr_id",key).or().like("attr_name",key); + }); + } + IPage page = this.page( + new Query().getPage(params), wrapper); + + return new PageUtils(page); + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupRelationVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupRelationVO.java new file mode 100644 index 0000000..bdea115 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupRelationVO.java @@ -0,0 +1,15 @@ +package com.carl.mall.product.vo; + + +import lombok.Data; + +@Data +public class AttrGroupRelationVO { + + private Long attrId; + + + private Long attrGroupId; + + +} diff --git a/mall-product/src/main/resources/mapper/product/AttrAttrgroupRelationDao.xml b/mall-product/src/main/resources/mapper/product/AttrAttrgroupRelationDao.xml index 50fc712..e066cd6 100644 --- a/mall-product/src/main/resources/mapper/product/AttrAttrgroupRelationDao.xml +++ b/mall-product/src/main/resources/mapper/product/AttrAttrgroupRelationDao.xml @@ -11,5 +11,15 @@ + + DELETE from pms_attr_attrgroup_relation + + + (attr_id = #{item.attrId} and attr_group_id = #{item.attrGroupId}) + + + + + \ No newline at end of file -- Gitee From 732497c67175d09090d2148fa577464455c24617 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Thu, 13 Jun 2024 17:51:29 +0800 Subject: [PATCH 09/14] =?UTF-8?q?98-=E6=96=B0=E5=A2=9E=E5=95=86=E5=93=81,?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=92=8C=E5=93=81=E7=89=8C=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AttrGroupController.java | 14 +++++++++++ .../CategoryBrandRelationController.java | 2 +- .../product/convert/EntityToVoConvert.java | 7 ++++++ .../service/AttrAttrgroupRelationService.java | 4 ++++ .../product/service/AttrGroupService.java | 1 + .../AttrAttrgroupRelationServiceImpl.java | 23 +++++++++++++++++++ .../service/impl/AttrGroupServiceImpl.java | 11 +++++++++ .../CategoryBrandRelationServiceImpl.java | 5 ++++ 8 files changed, 66 insertions(+), 1 deletion(-) diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java index c48f9cd..6923575 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.mall.product.service.AttrAttrgroupRelationService; import com.carl.mall.product.service.AttrService; import com.carl.mall.product.service.CategoryService; import com.carl.mall.product.vo.AttrGroupRelationVO; @@ -38,6 +39,19 @@ public class AttrGroupController { @Autowired private AttrService attrService; + @Autowired + private AttrAttrgroupRelationService attrAttrgroupRelationService; + + + /** + * 新建关联 + * /product/attrgroup/attr/relation + */ + @PostMapping("/attr/relation") + public R addAttrAttrGroupRelation(@RequestBody List relationVOList){ + attrAttrgroupRelationService.addAttrAttrGroupRelation(relationVOList); + return R.ok(); + } /** * 列表 diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/CategoryBrandRelationController.java b/mall-product/src/main/java/com/carl/mall/product/controller/CategoryBrandRelationController.java index d44116a..5aee018 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/CategoryBrandRelationController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/CategoryBrandRelationController.java @@ -47,7 +47,7 @@ public class CategoryBrandRelationController { } @GetMapping("/brands/list") - public R categoryBrandRelation(@RequestParam(value = "catId",required = true,defaultValue = "0") Long catId){ + public R categoryBrandRelation(@RequestParam(value = "catId",required = true) Long catId){ List list = categoryBrandRelationService.categroyBrandRelation(catId); return R.ok().put("data",list); } diff --git a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java index 49ff79e..5f23acd 100644 --- a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java +++ b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java @@ -1,12 +1,16 @@ package com.carl.mall.product.convert; +import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; +import java.util.List; + @Mapper public interface EntityToVoConvert { EntityToVoConvert INSTANCE = Mappers.getMapper(EntityToVoConvert.class); @@ -15,5 +19,8 @@ public interface EntityToVoConvert { AttrResponseVO attrEntityToResponseVO(AttrEntity attrEntity); + List attrGroupRelationVOTOEntityList(List relationVOList); + + AttrAttrgroupRelationEntity AttrAttrgroupRelationEntity(AttrGroupRelationVO attrGroupRelationVO); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java index 0fa3f2a..ac831ea 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrAttrgroupRelationService.java @@ -4,7 +4,9 @@ package com.carl.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; +import com.carl.mall.product.vo.AttrGroupRelationVO; +import java.util.List; import java.util.Map; /** @@ -18,5 +20,7 @@ public interface AttrAttrgroupRelationService extends IService params); + void addAttrAttrGroupRelation(List relationVOList); + } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java index 560a881..9a9c7b2 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java @@ -3,6 +3,7 @@ package com.carl.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrGroupEntity; +import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; import java.util.List; diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java index be97809..3c60b5a 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java @@ -1,7 +1,15 @@ package com.carl.mall.product.service.impl; +import com.carl.mall.product.convert.EntityToVoConvert; +import com.carl.mall.product.dao.AttrGroupDao; +import com.carl.mall.product.vo.AttrGroupRelationVO; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -16,6 +24,10 @@ import com.carl.mall.product.service.AttrAttrgroupRelationService; @Service("attrAttrgroupRelationService") public class AttrAttrgroupRelationServiceImpl extends ServiceImpl implements AttrAttrgroupRelationService { + + @Autowired + private AttrGroupDao attrGroupDao; + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +38,15 @@ public class AttrAttrgroupRelationServiceImpl extends ServiceImpl relationVOList) { + List attrgroupRelationEntities = relationVOList.stream().map((e) -> { + AttrAttrgroupRelationEntity relationEntity = EntityToVoConvert.INSTANCE.AttrAttrgroupRelationEntity(e); + Integer sort = attrGroupDao.selectById(relationEntity.getAttrGroupId()).getSort(); + relationEntity.setAttrSort(sort); + return relationEntity; + }).collect(Collectors.toList()); + this.saveBatch(attrgroupRelationEntities); + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java index 7c5b38f..5bc8468 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java @@ -2,9 +2,13 @@ package com.carl.mall.product.service.impl; import com.carl.common.constant.AttrEnum; +import com.carl.mall.product.convert.EntityToVoConvert; import com.carl.mall.product.dao.AttrAttrgroupRelationDao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; import com.carl.mall.product.entity.AttrEntity; +import com.carl.mall.product.service.AttrService; +import com.carl.mall.product.vo.AttrGroupRelationVO; +import com.google.common.base.Preconditions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +33,12 @@ import org.springframework.util.StringUtils; public class AttrGroupServiceImpl extends ServiceImpl implements AttrGroupService { + @Autowired + private AttrAttrgroupRelationDao attrAttrgroupRelationDao; + + @Autowired + private AttrGroupDao attrGroupDao; + @Override public PageUtils queryPage(Map params) { @@ -86,4 +96,5 @@ public class AttrGroupServiceImpl extends ServiceImpl categroyBrandRelation(Long catId) { // 找到所有的品牌信息 -- Gitee From 0f3e03180a256094d5c35c0bdcf8f3ae550ef22c Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Thu, 13 Jun 2024 21:58:31 +0800 Subject: [PATCH 10/14] =?UTF-8?q?102-=E8=A7=84=E6=A0=BC=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberLevelController.java | 1 - .../src/main/resources/application.yml | 46 ++++++++--------- .../src/main/resources/bootstrap.properties | 20 +++++++- .../controller/AttrGroupController.java | 10 ++++ .../product/convert/EntityToVoConvert.java | 5 ++ .../product/service/AttrGroupService.java | 2 + .../service/impl/AttrGroupServiceImpl.java | 28 ++++++++-- .../product/vo/AttrGroupAttrResponseVO.java | 51 +++++++++++++++++++ 8 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupAttrResponseVO.java diff --git a/mall-member/src/main/java/com/carl/mall/member/controller/MemberLevelController.java b/mall-member/src/main/java/com/carl/mall/member/controller/MemberLevelController.java index fd5e4ed..2de95ea 100644 --- a/mall-member/src/main/java/com/carl/mall/member/controller/MemberLevelController.java +++ b/mall-member/src/main/java/com/carl/mall/member/controller/MemberLevelController.java @@ -38,7 +38,6 @@ public class MemberLevelController { //@RequiresPermissions("member:memberlevel:list") public R list(@RequestParam Map params){ PageUtils page = memberLevelService.queryPage(params); - return R.ok().put("page", page); } diff --git a/mall-member/src/main/resources/application.yml b/mall-member/src/main/resources/application.yml index 3fec578..ab0d932 100644 --- a/mall-member/src/main/resources/application.yml +++ b/mall-member/src/main/resources/application.yml @@ -1,23 +1,23 @@ -server: - port: 9002 -# 数据库的连接新 -spring: - datasource: - username: root - password: 123456 - url: jdbc:mysql://192.168.73.130:12345/mall-ums - driver-class-name: com.mysql.cj.jdbc.Driver - cloud: - nacos: - discovery: - server-addr: 192.168.73.130:8848 - application: - name: mall-member - - -#mybatis-plus 配置 -mybatis-plus: - mapper-locations: classpath*:/mapper/**/*.xml - global-config: - db-config: - id-type: auto # 主键自增 \ No newline at end of file +#server: +# port: 9002 +## 数据库的连接新 +#spring: +# datasource: +# username: root +# password: 123456 +# url: jdbc:mysql://192.168.73.130:12345/mall-ums +# driver-class-name: com.mysql.cj.jdbc.Driver +# cloud: +# nacos: +# discovery: +# server-addr: 192.168.73.130:8848 +# application: +# name: mall-member +# +# +##mybatis-plus 配置 +#mybatis-plus: +# mapper-locations: classpath*:/mapper/**/*.xml +# global-config: +# db-config: +# id-type: auto # 主键自增 \ No newline at end of file diff --git a/mall-member/src/main/resources/bootstrap.properties b/mall-member/src/main/resources/bootstrap.properties index 61352dc..92536ee 100644 --- a/mall-member/src/main/resources/bootstrap.properties +++ b/mall-member/src/main/resources/bootstrap.properties @@ -1,3 +1,21 @@ #nacos config spring.cloud.nacos.config.server-addr=192.168.73.130:8848 -spring.application.name= mall-member \ No newline at end of file +spring.application.name=mall-member + +#\u6307\u5B9A\u4F7F\u7528\u7684\u547D\u540D\u7A7A\u95F4 +spring.cloud.nacos.config.namespace=eeac7511-c039-4902-bacc-90c09b896404 + +#\u6307\u5B9A\u5BF9\u5E94\u7684\u914D\u7F6E\u7EC4 +spring.cloud.nacos.config.group=prod +#\u914D\u7F6E\u591A\u4E2A\u914D\u7F6E\u96C6 +spring.cloud.nacos.config.ext-config[0].data-id=mybatis.yml +spring.cloud.nacos.config.ext-config[0].group=prod +spring.cloud.nacos.config.ext-config[0].refresh=false + +spring.cloud.nacos.config.ext-config[1].data-id=datasource.yml +spring.cloud.nacos.config.ext-config[1].group=prod +spring.cloud.nacos.config.ext-config[1].refresh=false + +spring.cloud.nacos.config.ext-config[2].data-id=other.yml +spring.cloud.nacos.config.ext-config[2].group=prod +spring.cloud.nacos.config.ext-config[2].refresh=false \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java index 6923575..f916a46 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrGroupController.java @@ -8,6 +8,7 @@ import java.util.Map; import com.carl.mall.product.service.AttrAttrgroupRelationService; import com.carl.mall.product.service.AttrService; import com.carl.mall.product.service.CategoryService; +import com.carl.mall.product.vo.AttrGroupAttrResponseVO; import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; import org.springframework.beans.factory.annotation.Autowired; @@ -52,6 +53,15 @@ public class AttrGroupController { attrAttrgroupRelationService.addAttrAttrGroupRelation(relationVOList); return R.ok(); } + /** + * 根据分类id获得属性组和属性信息 + */ + @RequestMapping ("/{catelogId}/withattr") + public R getAttrGroupAndAttr(@PathVariable("catelogId") Long catelogId){ + //根据三级分类id查询属性和属性组信息 + List attrGroupAndAttr = attrGroupService.getAttrGroupAndAttr(catelogId); + return R.ok().put("data", attrGroupAndAttr); + } /** * 列表 diff --git a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java index 5f23acd..b693000 100644 --- a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java +++ b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java @@ -3,7 +3,9 @@ package com.carl.mall.product.convert; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; import com.carl.mall.product.entity.AttrEntity; +import com.carl.mall.product.entity.AttrGroupEntity; import com.carl.mall.product.vo.AttrEntityVO; +import com.carl.mall.product.vo.AttrGroupAttrResponseVO; import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; import org.mapstruct.Mapper; @@ -23,4 +25,7 @@ public interface EntityToVoConvert { AttrAttrgroupRelationEntity AttrAttrgroupRelationEntity(AttrGroupRelationVO attrGroupRelationVO); + + + AttrGroupAttrResponseVO attrGroupAttrEnToVo(AttrGroupEntity attrGroupEntity); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java index 9a9c7b2..bc080ed 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/AttrGroupService.java @@ -3,6 +3,7 @@ package com.carl.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.AttrGroupEntity; +import com.carl.mall.product.vo.AttrGroupAttrResponseVO; import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; @@ -22,5 +23,6 @@ public interface AttrGroupService extends IService { PageUtils queryPageWithTree(Map params, Long catelogId); + List getAttrGroupAndAttr(Long catelogId); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java index 5bc8468..ca93bb1 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/AttrGroupServiceImpl.java @@ -1,14 +1,12 @@ package com.carl.mall.product.service.impl; -import com.carl.common.constant.AttrEnum; import com.carl.mall.product.convert.EntityToVoConvert; import com.carl.mall.product.dao.AttrAttrgroupRelationDao; import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; -import com.carl.mall.product.entity.AttrEntity; import com.carl.mall.product.service.AttrService; -import com.carl.mall.product.vo.AttrGroupRelationVO; -import com.google.common.base.Preconditions; +import com.carl.mall.product.vo.AttrGroupAttrResponseVO; +import com.carl.mall.product.vo.AttrResponseVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -39,6 +38,9 @@ public class AttrGroupServiceImpl extends ServiceImpl params) { @@ -94,7 +96,23 @@ public class AttrGroupServiceImpl extends ServiceImpl getAttrGroupAndAttr(Long catelogId) { + //在属性分组表中通过分类的id查出分组的信息 + List attrGroupEntities = attrGroupDao.selectList(new QueryWrapper().eq("catelog_id", catelogId)); + List list = attrGroupEntities.stream().map((group)->{ + //将每一个分组的信息转换成响应体 + AttrGroupAttrResponseVO attrGroupAttrResponseVO = EntityToVoConvert.INSTANCE.attrGroupAttrEnToVo(group); + //通过分组id查出所有分类的信息 + List attrResponseVOList = attrService.queryByAttrGroupId(group.getAttrGroupId()); + //设置一个分组下的规格参数 + attrGroupAttrResponseVO.setAttrs(attrResponseVOList); + //返回这个分组下的规格参数信息 + return attrGroupAttrResponseVO; + }).collect(Collectors.toList()); + + return list; + } } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupAttrResponseVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupAttrResponseVO.java new file mode 100644 index 0000000..1874d23 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/AttrGroupAttrResponseVO.java @@ -0,0 +1,51 @@ +package com.carl.mall.product.vo; + + +import com.baomidou.mybatisplus.annotation.TableId; +import com.carl.mall.product.entity.AttrEntity; +import lombok.Data; + + +import java.util.List; + +/** + * 属性分组 + * + * @author carl + * @email 541020344@qq.com + * @date 2024-03-09 23:50:01 + */ +@Data +public class AttrGroupAttrResponseVO{ + + /** + * 分组id + */ + @TableId + private Long attrGroupId; + /** + * 组名 + */ + private String attrGroupName; + /** + * 排序 + */ + private Integer sort; + /** + * 描述 + */ + private String descript; + /** + * 组图标 + */ + private String icon; + /** + * 所属分类id + */ + private Long catelogId; + + // 关联对应的属性信息 + private List attrs; + + +} -- Gitee From fc078c775101bd3caaca0a16da75a26fb98e1bc7 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Sun, 16 Jun 2024 23:09:42 +0800 Subject: [PATCH 11/14] =?UTF-8?q?117-=E5=95=86=E5=93=81=E6=9C=8D=E5=8A=A1-?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=95=86=E5=93=81=E8=B0=83=E8=AF=95=EF=BC=88?= =?UTF-8?q?=E4=B8=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mall-commons/pom.xml | 6 + .../java/com/carl/common/dto/MemberPrice.java | 21 +++ .../com/carl/common/dto/SkuReductionDTO.java | 24 +++ .../com/carl/common/dto/SpuBoundsDTO.java | 14 ++ .../main/java/com/carl/common/utils/R.java | 4 + .../java/com/carl/common/utils/splitUrl.java | 23 +++ .../SkuFullReductionController.java | 21 ++- .../controller/SkuLadderController.java | 2 - .../controller/SpuBoundsController.java | 13 +- .../mall/coupon/convert/CouponConvert.java | 14 ++ .../service/SkuFullReductionService.java | 3 + .../mall/coupon/service/SpuBoundsService.java | 3 + .../impl/SkuFullReductionServiceImpl.java | 85 +++++++++ .../service/impl/SpuBoundsServiceImpl.java | 11 ++ .../src/main/resources/application.yml | 46 ++--- .../src/main/resources/bootstrap.properties | 20 ++- mall-product/pom.xml | 4 + .../mall/product/MallProductApplication.java | 2 + .../product/controller/SpuInfoController.java | 17 +- .../product/convert/EntityToVoConvert.java | 17 +- .../product/entity/SpuInfoDescEntity.java | 3 +- .../product/feign/CouponFeignService.java | 30 ++++ .../mall/product/service/SpuInfoService.java | 3 + .../service/impl/SpuInfoServiceImpl.java | 163 +++++++++++++++++- .../com/carl/mall/product/vo/skuvo/Attr.java | 19 ++ .../carl/mall/product/vo/skuvo/BaseAttrs.java | 16 ++ .../carl/mall/product/vo/skuvo/Bounds.java | 21 +++ .../carl/mall/product/vo/skuvo/Images.java | 16 ++ .../mall/product/vo/skuvo/MemberPrice.java | 21 +++ .../com/carl/mall/product/vo/skuvo/Skus.java | 39 +++++ .../carl/mall/product/vo/skuvo/SpuInfoVO.java | 28 +++ 31 files changed, 663 insertions(+), 46 deletions(-) create mode 100644 mall-commons/src/main/java/com/carl/common/dto/MemberPrice.java create mode 100644 mall-commons/src/main/java/com/carl/common/dto/SkuReductionDTO.java create mode 100644 mall-commons/src/main/java/com/carl/common/dto/SpuBoundsDTO.java create mode 100644 mall-commons/src/main/java/com/carl/common/utils/splitUrl.java create mode 100644 mall-coupon/src/main/java/com/carl/mall/coupon/convert/CouponConvert.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/feign/CouponFeignService.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Attr.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/BaseAttrs.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Bounds.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Images.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/MemberPrice.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Skus.java create mode 100644 mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java diff --git a/mall-commons/pom.xml b/mall-commons/pom.xml index 7cc5704..bec1ef3 100644 --- a/mall-commons/pom.xml +++ b/mall-commons/pom.xml @@ -83,6 +83,12 @@ mapstruct-processor 1.4.2.Final + + com.alibaba + fastjson + 2.0.28 + + diff --git a/mall-commons/src/main/java/com/carl/common/dto/MemberPrice.java b/mall-commons/src/main/java/com/carl/common/dto/MemberPrice.java new file mode 100644 index 0000000..fb097aa --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/dto/MemberPrice.java @@ -0,0 +1,21 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.common.dto; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 会员价格 + */ +@Data +public class MemberPrice { + + private Long id; //会员等级id + private String name; //会员等级名 + private BigDecimal price; //会员对应价格 + + +} \ No newline at end of file diff --git a/mall-commons/src/main/java/com/carl/common/dto/SkuReductionDTO.java b/mall-commons/src/main/java/com/carl/common/dto/SkuReductionDTO.java new file mode 100644 index 0000000..c2003a4 --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/dto/SkuReductionDTO.java @@ -0,0 +1,24 @@ +package com.carl.common.dto; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; +@Data +public class SkuReductionDTO { + private Long skuId; + /* mall-sms sms_sku_ladder */ + //设置满减 + private int fullCount; //满几件 + private BigDecimal discount; //打几折 + private int countStatus; //数量状况 + /* mall-sms sms_sku_full_reduction */ + //设置折扣 + private BigDecimal fullPrice; //满多少 + private BigDecimal reducePrice; //降多少 + private int priceStatus; //价格状况 + /* mall-sms sms_member_price */ + //设置会员价 + private List memberPrice; + +} diff --git a/mall-commons/src/main/java/com/carl/common/dto/SpuBoundsDTO.java b/mall-commons/src/main/java/com/carl/common/dto/SpuBoundsDTO.java new file mode 100644 index 0000000..3962c3c --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/dto/SpuBoundsDTO.java @@ -0,0 +1,14 @@ +package com.carl.common.dto; + + +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class SpuBoundsDTO { + + private Long spuId; + private BigDecimal buyBounds; //金币 + private BigDecimal growBounds; //成长值 +} diff --git a/mall-commons/src/main/java/com/carl/common/utils/R.java b/mall-commons/src/main/java/com/carl/common/utils/R.java index 9f8cf7d..084f706 100644 --- a/mall-commons/src/main/java/com/carl/common/utils/R.java +++ b/mall-commons/src/main/java/com/carl/common/utils/R.java @@ -61,4 +61,8 @@ public class R extends HashMap { super.put(key, value); return this; } + + public Integer getCode() { + return (Integer) this.get("code"); + } } diff --git a/mall-commons/src/main/java/com/carl/common/utils/splitUrl.java b/mall-commons/src/main/java/com/carl/common/utils/splitUrl.java new file mode 100644 index 0000000..bdc13c5 --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/utils/splitUrl.java @@ -0,0 +1,23 @@ +package com.carl.common.utils; + + +/** + * 截取url当中的图片名字 + */ +public class splitUrl { + + public String urlSplit(String s){ + // 找到第一个 '_' 的位置 + int underscoreIndex = s.indexOf('_'); + // 从 '_' 后的第一个字符开始截取直到字符串结束 + return s.substring(underscoreIndex + 1); + } + + + public static void main(String[] args) { + String s = "https://xinxing-mall.oss-cn-beijing.aliyuncs.com/2024-06-14//f72073be-c944-4dd8-8dd6-57c5d773d73e_华为mate60-紫.png"; + String s1 = new splitUrl().urlSplit(s); + System.out.println(s1); + } + +} diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuFullReductionController.java b/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuFullReductionController.java index 2b49315..515191d 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuFullReductionController.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuFullReductionController.java @@ -4,12 +4,9 @@ import java.util.Arrays; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.common.dto.SkuReductionDTO; 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 org.springframework.web.bind.annotation.*; import com.carl.mall.coupon.entity.SkuFullReductionEntity; import com.carl.mall.coupon.service.SkuFullReductionService; @@ -31,6 +28,20 @@ public class SkuFullReductionController { @Autowired private SkuFullReductionService skuFullReductionService; + + /** + * mall-product 服务调用的满减接口 + * @param skuReductionDTO + * @return + */ + @PostMapping("/saveInfo") + public R saveFullReductionInfo(@RequestBody SkuReductionDTO skuReductionDTO){ + skuFullReductionService.saveSkuReduction(skuReductionDTO); + return R.ok(); + } + + + /** * 列表 */ diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuLadderController.java b/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuLadderController.java index 9608315..753c966 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuLadderController.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SkuLadderController.java @@ -50,7 +50,6 @@ public class SkuLadderController { //@RequiresPermissions("coupon:skuladder:info") public R info(@PathVariable("id") Long id){ SkuLadderEntity skuLadder = skuLadderService.getById(id); - return R.ok().put("skuLadder", skuLadder); } @@ -61,7 +60,6 @@ public class SkuLadderController { //@RequiresPermissions("coupon:skuladder:save") public R save(@RequestBody SkuLadderEntity skuLadder){ skuLadderService.save(skuLadder); - return R.ok(); } diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SpuBoundsController.java b/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SpuBoundsController.java index 04fd918..7bf691e 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SpuBoundsController.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/controller/SpuBoundsController.java @@ -4,12 +4,9 @@ import java.util.Arrays; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.common.dto.SpuBoundsDTO; 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 org.springframework.web.bind.annotation.*; import com.carl.mall.coupon.entity.SpuBoundsEntity; import com.carl.mall.coupon.service.SpuBoundsService; @@ -54,6 +51,12 @@ public class SpuBoundsController { return R.ok().put("spuBounds", spuBounds); } + + @PostMapping("/saveBoundInfo") + public R saveBoundInfo(@RequestBody SpuBoundsDTO spuBoundsDTO){ + spuBoundsService.saveBoundInfo(spuBoundsDTO); + return R.ok(); + } /** * 保存 */ diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/convert/CouponConvert.java b/mall-coupon/src/main/java/com/carl/mall/coupon/convert/CouponConvert.java new file mode 100644 index 0000000..2b534df --- /dev/null +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/convert/CouponConvert.java @@ -0,0 +1,14 @@ +package com.carl.mall.coupon.convert; + + +import com.carl.common.dto.SkuReductionDTO; +import com.carl.mall.coupon.entity.SkuFullReductionEntity; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CouponConvert { + CouponConvert INSTANCE = Mappers.getMapper(CouponConvert.class); + + SkuFullReductionEntity skuReductionDTOTOSkuFullReductionEntity(SkuReductionDTO skuReductionDTO); +} diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/service/SkuFullReductionService.java b/mall-coupon/src/main/java/com/carl/mall/coupon/service/SkuFullReductionService.java index f22f5be..913bd6f 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/service/SkuFullReductionService.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/service/SkuFullReductionService.java @@ -1,6 +1,7 @@ package com.carl.mall.coupon.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.carl.common.dto.SkuReductionDTO; import com.carl.common.utils.PageUtils; import com.carl.mall.coupon.entity.SkuFullReductionEntity; @@ -16,5 +17,7 @@ import java.util.Map; public interface SkuFullReductionService extends IService { PageUtils queryPage(Map params); + + void saveSkuReduction(SkuReductionDTO skuReductionDTO); } diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/service/SpuBoundsService.java b/mall-coupon/src/main/java/com/carl/mall/coupon/service/SpuBoundsService.java index 897ab89..cfdf1cb 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/service/SpuBoundsService.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/service/SpuBoundsService.java @@ -1,6 +1,7 @@ package com.carl.mall.coupon.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.carl.common.dto.SpuBoundsDTO; import com.carl.common.utils.PageUtils; import com.carl.mall.coupon.entity.SpuBoundsEntity; @@ -16,5 +17,7 @@ import java.util.Map; public interface SpuBoundsService extends IService { PageUtils queryPage(Map params); + + void saveBoundInfo(SpuBoundsDTO spuBoundsDTO); } diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java b/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java index a030297..c63f187 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java @@ -1,7 +1,19 @@ package com.carl.mall.coupon.service.impl; +import com.carl.common.dto.SkuReductionDTO; +import com.carl.mall.coupon.convert.CouponConvert; +import com.carl.mall.coupon.entity.MemberPriceEntity; +import com.carl.mall.coupon.entity.SkuLadderEntity; +import com.carl.mall.coupon.service.MemberPriceService; +import com.carl.mall.coupon.service.SkuLadderService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -16,6 +28,17 @@ import com.carl.mall.coupon.service.SkuFullReductionService; @Service("skuFullReductionService") public class SkuFullReductionServiceImpl extends ServiceImpl implements SkuFullReductionService { + + @Autowired + private SkuFullReductionService skuFullReductionService; + + + @Autowired + private SkuLadderService skuLadderService; + + + @Autowired + private MemberPriceService memberPriceService; @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +49,66 @@ public class SkuFullReductionServiceImpl extends ServiceImpl 0 && skuReductionDTO.getFullPrice().compareTo(new BigDecimal(0)) > 0){ + skuLadderEntity.setSkuId(skuReductionDTO.getSkuId()); + skuLadderEntity.setDiscount(skuReductionDTO.getDiscount()); + skuLadderEntity.setFullCount(skuReductionDTO.getFullCount()); + skuLadderEntity.setAddOther(skuReductionDTO.getCountStatus()); + skuLadderService.save(skuLadderEntity); + } + /* + * 满多少元打几折 + */ + ///////////////////////////////////////////////////// + SkuFullReductionEntity skuFullReductionEntity = new SkuFullReductionEntity(); + skuFullReductionEntity.setSkuId(skuReductionDTO.getSkuId()); + if (skuReductionDTO.getFullPrice().compareTo(new BigDecimal(0)) > 0 && skuReductionDTO.getFullCount()>0){ + skuFullReductionEntity.setFullPrice(skuReductionDTO.getFullPrice()); + skuFullReductionEntity.setReducePrice(skuReductionDTO.getReducePrice()); + skuFullReductionEntity.setAddOther(skuReductionDTO.getCountStatus()); + skuFullReductionService.save(skuFullReductionEntity); + } + /* + * 会员价 + */ + if (skuReductionDTO.getMemberPrice() != null && !skuReductionDTO.getMemberPrice().isEmpty()){ + List memberPriceEntities = skuReductionDTO.getMemberPrice().stream().map((member) -> { + MemberPriceEntity memberPriceEntity = new MemberPriceEntity(); + memberPriceEntity.setAddOther(1); //是否可叠加 前端暂时没有 + memberPriceEntity.setSkuId(skuReductionDTO.getSkuId()); + memberPriceEntity.setMemberLevelId(member.getId()); + memberPriceEntity.setMemberLevelName(member.getName()); + memberPriceEntity.setMemberPrice(member.getPrice()); + return memberPriceEntity; + }).collect(Collectors.toList()); + memberPriceService.saveBatch(memberPriceEntities); + } + + + } + + + + + + + + + + + + + + } \ No newline at end of file diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SpuBoundsServiceImpl.java b/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SpuBoundsServiceImpl.java index b02321d..38561e9 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SpuBoundsServiceImpl.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SpuBoundsServiceImpl.java @@ -1,5 +1,6 @@ package com.carl.mall.coupon.service.impl; +import com.carl.common.dto.SpuBoundsDTO; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -26,4 +27,14 @@ public class SpuBoundsServiceImpl extends ServiceImplcom.alibaba.cloud aliyun-oss-spring-boot-starter + + org.springframework.cloud + spring-cloud-starter-loadbalancer + diff --git a/mall-product/src/main/java/com/carl/mall/product/MallProductApplication.java b/mall-product/src/main/java/com/carl/mall/product/MallProductApplication.java index e338d9b..2cf2880 100644 --- a/mall-product/src/main/java/com/carl/mall/product/MallProductApplication.java +++ b/mall-product/src/main/java/com/carl/mall/product/MallProductApplication.java @@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @@ -12,6 +13,7 @@ import org.springframework.context.annotation.ComponentScan; @MapperScan("com.carl.mall.product.dao") @EnableDiscoveryClient @ComponentScan(basePackages = "com.carl") +@EnableFeignClients("com.carl.mall.product.feign") //远程接口所在的包 public class MallProductApplication { public static void main(String[] args) { diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java b/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java index 64dcd3a..a3ddb03 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java @@ -4,6 +4,10 @@ import java.util.Arrays; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.mall.product.vo.skuvo.SpuInfoVO; +import com.google.common.base.Preconditions; +import lombok.extern.slf4j.Slf4j; +import com.alibaba.fastjson.JSON; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -27,7 +31,9 @@ import com.carl.common.utils.R; */ @RestController @RequestMapping("product/spuinfo") +@Slf4j public class SpuInfoController { + @Autowired private SpuInfoService spuInfoService; @@ -37,6 +43,7 @@ public class SpuInfoController { @RequestMapping("/list") //@RequiresPermissions("product:spuinfo:list") public R list(@RequestParam Map params){ + PageUtils page = spuInfoService.queryPage(params); return R.ok().put("page", page); @@ -59,9 +66,13 @@ public class SpuInfoController { */ @RequestMapping("/save") //@RequiresPermissions("product:spuinfo:save") - public R save(@RequestBody SpuInfoEntity spuInfo){ - spuInfoService.save(spuInfo); - + public R save(@RequestBody SpuInfoVO skuInfoVO){ + if (log.isInfoEnabled()){ + log.info("SpuInfoController.save.SpuInfoVO:{}", + JSON.toJSONString(skuInfoVO)); + } + //spuInfoService.save(skuInfoVO); + spuInfoService.saveSpuInfo(skuInfoVO); return R.ok(); } diff --git a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java index b693000..420dfae 100644 --- a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java +++ b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java @@ -1,13 +1,15 @@ package com.carl.mall.product.convert; -import com.carl.mall.product.entity.AttrAttrgroupRelationEntity; -import com.carl.mall.product.entity.AttrEntity; -import com.carl.mall.product.entity.AttrGroupEntity; +import com.carl.common.dto.SkuReductionDTO; +import com.carl.mall.product.entity.*; import com.carl.mall.product.vo.AttrEntityVO; import com.carl.mall.product.vo.AttrGroupAttrResponseVO; import com.carl.mall.product.vo.AttrGroupRelationVO; import com.carl.mall.product.vo.AttrResponseVO; +import com.carl.mall.product.vo.skuvo.Attr; +import com.carl.mall.product.vo.skuvo.Skus; +import com.carl.mall.product.vo.skuvo.SpuInfoVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -25,7 +27,14 @@ public interface EntityToVoConvert { AttrAttrgroupRelationEntity AttrAttrgroupRelationEntity(AttrGroupRelationVO attrGroupRelationVO); + AttrGroupAttrResponseVO attrGroupAttrEnToVo(AttrGroupEntity attrGroupEntity); + SpuInfoEntity spuInfoVOTOSpuInfoEntity(SpuInfoVO spuInfoVO); + + SkuInfoEntity skusTOskuInfoEntity(Skus skus); + + SkuSaleAttrValueEntity attrsTOSkuSaleAttrValueEntity(Attr attr); + + SkuReductionDTO skuTOSkuReductionDTO(Skus skus); - AttrGroupAttrResponseVO attrGroupAttrEnToVo(AttrGroupEntity attrGroupEntity); } diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoDescEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoDescEntity.java index d49d308..7ec9436 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoDescEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoDescEntity.java @@ -1,5 +1,6 @@ package com.carl.mall.product.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -22,7 +23,7 @@ public class SpuInfoDescEntity implements Serializable { /** * 商品id */ - @TableId + @TableId(type = IdType.INPUT) //数据表中的这个id不是自增的 private Long spuId; /** * 商品介绍 diff --git a/mall-product/src/main/java/com/carl/mall/product/feign/CouponFeignService.java b/mall-product/src/main/java/com/carl/mall/product/feign/CouponFeignService.java new file mode 100644 index 0000000..0fc4268 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/feign/CouponFeignService.java @@ -0,0 +1,30 @@ +package com.carl.mall.product.feign; + + +import com.carl.common.dto.SkuReductionDTO; +import com.carl.common.dto.SpuBoundsDTO; +import com.carl.common.utils.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient("mall-coupon") +public interface CouponFeignService { + + /** + * 调用远程服务 保存满减,折扣和会员价的相关信息 + * @param skuReductionDTO + * @return + */ + @PostMapping("/coupon/skufullreduction/saveInfo") + R saveFullReductionInfo(@RequestBody SkuReductionDTO skuReductionDTO); + + /** + * 调用远程服务 保存会员积分 + * @param spuBoundsDTO + * @return + */ + @PostMapping("/coupon/spubounds/saveBoundInfo") + R saveBoundInfo(@RequestBody SpuBoundsDTO spuBoundsDTO); + +} diff --git a/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java b/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java index 077b18e..85cdcfd 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java @@ -3,6 +3,7 @@ package com.carl.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.product.entity.SpuInfoEntity; +import com.carl.mall.product.vo.skuvo.SpuInfoVO; import java.util.Map; @@ -16,5 +17,7 @@ import java.util.Map; public interface SpuInfoService extends IService { PageUtils queryPage(Map params); + + void saveSpuInfo(SpuInfoVO skuInfoVO); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java index b7c43b1..d15961e 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java @@ -1,7 +1,27 @@ package com.carl.mall.product.service.impl; +import com.carl.common.dto.SkuReductionDTO; +import com.carl.common.dto.SpuBoundsDTO; +import com.carl.common.utils.R; +import com.carl.common.utils.splitUrl; +import com.carl.mall.product.convert.EntityToVoConvert; +import com.carl.mall.product.dao.AttrAttrgroupRelationDao; +import com.carl.mall.product.entity.*; +import com.carl.mall.product.feign.CouponFeignService; +import com.carl.mall.product.service.*; +import com.carl.mall.product.vo.skuvo.*; +import com.google.common.base.Preconditions; +import com.mysql.cj.x.protobuf.MysqlxDatatypes; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -9,13 +29,42 @@ import com.carl.common.utils.PageUtils; import com.carl.common.utils.Query; import com.carl.mall.product.dao.SpuInfoDao; -import com.carl.mall.product.entity.SpuInfoEntity; -import com.carl.mall.product.service.SpuInfoService; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; @Service("spuInfoService") public class SpuInfoServiceImpl extends ServiceImpl implements SpuInfoService { + + @Autowired + private SpuInfoDescService spuInfoDescService; + + @Autowired + private SpuImagesService spuImagesService; + + @Autowired + private AttrService attrService; + + @Autowired + private AttrAttrgroupRelationDao attrAttrgroupRelationDao; + + @Autowired + private ProductAttrValueService productAttrValueService; + + @Autowired + private SkuInfoService skuInfoService; + + @Autowired + private SkuSaleAttrValueService skuSaleAttrValueService; + + @Autowired + private SkuImagesService skuImagesService; + + //远程调用接口 + @Autowired + CouponFeignService couponFeignService; + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +75,114 @@ public class SpuInfoServiceImpl extends ServiceImpl i return new PageUtils(page); } + + /** + * 保存商品发布信息 + * @param skuInfoVO + */ + @Transactional + @Override + public void saveSpuInfo(SpuInfoVO skuInfoVO) { + //1.保存spu的基本信息 pms_spu_info + SpuInfoEntity spuInfoEntity = EntityToVoConvert.INSTANCE.spuInfoVOTOSpuInfoEntity(skuInfoVO); + spuInfoEntity.setCreateTime(new Date()); + spuInfoEntity.setUpdateTime(new Date()); + this.save(spuInfoEntity); + //2.保存spu的详情信息 pms_spu_info_desc + List decript = skuInfoVO.getDecript(); + SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity(); + spuInfoDescEntity.setSpuId(spuInfoEntity.getId()); + spuInfoDescEntity.setDecript(String.join(",",decript)); + spuInfoDescService.save(spuInfoDescEntity); + //3.保存商品的图集信息 pms_spu_images + List images = skuInfoVO.getImages(); + List list = images.stream().map((e) -> { + SpuImagesEntity spuImagesEntity = new SpuImagesEntity(); + spuImagesEntity.setSpuId(spuInfoEntity.getId()); + spuImagesEntity.setImgUrl(e); + String imgName = new splitUrl().urlSplit(e); + spuImagesEntity.setImgName(imgName); + return spuImagesEntity; + }).collect(Collectors.toList()); + spuImagesService.saveBatch(list); + //4.保存规格参数 pms_product_attr_value + List baseAttrs = skuInfoVO.getBaseAttrs(); + List productAttrValueEntities = baseAttrs.stream().map((baseAttr) -> { + ProductAttrValueEntity productAttrValueEntity = new ProductAttrValueEntity(); + productAttrValueEntity.setSpuId(spuInfoEntity.getId()); + productAttrValueEntity.setAttrId(baseAttr.getAttrId()); + AttrEntity attrEntity = attrService.getById(baseAttr.getAttrId()); + productAttrValueEntity.setAttrName(attrEntity.getAttrName()); + productAttrValueEntity.setAttrValue(baseAttr.getAttrValues()); + productAttrValueEntity.setQuickShow(baseAttr.getShowDesc()); + AttrAttrgroupRelationEntity relationEntity = attrAttrgroupRelationDao + .selectOne(new QueryWrapper() + .eq("attr_id", baseAttr.getAttrId())); + productAttrValueEntity.setAttrSort(relationEntity.getAttrSort()); + return productAttrValueEntity; + }).collect(Collectors.toList()); + productAttrValueService.saveBatch(productAttrValueEntities); + //5.保存当前的spu对应的所有的sku(销售属性)的信息 + //5.1 保存sku的基本信息pms_sku_info + List skus = skuInfoVO.getSkus(); + if (!StringUtils.isEmpty(skus)){ + skus.forEach((sku)-> { + SkuInfoEntity skuInfoEntity = EntityToVoConvert.INSTANCE.skusTOskuInfoEntity(sku); + skuInfoEntity.setSpuId(spuInfoEntity.getId()); + skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId()); + skuInfoEntity.setBrandId(spuInfoEntity.getBrandId()); + skuInfoEntity.setSaleCount(0L); + List images1 = sku.getImages(); + String defaultImage = ""; + for (Images images2 : images1) { + if (images2.getDefaultImg() == 1) { + defaultImage = images2.getImgUrl(); + } + } + skuInfoEntity.setSkuDefaultImg(defaultImage); + skuInfoService.save(skuInfoEntity); + //5.2 保存sku销售属性信息pms_sku_sale_attr_value + List attrs = sku.getAttr(); + List skuSaleAttrValueEntities = attrs.stream().map((attr) -> { + SkuSaleAttrValueEntity skuSaleAttrValueEntity = EntityToVoConvert + .INSTANCE.attrsTOSkuSaleAttrValueEntity(attr); + skuSaleAttrValueEntity.setSkuId(skuInfoEntity.getSkuId()); + return skuSaleAttrValueEntity; + }).collect(Collectors.toList()); + skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities); + //5.3 保存sku的图片信息 pms_sku_image + List skuImagesEntities = images1.stream().map((img) -> { + SkuImagesEntity skuImagesEntity = new SkuImagesEntity(); + skuImagesEntity.setSkuId(skuInfoEntity.getSkuId()); + skuImagesEntity.setImgUrl(img.getImgUrl()); + skuImagesEntity.setDefaultImg(img.getDefaultImg()); + return skuImagesEntity; + }).filter((img) -> { + return !img.getImgUrl().isEmpty(); //将图片链接为空的过滤掉 + }).collect(Collectors.toList()); + skuImagesService.saveBatch(skuImagesEntities); + //5.4 mall_sms服务中 保存满减信息sms_sku_full_reduction,折扣sms_sku_ladder,会员价sms_member_price + SkuReductionDTO skuReductionDTO =null; + if(sku.getMemberPrice() != null && !sku.getMemberPrice().isEmpty()) { + skuReductionDTO = EntityToVoConvert.INSTANCE.skuTOSkuReductionDTO(sku); + skuReductionDTO.setSkuId(skuInfoEntity.getSkuId()); + } + R r = couponFeignService.saveFullReductionInfo(skuReductionDTO); + if (r.getCode() != 0){ + log.error("调用Coupon服务处理满减、折扣、会员价操作失败..."); + } + }); + } + //6.保存积分信息(第一步中的) mall_sms: sms_spu_bounds + Bounds bounds = skuInfoVO.getBounds(); + SpuBoundsDTO spuBoundsDTO = new SpuBoundsDTO(); + spuBoundsDTO.setSpuId(spuInfoEntity.getId()); + spuBoundsDTO.setGrowBounds(bounds.getGrowBounds()); + spuBoundsDTO.setBuyBounds(bounds.getBuyBounds()); + R r = couponFeignService.saveBoundInfo(spuBoundsDTO); + if (r.getCode() != 0){ + log.error("调用Coupon服务处理积分操作失败..."); + } + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Attr.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Attr.java new file mode 100644 index 0000000..6c2c09d --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Attr.java @@ -0,0 +1,19 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.mall.product.vo.skuvo; + +import lombok.Data; + + +/** + * SKU销售属性 + */ +@Data +public class Attr { + + private Long attrId; + private String attrName; + private String attrValue; + +} \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/BaseAttrs.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/BaseAttrs.java new file mode 100644 index 0000000..72b51ea --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/BaseAttrs.java @@ -0,0 +1,16 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.mall.product.vo.skuvo; + +import lombok.Data; + +@Data +public class BaseAttrs { + + private Long attrId; //分类id + private String attrValues; //分类值 + private int showDesc; //是否快速展示 【是否展示在介绍上;0-否 1-是】 + + +} \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Bounds.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Bounds.java new file mode 100644 index 0000000..442b2ce --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Bounds.java @@ -0,0 +1,21 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.mall.product.vo.skuvo; + +import lombok.Data; + +import java.math.BigDecimal; + + +/** + * 商品spu积分设置 + */ +@Data +public class Bounds { + + private BigDecimal buyBounds; + private BigDecimal growBounds; + + +} \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Images.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Images.java new file mode 100644 index 0000000..59d89d1 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Images.java @@ -0,0 +1,16 @@ + +package com.carl.mall.product.vo.skuvo; + +import lombok.Data; + +/** + * sku图片 + */ +@Data +public class Images { + + private String imgUrl; //图片链接 + private int defaultImg; //是否是默认图片 默认图[0 - 不是默认图,1 - 是默认图] + + +} \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/MemberPrice.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/MemberPrice.java new file mode 100644 index 0000000..63d7ab0 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/MemberPrice.java @@ -0,0 +1,21 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.mall.product.vo.skuvo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 会员价格 + */ +@Data +public class MemberPrice { + + private Long id; + private String name; //会员等级名 + private BigDecimal price; //会员对应价格 + + +} \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Skus.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Skus.java new file mode 100644 index 0000000..43e9de2 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/Skus.java @@ -0,0 +1,39 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.mall.product.vo.skuvo; +import com.carl.common.dto.MemberPrice; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + + +@Data +public class Skus { + /* pms_sku_sale_attr_value */ + private List attr; //商品销售属性 + /* pms_sku_info */ + private String skuName; //sku名字 + private BigDecimal price; //价格 + private String skuTitle; //标题 + private String skuSubtitle; //副标题 + /* pms_sku_image */ + private List images; //sku图片 + private List descar; //根据笛卡尔积运算进行生成sku 将不同的销售属性和商品名称组合起来 + /* mall-sms sms_sku_ladder */ + //设置满减 + private int fullCount; //满几件 + private BigDecimal discount; //打几折 + private int countStatus; //数量状况 有没有其他优惠 + /* mall-sms sms_sku_full_reduction */ + //设置折扣 + private BigDecimal fullPrice; //满多少元 + private BigDecimal reducePrice; //降多少 + private int priceStatus; //价格状况 有没有其他优惠 + /* mall-sms sms_member_price */ + //设置会员价 + private List memberPrice; + + +} \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java new file mode 100644 index 0000000..061f119 --- /dev/null +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java @@ -0,0 +1,28 @@ +/** + * Copyright 2024 bejson.com + */ +package com.carl.mall.product.vo.skuvo; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +@Data +public class SpuInfoVO { + /* pms_spu_info */ + private String spuName; //商品名称 + private String spuDescription; //商品描述 + private Long catalogId; //分类id + private Long brandId; //品牌id + private BigDecimal weight; //商品重量(Kg) + private int publishStatus; //展示状态 上架状态[0 - 下架,1 - 上架] + /* pms_spu_info_desc */ + private List decript; //商品介绍 + /* pms_spu_image */ + private List images; //商品图集 + /* mall_sms: sms_spu_bounds */ + private Bounds bounds; //商品spu积分设置 mall-sms + /* pms_product_attr_value */ + private List baseAttrs; //商品规格参数 + private List skus; //sku信息 +} \ No newline at end of file -- Gitee From 89c43cd2fc34db6f3709e18aa7762ad8f2afcb03 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Thu, 20 Jun 2024 18:07:24 +0800 Subject: [PATCH 12/14] =?UTF-8?q?122-=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A3=80=E7=B4=A2=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SkuFullReductionServiceImpl.java | 9 ++- .../product/controller/AttrController.java | 2 +- .../product/controller/SkuInfoController.java | 2 +- .../product/controller/SpuInfoController.java | 5 +- .../product/convert/EntityToVoConvert.java | 2 + .../entity/SkuSaleAttrValueEntity.java | 1 - .../mall/product/entity/SpuInfoEntity.java | 6 +- .../mall/product/service/SkuInfoService.java | 2 + .../mall/product/service/SpuInfoService.java | 2 + .../service/impl/SkuInfoServiceImpl.java | 56 ++++++++++++++++ .../service/impl/SpuInfoServiceImpl.java | 67 ++++++++++++++++++- .../carl/mall/product/vo/skuvo/SpuInfoVO.java | 20 +++++- 12 files changed, 161 insertions(+), 13 deletions(-) diff --git a/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java b/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java index c63f187..27c9061 100644 --- a/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java +++ b/mall-coupon/src/main/java/com/carl/mall/coupon/service/impl/SkuFullReductionServiceImpl.java @@ -1,5 +1,6 @@ package com.carl.mall.coupon.service.impl; +import com.carl.common.dto.MemberPrice; import com.carl.common.dto.SkuReductionDTO; import com.carl.mall.coupon.convert.CouponConvert; import com.carl.mall.coupon.entity.MemberPriceEntity; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -55,6 +57,11 @@ public class SkuFullReductionServiceImpl extends ServiceImpl0){ List memberPriceEntities = skuReductionDTO.getMemberPrice().stream().map((member) -> { MemberPriceEntity memberPriceEntity = new MemberPriceEntity(); memberPriceEntity.setAddOther(1); //是否可叠加 前端暂时没有 diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java index 430c950..b6a0c88 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/AttrController.java @@ -36,7 +36,7 @@ public class AttrController { //http://localhost:9006/app/product/attr/base/list/0?t=1717931509778&page=1&limit=10&key= /** - * 规格参数 和销售属性 + * 规格参数 和 销售属性 */ @RequestMapping("/{attrType}/list/{catelogId}") public R baseList(@RequestParam Map params, diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java b/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java index f99ce49..e88712f 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java @@ -37,7 +37,7 @@ public class SkuInfoController { @RequestMapping("/list") //@RequiresPermissions("product:skuinfo:list") public R list(@RequestParam Map params){ - PageUtils page = skuInfoService.queryPage(params); + PageUtils page = skuInfoService.queryPageByCondition(params); return R.ok().put("page", page); } diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java b/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java index a3ddb03..4f1bb5a 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/SpuInfoController.java @@ -43,9 +43,7 @@ public class SpuInfoController { @RequestMapping("/list") //@RequiresPermissions("product:spuinfo:list") public R list(@RequestParam Map params){ - - PageUtils page = spuInfoService.queryPage(params); - + PageUtils page = spuInfoService.queryPageByCondition(params); return R.ok().put("page", page); } @@ -57,7 +55,6 @@ public class SpuInfoController { //@RequiresPermissions("product:spuinfo:info") public R info(@PathVariable("id") Long id){ SpuInfoEntity spuInfo = spuInfoService.getById(id); - return R.ok().put("spuInfo", spuInfo); } diff --git a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java index 420dfae..32bafed 100644 --- a/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java +++ b/mall-product/src/main/java/com/carl/mall/product/convert/EntityToVoConvert.java @@ -37,4 +37,6 @@ public interface EntityToVoConvert { SkuReductionDTO skuTOSkuReductionDTO(Skus skus); + SpuInfoVO spuInfoEnToSpuInfoVo(SpuInfoEntity spuInfoEntity); + } diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/SkuSaleAttrValueEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/SkuSaleAttrValueEntity.java index f3baccf..2447fc4 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/SkuSaleAttrValueEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/SkuSaleAttrValueEntity.java @@ -18,7 +18,6 @@ import lombok.Data; @TableName("pms_sku_sale_attr_value") public class SkuSaleAttrValueEntity implements Serializable { private static final long serialVersionUID = 1L; - /** * id */ diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java index e4996dc..840ffc2 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.math.BigDecimal; import java.io.Serializable; import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; /** @@ -46,16 +48,18 @@ public class SpuInfoEntity implements Serializable { */ private BigDecimal weight; /** - * 上架状态[0 - 下架,1 - 上架] + * 上架状态[0 - 新建,1 - 上架,2- 下架] */ private Integer publishStatus; /** * */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; /** * */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date updateTime; } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/SkuInfoService.java b/mall-product/src/main/java/com/carl/mall/product/service/SkuInfoService.java index d407a4b..d7e1306 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/SkuInfoService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/SkuInfoService.java @@ -16,5 +16,7 @@ import java.util.Map; public interface SkuInfoService extends IService { PageUtils queryPage(Map params); + + PageUtils queryPageByCondition(Map params); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java b/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java index 85cdcfd..f3d1476 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/SpuInfoService.java @@ -19,5 +19,7 @@ public interface SpuInfoService extends IService { PageUtils queryPage(Map params); void saveSpuInfo(SpuInfoVO skuInfoVO); + + PageUtils queryPageByCondition(Map params); } diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java index 0a633f7..26e8294 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java @@ -1,6 +1,8 @@ package com.carl.mall.product.service.impl; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -11,6 +13,7 @@ import com.carl.common.utils.Query; import com.carl.mall.product.dao.SkuInfoDao; import com.carl.mall.product.entity.SkuInfoEntity; import com.carl.mall.product.service.SkuInfoService; +import org.springframework.util.StringUtils; @Service("skuInfoService") @@ -26,4 +29,57 @@ public class SkuInfoServiceImpl extends ServiceImpl i return new PageUtils(page); } + @Override + public PageUtils queryPageByCondition(Map params) { + + QueryWrapper wrapper = new QueryWrapper<>(); + + String key = (String) params.get("key"); + + if (!StringUtils.isEmpty(key)){ + wrapper.and((wrappers)->{ + wrappers.eq("sku_id",key) + .or().like("sku_name",key); + }); + } + // catalogId + String catalogId = ( String)params.get("catelogId"); + if (!StringUtils.isEmpty(catalogId)&&!"0".equalsIgnoreCase(catalogId)){ + wrapper.eq("catalog_id",catalogId); + } + //brandId + String brandId = ( String)params.get("brandId"); + if (!StringUtils.isEmpty(brandId)&&!"0".equalsIgnoreCase(brandId)){ + wrapper.eq("brand_id",brandId); + } + + //min + String min = (String)params.get("min"); + if(!StringUtils.isEmpty(min)){ + wrapper.ge("price",min); + } + //max + String max = (String)params.get("max"); + if(!StringUtils.isEmpty(max)){ + try { + // 如果max=0那么我们也不需要加这个条件 + BigDecimal bigDecimal = new BigDecimal(max); + if(bigDecimal.compareTo(new BigDecimal(0)) > 0){ + // 说明 max > 0 + wrapper.le("price",max); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + + return new PageUtils(page); + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java index d15961e..cbaa9d5 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/SpuInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.carl.mall.product.service.impl; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.carl.common.dto.SkuReductionDTO; import com.carl.common.dto.SpuBoundsDTO; import com.carl.common.utils.R; @@ -18,6 +19,7 @@ import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -61,6 +63,12 @@ public class SpuInfoServiceImpl extends ServiceImpl i @Autowired private SkuImagesService skuImagesService; + @Autowired + private CategoryService categoryService; + + @Autowired + private BrandService brandService; + //远程调用接口 @Autowired CouponFeignService couponFeignService; @@ -112,7 +120,7 @@ public class SpuInfoServiceImpl extends ServiceImpl i productAttrValueEntity.setSpuId(spuInfoEntity.getId()); productAttrValueEntity.setAttrId(baseAttr.getAttrId()); AttrEntity attrEntity = attrService.getById(baseAttr.getAttrId()); - productAttrValueEntity.setAttrName(attrEntity.getAttrName()); + productAttrValueEntity.setAttrName(attrEntity.getAttrName()); //前端自定义属性值的时候容易产生空指针异常 productAttrValueEntity.setAttrValue(baseAttr.getAttrValues()); productAttrValueEntity.setQuickShow(baseAttr.getShowDesc()); AttrAttrgroupRelationEntity relationEntity = attrAttrgroupRelationDao @@ -133,7 +141,7 @@ public class SpuInfoServiceImpl extends ServiceImpl i skuInfoEntity.setBrandId(spuInfoEntity.getBrandId()); skuInfoEntity.setSaleCount(0L); List images1 = sku.getImages(); - String defaultImage = ""; + String defaultImage = "sku图片为空"; for (Images images2 : images1) { if (images2.getDefaultImg() == 1) { defaultImage = images2.getImgUrl(); @@ -158,7 +166,7 @@ public class SpuInfoServiceImpl extends ServiceImpl i skuImagesEntity.setDefaultImg(img.getDefaultImg()); return skuImagesEntity; }).filter((img) -> { - return !img.getImgUrl().isEmpty(); //将图片链接为空的过滤掉 + return img != null && img.getImgUrl() != null && !img.getImgUrl().isEmpty() && !img.getImgUrl().trim().isEmpty(); //将图片链接为空的过滤掉 }).collect(Collectors.toList()); skuImagesService.saveBatch(skuImagesEntities); //5.4 mall_sms服务中 保存满减信息sms_sku_full_reduction,折扣sms_sku_ladder,会员价sms_member_price @@ -185,4 +193,57 @@ public class SpuInfoServiceImpl extends ServiceImpl i } } + @Override + public PageUtils queryPageByCondition(Map params) { + QueryWrapper wrapper = new QueryWrapper<>(); + String key = (String) params.get("key"); + if (!StringUtils.isEmpty(key)){ + wrapper.and((queryWrapper) ->{ + queryWrapper.eq("id",key).or().like("spu_name",key).or().like("spu_description",key); + }); + } + //status + String status = ( String)params.get("status"); + if (!StringUtils.isEmpty(status) ){ + wrapper.eq("publish_status",status); + } + // catalogId + String catalogId = ( String)params.get("catelogId"); + if (!StringUtils.isEmpty(catalogId)&&!"0".equalsIgnoreCase(catalogId)){ + wrapper.eq("catalog_id",catalogId); + } + //brandId + String brandId = ( String)params.get("brandId"); + if (!StringUtils.isEmpty(brandId)&&!"0".equalsIgnoreCase(brandId)){ + wrapper.eq("brand_id",brandId); + } + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + + List list = page.getRecords().stream().map((spuInfoEntity -> { + Long catalogId1 = spuInfoEntity.getCatalogId(); + Long brandId1 = spuInfoEntity.getBrandId(); + String cateLogName = categoryService.getById(catalogId1).getName(); + String brandName = brandService.getById(brandId1).getName(); + SpuInfoVO spuInfoVO = EntityToVoConvert.INSTANCE.spuInfoEnToSpuInfoVo(spuInfoEntity); + spuInfoVO.setBrandName(brandName); + spuInfoVO.setCatalogName(cateLogName); + return spuInfoVO; + })).collect(Collectors.toList()); + + IPage page1 = new Page<>(); + page1.setRecords(list); + page1.setPages(page.getPages()); + page1.setCurrent(page.getCurrent()); + page1.setSize(page.getSize()); + page1.setTotal(page.getTotal()); + return new PageUtils(page1); + + + + + } + } \ No newline at end of file diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java index 061f119..edeeed1 100644 --- a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java @@ -2,20 +2,26 @@ * Copyright 2024 bejson.com */ package com.carl.mall.product.vo.skuvo; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.math.BigDecimal; +import java.util.Date; import java.util.List; @Data public class SpuInfoVO { + + private Long id; //spu id /* pms_spu_info */ private String spuName; //商品名称 private String spuDescription; //商品描述 private Long catalogId; //分类id + private String catalogName; //分类名称 private Long brandId; //品牌id + private String brandName; //品牌名称 private BigDecimal weight; //商品重量(Kg) - private int publishStatus; //展示状态 上架状态[0 - 下架,1 - 上架] + private Integer publishStatus; //展示状态 上架状态[0 - 新建,1 - 上架,2- 下架] /* pms_spu_info_desc */ private List decript; //商品介绍 /* pms_spu_image */ @@ -25,4 +31,16 @@ public class SpuInfoVO { /* pms_product_attr_value */ private List baseAttrs; //商品规格参数 private List skus; //sku信息 + /** + * + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + /** + * + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + + } \ No newline at end of file -- Gitee From 3a7506fb64516058e6036e99cec767d1df1461f7 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Fri, 21 Jun 2024 23:30:59 +0800 Subject: [PATCH 13/14] =?UTF-8?q?129-=E9=87=87=E8=B4=AD=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../carl/common/constant/WareConstant.java | 57 +++++++++++++ .../service/impl/SkuInfoServiceImpl.java | 11 +-- .../carl/mall/ware/MallWareApplication.java | 2 + .../mall/ware/config/MybatisPlusConfig.java | 37 ++++++++ .../ware/controller/PurchaseController.java | 29 +++++-- .../controller/PurchaseDetailController.java | 6 +- .../ware/controller/WareInfoController.java | 3 +- .../ware/controller/WareSkuController.java | 3 +- .../ware/entity/PurchaseDetailEntity.java | 1 - .../carl/mall/ware/entity/PurchaseEntity.java | 4 + .../ware/service/PurchaseDetailService.java | 2 + .../mall/ware/service/PurchaseService.java | 7 ++ .../mall/ware/service/WareInfoService.java | 2 + .../mall/ware/service/WareSkuService.java | 2 + .../impl/PurchaseDetailServiceImpl.java | 30 +++++++ .../service/impl/PurchaseServiceImpl.java | 84 +++++++++++++++++++ .../service/impl/WareInfoServiceImpl.java | 18 ++++ .../ware/service/impl/WareSkuServiceImpl.java | 22 +++++ .../java/com/carl/mall/ware/vo/MergeVO.java | 22 +++++ mall-ware/src/main/resources/application.yml | 46 +++++----- .../src/main/resources/bootstrap.properties | 21 ++++- 21 files changed, 364 insertions(+), 45 deletions(-) create mode 100644 mall-commons/src/main/java/com/carl/common/constant/WareConstant.java create mode 100644 mall-ware/src/main/java/com/carl/mall/ware/config/MybatisPlusConfig.java create mode 100644 mall-ware/src/main/java/com/carl/mall/ware/vo/MergeVO.java diff --git a/mall-commons/src/main/java/com/carl/common/constant/WareConstant.java b/mall-commons/src/main/java/com/carl/common/constant/WareConstant.java new file mode 100644 index 0000000..88af9c3 --- /dev/null +++ b/mall-commons/src/main/java/com/carl/common/constant/WareConstant.java @@ -0,0 +1,57 @@ +package com.carl.common.constant; + + +/** + * 库存模块的常量 + * + */ +public class WareConstant { + + /** + * 采购单状态 + */ + public enum PurchaseStatusEnum{ + CREATED(0,"新建") + ,ASSIGED(1,"已分配") + ,RECEIVE(2,"已领取") + ,FINISH(3,"已完成") + ,HASERROR(4,"有异常"); + private int code; + private String msg; + PurchaseStatusEnum(int code,String msg){ + this.code = code; + this.msg = msg; + } + public int getCode(){ + return code; + } + + public String getMsg() { + return msg; + } + } + + /** + * 采购需求状态 + */ + public enum PurchaseDetailStatusEnum{ + CREATED(0,"新建") + ,ASSIGED(1,"已分配") + ,BUYING(2,"正在采购") + ,FINISH(3,"已完成") + ,HASERROR(4,"采购失败"); + private int code; + private String msg; + PurchaseDetailStatusEnum(int code,String msg){ + this.code = code; + this.msg = msg; + } + public int getCode(){ + return code; + } + + public String getMsg() { + return msg; + } + } +} diff --git a/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java b/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java index 26e8294..9c08ad4 100644 --- a/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java +++ b/mall-product/src/main/java/com/carl/mall/product/service/impl/SkuInfoServiceImpl.java @@ -35,7 +35,6 @@ public class SkuInfoServiceImpl extends ServiceImpl i QueryWrapper wrapper = new QueryWrapper<>(); String key = (String) params.get("key"); - if (!StringUtils.isEmpty(key)){ wrapper.and((wrappers)->{ wrappers.eq("sku_id",key) @@ -60,16 +59,14 @@ public class SkuInfoServiceImpl extends ServiceImpl i } //max String max = (String)params.get("max"); - if(!StringUtils.isEmpty(max)){ + if (!StringUtils.isEmpty(max)){ try { - // 如果max=0那么我们也不需要加这个条件 BigDecimal bigDecimal = new BigDecimal(max); - if(bigDecimal.compareTo(new BigDecimal(0)) > 0){ - // 说明 max > 0 + if (bigDecimal.compareTo(new BigDecimal(0))>0){ wrapper.le("price",max); } - }catch (Exception e){ - e.printStackTrace(); + } catch (Exception e) { + throw new RuntimeException(e); } } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java b/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java index b5dca9e..0a8b712 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java @@ -5,11 +5,13 @@ import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication // 指定Mapper接口对应的路径 @MapperScan("com.carl.mall.ware.dao") @EnableDiscoveryClient +@ComponentScan(basePackages = "com.carl") public class MallWareApplication { public static void main(String[] args) { diff --git a/mall-ware/src/main/java/com/carl/mall/ware/config/MybatisPlusConfig.java b/mall-ware/src/main/java/com/carl/mall/ware/config/MybatisPlusConfig.java new file mode 100644 index 0000000..13bac5d --- /dev/null +++ b/mall-ware/src/main/java/com/carl/mall/ware/config/MybatisPlusConfig.java @@ -0,0 +1,37 @@ +package com.carl.mall.ware.config; + + +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableTransactionManagement +@MapperScan("com.carl.mall.ware.dao") +public class MybatisPlusConfig { + + // 旧版 + @Bean + public PaginationInterceptor paginationInterceptor() { + PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); + // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false + paginationInterceptor.setOverflow(true); + // 设置最大单页限制数量,默认 500 条,-1 不受限制 + paginationInterceptor.setLimit(500); + // 开启 count 的 join 优化,只针对部分 left join + paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true)); + return paginationInterceptor; + } + + + // 最新版 + /*@Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); + return interceptor; + }*/ +} diff --git a/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java b/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java index d5f359e..83eb988 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java @@ -4,12 +4,9 @@ import java.util.Arrays; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; +import com.carl.mall.ware.vo.MergeVO; 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 org.springframework.web.bind.annotation.*; import com.carl.mall.ware.entity.PurchaseEntity; import com.carl.mall.ware.service.PurchaseService; @@ -31,13 +28,33 @@ public class PurchaseController { @Autowired private PurchaseService purchaseService; + ///unreceive/list + /** + * 列表 + */ + @RequestMapping("/unreceive/list") + //@RequiresPermissions("ware:purchase:list") + public R listUnReceive(@RequestParam Map params){ + PageUtils page = purchaseService.queryPageByUnreceive(params); + + return R.ok().put("page", page); + } + + @PostMapping("/merge") + public R merge(@RequestBody MergeVO mergeVO){ + purchaseService.saveMerge(mergeVO); + return R.ok(); + } + + + /** * 列表 */ @RequestMapping("/list") //@RequiresPermissions("ware:purchase:list") public R list(@RequestParam Map params){ - PageUtils page = purchaseService.queryPage(params); + PageUtils page = purchaseService.queryPageByCondition(params); return R.ok().put("page", page); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseDetailController.java b/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseDetailController.java index 74a3f09..a594c57 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseDetailController.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseDetailController.java @@ -5,6 +5,7 @@ import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,7 +21,7 @@ import com.carl.common.utils.R; /** * - * + * 采购需求 * @author carl * @email 541020344@qq.com * @date 2024-03-10 23:34:07 @@ -37,8 +38,7 @@ public class PurchaseDetailController { @RequestMapping("/list") //@RequiresPermissions("ware:purchasedetail:list") public R list(@RequestParam Map params){ - PageUtils page = purchaseDetailService.queryPage(params); - + PageUtils page = purchaseDetailService.queryPageByCondition(params); return R.ok().put("page", page); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/controller/WareInfoController.java b/mall-ware/src/main/java/com/carl/mall/ware/controller/WareInfoController.java index df25bd0..43be4f6 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/controller/WareInfoController.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/controller/WareInfoController.java @@ -37,7 +37,7 @@ public class WareInfoController { @RequestMapping("/list") //@RequiresPermissions("ware:wareinfo:list") public R list(@RequestParam Map params){ - PageUtils page = wareInfoService.queryPage(params); + PageUtils page = wareInfoService.queryPageBycondition(params); return R.ok().put("page", page); } @@ -83,7 +83,6 @@ public class WareInfoController { //@RequiresPermissions("ware:wareinfo:delete") public R delete(@RequestBody Long[] ids){ wareInfoService.removeByIds(Arrays.asList(ids)); - return R.ok(); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/controller/WareSkuController.java b/mall-ware/src/main/java/com/carl/mall/ware/controller/WareSkuController.java index 8b8d3cc..0924fab 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/controller/WareSkuController.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/controller/WareSkuController.java @@ -37,8 +37,7 @@ public class WareSkuController { @RequestMapping("/list") //@RequiresPermissions("ware:waresku:list") public R list(@RequestParam Map params){ - PageUtils page = wareSkuService.queryPage(params); - + PageUtils page = wareSkuService.queryPageByCondition(params); return R.ok().put("page", page); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseDetailEntity.java b/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseDetailEntity.java index 2273b65..8c6bbe3 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseDetailEntity.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseDetailEntity.java @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.math.BigDecimal; import java.io.Serializable; -import java.util.Date; import lombok.Data; /** diff --git a/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java b/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java index acd42b4..388a9c1 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.math.BigDecimal; import java.io.Serializable; import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; /** @@ -56,10 +58,12 @@ public class PurchaseEntity implements Serializable { /** * 创建日期 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; /** * 更新日期 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date updateTime; } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseDetailService.java b/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseDetailService.java index dd5ab7f..c7834f3 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseDetailService.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseDetailService.java @@ -16,5 +16,7 @@ import java.util.Map; public interface PurchaseDetailService extends IService { PageUtils queryPage(Map params); + + PageUtils queryPageByCondition(Map params); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java b/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java index bd01db2..09c09ee 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java @@ -3,6 +3,7 @@ package com.carl.mall.ware.service; import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.ware.entity.PurchaseEntity; +import com.carl.mall.ware.vo.MergeVO; import java.util.Map; @@ -16,5 +17,11 @@ import java.util.Map; public interface PurchaseService extends IService { PageUtils queryPage(Map params); + + PageUtils queryPageByUnreceive(Map params); + + void saveMerge(MergeVO mergeVO); + + PageUtils queryPageByCondition(Map params); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/WareInfoService.java b/mall-ware/src/main/java/com/carl/mall/ware/service/WareInfoService.java index a39beb0..465dac4 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/WareInfoService.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/WareInfoService.java @@ -16,5 +16,7 @@ import java.util.Map; public interface WareInfoService extends IService { PageUtils queryPage(Map params); + + PageUtils queryPageBycondition(Map params); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java b/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java index eda8039..dcd2af0 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java @@ -16,5 +16,7 @@ import java.util.Map; public interface WareSkuService extends IService { PageUtils queryPage(Map params); + + PageUtils queryPageByCondition(Map params); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseDetailServiceImpl.java b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseDetailServiceImpl.java index bb4184c..13b20f5 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseDetailServiceImpl.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseDetailServiceImpl.java @@ -1,5 +1,6 @@ package com.carl.mall.ware.service.impl; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -26,4 +27,33 @@ public class PurchaseDetailServiceImpl extends ServiceImpl params) { + + QueryWrapper wrapper = new QueryWrapper<>(); + + String key = (String)params.get("key"); + if (!StringUtils.isEmpty(key)){ + wrapper.and((wrappers) ->{ + wrappers.eq("sku_id",key).or().eq("purchase_id",key); + }); + } + + String status = (String)params.get("status"); + if (!StringUtils.isEmpty(status)){ + wrapper.eq("status",status); + } + + String wareId = (String)params.get("wareId"); + if (!StringUtils.isEmpty(wareId)){ + wrapper.eq("ware_id",wareId); + } + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + + return new PageUtils(page); + } + } \ No newline at end of file diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java index d8ad952..c0f3334 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java @@ -1,7 +1,18 @@ package com.carl.mall.ware.service.impl; +import com.carl.common.constant.WareConstant; +import com.carl.mall.ware.entity.PurchaseDetailEntity; +import com.carl.mall.ware.service.PurchaseDetailService; +import com.carl.mall.ware.vo.MergeVO; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -11,11 +22,15 @@ import com.carl.common.utils.Query; import com.carl.mall.ware.dao.PurchaseDao; import com.carl.mall.ware.entity.PurchaseEntity; import com.carl.mall.ware.service.PurchaseService; +import org.springframework.transaction.annotation.Transactional; @Service("purchaseService") public class PurchaseServiceImpl extends ServiceImpl implements PurchaseService { + + @Autowired + private PurchaseDetailService purchaseDetailService; @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +41,73 @@ public class PurchaseServiceImpl extends ServiceImpl params) { + + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper().eq("status",0).or().eq("status",1) + ); + + return new PageUtils(page); + } + + @Transactional + @Override + public void saveMerge(MergeVO mergeVO) { + //1.没有采购单则新建一个采购单进行合并 + //2.有采购单则新建到这个采购单 + Long purchaseId = mergeVO.getPurchaseId(); + if (purchaseId == null) { + //采购单 + PurchaseEntity purchaseEntity = new PurchaseEntity(); + purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode()); + purchaseEntity.setCreateTime(new Date()); + purchaseEntity.setUpdateTime(new Date()); + this.save(purchaseEntity); + purchaseId = purchaseEntity.getId(); + } + //整合采购需求单 + List items = mergeVO.getItems(); + final Long purchaseFinalId = purchaseId; + List detailEntityList = items.stream().map((item) -> { + PurchaseDetailEntity detailEntity = new PurchaseDetailEntity(); + detailEntity.setId(item); + detailEntity.setPurchaseId(purchaseFinalId); + detailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.ASSIGED.getCode()); + return detailEntity; + }).collect(Collectors.toList()); + purchaseDetailService.updateBatchById(detailEntityList); + PurchaseEntity entity = new PurchaseEntity(); + entity.setUpdateTime(new Date()); + entity.setId(purchaseId); + this.updateById(entity); + + } + + @Override + public PageUtils queryPageByCondition(Map params) { + QueryWrapper wrapper = new QueryWrapper<>(); + String status = (String) params.get("status"); + if (!StringUtils.isEmpty(status)){ + wrapper.eq("status",status); + } + String key = (String) params.get("key"); + if (!StringUtils.isEmpty(key)){ + wrapper.and((wrappers) ->{ + wrappers.eq("assignee_id",key).or().eq("phone",key) + .or().like("assignee_name",key) + .or().eq("priority",key) + .or().eq("ware_id",key); + }); + } + + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + return new PageUtils(page); + } + + } \ No newline at end of file diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareInfoServiceImpl.java b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareInfoServiceImpl.java index 4d58491..333b0c7 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareInfoServiceImpl.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.carl.mall.ware.service.impl; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -26,4 +27,21 @@ public class WareInfoServiceImpl extends ServiceImpl params) { + + QueryWrapper wrapper = new QueryWrapper<>(); + String key = (String) params.get("key"); + if (!StringUtils.isEmpty(key)){ + wrapper.like("name",key).or().eq("id",key).or().like("address",key) + .or().eq("areacode",key); + } + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + + return new PageUtils(page); + } + } \ No newline at end of file diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java index 43bcdc1..566e402 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java @@ -1,5 +1,6 @@ package com.carl.mall.ware.service.impl; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -26,4 +27,25 @@ public class WareSkuServiceImpl extends ServiceImpl i return new PageUtils(page); } + @Override + public PageUtils queryPageByCondition(Map params) { + QueryWrapper wrapper = new QueryWrapper<>(); + String skuId = (String) params.get("skuId"); + if (!StringUtils.isEmpty(skuId)){ + wrapper.and((wrappers) ->{ + wrappers.eq("sku_id",skuId); + }); + } + String wareId = (String) params.get("wareId"); + if (!StringUtils.isEmpty(wareId)){ + wrapper.eq("ware_id",wareId); + } + IPage page = this.page( + new Query().getPage(params), + wrapper + ); + + return new PageUtils(page); + } + } \ No newline at end of file diff --git a/mall-ware/src/main/java/com/carl/mall/ware/vo/MergeVO.java b/mall-ware/src/main/java/com/carl/mall/ware/vo/MergeVO.java new file mode 100644 index 0000000..43dee7a --- /dev/null +++ b/mall-ware/src/main/java/com/carl/mall/ware/vo/MergeVO.java @@ -0,0 +1,22 @@ +package com.carl.mall.ware.vo; + + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +@Data +public class MergeVO { + + //{purchaseId: 1, items: [1, 2, 3]} + /** + * 采购单id + */ + private Long purchaseId; + + private List items; + + +} diff --git a/mall-ware/src/main/resources/application.yml b/mall-ware/src/main/resources/application.yml index e442d09..9b259cf 100644 --- a/mall-ware/src/main/resources/application.yml +++ b/mall-ware/src/main/resources/application.yml @@ -1,23 +1,23 @@ -server: - port: 9005 -# 数据库的连接新 -spring: - datasource: - username: root - password: 123456 - url: jdbc:mysql://192.168.73.130:12345/mall-wms - driver-class-name: com.mysql.cj.jdbc.Driver - cloud: - nacos: - discovery: - server-addr: 192.168.73.130:8848 - application: - name: mall-ware - - -#mybatis-plus 配置 -mybatis-plus: - mapper-locations: classpath*:/mapper/**/*.xml - global-config: - db-config: - id-type: auto # 主键自增 \ No newline at end of file +#server: +# port: 9005 +## 数据库的连接新 +#spring: +# datasource: +# username: root +# password: 123456 +# url: jdbc:mysql://192.168.73.130:12345/mall-wms +# driver-class-name: com.mysql.cj.jdbc.Driver +# cloud: +# nacos: +# discovery: +# server-addr: 192.168.73.130:8848 +# application: +# name: mall-ware +# +# +##mybatis-plus 配置 +#mybatis-plus: +# mapper-locations: classpath*:/mapper/**/*.xml +# global-config: +# db-config: +# id-type: auto # 主键自增 \ No newline at end of file diff --git a/mall-ware/src/main/resources/bootstrap.properties b/mall-ware/src/main/resources/bootstrap.properties index 06a0dd9..24535a0 100644 --- a/mall-ware/src/main/resources/bootstrap.properties +++ b/mall-ware/src/main/resources/bootstrap.properties @@ -1,3 +1,22 @@ #nacos config spring.cloud.nacos.config.server-addr=192.168.73.130:8848 -spring.application.name= mall-ware \ No newline at end of file +spring.application.name=mall-ware + + +#\u6307\u5B9A\u4F7F\u7528\u7684\u547D\u540D\u7A7A\u95F4 +spring.cloud.nacos.config.namespace=d7ef8935-3aa7-4166-9329-c9ba659f1642 + +#\u6307\u5B9A\u5BF9\u5E94\u7684\u914D\u7F6E\u7EC4 +spring.cloud.nacos.config.group=prod +#\u914D\u7F6E\u591A\u4E2A\u914D\u7F6E\u96C6 +spring.cloud.nacos.config.ext-config[0].data-id=mybatis.yml +spring.cloud.nacos.config.ext-config[0].group=prod +spring.cloud.nacos.config.ext-config[0].refresh=false + +spring.cloud.nacos.config.ext-config[1].data-id=datasource.yml +spring.cloud.nacos.config.ext-config[1].group=prod +spring.cloud.nacos.config.ext-config[1].refresh=false + +spring.cloud.nacos.config.ext-config[2].data-id=other.yml +spring.cloud.nacos.config.ext-config[2].group=prod +spring.cloud.nacos.config.ext-config[2].refresh=false \ No newline at end of file -- Gitee From 099ae282abc988bdba7306ef9cac23d261a49436 Mon Sep 17 00:00:00 2001 From: weixin_47384104 <541020344@qq.com> Date: Sun, 23 Jun 2024 15:18:16 +0800 Subject: [PATCH 14/14] =?UTF-8?q?137-=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90,=E9=87=87=E8=B4=AD=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E5=88=9B=E5=BB=BA,=E9=9C=80=E6=B1=82=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E6=88=90=E9=87=87=E8=B4=AD=E5=8D=95->=E5=88=86=E9=85=8D?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E4=BA=BA=E5=91=98->=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E8=BF=9B=E8=A1=8C=E9=87=87=E8=B4=AD->?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E5=85=A5=E5=BA=93->=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/controller/SkuInfoController.java | 1 - .../mall/product/entity/SpuInfoEntity.java | 4 +- .../carl/mall/product/vo/skuvo/SpuInfoVO.java | 4 +- mall-ware/pom.xml | 5 + .../carl/mall/ware/MallWareApplication.java | 2 + .../ware/controller/PurchaseController.java | 36 +++++- .../com/carl/mall/ware/dao/WareSkuDao.java | 4 +- .../carl/mall/ware/entity/PurchaseEntity.java | 4 +- .../mall/ware/feign/ProductFeignService.java | 18 +++ .../mall/ware/service/PurchaseService.java | 8 +- .../mall/ware/service/WareSkuService.java | 2 + .../service/impl/PurchaseServiceImpl.java | 115 +++++++++++++++++- .../ware/service/impl/WareSkuServiceImpl.java | 41 +++++++ .../com/carl/mall/ware/vo/PurchaseDoneVO.java | 17 +++ .../carl/mall/ware/vo/PurchaseItemDoneVO.java | 15 +++ .../main/resources/mapper/ware/WareSkuDao.xml | 3 + 16 files changed, 264 insertions(+), 15 deletions(-) create mode 100644 mall-ware/src/main/java/com/carl/mall/ware/feign/ProductFeignService.java create mode 100644 mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseDoneVO.java create mode 100644 mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseItemDoneVO.java diff --git a/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java b/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java index e88712f..1ae72bf 100644 --- a/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java +++ b/mall-product/src/main/java/com/carl/mall/product/controller/SkuInfoController.java @@ -50,7 +50,6 @@ public class SkuInfoController { //@RequiresPermissions("product:skuinfo:info") public R info(@PathVariable("skuId") Long skuId){ SkuInfoEntity skuInfo = skuInfoService.getById(skuId); - return R.ok().put("skuInfo", skuInfo); } diff --git a/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java b/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java index 840ffc2..c1d7e5c 100644 --- a/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java +++ b/mall-product/src/main/java/com/carl/mall/product/entity/SpuInfoEntity.java @@ -54,12 +54,12 @@ public class SpuInfoEntity implements Serializable { /** * */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date createTime; /** * */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date updateTime; } diff --git a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java index edeeed1..4e9121a 100644 --- a/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java +++ b/mall-product/src/main/java/com/carl/mall/product/vo/skuvo/SpuInfoVO.java @@ -34,12 +34,12 @@ public class SpuInfoVO { /** * */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date createTime; /** * */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date updateTime; diff --git a/mall-ware/pom.xml b/mall-ware/pom.xml index 1380369..546a6f3 100644 --- a/mall-ware/pom.xml +++ b/mall-ware/pom.xml @@ -35,6 +35,11 @@ test + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + diff --git a/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java b/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java index 0a8b712..5f0cf0e 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/MallWareApplication.java @@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @@ -12,6 +13,7 @@ import org.springframework.context.annotation.ComponentScan; @MapperScan("com.carl.mall.ware.dao") @EnableDiscoveryClient @ComponentScan(basePackages = "com.carl") +@EnableFeignClients public class MallWareApplication { public static void main(String[] args) { diff --git a/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java b/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java index 83eb988..96c290f 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/controller/PurchaseController.java @@ -1,10 +1,12 @@ package com.carl.mall.ware.controller; import java.util.Arrays; +import java.util.List; import java.util.Map; //import org.apache.shiro.authz.annotation.RequiresPermissions; import com.carl.mall.ware.vo.MergeVO; +import com.carl.mall.ware.vo.PurchaseDoneVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -42,11 +44,43 @@ public class PurchaseController { @PostMapping("/merge") public R merge(@RequestBody MergeVO mergeVO){ - purchaseService.saveMerge(mergeVO); + Integer flag = purchaseService.saveMerge(mergeVO); + if (flag == -1){ + return R.error("合并失败。。。该采购单不能被合并"); + } + return R.ok(); + } + + /** + * 领取采购单 + * [2,3,4] + * @return + */ + @PostMapping("/receive") + public R receive(@RequestBody List ids){ + purchaseService.received(ids); return R.ok(); } + /** + * 完成采购 + * { + * id : 1 采购单 + * items:[ + * {itemId : 1,status: 4,reason: ""}, + * {itemId : 2,status: 4,reason: ""} + * ] //采购项 + * } + */ + @PostMapping("/done") + public R done(@RequestBody PurchaseDoneVO purchaseDoneVO){ + purchaseService.done(purchaseDoneVO); + return R.ok(); + } + + + /** * 列表 diff --git a/mall-ware/src/main/java/com/carl/mall/ware/dao/WareSkuDao.java b/mall-ware/src/main/java/com/carl/mall/ware/dao/WareSkuDao.java index faa887b..7b20c0a 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/dao/WareSkuDao.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/dao/WareSkuDao.java @@ -3,6 +3,7 @@ package com.carl.mall.ware.dao; import com.carl.mall.ware.entity.WareSkuEntity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 商品库存 @@ -13,5 +14,6 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface WareSkuDao extends BaseMapper { - + + void addStock(@Param("skuId") Long skuId, @Param("wareId")Long wareId, @Param("skuNum")Integer skuNum); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java b/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java index 388a9c1..b93e3ef 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/entity/PurchaseEntity.java @@ -58,12 +58,12 @@ public class PurchaseEntity implements Serializable { /** * 创建日期 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" ,timezone = "GMT+8") private Date createTime; /** * 更新日期 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date updateTime; } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/feign/ProductFeignService.java b/mall-ware/src/main/java/com/carl/mall/ware/feign/ProductFeignService.java new file mode 100644 index 0000000..4773c96 --- /dev/null +++ b/mall-ware/src/main/java/com/carl/mall/ware/feign/ProductFeignService.java @@ -0,0 +1,18 @@ +package com.carl.mall.ware.feign; + + +import com.carl.common.utils.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +@FeignClient("mall-product") +public interface ProductFeignService { + + /** + * 信息 + */ + @RequestMapping("/product/skuinfo/info/{skuId}") + //@RequiresPermissions("product:skuinfo:info") + public R info(@PathVariable("skuId") Long skuId); +} diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java b/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java index 09c09ee..d8c3dac 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/PurchaseService.java @@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.carl.common.utils.PageUtils; import com.carl.mall.ware.entity.PurchaseEntity; import com.carl.mall.ware.vo.MergeVO; +import com.carl.mall.ware.vo.PurchaseDoneVO; +import java.util.List; import java.util.Map; /** @@ -20,8 +22,12 @@ public interface PurchaseService extends IService { PageUtils queryPageByUnreceive(Map params); - void saveMerge(MergeVO mergeVO); + Integer saveMerge(MergeVO mergeVO); PageUtils queryPageByCondition(Map params); + + void received(List ids); + + void done(PurchaseDoneVO purchaseDoneVO); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java b/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java index dcd2af0..8bb4d76 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/WareSkuService.java @@ -18,5 +18,7 @@ public interface WareSkuService extends IService { PageUtils queryPage(Map params); PageUtils queryPageByCondition(Map params); + + void addStock(Long skuId, Long wareId, Integer skuNum); } diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java index c0f3334..c533c5d 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/PurchaseServiceImpl.java @@ -3,14 +3,15 @@ package com.carl.mall.ware.service.impl; import com.carl.common.constant.WareConstant; import com.carl.mall.ware.entity.PurchaseDetailEntity; import com.carl.mall.ware.service.PurchaseDetailService; +import com.carl.mall.ware.service.WareSkuService; import com.carl.mall.ware.vo.MergeVO; +import com.carl.mall.ware.vo.PurchaseDoneVO; +import com.carl.mall.ware.vo.PurchaseItemDoneVO; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -31,6 +32,10 @@ public class PurchaseServiceImpl extends ServiceImpl params) { IPage page = this.page( @@ -54,7 +59,7 @@ public class PurchaseServiceImpl extends ServiceImpl WareConstant.PurchaseStatusEnum.RECEIVE.getCode()){ + // 该菜单不能合并 + return -1; + } //整合采购需求单 List items = mergeVO.getItems(); final Long purchaseFinalId = purchaseId; @@ -76,12 +87,22 @@ public class PurchaseServiceImpl extends ServiceImpl{ + PurchaseDetailEntity detailEntity = purchaseDetailService.getById(id); + if (detailEntity.getStatus() == WareConstant.PurchaseDetailStatusEnum.ASSIGED.getCode() || + detailEntity.getStatus() == WareConstant.PurchaseDetailStatusEnum.CREATED.getCode()){ + return true; + } + return false; }).collect(Collectors.toList()); - purchaseDetailService.updateBatchById(detailEntityList); + if (!detailEntityList.isEmpty()){ + purchaseDetailService.updateBatchById(detailEntityList); + } PurchaseEntity entity = new PurchaseEntity(); entity.setUpdateTime(new Date()); entity.setId(purchaseId); this.updateById(entity); + return 1; } @@ -109,5 +130,89 @@ public class PurchaseServiceImpl extends ServiceImpl ids) { + //1. 领取的采购单状态只能是新建或者已分配的采购单 其他的是不能领取的 + if (!ids.isEmpty()){ + List purchaseEntities = this.listByIds(ids); + for (PurchaseEntity purchaseEntity : purchaseEntities) { + Long purchaseEntityId = purchaseEntity.getId(); + List detailEntities = purchaseDetailService + .list(new QueryWrapper() + .eq("purchase_id", purchaseEntityId)); + if ((purchaseEntity.getStatus() == WareConstant.PurchaseStatusEnum.CREATED.getCode() + || purchaseEntity.getStatus() == WareConstant.PurchaseStatusEnum.ASSIGED.getCode())&& !detailEntities.isEmpty()){ + //2. 更新采购单的状态为 已领取 + PurchaseEntity purchaseEntity1 = new PurchaseEntity(); + purchaseEntity1.setId(purchaseEntity.getId()); + purchaseEntity1.setStatus(WareConstant.PurchaseStatusEnum.RECEIVE.getCode()); + purchaseEntity1.setUpdateTime(new Date()); + this.updateById(purchaseEntity1); + //3. 更新采购项的状态 为正在采购 + //根据采购单获取对应的采购项 + for (PurchaseDetailEntity detailEntity : detailEntities) { + PurchaseDetailEntity detailEntity1 = new PurchaseDetailEntity(); + detailEntity1.setId(detailEntity.getId()); + detailEntity1.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode()); + purchaseDetailService.updateById(detailEntity1); + } + } + + } + } + + } + /** + * 完成采购 + * { + * id : 1 采购单 + * items:[ + * {itemId : 1,status: 4,reason: ""}, + * {itemId : 2,status: 4,reason: ""} + * ] //采购项 + * } + */ + @Transactional + @Override + public void done(PurchaseDoneVO purchaseDoneVO) { + //1.获取采购单id + Long id = purchaseDoneVO.getId(); //获取采购单id + //标识符 + boolean flag = true; + //获取所有采购项 + List purchaseDoneVOItems = purchaseDoneVO.getItems(); + List purchaseDetailEntityList = new ArrayList<>(); + for (PurchaseItemDoneVO purchaseDoneVOItem : purchaseDoneVOItems) { + PurchaseDetailEntity purchaseDetailEntity = new PurchaseDetailEntity(); + if (purchaseDoneVOItem.getStatus() == WareConstant.PurchaseDetailStatusEnum.HASERROR.getCode()){ + //如果有异常则把标识符制成false + flag = false; + purchaseDetailEntity.setStatus(purchaseDoneVOItem.getStatus()); + }else { + //采购项的状态是成功的 + purchaseDetailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.FINISH.getCode()); + //然后将成功的进行入库操作 从数据库查出来对应的实体然后存到库存中去 + PurchaseDetailEntity detailEntity = purchaseDetailService.getById(purchaseDoneVOItem.getItemId()); + wareSkuService.addStock(detailEntity.getSkuId(),detailEntity.getWareId(),detailEntity.getSkuNum()); + } + purchaseDetailEntity.setId(purchaseDoneVOItem.getItemId()); + purchaseDetailEntityList.add(purchaseDetailEntity); + purchaseDetailService.updateBatchById(purchaseDetailEntityList); + + } + + //改变采购单的状态 + PurchaseEntity purchaseEntity = new PurchaseEntity(); + purchaseEntity.setId(id); + purchaseEntity.setStatus(flag?WareConstant.PurchaseStatusEnum.FINISH.getCode() + :WareConstant.PurchaseStatusEnum.HASERROR.getCode()); + purchaseEntity.setUpdateTime(new Date()); + this.updateById(purchaseEntity); + + + + } + } \ No newline at end of file diff --git a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java index 566e402..8d59912 100644 --- a/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java +++ b/mall-ware/src/main/java/com/carl/mall/ware/service/impl/WareSkuServiceImpl.java @@ -1,7 +1,12 @@ package com.carl.mall.ware.service.impl; +import com.carl.common.utils.R; +import com.carl.mall.ware.feign.ProductFeignService; import org.apache.commons.lang.StringUtils; +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; @@ -17,6 +22,13 @@ import com.carl.mall.ware.service.WareSkuService; @Service("wareSkuService") public class WareSkuServiceImpl extends ServiceImpl implements WareSkuService { + + @Autowired + private WareSkuDao wareSkuDao; + + @Autowired + private ProductFeignService productFeignService; + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -48,4 +60,33 @@ public class WareSkuServiceImpl extends ServiceImpl i return new PageUtils(page); } + @Override + public void addStock(Long skuId, Long wareId, Integer skuNum) { + //先查一下有没有入库记录 必须sku_id和ware_id两个条件都满足才行 + List skuEntities = wareSkuDao + .selectList(new QueryWrapper().eq("sku_id", skuId).eq("ware_id", wareId)); + if (skuEntities == null || skuEntities.isEmpty()){ + //如果没有则新增数据 + WareSkuEntity wareSkuEntity = new WareSkuEntity(); + wareSkuEntity.setSkuId(skuId); + wareSkuEntity.setStock(skuNum); + wareSkuEntity.setWareId(wareId); + wareSkuEntity.setStockLocked(0); + //调远程商品服务获取sku name + try { + R info = productFeignService.info(skuId); + Map data= (Map) info.get("skuInfo"); + if (info.getCode() == 0){ + wareSkuEntity.setSkuName((String) data.get("skuName")); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + wareSkuDao.insert(wareSkuEntity); + + } + wareSkuDao.addStock(skuId,wareId,skuNum); + + } + } \ No newline at end of file diff --git a/mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseDoneVO.java b/mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseDoneVO.java new file mode 100644 index 0000000..82d51c7 --- /dev/null +++ b/mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseDoneVO.java @@ -0,0 +1,17 @@ +package com.carl.mall.ware.vo; + +import lombok.Data; + +import java.util.List; + +/** + * 采购单的VO数据 + */ +@Data +public class PurchaseDoneVO { + + private Long id; //采购单id + + private List items; + +} diff --git a/mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseItemDoneVO.java b/mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseItemDoneVO.java new file mode 100644 index 0000000..654038b --- /dev/null +++ b/mall-ware/src/main/java/com/carl/mall/ware/vo/PurchaseItemDoneVO.java @@ -0,0 +1,15 @@ +package com.carl.mall.ware.vo; + + +import lombok.Data; + +/** + * 采购项的VO数据 + */ +@Data +public class PurchaseItemDoneVO { + + private Long itemId; //采购需求id + private Integer status; + private String reason; +} \ No newline at end of file diff --git a/mall-ware/src/main/resources/mapper/ware/WareSkuDao.xml b/mall-ware/src/main/resources/mapper/ware/WareSkuDao.xml index 69197e0..bff61dc 100644 --- a/mall-ware/src/main/resources/mapper/ware/WareSkuDao.xml +++ b/mall-ware/src/main/resources/mapper/ware/WareSkuDao.xml @@ -12,6 +12,9 @@ + + update wms_ware_sku set stock = stock + #{skuNum} WHERE sku_id=#{skuId} AND ware_id=#{wareId} + \ No newline at end of file -- Gitee