diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 532368a1..e6cb4ab1 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -86,6 +86,18 @@ oshi-core 6.1.4 + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.1.4 + + + + com.baomidou + mybatis-plus-extension + 3.3.2 + diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java index 68230a65..6cd90865 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java @@ -16,9 +16,13 @@ package me.zhengjie.modules.productGroup.rest; import me.zhengjie.annotation.Log; +import me.zhengjie.modules.product.domain.TbProduct; +import me.zhengjie.modules.product.service.TbProductService; +import me.zhengjie.modules.product.service.dto.TbProductQueryCriteria; import me.zhengjie.modules.productGroup.domain.TbProductGroup; import me.zhengjie.modules.productGroup.service.TbProductGroupService; import me.zhengjie.modules.productGroup.service.dto.TbProductGroupQueryCriteria; +import me.zhengjie.modules.productGroup.service.vo.AddProduct; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -28,6 +32,8 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import java.io.IOException; +import java.util.List; +import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; /** @@ -43,6 +49,9 @@ public class TbProductGroupController { private final TbProductGroupService tbProductGroupService; + @Resource + private TbProductService tbProductService; + @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/download") @@ -84,4 +93,20 @@ public class TbProductGroupController { tbProductGroupService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } + + /** + *添加商品(商品列表) + * @return + */ + @GetMapping("/addProduct") + public ResponseEntity ProductList(TbProductQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbProductService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping("/addProductInfo") + public ResponseEntity addProductInfo(@RequestBody AddProduct addProduct){ + + + tbProductGroupService.updateProductIds(); + } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java index 4ee8a04b..2c5f4fdc 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java @@ -18,7 +18,10 @@ package me.zhengjie.modules.productGroup.service; import me.zhengjie.modules.productGroup.domain.TbProductGroup; import me.zhengjie.modules.productGroup.service.dto.TbProductGroupDto; import me.zhengjie.modules.productGroup.service.dto.TbProductGroupQueryCriteria; +import me.zhengjie.modules.productGroup.service.vo.AddProduct; import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; + import java.util.Map; import java.util.List; import java.io.IOException; @@ -80,4 +83,6 @@ public interface TbProductGroupService { * @throws IOException / */ void download(List all, HttpServletResponse response) throws IOException; + + ResponseEntity updateProductIds(AddProduct addProduct); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java index ffa0274b..8d391ec2 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java @@ -16,6 +16,7 @@ package me.zhengjie.modules.productGroup.service.impl; import me.zhengjie.modules.productGroup.domain.TbProductGroup; +import me.zhengjie.modules.productGroup.service.vo.AddProduct; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; @@ -24,6 +25,8 @@ import me.zhengjie.modules.productGroup.service.TbProductGroupService; import me.zhengjie.modules.productGroup.service.dto.TbProductGroupDto; import me.zhengjie.modules.productGroup.service.dto.TbProductGroupQueryCriteria; import me.zhengjie.modules.productGroup.service.mapstruct.TbProductGroupMapper; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; @@ -90,7 +93,6 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { tbProductGroupRepository.deleteById(id); } } - @Override public void download(List all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); @@ -111,4 +113,31 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { } FileUtil.downloadExcel(list, response); } + + @Override + public ResponseEntity updateProductIds(AddProduct addProduct) { + if (addProduct.getIds().size()<1){ + return new ResponseEntity<>("错误", HttpStatus.NOT_ACCEPTABLE); + } + TbProductGroup productGroup = tbProductGroupMapper.queryById(addProduct.getProductId()); + + if (productGroup == null){ + return new ResponseEntity<>("没有找到改分类", HttpStatus.NOT_ACCEPTABLE); + } + TbProductGroup tbProductGroup = new TbProductGroup(); + StringBuilder sb = new StringBuilder(); + if (productGroup.getProductIds() == null) { + for (String s : addProduct.getIds()) { + sb.append(s); + sb.append(","); + } + + tbProductGroup.setProductIds(sb.toString()); + tbProductGroup.setId(addProduct.getProductId()); + tbProductGroupMapper.update(tbProductGroup); + } + + } + + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java index d5f2fdb0..2d0dc468 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java @@ -29,4 +29,7 @@ import org.mapstruct.ReportingPolicy; @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface TbProductGroupMapper extends BaseMapper { + int update(TbProductGroup tbProductGroup); + + TbProductGroup queryById(Integer id); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.xml b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.xml new file mode 100644 index 00000000..01454082 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into tb_product_group(name, merchant_id, shop_id, pic, is_show, detail, style, sort, product_ids, created_at, updated_at) + values (#{name}, #{merchantId}, #{shopId}, #{pic}, #{isShow}, #{detail}, #{style}, #{sort}, #{productIds}, #{createdAt}, #{updatedAt}) + + + + insert into tb_product_group(name, merchant_id, shop_id, pic, is_show, detail, style, sort, product_ids, created_at, updated_at) + values + + (#{entity.name}, #{entity.merchantId}, #{entity.shopId}, #{entity.pic}, #{entity.isShow}, #{entity.detail}, #{entity.style}, #{entity.sort}, #{entity.productIds}, #{entity.createdAt}, #{entity.updatedAt}) + + + + + insert into tb_product_group(name, merchant_id, shop_id, pic, is_show, detail, style, sort, product_ids, created_at, updated_at) + values + + (#{entity.name}, #{entity.merchantId}, #{entity.shopId}, #{entity.pic}, #{entity.isShow}, #{entity.detail}, #{entity.style}, #{entity.sort}, #{entity.productIds}, #{entity.createdAt}, #{entity.updatedAt}) + + on duplicate key update + name = values(name), + merchant_id = values(merchant_id), + shop_id = values(shop_id), + pic = values(pic), + is_show = values(is_show), + detail = values(detail), + style = values(style), + sort = values(sort), + product_ids = values(product_ids), + created_at = values(created_at), + updated_at = values(updated_at) + + + + + update tb_product_group + + + name = #{name}, + + + merchant_id = #{merchantId}, + + + shop_id = #{shopId}, + + + pic = #{pic}, + + + is_show = #{isShow}, + + + detail = #{detail}, + + + style = #{style}, + + + sort = #{sort}, + + + product_ids = #{productIds}, + + + created_at = #{createdAt}, + + + updated_at = #{updatedAt}, + + + where id = #{id} + + + + + delete from tb_product_group where id = #{id} + + + + diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java new file mode 100644 index 00000000..67008b33 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java @@ -0,0 +1,16 @@ +package me.zhengjie.modules.productGroup.service.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @author lyf + */ +@Data +public class AddProduct { + List ids; + + Integer productId; + +}